From 8995a9e2c580020016b63a2067356d787838ad24 Mon Sep 17 00:00:00 2001 From: Alan Pierce Date: Sun, 3 Mar 2019 23:28:39 -0800 Subject: [PATCH] Don't treat `/*/` as an entire block comment Fixes #428 After seeing a `/*`, we were searching for a `*/`, but really we needed to search starting at two past the start of the comment. --- src/parser/tokenizer/index.ts | 1 + test/sucrase-test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/parser/tokenizer/index.ts b/src/parser/tokenizer/index.ts index 1346e236..9ba69b19 100644 --- a/src/parser/tokenizer/index.ts +++ b/src/parser/tokenizer/index.ts @@ -265,6 +265,7 @@ export function skipSpace(): void { case charCodes.slash: switch (input.charCodeAt(state.pos + 1)) { case charCodes.asterisk: + state.pos += 2; skipBlockComment(); break; diff --git a/test/sucrase-test.ts b/test/sucrase-test.ts index e36eca1f..746dd60c 100644 --- a/test/sucrase-test.ts +++ b/test/sucrase-test.ts @@ -747,4 +747,28 @@ describe("sucrase", () => { it("handles a file with only an assignment", () => { assertResult("a = 1", '"use strict";a = 1', {transforms: ["imports"]}); }); + + it("handles a standalone comment that looks like it could be a regex", () => { + assertResult( + ` + /*/*/; + `, + ` + /*/*/; + `, + {transforms: []}, + ); + }); + + it("handles a comment that looks like it could be a regex after a string", () => { + assertResult( + ` + let thing = "sup" /*/*/; + `, + ` + let thing = "sup" /*/*/; + `, + {transforms: []}, + ); + }); });