From 7da3b6f1fd3c97063b169daa4305638508d8098d Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Wed, 3 Sep 2014 18:20:39 +0100 Subject: [PATCH] Fix start position for HTML comments and add tests. --- acorn.js | 14 ++++++-------- test/driver.js | 24 +++++++++++++++++++++--- test/tests.js | 47 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 69 insertions(+), 16 deletions(-) diff --git a/acorn.js b/acorn.js index acf76f6a6c..d7e6ce4e85 100644 --- a/acorn.js +++ b/acorn.js @@ -565,16 +565,16 @@ startLoc, options.locations && new Position); } - function skipLineComment() { + function skipLineComment(startSkip) { var start = tokPos; var startLoc = options.onComment && options.locations && new Position; - var ch = input.charCodeAt(tokPos+=2); + var ch = input.charCodeAt(tokPos+=startSkip); while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) { ++tokPos; ch = input.charCodeAt(tokPos); } if (options.onComment) - options.onComment(false, input.slice(start + 2, tokPos), start, tokPos, + options.onComment(false, input.slice(start + startSkip, tokPos), start, tokPos, startLoc, options.locations && new Position); } @@ -609,7 +609,7 @@ if (next === 42) { // '*' skipBlockComment(); } else if (next === 47) { // '/' - skipLineComment(); + skipLineComment(2); } else break; } else if (ch === 160) { // '\xa0' ++tokPos; @@ -678,8 +678,7 @@ if (next == 45 && input.charCodeAt(tokPos + 2) == 62 && newline.test(input.slice(lastEnd, tokPos))) { // A `-->` line comment - tokPos += 3; - skipLineComment(); + skipLineComment(3); skipSpace(); return readToken(); } @@ -700,8 +699,7 @@ if (next == 33 && code == 60 && input.charCodeAt(tokPos + 2) == 45 && input.charCodeAt(tokPos + 3) == 45) { // ` HTML comment", {}, {locations: true}, + [{ + block: false, + text: " HTML comment", + startLoc: { line: 2, column: 0 }, + endLoc: { line: 2, column: 16 } + }]); })(); (function() { @@ -28747,4 +28784,4 @@ testFail("for(const x = 0;;);", "Unexpected token (1:4)", {ecmaVersion: 6}); actualTokens.push(token); } }); -})(); \ No newline at end of file +})();