diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 33f14e4a454..fe3009da3aa 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -88,7 +88,7 @@ module ts { function getDeclarationName(node: Declaration): string { if (node.name) { if (node.kind === SyntaxKind.ModuleDeclaration && node.name.kind === SyntaxKind.StringLiteral) { - return '"' + (node.name).text + '"'; + return '"' + (node.name).text + '"'; } return (node.name).text; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3e0da863027..2567b54de4a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -960,15 +960,14 @@ module ts { if (declaration.kind === SyntaxKind.ImportDeclaration && !(declaration.flags & NodeFlags.Export) && isDeclarationVisible(declaration.parent)) { - var importDeclaration = declaration; - getNodeLinks(importDeclaration).isVisible = true; + getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { - if (!contains(aliasesToMakeVisible, importDeclaration)) { - aliasesToMakeVisible.push(importDeclaration); + if (!contains(aliasesToMakeVisible, declaration)) { + aliasesToMakeVisible.push(declaration); } } else { - aliasesToMakeVisible = [importDeclaration]; + aliasesToMakeVisible = [declaration]; } return true; } @@ -1639,7 +1638,7 @@ module ts { return getTypeFromTypeNode(declaration.type); } if (declaration.kind === SyntaxKind.Parameter) { - var func = declaration.parent; + var func = declaration.parent; // For a parameter of a set accessor, use the type of the get accessor if one is present if (func.kind === SyntaxKind.SetAccessor) { var getter = getDeclarationOfKind(declaration.parent.symbol, SyntaxKind.GetAccessor); @@ -2507,7 +2506,7 @@ module ts { returnType = getAnnotatedAccessorType(setter); } - if (!returnType && !(declaration).body) { + if (!returnType && !(declaration).body) { returnType = anyType; } } @@ -2537,7 +2536,7 @@ module ts { // Don't include signature if node is the implementation of an overloaded function. A node is considered // an implementation node if it has a body and the previous node is of the same kind and immediately // precedes the implementation node (i.e. has the same parent and ends where the implementation starts). - if (i > 0 && (node).body) { + if (i > 0 && (node).body) { var previous = symbol.declarations[i - 1]; if (node.parent === previous.parent && node.kind === previous.kind && node.pos === previous.end) { break; @@ -2559,7 +2558,7 @@ module ts { var type = getUnionType(map(signature.unionSignatures, getReturnTypeOfSignature)); } else { - var type = getReturnTypeFromBody(signature.declaration); + var type = getReturnTypeFromBody(signature.declaration); } if (signature.resolvedReturnType === resolvingType) { signature.resolvedReturnType = type; @@ -4666,7 +4665,7 @@ module ts { // Return contextual type of parameter or undefined if no contextual type is available function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type { - var func = parameter.parent; + var func = parameter.parent; if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) { if (isContextSensitiveExpression(func)) { var contextualSignature = getContextualSignature(func); @@ -5727,7 +5726,7 @@ module ts { } } - function getReturnTypeFromBody(func: FunctionLike, contextualMapper?: TypeMapper): Type { + function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type { var contextualSignature = getContextualSignature(func); if (func.body.kind !== SyntaxKind.FunctionBlock) { var unwidenedType = checkAndMarkExpression(func.body, contextualMapper); @@ -5805,7 +5804,7 @@ module ts { // An explicitly typed function whose return type isn't the Void or the Any type // must have at least one return statement somewhere in its body. // An exception to this rule is if the function implementation consists of a single 'throw' statement. - function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func: FunctionLike, returnType: Type): void { + function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func: FunctionLikeDeclaration, returnType: Type): void { if (!fullTypeCheck) { return; } @@ -6364,7 +6363,7 @@ module ts { } } else { - if (parameterDeclaration.initializer && !(parameterDeclaration.parent).body) { + if (parameterDeclaration.initializer && !(parameterDeclaration.parent).body) { error(parameterDeclaration, Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation); } } @@ -6373,7 +6372,7 @@ module ts { function checkReferencesInInitializer(n: Node): void { if (n.kind === SyntaxKind.Identifier) { var referencedSymbol = getNodeLinks(n).resolvedSymbol; - // check FunctionLike.locals (stores parameters\function local variable) + // check FunctionLikeDeclaration.locals (stores parameters\function local variable) // if it contains entry with a specified name and if this entry matches the resolved symbol if (referencedSymbol && referencedSymbol !== unknownSymbol && getSymbol(parameterDeclaration.parent.locals, referencedSymbol.name, SymbolFlags.Value) === referencedSymbol) { if (referencedSymbol.valueDeclaration.kind === SyntaxKind.Parameter) { @@ -6382,7 +6381,7 @@ module ts { return; } var enclosingOrReferencedParameter = - forEach((parameterDeclaration.parent).parameters, p => p === parameterDeclaration || p === referencedSymbol.valueDeclaration ? p : undefined); + forEach((parameterDeclaration.parent).parameters, p => p === parameterDeclaration || p === referencedSymbol.valueDeclaration ? p : undefined); if (enclosingOrReferencedParameter === referencedSymbol.valueDeclaration) { // legal case - parameter initializer references some parameter strictly on left of current parameter declaration @@ -6656,7 +6655,7 @@ module ts { // TypeScript 1.0 spec (April 2014): 3.7.2.2 // Specialized signatures are not permitted in conjunction with a function body - if ((signatureDeclarationNode).body) { + if ((signatureDeclarationNode).body) { error(signatureDeclarationNode, Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type); return; } @@ -6707,7 +6706,7 @@ module ts { return; } - function checkFlagAgreementBetweenOverloads(overloads: Declaration[], implementation: FunctionLike, flagsToCheck: NodeFlags, someOverloadFlags: NodeFlags, allOverloadFlags: NodeFlags): void { + function checkFlagAgreementBetweenOverloads(overloads: Declaration[], implementation: FunctionLikeDeclaration, flagsToCheck: NodeFlags, someOverloadFlags: NodeFlags, allOverloadFlags: NodeFlags): void { // Error if some overloads have a flag that is not shared by all overloads. To find the // deviations, we XOR someOverloadFlags with allOverloadFlags var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags; @@ -6743,14 +6742,14 @@ module ts { var someNodeFlags: NodeFlags = 0; var allNodeFlags = flagsToCheck; var hasOverloads = false; - var bodyDeclaration: FunctionLike; - var lastSeenNonAmbientDeclaration: FunctionLike; - var previousDeclaration: FunctionLike; + var bodyDeclaration: FunctionLikeDeclaration; + var lastSeenNonAmbientDeclaration: FunctionLikeDeclaration; + var previousDeclaration: FunctionLikeDeclaration; var declarations = symbol.declarations; var isConstructor = (symbol.flags & SymbolFlags.Constructor) !== 0; - function reportImplementationExpectedError(node: FunctionLike): void { + function reportImplementationExpectedError(node: FunctionLikeDeclaration): void { if (node.name && node.name.kind === SyntaxKind.Missing) { return; } @@ -6766,9 +6765,9 @@ module ts { }); if (subsequentNode) { if (subsequentNode.kind === node.kind) { - var errorNode: Node = (subsequentNode).name || subsequentNode; + var errorNode: Node = (subsequentNode).name || subsequentNode; // TODO(jfreeman): These are methods, so handle computed name case - if (node.name && (subsequentNode).name && (node.name).text === ((subsequentNode).name).text) { + if (node.name && (subsequentNode).name && (node.name).text === ((subsequentNode).name).text) { // the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members Debug.assert(node.kind === SyntaxKind.Method); Debug.assert((node.flags & NodeFlags.Static) !== (subsequentNode.flags & NodeFlags.Static)); @@ -6776,7 +6775,7 @@ module ts { error(errorNode, diagnostic); return; } - else if ((subsequentNode).body) { + else if ((subsequentNode).body) { error(errorNode, Diagnostics.Function_implementation_name_must_be_0, declarationNameToString(node.name)); return; } @@ -6797,7 +6796,7 @@ module ts { var duplicateFunctionDeclaration = false; var multipleConstructorImplementation = false; for (var i = 0; i < declarations.length; i++) { - var node = declarations[i]; + var node = declarations[i]; var inAmbientContext = isInAmbientContext(node); var inAmbientContextOrInterface = node.parent.kind === SyntaxKind.InterfaceDeclaration || node.parent.kind === SyntaxKind.TypeLiteral || inAmbientContext; if (inAmbientContextOrInterface) { @@ -6968,7 +6967,7 @@ module ts { } } - function checkFunctionDeclaration(node: FunctionLike): void { + function checkFunctionDeclaration(node: FunctionLikeDeclaration): void { checkSignatureDeclaration(node); var symbol = getSymbolOfNode(node); @@ -7019,7 +7018,7 @@ module ts { function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { // no rest parameters \ declaration context \ overload - no codegen impact - if (!hasRestParameters(node) || isInAmbientContext(node) || !(node).body) { + if (!hasRestParameters(node) || isInAmbientContext(node) || !(node).body) { return; } @@ -7040,7 +7039,7 @@ module ts { // - function has implementation (not a signature) // - function has rest parameters // - context is not ambient (otherwise no codegen impact) - if ((node.parent).body && hasRestParameters(node.parent) && !isInAmbientContext(node)) { + if ((node.parent).body && hasRestParameters(node.parent) && !isInAmbientContext(node)) { error(node, Diagnostics.Duplicate_identifier_i_Compiler_uses_i_to_initialize_rest_parameter); } return; @@ -7098,7 +7097,7 @@ module ts { case SyntaxKind.Method: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: - if (hasRestParameters(current)) { + if (hasRestParameters(current)) { error(node, Diagnostics.Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter); return; } @@ -7109,7 +7108,7 @@ module ts { } // TODO(jfreeman): Decide what to do for computed properties - function needCollisionCheckForIdentifier(node: Node, identifier: Identifier | ComputedPropertyName, name: string): boolean { + function needCollisionCheckForIdentifier(node: Node, identifier: DeclarationName, name: string): boolean { if (!(identifier && (identifier).text === name)) { return false; } @@ -7127,7 +7126,7 @@ module ts { return false; } - if (node.kind === SyntaxKind.Parameter && !(node.parent).body) { + if (node.kind === SyntaxKind.Parameter && !(node.parent).body) { // just an overload - no codegen impact return false; } @@ -7136,7 +7135,7 @@ module ts { } // TODO(jfreeman): Decide what to do for computed properties - function checkCollisionWithCapturedThisVariable(node: Node, name: Identifier | ComputedPropertyName): void { + function checkCollisionWithCapturedThisVariable(node: Node, name: DeclarationName): void { if (!needCollisionCheckForIdentifier(node, name, "_this")) { return; } @@ -7161,7 +7160,7 @@ module ts { } } - function checkCollisionWithCapturedSuperVariable(node: Node, name: Identifier | ComputedPropertyName) { + function checkCollisionWithCapturedSuperVariable(node: Node, name: DeclarationName) { if (!needCollisionCheckForIdentifier(node, name, "_super")) { return; } @@ -7185,7 +7184,7 @@ module ts { } // TODO(jfreeman): Decide what to do for computed properties - function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: Identifier | ComputedPropertyName) { + function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: DeclarationName) { if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { return; } @@ -7490,7 +7489,7 @@ module ts { } // TODO(jfreeman): Decide what to do for computed properties - function checkTypeNameIsReserved(name: Identifier | ComputedPropertyName, message: DiagnosticMessage): void { + function checkTypeNameIsReserved(name: DeclarationName, message: DiagnosticMessage): void { // TS 1.0 spec (April 2014): 3.6.1 // The predefined type keywords are reserved and cannot be used as names of user defined types. switch ((name).text) { @@ -7977,7 +7976,7 @@ module ts { var declarations = symbol.declarations; for (var i = 0; i < declarations.length; i++) { var declaration = declarations[i]; - if ((declaration.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.FunctionDeclaration && (declaration).body)) && !isInAmbientContext(declaration)) { + if ((declaration.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.FunctionDeclaration && (declaration).body)) && !isInAmbientContext(declaration)) { return declaration; } } @@ -8124,7 +8123,7 @@ module ts { case SyntaxKind.ParenType: return checkSourceElement((node).type); case SyntaxKind.FunctionDeclaration: - return checkFunctionDeclaration(node); + return checkFunctionDeclaration(node); case SyntaxKind.Block: return checkBlock(node); case SyntaxKind.FunctionBlock: @@ -8191,7 +8190,7 @@ module ts { switch (node.kind) { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - forEach((node).parameters, checkFunctionExpressionBodies); + forEach((node).parameters, checkFunctionExpressionBodies); checkFunctionExpressionBody(node); break; case SyntaxKind.Method: @@ -8199,7 +8198,7 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: - forEach((node).parameters, checkFunctionExpressionBodies); + forEach((node).parameters, checkFunctionExpressionBodies); break; case SyntaxKind.WithStatement: checkFunctionExpressionBodies((node).expression); @@ -8481,7 +8480,7 @@ module ts { case SyntaxKind.Method: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return node === (parent).type; + return node === (parent).type; case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: @@ -8825,7 +8824,7 @@ module ts { return false; } - function isImplementationOfOverload(node: FunctionLike) { + function isImplementationOfOverload(node: FunctionLikeDeclaration) { if (node.body) { var symbol = getSymbolOfNode(node); var signaturesOfSymbol = getSignaturesOfSymbol(symbol); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a81cfc18224..f61d4403eec 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -909,7 +909,7 @@ module ts { // This function specifically handles numeric/string literals for enum and accessor 'identifiers'. // In a sense, it does not actually emit identifiers as much as it declares a name for a specific property. - function emitExpressionForPropertyName(node: Identifier | ComputedPropertyName) { + function emitExpressionForPropertyName(node: DeclarationName) { if (node.kind === SyntaxKind.StringLiteral) { emitLiteral(node); } @@ -1466,7 +1466,7 @@ module ts { emitTrailingComments(node); } - function emitDefaultValueAssignments(node: FunctionLike) { + function emitDefaultValueAssignments(node: FunctionLikeDeclaration) { forEach(node.parameters, param => { if (param.initializer) { writeLine(); @@ -1486,7 +1486,7 @@ module ts { }); } - function emitRestParameter(node: FunctionLike) { + function emitRestParameter(node: FunctionLikeDeclaration) { if (hasRestParameters(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; @@ -1532,7 +1532,7 @@ module ts { emitTrailingComments(node); } - function emitFunctionDeclaration(node: FunctionLike) { + function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (!node.body) { return emitPinnedOrTripleSlashComments(node); } @@ -1560,7 +1560,7 @@ module ts { } } - function emitSignatureParameters(node: FunctionLike) { + function emitSignatureParameters(node: FunctionLikeDeclaration) { increaseIndent(); write("("); if (node) { @@ -1570,7 +1570,7 @@ module ts { decreaseIndent(); } - function emitSignatureAndBody(node: FunctionLike) { + function emitSignatureAndBody(node: FunctionLikeDeclaration) { emitSignatureParameters(node); write(" {"); scopeEmitStart(node); @@ -1668,7 +1668,7 @@ module ts { } // TODO(jfreeman): Account for computed property name - function emitMemberAccess(memberName: Identifier | ComputedPropertyName) { + function emitMemberAccess(memberName: DeclarationName) { if (memberName.kind === SyntaxKind.StringLiteral || memberName.kind === SyntaxKind.NumericLiteral) { write("["); emitNode(memberName); @@ -2075,11 +2075,11 @@ module ts { function getExternalImportDeclarations(node: SourceFile): ImportDeclaration[] { var result: ImportDeclaration[] = []; forEach(node.statements, stat => { - if (stat.kind === SyntaxKind.ImportDeclaration) { - var importDeclaration = stat; - if (importDeclaration.externalModuleName && resolver.isReferencedImportDeclaration(importDeclaration)) { - result.push(importDeclaration); - } + if (stat.kind === SyntaxKind.ImportDeclaration + && (stat).externalModuleName + && resolver.isReferencedImportDeclaration(stat)) { + + result.push(stat); } }); return result; @@ -2267,7 +2267,7 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - return emitFunctionDeclaration(node); + return emitFunctionDeclaration(node); case SyntaxKind.PrefixOperator: case SyntaxKind.PostfixOperator: return emitUnaryExpression(node); @@ -2510,7 +2510,7 @@ module ts { var getSymbolVisibilityDiagnosticMessage: (symbolAccesibilityResult: SymbolAccessiblityResult) => { errorNode: Node; diagnosticMessage: DiagnosticMessage; - typeName?: Identifier | ComputedPropertyName + typeName?: DeclarationName } function createTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { @@ -3117,7 +3117,7 @@ module ts { } } - function emitFunctionDeclaration(node: FunctionLike) { + function emitFunctionDeclaration(node: FunctionLikeDeclaration) { // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting // so no need to verify if the declaration is visible if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) && @@ -3336,7 +3336,7 @@ module ts { case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.Method: - return emitFunctionDeclaration(node); + return emitFunctionDeclaration(node); case SyntaxKind.ConstructSignature: return emitConstructSignatureDeclaration(node); case SyntaxKind.CallSignature: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1e3ed77be3a..41243efa171 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -64,8 +64,8 @@ module ts { // TODO(jfreeman): Implement declarationNameToString for computed properties // Return display name of an identifier - export function declarationNameToString(identifier: Identifier | ComputedPropertyName) { - return identifier.kind === SyntaxKind.Missing ? "(Missing)" : getTextOfNode(identifier); + export function declarationNameToString(name: DeclarationName) { + return name.kind === SyntaxKind.Missing ? "(Missing)" : getTextOfNode(name); } export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic { @@ -214,11 +214,11 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - return child((node).name) || - children((node).typeParameters) || - children((node).parameters) || - child((node).type) || - child((node).body); + return child((node).name) || + children((node).typeParameters) || + children((node).parameters) || + child((node).type) || + child((node).body); case SyntaxKind.TypeReference: return child((node).typeName) || children((node).typeArguments); @@ -1632,7 +1632,7 @@ module ts { // Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code // or if its FunctionBody is strict code(11.1.5). // It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a - // strict mode FunctionLike or FunctionExpression(13.1) + // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) if (isInStrictMode && isEvalOrArgumentsIdentifier(parameter.name)) { reportInvalidUseInStrictMode(parameter.name); return; @@ -2776,7 +2776,7 @@ module ts { var body = parseBody(/* ignoreMissingOpenBrace */ false); if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) { // It is a SyntaxError to use within strict mode code the identifiers eval or arguments as the - // Identifier of a FunctionLike or FunctionExpression or as a formal parameter name(13.1) + // Identifier of a FunctionLikeDeclaration or FunctionExpression or as a formal parameter name(13.1) reportInvalidUseInStrictMode(name); } return makeFunctionExpression(SyntaxKind.FunctionExpression, pos, name, sig, body); @@ -3442,8 +3442,8 @@ module ts { return node; } - function parseFunctionDeclaration(pos?: number, flags?: NodeFlags): FunctionLike { - var node = createNode(SyntaxKind.FunctionDeclaration, pos); + function parseFunctionDeclaration(pos?: number, flags?: NodeFlags): FunctionLikeDeclaration { + var node = createNode(SyntaxKind.FunctionDeclaration, pos); if (flags) node.flags = flags; parseExpected(SyntaxKind.FunctionKeyword); node.name = parseIdentifier(); @@ -3454,7 +3454,7 @@ module ts { node.body = parseAndCheckFunctionBody(/*isConstructor*/ false); if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name) && node.name.kind === SyntaxKind.Identifier) { // It is a SyntaxError to use within strict mode code the identifiers eval or arguments as the - // Identifier of a FunctionLike or FunctionExpression or as a formal parameter name(13.1) + // Identifier of a FunctionLikeDeclaration or FunctionExpression or as a formal parameter name(13.1) reportInvalidUseInStrictMode(node.name); } return finishNode(node); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 78f07970f11..0c78706ebb6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -302,8 +302,10 @@ module ts { type?: TypeNode; } + export type DeclarationName = Identifier | LiteralExpression | ComputedPropertyName; + export interface Declaration extends Node { - name?: Identifier | ComputedPropertyName; + name?: DeclarationName; } export interface ComputedPropertyName extends Node { @@ -330,24 +332,34 @@ module ts { export interface ParameterDeclaration extends VariableDeclaration { } - export interface FunctionLike extends Declaration, ParsedSignature { + /** + * Several node kinds share function-like features such as a signature, + * a name, and a body. These nodes should extend FunctionLikeDeclaration. + * Examples: + * FunctionDeclaration + * MethodDeclaration + * ConstructorDeclaration + * AccessorDeclaration + * FunctionExpression + */ + export interface FunctionLikeDeclaration extends Declaration, ParsedSignature { body?: Block | Expression; } - export interface FunctionDeclaration extends FunctionLike { + export interface FunctionDeclaration extends FunctionLikeDeclaration { name: Identifier; body?: Block; } - export interface MethodDeclaration extends FunctionLike { + export interface MethodDeclaration extends FunctionLikeDeclaration { body?: Block; } - export interface ConstructorDeclaration extends FunctionLike { + export interface ConstructorDeclaration extends FunctionLikeDeclaration { body?: Block; } - export interface AccessorDeclaration extends FunctionLike { + export interface AccessorDeclaration extends FunctionLikeDeclaration { body?: Block; } @@ -407,7 +419,7 @@ module ts { whenFalse: Expression; } - export interface FunctionExpression extends Expression, FunctionLike { + export interface FunctionExpression extends Expression, FunctionLikeDeclaration { name?: Identifier; body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional } @@ -579,7 +591,7 @@ module ts { } export interface EnumMember extends Declaration { - name: Identifier; + name: Identifier | LiteralExpression; initializer?: Expression; } @@ -589,7 +601,7 @@ module ts { } export interface ModuleDeclaration extends Declaration { - name: Identifier; + name: Identifier | LiteralExpression; body: Block | ModuleDeclaration; } @@ -709,7 +721,7 @@ module ts { getContextualType(node: Node): Type; getResolvedSignature(node: CallExpression, candidatesOutArray?: Signature[]): Signature; getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature; - isImplementationOfOverload(node: FunctionLike): boolean; + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; isUndefinedSymbol(symbol: Symbol): boolean; isArgumentsSymbol(symbol: Symbol): boolean; hasEarlyErrors(sourceFile?: SourceFile): boolean; @@ -796,7 +808,7 @@ module ts { getEnumMemberValue(node: EnumMember): number; hasSemanticErrors(): boolean; isDeclarationVisible(node: Declaration): boolean; - isImplementationOfOverload(node: FunctionLike): boolean; + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeAtLocation(location: Node, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 08f0c745e8b..aa8ec8217ce 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -74,7 +74,7 @@ module ts.BreakpointResolver { return textSpan(node); } - if (node.parent.kind == SyntaxKind.ArrowFunction && (node.parent).body == node) { + if (node.parent.kind == SyntaxKind.ArrowFunction && (node.parent).body == node) { // If this is body of arrow function, it is allowed to have the breakpoint return textSpan(node); } @@ -99,7 +99,7 @@ module ts.BreakpointResolver { case SyntaxKind.Constructor: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - return spanInFunctionDeclaration(node); + return spanInFunctionDeclaration(node); case SyntaxKind.FunctionBlock: return spanInFunctionBlock(node); @@ -246,7 +246,7 @@ module ts.BreakpointResolver { } // return type of function go to previous token - if (isAnyFunction(node.parent) && (node.parent).type === node) { + if (isAnyFunction(node.parent) && (node.parent).type === node) { return spanInPreviousNode(node); } @@ -305,7 +305,7 @@ module ts.BreakpointResolver { return textSpan(parameter); } else { - var functionDeclaration = parameter.parent; + var functionDeclaration = parameter.parent; var indexOfParameter = indexOf(functionDeclaration.parameters, parameter); if (indexOfParameter) { // Not a first parameter, go to previous parameter @@ -318,12 +318,12 @@ module ts.BreakpointResolver { } } - function canFunctionHaveSpanInWholeDeclaration(functionDeclaration: FunctionLike) { + function canFunctionHaveSpanInWholeDeclaration(functionDeclaration: FunctionLikeDeclaration) { return !!(functionDeclaration.flags & NodeFlags.Export) || (functionDeclaration.parent.kind === SyntaxKind.ClassDeclaration && functionDeclaration.kind !== SyntaxKind.Constructor); } - function spanInFunctionDeclaration(functionDeclaration: FunctionLike): TypeScript.TextSpan { + function spanInFunctionDeclaration(functionDeclaration: FunctionLikeDeclaration): TypeScript.TextSpan { // No breakpoints in the function signature if (!functionDeclaration.body) { return undefined; @@ -340,7 +340,7 @@ module ts.BreakpointResolver { function spanInFunctionBlock(block: Block): TypeScript.TextSpan { var nodeForSpanInBlock = block.statements.length ? block.statements[0] : block.getLastToken(); - if (canFunctionHaveSpanInWholeDeclaration(block.parent)) { + if (canFunctionHaveSpanInWholeDeclaration(block.parent)) { return spanInNodeIfStartsOnSameLine(block.parent, nodeForSpanInBlock); } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 9a72f841c92..029df425045 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -361,7 +361,7 @@ module ts.formatting { case SyntaxKind.FunctionExpression: case SyntaxKind.Method: case SyntaxKind.ArrowFunction: - return !(n).body || isCompletedNode((n).body, sourceFile); + return !(n).body || isCompletedNode((n).body, sourceFile); case SyntaxKind.ModuleDeclaration: return (n).body && isCompletedNode((n).body, sourceFile); case SyntaxKind.IfStatement: diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 99cba0f6514..ca06d40fa88 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -80,7 +80,7 @@ module ts.NavigationBar { return 1; } else if (n2.name) { - -1; + return -1; } else { return n1.kind - n2.kind; @@ -107,7 +107,7 @@ module ts.NavigationBar { break; case SyntaxKind.FunctionDeclaration: - var functionDeclaration = node; + var functionDeclaration = node; if (isTopLevelFunctionDeclaration(functionDeclaration)) { topLevelNodes.push(node); addTopLevelNodes((functionDeclaration.body).statements, topLevelNodes); @@ -117,7 +117,7 @@ module ts.NavigationBar { } } - function isTopLevelFunctionDeclaration(functionDeclaration: FunctionLike) { + function isTopLevelFunctionDeclaration(functionDeclaration: FunctionLikeDeclaration) { if (functionDeclaration.kind === SyntaxKind.FunctionDeclaration) { // A function declaration is 'top level' if it contains any function declarations // within it. @@ -232,7 +232,7 @@ module ts.NavigationBar { return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.memberVariableElement); case SyntaxKind.FunctionDeclaration: - return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); + return createItem(node, getTextOfNode((node).name), ts.ScriptElementKind.functionElement); case SyntaxKind.VariableDeclaration: if (node.flags & NodeFlags.Const) { diff --git a/src/services/services.ts b/src/services/services.ts index 73cb8169dc2..d6465084fa4 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -674,7 +674,7 @@ module ts { switch (node.kind) { case SyntaxKind.FunctionDeclaration: case SyntaxKind.Method: - var functionDeclaration = node; + var functionDeclaration = node; if (functionDeclaration.name && functionDeclaration.name.kind !== SyntaxKind.Missing) { var lastDeclaration = namedDeclarations.length > 0 ? @@ -685,7 +685,7 @@ module ts { if (lastDeclaration && functionDeclaration.symbol === lastDeclaration.symbol) { // Overwrite the last declaration if it was an overload // and this one is an implementation. - if (functionDeclaration.body && !(lastDeclaration).body) { + if (functionDeclaration.body && !(lastDeclaration).body) { namedDeclarations[namedDeclarations.length - 1] = functionDeclaration; } } @@ -1963,7 +1963,7 @@ module ts { function isNameOfFunctionDeclaration(node: Node): boolean { return node.kind === SyntaxKind.Identifier && - isAnyFunction(node.parent) && (node.parent).name === node; + isAnyFunction(node.parent) && (node.parent).name === node; } /** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */ @@ -2946,7 +2946,7 @@ module ts { (location.kind === SyntaxKind.ConstructorKeyword && location.parent.kind === SyntaxKind.Constructor)) { // At constructor keyword of constructor declaration // get the signature from the declaration and write it var signature: Signature; - var functionDeclaration = location.parent; + var functionDeclaration = location.parent; var allSignatures = functionDeclaration.kind === SyntaxKind.Constructor ? type.getConstructSignatures() : type.getCallSignatures(); if (!typeResolver.isImplementationOfOverload(functionDeclaration)) { signature = typeResolver.getSignatureFromDeclaration(functionDeclaration); @@ -3226,7 +3226,7 @@ module ts { if ((selectConstructors && d.kind === SyntaxKind.Constructor) || (!selectConstructors && (d.kind === SyntaxKind.FunctionDeclaration || d.kind === SyntaxKind.Method))) { declarations.push(d); - if ((d).body) definition = d; + if ((d).body) definition = d; } }); @@ -3473,7 +3473,7 @@ module ts { } function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[] { - var func = getContainingFunction(returnStatement); + var func = getContainingFunction(returnStatement); // If we didn't find a containing function with a block body, bail out. if (!(func && hasKind(func.body, SyntaxKind.FunctionBlock))) { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 26f531a7832..8dcd06f5621 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -238,7 +238,7 @@ module ts { } if (isAnyFunction(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) { - return (node).typeParameters; + return (node).typeParameters; } return undefined;