diff --git a/acorn.js b/acorn.js
index 60ee4c4f68..86a7762344 100644
--- a/acorn.js
+++ b/acorn.js
@@ -287,8 +287,7 @@
var _while = {keyword: "while", isLoop: true}, _with = {keyword: "with"}, _new = {keyword: "new", beforeExpr: true};
var _this = {keyword: "this"};
var _class = {keyword: "class"}, _extends = {keyword: "extends", beforeExpr: true}, _static = {keyword: "static"};
- var _module = {keyword: "module"}, _export = {keyword: "export"};
- var _import = {keyword: "import"}, _from = {keyword: "from"}, _as = {keyword: "as"};
+ var _export = {keyword: "export"}, _import = {keyword: "import"}, _from = {keyword: "from"}, _as = {keyword: "as"};
// The keywords that denote values.
@@ -316,8 +315,7 @@
"void": {keyword: "void", prefix: true, beforeExpr: true},
"delete": {keyword: "delete", prefix: true, beforeExpr: true},
"class": _class, "extends": _extends, "static": _static, "of": _of,
- "module": _module, "export": _export, "import": _import,
- "from": _from, "as": _as};
+ "export": _export, "import": _import, "from": _from, "as": _as};
// Punctuation token types. Again, the `type` property is purely for debugging.
@@ -436,7 +434,7 @@
var isEcma5AndLessKeyword = makePredicate(ecma5AndLessKeywords);
- var isEcma6Keyword = makePredicate(ecma5AndLessKeywords + " let const class extends static of module export import from as");
+ var isEcma6Keyword = makePredicate(ecma5AndLessKeywords + " let const class extends static of export import from as");
var isKeyword = isEcma5AndLessKeyword;
@@ -1254,6 +1252,7 @@
case _braceL: return parseBlock(); // no point creating a function for this
case _semi: return parseEmptyStatement(node);
case _export: return parseExport(node);
+ case _import: return parseImport(node);
// If the statement does not start with a statement keyword or a
// brace, it's an ExpressionStatement or LabeledStatement. We
@@ -2178,41 +2177,108 @@
function parseExport(node) {
next();
+ // export var|const|let|function|class ...;
if (tokType === _var || tokType === _const || tokType === _let || tokType === _function || tokType === _class) {
node.declaration = parseStatement();
node.default = false;
node.specifiers = null;
node.source = null;
} else
+ // export default ...;
if (eat(_default)) {
node.declaration = parseExpression(true);
node.default = true;
node.specifiers = null;
node.source = null;
semicolon();
- } else
- if (tokVal === '*') {
+ } else {
+ // export * from '...'
+ // export { x, y as z } [from '...']
+ var isBatch = tokVal === '*';
node.declaration = null;
node.default = false;
- var specifier = startNode();
- next();
- node.specifiers = [finishNode(specifier, "ExportBatchSpecifier")];
- expect(_from);
- node.source = tokType === _string ? parseExprAtom() : unexpected();
- } else
- if (eat(_braceL)) {
- node.declaration = null;
- node.default = false;
- node.specifiers = parseModuleSpecifiers("ExportSpecifier");
- node.source = eat(_from) ? (tokType === _string ? parseExprAtom() : unexpected()) : null;
- } else unexpected();
+ node.specifiers = parseExportSpecifiers();
+ if (isBatch || tokType === _from) {
+ expect(_from);
+ node.source = tokType === _string ? parseExprAtom() : unexpected();
+ } else {
+ node.source = null;
+ }
+ }
return finishNode(node, "ExportDeclaration");
}
- // Parses a comma-separated list of module imports/exports.
+ // Parses a comma-separated list of module exports.
- function parseModuleSpecifiers(type) {
+ function parseExportSpecifiers() {
var nodes = [], first = true;
+ if (tokVal === "*") {
+ // export * from '...'
+ var node = startNode();
+ next();
+ nodes.push(finishNode(node, "ExportBatchSpecifier"));
+ } else {
+ // export { x, y as z } [from '...']
+ expect(_braceL);
+ while (!eat(_braceR)) {
+ if (!first) {
+ expect(_comma);
+ if (options.allowTrailingCommas && eat(_braceR)) break;
+ } else first = false;
+
+ var node = startNode();
+ node.id = parseIdent();
+ node.name = eat(_as) ? parseIdent(true) : null;
+ nodes.push(finishNode(node, "ExportSpecifier"));
+ }
+ }
+ return nodes;
+ }
+
+ // Parses import declaration.
+
+ function parseImport(node) {
+ next();
+ // import '...';
+ if (tokType === _string) {
+ node.specifiers = [];
+ node.source = parseExprAtom();
+ node.kind = "";
+ } else {
+ node.specifiers = parseImportSpecifiers();
+ expect(_from);
+ node.source = tokType === _string ? parseExprAtom() : unexpected();
+ // only for backward compatibility with Esprima's AST
+ // (it doesn't support mixed default + named yet)
+ node.kind = node.specifiers[0].default ? "default" : "named";
+ }
+ return finishNode(node, "ImportDeclaration");
+ }
+
+ // Parses a comma-separated list of module imports.
+
+ function parseImportSpecifiers() {
+ var nodes = [], first = true;
+ if (tokVal === '*') {
+ var node = startNode();
+ next();
+ expect(_as);
+ node.name = parseIdent();
+ checkLVal(node.name, true);
+ nodes.push(finishNode(node, "ImportBatchSpecifier"));
+ return nodes;
+ }
+ if (tokType === _name) {
+ // import defaultObj, { x, y as z } from '...'
+ var node = startNode();
+ node.id = parseIdent();
+ checkLVal(node.id, true);
+ node.name = null;
+ node.default = true;
+ nodes.push(finishNode(node, "ImportSpecifier"));
+ if (!eat(_comma)) return nodes;
+ }
+ expect(_braceL);
while (!eat(_braceR)) {
if (!first) {
expect(_comma);
@@ -2220,9 +2286,11 @@
} else first = false;
var node = startNode();
- node.id = parseIdent();
- node.name = eat(_as) ? parseIdent(true) : null;
- nodes.push(finishNode(node, type));
+ node.id = parseIdent(true);
+ node.name = eat(_as) ? parseIdent() : null;
+ checkLVal(node.name || node.id, true);
+ node.default = false;
+ nodes.push(finishNode(node, "ImportSpecifier"));
}
return nodes;
}
diff --git a/index.html b/index.html
index 72770c4329..6a06009c50 100644
--- a/index.html
+++ b/index.html
@@ -179,8 +179,7 @@ continue jumps to that label.
| import defaultObj, { x, y as z } from '...' | var node = startNode();
+ node.id = parseIdent();
+ checkLVal(node.id, true);
+ node.name = null;
+ node.default = true;
+ nodes.push(finishNode(node, "ImportSpecifier"));
+ if (!eat(_comma)) return nodes;
+ }
+ expect(_braceL);
while (!eat(_braceR)) {
if (!first) {
expect(_comma);
@@ -1729,9 +1771,11 @@ if possible. | <
} else first = false;
var node = startNode();
- node.id = parseIdent();
- node.name = eat(_as) ? parseIdent(true) : null;
- nodes.push(finishNode(node, type));
+ node.id = parseIdent(true);
+ node.name = eat(_as) ? parseIdent() : null;
+ checkLVal(node.name || node.id, true);
+ node.default = false;
+ nodes.push(finishNode(node, "ImportSpecifier"));
}
return nodes;
}
diff --git a/test/tests-harmony.js b/test/tests-harmony.js
index eed92440bd..ac98e2734c 100644
--- a/test/tests-harmony.js
+++ b/test/tests-harmony.js
@@ -4811,129 +4811,6 @@ test("var {a:b} = {}", {
// Harmony: Modules
-test("module \"crypto\" {}", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "crypto",
- raw: "\"crypto\"",
- range: [7, 15],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 15}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [],
- range: [16, 18],
- loc: {
- start: {line: 1, column: 16},
- end: {line: 1, column: 18}
- }
- },
- range: [0, 18],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 18}
- }
- }],
- range: [0, 18],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 18}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module crypto from \"crypto\";", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Identifier",
- name: "crypto",
- range: [7, 13],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 13}
- }
- },
- source: {
- type: "Literal",
- value: "crypto",
- raw: "\"crypto\"",
- range: [19, 27],
- loc: {
- start: {line: 1, column: 19},
- end: {line: 1, column: 27}
- }
- },
- body: null,
- range: [0, 28],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 28}
- }
- }],
- range: [0, 28],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 28}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"crypto/e\" {}", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "crypto/e",
- raw: "\"crypto/e\"",
- range: [7, 17],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 17}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [],
- range: [18, 20],
- loc: {
- start: {line: 1, column: 18},
- end: {line: 1, column: 20}
- }
- },
- range: [0, 20],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 20}
- }
- }],
- range: [0, 20],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 20}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
test("export var document", {
type: "Program",
body: [{
@@ -5615,950 +5492,6 @@ test("export { encrypt, decrypt as dec }", {
locations: true
});
-test("module \"lib\" { export var document }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: {
- type: "VariableDeclaration",
- declarations: [{
- type: "VariableDeclarator",
- id: {
- type: "Identifier",
- name: "document",
- range: [26, 34],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 34}
- }
- },
- init: null,
- range: [26, 34],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 34}
- }
- }],
- kind: "var",
- range: [22, 35],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 35}
- }
- },
- specifiers: null,
- source: null,
- range: [15, 35],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 35}
- }
- }],
- range: [13, 36],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 36}
- }
- },
- range: [0, 36],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 36}
- }
- }],
- range: [0, 36],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 36}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"lib\" { export var document = { } }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: {
- type: "VariableDeclaration",
- declarations: [{
- type: "VariableDeclarator",
- id: {
- type: "Identifier",
- name: "document",
- range: [26, 34],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 34}
- }
- },
- init: {
- type: "ObjectExpression",
- properties: [],
- range: [37, 40],
- loc: {
- start: {line: 1, column: 37},
- end: {line: 1, column: 40}
- }
- },
- range: [26, 40],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 40}
- }
- }],
- kind: "var",
- range: [22, 41],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 41}
- }
- },
- specifiers: null,
- source: null,
- range: [15, 41],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 41}
- }
- }],
- range: [13, 42],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 42}
- }
- },
- range: [0, 42],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 42}
- }
- }],
- range: [0, 42],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 42}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"lib\" { export let document }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: {
- type: "VariableDeclaration",
- declarations: [{
- type: "VariableDeclarator",
- id: {
- type: "Identifier",
- name: "document",
- range: [26, 34],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 34}
- }
- },
- init: null,
- range: [26, 34],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 34}
- }
- }],
- kind: "let",
- range: [22, 35],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 35}
- }
- },
- specifiers: null,
- source: null,
- range: [15, 35],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 35}
- }
- }],
- range: [13, 36],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 36}
- }
- },
- range: [0, 36],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 36}
- }
- }],
- range: [0, 36],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 36}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"lib\" { export let document = { } }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: {
- type: "VariableDeclaration",
- declarations: [{
- type: "VariableDeclarator",
- id: {
- type: "Identifier",
- name: "document",
- range: [26, 34],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 34}
- }
- },
- init: {
- type: "ObjectExpression",
- properties: [],
- range: [37, 40],
- loc: {
- start: {line: 1, column: 37},
- end: {line: 1, column: 40}
- }
- },
- range: [26, 40],
- loc: {
- start: {line: 1, column: 26},
- end: {line: 1, column: 40}
- }
- }],
- kind: "let",
- range: [22, 41],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 41}
- }
- },
- specifiers: null,
- source: null,
- range: [15, 41],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 41}
- }
- }],
- range: [13, 42],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 42}
- }
- },
- range: [0, 42],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 42}
- }
- }],
- range: [0, 42],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 42}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"lib\" { export const document = { } }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: {
- type: "VariableDeclaration",
- declarations: [{
- type: "VariableDeclarator",
- id: {
- type: "Identifier",
- name: "document",
- range: [28, 36],
- loc: {
- start: {line: 1, column: 28},
- end: {line: 1, column: 36}
- }
- },
- init: {
- type: "ObjectExpression",
- properties: [],
- range: [39, 42],
- loc: {
- start: {line: 1, column: 39},
- end: {line: 1, column: 42}
- }
- },
- range: [28, 42],
- loc: {
- start: {line: 1, column: 28},
- end: {line: 1, column: 42}
- }
- }],
- kind: "const",
- range: [22, 43],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 43}
- }
- },
- specifiers: null,
- source: null,
- range: [15, 43],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 43}
- }
- }],
- range: [13, 44],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 44}
- }
- },
- range: [0, 44],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 44}
- }
- }],
- range: [0, 44],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 44}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"lib\" { export function parse() { } }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: {
- type: "FunctionDeclaration",
- id: {
- type: "Identifier",
- name: "parse",
- range: [31, 36],
- loc: {
- start: {line: 1, column: 31},
- end: {line: 1, column: 36}
- }
- },
- params: [],
- defaults: [],
- body: {
- type: "BlockStatement",
- body: [],
- range: [39, 42],
- loc: {
- start: {line: 1, column: 39},
- end: {line: 1, column: 42}
- }
- },
- rest: null,
- generator: false,
- expression: false,
- range: [22, 42],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 42}
- }
- },
- specifiers: null,
- source: null,
- range: [15, 42],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 42}
- }
- }],
- range: [13, 44],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 44}
- }
- },
- range: [0, 44],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 44}
- }
- }],
- range: [0, 44],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 44}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"lib\" { export class Class {} }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: {
- type: "ClassDeclaration",
- id: {
- type: "Identifier",
- name: "Class",
- range: [28, 33],
- loc: {
- start: {line: 1, column: 28},
- end: {line: 1, column: 33}
- }
- },
- superClass: null,
- body: {
- type: "ClassBody",
- body: [],
- range: [34, 36],
- loc: {
- start: {line: 1, column: 34},
- end: {line: 1, column: 36}
- }
- },
- range: [22, 36],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 36}
- }
- },
- specifiers: null,
- source: null,
- range: [15, 36],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 36}
- }
- }],
- range: [13, 38],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 38}
- }
- },
- range: [0, 38],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 38}
- }
- }],
- range: [0, 38],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 38}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"lib\" { export * }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "lib",
- raw: "\"lib\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: null,
- specifiers: [{
- type: "ExportBatchSpecifier",
- range: [22, 23],
- loc: {
- start: {line: 1, column: 22},
- end: {line: 1, column: 23}
- }
- }],
- source: null,
- range: [15, 24],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 24}
- }
- }],
- range: [13, 25],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 25}
- }
- },
- range: [0, 25],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 25}
- }
- }],
- range: [0, 25],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 25}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"security\" { export * from \"crypto\" }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "security",
- raw: "\"security\"",
- range: [7, 17],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 17}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: null,
- specifiers: [{
- type: "ExportBatchSpecifier",
- range: [27, 28],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 28}
- }
- }],
- source: {
- type: "Literal",
- value: "crypto",
- raw: "\"crypto\"",
- range: [34, 42],
- loc: {
- start: {line: 1, column: 34},
- end: {line: 1, column: 42}
- }
- },
- range: [20, 43],
- loc: {
- start: {line: 1, column: 20},
- end: {line: 1, column: 43}
- }
- }],
- range: [18, 44],
- loc: {
- start: {line: 1, column: 18},
- end: {line: 1, column: 44}
- }
- },
- range: [0, 44],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 44}
- }
- }],
- range: [0, 44],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 44}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"crypto\" { export { encrypt } }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "crypto",
- raw: "\"crypto\"",
- range: [7, 15],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 15}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: null,
- specifiers: [{
- type: "ExportSpecifier",
- id: {
- type: "Identifier",
- name: "encrypt",
- range: [27, 34],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 34}
- }
- },
- name: null,
- range: [27, 34],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 34}
- }
- }],
- source: null,
- range: [18, 37],
- loc: {
- start: {line: 1, column: 18},
- end: {line: 1, column: 37}
- }
- }],
- range: [16, 38],
- loc: {
- start: {line: 1, column: 16},
- end: {line: 1, column: 38}
- }
- },
- range: [0, 38],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 38}
- }
- }],
- range: [0, 38],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 38}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"crypto\" { export { encrypt, decrypt } }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "crypto",
- raw: "\"crypto\"",
- range: [7, 15],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 15}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: null,
- specifiers: [
- {
- type: "ExportSpecifier",
- id: {
- type: "Identifier",
- name: "encrypt",
- range: [27, 34],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 34}
- }
- },
- name: null,
- range: [27, 34],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 34}
- }
- },
- {
- type: "ExportSpecifier",
- id: {
- type: "Identifier",
- name: "decrypt",
- range: [36, 43],
- loc: {
- start: {line: 1, column: 36},
- end: {line: 1, column: 43}
- }
- },
- name: null,
- range: [36, 43],
- loc: {
- start: {line: 1, column: 36},
- end: {line: 1, column: 43}
- }
- }
- ],
- source: null,
- range: [18, 46],
- loc: {
- start: {line: 1, column: 18},
- end: {line: 1, column: 46}
- }
- }],
- range: [16, 47],
- loc: {
- start: {line: 1, column: 16},
- end: {line: 1, column: 47}
- }
- },
- range: [0, 47],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 47}
- }
- }],
- range: [0, 47],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 47}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"crypto\" { export { encrypt, decrypt as dec } }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "crypto",
- raw: "\"crypto\"",
- range: [7, 15],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 15}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExportDeclaration",
- declaration: null,
- specifiers: [
- {
- type: "ExportSpecifier",
- id: {
- type: "Identifier",
- name: "encrypt",
- range: [27, 34],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 34}
- }
- },
- name: null,
- range: [27, 34],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 34}
- }
- },
- {
- type: "ExportSpecifier",
- id: {
- type: "Identifier",
- name: "decrypt",
- range: [36, 43],
- loc: {
- start: {line: 1, column: 36},
- end: {line: 1, column: 43}
- }
- },
- name: {
- type: "Identifier",
- name: "dec",
- range: [47, 50],
- loc: {
- start: {line: 1, column: 47},
- end: {line: 1, column: 50}
- }
- },
- range: [36, 50],
- loc: {
- start: {line: 1, column: 36},
- end: {line: 1, column: 50}
- }
- }
- ],
- source: null,
- range: [18, 53],
- loc: {
- start: {line: 1, column: 18},
- end: {line: 1, column: 53}
- }
- }],
- range: [16, 54],
- loc: {
- start: {line: 1, column: 16},
- end: {line: 1, column: 54}
- }
- },
- range: [0, 54],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 54}
- }
- }],
- range: [0, 54],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 54}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
test("import \"jquery\"", {
type: "Program",
body: [{
@@ -6847,55 +5780,7 @@ test("import { decrypt, encrypt as enc } from \"crypto\"", {
locations: true
});
-test("import default from \"foo\"", {
- type: "Program",
- body: [{
- type: "ImportDeclaration",
- specifiers: [{
- type: "ImportSpecifier",
- id: {
- type: "Identifier",
- name: "default",
- range: [7, 14],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 14}
- }
- },
- name: null,
- range: [7, 14],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 14}
- }
- }],
- kind: "default",
- source: {
- type: "Literal",
- value: "foo",
- raw: "\"foo\"",
- range: [20, 25],
- loc: {
- start: {line: 1, column: 20},
- end: {line: 1, column: 25}
- }
- },
- range: [0, 25],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 25}
- }
- }],
- range: [0, 25],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 25}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
+testFail("import default from \"foo\"", "Unexpected token (1:7)", {ecmaVersion: 6});
test("import { null as nil } from \"bar\"", {
type: "Program",
@@ -6955,164 +5840,59 @@ test("import { null as nil } from \"bar\"", {
locations: true
});
-test("module \"security\" { import \"cryto\" }", {
+test("import * as crypto from \"crypto\"", {
type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "security",
- raw: "\"security\"",
- range: [7, 17],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 17}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ImportDeclaration",
- specifiers: [],
- source: {
- type: "Literal",
- value: "cryto",
- raw: "\"cryto\"",
- range: [27, 34],
- loc: {
- start: {line: 1, column: 27},
- end: {line: 1, column: 34}
- }
- },
- range: [20, 35],
- loc: {
- start: {line: 1, column: 20},
- end: {line: 1, column: 35}
- }
- }],
- range: [18, 36],
- loc: {
- start: {line: 1, column: 18},
- end: {line: 1, column: 36}
- }
- },
- range: [0, 36],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 36}
- }
- }],
- range: [0, 36],
+ start: 0,
+ end: 32,
loc: {
start: {line: 1, column: 0},
- end: {line: 1, column: 36}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module()", {
- type: "Program",
+ end: {line: 1, column: 32}
+ },
+ range: [0, 32],
body: [{
- type: "ExpressionStatement",
- expression: {
- type: "CallExpression",
- callee: {
- type: "Identifier",
- name: "module",
- range: [0, 6],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 6}
- }
+ type: "ImportDeclaration",
+ start: 0,
+ end: 32,
+ loc: {
+ start: {line: 1, column: 0},
+ end: {line: 1, column: 32}
+ },
+ range: [0, 32],
+ specifiers: [{
+ type: "ImportBatchSpecifier",
+ start: 7,
+ end: 18,
+ loc: {
+ start: {line: 1, column: 7},
+ end: {line: 1, column: 18}
},
- arguments: [],
- range: [0, 8],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 8}
- }
- },
- range: [0, 8],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 8}
- }
- }],
- range: [0, 8],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 8}
- }
-}, {
- ecmaVersion: 6,
- ranges: true,
- locations: true
-});
-
-test("module \"foo\" { module() }", {
- type: "Program",
- body: [{
- type: "ModuleDeclaration",
- id: {
- type: "Literal",
- value: "foo",
- raw: "\"foo\"",
- range: [7, 12],
- loc: {
- start: {line: 1, column: 7},
- end: {line: 1, column: 12}
- }
- },
- source: null,
- body: {
- type: "BlockStatement",
- body: [{
- type: "ExpressionStatement",
- expression: {
- type: "CallExpression",
- callee: {
- type: "Identifier",
- name: "module",
- range: [15, 21],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 21}
- }
- },
- arguments: [],
- range: [15, 23],
- loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 23}
- }
- },
- range: [15, 24],
+ range: [7, 18],
+ name: {
+ type: "Identifier",
+ start: 12,
+ end: 18,
loc: {
- start: {line: 1, column: 15},
- end: {line: 1, column: 24}
- }
- }],
- range: [13, 25],
- loc: {
- start: {line: 1, column: 13},
- end: {line: 1, column: 25}
+ start: {line: 1, column: 12},
+ end: {line: 1, column: 18}
+ },
+ range: [12, 18],
+ name: "crypto"
}
+ }],
+ source: {
+ type: "Literal",
+ start: 24,
+ end: 32,
+ loc: {
+ start: {line: 1, column: 24},
+ end: {line: 1, column: 32}
+ },
+ range: [24, 32],
+ value: "crypto",
+ raw: "\"crypto\""
},
- range: [0, 25],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 25}
- }
- }],
- range: [0, 25],
- loc: {
- start: {line: 1, column: 0},
- end: {line: 1, column: 25}
- }
+ kind: "named"
+ }]
}, {
ecmaVersion: 6,
ranges: true,
@@ -15717,18 +14497,6 @@ testFail("for (let x = 42 in list) process(x);", "Unexpected token (1:16)", {ecm
testFail("for (let x = 42 of list) process(x);", "Unexpected token (1:16)", {ecmaVersion: 6});
-testFail("module\n\"crypto\" {}", "Unexpected token (1:7)", {ecmaVersion: 6});
-
-testFail("module foo from bar", "Unexpected token (1:20)", {ecmaVersion: 6});
-
-testFail("module 42", "Unexpected token (1:8)", {ecmaVersion: 6});
-
-testFail("module foo bar", "Unexpected token (1:12)", {ecmaVersion: 6});
-
-testFail("module \"crypto\" { module \"e\" {} }", "Unexpected token (1:18)", {ecmaVersion: 6});
-
-testFail("module \"x\" { export * from foo }", "Unexpected token (1:31)", {ecmaVersion: 6});
-
testFail("import foo", "Unexpected token (1:11)", {ecmaVersion: 6});
testFail("import { foo, bar }", "Unexpected token (1:20)", {ecmaVersion: 6});
@@ -16096,8 +14864,6 @@ testFail("if (b,...a, );", "Unexpected token (1:11)", {ecmaVersion: 6});
testFail("(b, ...a)", "Unexpected token (1:9)", {ecmaVersion: 6});
-testFail("module \"Universe\" { ; ; ", "Unexpected token (1:27)", {ecmaVersion: 6});
-
testFail("switch (cond) { case 10: let a = 20; ", "Unexpected token (1:37)", {ecmaVersion: 6});
testFail("\"use strict\"; (eval) => 42", "Defining 'eval' in strict mode (1:15)", {ecmaVersion: 6});
|