diff --git a/test/fixtures/backbone/actual.js b/test/fixtures/backbone/actual.js new file mode 100644 index 0000000..469a7b6 --- /dev/null +++ b/test/fixtures/backbone/actual.js @@ -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; +}); \ No newline at end of file diff --git a/test/fixtures/backbone/expected.js b/test/fixtures/backbone/expected.js new file mode 100644 index 0000000..ac8c6c4 --- /dev/null +++ b/test/fixtures/backbone/expected.js @@ -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; +} \ No newline at end of file diff --git a/test/fixtures/umd-require/expected.js b/test/fixtures/umd-require/expected.js index c617912..297ca43 100644 --- a/test/fixtures/umd-require/expected.js +++ b/test/fixtures/umd-require/expected.js @@ -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; } diff --git a/transform-cjs-dew.js b/transform-cjs-dew.js index ac5ed33..c7db000 100644 --- a/transform-cjs-dew.js +++ b/transform-cjs-dew.js @@ -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);