Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e9817d

Browse filesBrowse files
LongTengDaomarijnh
authored andcommitted
Allow sourceType: module even with ecmaVersion < 6
1 parent e2b8cc0 commit 7e9817d
Copy full SHA for 7e9817d

File tree

Expand file treeCollapse file tree

6 files changed

+36
-7
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+36
-7
lines changed

‎acorn-loose/src/statement.js

Copy file name to clipboardExpand all lines: acorn-loose/src/statement.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ lp.parseTopLevel = function() {
1010
while (this.tok.type !== tt.eof) node.body.push(this.parseStatement())
1111
this.toks.adaptDirectivePrologue(node.body)
1212
this.last = this.tok
13-
if (this.options.ecmaVersion >= 6) {
14-
node.sourceType = this.options.sourceType
15-
}
13+
node.sourceType = this.options.sourceType
1614
return this.finishNode(node, "Program")
1715
}
1816

‎acorn/README.md

Copy file name to clipboardExpand all lines: acorn/README.md
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ an object containing any of these fields:
6464
either `"script"` or `"module"`. This influences global strict mode
6565
and parsing of `import` and `export` declarations.
6666

67+
**NOTE**: If set to `"module"`, then static `import` / `export` syntax
68+
will be valid, even if `ecmaVersion` is less than 6.
69+
6770
- **onInsertedSemicolon**: If given a callback, that callback will be
6871
called whenever a missing semicolon is inserted by the parser. The
6972
callback will be given the character offset of the point where the

‎acorn/src/identifier.js

Copy file name to clipboardExpand all lines: acorn/src/identifier.js
+1Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎acorn/src/state.js

Copy file name to clipboardExpand all lines: acorn/src/state.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class Parser {
99
constructor(options, input, startPos) {
1010
this.options = options = getOptions(options)
1111
this.sourceFile = options.sourceFile
12-
this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5])
12+
this.keywords = wordsRegexp(keywords[options.ecmaVersion >= 6 ? 6 : options.sourceType === "module" ? "5module" : 5])
1313
let reserved = ""
1414
if (options.allowReserved !== true) {
1515
for (let v = options.ecmaVersion;; v--)

‎acorn/src/statement.js

Copy file name to clipboardExpand all lines: acorn/src/statement.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ pp.parseTopLevel = function(node) {
2727
this.raiseRecoverable(this.undefinedExports[name].start, `Export '${name}' is not defined`)
2828
this.adaptDirectivePrologue(node.body)
2929
this.next()
30-
if (this.options.ecmaVersion >= 6) {
31-
node.sourceType = this.options.sourceType
32-
}
30+
node.sourceType = this.options.sourceType
3331
return this.finishNode(node, "Program")
3432
}
3533

‎test/tests.js

Copy file name to clipboardExpand all lines: test/tests.js
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,35 @@ if (typeof exports != "undefined") {
77
var acorn = require("../acorn");
88
}
99

10+
test("import ''", {
11+
type: "Program",
12+
start: 0,
13+
end: 9,
14+
body: [
15+
{
16+
type: "ImportDeclaration",
17+
start: 0,
18+
end: 9,
19+
specifiers: [],
20+
source: {
21+
type: "Literal",
22+
start: 7,
23+
end: 9,
24+
value: "",
25+
raw: "''"
26+
}
27+
}
28+
]
29+
}, {
30+
ecmaVersion: 5,
31+
sourceType: "module"
32+
});
33+
34+
testFail("import('')", "Unexpected token (1:6)", {
35+
ecmaVersion: 5,
36+
sourceType: "module"
37+
});
38+
1039
test("new Object", {
1140
type: "Program",
1241
start: 0,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.