[babel 8] Use an identifier for TSTypeParameter.name (#12829)
This commit is contained in:
@@ -485,7 +485,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
tsParseTypeParameter(): N.TsTypeParameter {
|
||||
const node: N.TsTypeParameter = this.startNode();
|
||||
node.name = this.parseIdentifierName(node.start);
|
||||
node.name = this.tsParseTypeParameterName();
|
||||
node.constraint = this.tsEatThenParseType(tt._extends);
|
||||
node.default = this.tsEatThenParseType(tt.eq);
|
||||
return this.finishNode(node, "TSTypeParameter");
|
||||
@@ -777,7 +777,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
|
||||
tsParseMappedTypeParameter(): N.TsTypeParameter {
|
||||
const node: N.TsTypeParameter = this.startNode();
|
||||
node.name = this.parseIdentifierName(node.start);
|
||||
node.name = this.tsParseTypeParameterName();
|
||||
node.constraint = this.tsExpectThenParseType(tt._in);
|
||||
return this.finishNode(node, "TSTypeParameter");
|
||||
}
|
||||
@@ -1091,7 +1091,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
const node = this.startNode();
|
||||
this.expectContextual("infer");
|
||||
const typeParameter = this.startNode();
|
||||
typeParameter.name = this.parseIdentifierName(typeParameter.start);
|
||||
typeParameter.name = this.tsParseTypeParameterName();
|
||||
node.typeParameter = this.finishNode(typeParameter, "TSTypeParameter");
|
||||
return this.finishNode(node, "TSInferType");
|
||||
}
|
||||
@@ -3191,6 +3191,11 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
return method;
|
||||
}
|
||||
|
||||
tsParseTypeParameterName(): N.Identifier | string {
|
||||
const typeName: N.Identifier = this.parseIdentifier();
|
||||
return process.env.BABEL_8_BREAKING ? typeName : typeName.name;
|
||||
}
|
||||
|
||||
shouldParseAsAmbientContext(): boolean {
|
||||
return !!this.getPluginOption("typescript", "dts");
|
||||
}
|
||||
|
||||
@@ -960,7 +960,7 @@ export type TsTypeAnnotation = NodeBase & {
|
||||
};
|
||||
|
||||
export type TypeParameterDeclarationBase = NodeBase & {
|
||||
params: $ReadOnlyArray<TypeParameterBase>,
|
||||
params: $ReadOnlyArray<TypeParameter | TsTypeParameter>,
|
||||
};
|
||||
|
||||
export type TypeParameterDeclaration = TypeParameterDeclarationBase & {
|
||||
@@ -973,17 +973,16 @@ export type TsTypeParameterDeclaration = TypeParameterDeclarationBase & {
|
||||
params: $ReadOnlyArray<TsTypeParameter>,
|
||||
};
|
||||
|
||||
export type TypeParameterBase = NodeBase & {
|
||||
name: string,
|
||||
};
|
||||
|
||||
export type TypeParameter = TypeParameterBase & {
|
||||
export type TypeParameter = NodeBase & {
|
||||
type: "TypeParameter",
|
||||
name: string,
|
||||
default?: TypeAnnotation,
|
||||
};
|
||||
|
||||
export type TsTypeParameter = TypeParameterBase & {
|
||||
export type TsTypeParameter = NodeBase & {
|
||||
type: "TSTypeParameter",
|
||||
// TODO(Babel-8): remove string type support
|
||||
name: string | Identifier,
|
||||
constraint?: TsType,
|
||||
default?: TsType,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user