Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

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

Merged
merged 1 commit into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tokenizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
) {
Expand Down Expand Up @@ -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();
Expand Down
139 changes: 139 additions & 0 deletions test/fixtures/es2015/modules/xml-comment-in-module/expected.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo <!--bar
104 changes: 104 additions & 0 deletions test/fixtures/es2015/modules/xml-comment-in-script/expected.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sourceType": "script"
}