diff --git a/packages/babel-parser/src/plugins/typescript/index.ts b/packages/babel-parser/src/plugins/typescript/index.ts index e781b07987be..61eae5d827c1 100644 --- a/packages/babel-parser/src/plugins/typescript/index.ts +++ b/packages/babel-parser/src/plugins/typescript/index.ts @@ -52,6 +52,7 @@ type TsModifier = | "declare" | "static" | "override" + | "const" | N.Accessibility | N.VarianceAnnotations; @@ -324,7 +325,11 @@ export default (superClass: ClassWithMixin) => allowedModifiers: T[], stopOnStartOfClassStaticBlock?: boolean, ): T | undefined | null { - if (!tokenIsIdentifier(this.state.type) && this.state.type !== tt._in) { + if ( + !tokenIsIdentifier(this.state.type) && + this.state.type !== tt._in && + this.state.type !== tt._const + ) { return undefined; } @@ -345,20 +350,20 @@ export default (superClass: ClassWithMixin) => * this.tsParseModifiers({ modified: node, allowedModifiers: ["public"] }); * this.tsParseModifiers({ modified: node, allowedModifiers: ["abstract", "readonly"] }); */ - tsParseModifiers({ - modified, - allowedModifiers, - disallowedModifiers, - stopOnStartOfClassStaticBlock, - errorTemplate = TSErrors.InvalidModifierOnTypeMember, - }: { - modified: ModifierBase; - allowedModifiers: readonly TsModifier[]; - disallowedModifiers?: TsModifier[]; - stopOnStartOfClassStaticBlock?: boolean; - // FIXME: make sure errorTemplate can receive `modifier` - errorTemplate?: any; - }): void { + tsParseModifiers( + { + allowedModifiers, + disallowedModifiers, + stopOnStartOfClassStaticBlock, + errorTemplate = TSErrors.InvalidModifierOnTypeMember, + }: { + allowedModifiers: readonly TsModifier[]; + disallowedModifiers?: TsModifier[]; + stopOnStartOfClassStaticBlock?: boolean; + errorTemplate?: typeof TSErrors.InvalidModifierOnTypeMember; + }, + modified: N, + ): void { const enforceOrder = ( loc: Position, modifier: TsModifier, @@ -644,37 +649,44 @@ export default (superClass: ClassWithMixin) => return this.finishNode(node, "TSTypeQuery"); } - tsParseInOutModifiers(node: N.TsTypeParameter) { - this.tsParseModifiers({ - modified: node, - allowedModifiers: ["in", "out"], - disallowedModifiers: [ - "public", - "private", - "protected", - "readonly", - "declare", - "abstract", - "override", - ], - errorTemplate: TSErrors.InvalidModifierOnTypeParameter, - }); - } - - // for better error recover - tsParseNoneModifiers(node: N.TsTypeParameter) { - this.tsParseModifiers({ - modified: node, - allowedModifiers: [], - disallowedModifiers: ["in", "out"], - errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions, - }); - } + tsParseInOutModifiers = this.tsParseModifiers.bind(this, { + allowedModifiers: ["in", "out"], + disallowedModifiers: [ + "const", + "public", + "private", + "protected", + "readonly", + "declare", + "abstract", + "override", + ], + errorTemplate: TSErrors.InvalidModifierOnTypeParameter, + }); + + tsParseConstModifier = this.tsParseModifiers.bind(this, { + allowedModifiers: ["const"], + // for better error recover + disallowedModifiers: ["in", "out"], + errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions, + }); + + tsParseInOutConstModifiers = this.tsParseModifiers.bind(this, { + allowedModifiers: ["in", "out", "const"], + disallowedModifiers: [ + "public", + "private", + "protected", + "readonly", + "declare", + "abstract", + "override", + ], + errorTemplate: TSErrors.InvalidModifierOnTypeParameter, + }); tsParseTypeParameter( - parseModifiers: ( - node: Undone, - ) => void = this.tsParseNoneModifiers.bind(this), + parseModifiers: (node: Undone) => void, ): N.TsTypeParameter { const node = this.startNode(); @@ -687,16 +699,14 @@ export default (superClass: ClassWithMixin) => } tsTryParseTypeParameters( - parseModifiers?: ((node: N.TsTypeParameter) => void) | null, + parseModifiers: (node: N.TsTypeParameter) => void, ): N.TsTypeParameterDeclaration | undefined | null { if (this.match(tt.lt)) { return this.tsParseTypeParameters(parseModifiers); } } - tsParseTypeParameters( - parseModifiers?: ((node: N.TsTypeParameter) => void) | null, - ) { + tsParseTypeParameters(parseModifiers: (node: N.TsTypeParameter) => void) { const node = this.startNode(); if (this.match(tt.lt) || this.match(tt.jsxTagStart)) { @@ -739,7 +749,9 @@ export default (superClass: ClassWithMixin) => ? "returnType" : "typeAnnotation"; - signature.typeParameters = this.tsTryParseTypeParameters(); + signature.typeParameters = this.tsTryParseTypeParameters( + this.tsParseConstModifier, + ); this.expect(tt.parenL); signature[paramsKey] = this.tsParseBindingListForSignature(); if (returnTokenRequired) { @@ -922,19 +934,21 @@ export default (superClass: ClassWithMixin) => } } - this.tsParseModifiers({ - modified: node, - allowedModifiers: ["readonly"], - disallowedModifiers: [ - "declare", - "abstract", - "private", - "protected", - "public", - "static", - "override", - ], - }); + this.tsParseModifiers( + { + allowedModifiers: ["readonly"], + disallowedModifiers: [ + "declare", + "abstract", + "private", + "protected", + "public", + "static", + "override", + ], + }, + node, + ); const idx = this.tsTryParseIndexSignature(node); if (idx) { @@ -1699,7 +1713,7 @@ export default (superClass: ClassWithMixin) => } node.typeParameters = this.tsTryParseTypeParameters( - this.tsParseInOutModifiers.bind(this), + this.tsParseInOutConstModifiers, ); if (this.eat(tt._extends)) { node.extends = this.tsParseHeritageClause("extends"); @@ -1718,7 +1732,7 @@ export default (superClass: ClassWithMixin) => node.typeAnnotation = this.tsInType(() => { node.typeParameters = this.tsTryParseTypeParameters( - this.tsParseInOutModifiers.bind(this), + this.tsParseInOutModifiers, ); this.expect(tt.eq); @@ -2186,7 +2200,9 @@ export default (superClass: ClassWithMixin) => const res: Undone | undefined | null = this.tsTryParseAndCatch(() => { const node = this.startNodeAt(startLoc); - node.typeParameters = this.tsParseTypeParameters(); + node.typeParameters = this.tsParseTypeParameters( + this.tsParseConstModifier, + ); // Don't use overloaded parseFunctionParams which would look for "<" again. super.parseFunctionParams(node); node.returnType = this.tsTryParseTypeOrTypePredicateAnnotation(); @@ -2260,16 +2276,18 @@ export default (superClass: ClassWithMixin) => let override = false; if (allowModifiers !== undefined) { const modified: ModifierBase = {}; - this.tsParseModifiers({ + this.tsParseModifiers( + { + allowedModifiers: [ + "public", + "private", + "protected", + "override", + "readonly", + ], + }, modified, - allowedModifiers: [ - "public", - "private", - "protected", - "override", - "readonly", - ], - }); + ); accessibility = modified.accessibility; override = modified.override; readonly = modified.readonly; @@ -2852,13 +2870,15 @@ export default (superClass: ClassWithMixin) => "readonly", "static", ] as const; - this.tsParseModifiers({ - modified: member, - allowedModifiers: modifiers, - disallowedModifiers: ["in", "out"], - stopOnStartOfClassStaticBlock: true, - errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions, - }); + this.tsParseModifiers( + { + allowedModifiers: modifiers, + disallowedModifiers: ["in", "out"], + stopOnStartOfClassStaticBlock: true, + errorTemplate: TSErrors.InvalidModifierOnTypeParameterPositions, + }, + member, + ); const callParseClassMemberWithIsStatic = () => { if (this.tsIsStartOfStaticBlocks()) { @@ -3104,7 +3124,7 @@ export default (superClass: ClassWithMixin) => (node as any).declare ? BIND_TS_AMBIENT : BIND_CLASS, ); const typeParameters = this.tsTryParseTypeParameters( - this.tsParseInOutModifiers.bind(this), + this.tsParseInOutConstModifiers, ); if (typeParameters) node.typeParameters = typeParameters; } @@ -3189,7 +3209,9 @@ export default (superClass: ClassWithMixin) => isConstructor: boolean, allowsDirectSuper: boolean, ): void { - const typeParameters = this.tsTryParseTypeParameters(); + const typeParameters = this.tsTryParseTypeParameters( + this.tsParseConstModifier, + ); if (typeParameters && isConstructor) { this.raise(TSErrors.ConstructorHasTypeParameters, { at: typeParameters, @@ -3219,7 +3241,9 @@ export default (superClass: ClassWithMixin) => isGenerator: boolean, isAsync: boolean, ): void { - const typeParameters = this.tsTryParseTypeParameters(); + const typeParameters = this.tsTryParseTypeParameters( + this.tsParseConstModifier, + ); if (typeParameters) method.typeParameters = typeParameters; super.pushClassPrivateMethod(classBody, method, isGenerator, isAsync); } @@ -3256,7 +3280,9 @@ export default (superClass: ClassWithMixin) => isAccessor: boolean, refExpressionErrors?: ExpressionErrors | null, ) { - const typeParameters = this.tsTryParseTypeParameters(); + const typeParameters = this.tsTryParseTypeParameters( + this.tsParseConstModifier, + ); if (typeParameters) prop.typeParameters = typeParameters; return super.parseObjPropValue( @@ -3272,7 +3298,9 @@ export default (superClass: ClassWithMixin) => } parseFunctionParams(node: N.Function, allowModifiers?: boolean): void { - const typeParameters = this.tsTryParseTypeParameters(); + const typeParameters = this.tsTryParseTypeParameters( + this.tsParseConstModifier, + ); if (typeParameters) node.typeParameters = typeParameters; super.parseFunctionParams(node, allowModifiers); } @@ -3359,7 +3387,7 @@ export default (superClass: ClassWithMixin) => let typeParameters: N.TsTypeParameterDeclaration | undefined | null; const arrow = this.tryParse(abort => { // This is similar to TypeScript's `tryParseParenthesizedArrowFunctionExpression`. - typeParameters = this.tsParseTypeParameters(); + typeParameters = this.tsParseTypeParameters(this.tsParseConstModifier); const expr = super.parseMaybeAssign( refExpressionErrors, afterLeftParse, diff --git a/packages/babel-parser/src/types.d.ts b/packages/babel-parser/src/types.d.ts index 1164ac98f98d..f7bf3c1a5421 100644 --- a/packages/babel-parser/src/types.d.ts +++ b/packages/babel-parser/src/types.d.ts @@ -1053,6 +1053,7 @@ export interface TsTypeParameter extends NodeBase { name: string | Identifier; in?: boolean; out?: boolean; + const?: boolean; constraint?: TsType; default?: TsType; } diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/input.ts new file mode 100644 index 000000000000..0e9aa76b39c1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/input.ts @@ -0,0 +1,24 @@ +function a() {} +function b() {} +function c() {} +declare function d(); +() => {}; +() => {}; + +class A {} +class B {} +class C {} +class D {} +class E {} + +interface I {} +interface J {} +interface K {} +interface L {} +interface M {} + +class _ { + method() {} + method() {} + method() {} +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/output.json new file mode 100644 index 000000000000..5347298fe4a2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-babel-7/output.json @@ -0,0 +1,640 @@ +{ + "type": "File", + "start":0,"end":521,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":24,"column":1,"index":521}}, + "program": { + "type": "Program", + "start":0,"end":521,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":24,"column":1,"index":521}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":24,"index":24}}, + "id": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"a"}, + "name": "a" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":10,"end":19,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":19,"index":19}}, + "params": [ + { + "type": "TSTypeParameter", + "start":11,"end":18,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":18,"index":18}}, + "const": true, + "name": "T" + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start":22,"end":24,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":24,"index":24}}, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":25,"end":59,"loc":{"start":{"line":2,"column":0,"index":25},"end":{"line":2,"column":34,"index":59}}, + "id": { + "type": "Identifier", + "start":34,"end":35,"loc":{"start":{"line":2,"column":9,"index":34},"end":{"line":2,"column":10,"index":35},"identifierName":"b"}, + "name": "b" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":35,"end":54,"loc":{"start":{"line":2,"column":10,"index":35},"end":{"line":2,"column":29,"index":54}}, + "params": [ + { + "type": "TSTypeParameter", + "start":36,"end":53,"loc":{"start":{"line":2,"column":11,"index":36},"end":{"line":2,"column":28,"index":53}}, + "const": true, + "name": "T", + "constraint": { + "type": "TSTypeReference", + "start":52,"end":53,"loc":{"start":{"line":2,"column":27,"index":52},"end":{"line":2,"column":28,"index":53}}, + "typeName": { + "type": "Identifier", + "start":52,"end":53,"loc":{"start":{"line":2,"column":27,"index":52},"end":{"line":2,"column":28,"index":53},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start":57,"end":59,"loc":{"start":{"line":2,"column":32,"index":57},"end":{"line":2,"column":34,"index":59}}, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":60,"end":87,"loc":{"start":{"line":3,"column":0,"index":60},"end":{"line":3,"column":27,"index":87}}, + "id": { + "type": "Identifier", + "start":69,"end":70,"loc":{"start":{"line":3,"column":9,"index":69},"end":{"line":3,"column":10,"index":70},"identifierName":"c"}, + "name": "c" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":70,"end":82,"loc":{"start":{"line":3,"column":10,"index":70},"end":{"line":3,"column":22,"index":82}}, + "params": [ + { + "type": "TSTypeParameter", + "start":71,"end":72,"loc":{"start":{"line":3,"column":11,"index":71},"end":{"line":3,"column":12,"index":72}}, + "name": "T" + }, + { + "type": "TSTypeParameter", + "start":74,"end":81,"loc":{"start":{"line":3,"column":14,"index":74},"end":{"line":3,"column":21,"index":81}}, + "const": true, + "name": "U" + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start":85,"end":87,"loc":{"start":{"line":3,"column":25,"index":85},"end":{"line":3,"column":27,"index":87}}, + "body": [], + "directives": [] + } + }, + { + "type": "TSDeclareFunction", + "start":88,"end":118,"loc":{"start":{"line":4,"column":0,"index":88},"end":{"line":4,"column":30,"index":118}}, + "declare": true, + "id": { + "type": "Identifier", + "start":105,"end":106,"loc":{"start":{"line":4,"column":17,"index":105},"end":{"line":4,"column":18,"index":106},"identifierName":"d"}, + "name": "d" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":106,"end":115,"loc":{"start":{"line":4,"column":18,"index":106},"end":{"line":4,"column":27,"index":115}}, + "params": [ + { + "type": "TSTypeParameter", + "start":107,"end":114,"loc":{"start":{"line":4,"column":19,"index":107},"end":{"line":4,"column":26,"index":114}}, + "const": true, + "name": "T" + } + ] + }, + "params": [] + }, + { + "type": "ExpressionStatement", + "start":119,"end":137,"loc":{"start":{"line":5,"column":0,"index":119},"end":{"line":5,"column":18,"index":137}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":119,"end":136,"loc":{"start":{"line":5,"column":0,"index":119},"end":{"line":5,"column":17,"index":136}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":134,"end":136,"loc":{"start":{"line":5,"column":15,"index":134},"end":{"line":5,"column":17,"index":136}}, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":119,"end":128,"loc":{"start":{"line":5,"column":0,"index":119},"end":{"line":5,"column":9,"index":128}}, + "params": [ + { + "type": "TSTypeParameter", + "start":120,"end":127,"loc":{"start":{"line":5,"column":1,"index":120},"end":{"line":5,"column":8,"index":127}}, + "const": true, + "name": "T" + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start":138,"end":166,"loc":{"start":{"line":6,"column":0,"index":138},"end":{"line":6,"column":28,"index":166}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":138,"end":165,"loc":{"start":{"line":6,"column":0,"index":138},"end":{"line":6,"column":27,"index":165}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":163,"end":165,"loc":{"start":{"line":6,"column":25,"index":163},"end":{"line":6,"column":27,"index":165}}, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":138,"end":157,"loc":{"start":{"line":6,"column":0,"index":138},"end":{"line":6,"column":19,"index":157}}, + "params": [ + { + "type": "TSTypeParameter", + "start":139,"end":156,"loc":{"start":{"line":6,"column":1,"index":139},"end":{"line":6,"column":18,"index":156}}, + "const": true, + "name": "T", + "constraint": { + "type": "TSTypeReference", + "start":155,"end":156,"loc":{"start":{"line":6,"column":17,"index":155},"end":{"line":6,"column":18,"index":156}}, + "typeName": { + "type": "Identifier", + "start":155,"end":156,"loc":{"start":{"line":6,"column":17,"index":155},"end":{"line":6,"column":18,"index":156},"identifierName":"U"}, + "name": "U" + } + } + } + ] + } + } + }, + { + "type": "ClassDeclaration", + "start":168,"end":187,"loc":{"start":{"line":8,"column":0,"index":168},"end":{"line":8,"column":19,"index":187}}, + "id": { + "type": "Identifier", + "start":174,"end":175,"loc":{"start":{"line":8,"column":6,"index":174},"end":{"line":8,"column":7,"index":175},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":175,"end":184,"loc":{"start":{"line":8,"column":7,"index":175},"end":{"line":8,"column":16,"index":184}}, + "params": [ + { + "type": "TSTypeParameter", + "start":176,"end":183,"loc":{"start":{"line":8,"column":8,"index":176},"end":{"line":8,"column":15,"index":183}}, + "const": true, + "name": "T" + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":185,"end":187,"loc":{"start":{"line":8,"column":17,"index":185},"end":{"line":8,"column":19,"index":187}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":188,"end":217,"loc":{"start":{"line":9,"column":0,"index":188},"end":{"line":9,"column":29,"index":217}}, + "id": { + "type": "Identifier", + "start":194,"end":195,"loc":{"start":{"line":9,"column":6,"index":194},"end":{"line":9,"column":7,"index":195},"identifierName":"B"}, + "name": "B" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":195,"end":214,"loc":{"start":{"line":9,"column":7,"index":195},"end":{"line":9,"column":26,"index":214}}, + "params": [ + { + "type": "TSTypeParameter", + "start":196,"end":213,"loc":{"start":{"line":9,"column":8,"index":196},"end":{"line":9,"column":25,"index":213}}, + "const": true, + "name": "T", + "constraint": { + "type": "TSTypeReference", + "start":212,"end":213,"loc":{"start":{"line":9,"column":24,"index":212},"end":{"line":9,"column":25,"index":213}}, + "typeName": { + "type": "Identifier", + "start":212,"end":213,"loc":{"start":{"line":9,"column":24,"index":212},"end":{"line":9,"column":25,"index":213},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":215,"end":217,"loc":{"start":{"line":9,"column":27,"index":215},"end":{"line":9,"column":29,"index":217}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":218,"end":240,"loc":{"start":{"line":10,"column":0,"index":218},"end":{"line":10,"column":22,"index":240}}, + "id": { + "type": "Identifier", + "start":224,"end":225,"loc":{"start":{"line":10,"column":6,"index":224},"end":{"line":10,"column":7,"index":225},"identifierName":"C"}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":225,"end":237,"loc":{"start":{"line":10,"column":7,"index":225},"end":{"line":10,"column":19,"index":237}}, + "params": [ + { + "type": "TSTypeParameter", + "start":226,"end":227,"loc":{"start":{"line":10,"column":8,"index":226},"end":{"line":10,"column":9,"index":227}}, + "name": "T" + }, + { + "type": "TSTypeParameter", + "start":229,"end":236,"loc":{"start":{"line":10,"column":11,"index":229},"end":{"line":10,"column":18,"index":236}}, + "const": true, + "name": "U" + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":238,"end":240,"loc":{"start":{"line":10,"column":20,"index":238},"end":{"line":10,"column":22,"index":240}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":241,"end":263,"loc":{"start":{"line":11,"column":0,"index":241},"end":{"line":11,"column":22,"index":263}}, + "id": { + "type": "Identifier", + "start":247,"end":248,"loc":{"start":{"line":11,"column":6,"index":247},"end":{"line":11,"column":7,"index":248},"identifierName":"D"}, + "name": "D" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":248,"end":260,"loc":{"start":{"line":11,"column":7,"index":248},"end":{"line":11,"column":19,"index":260}}, + "params": [ + { + "type": "TSTypeParameter", + "start":249,"end":259,"loc":{"start":{"line":11,"column":8,"index":249},"end":{"line":11,"column":18,"index":259}}, + "in": true, + "const": true, + "name": "T" + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":261,"end":263,"loc":{"start":{"line":11,"column":20,"index":261},"end":{"line":11,"column":22,"index":263}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":264,"end":286,"loc":{"start":{"line":12,"column":0,"index":264},"end":{"line":12,"column":22,"index":286}}, + "id": { + "type": "Identifier", + "start":270,"end":271,"loc":{"start":{"line":12,"column":6,"index":270},"end":{"line":12,"column":7,"index":271},"identifierName":"E"}, + "name": "E" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":271,"end":283,"loc":{"start":{"line":12,"column":7,"index":271},"end":{"line":12,"column":19,"index":283}}, + "params": [ + { + "type": "TSTypeParameter", + "start":272,"end":282,"loc":{"start":{"line":12,"column":8,"index":272},"end":{"line":12,"column":18,"index":282}}, + "const": true, + "in": true, + "name": "T" + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":284,"end":286,"loc":{"start":{"line":12,"column":20,"index":284},"end":{"line":12,"column":22,"index":286}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":288,"end":311,"loc":{"start":{"line":14,"column":0,"index":288},"end":{"line":14,"column":23,"index":311}}, + "id": { + "type": "Identifier", + "start":298,"end":299,"loc":{"start":{"line":14,"column":10,"index":298},"end":{"line":14,"column":11,"index":299},"identifierName":"I"}, + "name": "I" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":299,"end":308,"loc":{"start":{"line":14,"column":11,"index":299},"end":{"line":14,"column":20,"index":308}}, + "params": [ + { + "type": "TSTypeParameter", + "start":300,"end":307,"loc":{"start":{"line":14,"column":12,"index":300},"end":{"line":14,"column":19,"index":307}}, + "const": true, + "name": "T" + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":309,"end":311,"loc":{"start":{"line":14,"column":21,"index":309},"end":{"line":14,"column":23,"index":311}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":312,"end":345,"loc":{"start":{"line":15,"column":0,"index":312},"end":{"line":15,"column":33,"index":345}}, + "id": { + "type": "Identifier", + "start":322,"end":323,"loc":{"start":{"line":15,"column":10,"index":322},"end":{"line":15,"column":11,"index":323},"identifierName":"J"}, + "name": "J" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":323,"end":342,"loc":{"start":{"line":15,"column":11,"index":323},"end":{"line":15,"column":30,"index":342}}, + "params": [ + { + "type": "TSTypeParameter", + "start":324,"end":341,"loc":{"start":{"line":15,"column":12,"index":324},"end":{"line":15,"column":29,"index":341}}, + "const": true, + "name": "T", + "constraint": { + "type": "TSTypeReference", + "start":340,"end":341,"loc":{"start":{"line":15,"column":28,"index":340},"end":{"line":15,"column":29,"index":341}}, + "typeName": { + "type": "Identifier", + "start":340,"end":341,"loc":{"start":{"line":15,"column":28,"index":340},"end":{"line":15,"column":29,"index":341},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":343,"end":345,"loc":{"start":{"line":15,"column":31,"index":343},"end":{"line":15,"column":33,"index":345}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":346,"end":372,"loc":{"start":{"line":16,"column":0,"index":346},"end":{"line":16,"column":26,"index":372}}, + "id": { + "type": "Identifier", + "start":356,"end":357,"loc":{"start":{"line":16,"column":10,"index":356},"end":{"line":16,"column":11,"index":357},"identifierName":"K"}, + "name": "K" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":357,"end":369,"loc":{"start":{"line":16,"column":11,"index":357},"end":{"line":16,"column":23,"index":369}}, + "params": [ + { + "type": "TSTypeParameter", + "start":358,"end":359,"loc":{"start":{"line":16,"column":12,"index":358},"end":{"line":16,"column":13,"index":359}}, + "name": "T" + }, + { + "type": "TSTypeParameter", + "start":361,"end":368,"loc":{"start":{"line":16,"column":15,"index":361},"end":{"line":16,"column":22,"index":368}}, + "const": true, + "name": "U" + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":370,"end":372,"loc":{"start":{"line":16,"column":24,"index":370},"end":{"line":16,"column":26,"index":372}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":373,"end":399,"loc":{"start":{"line":17,"column":0,"index":373},"end":{"line":17,"column":26,"index":399}}, + "id": { + "type": "Identifier", + "start":383,"end":384,"loc":{"start":{"line":17,"column":10,"index":383},"end":{"line":17,"column":11,"index":384},"identifierName":"L"}, + "name": "L" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":384,"end":396,"loc":{"start":{"line":17,"column":11,"index":384},"end":{"line":17,"column":23,"index":396}}, + "params": [ + { + "type": "TSTypeParameter", + "start":385,"end":395,"loc":{"start":{"line":17,"column":12,"index":385},"end":{"line":17,"column":22,"index":395}}, + "in": true, + "const": true, + "name": "T" + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":397,"end":399,"loc":{"start":{"line":17,"column":24,"index":397},"end":{"line":17,"column":26,"index":399}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":400,"end":426,"loc":{"start":{"line":18,"column":0,"index":400},"end":{"line":18,"column":26,"index":426}}, + "id": { + "type": "Identifier", + "start":410,"end":411,"loc":{"start":{"line":18,"column":10,"index":410},"end":{"line":18,"column":11,"index":411},"identifierName":"M"}, + "name": "M" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":411,"end":423,"loc":{"start":{"line":18,"column":11,"index":411},"end":{"line":18,"column":23,"index":423}}, + "params": [ + { + "type": "TSTypeParameter", + "start":412,"end":422,"loc":{"start":{"line":18,"column":12,"index":412},"end":{"line":18,"column":22,"index":422}}, + "const": true, + "in": true, + "name": "T" + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":424,"end":426,"loc":{"start":{"line":18,"column":24,"index":424},"end":{"line":18,"column":26,"index":426}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":428,"end":521,"loc":{"start":{"line":20,"column":0,"index":428},"end":{"line":24,"column":1,"index":521}}, + "id": { + "type": "Identifier", + "start":434,"end":435,"loc":{"start":{"line":20,"column":6,"index":434},"end":{"line":20,"column":7,"index":435},"identifierName":"_"}, + "name": "_" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":436,"end":521,"loc":{"start":{"line":20,"column":8,"index":436},"end":{"line":24,"column":1,"index":521}}, + "body": [ + { + "type": "ClassMethod", + "start":440,"end":460,"loc":{"start":{"line":21,"column":2,"index":440},"end":{"line":21,"column":22,"index":460}}, + "static": false, + "key": { + "type": "Identifier", + "start":440,"end":446,"loc":{"start":{"line":21,"column":2,"index":440},"end":{"line":21,"column":8,"index":446},"identifierName":"method"}, + "name": "method" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":446,"end":455,"loc":{"start":{"line":21,"column":8,"index":446},"end":{"line":21,"column":17,"index":455}}, + "params": [ + { + "type": "TSTypeParameter", + "start":447,"end":454,"loc":{"start":{"line":21,"column":9,"index":447},"end":{"line":21,"column":16,"index":454}}, + "const": true, + "name": "T" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":458,"end":460,"loc":{"start":{"line":21,"column":20,"index":458},"end":{"line":21,"column":22,"index":460}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":463,"end":493,"loc":{"start":{"line":22,"column":2,"index":463},"end":{"line":22,"column":32,"index":493}}, + "static": false, + "key": { + "type": "Identifier", + "start":463,"end":469,"loc":{"start":{"line":22,"column":2,"index":463},"end":{"line":22,"column":8,"index":469},"identifierName":"method"}, + "name": "method" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":469,"end":488,"loc":{"start":{"line":22,"column":8,"index":469},"end":{"line":22,"column":27,"index":488}}, + "params": [ + { + "type": "TSTypeParameter", + "start":470,"end":487,"loc":{"start":{"line":22,"column":9,"index":470},"end":{"line":22,"column":26,"index":487}}, + "const": true, + "name": "T", + "constraint": { + "type": "TSTypeReference", + "start":486,"end":487,"loc":{"start":{"line":22,"column":25,"index":486},"end":{"line":22,"column":26,"index":487}}, + "typeName": { + "type": "Identifier", + "start":486,"end":487,"loc":{"start":{"line":22,"column":25,"index":486},"end":{"line":22,"column":26,"index":487},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":491,"end":493,"loc":{"start":{"line":22,"column":30,"index":491},"end":{"line":22,"column":32,"index":493}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":496,"end":519,"loc":{"start":{"line":23,"column":2,"index":496},"end":{"line":23,"column":25,"index":519}}, + "static": false, + "key": { + "type": "Identifier", + "start":496,"end":502,"loc":{"start":{"line":23,"column":2,"index":496},"end":{"line":23,"column":8,"index":502},"identifierName":"method"}, + "name": "method" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":502,"end":514,"loc":{"start":{"line":23,"column":8,"index":502},"end":{"line":23,"column":20,"index":514}}, + "params": [ + { + "type": "TSTypeParameter", + "start":503,"end":504,"loc":{"start":{"line":23,"column":9,"index":503},"end":{"line":23,"column":10,"index":504}}, + "name": "T" + }, + { + "type": "TSTypeParameter", + "start":506,"end":513,"loc":{"start":{"line":23,"column":12,"index":506},"end":{"line":23,"column":19,"index":513}}, + "const": true, + "name": "U" + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":517,"end":519,"loc":{"start":{"line":23,"column":23,"index":517},"end":{"line":23,"column":25,"index":519}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/input.ts b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/input.ts new file mode 100644 index 000000000000..cd3e2249f66c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/input.ts @@ -0,0 +1 @@ +type T = {}; diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/options.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/options.json new file mode 100644 index 000000000000..29a3f0e84167 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": false +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/output.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/output.json new file mode 100644 index 000000000000..f04185519076 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid-babel-7/output.json @@ -0,0 +1,42 @@ +{ + "type": "File", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}}, + "errors": [ + "SyntaxError: 'const' modifier cannot appear on a type parameter. (1:7)" + ], + "program": { + "type": "Program", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":15,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":15,"index":15}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "const": true, + "name": "U" + } + ] + }, + "typeAnnotation": { + "type": "TSTypeLiteral", + "start":18,"end":20,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":20,"index":20}}, + "members": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/input.ts b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/input.ts new file mode 100644 index 000000000000..cd3e2249f66c --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/input.ts @@ -0,0 +1 @@ +type T = {}; diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/options.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/output.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/output.json new file mode 100644 index 000000000000..ec7736dbcd26 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters-invalid/output.json @@ -0,0 +1,46 @@ +{ + "type": "File", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}}, + "errors": [ + "SyntaxError: 'const' modifier cannot appear on a type parameter. (1:7)" + ], + "program": { + "type": "Program", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TSTypeAliasDeclaration", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":21,"index":21}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5,"index":5},"end":{"line":1,"column":6,"index":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":6,"end":15,"loc":{"start":{"line":1,"column":6,"index":6},"end":{"line":1,"column":15,"index":15}}, + "params": [ + { + "type": "TSTypeParameter", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "const": true, + "name": { + "type": "Identifier", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13,"index":13},"end":{"line":1,"column":14,"index":14},"identifierName":"U"}, + "name": "U" + } + } + ] + }, + "typeAnnotation": { + "type": "TSTypeLiteral", + "start":18,"end":20,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":20,"index":20}}, + "members": [] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/input.ts b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/input.ts new file mode 100644 index 000000000000..0e9aa76b39c1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/input.ts @@ -0,0 +1,24 @@ +function a() {} +function b() {} +function c() {} +declare function d(); +() => {}; +() => {}; + +class A {} +class B {} +class C {} +class D {} +class E {} + +interface I {} +interface J {} +interface K {} +interface L {} +interface M {} + +class _ { + method() {} + method() {} + method() {} +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/options.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/options.json new file mode 100644 index 000000000000..cbf6d1595427 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/options.json @@ -0,0 +1,3 @@ +{ + "BABEL_8_BREAKING": true +} diff --git a/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/output.json b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/output.json new file mode 100644 index 000000000000..9b681fd4eec7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/typescript/types/const-type-parameters/output.json @@ -0,0 +1,732 @@ +{ + "type": "File", + "start":0,"end":521,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":24,"column":1,"index":521}}, + "program": { + "type": "Program", + "start":0,"end":521,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":24,"column":1,"index":521}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":24,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":24,"index":24}}, + "id": { + "type": "Identifier", + "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"a"}, + "name": "a" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":10,"end":19,"loc":{"start":{"line":1,"column":10,"index":10},"end":{"line":1,"column":19,"index":19}}, + "params": [ + { + "type": "TSTypeParameter", + "start":11,"end":18,"loc":{"start":{"line":1,"column":11,"index":11},"end":{"line":1,"column":18,"index":18}}, + "const": true, + "name": { + "type": "Identifier", + "start":17,"end":18,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":18,"index":18},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start":22,"end":24,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":24,"index":24}}, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":25,"end":59,"loc":{"start":{"line":2,"column":0,"index":25},"end":{"line":2,"column":34,"index":59}}, + "id": { + "type": "Identifier", + "start":34,"end":35,"loc":{"start":{"line":2,"column":9,"index":34},"end":{"line":2,"column":10,"index":35},"identifierName":"b"}, + "name": "b" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":35,"end":54,"loc":{"start":{"line":2,"column":10,"index":35},"end":{"line":2,"column":29,"index":54}}, + "params": [ + { + "type": "TSTypeParameter", + "start":36,"end":53,"loc":{"start":{"line":2,"column":11,"index":36},"end":{"line":2,"column":28,"index":53}}, + "const": true, + "name": { + "type": "Identifier", + "start":42,"end":43,"loc":{"start":{"line":2,"column":17,"index":42},"end":{"line":2,"column":18,"index":43},"identifierName":"T"}, + "name": "T" + }, + "constraint": { + "type": "TSTypeReference", + "start":52,"end":53,"loc":{"start":{"line":2,"column":27,"index":52},"end":{"line":2,"column":28,"index":53}}, + "typeName": { + "type": "Identifier", + "start":52,"end":53,"loc":{"start":{"line":2,"column":27,"index":52},"end":{"line":2,"column":28,"index":53},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start":57,"end":59,"loc":{"start":{"line":2,"column":32,"index":57},"end":{"line":2,"column":34,"index":59}}, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":60,"end":87,"loc":{"start":{"line":3,"column":0,"index":60},"end":{"line":3,"column":27,"index":87}}, + "id": { + "type": "Identifier", + "start":69,"end":70,"loc":{"start":{"line":3,"column":9,"index":69},"end":{"line":3,"column":10,"index":70},"identifierName":"c"}, + "name": "c" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":70,"end":82,"loc":{"start":{"line":3,"column":10,"index":70},"end":{"line":3,"column":22,"index":82}}, + "params": [ + { + "type": "TSTypeParameter", + "start":71,"end":72,"loc":{"start":{"line":3,"column":11,"index":71},"end":{"line":3,"column":12,"index":72}}, + "name": { + "type": "Identifier", + "start":71,"end":72,"loc":{"start":{"line":3,"column":11,"index":71},"end":{"line":3,"column":12,"index":72},"identifierName":"T"}, + "name": "T" + } + }, + { + "type": "TSTypeParameter", + "start":74,"end":81,"loc":{"start":{"line":3,"column":14,"index":74},"end":{"line":3,"column":21,"index":81}}, + "const": true, + "name": { + "type": "Identifier", + "start":80,"end":81,"loc":{"start":{"line":3,"column":20,"index":80},"end":{"line":3,"column":21,"index":81},"identifierName":"U"}, + "name": "U" + } + } + ] + }, + "params": [], + "body": { + "type": "BlockStatement", + "start":85,"end":87,"loc":{"start":{"line":3,"column":25,"index":85},"end":{"line":3,"column":27,"index":87}}, + "body": [], + "directives": [] + } + }, + { + "type": "TSDeclareFunction", + "start":88,"end":118,"loc":{"start":{"line":4,"column":0,"index":88},"end":{"line":4,"column":30,"index":118}}, + "declare": true, + "id": { + "type": "Identifier", + "start":105,"end":106,"loc":{"start":{"line":4,"column":17,"index":105},"end":{"line":4,"column":18,"index":106},"identifierName":"d"}, + "name": "d" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":106,"end":115,"loc":{"start":{"line":4,"column":18,"index":106},"end":{"line":4,"column":27,"index":115}}, + "params": [ + { + "type": "TSTypeParameter", + "start":107,"end":114,"loc":{"start":{"line":4,"column":19,"index":107},"end":{"line":4,"column":26,"index":114}}, + "const": true, + "name": { + "type": "Identifier", + "start":113,"end":114,"loc":{"start":{"line":4,"column":25,"index":113},"end":{"line":4,"column":26,"index":114},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "params": [] + }, + { + "type": "ExpressionStatement", + "start":119,"end":137,"loc":{"start":{"line":5,"column":0,"index":119},"end":{"line":5,"column":18,"index":137}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":119,"end":136,"loc":{"start":{"line":5,"column":0,"index":119},"end":{"line":5,"column":17,"index":136}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":134,"end":136,"loc":{"start":{"line":5,"column":15,"index":134},"end":{"line":5,"column":17,"index":136}}, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":119,"end":128,"loc":{"start":{"line":5,"column":0,"index":119},"end":{"line":5,"column":9,"index":128}}, + "params": [ + { + "type": "TSTypeParameter", + "start":120,"end":127,"loc":{"start":{"line":5,"column":1,"index":120},"end":{"line":5,"column":8,"index":127}}, + "const": true, + "name": { + "type": "Identifier", + "start":126,"end":127,"loc":{"start":{"line":5,"column":7,"index":126},"end":{"line":5,"column":8,"index":127},"identifierName":"T"}, + "name": "T" + } + } + ] + } + } + }, + { + "type": "ExpressionStatement", + "start":138,"end":166,"loc":{"start":{"line":6,"column":0,"index":138},"end":{"line":6,"column":28,"index":166}}, + "expression": { + "type": "ArrowFunctionExpression", + "start":138,"end":165,"loc":{"start":{"line":6,"column":0,"index":138},"end":{"line":6,"column":27,"index":165}}, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":163,"end":165,"loc":{"start":{"line":6,"column":25,"index":163},"end":{"line":6,"column":27,"index":165}}, + "body": [], + "directives": [] + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":138,"end":157,"loc":{"start":{"line":6,"column":0,"index":138},"end":{"line":6,"column":19,"index":157}}, + "params": [ + { + "type": "TSTypeParameter", + "start":139,"end":156,"loc":{"start":{"line":6,"column":1,"index":139},"end":{"line":6,"column":18,"index":156}}, + "const": true, + "name": { + "type": "Identifier", + "start":145,"end":146,"loc":{"start":{"line":6,"column":7,"index":145},"end":{"line":6,"column":8,"index":146},"identifierName":"T"}, + "name": "T" + }, + "constraint": { + "type": "TSTypeReference", + "start":155,"end":156,"loc":{"start":{"line":6,"column":17,"index":155},"end":{"line":6,"column":18,"index":156}}, + "typeName": { + "type": "Identifier", + "start":155,"end":156,"loc":{"start":{"line":6,"column":17,"index":155},"end":{"line":6,"column":18,"index":156},"identifierName":"U"}, + "name": "U" + } + } + } + ] + } + } + }, + { + "type": "ClassDeclaration", + "start":168,"end":187,"loc":{"start":{"line":8,"column":0,"index":168},"end":{"line":8,"column":19,"index":187}}, + "id": { + "type": "Identifier", + "start":174,"end":175,"loc":{"start":{"line":8,"column":6,"index":174},"end":{"line":8,"column":7,"index":175},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":175,"end":184,"loc":{"start":{"line":8,"column":7,"index":175},"end":{"line":8,"column":16,"index":184}}, + "params": [ + { + "type": "TSTypeParameter", + "start":176,"end":183,"loc":{"start":{"line":8,"column":8,"index":176},"end":{"line":8,"column":15,"index":183}}, + "const": true, + "name": { + "type": "Identifier", + "start":182,"end":183,"loc":{"start":{"line":8,"column":14,"index":182},"end":{"line":8,"column":15,"index":183},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":185,"end":187,"loc":{"start":{"line":8,"column":17,"index":185},"end":{"line":8,"column":19,"index":187}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":188,"end":217,"loc":{"start":{"line":9,"column":0,"index":188},"end":{"line":9,"column":29,"index":217}}, + "id": { + "type": "Identifier", + "start":194,"end":195,"loc":{"start":{"line":9,"column":6,"index":194},"end":{"line":9,"column":7,"index":195},"identifierName":"B"}, + "name": "B" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":195,"end":214,"loc":{"start":{"line":9,"column":7,"index":195},"end":{"line":9,"column":26,"index":214}}, + "params": [ + { + "type": "TSTypeParameter", + "start":196,"end":213,"loc":{"start":{"line":9,"column":8,"index":196},"end":{"line":9,"column":25,"index":213}}, + "const": true, + "name": { + "type": "Identifier", + "start":202,"end":203,"loc":{"start":{"line":9,"column":14,"index":202},"end":{"line":9,"column":15,"index":203},"identifierName":"T"}, + "name": "T" + }, + "constraint": { + "type": "TSTypeReference", + "start":212,"end":213,"loc":{"start":{"line":9,"column":24,"index":212},"end":{"line":9,"column":25,"index":213}}, + "typeName": { + "type": "Identifier", + "start":212,"end":213,"loc":{"start":{"line":9,"column":24,"index":212},"end":{"line":9,"column":25,"index":213},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":215,"end":217,"loc":{"start":{"line":9,"column":27,"index":215},"end":{"line":9,"column":29,"index":217}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":218,"end":240,"loc":{"start":{"line":10,"column":0,"index":218},"end":{"line":10,"column":22,"index":240}}, + "id": { + "type": "Identifier", + "start":224,"end":225,"loc":{"start":{"line":10,"column":6,"index":224},"end":{"line":10,"column":7,"index":225},"identifierName":"C"}, + "name": "C" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":225,"end":237,"loc":{"start":{"line":10,"column":7,"index":225},"end":{"line":10,"column":19,"index":237}}, + "params": [ + { + "type": "TSTypeParameter", + "start":226,"end":227,"loc":{"start":{"line":10,"column":8,"index":226},"end":{"line":10,"column":9,"index":227}}, + "name": { + "type": "Identifier", + "start":226,"end":227,"loc":{"start":{"line":10,"column":8,"index":226},"end":{"line":10,"column":9,"index":227},"identifierName":"T"}, + "name": "T" + } + }, + { + "type": "TSTypeParameter", + "start":229,"end":236,"loc":{"start":{"line":10,"column":11,"index":229},"end":{"line":10,"column":18,"index":236}}, + "const": true, + "name": { + "type": "Identifier", + "start":235,"end":236,"loc":{"start":{"line":10,"column":17,"index":235},"end":{"line":10,"column":18,"index":236},"identifierName":"U"}, + "name": "U" + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":238,"end":240,"loc":{"start":{"line":10,"column":20,"index":238},"end":{"line":10,"column":22,"index":240}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":241,"end":263,"loc":{"start":{"line":11,"column":0,"index":241},"end":{"line":11,"column":22,"index":263}}, + "id": { + "type": "Identifier", + "start":247,"end":248,"loc":{"start":{"line":11,"column":6,"index":247},"end":{"line":11,"column":7,"index":248},"identifierName":"D"}, + "name": "D" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":248,"end":260,"loc":{"start":{"line":11,"column":7,"index":248},"end":{"line":11,"column":19,"index":260}}, + "params": [ + { + "type": "TSTypeParameter", + "start":249,"end":259,"loc":{"start":{"line":11,"column":8,"index":249},"end":{"line":11,"column":18,"index":259}}, + "in": true, + "const": true, + "name": { + "type": "Identifier", + "start":258,"end":259,"loc":{"start":{"line":11,"column":17,"index":258},"end":{"line":11,"column":18,"index":259},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":261,"end":263,"loc":{"start":{"line":11,"column":20,"index":261},"end":{"line":11,"column":22,"index":263}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":264,"end":286,"loc":{"start":{"line":12,"column":0,"index":264},"end":{"line":12,"column":22,"index":286}}, + "id": { + "type": "Identifier", + "start":270,"end":271,"loc":{"start":{"line":12,"column":6,"index":270},"end":{"line":12,"column":7,"index":271},"identifierName":"E"}, + "name": "E" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":271,"end":283,"loc":{"start":{"line":12,"column":7,"index":271},"end":{"line":12,"column":19,"index":283}}, + "params": [ + { + "type": "TSTypeParameter", + "start":272,"end":282,"loc":{"start":{"line":12,"column":8,"index":272},"end":{"line":12,"column":18,"index":282}}, + "const": true, + "in": true, + "name": { + "type": "Identifier", + "start":281,"end":282,"loc":{"start":{"line":12,"column":17,"index":281},"end":{"line":12,"column":18,"index":282},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":284,"end":286,"loc":{"start":{"line":12,"column":20,"index":284},"end":{"line":12,"column":22,"index":286}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":288,"end":311,"loc":{"start":{"line":14,"column":0,"index":288},"end":{"line":14,"column":23,"index":311}}, + "id": { + "type": "Identifier", + "start":298,"end":299,"loc":{"start":{"line":14,"column":10,"index":298},"end":{"line":14,"column":11,"index":299},"identifierName":"I"}, + "name": "I" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":299,"end":308,"loc":{"start":{"line":14,"column":11,"index":299},"end":{"line":14,"column":20,"index":308}}, + "params": [ + { + "type": "TSTypeParameter", + "start":300,"end":307,"loc":{"start":{"line":14,"column":12,"index":300},"end":{"line":14,"column":19,"index":307}}, + "const": true, + "name": { + "type": "Identifier", + "start":306,"end":307,"loc":{"start":{"line":14,"column":18,"index":306},"end":{"line":14,"column":19,"index":307},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":309,"end":311,"loc":{"start":{"line":14,"column":21,"index":309},"end":{"line":14,"column":23,"index":311}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":312,"end":345,"loc":{"start":{"line":15,"column":0,"index":312},"end":{"line":15,"column":33,"index":345}}, + "id": { + "type": "Identifier", + "start":322,"end":323,"loc":{"start":{"line":15,"column":10,"index":322},"end":{"line":15,"column":11,"index":323},"identifierName":"J"}, + "name": "J" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":323,"end":342,"loc":{"start":{"line":15,"column":11,"index":323},"end":{"line":15,"column":30,"index":342}}, + "params": [ + { + "type": "TSTypeParameter", + "start":324,"end":341,"loc":{"start":{"line":15,"column":12,"index":324},"end":{"line":15,"column":29,"index":341}}, + "const": true, + "name": { + "type": "Identifier", + "start":330,"end":331,"loc":{"start":{"line":15,"column":18,"index":330},"end":{"line":15,"column":19,"index":331},"identifierName":"T"}, + "name": "T" + }, + "constraint": { + "type": "TSTypeReference", + "start":340,"end":341,"loc":{"start":{"line":15,"column":28,"index":340},"end":{"line":15,"column":29,"index":341}}, + "typeName": { + "type": "Identifier", + "start":340,"end":341,"loc":{"start":{"line":15,"column":28,"index":340},"end":{"line":15,"column":29,"index":341},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":343,"end":345,"loc":{"start":{"line":15,"column":31,"index":343},"end":{"line":15,"column":33,"index":345}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":346,"end":372,"loc":{"start":{"line":16,"column":0,"index":346},"end":{"line":16,"column":26,"index":372}}, + "id": { + "type": "Identifier", + "start":356,"end":357,"loc":{"start":{"line":16,"column":10,"index":356},"end":{"line":16,"column":11,"index":357},"identifierName":"K"}, + "name": "K" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":357,"end":369,"loc":{"start":{"line":16,"column":11,"index":357},"end":{"line":16,"column":23,"index":369}}, + "params": [ + { + "type": "TSTypeParameter", + "start":358,"end":359,"loc":{"start":{"line":16,"column":12,"index":358},"end":{"line":16,"column":13,"index":359}}, + "name": { + "type": "Identifier", + "start":358,"end":359,"loc":{"start":{"line":16,"column":12,"index":358},"end":{"line":16,"column":13,"index":359},"identifierName":"T"}, + "name": "T" + } + }, + { + "type": "TSTypeParameter", + "start":361,"end":368,"loc":{"start":{"line":16,"column":15,"index":361},"end":{"line":16,"column":22,"index":368}}, + "const": true, + "name": { + "type": "Identifier", + "start":367,"end":368,"loc":{"start":{"line":16,"column":21,"index":367},"end":{"line":16,"column":22,"index":368},"identifierName":"U"}, + "name": "U" + } + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":370,"end":372,"loc":{"start":{"line":16,"column":24,"index":370},"end":{"line":16,"column":26,"index":372}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":373,"end":399,"loc":{"start":{"line":17,"column":0,"index":373},"end":{"line":17,"column":26,"index":399}}, + "id": { + "type": "Identifier", + "start":383,"end":384,"loc":{"start":{"line":17,"column":10,"index":383},"end":{"line":17,"column":11,"index":384},"identifierName":"L"}, + "name": "L" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":384,"end":396,"loc":{"start":{"line":17,"column":11,"index":384},"end":{"line":17,"column":23,"index":396}}, + "params": [ + { + "type": "TSTypeParameter", + "start":385,"end":395,"loc":{"start":{"line":17,"column":12,"index":385},"end":{"line":17,"column":22,"index":395}}, + "in": true, + "const": true, + "name": { + "type": "Identifier", + "start":394,"end":395,"loc":{"start":{"line":17,"column":21,"index":394},"end":{"line":17,"column":22,"index":395},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":397,"end":399,"loc":{"start":{"line":17,"column":24,"index":397},"end":{"line":17,"column":26,"index":399}}, + "body": [] + } + }, + { + "type": "TSInterfaceDeclaration", + "start":400,"end":426,"loc":{"start":{"line":18,"column":0,"index":400},"end":{"line":18,"column":26,"index":426}}, + "id": { + "type": "Identifier", + "start":410,"end":411,"loc":{"start":{"line":18,"column":10,"index":410},"end":{"line":18,"column":11,"index":411},"identifierName":"M"}, + "name": "M" + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":411,"end":423,"loc":{"start":{"line":18,"column":11,"index":411},"end":{"line":18,"column":23,"index":423}}, + "params": [ + { + "type": "TSTypeParameter", + "start":412,"end":422,"loc":{"start":{"line":18,"column":12,"index":412},"end":{"line":18,"column":22,"index":422}}, + "const": true, + "in": true, + "name": { + "type": "Identifier", + "start":421,"end":422,"loc":{"start":{"line":18,"column":21,"index":421},"end":{"line":18,"column":22,"index":422},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "body": { + "type": "TSInterfaceBody", + "start":424,"end":426,"loc":{"start":{"line":18,"column":24,"index":424},"end":{"line":18,"column":26,"index":426}}, + "body": [] + } + }, + { + "type": "ClassDeclaration", + "start":428,"end":521,"loc":{"start":{"line":20,"column":0,"index":428},"end":{"line":24,"column":1,"index":521}}, + "id": { + "type": "Identifier", + "start":434,"end":435,"loc":{"start":{"line":20,"column":6,"index":434},"end":{"line":20,"column":7,"index":435},"identifierName":"_"}, + "name": "_" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":436,"end":521,"loc":{"start":{"line":20,"column":8,"index":436},"end":{"line":24,"column":1,"index":521}}, + "body": [ + { + "type": "ClassMethod", + "start":440,"end":460,"loc":{"start":{"line":21,"column":2,"index":440},"end":{"line":21,"column":22,"index":460}}, + "static": false, + "key": { + "type": "Identifier", + "start":440,"end":446,"loc":{"start":{"line":21,"column":2,"index":440},"end":{"line":21,"column":8,"index":446},"identifierName":"method"}, + "name": "method" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":446,"end":455,"loc":{"start":{"line":21,"column":8,"index":446},"end":{"line":21,"column":17,"index":455}}, + "params": [ + { + "type": "TSTypeParameter", + "start":447,"end":454,"loc":{"start":{"line":21,"column":9,"index":447},"end":{"line":21,"column":16,"index":454}}, + "const": true, + "name": { + "type": "Identifier", + "start":453,"end":454,"loc":{"start":{"line":21,"column":15,"index":453},"end":{"line":21,"column":16,"index":454},"identifierName":"T"}, + "name": "T" + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":458,"end":460,"loc":{"start":{"line":21,"column":20,"index":458},"end":{"line":21,"column":22,"index":460}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":463,"end":493,"loc":{"start":{"line":22,"column":2,"index":463},"end":{"line":22,"column":32,"index":493}}, + "static": false, + "key": { + "type": "Identifier", + "start":463,"end":469,"loc":{"start":{"line":22,"column":2,"index":463},"end":{"line":22,"column":8,"index":469},"identifierName":"method"}, + "name": "method" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":469,"end":488,"loc":{"start":{"line":22,"column":8,"index":469},"end":{"line":22,"column":27,"index":488}}, + "params": [ + { + "type": "TSTypeParameter", + "start":470,"end":487,"loc":{"start":{"line":22,"column":9,"index":470},"end":{"line":22,"column":26,"index":487}}, + "const": true, + "name": { + "type": "Identifier", + "start":476,"end":477,"loc":{"start":{"line":22,"column":15,"index":476},"end":{"line":22,"column":16,"index":477},"identifierName":"T"}, + "name": "T" + }, + "constraint": { + "type": "TSTypeReference", + "start":486,"end":487,"loc":{"start":{"line":22,"column":25,"index":486},"end":{"line":22,"column":26,"index":487}}, + "typeName": { + "type": "Identifier", + "start":486,"end":487,"loc":{"start":{"line":22,"column":25,"index":486},"end":{"line":22,"column":26,"index":487},"identifierName":"U"}, + "name": "U" + } + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":491,"end":493,"loc":{"start":{"line":22,"column":30,"index":491},"end":{"line":22,"column":32,"index":493}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":496,"end":519,"loc":{"start":{"line":23,"column":2,"index":496},"end":{"line":23,"column":25,"index":519}}, + "static": false, + "key": { + "type": "Identifier", + "start":496,"end":502,"loc":{"start":{"line":23,"column":2,"index":496},"end":{"line":23,"column":8,"index":502},"identifierName":"method"}, + "name": "method" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "start":502,"end":514,"loc":{"start":{"line":23,"column":8,"index":502},"end":{"line":23,"column":20,"index":514}}, + "params": [ + { + "type": "TSTypeParameter", + "start":503,"end":504,"loc":{"start":{"line":23,"column":9,"index":503},"end":{"line":23,"column":10,"index":504}}, + "name": { + "type": "Identifier", + "start":503,"end":504,"loc":{"start":{"line":23,"column":9,"index":503},"end":{"line":23,"column":10,"index":504},"identifierName":"T"}, + "name": "T" + } + }, + { + "type": "TSTypeParameter", + "start":506,"end":513,"loc":{"start":{"line":23,"column":12,"index":506},"end":{"line":23,"column":19,"index":513}}, + "const": true, + "name": { + "type": "Identifier", + "start":512,"end":513,"loc":{"start":{"line":23,"column":18,"index":512},"end":{"line":23,"column":19,"index":513},"identifierName":"U"}, + "name": "U" + } + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start":517,"end":519,"loc":{"start":{"line":23,"column":23,"index":517},"end":{"line":23,"column":25,"index":519}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index d09439230eac..2e786a3d9219 100644 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -2074,6 +2074,7 @@ export interface TSTypeParameter extends BaseNode { constraint?: TSType | null; default?: TSType | null; name: string; + const?: boolean | null; in?: boolean | null; out?: boolean | null; } diff --git a/packages/babel-types/src/definitions/typescript.ts b/packages/babel-types/src/definitions/typescript.ts index 9475c9dd6675..1cf08c5a7eda 100644 --- a/packages/babel-types/src/definitions/typescript.ts +++ b/packages/babel-types/src/definitions/typescript.ts @@ -632,6 +632,10 @@ defineType("TSTypeParameter", { validate: assertValueType("boolean"), optional: true, }, + const: { + validate: assertValueType("boolean"), + optional: true, + }, constraint: { validate: assertNodeType("TSType"), optional: true,