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

Fix ASTBuilder for parameters #1377

Merged
merged 1 commit into from
Jul 7, 2020
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
2 changes: 1 addition & 1 deletion src/extra/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ export class ASTBuilder {
var type = node.type;
var initializer = node.initializer;
if (type) {
if (kind == ParameterKind.OPTIONAL) sb.push("?");
if (kind == ParameterKind.OPTIONAL && !initializer) sb.push("?");
if (!isTypeOmitted(type)) {
sb.push(": ");
this.visitTypeNode(type);
Expand Down
2 changes: 1 addition & 1 deletion tests/parser/constructor.ts.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class MyClass {
constructor(a: i32, b: i32) {}
}
class MyClassImplicit {
constructor(public a: i32, private readonly b?: i32 = 2, c?: i32 = 3) {}
constructor(public a: i32, private readonly b: i32 = 2, c: i32 = 3) {}
}
2 changes: 1 addition & 1 deletion tests/parser/function.ts.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function simple(): void {}
function typeparams<T, V extends T>(a?: V | null = null): void {}
function typeparams<T, V extends T>(a: V | null = null): void {}
@decorator()
function withdecorator(): void {}
function withthis(this: i32): i32 {
Expand Down
1 change: 1 addition & 0 deletions tests/parser/parameter-optional.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function optionalParam(a: string = ""): void {}
1 change: 1 addition & 0 deletions tests/parser/parameter-optional.ts.fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function optionalParam(a: string = ""): void {}
2 changes: 1 addition & 1 deletion tests/parser/parameter-order.ts.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function restValid(a: i32, ...b: Array<i32>): void {}
function optionalValid(a: i32, b?: i32): void {}
function restParameterMustBeLast(...a: Array<i32>, b: i32): void {}
function optionalCannotPrecedeRequired(a?: i32, b: i32): void {}
function optionalWithInitializerCannotPrecedeRequired(a?: i32 = 1, b: i32): void {}
function optionalWithInitializerCannotPrecedeRequired(a: i32 = 1, b: i32): void {}
// ERROR 1014: "A rest parameter must be last in a parameter list." in parameter-order.ts(5,37+1)
// ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts(8,49+1)
// ERROR 1016: "A required parameter cannot follow an optional parameter." in parameter-order.ts(11,67+1)
2 changes: 1 addition & 1 deletion tests/parser/string-binding.ts.fixture.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@binding(BindingCall.NEW, [BindingType.STRING], BindingType.OBJECT_HANDLE)
export class ExternalString {
@binding(BindingCall.FUNCTION, [BindingType.U32, BindingType.U32], BindingType.OBJECT_HANDLE)
static fromCharCode(char: u16, schar?: u16 = <u16>-1): String {
static fromCharCode(char: u16, schar: u16 = <u16>-1): String {
return unreachable();
}
@binding(BindingCall.FUNCTION, [BindingType.U32], BindingType.OBJECT_HANDLE)
Expand Down