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

Commit

Permalink
Fix parsing a <!-- b in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
existentialism committed Jul 13, 2017
1 parent b0c3a9d commit ed0da6d
Show file tree
Hide file tree
Showing 7 changed files with 282 additions and 4 deletions.
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"
}
33 changes: 33 additions & 0 deletions test/fixtures/typescript/function/expression/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type": "File",
"start": 0,
"end": 0,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 0,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 0
}
},
"sourceType": "module",
"body": [],
"directives": []
}
}

0 comments on commit ed0da6d

Please sign in to comment.