Merge branch 'external-runtime' into scoped-es6-runtime
This commit is contained in:
commit
061bbe0409
@ -87,7 +87,7 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
|||||||
var key = t.getSpecifierName(specifier);
|
var key = t.getSpecifierName(specifier);
|
||||||
var ref = this._push(node);
|
var ref = this._push(node);
|
||||||
|
|
||||||
if (t.isImportBatchSpecifier(specifier)) {
|
if (t.isImportBatchSpecifier(specifier) || _.contains(this.file.dynamicImports, node)) {
|
||||||
// import * as bar from "foo";
|
// import * as bar from "foo";
|
||||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
|
||||||
// import foo from "foo";
|
// import foo from "foo";
|
||||||
|
|||||||
@ -6,6 +6,7 @@ var DefaultFormatter = require("./_default");
|
|||||||
var traverse = require("../../traverse");
|
var traverse = require("../../traverse");
|
||||||
var util = require("../../util");
|
var util = require("../../util");
|
||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
|
var _ = require("lodash");
|
||||||
|
|
||||||
function CommonJSFormatter(file) {
|
function CommonJSFormatter(file) {
|
||||||
DefaultFormatter.apply(this, arguments);
|
DefaultFormatter.apply(this, arguments);
|
||||||
@ -26,13 +27,11 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
|||||||
|
|
||||||
// import foo from "foo";
|
// import foo from "foo";
|
||||||
if (t.isSpecifierDefault(specifier)) {
|
if (t.isSpecifierDefault(specifier)) {
|
||||||
nodes.push(t.variableDeclaration("var", [
|
var ref = util.template("require", {MODULE_NAME: node.source});
|
||||||
t.variableDeclarator(variableName,
|
if (!_.contains(this.file.dynamicImports, node)) {
|
||||||
t.callExpression(this.file.addHelper("interop-require"), [util.template("require", {
|
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||||
MODULE_NAME: node.source
|
}
|
||||||
})])
|
nodes.push(t.variableDeclaration("var", [t.variableDeclarator(variableName, ref)]));
|
||||||
)
|
|
||||||
]));
|
|
||||||
} else {
|
} else {
|
||||||
if (specifier.type === "ImportBatchSpecifier") {
|
if (specifier.type === "ImportBatchSpecifier") {
|
||||||
// import * as bar from "foo";
|
// import * as bar from "foo";
|
||||||
|
|||||||
@ -95,6 +95,7 @@ _.each({
|
|||||||
_moduleFormatter: require("./transformers/_module-formatter"),
|
_moduleFormatter: require("./transformers/_module-formatter"),
|
||||||
|
|
||||||
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
typeofSymbol: require("./transformers/optional-typeof-symbol"),
|
||||||
|
externalRuntime: require("./transformers/optional-external-runtime"),
|
||||||
coreAliasing: require("./transformers/optional-core-aliasing"),
|
coreAliasing: require("./transformers/optional-core-aliasing"),
|
||||||
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
undefinedToVoid: require("./transformers/optional-undefined-to-void"),
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
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(file.opts.runtime, "to5Runtime").name;
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -1,10 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
var _bluebird = require("bluebird");
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _bluebird = _interopRequire(require("bluebird"));
|
|
||||||
|
|
||||||
var foo = _bluebird.coroutine(function* () {
|
var foo = _bluebird.coroutine(function* () {
|
||||||
var wat = yield bar();
|
var wat = yield bar();
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
var _bluebird = require("bluebird");
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _bluebird = _interopRequire(require("bluebird"));
|
|
||||||
|
|
||||||
var foo = _bluebird.coroutine(function* foo() {
|
var foo = _bluebird.coroutine(function* foo() {
|
||||||
var wat = yield bar();
|
var wat = yield bar();
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
var _core = require("core-js/library");
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _core = _interopRequire(require("core-js/library"));
|
|
||||||
|
|
||||||
obj.constructor === Object;
|
obj.constructor === Object;
|
||||||
obj.constructor === _core.Promise;
|
obj.constructor === _core.Promise;
|
||||||
|
|||||||
@ -16,11 +16,7 @@ var _slicedToArray = function (arr, i) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
var _core = require("core-js/library");
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _core = _interopRequire(require("core-js/library"));
|
|
||||||
|
|
||||||
var _ref = ["hello", [", ", "junk"], ["world"]];
|
var _ref = ["hello", [", ", "junk"], ["world"]];
|
||||||
|
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
var _core = require("core-js/library");
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _core = _interopRequire(require("core-js/library"));
|
|
||||||
|
|
||||||
for (var _iterator = _core.$for.getIterator(arr), _step; !(_step = _iterator.next()).done;) {
|
for (var _iterator = _core.$for.getIterator(arr), _step; !(_step = _iterator.next()).done;) {
|
||||||
var i = _step.value;
|
var i = _step.value;
|
||||||
|
|||||||
@ -4,10 +4,6 @@ var _toArray = function (arr) {
|
|||||||
return Array.isArray(arr) ? arr : _core.Array.from(arr);
|
return Array.isArray(arr) ? arr : _core.Array.from(arr);
|
||||||
};
|
};
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
var _core = require("core-js/library");
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _core = _interopRequire(require("core-js/library"));
|
|
||||||
|
|
||||||
var lyrics = ["head", "and", "toes"].concat(_toArray(parts));
|
var lyrics = ["head", "and", "toes"].concat(_toArray(parts));
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _interopRequire = function (obj) {
|
var _core = require("core-js/library");
|
||||||
return obj && (obj["default"] || obj);
|
|
||||||
};
|
|
||||||
|
|
||||||
var _core = _interopRequire(require("core-js/library"));
|
|
||||||
|
|
||||||
var arr = (function () {
|
var arr = (function () {
|
||||||
var _arr = [];
|
var _arr = [];
|
||||||
|
|||||||
1
test/fixtures/transformation/optional-external-runtime/amd/actual.js
vendored
Normal file
1
test/fixtures/transformation/optional-external-runtime/amd/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import foo from "someModule";
|
||||||
6
test/fixtures/transformation/optional-external-runtime/amd/expected.js
vendored
Normal file
6
test/fixtures/transformation/optional-external-runtime/amd/expected.js
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
define(["exports", "6to5-runtime", "someModule"], function (exports, _to5Runtime2, _someModule) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var _to5Runtime = _to5Runtime2;
|
||||||
|
var foo = _to5Runtime.interopRequire(_someModule);
|
||||||
|
});
|
||||||
3
test/fixtures/transformation/optional-external-runtime/amd/options.json
vendored
Normal file
3
test/fixtures/transformation/optional-external-runtime/amd/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"modules": "amd"
|
||||||
|
}
|
||||||
1
test/fixtures/transformation/optional-external-runtime/commonjs/actual.js
vendored
Normal file
1
test/fixtures/transformation/optional-external-runtime/commonjs/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import * as foo from "someModule";
|
||||||
5
test/fixtures/transformation/optional-external-runtime/commonjs/expected.js
vendored
Normal file
5
test/fixtures/transformation/optional-external-runtime/commonjs/expected.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var _to5Runtime = require("6to5-runtime");
|
||||||
|
|
||||||
|
var foo = _to5Runtime.interopRequireWildcard(require("someModule"));
|
||||||
4
test/fixtures/transformation/optional-external-runtime/options.json
vendored
Normal file
4
test/fixtures/transformation/optional-external-runtime/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"runtime": "6to5-runtime",
|
||||||
|
"optional": ["externalRuntime"]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user