From 7d87e52377b74f159a03fa392a6480296efd5432 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Wed, 25 Feb 2015 17:20:23 +1100 Subject: [PATCH] rejigger strict directives transformer logic so they're included in the body before module formatters are ran - @jayphelps --- .../transformation/helpers/use-strict.js | 21 +++++++++++ .../transformation/transformers/index.js | 1 + .../transformers/internal/declarations.js | 37 ++++++++++--------- .../transformers/internal/module-formatter.js | 6 ++- .../transformers/internal/use-strict.js | 9 +++++ .../transformers/other/use-strict.js | 4 -- .../exports-default/expected.js | 4 +- .../es6-modules-amd/exports-from/expected.js | 4 +- .../es6-modules-amd/exports-named/expected.js | 4 +- .../exports-variable/expected.js | 4 +- .../get-module-name-option/expected.js | 6 +-- .../hoist-function-exports/expected.js | 4 +- .../imports-default/expected.js | 4 +- .../es6-modules-amd/imports-glob/expected.js | 4 +- .../imports-mixing/expected.js | 4 +- .../es6-modules-amd/imports-named/expected.js | 4 +- .../es6-modules-amd/imports/expected.js | 6 +-- .../es6-modules-amd/module-name/expected.js | 4 +- .../es6-modules-amd/overview/expected.js | 4 +- .../es6-modules-amd/remap/expected.js | 4 +- .../exports-default/expected.js | 4 +- .../exports-from/expected.js | 6 +-- .../exports-generator/expected.js | 6 +-- .../exports-named/expected.js | 4 +- .../exports-variable/expected.js | 4 +- .../get-module-name-option/expected.js | 6 +-- .../hoist-function-exports/expected.js | 4 +- .../imports-default/expected.js | 6 +-- .../imports-glob/expected.js | 6 +-- .../imports-mixing/expected.js | 6 +-- .../imports-named/expected.js | 6 +-- .../es6-modules-system/imports/expected.js | 6 +-- .../es6-modules-system/overview/expected.js | 4 +- .../es6-modules-system/remap/expected.js | 4 +- .../exports-default/expected.js | 4 +- .../es6-modules-umd/exports-from/expected.js | 4 +- .../es6-modules-umd/exports-named/expected.js | 4 +- .../exports-variable/expected.js | 4 +- .../get-module-name-option/expected.js | 6 +-- .../hoist-function-exports/expected.js | 4 +- .../imports-default/expected.js | 4 +- .../es6-modules-umd/imports-glob/expected.js | 4 +- .../imports-mixing/expected.js | 4 +- .../es6-modules-umd/imports-named/expected.js | 4 +- .../es6-modules-umd/imports/expected.js | 6 +-- .../es6-modules-umd/module-name/expected.js | 4 +- .../es6-modules-umd/overview/expected.js | 4 +- .../es6-modules-umd/remap/expected.js | 4 +- .../runtime/modules-amd/expected.js | 4 +- .../runtime/modules-system/expected.js | 4 +- .../runtime/modules-umd/expected.js | 6 +-- 51 files changed, 159 insertions(+), 125 deletions(-) create mode 100644 lib/babel/transformation/helpers/use-strict.js create mode 100644 lib/babel/transformation/transformers/internal/use-strict.js diff --git a/lib/babel/transformation/helpers/use-strict.js b/lib/babel/transformation/helpers/use-strict.js new file mode 100644 index 0000000000..7709528a41 --- /dev/null +++ b/lib/babel/transformation/helpers/use-strict.js @@ -0,0 +1,21 @@ +"use strict"; + +var t = require("../../types"); + +exports.has = function (node) { + var first = node.body[0]; + return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" }); +}; + +exports.wrap = function (node, callback) { + var useStrictNode; + if (exports.has(node)) { + useStrictNode = node.body.shift(); + } + + callback(); + + if (useStrictNode) { + node.body.unshift(useStrictNode); + } +}; diff --git a/lib/babel/transformation/transformers/index.js b/lib/babel/transformation/transformers/index.js index 4fa7330963..7162c0d066 100644 --- a/lib/babel/transformation/transformers/index.js +++ b/lib/babel/transformation/transformers/index.js @@ -95,6 +95,7 @@ module.exports = { "spec.typeofSymbol": require("./spec/typeof-symbol"), "spec.undefinedToVoid": require("./spec/undefined-to-void"), + _useStrict: require("./internal/use-strict"), _moduleFormatter: require("./internal/module-formatter"), "es3.propertyLiterals": require("./es3/property-literals"), diff --git a/lib/babel/transformation/transformers/internal/declarations.js b/lib/babel/transformation/transformers/internal/declarations.js index a4297143a4..faa1ca5c54 100644 --- a/lib/babel/transformation/transformers/internal/declarations.js +++ b/lib/babel/transformation/transformers/internal/declarations.js @@ -1,6 +1,7 @@ "use strict"; -var t = require("../../../types"); +var useStrict = require("../../helpers/use-strict"); +var t = require("../../../types"); exports.secondPass = true; @@ -8,26 +9,28 @@ exports.BlockStatement = exports.Program = function (node, parent, scope, file) { if (!node._declarations) return; - var kinds = {}; - var kind; + useStrict.wrap(node, function () { + var kinds = {}; + var kind; - for (var i in node._declarations) { - var declar = node._declarations[i]; + for (var i in node._declarations) { + var declar = node._declarations[i]; - kind = declar.kind || "var"; - var declarNode = t.variableDeclarator(declar.id, declar.init); + kind = declar.kind || "var"; + var declarNode = t.variableDeclarator(declar.id, declar.init); - if (declar.init) { - node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, [declarNode]))); - } else { - kinds[kind] = kinds[kind] || []; - kinds[kind].push(declarNode); + if (declar.init) { + node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, [declarNode]))); + } else { + kinds[kind] = kinds[kind] || []; + kinds[kind].push(declarNode); + } } - } - for (kind in kinds) { - node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, kinds[kind]))); - } + for (kind in kinds) { + node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, kinds[kind]))); + } - node._declarations = null; + node._declarations = null; + }); }; diff --git a/lib/babel/transformation/transformers/internal/module-formatter.js b/lib/babel/transformation/transformers/internal/module-formatter.js index 4499ea7bbb..d1982280c4 100644 --- a/lib/babel/transformation/transformers/internal/module-formatter.js +++ b/lib/babel/transformation/transformers/internal/module-formatter.js @@ -1,9 +1,13 @@ "use strict"; +var useStrict = require("../../helpers/use-strict"); + exports.Program = function (program, parent, scope, file) { if (!file.transformers["es6.modules"].canRun()) return; - program.body = file.dynamicImports.concat(program.body); + useStrict.wrap(program, function () { + program.body = file.dynamicImports.concat(program.body); + }); if (file.moduleFormatter.transform) { file.moduleFormatter.transform(program); diff --git a/lib/babel/transformation/transformers/internal/use-strict.js b/lib/babel/transformation/transformers/internal/use-strict.js new file mode 100644 index 0000000000..3df31e1c73 --- /dev/null +++ b/lib/babel/transformation/transformers/internal/use-strict.js @@ -0,0 +1,9 @@ +"use strict"; + +var t = require("../../../types"); + +exports.Program = function (program, parent, scope, file) { + if (file.transformers.useStrict.canRun()) { + program.body.unshift(t.expressionStatement(t.literal("use strict"))); + } +}; diff --git a/lib/babel/transformation/transformers/other/use-strict.js b/lib/babel/transformation/transformers/other/use-strict.js index 5ce37145f8..dc864770e8 100644 --- a/lib/babel/transformation/transformers/other/use-strict.js +++ b/lib/babel/transformation/transformers/other/use-strict.js @@ -10,10 +10,6 @@ exports.Program = function (program) { } }; -exports.post = function (file) { - file.ast.program.body.unshift(t.expressionStatement(t.literal("use strict"))); -}; - exports.FunctionDeclaration = exports.FunctionExpression = function () { this.skip(); diff --git a/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js b/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js index 371d42a3ac..ea14e00737 100644 --- a/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/exports-default/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "module"], function (exports, module) { + "use strict"; + var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; module.exports = foo; diff --git a/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js b/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js index ed602a6536..113dd40be3 100644 --- a/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/exports-from/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "foo"], function (exports, _foo) { + "use strict"; + var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; }; var _defaults = function (obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }; diff --git a/test/fixtures/transformation/es6-modules-amd/exports-named/expected.js b/test/fixtures/transformation/es6-modules-amd/exports-named/expected.js index 84d448ff9c..d66e609acb 100644 --- a/test/fixtures/transformation/es6-modules-amd/exports-named/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/exports-named/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports"], function (exports) { + "use strict"; + exports.foo = foo; exports.foo = foo; exports.bar = bar; diff --git a/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js index 78d201535b..9f4243860d 100644 --- a/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/exports-variable/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports"], function (exports) { + "use strict"; + var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; exports.foo7 = foo7; diff --git a/test/fixtures/transformation/es6-modules-amd/get-module-name-option/expected.js b/test/fixtures/transformation/es6-modules-amd/get-module-name-option/expected.js index b06fd3928a..4a88732e99 100644 --- a/test/fixtures/transformation/es6-modules-amd/get-module-name-option/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/get-module-name-option/expected.js @@ -1,3 +1,3 @@ -"use strict"; - -define("my custom module name", ["exports"], function (exports) {}); \ No newline at end of file +define("my custom module name", ["exports"], function (exports) { + "use strict"; +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-amd/hoist-function-exports/expected.js b/test/fixtures/transformation/es6-modules-amd/hoist-function-exports/expected.js index 058d009ac2..79267d3f30 100644 --- a/test/fixtures/transformation/es6-modules-amd/hoist-function-exports/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/hoist-function-exports/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "./evens"], function (exports, _evens) { + "use strict"; + exports.nextOdd = nextOdd; var isEven = _evens.isEven; function nextOdd(n) { diff --git a/test/fixtures/transformation/es6-modules-amd/imports-default/expected.js b/test/fixtures/transformation/es6-modules-amd/imports-default/expected.js index 167222ee75..4575943441 100644 --- a/test/fixtures/transformation/es6-modules-amd/imports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/imports-default/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "foo"], function (exports, _foo) { + "use strict"; + var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; var foo = _interopRequire(_foo); diff --git a/test/fixtures/transformation/es6-modules-amd/imports-glob/expected.js b/test/fixtures/transformation/es6-modules-amd/imports-glob/expected.js index 4788c80508..cc03946787 100644 --- a/test/fixtures/transformation/es6-modules-amd/imports-glob/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/imports-glob/expected.js @@ -1,5 +1,5 @@ -"use strict"; - define(["exports", "foo"], function (exports, _foo) { + "use strict"; + var foo = _foo; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-amd/imports-mixing/expected.js b/test/fixtures/transformation/es6-modules-amd/imports-mixing/expected.js index 59164e1d1f..b147224a07 100644 --- a/test/fixtures/transformation/es6-modules-amd/imports-mixing/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/imports-mixing/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "foo"], function (exports, _foo) { + "use strict"; + var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; var foo = _interopRequire(_foo); diff --git a/test/fixtures/transformation/es6-modules-amd/imports-named/expected.js b/test/fixtures/transformation/es6-modules-amd/imports-named/expected.js index 8e5e4a9e81..0b46440074 100644 --- a/test/fixtures/transformation/es6-modules-amd/imports-named/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/imports-named/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "foo"], function (exports, _foo) { + "use strict"; + var bar = _foo.bar; var bar2 = _foo.bar2; var baz = _foo.baz; diff --git a/test/fixtures/transformation/es6-modules-amd/imports/expected.js b/test/fixtures/transformation/es6-modules-amd/imports/expected.js index 36ff98ebcc..84e1e6dcc7 100644 --- a/test/fixtures/transformation/es6-modules-amd/imports/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/imports/expected.js @@ -1,3 +1,3 @@ -"use strict"; - -define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) {}); \ No newline at end of file +define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) { + "use strict"; +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-amd/module-name/expected.js b/test/fixtures/transformation/es6-modules-amd/module-name/expected.js index 5c6619dc82..c129a9ffb6 100644 --- a/test/fixtures/transformation/es6-modules-amd/module-name/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/module-name/expected.js @@ -1,5 +1,5 @@ -"use strict"; - define("es6-modules-amd/module-name/expected", ["exports"], function (exports) { + "use strict"; + foobar(); }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-amd/overview/expected.js b/test/fixtures/transformation/es6-modules-amd/overview/expected.js index 28fa5347fa..a9993c1612 100644 --- a/test/fixtures/transformation/es6-modules-amd/overview/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/overview/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) { + "use strict"; + var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; var foo = _interopRequire(_foo); diff --git a/test/fixtures/transformation/es6-modules-amd/remap/expected.js b/test/fixtures/transformation/es6-modules-amd/remap/expected.js index 0fe9ee14d8..accde1fb6e 100644 --- a/test/fixtures/transformation/es6-modules-amd/remap/expected.js +++ b/test/fixtures/transformation/es6-modules-amd/remap/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports"], function (exports) { + "use strict"; + var test = exports.test = 2; test = exports.test = 5; test = exports.test += 1; diff --git a/test/fixtures/transformation/es6-modules-system/exports-default/expected.js b/test/fixtures/transformation/es6-modules-system/exports-default/expected.js index 9fa1b7604a..f6442f9402 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-default/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register([], function (_export) { var _classCallCheck, _default, Foo; @@ -9,6 +7,8 @@ System.register([], function (_export) { return { setters: [], execute: function () { + "use strict"; + _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; _export("default", 42); diff --git a/test/fixtures/transformation/es6-modules-system/exports-from/expected.js b/test/fixtures/transformation/es6-modules-system/exports-from/expected.js index 389dfc41ae..c1eaca763d 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-from/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-from/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register(["foo"], function (_export) { return { setters: [function (_foo) { @@ -21,6 +19,8 @@ System.register(["foo"], function (_export) { _export("bar", _foo.bar); }], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js b/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js index b7ae39a4d7..e4af9b4163 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register([], function (_export) { var generator = regeneratorRuntime.mark(function generator() { return regeneratorRuntime.wrap(function generator$(context$1$0) { @@ -19,6 +17,8 @@ System.register([], function (_export) { return { setters: [], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/exports-named/expected.js b/test/fixtures/transformation/es6-modules-system/exports-named/expected.js index e332163eba..410345bcfa 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-named/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-named/expected.js @@ -1,9 +1,9 @@ -"use strict"; - System.register([], function (_export) { return { setters: [], execute: function () { + "use strict"; + _export("foo", foo); _export("foo", foo); diff --git a/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js index 9ada1fff32..8e7893b129 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-variable/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register([], function (_export) { var _classCallCheck, foo, foo2, foo3, foo4, foo5, foo6, foo8; @@ -9,6 +7,8 @@ System.register([], function (_export) { return { setters: [], execute: function () { + "use strict"; + _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; foo = _export("foo", 1); diff --git a/test/fixtures/transformation/es6-modules-system/get-module-name-option/expected.js b/test/fixtures/transformation/es6-modules-system/get-module-name-option/expected.js index bd650c0abc..0f7fc369ae 100644 --- a/test/fixtures/transformation/es6-modules-system/get-module-name-option/expected.js +++ b/test/fixtures/transformation/es6-modules-system/get-module-name-option/expected.js @@ -1,8 +1,8 @@ -"use strict"; - System.register("my custom module name", [], function (_export) { return { setters: [], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/hoist-function-exports/expected.js b/test/fixtures/transformation/es6-modules-system/hoist-function-exports/expected.js index 553b69fe58..0e4643803d 100644 --- a/test/fixtures/transformation/es6-modules-system/hoist-function-exports/expected.js +++ b/test/fixtures/transformation/es6-modules-system/hoist-function-exports/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register(["./evens"], function (_export) { var isEven, p, isOdd; @@ -14,6 +12,8 @@ System.register(["./evens"], function (_export) { isEven = _evens.isEven; }], execute: function () { + "use strict"; + p = _export("p", 5); isOdd = _export("isOdd", (function (isEven) { return function (n) { diff --git a/test/fixtures/transformation/es6-modules-system/imports-default/expected.js b/test/fixtures/transformation/es6-modules-system/imports-default/expected.js index 12696f6653..2cb90409c2 100644 --- a/test/fixtures/transformation/es6-modules-system/imports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-system/imports-default/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register(["foo"], function (_export) { var foo, foo2; return { @@ -7,6 +5,8 @@ System.register(["foo"], function (_export) { foo = _foo["default"]; foo2 = _foo["default"]; }], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/imports-glob/expected.js b/test/fixtures/transformation/es6-modules-system/imports-glob/expected.js index acd0e1efcf..67e60e45ca 100644 --- a/test/fixtures/transformation/es6-modules-system/imports-glob/expected.js +++ b/test/fixtures/transformation/es6-modules-system/imports-glob/expected.js @@ -1,11 +1,11 @@ -"use strict"; - System.register(["foo"], function (_export) { var foo; return { setters: [function (_foo) { foo = _foo; }], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/imports-mixing/expected.js b/test/fixtures/transformation/es6-modules-system/imports-mixing/expected.js index 7e4f71269d..9ac0cd5ce2 100644 --- a/test/fixtures/transformation/es6-modules-system/imports-mixing/expected.js +++ b/test/fixtures/transformation/es6-modules-system/imports-mixing/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register(["foo"], function (_export) { var foo, xyz; return { @@ -7,6 +5,8 @@ System.register(["foo"], function (_export) { foo = _foo["default"]; xyz = _foo.baz; }], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/imports-named/expected.js b/test/fixtures/transformation/es6-modules-system/imports-named/expected.js index 9b8eb605bf..b66550bded 100644 --- a/test/fixtures/transformation/es6-modules-system/imports-named/expected.js +++ b/test/fixtures/transformation/es6-modules-system/imports-named/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register(["foo"], function (_export) { var bar, bar2, baz, baz2, baz3, xyz; return { @@ -11,6 +9,8 @@ System.register(["foo"], function (_export) { baz3 = _foo.bar; xyz = _foo.xyz; }], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/imports/expected.js b/test/fixtures/transformation/es6-modules-system/imports/expected.js index dcd2757e57..2b02e610fc 100644 --- a/test/fixtures/transformation/es6-modules-system/imports/expected.js +++ b/test/fixtures/transformation/es6-modules-system/imports/expected.js @@ -1,8 +1,8 @@ -"use strict"; - System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) { return { setters: [function (_foo) {}, function (_fooBar) {}, function (_directoryFooBar) {}], - execute: function () {} + execute: function () { + "use strict"; + } }; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-system/overview/expected.js b/test/fixtures/transformation/es6-modules-system/overview/expected.js index d7a161df9f..c8e042ef50 100644 --- a/test/fixtures/transformation/es6-modules-system/overview/expected.js +++ b/test/fixtures/transformation/es6-modules-system/overview/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) { var foo, foo2, bar, bar2, test2; return { @@ -10,6 +8,8 @@ System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) { bar2 = _foo.foo; }, function (_fooBar) {}, function (_directoryFooBar) {}], execute: function () { + "use strict"; + _export("test", test); test2 = _export("test2", 5); diff --git a/test/fixtures/transformation/es6-modules-system/remap/expected.js b/test/fixtures/transformation/es6-modules-system/remap/expected.js index 75dfba18e2..16a16011c6 100644 --- a/test/fixtures/transformation/es6-modules-system/remap/expected.js +++ b/test/fixtures/transformation/es6-modules-system/remap/expected.js @@ -1,10 +1,10 @@ -"use strict"; - System.register([], function (_export) { var test; return { setters: [], execute: function () { + "use strict"; + test = _export("test", 2); _export("test", test = 5); diff --git a/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js b/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js index dea3d841ba..7395d1a5f7 100644 --- a/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/exports-default/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "module"], factory); @@ -7,6 +5,8 @@ factory(exports, module); } })(function (exports, module) { + "use strict"; + var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; module.exports = foo; diff --git a/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js b/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js index 022983fc7b..35cdb100e3 100644 --- a/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/exports-from/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo"], factory); @@ -7,6 +5,8 @@ factory(exports, require("foo")); } })(function (exports, _foo) { + "use strict"; + var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; }; var _defaults = function (obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }; diff --git a/test/fixtures/transformation/es6-modules-umd/exports-named/expected.js b/test/fixtures/transformation/es6-modules-umd/exports-named/expected.js index a894d9a509..3b4d067ec0 100644 --- a/test/fixtures/transformation/es6-modules-umd/exports-named/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/exports-named/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports"], factory); @@ -7,6 +5,8 @@ factory(exports); } })(function (exports) { + "use strict"; + exports.foo = foo; exports.foo = foo; exports.bar = bar; diff --git a/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js b/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js index 828ae59ea0..abd2b1fee0 100644 --- a/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/exports-variable/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports"], factory); @@ -7,6 +5,8 @@ factory(exports); } })(function (exports) { + "use strict"; + var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; exports.foo7 = foo7; diff --git a/test/fixtures/transformation/es6-modules-umd/get-module-name-option/expected.js b/test/fixtures/transformation/es6-modules-umd/get-module-name-option/expected.js index bd0e644592..ceb362161c 100644 --- a/test/fixtures/transformation/es6-modules-umd/get-module-name-option/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/get-module-name-option/expected.js @@ -1,9 +1,9 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define("my custom module name", ["exports"], factory); } else if (typeof exports !== "undefined") { factory(exports); } -})(function (exports) {}); \ No newline at end of file +})(function (exports) { + "use strict"; +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-umd/hoist-function-exports/expected.js b/test/fixtures/transformation/es6-modules-umd/hoist-function-exports/expected.js index 09d47d6c27..1241f1f68e 100644 --- a/test/fixtures/transformation/es6-modules-umd/hoist-function-exports/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/hoist-function-exports/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "./evens"], factory); @@ -7,6 +5,8 @@ factory(exports, require("./evens")); } })(function (exports, _evens) { + "use strict"; + exports.nextOdd = nextOdd; var isEven = _evens.isEven; function nextOdd(n) { diff --git a/test/fixtures/transformation/es6-modules-umd/imports-default/expected.js b/test/fixtures/transformation/es6-modules-umd/imports-default/expected.js index 17c0bb534c..46111b877c 100644 --- a/test/fixtures/transformation/es6-modules-umd/imports-default/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/imports-default/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo"], factory); @@ -7,6 +5,8 @@ factory(exports, require("foo")); } })(function (exports, _foo) { + "use strict"; + var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; var foo = _interopRequire(_foo); diff --git a/test/fixtures/transformation/es6-modules-umd/imports-glob/expected.js b/test/fixtures/transformation/es6-modules-umd/imports-glob/expected.js index 067a1a2714..45a763f2f2 100644 --- a/test/fixtures/transformation/es6-modules-umd/imports-glob/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/imports-glob/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo"], factory); @@ -7,5 +5,7 @@ factory(exports, require("foo")); } })(function (exports, _foo) { + "use strict"; + var foo = _foo; }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-umd/imports-mixing/expected.js b/test/fixtures/transformation/es6-modules-umd/imports-mixing/expected.js index 5de8931b9b..6b684e31de 100644 --- a/test/fixtures/transformation/es6-modules-umd/imports-mixing/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/imports-mixing/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo"], factory); @@ -7,6 +5,8 @@ factory(exports, require("foo")); } })(function (exports, _foo) { + "use strict"; + var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; var foo = _interopRequire(_foo); diff --git a/test/fixtures/transformation/es6-modules-umd/imports-named/expected.js b/test/fixtures/transformation/es6-modules-umd/imports-named/expected.js index 3e4f5746d9..22062a454c 100644 --- a/test/fixtures/transformation/es6-modules-umd/imports-named/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/imports-named/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo"], factory); @@ -7,6 +5,8 @@ factory(exports, require("foo")); } })(function (exports, _foo) { + "use strict"; + var bar = _foo.bar; var bar2 = _foo.bar2; var baz = _foo.baz; diff --git a/test/fixtures/transformation/es6-modules-umd/imports/expected.js b/test/fixtures/transformation/es6-modules-umd/imports/expected.js index 29cf8095a7..2e39b15cd2 100644 --- a/test/fixtures/transformation/es6-modules-umd/imports/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/imports/expected.js @@ -1,9 +1,9 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar")); } -})(function (exports, _foo, _fooBar, _directoryFooBar) {}); \ No newline at end of file +})(function (exports, _foo, _fooBar, _directoryFooBar) { + "use strict"; +}); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-umd/module-name/expected.js b/test/fixtures/transformation/es6-modules-umd/module-name/expected.js index 193a600c46..aa570b25e3 100644 --- a/test/fixtures/transformation/es6-modules-umd/module-name/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/module-name/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define("es6-modules-umd/module-name/expected", ["exports"], factory); @@ -7,5 +5,7 @@ factory(exports); } })(function (exports) { + "use strict"; + foobar(); }); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-modules-umd/overview/expected.js b/test/fixtures/transformation/es6-modules-umd/overview/expected.js index 821fab6755..8f0262a8ee 100644 --- a/test/fixtures/transformation/es6-modules-umd/overview/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/overview/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory); @@ -7,6 +5,8 @@ factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar")); } })(function (exports, _foo, _fooBar, _directoryFooBar) { + "use strict"; + var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; }; var foo = _interopRequire(_foo); diff --git a/test/fixtures/transformation/es6-modules-umd/remap/expected.js b/test/fixtures/transformation/es6-modules-umd/remap/expected.js index 82882dde3f..e44f8e70c5 100644 --- a/test/fixtures/transformation/es6-modules-umd/remap/expected.js +++ b/test/fixtures/transformation/es6-modules-umd/remap/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports"], factory); @@ -7,6 +5,8 @@ factory(exports); } })(function (exports) { + "use strict"; + var test = exports.test = 2; test = exports.test = 5; test = exports.test += 1; diff --git a/test/fixtures/transformation/runtime/modules-amd/expected.js b/test/fixtures/transformation/runtime/modules-amd/expected.js index 9db3f81296..ef9e316cb0 100644 --- a/test/fixtures/transformation/runtime/modules-amd/expected.js +++ b/test/fixtures/transformation/runtime/modules-amd/expected.js @@ -1,6 +1,6 @@ -"use strict"; - define(["exports", "foo", "babel-runtime/helpers"], function (exports, _foo, _babelRuntimeHelpers) { + "use strict"; + var _babelHelpers = _babelRuntimeHelpers["default"]; var foo = _babelHelpers.interopRequire(_foo); diff --git a/test/fixtures/transformation/runtime/modules-system/expected.js b/test/fixtures/transformation/runtime/modules-system/expected.js index 526b72c64d..cdd6623fbf 100644 --- a/test/fixtures/transformation/runtime/modules-system/expected.js +++ b/test/fixtures/transformation/runtime/modules-system/expected.js @@ -1,5 +1,3 @@ -"use strict"; - System.register(["babel-runtime/helpers"], function (_export) { var _babelHelpers; @@ -8,6 +6,8 @@ System.register(["babel-runtime/helpers"], function (_export) { _babelHelpers = _babelRuntimeHelpers["default"]; }], execute: function () { + "use strict"; + foo.apply(undefined, _babelHelpers.toConsumableArray(bar)); } }; diff --git a/test/fixtures/transformation/runtime/modules-umd/expected.js b/test/fixtures/transformation/runtime/modules-umd/expected.js index d380c97e69..5868c4ac04 100644 --- a/test/fixtures/transformation/runtime/modules-umd/expected.js +++ b/test/fixtures/transformation/runtime/modules-umd/expected.js @@ -1,5 +1,3 @@ -"use strict"; - (function (factory) { if (typeof define === "function" && define.amd) { define(["exports", "foo", "babel-runtime/helpers"], factory); @@ -7,7 +5,9 @@ factory(exports, require("foo"), require("babel-runtime/helpers")); } })(function (exports, _foo, _babelRuntimeHelpers) { + "use strict"; + var _babelHelpers = _babelRuntimeHelpers["default"]; var foo = _babelHelpers.interopRequire(_foo); -}); +}); \ No newline at end of file