Fix parsing a <!-- b in modules (#626)

This commit is contained in:
Brian Ng 2017-07-14 09:16:31 -05:00 committed by GitHub
parent 63143ea5e9
commit 688a1e523e
6 changed files with 249 additions and 4 deletions

View File

@ -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();

View 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": []
}
}

View File

@ -1,3 +0,0 @@
{
"throws": "Unexpected token (1:4)"
}

View File

@ -0,0 +1 @@
foo <!--bar

View 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
}
}
}
]
}

View File

@ -0,0 +1,3 @@
{
"sourceType": "script"
}