Skip to content

Commit

Permalink
backbone fix
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 15, 2024
1 parent c4b7b85 commit 6981360
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
28 changes: 28 additions & 0 deletions test/fixtures/backbone/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Backbone.js 1.5.0

// (c) 2010-2022 Jeremy Ashkenas and DocumentCloud
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org

(function(factory) {

// Set up Backbone appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
define(['underscore', 'jquery', 'exports'], function($, exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global Backbone.
root.Backbone = factory(root, exports, $);
});

// Next for Node.js or CommonJS. jQuery may not be needed as a module.
} else if (typeof exports !== 'undefined') {
require('underscore'), $;
try { $ = require('jquery'); } catch (e) {}
factory(root, exports, _, $);
}

})(function(root, Backbone, _, $) {

return Backbone;
});
30 changes: 30 additions & 0 deletions test/fixtures/backbone/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { dew as _underscoreDew } from "underscore";
import { dew as _jqueryDew } from "jquery";
var exports = {},
_dewExec = false;
var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global;
export function dew() {
if (_dewExec) return exports;
_dewExec = true;
// Backbone.js 1.5.0

// (c) 2010-2022 Jeremy Ashkenas and DocumentCloud
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://backbonejs.org

(function (factory) {
// Set up Backbone appropriately for the environment. Start with AMD.

if (true) {
_underscoreDew(), $;
try {
_global.$ = _jqueryDew();
} catch (e) {}
factory(root, exports, _, $);
}
})(function (root, Backbone, _, $) {
return Backbone;
});
return exports;
}
2 changes: 1 addition & 1 deletion test/fixtures/umd-require/expected.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dew as _quickStartDew } from "./quick-start";
var exports = {};
(function (factory) {
{
if (true) {
var v = factory(null, exports);
if (v !== undefined) exports = v;
}
Expand Down
15 changes: 10 additions & 5 deletions transform-cjs-dew.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,22 @@ module.exports = function ({ types: t }) {
if (truthy) {
if (alternate.node)
alternate.remove();
if (t.isBlockStatement(consequent.node) && consequent.node.body.length === 1 && t.isExpressionStatement(consequent.node.body[0])) {
path.parentPath.replaceWith(consequent.node.body[0]);
if (t.isBlockStatement(consequent.node)) {
if (consequent.node.body.length === 1 && t.isExpressionStatement(consequent.node.body[0])) {
path.parentPath.replaceWith(consequent.node.body[0]);
}
}
else {
path.parentPath.replaceWith(consequent);
}
}
else {
consequent.remove();
if (t.isBlockStatement(alternate.node) && alternate.node.body.length === 1 && t.isExpressionStatement(alternate.node.body[0])) {
path.parentPath.replaceWith(alternate.node.body[0]);
if (consequent.node)
consequent.remove();
if (t.isBlockStatement(alternate.node)) {
if (alternate.node.body.length === 1 && t.isExpressionStatement(alternate.node.body[0])) {
path.parentPath.replaceWith(alternate.node.body[0]);
}
}
else if (alternate.node) {
path.parentPath.replaceWith(alternate);
Expand Down

0 comments on commit 6981360

Please sign in to comment.