use default property on 6to5-runtime modules - fixes #774
This commit is contained in:
@@ -18,9 +18,10 @@ var each = require("lodash/collection/each");
|
||||
var t = require("../types");
|
||||
|
||||
function File(opts) {
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
this.dynamicImportedNoDefault = [];
|
||||
this.dynamicImportIds = {};
|
||||
this.dynamicImported = [];
|
||||
this.dynamicImports = [];
|
||||
|
||||
this.dynamicData = {};
|
||||
this.data = {};
|
||||
@@ -273,7 +274,7 @@ File.prototype.get = function (key) {
|
||||
}
|
||||
};
|
||||
|
||||
File.prototype.addImport = function (source, name) {
|
||||
File.prototype.addImport = function (source, name, noDefault) {
|
||||
name = name || source;
|
||||
var id = this.dynamicImportIds[name];
|
||||
|
||||
@@ -283,7 +284,9 @@ File.prototype.addImport = function (source, name) {
|
||||
var specifiers = [t.importSpecifier(t.identifier("default"), id)];
|
||||
var declar = t.importDeclaration(specifiers, t.literal(source));
|
||||
declar._blockHoist = 3;
|
||||
|
||||
this.dynamicImported.push(declar);
|
||||
if (noDefault) this.dynamicImportedNoDefault.push(declar);
|
||||
|
||||
this.moduleFormatter.importSpecifier(specifiers[0], declar, this.dynamicImports);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ module.exports = AMDFormatter;
|
||||
|
||||
var DefaultFormatter = require("./_default");
|
||||
var CommonFormatter = require("./common");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var includes = require("lodash/collection/includes");
|
||||
var values = require("lodash/object/values");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
|
||||
function AMDFormatter() {
|
||||
CommonFormatter.apply(this, arguments);
|
||||
@@ -81,12 +81,12 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
|
||||
var key = t.getSpecifierName(specifier);
|
||||
var ref = this.getExternalReference(node);
|
||||
|
||||
if (includes(this.file.dynamicImported, node)) {
|
||||
if (includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
// Prevent unnecessary renaming of dynamic imports.
|
||||
this.ids[node.source.value] = ref;
|
||||
} else if (t.isImportBatchSpecifier(specifier)) {
|
||||
// import * as bar from "foo";
|
||||
} else if (t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
} else if (!includes(this.file.dynamicImported, node) && t.isSpecifierDefault(specifier) && !this.noInteropRequireImport) {
|
||||
// import foo from "foo";
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
} else {
|
||||
|
||||
@@ -31,8 +31,8 @@ CommonJSFormatter.prototype.importSpecifier = function (specifier, node, nodes)
|
||||
|
||||
// import foo from "foo";
|
||||
if (t.isSpecifierDefault(specifier)) {
|
||||
if (!includes(this.file.dynamicImported, node)) {
|
||||
if (this.noInteropRequireImport) {
|
||||
if (!includes(this.file.dynamicImportedNoDefault, node)) {
|
||||
if (this.noInteropRequireImport || includes(this.file.dynamicImported, node)) {
|
||||
ref = t.memberExpression(ref, t.identifier("default"));
|
||||
} else {
|
||||
ref = t.callExpression(this.file.addHelper("interop-require"), [ref]);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
var helpers = exports.default = {};
|
||||
exports.__esModule = true;
|
||||
@@ -55,6 +55,8 @@ Transformer.prototype.normalize = function (transformer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === "enter" || type === "exit") return;
|
||||
|
||||
if (isFunction(fns)) fns = { enter: fns };
|
||||
|
||||
if (!isObject(fns)) return;
|
||||
|
||||
@@ -86,11 +86,12 @@ module.exports = {
|
||||
_declarations: require("./internal/declarations"),
|
||||
|
||||
_aliasFunctions: require("./internal/alias-functions"),
|
||||
_moduleFormatter: require("./internal/module-formatter"),
|
||||
|
||||
"spec.typeofSymbol": require("./spec/typeof-symbol"),
|
||||
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
|
||||
|
||||
_moduleFormatter: require("./internal/module-formatter"),
|
||||
|
||||
"es3.propertyLiterals": require("./es3/property-literals"),
|
||||
"es3.memberExpressionLiterals": require("./es3/member-expression-literals"),
|
||||
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
|
||||
exports.post = function (file) {
|
||||
exports.Program = function (program, parent, scope, file) {
|
||||
if (!file.transformers["es6.modules"].canRun()) return;
|
||||
|
||||
var program = file.ast.program;
|
||||
|
||||
useStrict.wrap(program, function () {
|
||||
program.body = file.dynamicImports.concat(program.body);
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ exports.Function = function (node, parent, scope, file) {
|
||||
|
||||
return remapAsyncToGenerator(
|
||||
node,
|
||||
t.memberExpression(file.addImport("bluebird"), t.identifier("coroutine")),
|
||||
t.memberExpression(file.addImport("bluebird", null, true), t.identifier("coroutine")),
|
||||
scope
|
||||
);
|
||||
};
|
||||
|
||||
@@ -78,8 +78,8 @@ exports.manipulateOptions = function (opts) {
|
||||
if (opts.whitelist.length) opts.whitelist.push("es6.modules");
|
||||
};
|
||||
|
||||
exports.post = function (file) {
|
||||
file.scope.traverse(file.ast, astVisitor, file);
|
||||
exports.Program = function (node, parent, scope, file) {
|
||||
scope.traverse(node, astVisitor, file);
|
||||
};
|
||||
|
||||
exports.pre = function (file) {
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
var useStrict = require("../../helpers/use-strict");
|
||||
var t = require("../../../types");
|
||||
|
||||
exports.post = function (file) {
|
||||
var program = file.ast.program;
|
||||
exports.Program = function (program) {
|
||||
if (!useStrict.has(program)) {
|
||||
program.body.unshift(t.expressionStatement(t.literal("use strict")));
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ TraversalPath.prototype.call = function (key) {
|
||||
if (!node) return;
|
||||
|
||||
var opts = this.opts;
|
||||
var fn = opts[key];
|
||||
var fn = opts[key] || opts;
|
||||
if (opts[node.type]) fn = opts[node.type][key] || fn;
|
||||
|
||||
var replacement = fn.call(this, node, this.parent, this.scope, this.state);
|
||||
|
||||
@@ -109,6 +109,8 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
traverse(template, templateVisitor, null, nodes);
|
||||
}
|
||||
|
||||
if (template.body.length > 1) return template.body;
|
||||
|
||||
var node = template.body[0];
|
||||
|
||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
var buildHelpers = require("../lib/6to5/build-helpers");
|
||||
var transform = require("../lib/6to5/transformation");
|
||||
var util = require("../lib/6to5/util");
|
||||
var fs = require("fs");
|
||||
var t = require("../lib/6to5/types");
|
||||
var _ = require("lodash");
|
||||
@@ -16,8 +17,14 @@ var writeFile = function (filename, content) {
|
||||
fs.writeFileSync(filename, content);
|
||||
};
|
||||
|
||||
var readFile = function (filename) {
|
||||
return fs.readFileSync(require.resolve(filename), "utf8");
|
||||
var readFile = function (filename, defaultify) {
|
||||
var file = fs.readFileSync(require.resolve(filename), "utf8");
|
||||
|
||||
if (defaultify) {
|
||||
file += '\nmodule.exports = { "default": module.exports, __esModule: true };\n';
|
||||
}
|
||||
|
||||
return file;
|
||||
};
|
||||
|
||||
var updatePackage = function () {
|
||||
@@ -37,10 +44,10 @@ var selfContainify = function (code) {
|
||||
};
|
||||
|
||||
var buildHelpers2 = function () {
|
||||
var body = [];
|
||||
var body = util.template("self-contained-helpers-head");
|
||||
var tree = t.program(body);
|
||||
|
||||
buildHelpers(body, t.identifier("exports"));
|
||||
buildHelpers(body, t.identifier("helpers"));
|
||||
|
||||
return transform.fromAst(tree, null, {
|
||||
optional: ["selfContained"]
|
||||
@@ -48,7 +55,7 @@ var buildHelpers2 = function () {
|
||||
};
|
||||
|
||||
writeFile("helpers.js", buildHelpers2());
|
||||
writeFile("core-js.js", readFile("core-js/library"));
|
||||
writeFile("regenerator/index.js", readFile("regenerator-6to5/runtime-module"));
|
||||
writeFile("core-js.js", readFile("core-js/library", true));
|
||||
writeFile("regenerator/index.js", readFile("regenerator-6to5/runtime-module", true));
|
||||
writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator-6to5/runtime")));
|
||||
updatePackage();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
obj.constructor === Object;
|
||||
obj.constructor === _core.Promise;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
for (var _iterator = _core.$for.getIterator(arr), _step; !(_step = _iterator.next()).done;) {
|
||||
var i = _step.value;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
var arr = (function () {
|
||||
var _arr = [];
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
var _to5Helpers = require("6to5-runtime/helpers");
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator")["default"];
|
||||
var _to5Helpers = require("6to5-runtime/helpers")["default"];
|
||||
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) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
define(["exports", "foo", "6to5-runtime/helpers"], function (exports, _foo, _to5RuntimeHelpers) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = _to5RuntimeHelpers;
|
||||
var _to5Helpers = _to5RuntimeHelpers["default"];
|
||||
var foo = _to5Helpers.interopRequire(_foo);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = require("6to5-runtime/helpers");
|
||||
|
||||
var foo = _to5Helpers.interopRequire(require("foo"));
|
||||
var _to5Helpers = require("6to5-runtime/helpers")["default"];
|
||||
var foo = _to5Helpers.interopRequire(require("foo"));
|
||||
|
||||
@@ -4,10 +4,10 @@ System.register(["6to5-runtime/helpers"], function (_export) {
|
||||
var _to5Helpers;
|
||||
return {
|
||||
setters: [function (_to5RuntimeHelpers) {
|
||||
_to5Helpers = _to5RuntimeHelpers;
|
||||
_to5Helpers = _to5RuntimeHelpers["default"];
|
||||
}],
|
||||
execute: function () {
|
||||
foo.apply(undefined, _to5Helpers.toConsumableArray(bar));
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,6 @@
|
||||
})(function (exports, _foo, _to5RuntimeHelpers) {
|
||||
"use strict";
|
||||
|
||||
var _to5Helpers = _to5RuntimeHelpers;
|
||||
var _to5Helpers = _to5RuntimeHelpers["default"];
|
||||
var foo = _to5Helpers.interopRequire(_foo);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator");
|
||||
|
||||
var _regeneratorRuntime = require("6to5-runtime/regenerator")["default"];
|
||||
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) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"use strict";
|
||||
|
||||
var _core = require("6to5-runtime/core-js");
|
||||
|
||||
var _core = require("6to5-runtime/core-js")["default"];
|
||||
_core.$for.isIterable(Object(arr));
|
||||
|
||||
Reference in New Issue
Block a user