diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 084a7ff9335b..1dfa40089970 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -526,7 +526,10 @@ export default class Tokenizer extends LocationParser { next === charCodes.dash && !this.inModule && this.input.charCodeAt(this.state.pos + 2) === charCodes.greaterThan && - lineBreak.test(this.input.slice(this.state.lastTokEnd, this.state.pos)) + (this.state.lastTokEnd === 0 || + lineBreak.test( + this.input.slice(this.state.lastTokEnd, this.state.pos), + )) ) { // A `-->` line comment this.skipLineComment(3); diff --git a/packages/babel-parser/test/fixtures/comments/html/first-line/input.js b/packages/babel-parser/test/fixtures/comments/html/first-line/input.js new file mode 100644 index 000000000000..9fe3a97d3a3a --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/html/first-line/input.js @@ -0,0 +1 @@ +/**/ --> comment diff --git a/packages/babel-parser/test/fixtures/comments/html/first-line/output.json b/packages/babel-parser/test/fixtures/comments/html/first-line/output.json new file mode 100644 index 000000000000..d42874927c64 --- /dev/null +++ b/packages/babel-parser/test/fixtures/comments/html/first-line/output.json @@ -0,0 +1,102 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [], + "directives": [], + "innerComments": [ + { + "type": "CommentBlock", + "value": "", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "CommentLine", + "value": " comment", + "start": 5, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ] + }, + "comments": [ + { + "type": "CommentBlock", + "value": "", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "CommentLine", + "value": " comment", + "start": 5, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ] +} \ No newline at end of file