diff --git a/lib/6to5/transformation/transform.js b/lib/6to5/transformation/transform.js index 4c64371d3a..c90a23290c 100644 --- a/lib/6to5/transformation/transform.js +++ b/lib/6to5/transformation/transform.js @@ -94,9 +94,7 @@ _.each({ _moduleFormatter: require("./transformers/_module-formatter"), typeofSymbol: require("./transformers/optional-typeof-symbol"), - externalRuntime: require("./transformers/optional-external-runtime"), - coreAliasing: require("./transformers/optional-core-aliasing"), - externalRegenerator: require("./transformers/optional-external-regenerator-runtime"), + selfContained: require("./transformers/optional-self-contained"), undefinedToVoid: require("./transformers/optional-undefined-to-void"), // spec diff --git a/lib/6to5/transformation/transformers/optional-external-regenerator-runtime.js b/lib/6to5/transformation/transformers/optional-external-regenerator-runtime.js deleted file mode 100644 index 6fee6be612..0000000000 --- a/lib/6to5/transformation/transformers/optional-external-regenerator-runtime.js +++ /dev/null @@ -1,16 +0,0 @@ -var t = require("../../types"); - -exports.optional = true; - -exports.ast = { - enter: function (ast, file) { - file._regeneratorId = file.addImport("6to5-runtime/regenerator", "regeneratorRuntime"); - } -}; - -exports.MemberExpression = function (node, parent, scope, context, file) { - var obj = node.object; - var prop = node.property; - if (!t.isReferenced(node, parent) || !t.isReferenced(obj, node)) return; - if (obj.name === "regeneratorRuntime") return t.memberExpression(file._regeneratorId, prop); -}; diff --git a/lib/6to5/transformation/transformers/optional-external-runtime.js b/lib/6to5/transformation/transformers/optional-external-runtime.js deleted file mode 100644 index 56c14e0fc4..0000000000 --- a/lib/6to5/transformation/transformers/optional-external-runtime.js +++ /dev/null @@ -1,10 +0,0 @@ -exports.optional = true; - -// In theory, it would be more appropriate to do this in `manipulateOptions`, -// but we need an identifier for the import and we can't get that before the -// AST is built. -exports.ast = { - enter: function (ast, file) { - file.opts.runtime = file.addImport("6to5-runtime/6to5", "to5Runtime").name; - } -}; diff --git a/lib/6to5/transformation/transformers/optional-core-aliasing.js b/lib/6to5/transformation/transformers/optional-self-contained.js similarity index 81% rename from lib/6to5/transformation/transformers/optional-core-aliasing.js rename to lib/6to5/transformation/transformers/optional-self-contained.js index 62613bf198..7fe1b5b4d9 100644 --- a/lib/6to5/transformation/transformers/optional-core-aliasing.js +++ b/lib/6to5/transformation/transformers/optional-self-contained.js @@ -23,7 +23,9 @@ exports.optional = true; exports.ast = { enter: function (ast, file) { + file.opts.runtime = file.addImport("6to5-runtime/6to5", "to5Runtime").name; file._coreId = file.addImport("6to5-runtime/core-js", "core"); + file._regeneratorId = file.addImport("6to5-runtime/regenerator", "regeneratorRuntime"); }, exit: function (ast, file) { @@ -67,3 +69,10 @@ exports.ast = { }); } }; + +exports.MemberExpression = function (node, parent, scope, context, file) { + var obj = node.object; + var prop = node.property; + if (!t.isReferenced(node, parent) || !t.isReferenced(obj, node)) return; + if (obj.name === "regeneratorRuntime") return t.memberExpression(file._regeneratorId, prop); +}; diff --git a/test/fixtures/transformation/optional-core-aliasing/es6-destructuring/actual.js b/test/fixtures/transformation/optional-core-aliasing/es6-destructuring/actual.js deleted file mode 100644 index 10aa8799ed..0000000000 --- a/test/fixtures/transformation/optional-core-aliasing/es6-destructuring/actual.js +++ /dev/null @@ -1 +0,0 @@ -var [a, [b], [c], d] = ["hello", [", ", "junk"], ["world"]]; diff --git a/test/fixtures/transformation/optional-core-aliasing/es6-destructuring/expected.js b/test/fixtures/transformation/optional-core-aliasing/es6-destructuring/expected.js deleted file mode 100644 index 7abd2c0cd5..0000000000 --- a/test/fixtures/transformation/optional-core-aliasing/es6-destructuring/expected.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; - -var _slicedToArray = function (arr, i) { - if (Array.isArray(arr)) { - return arr; - } else { - var _arr = []; - - for (var _iterator = _core.$for.getIterator(arr), _step; !(_step = _iterator.next()).done;) { - _arr.push(_step.value); - - if (i && _arr.length === i) break; - } - - return _arr; - } -}; - -var _core = require("6to5-runtime/core-js"); - -var _ref = ["hello", [", ", "junk"], ["world"]]; - -var a = _ref[0]; -var _ref$1 = _slicedToArray(_ref[1], 1); - -var b = _ref$1[0]; -var _ref$2 = _slicedToArray(_ref[2], 1); - -var c = _ref$2[0]; -var d = _ref[3]; diff --git a/test/fixtures/transformation/optional-core-aliasing/es6-spread/actual.js b/test/fixtures/transformation/optional-core-aliasing/es6-spread/actual.js deleted file mode 100644 index 5ebb80da66..0000000000 --- a/test/fixtures/transformation/optional-core-aliasing/es6-spread/actual.js +++ /dev/null @@ -1 +0,0 @@ -var lyrics = ["head", "and", "toes", ...parts]; diff --git a/test/fixtures/transformation/optional-core-aliasing/es6-spread/expected.js b/test/fixtures/transformation/optional-core-aliasing/es6-spread/expected.js deleted file mode 100644 index d01fa15ace..0000000000 --- a/test/fixtures/transformation/optional-core-aliasing/es6-spread/expected.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -var _toArray = function (arr) { - return Array.isArray(arr) ? arr : _core.Array.from(arr); -}; - -var _core = require("6to5-runtime/core-js"); - -var lyrics = ["head", "and", "toes"].concat(_toArray(parts)); diff --git a/test/fixtures/transformation/optional-core-aliasing/options.json b/test/fixtures/transformation/optional-core-aliasing/options.json deleted file mode 100644 index 371b5f0b20..0000000000 --- a/test/fixtures/transformation/optional-core-aliasing/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "optional": ["coreAliasing"], - "experimental": true -} diff --git a/test/fixtures/transformation/optional-external-regenerator-runtime/options.json b/test/fixtures/transformation/optional-external-regenerator-runtime/options.json deleted file mode 100644 index 40d336b5be..0000000000 --- a/test/fixtures/transformation/optional-external-regenerator-runtime/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "optional": ["externalRegenerator"] -} diff --git a/test/fixtures/transformation/optional-external-runtime/amd/expected.js b/test/fixtures/transformation/optional-external-runtime/amd/expected.js deleted file mode 100644 index 6e504dd685..0000000000 --- a/test/fixtures/transformation/optional-external-runtime/amd/expected.js +++ /dev/null @@ -1,6 +0,0 @@ -define(["exports", "6to5-runtime/6to5", "someModule"], function (exports, _to5Runtime6to5, _someModule) { - "use strict"; - - var _to5Runtime = _to5Runtime6to5; - var foo = _to5Runtime.interopRequire(_someModule); -}); diff --git a/test/fixtures/transformation/optional-external-runtime/options.json b/test/fixtures/transformation/optional-external-runtime/options.json deleted file mode 100644 index 5149c1159a..0000000000 --- a/test/fixtures/transformation/optional-external-runtime/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "optional": ["externalRuntime"] -} diff --git a/test/fixtures/transformation/optional-core-aliasing/aliased-constructors/actual.js b/test/fixtures/transformation/optional-self-contained/aliased-constructors/actual.js similarity index 100% rename from test/fixtures/transformation/optional-core-aliasing/aliased-constructors/actual.js rename to test/fixtures/transformation/optional-self-contained/aliased-constructors/actual.js diff --git a/test/fixtures/transformation/optional-core-aliasing/aliased-constructors/expected.js b/test/fixtures/transformation/optional-self-contained/aliased-constructors/expected.js similarity index 61% rename from test/fixtures/transformation/optional-core-aliasing/aliased-constructors/expected.js rename to test/fixtures/transformation/optional-self-contained/aliased-constructors/expected.js index b517b90ea6..2b56ea0257 100644 --- a/test/fixtures/transformation/optional-core-aliasing/aliased-constructors/expected.js +++ b/test/fixtures/transformation/optional-self-contained/aliased-constructors/expected.js @@ -1,7 +1,11 @@ "use strict"; +var _to5Runtime = require("6to5-runtime/6to5"); + var _core = require("6to5-runtime/core-js"); +var _regeneratorRuntime = require("6to5-runtime/regenerator"); + obj.constructor === Object; obj.constructor === _core.Promise; diff --git a/test/fixtures/transformation/optional-core-aliasing/es6-for-of/actual.js b/test/fixtures/transformation/optional-self-contained/es6-for-of/actual.js similarity index 100% rename from test/fixtures/transformation/optional-core-aliasing/es6-for-of/actual.js rename to test/fixtures/transformation/optional-self-contained/es6-for-of/actual.js diff --git a/test/fixtures/transformation/optional-core-aliasing/es6-for-of/expected.js b/test/fixtures/transformation/optional-self-contained/es6-for-of/expected.js similarity index 61% rename from test/fixtures/transformation/optional-core-aliasing/es6-for-of/expected.js rename to test/fixtures/transformation/optional-self-contained/es6-for-of/expected.js index 0fdc4cc4f5..c520e9da0a 100644 --- a/test/fixtures/transformation/optional-core-aliasing/es6-for-of/expected.js +++ b/test/fixtures/transformation/optional-self-contained/es6-for-of/expected.js @@ -1,7 +1,11 @@ "use strict"; +var _to5Runtime = require("6to5-runtime/6to5"); + var _core = require("6to5-runtime/core-js"); +var _regeneratorRuntime = require("6to5-runtime/regenerator"); + for (var _iterator = _core.$for.getIterator(arr), _step; !(_step = _iterator.next()).done;) { var i = _step.value; } diff --git a/test/fixtures/transformation/optional-core-aliasing/es7-array-comprehensions/actual.js b/test/fixtures/transformation/optional-self-contained/es7-array-comprehensions/actual.js similarity index 100% rename from test/fixtures/transformation/optional-core-aliasing/es7-array-comprehensions/actual.js rename to test/fixtures/transformation/optional-self-contained/es7-array-comprehensions/actual.js diff --git a/test/fixtures/transformation/optional-core-aliasing/es7-array-comprehensions/expected.js b/test/fixtures/transformation/optional-self-contained/es7-array-comprehensions/expected.js similarity index 70% rename from test/fixtures/transformation/optional-core-aliasing/es7-array-comprehensions/expected.js rename to test/fixtures/transformation/optional-self-contained/es7-array-comprehensions/expected.js index 9ea3b708c6..1a7d5c5482 100644 --- a/test/fixtures/transformation/optional-core-aliasing/es7-array-comprehensions/expected.js +++ b/test/fixtures/transformation/optional-self-contained/es7-array-comprehensions/expected.js @@ -1,7 +1,11 @@ "use strict"; +var _to5Runtime = require("6to5-runtime/6to5"); + var _core = require("6to5-runtime/core-js"); +var _regeneratorRuntime = require("6to5-runtime/regenerator"); + var arr = (function () { var _arr = []; diff --git a/test/fixtures/transformation/optional-self-contained/options.json b/test/fixtures/transformation/optional-self-contained/options.json new file mode 100644 index 0000000000..079cf304ad --- /dev/null +++ b/test/fixtures/transformation/optional-self-contained/options.json @@ -0,0 +1,4 @@ +{ + "optional": ["selfContained"], + "experimental": true +} diff --git a/test/fixtures/transformation/optional-external-regenerator-runtime/basic/actual.js b/test/fixtures/transformation/optional-self-contained/regenerator-runtime/actual.js similarity index 100% rename from test/fixtures/transformation/optional-external-regenerator-runtime/basic/actual.js rename to test/fixtures/transformation/optional-self-contained/regenerator-runtime/actual.js diff --git a/test/fixtures/transformation/optional-external-regenerator-runtime/basic/expected.js b/test/fixtures/transformation/optional-self-contained/regenerator-runtime/expected.js similarity index 79% rename from test/fixtures/transformation/optional-external-regenerator-runtime/basic/expected.js rename to test/fixtures/transformation/optional-self-contained/regenerator-runtime/expected.js index 275ec24ac5..92dc0c8704 100644 --- a/test/fixtures/transformation/optional-external-regenerator-runtime/basic/expected.js +++ b/test/fixtures/transformation/optional-self-contained/regenerator-runtime/expected.js @@ -1,5 +1,9 @@ "use strict"; +var _to5Runtime = require("6to5-runtime/6to5"); + +var _core = require("6to5-runtime/core-js"); + var _regeneratorRuntime = require("6to5-runtime/regenerator"); void _regeneratorRuntime.mark(function callee$0$0() { diff --git a/test/fixtures/transformation/optional-external-runtime/amd/actual.js b/test/fixtures/transformation/optional-self-contained/runtime-amd/actual.js similarity index 100% rename from test/fixtures/transformation/optional-external-runtime/amd/actual.js rename to test/fixtures/transformation/optional-self-contained/runtime-amd/actual.js diff --git a/test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js b/test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js new file mode 100644 index 0000000000..17b753e8c5 --- /dev/null +++ b/test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js @@ -0,0 +1,8 @@ +define(["exports", "6to5-runtime/6to5", "6to5-runtime/core-js", "6to5-runtime/regenerator", "someModule"], function (exports, _to5Runtime6to5, _to5RuntimeCoreJs, _to5RuntimeRegenerator, _someModule) { + "use strict"; + + var _to5Runtime = _to5Runtime6to5; + var _core = _to5RuntimeCoreJs; + var _regeneratorRuntime = _to5RuntimeRegenerator; + var foo = _to5Runtime.interopRequire(_someModule); +}); diff --git a/test/fixtures/transformation/optional-external-runtime/amd/options.json b/test/fixtures/transformation/optional-self-contained/runtime-amd/options.json similarity index 100% rename from test/fixtures/transformation/optional-external-runtime/amd/options.json rename to test/fixtures/transformation/optional-self-contained/runtime-amd/options.json diff --git a/test/fixtures/transformation/optional-external-runtime/commonjs/actual.js b/test/fixtures/transformation/optional-self-contained/runtime-commonjs/actual.js similarity index 100% rename from test/fixtures/transformation/optional-external-runtime/commonjs/actual.js rename to test/fixtures/transformation/optional-self-contained/runtime-commonjs/actual.js diff --git a/test/fixtures/transformation/optional-external-runtime/commonjs/expected.js b/test/fixtures/transformation/optional-self-contained/runtime-commonjs/expected.js similarity index 54% rename from test/fixtures/transformation/optional-external-runtime/commonjs/expected.js rename to test/fixtures/transformation/optional-self-contained/runtime-commonjs/expected.js index d660411bc0..9fd1cd7ec9 100644 --- a/test/fixtures/transformation/optional-external-runtime/commonjs/expected.js +++ b/test/fixtures/transformation/optional-self-contained/runtime-commonjs/expected.js @@ -2,4 +2,8 @@ var _to5Runtime = require("6to5-runtime/6to5"); +var _core = require("6to5-runtime/core-js"); + +var _regeneratorRuntime = require("6to5-runtime/regenerator"); + var foo = _to5Runtime.interopRequireWildcard(require("someModule"));