Merge branch 'AluisioASG-scoped-es6-runtime' into 3.0.0
This commit is contained in:
commit
d6412d0a1b
@ -87,7 +87,11 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var key = t.getSpecifierName(specifier);
|
||||
var ref = this._push(node);
|
||||
|
||||
if (t.isImportBatchSpecifier(specifier)) {
|
||||
if (_.contains(this.file.dynamicImports, node)) {
|
||||
// Prevent unnecessary renaming of dynamic imports.
|
||||
this.ids[node.source.value] = key;
|
||||
return;
|
||||
} else if (t.isImportBatchSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||
// import foo from "foo";
|
||||
|
||||
@ -6,6 +6,7 @@ var DefaultFormatter = require("./_default");
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
function CommonJSFormatter(file) {
|
||||
DefaultFormatter.apply(this, arguments);
|
||||
@ -26,13 +27,13 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
nodes.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(variableName,
|
||||
t.callExpression(this.file.addHelper("interop-require"), [util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
})])
|
||||
)
|
||||
]));
|
||||
var ref = util.template("require", {
|
||||
MODULE_NAME: node.source
|
||||
});
|
||||
if (!_.contains(this.file.dynamicImports, node)) {
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
}
|
||||
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(variableName, ref)]));
|
||||
} else {
|
||||
if (specifier.type === "ImportBatchSpecifier") {
|
||||
// import * as bar from "foo";
|
||||
|
||||
@ -96,7 +96,7 @@ _.each({
|
||||
_moduleFormatter: require("./transformers/_module-formatter"),
|
||||
|
||||
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||
selfContained: require("./transformers/optional-self-contained"),
|
||||
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
||||
undeclaredVariableCheck: require("./transformers/optional-undeclared-variable-check"),
|
||||
|
||||
|
||||
@ -23,7 +23,9 @@ exports.optional = true;
|
||||
|
||||
exports.ast = {
|
||||
enter: function (ast, file) {
|
||||
file._coreId = file.addImport("core-js/library", "core");
|
||||
file.opts.runtime = file.addImport("6to5-runtime/helpers", "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,9 @@ exports.ast = {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.Identifier = function (node, parent, scope, context, file) {
|
||||
if (node.name === "regeneratorRuntime" && t.isReferenced(node, parent)) {
|
||||
node.name = file._regeneratorId;
|
||||
}
|
||||
};
|
||||
@ -1,10 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _bluebird = _interopRequire(require("bluebird"));
|
||||
var _bluebird = require("bluebird");
|
||||
|
||||
var foo = _bluebird.coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _bluebird = _interopRequire(require("bluebird"));
|
||||
var _bluebird = require("bluebird");
|
||||
|
||||
var foo = _bluebird.coroutine(function* foo() {
|
||||
var wat = yield bar();
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
|
||||
obj.constructor === Object;
|
||||
obj.constructor === _core.Promise;
|
||||
|
||||
_core.Symbol();
|
||||
_core.Symbol("test");
|
||||
|
||||
new _core.Map();
|
||||
@ -1 +0,0 @@
|
||||
var [a, [b], [c], d] = ["hello", [", ", "junk"], ["world"]];
|
||||
@ -1,34 +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 _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
|
||||
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];
|
||||
@ -1,11 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
|
||||
for (var _iterator = _core.$for.getIterator(arr), _step; !(_step = _iterator.next()).done;) {
|
||||
var i = _step.value;
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
var lyrics = ["head", "and", "toes", ...parts];
|
||||
@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _toArray = function (arr) {
|
||||
return Array.isArray(arr) ? arr : _core.Array.from(arr);
|
||||
};
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
|
||||
var lyrics = ["head", "and", "toes"].concat(_toArray(parts));
|
||||
@ -1,4 +0,0 @@
|
||||
{
|
||||
"optional": ["coreAliasing"],
|
||||
"experimental": true
|
||||
}
|
||||
15
test/fixtures/transformation/optional-self-contained/aliased-constructors/expected.js
vendored
Normal file
15
test/fixtures/transformation/optional-self-contained/aliased-constructors/expected.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Runtime = require("6to5-runtime/helpers");
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
obj.constructor === Object;
|
||||
obj.constructor === _core.Promise;
|
||||
|
||||
_core.Symbol();
|
||||
_core.Symbol("test");
|
||||
|
||||
new _core.Map();
|
||||
11
test/fixtures/transformation/optional-self-contained/es6-for-of/expected.js
vendored
Normal file
11
test/fixtures/transformation/optional-self-contained/es6-for-of/expected.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Runtime = require("6to5-runtime/helpers");
|
||||
|
||||
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;
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
var _to5Runtime = require("6to5-runtime/helpers");
|
||||
|
||||
var _core = _interopRequire(require("core-js/library"));
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
var arr = (function () {
|
||||
var _arr = [];
|
||||
6
test/fixtures/transformation/optional-self-contained/full/actual.js
vendored
Normal file
6
test/fixtures/transformation/optional-self-contained/full/actual.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import foo, * as bar from "someModule";
|
||||
|
||||
export const myWord = Symbol("abc");
|
||||
export function* giveWord () {
|
||||
yield myWord;
|
||||
}
|
||||
27
test/fixtures/transformation/optional-self-contained/full/expected.js
vendored
Normal file
27
test/fixtures/transformation/optional-self-contained/full/expected.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Runtime = require("6to5-runtime/helpers");
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
var giveWord = _regeneratorRuntime.mark(function giveWord() {
|
||||
return _regeneratorRuntime.wrap(function giveWord$(context$1$0) {
|
||||
while (1) switch (context$1$0.prev = context$1$0.next) {
|
||||
case 0:
|
||||
context$1$0.next = 2;
|
||||
return myWord;
|
||||
case 2:
|
||||
case "end":
|
||||
return context$1$0.stop();
|
||||
}
|
||||
}, giveWord, this);
|
||||
});
|
||||
|
||||
exports.giveWord = giveWord;
|
||||
var foo = _to5Runtime.interopRequire(require("someModule"));
|
||||
|
||||
var bar = _to5Runtime.interopRequireWildcard(require("someModule"));
|
||||
|
||||
var myWord = exports.myWord = _core.Symbol("abc");
|
||||
4
test/fixtures/transformation/optional-self-contained/options.json
vendored
Normal file
4
test/fixtures/transformation/optional-self-contained/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"optional": ["selfContained"],
|
||||
"experimental": true
|
||||
}
|
||||
2
test/fixtures/transformation/optional-self-contained/regenerator-runtime/actual.js
vendored
Normal file
2
test/fixtures/transformation/optional-self-contained/regenerator-runtime/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
void function* () {
|
||||
};
|
||||
17
test/fixtures/transformation/optional-self-contained/regenerator-runtime/expected.js
vendored
Normal file
17
test/fixtures/transformation/optional-self-contained/regenerator-runtime/expected.js
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Runtime = require("6to5-runtime/helpers");
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
void _regeneratorRuntime.mark(function callee$0$0() {
|
||||
return _regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
|
||||
while (1) switch (context$1$0.prev = context$1$0.next) {
|
||||
case 0:
|
||||
case "end":
|
||||
return context$1$0.stop();
|
||||
}
|
||||
}, callee$0$0, this);
|
||||
});
|
||||
1
test/fixtures/transformation/optional-self-contained/runtime-amd/actual.js
vendored
Normal file
1
test/fixtures/transformation/optional-self-contained/runtime-amd/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
import foo from "someModule";
|
||||
5
test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js
vendored
Normal file
5
test/fixtures/transformation/optional-self-contained/runtime-amd/expected.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
define(["exports", "6to5-runtime/helpers", "6to5-runtime/core-js", "6to5-runtime/regenerator", "someModule"], function (exports, _to5Runtime, _core, _regeneratorRuntime, _someModule) {
|
||||
"use strict";
|
||||
|
||||
var foo = _to5Runtime.interopRequire(_someModule);
|
||||
});
|
||||
3
test/fixtures/transformation/optional-self-contained/runtime-amd/options.json
vendored
Normal file
3
test/fixtures/transformation/optional-self-contained/runtime-amd/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"modules": "amd"
|
||||
}
|
||||
1
test/fixtures/transformation/optional-self-contained/runtime-commonjs/actual.js
vendored
Normal file
1
test/fixtures/transformation/optional-self-contained/runtime-commonjs/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
import * as foo from "someModule";
|
||||
9
test/fixtures/transformation/optional-self-contained/runtime-commonjs/expected.js
vendored
Normal file
9
test/fixtures/transformation/optional-self-contained/runtime-commonjs/expected.js
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Runtime = require("6to5-runtime/helpers");
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
var foo = _to5Runtime.interopRequireWildcard(require("someModule"));
|
||||
Loading…
x
Reference in New Issue
Block a user