Skip to content

Commit

Permalink
Revert "Allow options.generateLegacyModuleImport to force legacy modu…
Browse files Browse the repository at this point in the history
…le.import."

This reverts commit 420b463.

I managed to fix the motivating problem in a different way:
meteor/meteor@ac5131d

Closes standard-things#116.
  • Loading branch information
benjamn committed Apr 7, 2017
1 parent 7e8e940 commit 6bf5564
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 34 deletions.
18 changes: 5 additions & 13 deletions lib/import-export-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ IEVp.reset = function (rootPath, codeOrNull, options) {
this.modifyAST = !! getOption(options, "ast");
this.parse = getOption(options, "parse");
this.nextKey = 0;
this.importMethod = getOption(options, "generateLegacyModuleImport")
? "import" : "importSync";

return this;
};
Expand Down Expand Up @@ -408,8 +406,7 @@ IEVp.visitImportDeclaration = function (path) {
parts.push(toModuleImport(
this._getSourceString(decl),
computeSpecifierMap(decl.specifiers),
this.makeUniqueKey(),
this.importMethod
this.makeUniqueKey()
));

this.hoistImports(path, parts.join(""));
Expand All @@ -420,11 +417,7 @@ IEVp.visitImportDeclaration = function (path) {
IEVp.visitExportAllDeclaration = function (path) {
const decl = path.getValue();
const parts = [
this.pad(
"module." + this.importMethod + "(",
decl.start,
decl.source.start
),
this.pad("module.importSync(", decl.start, decl.source.start),
this._getSourceString(decl),
this.pad(
",{'*':(v,k)=>{exports[k]=v;}}," +
Expand Down Expand Up @@ -567,8 +560,7 @@ IEVp.visitExportNamedDeclaration = function (path) {
this.hoistExports(path, toModuleImport(
this._getSourceString(decl),
specifierMap,
this.makeUniqueKey(),
this.importMethod
this.makeUniqueKey()
));

} else {
Expand Down Expand Up @@ -671,8 +663,8 @@ function addToSpecifierMap(map, __ported, local) {
return map;
}

function toModuleImport(source, specifierMap, uniqueKey, importMethod) {
const parts = ["module.", importMethod, "(", source];
function toModuleImport(source, specifierMap, uniqueKey) {
const parts = ["module.importSync(", source];
const importedNames = specifierMap ? Object.keys(specifierMap) : null;
const nameCount = importedNames ? importedNames.length : 0;

Expand Down
1 change: 0 additions & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const defaultCompileOptions = {
ast: false,
force: false,
generateLetDeclarations: false,
generateLegacyModuleImport: false,
get parse () {
return require("./parsers/default.js").parse;
}
Expand Down
20 changes: 0 additions & 20 deletions test/compiler-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,6 @@ describe("compiler", function () {
).code.indexOf("var foo;"), 0);
});

it("should respect options.generateLegacyModuleImport", function () {
import { compile } from "../lib/compiler.js";

function check(code) {
var legacy = compile(code, {
generateLegacyModuleImport: true
}).code;
assert.notStrictEqual(legacy.indexOf("module.import("), -1);
}

check('import foo from "./foo"');
check('import { a, b as c } from "./foo"');
check('import * as ns from "./foo"');
check('import "./foo"');

// These exports are really imports behind the scenes.
check('export { a, b as c } from "./foo"');
check('export * from "./foo"');
});

it("should allow pre-parsed ASTs via options.parse", function () {
import { compile } from "../lib/compiler.js";
import { parse } from "../lib/parsers/default.js";
Expand Down

0 comments on commit 6bf5564

Please sign in to comment.