Skip to content

Commit

Permalink
Don't emit semicolons in class bodies (#285)
Browse files Browse the repository at this point in the history
Fixes #280.

It's unclear what the real problem is, but this broke the website build, and is
probably cleaner to remove anyway.
  • Loading branch information
alangpierce authored Jun 29, 2018
1 parent 33a8c12 commit 079556b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/util/getClassInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/flow-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe("transform flow", () => {
`,
`"use strict";
class C {
;
;
}
`,
);
Expand Down
26 changes: 21 additions & 5 deletions test/sucrase-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ describe("sucrase", () => {
`,
`"use strict";
class A {
;
} A.x = 3;
`,
{transforms: ["jsx", "imports", "typescript"]},
Expand All @@ -300,7 +300,7 @@ describe("sucrase", () => {
`,
`"use strict"; var _class;
const A = (_class = class {
;
}, _class.x = 3, _class)
`,
{transforms: ["jsx", "imports", "typescript"]},
Expand All @@ -316,7 +316,7 @@ describe("sucrase", () => {
`,
`"use strict";${ESMODULE_PREFIX}
class C {
;
} C.x = 3; exports.default = C;
`,
{transforms: ["jsx", "imports", "typescript"]},
Expand All @@ -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"]},
Expand Down Expand Up @@ -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"]},
);
});
});
6 changes: 3 additions & 3 deletions test/types-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ describe("type transforms", () => {
`,
`"use strict";
class A {constructor() { this.x = 2;this.y = {}; }
;
;
}
`,
);
Expand All @@ -135,7 +135,7 @@ describe("type transforms", () => {
`,
`"use strict";
class A {
;
}
`,
);
Expand Down
30 changes: 15 additions & 15 deletions test/typescript-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {
;
c() {
return "hi";
}
Expand All @@ -74,7 +74,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {
;
constructor() {;this.x = 1;
this.y = 2;
}
Expand All @@ -95,7 +95,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A extends B {
;
constructor(a) {
super(a);this.x = 1;;
}
Expand All @@ -113,7 +113,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {constructor() { this.x = 1; }
;
}
`,
);
Expand All @@ -128,7 +128,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A extends B {constructor(...args) { super(...args); this.x = 1; }
;
}
`,
);
Expand All @@ -143,7 +143,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A extends B {constructor(...args2) { super(...args2); this.args = 1; }
;
}
`,
);
Expand Down Expand Up @@ -307,8 +307,8 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {constructor() { this.f = function() {}; }
;
;
}
`,
);
Expand Down Expand Up @@ -362,9 +362,9 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {constructor() { this[a + b] = 3;this[0] = 1;this["Hello, world"] = 2; }
;
;
;
}
`,
);
Expand Down Expand Up @@ -698,7 +698,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {
;
constructor() {;this.x = 1;
}
}
Expand Down Expand Up @@ -834,7 +834,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {
;
getFoo() {
return foo;
}
Expand Down Expand Up @@ -968,7 +968,7 @@ describe("typescript transform", () => {
`,
`"use strict";
class A {constructor() { this.n = 3; }
;
}
`,
);
Expand Down Expand Up @@ -1006,7 +1006,7 @@ describe("typescript transform", () => {
f() {
}
;
} exports.Foo = Foo;
`,
);
Expand Down

0 comments on commit 079556b

Please sign in to comment.