Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts] Allow optional binding pattern parameters within types/interfaces (
- Loading branch information
1 parent
ddb7e05
commit d51aa6d
Showing
8 changed files
with
432 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/babel-parser/test/fixtures/typescript/declare/pattern-parameters/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare interface B { | ||
foo([]?): void; | ||
bar({}, []?): any; | ||
baz(a: string, b: number, []?): void; | ||
} |
138 changes: 138 additions & 0 deletions
138
packages/babel-parser/test/fixtures/typescript/declare/pattern-parameters/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":102,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":102,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSInterfaceDeclaration", | ||
"start":0,"end":102,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":18,"end":19,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":19},"identifierName":"B"}, | ||
"name": "B" | ||
}, | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":20,"end":102,"loc":{"start":{"line":1,"column":20},"end":{"line":5,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":24,"end":39,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":24,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"computed": false, | ||
"parameters": [ | ||
{ | ||
"type": "ArrayPattern", | ||
"start":28,"end":31,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9}}, | ||
"elements": [], | ||
"optional": true | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":32,"end":38,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":16}}, | ||
"typeAnnotation": { | ||
"type": "TSVoidKeyword", | ||
"start":34,"end":38,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":16}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":42,"end":60,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":20}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":42,"end":45,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"bar"}, | ||
"name": "bar" | ||
}, | ||
"computed": false, | ||
"parameters": [ | ||
{ | ||
"type": "ObjectPattern", | ||
"start":46,"end":48,"loc":{"start":{"line":3,"column":6},"end":{"line":3,"column":8}}, | ||
"properties": [] | ||
}, | ||
{ | ||
"type": "ArrayPattern", | ||
"start":50,"end":53,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":13}}, | ||
"elements": [], | ||
"optional": true | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":54,"end":59,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":19}}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":56,"end":59,"loc":{"start":{"line":3,"column":16},"end":{"line":3,"column":19}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":63,"end":100,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":39}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":63,"end":66,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":5},"identifierName":"baz"}, | ||
"name": "baz" | ||
}, | ||
"computed": false, | ||
"parameters": [ | ||
{ | ||
"type": "Identifier", | ||
"start":67,"end":76,"loc":{"start":{"line":4,"column":6},"end":{"line":4,"column":15},"identifierName":"a"}, | ||
"name": "a", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":68,"end":76,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":15}}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start":70,"end":76,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":15}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Identifier", | ||
"start":78,"end":87,"loc":{"start":{"line":4,"column":17},"end":{"line":4,"column":26},"identifierName":"b"}, | ||
"name": "b", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":79,"end":87,"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":26}}, | ||
"typeAnnotation": { | ||
"type": "TSNumberKeyword", | ||
"start":81,"end":87,"loc":{"start":{"line":4,"column":20},"end":{"line":4,"column":26}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "ArrayPattern", | ||
"start":89,"end":92,"loc":{"start":{"line":4,"column":28},"end":{"line":4,"column":31}}, | ||
"elements": [], | ||
"optional": true | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":93,"end":99,"loc":{"start":{"line":4,"column":32},"end":{"line":4,"column":38}}, | ||
"typeAnnotation": { | ||
"type": "TSVoidKeyword", | ||
"start":95,"end":99,"loc":{"start":{"line":4,"column":34},"end":{"line":4,"column":38}} | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"declare": true | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-parser/test/fixtures/typescript/interface/pattern-parameters/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface A { | ||
foo([]?): void; | ||
bar({}, []?): any; | ||
baz(a: string, b: number, []?): void; | ||
} |
137 changes: 137 additions & 0 deletions
137
packages/babel-parser/test/fixtures/typescript/interface/pattern-parameters/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":94,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":94,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"sourceType": "module", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "TSInterfaceDeclaration", | ||
"start":0,"end":94,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"A"}, | ||
"name": "A" | ||
}, | ||
"body": { | ||
"type": "TSInterfaceBody", | ||
"start":12,"end":94,"loc":{"start":{"line":1,"column":12},"end":{"line":5,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":16,"end":31,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":16,"end":19,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":5},"identifierName":"foo"}, | ||
"name": "foo" | ||
}, | ||
"computed": false, | ||
"parameters": [ | ||
{ | ||
"type": "ArrayPattern", | ||
"start":20,"end":23,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9}}, | ||
"elements": [], | ||
"optional": true | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":24,"end":30,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":16}}, | ||
"typeAnnotation": { | ||
"type": "TSVoidKeyword", | ||
"start":26,"end":30,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":16}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":34,"end":52,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":20}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":34,"end":37,"loc":{"start":{"line":3,"column":2},"end":{"line":3,"column":5},"identifierName":"bar"}, | ||
"name": "bar" | ||
}, | ||
"computed": false, | ||
"parameters": [ | ||
{ | ||
"type": "ObjectPattern", | ||
"start":38,"end":40,"loc":{"start":{"line":3,"column":6},"end":{"line":3,"column":8}}, | ||
"properties": [] | ||
}, | ||
{ | ||
"type": "ArrayPattern", | ||
"start":42,"end":45,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":13}}, | ||
"elements": [], | ||
"optional": true | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":46,"end":51,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":19}}, | ||
"typeAnnotation": { | ||
"type": "TSAnyKeyword", | ||
"start":48,"end":51,"loc":{"start":{"line":3,"column":16},"end":{"line":3,"column":19}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "TSMethodSignature", | ||
"start":55,"end":92,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":39}}, | ||
"key": { | ||
"type": "Identifier", | ||
"start":55,"end":58,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":5},"identifierName":"baz"}, | ||
"name": "baz" | ||
}, | ||
"computed": false, | ||
"parameters": [ | ||
{ | ||
"type": "Identifier", | ||
"start":59,"end":68,"loc":{"start":{"line":4,"column":6},"end":{"line":4,"column":15},"identifierName":"a"}, | ||
"name": "a", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":60,"end":68,"loc":{"start":{"line":4,"column":7},"end":{"line":4,"column":15}}, | ||
"typeAnnotation": { | ||
"type": "TSStringKeyword", | ||
"start":62,"end":68,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":15}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "Identifier", | ||
"start":70,"end":79,"loc":{"start":{"line":4,"column":17},"end":{"line":4,"column":26},"identifierName":"b"}, | ||
"name": "b", | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":71,"end":79,"loc":{"start":{"line":4,"column":18},"end":{"line":4,"column":26}}, | ||
"typeAnnotation": { | ||
"type": "TSNumberKeyword", | ||
"start":73,"end":79,"loc":{"start":{"line":4,"column":20},"end":{"line":4,"column":26}} | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "ArrayPattern", | ||
"start":81,"end":84,"loc":{"start":{"line":4,"column":28},"end":{"line":4,"column":31}}, | ||
"elements": [], | ||
"optional": true | ||
} | ||
], | ||
"typeAnnotation": { | ||
"type": "TSTypeAnnotation", | ||
"start":85,"end":91,"loc":{"start":{"line":4,"column":32},"end":{"line":4,"column":38}}, | ||
"typeAnnotation": { | ||
"type": "TSVoidKeyword", | ||
"start":87,"end":91,"loc":{"start":{"line":4,"column":34},"end":{"line":4,"column":38}} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-parser/test/fixtures/typescript/types/pattern-parameters/input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type C = { | ||
foo([]?): void; | ||
bar({}, []?): any; | ||
baz(a: string, b: number, []?): void; | ||
}; |
Oops, something went wrong.