Skip to content

Commit

Permalink
WIP next backport
Browse files Browse the repository at this point in the history
  • Loading branch information
alangpierce committed Jun 22, 2022
1 parent cf849ab commit 3691bda
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parser/plugins/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,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();
Expand Down
21 changes: 21 additions & 0 deletions test/sucrase-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,4 +1469,25 @@ describe("sucrase", () => {
{transforms: ["typescript"]},
);
});

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");
}
}
`,
);
});
});
14 changes: 14 additions & 0 deletions test/typescript-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2870,4 +2870,18 @@ 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"]},
);
});
});

0 comments on commit 3691bda

Please sign in to comment.