Skip to content

Commit

Permalink
Don't treat /*/ as an entire block comment (#430)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alangpierce authored Mar 4, 2019
1 parent 5b3e0de commit 3b00a35
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/parser/tokenizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 24 additions & 0 deletions test/sucrase-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: []},
);
});
});

0 comments on commit 3b00a35

Please sign in to comment.