From a77f13f1edf1adad800d47b42a77b1ff5d4685f5 Mon Sep 17 00:00:00 2001 From: Alan Pierce Date: Thu, 28 Jun 2018 17:32:56 -0700 Subject: [PATCH] Don't emit semicolons in class bodies Fixes #280. It's unclear what the real problem is, but this broke the website build, and is probably cleaner to remove anyway. --- src/util/getClassInfo.ts | 1 + test/flow-test.ts | 4 ++-- test/sucrase-test.ts | 26 +++++++++++++++++++++----- test/types-test.ts | 6 +++--- test/typescript-test.ts | 30 +++++++++++++++--------------- 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/util/getClassInfo.ts b/src/util/getClassInfo.ts index 5bcce4b2..4c03afe3 100644 --- a/src/util/getClassInfo.ts +++ b/src/util/getClassInfo.ts @@ -51,6 +51,7 @@ export default function getClassInfo( if (tokens.matchesContextual(ContextualKeyword._constructor)) { ({constructorInitializers, constructorInsertPos} = processConstructor(tokens)); } else if (tokens.matches1(tt.semi)) { + fieldRanges.push({start: tokens.currentIndex(), end: tokens.currentIndex() + 1}); tokens.nextToken(); } else if (tokens.currentToken().isType) { tokens.nextToken(); diff --git a/test/flow-test.ts b/test/flow-test.ts index 24ae65df..54a2149e 100644 --- a/test/flow-test.ts +++ b/test/flow-test.ts @@ -54,8 +54,8 @@ describe("transform flow", () => { `, `"use strict"; class C { - ; - ; + + } `, ); diff --git a/test/sucrase-test.ts b/test/sucrase-test.ts index 4324aec6..75f48843 100644 --- a/test/sucrase-test.ts +++ b/test/sucrase-test.ts @@ -284,7 +284,7 @@ describe("sucrase", () => { `, `"use strict"; class A { - ; + } A.x = 3; `, {transforms: ["jsx", "imports", "typescript"]}, @@ -300,7 +300,7 @@ describe("sucrase", () => { `, `"use strict"; var _class; const A = (_class = class { - ; + }, _class.x = 3, _class) `, {transforms: ["jsx", "imports", "typescript"]}, @@ -316,7 +316,7 @@ describe("sucrase", () => { `, `"use strict";${ESMODULE_PREFIX} class C { - ; + } C.x = 3; exports.default = C; `, {transforms: ["jsx", "imports", "typescript"]}, @@ -337,8 +337,8 @@ describe("sucrase", () => { var _A = require('A'); var _A2 = _interopRequireDefault(_A); var _B = require('B'); var _B2 = _interopRequireDefault(_B); class C {constructor() { this.a = _A2.default; } - ; - ; + + } C.b = _B2.default; `, {transforms: ["jsx", "imports", "typescript"]}, @@ -551,4 +551,20 @@ describe("sucrase", () => { {transforms: ["imports", "typescript"]}, ); }); + + it("removes semicolons from class bodies", () => { + assertResult( + ` + class A { + ; + } + `, + `"use strict"; + class A { + + } + `, + {transforms: ["imports", "typescript"]}, + ); + }); }); diff --git a/test/types-test.ts b/test/types-test.ts index b0518801..dfac2cb7 100644 --- a/test/types-test.ts +++ b/test/types-test.ts @@ -119,8 +119,8 @@ describe("type transforms", () => { `, `"use strict"; class A {constructor() { this.x = 2;this.y = {}; } - ; - ; + + } `, ); @@ -135,7 +135,7 @@ describe("type transforms", () => { `, `"use strict"; class A { - ; + } `, ); diff --git a/test/typescript-test.ts b/test/typescript-test.ts index ad3d4aa9..8ad16bb8 100644 --- a/test/typescript-test.ts +++ b/test/typescript-test.ts @@ -53,7 +53,7 @@ describe("typescript transform", () => { `, `"use strict"; class A { - ; + c() { return "hi"; } @@ -74,7 +74,7 @@ describe("typescript transform", () => { `, `"use strict"; class A { - ; + constructor() {;this.x = 1; this.y = 2; } @@ -95,7 +95,7 @@ describe("typescript transform", () => { `, `"use strict"; class A extends B { - ; + constructor(a) { super(a);this.x = 1;; } @@ -113,7 +113,7 @@ describe("typescript transform", () => { `, `"use strict"; class A {constructor() { this.x = 1; } - ; + } `, ); @@ -128,7 +128,7 @@ describe("typescript transform", () => { `, `"use strict"; class A extends B {constructor(...args) { super(...args); this.x = 1; } - ; + } `, ); @@ -143,7 +143,7 @@ describe("typescript transform", () => { `, `"use strict"; class A extends B {constructor(...args2) { super(...args2); this.args = 1; } - ; + } `, ); @@ -307,8 +307,8 @@ describe("typescript transform", () => { `, `"use strict"; class A {constructor() { this.f = function() {}; } - ; - ; + + } `, ); @@ -362,9 +362,9 @@ describe("typescript transform", () => { `, `"use strict"; class A {constructor() { this[a + b] = 3;this[0] = 1;this["Hello, world"] = 2; } - ; - ; - ; + + + } `, ); @@ -698,7 +698,7 @@ describe("typescript transform", () => { `, `"use strict"; class A { - ; + constructor() {;this.x = 1; } } @@ -834,7 +834,7 @@ describe("typescript transform", () => { `, `"use strict"; class A { - ; + getFoo() { return foo; } @@ -968,7 +968,7 @@ describe("typescript transform", () => { `, `"use strict"; class A {constructor() { this.n = 3; } - ; + } `, ); @@ -1006,7 +1006,7 @@ describe("typescript transform", () => { f() { } - ; + } exports.Foo = Foo; `, );