Fix parsing a <!-- b in modules (#626)
This commit is contained in:
parent
63143ea5e9
commit
688a1e523e
@ -434,6 +434,7 @@ export default class Tokenizer extends LocationParser {
|
||||
if (next === code) {
|
||||
if (
|
||||
next === 45 &&
|
||||
!this.inModule &&
|
||||
this.input.charCodeAt(this.state.pos + 2) === 62 &&
|
||||
lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.pos))
|
||||
) {
|
||||
@ -468,10 +469,10 @@ export default class Tokenizer extends LocationParser {
|
||||
if (
|
||||
next === 33 &&
|
||||
code === 60 &&
|
||||
!this.inModule &&
|
||||
this.input.charCodeAt(this.state.pos + 2) === 45 &&
|
||||
this.input.charCodeAt(this.state.pos + 3) === 45
|
||||
) {
|
||||
if (this.inModule) this.unexpected();
|
||||
// `<!--`, an XML-style comment that should be interpreted as a line comment
|
||||
this.skipLineComment(4);
|
||||
this.skipSpace();
|
||||
|
||||
139
test/fixtures/es2015/modules/xml-comment-in-module/expected.json
vendored
Normal file
139
test/fixtures/es2015/modules/xml-comment-in-module/expected.json
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 0,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "BinaryExpression",
|
||||
"start": 0,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"left": {
|
||||
"type": "Identifier",
|
||||
"start": 0,
|
||||
"end": 3,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "foo"
|
||||
},
|
||||
"name": "foo"
|
||||
},
|
||||
"operator": "<",
|
||||
"right": {
|
||||
"type": "UnaryExpression",
|
||||
"start": 5,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"operator": "!",
|
||||
"prefix": true,
|
||||
"argument": {
|
||||
"type": "UpdateExpression",
|
||||
"start": 6,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"operator": "--",
|
||||
"prefix": true,
|
||||
"argument": {
|
||||
"type": "Identifier",
|
||||
"start": 8,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
},
|
||||
"identifierName": "bar"
|
||||
},
|
||||
"name": "bar"
|
||||
},
|
||||
"extra": {
|
||||
"parenthesizedArgument": false
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"parenthesizedArgument": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
{
|
||||
"throws": "Unexpected token (1:4)"
|
||||
}
|
||||
1
test/fixtures/es2015/modules/xml-comment-in-script/actual.js
vendored
Normal file
1
test/fixtures/es2015/modules/xml-comment-in-script/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
foo <!--bar
|
||||
104
test/fixtures/es2015/modules/xml-comment-in-script/expected.json
vendored
Normal file
104
test/fixtures/es2015/modules/xml-comment-in-script/expected.json
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"body": [
|
||||
{
|
||||
"type": "ExpressionStatement",
|
||||
"start": 0,
|
||||
"end": 3,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 3
|
||||
}
|
||||
},
|
||||
"expression": {
|
||||
"type": "Identifier",
|
||||
"start": 0,
|
||||
"end": 3,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 3
|
||||
},
|
||||
"identifierName": "foo"
|
||||
},
|
||||
"name": "foo",
|
||||
"leadingComments": null,
|
||||
"trailingComments": null
|
||||
},
|
||||
"trailingComments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": "bar",
|
||||
"start": 4,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
},
|
||||
"comments": [
|
||||
{
|
||||
"type": "CommentLine",
|
||||
"value": "bar",
|
||||
"start": 4,
|
||||
"end": 11,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 4
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 11
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
3
test/fixtures/es2015/modules/xml-comment-in-script/options.json
vendored
Normal file
3
test/fixtures/es2015/modules/xml-comment-in-script/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sourceType": "script"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user