Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit semicolons in class bodies #285

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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