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

Properly mark the ? as a type token in ?: class properties #264

Merged
merged 1 commit into from
Jun 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/parser/traverser/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import {
lookaheadTypeAndKeyword,
match,
next,
} from "../tokenizer/index";
popTypeContext,
pushTypeContext,
} from "../tokenizer";
import {Scope} from "../tokenizer/state";
import {TokenType, TokenType as tt} from "../tokenizer/types";
import {getNextContextId, isFlowEnabled, isTypeScriptEnabled, state} from "./base";
Expand Down Expand Up @@ -747,7 +749,9 @@ export function parseClassPropertyName(classContextId: number): void {

export function parsePostMemberNameModifiers(): void {
if (isTypeScriptEnabled) {
const oldIsType = pushTypeContext(0);
eat(tt.question);
popTypeContext(oldIsType);
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/typescript-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,19 @@ describe("typescript transform", () => {
`,
);
});

it("properly handles optional class fields with default values", () => {
assertTypeScriptResult(
`
class A {
n?: number = 3;
}
`,
`"use strict";
class A {constructor() { this.n = 3; }

}
`,
);
});
});