Address feedback

This commit is contained in:
Jason Freeman 2014-11-06 11:51:49 -08:00
parent bc70e4a29d
commit 279166be50
10 changed files with 111 additions and 100 deletions

View file

@ -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 '"' + (<Identifier>node.name).text + '"';
return '"' + (<LiteralExpression>node.name).text + '"';
}
return (<Identifier>node.name).text;
}

View file

@ -960,15 +960,14 @@ module ts {
if (declaration.kind === SyntaxKind.ImportDeclaration &&
!(declaration.flags & NodeFlags.Export) &&
isDeclarationVisible(declaration.parent)) {
var importDeclaration = <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(<ImportDeclaration>declaration);
}
}
else {
aliasesToMakeVisible = [importDeclaration];
aliasesToMakeVisible = [<ImportDeclaration>declaration];
}
return true;
}
@ -1639,7 +1638,7 @@ module ts {
return getTypeFromTypeNode(declaration.type);
}
if (declaration.kind === SyntaxKind.Parameter) {
var func = <FunctionLike>declaration.parent;
var func = <FunctionLikeDeclaration>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 = <AccessorDeclaration>getDeclarationOfKind(declaration.parent.symbol, SyntaxKind.GetAccessor);
@ -2507,7 +2506,7 @@ module ts {
returnType = getAnnotatedAccessorType(setter);
}
if (!returnType && !(<FunctionLike>declaration).body) {
if (!returnType && !(<FunctionLikeDeclaration>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 && (<FunctionLike>node).body) {
if (i > 0 && (<FunctionLikeDeclaration>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(<FunctionLike>signature.declaration);
var type = getReturnTypeFromBody(<FunctionLikeDeclaration>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 = <FunctionLike>parameter.parent;
var func = <FunctionLikeDeclaration>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 && !(<FunctionLike>parameterDeclaration.parent).body) {
if (parameterDeclaration.initializer && !(<FunctionLikeDeclaration>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((<FunctionLike>parameterDeclaration.parent).parameters, p => p === parameterDeclaration || p === referencedSymbol.valueDeclaration ? p : undefined);
forEach((<FunctionLikeDeclaration>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 ((<FunctionLike>signatureDeclarationNode).body) {
if ((<FunctionLikeDeclaration>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 = (<FunctionLike>subsequentNode).name || subsequentNode;
var errorNode: Node = (<FunctionLikeDeclaration>subsequentNode).name || subsequentNode;
// TODO(jfreeman): These are methods, so handle computed name case
if (node.name && (<FunctionLike>subsequentNode).name && (<Identifier>node.name).text === (<Identifier>(<FunctionLike>subsequentNode).name).text) {
if (node.name && (<FunctionLikeDeclaration>subsequentNode).name && (<Identifier>node.name).text === (<Identifier>(<FunctionLikeDeclaration>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 ((<FunctionLike>subsequentNode).body) {
else if ((<FunctionLikeDeclaration>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 = <FunctionLike>declarations[i];
var node = <FunctionLikeDeclaration>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) || !(<FunctionLike>node).body) {
if (!hasRestParameters(node) || isInAmbientContext(node) || !(<FunctionLikeDeclaration>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 ((<FunctionLike>node.parent).body && hasRestParameters(<FunctionLike>node.parent) && !isInAmbientContext(node)) {
if ((<FunctionLikeDeclaration>node.parent).body && hasRestParameters(<FunctionLikeDeclaration>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(<FunctionLike>current)) {
if (hasRestParameters(<FunctionLikeDeclaration>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>identifier).text === name)) {
return false;
}
@ -7127,7 +7126,7 @@ module ts {
return false;
}
if (node.kind === SyntaxKind.Parameter && !(<FunctionLike>node.parent).body) {
if (node.kind === SyntaxKind.Parameter && !(<FunctionLikeDeclaration>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 ((<Identifier>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 && (<FunctionLike>declaration).body)) && !isInAmbientContext(declaration)) {
if ((declaration.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.FunctionDeclaration && (<FunctionLikeDeclaration>declaration).body)) && !isInAmbientContext(declaration)) {
return declaration;
}
}
@ -8124,7 +8123,7 @@ module ts {
case SyntaxKind.ParenType:
return checkSourceElement((<ParenTypeNode>node).type);
case SyntaxKind.FunctionDeclaration:
return checkFunctionDeclaration(<FunctionLike>node);
return checkFunctionDeclaration(<FunctionLikeDeclaration>node);
case SyntaxKind.Block:
return checkBlock(<Block>node);
case SyntaxKind.FunctionBlock:
@ -8191,7 +8190,7 @@ module ts {
switch (node.kind) {
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
forEach((<FunctionLike>node).parameters, checkFunctionExpressionBodies);
forEach((<FunctionLikeDeclaration>node).parameters, checkFunctionExpressionBodies);
checkFunctionExpressionBody(<FunctionExpression>node);
break;
case SyntaxKind.Method:
@ -8199,7 +8198,7 @@ module ts {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.FunctionDeclaration:
forEach((<FunctionLike>node).parameters, checkFunctionExpressionBodies);
forEach((<FunctionLikeDeclaration>node).parameters, checkFunctionExpressionBodies);
break;
case SyntaxKind.WithStatement:
checkFunctionExpressionBodies((<WithStatement>node).expression);
@ -8481,7 +8480,7 @@ module ts {
case SyntaxKind.Method:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return node === (<FunctionLike>parent).type;
return node === (<FunctionLikeDeclaration>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);

View file

@ -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(<LiteralExpression>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 = <ImportDeclaration>stat;
if (importDeclaration.externalModuleName && resolver.isReferencedImportDeclaration(importDeclaration)) {
result.push(importDeclaration);
}
if (stat.kind === SyntaxKind.ImportDeclaration
&& (<ImportDeclaration>stat).externalModuleName
&& resolver.isReferencedImportDeclaration(<ImportDeclaration>stat)) {
result.push(<ImportDeclaration>stat);
}
});
return result;
@ -2267,7 +2267,7 @@ module ts {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
return emitFunctionDeclaration(<FunctionLike>node);
return emitFunctionDeclaration(<FunctionLikeDeclaration>node);
case SyntaxKind.PrefixOperator:
case SyntaxKind.PostfixOperator:
return emitUnaryExpression(<UnaryExpression>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(<FunctionLike>node);
return emitFunctionDeclaration(<FunctionLikeDeclaration>node);
case SyntaxKind.ConstructSignature:
return emitConstructSignatureDeclaration(<SignatureDeclaration>node);
case SyntaxKind.CallSignature:

View file

@ -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((<FunctionLike>node).name) ||
children((<FunctionLike>node).typeParameters) ||
children((<FunctionLike>node).parameters) ||
child((<FunctionLike>node).type) ||
child((<FunctionLike>node).body);
return child((<FunctionLikeDeclaration>node).name) ||
children((<FunctionLikeDeclaration>node).typeParameters) ||
children((<FunctionLikeDeclaration>node).parameters) ||
child((<FunctionLikeDeclaration>node).type) ||
child((<FunctionLikeDeclaration>node).body);
case SyntaxKind.TypeReference:
return child((<TypeReferenceNode>node).typeName) ||
children((<TypeReferenceNode>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 = <FunctionLike>createNode(SyntaxKind.FunctionDeclaration, pos);
function parseFunctionDeclaration(pos?: number, flags?: NodeFlags): FunctionLikeDeclaration {
var node = <FunctionLikeDeclaration>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(<Identifier>node.name);
}
return finishNode(node);

View file

@ -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;

View file

@ -74,7 +74,7 @@ module ts.BreakpointResolver {
return textSpan(node);
}
if (node.parent.kind == SyntaxKind.ArrowFunction && (<FunctionLike>node.parent).body == node) {
if (node.parent.kind == SyntaxKind.ArrowFunction && (<FunctionLikeDeclaration>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(<FunctionLike>node);
return spanInFunctionDeclaration(<FunctionLikeDeclaration>node);
case SyntaxKind.FunctionBlock:
return spanInFunctionBlock(<Block>node);
@ -246,7 +246,7 @@ module ts.BreakpointResolver {
}
// return type of function go to previous token
if (isAnyFunction(node.parent) && (<FunctionLike>node.parent).type === node) {
if (isAnyFunction(node.parent) && (<FunctionLikeDeclaration>node.parent).type === node) {
return spanInPreviousNode(node);
}
@ -305,7 +305,7 @@ module ts.BreakpointResolver {
return textSpan(parameter);
}
else {
var functionDeclaration = <FunctionLike>parameter.parent;
var functionDeclaration = <FunctionLikeDeclaration>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(<FunctionLike>block.parent)) {
if (canFunctionHaveSpanInWholeDeclaration(<FunctionLikeDeclaration>block.parent)) {
return spanInNodeIfStartsOnSameLine(block.parent, nodeForSpanInBlock);
}

View file

@ -361,7 +361,7 @@ module ts.formatting {
case SyntaxKind.FunctionExpression:
case SyntaxKind.Method:
case SyntaxKind.ArrowFunction:
return !(<FunctionLike>n).body || isCompletedNode((<FunctionLike>n).body, sourceFile);
return !(<FunctionLikeDeclaration>n).body || isCompletedNode((<FunctionLikeDeclaration>n).body, sourceFile);
case SyntaxKind.ModuleDeclaration:
return (<ModuleDeclaration>n).body && isCompletedNode((<ModuleDeclaration>n).body, sourceFile);
case SyntaxKind.IfStatement:

View file

@ -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 = <FunctionLike>node;
var functionDeclaration = <FunctionLikeDeclaration>node;
if (isTopLevelFunctionDeclaration(functionDeclaration)) {
topLevelNodes.push(node);
addTopLevelNodes((<Block>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((<PropertyDeclaration>node).name), ts.ScriptElementKind.memberVariableElement);
case SyntaxKind.FunctionDeclaration:
return createItem(node, getTextOfNode((<FunctionLike>node).name), ts.ScriptElementKind.functionElement);
return createItem(node, getTextOfNode((<FunctionLikeDeclaration>node).name), ts.ScriptElementKind.functionElement);
case SyntaxKind.VariableDeclaration:
if (node.flags & NodeFlags.Const) {

View file

@ -674,7 +674,7 @@ module ts {
switch (node.kind) {
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.Method:
var functionDeclaration = <FunctionLike>node;
var functionDeclaration = <FunctionLikeDeclaration>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 && !(<FunctionLike>lastDeclaration).body) {
if (functionDeclaration.body && !(<FunctionLikeDeclaration>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) && (<FunctionLike>node.parent).name === node;
isAnyFunction(node.parent) && (<FunctionLikeDeclaration>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 = <FunctionLike>location.parent;
var functionDeclaration = <FunctionLikeDeclaration>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 ((<FunctionLike>d).body) definition = d;
if ((<FunctionLikeDeclaration>d).body) definition = d;
}
});
@ -3473,7 +3473,7 @@ module ts {
}
function getReturnOccurrences(returnStatement: ReturnStatement): ReferenceEntry[] {
var func = <FunctionLike>getContainingFunction(returnStatement);
var func = <FunctionLikeDeclaration>getContainingFunction(returnStatement);
// If we didn't find a containing function with a block body, bail out.
if (!(func && hasKind(func.body, SyntaxKind.FunctionBlock))) {

View file

@ -238,7 +238,7 @@ module ts {
}
if (isAnyFunction(node) || node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.InterfaceDeclaration) {
return (<FunctionLike>node).typeParameters;
return (<FunctionLikeDeclaration>node).typeParameters;
}
return undefined;