Permalink
Browse files

Correct the handling of HTML comment when parsing as a module

Fix #1841
Closes gh-1885
  • Loading branch information...
ariya committed Nov 21, 2017
1 parent d00740b commit 512ce40c276c53adadb5f87e992c91b94bad614d
View
@@ -3374,6 +3374,7 @@ export class Parser {
parseModule(): Node.Module {
this.context.strict = true;
this.context.isModule = true;
this.scanner.isModule = true;
const node = this.createNode();
const body = this.parseDirectivePrologues();
while (this.lookahead.type !== Token.EOF) {
View
@@ -57,6 +57,7 @@ export class Scanner {
readonly source: string;
readonly errorHandler: ErrorHandler;
trackComment: boolean;
isModule: boolean;
index: number;
lineNumber: number;
@@ -69,6 +70,7 @@ export class Scanner {
this.source = code;
this.errorHandler = handler;
this.trackComment = false;
this.isModule = false;
this.length = code.length;
this.index = 0;
@@ -285,7 +287,7 @@ export class Scanner {
} else {
break;
}
} else if (ch === 0x3C) { // U+003C is '<'
} else if (ch === 0x3C && !this.isModule) { // U+003C is '<'
if (this.source.slice(this.index + 1, this.index + 4) === '!--') {
this.index += 4; // `<!--`
const comment = this.skipSingleLineComment(4);
@@ -0,0 +1 @@
a <!-- b
@@ -0,0 +1,221 @@
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "BinaryExpression",
"operator": "<",
"left": {
"type": "Identifier",
"name": "a",
"range": [
0,
1
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
}
},
"right": {
"type": "UnaryExpression",
"operator": "!",
"argument": {
"type": "UpdateExpression",
"operator": "--",
"argument": {
"type": "Identifier",
"name": "b",
"range": [
7,
8
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
}
},
"prefix": true,
"range": [
4,
8
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 8
}
}
},
"prefix": true,
"range": [
3,
8
],
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 8
}
}
},
"range": [
0,
8
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
},
"range": [
0,
8
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
}
}
],
"sourceType": "module",
"range": [
0,
8
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 8
}
},
"tokens": [
{
"type": "Identifier",
"value": "a",
"range": [
0,
1
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 1
}
}
},
{
"type": "Punctuator",
"value": "<",
"range": [
2,
3
],
"loc": {
"start": {
"line": 1,
"column": 2
},
"end": {
"line": 1,
"column": 3
}
}
},
{
"type": "Punctuator",
"value": "!",
"range": [
3,
4
],
"loc": {
"start": {
"line": 1,
"column": 3
},
"end": {
"line": 1,
"column": 4
}
}
},
{
"type": "Punctuator",
"value": "--",
"range": [
4,
6
],
"loc": {
"start": {
"line": 1,
"column": 4
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "Identifier",
"value": "b",
"range": [
7,
8
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
}
}
]
}
@@ -7660,8 +7660,6 @@ test/language/module-code/comment-multi-line-html-close.js(default)
test/language/module-code/comment-multi-line-html-close.js(strict mode)
test/language/module-code/comment-single-line-html-close.js(default)
test/language/module-code/comment-single-line-html-close.js(strict mode)
test/language/module-code/comment-single-line-html-open.js(default)
test/language/module-code/comment-single-line-html-open.js(strict mode)
test/language/module-code/early-dup-export-decl.js(default)
test/language/module-code/early-dup-export-decl.js(strict mode)
test/language/module-code/early-dup-export-dflt-id.js(default)
@@ -8015,4 +8013,4 @@ test/language/expressions/object/method-definition/generator-super-prop-param.js
test/language/expressions/object/method-definition/name-super-prop-param.js(default)
test/language/expressions/object/method-definition/name-super-prop-param.js(strict mode)
test/language/statements/class/definition/methods-async-super-call-param.js(default)
test/language/statements/class/definition/methods-async-super-call-param.js(strict mode)
test/language/statements/class/definition/methods-async-super-call-param.js(strict mode)

0 comments on commit 512ce40

Please sign in to comment.