From 47449de1d2a152291cc02968d6c262ccb491839b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Tore=20H=C3=A5vie?= Date: Tue, 25 Jun 2019 16:55:00 +0200 Subject: [PATCH 1/3] Do not remove generator markers Fixes #462 --- src/util/getClassInfo.ts | 3 ++- test/sucrase-test.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/util/getClassInfo.ts b/src/util/getClassInfo.ts index a8f59d40..c7529f44 100644 --- a/src/util/getClassInfo.ts +++ b/src/util/getClassInfo.ts @@ -79,7 +79,8 @@ export default function getClassInfo( // Either a method or a field. Skip to the identifier part. const statementStartIndex = tokens.currentIndex(); let isStatic = false; - while (isAccessModifier(tokens.currentToken())) { + // Access modifiers and generator marker. + while (isAccessModifier(tokens.currentToken()) || tokens.matches1(tt.star)) { if (tokens.matches1(tt._static)) { isStatic = true; } diff --git a/test/sucrase-test.ts b/test/sucrase-test.ts index 03554a0b..0ecf686c 100644 --- a/test/sucrase-test.ts +++ b/test/sucrase-test.ts @@ -249,6 +249,24 @@ describe("sucrase", () => { ); }); + it("handles generator class methods", () => { + assertResult( + ` + class A { + *foo() { + } + } + `, + `"use strict"; + class A { + *foo() { + } + } + `, + {transforms: ["jsx", "imports", "typescript"]}, + ); + }); + it("removes numeric separators from number literals", () => { assertResult( ` From fdeabfa203f2a32b5d3acf962dff3c93cafd3ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Tore=20H=C3=A5vie?= Date: Wed, 26 Jun 2019 09:39:41 +0200 Subject: [PATCH 2/3] Move test to isAccessModifier --- src/util/getClassInfo.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/getClassInfo.ts b/src/util/getClassInfo.ts index c7529f44..f361b012 100644 --- a/src/util/getClassInfo.ts +++ b/src/util/getClassInfo.ts @@ -79,8 +79,7 @@ export default function getClassInfo( // Either a method or a field. Skip to the identifier part. const statementStartIndex = tokens.currentIndex(); let isStatic = false; - // Access modifiers and generator marker. - while (isAccessModifier(tokens.currentToken()) || tokens.matches1(tt.star)) { + while (isAccessModifier(tokens.currentToken())) { if (tokens.matches1(tt._static)) { isStatic = true; } @@ -258,6 +257,7 @@ function isAccessModifier(token: Token): boolean { tt._private, tt._protected, tt._abstract, + tt.star, ].includes(token.type); } From cfbc4438a8bf0b820afc96212eb2c449a4553154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Tore=20H=C3=A5vie?= Date: Thu, 25 Jul 2019 10:21:51 +0200 Subject: [PATCH 3/3] Add test for async generator method --- test/sucrase-test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/sucrase-test.ts b/test/sucrase-test.ts index 0ecf686c..c51efdd0 100644 --- a/test/sucrase-test.ts +++ b/test/sucrase-test.ts @@ -267,6 +267,26 @@ describe("sucrase", () => { ); }); + it("handles async generator class methods", () => { + assertResult( + ` + class C { + async *m() { + yield await 1; + } + } + `, + `"use strict"; + class C { + async *m() { + yield await 1; + } + } + `, + {transforms: ["jsx", "imports", "typescript"]}, + ); + }); + it("removes numeric separators from number literals", () => { assertResult( `