File tree Expand file tree Collapse file tree 6 files changed +36
-7
lines changed
Filter options
Expand file tree Collapse file tree 6 files changed +36
-7
lines changed
Original file line number Diff line number Diff line change @@ -10,9 +10,7 @@ lp.parseTopLevel = function() {
10
10
while ( this . tok . type !== tt . eof ) node . body . push ( this . parseStatement ( ) )
11
11
this . toks . adaptDirectivePrologue ( node . body )
12
12
this . last = this . tok
13
- if ( this . options . ecmaVersion >= 6 ) {
14
- node . sourceType = this . options . sourceType
15
- }
13
+ node . sourceType = this . options . sourceType
16
14
return this . finishNode ( node , "Program" )
17
15
}
18
16
Original file line number Diff line number Diff line change @@ -64,6 +64,9 @@ an object containing any of these fields:
64
64
either ` "script" ` or ` "module" ` . This influences global strict mode
65
65
and parsing of ` import ` and ` export ` declarations.
66
66
67
+ ** NOTE** : If set to ` "module" ` , then static ` import ` / ` export ` syntax
68
+ will be valid, even if ` ecmaVersion ` is less than 6.
69
+
67
70
- ** onInsertedSemicolon** : If given a callback, that callback will be
68
71
called whenever a missing semicolon is inserted by the parser. The
69
72
callback will be given the character offset of the point where the
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export class Parser {
9
9
constructor ( options , input , startPos ) {
10
10
this . options = options = getOptions ( options )
11
11
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 ] )
13
13
let reserved = ""
14
14
if ( options . allowReserved !== true ) {
15
15
for ( let v = options . ecmaVersion ; ; v -- )
Original file line number Diff line number Diff line change @@ -27,9 +27,7 @@ pp.parseTopLevel = function(node) {
27
27
this . raiseRecoverable ( this . undefinedExports [ name ] . start , `Export '${ name } ' is not defined` )
28
28
this . adaptDirectivePrologue ( node . body )
29
29
this . next ( )
30
- if ( this . options . ecmaVersion >= 6 ) {
31
- node . sourceType = this . options . sourceType
32
- }
30
+ node . sourceType = this . options . sourceType
33
31
return this . finishNode ( node , "Program" )
34
32
}
35
33
Original file line number Diff line number Diff line change @@ -7,6 +7,35 @@ if (typeof exports != "undefined") {
7
7
var acorn = require("../acorn");
8
8
}
9
9
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
+
10
39
test("new Object", {
11
40
type: "Program",
12
41
start: 0,
You can’t perform that action at this time.
0 commit comments