From 8110b8cdd1f77c3d41cf74e59e1bc782e5aa9ac2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 5 Sep 2017 16:30:58 -0700 Subject: [PATCH 1/2] Union types for all the things Migration WIP More betterness Unions, unions everywhere Full type action Finish updating services layer Just change the type --- src/compiler/binder.ts | 8 +- src/compiler/checker.ts | 177 ++-- src/compiler/core.ts | 4 +- src/compiler/declarationEmitter.ts | 6 +- src/compiler/factory.ts | 2 +- src/compiler/parser.ts | 53 +- src/compiler/transformer.ts | 2 +- src/compiler/transformers/es2015.ts | 2 +- src/compiler/transformers/module/module.ts | 2 +- src/compiler/types.ts | 1031 +++++++++++++++----- src/compiler/utilities.ts | 261 +++-- src/compiler/visitor.ts | 10 +- src/services/breakpoints.ts | 4 +- src/services/completions.ts | 2 +- src/services/documentHighlights.ts | 6 +- src/services/findAllReferences.ts | 4 +- src/services/services.ts | 30 +- src/services/signatureHelp.ts | 4 +- src/services/textChanges.ts | 12 +- src/services/types.ts | 2 +- src/services/utilities.ts | 2 +- 21 files changed, 1168 insertions(+), 456 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d6d253e1d77e7..90b8199409795 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2138,7 +2138,7 @@ namespace ts { return updateStrictModeStatementList((node).statements); case SyntaxKind.JSDocParameterTag: - if (node.parent.kind !== SyntaxKind.JSDocTypeLiteral) { + if ((node as Node).parent.kind !== SyntaxKind.JSDocTypeLiteral) { break; } // falls through @@ -2553,11 +2553,11 @@ namespace ts { // report error on all statements except empty ones (isStatementButNotDeclaration(node) && node.kind !== SyntaxKind.EmptyStatement) || // report error on class declarations - node.kind === SyntaxKind.ClassDeclaration || + (node as Declaration).kind === SyntaxKind.ClassDeclaration || // report error on instantiated modules or const-enums only modules if preserveConstEnums is set - (node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(node)) || + ((node as Declaration).kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration((node as Declaration))) || // report error on regular enums and const enums if preserveConstEnums is set - (node.kind === SyntaxKind.EnumDeclaration && (!isConstEnumDeclaration(node) || options.preserveConstEnums)); + ((node as Declaration).kind === SyntaxKind.EnumDeclaration && (!isConstEnumDeclaration(node) || options.preserveConstEnums)); if (reportError) { currentFlow = reportedUnreachableFlow; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 91653c140c83e..ead4c14cfa3bd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -526,9 +526,9 @@ namespace ts { return emitResolver; } - function error(location: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): void { + function error(location: Node | Token, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): void { const diagnostic = location - ? createDiagnosticForNode(location, message, arg0, arg1, arg2) + ? createDiagnosticForNode(location as Node, message, arg0, arg1, arg2) : createCompilerDiagnostic(message, arg0, arg1, arg2); diagnostics.add(diagnostic); } @@ -3930,16 +3930,9 @@ namespace ts { case SyntaxKind.CallSignature: case SyntaxKind.IndexSignature: case SyntaxKind.Parameter: - case SyntaxKind.ModuleBlock: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.TypeLiteral: - case SyntaxKind.TypeReference: - case SyntaxKind.ArrayType: - case SyntaxKind.TupleType: - case SyntaxKind.UnionType: - case SyntaxKind.IntersectionType: - case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); // Default binding, import specifier and namespace import is visible @@ -3961,6 +3954,17 @@ namespace ts { return false; default: + // TODO (weswig): These are not declarations, yet appear here - why? + switch ((node as Node).kind) { + case SyntaxKind.ModuleBlock: + case SyntaxKind.TypeReference: + case SyntaxKind.ArrayType: + case SyntaxKind.TupleType: + case SyntaxKind.UnionType: + case SyntaxKind.IntersectionType: + case SyntaxKind.ParenthesizedType: + return isDeclarationVisible(node.parent); + } return false; } } @@ -4282,7 +4286,7 @@ namespace ts { const typeNode = getEffectiveTypeAnnotationNode(declaration); if (typeNode) { const declaredType = getTypeFromTypeNode(typeNode); - return addOptionality(declaredType, /*optional*/ declaration.questionToken && includeOptionality); + return addOptionality(declaredType, hasQuestionToken(declaration) && includeOptionality); } if ((noImplicitAny || isInJavaScriptFile(declaration)) && @@ -4331,9 +4335,9 @@ namespace ts { } // Use the type of the initializer expression if one is present - if (declaration.initializer) { - const type = checkDeclarationInitializer(declaration); - return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); + if (hasInitializer(declaration)) { + const type = checkDeclarationInitializer(declaration as VariableLikeInitializedDeclaration); + return addOptionality(type, hasQuestionToken(declaration) && includeOptionality); } if (isJsxAttribute(declaration)) { @@ -4506,7 +4510,7 @@ namespace ts { } // Rest parameters default to type any[], other parameters default to type any - type = declaration.dotDotDotToken ? anyArrayType : anyType; + type = hasDotDotDot(declaration) ? anyArrayType : anyType; // Report implicit any errors unless this is a private property within an ambient declaration if (reportErrors && noImplicitAny) { @@ -5127,8 +5131,8 @@ namespace ts { return unknownType; } - const declaration = find(symbol.declarations, d => - d.kind === SyntaxKind.JSDocTypedefTag || d.kind === SyntaxKind.TypeAliasDeclaration); + const declaration = find(symbol.declarations, (d => + d.kind === SyntaxKind.JSDocTypedefTag || d.kind === SyntaxKind.TypeAliasDeclaration) as (d: Declaration) => d is JSDocTypedefTag | TypeAliasDeclaration); let type = getTypeFromTypeNode(declaration.kind === SyntaxKind.JSDocTypedefTag ? declaration.typeExpression : declaration.type); if (popTypeResolution()) { @@ -5317,7 +5321,7 @@ namespace ts { // that specifies an independent type, or if it has no type annotation and no initializer (and thus of type any). function isIndependentVariableLikeDeclaration(node: VariableLikeDeclaration): boolean { const typeNode = getEffectiveTypeAnnotationNode(node); - return typeNode ? isIndependentType(typeNode) : !node.initializer; + return typeNode ? isIndependentType(typeNode) : !hasInitializer(node); } // A function-like declaration is considered independent (free of this references) if it has a return type @@ -7969,7 +7973,7 @@ namespace ts { return links.resolvedType; } - function getTypeFromTypeNode(node: TypeNode): Type { + function getTypeFromTypeNode(node: TypeNode | Identifier | QualifiedName): Type { switch (node.kind) { case SyntaxKind.AnyKeyword: case SyntaxKind.JSDocAllType: @@ -7997,30 +8001,30 @@ namespace ts { case SyntaxKind.ThisKeyword: return getTypeFromThisTypeNode(node); case SyntaxKind.LiteralType: - return getTypeFromLiteralTypeNode(node); + return getTypeFromLiteralTypeNode(node); case SyntaxKind.TypeReference: - return getTypeFromTypeReference(node); + return getTypeFromTypeReference(node); case SyntaxKind.TypePredicate: return booleanType; case SyntaxKind.ExpressionWithTypeArguments: - return getTypeFromTypeReference(node); + return getTypeFromTypeReference(node); case SyntaxKind.TypeQuery: - return getTypeFromTypeQueryNode(node); + return getTypeFromTypeQueryNode(node); case SyntaxKind.ArrayType: - return getTypeFromArrayTypeNode(node); + return getTypeFromArrayTypeNode(node); case SyntaxKind.TupleType: - return getTypeFromTupleTypeNode(node); + return getTypeFromTupleTypeNode(node); case SyntaxKind.UnionType: - return getTypeFromUnionTypeNode(node); + return getTypeFromUnionTypeNode(node); case SyntaxKind.IntersectionType: - return getTypeFromIntersectionTypeNode(node); + return getTypeFromIntersectionTypeNode(node); case SyntaxKind.JSDocNullableType: - return getTypeFromJSDocNullableTypeNode(node); + return getTypeFromJSDocNullableTypeNode(node); case SyntaxKind.ParenthesizedType: case SyntaxKind.JSDocNonNullableType: case SyntaxKind.JSDocOptionalType: case SyntaxKind.JSDocTypeExpression: - return getTypeFromTypeNode((node).type); + return getTypeFromTypeNode(node.type); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.TypeLiteral: @@ -8028,11 +8032,11 @@ namespace ts { case SyntaxKind.JSDocFunctionType: return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); case SyntaxKind.TypeOperator: - return getTypeFromTypeOperatorNode(node); + return getTypeFromTypeOperatorNode(node); case SyntaxKind.IndexedAccessType: - return getTypeFromIndexedAccessTypeNode(node); + return getTypeFromIndexedAccessTypeNode(node); case SyntaxKind.MappedType: - return getTypeFromMappedTypeNode(node); + return getTypeFromMappedTypeNode(node); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case SyntaxKind.Identifier: @@ -8040,7 +8044,7 @@ namespace ts { const symbol = getSymbolAtLocation(node); return symbol && getDeclaredTypeOfSymbol(symbol); case SyntaxKind.JSDocVariadicType: - return getTypeFromJSDocVariadicType(node); + return getTypeFromJSDocVariadicType(node); default: return unknownType; } @@ -8247,7 +8251,7 @@ namespace ts { return node.kind === SyntaxKind.ThisType || forEachChild(node, checkThis); } function checkIdentifier(node: Node): boolean { - return node.kind === SyntaxKind.Identifier && isPartOfTypeNode(node) && getTypeFromTypeNode(node) === tp || forEachChild(node, checkIdentifier); + return node.kind === SyntaxKind.Identifier && isPartOfTypeNode(node) && getTypeFromTypeNode(node) === tp || forEachChild(node, checkIdentifier); } } @@ -8333,35 +8337,35 @@ namespace ts { // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. - function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike | JsxAttributeLike): boolean { + function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike | JsxAttributeLike | JsxExpression | JsxAttributes): boolean { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: case SyntaxKind.MethodDeclaration: - return isContextSensitiveFunctionLikeDeclaration(node); + return isContextSensitiveFunctionLikeDeclaration(node); case SyntaxKind.ObjectLiteralExpression: - return forEach((node).properties, isContextSensitive); + return forEach(node.properties, isContextSensitive); case SyntaxKind.ArrayLiteralExpression: - return forEach((node).elements, isContextSensitive); + return forEach(node.elements, isContextSensitive); case SyntaxKind.ConditionalExpression: - return isContextSensitive((node).whenTrue) || - isContextSensitive((node).whenFalse); + return isContextSensitive(node.whenTrue) || + isContextSensitive(node.whenFalse); case SyntaxKind.BinaryExpression: - return (node).operatorToken.kind === SyntaxKind.BarBarToken && - (isContextSensitive((node).left) || isContextSensitive((node).right)); + return node.operatorToken.kind === SyntaxKind.BarBarToken && + (isContextSensitive(node.left) || isContextSensitive(node.right)); case SyntaxKind.PropertyAssignment: - return isContextSensitive((node).initializer); + return isContextSensitive(node.initializer); case SyntaxKind.ParenthesizedExpression: - return isContextSensitive((node).expression); + return isContextSensitive(node.expression); case SyntaxKind.JsxAttributes: - return forEach((node).properties, isContextSensitive); + return forEach(node.properties, isContextSensitive); case SyntaxKind.JsxAttribute: // If there is no initializer, JSX attribute has a boolean value of true which is not context sensitive. - return (node).initializer && isContextSensitive((node).initializer); + return node.initializer && isContextSensitive(node.initializer); case SyntaxKind.JsxExpression: // It is possible to that node.expression is undefined (e.g
) - return (node).expression && isContextSensitive((node).expression); + return node.expression && isContextSensitive(node.expression); } return false; @@ -12898,7 +12902,13 @@ namespace ts { // Otherwise, in a binding pattern inside a variable or parameter declaration, // the contextual type of an initializer expression is the type annotation of the containing declaration, if present. function getContextualTypeForInitializerExpression(node: Expression): Type { - const declaration = node.parent; + const declaration = node.parent; + if (!isDeclaration(declaration)) { + return undefined; + } + if (!canHaveInitializer(declaration)) { + return undefined; + } if (node === declaration.initializer) { const typeNode = getEffectiveTypeAnnotationNode(declaration); if (typeNode) { @@ -12915,7 +12925,7 @@ namespace ts { } if (isBindingPattern(declaration.parent)) { const parentDeclaration = declaration.parent.parent; - const name = declaration.propertyName || declaration.name; + const name = (declaration as BindingElement).propertyName || declaration.name; if (parentDeclaration.kind !== SyntaxKind.BindingElement) { const parentTypeNode = getEffectiveTypeAnnotationNode(parentDeclaration); if (parentTypeNode && !isBindingPattern(name)) { @@ -13423,7 +13433,7 @@ namespace ts { strictNullChecks ? neverType : undefinedWideningType); } - function isNumericName(name: DeclarationName): boolean { + function isNumericName(name: DeclarationName | QualifiedName): boolean { switch (name.kind) { case SyntaxKind.ComputedPropertyName: return isNumericComputedName(name); @@ -16605,7 +16615,7 @@ namespace ts { const type = getTypeOfSymbol(symbol); if (strictNullChecks) { const declaration = symbol.valueDeclaration; - if (declaration && (declaration).initializer) { + if (declaration && hasInitializer(declaration)) { return getNullableType(type, TypeFlags.Undefined); } } @@ -17537,7 +17547,7 @@ namespace ts { return checkBinaryLikeExpression(node.left, node.operatorToken, node.right, checkMode, node); } - function checkBinaryLikeExpression(left: Expression, operatorToken: Node, right: Expression, checkMode?: CheckMode, errorNode?: Node) { + function checkBinaryLikeExpression(left: Expression, operatorToken: Token, right: Expression, checkMode?: CheckMode, errorNode?: Node) { const operator = operatorToken.kind; if (operator === SyntaxKind.EqualsToken && (left.kind === SyntaxKind.ObjectLiteralExpression || left.kind === SyntaxKind.ArrayLiteralExpression)) { return checkDestructuringAssignment(left, checkExpression(right, checkMode), checkMode); @@ -17877,7 +17887,7 @@ namespace ts { return node.kind === SyntaxKind.TypeAssertionExpression || node.kind === SyntaxKind.AsExpression; } - function checkDeclarationInitializer(declaration: VariableLikeDeclaration) { + function checkDeclarationInitializer(declaration: VariableLikeInitializedDeclaration) { const type = getTypeOfExpression(declaration.initializer, /*cache*/ true); return getCombinedNodeFlags(declaration) & NodeFlags.Const || getCombinedModifierFlags(declaration) & ModifierFlags.Readonly && !isParameterPropertyDeclaration(declaration) || @@ -19084,7 +19094,7 @@ namespace ts { } } - function checkExportsOnMergedDeclarations(node: Node): void { + function checkExportsOnMergedDeclarations(node: Declaration): void { if (!produceDiagnostics) { return; } @@ -19628,7 +19638,7 @@ namespace ts { // we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator. switch (node.kind) { case SyntaxKind.ClassDeclaration: - const constructor = getFirstConstructorWithBody(node); + const constructor = getFirstConstructorWithBody(node); if (constructor) { for (const parameter of constructor.parameters) { markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(parameter)); @@ -19639,19 +19649,19 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - for (const parameter of (node).parameters) { + for (const parameter of node.parameters) { markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(parameter)); } - markDecoratorMedataDataTypeNodeAsReferenced(getEffectiveReturnTypeNode(node)); + markDecoratorMedataDataTypeNodeAsReferenced(getEffectiveReturnTypeNode(node)); break; case SyntaxKind.PropertyDeclaration: - markDecoratorMedataDataTypeNodeAsReferenced(getEffectiveTypeAnnotationNode(node)); + markDecoratorMedataDataTypeNodeAsReferenced(getEffectiveTypeAnnotationNode(node)); break; case SyntaxKind.Parameter: - markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(node)); + markDecoratorMedataDataTypeNodeAsReferenced(getParameterTypeNodeForDecoratorCheck(node)); break; } } @@ -19769,15 +19779,15 @@ namespace ts { switch (node.kind) { case SyntaxKind.SourceFile: case SyntaxKind.ModuleDeclaration: - checkUnusedModuleMembers(node); + checkUnusedModuleMembers(node); break; case SyntaxKind.ClassDeclaration: case SyntaxKind.ClassExpression: - checkUnusedClassMembers(node); - checkUnusedTypeParameters(node); + checkUnusedClassMembers(node); + checkUnusedTypeParameters(node); break; case SyntaxKind.InterfaceDeclaration: - checkUnusedTypeParameters(node); + checkUnusedTypeParameters(node); break; case SyntaxKind.Block: case SyntaxKind.CaseBlock: @@ -19793,10 +19803,10 @@ namespace ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - if ((node).body) { - checkUnusedLocalsAndParameters(node); + if (node.body) { + checkUnusedLocalsAndParameters(node); } - checkUnusedTypeParameters(node); + checkUnusedTypeParameters(node); break; case SyntaxKind.MethodSignature: case SyntaxKind.CallSignature: @@ -19804,10 +19814,10 @@ namespace ts { case SyntaxKind.IndexSignature: case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: - checkUnusedTypeParameters(node); + checkUnusedTypeParameters(node); break; case SyntaxKind.TypeAliasDeclaration: - checkUnusedTypeParameters(node); + checkUnusedTypeParameters(node); break; } } @@ -19858,7 +19868,7 @@ namespace ts { } } - function parameterNameStartsWithUnderscore(parameterName: DeclarationName) { + function parameterNameStartsWithUnderscore(parameterName: DeclarationName | QualifiedName) { return parameterName && isIdentifierThatStartsWithUnderScore(parameterName); } @@ -20157,7 +20167,7 @@ namespace ts { } // Check that a parameter initializer contains no references to parameters declared to the right of itself - function checkParameterInitializer(node: VariableLikeDeclaration): void { + function checkParameterInitializer(node: VariableLikeInitializedDeclaration): void { if (getRootDeclaration(node).kind !== SyntaxKind.Parameter) { return; } @@ -20229,9 +20239,10 @@ namespace ts { } // Check variable, parameter, or property declaration + // TODO: Specialize and remove `VariableLikeDeclarationBase` casts function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { checkDecorators(node); - checkSourceElement(node.type); + checkSourceElement((node as VariableLikeDeclarationBase).type); // JSDoc `function(string, string): string` syntax results in parameters with no name if (!node.name) { @@ -20243,8 +20254,8 @@ namespace ts { // well known symbols. if (node.name.kind === SyntaxKind.ComputedPropertyName) { checkComputedPropertyName(node.name); - if (node.initializer) { - checkExpressionCached(node.initializer); + if (hasInitializer(node)) { + checkExpressionCached((node as VariableLikeInitializedDeclaration).initializer); } } @@ -20263,8 +20274,8 @@ namespace ts { const name = node.propertyName || node.name; const property = getPropertyOfType(parentType, getTextOfPropertyName(name)); markPropertyAsReferenced(property); - if (parent.initializer && property) { - checkPropertyAccessibility(parent, parent.initializer, parentType, property); + if (hasInitializer(parent) && property) { + checkPropertyAccessibility(parent, (parent as VariableLikeInitializedDeclaration).initializer, parentType, property); } } @@ -20277,16 +20288,16 @@ namespace ts { forEach((node.name).elements, checkSourceElement); } // For a parameter declaration with an initializer, error and exit if the containing function doesn't have a body - if (node.initializer && getRootDeclaration(node).kind === SyntaxKind.Parameter && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { + if (hasInitializer(node) && getRootDeclaration(node).kind === SyntaxKind.Parameter && nodeIsMissing((getContainingFunction(node) as FunctionLikeDeclaration).body)) { error(node, Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); return; } // For a binding pattern, validate the initializer and exit if (isBindingPattern(node.name)) { // Don't validate for-in initializer as it is already an error - if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) { - checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined); - checkParameterInitializer(node); + if (hasInitializer(node) && node.parent.parent.kind !== SyntaxKind.ForInStatement) { + checkTypeAssignableTo(checkExpressionCached((node as VariableLikeInitializedDeclaration).initializer), getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined); + checkParameterInitializer(node as VariableLikeInitializedDeclaration); } return; } @@ -20295,9 +20306,9 @@ namespace ts { if (node === symbol.valueDeclaration) { // Node is the primary declaration of the symbol, just validate the initializer // Don't validate for-in initializer as it is already an error - if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) { - checkTypeAssignableTo(checkExpressionCached(node.initializer), type, node, /*headMessage*/ undefined); - checkParameterInitializer(node); + if (hasInitializer(node) && node.parent.parent.kind !== SyntaxKind.ForInStatement) { + checkTypeAssignableTo(checkExpressionCached((node as VariableLikeInitializedDeclaration).initializer), type, node, /*headMessage*/ undefined); + checkParameterInitializer(node as VariableLikeInitializedDeclaration); } } else { @@ -20307,8 +20318,8 @@ namespace ts { if (type !== unknownType && declarationType !== unknownType && !isTypeIdenticalTo(type, declarationType)) { error(node.name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(node.name), typeToString(type), typeToString(declarationType)); } - if (node.initializer) { - checkTypeAssignableTo(checkExpressionCached(node.initializer), declarationType, node, /*headMessage*/ undefined); + if (hasInitializer(node)) { + checkTypeAssignableTo(checkExpressionCached((node as VariableLikeInitializedDeclaration).initializer), declarationType, node, /*headMessage*/ undefined); } if (!areDeclarationFlagsIdentical(node, symbol.valueDeclaration)) { error(getNameOfDeclaration(symbol.valueDeclaration), Diagnostics.All_declarations_of_0_must_have_identical_modifiers, declarationNameToString(node.name)); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 2c0416c071157..a9a6cae9350ac 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -247,6 +247,8 @@ namespace ts { } /** Works like Array.prototype.find, returning `undefined` if no element satisfying the predicate is found. */ + export function find(array: ReadonlyArray, predicate: (element: T, index: number) => element is U): U | undefined; + export function find(array: ReadonlyArray, predicate: (element: T, index: number) => boolean): T | undefined; export function find(array: ReadonlyArray, predicate: (element: T, index: number) => boolean): T | undefined { for (let i = 0; i < array.length; i++) { const value = array[i]; @@ -2338,7 +2340,7 @@ namespace ts { export interface ObjectAllocator { getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node; - getTokenConstructor(): new (kind: TKind, pos?: number, end?: number) => Token; + getTokenConstructor(): new (kind: TKind, pos?: number, end?: number) => Node; // Token is incompatible with the union-based Node, as its union is not lifted out of the kind field getIdentifierConstructor(): new (kind: SyntaxKind.Identifier, pos?: number, end?: number) => Identifier; getSourceFileConstructor(): new (kind: SyntaxKind.SourceFile, pos?: number, end?: number) => SourceFile; getSymbolConstructor(): new (flags: SymbolFlags, name: __String) => Symbol; diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 3de2091502949..c433d3d79a158 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -27,7 +27,7 @@ namespace ts { interface SymbolAccessibilityDiagnostic { errorNode: Node; diagnosticMessage: DiagnosticMessage; - typeName?: DeclarationName; + typeName?: DeclarationName | QualifiedName; } export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { @@ -64,7 +64,7 @@ namespace ts { let currentIdentifiers: Map; let isCurrentFileExternalModule: boolean; let reportedDeclarationError = false; - let errorNameNode: DeclarationName; + let errorNameNode: DeclarationName | QualifiedName; const emitJsDocComments = compilerOptions.removeComments ? noop : writeJsDocComments; const emit = compilerOptions.stripInternal ? stripInternal : emitNode; let needsDeclare = true; @@ -1351,7 +1351,7 @@ namespace ts { } } - function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) { + function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclarationBase) { // if this is property of type literal, // or is parameter of method/call/construct/index signature of type literal // emit only if type is specified diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 4492c3ed47426..43514eed15603 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1108,7 +1108,7 @@ namespace ts { export function createBinary(left: Expression, operator: BinaryOperator | BinaryOperatorToken, right: Expression) { const node = createSynthesizedNode(SyntaxKind.BinaryExpression); - const operatorToken = asToken(operator); + const operatorToken = asToken(operator) as BinaryOperatorToken; const operatorKind = operatorToken.kind; node.left = parenthesizeBinaryOperand(operatorKind, left, /*isLeftSideOfBinary*/ true, /*leftOperand*/ undefined); node.operatorToken = operatorToken; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e30d5dbe1e400..bcd981d1e70a6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -25,7 +25,7 @@ namespace ts { return new (IdentifierConstructor || (IdentifierConstructor = objectAllocator.getIdentifierConstructor()))(kind, pos, end); } else if (!isNodeKind(kind)) { - return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind, pos, end); + return new (TokenConstructor || (TokenConstructor = objectAllocator.getTokenConstructor()))(kind as SyntaxKind, pos, end); } else { return new (NodeConstructor || (NodeConstructor = objectAllocator.getNodeConstructor()))(kind, pos, end); @@ -93,12 +93,13 @@ namespace ts { case SyntaxKind.BindingElement: return visitNodes(cbNode, cbNodes, node.decorators) || visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, (node).propertyName) || - visitNode(cbNode, (node).dotDotDotToken) || - visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).questionToken) || - visitNode(cbNode, (node).type) || - visitNode(cbNode, (node).initializer); + // TODO: Specialize, remove casts to VariableLikeDeclarationBase + visitNode(cbNode, (node).propertyName) || + visitNode(cbNode, (node).dotDotDotToken) || + visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).questionToken) || + visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).initializer); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.CallSignature: @@ -298,9 +299,9 @@ namespace ts { case SyntaxKind.InterfaceDeclaration: return visitNodes(cbNode, cbNodes, node.decorators) || visitNodes(cbNode, cbNodes, node.modifiers) || - visitNode(cbNode, (node).name) || - visitNodes(cbNode, cbNodes, (node).typeParameters) || - visitNodes(cbNode, cbNodes, (node).heritageClauses) || + visitNode(cbNode, node.name) || + visitNodes(cbNode, cbNodes, node.typeParameters) || + visitNodes(cbNode, cbNodes, node.heritageClauses) || visitNodes(cbNode, cbNodes, (node).members); case SyntaxKind.TypeAliasDeclaration: return visitNodes(cbNode, cbNodes, node.decorators) || @@ -1089,7 +1090,7 @@ namespace ts { function parseExpectedToken(t: TKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Token; function parseExpectedToken(t: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { - return parseOptionalToken(t) || + return parseOptionalToken(t) as Node || createMissingNode(t, reportAtCurrentPosition, diagnosticMessage, arg0); } @@ -1180,7 +1181,7 @@ namespace ts { (result as LiteralLikeNode).text = ""; } - return finishNode(result) as T; + return finishNode(result as Node) as T; } function internIdentifier(text: string): string { @@ -1609,11 +1610,11 @@ namespace ts { // Ok, we have a node that looks like it could be reused. Now verify that it is valid // in the current list parsing context that we're currently at. - if (!canReuseNode(node, parsingContext)) { + if (!canReuseNode(node as Node, parsingContext)) { return undefined; } - return node; + return node as Node; } function consumeNode(node: Node) { @@ -6970,14 +6971,14 @@ namespace ts { function moveElementEntirelyPastChangeRange(element: IncrementalElement, isArray: boolean, delta: number, oldText: string, newText: string, aggressiveChecks: boolean) { if (isArray) { - visitArray(element); + visitArray(>element); } else { - visitNode(element); + visitNode(element); } return; - function visitNode(node: IncrementalNode) { + function visitNode(node: Node) { let text = ""; if (aggressiveChecks && shouldCheckNode(node)) { text = oldText.substring(node.pos, node.end); @@ -6985,8 +6986,8 @@ namespace ts { // Ditch any existing LS children we may have created. This way we can avoid // moving them forward. - if (node._children) { - node._children = undefined; + if ((node as IncrementalNode)._children) { + (node as IncrementalNode)._children = undefined; } node.pos += delta; @@ -6996,7 +6997,7 @@ namespace ts { Debug.assert(text === newText.substring(node.pos, node.end)); } - forEachChild(node, visitNode, visitArray); + forEachChild(node as Node, visitNode, visitArray); if (hasJSDocNodes(node)) { for (const jsDocComment of node.jsDoc) { forEachChild(jsDocComment, visitNode, visitArray); @@ -7005,8 +7006,8 @@ namespace ts { checkNodePositions(node, aggressiveChecks); } - function visitArray(array: IncrementalNodeArray) { - array._children = undefined; + function visitArray(array: NodeArray) { + (array as IncrementalNodeArray)._children = undefined; array.pos += delta; array.end += delta; @@ -7016,7 +7017,7 @@ namespace ts { } } - function shouldCheckNode(node: Node) { + function shouldCheckNode(node: BaseNode) { switch (node.kind) { case SyntaxKind.StringLiteral: case SyntaxKind.NumericLiteral: @@ -7145,9 +7146,9 @@ namespace ts { // Adjust the pos or end (or both) of the intersecting element accordingly. adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta); - forEachChild(child, visitNode, visitArray); + forEachChild(child as Node, visitNode as (n: Node) => undefined, visitArray as (n: NodeArray) => undefined); - checkNodePositions(child, aggressiveChecks); + checkNodePositions(child as Node, aggressiveChecks); return; } @@ -7336,7 +7337,7 @@ namespace ts { _children: Node[]; } - export interface IncrementalNode extends Node, IncrementalElement { + export interface IncrementalNode extends BaseNode, IncrementalElement { hasBeenIncrementallyParsed: boolean; } diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index 341c0c9cd45ec..5b620c3283863 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -93,7 +93,7 @@ namespace ts { * @param allowDtsFiles A value indicating whether to allow the transformation of .d.ts files. */ export function transformNodes(resolver: EmitResolver, host: EmitHost, options: CompilerOptions, nodes: ReadonlyArray, transformers: ReadonlyArray>, allowDtsFiles: boolean): TransformationResult { - const enabledSyntaxKindFeatures = new Array(SyntaxKind.Count); + const enabledSyntaxKindFeatures = new Array(SyntaxKind.Count + 1); let lexicalEnvironmentVariableDeclarations: VariableDeclaration[]; let lexicalEnvironmentFunctionDeclarations: FunctionDeclaration[]; let lexicalEnvironmentVariableDeclarationsStack: VariableDeclaration[][] = []; diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index e9c84be51766a..443a0ef269231 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -342,7 +342,7 @@ namespace ts { function shouldVisitNode(node: Node): boolean { return (node.transformFlags & TransformFlags.ContainsES2015) !== 0 || convertedLoopState !== undefined - || (hierarchyFacts & HierarchyFacts.ConstructorWithCapturedSuper && (isStatement(node) || (node.kind === SyntaxKind.Block))) + || (hierarchyFacts & HierarchyFacts.ConstructorWithCapturedSuper && (isStatement(node) || ((node as Node).kind === SyntaxKind.Block))) || (isIterationStatement(node, /*lookInLabeledStatements*/ false) && shouldConvertIterationStatementBody(node)) || (getEmitFlags(node) & EmitFlags.TypeScriptClassWrapper) !== 0; } diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 493f5a43a1f7a..1d4f50d20d5ad 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -1551,7 +1551,7 @@ namespace ts { ? setTextRange( createBinary( node.operand, - createToken(node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken), + node.operator === SyntaxKind.PlusPlusToken ? createToken(SyntaxKind.PlusEqualsToken) : createToken(SyntaxKind.MinusEqualsToken), createLiteral(1) ), /*location*/ node) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 55baf9763c2ed..2eaa2b173c94d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -384,7 +384,7 @@ namespace ts { EndOfDeclarationMarker, // Enum value count - Count, + Count = EndOfDeclarationMarker, // Markers FirstAssignment = EqualsToken, @@ -505,7 +505,7 @@ namespace ts { FailedAndReported = 3 } - export interface Node extends TextRange { + export interface BaseNode extends TextRange { kind: SyntaxKind; flags: NodeFlags; /* @internal */ modifierFlagsCache?: ModifierFlags; @@ -565,14 +565,14 @@ namespace ts { | EndOfFileToken; /* @internal */ - export type MutableNodeArray = NodeArray & T[]; + export type MutableNodeArray = NodeArray & T[]; - export interface NodeArray extends ReadonlyArray, TextRange { + export interface NodeArray extends ReadonlyArray, TextRange { hasTrailingComma?: boolean; /* @internal */ transformFlags?: TransformFlags; } - export interface Token extends Node { + export interface Token extends BaseNode { kind: TKind; } @@ -612,7 +612,7 @@ namespace ts { Node, // Unique name based on the node in the 'original' property. } - export interface Identifier extends PrimaryExpression { + export interface Identifier extends PrimaryExpressionBase { kind: SyntaxKind.Identifier; /** * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) @@ -640,7 +640,7 @@ namespace ts { | GeneratedIdentifierKind.Node; } - export interface QualifiedName extends Node { + export interface QualifiedName extends BaseNode { kind: SyntaxKind.QualifiedName; left: EntityName; right: Identifier; @@ -653,30 +653,30 @@ namespace ts { export type DeclarationName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | BindingPattern; - export interface Declaration extends Node { + export interface DeclarationBase extends BaseNode { _declarationBrand: any; } - export interface NamedDeclaration extends Declaration { + export interface NamedDeclarationBase extends DeclarationBase { name?: DeclarationName; } - export interface DeclarationStatement extends NamedDeclaration, Statement { + export interface DeclarationStatementBase extends NamedDeclarationBase, StatementBase { name?: Identifier | StringLiteral | NumericLiteral; } - export interface ComputedPropertyName extends Node { + export interface ComputedPropertyName extends BaseNode { kind: SyntaxKind.ComputedPropertyName; expression: Expression; } - export interface Decorator extends Node { + export interface Decorator extends BaseNode { kind: SyntaxKind.Decorator; parent?: NamedDeclaration; expression: LeftHandSideExpression; } - export interface TypeParameterDeclaration extends NamedDeclaration { + export interface TypeParameterDeclaration extends NamedDeclarationBase { kind: SyntaxKind.TypeParameter; parent?: DeclarationWithTypeParameters; name: Identifier; @@ -687,7 +687,7 @@ namespace ts { expression?: Expression; } - export interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { + export interface SignatureDeclarationBase extends NamedDeclarationBase, JSDocContainer { kind: SignatureDeclaration["kind"]; name?: PropertyName; typeParameters?: NodeArray; @@ -710,17 +710,17 @@ namespace ts { | FunctionExpression | ArrowFunction; - export interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement { + export interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.CallSignature; } - export interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement { + export interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.ConstructSignature; } export type BindingName = Identifier | BindingPattern; - export interface VariableDeclaration extends NamedDeclaration { + export interface VariableDeclaration extends NamedDeclarationBase { kind: SyntaxKind.VariableDeclaration; parent?: VariableDeclarationList | CatchClause; name: BindingName; // Declared variable name @@ -728,13 +728,13 @@ namespace ts { initializer?: Expression; // Optional initializer } - export interface VariableDeclarationList extends Node { + export interface VariableDeclarationList extends BaseNode { kind: SyntaxKind.VariableDeclarationList; parent?: VariableStatement | ForStatement | ForOfStatement | ForInStatement; declarations: NodeArray; } - export interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { + export interface ParameterDeclaration extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.Parameter; parent?: SignatureDeclaration; dotDotDotToken?: DotDotDotToken; // Present on rest parameter @@ -744,7 +744,7 @@ namespace ts { initializer?: Expression; // Optional initializer } - export interface BindingElement extends NamedDeclaration { + export interface BindingElement extends NamedDeclarationBase { kind: SyntaxKind.BindingElement; parent?: BindingPattern; propertyName?: PropertyName; // Binding property name (in object binding pattern) @@ -753,7 +753,7 @@ namespace ts { initializer?: Expression; // Optional initializer } - export interface PropertySignature extends TypeElement, JSDocContainer { + export interface PropertySignature extends TypeElementBase, JSDocContainer { kind: SyntaxKind.PropertySignature; name: PropertyName; // Declared property name questionToken?: QuestionToken; // Present on optional property @@ -761,7 +761,7 @@ namespace ts { initializer?: Expression; // Optional initializer } - export interface PropertyDeclaration extends ClassElement, JSDocContainer { + export interface PropertyDeclaration extends ClassElementBase, JSDocContainer { kind: SyntaxKind.PropertyDeclaration; questionToken?: QuestionToken; // Present for use with reporting a grammar error name: PropertyName; @@ -769,7 +769,7 @@ namespace ts { initializer?: Expression; // Optional initializer } - export interface ObjectLiteralElement extends NamedDeclaration { + export interface ObjectLiteralElementBase extends NamedDeclarationBase { _objectLiteralBrandBrand: any; name?: PropertyName; } @@ -782,7 +782,7 @@ namespace ts { | AccessorDeclaration ; - export interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { + export interface PropertyAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.PropertyAssignment; name: PropertyName; @@ -790,7 +790,7 @@ namespace ts { initializer: Expression; } - export interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { + export interface ShorthandPropertyAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.ShorthandPropertyAssignment; name: Identifier; @@ -801,23 +801,13 @@ namespace ts { objectAssignmentInitializer?: Expression; } - export interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { + export interface SpreadAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.SpreadAssignment; expression: Expression; } - // SyntaxKind.VariableDeclaration - // SyntaxKind.Parameter - // SyntaxKind.BindingElement - // SyntaxKind.Property - // SyntaxKind.PropertyAssignment - // SyntaxKind.JsxAttribute - // SyntaxKind.ShorthandPropertyAssignment - // SyntaxKind.EnumMember - // SyntaxKind.JSDocPropertyTag - // SyntaxKind.JSDocParameterTag - export interface VariableLikeDeclaration extends NamedDeclaration { + export interface VariableLikeDeclarationBase extends NamedDeclarationBase { propertyName?: PropertyName; dotDotDotToken?: DotDotDotToken; name: DeclarationName; @@ -825,18 +815,34 @@ namespace ts { type?: TypeNode; initializer?: Expression; } - - export interface PropertyLikeDeclaration extends NamedDeclaration { - name: PropertyName; - } - - export interface ObjectBindingPattern extends Node { + export type VariableLikeDeclaration = + | VariableDeclaration + | ParameterDeclaration + | BindingElement + | PropertyDeclaration + | PropertySignature + | PropertyAssignment + | JsxAttribute + | ShorthandPropertyAssignment + | EnumMember + | JSDocPropertyLikeTag; + + export type VariableLikeInitializedDeclaration = + | VariableDeclaration + | ParameterDeclaration + | BindingElement + | PropertyDeclaration + | PropertyAssignment + | JsxAttribute + | EnumMember; + + export interface ObjectBindingPattern extends BaseNode { kind: SyntaxKind.ObjectBindingPattern; parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; } - export interface ArrayBindingPattern extends Node { + export interface ArrayBindingPattern extends BaseNode { kind: SyntaxKind.ArrayBindingPattern; parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; @@ -879,13 +885,13 @@ namespace ts { | ConstructSignatureDeclaration | CallSignatureDeclaration; - export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { + export interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatementBase { kind: SyntaxKind.FunctionDeclaration; name?: Identifier; body?: FunctionBody; } - export interface MethodSignature extends SignatureDeclarationBase, TypeElement { + export interface MethodSignature extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.MethodSignature; name: PropertyName; } @@ -899,27 +905,27 @@ namespace ts { // Because of this, it may be necessary to determine what sort of MethodDeclaration you have // at later stages of the compiler pipeline. In that case, you can either check the parent kind // of the method, or use helpers like isObjectLiteralMethodDeclaration - export interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + export interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.MethodDeclaration; name: PropertyName; body?: FunctionBody; } - export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer { + export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, JSDocContainer { kind: SyntaxKind.Constructor; parent?: ClassDeclaration | ClassExpression; body?: FunctionBody; } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ - export interface SemicolonClassElement extends ClassElement { + export interface SemicolonClassElement extends ClassElementBase { kind: SyntaxKind.SemicolonClassElement; parent?: ClassDeclaration | ClassExpression; } // See the comment on MethodDeclaration for the intuition behind GetAccessorDeclaration being a // ClassElement and an ObjectLiteralElement. - export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.GetAccessor; parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression; name: PropertyName; @@ -928,7 +934,7 @@ namespace ts { // See the comment on MethodDeclaration for the intuition behind SetAccessorDeclaration being a // ClassElement and an ObjectLiteralElement. - export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.SetAccessor; parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression; name: PropertyName; @@ -937,109 +943,95 @@ namespace ts { export type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; - export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { + export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElementBase, TypeElementBase { kind: SyntaxKind.IndexSignature; parent?: ClassDeclaration | ClassExpression | InterfaceDeclaration | TypeLiteralNode; } - export interface TypeNode extends Node { + export interface TypeNodeBase extends BaseNode { _typeNodeBrand: any; } - export interface KeywordTypeNode extends TypeNode { - kind: SyntaxKind.AnyKeyword - | SyntaxKind.NumberKeyword - | SyntaxKind.ObjectKeyword - | SyntaxKind.BooleanKeyword - | SyntaxKind.StringKeyword - | SyntaxKind.SymbolKeyword - | SyntaxKind.ThisKeyword - | SyntaxKind.VoidKeyword - | SyntaxKind.UndefinedKeyword - | SyntaxKind.NullKeyword - | SyntaxKind.NeverKeyword; - } - - export interface ThisTypeNode extends TypeNode { + export interface ThisTypeNode extends TypeNodeBase { kind: SyntaxKind.ThisType; } export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; - export interface FunctionTypeNode extends TypeNode, SignatureDeclarationBase { + export interface FunctionTypeNode extends TypeNodeBase, SignatureDeclarationBase { kind: SyntaxKind.FunctionType; } - export interface ConstructorTypeNode extends TypeNode, SignatureDeclarationBase { + export interface ConstructorTypeNode extends TypeNodeBase, SignatureDeclarationBase { kind: SyntaxKind.ConstructorType; } export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; - export interface TypeReferenceNode extends TypeNode { + export interface TypeReferenceNode extends TypeNodeBase { kind: SyntaxKind.TypeReference; typeName: EntityName; typeArguments?: NodeArray; } - export interface TypePredicateNode extends TypeNode { + export interface TypePredicateNode extends TypeNodeBase { kind: SyntaxKind.TypePredicate; parent?: SignatureDeclaration; parameterName: Identifier | ThisTypeNode; type: TypeNode; } - export interface TypeQueryNode extends TypeNode { + export interface TypeQueryNode extends TypeNodeBase { kind: SyntaxKind.TypeQuery; exprName: EntityName; } // A TypeLiteral is the declaration node for an anonymous symbol. - export interface TypeLiteralNode extends TypeNode, Declaration { + export interface TypeLiteralNode extends TypeNodeBase, DeclarationBase { kind: SyntaxKind.TypeLiteral; members: NodeArray; } - export interface ArrayTypeNode extends TypeNode { + export interface ArrayTypeNode extends TypeNodeBase { kind: SyntaxKind.ArrayType; elementType: TypeNode; } - export interface TupleTypeNode extends TypeNode { + export interface TupleTypeNode extends TypeNodeBase { kind: SyntaxKind.TupleType; elementTypes: NodeArray; } export type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; - export interface UnionTypeNode extends TypeNode { + export interface UnionTypeNode extends TypeNodeBase { kind: SyntaxKind.UnionType; types: NodeArray; } - export interface IntersectionTypeNode extends TypeNode { + export interface IntersectionTypeNode extends TypeNodeBase { kind: SyntaxKind.IntersectionType; types: NodeArray; } - export interface ParenthesizedTypeNode extends TypeNode { + export interface ParenthesizedTypeNode extends TypeNodeBase { kind: SyntaxKind.ParenthesizedType; type: TypeNode; } - export interface TypeOperatorNode extends TypeNode { + export interface TypeOperatorNode extends TypeNodeBase { kind: SyntaxKind.TypeOperator; operator: SyntaxKind.KeyOfKeyword; type: TypeNode; } - export interface IndexedAccessTypeNode extends TypeNode { + export interface IndexedAccessTypeNode extends TypeNodeBase { kind: SyntaxKind.IndexedAccessType; objectType: TypeNode; indexType: TypeNode; } - export interface MappedTypeNode extends TypeNode, Declaration { + export interface MappedTypeNode extends TypeNodeBase, DeclarationBase { kind: SyntaxKind.MappedType; readonlyToken?: ReadonlyToken; typeParameter: TypeParameterDeclaration; @@ -1047,12 +1039,12 @@ namespace ts { type?: TypeNode; } - export interface LiteralTypeNode extends TypeNode { + export interface LiteralTypeNode extends TypeNodeBase { kind: SyntaxKind.LiteralType; literal: Expression; } - export interface StringLiteral extends LiteralExpression { + export interface StringLiteral extends LiteralExpressionBase { kind: SyntaxKind.StringLiteral; /* @internal */ textSourceNode?: Identifier | StringLiteral | NumericLiteral; // Allows a StringLiteral to get its text from another node (used by transforms). /* @internal */ singleQuote?: boolean; @@ -1065,28 +1057,28 @@ namespace ts { // checker actually thinks you have something of the right type. Note: the brands are // never actually given values. At runtime they have zero cost. - export interface Expression extends Node { + export interface ExpressionBase extends BaseNode { _expressionBrand: any; } - export interface OmittedExpression extends Expression { + export interface OmittedExpression extends ExpressionBase { kind: SyntaxKind.OmittedExpression; } // Represents an expression that is elided as part of a transformation to emit comments on a // not-emitted node. The 'expression' property of a PartiallyEmittedExpression should be emitted. - export interface PartiallyEmittedExpression extends LeftHandSideExpression { + export interface PartiallyEmittedExpression extends LeftHandSideExpressionBase { kind: SyntaxKind.PartiallyEmittedExpression; expression: Expression; } - export interface UnaryExpression extends Expression { + export interface UnaryExpressionBase extends ExpressionBase { _unaryExpressionBrand: any; } /** Deprecated, please use UpdateExpression */ export type IncrementExpression = UpdateExpression; - export interface UpdateExpression extends UnaryExpression { + export interface UpdateExpressionBase extends UnaryExpressionBase { _updateExpressionBrand: any; } @@ -1100,7 +1092,7 @@ namespace ts { | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; - export interface PrefixUnaryExpression extends UpdateExpression { + export interface PrefixUnaryExpression extends UpdateExpressionBase { kind: SyntaxKind.PrefixUnaryExpression; operator: PrefixUnaryOperator; operand: UnaryExpression; @@ -1112,65 +1104,65 @@ namespace ts { | SyntaxKind.MinusMinusToken ; - export interface PostfixUnaryExpression extends UpdateExpression { + export interface PostfixUnaryExpression extends UpdateExpressionBase { kind: SyntaxKind.PostfixUnaryExpression; operand: LeftHandSideExpression; operator: PostfixUnaryOperator; } - export interface LeftHandSideExpression extends UpdateExpression { + export interface LeftHandSideExpressionBase extends UpdateExpressionBase { _leftHandSideExpressionBrand: any; } - export interface MemberExpression extends LeftHandSideExpression { + export interface MemberExpressionBase extends LeftHandSideExpressionBase { _memberExpressionBrand: any; } - export interface PrimaryExpression extends MemberExpression { + export interface PrimaryExpressionBase extends MemberExpressionBase { _primaryExpressionBrand: any; } - export interface NullLiteral extends PrimaryExpression, TypeNode { + export interface NullLiteral extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.NullKeyword; } - export interface BooleanLiteral extends PrimaryExpression, TypeNode { + export interface BooleanLiteral extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword; } - export interface ThisExpression extends PrimaryExpression, KeywordTypeNode { + export interface ThisExpression extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.ThisKeyword; } - export interface SuperExpression extends PrimaryExpression { + export interface SuperExpression extends PrimaryExpressionBase { kind: SyntaxKind.SuperKeyword; } - export interface ImportExpression extends PrimaryExpression { + export interface ImportExpression extends PrimaryExpressionBase { kind: SyntaxKind.ImportKeyword; } - export interface DeleteExpression extends UnaryExpression { + export interface DeleteExpression extends UnaryExpressionBase { kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; } - export interface TypeOfExpression extends UnaryExpression { + export interface TypeOfExpression extends UnaryExpressionBase { kind: SyntaxKind.TypeOfExpression; expression: UnaryExpression; } - export interface VoidExpression extends UnaryExpression { + export interface VoidExpression extends UnaryExpressionBase { kind: SyntaxKind.VoidExpression; expression: UnaryExpression; } - export interface AwaitExpression extends UnaryExpression { + export interface AwaitExpression extends UnaryExpressionBase { kind: SyntaxKind.AwaitExpression; expression: UnaryExpression; } - export interface YieldExpression extends Expression { + export interface YieldExpression extends ExpressionBase { kind: SyntaxKind.YieldExpression; asteriskToken?: AsteriskToken; expression?: Expression; @@ -1313,16 +1305,83 @@ namespace ts { | SyntaxKind.CommaToken ; - export type BinaryOperatorToken = Token; - - export interface BinaryExpression extends Expression, Declaration { + export type BinaryOperatorToken = + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token; + + // Small check to verify in the type system that BinaryOperatorToken["kind"] and BinaryOperator are the same + if (!!false) { + let x: BinaryOperatorToken["kind"]; + let y: BinaryOperator; + x = y; + y = x; + } + + export interface BinaryExpression extends ExpressionBase, DeclarationBase { kind: SyntaxKind.BinaryExpression; left: Expression; operatorToken: BinaryOperatorToken; right: Expression; } - export type AssignmentOperatorToken = Token; + export type AssignmentOperatorToken = + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token; + + // Small check to verify in the type system that AssignmentOperatorToken["kind"] and AssignmentOperator are the same + if (!!false) { + let x: AssignmentOperatorToken["kind"]; + let y: AssignmentOperator; + x = y; + y = x; + } export interface AssignmentExpression extends BinaryExpression { left: LeftHandSideExpression; @@ -1381,7 +1440,7 @@ namespace ts { export type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; - export interface ConditionalExpression extends Expression { + export interface ConditionalExpression extends ExpressionBase { kind: SyntaxKind.ConditionalExpression; condition: Expression; questionToken: QuestionToken; @@ -1393,13 +1452,13 @@ namespace ts { export type FunctionBody = Block; export type ConciseBody = FunctionBody | Expression; - export interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer { + export interface FunctionExpression extends PrimaryExpressionBase, FunctionLikeDeclarationBase, JSDocContainer { kind: SyntaxKind.FunctionExpression; name?: Identifier; body: FunctionBody; // Required, whereas the member inherited from FunctionDeclaration is optional } - export interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer { + export interface ArrowFunction extends ExpressionBase, FunctionLikeDeclarationBase, JSDocContainer { kind: SyntaxKind.ArrowFunction; equalsGreaterThanToken: EqualsGreaterThanToken; body: ConciseBody; @@ -1408,7 +1467,7 @@ namespace ts { // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". - export interface LiteralLikeNode extends Node { + export interface LiteralLikeNodeBase extends BaseNode { text: string; isUnterminated?: boolean; hasExtendedUnicodeEscape?: boolean; @@ -1417,15 +1476,15 @@ namespace ts { // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". - export interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { + export interface LiteralExpressionBase extends LiteralLikeNodeBase, PrimaryExpressionBase { _literalExpressionBrand: any; } - export interface RegularExpressionLiteral extends LiteralExpression { + export interface RegularExpressionLiteral extends LiteralExpressionBase { kind: SyntaxKind.RegularExpressionLiteral; } - export interface NoSubstitutionTemplateLiteral extends LiteralExpression { + export interface NoSubstitutionTemplateLiteral extends LiteralExpressionBase { kind: SyntaxKind.NoSubstitutionTemplateLiteral; } @@ -1440,30 +1499,30 @@ namespace ts { BinaryOrOctalSpecifier = BinarySpecifier | OctalSpecifier, } - export interface NumericLiteral extends LiteralExpression { + export interface NumericLiteral extends LiteralExpressionBase { kind: SyntaxKind.NumericLiteral; /* @internal */ numericLiteralFlags?: NumericLiteralFlags; } - export interface TemplateHead extends LiteralLikeNode { + export interface TemplateHead extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateHead; parent?: TemplateExpression; } - export interface TemplateMiddle extends LiteralLikeNode { + export interface TemplateMiddle extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateMiddle; parent?: TemplateSpan; } - export interface TemplateTail extends LiteralLikeNode { + export interface TemplateTail extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateTail; parent?: TemplateSpan; } export type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; - export interface TemplateExpression extends PrimaryExpression { + export interface TemplateExpression extends PrimaryExpressionBase { kind: SyntaxKind.TemplateExpression; head: TemplateHead; templateSpans: NodeArray; @@ -1471,26 +1530,26 @@ namespace ts { // Each of these corresponds to a substitution expression and a template literal, in that order. // The template literal must have kind TemplateMiddleLiteral or TemplateTailLiteral. - export interface TemplateSpan extends Node { + export interface TemplateSpan extends BaseNode { kind: SyntaxKind.TemplateSpan; parent?: TemplateExpression; expression: Expression; literal: TemplateMiddle | TemplateTail; } - export interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { + export interface ParenthesizedExpression extends PrimaryExpressionBase, JSDocContainer { kind: SyntaxKind.ParenthesizedExpression; expression: Expression; } - export interface ArrayLiteralExpression extends PrimaryExpression { + export interface ArrayLiteralExpression extends PrimaryExpressionBase { kind: SyntaxKind.ArrayLiteralExpression; elements: NodeArray; /* @internal */ multiLine?: boolean; } - export interface SpreadElement extends Expression { + export interface SpreadElement extends ExpressionBase { kind: SyntaxKind.SpreadElement; parent?: ArrayLiteralExpression | CallExpression | NewExpression; expression: Expression; @@ -1502,7 +1561,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 extends PrimaryExpression, Declaration { + export interface ObjectLiteralExpressionBase extends PrimaryExpressionBase, DeclarationBase { properties: NodeArray; } @@ -1516,7 +1575,7 @@ namespace ts { export type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression; export type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; - export interface PropertyAccessExpression extends MemberExpression, NamedDeclaration { + export interface PropertyAccessExpression extends MemberExpressionBase, NamedDeclarationBase { kind: SyntaxKind.PropertyAccessExpression; expression: LeftHandSideExpression; name: Identifier; @@ -1532,7 +1591,7 @@ namespace ts { expression: EntityNameExpression; } - export interface ElementAccessExpression extends MemberExpression { + export interface ElementAccessExpression extends MemberExpressionBase { kind: SyntaxKind.ElementAccessExpression; expression: LeftHandSideExpression; argumentExpression?: Expression; @@ -1545,7 +1604,7 @@ namespace ts { // see: https://tc39.github.io/ecma262/#prod-SuperProperty export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; - export interface CallExpression extends LeftHandSideExpression, Declaration { + export interface CallExpression extends LeftHandSideExpressionBase, DeclarationBase { kind: SyntaxKind.CallExpression; expression: LeftHandSideExpression; typeArguments?: NodeArray; @@ -1561,21 +1620,21 @@ namespace ts { expression: ImportExpression; } - export interface ExpressionWithTypeArguments extends TypeNode { + export interface ExpressionWithTypeArguments extends TypeNodeBase { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause; expression: LeftHandSideExpression; typeArguments?: NodeArray; } - export interface NewExpression extends PrimaryExpression, Declaration { + export interface NewExpression extends PrimaryExpressionBase, DeclarationBase { kind: SyntaxKind.NewExpression; expression: LeftHandSideExpression; typeArguments?: NodeArray; arguments?: NodeArray; } - export interface TaggedTemplateExpression extends MemberExpression { + export interface TaggedTemplateExpression extends MemberExpressionBase { kind: SyntaxKind.TaggedTemplateExpression; tag: LeftHandSideExpression; template: TemplateLiteral; @@ -1583,13 +1642,13 @@ namespace ts { export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement; - export interface AsExpression extends Expression { + export interface AsExpression extends ExpressionBase { kind: SyntaxKind.AsExpression; expression: Expression; type: TypeNode; } - export interface TypeAssertion extends UnaryExpression { + export interface TypeAssertion extends UnaryExpressionBase { kind: SyntaxKind.TypeAssertionExpression; type: TypeNode; expression: UnaryExpression; @@ -1597,21 +1656,21 @@ namespace ts { export type AssertionExpression = TypeAssertion | AsExpression; - export interface NonNullExpression extends LeftHandSideExpression { + export interface NonNullExpression extends LeftHandSideExpressionBase { kind: SyntaxKind.NonNullExpression; expression: Expression; } // NOTE: MetaProperty is really a MemberExpression, but we consider it a PrimaryExpression // for the same reasons we treat NewExpression as a PrimaryExpression. - export interface MetaProperty extends PrimaryExpression { + export interface MetaProperty extends PrimaryExpressionBase { kind: SyntaxKind.MetaProperty; keywordToken: SyntaxKind.NewKeyword; name: Identifier; } /// A JSX expression of the form ... - export interface JsxElement extends PrimaryExpression { + export interface JsxElement extends PrimaryExpressionBase { kind: SyntaxKind.JsxElement; openingElement: JsxOpeningElement; children: NodeArray; @@ -1626,11 +1685,12 @@ namespace ts { export type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression; export interface JsxAttributes extends ObjectLiteralExpressionBase { + kind: SyntaxKind.JsxAttributes; parent?: JsxOpeningLikeElement; } /// The opening element of a ... JsxElement - export interface JsxOpeningElement extends Expression { + export interface JsxOpeningElement extends ExpressionBase { kind: SyntaxKind.JsxOpeningElement; parent?: JsxElement; tagName: JsxTagNameExpression; @@ -1638,13 +1698,13 @@ namespace ts { } /// A JSX expression of the form - export interface JsxSelfClosingElement extends PrimaryExpression { + export interface JsxSelfClosingElement extends PrimaryExpressionBase { kind: SyntaxKind.JsxSelfClosingElement; tagName: JsxTagNameExpression; attributes: JsxAttributes; } - export interface JsxAttribute extends ObjectLiteralElement { + export interface JsxAttribute extends ObjectLiteralElementBase { kind: SyntaxKind.JsxAttribute; parent?: JsxAttributes; name: Identifier; @@ -1652,26 +1712,26 @@ namespace ts { initializer?: StringLiteral | JsxExpression; } - export interface JsxSpreadAttribute extends ObjectLiteralElement { + export interface JsxSpreadAttribute extends ObjectLiteralElementBase { kind: SyntaxKind.JsxSpreadAttribute; parent?: JsxAttributes; expression: Expression; } - export interface JsxClosingElement extends Node { + export interface JsxClosingElement extends BaseNode { kind: SyntaxKind.JsxClosingElement; parent?: JsxElement; tagName: JsxTagNameExpression; } - export interface JsxExpression extends Expression { + export interface JsxExpression extends ExpressionBase { kind: SyntaxKind.JsxExpression; parent?: JsxElement | JsxAttributeLike; dotDotDotToken?: Token; expression?: Expression; } - export interface JsxText extends Node { + export interface JsxText extends BaseNode { kind: SyntaxKind.JsxText; containsOnlyWhiteSpaces: boolean; parent?: JsxElement; @@ -1679,28 +1739,27 @@ namespace ts { export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement; - export interface Statement extends Node { + export interface StatementBase extends BaseNode { _statementBrand: any; } // Represents a statement that is elided as part of a transformation to emit comments on a // not-emitted node. - export interface NotEmittedStatement extends Statement { + export interface NotEmittedStatement extends StatementBase { kind: SyntaxKind.NotEmittedStatement; } /** * Marks the end of transformed declaration to properly emit exports. */ - /* @internal */ - export interface EndOfDeclarationMarker extends Statement { + export interface EndOfDeclarationMarker extends StatementBase { kind: SyntaxKind.EndOfDeclarationMarker; } /** * A list of comma-seperated expressions. This node is only created by transformations. */ - export interface CommaListExpression extends Expression { + export interface CommaListExpression extends ExpressionBase { kind: SyntaxKind.CommaListExpression; elements: NodeArray; } @@ -1708,38 +1767,37 @@ namespace ts { /** * Marks the beginning of a merged transformed declaration. */ - /* @internal */ - export interface MergeDeclarationMarker extends Statement { + export interface MergeDeclarationMarker extends StatementBase { kind: SyntaxKind.MergeDeclarationMarker; } - export interface EmptyStatement extends Statement { + export interface EmptyStatement extends StatementBase { kind: SyntaxKind.EmptyStatement; } - export interface DebuggerStatement extends Statement { + export interface DebuggerStatement extends StatementBase { kind: SyntaxKind.DebuggerStatement; } - export interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement { + export interface MissingDeclaration extends DeclarationStatementBase, ClassElementBase, ObjectLiteralElementBase, TypeElementBase { kind: SyntaxKind.MissingDeclaration; name?: Identifier; } export type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; - export interface Block extends Statement { + export interface Block extends StatementBase { kind: SyntaxKind.Block; statements: NodeArray; /*@internal*/ multiLine?: boolean; } - export interface VariableStatement extends Statement, JSDocContainer { + export interface VariableStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.VariableStatement; declarationList: VariableDeclarationList; } - export interface ExpressionStatement extends Statement, JSDocContainer { + export interface ExpressionStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.ExpressionStatement; expression: Expression; } @@ -1749,30 +1807,37 @@ namespace ts { expression: StringLiteral; } - export interface IfStatement extends Statement { + export interface IfStatement extends StatementBase { kind: SyntaxKind.IfStatement; expression: Expression; thenStatement: Statement; elseStatement?: Statement; } - export interface IterationStatement extends Statement { + export type IterationStatement = + | DoStatement + | WhileStatement + | ForStatement + | ForInStatement + | ForOfStatement; + + export interface IterationStatementBase extends StatementBase { statement: Statement; } - export interface DoStatement extends IterationStatement { + export interface DoStatement extends IterationStatementBase { kind: SyntaxKind.DoStatement; expression: Expression; } - export interface WhileStatement extends IterationStatement { + export interface WhileStatement extends IterationStatementBase { kind: SyntaxKind.WhileStatement; expression: Expression; } export type ForInitializer = VariableDeclarationList | Expression; - export interface ForStatement extends IterationStatement { + export interface ForStatement extends IterationStatementBase { kind: SyntaxKind.ForStatement; initializer?: ForInitializer; condition?: Expression; @@ -1781,63 +1846,63 @@ namespace ts { export type ForInOrOfStatement = ForInStatement | ForOfStatement; - export interface ForInStatement extends IterationStatement { + export interface ForInStatement extends IterationStatementBase { kind: SyntaxKind.ForInStatement; initializer: ForInitializer; expression: Expression; } - export interface ForOfStatement extends IterationStatement { + export interface ForOfStatement extends IterationStatementBase { kind: SyntaxKind.ForOfStatement; awaitModifier?: AwaitKeywordToken; initializer: ForInitializer; expression: Expression; } - export interface BreakStatement extends Statement { + export interface BreakStatement extends StatementBase { kind: SyntaxKind.BreakStatement; label?: Identifier; } - export interface ContinueStatement extends Statement { + export interface ContinueStatement extends StatementBase { kind: SyntaxKind.ContinueStatement; label?: Identifier; } export type BreakOrContinueStatement = BreakStatement | ContinueStatement; - export interface ReturnStatement extends Statement { + export interface ReturnStatement extends StatementBase { kind: SyntaxKind.ReturnStatement; expression?: Expression; } - export interface WithStatement extends Statement { + export interface WithStatement extends StatementBase { kind: SyntaxKind.WithStatement; expression: Expression; statement: Statement; } - export interface SwitchStatement extends Statement { + export interface SwitchStatement extends StatementBase { kind: SyntaxKind.SwitchStatement; expression: Expression; caseBlock: CaseBlock; possiblyExhaustive?: boolean; } - export interface CaseBlock extends Node { + export interface CaseBlock extends BaseNode { kind: SyntaxKind.CaseBlock; parent?: SwitchStatement; clauses: NodeArray; } - export interface CaseClause extends Node { + export interface CaseClause extends BaseNode { kind: SyntaxKind.CaseClause; parent?: CaseBlock; expression: Expression; statements: NodeArray; } - export interface DefaultClause extends Node { + export interface DefaultClause extends BaseNode { kind: SyntaxKind.DefaultClause; parent?: CaseBlock; statements: NodeArray; @@ -1845,25 +1910,25 @@ namespace ts { export type CaseOrDefaultClause = CaseClause | DefaultClause; - export interface LabeledStatement extends Statement, JSDocContainer { + export interface LabeledStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.LabeledStatement; label: Identifier; statement: Statement; } - export interface ThrowStatement extends Statement { + export interface ThrowStatement extends StatementBase { kind: SyntaxKind.ThrowStatement; expression: Expression; } - export interface TryStatement extends Statement { + export interface TryStatement extends StatementBase { kind: SyntaxKind.TryStatement; tryBlock: Block; catchClause?: CatchClause; finallyBlock?: Block; } - export interface CatchClause extends Node { + export interface CatchClause extends BaseNode { kind: SyntaxKind.CatchClause; parent?: TryStatement; variableDeclaration?: VariableDeclaration; @@ -1872,7 +1937,9 @@ namespace ts { export type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; - export interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { + export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; + + export interface ClassLikeDeclarationBase extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; name?: Identifier; typeParameters?: NodeArray; @@ -1880,29 +1947,29 @@ namespace ts { members: NodeArray; } - export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { + export interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatementBase { kind: SyntaxKind.ClassDeclaration; name?: Identifier; } - export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { + export interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpressionBase { kind: SyntaxKind.ClassExpression; } - export type ClassLikeDeclaration = ClassDeclaration | ClassExpression; + export type ClassElement = PropertyDeclaration | MissingDeclaration | IndexSignatureDeclaration | AccessorDeclaration | SemicolonClassElement | ConstructorDeclaration | MethodDeclaration; - export interface ClassElement extends NamedDeclaration { + export interface ClassElementBase extends NamedDeclarationBase { _classElementBrand: any; name?: PropertyName; } - export interface TypeElement extends NamedDeclaration { + export interface TypeElementBase extends NamedDeclarationBase { _typeElementBrand: any; name?: PropertyName; questionToken?: QuestionToken; } - export interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { + export interface InterfaceDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.InterfaceDeclaration; name: Identifier; typeParameters?: NodeArray; @@ -1910,21 +1977,21 @@ namespace ts { members: NodeArray; } - export interface HeritageClause extends Node { + export interface HeritageClause extends BaseNode { kind: SyntaxKind.HeritageClause; parent?: InterfaceDeclaration | ClassDeclaration | ClassExpression; token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; types: NodeArray; } - export interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer { + export interface TypeAliasDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.TypeAliasDeclaration; name: Identifier; typeParameters?: NodeArray; type: TypeNode; } - export interface EnumMember extends NamedDeclaration, JSDocContainer { + export interface EnumMember extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.EnumMember; parent?: EnumDeclaration; // This does include ComputedPropertyName, but the parser will give an error @@ -1933,7 +2000,7 @@ namespace ts { initializer?: Expression; } - export interface EnumDeclaration extends DeclarationStatement, JSDocContainer { + export interface EnumDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.EnumDeclaration; name: Identifier; members: NodeArray; @@ -1943,7 +2010,7 @@ namespace ts { export type ModuleBody = NamespaceBody | JSDocNamespaceBody; - export interface ModuleDeclaration extends DeclarationStatement, JSDocContainer { + export interface ModuleDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.ModuleDeclaration; parent?: ModuleBody | SourceFile; name: ModuleName; @@ -1964,7 +2031,7 @@ namespace ts { body: JSDocNamespaceBody; } - export interface ModuleBlock extends Node, Statement { + export interface ModuleBlock extends BaseNode, StatementBase { kind: SyntaxKind.ModuleBlock; parent?: ModuleDeclaration; statements: NodeArray; @@ -1977,7 +2044,7 @@ namespace ts { * - import x = require("mod"); * - import x = M.x; */ - export interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { + export interface ImportEqualsDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.ImportEqualsDeclaration; parent?: SourceFile | ModuleBlock; name: Identifier; @@ -1987,7 +2054,7 @@ namespace ts { moduleReference: ModuleReference; } - export interface ExternalModuleReference extends Node { + export interface ExternalModuleReference extends BaseNode { kind: SyntaxKind.ExternalModuleReference; parent?: ImportEqualsDeclaration; expression?: Expression; @@ -1997,7 +2064,7 @@ namespace ts { // import "mod" => importClause = undefined, moduleSpecifier = "mod" // In rest of the cases, module specifier is string literal corresponding to module // ImportClause information is shown at its declaration below. - export interface ImportDeclaration extends Statement { + export interface ImportDeclaration extends StatementBase { kind: SyntaxKind.ImportDeclaration; parent?: SourceFile | ModuleBlock; importClause?: ImportClause; @@ -2013,25 +2080,25 @@ 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 NamedDeclaration { + export interface ImportClause extends NamedDeclarationBase { kind: SyntaxKind.ImportClause; parent?: ImportDeclaration; name?: Identifier; // Default binding namedBindings?: NamedImportBindings; } - export interface NamespaceImport extends NamedDeclaration { + export interface NamespaceImport extends NamedDeclarationBase { kind: SyntaxKind.NamespaceImport; parent?: ImportClause; name: Identifier; } - export interface NamespaceExportDeclaration extends DeclarationStatement { + export interface NamespaceExportDeclaration extends DeclarationStatementBase { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; } - export interface ExportDeclaration extends DeclarationStatement { + export interface ExportDeclaration extends DeclarationStatementBase { kind: SyntaxKind.ExportDeclaration; parent?: SourceFile | ModuleBlock; exportClause?: NamedExports; @@ -2039,13 +2106,13 @@ namespace ts { moduleSpecifier?: Expression; } - export interface NamedImports extends Node { + export interface NamedImports extends BaseNode { kind: SyntaxKind.NamedImports; parent?: ImportClause; elements: NodeArray; } - export interface NamedExports extends Node { + export interface NamedExports extends BaseNode { kind: SyntaxKind.NamedExports; parent?: ExportDeclaration; elements: NodeArray; @@ -2053,14 +2120,14 @@ namespace ts { export type NamedImportsOrExports = NamedImports | NamedExports; - export interface ImportSpecifier extends NamedDeclaration { + export interface ImportSpecifier extends NamedDeclarationBase { 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 NamedDeclaration { + export interface ExportSpecifier extends NamedDeclarationBase { kind: SyntaxKind.ExportSpecifier; parent?: NamedExports; propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) @@ -2069,7 +2136,7 @@ namespace ts { export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; - export interface ExportAssignment extends DeclarationStatement { + export interface ExportAssignment extends DeclarationStatementBase { kind: SyntaxKind.ExportAssignment; parent?: SourceFile; isExportEquals?: boolean; @@ -2098,92 +2165,92 @@ namespace ts { } // represents a top level: { type } expression in a JSDoc comment. - export interface JSDocTypeExpression extends TypeNode { + export interface JSDocTypeExpression extends TypeNodeBase { kind: SyntaxKind.JSDocTypeExpression; type: TypeNode; } - export interface JSDocType extends TypeNode { + export interface JSDocTypeBase extends TypeNodeBase { _jsDocTypeBrand: any; } - export interface JSDocAllType extends JSDocType { + export interface JSDocAllType extends JSDocTypeBase { kind: SyntaxKind.JSDocAllType; } - export interface JSDocUnknownType extends JSDocType { + export interface JSDocUnknownType extends JSDocTypeBase { kind: SyntaxKind.JSDocUnknownType; } - export interface JSDocNonNullableType extends JSDocType { + export interface JSDocNonNullableType extends JSDocTypeBase { kind: SyntaxKind.JSDocNonNullableType; type: TypeNode; } - export interface JSDocNullableType extends JSDocType { + export interface JSDocNullableType extends JSDocTypeBase { kind: SyntaxKind.JSDocNullableType; type: TypeNode; } - export interface JSDocOptionalType extends JSDocType { + export interface JSDocOptionalType extends JSDocTypeBase { kind: SyntaxKind.JSDocOptionalType; type: TypeNode; } - export interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase { + export interface JSDocFunctionType extends JSDocTypeBase, SignatureDeclarationBase { kind: SyntaxKind.JSDocFunctionType; } - export interface JSDocVariadicType extends JSDocType { + export interface JSDocVariadicType extends JSDocTypeBase { kind: SyntaxKind.JSDocVariadicType; type: TypeNode; } export type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; - export interface JSDoc extends Node { + export interface JSDoc extends BaseNode { kind: SyntaxKind.JSDocComment; parent?: HasJSDoc; tags: NodeArray | undefined; comment: string | undefined; } - export interface JSDocTag extends Node { + export interface JSDocTagBase extends BaseNode { parent: JSDoc; atToken: AtToken; tagName: Identifier; comment: string | undefined; } - export interface JSDocUnknownTag extends JSDocTag { + export interface JSDocUnknownTag extends JSDocTagBase { kind: SyntaxKind.JSDocTag; } - export interface JSDocAugmentsTag extends JSDocTag { + export interface JSDocAugmentsTag extends JSDocTagBase { kind: SyntaxKind.JSDocAugmentsTag; typeExpression: JSDocTypeExpression; } - export interface JSDocClassTag extends JSDocTag { + export interface JSDocClassTag extends JSDocTagBase { kind: SyntaxKind.JSDocClassTag; } - export interface JSDocTemplateTag extends JSDocTag { + export interface JSDocTemplateTag extends JSDocTagBase { kind: SyntaxKind.JSDocTemplateTag; typeParameters: NodeArray; } - export interface JSDocReturnTag extends JSDocTag { + export interface JSDocReturnTag extends JSDocTagBase { kind: SyntaxKind.JSDocReturnTag; typeExpression: JSDocTypeExpression; } - export interface JSDocTypeTag extends JSDocTag { + export interface JSDocTypeTag extends JSDocTagBase { kind: SyntaxKind.JSDocTypeTag; typeExpression: JSDocTypeExpression; } - export interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { + export interface JSDocTypedefTag extends JSDocTagBase, NamedDeclarationBase { parent: JSDoc; kind: SyntaxKind.JSDocTypedefTag; fullName?: JSDocNamespaceDeclaration | Identifier; @@ -2191,7 +2258,7 @@ namespace ts { typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; } - export interface JSDocPropertyLikeTag extends JSDocTag, Declaration { + export interface JSDocPropertyLikeTagBase extends JSDocTagBase, DeclarationBase { parent: JSDoc; name: EntityName; typeExpression: JSDocTypeExpression; @@ -2200,15 +2267,15 @@ namespace ts { isBracketed: boolean; } - export interface JSDocPropertyTag extends JSDocPropertyLikeTag { + export interface JSDocPropertyTag extends JSDocPropertyLikeTagBase { kind: SyntaxKind.JSDocPropertyTag; } - export interface JSDocParameterTag extends JSDocPropertyLikeTag { + export interface JSDocParameterTag extends JSDocPropertyLikeTagBase { kind: SyntaxKind.JSDocParameterTag; } - export interface JSDocTypeLiteral extends JSDocType { + export interface JSDocTypeLiteral extends JSDocTypeBase { kind: SyntaxKind.JSDocTypeLiteral; jsDocPropertyTags?: ReadonlyArray; jsDocTypeTag?: JSDocTypeTag; @@ -2331,7 +2398,7 @@ namespace ts { } // Source files are declarations when they are external modules. - export interface SourceFile extends Declaration { + export interface SourceFile extends DeclarationBase { kind: SyntaxKind.SourceFile; statements: NodeArray; endOfFileToken: Token; @@ -2411,7 +2478,7 @@ namespace ts { /* @internal */ checkJsDirective: CheckJsDirective | undefined; } - export interface Bundle extends Node { + export interface Bundle extends BaseNode { kind: SyntaxKind.Bundle; sourceFiles: ReadonlyArray; } @@ -4389,7 +4456,7 @@ namespace ts { onEmitNode: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void; } - export interface TransformationResult { + export interface TransformationResult { /** Gets the transformed source files. */ transformed: T[]; @@ -4576,8 +4643,518 @@ namespace ts { /* @internal */ reattachFileDiagnostics(newFile: SourceFile): void; } - // SyntaxKind.SyntaxList - export interface SyntaxList extends Node { + export interface SyntaxList extends BaseNode { + kind: SyntaxKind.SyntaxList; _children: Node[]; } + + export type Literals = + | NumericLiteral + | StringLiteral + | JsxText + | RegularExpressionLiteral + | NoSubstitutionTemplateLiteral; + + export type PseudoLiterals = + | TemplateHead + | TemplateMiddle + | TemplateTail; + + export type Tokens = + // Only appears as token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + // Punctuation + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + // Assignments + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + // Reserved words + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + // Strict mode reserved words + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + // Contextual keywords + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token; + + export type Names = + | QualifiedName + | ComputedPropertyName; + + export type SignatureElement = + | TypeParameterDeclaration + | ParameterDeclaration + | Decorator; + + export type TypeMembers = + | PropertySignature + | PropertyDeclaration + | MethodSignature + | MethodDeclaration + | ConstructorDeclaration + | GetAccessorDeclaration + | SetAccessorDeclaration + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | IndexSignatureDeclaration; + + export type KeywordTypeNode = + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token + | Token; + + export type TypeNode = + | TypePredicateNode + | TypeReferenceNode + | FunctionTypeNode + | ConstructorTypeNode + | TypeQueryNode + | TypeLiteralNode + | ArrayTypeNode + | TupleTypeNode + | UnionTypeNode + | IntersectionTypeNode + | ParenthesizedTypeNode + | ThisTypeNode + | TypeOperatorNode + | IndexedAccessTypeNode + | MappedTypeNode + | LiteralTypeNode + | ExpressionWithTypeArguments + | JSDocAllType + | JSDocUnknownType + | JSDocNullableType + | JSDocNonNullableType + | JSDocOptionalType + | JSDocFunctionType + | JSDocVariadicType + | JSDocTypeExpression + | JSDocTypeLiteral + | KeywordTypeNode; + + // Organized by classification + export type Expression = + | ConditionalExpression + | YieldExpression + | ArrowFunction + | BinaryExpression + | SpreadElement + | AsExpression + | OmittedExpression + | CommaListExpression + | PartiallyEmittedExpression + | JsxAttributes // This is suspect - this is never available in most expression contexts + | JsxExpression + | JsxOpeningElement + | UnaryExpression; + + export type UnaryExpression = + | DeleteExpression + | TypeOfExpression + | VoidExpression + | AwaitExpression + | TypeAssertion + | UpdateExpression; + + export type UpdateExpression = + | PrefixUnaryExpression + | PostfixUnaryExpression + | LeftHandSideExpression; + + export type LeftHandSideExpression = + | PartiallyEmittedExpression + | CallExpression + | NonNullExpression + | MemberExpression; + + export type MemberExpression = + | PropertyAccessExpression + | PropertyAccessEntityNameExpression // Included for completeness + | ElementAccessExpression + | TaggedTemplateExpression + | PrimaryExpression; + + export type PrimaryExpression = + | Identifier + | NullLiteral + | BooleanLiteral + | ThisExpression + | SuperExpression + | ImportExpression + | FunctionExpression + | LiteralExpression + | TemplateExpression + | ParenthesizedExpression + | ArrayLiteralExpression + | ObjectLiteralExpression + | NewExpression + | MetaProperty + | JsxElement + | JsxSelfClosingElement + | ClassExpression; + + export type LiteralExpression = + | StringLiteral + | RegularExpressionLiteral + | NoSubstitutionTemplateLiteral + | NumericLiteral; + + export type Miscellaneous = + | TemplateSpan + | SemicolonClassElement; + + export type Elements = + | Block + | VariableStatement + | EmptyStatement + | ExpressionStatement + | IfStatement + | DoStatement + | WhileStatement + | ForStatement + | ForInStatement + | ForOfStatement + | ContinueStatement + | BreakStatement + | ReturnStatement + | WithStatement + | SwitchStatement + | LabeledStatement + | ThrowStatement + | TryStatement + | DebuggerStatement + | VariableDeclaration + | VariableDeclarationList + | FunctionDeclaration + | ClassDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | EnumDeclaration + | ModuleDeclaration + | ModuleBlock + | CaseBlock + | NamespaceExportDeclaration + | ImportEqualsDeclaration + | ImportDeclaration + | ImportClause + | NamespaceImport + | NamedImports + | ImportSpecifier + | ExportAssignment + | ExportDeclaration + | NamedExports + | ExportSpecifier + | MissingDeclaration; + + export type JSXNodes = + | JsxElement + | JsxSelfClosingElement + | JsxOpeningElement + | JsxClosingElement + | JsxAttribute + | JsxAttributes + | JsxSpreadAttribute + | JsxExpression; + + export type Clauses = + | CaseClause + | DefaultClause + | HeritageClause + | CatchClause; + + export type PropertyAssignments = + | PropertyAssignment + | ShorthandPropertyAssignment + | SpreadAssignment; + + export type JSDocNode = + | JSDocTypeExpression + | JSDocAllType + | JSDocUnknownType + | JSDocNullableType + | JSDocNonNullableType + | JSDocOptionalType + | JSDocFunctionType + | JSDocVariadicType + | JSDoc + | JSDocUnknownTag + | JSDocAugmentsTag + | JSDocClassTag + | JSDocParameterTag + | JSDocReturnTag + | JSDocTypeTag + | JSDocTemplateTag + | JSDocTypedefTag + | JSDocPropertyTag + | JSDocTypeLiteral; + + export type TransformationNodes = + | NotEmittedStatement + | PartiallyEmittedExpression + | CommaListExpression + | MergeDeclarationMarker + | EndOfDeclarationMarker; + + export type Statement = + | NotEmittedStatement + | EndOfDeclarationMarker + | MergeDeclarationMarker + | EmptyStatement + | DebuggerStatement + | Block + | VariableStatement + | ExpressionStatement + | IfStatement + | IterationStatement + | BreakStatement + | ContinueStatement + | ReturnStatement + | WithStatement + | SwitchStatement + | LabeledStatement + | ThrowStatement + | TryStatement + | ImportDeclaration + | DeclarationStatement; + + export type JSDocTag = + | JSDocUnknownTag + | JSDocAugmentsTag + | JSDocClassTag + | JSDocTemplateTag + | JSDocReturnTag + | JSDocTypeTag + | JSDocTypedefTag + | JSDocPropertyLikeTag; + + export type JSDocPropertyLikeTag = + | JSDocPropertyTag + | JSDocParameterTag; + + export type Declaration = + | TypeLiteralNode + | MappedTypeNode + | BinaryExpression + | ObjectLiteralExpression + | JsxAttributes + | CallExpression + | NewExpression + | JSDocPropertyLikeTag + | PropertyAccessExpression + | JSDocTypedefTag + | NamedDeclaration + | SourceFile; + + export type NamedDeclaration = + | DeclarationStatement + | TypeParameterDeclaration + | SignatureDeclaration + | VariableDeclaration + | ParameterDeclaration + | BindingElement + | ObjectLiteralElement + | VariableLikeDeclaration + | ClassLikeDeclaration + | ClassElement + | TypeElement + | EnumMember + | ImportClause + | NamespaceImport + | ImportSpecifier + | ExportSpecifier; + + export type DeclarationStatement = + | FunctionDeclaration + | MissingDeclaration + | ClassDeclaration + | InterfaceDeclaration + | TypeAliasDeclaration + | EnumDeclaration + | ModuleDeclaration + | ImportEqualsDeclaration + | NamespaceExportDeclaration + | ExportDeclaration + | ExportAssignment; + + export type ObjectLiteralElement = + | PropertyAssignment + | ShorthandPropertyAssignment + | SpreadAssignment + | MethodDeclaration + | AccessorDeclaration + | JsxAttribute + | JsxSpreadAttribute; + + export type TypeElement = + | CallSignatureDeclaration + | ConstructSignatureDeclaration + | PropertySignature + | MethodSignature + | IndexSignatureDeclaration + | MissingDeclaration; + + export type LiteralLikeNode = + | LiteralExpression + | TemplateHead + | TemplateMiddle + | TemplateTail; + + export type Node = + | Literals + | PseudoLiterals + | Tokens + | Names + | SignatureElement + | TypeMembers + | TypeNode + | BindingPattern + | BindingElement + | Expression + | Miscellaneous + | Elements + | ModuleReference + | JSXNodes + | Clauses + | PropertyAssignments + | EnumMember + | SourceFile + | Bundle + | JSDocNode + | SyntaxList + | TransformationNodes; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 11c30a2d8abd2..9fa901c60ad8b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -133,18 +133,18 @@ namespace ts { } // Returns true if this node contains a parse error anywhere underneath it. - export function containsParseError(node: Node): boolean { + export function containsParseError(node: BaseNode): boolean { aggregateChildData(node); return (node.flags & NodeFlags.ThisNodeOrAnySubNodesHasError) !== 0; } - function aggregateChildData(node: Node): void { + function aggregateChildData(node: BaseNode): void { if (!(node.flags & NodeFlags.HasAggregatedChildData)) { // A node is considered to contain a parse error if: // a) the parser explicitly marked that it had an error // b) any of it's children reported that it had an error. const thisNodeOrAnySubNodesHasError = ((node.flags & NodeFlags.ThisNodeHasError) !== 0) || - forEachChild(node, containsParseError); + forEachChild(node as Node, containsParseError); // If so, mark ourselves accordingly. if (thisNodeOrAnySubNodesHasError) { @@ -228,7 +228,7 @@ namespace ts { // code). So the parser will attempt to parse out a type, and will create an actual node. // However, this node will be 'missing' in the sense that no actual source-code/tokens are // contained within it. - export function nodeIsMissing(node: Node) { + export function nodeIsMissing(node: BaseNode) { if (node === undefined) { return true; } @@ -236,7 +236,7 @@ namespace ts { return node.pos === node.end && node.pos >= 0 && node.kind !== SyntaxKind.EndOfFileToken; } - export function nodeIsPresent(node: Node) { + export function nodeIsPresent(node: BaseNode) { return !nodeIsMissing(node); } @@ -361,7 +361,7 @@ namespace ts { return node.text; } - Debug.fail(`Literal kind '${node.kind}' not accounted for.`); + Debug.fail(`Literal kind '${(node as any).kind}' not accounted for.`); } export function getTextOfConstantValue(value: string | number) { @@ -523,7 +523,7 @@ namespace ts { // Return display name of an identifier // Computed property names will just be emitted as "[]", where is the source // text of the expression in the computed property. - export function declarationNameToString(name: DeclarationName) { + export function declarationNameToString(name: DeclarationName | QualifiedName) { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } @@ -754,12 +754,11 @@ namespace ts { case SyntaxKind.ExpressionWithTypeArguments: return !isExpressionWithTypeArgumentsInClassExtendsClause(parent); case SyntaxKind.TypeParameter: - return node === (parent).constraint; + return node === parent.constraint; case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: case SyntaxKind.Parameter: case SyntaxKind.VariableDeclaration: - return node === (parent).type; case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: @@ -768,16 +767,14 @@ namespace ts { case SyntaxKind.MethodSignature: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return node === (parent).type; case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - return node === (parent).type; case SyntaxKind.TypeAssertionExpression: - return node === (parent).type; + return node === parent.type; case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: - return (parent).typeArguments && indexOf((parent).typeArguments, node) >= 0; + return parent.typeArguments && indexOf(parent.typeArguments, node as TypeNode) >= 0; case SyntaxKind.TaggedTemplateExpression: // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. return false; @@ -887,7 +884,7 @@ namespace ts { } } - export function isVariableLike(node: Node): node is VariableLikeDeclaration { + export function isVariableLike(node: Node): node is ParameterDeclaration | PropertySignature | PropertyDeclaration | BindingElement | VariableDeclaration | PropertyAssignment | ShorthandPropertyAssignment | EnumMember { if (node) { switch (node.kind) { case SyntaxKind.BindingElement: @@ -904,6 +901,22 @@ namespace ts { return false; } + export function isInitializableVariable(node: Node): node is ParameterDeclaration | PropertySignature | PropertyDeclaration | BindingElement | VariableDeclaration | PropertyAssignment | EnumMember { + if (node) { + switch (node.kind) { + case SyntaxKind.BindingElement: + case SyntaxKind.EnumMember: + case SyntaxKind.Parameter: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.VariableDeclaration: + return true; + } + } + return false; + } + export function introducesArgumentsExoticObject(node: Node) { switch (node.kind) { case SyntaxKind.MethodDeclaration: @@ -1095,14 +1108,14 @@ namespace ts { export function getImmediatelyInvokedFunctionExpression(func: Node): CallExpression { if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) { - let prev = func; + let prev: Node = func; let parent = func.parent; while (parent.kind === SyntaxKind.ParenthesizedExpression) { prev = parent; parent = parent.parent; } - if (parent.kind === SyntaxKind.CallExpression && (parent as CallExpression).expression === prev) { - return parent as CallExpression; + if (parent.kind === SyntaxKind.CallExpression && parent.expression === prev) { + return parent; } } } @@ -1116,19 +1129,19 @@ namespace ts { && (node).expression.kind === SyntaxKind.SuperKeyword; } - export function getEntityNameFromTypeNode(node: TypeNode): EntityNameOrEntityNameExpression { + export function getEntityNameFromTypeNode(node: TypeNode | Identifier | QualifiedName): EntityNameOrEntityNameExpression { switch (node.kind) { case SyntaxKind.TypeReference: - return (node).typeName; + return node.typeName; case SyntaxKind.ExpressionWithTypeArguments: - return isEntityNameExpression((node).expression) - ? (node).expression + return isEntityNameExpression(node.expression) + ? node.expression : undefined; case SyntaxKind.Identifier: case SyntaxKind.QualifiedName: - return (node); + return node; } return undefined; @@ -1264,7 +1277,7 @@ namespace ts { case SyntaxKind.EnumMember: case SyntaxKind.PropertyAssignment: case SyntaxKind.BindingElement: - return (parent).initializer === node; + return parent.initializer === node; case SyntaxKind.ExpressionStatement: case SyntaxKind.IfStatement: case SyntaxKind.DoStatement: @@ -1274,31 +1287,31 @@ namespace ts { case SyntaxKind.SwitchStatement: case SyntaxKind.CaseClause: case SyntaxKind.ThrowStatement: - return (parent).expression === node; + return parent.expression === node; case SyntaxKind.ForStatement: - const forStatement = parent; - return (forStatement.initializer === node && forStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) || + const forStatement = parent; + return (forStatement.initializer === node) || forStatement.condition === node || forStatement.incrementor === node; case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: - const forInStatement = parent; - return (forInStatement.initializer === node && forInStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) || + const forInStatement = parent; + return (forInStatement.initializer === node) || forInStatement.expression === node; case SyntaxKind.TypeAssertionExpression: case SyntaxKind.AsExpression: - return node === (parent).expression; + return node === parent.expression; case SyntaxKind.TemplateSpan: - return node === (parent).expression; + return node === parent.expression; case SyntaxKind.ComputedPropertyName: - return node === (parent).expression; + return node === parent.expression; case SyntaxKind.Decorator: case SyntaxKind.JsxExpression: case SyntaxKind.JsxSpreadAttribute: case SyntaxKind.SpreadAssignment: return true; case SyntaxKind.ExpressionWithTypeArguments: - return (parent).expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent); + return parent.expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent); default: if (isPartOfExpression(parent)) { return true; @@ -1479,7 +1492,99 @@ namespace ts { case SyntaxKind.PropertyAssignment: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - return (node).questionToken !== undefined; + return node.questionToken !== undefined; + } + } + + return false; + } + + export function hasInitializer(node: Node) { + if (node) { + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.Parameter: + case SyntaxKind.BindingElement: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.JsxAttribute: + case SyntaxKind.EnumMember: + return node.initializer !== undefined; + } + } + + return false; + } + + export function hasType(node: VariableLikeDeclaration) { + if (node) { + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.Parameter: + return node.type !== undefined; + } + } + + return false; + } + + export function canHaveType(node: Declaration): node is + | VariableDeclaration + | PropertyDeclaration + | PropertySignature + | ParameterDeclaration { + if (node) { + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.Parameter: + return true; + } + } + + return false; +} + + export function canHaveInitializer(node: Declaration): node is + | VariableDeclaration + | PropertyAssignment + | PropertyDeclaration + | PropertySignature + | ParameterDeclaration + | BindingElement + | JsxAttribute + | EnumMember { + if (node) { + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + case SyntaxKind.PropertyAssignment: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.Parameter: + case SyntaxKind.BindingElement: + case SyntaxKind.JsxAttribute: + case SyntaxKind.EnumMember: + return true; + } + } + + return false; + } + + export function hasDotDotDot(node: Node) { + if (node) { + switch (node.kind) { + case SyntaxKind.Parameter: + case SyntaxKind.BindingElement: + case SyntaxKind.JsxExpression: + return node.dotDotDotToken !== undefined; } } @@ -1532,7 +1637,7 @@ namespace ts { // */ // var x = function(name) { return name.length; } const isInitializerOfVariableDeclarationInStatement = - isVariableLike(parent) && + isInitializableVariable(parent) && parent.initializer === node && parent.parent.parent.kind === SyntaxKind.VariableStatement; const isVariableOfVariableDeclarationStatement = isVariableLike(node) && @@ -1567,7 +1672,7 @@ namespace ts { result = addRange(result, getJSDocParameterTags(node as ParameterDeclaration)); } - if (isVariableLike(node) && node.initializer && hasJSDocNodes(node.initializer)) { + if (isInitializableVariable(node) && node.initializer && hasJSDocNodes(node.initializer)) { result = addRange(result, node.initializer.jsDoc); } @@ -1676,30 +1781,30 @@ namespace ts { while (true) { switch (parent.kind) { case SyntaxKind.BinaryExpression: - const binaryOperator = (parent).operatorToken.kind; - return isAssignmentOperator(binaryOperator) && (parent).left === node ? + const binaryOperator = parent.operatorToken.kind; + return isAssignmentOperator(binaryOperator) && parent.left === node ? binaryOperator === SyntaxKind.EqualsToken ? AssignmentKind.Definite : AssignmentKind.Compound : AssignmentKind.None; case SyntaxKind.PrefixUnaryExpression: case SyntaxKind.PostfixUnaryExpression: - const unaryOperator = (parent).operator; + const unaryOperator = parent.operator; return unaryOperator === SyntaxKind.PlusPlusToken || unaryOperator === SyntaxKind.MinusMinusToken ? AssignmentKind.Compound : AssignmentKind.None; case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: - return (parent).initializer === node ? AssignmentKind.Definite : AssignmentKind.None; + return parent.initializer === node ? AssignmentKind.Definite : AssignmentKind.None; case SyntaxKind.ParenthesizedExpression: case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.SpreadElement: node = parent; break; case SyntaxKind.ShorthandPropertyAssignment: - if ((parent as ShorthandPropertyAssignment).name !== node) { + if (parent.name !== node) { return AssignmentKind.None; } node = parent.parent; break; case SyntaxKind.PropertyAssignment: - if ((parent as ShorthandPropertyAssignment).name === node) { + if (parent.name === node) { return AssignmentKind.None; } node = parent.parent; @@ -1995,10 +2100,10 @@ namespace ts { return name && isDynamicName(name); } - export function isDynamicName(name: DeclarationName): boolean { + export function isDynamicName(name: DeclarationName | QualifiedName): boolean { return name.kind === SyntaxKind.ComputedPropertyName && - !isStringOrNumericLiteral((name).expression) && - !isWellKnownSymbolSyntactically((name).expression); + !isStringOrNumericLiteral(name.expression) && + !isWellKnownSymbolSyntactically(name.expression); } /** @@ -2010,7 +2115,7 @@ namespace ts { return isPropertyAccessExpression(node) && isESSymbolIdentifier(node.expression); } - export function getPropertyNameForPropertyNameNode(name: DeclarationName): __String { + export function getPropertyNameForPropertyNameNode(name: DeclarationName | QualifiedName): __String { if (name.kind === SyntaxKind.Identifier) { return name.escapedText; } @@ -2723,22 +2828,22 @@ namespace ts { forEach(declarations, (member: Declaration) => { if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) && hasModifier(member, ModifierFlags.Static) === hasModifier(accessor, ModifierFlags.Static)) { - const memberName = getPropertyNameForPropertyNameNode((member as NamedDeclaration).name); + const memberName = getPropertyNameForPropertyNameNode(member.name); const accessorName = getPropertyNameForPropertyNameNode(accessor.name); if (memberName === accessorName) { if (!firstAccessor) { - firstAccessor = member; + firstAccessor = member; } else if (!secondAccessor) { - secondAccessor = member; + secondAccessor = member; } if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { - getAccessor = member; + getAccessor = member; } if (member.kind === SyntaxKind.SetAccessor && !setAccessor) { - setAccessor = member; + setAccessor = member; } } } @@ -2756,8 +2861,15 @@ namespace ts { * Gets the effective type annotation of a variable, parameter, or property. If the node was * parsed in a JavaScript file, gets the type annotation from JSDoc. */ - export function getEffectiveTypeAnnotationNode(node: VariableLikeDeclaration): TypeNode | undefined { - if (node.type) { + export function getEffectiveTypeAnnotationNode(node: VariableLikeDeclaration | PropertySignature): TypeNode | undefined { + if (node.kind !== SyntaxKind.JSDocPropertyTag && + node.kind !== SyntaxKind.JSDocParameterTag && + node.kind !== SyntaxKind.BindingElement && + node.kind !== SyntaxKind.PropertyAssignment && + node.kind !== SyntaxKind.ShorthandPropertyAssignment && + node.kind !== SyntaxKind.JsxAttribute && + node.kind !== SyntaxKind.EnumMember && + node.type) { return node.type; } if (isInJavaScriptFile(node)) { @@ -3977,18 +4089,18 @@ namespace ts { // Covers remaining cases switch (hostNode.kind) { case SyntaxKind.VariableStatement: - if ((hostNode as VariableStatement).declarationList && - (hostNode as VariableStatement).declarationList.declarations[0]) { - return getDeclarationIdentifier((hostNode as VariableStatement).declarationList.declarations[0]); + if (hostNode.declarationList && + hostNode.declarationList.declarations[0]) { + return getDeclarationIdentifier(hostNode.declarationList.declarations[0]); } return undefined; case SyntaxKind.ExpressionStatement: - const expr = (hostNode as ExpressionStatement).expression; + const expr = hostNode.expression; switch (expr.kind) { case SyntaxKind.PropertyAccessExpression: - return (expr as PropertyAccessExpression).name; + return expr.name; case SyntaxKind.ElementAccessExpression: - const arg = (expr as ElementAccessExpression).argumentExpression; + const arg = expr.argumentExpression; if (isIdentifier(arg)) { return arg; } @@ -3997,10 +4109,10 @@ namespace ts { case SyntaxKind.EndOfFileToken: return undefined; case SyntaxKind.ParenthesizedExpression: { - return getDeclarationIdentifier(hostNode.expression); + return (isBinaryExpression(hostNode.expression) || isPropertyAccessExpression(hostNode.expression)) ? getDeclarationIdentifier(hostNode.expression) : undefined; } case SyntaxKind.LabeledStatement: { - if (isDeclaration(hostNode.statement) || isExpression(hostNode.statement)) { + if (isDeclaration(hostNode.statement) || isBinaryExpression(hostNode.statement) || isPropertyAccessExpression(hostNode.statement)) { return getDeclarationIdentifier(hostNode.statement); } return undefined; @@ -4010,16 +4122,16 @@ namespace ts { } } - function getDeclarationIdentifier(node: Declaration | Expression) { + function getDeclarationIdentifier(node: Declaration) { const name = getNameOfDeclaration(node); return isIdentifier(name) ? name : undefined; } export function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | undefined { - return declaration.name || nameForNamelessJSDocTypedef(declaration as JSDocTypedefTag); + return declaration.name || nameForNamelessJSDocTypedef(declaration); } - export function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined { + export function getNameOfDeclaration(declaration: Declaration): DeclarationName | QualifiedName | undefined { if (!declaration) { return undefined; } @@ -4027,22 +4139,31 @@ namespace ts { return declaration.name.right; } if (declaration.kind === SyntaxKind.BinaryExpression) { - const expr = declaration as BinaryExpression; - switch (getSpecialPropertyAssignmentKind(expr)) { + switch (getSpecialPropertyAssignmentKind(declaration)) { case SpecialPropertyAssignmentKind.ExportsProperty: case SpecialPropertyAssignmentKind.ThisProperty: case SpecialPropertyAssignmentKind.Property: case SpecialPropertyAssignmentKind.PrototypeProperty: - return (expr.left as PropertyAccessExpression).name; + return (declaration.left as PropertyAccessExpression).name; default: return undefined; } } else if (declaration.kind === SyntaxKind.JSDocTypedefTag) { - return getNameOfJSDocTypedef(declaration as JSDocTypedefTag); + return getNameOfJSDocTypedef(declaration); } else { - return (declaration as NamedDeclaration).name; + switch (declaration.kind) { + case SyntaxKind.TypeLiteral: + case SyntaxKind.MappedType: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.JsxAttributes: + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.SourceFile: + return undefined; + } + return declaration.name; } } } @@ -4274,9 +4395,9 @@ namespace ts { export function skipPartiallyEmittedExpressions(node: Expression): Expression; export function skipPartiallyEmittedExpressions(node: Node): Node; - export function skipPartiallyEmittedExpressions(node: Node) { + export function skipPartiallyEmittedExpressions(node: Node): Node { while (node.kind === SyntaxKind.PartiallyEmittedExpression) { - node = (node).expression; + node = node.expression; } return node; diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 1ce42199372d8..6430d66903ea9 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -1022,11 +1022,11 @@ namespace ts { break; case SyntaxKind.SetAccessor: - result = reduceNodes((node).decorators, cbNodes, result); - result = reduceNodes((node).modifiers, cbNodes, result); - result = reduceNode((node).name, cbNode, result); - result = reduceNodes((node).parameters, cbNodes, result); - result = reduceNode((node).body, cbNode, result); + result = reduceNodes(node.decorators, cbNodes, result); + result = reduceNodes(node.modifiers, cbNodes, result); + result = reduceNode(node.name, cbNode, result); + result = reduceNodes(node.parameters, cbNodes, result); + result = reduceNode(node.body, cbNode, result); break; // Binding patterns diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 37aa8df0ca175..8ca5bf2b15342 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -329,9 +329,9 @@ namespace ts.BreakpointResolver { // If this is name of property assignment, set breakpoint in the initializer if (node.parent.kind === SyntaxKind.PropertyAssignment && - (node.parent).name === node && + node.parent.name === node && !isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent.parent)) { - return spanInNode((node.parent).initializer); + return spanInNode(node.parent.initializer); } // Breakpoint in type assertion goes to its operand diff --git a/src/services/completions.ts b/src/services/completions.ts index 15a20798508b8..9bbd6064a75c6 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -994,7 +994,7 @@ namespace ts.Completions { // through type declaration or inference. // Also proceed if rootDeclaration is a parameter and if its containing function expression/arrow function is contextually typed - // type of parameter will flow in from the contextual type of the function - let canGetType = rootDeclaration.initializer || rootDeclaration.type || rootDeclaration.parent.parent.kind === SyntaxKind.ForOfStatement; + let canGetType = hasInitializer(rootDeclaration) || hasType(rootDeclaration) || rootDeclaration.parent.parent.kind === SyntaxKind.ForOfStatement; if (!canGetType && rootDeclaration.kind === SyntaxKind.Parameter) { if (isExpression(rootDeclaration.parent)) { canGetType = !!typeChecker.getContextualType(rootDeclaration.parent); diff --git a/src/services/documentHighlights.ts b/src/services/documentHighlights.ts index ca4bb861c7dab..bb0ce4d676c01 100644 --- a/src/services/documentHighlights.ts +++ b/src/services/documentHighlights.ts @@ -191,7 +191,7 @@ namespace ts.DocumentHighlights { let child: Node = throwStatement; while (child.parent) { - const parent = child.parent; + const parent: Node = child.parent; if (isFunctionBlock(parent) || parent.kind === SyntaxKind.SourceFile) { return parent; @@ -307,7 +307,7 @@ namespace ts.DocumentHighlights { nodes = [...(declaration).members, declaration]; } else { - nodes = (container).statements; + nodes = container.statements; } break; case SyntaxKind.Constructor: @@ -383,7 +383,7 @@ namespace ts.DocumentHighlights { return keywords; - function tryPushAccessorKeyword(accessorSymbol: Symbol, accessorKind: SyntaxKind): void { + function tryPushAccessorKeyword(accessorSymbol: Symbol, accessorKind: SyntaxKind.GetAccessor | SyntaxKind.SetAccessor): void { const accessor = getDeclarationOfKind(accessorSymbol, accessorKind); if (accessor) { diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index b12b0f85fda49..6064398a59020 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1063,7 +1063,7 @@ namespace ts.FindAllReferences.Core { const containingTypeReference = getContainingTypeReference(refNode); if (containingTypeReference && state.markSeenContainingTypeReference(containingTypeReference)) { const parent = containingTypeReference.parent; - if (isVariableLike(parent) && parent.type === containingTypeReference && parent.initializer && isImplementationExpression(parent.initializer)) { + if (isVariableLike(parent) && canHaveType(parent) && parent.type === containingTypeReference && parent.initializer && isImplementationExpression(parent.initializer)) { addReference(parent.initializer); } else if (isFunctionLike(parent) && parent.type === containingTypeReference && (parent as FunctionLikeDeclaration).body) { @@ -1662,7 +1662,7 @@ namespace ts.FindAllReferences.Core { return false; } else if (isVariableLike(node)) { - if (node.initializer) { + if (hasInitializer(node)) { return true; } else if (node.kind === SyntaxKind.VariableDeclaration) { diff --git a/src/services/services.ts b/src/services/services.ts index 1feafdd55f5c4..eaeeff0276c34 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -44,7 +44,7 @@ namespace ts { return node; } - class NodeObject implements Node { + class NodeObject implements BaseNode { public kind: SyntaxKind; public pos: number; public end: number; @@ -65,11 +65,11 @@ namespace ts { } public getSourceFile(): SourceFile { - return getSourceFileOfNode(this); + return getSourceFileOfNode(this as Node); } public getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number { - return getTokenPosOfNode(this, sourceFile, includeJsDocComment); + return getTokenPosOfNode(this as Node, sourceFile, includeJsDocComment); } public getFullStart(): number { @@ -109,7 +109,7 @@ namespace ts { const token = scanner.scan(); const textPos = scanner.getTextPos(); if (textPos <= end) { - nodes.push(createNode(token, pos, textPos, this)); + nodes.push(createNode(token, pos, textPos, this as Node) as Node); } pos = textPos; if (token === SyntaxKind.EndOfFileToken) { @@ -120,7 +120,7 @@ namespace ts { } private createSyntaxList(nodes: NodeArray): Node { - const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, this); + const list = createNode(SyntaxKind.SyntaxList, nodes.pos, nodes.end, this as Node); list._children = []; let pos = nodes.pos; @@ -134,7 +134,7 @@ namespace ts { if (pos < nodes.end) { this.addSyntheticNodes(list._children, pos, nodes.end); } - return list; + return list as Node; } private createChildren(sourceFile?: SourceFileLike) { @@ -143,7 +143,7 @@ namespace ts { return; } - if (isJSDocCommentContainingNode(this)) { + if (isJSDocCommentContainingNode(this as Node)) { /** Don't add trivia for "tokens" since this is in a comment. */ const children: Node[] = []; this.forEachChild(child => { children.push(child); }); @@ -176,7 +176,7 @@ namespace ts { // For that to work, the jsdoc comments should still be the leading trivia of the first child. // Restoring the scanner position ensures that. pos = this.pos; - forEachChild(this, processNode, processNodes); + forEachChild(this as Node, processNode, processNodes); if (pos < this.end) { this.addSyntheticNodes(children, pos, this.end); } @@ -223,11 +223,11 @@ namespace ts { } public forEachChild(cbNode: (node: Node) => T, cbNodeArray?: (nodes: NodeArray) => T): T { - return forEachChild(this, cbNode, cbNodeArray); + return forEachChild(this as Node, cbNode, cbNodeArray); } } - class TokenOrIdentifierObject implements Node { + class TokenOrIdentifierObject implements BaseNode { public kind: SyntaxKind; public pos: number; public end: number; @@ -244,11 +244,11 @@ namespace ts { } public getSourceFile(): SourceFile { - return getSourceFileOfNode(this); + return getSourceFileOfNode(this as Node); } public getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number { - return getTokenPosOfNode(this, sourceFile, includeJsDocComment); + return getTokenPosOfNode(this as Node, sourceFile, includeJsDocComment); } public getFullStart(): number { @@ -746,8 +746,8 @@ namespace ts { function getServicesObjectAllocator(): ObjectAllocator { return { - getNodeConstructor: () => NodeObject, - getTokenConstructor: () => TokenObject, + getNodeConstructor: () => NodeObject as new (kind: SyntaxKind, pos?: number, end?: number) => Node, + getTokenConstructor: () => TokenObject as new (kind: SyntaxKind, pos?: number, end?: number) => Node, getIdentifierConstructor: () => IdentifierObject, getSourceFileConstructor: () => SourceFileObject, @@ -1616,7 +1616,7 @@ namespace ts { return; } - let nodeForStartPos = node; + let nodeForStartPos: Node = node; while (true) { if (isRightSideOfPropertyAccess(nodeForStartPos) || isRightSideOfQualifiedName(nodeForStartPos)) { // If on the span is in right side of the the property or qualified name, return the span from the qualified name pos to end of this node diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 7e8e748bb172d..da5de4b9f4ce4 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -154,7 +154,7 @@ namespace ts.SignatureHelp { const tagExpression = templateExpression.parent; Debug.assert(templateExpression.kind === SyntaxKind.TemplateExpression); - const argumentIndex = isInsideTemplateLiteral(node, position) ? 0 : 1; + const argumentIndex = isInsideTemplateLiteral(node, position) ? 0 : 1; return getArgumentListInfoForTemplate(tagExpression, argumentIndex, sourceFile); } @@ -165,7 +165,7 @@ namespace ts.SignatureHelp { Debug.assert(templateExpression.kind === SyntaxKind.TemplateExpression); // If we're just after a template tail, don't show signature help. - if (node.kind === SyntaxKind.TemplateTail && !isInsideTemplateLiteral(node, position)) { + if (node.kind === SyntaxKind.TemplateTail && !isInsideTemplateLiteral(node, position)) { return undefined; } diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 7909d2d3adb5d..208d8000e9bea 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -166,7 +166,7 @@ namespace ts.textChanges { /** * Checks if 'candidate' argument is a legal separator in the list that contains 'node' as an element */ - function isSeparator(node: Node, candidate: Node): candidate is Token { + function isSeparator(node: Node, candidate: Node): candidate is Token | Token { return candidate && node.parent && (candidate.kind === SyntaxKind.CommaToken || (candidate.kind === SyntaxKind.SemicolonToken && node.parent.kind === SyntaxKind.ObjectLiteralExpression)); } @@ -425,7 +425,7 @@ namespace ts.textChanges { const afterStart = after.getStart(sourceFile); const afterStartLinePosition = getLineStartPositionForPosition(afterStart, sourceFile); - let separator: SyntaxKind.CommaToken | SyntaxKind.SemicolonToken; + let separator: Token | Token; let multilineList = false; // insert element after the last element in the list that has more than one item @@ -436,12 +436,12 @@ namespace ts.textChanges { // if list has only one element then we'll format is as multiline if node has comment in trailing trivia, or as singleline otherwise // i.e. var x = 1 // this is x // | new element will be inserted at this position - separator = SyntaxKind.CommaToken; + separator = createToken(SyntaxKind.CommaToken); } else { // element has more than one element, pick separator from the list const tokenBeforeInsertPosition = findPrecedingToken(after.pos, sourceFile); - separator = isSeparator(after, tokenBeforeInsertPosition) ? tokenBeforeInsertPosition.kind : SyntaxKind.CommaToken; + separator = isSeparator(after, tokenBeforeInsertPosition) ? createToken(tokenBeforeInsertPosition.kind) as typeof separator : createToken(SyntaxKind.CommaToken); // determine if list is multiline by checking lines of after element and element that precedes it. const afterMinusOneStartLinePosition = getLineStartPositionForPosition(containingList[index - 1].getStart(sourceFile), sourceFile); multilineList = afterMinusOneStartLinePosition !== afterStartLinePosition; @@ -456,7 +456,7 @@ namespace ts.textChanges { kind: ChangeKind.ReplaceWithSingleNode, sourceFile, range: { pos: end, end }, - node: createToken(separator), + node: separator, options: {} }); // use the same indentation as 'after' item @@ -480,7 +480,7 @@ namespace ts.textChanges { sourceFile, range: { pos: end, end }, node: newNode, - options: { prefix: `${tokenToString(separator)} ` } + options: { prefix: `${tokenToString(separator.kind)} ` } }); } } diff --git a/src/services/types.ts b/src/services/types.ts index 8a23bfec1c5c6..1822e223b513d 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -1,5 +1,5 @@ namespace ts { - export interface Node { + export interface BaseNode { getSourceFile(): SourceFile; getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index c3a1d5d571df7..d64fdbf4c1446 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -977,7 +977,7 @@ namespace ts { return SyntaxKind.FirstPunctuation <= kind && kind <= SyntaxKind.LastPunctuation; } - export function isInsideTemplateLiteral(node: LiteralExpression, position: number) { + export function isInsideTemplateLiteral(node: LiteralLikeNode, position: number) { return isTemplateLiteralKind(node.kind) && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } From 28143c013e07c5d22591685e17e2dca9ce13c133 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 10 Oct 2017 18:25:09 -0700 Subject: [PATCH 2/2] Fix invalid cast, accept API baselines --- src/services/refactors/extractSymbol.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 444 ++++++++++-------- tests/baselines/reference/api/typescript.d.ts | 444 ++++++++++-------- 3 files changed, 489 insertions(+), 401 deletions(-) diff --git a/src/services/refactors/extractSymbol.ts b/src/services/refactors/extractSymbol.ts index c16a290a30f30..cbd50c6467245 100644 --- a/src/services/refactors/extractSymbol.ts +++ b/src/services/refactors/extractSymbol.ts @@ -375,7 +375,7 @@ namespace ts.refactor.extractSymbol { permittedJumps = PermittedJumps.None; break; case SyntaxKind.Block: - if (node.parent && node.parent.kind === SyntaxKind.TryStatement && (node).finallyBlock === node) { + if (node.parent && node.parent.kind === SyntaxKind.TryStatement && node.parent.finallyBlock === node) { // allow unconditional returns from finally blocks permittedJumps = PermittedJumps.Return; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index d862513c29387..dc107d0fedafc 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -352,7 +352,7 @@ declare namespace ts { CommaListExpression = 289, MergeDeclarationMarker = 290, EndOfDeclarationMarker = 291, - Count = 292, + Count = 291, FirstAssignment = 58, LastAssignment = 70, FirstCompoundAssignment = 59, @@ -439,7 +439,7 @@ declare namespace ts { IntrinsicIndexedElement = 2, IntrinsicElement = 3, } - interface Node extends TextRange { + interface BaseNode extends TextRange { kind: SyntaxKind; flags: NodeFlags; decorators?: NodeArray; @@ -449,10 +449,10 @@ declare namespace ts { interface JSDocContainer { } type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | LabeledStatement | ExpressionStatement | VariableStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | EndOfFileToken; - interface NodeArray extends ReadonlyArray, TextRange { + interface NodeArray extends ReadonlyArray, TextRange { hasTrailingComma?: boolean; } - interface Token extends Node { + interface Token extends BaseNode { kind: TKind; } type DotDotDotToken = Token; @@ -467,7 +467,7 @@ declare namespace ts { type AwaitKeywordToken = Token; type Modifier = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; type ModifiersArray = NodeArray; - interface Identifier extends PrimaryExpression { + interface Identifier extends PrimaryExpressionBase { kind: SyntaxKind.Identifier; /** * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) @@ -480,7 +480,7 @@ declare namespace ts { interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; } - interface QualifiedName extends Node { + interface QualifiedName extends BaseNode { kind: SyntaxKind.QualifiedName; left: EntityName; right: Identifier; @@ -488,25 +488,25 @@ declare namespace ts { type EntityName = Identifier | QualifiedName; type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName; type DeclarationName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | BindingPattern; - interface Declaration extends Node { + interface DeclarationBase extends BaseNode { _declarationBrand: any; } - interface NamedDeclaration extends Declaration { + interface NamedDeclarationBase extends DeclarationBase { name?: DeclarationName; } - interface DeclarationStatement extends NamedDeclaration, Statement { + interface DeclarationStatementBase extends NamedDeclarationBase, StatementBase { name?: Identifier | StringLiteral | NumericLiteral; } - interface ComputedPropertyName extends Node { + interface ComputedPropertyName extends BaseNode { kind: SyntaxKind.ComputedPropertyName; expression: Expression; } - interface Decorator extends Node { + interface Decorator extends BaseNode { kind: SyntaxKind.Decorator; parent?: NamedDeclaration; expression: LeftHandSideExpression; } - interface TypeParameterDeclaration extends NamedDeclaration { + interface TypeParameterDeclaration extends NamedDeclarationBase { kind: SyntaxKind.TypeParameter; parent?: DeclarationWithTypeParameters; name: Identifier; @@ -514,7 +514,7 @@ declare namespace ts { default?: TypeNode; expression?: Expression; } - interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { + interface SignatureDeclarationBase extends NamedDeclarationBase, JSDocContainer { kind: SignatureDeclaration["kind"]; name?: PropertyName; typeParameters?: NodeArray; @@ -522,26 +522,26 @@ declare namespace ts { type: TypeNode | undefined; } type SignatureDeclaration = CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; - interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement { + interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.CallSignature; } - interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement { + interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.ConstructSignature; } type BindingName = Identifier | BindingPattern; - interface VariableDeclaration extends NamedDeclaration { + interface VariableDeclaration extends NamedDeclarationBase { kind: SyntaxKind.VariableDeclaration; parent?: VariableDeclarationList | CatchClause; name: BindingName; type?: TypeNode; initializer?: Expression; } - interface VariableDeclarationList extends Node { + interface VariableDeclarationList extends BaseNode { kind: SyntaxKind.VariableDeclarationList; parent?: VariableStatement | ForStatement | ForOfStatement | ForInStatement; declarations: NodeArray; } - interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { + interface ParameterDeclaration extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.Parameter; parent?: SignatureDeclaration; dotDotDotToken?: DotDotDotToken; @@ -550,7 +550,7 @@ declare namespace ts { type?: TypeNode; initializer?: Expression; } - interface BindingElement extends NamedDeclaration { + interface BindingElement extends NamedDeclarationBase { kind: SyntaxKind.BindingElement; parent?: BindingPattern; propertyName?: PropertyName; @@ -558,33 +558,33 @@ declare namespace ts { name: BindingName; initializer?: Expression; } - interface PropertySignature extends TypeElement, JSDocContainer { + interface PropertySignature extends TypeElementBase, JSDocContainer { kind: SyntaxKind.PropertySignature; name: PropertyName; questionToken?: QuestionToken; type?: TypeNode; initializer?: Expression; } - interface PropertyDeclaration extends ClassElement, JSDocContainer { + interface PropertyDeclaration extends ClassElementBase, JSDocContainer { kind: SyntaxKind.PropertyDeclaration; questionToken?: QuestionToken; name: PropertyName; type?: TypeNode; initializer?: Expression; } - interface ObjectLiteralElement extends NamedDeclaration { + interface ObjectLiteralElementBase extends NamedDeclarationBase { _objectLiteralBrandBrand: any; name?: PropertyName; } type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; - interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { + interface PropertyAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.PropertyAssignment; name: PropertyName; questionToken?: QuestionToken; initializer: Expression; } - interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { + interface ShorthandPropertyAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.ShorthandPropertyAssignment; name: Identifier; @@ -592,12 +592,12 @@ declare namespace ts { equalsToken?: Token; objectAssignmentInitializer?: Expression; } - interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { + interface SpreadAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.SpreadAssignment; expression: Expression; } - interface VariableLikeDeclaration extends NamedDeclaration { + interface VariableLikeDeclarationBase extends NamedDeclarationBase { propertyName?: PropertyName; dotDotDotToken?: DotDotDotToken; name: DeclarationName; @@ -605,15 +605,14 @@ declare namespace ts { type?: TypeNode; initializer?: Expression; } - interface PropertyLikeDeclaration extends NamedDeclaration { - name: PropertyName; - } - interface ObjectBindingPattern extends Node { + type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertySignature | PropertyAssignment | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyLikeTag; + type VariableLikeInitializedDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | JsxAttribute | EnumMember; + interface ObjectBindingPattern extends BaseNode { kind: SyntaxKind.ObjectBindingPattern; parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; } - interface ArrayBindingPattern extends Node { + interface ArrayBindingPattern extends BaseNode { kind: SyntaxKind.ArrayBindingPattern; parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; @@ -636,199 +635,196 @@ declare namespace ts { } type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionExpression | ArrowFunction; type FunctionLike = FunctionLikeDeclaration | FunctionTypeNode | ConstructorTypeNode | IndexSignatureDeclaration | MethodSignature | ConstructSignatureDeclaration | CallSignatureDeclaration; - interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { + interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatementBase { kind: SyntaxKind.FunctionDeclaration; name?: Identifier; body?: FunctionBody; } - interface MethodSignature extends SignatureDeclarationBase, TypeElement { + interface MethodSignature extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.MethodSignature; name: PropertyName; } - interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.MethodDeclaration; name: PropertyName; body?: FunctionBody; } - interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer { + interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, JSDocContainer { kind: SyntaxKind.Constructor; parent?: ClassDeclaration | ClassExpression; body?: FunctionBody; } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ - interface SemicolonClassElement extends ClassElement { + interface SemicolonClassElement extends ClassElementBase { kind: SyntaxKind.SemicolonClassElement; parent?: ClassDeclaration | ClassExpression; } - interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.GetAccessor; parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression; name: PropertyName; body: FunctionBody; } - interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.SetAccessor; parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression; name: PropertyName; body: FunctionBody; } type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; - interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { + interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElementBase, TypeElementBase { kind: SyntaxKind.IndexSignature; parent?: ClassDeclaration | ClassExpression | InterfaceDeclaration | TypeLiteralNode; } - interface TypeNode extends Node { + interface TypeNodeBase extends BaseNode { _typeNodeBrand: any; } - interface KeywordTypeNode extends TypeNode { - kind: SyntaxKind.AnyKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.VoidKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.NullKeyword | SyntaxKind.NeverKeyword; - } - interface ThisTypeNode extends TypeNode { + interface ThisTypeNode extends TypeNodeBase { kind: SyntaxKind.ThisType; } type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; - interface FunctionTypeNode extends TypeNode, SignatureDeclarationBase { + interface FunctionTypeNode extends TypeNodeBase, SignatureDeclarationBase { kind: SyntaxKind.FunctionType; } - interface ConstructorTypeNode extends TypeNode, SignatureDeclarationBase { + interface ConstructorTypeNode extends TypeNodeBase, SignatureDeclarationBase { kind: SyntaxKind.ConstructorType; } type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; - interface TypeReferenceNode extends TypeNode { + interface TypeReferenceNode extends TypeNodeBase { kind: SyntaxKind.TypeReference; typeName: EntityName; typeArguments?: NodeArray; } - interface TypePredicateNode extends TypeNode { + interface TypePredicateNode extends TypeNodeBase { kind: SyntaxKind.TypePredicate; parent?: SignatureDeclaration; parameterName: Identifier | ThisTypeNode; type: TypeNode; } - interface TypeQueryNode extends TypeNode { + interface TypeQueryNode extends TypeNodeBase { kind: SyntaxKind.TypeQuery; exprName: EntityName; } - interface TypeLiteralNode extends TypeNode, Declaration { + interface TypeLiteralNode extends TypeNodeBase, DeclarationBase { kind: SyntaxKind.TypeLiteral; members: NodeArray; } - interface ArrayTypeNode extends TypeNode { + interface ArrayTypeNode extends TypeNodeBase { kind: SyntaxKind.ArrayType; elementType: TypeNode; } - interface TupleTypeNode extends TypeNode { + interface TupleTypeNode extends TypeNodeBase { kind: SyntaxKind.TupleType; elementTypes: NodeArray; } type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; - interface UnionTypeNode extends TypeNode { + interface UnionTypeNode extends TypeNodeBase { kind: SyntaxKind.UnionType; types: NodeArray; } - interface IntersectionTypeNode extends TypeNode { + interface IntersectionTypeNode extends TypeNodeBase { kind: SyntaxKind.IntersectionType; types: NodeArray; } - interface ParenthesizedTypeNode extends TypeNode { + interface ParenthesizedTypeNode extends TypeNodeBase { kind: SyntaxKind.ParenthesizedType; type: TypeNode; } - interface TypeOperatorNode extends TypeNode { + interface TypeOperatorNode extends TypeNodeBase { kind: SyntaxKind.TypeOperator; operator: SyntaxKind.KeyOfKeyword; type: TypeNode; } - interface IndexedAccessTypeNode extends TypeNode { + interface IndexedAccessTypeNode extends TypeNodeBase { kind: SyntaxKind.IndexedAccessType; objectType: TypeNode; indexType: TypeNode; } - interface MappedTypeNode extends TypeNode, Declaration { + interface MappedTypeNode extends TypeNodeBase, DeclarationBase { kind: SyntaxKind.MappedType; readonlyToken?: ReadonlyToken; typeParameter: TypeParameterDeclaration; questionToken?: QuestionToken; type?: TypeNode; } - interface LiteralTypeNode extends TypeNode { + interface LiteralTypeNode extends TypeNodeBase { kind: SyntaxKind.LiteralType; literal: BooleanLiteral | LiteralExpression | PrefixUnaryExpression; } - interface StringLiteral extends LiteralExpression { + interface StringLiteral extends LiteralExpressionBase { kind: SyntaxKind.StringLiteral; } - interface Expression extends Node { + interface ExpressionBase extends BaseNode { _expressionBrand: any; } - interface OmittedExpression extends Expression { + interface OmittedExpression extends ExpressionBase { kind: SyntaxKind.OmittedExpression; } - interface PartiallyEmittedExpression extends LeftHandSideExpression { + interface PartiallyEmittedExpression extends LeftHandSideExpressionBase { kind: SyntaxKind.PartiallyEmittedExpression; expression: Expression; } - interface UnaryExpression extends Expression { + interface UnaryExpressionBase extends ExpressionBase { _unaryExpressionBrand: any; } /** Deprecated, please use UpdateExpression */ type IncrementExpression = UpdateExpression; - interface UpdateExpression extends UnaryExpression { + interface UpdateExpressionBase extends UnaryExpressionBase { _updateExpressionBrand: any; } type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; - interface PrefixUnaryExpression extends UpdateExpression { + interface PrefixUnaryExpression extends UpdateExpressionBase { kind: SyntaxKind.PrefixUnaryExpression; operator: PrefixUnaryOperator; operand: UnaryExpression; } type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; - interface PostfixUnaryExpression extends UpdateExpression { + interface PostfixUnaryExpression extends UpdateExpressionBase { kind: SyntaxKind.PostfixUnaryExpression; operand: LeftHandSideExpression; operator: PostfixUnaryOperator; } - interface LeftHandSideExpression extends UpdateExpression { + interface LeftHandSideExpressionBase extends UpdateExpressionBase { _leftHandSideExpressionBrand: any; } - interface MemberExpression extends LeftHandSideExpression { + interface MemberExpressionBase extends LeftHandSideExpressionBase { _memberExpressionBrand: any; } - interface PrimaryExpression extends MemberExpression { + interface PrimaryExpressionBase extends MemberExpressionBase { _primaryExpressionBrand: any; } - interface NullLiteral extends PrimaryExpression, TypeNode { + interface NullLiteral extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.NullKeyword; } - interface BooleanLiteral extends PrimaryExpression, TypeNode { + interface BooleanLiteral extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword; } - interface ThisExpression extends PrimaryExpression, KeywordTypeNode { + interface ThisExpression extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.ThisKeyword; } - interface SuperExpression extends PrimaryExpression { + interface SuperExpression extends PrimaryExpressionBase { kind: SyntaxKind.SuperKeyword; } - interface ImportExpression extends PrimaryExpression { + interface ImportExpression extends PrimaryExpressionBase { kind: SyntaxKind.ImportKeyword; } - interface DeleteExpression extends UnaryExpression { + interface DeleteExpression extends UnaryExpressionBase { kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; } - interface TypeOfExpression extends UnaryExpression { + interface TypeOfExpression extends UnaryExpressionBase { kind: SyntaxKind.TypeOfExpression; expression: UnaryExpression; } - interface VoidExpression extends UnaryExpression { + interface VoidExpression extends UnaryExpressionBase { kind: SyntaxKind.VoidExpression; expression: UnaryExpression; } - interface AwaitExpression extends UnaryExpression { + interface AwaitExpression extends UnaryExpressionBase { kind: SyntaxKind.AwaitExpression; expression: UnaryExpression; } - interface YieldExpression extends Expression { + interface YieldExpression extends ExpressionBase { kind: SyntaxKind.YieldExpression; asteriskToken?: AsteriskToken; expression?: Expression; @@ -852,14 +848,14 @@ declare namespace ts { type AssignmentOperator = SyntaxKind.EqualsToken | CompoundAssignmentOperator; type AssignmentOperatorOrHigher = LogicalOperatorOrHigher | AssignmentOperator; type BinaryOperator = AssignmentOperatorOrHigher | SyntaxKind.CommaToken; - type BinaryOperatorToken = Token; - interface BinaryExpression extends Expression, Declaration { + type BinaryOperatorToken = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; + interface BinaryExpression extends ExpressionBase, DeclarationBase { kind: SyntaxKind.BinaryExpression; left: Expression; operatorToken: BinaryOperatorToken; right: Expression; } - type AssignmentOperatorToken = Token; + type AssignmentOperatorToken = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; interface AssignmentExpression extends BinaryExpression { left: LeftHandSideExpression; operatorToken: TOperator; @@ -878,7 +874,7 @@ declare namespace ts { type ArrayBindingOrAssignmentPattern = ArrayBindingPattern | ArrayLiteralExpression; type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression; type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; - interface ConditionalExpression extends Expression { + interface ConditionalExpression extends ExpressionBase { kind: SyntaxKind.ConditionalExpression; condition: Expression; questionToken: QuestionToken; @@ -888,66 +884,66 @@ declare namespace ts { } type FunctionBody = Block; type ConciseBody = FunctionBody | Expression; - interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer { + interface FunctionExpression extends PrimaryExpressionBase, FunctionLikeDeclarationBase, JSDocContainer { kind: SyntaxKind.FunctionExpression; name?: Identifier; body: FunctionBody; } - interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer { + interface ArrowFunction extends ExpressionBase, FunctionLikeDeclarationBase, JSDocContainer { kind: SyntaxKind.ArrowFunction; equalsGreaterThanToken: EqualsGreaterThanToken; body: ConciseBody; } - interface LiteralLikeNode extends Node { + interface LiteralLikeNodeBase extends BaseNode { text: string; isUnterminated?: boolean; hasExtendedUnicodeEscape?: boolean; } - interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { + interface LiteralExpressionBase extends LiteralLikeNodeBase, PrimaryExpressionBase { _literalExpressionBrand: any; } - interface RegularExpressionLiteral extends LiteralExpression { + interface RegularExpressionLiteral extends LiteralExpressionBase { kind: SyntaxKind.RegularExpressionLiteral; } - interface NoSubstitutionTemplateLiteral extends LiteralExpression { + interface NoSubstitutionTemplateLiteral extends LiteralExpressionBase { kind: SyntaxKind.NoSubstitutionTemplateLiteral; } - interface NumericLiteral extends LiteralExpression { + interface NumericLiteral extends LiteralExpressionBase { kind: SyntaxKind.NumericLiteral; } - interface TemplateHead extends LiteralLikeNode { + interface TemplateHead extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateHead; parent?: TemplateExpression; } - interface TemplateMiddle extends LiteralLikeNode { + interface TemplateMiddle extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateMiddle; parent?: TemplateSpan; } - interface TemplateTail extends LiteralLikeNode { + interface TemplateTail extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateTail; parent?: TemplateSpan; } type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; - interface TemplateExpression extends PrimaryExpression { + interface TemplateExpression extends PrimaryExpressionBase { kind: SyntaxKind.TemplateExpression; head: TemplateHead; templateSpans: NodeArray; } - interface TemplateSpan extends Node { + interface TemplateSpan extends BaseNode { kind: SyntaxKind.TemplateSpan; parent?: TemplateExpression; expression: Expression; literal: TemplateMiddle | TemplateTail; } - interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { + interface ParenthesizedExpression extends PrimaryExpressionBase, JSDocContainer { kind: SyntaxKind.ParenthesizedExpression; expression: Expression; } - interface ArrayLiteralExpression extends PrimaryExpression { + interface ArrayLiteralExpression extends PrimaryExpressionBase { kind: SyntaxKind.ArrayLiteralExpression; elements: NodeArray; } - interface SpreadElement extends Expression { + interface SpreadElement extends ExpressionBase { kind: SyntaxKind.SpreadElement; parent?: ArrayLiteralExpression | CallExpression | NewExpression; expression: Expression; @@ -958,7 +954,7 @@ declare namespace ts { * JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ - interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { + interface ObjectLiteralExpressionBase extends PrimaryExpressionBase, DeclarationBase { properties: NodeArray; } interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { @@ -966,7 +962,7 @@ declare namespace ts { } type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression; type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; - interface PropertyAccessExpression extends MemberExpression, NamedDeclaration { + interface PropertyAccessExpression extends MemberExpressionBase, NamedDeclarationBase { kind: SyntaxKind.PropertyAccessExpression; expression: LeftHandSideExpression; name: Identifier; @@ -979,7 +975,7 @@ declare namespace ts { _propertyAccessExpressionLikeQualifiedNameBrand?: any; expression: EntityNameExpression; } - interface ElementAccessExpression extends MemberExpression { + interface ElementAccessExpression extends MemberExpressionBase { kind: SyntaxKind.ElementAccessExpression; expression: LeftHandSideExpression; argumentExpression?: Expression; @@ -988,7 +984,7 @@ declare namespace ts { expression: SuperExpression; } type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; - interface CallExpression extends LeftHandSideExpression, Declaration { + interface CallExpression extends LeftHandSideExpressionBase, DeclarationBase { kind: SyntaxKind.CallExpression; expression: LeftHandSideExpression; typeArguments?: NodeArray; @@ -1000,45 +996,45 @@ declare namespace ts { interface ImportCall extends CallExpression { expression: ImportExpression; } - interface ExpressionWithTypeArguments extends TypeNode { + interface ExpressionWithTypeArguments extends TypeNodeBase { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause; expression: LeftHandSideExpression; typeArguments?: NodeArray; } - interface NewExpression extends PrimaryExpression, Declaration { + interface NewExpression extends PrimaryExpressionBase, DeclarationBase { kind: SyntaxKind.NewExpression; expression: LeftHandSideExpression; typeArguments?: NodeArray; arguments?: NodeArray; } - interface TaggedTemplateExpression extends MemberExpression { + interface TaggedTemplateExpression extends MemberExpressionBase { kind: SyntaxKind.TaggedTemplateExpression; tag: LeftHandSideExpression; template: TemplateLiteral; } type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement; - interface AsExpression extends Expression { + interface AsExpression extends ExpressionBase { kind: SyntaxKind.AsExpression; expression: Expression; type: TypeNode; } - interface TypeAssertion extends UnaryExpression { + interface TypeAssertion extends UnaryExpressionBase { kind: SyntaxKind.TypeAssertionExpression; type: TypeNode; expression: UnaryExpression; } type AssertionExpression = TypeAssertion | AsExpression; - interface NonNullExpression extends LeftHandSideExpression { + interface NonNullExpression extends LeftHandSideExpressionBase { kind: SyntaxKind.NonNullExpression; expression: Expression; } - interface MetaProperty extends PrimaryExpression { + interface MetaProperty extends PrimaryExpressionBase { kind: SyntaxKind.MetaProperty; keywordToken: SyntaxKind.NewKeyword; name: Identifier; } - interface JsxElement extends PrimaryExpression { + interface JsxElement extends PrimaryExpressionBase { kind: SyntaxKind.JsxElement; openingElement: JsxOpeningElement; children: NodeArray; @@ -1048,239 +1044,254 @@ declare namespace ts { type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression; interface JsxAttributes extends ObjectLiteralExpressionBase { + kind: SyntaxKind.JsxAttributes; parent?: JsxOpeningLikeElement; } - interface JsxOpeningElement extends Expression { + interface JsxOpeningElement extends ExpressionBase { kind: SyntaxKind.JsxOpeningElement; parent?: JsxElement; tagName: JsxTagNameExpression; attributes: JsxAttributes; } - interface JsxSelfClosingElement extends PrimaryExpression { + interface JsxSelfClosingElement extends PrimaryExpressionBase { kind: SyntaxKind.JsxSelfClosingElement; tagName: JsxTagNameExpression; attributes: JsxAttributes; } - interface JsxAttribute extends ObjectLiteralElement { + interface JsxAttribute extends ObjectLiteralElementBase { kind: SyntaxKind.JsxAttribute; parent?: JsxAttributes; name: Identifier; initializer?: StringLiteral | JsxExpression; } - interface JsxSpreadAttribute extends ObjectLiteralElement { + interface JsxSpreadAttribute extends ObjectLiteralElementBase { kind: SyntaxKind.JsxSpreadAttribute; parent?: JsxAttributes; expression: Expression; } - interface JsxClosingElement extends Node { + interface JsxClosingElement extends BaseNode { kind: SyntaxKind.JsxClosingElement; parent?: JsxElement; tagName: JsxTagNameExpression; } - interface JsxExpression extends Expression { + interface JsxExpression extends ExpressionBase { kind: SyntaxKind.JsxExpression; parent?: JsxElement | JsxAttributeLike; dotDotDotToken?: Token; expression?: Expression; } - interface JsxText extends Node { + interface JsxText extends BaseNode { kind: SyntaxKind.JsxText; containsOnlyWhiteSpaces: boolean; parent?: JsxElement; } type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement; - interface Statement extends Node { + interface StatementBase extends BaseNode { _statementBrand: any; } - interface NotEmittedStatement extends Statement { + interface NotEmittedStatement extends StatementBase { kind: SyntaxKind.NotEmittedStatement; } + /** + * Marks the end of transformed declaration to properly emit exports. + */ + interface EndOfDeclarationMarker extends StatementBase { + kind: SyntaxKind.EndOfDeclarationMarker; + } /** * A list of comma-seperated expressions. This node is only created by transformations. */ - interface CommaListExpression extends Expression { + interface CommaListExpression extends ExpressionBase { kind: SyntaxKind.CommaListExpression; elements: NodeArray; } - interface EmptyStatement extends Statement { + /** + * Marks the beginning of a merged transformed declaration. + */ + interface MergeDeclarationMarker extends StatementBase { + kind: SyntaxKind.MergeDeclarationMarker; + } + interface EmptyStatement extends StatementBase { kind: SyntaxKind.EmptyStatement; } - interface DebuggerStatement extends Statement { + interface DebuggerStatement extends StatementBase { kind: SyntaxKind.DebuggerStatement; } - interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement { + interface MissingDeclaration extends DeclarationStatementBase, ClassElementBase, ObjectLiteralElementBase, TypeElementBase { kind: SyntaxKind.MissingDeclaration; name?: Identifier; } type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; - interface Block extends Statement { + interface Block extends StatementBase { kind: SyntaxKind.Block; statements: NodeArray; } - interface VariableStatement extends Statement, JSDocContainer { + interface VariableStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.VariableStatement; declarationList: VariableDeclarationList; } - interface ExpressionStatement extends Statement, JSDocContainer { + interface ExpressionStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.ExpressionStatement; expression: Expression; } - interface IfStatement extends Statement { + interface IfStatement extends StatementBase { kind: SyntaxKind.IfStatement; expression: Expression; thenStatement: Statement; elseStatement?: Statement; } - interface IterationStatement extends Statement { + type IterationStatement = DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement; + interface IterationStatementBase extends StatementBase { statement: Statement; } - interface DoStatement extends IterationStatement { + interface DoStatement extends IterationStatementBase { kind: SyntaxKind.DoStatement; expression: Expression; } - interface WhileStatement extends IterationStatement { + interface WhileStatement extends IterationStatementBase { kind: SyntaxKind.WhileStatement; expression: Expression; } type ForInitializer = VariableDeclarationList | Expression; - interface ForStatement extends IterationStatement { + interface ForStatement extends IterationStatementBase { kind: SyntaxKind.ForStatement; initializer?: ForInitializer; condition?: Expression; incrementor?: Expression; } type ForInOrOfStatement = ForInStatement | ForOfStatement; - interface ForInStatement extends IterationStatement { + interface ForInStatement extends IterationStatementBase { kind: SyntaxKind.ForInStatement; initializer: ForInitializer; expression: Expression; } - interface ForOfStatement extends IterationStatement { + interface ForOfStatement extends IterationStatementBase { kind: SyntaxKind.ForOfStatement; awaitModifier?: AwaitKeywordToken; initializer: ForInitializer; expression: Expression; } - interface BreakStatement extends Statement { + interface BreakStatement extends StatementBase { kind: SyntaxKind.BreakStatement; label?: Identifier; } - interface ContinueStatement extends Statement { + interface ContinueStatement extends StatementBase { kind: SyntaxKind.ContinueStatement; label?: Identifier; } type BreakOrContinueStatement = BreakStatement | ContinueStatement; - interface ReturnStatement extends Statement { + interface ReturnStatement extends StatementBase { kind: SyntaxKind.ReturnStatement; expression?: Expression; } - interface WithStatement extends Statement { + interface WithStatement extends StatementBase { kind: SyntaxKind.WithStatement; expression: Expression; statement: Statement; } - interface SwitchStatement extends Statement { + interface SwitchStatement extends StatementBase { kind: SyntaxKind.SwitchStatement; expression: Expression; caseBlock: CaseBlock; possiblyExhaustive?: boolean; } - interface CaseBlock extends Node { + interface CaseBlock extends BaseNode { kind: SyntaxKind.CaseBlock; parent?: SwitchStatement; clauses: NodeArray; } - interface CaseClause extends Node { + interface CaseClause extends BaseNode { kind: SyntaxKind.CaseClause; parent?: CaseBlock; expression: Expression; statements: NodeArray; } - interface DefaultClause extends Node { + interface DefaultClause extends BaseNode { kind: SyntaxKind.DefaultClause; parent?: CaseBlock; statements: NodeArray; } type CaseOrDefaultClause = CaseClause | DefaultClause; - interface LabeledStatement extends Statement, JSDocContainer { + interface LabeledStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.LabeledStatement; label: Identifier; statement: Statement; } - interface ThrowStatement extends Statement { + interface ThrowStatement extends StatementBase { kind: SyntaxKind.ThrowStatement; expression: Expression; } - interface TryStatement extends Statement { + interface TryStatement extends StatementBase { kind: SyntaxKind.TryStatement; tryBlock: Block; catchClause?: CatchClause; finallyBlock?: Block; } - interface CatchClause extends Node { + interface CatchClause extends BaseNode { kind: SyntaxKind.CatchClause; parent?: TryStatement; variableDeclaration?: VariableDeclaration; block: Block; } type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; - interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { + type ClassLikeDeclaration = ClassDeclaration | ClassExpression; + interface ClassLikeDeclarationBase extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; name?: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; members: NodeArray; } - interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { + interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatementBase { kind: SyntaxKind.ClassDeclaration; name?: Identifier; } - interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { + interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpressionBase { kind: SyntaxKind.ClassExpression; } - type ClassLikeDeclaration = ClassDeclaration | ClassExpression; - interface ClassElement extends NamedDeclaration { + type ClassElement = PropertyDeclaration | MissingDeclaration | IndexSignatureDeclaration | AccessorDeclaration | SemicolonClassElement | ConstructorDeclaration | MethodDeclaration; + interface ClassElementBase extends NamedDeclarationBase { _classElementBrand: any; name?: PropertyName; } - interface TypeElement extends NamedDeclaration { + interface TypeElementBase extends NamedDeclarationBase { _typeElementBrand: any; name?: PropertyName; questionToken?: QuestionToken; } - interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { + interface InterfaceDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.InterfaceDeclaration; name: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; members: NodeArray; } - interface HeritageClause extends Node { + interface HeritageClause extends BaseNode { kind: SyntaxKind.HeritageClause; parent?: InterfaceDeclaration | ClassDeclaration | ClassExpression; token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; types: NodeArray; } - interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer { + interface TypeAliasDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.TypeAliasDeclaration; name: Identifier; typeParameters?: NodeArray; type: TypeNode; } - interface EnumMember extends NamedDeclaration, JSDocContainer { + interface EnumMember extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.EnumMember; parent?: EnumDeclaration; name: PropertyName; initializer?: Expression; } - interface EnumDeclaration extends DeclarationStatement, JSDocContainer { + interface EnumDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.EnumDeclaration; name: Identifier; members: NodeArray; } type ModuleName = Identifier | StringLiteral; type ModuleBody = NamespaceBody | JSDocNamespaceBody; - interface ModuleDeclaration extends DeclarationStatement, JSDocContainer { + interface ModuleDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.ModuleDeclaration; parent?: ModuleBody | SourceFile; name: ModuleName; @@ -1296,7 +1307,7 @@ declare namespace ts { name: Identifier; body: JSDocNamespaceBody; } - interface ModuleBlock extends Node, Statement { + interface ModuleBlock extends BaseNode, StatementBase { kind: SyntaxKind.ModuleBlock; parent?: ModuleDeclaration; statements: NodeArray; @@ -1307,18 +1318,18 @@ declare namespace ts { * - import x = require("mod"); * - import x = M.x; */ - interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { + interface ImportEqualsDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.ImportEqualsDeclaration; parent?: SourceFile | ModuleBlock; name: Identifier; moduleReference: ModuleReference; } - interface ExternalModuleReference extends Node { + interface ExternalModuleReference extends BaseNode { kind: SyntaxKind.ExternalModuleReference; parent?: ImportEqualsDeclaration; expression?: Expression; } - interface ImportDeclaration extends Statement { + interface ImportDeclaration extends StatementBase { kind: SyntaxKind.ImportDeclaration; parent?: SourceFile | ModuleBlock; importClause?: ImportClause; @@ -1326,53 +1337,53 @@ declare namespace ts { moduleSpecifier: Expression; } type NamedImportBindings = NamespaceImport | NamedImports; - interface ImportClause extends NamedDeclaration { + interface ImportClause extends NamedDeclarationBase { kind: SyntaxKind.ImportClause; parent?: ImportDeclaration; name?: Identifier; namedBindings?: NamedImportBindings; } - interface NamespaceImport extends NamedDeclaration { + interface NamespaceImport extends NamedDeclarationBase { kind: SyntaxKind.NamespaceImport; parent?: ImportClause; name: Identifier; } - interface NamespaceExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatementBase { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; } - interface ExportDeclaration extends DeclarationStatement { + interface ExportDeclaration extends DeclarationStatementBase { kind: SyntaxKind.ExportDeclaration; parent?: SourceFile | ModuleBlock; exportClause?: NamedExports; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } - interface NamedImports extends Node { + interface NamedImports extends BaseNode { kind: SyntaxKind.NamedImports; parent?: ImportClause; elements: NodeArray; } - interface NamedExports extends Node { + interface NamedExports extends BaseNode { kind: SyntaxKind.NamedExports; parent?: ExportDeclaration; elements: NodeArray; } type NamedImportsOrExports = NamedImports | NamedExports; - interface ImportSpecifier extends NamedDeclaration { + interface ImportSpecifier extends NamedDeclarationBase { kind: SyntaxKind.ImportSpecifier; parent?: NamedImports; propertyName?: Identifier; name: Identifier; } - interface ExportSpecifier extends NamedDeclaration { + interface ExportSpecifier extends NamedDeclarationBase { kind: SyntaxKind.ExportSpecifier; parent?: NamedExports; propertyName?: Identifier; name: Identifier; } type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; - interface ExportAssignment extends DeclarationStatement { + interface ExportAssignment extends DeclarationStatementBase { kind: SyntaxKind.ExportAssignment; parent?: SourceFile; isExportEquals?: boolean; @@ -1394,87 +1405,87 @@ declare namespace ts { pos: -1; end: -1; } - interface JSDocTypeExpression extends TypeNode { + interface JSDocTypeExpression extends TypeNodeBase { kind: SyntaxKind.JSDocTypeExpression; type: TypeNode; } - interface JSDocType extends TypeNode { + interface JSDocTypeBase extends TypeNodeBase { _jsDocTypeBrand: any; } - interface JSDocAllType extends JSDocType { + interface JSDocAllType extends JSDocTypeBase { kind: SyntaxKind.JSDocAllType; } - interface JSDocUnknownType extends JSDocType { + interface JSDocUnknownType extends JSDocTypeBase { kind: SyntaxKind.JSDocUnknownType; } - interface JSDocNonNullableType extends JSDocType { + interface JSDocNonNullableType extends JSDocTypeBase { kind: SyntaxKind.JSDocNonNullableType; type: TypeNode; } - interface JSDocNullableType extends JSDocType { + interface JSDocNullableType extends JSDocTypeBase { kind: SyntaxKind.JSDocNullableType; type: TypeNode; } - interface JSDocOptionalType extends JSDocType { + interface JSDocOptionalType extends JSDocTypeBase { kind: SyntaxKind.JSDocOptionalType; type: TypeNode; } - interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase { + interface JSDocFunctionType extends JSDocTypeBase, SignatureDeclarationBase { kind: SyntaxKind.JSDocFunctionType; } - interface JSDocVariadicType extends JSDocType { + interface JSDocVariadicType extends JSDocTypeBase { kind: SyntaxKind.JSDocVariadicType; type: TypeNode; } type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; - interface JSDoc extends Node { + interface JSDoc extends BaseNode { kind: SyntaxKind.JSDocComment; parent?: HasJSDoc; tags: NodeArray | undefined; comment: string | undefined; } - interface JSDocTag extends Node { + interface JSDocTagBase extends BaseNode { parent: JSDoc; atToken: AtToken; tagName: Identifier; comment: string | undefined; } - interface JSDocUnknownTag extends JSDocTag { + interface JSDocUnknownTag extends JSDocTagBase { kind: SyntaxKind.JSDocTag; } /** * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ - interface JSDocAugmentsTag extends JSDocTag { + interface JSDocAugmentsTag extends JSDocTagBase { kind: SyntaxKind.JSDocAugmentsTag; class: ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression; }; } - interface JSDocClassTag extends JSDocTag { + interface JSDocClassTag extends JSDocTagBase { kind: SyntaxKind.JSDocClassTag; } - interface JSDocTemplateTag extends JSDocTag { + interface JSDocTemplateTag extends JSDocTagBase { kind: SyntaxKind.JSDocTemplateTag; typeParameters: NodeArray; } - interface JSDocReturnTag extends JSDocTag { + interface JSDocReturnTag extends JSDocTagBase { kind: SyntaxKind.JSDocReturnTag; typeExpression: JSDocTypeExpression; } - interface JSDocTypeTag extends JSDocTag { + interface JSDocTypeTag extends JSDocTagBase { kind: SyntaxKind.JSDocTypeTag; typeExpression: JSDocTypeExpression; } - interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { + interface JSDocTypedefTag extends JSDocTagBase, NamedDeclarationBase { parent: JSDoc; kind: SyntaxKind.JSDocTypedefTag; fullName?: JSDocNamespaceDeclaration | Identifier; name?: Identifier; typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; } - interface JSDocPropertyLikeTag extends JSDocTag, Declaration { + interface JSDocPropertyLikeTagBase extends JSDocTagBase, DeclarationBase { parent: JSDoc; name: EntityName; typeExpression?: JSDocTypeExpression; @@ -1482,13 +1493,13 @@ declare namespace ts { isNameFirst: boolean; isBracketed: boolean; } - interface JSDocPropertyTag extends JSDocPropertyLikeTag { + interface JSDocPropertyTag extends JSDocPropertyLikeTagBase { kind: SyntaxKind.JSDocPropertyTag; } - interface JSDocParameterTag extends JSDocPropertyLikeTag { + interface JSDocParameterTag extends JSDocPropertyLikeTagBase { kind: SyntaxKind.JSDocParameterTag; } - interface JSDocTypeLiteral extends JSDocType { + interface JSDocTypeLiteral extends JSDocTypeBase { kind: SyntaxKind.JSDocTypeLiteral; jsDocPropertyTags?: ReadonlyArray; /** If true, then this type literal represents an *array* of its type. */ @@ -1559,7 +1570,7 @@ declare namespace ts { path: string; name: string; } - interface SourceFile extends Declaration { + interface SourceFile extends DeclarationBase { kind: SyntaxKind.SourceFile; statements: NodeArray; endOfFileToken: Token; @@ -1582,7 +1593,7 @@ declare namespace ts { hasNoDefaultLib: boolean; languageVersion: ScriptTarget; } - interface Bundle extends Node { + interface Bundle extends BaseNode { kind: SyntaxKind.Bundle; sourceFiles: ReadonlyArray; } @@ -2547,7 +2558,7 @@ declare namespace ts { */ onEmitNode: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void; } - interface TransformationResult { + interface TransformationResult { /** Gets the transformed source files. */ transformed: T[]; /** Gets diagnostics for the transformation. */ @@ -2665,9 +2676,42 @@ declare namespace ts { span: TextSpan; newLength: number; } - interface SyntaxList extends Node { + interface SyntaxList extends BaseNode { + kind: SyntaxKind.SyntaxList; _children: Node[]; } + type Literals = NumericLiteral | StringLiteral | JsxText | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; + type PseudoLiterals = TemplateHead | TemplateMiddle | TemplateTail; + type Tokens = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; + type Names = QualifiedName | ComputedPropertyName; + type SignatureElement = TypeParameterDeclaration | ParameterDeclaration | Decorator; + type TypeMembers = PropertySignature | PropertyDeclaration | MethodSignature | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | IndexSignatureDeclaration; + type KeywordTypeNode = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; + type TypeNode = TypePredicateNode | TypeReferenceNode | FunctionTypeNode | ConstructorTypeNode | TypeQueryNode | TypeLiteralNode | ArrayTypeNode | TupleTypeNode | UnionTypeNode | IntersectionTypeNode | ParenthesizedTypeNode | ThisTypeNode | TypeOperatorNode | IndexedAccessTypeNode | MappedTypeNode | LiteralTypeNode | ExpressionWithTypeArguments | JSDocAllType | JSDocUnknownType | JSDocNullableType | JSDocNonNullableType | JSDocOptionalType | JSDocFunctionType | JSDocVariadicType | JSDocTypeExpression | JSDocTypeLiteral | KeywordTypeNode; + type Expression = ConditionalExpression | YieldExpression | ArrowFunction | BinaryExpression | SpreadElement | AsExpression | OmittedExpression | CommaListExpression | PartiallyEmittedExpression | JsxAttributes | JsxExpression | JsxOpeningElement | UnaryExpression; + type UnaryExpression = DeleteExpression | TypeOfExpression | VoidExpression | AwaitExpression | TypeAssertion | UpdateExpression; + type UpdateExpression = PrefixUnaryExpression | PostfixUnaryExpression | LeftHandSideExpression; + type LeftHandSideExpression = PartiallyEmittedExpression | CallExpression | NonNullExpression | MemberExpression; + type MemberExpression = PropertyAccessExpression | PropertyAccessEntityNameExpression | ElementAccessExpression | TaggedTemplateExpression | PrimaryExpression; + type PrimaryExpression = Identifier | NullLiteral | BooleanLiteral | ThisExpression | SuperExpression | ImportExpression | FunctionExpression | LiteralExpression | TemplateExpression | ParenthesizedExpression | ArrayLiteralExpression | ObjectLiteralExpression | NewExpression | MetaProperty | JsxElement | JsxSelfClosingElement | ClassExpression; + type LiteralExpression = StringLiteral | RegularExpressionLiteral | NoSubstitutionTemplateLiteral | NumericLiteral; + type Miscellaneous = TemplateSpan | SemicolonClassElement; + type Elements = Block | VariableStatement | EmptyStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | ContinueStatement | BreakStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | DebuggerStatement | VariableDeclaration | VariableDeclarationList | FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ModuleBlock | CaseBlock | NamespaceExportDeclaration | ImportEqualsDeclaration | ImportDeclaration | ImportClause | NamespaceImport | NamedImports | ImportSpecifier | ExportAssignment | ExportDeclaration | NamedExports | ExportSpecifier | MissingDeclaration; + type JSXNodes = JsxElement | JsxSelfClosingElement | JsxOpeningElement | JsxClosingElement | JsxAttribute | JsxAttributes | JsxSpreadAttribute | JsxExpression; + type Clauses = CaseClause | DefaultClause | HeritageClause | CatchClause; + type PropertyAssignments = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment; + type JSDocNode = JSDocTypeExpression | JSDocAllType | JSDocUnknownType | JSDocNullableType | JSDocNonNullableType | JSDocOptionalType | JSDocFunctionType | JSDocVariadicType | JSDoc | JSDocUnknownTag | JSDocAugmentsTag | JSDocClassTag | JSDocParameterTag | JSDocReturnTag | JSDocTypeTag | JSDocTemplateTag | JSDocTypedefTag | JSDocPropertyTag | JSDocTypeLiteral; + type TransformationNodes = NotEmittedStatement | PartiallyEmittedExpression | CommaListExpression | MergeDeclarationMarker | EndOfDeclarationMarker; + type Statement = NotEmittedStatement | EndOfDeclarationMarker | MergeDeclarationMarker | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | IterationStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | ImportDeclaration | DeclarationStatement; + type JSDocTag = JSDocUnknownTag | JSDocAugmentsTag | JSDocClassTag | JSDocTemplateTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag | JSDocPropertyLikeTag; + type JSDocPropertyLikeTag = JSDocPropertyTag | JSDocParameterTag; + type Declaration = TypeLiteralNode | MappedTypeNode | BinaryExpression | ObjectLiteralExpression | JsxAttributes | CallExpression | NewExpression | JSDocPropertyLikeTag | PropertyAccessExpression | JSDocTypedefTag | NamedDeclaration | SourceFile; + type NamedDeclaration = DeclarationStatement | TypeParameterDeclaration | SignatureDeclaration | VariableDeclaration | ParameterDeclaration | BindingElement | ObjectLiteralElement | VariableLikeDeclaration | ClassLikeDeclaration | ClassElement | TypeElement | EnumMember | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier; + type DeclarationStatement = FunctionDeclaration | MissingDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | NamespaceExportDeclaration | ExportDeclaration | ExportAssignment; + type ObjectLiteralElement = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration | JsxAttribute | JsxSpreadAttribute; + type TypeElement = CallSignatureDeclaration | ConstructSignatureDeclaration | PropertySignature | MethodSignature | IndexSignatureDeclaration | MissingDeclaration; + type LiteralLikeNode = LiteralExpression | TemplateHead | TemplateMiddle | TemplateTail; + type Node = Literals | PseudoLiterals | Tokens | Names | SignatureElement | TypeMembers | TypeNode | BindingPattern | BindingElement | Expression | Miscellaneous | Elements | ModuleReference | JSXNodes | Clauses | PropertyAssignments | EnumMember | SourceFile | Bundle | JSDocNode | SyntaxList | TransformationNodes; } declare namespace ts { const versionMajorMinor = "2.6"; @@ -2821,7 +2865,7 @@ declare namespace ts { */ function unescapeIdentifier(id: string): string; function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | undefined; - function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined; + function getNameOfDeclaration(declaration: Declaration): DeclarationName | QualifiedName | undefined; /** * Gets the JSDoc parameter tags for the node if present. * @@ -3323,7 +3367,7 @@ declare namespace ts { function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray): UnionTypeNode; function createIntersectionTypeNode(types: TypeNode[]): IntersectionTypeNode; function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray): IntersectionTypeNode; - function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: ReadonlyArray): UnionOrIntersectionTypeNode; + function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: ReadonlyArray): UnionTypeNode | IntersectionTypeNode; function createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; function createThisTypeNode(): ThisTypeNode; @@ -3769,7 +3813,7 @@ declare namespace ts { function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program; } declare namespace ts { - interface Node { + interface BaseNode { getSourceFile(): SourceFile; getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0c74f74c7413c..7c91902d64adb 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -352,7 +352,7 @@ declare namespace ts { CommaListExpression = 289, MergeDeclarationMarker = 290, EndOfDeclarationMarker = 291, - Count = 292, + Count = 291, FirstAssignment = 58, LastAssignment = 70, FirstCompoundAssignment = 59, @@ -439,7 +439,7 @@ declare namespace ts { IntrinsicIndexedElement = 2, IntrinsicElement = 3, } - interface Node extends TextRange { + interface BaseNode extends TextRange { kind: SyntaxKind; flags: NodeFlags; decorators?: NodeArray; @@ -449,10 +449,10 @@ declare namespace ts { interface JSDocContainer { } type HasJSDoc = ParameterDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | PropertySignature | ArrowFunction | ParenthesizedExpression | SpreadAssignment | ShorthandPropertyAssignment | PropertyAssignment | FunctionExpression | LabeledStatement | ExpressionStatement | VariableStatement | FunctionDeclaration | ConstructorDeclaration | MethodDeclaration | PropertyDeclaration | AccessorDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumMember | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | EndOfFileToken; - interface NodeArray extends ReadonlyArray, TextRange { + interface NodeArray extends ReadonlyArray, TextRange { hasTrailingComma?: boolean; } - interface Token extends Node { + interface Token extends BaseNode { kind: TKind; } type DotDotDotToken = Token; @@ -467,7 +467,7 @@ declare namespace ts { type AwaitKeywordToken = Token; type Modifier = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; type ModifiersArray = NodeArray; - interface Identifier extends PrimaryExpression { + interface Identifier extends PrimaryExpressionBase { kind: SyntaxKind.Identifier; /** * Prefer to use `id.unescapedText`. (Note: This is available only in services, not internally to the TypeScript compiler.) @@ -480,7 +480,7 @@ declare namespace ts { interface TransientIdentifier extends Identifier { resolvedSymbol: Symbol; } - interface QualifiedName extends Node { + interface QualifiedName extends BaseNode { kind: SyntaxKind.QualifiedName; left: EntityName; right: Identifier; @@ -488,25 +488,25 @@ declare namespace ts { type EntityName = Identifier | QualifiedName; type PropertyName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName; type DeclarationName = Identifier | StringLiteral | NumericLiteral | ComputedPropertyName | BindingPattern; - interface Declaration extends Node { + interface DeclarationBase extends BaseNode { _declarationBrand: any; } - interface NamedDeclaration extends Declaration { + interface NamedDeclarationBase extends DeclarationBase { name?: DeclarationName; } - interface DeclarationStatement extends NamedDeclaration, Statement { + interface DeclarationStatementBase extends NamedDeclarationBase, StatementBase { name?: Identifier | StringLiteral | NumericLiteral; } - interface ComputedPropertyName extends Node { + interface ComputedPropertyName extends BaseNode { kind: SyntaxKind.ComputedPropertyName; expression: Expression; } - interface Decorator extends Node { + interface Decorator extends BaseNode { kind: SyntaxKind.Decorator; parent?: NamedDeclaration; expression: LeftHandSideExpression; } - interface TypeParameterDeclaration extends NamedDeclaration { + interface TypeParameterDeclaration extends NamedDeclarationBase { kind: SyntaxKind.TypeParameter; parent?: DeclarationWithTypeParameters; name: Identifier; @@ -514,7 +514,7 @@ declare namespace ts { default?: TypeNode; expression?: Expression; } - interface SignatureDeclarationBase extends NamedDeclaration, JSDocContainer { + interface SignatureDeclarationBase extends NamedDeclarationBase, JSDocContainer { kind: SignatureDeclaration["kind"]; name?: PropertyName; typeParameters?: NodeArray; @@ -522,26 +522,26 @@ declare namespace ts { type: TypeNode | undefined; } type SignatureDeclaration = CallSignatureDeclaration | ConstructSignatureDeclaration | MethodSignature | IndexSignatureDeclaration | FunctionTypeNode | ConstructorTypeNode | JSDocFunctionType | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | AccessorDeclaration | FunctionExpression | ArrowFunction; - interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElement { + interface CallSignatureDeclaration extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.CallSignature; } - interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElement { + interface ConstructSignatureDeclaration extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.ConstructSignature; } type BindingName = Identifier | BindingPattern; - interface VariableDeclaration extends NamedDeclaration { + interface VariableDeclaration extends NamedDeclarationBase { kind: SyntaxKind.VariableDeclaration; parent?: VariableDeclarationList | CatchClause; name: BindingName; type?: TypeNode; initializer?: Expression; } - interface VariableDeclarationList extends Node { + interface VariableDeclarationList extends BaseNode { kind: SyntaxKind.VariableDeclarationList; parent?: VariableStatement | ForStatement | ForOfStatement | ForInStatement; declarations: NodeArray; } - interface ParameterDeclaration extends NamedDeclaration, JSDocContainer { + interface ParameterDeclaration extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.Parameter; parent?: SignatureDeclaration; dotDotDotToken?: DotDotDotToken; @@ -550,7 +550,7 @@ declare namespace ts { type?: TypeNode; initializer?: Expression; } - interface BindingElement extends NamedDeclaration { + interface BindingElement extends NamedDeclarationBase { kind: SyntaxKind.BindingElement; parent?: BindingPattern; propertyName?: PropertyName; @@ -558,33 +558,33 @@ declare namespace ts { name: BindingName; initializer?: Expression; } - interface PropertySignature extends TypeElement, JSDocContainer { + interface PropertySignature extends TypeElementBase, JSDocContainer { kind: SyntaxKind.PropertySignature; name: PropertyName; questionToken?: QuestionToken; type?: TypeNode; initializer?: Expression; } - interface PropertyDeclaration extends ClassElement, JSDocContainer { + interface PropertyDeclaration extends ClassElementBase, JSDocContainer { kind: SyntaxKind.PropertyDeclaration; questionToken?: QuestionToken; name: PropertyName; type?: TypeNode; initializer?: Expression; } - interface ObjectLiteralElement extends NamedDeclaration { + interface ObjectLiteralElementBase extends NamedDeclarationBase { _objectLiteralBrandBrand: any; name?: PropertyName; } type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration; - interface PropertyAssignment extends ObjectLiteralElement, JSDocContainer { + interface PropertyAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.PropertyAssignment; name: PropertyName; questionToken?: QuestionToken; initializer: Expression; } - interface ShorthandPropertyAssignment extends ObjectLiteralElement, JSDocContainer { + interface ShorthandPropertyAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.ShorthandPropertyAssignment; name: Identifier; @@ -592,12 +592,12 @@ declare namespace ts { equalsToken?: Token; objectAssignmentInitializer?: Expression; } - interface SpreadAssignment extends ObjectLiteralElement, JSDocContainer { + interface SpreadAssignment extends ObjectLiteralElementBase, JSDocContainer { parent: ObjectLiteralExpression; kind: SyntaxKind.SpreadAssignment; expression: Expression; } - interface VariableLikeDeclaration extends NamedDeclaration { + interface VariableLikeDeclarationBase extends NamedDeclarationBase { propertyName?: PropertyName; dotDotDotToken?: DotDotDotToken; name: DeclarationName; @@ -605,15 +605,14 @@ declare namespace ts { type?: TypeNode; initializer?: Expression; } - interface PropertyLikeDeclaration extends NamedDeclaration { - name: PropertyName; - } - interface ObjectBindingPattern extends Node { + type VariableLikeDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertySignature | PropertyAssignment | JsxAttribute | ShorthandPropertyAssignment | EnumMember | JSDocPropertyLikeTag; + type VariableLikeInitializedDeclaration = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | JsxAttribute | EnumMember; + interface ObjectBindingPattern extends BaseNode { kind: SyntaxKind.ObjectBindingPattern; parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; } - interface ArrayBindingPattern extends Node { + interface ArrayBindingPattern extends BaseNode { kind: SyntaxKind.ArrayBindingPattern; parent?: VariableDeclaration | ParameterDeclaration | BindingElement; elements: NodeArray; @@ -636,199 +635,196 @@ declare namespace ts { } type FunctionLikeDeclaration = FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | FunctionExpression | ArrowFunction; type FunctionLike = FunctionLikeDeclaration | FunctionTypeNode | ConstructorTypeNode | IndexSignatureDeclaration | MethodSignature | ConstructSignatureDeclaration | CallSignatureDeclaration; - interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatement { + interface FunctionDeclaration extends FunctionLikeDeclarationBase, DeclarationStatementBase { kind: SyntaxKind.FunctionDeclaration; name?: Identifier; body?: FunctionBody; } - interface MethodSignature extends SignatureDeclarationBase, TypeElement { + interface MethodSignature extends SignatureDeclarationBase, TypeElementBase { kind: SyntaxKind.MethodSignature; name: PropertyName; } - interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + interface MethodDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.MethodDeclaration; name: PropertyName; body?: FunctionBody; } - interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer { + interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, JSDocContainer { kind: SyntaxKind.Constructor; parent?: ClassDeclaration | ClassExpression; body?: FunctionBody; } /** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */ - interface SemicolonClassElement extends ClassElement { + interface SemicolonClassElement extends ClassElementBase { kind: SyntaxKind.SemicolonClassElement; parent?: ClassDeclaration | ClassExpression; } - interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.GetAccessor; parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression; name: PropertyName; body: FunctionBody; } - interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer { + interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElementBase, ObjectLiteralElementBase, JSDocContainer { kind: SyntaxKind.SetAccessor; parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression; name: PropertyName; body: FunctionBody; } type AccessorDeclaration = GetAccessorDeclaration | SetAccessorDeclaration; - interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement { + interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElementBase, TypeElementBase { kind: SyntaxKind.IndexSignature; parent?: ClassDeclaration | ClassExpression | InterfaceDeclaration | TypeLiteralNode; } - interface TypeNode extends Node { + interface TypeNodeBase extends BaseNode { _typeNodeBrand: any; } - interface KeywordTypeNode extends TypeNode { - kind: SyntaxKind.AnyKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.VoidKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.NullKeyword | SyntaxKind.NeverKeyword; - } - interface ThisTypeNode extends TypeNode { + interface ThisTypeNode extends TypeNodeBase { kind: SyntaxKind.ThisType; } type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; - interface FunctionTypeNode extends TypeNode, SignatureDeclarationBase { + interface FunctionTypeNode extends TypeNodeBase, SignatureDeclarationBase { kind: SyntaxKind.FunctionType; } - interface ConstructorTypeNode extends TypeNode, SignatureDeclarationBase { + interface ConstructorTypeNode extends TypeNodeBase, SignatureDeclarationBase { kind: SyntaxKind.ConstructorType; } type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments; - interface TypeReferenceNode extends TypeNode { + interface TypeReferenceNode extends TypeNodeBase { kind: SyntaxKind.TypeReference; typeName: EntityName; typeArguments?: NodeArray; } - interface TypePredicateNode extends TypeNode { + interface TypePredicateNode extends TypeNodeBase { kind: SyntaxKind.TypePredicate; parent?: SignatureDeclaration; parameterName: Identifier | ThisTypeNode; type: TypeNode; } - interface TypeQueryNode extends TypeNode { + interface TypeQueryNode extends TypeNodeBase { kind: SyntaxKind.TypeQuery; exprName: EntityName; } - interface TypeLiteralNode extends TypeNode, Declaration { + interface TypeLiteralNode extends TypeNodeBase, DeclarationBase { kind: SyntaxKind.TypeLiteral; members: NodeArray; } - interface ArrayTypeNode extends TypeNode { + interface ArrayTypeNode extends TypeNodeBase { kind: SyntaxKind.ArrayType; elementType: TypeNode; } - interface TupleTypeNode extends TypeNode { + interface TupleTypeNode extends TypeNodeBase { kind: SyntaxKind.TupleType; elementTypes: NodeArray; } type UnionOrIntersectionTypeNode = UnionTypeNode | IntersectionTypeNode; - interface UnionTypeNode extends TypeNode { + interface UnionTypeNode extends TypeNodeBase { kind: SyntaxKind.UnionType; types: NodeArray; } - interface IntersectionTypeNode extends TypeNode { + interface IntersectionTypeNode extends TypeNodeBase { kind: SyntaxKind.IntersectionType; types: NodeArray; } - interface ParenthesizedTypeNode extends TypeNode { + interface ParenthesizedTypeNode extends TypeNodeBase { kind: SyntaxKind.ParenthesizedType; type: TypeNode; } - interface TypeOperatorNode extends TypeNode { + interface TypeOperatorNode extends TypeNodeBase { kind: SyntaxKind.TypeOperator; operator: SyntaxKind.KeyOfKeyword; type: TypeNode; } - interface IndexedAccessTypeNode extends TypeNode { + interface IndexedAccessTypeNode extends TypeNodeBase { kind: SyntaxKind.IndexedAccessType; objectType: TypeNode; indexType: TypeNode; } - interface MappedTypeNode extends TypeNode, Declaration { + interface MappedTypeNode extends TypeNodeBase, DeclarationBase { kind: SyntaxKind.MappedType; readonlyToken?: ReadonlyToken; typeParameter: TypeParameterDeclaration; questionToken?: QuestionToken; type?: TypeNode; } - interface LiteralTypeNode extends TypeNode { + interface LiteralTypeNode extends TypeNodeBase { kind: SyntaxKind.LiteralType; literal: BooleanLiteral | LiteralExpression | PrefixUnaryExpression; } - interface StringLiteral extends LiteralExpression { + interface StringLiteral extends LiteralExpressionBase { kind: SyntaxKind.StringLiteral; } - interface Expression extends Node { + interface ExpressionBase extends BaseNode { _expressionBrand: any; } - interface OmittedExpression extends Expression { + interface OmittedExpression extends ExpressionBase { kind: SyntaxKind.OmittedExpression; } - interface PartiallyEmittedExpression extends LeftHandSideExpression { + interface PartiallyEmittedExpression extends LeftHandSideExpressionBase { kind: SyntaxKind.PartiallyEmittedExpression; expression: Expression; } - interface UnaryExpression extends Expression { + interface UnaryExpressionBase extends ExpressionBase { _unaryExpressionBrand: any; } /** Deprecated, please use UpdateExpression */ type IncrementExpression = UpdateExpression; - interface UpdateExpression extends UnaryExpression { + interface UpdateExpressionBase extends UnaryExpressionBase { _updateExpressionBrand: any; } type PrefixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken | SyntaxKind.ExclamationToken; - interface PrefixUnaryExpression extends UpdateExpression { + interface PrefixUnaryExpression extends UpdateExpressionBase { kind: SyntaxKind.PrefixUnaryExpression; operator: PrefixUnaryOperator; operand: UnaryExpression; } type PostfixUnaryOperator = SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken; - interface PostfixUnaryExpression extends UpdateExpression { + interface PostfixUnaryExpression extends UpdateExpressionBase { kind: SyntaxKind.PostfixUnaryExpression; operand: LeftHandSideExpression; operator: PostfixUnaryOperator; } - interface LeftHandSideExpression extends UpdateExpression { + interface LeftHandSideExpressionBase extends UpdateExpressionBase { _leftHandSideExpressionBrand: any; } - interface MemberExpression extends LeftHandSideExpression { + interface MemberExpressionBase extends LeftHandSideExpressionBase { _memberExpressionBrand: any; } - interface PrimaryExpression extends MemberExpression { + interface PrimaryExpressionBase extends MemberExpressionBase { _primaryExpressionBrand: any; } - interface NullLiteral extends PrimaryExpression, TypeNode { + interface NullLiteral extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.NullKeyword; } - interface BooleanLiteral extends PrimaryExpression, TypeNode { + interface BooleanLiteral extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.TrueKeyword | SyntaxKind.FalseKeyword; } - interface ThisExpression extends PrimaryExpression, KeywordTypeNode { + interface ThisExpression extends PrimaryExpressionBase, TypeNodeBase { kind: SyntaxKind.ThisKeyword; } - interface SuperExpression extends PrimaryExpression { + interface SuperExpression extends PrimaryExpressionBase { kind: SyntaxKind.SuperKeyword; } - interface ImportExpression extends PrimaryExpression { + interface ImportExpression extends PrimaryExpressionBase { kind: SyntaxKind.ImportKeyword; } - interface DeleteExpression extends UnaryExpression { + interface DeleteExpression extends UnaryExpressionBase { kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; } - interface TypeOfExpression extends UnaryExpression { + interface TypeOfExpression extends UnaryExpressionBase { kind: SyntaxKind.TypeOfExpression; expression: UnaryExpression; } - interface VoidExpression extends UnaryExpression { + interface VoidExpression extends UnaryExpressionBase { kind: SyntaxKind.VoidExpression; expression: UnaryExpression; } - interface AwaitExpression extends UnaryExpression { + interface AwaitExpression extends UnaryExpressionBase { kind: SyntaxKind.AwaitExpression; expression: UnaryExpression; } - interface YieldExpression extends Expression { + interface YieldExpression extends ExpressionBase { kind: SyntaxKind.YieldExpression; asteriskToken?: AsteriskToken; expression?: Expression; @@ -852,14 +848,14 @@ declare namespace ts { type AssignmentOperator = SyntaxKind.EqualsToken | CompoundAssignmentOperator; type AssignmentOperatorOrHigher = LogicalOperatorOrHigher | AssignmentOperator; type BinaryOperator = AssignmentOperatorOrHigher | SyntaxKind.CommaToken; - type BinaryOperatorToken = Token; - interface BinaryExpression extends Expression, Declaration { + type BinaryOperatorToken = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; + interface BinaryExpression extends ExpressionBase, DeclarationBase { kind: SyntaxKind.BinaryExpression; left: Expression; operatorToken: BinaryOperatorToken; right: Expression; } - type AssignmentOperatorToken = Token; + type AssignmentOperatorToken = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; interface AssignmentExpression extends BinaryExpression { left: LeftHandSideExpression; operatorToken: TOperator; @@ -878,7 +874,7 @@ declare namespace ts { type ArrayBindingOrAssignmentPattern = ArrayBindingPattern | ArrayLiteralExpression; type AssignmentPattern = ObjectLiteralExpression | ArrayLiteralExpression; type BindingOrAssignmentPattern = ObjectBindingOrAssignmentPattern | ArrayBindingOrAssignmentPattern; - interface ConditionalExpression extends Expression { + interface ConditionalExpression extends ExpressionBase { kind: SyntaxKind.ConditionalExpression; condition: Expression; questionToken: QuestionToken; @@ -888,66 +884,66 @@ declare namespace ts { } type FunctionBody = Block; type ConciseBody = FunctionBody | Expression; - interface FunctionExpression extends PrimaryExpression, FunctionLikeDeclarationBase, JSDocContainer { + interface FunctionExpression extends PrimaryExpressionBase, FunctionLikeDeclarationBase, JSDocContainer { kind: SyntaxKind.FunctionExpression; name?: Identifier; body: FunctionBody; } - interface ArrowFunction extends Expression, FunctionLikeDeclarationBase, JSDocContainer { + interface ArrowFunction extends ExpressionBase, FunctionLikeDeclarationBase, JSDocContainer { kind: SyntaxKind.ArrowFunction; equalsGreaterThanToken: EqualsGreaterThanToken; body: ConciseBody; } - interface LiteralLikeNode extends Node { + interface LiteralLikeNodeBase extends BaseNode { text: string; isUnterminated?: boolean; hasExtendedUnicodeEscape?: boolean; } - interface LiteralExpression extends LiteralLikeNode, PrimaryExpression { + interface LiteralExpressionBase extends LiteralLikeNodeBase, PrimaryExpressionBase { _literalExpressionBrand: any; } - interface RegularExpressionLiteral extends LiteralExpression { + interface RegularExpressionLiteral extends LiteralExpressionBase { kind: SyntaxKind.RegularExpressionLiteral; } - interface NoSubstitutionTemplateLiteral extends LiteralExpression { + interface NoSubstitutionTemplateLiteral extends LiteralExpressionBase { kind: SyntaxKind.NoSubstitutionTemplateLiteral; } - interface NumericLiteral extends LiteralExpression { + interface NumericLiteral extends LiteralExpressionBase { kind: SyntaxKind.NumericLiteral; } - interface TemplateHead extends LiteralLikeNode { + interface TemplateHead extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateHead; parent?: TemplateExpression; } - interface TemplateMiddle extends LiteralLikeNode { + interface TemplateMiddle extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateMiddle; parent?: TemplateSpan; } - interface TemplateTail extends LiteralLikeNode { + interface TemplateTail extends LiteralLikeNodeBase { kind: SyntaxKind.TemplateTail; parent?: TemplateSpan; } type TemplateLiteral = TemplateExpression | NoSubstitutionTemplateLiteral; - interface TemplateExpression extends PrimaryExpression { + interface TemplateExpression extends PrimaryExpressionBase { kind: SyntaxKind.TemplateExpression; head: TemplateHead; templateSpans: NodeArray; } - interface TemplateSpan extends Node { + interface TemplateSpan extends BaseNode { kind: SyntaxKind.TemplateSpan; parent?: TemplateExpression; expression: Expression; literal: TemplateMiddle | TemplateTail; } - interface ParenthesizedExpression extends PrimaryExpression, JSDocContainer { + interface ParenthesizedExpression extends PrimaryExpressionBase, JSDocContainer { kind: SyntaxKind.ParenthesizedExpression; expression: Expression; } - interface ArrayLiteralExpression extends PrimaryExpression { + interface ArrayLiteralExpression extends PrimaryExpressionBase { kind: SyntaxKind.ArrayLiteralExpression; elements: NodeArray; } - interface SpreadElement extends Expression { + interface SpreadElement extends ExpressionBase { kind: SyntaxKind.SpreadElement; parent?: ArrayLiteralExpression | CallExpression | NewExpression; expression: Expression; @@ -958,7 +954,7 @@ declare namespace ts { * JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) */ - interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { + interface ObjectLiteralExpressionBase extends PrimaryExpressionBase, DeclarationBase { properties: NodeArray; } interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { @@ -966,7 +962,7 @@ declare namespace ts { } type EntityNameExpression = Identifier | PropertyAccessEntityNameExpression | ParenthesizedExpression; type EntityNameOrEntityNameExpression = EntityName | EntityNameExpression; - interface PropertyAccessExpression extends MemberExpression, NamedDeclaration { + interface PropertyAccessExpression extends MemberExpressionBase, NamedDeclarationBase { kind: SyntaxKind.PropertyAccessExpression; expression: LeftHandSideExpression; name: Identifier; @@ -979,7 +975,7 @@ declare namespace ts { _propertyAccessExpressionLikeQualifiedNameBrand?: any; expression: EntityNameExpression; } - interface ElementAccessExpression extends MemberExpression { + interface ElementAccessExpression extends MemberExpressionBase { kind: SyntaxKind.ElementAccessExpression; expression: LeftHandSideExpression; argumentExpression?: Expression; @@ -988,7 +984,7 @@ declare namespace ts { expression: SuperExpression; } type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; - interface CallExpression extends LeftHandSideExpression, Declaration { + interface CallExpression extends LeftHandSideExpressionBase, DeclarationBase { kind: SyntaxKind.CallExpression; expression: LeftHandSideExpression; typeArguments?: NodeArray; @@ -1000,45 +996,45 @@ declare namespace ts { interface ImportCall extends CallExpression { expression: ImportExpression; } - interface ExpressionWithTypeArguments extends TypeNode { + interface ExpressionWithTypeArguments extends TypeNodeBase { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause; expression: LeftHandSideExpression; typeArguments?: NodeArray; } - interface NewExpression extends PrimaryExpression, Declaration { + interface NewExpression extends PrimaryExpressionBase, DeclarationBase { kind: SyntaxKind.NewExpression; expression: LeftHandSideExpression; typeArguments?: NodeArray; arguments?: NodeArray; } - interface TaggedTemplateExpression extends MemberExpression { + interface TaggedTemplateExpression extends MemberExpressionBase { kind: SyntaxKind.TaggedTemplateExpression; tag: LeftHandSideExpression; template: TemplateLiteral; } type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator | JsxOpeningLikeElement; - interface AsExpression extends Expression { + interface AsExpression extends ExpressionBase { kind: SyntaxKind.AsExpression; expression: Expression; type: TypeNode; } - interface TypeAssertion extends UnaryExpression { + interface TypeAssertion extends UnaryExpressionBase { kind: SyntaxKind.TypeAssertionExpression; type: TypeNode; expression: UnaryExpression; } type AssertionExpression = TypeAssertion | AsExpression; - interface NonNullExpression extends LeftHandSideExpression { + interface NonNullExpression extends LeftHandSideExpressionBase { kind: SyntaxKind.NonNullExpression; expression: Expression; } - interface MetaProperty extends PrimaryExpression { + interface MetaProperty extends PrimaryExpressionBase { kind: SyntaxKind.MetaProperty; keywordToken: SyntaxKind.NewKeyword; name: Identifier; } - interface JsxElement extends PrimaryExpression { + interface JsxElement extends PrimaryExpressionBase { kind: SyntaxKind.JsxElement; openingElement: JsxOpeningElement; children: NodeArray; @@ -1048,239 +1044,254 @@ declare namespace ts { type JsxAttributeLike = JsxAttribute | JsxSpreadAttribute; type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression; interface JsxAttributes extends ObjectLiteralExpressionBase { + kind: SyntaxKind.JsxAttributes; parent?: JsxOpeningLikeElement; } - interface JsxOpeningElement extends Expression { + interface JsxOpeningElement extends ExpressionBase { kind: SyntaxKind.JsxOpeningElement; parent?: JsxElement; tagName: JsxTagNameExpression; attributes: JsxAttributes; } - interface JsxSelfClosingElement extends PrimaryExpression { + interface JsxSelfClosingElement extends PrimaryExpressionBase { kind: SyntaxKind.JsxSelfClosingElement; tagName: JsxTagNameExpression; attributes: JsxAttributes; } - interface JsxAttribute extends ObjectLiteralElement { + interface JsxAttribute extends ObjectLiteralElementBase { kind: SyntaxKind.JsxAttribute; parent?: JsxAttributes; name: Identifier; initializer?: StringLiteral | JsxExpression; } - interface JsxSpreadAttribute extends ObjectLiteralElement { + interface JsxSpreadAttribute extends ObjectLiteralElementBase { kind: SyntaxKind.JsxSpreadAttribute; parent?: JsxAttributes; expression: Expression; } - interface JsxClosingElement extends Node { + interface JsxClosingElement extends BaseNode { kind: SyntaxKind.JsxClosingElement; parent?: JsxElement; tagName: JsxTagNameExpression; } - interface JsxExpression extends Expression { + interface JsxExpression extends ExpressionBase { kind: SyntaxKind.JsxExpression; parent?: JsxElement | JsxAttributeLike; dotDotDotToken?: Token; expression?: Expression; } - interface JsxText extends Node { + interface JsxText extends BaseNode { kind: SyntaxKind.JsxText; containsOnlyWhiteSpaces: boolean; parent?: JsxElement; } type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement; - interface Statement extends Node { + interface StatementBase extends BaseNode { _statementBrand: any; } - interface NotEmittedStatement extends Statement { + interface NotEmittedStatement extends StatementBase { kind: SyntaxKind.NotEmittedStatement; } + /** + * Marks the end of transformed declaration to properly emit exports. + */ + interface EndOfDeclarationMarker extends StatementBase { + kind: SyntaxKind.EndOfDeclarationMarker; + } /** * A list of comma-seperated expressions. This node is only created by transformations. */ - interface CommaListExpression extends Expression { + interface CommaListExpression extends ExpressionBase { kind: SyntaxKind.CommaListExpression; elements: NodeArray; } - interface EmptyStatement extends Statement { + /** + * Marks the beginning of a merged transformed declaration. + */ + interface MergeDeclarationMarker extends StatementBase { + kind: SyntaxKind.MergeDeclarationMarker; + } + interface EmptyStatement extends StatementBase { kind: SyntaxKind.EmptyStatement; } - interface DebuggerStatement extends Statement { + interface DebuggerStatement extends StatementBase { kind: SyntaxKind.DebuggerStatement; } - interface MissingDeclaration extends DeclarationStatement, ClassElement, ObjectLiteralElement, TypeElement { + interface MissingDeclaration extends DeclarationStatementBase, ClassElementBase, ObjectLiteralElementBase, TypeElementBase { kind: SyntaxKind.MissingDeclaration; name?: Identifier; } type BlockLike = SourceFile | Block | ModuleBlock | CaseOrDefaultClause; - interface Block extends Statement { + interface Block extends StatementBase { kind: SyntaxKind.Block; statements: NodeArray; } - interface VariableStatement extends Statement, JSDocContainer { + interface VariableStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.VariableStatement; declarationList: VariableDeclarationList; } - interface ExpressionStatement extends Statement, JSDocContainer { + interface ExpressionStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.ExpressionStatement; expression: Expression; } - interface IfStatement extends Statement { + interface IfStatement extends StatementBase { kind: SyntaxKind.IfStatement; expression: Expression; thenStatement: Statement; elseStatement?: Statement; } - interface IterationStatement extends Statement { + type IterationStatement = DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement; + interface IterationStatementBase extends StatementBase { statement: Statement; } - interface DoStatement extends IterationStatement { + interface DoStatement extends IterationStatementBase { kind: SyntaxKind.DoStatement; expression: Expression; } - interface WhileStatement extends IterationStatement { + interface WhileStatement extends IterationStatementBase { kind: SyntaxKind.WhileStatement; expression: Expression; } type ForInitializer = VariableDeclarationList | Expression; - interface ForStatement extends IterationStatement { + interface ForStatement extends IterationStatementBase { kind: SyntaxKind.ForStatement; initializer?: ForInitializer; condition?: Expression; incrementor?: Expression; } type ForInOrOfStatement = ForInStatement | ForOfStatement; - interface ForInStatement extends IterationStatement { + interface ForInStatement extends IterationStatementBase { kind: SyntaxKind.ForInStatement; initializer: ForInitializer; expression: Expression; } - interface ForOfStatement extends IterationStatement { + interface ForOfStatement extends IterationStatementBase { kind: SyntaxKind.ForOfStatement; awaitModifier?: AwaitKeywordToken; initializer: ForInitializer; expression: Expression; } - interface BreakStatement extends Statement { + interface BreakStatement extends StatementBase { kind: SyntaxKind.BreakStatement; label?: Identifier; } - interface ContinueStatement extends Statement { + interface ContinueStatement extends StatementBase { kind: SyntaxKind.ContinueStatement; label?: Identifier; } type BreakOrContinueStatement = BreakStatement | ContinueStatement; - interface ReturnStatement extends Statement { + interface ReturnStatement extends StatementBase { kind: SyntaxKind.ReturnStatement; expression?: Expression; } - interface WithStatement extends Statement { + interface WithStatement extends StatementBase { kind: SyntaxKind.WithStatement; expression: Expression; statement: Statement; } - interface SwitchStatement extends Statement { + interface SwitchStatement extends StatementBase { kind: SyntaxKind.SwitchStatement; expression: Expression; caseBlock: CaseBlock; possiblyExhaustive?: boolean; } - interface CaseBlock extends Node { + interface CaseBlock extends BaseNode { kind: SyntaxKind.CaseBlock; parent?: SwitchStatement; clauses: NodeArray; } - interface CaseClause extends Node { + interface CaseClause extends BaseNode { kind: SyntaxKind.CaseClause; parent?: CaseBlock; expression: Expression; statements: NodeArray; } - interface DefaultClause extends Node { + interface DefaultClause extends BaseNode { kind: SyntaxKind.DefaultClause; parent?: CaseBlock; statements: NodeArray; } type CaseOrDefaultClause = CaseClause | DefaultClause; - interface LabeledStatement extends Statement, JSDocContainer { + interface LabeledStatement extends StatementBase, JSDocContainer { kind: SyntaxKind.LabeledStatement; label: Identifier; statement: Statement; } - interface ThrowStatement extends Statement { + interface ThrowStatement extends StatementBase { kind: SyntaxKind.ThrowStatement; expression: Expression; } - interface TryStatement extends Statement { + interface TryStatement extends StatementBase { kind: SyntaxKind.TryStatement; tryBlock: Block; catchClause?: CatchClause; finallyBlock?: Block; } - interface CatchClause extends Node { + interface CatchClause extends BaseNode { kind: SyntaxKind.CatchClause; parent?: TryStatement; variableDeclaration?: VariableDeclaration; block: Block; } type DeclarationWithTypeParameters = SignatureDeclaration | ClassLikeDeclaration | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag; - interface ClassLikeDeclarationBase extends NamedDeclaration, JSDocContainer { + type ClassLikeDeclaration = ClassDeclaration | ClassExpression; + interface ClassLikeDeclarationBase extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.ClassDeclaration | SyntaxKind.ClassExpression; name?: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; members: NodeArray; } - interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatement { + interface ClassDeclaration extends ClassLikeDeclarationBase, DeclarationStatementBase { kind: SyntaxKind.ClassDeclaration; name?: Identifier; } - interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpression { + interface ClassExpression extends ClassLikeDeclarationBase, PrimaryExpressionBase { kind: SyntaxKind.ClassExpression; } - type ClassLikeDeclaration = ClassDeclaration | ClassExpression; - interface ClassElement extends NamedDeclaration { + type ClassElement = PropertyDeclaration | MissingDeclaration | IndexSignatureDeclaration | AccessorDeclaration | SemicolonClassElement | ConstructorDeclaration | MethodDeclaration; + interface ClassElementBase extends NamedDeclarationBase { _classElementBrand: any; name?: PropertyName; } - interface TypeElement extends NamedDeclaration { + interface TypeElementBase extends NamedDeclarationBase { _typeElementBrand: any; name?: PropertyName; questionToken?: QuestionToken; } - interface InterfaceDeclaration extends DeclarationStatement, JSDocContainer { + interface InterfaceDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.InterfaceDeclaration; name: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; members: NodeArray; } - interface HeritageClause extends Node { + interface HeritageClause extends BaseNode { kind: SyntaxKind.HeritageClause; parent?: InterfaceDeclaration | ClassDeclaration | ClassExpression; token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword; types: NodeArray; } - interface TypeAliasDeclaration extends DeclarationStatement, JSDocContainer { + interface TypeAliasDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.TypeAliasDeclaration; name: Identifier; typeParameters?: NodeArray; type: TypeNode; } - interface EnumMember extends NamedDeclaration, JSDocContainer { + interface EnumMember extends NamedDeclarationBase, JSDocContainer { kind: SyntaxKind.EnumMember; parent?: EnumDeclaration; name: PropertyName; initializer?: Expression; } - interface EnumDeclaration extends DeclarationStatement, JSDocContainer { + interface EnumDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.EnumDeclaration; name: Identifier; members: NodeArray; } type ModuleName = Identifier | StringLiteral; type ModuleBody = NamespaceBody | JSDocNamespaceBody; - interface ModuleDeclaration extends DeclarationStatement, JSDocContainer { + interface ModuleDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.ModuleDeclaration; parent?: ModuleBody | SourceFile; name: ModuleName; @@ -1296,7 +1307,7 @@ declare namespace ts { name: Identifier; body: JSDocNamespaceBody; } - interface ModuleBlock extends Node, Statement { + interface ModuleBlock extends BaseNode, StatementBase { kind: SyntaxKind.ModuleBlock; parent?: ModuleDeclaration; statements: NodeArray; @@ -1307,18 +1318,18 @@ declare namespace ts { * - import x = require("mod"); * - import x = M.x; */ - interface ImportEqualsDeclaration extends DeclarationStatement, JSDocContainer { + interface ImportEqualsDeclaration extends DeclarationStatementBase, JSDocContainer { kind: SyntaxKind.ImportEqualsDeclaration; parent?: SourceFile | ModuleBlock; name: Identifier; moduleReference: ModuleReference; } - interface ExternalModuleReference extends Node { + interface ExternalModuleReference extends BaseNode { kind: SyntaxKind.ExternalModuleReference; parent?: ImportEqualsDeclaration; expression?: Expression; } - interface ImportDeclaration extends Statement { + interface ImportDeclaration extends StatementBase { kind: SyntaxKind.ImportDeclaration; parent?: SourceFile | ModuleBlock; importClause?: ImportClause; @@ -1326,53 +1337,53 @@ declare namespace ts { moduleSpecifier: Expression; } type NamedImportBindings = NamespaceImport | NamedImports; - interface ImportClause extends NamedDeclaration { + interface ImportClause extends NamedDeclarationBase { kind: SyntaxKind.ImportClause; parent?: ImportDeclaration; name?: Identifier; namedBindings?: NamedImportBindings; } - interface NamespaceImport extends NamedDeclaration { + interface NamespaceImport extends NamedDeclarationBase { kind: SyntaxKind.NamespaceImport; parent?: ImportClause; name: Identifier; } - interface NamespaceExportDeclaration extends DeclarationStatement { + interface NamespaceExportDeclaration extends DeclarationStatementBase { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; } - interface ExportDeclaration extends DeclarationStatement { + interface ExportDeclaration extends DeclarationStatementBase { kind: SyntaxKind.ExportDeclaration; parent?: SourceFile | ModuleBlock; exportClause?: NamedExports; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } - interface NamedImports extends Node { + interface NamedImports extends BaseNode { kind: SyntaxKind.NamedImports; parent?: ImportClause; elements: NodeArray; } - interface NamedExports extends Node { + interface NamedExports extends BaseNode { kind: SyntaxKind.NamedExports; parent?: ExportDeclaration; elements: NodeArray; } type NamedImportsOrExports = NamedImports | NamedExports; - interface ImportSpecifier extends NamedDeclaration { + interface ImportSpecifier extends NamedDeclarationBase { kind: SyntaxKind.ImportSpecifier; parent?: NamedImports; propertyName?: Identifier; name: Identifier; } - interface ExportSpecifier extends NamedDeclaration { + interface ExportSpecifier extends NamedDeclarationBase { kind: SyntaxKind.ExportSpecifier; parent?: NamedExports; propertyName?: Identifier; name: Identifier; } type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier; - interface ExportAssignment extends DeclarationStatement { + interface ExportAssignment extends DeclarationStatementBase { kind: SyntaxKind.ExportAssignment; parent?: SourceFile; isExportEquals?: boolean; @@ -1394,87 +1405,87 @@ declare namespace ts { pos: -1; end: -1; } - interface JSDocTypeExpression extends TypeNode { + interface JSDocTypeExpression extends TypeNodeBase { kind: SyntaxKind.JSDocTypeExpression; type: TypeNode; } - interface JSDocType extends TypeNode { + interface JSDocTypeBase extends TypeNodeBase { _jsDocTypeBrand: any; } - interface JSDocAllType extends JSDocType { + interface JSDocAllType extends JSDocTypeBase { kind: SyntaxKind.JSDocAllType; } - interface JSDocUnknownType extends JSDocType { + interface JSDocUnknownType extends JSDocTypeBase { kind: SyntaxKind.JSDocUnknownType; } - interface JSDocNonNullableType extends JSDocType { + interface JSDocNonNullableType extends JSDocTypeBase { kind: SyntaxKind.JSDocNonNullableType; type: TypeNode; } - interface JSDocNullableType extends JSDocType { + interface JSDocNullableType extends JSDocTypeBase { kind: SyntaxKind.JSDocNullableType; type: TypeNode; } - interface JSDocOptionalType extends JSDocType { + interface JSDocOptionalType extends JSDocTypeBase { kind: SyntaxKind.JSDocOptionalType; type: TypeNode; } - interface JSDocFunctionType extends JSDocType, SignatureDeclarationBase { + interface JSDocFunctionType extends JSDocTypeBase, SignatureDeclarationBase { kind: SyntaxKind.JSDocFunctionType; } - interface JSDocVariadicType extends JSDocType { + interface JSDocVariadicType extends JSDocTypeBase { kind: SyntaxKind.JSDocVariadicType; type: TypeNode; } type JSDocTypeReferencingNode = JSDocVariadicType | JSDocOptionalType | JSDocNullableType | JSDocNonNullableType; - interface JSDoc extends Node { + interface JSDoc extends BaseNode { kind: SyntaxKind.JSDocComment; parent?: HasJSDoc; tags: NodeArray | undefined; comment: string | undefined; } - interface JSDocTag extends Node { + interface JSDocTagBase extends BaseNode { parent: JSDoc; atToken: AtToken; tagName: Identifier; comment: string | undefined; } - interface JSDocUnknownTag extends JSDocTag { + interface JSDocUnknownTag extends JSDocTagBase { kind: SyntaxKind.JSDocTag; } /** * Note that `@extends` is a synonym of `@augments`. * Both tags are represented by this interface. */ - interface JSDocAugmentsTag extends JSDocTag { + interface JSDocAugmentsTag extends JSDocTagBase { kind: SyntaxKind.JSDocAugmentsTag; class: ExpressionWithTypeArguments & { expression: Identifier | PropertyAccessEntityNameExpression; }; } - interface JSDocClassTag extends JSDocTag { + interface JSDocClassTag extends JSDocTagBase { kind: SyntaxKind.JSDocClassTag; } - interface JSDocTemplateTag extends JSDocTag { + interface JSDocTemplateTag extends JSDocTagBase { kind: SyntaxKind.JSDocTemplateTag; typeParameters: NodeArray; } - interface JSDocReturnTag extends JSDocTag { + interface JSDocReturnTag extends JSDocTagBase { kind: SyntaxKind.JSDocReturnTag; typeExpression: JSDocTypeExpression; } - interface JSDocTypeTag extends JSDocTag { + interface JSDocTypeTag extends JSDocTagBase { kind: SyntaxKind.JSDocTypeTag; typeExpression: JSDocTypeExpression; } - interface JSDocTypedefTag extends JSDocTag, NamedDeclaration { + interface JSDocTypedefTag extends JSDocTagBase, NamedDeclarationBase { parent: JSDoc; kind: SyntaxKind.JSDocTypedefTag; fullName?: JSDocNamespaceDeclaration | Identifier; name?: Identifier; typeExpression?: JSDocTypeExpression | JSDocTypeLiteral; } - interface JSDocPropertyLikeTag extends JSDocTag, Declaration { + interface JSDocPropertyLikeTagBase extends JSDocTagBase, DeclarationBase { parent: JSDoc; name: EntityName; typeExpression?: JSDocTypeExpression; @@ -1482,13 +1493,13 @@ declare namespace ts { isNameFirst: boolean; isBracketed: boolean; } - interface JSDocPropertyTag extends JSDocPropertyLikeTag { + interface JSDocPropertyTag extends JSDocPropertyLikeTagBase { kind: SyntaxKind.JSDocPropertyTag; } - interface JSDocParameterTag extends JSDocPropertyLikeTag { + interface JSDocParameterTag extends JSDocPropertyLikeTagBase { kind: SyntaxKind.JSDocParameterTag; } - interface JSDocTypeLiteral extends JSDocType { + interface JSDocTypeLiteral extends JSDocTypeBase { kind: SyntaxKind.JSDocTypeLiteral; jsDocPropertyTags?: ReadonlyArray; /** If true, then this type literal represents an *array* of its type. */ @@ -1559,7 +1570,7 @@ declare namespace ts { path: string; name: string; } - interface SourceFile extends Declaration { + interface SourceFile extends DeclarationBase { kind: SyntaxKind.SourceFile; statements: NodeArray; endOfFileToken: Token; @@ -1582,7 +1593,7 @@ declare namespace ts { hasNoDefaultLib: boolean; languageVersion: ScriptTarget; } - interface Bundle extends Node { + interface Bundle extends BaseNode { kind: SyntaxKind.Bundle; sourceFiles: ReadonlyArray; } @@ -2547,7 +2558,7 @@ declare namespace ts { */ onEmitNode: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void; } - interface TransformationResult { + interface TransformationResult { /** Gets the transformed source files. */ transformed: T[]; /** Gets diagnostics for the transformation. */ @@ -2665,9 +2676,42 @@ declare namespace ts { span: TextSpan; newLength: number; } - interface SyntaxList extends Node { + interface SyntaxList extends BaseNode { + kind: SyntaxKind.SyntaxList; _children: Node[]; } + type Literals = NumericLiteral | StringLiteral | JsxText | RegularExpressionLiteral | NoSubstitutionTemplateLiteral; + type PseudoLiterals = TemplateHead | TemplateMiddle | TemplateTail; + type Tokens = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; + type Names = QualifiedName | ComputedPropertyName; + type SignatureElement = TypeParameterDeclaration | ParameterDeclaration | Decorator; + type TypeMembers = PropertySignature | PropertyDeclaration | MethodSignature | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | CallSignatureDeclaration | ConstructSignatureDeclaration | IndexSignatureDeclaration; + type KeywordTypeNode = Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token | Token; + type TypeNode = TypePredicateNode | TypeReferenceNode | FunctionTypeNode | ConstructorTypeNode | TypeQueryNode | TypeLiteralNode | ArrayTypeNode | TupleTypeNode | UnionTypeNode | IntersectionTypeNode | ParenthesizedTypeNode | ThisTypeNode | TypeOperatorNode | IndexedAccessTypeNode | MappedTypeNode | LiteralTypeNode | ExpressionWithTypeArguments | JSDocAllType | JSDocUnknownType | JSDocNullableType | JSDocNonNullableType | JSDocOptionalType | JSDocFunctionType | JSDocVariadicType | JSDocTypeExpression | JSDocTypeLiteral | KeywordTypeNode; + type Expression = ConditionalExpression | YieldExpression | ArrowFunction | BinaryExpression | SpreadElement | AsExpression | OmittedExpression | CommaListExpression | PartiallyEmittedExpression | JsxAttributes | JsxExpression | JsxOpeningElement | UnaryExpression; + type UnaryExpression = DeleteExpression | TypeOfExpression | VoidExpression | AwaitExpression | TypeAssertion | UpdateExpression; + type UpdateExpression = PrefixUnaryExpression | PostfixUnaryExpression | LeftHandSideExpression; + type LeftHandSideExpression = PartiallyEmittedExpression | CallExpression | NonNullExpression | MemberExpression; + type MemberExpression = PropertyAccessExpression | PropertyAccessEntityNameExpression | ElementAccessExpression | TaggedTemplateExpression | PrimaryExpression; + type PrimaryExpression = Identifier | NullLiteral | BooleanLiteral | ThisExpression | SuperExpression | ImportExpression | FunctionExpression | LiteralExpression | TemplateExpression | ParenthesizedExpression | ArrayLiteralExpression | ObjectLiteralExpression | NewExpression | MetaProperty | JsxElement | JsxSelfClosingElement | ClassExpression; + type LiteralExpression = StringLiteral | RegularExpressionLiteral | NoSubstitutionTemplateLiteral | NumericLiteral; + type Miscellaneous = TemplateSpan | SemicolonClassElement; + type Elements = Block | VariableStatement | EmptyStatement | ExpressionStatement | IfStatement | DoStatement | WhileStatement | ForStatement | ForInStatement | ForOfStatement | ContinueStatement | BreakStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | DebuggerStatement | VariableDeclaration | VariableDeclarationList | FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ModuleBlock | CaseBlock | NamespaceExportDeclaration | ImportEqualsDeclaration | ImportDeclaration | ImportClause | NamespaceImport | NamedImports | ImportSpecifier | ExportAssignment | ExportDeclaration | NamedExports | ExportSpecifier | MissingDeclaration; + type JSXNodes = JsxElement | JsxSelfClosingElement | JsxOpeningElement | JsxClosingElement | JsxAttribute | JsxAttributes | JsxSpreadAttribute | JsxExpression; + type Clauses = CaseClause | DefaultClause | HeritageClause | CatchClause; + type PropertyAssignments = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment; + type JSDocNode = JSDocTypeExpression | JSDocAllType | JSDocUnknownType | JSDocNullableType | JSDocNonNullableType | JSDocOptionalType | JSDocFunctionType | JSDocVariadicType | JSDoc | JSDocUnknownTag | JSDocAugmentsTag | JSDocClassTag | JSDocParameterTag | JSDocReturnTag | JSDocTypeTag | JSDocTemplateTag | JSDocTypedefTag | JSDocPropertyTag | JSDocTypeLiteral; + type TransformationNodes = NotEmittedStatement | PartiallyEmittedExpression | CommaListExpression | MergeDeclarationMarker | EndOfDeclarationMarker; + type Statement = NotEmittedStatement | EndOfDeclarationMarker | MergeDeclarationMarker | EmptyStatement | DebuggerStatement | Block | VariableStatement | ExpressionStatement | IfStatement | IterationStatement | BreakStatement | ContinueStatement | ReturnStatement | WithStatement | SwitchStatement | LabeledStatement | ThrowStatement | TryStatement | ImportDeclaration | DeclarationStatement; + type JSDocTag = JSDocUnknownTag | JSDocAugmentsTag | JSDocClassTag | JSDocTemplateTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag | JSDocPropertyLikeTag; + type JSDocPropertyLikeTag = JSDocPropertyTag | JSDocParameterTag; + type Declaration = TypeLiteralNode | MappedTypeNode | BinaryExpression | ObjectLiteralExpression | JsxAttributes | CallExpression | NewExpression | JSDocPropertyLikeTag | PropertyAccessExpression | JSDocTypedefTag | NamedDeclaration | SourceFile; + type NamedDeclaration = DeclarationStatement | TypeParameterDeclaration | SignatureDeclaration | VariableDeclaration | ParameterDeclaration | BindingElement | ObjectLiteralElement | VariableLikeDeclaration | ClassLikeDeclaration | ClassElement | TypeElement | EnumMember | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier; + type DeclarationStatement = FunctionDeclaration | MissingDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | NamespaceExportDeclaration | ExportDeclaration | ExportAssignment; + type ObjectLiteralElement = PropertyAssignment | ShorthandPropertyAssignment | SpreadAssignment | MethodDeclaration | AccessorDeclaration | JsxAttribute | JsxSpreadAttribute; + type TypeElement = CallSignatureDeclaration | ConstructSignatureDeclaration | PropertySignature | MethodSignature | IndexSignatureDeclaration | MissingDeclaration; + type LiteralLikeNode = LiteralExpression | TemplateHead | TemplateMiddle | TemplateTail; + type Node = Literals | PseudoLiterals | Tokens | Names | SignatureElement | TypeMembers | TypeNode | BindingPattern | BindingElement | Expression | Miscellaneous | Elements | ModuleReference | JSXNodes | Clauses | PropertyAssignments | EnumMember | SourceFile | Bundle | JSDocNode | SyntaxList | TransformationNodes; } declare namespace ts { const versionMajorMinor = "2.6"; @@ -2876,7 +2920,7 @@ declare namespace ts { */ function unescapeIdentifier(id: string): string; function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | undefined; - function getNameOfDeclaration(declaration: Declaration | Expression): DeclarationName | undefined; + function getNameOfDeclaration(declaration: Declaration): DeclarationName | QualifiedName | undefined; /** * Gets the JSDoc parameter tags for the node if present. * @@ -3270,7 +3314,7 @@ declare namespace ts { function updateUnionTypeNode(node: UnionTypeNode, types: NodeArray): UnionTypeNode; function createIntersectionTypeNode(types: TypeNode[]): IntersectionTypeNode; function updateIntersectionTypeNode(node: IntersectionTypeNode, types: NodeArray): IntersectionTypeNode; - function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: ReadonlyArray): UnionOrIntersectionTypeNode; + function createUnionOrIntersectionTypeNode(kind: SyntaxKind.UnionType | SyntaxKind.IntersectionType, types: ReadonlyArray): UnionTypeNode | IntersectionTypeNode; function createParenthesizedType(type: TypeNode): ParenthesizedTypeNode; function updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode; function createThisTypeNode(): ThisTypeNode; @@ -3769,7 +3813,7 @@ declare namespace ts { }; } declare namespace ts { - interface Node { + interface BaseNode { getSourceFile(): SourceFile; getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node;