From 5ed5e5fd9432a5104de7a1e3459d0a6ea5951661 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sun, 19 Feb 2017 18:38:09 +0100 Subject: [PATCH 1/4] Add CatchClause to VariableDeclaration.parent --- src/compiler/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index de42d5d9745..234e5570029 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -651,7 +651,7 @@ export interface VariableDeclaration extends Declaration { kind: SyntaxKind.VariableDeclaration; - parent?: VariableDeclarationList; + parent?: VariableDeclarationList | CatchClause; name: BindingName; // Declared variable name type?: TypeNode; // Optional type annotation initializer?: Expression; // Optional initializer From 077862736d00f9184ae89ae08f46f7b52333ebbd Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sun, 19 Feb 2017 21:26:04 +0100 Subject: [PATCH 2/4] Add parent type for nodes where possible --- src/compiler/types.ts | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 234e5570029..3d93907ae98 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -624,6 +624,7 @@ export interface TypeParameterDeclaration extends Declaration { kind: SyntaxKind.TypeParameter; + parent?: DeclarationWithTypeParameters; name: Identifier; constraint?: TypeNode; default?: TypeNode; @@ -659,11 +660,13 @@ export interface VariableDeclarationList extends Node { kind: SyntaxKind.VariableDeclarationList; + parent?: VariableStatement | ForStatement | ForOfStatement | ForInStatement; declarations: NodeArray; } export interface ParameterDeclaration extends Declaration { kind: SyntaxKind.Parameter; + parent?: SignatureDeclaration; dotDotDotToken?: DotDotDotToken; // Present on rest parameter name: BindingName; // Declared parameter name questionToken?: QuestionToken; // Present on optional parameter @@ -673,6 +676,7 @@ export interface BindingElement extends Declaration { kind: SyntaxKind.BindingElement; + parent?: BindingPattern; propertyName?: PropertyName; // Binding property name (in object binding pattern) dotDotDotToken?: DotDotDotToken; // Present on rest element (in object binding pattern) name: BindingName; // Declared binding element name @@ -754,11 +758,13 @@ export interface ObjectBindingPattern extends Node { kind: SyntaxKind.ObjectBindingPattern; + parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; } export interface ArrayBindingPattern extends Node { kind: SyntaxKind.ArrayBindingPattern; + parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; } @@ -1327,14 +1333,17 @@ export interface TemplateHead extends LiteralLikeNode { kind: SyntaxKind.TemplateHead; + parent?: TemplateExpression; } export interface TemplateMiddle extends LiteralLikeNode { kind: SyntaxKind.TemplateMiddle; + parent?: TemplateSpan; } export interface TemplateTail extends LiteralLikeNode { kind: SyntaxKind.TemplateTail; + parent?: TemplateSpan; } export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; @@ -1349,6 +1358,7 @@ // The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral. export interface TemplateSpan extends Node { kind: SyntaxKind.TemplateSpan; + parent?: TemplateExpression; expression: Expression; literal: TemplateMiddle | TemplateTail; } @@ -1503,6 +1513,7 @@ /// The opening element of a ... JsxElement export interface JsxOpeningElement extends Expression { kind: SyntaxKind.JsxOpeningElement; + parent?: JsxElement; tagName: JsxTagNameExpression; attributes: JsxAttributes; } @@ -1516,6 +1527,7 @@ export interface JsxAttribute extends ObjectLiteralElement { kind: SyntaxKind.JsxAttribute; + parent?: JsxOpeningLikeElement; name: Identifier; /// JSX attribute initializers are optional; is sugar for initializer?: StringLiteral | JsxExpression; @@ -1523,22 +1535,26 @@ export interface JsxSpreadAttribute extends ObjectLiteralElement { kind: SyntaxKind.JsxSpreadAttribute; + parent?: JsxOpeningLikeElement; expression: Expression; } export interface JsxClosingElement extends Node { kind: SyntaxKind.JsxClosingElement; + parent?: JsxElement; tagName: JsxTagNameExpression; } export interface JsxExpression extends Expression { kind: SyntaxKind.JsxExpression; + parent?: JsxElement | JsxAttributeLike; dotDotDotToken?: Token; expression?: Expression; } export interface JsxText extends Node { kind: SyntaxKind.JsxText; + parent?: JsxElement; } export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement; @@ -1680,17 +1696,20 @@ export interface CaseBlock extends Node { kind: SyntaxKind.CaseBlock; + parent?: SwitchStatement; clauses: NodeArray; } export interface CaseClause extends Node { kind: SyntaxKind.CaseClause; + parent?: CaseBlock; expression: Expression; statements: NodeArray; } export interface DefaultClause extends Node { kind: SyntaxKind.DefaultClause; + parent?: CaseBlock; statements: NodeArray; } @@ -1716,6 +1735,7 @@ export interface CatchClause extends Node { kind: SyntaxKind.CatchClause; + parent?: TryStatement; variableDeclaration: VariableDeclaration; block: Block; } @@ -1759,6 +1779,7 @@ export interface HeritageClause extends Node { kind: SyntaxKind.HeritageClause; + parent?: InterfaceDeclaration | ClassDeclaration | ClassExpression; token: SyntaxKind; types?: NodeArray; } @@ -1772,6 +1793,7 @@ export interface EnumMember extends Declaration { kind: SyntaxKind.EnumMember; + parent?: EnumDeclaration; // This does include ComputedPropertyName, but the parser will give an error // if it parses a ComputedPropertyName in an EnumMember name: PropertyName; @@ -1790,7 +1812,8 @@ export interface ModuleDeclaration extends DeclarationStatement { kind: SyntaxKind.ModuleDeclaration; - name: Identifier | StringLiteral; + parent?: ModuleBody | SourceFile; + name: ModuleName; body?: ModuleBody | JSDocNamespaceDeclaration | Identifier; } @@ -1810,6 +1833,7 @@ export interface ModuleBlock extends Node, Statement { kind: SyntaxKind.ModuleBlock; + parent?: ModuleDeclaration; statements: NodeArray; } @@ -1817,6 +1841,7 @@ export interface ImportEqualsDeclaration extends DeclarationStatement { kind: SyntaxKind.ImportEqualsDeclaration; + parent?: SourceFile | ModuleBlock; name: Identifier; // 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external @@ -1826,6 +1851,7 @@ export interface ExternalModuleReference extends Node { kind: SyntaxKind.ExternalModuleReference; + parent?: ImportEqualsDeclaration; expression?: Expression; } @@ -1835,6 +1861,7 @@ // ImportClause information is shown at its declaration below. export interface ImportDeclaration extends Statement { kind: SyntaxKind.ImportDeclaration; + parent?: SourceFile | ModuleBlock; importClause?: ImportClause; moduleSpecifier: Expression; } @@ -1849,12 +1876,14 @@ // import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} export interface ImportClause extends Declaration { kind: SyntaxKind.ImportClause; + parent?: ImportDeclaration; name?: Identifier; // Default binding namedBindings?: NamedImportBindings; } export interface NamespaceImport extends Declaration { kind: SyntaxKind.NamespaceImport; + parent?: ImportClause; name: Identifier; } @@ -1866,17 +1895,20 @@ export interface ExportDeclaration extends DeclarationStatement { kind: SyntaxKind.ExportDeclaration; + parent?: SourceFile | ModuleBlock; exportClause?: NamedExports; moduleSpecifier?: Expression; } export interface NamedImports extends Node { kind: SyntaxKind.NamedImports; + parent?: ImportClause; elements: NodeArray; } export interface NamedExports extends Node { kind: SyntaxKind.NamedExports; + parent?: ExportDeclaration; elements: NodeArray; } @@ -1884,12 +1916,14 @@ export interface ImportSpecifier extends Declaration { 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 { kind: SyntaxKind.ExportSpecifier; + parent?: NamedExports; propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) name: Identifier; // Declared name } @@ -1898,6 +1932,7 @@ export interface ExportAssignment extends DeclarationStatement { kind: SyntaxKind.ExportAssignment; + parent?: SourceFile; isExportEquals?: boolean; expression: Expression; } From 6c9ba46e8b9253e95d899a9d6fbef2aba16ba4b9 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sun, 19 Feb 2017 22:03:32 +0100 Subject: [PATCH 3/4] Fix compile errors --- src/compiler/checker.ts | 2 +- src/services/breakpoints.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 12b55aa818b..541b49acb9a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11546,7 +11546,7 @@ namespace ts { if (isBindingPattern(declaration.parent)) { const parentDeclaration = declaration.parent.parent; const name = declaration.propertyName || declaration.name; - if (isVariableLike(parentDeclaration) && + if (parentDeclaration.kind !== SyntaxKind.BindingElement && parentDeclaration.type && !isBindingPattern(name)) { const text = getTextOfPropertyName(name); diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index c751cf3871b..1f6bec41109 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -370,8 +370,8 @@ namespace ts.BreakpointResolver { } function textSpanFromVariableDeclaration(variableDeclaration: VariableDeclaration): TextSpan { - const declarations = variableDeclaration.parent.declarations; - if (declarations && declarations[0] === variableDeclaration) { + if (variableDeclaration.parent.kind === SyntaxKind.VariableDeclarationList && + variableDeclaration.parent.declarations[0] === variableDeclaration) { // First declaration - include let keyword return textSpan(findPrecedingToken(variableDeclaration.pos, sourceFile, variableDeclaration.parent), variableDeclaration); } @@ -400,8 +400,8 @@ namespace ts.BreakpointResolver { return textSpanFromVariableDeclaration(variableDeclaration); } - const declarations = variableDeclaration.parent.declarations; - if (declarations && declarations[0] !== variableDeclaration) { + if (variableDeclaration.parent.kind === SyntaxKind.VariableDeclarationList && + variableDeclaration.parent.declarations[0] !== variableDeclaration) { // If we cannot set breakpoint on this declaration, set it on previous one // Because the variable declaration may be binding pattern and // we would like to set breakpoint in last binding element if that's the case, From 6ad9fe146a9f80028ecc7b8abc9df7faf7d56824 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 1 Mar 2017 18:08:53 +0100 Subject: [PATCH 4/4] Add parent type to ExpressionWithTypeArguments --- src/compiler/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3d93907ae98..bce435a7e6f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1446,6 +1446,7 @@ export interface ExpressionWithTypeArguments extends TypeNode { kind: SyntaxKind.ExpressionWithTypeArguments; + parent?: HeritageClause; expression: LeftHandSideExpression; typeArguments?: NodeArray; }