-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Get name of declaration uniformly, even for JS-style assignment declarations. #15594
Changes from 2 commits
d35f6c3
aceadeb
573040f
b39c319
6a17532
22f353a
dd94ad2
e81733b
acec74b
9392342
0080c5f
157b777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -603,12 +603,15 @@ namespace ts { | |
|
||
export type DeclarationName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | BindingPattern; | ||
|
||
export interface Declaration extends Node { | ||
export interface RealDeclaration extends Node { | ||
_declarationBrand: any; | ||
name?: DeclarationName; | ||
} | ||
|
||
export interface DeclarationStatement extends Declaration, Statement { | ||
// Binary expressions can be declarations if they are 'exports.foo = bar' expressions in JS files | ||
export type Declaration = RealDeclaration | BinaryExpression; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not name this |
||
|
||
export interface DeclarationStatement extends RealDeclaration, Statement { | ||
name?: Identifier | StringLiteral | NumericLiteral; | ||
} | ||
|
||
|
@@ -622,7 +625,7 @@ namespace ts { | |
expression: LeftHandSideExpression; | ||
} | ||
|
||
export interface TypeParameterDeclaration extends Declaration { | ||
export interface TypeParameterDeclaration extends RealDeclaration { | ||
kind: SyntaxKind.TypeParameter; | ||
parent?: DeclarationWithTypeParameters; | ||
name: Identifier; | ||
|
@@ -633,7 +636,7 @@ namespace ts { | |
expression?: Expression; | ||
} | ||
|
||
export interface SignatureDeclaration extends Declaration { | ||
export interface SignatureDeclaration extends RealDeclaration { | ||
name?: PropertyName; | ||
typeParameters?: NodeArray<TypeParameterDeclaration>; | ||
parameters: NodeArray<ParameterDeclaration>; | ||
|
@@ -650,7 +653,7 @@ namespace ts { | |
|
||
export type BindingName = Identifier | BindingPattern; | ||
|
||
export interface VariableDeclaration extends Declaration { | ||
export interface VariableDeclaration extends RealDeclaration { | ||
kind: SyntaxKind.VariableDeclaration; | ||
parent?: VariableDeclarationList | CatchClause; | ||
name: BindingName; // Declared variable name | ||
|
@@ -664,7 +667,7 @@ namespace ts { | |
declarations: NodeArray<VariableDeclaration>; | ||
} | ||
|
||
export interface ParameterDeclaration extends Declaration { | ||
export interface ParameterDeclaration extends RealDeclaration { | ||
kind: SyntaxKind.Parameter; | ||
parent?: SignatureDeclaration; | ||
dotDotDotToken?: DotDotDotToken; // Present on rest parameter | ||
|
@@ -674,7 +677,7 @@ namespace ts { | |
initializer?: Expression; // Optional initializer | ||
} | ||
|
||
export interface BindingElement extends Declaration { | ||
export interface BindingElement extends RealDeclaration { | ||
kind: SyntaxKind.BindingElement; | ||
parent?: BindingPattern; | ||
propertyName?: PropertyName; // Binding property name (in object binding pattern) | ||
|
@@ -699,7 +702,7 @@ namespace ts { | |
initializer?: Expression; // Optional initializer | ||
} | ||
|
||
export interface ObjectLiteralElement extends Declaration { | ||
export interface ObjectLiteralElement extends RealDeclaration { | ||
_objectLiteralBrandBrand: any; | ||
name?: PropertyName; | ||
} | ||
|
@@ -743,7 +746,7 @@ namespace ts { | |
// SyntaxKind.ShorthandPropertyAssignment | ||
// SyntaxKind.EnumMember | ||
// SyntaxKind.JSDocPropertyTag | ||
export interface VariableLikeDeclaration extends Declaration { | ||
export interface VariableLikeDeclaration extends RealDeclaration { | ||
propertyName?: PropertyName; | ||
dotDotDotToken?: DotDotDotToken; | ||
name: DeclarationName; | ||
|
@@ -752,7 +755,7 @@ namespace ts { | |
initializer?: Expression; | ||
} | ||
|
||
export interface PropertyLikeDeclaration extends Declaration { | ||
export interface PropertyLikeDeclaration extends RealDeclaration { | ||
name: PropertyName; | ||
} | ||
|
||
|
@@ -901,7 +904,7 @@ namespace ts { | |
} | ||
|
||
// A TypeLiteral is the declaration node for an anonymous symbol. | ||
export interface TypeLiteralNode extends TypeNode, Declaration { | ||
export interface TypeLiteralNode extends TypeNode, RealDeclaration { | ||
kind: SyntaxKind.TypeLiteral; | ||
members: NodeArray<TypeElement>; | ||
} | ||
|
@@ -945,7 +948,7 @@ namespace ts { | |
indexType: TypeNode; | ||
} | ||
|
||
export interface MappedTypeNode extends TypeNode, Declaration { | ||
export interface MappedTypeNode extends TypeNode, RealDeclaration { | ||
kind: SyntaxKind.MappedType; | ||
parent?: TypeAliasDeclaration; | ||
readonlyToken?: ReadonlyToken; | ||
|
@@ -1216,8 +1219,7 @@ namespace ts { | |
|
||
export type BinaryOperatorToken = Token<BinaryOperator>; | ||
|
||
// Binary expressions can be declarations if they are 'exports.foo = bar' expressions in JS files | ||
export interface BinaryExpression extends Expression, Declaration { | ||
export interface BinaryExpression extends Expression { | ||
kind: SyntaxKind.BinaryExpression; | ||
left: Expression; | ||
operatorToken: BinaryOperatorToken; | ||
|
@@ -1403,7 +1405,7 @@ namespace ts { | |
* JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type | ||
* ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) | ||
*/ | ||
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElement> extends PrimaryExpression, Declaration { | ||
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElement> extends PrimaryExpression, RealDeclaration { | ||
properties: NodeArray<T>; | ||
} | ||
|
||
|
@@ -1417,7 +1419,7 @@ namespace ts { | |
export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression; | ||
export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; | ||
|
||
export interface PropertyAccessExpression extends MemberExpression, Declaration { | ||
export interface PropertyAccessExpression extends MemberExpression, RealDeclaration { | ||
kind: SyntaxKind.PropertyAccessExpression; | ||
expression: LeftHandSideExpression; | ||
name: Identifier; | ||
|
@@ -1449,7 +1451,7 @@ namespace ts { | |
| SuperElementAccessExpression | ||
; | ||
|
||
export interface CallExpression extends LeftHandSideExpression, Declaration { | ||
export interface CallExpression extends LeftHandSideExpression, RealDeclaration { | ||
kind: SyntaxKind.CallExpression; | ||
expression: LeftHandSideExpression; | ||
typeArguments?: NodeArray<TypeNode>; | ||
|
@@ -1468,7 +1470,7 @@ namespace ts { | |
typeArguments?: NodeArray<TypeNode>; | ||
} | ||
|
||
export interface NewExpression extends PrimaryExpression, Declaration { | ||
export interface NewExpression extends PrimaryExpression, RealDeclaration { | ||
kind: SyntaxKind.NewExpression; | ||
expression: LeftHandSideExpression; | ||
typeArguments?: NodeArray<TypeNode>; | ||
|
@@ -1762,7 +1764,7 @@ namespace ts { | |
|
||
export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration; | ||
|
||
export interface ClassLikeDeclaration extends Declaration { | ||
export interface ClassLikeDeclaration extends RealDeclaration { | ||
name?: Identifier; | ||
typeParameters?: NodeArray<TypeParameterDeclaration>; | ||
heritageClauses?: NodeArray<HeritageClause>; | ||
|
@@ -1778,12 +1780,12 @@ namespace ts { | |
kind: SyntaxKind.ClassExpression; | ||
} | ||
|
||
export interface ClassElement extends Declaration { | ||
export interface ClassElement extends RealDeclaration { | ||
_classElementBrand: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we feasibly remove the brand with this change? |
||
name?: PropertyName; | ||
} | ||
|
||
export interface TypeElement extends Declaration { | ||
export interface TypeElement extends RealDeclaration { | ||
_typeElementBrand: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we feasibly remove the brand with this change? |
||
name?: PropertyName; | ||
questionToken?: QuestionToken; | ||
|
@@ -1811,7 +1813,7 @@ namespace ts { | |
type: TypeNode; | ||
} | ||
|
||
export interface EnumMember extends Declaration { | ||
export interface EnumMember extends RealDeclaration { | ||
kind: SyntaxKind.EnumMember; | ||
parent?: EnumDeclaration; | ||
// This does include ComputedPropertyName, but the parser will give an error | ||
|
@@ -1900,14 +1902,14 @@ namespace ts { | |
// import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns } | ||
// import { a, b as x } from "mod" => name = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} | ||
// import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} | ||
export interface ImportClause extends Declaration { | ||
export interface ImportClause extends RealDeclaration { | ||
kind: SyntaxKind.ImportClause; | ||
parent?: ImportDeclaration; | ||
name?: Identifier; // Default binding | ||
namedBindings?: NamedImportBindings; | ||
} | ||
|
||
export interface NamespaceImport extends Declaration { | ||
export interface NamespaceImport extends RealDeclaration { | ||
kind: SyntaxKind.NamespaceImport; | ||
parent?: ImportClause; | ||
name: Identifier; | ||
|
@@ -1940,14 +1942,14 @@ namespace ts { | |
|
||
export type NamedImportsOrExports = NamedImports | NamedExports; | ||
|
||
export interface ImportSpecifier extends Declaration { | ||
export interface ImportSpecifier extends RealDeclaration { | ||
kind: SyntaxKind.ImportSpecifier; | ||
parent?: NamedImports; | ||
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) | ||
name: Identifier; // Declared name | ||
} | ||
|
||
export interface ExportSpecifier extends Declaration { | ||
export interface ExportSpecifier extends RealDeclaration { | ||
kind: SyntaxKind.ExportSpecifier; | ||
parent?: NamedExports; | ||
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) | ||
|
@@ -2113,7 +2115,7 @@ namespace ts { | |
typeExpression: JSDocTypeExpression; | ||
} | ||
|
||
export interface JSDocTypedefTag extends JSDocTag, Declaration { | ||
export interface JSDocTypedefTag extends JSDocTag, RealDeclaration { | ||
kind: SyntaxKind.JSDocTypedefTag; | ||
fullName?: JSDocNamespaceDeclaration | Identifier; | ||
name?: Identifier; | ||
|
@@ -2247,7 +2249,7 @@ namespace ts { | |
|
||
|
||
// Source files are declarations when they are external modules. | ||
export interface SourceFile extends Declaration { | ||
export interface SourceFile extends RealDeclaration { | ||
kind: SyntaxKind.SourceFile; | ||
statements: NodeArray<Statement>; | ||
endOfFileToken: Token<SyntaxKind.EndOfFileToken>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we find a better name for this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not certain I'm a big fan of renaming this at all.