diff --git a/src/parser/plugins/typescript.ts b/src/parser/plugins/typescript.ts index 48d36416..c66dbc40 100644 --- a/src/parser/plugins/typescript.ts +++ b/src/parser/plugins/typescript.ts @@ -672,7 +672,7 @@ function tsTryParseType(): void { */ function tsParseTypePredicateOrAssertsPrefix(): boolean { const snapshot = state.snapshot(); - if (isContextual(ContextualKeyword._asserts) && !hasPrecedingLineBreak()) { + if (isContextual(ContextualKeyword._asserts)) { // Normally this is `asserts x is T`, but at this point, it might be `asserts is T` (a user- // defined type guard on the `asserts` variable) or just a type called `asserts`. next(); @@ -1453,7 +1453,9 @@ export function tsStartParseFunctionParams(): void { // `let x: number;` export function tsAfterParseVarHead(): void { const oldIsType = pushTypeContext(0); - eat(tt.bang); + if (!hasPrecedingLineBreak()) { + eat(tt.bang); + } tsTryParseTypeAnnotation(); popTypeContext(oldIsType); } diff --git a/test/sucrase-test.ts b/test/sucrase-test.ts index de25deef..bb1880e7 100644 --- a/test/sucrase-test.ts +++ b/test/sucrase-test.ts @@ -1513,4 +1513,36 @@ describe("sucrase", () => { `, ); }); + + it("allows static blocks with a line break after the static keyword", () => { + assertResult( + ` + class A { + static + { + console.log("hi"); + } + } + `, + `"use strict"; + class A { + static + { + console.log("hi"); + } + } + `, + ); + }); + + it("allows arrow functions with parameter object assignment", () => { + assertResult( + ` + ({x = 1}) => null + `, + `"use strict"; + ({x = 1}) => null + `, + ); + }); }); diff --git a/test/typescript-test.ts b/test/typescript-test.ts index e5e5de3d..478a770f 100644 --- a/test/typescript-test.ts +++ b/test/typescript-test.ts @@ -3003,4 +3003,32 @@ describe("typescript transform", () => { {transforms: ["typescript"]}, ); }); + + it("allows a line break before an `asserts` clause", () => { + assertResult( + ` + function assert(condition: any): + asserts condition {} + `, + ` + function assert(condition) + {} + `, + {transforms: ["typescript"]}, + ); + }); + + it("properly handles ASI for variable followed by exclamation point", () => { + assertResult( + ` + let a + !function(){}() + `, + ` + let a + !function(){}() + `, + {transforms: ["typescript"]}, + ); + }); });