From b42b44efc22e70758eb4aa25b1932c19edc8e69f Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 5 Feb 2015 16:16:12 -0800 Subject: [PATCH 01/33] Initial parse and emit for decorators on declarations, class elements, and parameters --- src/compiler/emitter.ts | 482 +++++++++++++++++++++++++++++++--------- src/compiler/parser.ts | 203 +++++++++++------ src/compiler/scanner.ts | 3 + src/compiler/types.ts | 22 +- 4 files changed, 540 insertions(+), 170 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a4521977802e1..7fef6a8a720ea 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -146,7 +146,7 @@ module ts { } function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, - writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { + writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { var emitLeadingSpace = !trailingSeparator; forEach(comments, comment => { if (emitLeadingSpace) { @@ -167,7 +167,7 @@ module ts { }); } - function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ + function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) { if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { var firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); var lastLine = getLineStarts(currentSourceFile).length; @@ -273,10 +273,12 @@ module ts { function getAllAccessorDeclarations(node: ClassDeclaration, accessor: AccessorDeclaration) { var firstAccessor: AccessorDeclaration; + var lastAccessor: AccessorDeclaration; var getAccessor: AccessorDeclaration; var setAccessor: AccessorDeclaration; if (accessor.name.kind === SyntaxKind.ComputedPropertyName) { firstAccessor = accessor; + lastAccessor = accessor; if (accessor.kind === SyntaxKind.GetAccessor) { getAccessor = accessor; } @@ -288,7 +290,7 @@ module ts { } } else { - forEach(node.members,(member: Declaration) => { + forEach(node.members, (member: Declaration) => { if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) && (member.name).text === (accessor.name).text && (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) { @@ -296,6 +298,8 @@ module ts { firstAccessor = member; } + lastAccessor = member; + if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { getAccessor = member; } @@ -308,6 +312,7 @@ module ts { } return { firstAccessor, + lastAccessor, getAccessor, setAccessor }; @@ -319,7 +324,7 @@ module ts { return combinePaths(newDirPath, sourceFilePath); } - function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string){ + function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) { var compilerOptions = host.getCompilerOptions(); if (compilerOptions.outDir) { var emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); @@ -1044,33 +1049,33 @@ module ts { var diagnosticMessage: DiagnosticMessage; if (node.kind === SyntaxKind.VariableDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } @@ -1116,7 +1121,7 @@ module ts { if (hasDynamicName(node)) { return; } - + var accessors = getAllAccessorDeclarations(node.parent, node); if (node === accessors.firstAccessor) { emitJsDocComments(accessors.getAccessor); @@ -1154,13 +1159,13 @@ module ts { // Setters have to have type named and cannot infer it so, the type should always be named if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; } return { diagnosticMessage, @@ -1172,17 +1177,17 @@ module ts { else { if (accessorWithTypeAnnotation.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; } return { diagnosticMessage, @@ -1283,54 +1288,54 @@ module ts { case SyntaxKind.ConstructSignature: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.CallSignature: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.IndexSignature: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; case SyntaxKind.FunctionDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -1375,56 +1380,56 @@ module ts { switch (node.parent.kind) { case SyntaxKind.Constructor: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; break; case SyntaxKind.ConstructSignature: // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.CallSignature: // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; case SyntaxKind.FunctionDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -1496,7 +1501,7 @@ module ts { referencePathsOutput += "/// " + newLine; } } - + export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { var diagnostics: Diagnostic[] = []; var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); @@ -1688,8 +1693,8 @@ module ts { lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { // Encode the last recordedSpan before assigning new encodeLastRecordedSourceMapSpan(); @@ -1940,7 +1945,7 @@ module ts { break; } // _a .. _h, _j ... _z, _0, _1, ... - name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0: 1) + CharacterCodes.a) : tempCount - 25); + name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + CharacterCodes.a) : tempCount - 25); tempCount++; } var result = createNode(SyntaxKind.Identifier); @@ -2068,7 +2073,7 @@ module ts { function emitLiteral(node: LiteralExpression) { var text = languageVersion < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : - node.text; + node.text; if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } @@ -2220,11 +2225,22 @@ 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: DeclarationName) { + function emitExpressionForPropertyName(node: DeclarationName, tempNames?: Identifier[]) { if (node.kind === SyntaxKind.StringLiteral) { emitLiteral(node); } else if (node.kind === SyntaxKind.ComputedPropertyName) { + if (tempNames) { + if (tempNames[node.id]) { + return emit(tempNames[node.id]); + } + + var tempName = createTempVariable(node); + recordTempDeclaration(tempName); + tempNames[node.id] = tempName; + write(tempName.text); + write(" = "); + } emit((node).expression); } else { @@ -2405,7 +2421,7 @@ module ts { i++; } write("["); - emitList(elements, pos, i - pos, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0, + emitList(elements, pos, i - pos, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, /*trailingComma*/ elements.hasTrailingComma); write("]"); pos = i; @@ -2434,8 +2450,15 @@ module ts { write("}"); } - function emitComputedPropertyName(node: ComputedPropertyName) { + function emitComputedPropertyName(node: ComputedPropertyName, tempNames?: Identifier[]) { write("["); + if (tempNames) { + var tempName = createTempVariable(node); + recordTempDeclaration(tempName); + tempNames[node.id] = tempName; + write(tempName.text); + write(" = "); + } emit(node.expression); write("]"); } @@ -2830,7 +2853,7 @@ module ts { function isOnSameLine(node1: Node, node2: Node) { return getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node1.pos)) === - getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos)); + getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos)); } function emitCaseOrDefaultClause(node: CaseOrDefaultClause) { @@ -3047,7 +3070,7 @@ module ts { function emitDestructuringAssignment(target: Expression, value: Expression) { if (target.kind === SyntaxKind.BinaryExpression && (target).operator === SyntaxKind.EqualsToken) { - value = createDefaultValueCheck(value,(target).right); + value = createDefaultValueCheck(value, (target).right); target = (target).left; } if (target.kind === SyntaxKind.ObjectLiteralExpression) { @@ -3445,14 +3468,14 @@ module ts { }); } - function emitMemberAccessForPropertyName(memberName: DeclarationName) { + function emitMemberAccessForPropertyName(memberName: DeclarationName, tempNames?: Identifier[]) { if (memberName.kind === SyntaxKind.StringLiteral || memberName.kind === SyntaxKind.NumericLiteral) { write("["); emitNode(memberName); write("]"); } else if (memberName.kind === SyntaxKind.ComputedPropertyName) { - emitComputedPropertyName(memberName); + emitComputedPropertyName(memberName, tempNames); } else { write("."); @@ -3485,6 +3508,8 @@ module ts { } function emitMemberFunctions(node: ClassDeclaration) { + var tempNames: Identifier[]; + var tempDescriptors: Identifier[]; forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -3495,11 +3520,11 @@ module ts { emitLeadingComments(member); emitStart(member); emitStart((member).name); - emitNode(node.name); - if (!(member.flags & NodeFlags.Static)) { - write(".prototype"); - } - emitMemberAccessForPropertyName((member).name); + emitTargetOfClassElement(node, member); + if (member.decorators && !tempNames && (member).name.kind === SyntaxKind.ComputedPropertyName) { + tempNames = []; + } + emitMemberAccessForPropertyName((member).name, member.decorators ? tempNames : undefined); emitEnd((member).name); write(" = "); emitStart(member); @@ -3512,18 +3537,33 @@ module ts { else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { var accessors = getAllAccessorDeclarations(node, member); if (member === accessors.firstAccessor) { + var tempDescriptor: Identifier; + if (member.decorators) { + if (!tempDescriptors) { + tempDescriptors = []; + } + tempDescriptor = createTempVariable(node); + recordTempDeclaration(tempDescriptor); + tempDescriptors[member.id] = tempDescriptor; + } writeLine(); emitStart(member); write("Object.defineProperty("); emitStart((member).name); - emitNode(node.name); - if (!(member.flags & NodeFlags.Static)) { - write(".prototype"); - } + emitTargetOfClassElement(node, member); write(", "); - emitExpressionForPropertyName((member).name); + + if ((member.decorators || accessors.lastAccessor.decorators) && !tempNames && (member).name.kind === SyntaxKind.ComputedPropertyName) { + tempNames = []; + } + emitExpressionForPropertyName((member).name, member.decorators ? tempNames : undefined); emitEnd((member).name); - write(", {"); + write(", "); + if (tempDescriptor) { + write(tempDescriptor.text); + write(" = "); + } + write("{"); increaseIndent(); if (accessors.getAccessor) { writeLine(); @@ -3558,6 +3598,9 @@ module ts { } } }); + if (tempNames || tempDescriptors) { + return { tempNames, tempDescriptors }; + } } function emitClassDeclaration(node: ClassDeclaration) { @@ -3569,6 +3612,12 @@ module ts { write("_super"); } write(") {"); + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; increaseIndent(); scopeEmitStart(node); if (baseTypeNode) { @@ -3581,9 +3630,15 @@ module ts { } writeLine(); emitConstructorOfClass(); - emitMemberFunctions(node); + var temps = emitMemberFunctions(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); + emitDecoratorsOfClass(node, temps); + emitTempDeclarations(/*newLine*/ true); + writeLine(); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; function emitClassReturnStatement() { write("return "); emitNode(node.name); @@ -3684,6 +3739,233 @@ module ts { } } + function emitTargetOfClassElement(node: ClassDeclaration, member: ClassElement) { + emitNode(node.name); + if (!(member.flags & NodeFlags.Static)) { + write(".prototype"); + } + } + + function emitDecoratorsOfClass(node: ClassDeclaration, temps: { tempNames: Identifier[]; tempDescriptors: Identifier[]; }) { + var temp: Identifier; + var tempNames: Identifier[]; + var tempDescriptors: Identifier[]; + if (temps) { + tempNames = temps.tempNames; + tempDescriptors = temps.tempDescriptors; + } + + forEach(node.members, member => { + var decorators: Decorator[]; + var name: DeclarationName; + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + decorators = (member).decorators; + name = (member).name; + break; + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + var accessors = getAllAccessorDeclarations(member.parent, member); + if (member !== accessors.firstAccessor) { + break; + } + if (accessors.firstAccessor.decorators) { + decorators = accessors.firstAccessor.decorators; + } + if (accessors.lastAccessor.decorators) { + if (decorators) { + decorators = decorators.concat(accessors.lastAccessor.decorators); + } + else { + decorators = accessors.lastAccessor.decorators; + } + } + name = accessors.firstAccessor.name; + break; + + case SyntaxKind.PropertyDeclaration: + decorators = (member).decorators; + name = (member).name; + break; + + default: + return; + } + + if (!decorators) { + return; + } + + + if (name.kind === SyntaxKind.ComputedPropertyName && !tempNames) { + tempNames = []; + } + + write("// "); + emitTargetOfClassElement(node, member); + emitMemberAccessForPropertyName(name); + write(" decorators:"); + writeLine(); + + if (languageVersion === ScriptTarget.ES3) { + for (var i = 0; i < decorators.length; i++) { + var decorator = decorators[i]; + emitStart(decorator); + emit(decorator.expression); + write("("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, tempNames); + write(", "); + if (i < decorators.length - 1) { + increaseIndent(); + writeLine(); + write("void "); + } + emitEnd(decorator); + } + write("void 0"); + for (var i = decorators.length - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(")"); + emitEnd(decorator); + if (i < decorators.length - 1) { + decreaseIndent(); + } + } + write(";"); + writeLine(); + } + else { + if (!temp) { + temp = createTempVariable(node); + recordTempDeclaration(temp); + } + + var emitInitialDescriptor = false; + if (member.kind !== SyntaxKind.PropertyDeclaration) { + emitStart(member); + emitNode(temp); + write(" = "); + if (tempDescriptors && tempDescriptors[member.id]) { + emitNode(tempDescriptors[member.id], /*disableComments*/ true); + } + else { + write("Object.getOwnPropertyDescriptor("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, tempNames); + write(")"); + } + write(";"); + emitEnd(member); + writeLine(); + emitInitialDescriptor = true; + } + + for (var i = 0; i < decorators.length; i++) { + var decorator = decorators[i]; + emitStart(decorator); + emitNode(temp); + write(" = "); + emit(decorators[i].expression); + write("("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, tempNames); + emitEnd(decorator); + if (emitInitialDescriptor || i < decorators.length - 1) { + write(", "); + } + if (i < decorators.length - 1) { + increaseIndent(); + writeLine(); + } + } + + if (emitInitialDescriptor) { + emitNode(temp); + } + + for (var i = decorators.length - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(")"); + if (emitInitialDescriptor || i < decorators.length - 1) { + write(" || "); + emitNode(temp); + } + if (i < decorators.length - 1) { + decreaseIndent(); + } + emitEnd(decorator); + } + + emitStart(member); + write(";"); + writeLine(); + write("if ("); + emitNode(temp); + write(" !== void 0) {"); + increaseIndent(); + writeLine(); + write("Object.defineProperty("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, tempNames); + write(", "); + emitNode(temp); + write(");"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + emitEnd(member); + } + }); + + var decorators = node.decorators; + if (!node.decorators) { + return; + } + + write("// "); + emit(node.name); + write(" decorators"); + writeLine(); + + emitStart(node); + for (var i = 0; i < decorators.length; i++) { + var decorator = decorators[i]; + emitStart(decorator); + emitNode(node.name); + write(" = "); + emit(decorators[i].expression); + write("("); + emitEnd(decorator); + if (i < decorators.length - 1) { + increaseIndent(); + writeLine(); + } + } + emitNode(node.name); + for (var i = decorators.length - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(") || "); + emitNode(node.name); + emitEnd(decorator); + if (i < decorators.length - 1) { + decreaseIndent(); + } + } + write(";"); + emitEnd(node); + writeLine(); + } + function emitInterfaceDeclaration(node: InterfaceDeclaration) { emitPinnedOrTripleSlashComments(node); } @@ -4023,7 +4305,7 @@ module ts { emitLeadingComments(node.endOfFileToken); } - function emitNode(node: Node, disableComments?:boolean): void { + function emitNode(node: Node, disableComments?: boolean): void { if (!node) { return; } @@ -4285,7 +4567,7 @@ module ts { } emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); + emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); } function emitDetachedCommentsAtPosition(node: TextRange) { @@ -4436,7 +4718,7 @@ module ts { emitFile(compilerOptions.out); } } - + function emitFile(jsFilePath: string, sourceFile?: SourceFile) { if (!isEmitBlocked) { emitJavaScript(jsFilePath, sourceFile); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 866d66d515166..bb9b2af7f1c37 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -63,7 +63,8 @@ module ts { case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).propertyName) || visitNode(cbNode, (node).dotDotDotToken) || visitNode(cbNode, (node).name) || @@ -75,7 +76,8 @@ module ts { case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).parameters) || visitNode(cbNode, (node).type); @@ -87,7 +89,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).asteriskToken) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).questionToken) || @@ -165,7 +168,8 @@ module ts { return visitNodes(cbNodes, (node).statements) || visitNode(cbNode, (node).endOfFileToken); case SyntaxKind.VariableStatement: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).declarationList); case SyntaxKind.VariableDeclarationList: return visitNodes(cbNodes, (node).declarations); @@ -220,38 +224,45 @@ module ts { visitNode(cbNode, (node).type) || visitNode(cbNode, (node).block); case SyntaxKind.ClassDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNode, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).heritageClauses) || visitNodes(cbNodes, (node).members); case SyntaxKind.InterfaceDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).heritageClauses) || visitNodes(cbNodes, (node).members); case SyntaxKind.TypeAliasDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).type); case SyntaxKind.EnumDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).members); case SyntaxKind.EnumMember: return visitNode(cbNode, (node).name) || visitNode(cbNode, (node).initializer); case SyntaxKind.ModuleDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).body); case SyntaxKind.ImportDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).moduleReference); case SyntaxKind.ExportAssignment: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportName); case SyntaxKind.TemplateExpression: return visitNode(cbNode, (node).head) || visitNodes(cbNodes, (node).templateSpans); @@ -263,6 +274,9 @@ module ts { return visitNodes(cbNodes, (node).types); case SyntaxKind.ExternalModuleReference: return visitNode(cbNode, (node).expression); + case SyntaxKind.IncompleteDeclaration: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers); } } @@ -2133,7 +2147,7 @@ module ts { } function isStartOfParameter(): boolean { - return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token); + return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token) || token === SyntaxKind.AtToken; } function setModifiers(node: Node, modifiers: ModifiersArray) { @@ -2145,6 +2159,7 @@ module ts { function parseParameter(): ParameterDeclaration { var node = createNode(SyntaxKind.Parameter); + node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); @@ -2336,9 +2351,9 @@ module ts { return token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBracketToken; } - function parseIndexSignatureDeclaration(modifiers: ModifiersArray): IndexSignatureDeclaration { - var fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); + function parseIndexSignatureDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): IndexSignatureDeclaration { var node = createNode(SyntaxKind.IndexSignature, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); @@ -2415,7 +2430,7 @@ module ts { case SyntaxKind.OpenBracketToken: // Indexer or computed property return isIndexSignature() - ? parseIndexSignatureDeclaration(/*modifiers:*/ undefined) + ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined) : parsePropertyOrMethodSignature(); case SyntaxKind.NewKeyword: if (lookAhead(isStartOfConstructSignature)) { @@ -2446,9 +2461,11 @@ module ts { } function parseIndexSignatureWithModifiers() { - var modifiers = parseModifiers(); + var fullStart = scanner.getStartPos(); + var decorators = parseDecorators(); + var modifiers = parseModifiers(); return isIndexSignature() - ? parseIndexSignatureDeclaration(modifiers) + ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers) : undefined; } @@ -2702,7 +2719,7 @@ module ts { function isStartOfExpressionStatement(): boolean { // As per the grammar, neither '{' nor 'function' can start an expression statement. - return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isStartOfExpression(); + return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && token !== SyntaxKind.AtToken && isStartOfExpression(); } function parseExpression(): Expression { @@ -3551,12 +3568,12 @@ module ts { return finishNode(node); } - function tryParseAccessorDeclaration(fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): AccessorDeclaration { if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers); } else if (parseContextualModifier(SyntaxKind.SetKeyword)) { - return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, decorators, modifiers); } return undefined; @@ -3564,9 +3581,10 @@ module ts { function parseObjectLiteralElement(): ObjectLiteralElement { var fullStart = scanner.getStartPos(); + var decorators = parseDecorators(); var modifiers = parseModifiers(); - var accessor = tryParseAccessorDeclaration(fullStart, modifiers); + var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers); if (accessor) { return accessor; } @@ -3579,7 +3597,7 @@ module ts { // Disallowing of optional property assignments happens in the grammar checker. var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); + return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } // Parse to check if it is short-hand property assignment or normal property assignment @@ -3982,9 +4000,9 @@ module ts { case SyntaxKind.VarKeyword: case SyntaxKind.ConstKeyword: // const here should always be parsed as const declaration because of check in 'isStatement' - return parseVariableStatement(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); case SyntaxKind.SemicolonToken: return parseEmptyStatement(); case SyntaxKind.IfKeyword: @@ -4017,7 +4035,7 @@ module ts { case SyntaxKind.LetKeyword: // If let follows identifier on the same line, it is declaration parse it as variable statement if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); } // Else parse it like identifier - fall through default: @@ -4027,7 +4045,9 @@ module ts { // work properly when incrementally parsing as the parser will produce the // same FunctionDeclaraiton or VariableStatement if it has the same text // regardless of whether it is inside a block or not. - if (isModifier(token)) { + // Even though variable statements and function declarations cannot have decorators, + // we parse them here to provide better error recovery. + if (isModifier(token) || token === SyntaxKind.AtToken) { var result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); if (result) { return result; @@ -4040,6 +4060,7 @@ module ts { function parseVariableStatementOrFunctionDeclarationWithModifiers(): FunctionDeclaration | VariableStatement { var start = scanner.getStartPos(); + var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { case SyntaxKind.ConstKeyword: @@ -4047,18 +4068,18 @@ module ts { if (nextTokenIsEnum) { return undefined; } - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.LetKeyword: if (!isLetDeclaration()) { return undefined; } - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.VarKeyword: - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(start, modifiers); + return parseFunctionDeclaration(start, decorators, modifiers); } return undefined; @@ -4167,16 +4188,18 @@ module ts { return finishNode(node); } - function parseVariableStatement(fullStart: number, modifiers: ModifiersArray): VariableStatement { + function parseVariableStatement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(/*disallowIn:*/ false); parseSemicolon(); return finishNode(node); } - function parseFunctionDeclaration(fullStart: number, modifiers: ModifiersArray): FunctionDeclaration { + function parseFunctionDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): FunctionDeclaration { var node = createNode(SyntaxKind.FunctionDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -4186,8 +4209,9 @@ module ts { return finishNode(node); } - function parseConstructorDeclaration(pos: number, modifiers: ModifiersArray): ConstructorDeclaration { + function parseConstructorDeclaration(pos: number, decorators: NodeArray, modifiers: ModifiersArray): ConstructorDeclaration { var node = createNode(SyntaxKind.Constructor, pos); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ConstructorKeyword); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4195,8 +4219,9 @@ module ts { return finishNode(node); } - function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { + function parseMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { var method = createNode(SyntaxKind.MethodDeclaration, fullStart); + method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; @@ -4206,7 +4231,7 @@ module ts { return finishNode(method); } - function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { + function parsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); var name = parsePropertyName(); @@ -4214,10 +4239,11 @@ module ts { // report an error in the grammar checker. var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); + return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); } else { var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; @@ -4232,8 +4258,9 @@ module ts { return parseInitializer(/*inParameter*/ false); } - function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): AccessorDeclaration { var node = createNode(kind, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4244,6 +4271,10 @@ module ts { function isClassMemberStart(): boolean { var idToken: SyntaxKind; + if (token === SyntaxKind.AtToken) { + return true; + } + // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. while (isModifier(token)) { idToken = token; @@ -4295,6 +4326,30 @@ module ts { return false; } + function parseDecorators(): NodeArray { + var decorators: NodeArray; + while (true) { + if (token !== SyntaxKind.AtToken) { + break; + } + + nextToken(); + + if (!decorators) { + decorators = >[]; + decorators.pos = scanner.getStartPos(); + } + + var decorator = createNode(SyntaxKind.Decorator); + decorator.expression = parseLeftHandSideExpressionOrHigher(); + decorators.push(finishNode(decorator)); + } + if (decorators) { + decorators.end = scanner.getStartPos(); + } + return decorators; + } + function parseModifiers(): ModifiersArray { var flags = 0; var modifiers: ModifiersArray; @@ -4322,19 +4377,20 @@ module ts { function parseClassElement(): ClassElement { var fullStart = getNodePos(); + var decorators = parseDecorators(); var modifiers = parseModifiers(); - var accessor = tryParseAccessorDeclaration(fullStart, modifiers); + var accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers); if (accessor) { return accessor; } if (token === SyntaxKind.ConstructorKeyword) { - return parseConstructorDeclaration(fullStart, modifiers); + return parseConstructorDeclaration(fullStart, decorators, modifiers); } if (isIndexSignature()) { - return parseIndexSignatureDeclaration(modifiers); + return parseIndexSignatureDeclaration(fullStart, decorators, modifiers); } // It is very important that we check this *after* checking indexers because @@ -4345,15 +4401,16 @@ module ts { token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBracketToken) { - return parsePropertyOrMethodDeclaration(fullStart, modifiers); + return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } // 'isClassMemberStart' should have hinted not to attempt parsing. Debug.fail("Should not have attempted to parse class member declaration."); } - function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration { + function parseClassDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassDeclaration { var node = createNode(SyntaxKind.ClassDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); node.name = parseIdentifier(); @@ -4414,8 +4471,9 @@ module ts { return parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassElement); } - function parseInterfaceDeclaration(fullStart: number, modifiers: ModifiersArray): InterfaceDeclaration { + function parseInterfaceDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): InterfaceDeclaration { var node = createNode(SyntaxKind.InterfaceDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); @@ -4425,8 +4483,9 @@ module ts { return finishNode(node); } - function parseTypeAliasDeclaration(fullStart: number, modifiers: ModifiersArray): TypeAliasDeclaration { + function parseTypeAliasDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): TypeAliasDeclaration { var node = createNode(SyntaxKind.TypeAliasDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.TypeKeyword); node.name = parseIdentifier(); @@ -4447,8 +4506,9 @@ module ts { return finishNode(node); } - function parseEnumDeclaration(fullStart: number, modifiers: ModifiersArray): EnumDeclaration { + function parseEnumDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): EnumDeclaration { var node = createNode(SyntaxKind.EnumDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.EnumKeyword); node.name = parseIdentifier(); @@ -4474,30 +4534,32 @@ module ts { return finishNode(node); } - function parseInternalModuleTail(fullStart: number, modifiers: ModifiersArray, flags: NodeFlags): ModuleDeclaration { + function parseInternalModuleTail(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, flags: NodeFlags): ModuleDeclaration { var node = createNode(SyntaxKind.ModuleDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); node.body = parseOptional(SyntaxKind.DotToken) - ? parseInternalModuleTail(getNodePos(), /*modifiers:*/undefined, NodeFlags.Export) + ? parseInternalModuleTail(getNodePos(), /*decorators*/ undefined, /*modifiers:*/undefined, NodeFlags.Export) : parseModuleBlock(); return finishNode(node); } - function parseAmbientExternalModuleDeclaration(fullStart: number, modifiers: ModifiersArray): ModuleDeclaration { + function parseAmbientExternalModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { var node = createNode(SyntaxKind.ModuleDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(/*internName:*/ true); node.body = parseModuleBlock(); return finishNode(node); } - function parseModuleDeclaration(fullStart: number, modifiers: ModifiersArray): ModuleDeclaration { + function parseModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { parseExpected(SyntaxKind.ModuleKeyword); return token === SyntaxKind.StringLiteral - ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) - : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); + ? parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) + : parseInternalModuleTail(fullStart, decorators, modifiers, modifiers ? modifiers.flags : 0); } function isExternalModuleReference() { @@ -4509,8 +4571,9 @@ module ts { return nextToken() === SyntaxKind.OpenParenToken; } - function parseImportDeclaration(fullStart: number, modifiers: ModifiersArray): ImportDeclaration { + function parseImportDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ImportDeclaration { var node = createNode(SyntaxKind.ImportDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ImportKeyword); node.name = parseIdentifier(); @@ -4546,8 +4609,9 @@ module ts { return finishNode(node); } - function parseExportAssignmentTail(fullStart: number, modifiers: ModifiersArray): ExportAssignment { + function parseExportAssignmentTail(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.exportName = parseIdentifier(); parseSemicolon(); @@ -4588,6 +4652,10 @@ module ts { case SyntaxKind.StaticKeyword: // Check for modifier on source element return lookAhead(nextTokenIsDeclarationStart); + case SyntaxKind.AtToken: + // a lookahead here is too costly, and decorators are only valid on a declaration. + // We will assume we are parsing a declaration here and report an error later + return true; } } @@ -4617,11 +4685,12 @@ module ts { function parseDeclaration(): ModuleElement { var fullStart = getNodePos(); + var decorators = parseDecorators(); var modifiers = parseModifiers(); if (token === SyntaxKind.ExportKeyword) { nextToken(); if (parseOptional(SyntaxKind.EqualsToken)) { - return parseExportAssignmentTail(fullStart, modifiers); + return parseExportAssignmentTail(fullStart, decorators, modifiers); } } @@ -4629,22 +4698,30 @@ module ts { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: - return parseVariableStatement(fullStart, modifiers); + return parseVariableStatement(fullStart, decorators, modifiers); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(fullStart, modifiers); + return parseFunctionDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ClassKeyword: - return parseClassDeclaration(fullStart, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); case SyntaxKind.InterfaceKeyword: - return parseInterfaceDeclaration(fullStart, modifiers); + return parseInterfaceDeclaration(fullStart, decorators, modifiers); case SyntaxKind.TypeKeyword: - return parseTypeAliasDeclaration(fullStart, modifiers); + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); case SyntaxKind.EnumKeyword: - return parseEnumDeclaration(fullStart, modifiers); + return parseEnumDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ModuleKeyword: - return parseModuleDeclaration(fullStart, modifiers); + return parseModuleDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ImportKeyword: - return parseImportDeclaration(fullStart, modifiers); + return parseImportDeclaration(fullStart, decorators, modifiers); default: + if (decorators) { + // We reached this point because we encountered an AtToken and assumed a declaration would + // follow. For recovery and error reporting purposes, return an incomplete declaration. + var node = createNode(SyntaxKind.IncompleteDeclaration, fullStart); + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index fbbd69bbd6924..23f4b88f46d27 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -143,6 +143,7 @@ module ts { "&=": SyntaxKind.AmpersandEqualsToken, "|=": SyntaxKind.BarEqualsToken, "^=": SyntaxKind.CaretEqualsToken, + "@": SyntaxKind.AtToken, }; /* @@ -1160,6 +1161,8 @@ module ts { return pos++, token = SyntaxKind.CloseBraceToken; case CharacterCodes.tilde: return pos++, token = SyntaxKind.TildeToken; + case CharacterCodes.at: + return pos++, token = SyntaxKind.AtToken; case CharacterCodes.backslash: var ch = peekUnicodeEscape(); if (ch >= 0 && isIdentifierStart(ch)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ff8f5d2ed48d9..fd32511bd6977 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -67,6 +67,7 @@ module ts { BarBarToken, QuestionToken, ColonToken, + AtToken, // Assignments EqualsToken, PlusEqualsToken, @@ -150,6 +151,7 @@ module ts { // Signature elements TypeParameter, Parameter, + Decorator, // TypeMember PropertySignature, PropertyDeclaration, @@ -230,6 +232,7 @@ module ts { ModuleBlock, ImportDeclaration, ExportAssignment, + IncompleteDeclaration, // Module references ExternalModuleReference, @@ -342,13 +345,14 @@ module ts { // Specific context the parser was in when this node was created. Normally undefined. // Only set when the parser was in some interesting context (like async/yield). parserContextFlags?: ParserContextFlags; - id?: number; // Unique id (used to look up NodeLinks) - parent?: Node; // Parent node (initialized by binding) - symbol?: Symbol; // Symbol declared by node (initialized by binding) - locals?: SymbolTable; // Locals associated with node (initialized by binding) - nextContainer?: Node; // Next container in declaration order (initialized by binding) - localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) - modifiers?: ModifiersArray; // Array of modifiers + id?: number; // Unique id (used to look up NodeLinks) + parent?: Node; // Parent node (initialized by binding) + symbol?: Symbol; // Symbol declared by node (initialized by binding) + locals?: SymbolTable; // Locals associated with node (initialized by binding) + nextContainer?: Node; // Next container in declaration order (initialized by binding) + localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) + decorators?: NodeArray; // Array of decorators + modifiers?: ModifiersArray; // Array of modifiers } export interface NodeArray extends Array, TextRange { @@ -382,6 +386,10 @@ module ts { expression: Expression; } + export interface Decorator extends Node { + expression: LeftHandSideExpression; + } + export interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; From ff73e97b4c7658f29e14d4670ba34d58bff64214 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 5 Feb 2015 17:32:39 -0800 Subject: [PATCH 02/33] Add emit for decorators on parameters --- src/compiler/emitter.ts | 406 +++++++++++++++++++++++----------------- 1 file changed, 238 insertions(+), 168 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7fef6a8a720ea..bd08b0bdbce4a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -41,6 +41,12 @@ module ts { referencePathsOutput: string; } + interface DecoratorEmitInfo { + workingVariable?: Identifier; // temporary variable used as working memory for decorator application + computedPropertyNameCache: Identifier[]; // a cache of temporary variables used to hold onto the result of the expression for a computed property + propertyDescriptorCache: Identifier[]; // a cache of property descriptors created when emitting accessor declarations + } + var indentStrings: string[] = ["", " "]; export function getIndentString(level: number) { if (indentStrings[level] === undefined) { @@ -3507,9 +3513,9 @@ module ts { }); } - function emitMemberFunctions(node: ClassDeclaration) { - var tempNames: Identifier[]; - var tempDescriptors: Identifier[]; + function emitMemberFunctions(node: ClassDeclaration): DecoratorEmitInfo { + var computedPropertyNameCache: Identifier[]; + var propertyDescriptorCache: Identifier[]; forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -3521,10 +3527,10 @@ module ts { emitStart(member); emitStart((member).name); emitTargetOfClassElement(node, member); - if (member.decorators && !tempNames && (member).name.kind === SyntaxKind.ComputedPropertyName) { - tempNames = []; + if (member.decorators && !computedPropertyNameCache && (member).name.kind === SyntaxKind.ComputedPropertyName) { + computedPropertyNameCache = []; } - emitMemberAccessForPropertyName((member).name, member.decorators ? tempNames : undefined); + emitMemberAccessForPropertyName((member).name, member.decorators ? computedPropertyNameCache : undefined); emitEnd((member).name); write(" = "); emitStart(member); @@ -3539,12 +3545,13 @@ module ts { if (member === accessors.firstAccessor) { var tempDescriptor: Identifier; if (member.decorators) { - if (!tempDescriptors) { - tempDescriptors = []; + if (!propertyDescriptorCache) { + propertyDescriptorCache = []; } tempDescriptor = createTempVariable(node); recordTempDeclaration(tempDescriptor); - tempDescriptors[member.id] = tempDescriptor; + propertyDescriptorCache[accessors.firstAccessor.id] = tempDescriptor; + propertyDescriptorCache[accessors.lastAccessor.id] = tempDescriptor; } writeLine(); emitStart(member); @@ -3553,10 +3560,10 @@ module ts { emitTargetOfClassElement(node, member); write(", "); - if ((member.decorators || accessors.lastAccessor.decorators) && !tempNames && (member).name.kind === SyntaxKind.ComputedPropertyName) { - tempNames = []; + if ((member.decorators || accessors.lastAccessor.decorators) && !computedPropertyNameCache && (member).name.kind === SyntaxKind.ComputedPropertyName) { + computedPropertyNameCache = []; } - emitExpressionForPropertyName((member).name, member.decorators ? tempNames : undefined); + emitExpressionForPropertyName((member).name, member.decorators ? computedPropertyNameCache : undefined); emitEnd((member).name); write(", "); if (tempDescriptor) { @@ -3598,8 +3605,8 @@ module ts { } } }); - if (tempNames || tempDescriptors) { - return { tempNames, tempDescriptors }; + if (computedPropertyNameCache || propertyDescriptorCache) { + return { computedPropertyNameCache, propertyDescriptorCache }; } } @@ -3739,200 +3746,258 @@ module ts { } } - function emitTargetOfClassElement(node: ClassDeclaration, member: ClassElement) { + function emitTargetOfClassElement(node: ClassDeclaration, member: Node) { emitNode(node.name); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } } - function emitDecoratorsOfClass(node: ClassDeclaration, temps: { tempNames: Identifier[]; tempDescriptors: Identifier[]; }) { - var temp: Identifier; - var tempNames: Identifier[]; - var tempDescriptors: Identifier[]; - if (temps) { - tempNames = temps.tempNames; - tempDescriptors = temps.tempDescriptors; - } - - forEach(node.members, member => { - var decorators: Decorator[]; - var name: DeclarationName; - switch (member.kind) { - case SyntaxKind.MethodDeclaration: - decorators = (member).decorators; - name = (member).name; - break; - - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - var accessors = getAllAccessorDeclarations(member.parent, member); - if (member !== accessors.firstAccessor) { - break; - } - if (accessors.firstAccessor.decorators) { - decorators = accessors.firstAccessor.decorators; - } - if (accessors.lastAccessor.decorators) { + function getDecoratorsOfMember(node: ClassDeclaration, member: ClassElement) { + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + return member.decorators; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + var accessors = getAllAccessorDeclarations(node, member); + if (member === accessors.firstAccessor) { + var decorators = accessors.firstAccessor.decorators; + if (member !== accessors.lastAccessor && accessors.lastAccessor.decorators) { if (decorators) { - decorators = decorators.concat(accessors.lastAccessor.decorators); - } - else { - decorators = accessors.lastAccessor.decorators; + return decorators.concat(accessors.lastAccessor.decorators); } + return accessors.lastAccessor.decorators; } - name = accessors.firstAccessor.name; - break; + } + break; + } + return undefined; + } + + function emitDecoratorsOfParameter(node: FunctionLikeDeclaration, parameter: ParameterDeclaration, parameterIndex: number, info: DecoratorEmitInfo) { + var decorators = parameter.decorators; + if (!decorators) { + return; + } - case SyntaxKind.PropertyDeclaration: - decorators = (member).decorators; - name = (member).name; - break; + var name = parameter.name; - default: - return; + write("// "); + if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { + if (node.kind === SyntaxKind.Constructor) { + emitNode((node.parent).name); + } + else { + emitTargetOfClassElement(node.parent, node); + var saveEmit = emit; + emit = emitNode; + emitMemberAccessForPropertyName(node.name, info.computedPropertyNameCache); + emit = saveEmit; } + } + else { + emitNode(node.name); + } + write(" parameter #"); + write(String(parameterIndex)); + if (name.kind === SyntaxKind.Identifier) { + write(" ("); + emitNode(name); + write(")"); + } + write(" decorators:"); + writeLine(); - if (!decorators) { - return; + emitStart(node); + var decoratorCount = decorators.length; + for (var i = 0; i < decoratorCount; i++) { + var decorator = decorators[i]; + emitStart(decorator); + emit(decorator.expression); + write("("); + if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { + if (node.kind === SyntaxKind.Constructor) { + emitNode((node.parent).name); + } + else if (node.kind === SyntaxKind.SetAccessor) { + emitNode(info.propertyDescriptorCache[node.id]); + } + else { + emitTargetOfClassElement(node.parent, node); + emitMemberAccessForPropertyName(node.name, info.computedPropertyNameCache); + } } + write(", "); + write(String(parameterIndex)); + write(", "); + emitEnd(decorator); + if (i < decoratorCount - 1) { + increaseIndent(); + writeLine(); + write("void "); + } + } + write("void 0"); + for (var i = decoratorCount - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(")"); + emitEnd(decorator); + if (i < decorators.length - 1) { + decreaseIndent(); + } + } + write(";"); + emitEnd(node); + writeLine(); + } + function emitDecoratorsOfParameters(node: FunctionLikeDeclaration, info: DecoratorEmitInfo) { + forEach(node.parameters, (parameter, parameterIndex) => emitDecoratorsOfParameter(node, parameter, parameterIndex, info)); + } - if (name.kind === SyntaxKind.ComputedPropertyName && !tempNames) { - tempNames = []; - } + function emitDecoratorsOfMember(node: ClassDeclaration, member: ClassElement, info: DecoratorEmitInfo) { + var name = member.name; + var decorators = getDecoratorsOfMember(node, member); + if (!decorators) { + return; + } - write("// "); - emitTargetOfClassElement(node, member); - emitMemberAccessForPropertyName(name); - write(" decorators:"); - writeLine(); + if (name.kind === SyntaxKind.ComputedPropertyName && !info.computedPropertyNameCache) { + info.computedPropertyNameCache = []; + } - if (languageVersion === ScriptTarget.ES3) { - for (var i = 0; i < decorators.length; i++) { - var decorator = decorators[i]; - emitStart(decorator); - emit(decorator.expression); - write("("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, tempNames); - write(", "); - if (i < decorators.length - 1) { - increaseIndent(); - writeLine(); - write("void "); - } - emitEnd(decorator); + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + emitDecoratorsOfParameters(member, info); + break; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + var accessors = getAllAccessorDeclarations(node, member); + if (accessors.setAccessor) { + emitDecoratorsOfParameters(accessors.setAccessor, info); } - write("void 0"); - for (var i = decorators.length - 1; i >= 0; i--) { - var decorator = decorators[i]; - emitStart(decorator); - write(")"); - emitEnd(decorator); - if (i < decorators.length - 1) { - decreaseIndent(); - } - } - write(";"); - writeLine(); + break; + } + + write("// "); + emitTargetOfClassElement(node, member); + emitMemberAccessForPropertyName(name); + write(" decorators:"); + writeLine(); + + var useDescriptors = languageVersion > ScriptTarget.ES3; + if (useDescriptors) { + if (info.propertyDescriptorCache && info.propertyDescriptorCache[member.id]) { + workingVariable = info.propertyDescriptorCache[member.id]; } else { - if (!temp) { - temp = createTempVariable(node); - recordTempDeclaration(temp); + if (!info.workingVariable) { + info.workingVariable = createTempVariable(node); + recordTempDeclaration(info.workingVariable); } - - var emitInitialDescriptor = false; + workingVariable = info.workingVariable; if (member.kind !== SyntaxKind.PropertyDeclaration) { - emitStart(member); - emitNode(temp); + emitNode(workingVariable); write(" = "); - if (tempDescriptors && tempDescriptors[member.id]) { - emitNode(tempDescriptors[member.id], /*disableComments*/ true); - } - else { - write("Object.getOwnPropertyDescriptor("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, tempNames); - write(")"); - } - write(";"); - emitEnd(member); - writeLine(); - emitInitialDescriptor = true; - } - - for (var i = 0; i < decorators.length; i++) { - var decorator = decorators[i]; - emitStart(decorator); - emitNode(temp); - write(" = "); - emit(decorators[i].expression); - write("("); + write("Object.getOwnPropertyDescriptor("); emitTargetOfClassElement(node, member); write(", "); - emitExpressionForPropertyName(name, tempNames); - emitEnd(decorator); - if (emitInitialDescriptor || i < decorators.length - 1) { - write(", "); - } - if (i < decorators.length - 1) { - increaseIndent(); - writeLine(); - } + emitExpressionForPropertyName(name, info.computedPropertyNameCache); + write(");"); + writeLine(); } + } + } - if (emitInitialDescriptor) { - emitNode(temp); + var workingVariable: Identifier; + var decoratorCount = decorators.length; + for (var i = 0; i < decoratorCount; i++) { + var decorator = decorators[i]; + emitStart(decorator); + if (useDescriptors) { + emitNode(workingVariable); + write(" = "); + } + emit(decorator.expression); + write("("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, info.computedPropertyNameCache); + write(", "); + if (i < decoratorCount - 1) { + increaseIndent(); + writeLine(); + if (!useDescriptors) { + write("void "); } + } + emitEnd(decorator); + } - for (var i = decorators.length - 1; i >= 0; i--) { - var decorator = decorators[i]; - emitStart(decorator); - write(")"); - if (emitInitialDescriptor || i < decorators.length - 1) { - write(" || "); - emitNode(temp); - } - if (i < decorators.length - 1) { - decreaseIndent(); - } - emitEnd(decorator); - } + var hasInitialDescriptor: boolean; + if (!useDescriptors || member.kind === SyntaxKind.PropertyDeclaration) { + hasInitialDescriptor = false; + write("void 0"); + } + else { + hasInitialDescriptor = true; + emitNode(workingVariable); + } - emitStart(member); - write(";"); - writeLine(); - write("if ("); - emitNode(temp); - write(" !== void 0) {"); - increaseIndent(); - writeLine(); - write("Object.defineProperty("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, tempNames); - write(", "); - emitNode(temp); - write(");"); + for (var i = decoratorCount - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(")"); + if (useDescriptors && (i < decoratorCount - 1 || hasInitialDescriptor)) { + write(" || "); + emitNode(workingVariable); + } + if (i < decoratorCount - 1) { decreaseIndent(); - writeLine(); - write("}"); - writeLine(); - emitEnd(member); } - }); + emitEnd(decorator); + } + emitStart(member); + write(";"); + if (useDescriptors) { + writeLine(); + write("if ("); + emitNode(workingVariable); + write(" !== void 0) {"); + increaseIndent(); + writeLine(); + write("Object.defineProperty("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, info.computedPropertyNameCache); + write(", "); + emitNode(workingVariable); + write(");"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + } + emitEnd(member); + writeLine(); + } + + function emitDecoratorsOfConstructor(node: ClassDeclaration, info: DecoratorEmitInfo) { var decorators = node.decorators; if (!node.decorators) { return; } + + var constructor = getFirstConstructorWithBody(node); + if (constructor) { + emitDecoratorsOfParameters(constructor, info); + } write("// "); - emit(node.name); + emitNode(node.name); write(" decorators"); writeLine(); @@ -3966,6 +4031,11 @@ module ts { writeLine(); } + function emitDecoratorsOfClass(node: ClassDeclaration, info: DecoratorEmitInfo) { + forEach(node.members, member => emitDecoratorsOfMember(node, member, info)); + emitDecoratorsOfConstructor(node, info); + } + function emitInterfaceDeclaration(node: InterfaceDeclaration) { emitPinnedOrTripleSlashComments(node); } From 346f167655354e60aafbb776623006e9860964ed Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 5 Feb 2015 18:11:26 -0800 Subject: [PATCH 03/33] Fixed incorrect emit for parameter on setter --- src/compiler/emitter.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bd08b0bdbce4a..f7e3de27fe574 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2459,13 +2459,20 @@ module ts { function emitComputedPropertyName(node: ComputedPropertyName, tempNames?: Identifier[]) { write("["); if (tempNames) { - var tempName = createTempVariable(node); - recordTempDeclaration(tempName); - tempNames[node.id] = tempName; - write(tempName.text); - write(" = "); + if (tempNames[node.id]) { + emitNode(tempNames[node.id]); + } else { + var tempName = createTempVariable(node); + recordTempDeclaration(tempName); + tempNames[node.id] = tempName; + write(tempName.text); + write(" = "); + emit(node.expression); + } + } + else { + emit(node.expression); } - emit(node.expression); write("]"); } @@ -3792,7 +3799,7 @@ module ts { emitTargetOfClassElement(node.parent, node); var saveEmit = emit; emit = emitNode; - emitMemberAccessForPropertyName(node.name, info.computedPropertyNameCache); + emitMemberAccessForPropertyName(node.name); emit = saveEmit; } } @@ -3822,6 +3829,7 @@ module ts { } else if (node.kind === SyntaxKind.SetAccessor) { emitNode(info.propertyDescriptorCache[node.id]); + write(".set"); } else { emitTargetOfClassElement(node.parent, node); @@ -3857,6 +3865,10 @@ module ts { forEach(node.parameters, (parameter, parameterIndex) => emitDecoratorsOfParameter(node, parameter, parameterIndex, info)); } + function emitDecoratorsOfMembers(node: ClassDeclaration, info: DecoratorEmitInfo) { + forEach(node.members, member => emitDecoratorsOfMember(node, member, info)); + } + function emitDecoratorsOfMember(node: ClassDeclaration, member: ClassElement, info: DecoratorEmitInfo) { var name = member.name; var decorators = getDecoratorsOfMember(node, member); @@ -3883,7 +3895,10 @@ module ts { write("// "); emitTargetOfClassElement(node, member); + var saveEmit = emit; + emit = emitNode; emitMemberAccessForPropertyName(name); + emit = saveEmit; write(" decorators:"); writeLine(); @@ -4032,7 +4047,7 @@ module ts { } function emitDecoratorsOfClass(node: ClassDeclaration, info: DecoratorEmitInfo) { - forEach(node.members, member => emitDecoratorsOfMember(node, member, info)); + emitDecoratorsOfMembers(node, info); emitDecoratorsOfConstructor(node, info); } From ec6acdf28b89e2bb7c9584675c6f9e52afd57d61 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 6 Feb 2015 10:29:21 -0800 Subject: [PATCH 04/33] Fixed whitespace --- src/compiler/emitter.ts | 890 ++++++++++++++++++++-------------------- src/compiler/parser.ts | 88 ++-- src/compiler/types.ts | 2 +- 3 files changed, 490 insertions(+), 490 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f7e3de27fe574..06a347c615656 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -41,11 +41,11 @@ module ts { referencePathsOutput: string; } - interface DecoratorEmitInfo { - workingVariable?: Identifier; // temporary variable used as working memory for decorator application - computedPropertyNameCache: Identifier[]; // a cache of temporary variables used to hold onto the result of the expression for a computed property - propertyDescriptorCache: Identifier[]; // a cache of property descriptors created when emitting accessor declarations - } + interface DecoratorEmitInfo { + workingVariable?: Identifier; // temporary variable used as working memory for decorator application + computedPropertyNameCache: Identifier[]; // a cache of temporary variables used to hold onto the result of the expression for a computed property + propertyDescriptorCache: Identifier[]; // a cache of property descriptors created when emitting accessor declarations + } var indentStrings: string[] = ["", " "]; export function getIndentString(level: number) { @@ -152,7 +152,7 @@ module ts { } function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, - writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { + writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { var emitLeadingSpace = !trailingSeparator; forEach(comments, comment => { if (emitLeadingSpace) { @@ -279,12 +279,12 @@ module ts { function getAllAccessorDeclarations(node: ClassDeclaration, accessor: AccessorDeclaration) { var firstAccessor: AccessorDeclaration; - var lastAccessor: AccessorDeclaration; + var lastAccessor: AccessorDeclaration; var getAccessor: AccessorDeclaration; var setAccessor: AccessorDeclaration; if (accessor.name.kind === SyntaxKind.ComputedPropertyName) { firstAccessor = accessor; - lastAccessor = accessor; + lastAccessor = accessor; if (accessor.kind === SyntaxKind.GetAccessor) { getAccessor = accessor; } @@ -304,7 +304,7 @@ module ts { firstAccessor = member; } - lastAccessor = member; + lastAccessor = member; if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { getAccessor = member; @@ -318,7 +318,7 @@ module ts { } return { firstAccessor, - lastAccessor, + lastAccessor, getAccessor, setAccessor }; @@ -1055,33 +1055,33 @@ module ts { var diagnosticMessage: DiagnosticMessage; if (node.kind === SyntaxKind.VariableDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } @@ -1165,13 +1165,13 @@ module ts { // Setters have to have type named and cannot infer it so, the type should always be named if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; } return { diagnosticMessage, @@ -1183,17 +1183,17 @@ module ts { else { if (accessorWithTypeAnnotation.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; } else { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; } return { diagnosticMessage, @@ -1294,54 +1294,54 @@ module ts { case SyntaxKind.ConstructSignature: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.CallSignature: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.IndexSignature: // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; } else { // Interfaces cannot have return types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; } break; case SyntaxKind.FunctionDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; break; default: @@ -1386,56 +1386,56 @@ module ts { switch (node.parent.kind) { case SyntaxKind.Constructor: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; break; case SyntaxKind.ConstructSignature: // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.CallSignature: // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (node.parent.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; } else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have parameter types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; } break; case SyntaxKind.FunctionDeclaration: diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; break; default: @@ -1699,8 +1699,8 @@ module ts { lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { // Encode the last recordedSpan before assigning new encodeLastRecordedSourceMapSpan(); @@ -2079,7 +2079,7 @@ module ts { function emitLiteral(node: LiteralExpression) { var text = languageVersion < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : - node.text; + node.text; if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } @@ -2236,17 +2236,17 @@ module ts { emitLiteral(node); } else if (node.kind === SyntaxKind.ComputedPropertyName) { - if (tempNames) { - if (tempNames[node.id]) { - return emit(tempNames[node.id]); - } - - var tempName = createTempVariable(node); - recordTempDeclaration(tempName); - tempNames[node.id] = tempName; - write(tempName.text); - write(" = "); - } + if (tempNames) { + if (tempNames[node.id]) { + return emit(tempNames[node.id]); + } + + var tempName = createTempVariable(node); + recordTempDeclaration(tempName); + tempNames[node.id] = tempName; + write(tempName.text); + write(" = "); + } emit((node).expression); } else { @@ -2458,21 +2458,21 @@ module ts { function emitComputedPropertyName(node: ComputedPropertyName, tempNames?: Identifier[]) { write("["); - if (tempNames) { - if (tempNames[node.id]) { - emitNode(tempNames[node.id]); - } else { - var tempName = createTempVariable(node); - recordTempDeclaration(tempName); - tempNames[node.id] = tempName; - write(tempName.text); - write(" = "); - emit(node.expression); - } - } - else { - emit(node.expression); - } + if (tempNames) { + if (tempNames[node.id]) { + emitNode(tempNames[node.id]); + } else { + var tempName = createTempVariable(node); + recordTempDeclaration(tempName); + tempNames[node.id] = tempName; + write(tempName.text); + write(" = "); + emit(node.expression); + } + } + else { + emit(node.expression); + } write("]"); } @@ -2866,7 +2866,7 @@ module ts { function isOnSameLine(node1: Node, node2: Node) { return getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node1.pos)) === - getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos)); + getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos)); } function emitCaseOrDefaultClause(node: CaseOrDefaultClause) { @@ -3521,8 +3521,8 @@ module ts { } function emitMemberFunctions(node: ClassDeclaration): DecoratorEmitInfo { - var computedPropertyNameCache: Identifier[]; - var propertyDescriptorCache: Identifier[]; + var computedPropertyNameCache: Identifier[]; + var propertyDescriptorCache: Identifier[]; forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -3533,10 +3533,10 @@ module ts { emitLeadingComments(member); emitStart(member); emitStart((member).name); - emitTargetOfClassElement(node, member); - if (member.decorators && !computedPropertyNameCache && (member).name.kind === SyntaxKind.ComputedPropertyName) { - computedPropertyNameCache = []; - } + emitTargetOfClassElement(node, member); + if (member.decorators && !computedPropertyNameCache && (member).name.kind === SyntaxKind.ComputedPropertyName) { + computedPropertyNameCache = []; + } emitMemberAccessForPropertyName((member).name, member.decorators ? computedPropertyNameCache : undefined); emitEnd((member).name); write(" = "); @@ -3550,34 +3550,34 @@ module ts { else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { var accessors = getAllAccessorDeclarations(node, member); if (member === accessors.firstAccessor) { - var tempDescriptor: Identifier; - if (member.decorators) { - if (!propertyDescriptorCache) { - propertyDescriptorCache = []; - } - tempDescriptor = createTempVariable(node); - recordTempDeclaration(tempDescriptor); - propertyDescriptorCache[accessors.firstAccessor.id] = tempDescriptor; - propertyDescriptorCache[accessors.lastAccessor.id] = tempDescriptor; - } + var tempDescriptor: Identifier; + if (member.decorators) { + if (!propertyDescriptorCache) { + propertyDescriptorCache = []; + } + tempDescriptor = createTempVariable(node); + recordTempDeclaration(tempDescriptor); + propertyDescriptorCache[accessors.firstAccessor.id] = tempDescriptor; + propertyDescriptorCache[accessors.lastAccessor.id] = tempDescriptor; + } writeLine(); emitStart(member); write("Object.defineProperty("); emitStart((member).name); - emitTargetOfClassElement(node, member); + emitTargetOfClassElement(node, member); write(", "); - if ((member.decorators || accessors.lastAccessor.decorators) && !computedPropertyNameCache && (member).name.kind === SyntaxKind.ComputedPropertyName) { - computedPropertyNameCache = []; - } + if ((member.decorators || accessors.lastAccessor.decorators) && !computedPropertyNameCache && (member).name.kind === SyntaxKind.ComputedPropertyName) { + computedPropertyNameCache = []; + } emitExpressionForPropertyName((member).name, member.decorators ? computedPropertyNameCache : undefined); emitEnd((member).name); write(", "); - if (tempDescriptor) { - write(tempDescriptor.text); - write(" = "); - } - write("{"); + if (tempDescriptor) { + write(tempDescriptor.text); + write(" = "); + } + write("{"); increaseIndent(); if (accessors.getAccessor) { writeLine(); @@ -3612,9 +3612,9 @@ module ts { } } }); - if (computedPropertyNameCache || propertyDescriptorCache) { - return { computedPropertyNameCache, propertyDescriptorCache }; - } + if (computedPropertyNameCache || propertyDescriptorCache) { + return { computedPropertyNameCache, propertyDescriptorCache }; + } } function emitClassDeclaration(node: ClassDeclaration) { @@ -3626,12 +3626,12 @@ module ts { write("_super"); } write(") {"); - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; increaseIndent(); scopeEmitStart(node); if (baseTypeNode) { @@ -3647,12 +3647,12 @@ module ts { var temps = emitMemberFunctions(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); - emitDecoratorsOfClass(node, temps); - emitTempDeclarations(/*newLine*/ true); - writeLine(); - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; + emitDecoratorsOfClass(node, temps); + emitTempDeclarations(/*newLine*/ true); + writeLine(); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; function emitClassReturnStatement() { write("return "); emitNode(node.name); @@ -3753,303 +3753,303 @@ module ts { } } - function emitTargetOfClassElement(node: ClassDeclaration, member: Node) { - emitNode(node.name); - if (!(member.flags & NodeFlags.Static)) { - write(".prototype"); - } - } - - function getDecoratorsOfMember(node: ClassDeclaration, member: ClassElement) { - switch (member.kind) { - case SyntaxKind.MethodDeclaration: - case SyntaxKind.PropertyDeclaration: - return member.decorators; - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - var accessors = getAllAccessorDeclarations(node, member); - if (member === accessors.firstAccessor) { - var decorators = accessors.firstAccessor.decorators; - if (member !== accessors.lastAccessor && accessors.lastAccessor.decorators) { - if (decorators) { - return decorators.concat(accessors.lastAccessor.decorators); - } - return accessors.lastAccessor.decorators; - } - } - break; - } - return undefined; - } - - function emitDecoratorsOfParameter(node: FunctionLikeDeclaration, parameter: ParameterDeclaration, parameterIndex: number, info: DecoratorEmitInfo) { - var decorators = parameter.decorators; - if (!decorators) { - return; - } - - var name = parameter.name; - - write("// "); - if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { - if (node.kind === SyntaxKind.Constructor) { - emitNode((node.parent).name); - } - else { - emitTargetOfClassElement(node.parent, node); - var saveEmit = emit; - emit = emitNode; - emitMemberAccessForPropertyName(node.name); - emit = saveEmit; - } - } - else { - emitNode(node.name); - } - write(" parameter #"); - write(String(parameterIndex)); - if (name.kind === SyntaxKind.Identifier) { - write(" ("); - emitNode(name); - write(")"); - } - write(" decorators:"); - writeLine(); - - emitStart(node); - var decoratorCount = decorators.length; - for (var i = 0; i < decoratorCount; i++) { - var decorator = decorators[i]; - emitStart(decorator); - emit(decorator.expression); - write("("); - if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { - if (node.kind === SyntaxKind.Constructor) { - emitNode((node.parent).name); - } - else if (node.kind === SyntaxKind.SetAccessor) { - emitNode(info.propertyDescriptorCache[node.id]); - write(".set"); - } - else { - emitTargetOfClassElement(node.parent, node); - emitMemberAccessForPropertyName(node.name, info.computedPropertyNameCache); - } - } - write(", "); - write(String(parameterIndex)); - write(", "); - emitEnd(decorator); - if (i < decoratorCount - 1) { - increaseIndent(); - writeLine(); - write("void "); - } - } - write("void 0"); - for (var i = decoratorCount - 1; i >= 0; i--) { - var decorator = decorators[i]; - emitStart(decorator); - write(")"); - emitEnd(decorator); - if (i < decorators.length - 1) { - decreaseIndent(); - } - } - write(";"); - emitEnd(node); - writeLine(); - } - - function emitDecoratorsOfParameters(node: FunctionLikeDeclaration, info: DecoratorEmitInfo) { - forEach(node.parameters, (parameter, parameterIndex) => emitDecoratorsOfParameter(node, parameter, parameterIndex, info)); - } - - function emitDecoratorsOfMembers(node: ClassDeclaration, info: DecoratorEmitInfo) { - forEach(node.members, member => emitDecoratorsOfMember(node, member, info)); - } - - function emitDecoratorsOfMember(node: ClassDeclaration, member: ClassElement, info: DecoratorEmitInfo) { - var name = member.name; - var decorators = getDecoratorsOfMember(node, member); - if (!decorators) { - return; - } - - if (name.kind === SyntaxKind.ComputedPropertyName && !info.computedPropertyNameCache) { - info.computedPropertyNameCache = []; - } - - switch (member.kind) { - case SyntaxKind.MethodDeclaration: - emitDecoratorsOfParameters(member, info); - break; - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - var accessors = getAllAccessorDeclarations(node, member); - if (accessors.setAccessor) { - emitDecoratorsOfParameters(accessors.setAccessor, info); - } - break; - } - - write("// "); - emitTargetOfClassElement(node, member); - var saveEmit = emit; - emit = emitNode; - emitMemberAccessForPropertyName(name); - emit = saveEmit; - write(" decorators:"); - writeLine(); - - var useDescriptors = languageVersion > ScriptTarget.ES3; - if (useDescriptors) { - if (info.propertyDescriptorCache && info.propertyDescriptorCache[member.id]) { - workingVariable = info.propertyDescriptorCache[member.id]; - } - else { - if (!info.workingVariable) { - info.workingVariable = createTempVariable(node); - recordTempDeclaration(info.workingVariable); - } - workingVariable = info.workingVariable; - if (member.kind !== SyntaxKind.PropertyDeclaration) { - emitNode(workingVariable); - write(" = "); - write("Object.getOwnPropertyDescriptor("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, info.computedPropertyNameCache); - write(");"); - writeLine(); - } - } - } - - var workingVariable: Identifier; - var decoratorCount = decorators.length; - for (var i = 0; i < decoratorCount; i++) { - var decorator = decorators[i]; - emitStart(decorator); - if (useDescriptors) { - emitNode(workingVariable); - write(" = "); - } - emit(decorator.expression); - write("("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, info.computedPropertyNameCache); - write(", "); - if (i < decoratorCount - 1) { - increaseIndent(); - writeLine(); - if (!useDescriptors) { - write("void "); - } - } - emitEnd(decorator); - } - - var hasInitialDescriptor: boolean; - if (!useDescriptors || member.kind === SyntaxKind.PropertyDeclaration) { - hasInitialDescriptor = false; - write("void 0"); - } - else { - hasInitialDescriptor = true; - emitNode(workingVariable); - } - - for (var i = decoratorCount - 1; i >= 0; i--) { - var decorator = decorators[i]; - emitStart(decorator); - write(")"); - if (useDescriptors && (i < decoratorCount - 1 || hasInitialDescriptor)) { - write(" || "); - emitNode(workingVariable); - } - if (i < decoratorCount - 1) { - decreaseIndent(); - } - emitEnd(decorator); - } - - emitStart(member); - write(";"); - if (useDescriptors) { - writeLine(); - write("if ("); - emitNode(workingVariable); - write(" !== void 0) {"); - increaseIndent(); - writeLine(); - write("Object.defineProperty("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, info.computedPropertyNameCache); - write(", "); - emitNode(workingVariable); - write(");"); - decreaseIndent(); - writeLine(); - write("}"); - writeLine(); - } - emitEnd(member); - writeLine(); - } - - function emitDecoratorsOfConstructor(node: ClassDeclaration, info: DecoratorEmitInfo) { - var decorators = node.decorators; - if (!node.decorators) { - return; - } - - var constructor = getFirstConstructorWithBody(node); - if (constructor) { - emitDecoratorsOfParameters(constructor, info); - } - - write("// "); - emitNode(node.name); - write(" decorators"); - writeLine(); - - emitStart(node); - for (var i = 0; i < decorators.length; i++) { - var decorator = decorators[i]; - emitStart(decorator); - emitNode(node.name); - write(" = "); - emit(decorators[i].expression); - write("("); - emitEnd(decorator); - if (i < decorators.length - 1) { - increaseIndent(); - writeLine(); - } - } - emitNode(node.name); - for (var i = decorators.length - 1; i >= 0; i--) { - var decorator = decorators[i]; - emitStart(decorator); - write(") || "); - emitNode(node.name); - emitEnd(decorator); - if (i < decorators.length - 1) { - decreaseIndent(); - } - } - write(";"); - emitEnd(node); - writeLine(); - } - - function emitDecoratorsOfClass(node: ClassDeclaration, info: DecoratorEmitInfo) { - emitDecoratorsOfMembers(node, info); - emitDecoratorsOfConstructor(node, info); - } + function emitTargetOfClassElement(node: ClassDeclaration, member: Node) { + emitNode(node.name); + if (!(member.flags & NodeFlags.Static)) { + write(".prototype"); + } + } + + function getDecoratorsOfMember(node: ClassDeclaration, member: ClassElement) { + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + return member.decorators; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + var accessors = getAllAccessorDeclarations(node, member); + if (member === accessors.firstAccessor) { + var decorators = accessors.firstAccessor.decorators; + if (member !== accessors.lastAccessor && accessors.lastAccessor.decorators) { + if (decorators) { + return decorators.concat(accessors.lastAccessor.decorators); + } + return accessors.lastAccessor.decorators; + } + } + break; + } + return undefined; + } + + function emitDecoratorsOfParameter(node: FunctionLikeDeclaration, parameter: ParameterDeclaration, parameterIndex: number, info: DecoratorEmitInfo) { + var decorators = parameter.decorators; + if (!decorators) { + return; + } + + var name = parameter.name; + + write("// "); + if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { + if (node.kind === SyntaxKind.Constructor) { + emitNode((node.parent).name); + } + else { + emitTargetOfClassElement(node.parent, node); + var saveEmit = emit; + emit = emitNode; + emitMemberAccessForPropertyName(node.name); + emit = saveEmit; + } + } + else { + emitNode(node.name); + } + write(" parameter #"); + write(String(parameterIndex)); + if (name.kind === SyntaxKind.Identifier) { + write(" ("); + emitNode(name); + write(")"); + } + write(" decorators:"); + writeLine(); + + emitStart(node); + var decoratorCount = decorators.length; + for (var i = 0; i < decoratorCount; i++) { + var decorator = decorators[i]; + emitStart(decorator); + emit(decorator.expression); + write("("); + if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { + if (node.kind === SyntaxKind.Constructor) { + emitNode((node.parent).name); + } + else if (node.kind === SyntaxKind.SetAccessor) { + emitNode(info.propertyDescriptorCache[node.id]); + write(".set"); + } + else { + emitTargetOfClassElement(node.parent, node); + emitMemberAccessForPropertyName(node.name, info.computedPropertyNameCache); + } + } + write(", "); + write(String(parameterIndex)); + write(", "); + emitEnd(decorator); + if (i < decoratorCount - 1) { + increaseIndent(); + writeLine(); + write("void "); + } + } + write("void 0"); + for (var i = decoratorCount - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(")"); + emitEnd(decorator); + if (i < decorators.length - 1) { + decreaseIndent(); + } + } + write(";"); + emitEnd(node); + writeLine(); + } + + function emitDecoratorsOfParameters(node: FunctionLikeDeclaration, info: DecoratorEmitInfo) { + forEach(node.parameters, (parameter, parameterIndex) => emitDecoratorsOfParameter(node, parameter, parameterIndex, info)); + } + + function emitDecoratorsOfMembers(node: ClassDeclaration, info: DecoratorEmitInfo) { + forEach(node.members, member => emitDecoratorsOfMember(node, member, info)); + } + + function emitDecoratorsOfMember(node: ClassDeclaration, member: ClassElement, info: DecoratorEmitInfo) { + var name = member.name; + var decorators = getDecoratorsOfMember(node, member); + if (!decorators) { + return; + } + + if (name.kind === SyntaxKind.ComputedPropertyName && !info.computedPropertyNameCache) { + info.computedPropertyNameCache = []; + } + + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + emitDecoratorsOfParameters(member, info); + break; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + var accessors = getAllAccessorDeclarations(node, member); + if (accessors.setAccessor) { + emitDecoratorsOfParameters(accessors.setAccessor, info); + } + break; + } + + write("// "); + emitTargetOfClassElement(node, member); + var saveEmit = emit; + emit = emitNode; + emitMemberAccessForPropertyName(name); + emit = saveEmit; + write(" decorators:"); + writeLine(); + + var useDescriptors = languageVersion > ScriptTarget.ES3; + if (useDescriptors) { + if (info.propertyDescriptorCache && info.propertyDescriptorCache[member.id]) { + workingVariable = info.propertyDescriptorCache[member.id]; + } + else { + if (!info.workingVariable) { + info.workingVariable = createTempVariable(node); + recordTempDeclaration(info.workingVariable); + } + workingVariable = info.workingVariable; + if (member.kind !== SyntaxKind.PropertyDeclaration) { + emitNode(workingVariable); + write(" = "); + write("Object.getOwnPropertyDescriptor("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, info.computedPropertyNameCache); + write(");"); + writeLine(); + } + } + } + + var workingVariable: Identifier; + var decoratorCount = decorators.length; + for (var i = 0; i < decoratorCount; i++) { + var decorator = decorators[i]; + emitStart(decorator); + if (useDescriptors) { + emitNode(workingVariable); + write(" = "); + } + emit(decorator.expression); + write("("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, info.computedPropertyNameCache); + write(", "); + if (i < decoratorCount - 1) { + increaseIndent(); + writeLine(); + if (!useDescriptors) { + write("void "); + } + } + emitEnd(decorator); + } + + var hasInitialDescriptor: boolean; + if (!useDescriptors || member.kind === SyntaxKind.PropertyDeclaration) { + hasInitialDescriptor = false; + write("void 0"); + } + else { + hasInitialDescriptor = true; + emitNode(workingVariable); + } + + for (var i = decoratorCount - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(")"); + if (useDescriptors && (i < decoratorCount - 1 || hasInitialDescriptor)) { + write(" || "); + emitNode(workingVariable); + } + if (i < decoratorCount - 1) { + decreaseIndent(); + } + emitEnd(decorator); + } + + emitStart(member); + write(";"); + if (useDescriptors) { + writeLine(); + write("if ("); + emitNode(workingVariable); + write(" !== void 0) {"); + increaseIndent(); + writeLine(); + write("Object.defineProperty("); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name, info.computedPropertyNameCache); + write(", "); + emitNode(workingVariable); + write(");"); + decreaseIndent(); + writeLine(); + write("}"); + writeLine(); + } + emitEnd(member); + writeLine(); + } + + function emitDecoratorsOfConstructor(node: ClassDeclaration, info: DecoratorEmitInfo) { + var decorators = node.decorators; + if (!node.decorators) { + return; + } + + var constructor = getFirstConstructorWithBody(node); + if (constructor) { + emitDecoratorsOfParameters(constructor, info); + } + + write("// "); + emitNode(node.name); + write(" decorators"); + writeLine(); + + emitStart(node); + for (var i = 0; i < decorators.length; i++) { + var decorator = decorators[i]; + emitStart(decorator); + emitNode(node.name); + write(" = "); + emit(decorators[i].expression); + write("("); + emitEnd(decorator); + if (i < decorators.length - 1) { + increaseIndent(); + writeLine(); + } + } + emitNode(node.name); + for (var i = decorators.length - 1; i >= 0; i--) { + var decorator = decorators[i]; + emitStart(decorator); + write(") || "); + emitNode(node.name); + emitEnd(decorator); + if (i < decorators.length - 1) { + decreaseIndent(); + } + } + write(";"); + emitEnd(node); + writeLine(); + } + + function emitDecoratorsOfClass(node: ClassDeclaration, info: DecoratorEmitInfo) { + emitDecoratorsOfMembers(node, info); + emitDecoratorsOfConstructor(node, info); + } function emitInterfaceDeclaration(node: InterfaceDeclaration) { emitPinnedOrTripleSlashComments(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index bb9b2af7f1c37..60e6f2191d3c9 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -64,7 +64,7 @@ module ts { case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).propertyName) || visitNode(cbNode, (node).dotDotDotToken) || visitNode(cbNode, (node).name) || @@ -77,7 +77,7 @@ module ts { case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).parameters) || visitNode(cbNode, (node).type); @@ -169,7 +169,7 @@ module ts { visitNode(cbNode, (node).endOfFileToken); case SyntaxKind.VariableStatement: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).declarationList); case SyntaxKind.VariableDeclarationList: return visitNodes(cbNodes, (node).declarations); @@ -232,19 +232,19 @@ module ts { visitNodes(cbNodes, (node).members); case SyntaxKind.InterfaceDeclaration: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).heritageClauses) || visitNodes(cbNodes, (node).members); case SyntaxKind.TypeAliasDeclaration: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).type); case SyntaxKind.EnumDeclaration: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).members); case SyntaxKind.EnumMember: @@ -252,17 +252,17 @@ module ts { visitNode(cbNode, (node).initializer); case SyntaxKind.ModuleDeclaration: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).body); case SyntaxKind.ImportDeclaration: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).moduleReference); case SyntaxKind.ExportAssignment: return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportName); case SyntaxKind.TemplateExpression: return visitNode(cbNode, (node).head) || visitNodes(cbNodes, (node).templateSpans); @@ -274,9 +274,9 @@ module ts { return visitNodes(cbNodes, (node).types); case SyntaxKind.ExternalModuleReference: return visitNode(cbNode, (node).expression); - case SyntaxKind.IncompleteDeclaration: - return visitNodes(cbNodes, node.decorators) || - visitNodes(cbNodes, node.modifiers); + case SyntaxKind.IncompleteDeclaration: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers); } } @@ -2159,7 +2159,7 @@ module ts { function parseParameter(): ParameterDeclaration { var node = createNode(SyntaxKind.Parameter); - node.decorators = parseDecorators(); + node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); @@ -2353,7 +2353,7 @@ module ts { function parseIndexSignatureDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): IndexSignatureDeclaration { var node = createNode(SyntaxKind.IndexSignature, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); @@ -2461,9 +2461,9 @@ module ts { } function parseIndexSignatureWithModifiers() { - var fullStart = scanner.getStartPos(); - var decorators = parseDecorators(); - var modifiers = parseModifiers(); + var fullStart = scanner.getStartPos(); + var decorators = parseDecorators(); + var modifiers = parseModifiers(); return isIndexSignature() ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers) : undefined; @@ -4045,8 +4045,8 @@ module ts { // work properly when incrementally parsing as the parser will produce the // same FunctionDeclaraiton or VariableStatement if it has the same text // regardless of whether it is inside a block or not. - // Even though variable statements and function declarations cannot have decorators, - // we parse them here to provide better error recovery. + // Even though variable statements and function declarations cannot have decorators, + // we parse them here to provide better error recovery. if (isModifier(token) || token === SyntaxKind.AtToken) { var result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); if (result) { @@ -4060,7 +4060,7 @@ module ts { function parseVariableStatementOrFunctionDeclarationWithModifiers(): FunctionDeclaration | VariableStatement { var start = scanner.getStartPos(); - var decorators = parseDecorators(); + var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { case SyntaxKind.ConstKeyword: @@ -4190,7 +4190,7 @@ module ts { function parseVariableStatement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): VariableStatement { var node = createNode(SyntaxKind.VariableStatement, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(/*disallowIn:*/ false); parseSemicolon(); @@ -4199,7 +4199,7 @@ module ts { function parseFunctionDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): FunctionDeclaration { var node = createNode(SyntaxKind.FunctionDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -4333,7 +4333,7 @@ module ts { break; } - nextToken(); + nextToken(); if (!decorators) { decorators = >[]; @@ -4410,7 +4410,7 @@ module ts { function parseClassDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassDeclaration { var node = createNode(SyntaxKind.ClassDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); node.name = parseIdentifier(); @@ -4473,7 +4473,7 @@ module ts { function parseInterfaceDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): InterfaceDeclaration { var node = createNode(SyntaxKind.InterfaceDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); @@ -4485,7 +4485,7 @@ module ts { function parseTypeAliasDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): TypeAliasDeclaration { var node = createNode(SyntaxKind.TypeAliasDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.TypeKeyword); node.name = parseIdentifier(); @@ -4508,7 +4508,7 @@ module ts { function parseEnumDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): EnumDeclaration { var node = createNode(SyntaxKind.EnumDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.EnumKeyword); node.name = parseIdentifier(); @@ -4536,7 +4536,7 @@ module ts { function parseInternalModuleTail(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, flags: NodeFlags): ModuleDeclaration { var node = createNode(SyntaxKind.ModuleDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); @@ -4548,7 +4548,7 @@ module ts { function parseAmbientExternalModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { var node = createNode(SyntaxKind.ModuleDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(/*internName:*/ true); node.body = parseModuleBlock(); @@ -4573,7 +4573,7 @@ module ts { function parseImportDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ImportDeclaration { var node = createNode(SyntaxKind.ImportDeclaration, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ImportKeyword); node.name = parseIdentifier(); @@ -4611,7 +4611,7 @@ module ts { function parseExportAssignmentTail(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, fullStart); - node.decorators = decorators; + node.decorators = decorators; setModifiers(node, modifiers); node.exportName = parseIdentifier(); parseSemicolon(); @@ -4652,10 +4652,10 @@ module ts { case SyntaxKind.StaticKeyword: // Check for modifier on source element return lookAhead(nextTokenIsDeclarationStart); - case SyntaxKind.AtToken: - // a lookahead here is too costly, and decorators are only valid on a declaration. - // We will assume we are parsing a declaration here and report an error later - return true; + case SyntaxKind.AtToken: + // a lookahead here is too costly, and decorators are only valid on a declaration. + // We will assume we are parsing a declaration here and report an error later + return true; } } @@ -4685,7 +4685,7 @@ module ts { function parseDeclaration(): ModuleElement { var fullStart = getNodePos(); - var decorators = parseDecorators(); + var decorators = parseDecorators(); var modifiers = parseModifiers(); if (token === SyntaxKind.ExportKeyword) { nextToken(); @@ -4714,14 +4714,14 @@ module ts { case SyntaxKind.ImportKeyword: return parseImportDeclaration(fullStart, decorators, modifiers); default: - if (decorators) { - // We reached this point because we encountered an AtToken and assumed a declaration would - // follow. For recovery and error reporting purposes, return an incomplete declaration. - var node = createNode(SyntaxKind.IncompleteDeclaration, fullStart); - node.decorators = decorators; - setModifiers(node, modifiers); - return finishNode(node); - } + if (decorators) { + // We reached this point because we encountered an AtToken and assumed a declaration would + // follow. For recovery and error reporting purposes, return an incomplete declaration. + var node = createNode(SyntaxKind.IncompleteDeclaration, fullStart); + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fd32511bd6977..5781bbf6415c9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -232,7 +232,7 @@ module ts { ModuleBlock, ImportDeclaration, ExportAssignment, - IncompleteDeclaration, + IncompleteDeclaration, // Module references ExternalModuleReference, From 8de67f37ef5761d5d9f1a71cc16a413c90e66952 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 10 Feb 2015 17:39:41 -0800 Subject: [PATCH 05/33] Always return the cache for computed property names and descriptors --- src/compiler/emitter.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 06a347c615656..628a54aaa4834 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3612,9 +3612,7 @@ module ts { } } }); - if (computedPropertyNameCache || propertyDescriptorCache) { - return { computedPropertyNameCache, propertyDescriptorCache }; - } + return { computedPropertyNameCache, propertyDescriptorCache }; } function emitClassDeclaration(node: ClassDeclaration) { From e4d9b744d54495039684f86a917cb171d2c5d5ea Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 10 Feb 2015 17:44:08 -0800 Subject: [PATCH 06/33] Added parser context and lookahead to avoid parsing a decorator for a computed property name as element access. --- src/compiler/parser.ts | 221 ++++++++++++++++++++++++++++++++++++++++- src/compiler/types.ts | 11 +- 2 files changed, 224 insertions(+), 8 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 60e6f2191d3c9..97bdfd589c453 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1024,6 +1024,10 @@ module ts { setContextFlag(val, ParserContextFlags.GeneratorParameter); } + function setDecoratorContext(val: boolean) { + setContextFlag(val, ParserContextFlags.Decorator); + } + function allowInAnd(func: () => T): T { if (contextFlags & ParserContextFlags.DisallowIn) { setDisallowInContext(false); @@ -1072,6 +1076,28 @@ module ts { return func(); } + function doInDecoratorContext(func: () => T): T { + if (contextFlags & ParserContextFlags.Decorator) { + return func(); + } + + setDecoratorContext(true); + var result = func(); + setDecoratorContext(false); + return result; + } + + function doOutsideOfDecoratorContext(func: () => T): T { + if (contextFlags & ParserContextFlags.Decorator) { + return func(); + } + + setDecoratorContext(true); + var result = func(); + setDecoratorContext(false); + return result; + } + function inYieldContext() { return (contextFlags & ParserContextFlags.Yield) !== 0; } @@ -1088,6 +1114,10 @@ module ts { return (contextFlags & ParserContextFlags.DisallowIn) !== 0; } + function inDecoratorContext() { + return (contextFlags & ParserContextFlags.Decorator) !== 0; + } + function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { var start = scanner.getTokenPos(); var length = scanner.getTextPos() - start; @@ -1271,8 +1301,12 @@ module ts { return node; } - function finishNode(node: T): T { - node.end = scanner.getStartPos(); + function finishNode(node: T, end?: number): T { + if (!(end >= 0)) { + end = scanner.getStartPos(); + } + + node.end = end; if (contextFlags) { node.parserContextFlags = contextFlags; @@ -3403,9 +3437,16 @@ module ts { } function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { + var isInDecoratorContext = inDecoratorContext(); while (true) { expression = parseMemberExpressionRest(expression); - + if (isInDecoratorContext && (token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken) && expression.kind === SyntaxKind.ElementAccessExpression) { + // TODO(rbuckton): switch to tryParse and reuse the parsed signature information? + var result = lookAhead(parseCoverCallExpressionOrComputedPropertyNamedMethod); + if (result) { + return expression; + } + } if (token === SyntaxKind.LessThanToken) { // See if this is the start of a generic invocation. If so, consume it and // keep checking for postfix expressions. Otherwise, it's just a '<' that's @@ -3435,6 +3476,37 @@ module ts { } } + function parseCoverCallExpressionOrComputedPropertyNamedMethod() { + // try to parse it as a signature, if successful and we are followed by an open brace, then this is a computed property named method + var typeParameters: NodeArray; + var parameters: NodeArray; + var type: TypeNode; + if (token === SyntaxKind.LessThanToken) { + typeParameters = parseTypeParameters(); + if (!typeParameters) { + return undefined; + } + } + if (token === SyntaxKind.OpenParenToken) { + var parameters = parseParameterList(/*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ true); + if (!parameters) { + return undefined; + } + if (token === SyntaxKind.ColonToken) { + type = parseTypeAnnotation(); + if (!type) { + return undefined; + } + } + if (token === SyntaxKind.OpenBraceToken || token === SyntaxKind.SemicolonToken) { + // this is a signature, not a call expression + return { typeParameters, parameters, type }; + } + } + + return undefined; + } + function parseArgumentList() { parseExpected(SyntaxKind.OpenParenToken); var result = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression); @@ -3634,12 +3706,19 @@ module ts { // function * BindingIdentifier[Yield]opt (FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] } // FunctionExpression: // function BindingIdentifieropt(FormalParameters) { FunctionBody } + var saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } var node = createNode(SyntaxKind.FunctionExpression); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.name = node.asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, /*requireCompleteParameterList:*/ false, node); node.body = parseFunctionBlock(/*allowYield:*/ !!node.asteriskToken, /* ignoreMissingOpenBrace */ false); + if (saveDecoratorContext) { + setDecoratorContext(true); + } return finishNode(node); } @@ -3676,8 +3755,17 @@ module ts { var savedYieldContext = inYieldContext(); setYieldContext(allowYield); + var saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } + var block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage); + if (saveDecoratorContext) { + setDecoratorContext(true); + } + setYieldContext(savedYieldContext); return block; @@ -4254,6 +4342,127 @@ module ts { } } + function reparsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { + // We may have parsed a decorator with an ElementAccess that we need to reinterpret as a computed property name + var lastDecorator = decorators[decorators.length - 1]; + var expression = lastDecorator.expression; + + var callExpression: CallExpression; + if (expression.kind === SyntaxKind.CallExpression) { + callExpression = expression; + expression = callExpression.expression; + } + + var elementAccessExpression: ElementAccessExpression; + if (expression.kind === SyntaxKind.ElementAccessExpression) { + elementAccessExpression = expression; + } + + if (elementAccessExpression) { + // update last decorator expression and end + lastDecorator.expression = elementAccessExpression.expression; + lastDecorator.end = elementAccessExpression.expression.end; + + var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, elementAccessExpression.pos); + computedPropertyName.expression = elementAccessExpression.argumentExpression; + finishNode(computedPropertyName, elementAccessExpression.end); + + var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); + if (callExpression) { + // reinterpret as a computed property method? + var method = createNode(SyntaxKind.MethodDeclaration, fullStart); + method.decorators = decorators; + setModifiers(method, modifiers); + method.name = computedPropertyName; + method.questionToken = questionToken; + reclassifyCallExpressionAsSignature(callExpression, method); + method.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false); + return finishNode(method); + } + else { + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return parseMethodDeclaration(fullStart, decorators, modifiers, /*asteriskToken*/ undefined, computedPropertyName, questionToken, Diagnostics.or_expected); + } + + // reinterpret as a computed property declaration + var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; + setModifiers(property, modifiers); + property.name = computedPropertyName; + property.type = parseTypeAnnotation(); + property.initializer = allowInAnd(parseNonParameterInitializer); + parseSemicolon(); + return finishNode(property); + } + } + + // 'isClassMemberStart' should have hinted not to attempt parsing. + Debug.fail("Should not have attempted to parse class member declaration."); + } + + function reclassifyTypeArgumentsAsTypeParameters(typeArguments: NodeArray): NodeArray { + var typeParameters = >[]; + typeParameters.pos = typeArguments.pos; + typeParameters.end = typeArguments.end; + for (var i = 0; i < typeArguments.length; i++) { + var typeArgument = typeArguments[i]; + var typeParameter = createNode(SyntaxKind.TypeParameter, typeArgument.pos); + Debug.assert(typeArgument.kind === SyntaxKind.TypeReference); + var typeReference = typeArgument; + Debug.assert(typeReference.typeName.kind === SyntaxKind.Identifier); + typeParameter.name = typeReference.typeName; + finishNode(typeParameter, typeArgument.end); + typeParameters.push(typeParameter); + } + return typeParameters; + } + + function reclassifyArgumentsAsParameters(arguments: NodeArray): NodeArray { + var parameters = >[]; + parameters.pos = arguments.pos; + parameters.end = arguments.end; + for (var i = 0; i < arguments.length; i++) { + var argument = arguments[i]; + + // TODO: Object literal as object binding + // TODO: Array literal as array binding + var name: Identifier; + var initializer: Expression; + if (argument.kind === SyntaxKind.Identifier) { + name = argument; + } + else if (argument.kind === SyntaxKind.BinaryExpression) { + var binaryExpression = argument; + Debug.assert(binaryExpression.operator === SyntaxKind.EqualsToken); + if (binaryExpression.left.kind === SyntaxKind.Identifier) { + name = binaryExpression.left; + initializer = binaryExpression.right; + } + else { + Debug.fail("Invalid attempt to reclassify expression."); + } + } + else { + Debug.fail("Invalid attempt to reclassify expression."); + } + + var parameter = createNode(SyntaxKind.Parameter, argument.pos); + parameter.name = name; + parameter.initializer = initializer; + finishNode(parameter, argument.end); + parameters.push(parameter); + } + return parameters; + } + + function reclassifyCallExpressionAsSignature(node: CallExpression, signature: SignatureDeclaration): void { + if (node.typeArguments) { + signature.typeParameters = reclassifyTypeArgumentsAsTypeParameters(node.typeArguments); + } + signature.parameters = reclassifyArgumentsAsParameters(node.arguments); + signature.type = parseTypeAnnotation(); + } + function parseNonParameterInitializer() { return parseInitializer(/*inParameter*/ false); } @@ -4341,7 +4550,7 @@ module ts { } var decorator = createNode(SyntaxKind.Decorator); - decorator.expression = parseLeftHandSideExpressionOrHigher(); + decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); decorators.push(finishNode(decorator)); } if (decorators) { @@ -4404,6 +4613,10 @@ module ts { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } + if (decorators) { + return reparsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); + } + // 'isClassMemberStart' should have hinted not to attempt parsing. Debug.fail("Should not have attempted to parse class member declaration."); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5781bbf6415c9..e43426106e1c5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -315,22 +315,25 @@ module ts { // If this node was parsed in the parameters of a generator. GeneratorParameter = 1 << 3, + // If this node was parsed as part of a decorator + Decorator = 1 << 4, + // If the parser encountered an error when parsing the code that created this node. Note // the parser only sets this directly on the node it creates right after encountering the // error. - ThisNodeHasError = 1 << 4, + ThisNodeHasError = 1 << 5, // Context flags set directly by the parser. - ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | ThisNodeHasError, + ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError, // Context flags computed by aggregating child flags upwards. // Used during incremental parsing to determine if this node or any of its children had an // error. Computed only once and then cached. - ThisNodeOrAnySubNodesHasError = 1 << 5, + ThisNodeOrAnySubNodesHasError = 1 << 6, // Used to know if we've computed data from children and cached it in this node. - HasAggregatedChildData = 1 << 6 + HasAggregatedChildData = 1 << 7 } export const enum RelationComparisonResult { From b25529bf3b9f1cd00f68df978073988c5d2e34b5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 10 Feb 2015 18:14:16 -0800 Subject: [PATCH 07/33] Initial type-check for decorators --- src/compiler/checker.ts | 61 ++++++++++++++++++- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ src/compiler/parser.ts | 2 + 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6aa4862abc577..8dd7b2f4940c6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -401,6 +401,26 @@ module ts { break loop; } break; + case SyntaxKind.Decorator: + if (location.parent) { + lastLocation = location; + var grandparent = location.parent.parent; + if (location.parent.kind === SyntaxKind.Parameter) { + // Parameter decorators are resolved in the context of their great-grandparent + if (grandparent) { + location = grandparent.parent; + } + else { + break loop; + } + } + else { + // all other decorators are resolved in the context of their grandparent + location = grandparent; + } + continue; + } + break; } lastLocation = location; location = location.parent; @@ -7413,6 +7433,7 @@ module ts { checkGrammarFunctionLikeDeclaration(node); } + checkDecorators(node); checkTypeParameters(node.typeParameters); forEach(node.parameters, checkParameter); @@ -8016,6 +8037,18 @@ module ts { } } + function checkDecorators(node: Node): void { + if (node.decorators) { + checkGrammarDecorators(node); + forEach(node.decorators, checkDecorator); + } + } + + function checkDecorator(node: Decorator): void { + var type = checkExpression(node.expression); + // TODO: check the type of the expression + } + function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || @@ -8733,7 +8766,7 @@ module ts { function checkClassDeclaration(node: ClassDeclaration) { // Grammar checking checkGrammarClassDeclarationHeritageClauses(node); - + checkDecorators(node); checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); checkTypeParameters(node.typeParameters); checkCollisionWithCapturedThisVariable(node, node.name); @@ -10540,6 +10573,32 @@ module ts { checkGrammarForOmittedArgument(node, arguments); } + function checkGrammarDecorators(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + return false; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return node.parent.kind === SyntaxKind.ClassDeclaration; + + case SyntaxKind.Parameter: + switch (node.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Constructor: + return true; + } + break; + } + + return grammarErrorOnNode(node, Diagnostics.Decorators_cannot_appear_here); + } + function checkGrammarHeritageClause(node: HeritageClause): boolean { var types = node.types; if (checkGrammarForDisallowedTrailingComma(types)) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 7bf95dcc84670..851d1dbc9eea5 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -147,6 +147,7 @@ module ts { Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, + Decorators_cannot_appear_here: { code: 1188, category: DiagnosticCategory.Error, key: "Decorators cannot appear here." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b4944f56d774a..588e9a3c2e935 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -579,6 +579,10 @@ "category": "Error", "code": 1187 }, + "Decorators cannot appear here.": { + "category": "Error", + "code": 1188 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 97bdfd589c453..b6cce774b44c6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -223,6 +223,8 @@ module ts { return visitNode(cbNode, (node).name) || visitNode(cbNode, (node).type) || visitNode(cbNode, (node).block); + case SyntaxKind.Decorator: + return visitNode(cbNode, (node).expression); case SyntaxKind.ClassDeclaration: return visitNodes(cbNode, node.decorators) || visitNodes(cbNodes, node.modifiers) || From d7fe7831ccc7a920f615120785a67541081ecaff Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 11 Feb 2015 14:06:32 -0800 Subject: [PATCH 08/33] Updated emit and typecheck for decorators --- src/compiler/checker.ts | 81 +++- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 + src/compiler/emitter.ts | 221 +++------- src/compiler/parser.ts | 381 +++++++++++------- src/compiler/types.ts | 1 + src/lib/core.d.ts | 81 ++++ 7 files changed, 452 insertions(+), 318 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8dd7b2f4940c6..a00d755289c15 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -92,12 +92,25 @@ module ts { var globalRegExpType: ObjectType; var globalTemplateStringsArrayType: ObjectType; + var globalTypedPropertyDescriptorType: ObjectType; + var globalDecoratorTargetsType: ObjectType; + var globalDecoratorFunctionType: ObjectType; + var globalArgumentDecoratorFunctionType: ObjectType; + var globalMemberDecoratorFunctionType: ObjectType; + var globalDecoratorDecorator: ObjectType; + var globalTypeDecorator: ObjectType; + var globalParamTypesDecorator: ObjectType; + var globalReturnTypeDecorator: ObjectType; + var globalConditionalDecorator: ObjectType; + var globalObsoleteDecorator: ObjectType; + var anyArrayType: Type; var tupleTypes: Map = {}; var unionTypes: Map = {}; var stringLiteralTypes: Map = {}; var emitExtends = false; + var emitDecorate = false; var mergedSymbols: Symbol[] = []; var symbolLinks: SymbolLinks[] = []; @@ -8038,10 +8051,24 @@ module ts { } function checkDecorators(node: Node): void { - if (node.decorators) { - checkGrammarDecorators(node); - forEach(node.decorators, checkDecorator); + if (!node.decorators) { + return; + } + + checkGrammarDecorators(node); + + switch (node.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + if (languageVersion >= ScriptTarget.ES5 && node.parent.kind === SyntaxKind.ClassDeclaration) { + emitDecorate = true; + } + break; } + + forEach(node.decorators, checkDecorator); } function checkDecorator(node: Decorator): void { @@ -9607,6 +9634,10 @@ module ts { links.flags |= NodeCheckFlags.EmitExtends; } + if (emitDecorate) { + links.flags |= NodeCheckFlags.EmitDecorate; + } + links.flags |= NodeCheckFlags.TypeChecked; } } @@ -10575,25 +10606,47 @@ module ts { function checkGrammarDecorators(node: Node): boolean { switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.InterfaceDeclaration: + // these are only supported for ambient decorators, which are checked in the typecheck pass + return; + case SyntaxKind.ClassDeclaration: - return false; + // decorators are always allowed on a class + return; case SyntaxKind.MethodDeclaration: case SyntaxKind.PropertyDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: - return node.parent.kind === SyntaxKind.ClassDeclaration; + // we allow decorators on these kinds of members, but disallow non-ambient decorators on class members in ES3 or non-class members in the typecheck pass + return; + //if (node.parent.kind === SyntaxKind.ClassDeclaration) { + // if (languageVersion < ScriptTarget.ES5) { + // return grammarErrorOnNode(node, Diagnostics.Decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher); + // } + // return; + //} + //break; case SyntaxKind.Parameter: - switch (node.kind) { - case SyntaxKind.MethodDeclaration: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.Constructor: - return true; - } - break; + // we allow decorators on parameters, but disallow non-ambient decorators using the above rules in the typecheck pass + return; + + //switch (node.kind) { + // case SyntaxKind.MethodDeclaration: + // case SyntaxKind.PropertyDeclaration: + // case SyntaxKind.GetAccessor: + // case SyntaxKind.SetAccessor: + // case SyntaxKind.Constructor: + // if (node.parent.kind === SyntaxKind.ClassDeclaration) { + // return; + // } + // break; + //} + //break; } return grammarErrorOnNode(node, Diagnostics.Decorators_cannot_appear_here); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 851d1dbc9eea5..7b2c05eecd3fc 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -148,6 +148,7 @@ module ts { A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, Decorators_cannot_appear_here: { code: 1188, category: DiagnosticCategory.Error, key: "Decorators cannot appear here." }, + Decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher: { code: 1189, category: DiagnosticCategory.Error, key: "Decorators are only supported on class members when targeting ECMAScript 5 or higher." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 588e9a3c2e935..33adaf0f5b9e2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -583,6 +583,10 @@ "category": "Error", "code": 1188 }, + "Decorators are only supported on class members when targeting ECMAScript 5 or higher.": { + "category": "Error", + "code": 1189 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 628a54aaa4834..9120dbcb45b64 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1534,6 +1534,7 @@ module ts { var currentSourceFile: SourceFile; var extendsEmitted = false; + var decorateEmitted = false; var tempCount = 0; var tempVariables: Identifier[]; var tempParameters: Identifier[]; @@ -3642,10 +3643,10 @@ module ts { } writeLine(); emitConstructorOfClass(); - var temps = emitMemberFunctions(node); + var decoratorEmitInfo = emitMemberFunctions(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); - emitDecoratorsOfClass(node, temps); + emitDecoratorsOfClass(node, decoratorEmitInfo); emitTempDeclarations(/*newLine*/ true); writeLine(); tempCount = saveTempCount; @@ -3774,6 +3775,7 @@ module ts { } return accessors.lastAccessor.decorators; } + return decorators; } break; } @@ -3786,34 +3788,6 @@ module ts { return; } - var name = parameter.name; - - write("// "); - if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { - if (node.kind === SyntaxKind.Constructor) { - emitNode((node.parent).name); - } - else { - emitTargetOfClassElement(node.parent, node); - var saveEmit = emit; - emit = emitNode; - emitMemberAccessForPropertyName(node.name); - emit = saveEmit; - } - } - else { - emitNode(node.name); - } - write(" parameter #"); - write(String(parameterIndex)); - if (name.kind === SyntaxKind.Identifier) { - write(" ("); - emitNode(name); - write(")"); - } - write(" decorators:"); - writeLine(); - emitStart(node); var decoratorCount = decorators.length; for (var i = 0; i < decoratorCount; i++) { @@ -3821,44 +3795,48 @@ module ts { emitStart(decorator); emit(decorator.expression); write("("); - if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { - if (node.kind === SyntaxKind.Constructor) { - emitNode((node.parent).name); - } - else if (node.kind === SyntaxKind.SetAccessor) { - emitNode(info.propertyDescriptorCache[node.id]); - write(".set"); - } - else { - emitTargetOfClassElement(node.parent, node); - emitMemberAccessForPropertyName(node.name, info.computedPropertyNameCache); - } - } - write(", "); - write(String(parameterIndex)); - write(", "); - emitEnd(decorator); if (i < decoratorCount - 1) { - increaseIndent(); - writeLine(); - write("void "); + write("("); } + emitEnd(decorator); } - write("void 0"); + + emitPropertyAccessForMethod(node, info); + for (var i = decoratorCount - 1; i >= 0; i--) { var decorator = decorators[i]; emitStart(decorator); + if (i < decoratorCount - 1) { + write(", "); + emitPropertyAccessForMethod(node, info); + write(")"); + } + write(", "); + write(String(parameterIndex)); write(")"); emitEnd(decorator); - if (i < decorators.length - 1) { - decreaseIndent(); - } } write(";"); emitEnd(node); writeLine(); } + function emitPropertyAccessForMethod(node: FunctionLikeDeclaration, info: DecoratorEmitInfo) { + if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { + if (node.kind === SyntaxKind.Constructor) { + emitNode((node.parent).name); + } + else if (node.kind === SyntaxKind.SetAccessor) { + emitNode(info.propertyDescriptorCache[node.id]); + write(".set"); + } + else { + emitTargetOfClassElement(node.parent, node); + emitMemberAccessForPropertyName(node.name, info.computedPropertyNameCache); + } + } + } + function emitDecoratorsOfParameters(node: FunctionLikeDeclaration, info: DecoratorEmitInfo) { forEach(node.parameters, (parameter, parameterIndex) => emitDecoratorsOfParameter(node, parameter, parameterIndex, info)); } @@ -3891,111 +3869,32 @@ module ts { break; } - write("// "); - emitTargetOfClassElement(node, member); - var saveEmit = emit; - emit = emitNode; - emitMemberAccessForPropertyName(name); - emit = saveEmit; - write(" decorators:"); - writeLine(); - - var useDescriptors = languageVersion > ScriptTarget.ES3; - if (useDescriptors) { - if (info.propertyDescriptorCache && info.propertyDescriptorCache[member.id]) { - workingVariable = info.propertyDescriptorCache[member.id]; - } - else { - if (!info.workingVariable) { - info.workingVariable = createTempVariable(node); - recordTempDeclaration(info.workingVariable); - } - workingVariable = info.workingVariable; - if (member.kind !== SyntaxKind.PropertyDeclaration) { - emitNode(workingVariable); - write(" = "); - write("Object.getOwnPropertyDescriptor("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, info.computedPropertyNameCache); - write(");"); - writeLine(); - } - } - } - - var workingVariable: Identifier; - var decoratorCount = decorators.length; - for (var i = 0; i < decoratorCount; i++) { - var decorator = decorators[i]; - emitStart(decorator); - if (useDescriptors) { - emitNode(workingVariable); - write(" = "); - } - emit(decorator.expression); - write("("); + if (languageVersion >= ScriptTarget.ES5) { + emitStart(member); + write("__decorate("); emitTargetOfClassElement(node, member); write(", "); emitExpressionForPropertyName(name, info.computedPropertyNameCache); - write(", "); - if (i < decoratorCount - 1) { - increaseIndent(); - writeLine(); - if (!useDescriptors) { - write("void "); + write(", ["); + var decoratorCount = decorators.length; + for (var i = 0; i < decoratorCount; i++) { + if (i > 0) { + write(", "); } + var decorator = decorators[i]; + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); } - emitEnd(decorator); - } - - var hasInitialDescriptor: boolean; - if (!useDescriptors || member.kind === SyntaxKind.PropertyDeclaration) { - hasInitialDescriptor = false; - write("void 0"); - } - else { - hasInitialDescriptor = true; - emitNode(workingVariable); - } - - for (var i = decoratorCount - 1; i >= 0; i--) { - var decorator = decorators[i]; - emitStart(decorator); - write(")"); - if (useDescriptors && (i < decoratorCount - 1 || hasInitialDescriptor)) { - write(" || "); - emitNode(workingVariable); - } - if (i < decoratorCount - 1) { - decreaseIndent(); + write("]"); + if (info.propertyDescriptorCache && info.propertyDescriptorCache[member.id]) { + write(", "); + emitNode(info.propertyDescriptorCache[member.id]); } - emitEnd(decorator); - } - - emitStart(member); - write(";"); - if (useDescriptors) { - writeLine(); - write("if ("); - emitNode(workingVariable); - write(" !== void 0) {"); - increaseIndent(); - writeLine(); - write("Object.defineProperty("); - emitTargetOfClassElement(node, member); - write(", "); - emitExpressionForPropertyName(name, info.computedPropertyNameCache); - write(", "); - emitNode(workingVariable); write(");"); - decreaseIndent(); - writeLine(); - write("}"); + emitEnd(member); writeLine(); - } - emitEnd(member); - writeLine(); + } } function emitDecoratorsOfConstructor(node: ClassDeclaration, info: DecoratorEmitInfo) { @@ -4009,11 +3908,6 @@ module ts { emitDecoratorsOfParameters(constructor, info); } - write("// "); - emitNode(node.name); - write(" decorators"); - writeLine(); - emitStart(node); for (var i = 0; i < decorators.length; i++) { var decorator = decorators[i]; @@ -4371,6 +4265,21 @@ module ts { write("};"); extendsEmitted = true; } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate && languageVersion >= ScriptTarget.ES5) { + writeLine(); + write("var __decorate = this.__decorate || function (t, p, a, d) {"); + increaseIndent(); + writeLine(); + write("d = d || Object.getOwnPropertyDescriptor(t, p);"); + writeLine(); + write("for (var i = a.length - 1; i >= 0; i--) d = (void 0, a[i])(t, p, d) || d;"); + writeLine(); + write("d && Object.defineProperty(t, p, d);"); + decreaseIndent(); + writeLine(); + write("};"); + decorateEmitted = true; + } if (isExternalModule(node)) { if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b6cce774b44c6..6985a409e2586 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -226,7 +226,7 @@ module ts { case SyntaxKind.Decorator: return visitNode(cbNode, (node).expression); case SyntaxKind.ClassDeclaration: - return visitNodes(cbNode, node.decorators) || + return visitNodes(cbNodes, node.decorators) || visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || @@ -312,6 +312,12 @@ module ts { Unknown } + interface SignatureResult { + typeParameters?: NodeArray; + parameters?: NodeArray; + type?: TypeNode; + } + function parsingContextErrors(context: ParsingContext): DiagnosticMessage { switch (context) { case ParsingContext.SourceElements: return Diagnostics.Declaration_or_statement_expected; @@ -884,7 +890,7 @@ module ts { var nodeCount = 0; var scanner: Scanner; var token: SyntaxKind; - + var sourceFile = createNode(SyntaxKind.SourceFile, /*pos*/ 0); sourceFile.pos = sourceFile.end = 0; @@ -1325,6 +1331,13 @@ module ts { return node; } + function createMissingNodeAtPosition(pos: number, kind: SyntaxKind, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { + parseErrorAtPosition(pos, 0, diagnosticMessage, arg0); + var result = createNode(kind, pos); + (result).text = ""; + return finishNode(result, pos); + } + function createMissingNode(kind: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { if (reportAtCurrentPosition) { parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0); @@ -2763,10 +2776,16 @@ module ts { // AssignmentExpression[in] // Expression[in] , AssignmentExpression[in] + // clear the decorator context when parsing Expression, as it should be unambiguous when parsing a decorator + var saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) setDecoratorContext(false); + var expr = parseAssignmentExpressionOrHigher(); while (parseOptional(SyntaxKind.CommaToken)) { expr = makeBinaryExpression(expr, SyntaxKind.CommaToken, parseAssignmentExpressionOrHigher()); } + + if (saveDecoratorContext) setDecoratorContext(true); return expr; } @@ -3439,12 +3458,14 @@ module ts { } function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { - var isInDecoratorContext = inDecoratorContext(); while (true) { expression = parseMemberExpressionRest(expression); - if (isInDecoratorContext && (token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken) && expression.kind === SyntaxKind.ElementAccessExpression) { + if (inDecoratorContext() && + parsingContext === ParsingContext.ClassMembers && + (token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken) && + (expression.kind === SyntaxKind.ElementAccessExpression || expression.kind === SyntaxKind.Identifier)) { // TODO(rbuckton): switch to tryParse and reuse the parsed signature information? - var result = lookAhead(parseCoverCallExpressionOrComputedPropertyNamedMethod); + var result = lookAhead(isStartOfMethodSignature); if (result) { return expression; } @@ -3478,35 +3499,26 @@ module ts { } } - function parseCoverCallExpressionOrComputedPropertyNamedMethod() { - // try to parse it as a signature, if successful and we are followed by an open brace, then this is a computed property named method - var typeParameters: NodeArray; + function isStartOfMethodSignature() { + // try to parse it as a signature, if successful and we are followed by an open brace or semicolon, this is really a method signature var parameters: NodeArray; var type: TypeNode; - if (token === SyntaxKind.LessThanToken) { - typeParameters = parseTypeParameters(); - if (!typeParameters) { - return undefined; - } + if (token === SyntaxKind.LessThanToken && !parseTypeParameters()) { + // failed to parse type parameters here, this is not a method + return false; } if (token === SyntaxKind.OpenParenToken) { - var parameters = parseParameterList(/*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ true); - if (!parameters) { - return undefined; + if (!parseParameterList(/*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ true)) { + // failed to parse a parameter list here, this is not a method + return false; } - if (token === SyntaxKind.ColonToken) { + if (token === SyntaxKind.ColonToken || token === SyntaxKind.SemicolonToken || token === SyntaxKind.OpenBraceToken) { + // found a type annotation, semicolon, or open brace, this is a method signature type = parseTypeAnnotation(); - if (!type) { - return undefined; - } - } - if (token === SyntaxKind.OpenBraceToken || token === SyntaxKind.SemicolonToken) { - // this is a signature, not a call expression - return { typeParameters, parameters, type }; + return true; } } - - return undefined; + return false; } function parseArgumentList() { @@ -4344,127 +4356,6 @@ module ts { } } - function reparsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { - // We may have parsed a decorator with an ElementAccess that we need to reinterpret as a computed property name - var lastDecorator = decorators[decorators.length - 1]; - var expression = lastDecorator.expression; - - var callExpression: CallExpression; - if (expression.kind === SyntaxKind.CallExpression) { - callExpression = expression; - expression = callExpression.expression; - } - - var elementAccessExpression: ElementAccessExpression; - if (expression.kind === SyntaxKind.ElementAccessExpression) { - elementAccessExpression = expression; - } - - if (elementAccessExpression) { - // update last decorator expression and end - lastDecorator.expression = elementAccessExpression.expression; - lastDecorator.end = elementAccessExpression.expression.end; - - var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, elementAccessExpression.pos); - computedPropertyName.expression = elementAccessExpression.argumentExpression; - finishNode(computedPropertyName, elementAccessExpression.end); - - var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - if (callExpression) { - // reinterpret as a computed property method? - var method = createNode(SyntaxKind.MethodDeclaration, fullStart); - method.decorators = decorators; - setModifiers(method, modifiers); - method.name = computedPropertyName; - method.questionToken = questionToken; - reclassifyCallExpressionAsSignature(callExpression, method); - method.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false); - return finishNode(method); - } - else { - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, decorators, modifiers, /*asteriskToken*/ undefined, computedPropertyName, questionToken, Diagnostics.or_expected); - } - - // reinterpret as a computed property declaration - var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); - property.decorators = decorators; - setModifiers(property, modifiers); - property.name = computedPropertyName; - property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); - parseSemicolon(); - return finishNode(property); - } - } - - // 'isClassMemberStart' should have hinted not to attempt parsing. - Debug.fail("Should not have attempted to parse class member declaration."); - } - - function reclassifyTypeArgumentsAsTypeParameters(typeArguments: NodeArray): NodeArray { - var typeParameters = >[]; - typeParameters.pos = typeArguments.pos; - typeParameters.end = typeArguments.end; - for (var i = 0; i < typeArguments.length; i++) { - var typeArgument = typeArguments[i]; - var typeParameter = createNode(SyntaxKind.TypeParameter, typeArgument.pos); - Debug.assert(typeArgument.kind === SyntaxKind.TypeReference); - var typeReference = typeArgument; - Debug.assert(typeReference.typeName.kind === SyntaxKind.Identifier); - typeParameter.name = typeReference.typeName; - finishNode(typeParameter, typeArgument.end); - typeParameters.push(typeParameter); - } - return typeParameters; - } - - function reclassifyArgumentsAsParameters(arguments: NodeArray): NodeArray { - var parameters = >[]; - parameters.pos = arguments.pos; - parameters.end = arguments.end; - for (var i = 0; i < arguments.length; i++) { - var argument = arguments[i]; - - // TODO: Object literal as object binding - // TODO: Array literal as array binding - var name: Identifier; - var initializer: Expression; - if (argument.kind === SyntaxKind.Identifier) { - name = argument; - } - else if (argument.kind === SyntaxKind.BinaryExpression) { - var binaryExpression = argument; - Debug.assert(binaryExpression.operator === SyntaxKind.EqualsToken); - if (binaryExpression.left.kind === SyntaxKind.Identifier) { - name = binaryExpression.left; - initializer = binaryExpression.right; - } - else { - Debug.fail("Invalid attempt to reclassify expression."); - } - } - else { - Debug.fail("Invalid attempt to reclassify expression."); - } - - var parameter = createNode(SyntaxKind.Parameter, argument.pos); - parameter.name = name; - parameter.initializer = initializer; - finishNode(parameter, argument.end); - parameters.push(parameter); - } - return parameters; - } - - function reclassifyCallExpressionAsSignature(node: CallExpression, signature: SignatureDeclaration): void { - if (node.typeArguments) { - signature.typeParameters = reclassifyTypeArgumentsAsTypeParameters(node.typeArguments); - } - signature.parameters = reclassifyArgumentsAsParameters(node.arguments); - signature.type = parseTypeAnnotation(); - } - function parseNonParameterInitializer() { return parseInitializer(/*inParameter*/ false); } @@ -4586,6 +4477,200 @@ module ts { return modifiers; } + function extractCallExpressionFromDecoratorTail(decorator: Decorator): CallExpression { + // We could have greedily parsed a method signature name as a call expression, so we extract it from the decorator. + var expression = decorator.expression; + if (expression.kind === SyntaxKind.CallExpression) { + decorator.expression = (expression).expression; + decorator.end = decorator.expression.end; + return expression; + } + return undefined; + } + + function extractDeclarationNameFromDecoratorTail(decorator: Decorator): DeclarationName { + var expression = decorator.expression; + var name: DeclarationName; + switch (expression.kind) { + case SyntaxKind.Identifier: + // We could have greedily parsed a property name as an identifier, so + // we extract it from the decorator for a better editor experience: + // @ + // id() {} + // + decorator.expression = createMissingNodeAtPosition(decorator.pos + 1, SyntaxKind.Identifier, Diagnostics.Expression_expected); + name = expression; + break; + + case SyntaxKind.PropertyAccessExpression: + // We could have greedily parsed a property name as a property access, so we extract it from the decorator + // for a better editor experience. + var propExpr = expression; + if (nodeIsMissing(propExpr.name)) { + name = createMissingNodeAtPosition(decorator.pos + 1, SyntaxKind.Identifier, Diagnostics.Identifier_expected); + } + else { + name = propExpr.name; + propExpr.name = createMissingNodeAtPosition(name.pos, SyntaxKind.Identifier, Diagnostics.Identifier_expected); + propExpr.end = propExpr.name.end; + } + break; + + case SyntaxKind.ArrayLiteralExpression: + // We could have greedily parsed a computed property name as an array literal expression, so + // we extract it from the decorator for a better editor experience: + // @ + // ["computed"]() {} + // + var arrayExpr = expression; + decorator.expression = createMissingNodeAtPosition(decorator.pos + 1, SyntaxKind.Identifier, Diagnostics.Expression_expected); + + var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, arrayExpr.pos); + if (arrayExpr.elements.length === 0) { + computedPropertyName.expression = createMissingNodeAtPosition(arrayExpr.pos + 1, SyntaxKind.Identifier, Diagnostics.Expression_expected); + } + else { + computedPropertyName.expression = arrayExpr.elements[0]; + for (var i = 1; i < arrayExpr.elements.length; i++) { + var commaExpr = createNode(SyntaxKind.BinaryExpression, computedPropertyName.expression.pos); + commaExpr.operator = SyntaxKind.CommaToken; + commaExpr.left = computedPropertyName.expression; + commaExpr.right = arrayExpr.elements[i]; + computedPropertyName.expression = finishNode(commaExpr, commaExpr.right.end); + } + } + name = finishNode(computedPropertyName, arrayExpr.end); + break; + + case SyntaxKind.ElementAccessExpression: + // We could have greedily parsed a computed property name as an element access, so we extract it from the decorator. + var elementExpr = expression; + decorator.expression = elementExpr.expression; + + var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, elementExpr.argumentExpression.pos); + computedPropertyName.expression = elementExpr.argumentExpression; + name = finishNode(computedPropertyName, elementExpr.end); + break; + + default: + return undefined; + } + + decorator.end = decorator.expression.end; + return name; + } + + function reparseTypeArgumentsAsTypeParameters(typeArguments: NodeArray): NodeArray { + var typeParameters = >[]; + typeParameters.pos = typeArguments.pos; + typeParameters.end = typeArguments.end; + for (var i = 0; i < typeArguments.length; i++) { + var typeArgument = typeArguments[i]; + var typeParameter = createNode(SyntaxKind.TypeParameter, typeArgument.pos); + Debug.assert(typeArgument.kind === SyntaxKind.TypeReference); + var typeReference = typeArgument; + Debug.assert(typeReference.typeName.kind === SyntaxKind.Identifier); + typeParameter.name = typeReference.typeName; + finishNode(typeParameter, typeArgument.end); + typeParameters.push(typeParameter); + } + return typeParameters; + } + + function reparseArgumentsAsParameters(argumentList: NodeArray): NodeArray { + var parameters = >[]; + parameters.pos = argumentList.pos; + parameters.end = argumentList.end; + for (var i = 0; i < argumentList.length; i++) { + var argument = argumentList[i]; + + // TODO: Object literal as object binding + // TODO: Array literal as array binding + var name: Identifier; + var initializer: Expression; + if (argument.kind === SyntaxKind.Identifier) { + name = argument; + } + else if (argument.kind === SyntaxKind.BinaryExpression) { + var binaryExpression = argument; + Debug.assert(binaryExpression.operator === SyntaxKind.EqualsToken); + if (binaryExpression.left.kind === SyntaxKind.Identifier) { + name = binaryExpression.left; + initializer = binaryExpression.right; + } + else { + Debug.fail("Invalid attempt to reclassify expression."); + } + } + else { + Debug.fail("Invalid attempt to reclassify expression."); + } + + var parameter = createNode(SyntaxKind.Parameter, argument.pos); + parameter.name = name; + parameter.initializer = initializer; + finishNode(parameter, argument.end); + parameters.push(parameter); + } + return parameters; + } + + function reparseCallExpressionAsSignature(node: CallExpression, signature: SignatureDeclaration): void { + if (node.typeArguments) { + signature.typeParameters = reparseTypeArgumentsAsTypeParameters(node.typeArguments); + } + signature.parameters = reparseArgumentsAsParameters(node.arguments); + signature.type = parseTypeAnnotation(); + } + + function reparseClassElement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { + // We may have parsed a decorator that greedily included part of the member as its expression. + var lastDecorator = decorators[decorators.length - 1]; + + // TODO(rbuckton): pull out the call expression or declaration name from the consise body of an arrow function + + // If we parsed a call expression, extract the call expression to reparse as a signature + var callExpression = extractCallExpressionFromDecoratorTail(lastDecorator); + + // Extract the declaration name from the decorator + var name = extractDeclarationNameFromDecoratorTail(lastDecorator); + if (name) { + var questionToken = parseOptionalToken(SyntaxKind.QuestionToken); + if (callExpression) { + // Reparse as a computed property method + var method = createNode(SyntaxKind.MethodDeclaration, fullStart); + method.decorators = decorators; + setModifiers(method, modifiers); + method.name = name; + method.questionToken = questionToken; + reparseCallExpressionAsSignature(callExpression, method); + method.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false); + return finishNode(method); + } + else { + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return parseMethodDeclaration(fullStart, decorators, modifiers, /*asteriskToken*/ undefined, name, questionToken, Diagnostics.or_expected); + } + + // Reparse as a computed property declaration + var property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; + setModifiers(property, modifiers); + property.name = name; + property.type = parseTypeAnnotation(); + property.initializer = allowInAnd(parseNonParameterInitializer); + parseSemicolon(); + return finishNode(property); + } + } + + // We couldn't reparse this node, so attach the decorators to an incomplete declaration + var incomplete = createNode(SyntaxKind.IncompleteDeclaration, fullStart); + incomplete.decorators = decorators; + setModifiers(incomplete, modifiers); + return incomplete; + } + function parseClassElement(): ClassElement { var fullStart = getNodePos(); var decorators = parseDecorators(); @@ -4616,7 +4701,7 @@ module ts { } if (decorators) { - return reparsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); + return reparseClassElement(fullStart, decorators, modifiers); } // 'isClassMemberStart' should have hinted not to attempt parsing. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e43426106e1c5..cbc4f3ac3ce18 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1268,6 +1268,7 @@ module ts { // Values for enum members have been computed, and any errors have been reported for them. EnumValuesComputed = 0x00000080, + EmitDecorate = 0x00000100, } export interface NodeLinks { diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index cb5324fbd3da1..c4200a3c3f06e 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1149,3 +1149,84 @@ interface ArrayConstructor { } declare var Array: ArrayConstructor; + +interface TypedPropertyDescriptor { + enumerable?: boolean; + configurable?: boolean; + writable?: boolean; + value?: T; + get?: () => T; + set?: (value: T) => void; +} + +declare const enum DecoratorTargets { + class = 0x1, + interface = 0x2, + function = 0x3, + method = 0x4, + accessor = 0x5, + property = 0x6, + parameter = 0x7, + all = DecoratorTargets.class | DecoratorTargets.interface | DecoratorTargets.function | DecoratorTargets.method | DecoratorTargets.accessor | DecoratorTargets.property | DecoratorTargets.parameter +} + +interface DecoratorFunction { (target: TFunction): TFunction | void; } +interface ArgumentDecoratorFunction { (target: Function, parameterIndex: number): void; } +interface MemberDecoratorFunction { (target: Function | Object, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void; } + +/** + * Built-in decorator. Used to define the valid usage of a decorator. + */ +@decorator({ ambient: true, allowOn: DecoratorTargets.function, allowMultiple: false }) +declare function decorator(options?: { + /** + * Valid targets for this decorator. + * + * default: DecoratorTargets.all + */ + allowOn?: DecoratorTargets; + + /** + * Indicates whether multiple applications are allowed on the same declaration or not. + * + * default: true + */ + allowMultiple?: boolean; + + /** + * Indicates whether the decorator is used for design-time only and should not be applied to emitted code. + * + * default: false + */ + ambient?: boolean; +}): DecoratorFunction; + +/** + * Built-in decorator. Emits the serialized type of the target in the argument position of the decorated parameter. + */ +@decorator({ ambient: true, allowOn: DecoratorTargets.parameter, allowMultiple: false }) +declare function type(): DecoratorFunction; + +/** + * Built-in decorator. Emits the serialized types of the parameters of the target in the argument position of the decorated parameter. + */ +@decorator({ ambient: true, allowOn: DecoratorTargets.parameter, allowMultiple: false }) +declare function paramTypes(): DecoratorFunction; + +/** + * Built-in decorator. Emits the serialized return type of the target in the argument position of the decorated parameter. + */ +@decorator({ ambient: true, allowOn: DecoratorTargets.parameter, allowMultiple: false }) +declare function returnType(): DecoratorFunction; + +/** + * Built-in decorator. Does not emit any calls to the target if the provided condition is true. + */ +@decorator({ ambient: true, allowOn: DecoratorTargets.function | DecoratorTargets.method, allowMultiple: false }) +declare function conditional(condition: string): DecoratorFunction; + +/** + * Built-in decorator. Any usage of the target is treated as an error during compilation. + */ +@decorator({ ambient: true, allowMultiple: false }) +declare function obsolete(message?: string): DecoratorFunction; \ No newline at end of file From f6d3a5f2d6e720721af2a79fe544eabcda7add3a Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 12 Feb 2015 14:05:29 -0800 Subject: [PATCH 09/33] Fixed formatting for decorators --- src/services/formatting/formatting.ts | 33 ++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 969f7260744ed..7d5535bd58bbe 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -419,6 +419,29 @@ module ts.formatting { } } + function getFirstNonDecoratorTokenOfNode(node: Node) { + if (node.modifiers && node.modifiers.length) { + return node.modifiers[0].kind; + } + switch (node.kind) { + case SyntaxKind.ClassDeclaration: return SyntaxKind.ClassKeyword; + case SyntaxKind.InterfaceDeclaration: return SyntaxKind.InterfaceKeyword; + case SyntaxKind.FunctionDeclaration: return SyntaxKind.FunctionKeyword; + case SyntaxKind.EnumDeclaration: return SyntaxKind.EnumDeclaration; + case SyntaxKind.GetAccessor: return SyntaxKind.GetKeyword; + case SyntaxKind.SetAccessor: return SyntaxKind.SetKeyword; + case SyntaxKind.MethodDeclaration: + if ((node).asteriskToken) { + return SyntaxKind.AsteriskToken; + } + // fall-through + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + return (node).name.kind; + } + } + function getDynamicIndentation(node: Node, nodeStartLine: number, indentation: number, delta: number): DynamicIndentation { return { getIndentationForComment: kind => { @@ -434,15 +457,23 @@ module ts.formatting { return indentation; }, getIndentationForToken: (line, kind) => { + if (nodeStartLine !== line && node.decorators) { + if (kind === getFirstNonDecoratorTokenOfNode(node)) { + // if this token is the first token following the list of decorators, we do not need to indent + return indentation; + } + } switch (kind) { - // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent + // open and close brace, 'else' and 'while' (in do statement), and '@' (decorator) tokens have indentation of the parent case SyntaxKind.OpenBraceToken: case SyntaxKind.CloseBraceToken: case SyntaxKind.OpenBracketToken: case SyntaxKind.CloseBracketToken: case SyntaxKind.ElseKeyword: case SyntaxKind.WhileKeyword: + case SyntaxKind.AtToken: return indentation; + default: // if token line equals to the line of containing node (this is a first token in the node) - use node indentation return nodeStartLine !== line ? indentation + delta : indentation; From 05fc881752cd4675009e1fc2b7b83f91277b8ec5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 12 Feb 2015 14:07:16 -0800 Subject: [PATCH 10/33] Added global resolution for symbols and types for decorators --- src/compiler/checker.ts | 30 +++++++---- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ src/lib/core.d.ts | 50 ++----------------- 4 files changed, 30 insertions(+), 55 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a00d755289c15..14d245ee85dbb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -82,6 +82,9 @@ module ts { var globals: SymbolTable = {}; var globalArraySymbol: Symbol; + var globalTypeDecoratorSymbol: Symbol; + var globalParamTypesDecoratorSymbol: Symbol; + var globalReturnTypeDecoratorSymbol: Symbol; var globalObjectType: ObjectType; var globalFunctionType: ObjectType; @@ -93,17 +96,10 @@ module ts { var globalTemplateStringsArrayType: ObjectType; var globalTypedPropertyDescriptorType: ObjectType; - var globalDecoratorTargetsType: ObjectType; var globalDecoratorFunctionType: ObjectType; - var globalArgumentDecoratorFunctionType: ObjectType; + var globalParameterDecoratorFunctionType: ObjectType; var globalMemberDecoratorFunctionType: ObjectType; - var globalDecoratorDecorator: ObjectType; - var globalTypeDecorator: ObjectType; - var globalParamTypesDecorator: ObjectType; - var globalReturnTypeDecorator: ObjectType; - var globalConditionalDecorator: ObjectType; - var globalObsoleteDecorator: ObjectType; - + var anyArrayType: Type; var tupleTypes: Map = {}; @@ -3029,6 +3025,14 @@ module ts { return type; } + function getGlobalConstEnumSymbol(name: string): Symbol { + return resolveName(undefined, name, SymbolFlags.ConstEnum, Diagnostics.Cannot_find_global_type_0, name); + } + + function getGlobalDecoratorSymbol(name: string): Symbol { + return resolveName(undefined, name, SymbolFlags.Function, Diagnostics.Cannot_find_global_decorator_function_0, name); + } + function getGlobalSymbol(name: string): Symbol { return resolveName(undefined, name, SymbolFlags.Type, Diagnostics.Cannot_find_global_type_0, name); } @@ -10320,6 +10324,14 @@ module ts { globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); + globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalSymbol("TypedPropertyDescriptor"), 1); + globalDecoratorFunctionType = getGlobalType("DecoratorFunction"); + globalParameterDecoratorFunctionType = getGlobalType("ParameterDecoratorFunction"); + globalMemberDecoratorFunctionType = getGlobalType("MemberDecoratorFunction"); + globalTypeDecoratorSymbol = getGlobalDecoratorSymbol("type"); + globalParamTypesDecoratorSymbol = getGlobalDecoratorSymbol("paramtypes"); + globalReturnTypeDecoratorSymbol = getGlobalDecoratorSymbol("returntype"); + // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. globalTemplateStringsArrayType = languageVersion >= ScriptTarget.ES6 diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 7b2c05eecd3fc..e89195f8f48d9 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -305,6 +305,7 @@ module ts { this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." }, super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." }, A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." }, + Cannot_find_global_decorator_function_0: { code: 2467, category: DiagnosticCategory.Error, key: "Cannot find global decorator function '{0}'." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 33adaf0f5b9e2..32c039d5f72ac 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1212,6 +1212,10 @@ "category": "Error", "code": 2466 }, + "Cannot find global decorator function '{0}'.": { + "category": "Error", + "code": 2467 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index c4200a3c3f06e..28b7eec601d1a 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1171,62 +1171,20 @@ declare const enum DecoratorTargets { } interface DecoratorFunction { (target: TFunction): TFunction | void; } -interface ArgumentDecoratorFunction { (target: Function, parameterIndex: number): void; } +interface ParameterDecoratorFunction { (target: Function, parameterIndex: number): void; } interface MemberDecoratorFunction { (target: Function | Object, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void; } -/** - * Built-in decorator. Used to define the valid usage of a decorator. - */ -@decorator({ ambient: true, allowOn: DecoratorTargets.function, allowMultiple: false }) -declare function decorator(options?: { - /** - * Valid targets for this decorator. - * - * default: DecoratorTargets.all - */ - allowOn?: DecoratorTargets; - - /** - * Indicates whether multiple applications are allowed on the same declaration or not. - * - * default: true - */ - allowMultiple?: boolean; - - /** - * Indicates whether the decorator is used for design-time only and should not be applied to emitted code. - * - * default: false - */ - ambient?: boolean; -}): DecoratorFunction; - /** * Built-in decorator. Emits the serialized type of the target in the argument position of the decorated parameter. */ -@decorator({ ambient: true, allowOn: DecoratorTargets.parameter, allowMultiple: false }) -declare function type(): DecoratorFunction; +declare function type(): void; /** * Built-in decorator. Emits the serialized types of the parameters of the target in the argument position of the decorated parameter. */ -@decorator({ ambient: true, allowOn: DecoratorTargets.parameter, allowMultiple: false }) -declare function paramTypes(): DecoratorFunction; +declare function paramtypes(): void; /** * Built-in decorator. Emits the serialized return type of the target in the argument position of the decorated parameter. */ -@decorator({ ambient: true, allowOn: DecoratorTargets.parameter, allowMultiple: false }) -declare function returnType(): DecoratorFunction; - -/** - * Built-in decorator. Does not emit any calls to the target if the provided condition is true. - */ -@decorator({ ambient: true, allowOn: DecoratorTargets.function | DecoratorTargets.method, allowMultiple: false }) -declare function conditional(condition: string): DecoratorFunction; - -/** - * Built-in decorator. Any usage of the target is treated as an error during compilation. - */ -@decorator({ ambient: true, allowMultiple: false }) -declare function obsolete(message?: string): DecoratorFunction; \ No newline at end of file +declare function returntype(): void; From 677d710aed675304976c7b9e4fd07f25902743ce Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 16 Feb 2015 15:37:25 -0800 Subject: [PATCH 11/33] Added initial support for built-in decorators: @type, @paramtypes, and @returntype --- src/compiler/checker.ts | 145 +++++++++++++- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 + src/compiler/emitter.ts | 177 ++++++++++++++---- src/compiler/types.ts | 26 ++- src/compiler/utilities.ts | 11 ++ 6 files changed, 312 insertions(+), 52 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 14d245ee85dbb..b66b5bae2b843 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -62,9 +62,9 @@ module ts { var resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); var anyType = createIntrinsicType(TypeFlags.Any, "any"); - var stringType = createIntrinsicType(TypeFlags.String, "string"); - var numberType = createIntrinsicType(TypeFlags.Number, "number"); - var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean"); + var stringType = createIntrinsicType(TypeFlags.String, "string", /*boxedType*/ "String"); + var numberType = createIntrinsicType(TypeFlags.Number, "number", /*boxedType*/ "Number"); + var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean", /*boxedType*/ "Boolean"); var voidType = createIntrinsicType(TypeFlags.Void, "void"); var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined"); var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null"); @@ -720,9 +720,10 @@ module ts { return result; } - function createIntrinsicType(kind: TypeFlags, intrinsicName: string): IntrinsicType { + function createIntrinsicType(kind: TypeFlags, intrinsicName: string, boxedName?: string): IntrinsicType { var type = createType(kind); type.intrinsicName = intrinsicName; + type.boxedName = boxedName; return type; } @@ -8076,8 +8077,51 @@ module ts { } function checkDecorator(node: Decorator): void { - var type = checkExpression(node.expression); - // TODO: check the type of the expression + var expression: Expression = node.expression; + var type = checkExpression(expression); + + // check built-in decorators + + // unwrap the identifier for the decorator (if present) + var decorator = expression; + while (decorator.kind === SyntaxKind.ParenthesizedExpression) { + decorator = (decorator).expression; + } + if (decorator.kind === SyntaxKind.CallExpression) { + decorator = (decorator).expression; + } + while (decorator.kind === SyntaxKind.ParenthesizedExpression) { + decorator = (decorator).expression; + } + + // if the identifier points to one of the built-in symbols, add relevant information for later emit. + if (decorator.kind === SyntaxKind.Identifier) { + var symbol = getResolvedSymbol(decorator); + if (symbol === globalTypeDecoratorSymbol + || symbol === globalParamTypesDecoratorSymbol + || symbol === globalReturnTypeDecoratorSymbol) { + + // these are only valid on a parameter + if (node.parent.kind !== SyntaxKind.Parameter) { + error(decorator, Diagnostics.Decorator_0_is_not_valid_on_this_declaration_type_It_is_only_valid_on_1_declarations, symbol.name, "parameter"); + } + + // TODO(rbuckton): check assignability to the parameter + // TODO(rbuckton): check decorator is only applied to value declaration + + if (symbol === globalTypeDecoratorSymbol) { + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedType; + } + else if (symbol === globalParamTypesDecoratorSymbol) { + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedParamTypes; + } + else if (symbol === globalReturnTypeDecoratorSymbol) { + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedReturnType; + } + } + } + + // TODO(rbuckton): check the type of the expression } function checkFunctionDeclaration(node: FunctionDeclaration): void { @@ -8328,6 +8372,7 @@ module ts { // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { + checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit if (hasDynamicName(node)) { @@ -10258,6 +10303,90 @@ module ts { return undefined; } + function serializeType(type: Type): string { + var flags = type.flags; + if (flags & TypeFlags.Void) { + return "void 0"; + } + else if (flags & TypeFlags.Intrinsic) { + var boxedName = (type).boxedName; + if (boxedName) { + return boxedName; + } + } + else if (flags & TypeFlags.StringLiteral) { + return "String"; + } + else if (flags & TypeFlags.Enum) { + return "Number"; + } + else if (flags & TypeFlags.Tuple) { + return "Array"; + } + else { + var symbol = type.symbol; + var declaration = symbol.valueDeclaration; + if (declaration) { + var name = declaration.name; + if (name && name.kind === SyntaxKind.Identifier) { + var prefix = getExpressionNamePrefix(name); + if (prefix) { + return prefix + "." + (name).text; + } + return (name).text; + } + } + } + + var signatures = getSignaturesOfType(type, SignatureKind.Call); + if (signatures.length) { + return "Function"; + } + + return "Object"; + } + + function serializeTypeOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration | PropertyDeclaration | ParameterDeclaration): string { + var symbol = getSymbolOfNode(node); + var type = symbol ? getTypeOfSymbol(symbol) : unknownType; + return serializeType(type); + } + + function serializeParameterTypesOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration): string[]{ + var valueDeclaration: FunctionLikeDeclaration; + if (node.kind === SyntaxKind.ClassDeclaration) { + valueDeclaration = getFirstConstructorWithBody(node); + } + else if (isAnyFunction(node) && nodeIsPresent((node).body)) { + valueDeclaration = node; + } + if (valueDeclaration) { + var result: string[]; + var parameters = valueDeclaration.parameters; + var parameterCount = parameters.length; + if (parameterCount > 0) { + result = new Array(parameterCount); + for (var i = 0; i < parameterCount; i++) { + result[i] = serializeTypeOfDeclaration(parameters[i]); + } + return result; + } + } + return emptyArray; + } + + function serializeReturnTypeOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration): string { + var valueDeclaration: FunctionLikeDeclaration; + if (node.kind === SyntaxKind.ClassDeclaration) { + return serializeTypeOfDeclaration(node); + } + else if (isAnyFunction(node) && nodeIsPresent((node).body)) { + var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(valueDeclaration)); + return serializeType(returnType); + } + return "void 0"; + } + function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { // Get type of the symbol if this is the valid symbol otherwise get type at location var symbol = getSymbolOfNode(declaration); @@ -10295,6 +10424,10 @@ module ts { isEntityNameVisible, getConstantValue, isUnknownIdentifier, + getResolvedSignature, + serializeTypeOfDeclaration, + serializeParameterTypesOfDeclaration, + serializeReturnTypeOfDeclaration }; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index e89195f8f48d9..602a56c861031 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -149,6 +149,7 @@ module ts { A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, Decorators_cannot_appear_here: { code: 1188, category: DiagnosticCategory.Error, key: "Decorators cannot appear here." }, Decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher: { code: 1189, category: DiagnosticCategory.Error, key: "Decorators are only supported on class members when targeting ECMAScript 5 or higher." }, + Decorator_0_is_not_valid_on_this_declaration_type_It_is_only_valid_on_1_declarations: { code: 1190, category: DiagnosticCategory.Error, key: "Decorator '{0}' is not valid on this declaration type. It is only valid on '{1}' declarations." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 32c039d5f72ac..710e6fae7fee7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -587,6 +587,10 @@ "category": "Error", "code": 1189 }, + "Decorator '{0}' is not valid on this declaration type. It is only valid on '{1}' declarations.": { + "category": "Error", + "code": 1190 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9120dbcb45b64..0dc4c74f4dba9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -269,14 +269,6 @@ module ts { } } - function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { - return forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { - return member; - } - }); - } - function getAllAccessorDeclarations(node: ClassDeclaration, accessor: AccessorDeclaration) { var firstAccessor: AccessorDeclaration; var lastAccessor: AccessorDeclaration; @@ -2548,7 +2540,7 @@ module ts { write("]"); } - function emitCallExpression(node: CallExpression) { + function emitCallExpression(node: CallExpression, emitArguments: (args: Expression[], node: CallExpression) => void = emitCommaList) { var superCall = false; if (node.expression.kind === SyntaxKind.SuperKeyword) { write("_super"); @@ -2563,13 +2555,13 @@ module ts { emitThis(node.expression); if (node.arguments.length) { write(", "); - emitCommaList(node.arguments); + emitArguments(node.arguments, node); } write(")"); } else { write("("); - emitCommaList(node.arguments); + emitArguments(node.arguments, node); write(")"); } } @@ -2947,6 +2939,14 @@ module ts { emitEnd(node.name); } + function createVoidZero(): Expression { + var zero = createNode(SyntaxKind.NumericLiteral); + zero.text = "0"; + var result = createNode(SyntaxKind.VoidExpression); + result.expression = zero; + return result; + } + function emitDestructuring(root: BinaryExpression | VariableDeclaration | ParameterDeclaration, value?: Expression) { var emitCount = 0; // An exported declaration is actually emitted as an assignment (to a property on the module object), so @@ -2985,14 +2985,6 @@ module ts { return expr; } - function createVoidZero(): Expression { - var zero = createNode(SyntaxKind.NumericLiteral); - zero.text = "0"; - var result = createNode(SyntaxKind.VoidExpression); - result.expression = zero; - return result; - } - function createDefaultValueCheck(value: Expression, defaultValue: Expression): Expression { // The value expression will be evaluated twice, so for anything but a simple identifier // we need to generate a temporary variable @@ -3782,6 +3774,117 @@ module ts { return undefined; } + function shouldEmitSerializedTypeForNode(decorated: Declaration): boolean { + switch (decorated.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.Parameter: + return true; + } + return false; + } + + function shouldEmitSerializedParameterTypesOrReturnTypeForNode(decorated: Declaration): boolean { + switch (decorated.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return true; + } + return false; + } + + function emitSerializedType(node: ClassDeclaration | PropertyDeclaration | FunctionLikeDeclaration | ParameterDeclaration) { + var serializedType = resolver.serializeTypeOfDeclaration(node); + write(serializedType); + } + + function emitSerializedParameterTypes(node: ClassDeclaration | FunctionLikeDeclaration) { + var serializedTypes = resolver.serializeParameterTypesOfDeclaration(node); + write("["); + for (var i = 0; i < serializedTypes.length; i++) { + if (i > 0) { + write(", "); + } + write(serializedTypes[i]); + } + write("]"); + } + + function emitSerializedReturnType(node: ClassDeclaration | FunctionLikeDeclaration) { + var serializedType = resolver.serializeReturnTypeOfDeclaration(node); + write(serializedType); + } + + function emitArgumentsOfDecoratorFactory(args: Expression[], node: CallExpression) { + emitCommaList(args); + + var decorator = node.parent; + if (!isDeclaration(decorator.parent)) { + return; + } + + var decorated = decorator.parent; + var signature = resolver.getResolvedSignature(node); + var declaration = signature.declaration; + if (!declaration) { + return; + } + + var argCount = args ? args.length : 0; + var parameters = declaration.parameters; + var parameterCount = signature.hasRestParameter ? parameters.length - 1 : parameters.length; + var lastArg = argCount; + for (var i = argCount; i < parameterCount; i++) { + var parameter = parameters[i]; + var flags = resolver.getNodeCheckFlags(parameter); + if (flags & (NodeCheckFlags.EmitDecoratedType | NodeCheckFlags.EmitDecoratedParamTypes | NodeCheckFlags.EmitDecoratedReturnType)) { + var shouldEmitCompilerGeneratedArgument = flags & NodeCheckFlags.EmitDecoratedType + ? shouldEmitSerializedTypeForNode + : shouldEmitSerializedParameterTypesOrReturnTypeForNode; + if (shouldEmitCompilerGeneratedArgument(decorated)) { + while (lastArg < i) { + if (i > 0) { + write(", "); + } + write("void 0"); + lastArg++; + } + if (i > 0) { + write(", "); + } + if (flags & NodeCheckFlags.EmitDecoratedType) { + emitSerializedType(decorated); + } + else if (flags & NodeCheckFlags.EmitDecoratedParamTypes) { + emitSerializedParameterTypes(decorated); + } + else if (flags & NodeCheckFlags.EmitDecoratedReturnType) { + emitSerializedReturnType(decorated); + } + lastArg++; + } + } + } + } + + function emitExpressionOfDecorator(node: Decorator) { + var expression = node.expression; + if (expression.kind === SyntaxKind.CallExpression) { + var callExpr = expression; + emitCallExpression(callExpr, emitArgumentsOfDecoratorFactory); + } + else { + emit(expression); + } + } + function emitDecoratorsOfParameter(node: FunctionLikeDeclaration, parameter: ParameterDeclaration, parameterIndex: number, info: DecoratorEmitInfo) { var decorators = parameter.decorators; if (!decorators) { @@ -3793,7 +3896,7 @@ module ts { for (var i = 0; i < decoratorCount; i++) { var decorator = decorators[i]; emitStart(decorator); - emit(decorator.expression); + emitExpressionOfDecorator(decorator); write("("); if (i < decoratorCount - 1) { write("("); @@ -3846,16 +3949,6 @@ module ts { } function emitDecoratorsOfMember(node: ClassDeclaration, member: ClassElement, info: DecoratorEmitInfo) { - var name = member.name; - var decorators = getDecoratorsOfMember(node, member); - if (!decorators) { - return; - } - - if (name.kind === SyntaxKind.ComputedPropertyName && !info.computedPropertyNameCache) { - info.computedPropertyNameCache = []; - } - switch (member.kind) { case SyntaxKind.MethodDeclaration: emitDecoratorsOfParameters(member, info); @@ -3869,6 +3962,16 @@ module ts { break; } + var name = member.name; + var decorators = getDecoratorsOfMember(node, member); + if (!decorators) { + return; + } + + if (name.kind === SyntaxKind.ComputedPropertyName && !info.computedPropertyNameCache) { + info.computedPropertyNameCache = []; + } + if (languageVersion >= ScriptTarget.ES5) { emitStart(member); write("__decorate("); @@ -3883,7 +3986,7 @@ module ts { } var decorator = decorators[i]; emitStart(decorator); - emit(decorator.expression); + emitExpressionOfDecorator(decorator); emitEnd(decorator); } write("]"); @@ -3898,23 +4001,23 @@ module ts { } function emitDecoratorsOfConstructor(node: ClassDeclaration, info: DecoratorEmitInfo) { - var decorators = node.decorators; - if (!node.decorators) { - return; - } - var constructor = getFirstConstructorWithBody(node); if (constructor) { emitDecoratorsOfParameters(constructor, info); } + var decorators = node.decorators; + if (!node.decorators) { + return; + } + emitStart(node); for (var i = 0; i < decorators.length; i++) { var decorator = decorators[i]; emitStart(decorator); emitNode(node.name); write(" = "); - emit(decorators[i].expression); + emitExpressionOfDecorator(decorator); write("("); emitEnd(decorator); if (i < decorators.length - 1) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index cbc4f3ac3ce18..c03b9a232616d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1145,6 +1145,10 @@ module ts { // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getResolvedSignature(node: CallLikeExpression): Signature; + serializeTypeOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration | PropertyDeclaration | ParameterDeclaration): string; + serializeParameterTypesOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration): string[]; + serializeReturnTypeOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration): string; } export const enum SymbolFlags { @@ -1258,17 +1262,20 @@ module ts { } export const enum NodeCheckFlags { - TypeChecked = 0x00000001, // Node has been type checked - LexicalThis = 0x00000002, // Lexical 'this' reference - CaptureThis = 0x00000004, // Lexical 'this' used in body - EmitExtends = 0x00000008, // Emit __extends - SuperInstance = 0x00000010, // Instance 'super' reference - SuperStatic = 0x00000020, // Static 'super' reference - ContextChecked = 0x00000040, // Contextual types have been assigned + TypeChecked = 0x00000001, // Node has been type checked + LexicalThis = 0x00000002, // Lexical 'this' reference + CaptureThis = 0x00000004, // Lexical 'this' used in body + EmitExtends = 0x00000008, // Emit __extends + SuperInstance = 0x00000010, // Instance 'super' reference + SuperStatic = 0x00000020, // Static 'super' reference + ContextChecked = 0x00000040, // Contextual types have been assigned // Values for enum members have been computed, and any errors have been reported for them. - EnumValuesComputed = 0x00000080, - EmitDecorate = 0x00000100, + EnumValuesComputed = 0x00000080, + EmitDecorate = 0x00000100, // Emit __extends + EmitDecoratedType = 0x00000200, // Emit the type of the decorator target as an argument in this parameter position + EmitDecoratedParamTypes = 0x00000400, // Emit the parameter types of the decorator target as an argument in this parameter position + EmitDecoratedReturnType = 0x00000800, // Emit the return type of the decorator target as an argument in this parameter position } export interface NodeLinks { @@ -1325,6 +1332,7 @@ module ts { // Intrinsic types (TypeFlags.Intrinsic) export interface IntrinsicType extends Type { intrinsicName: string; // Name of intrinsic type + boxedName: string; // Name of boxed constructor } // String literal types (TypeFlags.StringLiteral) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f95952dc5c53d..050533c8ac526 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -483,6 +483,17 @@ module ts { return (node).expression; } + function getConstructorWithBody(member: ClassElement): ConstructorDeclaration { + if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { + return member; + } + return undefined; + } + + export function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { + return forEach(node.members, getConstructorWithBody); + } + export function isExpression(node: Node): boolean { switch (node.kind) { case SyntaxKind.ThisKeyword: From 8c3c759883c37479b96aea6161f08cca8c1f381a Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Feb 2015 16:43:33 -0800 Subject: [PATCH 12/33] Additional type check for decorators, added @decorator --- src/compiler/checker.ts | 520 +++++++++++++++--- .../diagnosticInformationMap.generated.ts | 5 +- src/compiler/diagnosticMessages.json | 14 +- src/compiler/emitter.ts | 111 ++-- src/compiler/types.ts | 52 +- src/lib/core.d.ts | 25 +- 6 files changed, 578 insertions(+), 149 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 85903ec5dcee0..95386a768544d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5,6 +5,11 @@ module ts { var nextNodeId = 1; var nextMergeId = 1; + const enum EvalConstantFlags { + Numeric = 0x1, + ConstEnum = 0x2, + } + /* @internal */ export var checkTime = 0; export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker { @@ -16,6 +21,7 @@ module ts { var emptyArray: any[] = []; var emptySymbols: SymbolTable = {}; + var emptyMetadata = {}; var compilerOptions = host.getCompilerOptions(); var languageVersion = compilerOptions.target || ScriptTarget.ES3; @@ -84,6 +90,7 @@ module ts { var globals: SymbolTable = {}; var globalArraySymbol: Symbol; + var globalDecoratorSymbol: Symbol; var globalTypeDecoratorSymbol: Symbol; var globalParamTypesDecoratorSymbol: Symbol; var globalReturnTypeDecoratorSymbol: Symbol; @@ -101,6 +108,7 @@ module ts { var globalDecoratorFunctionType: ObjectType; var globalParameterDecoratorFunctionType: ObjectType; var globalMemberDecoratorFunctionType: ObjectType; + var resolvingMetadata = {}; var anyArrayType: Type; @@ -8083,52 +8091,297 @@ module ts { forEach(node.decorators, checkDecorator); } - function checkDecorator(node: Decorator): void { - var expression: Expression = node.expression; - var type = checkExpression(expression); + function getIdentifierOfDecoratorExpression(expression: Expression): Identifier { + // unwrap a parenthesized expression + while (expression.kind === SyntaxKind.ParenthesizedExpression) { + expression = (expression).expression; + } + + // if this is a decorator factory, get the expression of the CallExpression + if (expression.kind === SyntaxKind.CallExpression) { + expression = (expression).expression; + } + + // unwrap an remaining parenthesized expression + while (expression.kind === SyntaxKind.ParenthesizedExpression) { + expression = (expression).expression; + } + + // if this is a property access, return the name + if (expression.kind === SyntaxKind.PropertyAccessExpression) { + return (expression).name; + } + + // if the expression is an identifier, return it + if (expression.kind === SyntaxKind.Identifier) { + return expression; + } + + return undefined; + } + + function getArgumentsOfDecoratorExpression(expression: Expression): Expression[] { + // unwrap a parenthesized expression + while (expression.kind === SyntaxKind.ParenthesizedExpression) { + expression = (expression).expression; + } + + // if this is a decorator factory, get the expression of the CallExpression + if (expression.kind === SyntaxKind.CallExpression) { + return (expression).arguments; + } + + return undefined; + } + + function evalDecoratorArguments(node: Decorator, argumentList: Expression[]): any[]{ + var result: any[]; + if (argumentList) { + var argumentCount = argumentList.length; + for (var i = 0; i < argumentCount; i++) { + var value = evalConstant(argumentList[i], /*isNumeric*/ false, /*isConst*/ true); + if (value === undefined) { + error(node, Diagnostics.Argument_to_ambient_decorator_must_be_constant_expression); + return undefined; + } + if (!result) { + result = new Array(argumentCount); + } + result[i] = value; + } + } + return result; + } + + function reportInvalidDecoratorExpression(node: Decorator, exprType: Type): void { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + checkTypeAssignableTo(exprType, globalDecoratorFunctionType, node); + return; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + checkTypeAssignableTo(exprType, globalMemberDecoratorFunctionType, node); + return; + + case SyntaxKind.Parameter: + checkTypeAssignableTo(exprType, globalParameterDecoratorFunctionType, node); + return; + } + } + + function decoratorIsAmbient(symbol: Symbol) { + if (!symbol) { + return false; + } + if (symbol === globalDecoratorSymbol + || symbol === globalTypeDecoratorSymbol + || symbol === globalParamTypesDecoratorSymbol + || symbol === globalReturnTypeDecoratorSymbol) { + return true; + } + var metadataArray = getMetadataForSymbol(symbol); + var metadata = findMetadata(metadataArray, globalDecoratorSymbol); + if (metadata && metadata.arguments.length > 0) { + var usage = metadata.arguments[0]; + return usage.ambient; + } + return false; + } - // check built-in decorators + function findMetadata(metadataArray: DecoratorMetadata[], decoratorSymbol: Symbol): DecoratorMetadata { + if (metadataArray) { + for (var i = 0; i < metadataArray.length; i++) { + var metadata = metadataArray[i]; + if (metadata.symbol === globalDecoratorSymbol) { + return metadata; + } + } + } + return undefined; + } - // unwrap the identifier for the decorator (if present) - var decorator = expression; - while (decorator.kind === SyntaxKind.ParenthesizedExpression) { - decorator = (decorator).expression; + function resolveMetadataForDecorator(decorator: Decorator): DecoratorMetadata { + var name = getIdentifierOfDecoratorExpression(decorator.expression); + if (name) { + var symbol = getResolvedSymbol(name); + if (decoratorIsAmbient(symbol)) { + var arguments = getArgumentsOfDecoratorExpression(decorator.expression); + var argumentList = evalDecoratorArguments(decorator, arguments); + if (argumentList) { + var metadata: DecoratorMetadata = { + symbol, + arguments: argumentList + }; + return metadata; + } + } } - if (decorator.kind === SyntaxKind.CallExpression) { - decorator = (decorator).expression; + return emptyMetadata; + } + + function getMetadataForDecorator(node: Decorator): DecoratorMetadata { + var links = getNodeLinks(node); + if (!links.resolvedDecoratorMetadata) { + links.resolvedDecoratorMetadata = resolvingMetadata; + var metadata = resolveMetadataForDecorator(node); + if (links.resolvedDecoratorMetadata === resolvingMetadata) { + links.resolvedDecoratorMetadata = metadata; + } } - while (decorator.kind === SyntaxKind.ParenthesizedExpression) { - decorator = (decorator).expression; + else if (links.resolvedDecoratorMetadata === resolvingMetadata) { + // TODO: report an error? + links.resolvedDecoratorMetadata = emptyMetadata; } + return links.resolvedDecoratorMetadata; + } - // if the identifier points to one of the built-in symbols, add relevant information for later emit. - if (decorator.kind === SyntaxKind.Identifier) { - var symbol = getResolvedSymbol(decorator); - if (symbol === globalTypeDecoratorSymbol - || symbol === globalParamTypesDecoratorSymbol - || symbol === globalReturnTypeDecoratorSymbol) { - - // these are only valid on a parameter - if (node.parent.kind !== SyntaxKind.Parameter) { - error(decorator, Diagnostics.Decorator_0_is_not_valid_on_this_declaration_type_It_is_only_valid_on_1_declarations, symbol.name, "parameter"); + function resolveMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]{ + if (symbol.valueDeclaration) { + var decorators = symbol.valueDeclaration.decorators; + if (decorators) { + var metadataArray: DecoratorMetadata[]; + for (var i = 0; i < decorators.length; i++) { + var metadata = getMetadataForDecorator(decorators[i]); + if (metadata !== emptyMetadata) { + if (!metadataArray) { + metadataArray = []; + } + metadataArray.push(metadata); + } + } + if (metadataArray) { + return metadataArray; } + } + } + return emptyArray; + } - // TODO(rbuckton): check assignability to the parameter - // TODO(rbuckton): check decorator is only applied to value declaration + function getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[] { + var links = getSymbolLinks(symbol); + if (!links.decoratorMetadata) { + links.decoratorMetadata = resolveMetadataForSymbol(symbol); + } + return links.decoratorMetadata; + } - if (symbol === globalTypeDecoratorSymbol) { - getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedType; + function getValidDecoratorTarget(node: Node): DecoratorFlags { + if (node) { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: return DecoratorFlags.ClassDeclaration; + case SyntaxKind.InterfaceDeclaration: return DecoratorFlags.InterfaceDeclaration; + case SyntaxKind.TypeAliasDeclaration: return DecoratorFlags.TypeAliasDeclaration; + case SyntaxKind.EnumDeclaration: return DecoratorFlags.EnumDeclaration; + case SyntaxKind.EnumMember: return DecoratorFlags.EnumMember; + case SyntaxKind.ModuleDeclaration: return DecoratorFlags.ModuleDeclaration; + case SyntaxKind.ImportDeclaration: return DecoratorFlags.ImportDeclaration; + case SyntaxKind.VariableDeclaration: return DecoratorFlags.VariableDeclaration; + case SyntaxKind.FunctionDeclaration: return DecoratorFlags.FunctionDeclaration; + case SyntaxKind.PropertyDeclaration: return DecoratorFlags.PropertyDeclaration; + case SyntaxKind.MethodDeclaration: return DecoratorFlags.MethodDeclaration; + case SyntaxKind.GetAccessor: return DecoratorFlags.AccessorDeclaration; + case SyntaxKind.SetAccessor: return DecoratorFlags.AccessorDeclaration; + case SyntaxKind.Parameter: return DecoratorFlags.ParameterDeclaration; + } + } + return undefined; + } + + function getDecoratorFlagsForDecorator(node: Decorator, symbol: Symbol, exprType: Type) { + var flags: DecoratorFlags; + if (symbol === globalDecoratorSymbol) { + flags |= DecoratorFlags.BuiltIn | DecoratorFlags.FunctionDeclaration; + } + else if (symbol === globalTypeDecoratorSymbol + || symbol === globalParamTypesDecoratorSymbol + || symbol === globalReturnTypeDecoratorSymbol) { + flags |= DecoratorFlags.BuiltIn | DecoratorFlags.ParameterDeclaration; + } + else { + if (symbol && decoratorIsAmbient(symbol)) { + flags |= DecoratorFlags.UserDefinedAmbient | DecoratorFlags.AllTargets; + } + else { + var widenedType = getWidenedType(exprType); + if (isTypeAssignableTo(globalDecoratorFunctionType, widenedType) || isTypeAssignableTo(exprType, globalDecoratorFunctionType)) { + flags |= DecoratorFlags.ClassDeclaration; } - else if (symbol === globalParamTypesDecoratorSymbol) { - getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedParamTypes; + if (isTypeAssignableTo(globalMemberDecoratorFunctionType, widenedType) || isTypeAssignableTo(exprType, globalMemberDecoratorFunctionType)) { + flags |= DecoratorFlags.MethodDeclaration | DecoratorFlags.PropertyDeclaration | DecoratorFlags.AccessorDeclaration; } - else if (symbol === globalReturnTypeDecoratorSymbol) { - getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedReturnType; + if (isTypeAssignableTo(globalParameterDecoratorFunctionType, widenedType) || isTypeAssignableTo(exprType, globalParameterDecoratorFunctionType)) { + flags |= DecoratorFlags.ParameterDeclaration; } } } + return flags; + } + + function checkDecorator(node: Decorator): void { + var expression: Expression = node.expression; + var exprType = checkExpression(expression); + var name = getIdentifierOfDecoratorExpression(expression); + var symbol = name && getResolvedSymbol(name); + + // determine what targets the decorator can be applied to + var flags = getDecoratorFlagsForDecorator(node, symbol, exprType); + if (!flags) { + // report error if the type of the expression is not one of the valid decorator function types + reportInvalidDecoratorExpression(node, exprType); + return; + } + + // report error for invalid usage + var validFlags = getValidDecoratorTarget(node.parent); + if ((flags & validFlags) === 0) { + if (name) { + error(name, Diagnostics.Decorator_0_is_not_valid_on_this_declaration_type, symbol.name); + } + else { + error(expression, Diagnostics.Decorator_is_not_valid_on_this_declaration_type); + } + return; + } - // TODO(rbuckton): check the type of the expression + var metadata: DecoratorMetadata; + if (flags & DecoratorFlags.Ambient) { + getNodeLinks(node).flags |= NodeCheckFlags.AmbientDecorator; + metadata = getMetadataForDecorator(node); + if (!metadata) { + return; + } + } + else { + // report error for non-ambient decorator on member in ES3 + if (languageVersion < ScriptTarget.ES5 && (validFlags & DecoratorFlags.ES3TargetsExclude)) { + error(node, Diagnostics.Non_ambient_decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher); + return; + } + } + + // handle built-in decorators + switch (symbol) { + case globalDecoratorSymbol: + if (metadata && metadata.arguments.length > 0) { + var usage = metadata.arguments[0]; + if (usage.ambient) { + getNodeLinks(node.parent).flags |= NodeCheckFlags.AmbientDecorator; + } + } + break; + case globalTypeDecoratorSymbol: + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedType; + break; + case globalParamTypesDecoratorSymbol: + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedParamTypes; + break; + case globalReturnTypeDecoratorSymbol: + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedReturnType; + break; + } } function checkFunctionDeclaration(node: FunctionDeclaration): void { @@ -9154,7 +9407,7 @@ module ts { // If it is a constant value (not undefined), it is syntactically constrained to be a number. // Also, we do not need to check this for ambients because there is already // a syntax error if it is not a constant. - checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); + checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); } } else if (enumIsConst) { @@ -9180,60 +9433,70 @@ module ts { } function getConstantValueForEnumMemberInitializer(initializer: Expression, enumIsConst: boolean): number { - return evalConstant(initializer); + return evalConstant(initializer, /*isNumeric*/ true, /*isConst*/ enumIsConst); + } + } + + function evalConstant(expression: Expression, isNumeric: boolean, isConst: boolean): any { + return evalConstantWorker(expression); - function evalConstant(e: Node): number { - switch (e.kind) { - case SyntaxKind.PrefixUnaryExpression: - var value = evalConstant((e).operand); - if (value === undefined) { - return undefined; - } - switch ((e).operator) { - case SyntaxKind.PlusToken: return value; - case SyntaxKind.MinusToken: return -value; - case SyntaxKind.TildeToken: return enumIsConst ? ~value : undefined; - } + function evalConstantWorker(e: Node): any { + switch (e.kind) { + case SyntaxKind.PrefixUnaryExpression: + var value = evalConstantWorker((e).operand); + if (value === undefined) { return undefined; - case SyntaxKind.BinaryExpression: - if (!enumIsConst) { - return undefined; - } - - var left = evalConstant((e).left); - if (left === undefined) { - return undefined; - } - var right = evalConstant((e).right); - if (right === undefined) { - return undefined; - } - switch ((e).operator) { - case SyntaxKind.BarToken: return left | right; - case SyntaxKind.AmpersandToken: return left & right; - case SyntaxKind.GreaterThanGreaterThanToken: return left >> right; - case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: return left >>> right; - case SyntaxKind.LessThanLessThanToken: return left << right; - case SyntaxKind.CaretToken: return left ^ right; - case SyntaxKind.AsteriskToken: return left * right; - case SyntaxKind.SlashToken: return left / right; - case SyntaxKind.PlusToken: return left + right; - case SyntaxKind.MinusToken: return left - right; - case SyntaxKind.PercentToken: return left % right; - } + } + switch ((e).operator) { + case SyntaxKind.PlusToken: return value; + case SyntaxKind.MinusToken: return -value; + case SyntaxKind.TildeToken: return isConst ? ~value : undefined; + case SyntaxKind.ExclamationToken: return isNumeric ? undefined : !value; + } + return undefined; + case SyntaxKind.BinaryExpression: + var left = evalConstantWorker((e).left); + if (left === undefined) { return undefined; - case SyntaxKind.NumericLiteral: - return +(e).text; - case SyntaxKind.ParenthesizedExpression: - return enumIsConst ? evalConstant((e).expression) : undefined; + } + var right = evalConstantWorker((e).right); + if (right === undefined) { + return undefined; + } + switch ((e).operator) { + case SyntaxKind.BarToken: return left | right; + case SyntaxKind.AmpersandToken: return left & right; + case SyntaxKind.GreaterThanGreaterThanToken: return left >> right; + case SyntaxKind.GreaterThanGreaterThanGreaterThanToken: return left >>> right; + case SyntaxKind.LessThanLessThanToken: return left << right; + case SyntaxKind.CaretToken: return left ^ right; + case SyntaxKind.AsteriskToken: return left * right; + case SyntaxKind.SlashToken: return left / right; + case SyntaxKind.PlusToken: return left + right; + case SyntaxKind.MinusToken: return left - right; + case SyntaxKind.PercentToken: return left % right; + case SyntaxKind.BarBarToken: return isNumeric ? undefined : left || right; + case SyntaxKind.AmpersandAmpersandToken: return isNumeric ? undefined : left && right; + } + break; + case SyntaxKind.NumericLiteral: + return +(e).text; + case SyntaxKind.ParenthesizedExpression: + return evalConstantWorker((e).expression); + case SyntaxKind.StringLiteral: + return isNumeric ? undefined : (e).text; + } + + if (isNumeric) { + switch (e.kind) { case SyntaxKind.Identifier: case SyntaxKind.ElementAccessExpression: case SyntaxKind.PropertyAccessExpression: - if (!enumIsConst) { + if (!isConst) { return undefined; } - var member = initializer.parent; + var member = expression.parent; var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); var enumType: Type; var propertyName: string; @@ -9282,6 +9545,108 @@ module ts { return getNodeLinks(propertyDecl).enumMemberValue; } } + else { + switch (e.kind) { + case SyntaxKind.PrefixUnaryExpression: + switch ((e).operator) { + case SyntaxKind.ExclamationToken: return !value; + } + break; + case SyntaxKind.BinaryExpression: + switch ((e).operator) { + case SyntaxKind.BarBarToken: return left || right; + case SyntaxKind.AmpersandAmpersandToken: return left && right; + } + break; + case SyntaxKind.StringLiteral: + return (e).text; + case SyntaxKind.TrueKeyword: + return true; + case SyntaxKind.FalseKeyword: + return false; + case SyntaxKind.ArrayLiteralExpression: + return evalArrayLiteralConstant(e); + case SyntaxKind.ObjectLiteralExpression: + return evalObjectLiteralConstant(e); + case SyntaxKind.PropertyAccessExpression: + var member = expression.parent; + var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); + var enumType = getTypeOfNode((e).expression); + var propertyName = (e).name.text; + if (!isConstEnumObjectType(enumType)) { + return undefined; + } + var property = getPropertyOfObjectType(enumType, propertyName); + if (!property || !(property.flags & SymbolFlags.EnumMember)) { + return undefined; + } + var propertyDecl = property.valueDeclaration; + return getNodeLinks(propertyDecl).enumMemberValue; + } + } + + return undefined; + } + + function evalArrayLiteralConstant(node: ArrayLiteralExpression): any { + var result: any[]; + var elements = node.elements; + var elementCount = elements.length; + for (var i = 0; i < elementCount; i++) { + var value = evalConstantWorker(elements[i]); + if (value === undefined) { + return undefined; + } + if (!result) { + result = new Array(elementCount); + } + result[i] = value; + } + return result; + } + + function evalObjectLiteralConstant(node: ObjectLiteralExpression): any { + var result: Map; + var properties = node.properties; + var propertyCount = properties.length; + for (var i = 0; i < propertyCount; i++) { + var property = properties[i]; + if (property.kind !== SyntaxKind.PropertyAssignment) { + return undefined; + } + + var key: string; + var name = (property).name; + switch (name.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + key = (name).text; + break; + case SyntaxKind.ComputedPropertyName: + var expression = (name).expression; + switch (expression.kind) { + case SyntaxKind.Identifier: + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + key = (name).text; + break; + default: + return undefined; + } + break; + default: + return undefined; + } + + var initializer = (property).initializer; + var value = evalConstantWorker(initializer); + if (!result) { + result = {}; + } + result[key] = value; + } + return result; } } @@ -10492,6 +10857,7 @@ module ts { globalDecoratorFunctionType = getGlobalType("DecoratorFunction"); globalParameterDecoratorFunctionType = getGlobalType("ParameterDecoratorFunction"); globalMemberDecoratorFunctionType = getGlobalType("MemberDecoratorFunction"); + globalDecoratorSymbol = getGlobalDecoratorSymbol("decorator"); globalTypeDecoratorSymbol = getGlobalDecoratorSymbol("type"); globalParamTypesDecoratorSymbol = getGlobalDecoratorSymbol("paramtypes"); globalReturnTypeDecoratorSymbol = getGlobalDecoratorSymbol("returntype"); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5a6f4a98f6aa8..4d63ea1097531 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -148,8 +148,11 @@ module ts { A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, Decorators_cannot_appear_here: { code: 1188, category: DiagnosticCategory.Error, key: "Decorators cannot appear here." }, - Decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher: { code: 1189, category: DiagnosticCategory.Error, key: "Decorators are only supported on class members when targeting ECMAScript 5 or higher." }, + Non_ambient_decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher: { code: 1189, category: DiagnosticCategory.Error, key: "Non-ambient decorators are only supported on class members when targeting ECMAScript 5 or higher." }, Decorator_0_is_not_valid_on_this_declaration_type_It_is_only_valid_on_1_declarations: { code: 1190, category: DiagnosticCategory.Error, key: "Decorator '{0}' is not valid on this declaration type. It is only valid on '{1}' declarations." }, + Decorator_0_is_not_valid_on_this_declaration_type: { code: 1191, category: DiagnosticCategory.Error, key: "Decorator '{0}' is not valid on this declaration type." }, + Decorator_is_not_valid_on_this_declaration_type: { code: 1192, category: DiagnosticCategory.Error, key: "Decorator is not valid on this declaration type." }, + Argument_to_ambient_decorator_must_be_constant_expression: { code: 1193, category: DiagnosticCategory.Error, key: "Argument to ambient decorator must be constant expression." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index bdebcb691df1b..ad26e31e18c51 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -583,7 +583,7 @@ "category": "Error", "code": 1188 }, - "Decorators are only supported on class members when targeting ECMAScript 5 or higher.": { + "Non-ambient decorators are only supported on class members when targeting ECMAScript 5 or higher.": { "category": "Error", "code": 1189 }, @@ -591,6 +591,18 @@ "category": "Error", "code": 1190 }, + "Decorator '{0}' is not valid on this declaration type.": { + "category": "Error", + "code": 1191 + }, + "Decorator is not valid on this declaration type.": { + "category": "Error", + "code": 1192 + }, + "Argument to ambient decorator must be constant expression.": { + "category": "Error", + "code": 1193 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5900abcd8c9ef..517ec270f97a1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2667,7 +2667,7 @@ module ts { write(")"); } - function emitCallExpression(node: CallExpression, emitArguments: (args: Expression[], node: CallExpression) => void = emitCommaList) { + function emitCallExpression(node: CallExpression) { if (languageVersion < ScriptTarget.ES6 && hasSpreadElement(node.arguments)) { emitCallWithSpread(node); return; @@ -2686,13 +2686,13 @@ module ts { emitThis(node.expression); if (node.arguments.length) { write(", "); - emitArguments(node.arguments, node); + emitCommaList(node.arguments); } write(")"); } else { write("("); - emitArguments(node.arguments, node); + emitCommaList(node.arguments); write(")"); } } @@ -3955,43 +3955,38 @@ module ts { return false; } - function emitSerializedType(node: ClassDeclaration | PropertyDeclaration | FunctionLikeDeclaration | ParameterDeclaration) { - var serializedType = resolver.serializeTypeOfDeclaration(node); - write(serializedType); + function createSerializedTypeExpression(type: string): Expression { + if (!type || type === "void 0") { + return createVoidZero(); + } + var serializedType = createNode(SyntaxKind.Identifier); + serializedType.text = type; + return serializedType; } - function emitSerializedParameterTypes(node: ClassDeclaration | FunctionLikeDeclaration) { - var serializedTypes = resolver.serializeParameterTypesOfDeclaration(node); - write("["); - for (var i = 0; i < serializedTypes.length; i++) { - if (i > 0) { - write(", "); - } - write(serializedTypes[i]); + function createSerializedTypeArrayExpression(types: string[]): ArrayLiteralExpression { + var array = createNode(SyntaxKind.ArrayLiteralExpression); + var elements = >[]; + for (var i = 0; i < types.length; i++) { + elements[i] = createSerializedTypeExpression(types[i]); } - write("]"); + array.elements = elements; + return array; } - function emitSerializedReturnType(node: ClassDeclaration | FunctionLikeDeclaration) { - var serializedType = resolver.serializeReturnTypeOfDeclaration(node); - write(serializedType); - } - - function emitArgumentsOfDecoratorFactory(args: Expression[], node: CallExpression) { - emitCommaList(args); - + function rewriteDecoratorFactory(node: CallExpression): CallExpression { var decorator = node.parent; if (!isDeclaration(decorator.parent)) { - return; - } - + return node; + } var decorated = decorator.parent; var signature = resolver.getResolvedSignature(node); var declaration = signature.declaration; if (!declaration) { - return; + return node; } - + var newArgumentList: Expression[]; + var args = node.arguments; var argCount = args ? args.length : 0; var parameters = declaration.parameters; var parameterCount = signature.hasRestParameter ? parameters.length - 1 : parameters.length; @@ -4004,45 +3999,56 @@ module ts { ? shouldEmitSerializedTypeForNode : shouldEmitSerializedParameterTypesOrReturnTypeForNode; if (shouldEmitCompilerGeneratedArgument(decorated)) { + if (!newArgumentList) { + newArgumentList = args.slice(0); + } while (lastArg < i) { - if (i > 0) { - write(", "); - } - write("void 0"); + newArgumentList.push(createVoidZero()); lastArg++; } - if (i > 0) { - write(", "); - } - if (flags & NodeCheckFlags.EmitDecoratedType) { - emitSerializedType(decorated); + if (flags & NodeCheckFlags.EmitDecoratedType) { + var serializedType = resolver.serializeTypeOfDeclaration(decorated); + newArgumentList.push(createSerializedTypeExpression(serializedType)); } else if (flags & NodeCheckFlags.EmitDecoratedParamTypes) { - emitSerializedParameterTypes(decorated); + var serializedTypes = resolver.serializeParameterTypesOfDeclaration(decorated); + newArgumentList.push(createSerializedTypeArrayExpression(serializedTypes)); } else if (flags & NodeCheckFlags.EmitDecoratedReturnType) { - emitSerializedReturnType(decorated); + var serializedType = resolver.serializeReturnTypeOfDeclaration(decorated); + newArgumentList.push(createSerializedTypeExpression(serializedType)); } lastArg++; } } } + if (newArgumentList) { + var updated = createNode(SyntaxKind.CallExpression); + updated.expression = node.expression; + updated.arguments = >newArgumentList; + updated.pos = node.pos; + updated.end = node.end; + updated.flags = node.flags; + return updated; + } + return node; } function emitExpressionOfDecorator(node: Decorator) { var expression = node.expression; if (expression.kind === SyntaxKind.CallExpression) { - var callExpr = expression; - emitCallExpression(callExpr, emitArgumentsOfDecoratorFactory); - } - else { - emit(expression); + expression = rewriteDecoratorFactory(expression); } + emit(expression); + } + + function isNonAmbientDecorator(node: Decorator): boolean { + return (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AmbientDecorator) === 0; } function emitDecoratorsOfParameter(node: FunctionLikeDeclaration, parameter: ParameterDeclaration, parameterIndex: number, info: DecoratorEmitInfo) { - var decorators = parameter.decorators; - if (!decorators) { + var decorators = filter(parameter.decorators, isNonAmbientDecorator); + if (!decorators || decorators.length === 0) { return; } @@ -4119,7 +4125,8 @@ module ts { var name = member.name; var decorators = getDecoratorsOfMember(node, member); - if (!decorators) { + decorators = filter(decorators, isNonAmbientDecorator); + if (!decorators || decorators.length === 0) { return; } @@ -4161,8 +4168,8 @@ module ts { emitDecoratorsOfParameters(constructor, info); } - var decorators = node.decorators; - if (!node.decorators) { + var decorators = filter(node.decorators, isNonAmbientDecorator); + if (!decorators || decorators.length === 0) { return; } @@ -4928,11 +4935,11 @@ module ts { } function emitFile(jsFilePath: string, sourceFile?: SourceFile) { - emitJavaScript(jsFilePath, sourceFile); + emitJavaScript(jsFilePath, sourceFile); if (compilerOptions.declaration) { - writeDeclarationFile(jsFilePath, sourceFile); - } + writeDeclarationFile(jsFilePath, sourceFile); } + } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2404dca0ff40e..423d877e7b56f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1250,13 +1250,14 @@ module ts { } export interface SymbolLinks { - target?: Symbol; // Resolved (non-alias) target of an alias - type?: Type; // Type of value symbol - declaredType?: Type; // Type of class, interface, enum, or type parameter - mapper?: TypeMapper; // Type mapper for instantiation alias - referenced?: boolean; // True if alias symbol has been referenced as a value - exportAssignSymbol?: Symbol; // Symbol exported from external module - unionType?: UnionType; // Containing union type for union property + target?: Symbol; // Resolved (non-alias) target of an alias + type?: Type; // Type of value symbol + declaredType?: Type; // Type of class, interface, enum, or type parameter + mapper?: TypeMapper; // Type mapper for instantiation alias + referenced?: boolean; // True if alias symbol has been referenced as a value + exportAssignSymbol?: Symbol; // Symbol exported from external module + unionType?: UnionType; // Containing union type for union property + decoratorMetadata?: DecoratorMetadata[]; // Resolved ambient decorator metadata } export interface TransientSymbol extends Symbol, SymbolLinks { } @@ -1280,12 +1281,14 @@ module ts { EmitDecoratedType = 0x00000200, // Emit the type of the decorator target as an argument in this parameter position EmitDecoratedParamTypes = 0x00000400, // Emit the parameter types of the decorator target as an argument in this parameter position EmitDecoratedReturnType = 0x00000800, // Emit the return type of the decorator target as an argument in this parameter position + AmbientDecorator = 0x00001000, // Decorator was marked ambient, do not emit to output } export interface NodeLinks { resolvedType?: Type; // Cached type of type node resolvedSignature?: Signature; // Cached signature of signature node or call expression resolvedSymbol?: Symbol; // Cached name resolution result + resolvedDecoratorMetadata?: DecoratorMetadata; // Resolved metadata for a decorator flags?: NodeCheckFlags; // Set of flags specific to Node enumMemberValue?: number; // Constant value of enum member isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list @@ -1439,6 +1442,41 @@ module ts { // It is optional because in contextual signature instantiation, nothing fails } + export interface DecoratorUsage { + ambient: boolean; + } + + // DecoratorMetadata consists of the state information about an ambient decorator + export interface DecoratorMetadata { + symbol: Symbol; // The symbol of the ambient decorator + arguments: any[]; // The arguments to the ambient decorator + } + + export const enum DecoratorFlags { + BuiltIn = 0x00000001, // built-in ambient decorator + UserDefinedAmbient = 0x00000002, // user-provided ambient decorator + ClassDeclaration = 0x00000004, // decorator can target a class declaration + InterfaceDeclaration = 0x00000008, // decorator can target an interface declaration + TypeAliasDeclaration = 0x00000010, // decorator can target a type alias + EnumDeclaration = 0x00000020, // decorator can target an enum declaration + EnumMember = 0x00000040, // decorator can target an enum member + ModuleDeclaration = 0x00000080, // decorator can target a lexical module declaration + ImportDeclaration = 0x00000100, // decorator can target an import declaration + VariableDeclaration = 0x00000200, // decorator can target a variable declaration (var, let, or const) + FunctionDeclaration = 0x00000400, // decorator can target a function declaration + PropertyDeclaration = 0x00000800, // decorator can target a property declaration + MethodDeclaration = 0x00001000, // decorator can target a method declaration + AccessorDeclaration = 0x00002000, // decorator can target an accessor declaration + ParameterDeclaration = 0x00004000, // decorator can target a parameter declaration + + Ambient = BuiltIn | UserDefinedAmbient, + AllTargets = ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration + | EnumDeclaration | EnumMember | ModuleDeclaration | ImportDeclaration + | VariableDeclaration | FunctionDeclaration | PropertyDeclaration + | MethodDeclaration | AccessorDeclaration | ParameterDeclaration, + ES3TargetsExclude = PropertyDeclaration | MethodDeclaration | AccessorDeclaration + } + export interface DiagnosticMessage { key: string; category: DiagnosticCategory; diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 28b7eec601d1a..35d4be41c07a0 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1159,32 +1159,35 @@ interface TypedPropertyDescriptor { set?: (value: T) => void; } -declare const enum DecoratorTargets { - class = 0x1, - interface = 0x2, - function = 0x3, - method = 0x4, - accessor = 0x5, - property = 0x6, - parameter = 0x7, - all = DecoratorTargets.class | DecoratorTargets.interface | DecoratorTargets.function | DecoratorTargets.method | DecoratorTargets.accessor | DecoratorTargets.property | DecoratorTargets.parameter -} - interface DecoratorFunction { (target: TFunction): TFunction | void; } interface ParameterDecoratorFunction { (target: Function, parameterIndex: number): void; } interface MemberDecoratorFunction { (target: Function | Object, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void; } +/** + * Built-in decorator. Sets options for a function used as a decorator + */ +@decorator({ ambient: true }) +declare function decorator(options?: { + /** + * A value indicating whether the decorator is ambient (true) and should not be emitted to output. + */ + ambient?: boolean; +}): void; + /** * Built-in decorator. Emits the serialized type of the target in the argument position of the decorated parameter. */ +@decorator({ ambient: true }) declare function type(): void; /** * Built-in decorator. Emits the serialized types of the parameters of the target in the argument position of the decorated parameter. */ +@decorator({ ambient: true }) declare function paramtypes(): void; /** * Built-in decorator. Emits the serialized return type of the target in the argument position of the decorated parameter. */ +@decorator({ ambient: true }) declare function returntype(): void; From 86dbd504d248360472c6b08fe3495ba725f3985f Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Feb 2015 17:50:10 -0800 Subject: [PATCH 13/33] initial pass for @conditional --- src/compiler/checker.ts | 48 +++++++++++++++++++++++++++++-- src/compiler/commandLineParser.ts | 44 +++++++++++++++++++++++++--- src/compiler/emitter.ts | 23 +++++++++++++++ src/compiler/types.ts | 6 +++- src/lib/core.d.ts | 32 +++++++++++++++++++++ 5 files changed, 145 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 95386a768544d..59aa967de819b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -87,6 +87,7 @@ module ts { var anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false); var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); + var conditionalSymbols: Map; var globals: SymbolTable = {}; var globalArraySymbol: Symbol; @@ -94,6 +95,8 @@ module ts { var globalTypeDecoratorSymbol: Symbol; var globalParamTypesDecoratorSymbol: Symbol; var globalReturnTypeDecoratorSymbol: Symbol; + var globalObsoleteDecoratorSymbol: Symbol; + var globalConditionalDecoratorSymbol: Symbol; var globalObjectType: ObjectType; var globalFunctionType: ObjectType; @@ -6533,6 +6536,34 @@ module ts { return links.resolvedSignature; } + function isConditionalSymbolDefined(condition: string) { + if (!conditionalSymbols) { + conditionalSymbols = {}; + if (compilerOptions.defines) { + for (var i = 0; i < compilerOptions.defines.length; i++) { + conditionalSymbols[compilerOptions.defines[i].toUpperCase()] = true; + } + } + } + + return hasProperty(conditionalSymbols, condition.toUpperCase()); + } + + function isConditionallyRemoved(signature: Signature) { + if (signature.declaration) { + var symbol = signature.declaration.symbol; + var metadataArray = getMetadataForSymbol(symbol); + var metadata = findMetadata(metadataArray, globalConditionalDecoratorSymbol); + if (metadata && metadata.arguments.length > 0) { + var conditionSymbol = metadata.arguments[0]; + if (conditionSymbol && !isConditionalSymbolDefined(conditionSymbol)) { + return true; + } + } + } + return false; + } + function checkCallExpression(node: CallExpression): Type { // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); @@ -6555,6 +6586,9 @@ module ts { return anyType; } } + if (isConditionallyRemoved(signature)) { + getNodeLinks(node).flags |= NodeCheckFlags.ConditionallyRemoved; + } return getReturnTypeOfSignature(signature); } @@ -6564,7 +6598,12 @@ module ts { grammarErrorOnFirstToken(node.template, Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher); } - return getReturnTypeOfSignature(getResolvedSignature(node)); + var signature = getResolvedSignature(node); + if (isConditionallyRemoved(signature)) { + getNodeLinks(node).flags |= NodeCheckFlags.ConditionallyRemoved; + } + + return getReturnTypeOfSignature(signature); } function checkTypeAssertion(node: TypeAssertion): Type { @@ -8195,7 +8234,7 @@ module ts { if (metadataArray) { for (var i = 0; i < metadataArray.length; i++) { var metadata = metadataArray[i]; - if (metadata.symbol === globalDecoratorSymbol) { + if (metadata.symbol === decoratorSymbol) { return metadata; } } @@ -10822,7 +10861,8 @@ module ts { getResolvedSignature, serializeTypeOfDeclaration, serializeParameterTypesOfDeclaration, - serializeReturnTypeOfDeclaration + serializeReturnTypeOfDeclaration, + getMetadataForSymbol }; } @@ -10861,6 +10901,8 @@ module ts { globalTypeDecoratorSymbol = getGlobalDecoratorSymbol("type"); globalParamTypesDecoratorSymbol = getGlobalDecoratorSymbol("paramtypes"); globalReturnTypeDecoratorSymbol = getGlobalDecoratorSymbol("returntype"); + globalObsoleteDecoratorSymbol = getGlobalDecoratorSymbol("obsolete"); + globalConditionalDecoratorSymbol = getGlobalDecoratorSymbol("conditional"); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 4ba2da757e5d8..e592512c22953 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -159,6 +159,14 @@ module ts { shortName: "w", type: "boolean", description: Diagnostics.Watch_input_files, + }, + { + name: "define", + shortName: "d", + type: "string", + paramType: "SYMBOL", + multiple: true, + experimental: true } ]; @@ -205,15 +213,16 @@ module ts { errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_expects_an_argument, opt.name)); } + var value: number | string | boolean = undefined; switch (opt.type) { case "number": - options[opt.name] = parseInt(args[i++]); + value = parseInt(args[i++]); break; case "boolean": - options[opt.name] = true; + value = true; break; case "string": - options[opt.name] = args[i++] || ""; + value = args[i++] || ""; break; // If not a primitive, the possible types are specified in what is effectively a map of options. default: @@ -224,7 +233,22 @@ module ts { } else { errors.push(createCompilerDiagnostic(opt.error)); + continue; + } + } + + if (value !== undefined) { + if (opt.multiple) { + var list = options[opt.name]; + if (!list) { + list = []; + options[opt.name] = list; } + list.push(value); + } + else { + options[opt.name] = value; + } } } else { @@ -302,6 +326,7 @@ module ts { var opt = optionNameMap[id]; var optType = opt.type; var value = jsonOptions[id]; + var expectedType: string; var expectedType = typeof optType === "string" ? optType : "string"; if (typeof value === expectedType) { if (typeof optType !== "string") { @@ -317,7 +342,18 @@ module ts { if (opt.isFilePath) { value = normalizePath(combinePaths(basePath, value)); } - options[opt.name] = value; + + if (opt.multiple) { + var list = options[opt.name]; + if (!list) { + list = []; + options[opt.name] = list; + } + list.push(value); + } + else { + options[opt.name] = value; + } } else { errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, id, expectedType)); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 517ec270f97a1..a1ee795cd5c43 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2667,7 +2667,22 @@ module ts { write(")"); } + function emitVoidExpressionForConditionalRemoval(node: Expression): void { + if (node.parent.kind !== SyntaxKind.ExpressionStatement) { + if (node.parent.kind === SyntaxKind.ParenthesizedExpression) { + write("void 0"); + } + else { + write("(void 0)"); + } + } + } + function emitCallExpression(node: CallExpression) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConditionallyRemoved) { + emitVoidExpressionForConditionalRemoval(node); + return; + } if (languageVersion < ScriptTarget.ES6 && hasSpreadElement(node.arguments)) { emitCallWithSpread(node); return; @@ -2698,6 +2713,10 @@ module ts { } function emitNewExpression(node: NewExpression) { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConditionallyRemoved) { + emitVoidExpressionForConditionalRemoval(node); + return; + } write("new "); emit(node.expression); if (node.arguments) { @@ -2708,6 +2727,10 @@ module ts { } function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void { + if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ConditionallyRemoved) { + emitVoidExpressionForConditionalRemoval(node); + return; + } emit(node.tag); write(" "); emit(node.template); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 423d877e7b56f..6fd2d74279077 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1153,6 +1153,7 @@ module ts { serializeTypeOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration | PropertyDeclaration | ParameterDeclaration): string; serializeParameterTypesOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration): string[]; serializeReturnTypeOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration): string; + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; } export const enum SymbolFlags { @@ -1282,6 +1283,7 @@ module ts { EmitDecoratedParamTypes = 0x00000400, // Emit the parameter types of the decorator target as an argument in this parameter position EmitDecoratedReturnType = 0x00000800, // Emit the return type of the decorator target as an argument in this parameter position AmbientDecorator = 0x00001000, // Decorator was marked ambient, do not emit to output + ConditionallyRemoved = 0x00002000, // Call should be ignored due to @conditional } export interface NodeLinks { @@ -1540,7 +1542,8 @@ module ts { version?: boolean; watch?: boolean; stripInternal?: boolean; - [option: string]: string | number | boolean; + defines?: string[]; + [option: string]: string | number | boolean | string[]; } export const enum ModuleKind { @@ -1579,6 +1582,7 @@ module ts { paramType?: DiagnosticMessage; // The name to be used for a non-boolean option's parameter error?: DiagnosticMessage; // The error given when the argument does not fit a customized 'type' experimental?: boolean; + multiple?: boolean; } export const enum CharacterCodes { diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 35d4be41c07a0..dab31ac5f728e 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1159,6 +1159,20 @@ interface TypedPropertyDescriptor { set?: (value: T) => void; } +declare const enum DecoratorTargets { + module = 0x00000001, + class = 0x00000002, + interface = 0x00000004, + function = 0x00000008, + enum = 0x00000010, + enumMember = 0x00000020, + property = 0x00000040, + method = 0x00000080, + accessor = 0x00000100, + parameter = 0x00000200, + variable = 0x00000400, +} + interface DecoratorFunction { (target: TFunction): TFunction | void; } interface ParameterDecoratorFunction { (target: Function, parameterIndex: number): void; } interface MemberDecoratorFunction { (target: Function | Object, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void; } @@ -1172,6 +1186,12 @@ declare function decorator(options?: { * A value indicating whether the decorator is ambient (true) and should not be emitted to output. */ ambient?: boolean; + + /** + * The elements on which a decorator can be applied. + * @remarks Non-ambient decorators are only valid on `class`, `property`, `method`, `accessor`, and `parameter` targets. + */ + targets?: DecoratorTargets; }): void; /** @@ -1191,3 +1211,15 @@ declare function paramtypes(): void; */ @decorator({ ambient: true }) declare function returntype(): void; + +/** + * Built-in decorator. Reports an error on any usage of the symbol. + */ +@decorator({ ambient: true }) +declare function obsolete(message?: string): void; + +/** + * Built-in decorator. Indicates to the compiler that the call expression should be ignored unless a specified conditional compilation symbol is defined. + */ +@decorator({ ambient: true }) +declare function conditional(condition: string): void; \ No newline at end of file From 07f6d4d1d5d93a198d5af555fcf006cab3fbe098 Mon Sep 17 00:00:00 2001 From: rbuckton Date: Wed, 18 Feb 2015 14:59:51 -0800 Subject: [PATCH 14/33] Fixed typo in CompilerOptions --- src/compiler/checker.ts | 6 +++--- src/compiler/types.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 59aa967de819b..22e3216f55517 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6539,9 +6539,9 @@ module ts { function isConditionalSymbolDefined(condition: string) { if (!conditionalSymbols) { conditionalSymbols = {}; - if (compilerOptions.defines) { - for (var i = 0; i < compilerOptions.defines.length; i++) { - conditionalSymbols[compilerOptions.defines[i].toUpperCase()] = true; + if (compilerOptions.define) { + for (var i = 0; i < compilerOptions.define.length; i++) { + conditionalSymbols[compilerOptions.define[i].toUpperCase()] = true; } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6fd2d74279077..d5d95a4f9ff66 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1542,7 +1542,7 @@ module ts { version?: boolean; watch?: boolean; stripInternal?: boolean; - defines?: string[]; + define?: string[]; [option: string]: string | number | boolean | string[]; } From e71d3dff07a79b0cbbae139fd7b02729ea4a0768 Mon Sep 17 00:00:00 2001 From: rbuckton Date: Wed, 18 Feb 2015 17:06:42 -0800 Subject: [PATCH 15/33] Clean up for @conditional and @obsolete, added support for DecoratorTargets enum --- src/compiler/checker.ts | 218 +++++++++++------- src/compiler/commandLineParser.ts | 2 +- .../diagnosticInformationMap.generated.ts | 3 + src/compiler/diagnosticMessages.json | 12 + src/compiler/types.ts | 62 +++-- src/compiler/utilities.ts | 10 + src/lib/core.d.ts | 35 +-- 7 files changed, 218 insertions(+), 124 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 22e3216f55517..eb74e4fbef27c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5701,7 +5701,11 @@ module ts { } function checkPropertyAccessExpression(node: PropertyAccessExpression) { - return checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name); + var type = checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name); + if (!isCallLikeExpression(node.parent)) { + checkUsageOfObsoleteSymbol(node, getNodeLinks(node).resolvedSymbol); + } + return type; } function checkQualifiedName(node: QualifiedName) { @@ -6545,23 +6549,38 @@ module ts { } } } - return hasProperty(conditionalSymbols, condition.toUpperCase()); } - function isConditionallyRemoved(signature: Signature) { - if (signature.declaration) { - var symbol = signature.declaration.symbol; + function checkConditionallyRemovedExpression(node: Expression, symbol: Symbol) { + if (symbol) { var metadataArray = getMetadataForSymbol(symbol); var metadata = findMetadata(metadataArray, globalConditionalDecoratorSymbol); if (metadata && metadata.arguments.length > 0) { var conditionSymbol = metadata.arguments[0]; if (conditionSymbol && !isConditionalSymbolDefined(conditionSymbol)) { - return true; + getNodeLinks(node).flags = NodeCheckFlags.ConditionallyRemoved; } } } - return false; + } + + function checkUsageOfObsoleteSymbol(node: Expression, symbol: Symbol) { + if (symbol) { + var metadataArray = getMetadataForSymbol(symbol); + var metadata = findMetadata(metadataArray, globalObsoleteDecoratorSymbol); + if (metadata) { + if (metadata.arguments.length > 0) { + error(node, Diagnostics._0_is_obsolete_Colon_1, symbolToString(symbol), metadata.arguments[0]); + } + else { + error(node, Diagnostics._0_is_obsolete, symbolToString(symbol)); + } + } + else if (symbol.parent) { + checkUsageOfObsoleteSymbol(node, symbol.parent); + } + } } function checkCallExpression(node: CallExpression): Type { @@ -6572,9 +6591,9 @@ module ts { if (node.expression.kind === SyntaxKind.SuperKeyword) { return voidType; } - if (node.kind === SyntaxKind.NewExpression) { - var declaration = signature.declaration; - if (declaration && + var declaration = signature.declaration; + if (declaration) { + if (node.kind === SyntaxKind.NewExpression && declaration.kind !== SyntaxKind.Constructor && declaration.kind !== SyntaxKind.ConstructSignature && declaration.kind !== SyntaxKind.ConstructorType) { @@ -6585,10 +6604,11 @@ module ts { } return anyType; } + + checkConditionallyRemovedExpression(node, declaration.symbol); + checkUsageOfObsoleteSymbol(node, declaration.symbol); } - if (isConditionallyRemoved(signature)) { - getNodeLinks(node).flags |= NodeCheckFlags.ConditionallyRemoved; - } + return getReturnTypeOfSignature(signature); } @@ -6599,8 +6619,10 @@ module ts { } var signature = getResolvedSignature(node); - if (isConditionallyRemoved(signature)) { - getNodeLinks(node).flags |= NodeCheckFlags.ConditionallyRemoved; + var declaration = signature.declaration; + if (declaration) { + checkConditionallyRemovedExpression(node, declaration.symbol); + checkUsageOfObsoleteSymbol(node, declaration.symbol); } return getReturnTypeOfSignature(signature); @@ -8193,7 +8215,7 @@ module ts { } function reportInvalidDecoratorExpression(node: Decorator, exprType: Type): void { - switch (node.kind) { + switch (node.parent.kind) { case SyntaxKind.ClassDeclaration: checkTypeAssignableTo(exprType, globalDecoratorFunctionType, node); return; @@ -8211,25 +8233,35 @@ module ts { } } - function decoratorIsAmbient(symbol: Symbol) { - if (!symbol) { + function decoratorIsAmbient(decoratorSymbol: Symbol) { + if (!decoratorSymbol) { return false; } - if (symbol === globalDecoratorSymbol - || symbol === globalTypeDecoratorSymbol - || symbol === globalParamTypesDecoratorSymbol - || symbol === globalReturnTypeDecoratorSymbol) { + if (decoratorIsBuiltIn(decoratorSymbol)) { return true; } - var metadataArray = getMetadataForSymbol(symbol); + var metadataArray = getMetadataForSymbol(decoratorSymbol); var metadata = findMetadata(metadataArray, globalDecoratorSymbol); if (metadata && metadata.arguments.length > 0) { var usage = metadata.arguments[0]; - return usage.ambient; + return usage && usage.ambient; } return false; } + function decoratorIsBuiltIn(decoratorSymbol: Symbol) { + switch (decoratorSymbol) { + case globalDecoratorSymbol: + case globalTypeDecoratorSymbol: + case globalParamTypesDecoratorSymbol: + case globalReturnTypeDecoratorSymbol: + case globalConditionalDecoratorSymbol: + case globalObsoleteDecoratorSymbol: + return true; + } + return false; + } + function findMetadata(metadataArray: DecoratorMetadata[], decoratorSymbol: Symbol): DecoratorMetadata { if (metadataArray) { for (var i = 0; i < metadataArray.length; i++) { @@ -8261,23 +8293,7 @@ module ts { return emptyMetadata; } - function getMetadataForDecorator(node: Decorator): DecoratorMetadata { - var links = getNodeLinks(node); - if (!links.resolvedDecoratorMetadata) { - links.resolvedDecoratorMetadata = resolvingMetadata; - var metadata = resolveMetadataForDecorator(node); - if (links.resolvedDecoratorMetadata === resolvingMetadata) { - links.resolvedDecoratorMetadata = metadata; - } - } - else if (links.resolvedDecoratorMetadata === resolvingMetadata) { - // TODO: report an error? - links.resolvedDecoratorMetadata = emptyMetadata; - } - return links.resolvedDecoratorMetadata; - } - - function resolveMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]{ + function resolveMetadataForSymbol(symbol: Symbol): DecoratorMetadata[] { if (symbol.valueDeclaration) { var decorators = symbol.valueDeclaration.decorators; if (decorators) { @@ -8299,6 +8315,22 @@ module ts { return emptyArray; } + function getMetadataForDecorator(node: Decorator): DecoratorMetadata { + var links = getNodeLinks(node); + if (!links.resolvedDecoratorMetadata) { + links.resolvedDecoratorMetadata = resolvingMetadata; + var metadata = resolveMetadataForDecorator(node); + if (links.resolvedDecoratorMetadata === resolvingMetadata) { + links.resolvedDecoratorMetadata = metadata; + } + } + else if (links.resolvedDecoratorMetadata === resolvingMetadata) { + // TODO: report an error? + links.resolvedDecoratorMetadata = emptyMetadata; + } + return links.resolvedDecoratorMetadata; + } + function getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[] { var links = getSymbolLinks(symbol); if (!links.decoratorMetadata) { @@ -8310,50 +8342,64 @@ module ts { function getValidDecoratorTarget(node: Node): DecoratorFlags { if (node) { switch (node.kind) { + case SyntaxKind.ModuleDeclaration: return DecoratorFlags.ModuleDeclaration; + case SyntaxKind.ImportDeclaration: return DecoratorFlags.ImportDeclaration; case SyntaxKind.ClassDeclaration: return DecoratorFlags.ClassDeclaration; case SyntaxKind.InterfaceDeclaration: return DecoratorFlags.InterfaceDeclaration; - case SyntaxKind.TypeAliasDeclaration: return DecoratorFlags.TypeAliasDeclaration; + case SyntaxKind.FunctionDeclaration: return DecoratorFlags.FunctionDeclaration; case SyntaxKind.EnumDeclaration: return DecoratorFlags.EnumDeclaration; case SyntaxKind.EnumMember: return DecoratorFlags.EnumMember; - case SyntaxKind.ModuleDeclaration: return DecoratorFlags.ModuleDeclaration; - case SyntaxKind.ImportDeclaration: return DecoratorFlags.ImportDeclaration; - case SyntaxKind.VariableDeclaration: return DecoratorFlags.VariableDeclaration; - case SyntaxKind.FunctionDeclaration: return DecoratorFlags.FunctionDeclaration; + case SyntaxKind.Constructor: return DecoratorFlags.Constructor; case SyntaxKind.PropertyDeclaration: return DecoratorFlags.PropertyDeclaration; case SyntaxKind.MethodDeclaration: return DecoratorFlags.MethodDeclaration; case SyntaxKind.GetAccessor: return DecoratorFlags.AccessorDeclaration; case SyntaxKind.SetAccessor: return DecoratorFlags.AccessorDeclaration; case SyntaxKind.Parameter: return DecoratorFlags.ParameterDeclaration; + case SyntaxKind.VariableDeclaration: return DecoratorFlags.VariableDeclaration; } } return undefined; } - function getDecoratorFlagsForDecorator(node: Decorator, symbol: Symbol, exprType: Type) { + function getDecoratorFlagsForDecorator(node: Decorator, decoratorSymbol: Symbol, exprType: Type) { var flags: DecoratorFlags; - if (symbol === globalDecoratorSymbol) { - flags |= DecoratorFlags.BuiltIn | DecoratorFlags.FunctionDeclaration; - } - else if (symbol === globalTypeDecoratorSymbol - || symbol === globalParamTypesDecoratorSymbol - || symbol === globalReturnTypeDecoratorSymbol) { - flags |= DecoratorFlags.BuiltIn | DecoratorFlags.ParameterDeclaration; + if (decoratorSymbol) { + // get the valid targets from this decorator's @decorator + var metadataArray = getMetadataForSymbol(decoratorSymbol); + var metadata = findMetadata(metadataArray, globalDecoratorSymbol); + if (metadata && metadata.arguments.length > 0) { + var usage = metadata.arguments[0]; + if (usage) { + flags |= usage.targets & DecoratorFlags.DecoratorTargetsMask; + } + } + if (!flags) { + flags = DecoratorFlags.AllTargets; + } + if (decoratorIsBuiltIn(decoratorSymbol)) { + flags |= DecoratorFlags.BuiltIn; + } + else if (decoratorIsAmbient(decoratorSymbol)) { + flags |= DecoratorFlags.UserDefinedAmbient; + } + else { + flags &= DecoratorFlags.NonAmbientValidTargetMask; + } } else { - if (symbol && decoratorIsAmbient(symbol)) { - flags |= DecoratorFlags.UserDefinedAmbient | DecoratorFlags.AllTargets; + flags = DecoratorFlags.NonAmbientValidTargetMask; + } + if ((flags & DecoratorFlags.Ambient) === 0) { + // infer the valid targets from the type of the decorator's expression + var widenedType = getWidenedType(exprType); + if (!isTypeAssignableTo(globalDecoratorFunctionType, widenedType) && !isTypeAssignableTo(exprType, globalDecoratorFunctionType)) { + flags &= ~DecoratorFlags.DecoratorFunctionValidTargetMask; } - else { - var widenedType = getWidenedType(exprType); - if (isTypeAssignableTo(globalDecoratorFunctionType, widenedType) || isTypeAssignableTo(exprType, globalDecoratorFunctionType)) { - flags |= DecoratorFlags.ClassDeclaration; - } - if (isTypeAssignableTo(globalMemberDecoratorFunctionType, widenedType) || isTypeAssignableTo(exprType, globalMemberDecoratorFunctionType)) { - flags |= DecoratorFlags.MethodDeclaration | DecoratorFlags.PropertyDeclaration | DecoratorFlags.AccessorDeclaration; - } - if (isTypeAssignableTo(globalParameterDecoratorFunctionType, widenedType) || isTypeAssignableTo(exprType, globalParameterDecoratorFunctionType)) { - flags |= DecoratorFlags.ParameterDeclaration; - } + if (!isTypeAssignableTo(globalMemberDecoratorFunctionType, widenedType) && !isTypeAssignableTo(exprType, globalMemberDecoratorFunctionType)) { + flags &= ~DecoratorFlags.MemberDecoratorFunctionValidTargetsMask; + } + if (isTypeAssignableTo(globalParameterDecoratorFunctionType, widenedType) || isTypeAssignableTo(exprType, globalParameterDecoratorFunctionType)) { + flags &= ~DecoratorFlags.ParameterDecoratorFunctionValidTargetsMask; } } return flags; @@ -8402,24 +8448,26 @@ module ts { } // handle built-in decorators - switch (symbol) { - case globalDecoratorSymbol: - if (metadata && metadata.arguments.length > 0) { - var usage = metadata.arguments[0]; - if (usage.ambient) { - getNodeLinks(node.parent).flags |= NodeCheckFlags.AmbientDecorator; + if (flags & DecoratorFlags.BuiltIn) { + switch (symbol) { + case globalDecoratorSymbol: + if (metadata && metadata.arguments.length > 0) { + var usage = metadata.arguments[0]; + if (usage.ambient) { + getNodeLinks(node.parent).flags |= NodeCheckFlags.AmbientDecorator; + } } - } - break; - case globalTypeDecoratorSymbol: - getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedType; - break; - case globalParamTypesDecoratorSymbol: - getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedParamTypes; - break; - case globalReturnTypeDecoratorSymbol: - getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedReturnType; - break; + break; + case globalTypeDecoratorSymbol: + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedType; + break; + case globalParamTypesDecoratorSymbol: + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedParamTypes; + break; + case globalReturnTypeDecoratorSymbol: + getNodeLinks(node.parent).flags |= NodeCheckFlags.EmitDecoratedReturnType; + break; + } } } @@ -9608,8 +9656,6 @@ module ts { case SyntaxKind.ObjectLiteralExpression: return evalObjectLiteralConstant(e); case SyntaxKind.PropertyAccessExpression: - var member = expression.parent; - var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); var enumType = getTypeOfNode((e).expression); var propertyName = (e).name.text; if (!isConstEnumObjectType(enumType)) { diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index e592512c22953..d0b8ba2edd46b 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -164,7 +164,7 @@ module ts { name: "define", shortName: "d", type: "string", - paramType: "SYMBOL", + paramType: Diagnostics.SYMBOL, multiple: true, experimental: true } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 4d63ea1097531..1e8c880ad941b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -153,6 +153,8 @@ module ts { Decorator_0_is_not_valid_on_this_declaration_type: { code: 1191, category: DiagnosticCategory.Error, key: "Decorator '{0}' is not valid on this declaration type." }, Decorator_is_not_valid_on_this_declaration_type: { code: 1192, category: DiagnosticCategory.Error, key: "Decorator is not valid on this declaration type." }, Argument_to_ambient_decorator_must_be_constant_expression: { code: 1193, category: DiagnosticCategory.Error, key: "Argument to ambient decorator must be constant expression." }, + _0_is_obsolete: { code: 1194, category: DiagnosticCategory.Error, key: "'{0}' is obsolete." }, + _0_is_obsolete_Colon_1: { code: 1195, category: DiagnosticCategory.Error, key: "'{0}' is obsolete: '{1}'" }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -444,6 +446,7 @@ module ts { File_0_must_have_extension_ts_or_d_ts: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' must have extension '.ts' or '.d.ts'." }, Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, + SYMBOL: { code: 6057, category: DiagnosticCategory.Message, key: "SYMBOL" }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ad26e31e18c51..f674fc89b051c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -603,6 +603,14 @@ "category": "Error", "code": 1193 }, + "'{0}' is obsolete.": { + "category": "Error", + "code": 1194 + }, + "'{0}' is obsolete: '{1}'": { + "category": "Error", + "code": 1195 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -1769,6 +1777,10 @@ "category": "Message", "code": 6056 }, + "SYMBOL": { + "category": "Message", + "code": 6057 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d5d95a4f9ff66..32b251fa82459 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1445,7 +1445,8 @@ module ts { } export interface DecoratorUsage { - ambient: boolean; + ambient?: boolean; + targets?: number; } // DecoratorMetadata consists of the state information about an ambient decorator @@ -1455,28 +1456,47 @@ module ts { } export const enum DecoratorFlags { - BuiltIn = 0x00000001, // built-in ambient decorator - UserDefinedAmbient = 0x00000002, // user-provided ambient decorator - ClassDeclaration = 0x00000004, // decorator can target a class declaration - InterfaceDeclaration = 0x00000008, // decorator can target an interface declaration - TypeAliasDeclaration = 0x00000010, // decorator can target a type alias - EnumDeclaration = 0x00000020, // decorator can target an enum declaration - EnumMember = 0x00000040, // decorator can target an enum member - ModuleDeclaration = 0x00000080, // decorator can target a lexical module declaration - ImportDeclaration = 0x00000100, // decorator can target an import declaration - VariableDeclaration = 0x00000200, // decorator can target a variable declaration (var, let, or const) - FunctionDeclaration = 0x00000400, // decorator can target a function declaration - PropertyDeclaration = 0x00000800, // decorator can target a property declaration - MethodDeclaration = 0x00001000, // decorator can target a method declaration - AccessorDeclaration = 0x00002000, // decorator can target an accessor declaration - ParameterDeclaration = 0x00004000, // decorator can target a parameter declaration + // Flags from DecoratorTargets enum + ModuleDeclaration = 0x00000001, // decorator can target a lexical module declaration (from DecoratorTargets enum) + ImportDeclaration = 0x00000002, // decorator can target an import declaration (from DecoratorTargets enum) + ClassDeclaration = 0x00000004, // decorator can target a class declaration (from DecoratorTargets enum) + InterfaceDeclaration = 0x00000008, // decorator can target an interface declaration (from DecoratorTargets enum) + FunctionDeclaration = 0x00000010, // decorator can target a function declaration (from DecoratorTargets enum) + EnumDeclaration = 0x00000020, // decorator can target an enum declaration (from DecoratorTargets enum) + EnumMember = 0x00000040, // decorator can target an enum member (from DecoratorTargets enum) + Constructor = 0x00000080, // decorator can target a constructor (from DecoratorTargets enum) + PropertyDeclaration = 0x00000100, // decorator can target a property declaration (from DecoratorTargets enum) + MethodDeclaration = 0x00000200, // decorator can target a method declaration (from DecoratorTargets enum) + AccessorDeclaration = 0x00000400, // decorator can target an accessor declaration (from DecoratorTargets enum) + ParameterDeclaration = 0x00000800, // decorator can target a parameter declaration (from DecoratorTargets enum) + VariableDeclaration = 0x00001000, // decorator can target a variable declaration (var, let, or const) (from DecoratorTargets enum) + AllTargets = 0x00001fff, // decorator can target all targets (from DecoratorTargets enum) + + // Additional flags + BuiltIn = 0x00010000, // built-in ambient decorator + UserDefinedAmbient = 0x00020000, // user-provided ambient decorator Ambient = BuiltIn | UserDefinedAmbient, - AllTargets = ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration - | EnumDeclaration | EnumMember | ModuleDeclaration | ImportDeclaration - | VariableDeclaration | FunctionDeclaration | PropertyDeclaration - | MethodDeclaration | AccessorDeclaration | ParameterDeclaration, - ES3TargetsExclude = PropertyDeclaration | MethodDeclaration | AccessorDeclaration + + ES3TargetsExclude = PropertyDeclaration | MethodDeclaration | AccessorDeclaration, + + // Valid decorator targets (from DecoratorTargets enum) + DecoratorTargetsMask = AllTargets, + + // Valid targets for an ES3 non-ambient decorator + ES3ValidTargetMask = ClassDeclaration | ParameterDeclaration, + + // Valid targets for a non-ambient decorator + NonAmbientValidTargetMask = ClassDeclaration | PropertyDeclaration | MethodDeclaration | AccessorDeclaration | ParameterDeclaration, + + // Valid targets for a non-ambient decorator that resolves to a type compatible with DecoratorFunction + DecoratorFunctionValidTargetMask = ClassDeclaration, + + // Valid targets for a non-amient decorator that resolves to a type compatible with MemberDecoratorFunction + MemberDecoratorFunctionValidTargetsMask = PropertyDeclaration | MethodDeclaration | AccessorDeclaration, + + // Valid targets for a non-ambient decorator that resolves to a type compatible with ParameterDecoratorFunction + ParameterDecoratorFunctionValidTargetsMask = ParameterDeclaration, } export interface DiagnosticMessage { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 58b2fdcd64c1e..16901919a6ec6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -589,6 +589,16 @@ module ts { return false; } + export function isCallLikeExpression(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + case SyntaxKind.TaggedTemplateExpression: + return true; + } + return false; + } + export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) { var moduleState = getModuleInstanceState(node) return moduleState === ModuleInstanceState.Instantiated || diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index dab31ac5f728e..0778cec019c05 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1161,16 +1161,19 @@ interface TypedPropertyDescriptor { declare const enum DecoratorTargets { module = 0x00000001, - class = 0x00000002, - interface = 0x00000004, - function = 0x00000008, - enum = 0x00000010, - enumMember = 0x00000020, - property = 0x00000040, - method = 0x00000080, - accessor = 0x00000100, - parameter = 0x00000200, - variable = 0x00000400, + import = 0x00000002, + class = 0x00000004, + interface = 0x00000008, + function = 0x00000010, + enum = 0x00000020, + enumMember = 0x00000040, + constructor = 0x00000080, + property = 0x00000100, + method = 0x00000200, + accessor = 0x00000400, + parameter = 0x00000800, + variable = 0x00001000, + all = 0x00001fff, } interface DecoratorFunction { (target: TFunction): TFunction | void; } @@ -1180,7 +1183,7 @@ interface MemberDecoratorFunction { (target: Function | Object, propertyKey: /** * Built-in decorator. Sets options for a function used as a decorator */ -@decorator({ ambient: true }) +@decorator({ ambient: true, targets: DecoratorTargets.function }) declare function decorator(options?: { /** * A value indicating whether the decorator is ambient (true) and should not be emitted to output. @@ -1197,29 +1200,29 @@ declare function decorator(options?: { /** * Built-in decorator. Emits the serialized type of the target in the argument position of the decorated parameter. */ -@decorator({ ambient: true }) +@decorator({ ambient: true, targets: DecoratorTargets.parameter }) declare function type(): void; /** * Built-in decorator. Emits the serialized types of the parameters of the target in the argument position of the decorated parameter. */ -@decorator({ ambient: true }) +@decorator({ ambient: true, targets: DecoratorTargets.parameter }) declare function paramtypes(): void; /** * Built-in decorator. Emits the serialized return type of the target in the argument position of the decorated parameter. */ -@decorator({ ambient: true }) +@decorator({ ambient: true, targets: DecoratorTargets.parameter }) declare function returntype(): void; /** * Built-in decorator. Reports an error on any usage of the symbol. */ -@decorator({ ambient: true }) +@decorator({ ambient: true, targets: DecoratorTargets.function | DecoratorTargets.class | DecoratorTargets.interface | DecoratorTargets.constructor | DecoratorTargets.property | DecoratorTargets.accessor | DecoratorTargets.method | DecoratorTargets.enum | DecoratorTargets.enumMember }) declare function obsolete(message?: string): void; /** * Built-in decorator. Indicates to the compiler that the call expression should be ignored unless a specified conditional compilation symbol is defined. */ -@decorator({ ambient: true }) +@decorator({ ambient: true, targets: DecoratorTargets.class | DecoratorTargets.function | DecoratorTargets.method }) declare function conditional(condition: string): void; \ No newline at end of file From 5251ce29a74fd79689e53e1d4873699d88593ff1 Mon Sep 17 00:00:00 2001 From: rbuckton Date: Wed, 18 Feb 2015 17:45:22 -0800 Subject: [PATCH 16/33] cleanup of DecoratorFlags, scaffolding to check compatibility with MemberDecoratorFunction. --- src/compiler/checker.ts | 11 ++++++++++- src/compiler/types.ts | 2 -- src/lib/core.d.ts | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eb74e4fbef27c..0f0d71cdcf8c1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8433,18 +8433,27 @@ module ts { var metadata: DecoratorMetadata; if (flags & DecoratorFlags.Ambient) { + // read and check arguments for decorator getNodeLinks(node).flags |= NodeCheckFlags.AmbientDecorator; metadata = getMetadataForDecorator(node); if (!metadata) { + // if we received 'undefined' here, that means there was an error evaluating the metadata. return; } } else { // report error for non-ambient decorator on member in ES3 - if (languageVersion < ScriptTarget.ES5 && (validFlags & DecoratorFlags.ES3TargetsExclude)) { + if (languageVersion < ScriptTarget.ES5 && (validFlags & DecoratorFlags.ES3ValidTargetMask) === 0) { error(node, Diagnostics.Non_ambient_decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher); return; } + + // If we are decorating a class member, we need to check the type is compatible + if (validFlags & DecoratorFlags.MemberDecoratorFunctionValidTargetsMask) { + var memberSymbol = getSymbolOfNode(node.parent); + var memberType = getTypeOfSymbol(memberSymbol); + // TODO(rbuckton): Check compatibility for TypedPropertyDescriptor and MemberDecoratorFunction + } } // handle built-in decorators diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 32b251fa82459..c078b9def1445 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1478,8 +1478,6 @@ module ts { Ambient = BuiltIn | UserDefinedAmbient, - ES3TargetsExclude = PropertyDeclaration | MethodDeclaration | AccessorDeclaration, - // Valid decorator targets (from DecoratorTargets enum) DecoratorTargetsMask = AllTargets, diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 0778cec019c05..e5b2cc2d4d361 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1222,7 +1222,7 @@ declare function returntype(): void; declare function obsolete(message?: string): void; /** - * Built-in decorator. Indicates to the compiler that the call expression should be ignored unless a specified conditional compilation symbol is defined. + * Built-in decorator. Indicates to the compiler that the call expression should be ignored (and replaced with `void 0` if applicable) unless a specified conditional compilation symbol is defined. */ @decorator({ ambient: true, targets: DecoratorTargets.class | DecoratorTargets.function | DecoratorTargets.method }) declare function conditional(condition: string): void; \ No newline at end of file From b10ac56138232aa2a0d5ae4514d0dcf460255be7 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 20 Feb 2015 12:09:29 -0800 Subject: [PATCH 17/33] Fixed wrong return value when ambient decorator argument list is empty. --- src/compiler/checker.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0f0d71cdcf8c1..b047bcc58bbe1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8210,6 +8210,9 @@ module ts { } result[i] = value; } + if (!result) { + return emptyArray; + } } return result; } From fd966547a257eb407b9687af1d813ed3a3d0cef5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 20 Feb 2015 12:10:13 -0800 Subject: [PATCH 18/33] elide ExpressionStatement when it's expression is removed by @conditional. --- src/compiler/emitter.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a1ee795cd5c43..68ad73bbd0686 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2888,6 +2888,10 @@ module ts { } function emitExpressionStatement(node: ExpressionStatement) { + if (resolver.getNodeCheckFlags(node.expression) & NodeCheckFlags.ConditionallyRemoved) { + return; + } + emitParenthesized(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction); write(";"); } From 10e8f934970ff61f245a8a4d60496a3f0dc5ba88 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 23 Feb 2015 13:01:51 -0800 Subject: [PATCH 19/33] Updated @type, @paramtypes, and @returntype to only use explicit type annotations. Removed extraneous/unused code --- src/compiler/checker.ts | 245 ++++++++++++++++++++++++++++++-------- src/compiler/types.ts | 1 - src/compiler/utilities.ts | 19 ++- 3 files changed, 212 insertions(+), 53 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b047bcc58bbe1..db608d1662c5e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -70,9 +70,9 @@ module ts { var resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); var anyType = createIntrinsicType(TypeFlags.Any, "any"); - var stringType = createIntrinsicType(TypeFlags.String, "string", /*boxedType*/ "String"); - var numberType = createIntrinsicType(TypeFlags.Number, "number", /*boxedType*/ "Number"); - var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean", /*boxedType*/ "Boolean"); + var stringType = createIntrinsicType(TypeFlags.String, "string"); + var numberType = createIntrinsicType(TypeFlags.Number, "number"); + var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean"); var voidType = createIntrinsicType(TypeFlags.Void, "void"); var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined"); var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null"); @@ -734,10 +734,9 @@ module ts { return result; } - function createIntrinsicType(kind: TypeFlags, intrinsicName: string, boxedName?: string): IntrinsicType { + function createIntrinsicType(kind: TypeFlags, intrinsicName: string): IntrinsicType { var type = createType(kind); type.intrinsicName = intrinsicName; - type.boxedName = boxedName; return type; } @@ -8152,6 +8151,10 @@ module ts { forEach(node.decorators, checkDecorator); } + /** + * Gets the right-most Identifier of the expression of a Decorator. This is used to resolve + * the declaration of an ambient decorator. + */ function getIdentifierOfDecoratorExpression(expression: Expression): Identifier { // unwrap a parenthesized expression while (expression.kind === SyntaxKind.ParenthesizedExpression) { @@ -8181,6 +8184,9 @@ module ts { return undefined; } + /** + * Gets the argument list of the expression of a Decorator, if it is a decorator factory. + */ function getArgumentsOfDecoratorExpression(expression: Expression): Expression[] { // unwrap a parenthesized expression while (expression.kind === SyntaxKind.ParenthesizedExpression) { @@ -8195,6 +8201,9 @@ module ts { return undefined; } + /** + * Evaluates and returns the constant values of the arguments to a decorator factory. + */ function evalDecoratorArguments(node: Decorator, argumentList: Expression[]): any[]{ var result: any[]; if (argumentList) { @@ -8210,9 +8219,9 @@ module ts { } result[i] = value; } - if (!result) { - return emptyArray; - } + } + if (!result) { + return emptyArray; } return result; } @@ -8263,18 +8272,6 @@ module ts { return true; } return false; - } - - function findMetadata(metadataArray: DecoratorMetadata[], decoratorSymbol: Symbol): DecoratorMetadata { - if (metadataArray) { - for (var i = 0; i < metadataArray.length; i++) { - var metadata = metadataArray[i]; - if (metadata.symbol === decoratorSymbol) { - return metadata; - } - } - } - return undefined; } function resolveMetadataForDecorator(decorator: Decorator): DecoratorMetadata { @@ -8342,6 +8339,9 @@ module ts { return links.decoratorMetadata; } + /** + * For a node, gets a DecoratorFlags value that represents the decorator target for that node. + */ function getValidDecoratorTarget(node: Node): DecoratorFlags { if (node) { switch (node.kind) { @@ -8364,7 +8364,13 @@ module ts { return undefined; } - function getDecoratorFlagsForDecorator(node: Decorator, decoratorSymbol: Symbol, exprType: Type) { + /** + * Computes the DecoratorFlags for a decorator. + * @node The decorator + * @decoratorSymbol The symbol for the decorator function or factory + * @exprType The type of the decorator expression + */ + function getDecoratorFlagsForDecorator(node: Decorator, decoratorSymbol: Symbol, exprType: Type): DecoratorFlags { var flags: DecoratorFlags; if (decoratorSymbol) { // get the valid targets from this decorator's @decorator @@ -8408,6 +8414,68 @@ module ts { return flags; } + /** + * Checks the type annotation of an accessor declaration or property declaration as + * an expression if it is a type reference to a type with a value declaration. + */ + function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration) { + var typeNode: TypeNode; + if (isAccessor(node.kind)) { + typeNode = (node).type; + } + else if (node.kind === SyntaxKind.PropertyDeclaration) { + typeNode = (node).type; + } + if (typeNode && typeNode.kind === SyntaxKind.TypeReference) { + var type = getTypeOfSymbol(node.symbol); + if (type.symbol.valueDeclaration) { + checkExpressionOrQualifiedName((typeNode).typeName); + } + } + } + + /** + * Checks the type annotation of the parameters of a function-like or the constructor + * of a class as expressions if they are a type reference to a type with a value declaration. + */ + function checkParameterTypeAnnotationsAsExpressions(node: ClassDeclaration | FunctionLikeDeclaration) { + // ensure all type annotations with a value declaration are checked as an expression + var declaration: FunctionLikeDeclaration; + if (node.kind === SyntaxKind.ClassDeclaration) { + declaration = getFirstConstructorWithBody(node); + } + else { + declaration = node; + } + if (declaration) { + var parameters = declaration.parameters; + var parameterCount = parameters.length; + for (var i = 0; i < parameterCount; i++) { + var parameter = parameters[i]; + if (parameter.type && parameter.type.kind === SyntaxKind.TypeReference) { + var parameterType = getTypeOfSymbol(parameter.symbol); + if (parameterType.symbol.valueDeclaration) { + checkExpressionOrQualifiedName((parameter.type).typeName); + } + } + } + } + } + + /** + * Checks the return type annotation as an expression if it is a type reference to a + * type with a value declaration. + */ + function checkReturnTypeAnnotationAsExpression(node: FunctionLikeDeclaration) { + var returnTypeNode = node.type; + if (returnTypeNode && returnTypeNode.kind === SyntaxKind.TypeReference) { + var returnTypeSymbol = getSymbolOfNode(returnTypeNode); + if (returnTypeSymbol.valueDeclaration) { + checkExpressionOrQualifiedName((returnTypeNode).typeName); + } + } + } + function checkDecorator(node: Decorator): void { var expression: Expression = node.expression; var exprType = checkExpression(expression); @@ -8481,6 +8549,39 @@ module ts { break; } } + else if (symbol && !(flags & DecoratorFlags.UserDefinedAmbient)) { + var valueDeclaration = symbol.valueDeclaration; + if (valueDeclaration && isAnyFunction(valueDeclaration)) { + var hasTypeDecorator = false; + var hasParamTypesDecorator = false; + var hasReturnTypeDecorator = false; + var signature = getSignatureFromDeclaration(valueDeclaration); + var parameters = signature.parameters; + var parameterCount = parameters.length; + for (var i = 0; i < parameterCount; i++) { + var parameter = parameters[i]; + var metadataArray = getMetadataForSymbol(parameter); + if (findMetadata(metadataArray, globalTypeDecoratorSymbol)) { + hasTypeDecorator = true; + } + if (findMetadata(metadataArray, globalParamTypesDecoratorSymbol)) { + hasParamTypesDecorator = true; + } + if (findMetadata(metadataArray, globalReturnTypeDecoratorSymbol)) { + hasReturnTypeDecorator = true; + } + } + if (hasTypeDecorator && (isAccessor(node.parent.kind) || node.kind === SyntaxKind.PropertyDeclaration)) { + checkTypeAnnotationAsExpression(node.parent); + } + if (hasParamTypesDecorator && (node.parent.kind === SyntaxKind.ClassDeclaration || isAnyFunction(node.parent))) { + checkParameterTypeAnnotationsAsExpressions(node.parent); + } + if (hasReturnTypeDecorator && isAnyFunction(node.parent)) { + checkReturnTypeAnnotationAsExpression(node.parent); + } + } + } } function checkFunctionDeclaration(node: FunctionDeclaration): void { @@ -10797,53 +10898,96 @@ module ts { return undefined; } - function serializeType(type: Type): string { + function serializeEntityName(node: EntityName): string { + if (node.kind === SyntaxKind.Identifier) { + var prefix = getExpressionNamePrefix(node); + if (prefix) { + return prefix + "." + (node).text; + } + return (node).text; + } + else { + return serializeEntityName((node).left) + "." + serializeEntityName((node).right); + } + } + + function serializeTypeReferenceNode(node: TypeReferenceNode): string { + var type = getTypeFromTypeReferenceNode(node); var flags = type.flags; if (flags & TypeFlags.Void) { return "void 0"; } - else if (flags & TypeFlags.Intrinsic) { - var boxedName = (type).boxedName; - if (boxedName) { - return boxedName; - } - } - else if (flags & TypeFlags.StringLiteral) { - return "String"; + else if (type.flags & TypeFlags.Boolean) { + return "Boolean"; } - else if (flags & TypeFlags.Enum) { + else if (flags & TypeFlags.NumberLike) { return "Number"; } + else if (flags & TypeFlags.StringLike) { + return "String"; + } else if (flags & TypeFlags.Tuple) { return "Array"; } - else { - var symbol = type.symbol; - var declaration = symbol.valueDeclaration; - if (declaration) { - var name = declaration.name; - if (name && name.kind === SyntaxKind.Identifier) { - var prefix = getExpressionNamePrefix(name); - if (prefix) { - return prefix + "." + (name).text; - } - return (name).text; - } - } + else if (type.symbol.valueDeclaration) { + return serializeEntityName(node.typeName); } var signatures = getSignaturesOfType(type, SignatureKind.Call); if (signatures.length) { return "Function"; } - + return "Object"; + } + + function serializeTypeNode(node: TypeNode | EntityName): string { + if (node) { + switch (node.kind) { + case SyntaxKind.VoidKeyword: + return "void 0"; + case SyntaxKind.ParenthesizedType: + return serializeTypeNode((node).type); + case SyntaxKind.Identifier: + case SyntaxKind.QualifiedName: + return serializeEntityName(node); + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return "Function"; + case SyntaxKind.ArrayType: + case SyntaxKind.TupleType: + return "Array"; + case SyntaxKind.BooleanKeyword: + return "Boolean"; + case SyntaxKind.StringKeyword: + case SyntaxKind.StringLiteral: + return "String"; + case SyntaxKind.NumberKeyword: + return "Number"; + case SyntaxKind.TypeReference: + return serializeTypeReferenceNode(node); + case SyntaxKind.TypeQuery: + case SyntaxKind.TypeLiteral: + case SyntaxKind.UnionType: + case SyntaxKind.AnyKeyword: + default: + break; + } + } return "Object"; } function serializeTypeOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration | PropertyDeclaration | ParameterDeclaration): string { - var symbol = getSymbolOfNode(node); - var type = symbol ? getTypeOfSymbol(symbol) : unknownType; - return serializeType(type); + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + return serializeEntityName((node).name); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + return serializeTypeNode((node).type); + } + if (isAnyFunction(node)) { + return "Function"; + } + return "Object"; } function serializeParameterTypesOfDeclaration(node: ClassDeclaration | FunctionLikeDeclaration): string[]{ @@ -10874,9 +11018,8 @@ module ts { if (node.kind === SyntaxKind.ClassDeclaration) { return serializeTypeOfDeclaration(node); } - else if (isAnyFunction(node) && nodeIsPresent((node).body)) { - var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(valueDeclaration)); - return serializeType(returnType); + else if (isAnyFunction(node)) { + return serializeTypeNode((node).type); } return "void 0"; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c078b9def1445..d0657ec7100ee 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1341,7 +1341,6 @@ module ts { // Intrinsic types (TypeFlags.Intrinsic) export interface IntrinsicType extends Type { intrinsicName: string; // Name of intrinsic type - boxedName: string; // Name of boxed constructor } // String literal types (TypeFlags.StringLiteral) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 16901919a6ec6..bef40c5add4d3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1160,4 +1160,21 @@ module ts { } } } -} \ No newline at end of file + + /** + * Finds the first DecoratorMetadata entry in a DecoratorMetadataArray for the given decorator symbol. + * @metadataArray an array of DecoratorMetadata + * @decoratorSymbol the symbol to a function declaration representing an ambient decorator. + */ + export function findMetadata(metadataArray: DecoratorMetadata[], decoratorSymbol: Symbol): DecoratorMetadata { + if (metadataArray && decoratorSymbol) { + for (var i = 0; i < metadataArray.length; i++) { + var metadata = metadataArray[i]; + if (metadata.symbol === decoratorSymbol) { + return metadata; + } + } + } + return undefined; + } +} From ebdf444c1bfd5b3b0d2d50ca946bd3ccac99495e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 24 Feb 2015 16:02:10 -0800 Subject: [PATCH 20/33] Updated baselines and cleanup of decorator checks. --- src/compiler/checker.ts | 351 +++++------ .../baselines/reference/APISample_compile.js | 436 ++++++++------ .../reference/APISample_compile.types | 555 ++++++++++++------ tests/baselines/reference/APISample_linter.js | 454 +++++++------- .../reference/APISample_linter.types | 555 ++++++++++++------ .../reference/APISample_transform.js | 436 ++++++++------ .../reference/APISample_transform.types | 555 ++++++++++++------ .../baselines/reference/APISample_watcher.js | 436 ++++++++------ .../reference/APISample_watcher.types | 555 ++++++++++++------ .../reference/computedPropertyNames23_ES5.js | 2 +- .../reference/computedPropertyNames26_ES5.js | 2 +- .../reference/noDefaultLib.errors.txt | 24 +- .../reference/parser509698.errors.txt | 36 +- ...rserErrorRecovery_ClassElement3.errors.txt | 2 +- .../parserErrorRecovery_ClassElement3.js | 2 +- .../noDefaultLib/amd/noDefaultLib.errors.txt | 40 +- .../noDefaultLib/node/noDefaultLib.errors.txt | 40 +- .../typeCheckTypeArgument.errors.txt | 36 +- .../bestCommonTypeWithContextualTyping.ts | 2 +- .../parserErrorRecovery_ClassElement3.ts | 2 +- 20 files changed, 2777 insertions(+), 1744 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8533e7a0c3c45..8ae5704af3eab 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6,8 +6,10 @@ module ts { var nextMergeId = 1; const enum EvalConstantFlags { - Numeric = 0x1, - ConstEnum = 0x2, + None = 0x0, + Enum = 0x1, + Constant = 0x2, + ConstEnum = Enum | Constant } /* @internal */ export var checkTime = 0; @@ -626,12 +628,38 @@ module ts { function getFullyQualifiedName(symbol: Symbol): string { return symbol.parent ? getFullyQualifiedName(symbol.parent) + "." + symbolToString(symbol) : symbolToString(symbol); } + + function getLeftSideOfQualifiedNameOrPropertyAccessExpression(node: QualifiedName | PropertyAccessExpression): EntityName | PropertyAccessExpression { + if (node.kind === SyntaxKind.QualifiedName) { + return (node).left; + } + else { + var left = (node).expression; + if (left.kind === SyntaxKind.Identifier || left.kind === SyntaxKind.PropertyAccessExpression) { + return left; + } + } + return undefined; + } + + function getRightSideOfQualifiedNameOrPropertyAccessExpression(node: QualifiedName | PropertyAccessExpression): Identifier { + if (node.kind === SyntaxKind.QualifiedName) { + return (node).right; + } + else { + return (node).name; + } + } // Resolves a qualified name and any involved import aliases function resolveEntityName(location: Node, name: EntityName, meaning: SymbolFlags): Symbol { + return resolveEntityNameOrPropertyAccessExpression(location, name, meaning); + } + + function resolveEntityNameOrPropertyAccessExpression(location: Node, name: EntityName | PropertyAccessExpression, meaning: SymbolFlags): Symbol { if (getFullWidth(name) === 0) { return undefined; - } + } if (name.kind === SyntaxKind.Identifier) { var symbol = resolveName(location,(name).text, meaning, Diagnostics.Cannot_find_name_0, name); @@ -639,13 +667,22 @@ module ts { return; } } - else if (name.kind === SyntaxKind.QualifiedName) { - var namespace = resolveEntityName(location,(name).left, SymbolFlags.Namespace); - if (!namespace || namespace === unknownSymbol || getFullWidth((name).right) === 0) return; - var symbol = getSymbol(getExportsOfSymbol(namespace), (name).right.text, meaning); + else if (name.kind === SyntaxKind.QualifiedName || name.kind === SyntaxKind.PropertyAccessExpression) { + var left = getLeftSideOfQualifiedNameOrPropertyAccessExpression(name); + if (!left) { + return; + } + var namespace = resolveEntityNameOrPropertyAccessExpression(location, left, SymbolFlags.Namespace); + if (!namespace || namespace === unknownSymbol) { + return; + } + var right = getRightSideOfQualifiedNameOrPropertyAccessExpression(name); + if (getFullWidth(right) === 0) { + return; + } + var symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { - error(location, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), - declarationNameToString((name).right)); + error(location, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), declarationNameToString(right)); return; } } @@ -8416,63 +8453,44 @@ module ts { } } - function checkDecorators(node: Node): void { - if (!node.decorators) { - return; - } - - checkGrammarDecorators(node); - - switch (node.kind) { - case SyntaxKind.MethodDeclaration: - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - if (languageVersion >= ScriptTarget.ES5 && node.parent.kind === SyntaxKind.ClassDeclaration) { - emitDecorate = true; - } - break; - } - - forEach(node.decorators, checkDecorator); - } + /** Resolves the symbol of the declaration for a decorator. */ + function getResolvedSymbolOfDecorator(decorator: Decorator): Symbol { + var links = getNodeLinks(decorator); + if (!links.resolvedSymbol) { + var expression: Expression = decorator.expression; - /** - * Gets the right-most Identifier of the expression of a Decorator. This is used to resolve - * the declaration of an ambient decorator. - */ - function getIdentifierOfDecoratorExpression(expression: Expression): Identifier { - // unwrap a parenthesized expression - while (expression.kind === SyntaxKind.ParenthesizedExpression) { - expression = (expression).expression; - } + // unwrap a parenthesized expression + while (expression.kind === SyntaxKind.ParenthesizedExpression) { + expression = (expression).expression; + } - // if this is a decorator factory, get the expression of the CallExpression - if (expression.kind === SyntaxKind.CallExpression) { - expression = (expression).expression; - } + // if this is a decorator factory, get the expression of the CallExpression + if (expression.kind === SyntaxKind.CallExpression) { + expression = (expression).expression; + } - // unwrap an remaining parenthesized expression - while (expression.kind === SyntaxKind.ParenthesizedExpression) { - expression = (expression).expression; - } + // unwrap an remaining parenthesized expression + while (expression.kind === SyntaxKind.ParenthesizedExpression) { + expression = (expression).expression; + } - // if this is a property access, return the name - if (expression.kind === SyntaxKind.PropertyAccessExpression) { - return (expression).name; + if (expression.kind === SyntaxKind.PropertyAccessExpression) { + links.resolvedSymbol = resolveEntityNameOrPropertyAccessExpression(decorator, expression, SymbolFlags.Value | SymbolFlags.ExportValue); + } + else if (expression.kind === SyntaxKind.Identifier) { + links.resolvedSymbol = resolveEntityName(decorator, expression, SymbolFlags.Value | SymbolFlags.ExportValue); + } + else { + links.resolvedSymbol = unknownSymbol; + } } - - // if the expression is an identifier, return it - if (expression.kind === SyntaxKind.Identifier) { - return expression; + else if (links.resolvedSymbol === unknownSymbol) { + return undefined; } - - return undefined; + return links.resolvedSymbol; } - /** - * Gets the argument list of the expression of a Decorator, if it is a decorator factory. - */ + /** Gets the argument list of the expression of a Decorator, if it is a decorator factory. */ function getArgumentsOfDecoratorExpression(expression: Expression): Expression[] { // unwrap a parenthesized expression while (expression.kind === SyntaxKind.ParenthesizedExpression) { @@ -8487,15 +8505,13 @@ module ts { return undefined; } - /** - * Evaluates and returns the constant values of the arguments to a decorator factory. - */ + /** Evaluates and returns the constant values of the arguments to a decorator factory. */ function evalDecoratorArguments(node: Decorator, argumentList: Expression[]): any[]{ var result: any[]; if (argumentList) { var argumentCount = argumentList.length; for (var i = 0; i < argumentCount; i++) { - var value = evalConstant(argumentList[i], /*isNumeric*/ false, /*isConst*/ true); + var value = evalConstant(argumentList[i], EvalConstantFlags.Constant); if (value === undefined) { error(node, Diagnostics.Argument_to_ambient_decorator_must_be_constant_expression); return undefined; @@ -8512,6 +8528,7 @@ module ts { return result; } + /** Reports an error if the decorator expression resolves to a type that has an invalid signature for the declaration */ function reportInvalidDecoratorExpression(node: Decorator, exprType: Type): void { switch (node.parent.kind) { case SyntaxKind.ClassDeclaration: @@ -8531,6 +8548,7 @@ module ts { } } + /** Tests whether the specified symbol is an ambient decorator */ function decoratorIsAmbient(decoratorSymbol: Symbol) { if (!decoratorSymbol) { return false; @@ -8547,6 +8565,7 @@ module ts { return false; } + /** Tests whether the specified symbol is a built-in decorator */ function decoratorIsBuiltIn(decoratorSymbol: Symbol) { switch (decoratorSymbol) { case globalDecoratorSymbol: @@ -8560,25 +8579,24 @@ module ts { return false; } + /** Resolves the constant decorator metadata for an ambient decorator */ function resolveMetadataForDecorator(decorator: Decorator): DecoratorMetadata { - var name = getIdentifierOfDecoratorExpression(decorator.expression); - if (name) { - var symbol = getResolvedSymbol(name); - if (decoratorIsAmbient(symbol)) { - var arguments = getArgumentsOfDecoratorExpression(decorator.expression); - var argumentList = evalDecoratorArguments(decorator, arguments); - if (argumentList) { - var metadata: DecoratorMetadata = { - symbol, - arguments: argumentList - }; - return metadata; - } + var symbol = getResolvedSymbolOfDecorator(decorator); + if (decoratorIsAmbient(symbol)) { + var arguments = getArgumentsOfDecoratorExpression(decorator.expression); + var argumentList = evalDecoratorArguments(decorator, arguments); + if (argumentList) { + var metadata: DecoratorMetadata = { + symbol, + arguments: argumentList + }; + return metadata; } } return emptyMetadata; } + /** Resolves an array of constant decorator metadata that is applied to the value declaration for the symbol */ function resolveMetadataForSymbol(symbol: Symbol): DecoratorMetadata[] { if (symbol.valueDeclaration) { var decorators = symbol.valueDeclaration.decorators; @@ -8601,6 +8619,7 @@ module ts { return emptyArray; } + /** Gets the decorator metadata for a Decorator node */ function getMetadataForDecorator(node: Decorator): DecoratorMetadata { var links = getNodeLinks(node); if (!links.resolvedDecoratorMetadata) { @@ -8617,7 +8636,11 @@ module ts { return links.resolvedDecoratorMetadata; } - function getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[] { + /** Gets the decorator metadata for a symbol */ + function getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]{ + if (!symbol.valueDeclaration) { + return emptyArray; + } var links = getSymbolLinks(symbol); if (!links.decoratorMetadata) { links.decoratorMetadata = resolveMetadataForSymbol(symbol); @@ -8631,20 +8654,20 @@ module ts { function getValidDecoratorTarget(node: Node): DecoratorFlags { if (node) { switch (node.kind) { - case SyntaxKind.ModuleDeclaration: return DecoratorFlags.ModuleDeclaration; - case SyntaxKind.ImportDeclaration: return DecoratorFlags.ImportDeclaration; - case SyntaxKind.ClassDeclaration: return DecoratorFlags.ClassDeclaration; - case SyntaxKind.InterfaceDeclaration: return DecoratorFlags.InterfaceDeclaration; - case SyntaxKind.FunctionDeclaration: return DecoratorFlags.FunctionDeclaration; - case SyntaxKind.EnumDeclaration: return DecoratorFlags.EnumDeclaration; - case SyntaxKind.EnumMember: return DecoratorFlags.EnumMember; - case SyntaxKind.Constructor: return DecoratorFlags.Constructor; - case SyntaxKind.PropertyDeclaration: return DecoratorFlags.PropertyDeclaration; - case SyntaxKind.MethodDeclaration: return DecoratorFlags.MethodDeclaration; - case SyntaxKind.GetAccessor: return DecoratorFlags.AccessorDeclaration; - case SyntaxKind.SetAccessor: return DecoratorFlags.AccessorDeclaration; - case SyntaxKind.Parameter: return DecoratorFlags.ParameterDeclaration; - case SyntaxKind.VariableDeclaration: return DecoratorFlags.VariableDeclaration; + case SyntaxKind.ModuleDeclaration: return DecoratorFlags.ModuleDeclaration; + case SyntaxKind.ImportDeclaration: return DecoratorFlags.ImportDeclaration; + case SyntaxKind.ClassDeclaration: return DecoratorFlags.ClassDeclaration; + case SyntaxKind.InterfaceDeclaration: return DecoratorFlags.InterfaceDeclaration; + case SyntaxKind.FunctionDeclaration: return DecoratorFlags.FunctionDeclaration; + case SyntaxKind.EnumDeclaration: return DecoratorFlags.EnumDeclaration; + case SyntaxKind.EnumMember: return DecoratorFlags.EnumMember; + case SyntaxKind.Constructor: return DecoratorFlags.Constructor; + case SyntaxKind.PropertyDeclaration: return DecoratorFlags.PropertyDeclaration; + case SyntaxKind.MethodDeclaration: return DecoratorFlags.MethodDeclaration; + case SyntaxKind.GetAccessor: return DecoratorFlags.AccessorDeclaration; + case SyntaxKind.SetAccessor: return DecoratorFlags.AccessorDeclaration; + case SyntaxKind.Parameter: return DecoratorFlags.ParameterDeclaration; + case SyntaxKind.VariableDeclaration: return DecoratorFlags.VariableDeclaration; } } return undefined; @@ -8700,68 +8723,41 @@ module ts { return flags; } - /** - * Checks the type annotation of an accessor declaration or property declaration as - * an expression if it is a type reference to a type with a value declaration. - */ - function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration) { - var typeNode: TypeNode; - if (isAccessor(node.kind)) { - typeNode = (node).type; - } - else if (node.kind === SyntaxKind.PropertyDeclaration) { - typeNode = (node).type; - } - if (typeNode && typeNode.kind === SyntaxKind.TypeReference) { - var type = getTypeOfSymbol(node.symbol); + /** Checks a type reference node as an expression. */ + function checkTypeNodeAsExpression(node: TypeNode | LiteralExpression) { + if (node && node.kind === SyntaxKind.TypeReference) { + var type = getTypeFromTypeNode(node); + if (!type || type.flags & (TypeFlags.Intrinsic | TypeFlags.NumberLike | TypeFlags.StringLike)) { + return; + } if (type.symbol.valueDeclaration) { - checkExpressionOrQualifiedName((typeNode).typeName); + checkExpressionOrQualifiedName((node).typeName); } } } /** - * Checks the type annotation of the parameters of a function-like or the constructor - * of a class as expressions if they are a type reference to a type with a value declaration. + * Checks the type annotation of an accessor declaration or property declaration as + * an expression if it is a type reference to a type with a value declaration. */ - function checkParameterTypeAnnotationsAsExpressions(node: ClassDeclaration | FunctionLikeDeclaration) { - // ensure all type annotations with a value declaration are checked as an expression - var declaration: FunctionLikeDeclaration; - if (node.kind === SyntaxKind.ClassDeclaration) { - declaration = getFirstConstructorWithBody(node); - } - else { - declaration = node; - } - if (declaration) { - var parameters = declaration.parameters; - var parameterCount = parameters.length; - for (var i = 0; i < parameterCount; i++) { - var parameter = parameters[i]; - if (parameter.type && parameter.type.kind === SyntaxKind.TypeReference) { - var parameterType = getTypeOfSymbol(parameter.symbol); - if (parameterType.symbol.valueDeclaration) { - checkExpressionOrQualifiedName((parameter.type).typeName); - } - } - } + function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration | ParameterDeclaration) { + switch (node.kind) { + case SyntaxKind.PropertyDeclaration: return checkTypeNodeAsExpression((node).type); + case SyntaxKind.Parameter: return checkTypeNodeAsExpression((node).type); + case SyntaxKind.GetAccessor: return checkTypeNodeAsExpression((node).type); + case SyntaxKind.SetAccessor: return checkTypeNodeAsExpression(getSetAccessorTypeAnnotationNode(node)); } } - - /** - * Checks the return type annotation as an expression if it is a type reference to a - * type with a value declaration. - */ - function checkReturnTypeAnnotationAsExpression(node: FunctionLikeDeclaration) { - var returnTypeNode = node.type; - if (returnTypeNode && returnTypeNode.kind === SyntaxKind.TypeReference) { - var returnTypeSymbol = getSymbolOfNode(returnTypeNode); - if (returnTypeSymbol.valueDeclaration) { - checkExpressionOrQualifiedName((returnTypeNode).typeName); - } + + /** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */ + function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) { + // ensure all type annotations with a value declaration are checked as an expression + if (node) { + forEach(node.parameters, checkTypeAnnotationAsExpression); } - } + } + /** Checks the usage of a built-in parameter decorator (@type, @paramtypes, @returntype). */ function checkBuiltInParameterDecorator(node: Decorator, symbol: Symbol, flags: NodeCheckFlags) { var links = getNodeLinks(node.parent); if (links.flags & flags) { @@ -8781,6 +8777,7 @@ module ts { } } + /** Check the usage of a built-in decorator. */ function checkBuiltInDecorator(node: Decorator, symbol: Symbol, metadata: DecoratorMetadata) { switch (symbol) { case globalDecoratorSymbol: @@ -8803,6 +8800,7 @@ module ts { } } + /** Check the usage of an ambient decorator. */ function checkAmbientDecorator(node: Decorator, symbol: Symbol, flags: DecoratorFlags) { getNodeLinks(node).flags |= NodeCheckFlags.AmbientDecorator; @@ -8818,6 +8816,7 @@ module ts { } } + /** Check the usage of a non-ambient decorator. */ function checkNonAmbientDecorator(node: Decorator, symbol: Symbol, flags: DecoratorFlags) { // report error for invalid target for decorator var validFlags = getValidDecoratorTarget(node.parent); @@ -8864,21 +8863,24 @@ module ts { if (hasTypeDecorator && (isAccessor(node.parent.kind) || node.kind === SyntaxKind.PropertyDeclaration)) { checkTypeAnnotationAsExpression(node.parent); } - else if (hasParamTypesDecorator && (node.parent.kind === SyntaxKind.ClassDeclaration || isAnyFunction(node.parent))) { - checkParameterTypeAnnotationsAsExpressions(node.parent); + else if (hasParamTypesDecorator && node.parent.kind === SyntaxKind.ClassDeclaration) { + checkParameterTypeAnnotationsAsExpressions(getFirstConstructorWithBody(node.parent)); + } + else if (hasParamTypesDecorator && isAnyFunction(node.parent)) { + checkParameterTypeAnnotationsAsExpressions(node.parent); } else if (hasReturnTypeDecorator && isAnyFunction(node.parent)) { - checkReturnTypeAnnotationAsExpression(node.parent); + checkTypeNodeAsExpression((node.parent).type); } } } } + /** Check a decorator */ function checkDecorator(node: Decorator): void { var expression: Expression = node.expression; var exprType = checkExpression(expression); - var name = getIdentifierOfDecoratorExpression(expression); - var symbol = name && getResolvedSymbol(name); + var symbol = getResolvedSymbolOfDecorator(node); // determine what targets the decorator can be applied to var flags = getDecoratorFlagsForDecorator(node, symbol, exprType); @@ -8896,6 +8898,28 @@ module ts { } } + /** Check the decorators of a node */ + function checkDecorators(node: Node): void { + if (!node.decorators) { + return; + } + + checkGrammarDecorators(node); + + switch (node.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + if (languageVersion >= ScriptTarget.ES5 && node.parent.kind === SyntaxKind.ClassDeclaration) { + emitDecorate = true; + } + break; + } + + forEach(node.decorators, checkDecorator); + } + function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || @@ -9945,11 +9969,13 @@ module ts { } function getConstantValueForEnumMemberInitializer(initializer: Expression, enumIsConst: boolean): number { - return evalConstant(initializer, /*isNumeric*/ true, /*isConst*/ enumIsConst); + return evalConstant(initializer, enumIsConst ? EvalConstantFlags.ConstEnum : EvalConstantFlags.Enum); } } - function evalConstant(expression: Expression, isNumeric: boolean, isConst: boolean): any { + function evalConstant(expression: Expression, flags: EvalConstantFlags): any { + var isEnum = (flags & EvalConstantFlags.Enum) !== 0; + var isConst = (flags & EvalConstantFlags.Constant) !== 0; return evalConstantWorker(expression); function evalConstantWorker(e: Node): any { @@ -9964,8 +9990,11 @@ module ts { case SyntaxKind.MinusToken: return -value; case SyntaxKind.TildeToken: return isConst ? ~value : undefined; } - return undefined; + break; case SyntaxKind.BinaryExpression: + if (!isConst) { + return undefined; + } var left = evalConstantWorker((e).left); if (left === undefined) { return undefined; @@ -9994,7 +10023,7 @@ module ts { return evalConstantWorker((e).expression); } - if (isNumeric) { + if (isEnum) { switch (e.kind) { case SyntaxKind.Identifier: case SyntaxKind.ElementAccessExpression: @@ -10049,7 +10078,7 @@ module ts { if (!isDefinedBefore(propertyDecl, member)) { return undefined; } - return getNodeLinks(propertyDecl).enumMemberValue; + return getNodeLinks(propertyDecl).enumMemberValue; } } else { @@ -11920,30 +11949,10 @@ module ts { case SyntaxKind.SetAccessor: // we allow decorators on these kinds of members, but disallow non-ambient decorators on class members in ES3 or non-class members in the typecheck pass return; - //if (node.parent.kind === SyntaxKind.ClassDeclaration) { - // if (languageVersion < ScriptTarget.ES5) { - // return grammarErrorOnNode(node, Diagnostics.Decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher); - // } - // return; - //} - //break; case SyntaxKind.Parameter: // we allow decorators on parameters, but disallow non-ambient decorators using the above rules in the typecheck pass return; - - //switch (node.kind) { - // case SyntaxKind.MethodDeclaration: - // case SyntaxKind.PropertyDeclaration: - // case SyntaxKind.GetAccessor: - // case SyntaxKind.SetAccessor: - // case SyntaxKind.Constructor: - // if (node.parent.kind === SyntaxKind.ClassDeclaration) { - // return; - // } - // break; - //} - //break; } return grammarErrorOnNode(node, Diagnostics.Decorators_cannot_appear_here); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index ae9a91e9e4e8d..2b899347fbd6d 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -111,191 +111,194 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - FromKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, - AnyKeyword = 112, - BooleanKeyword = 113, - ConstructorKeyword = 114, - DeclareKeyword = 115, - GetKeyword = 116, - ModuleKeyword = 117, - RequireKeyword = 118, - NumberKeyword = 119, - SetKeyword = 120, - StringKeyword = 121, - SymbolKeyword = 122, - TypeKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + FromKeyword = 103, + ImplementsKeyword = 104, + InterfaceKeyword = 105, + LetKeyword = 106, + PackageKeyword = 107, + PrivateKeyword = 108, + ProtectedKeyword = 109, + PublicKeyword = 110, + StaticKeyword = 111, + YieldKeyword = 112, + AnyKeyword = 113, + BooleanKeyword = 114, + ConstructorKeyword = 115, + DeclareKeyword = 116, + GetKeyword = 117, + ModuleKeyword = 118, + RequireKeyword = 119, + NumberKeyword = 120, + SetKeyword = 121, + StringKeyword = 122, + SymbolKeyword = 123, + TypeKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + ImportEqualsDeclaration = 204, + ImportDeclaration = 205, + ImportClause = 206, + NamespaceImport = 207, + NamedImports = 208, + ImportSpecifier = 209, + ExportAssignment = 210, + ExportDeclaration = 211, + NamedExports = 212, + ExportSpecifier = 213, + IncompleteDeclaration = 214, + ExternalModuleReference = 215, + CaseClause = 216, + DefaultClause = 217, + HeritageClause = 218, + CatchClause = 219, + PropertyAssignment = 220, + ShorthandPropertyAssignment = 221, + EnumMember = 222, + SourceFile = 223, + SyntaxList = 224, + Count = 225, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 104, + LastFutureReservedWord = 112, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -303,8 +306,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -328,10 +331,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -342,6 +346,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -372,6 +377,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -940,6 +948,11 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getResolvedSignature(node: CallLikeExpression): Signature; + serializeTypeOfNode(node: Node): string; + serializeParameterTypesOfNode(node: Node): string[]; + serializeReturnTypeOfNode(node: Node): string; + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1029,6 +1042,7 @@ declare module "typescript" { exportAssignmentSymbol?: Symbol; unionType?: UnionType; resolvedExports?: SymbolTable; + decoratorMetadata?: DecoratorMetadata[]; } interface TransientSymbol extends Symbol, SymbolLinks { } @@ -1044,11 +1058,18 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + EmitDecorate = 256, + EmitDecoratedType = 512, + EmitDecoratedParamTypes = 1024, + EmitDecoratedReturnType = 2048, + AmbientDecorator = 4096, + ConditionallyRemoved = 8192, } interface NodeLinks { resolvedType?: Type; resolvedSignature?: Signature; resolvedSymbol?: Symbol; + resolvedDecoratorMetadata?: DecoratorMetadata; flags?: NodeCheckFlags; enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; @@ -1174,6 +1195,39 @@ declare module "typescript" { inferredTypes: Type[]; failedTypeParameterIndex?: number; } + interface DecoratorUsage { + ambient?: boolean; + targets?: number; + } + interface DecoratorMetadata { + symbol: Symbol; + arguments: any[]; + } + const enum DecoratorFlags { + ModuleDeclaration = 1, + ImportDeclaration = 2, + ClassDeclaration = 4, + InterfaceDeclaration = 8, + FunctionDeclaration = 16, + EnumDeclaration = 32, + EnumMember = 64, + Constructor = 128, + PropertyDeclaration = 256, + MethodDeclaration = 512, + AccessorDeclaration = 1024, + ParameterDeclaration = 2048, + VariableDeclaration = 4096, + AllTargets = 8191, + BuiltIn = 65536, + UserDefinedAmbient = 131072, + Ambient = 196608, + DecoratorTargetsMask = 8191, + ES3ValidTargetMask = 2052, + NonAmbientValidTargetMask = 3844, + DecoratorFunctionValidTargetMask = 4, + MemberDecoratorFunctionValidTargetsMask = 1792, + ParameterDecoratorFunctionValidTargetsMask = 2048, + } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1229,7 +1283,8 @@ declare module "typescript" { version?: boolean; watch?: boolean; stripInternal?: boolean; - [option: string]: string | number | boolean; + define?: string[]; + [option: string]: string | number | boolean | string[]; } const enum ModuleKind { None = 0, @@ -1260,6 +1315,7 @@ declare module "typescript" { paramType?: DiagnosticMessage; error?: DiagnosticMessage; experimental?: boolean; + multiple?: boolean; } const enum CharacterCodes { nullCharacter = 0, diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index a2f2a706eaa36..95a5caa43edc5 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -351,559 +351,568 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - FromKeyword = 102, + FromKeyword = 103, >FromKeyword : SyntaxKind - ImplementsKeyword = 103, + ImplementsKeyword = 104, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 104, + InterfaceKeyword = 105, >InterfaceKeyword : SyntaxKind - LetKeyword = 105, + LetKeyword = 106, >LetKeyword : SyntaxKind - PackageKeyword = 106, + PackageKeyword = 107, >PackageKeyword : SyntaxKind - PrivateKeyword = 107, + PrivateKeyword = 108, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 108, + ProtectedKeyword = 109, >ProtectedKeyword : SyntaxKind - PublicKeyword = 109, + PublicKeyword = 110, >PublicKeyword : SyntaxKind - StaticKeyword = 110, + StaticKeyword = 111, >StaticKeyword : SyntaxKind - YieldKeyword = 111, + YieldKeyword = 112, >YieldKeyword : SyntaxKind - AnyKeyword = 112, + AnyKeyword = 113, >AnyKeyword : SyntaxKind - BooleanKeyword = 113, + BooleanKeyword = 114, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 114, + ConstructorKeyword = 115, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 115, + DeclareKeyword = 116, >DeclareKeyword : SyntaxKind - GetKeyword = 116, + GetKeyword = 117, >GetKeyword : SyntaxKind - ModuleKeyword = 117, + ModuleKeyword = 118, >ModuleKeyword : SyntaxKind - RequireKeyword = 118, + RequireKeyword = 119, >RequireKeyword : SyntaxKind - NumberKeyword = 119, + NumberKeyword = 120, >NumberKeyword : SyntaxKind - SetKeyword = 120, + SetKeyword = 121, >SetKeyword : SyntaxKind - StringKeyword = 121, + StringKeyword = 122, >StringKeyword : SyntaxKind - SymbolKeyword = 122, + SymbolKeyword = 123, >SymbolKeyword : SyntaxKind - TypeKeyword = 123, + TypeKeyword = 124, >TypeKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + ImportEqualsDeclaration = 204, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 205, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 206, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 207, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 208, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 209, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 210, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 211, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 212, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 213, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + IncompleteDeclaration = 214, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 215, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 216, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 217, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 218, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 219, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 220, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 221, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 222, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 223, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 224, >SyntaxList : SyntaxKind - Count = 222, + Count = 225, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 103, + FirstFutureReservedWord = 104, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 111, + LastFutureReservedWord = 112, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -927,10 +936,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -996,16 +1005,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1036,6 +1048,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1130,6 +1147,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -3057,6 +3082,33 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getResolvedSignature(node: CallLikeExpression): Signature; +>getResolvedSignature : (node: CallExpression | NewExpression | TaggedTemplateExpression) => Signature +>node : CallExpression | NewExpression | TaggedTemplateExpression +>CallLikeExpression : CallExpression | NewExpression | TaggedTemplateExpression +>Signature : Signature + + serializeTypeOfNode(node: Node): string; +>serializeTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + serializeParameterTypesOfNode(node: Node): string[]; +>serializeParameterTypesOfNode : (node: Node) => string[] +>node : Node +>Node : Node + + serializeReturnTypeOfNode(node: Node): string; +>serializeReturnTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; +>getMetadataForSymbol : (symbol: Symbol) => DecoratorMetadata[] +>symbol : Symbol +>Symbol : Symbol +>DecoratorMetadata : DecoratorMetadata } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3329,6 +3381,10 @@ declare module "typescript" { resolvedExports?: SymbolTable; >resolvedExports : SymbolTable >SymbolTable : SymbolTable + + decoratorMetadata?: DecoratorMetadata[]; +>decoratorMetadata : DecoratorMetadata[] +>DecoratorMetadata : DecoratorMetadata } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol @@ -3368,6 +3424,24 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + EmitDecorate = 256, +>EmitDecorate : NodeCheckFlags + + EmitDecoratedType = 512, +>EmitDecoratedType : NodeCheckFlags + + EmitDecoratedParamTypes = 1024, +>EmitDecoratedParamTypes : NodeCheckFlags + + EmitDecoratedReturnType = 2048, +>EmitDecoratedReturnType : NodeCheckFlags + + AmbientDecorator = 4096, +>AmbientDecorator : NodeCheckFlags + + ConditionallyRemoved = 8192, +>ConditionallyRemoved : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -3384,6 +3458,10 @@ declare module "typescript" { >resolvedSymbol : Symbol >Symbol : Symbol + resolvedDecoratorMetadata?: DecoratorMetadata; +>resolvedDecoratorMetadata : DecoratorMetadata +>DecoratorMetadata : DecoratorMetadata + flags?: NodeCheckFlags; >flags : NodeCheckFlags >NodeCheckFlags : NodeCheckFlags @@ -3759,6 +3837,97 @@ declare module "typescript" { failedTypeParameterIndex?: number; >failedTypeParameterIndex : number + } + interface DecoratorUsage { +>DecoratorUsage : DecoratorUsage + + ambient?: boolean; +>ambient : boolean + + targets?: number; +>targets : number + } + interface DecoratorMetadata { +>DecoratorMetadata : DecoratorMetadata + + symbol: Symbol; +>symbol : Symbol +>Symbol : Symbol + + arguments: any[]; +>arguments : any[] + } + const enum DecoratorFlags { +>DecoratorFlags : DecoratorFlags + + ModuleDeclaration = 1, +>ModuleDeclaration : DecoratorFlags + + ImportDeclaration = 2, +>ImportDeclaration : DecoratorFlags + + ClassDeclaration = 4, +>ClassDeclaration : DecoratorFlags + + InterfaceDeclaration = 8, +>InterfaceDeclaration : DecoratorFlags + + FunctionDeclaration = 16, +>FunctionDeclaration : DecoratorFlags + + EnumDeclaration = 32, +>EnumDeclaration : DecoratorFlags + + EnumMember = 64, +>EnumMember : DecoratorFlags + + Constructor = 128, +>Constructor : DecoratorFlags + + PropertyDeclaration = 256, +>PropertyDeclaration : DecoratorFlags + + MethodDeclaration = 512, +>MethodDeclaration : DecoratorFlags + + AccessorDeclaration = 1024, +>AccessorDeclaration : DecoratorFlags + + ParameterDeclaration = 2048, +>ParameterDeclaration : DecoratorFlags + + VariableDeclaration = 4096, +>VariableDeclaration : DecoratorFlags + + AllTargets = 8191, +>AllTargets : DecoratorFlags + + BuiltIn = 65536, +>BuiltIn : DecoratorFlags + + UserDefinedAmbient = 131072, +>UserDefinedAmbient : DecoratorFlags + + Ambient = 196608, +>Ambient : DecoratorFlags + + DecoratorTargetsMask = 8191, +>DecoratorTargetsMask : DecoratorFlags + + ES3ValidTargetMask = 2052, +>ES3ValidTargetMask : DecoratorFlags + + NonAmbientValidTargetMask = 3844, +>NonAmbientValidTargetMask : DecoratorFlags + + DecoratorFunctionValidTargetMask = 4, +>DecoratorFunctionValidTargetMask : DecoratorFlags + + MemberDecoratorFunctionValidTargetsMask = 1792, +>MemberDecoratorFunctionValidTargetsMask : DecoratorFlags + + ParameterDecoratorFunctionValidTargetsMask = 2048, +>ParameterDecoratorFunctionValidTargetsMask : DecoratorFlags } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -3921,7 +4090,10 @@ declare module "typescript" { stripInternal?: boolean; >stripInternal : boolean - [option: string]: string | number | boolean; + define?: string[]; +>define : string[] + + [option: string]: string | number | boolean | string[]; >option : string } const enum ModuleKind { @@ -4004,6 +4176,9 @@ declare module "typescript" { experimental?: boolean; >experimental : boolean + + multiple?: boolean; +>multiple : boolean } const enum CharacterCodes { >CharacterCodes : CharacterCodes diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 13b3e4f068ac0..c84287533a35d 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -142,191 +142,194 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - FromKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, - AnyKeyword = 112, - BooleanKeyword = 113, - ConstructorKeyword = 114, - DeclareKeyword = 115, - GetKeyword = 116, - ModuleKeyword = 117, - RequireKeyword = 118, - NumberKeyword = 119, - SetKeyword = 120, - StringKeyword = 121, - SymbolKeyword = 122, - TypeKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + FromKeyword = 103, + ImplementsKeyword = 104, + InterfaceKeyword = 105, + LetKeyword = 106, + PackageKeyword = 107, + PrivateKeyword = 108, + ProtectedKeyword = 109, + PublicKeyword = 110, + StaticKeyword = 111, + YieldKeyword = 112, + AnyKeyword = 113, + BooleanKeyword = 114, + ConstructorKeyword = 115, + DeclareKeyword = 116, + GetKeyword = 117, + ModuleKeyword = 118, + RequireKeyword = 119, + NumberKeyword = 120, + SetKeyword = 121, + StringKeyword = 122, + SymbolKeyword = 123, + TypeKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + ImportEqualsDeclaration = 204, + ImportDeclaration = 205, + ImportClause = 206, + NamespaceImport = 207, + NamedImports = 208, + ImportSpecifier = 209, + ExportAssignment = 210, + ExportDeclaration = 211, + NamedExports = 212, + ExportSpecifier = 213, + IncompleteDeclaration = 214, + ExternalModuleReference = 215, + CaseClause = 216, + DefaultClause = 217, + HeritageClause = 218, + CatchClause = 219, + PropertyAssignment = 220, + ShorthandPropertyAssignment = 221, + EnumMember = 222, + SourceFile = 223, + SyntaxList = 224, + Count = 225, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 104, + LastFutureReservedWord = 112, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -334,8 +337,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -359,10 +362,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -373,6 +377,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -403,6 +408,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -971,6 +979,11 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getResolvedSignature(node: CallLikeExpression): Signature; + serializeTypeOfNode(node: Node): string; + serializeParameterTypesOfNode(node: Node): string[]; + serializeReturnTypeOfNode(node: Node): string; + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1060,6 +1073,7 @@ declare module "typescript" { exportAssignmentSymbol?: Symbol; unionType?: UnionType; resolvedExports?: SymbolTable; + decoratorMetadata?: DecoratorMetadata[]; } interface TransientSymbol extends Symbol, SymbolLinks { } @@ -1075,11 +1089,18 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + EmitDecorate = 256, + EmitDecoratedType = 512, + EmitDecoratedParamTypes = 1024, + EmitDecoratedReturnType = 2048, + AmbientDecorator = 4096, + ConditionallyRemoved = 8192, } interface NodeLinks { resolvedType?: Type; resolvedSignature?: Signature; resolvedSymbol?: Symbol; + resolvedDecoratorMetadata?: DecoratorMetadata; flags?: NodeCheckFlags; enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; @@ -1205,6 +1226,39 @@ declare module "typescript" { inferredTypes: Type[]; failedTypeParameterIndex?: number; } + interface DecoratorUsage { + ambient?: boolean; + targets?: number; + } + interface DecoratorMetadata { + symbol: Symbol; + arguments: any[]; + } + const enum DecoratorFlags { + ModuleDeclaration = 1, + ImportDeclaration = 2, + ClassDeclaration = 4, + InterfaceDeclaration = 8, + FunctionDeclaration = 16, + EnumDeclaration = 32, + EnumMember = 64, + Constructor = 128, + PropertyDeclaration = 256, + MethodDeclaration = 512, + AccessorDeclaration = 1024, + ParameterDeclaration = 2048, + VariableDeclaration = 4096, + AllTargets = 8191, + BuiltIn = 65536, + UserDefinedAmbient = 131072, + Ambient = 196608, + DecoratorTargetsMask = 8191, + ES3ValidTargetMask = 2052, + NonAmbientValidTargetMask = 3844, + DecoratorFunctionValidTargetMask = 4, + MemberDecoratorFunctionValidTargetsMask = 1792, + ParameterDecoratorFunctionValidTargetsMask = 2048, + } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1260,7 +1314,8 @@ declare module "typescript" { version?: boolean; watch?: boolean; stripInternal?: boolean; - [option: string]: string | number | boolean; + define?: string[]; + [option: string]: string | number | boolean | string[]; } const enum ModuleKind { None = 0, @@ -1291,6 +1346,7 @@ declare module "typescript" { paramType?: DiagnosticMessage; error?: DiagnosticMessage; experimental?: boolean; + multiple?: boolean; } const enum CharacterCodes { nullCharacter = 0, @@ -2028,25 +2084,25 @@ function delint(sourceFile) { delintNode(sourceFile); function delintNode(node) { switch (node.kind) { - case 181 /* ForStatement */: - case 182 /* ForInStatement */: - case 180 /* WhileStatement */: - case 179 /* DoStatement */: - if (node.statement.kind !== 174 /* Block */) { + case 183 /* ForStatement */: + case 184 /* ForInStatement */: + case 182 /* WhileStatement */: + case 181 /* DoStatement */: + if (node.statement.kind !== 176 /* Block */) { report(node, "A looping statement's contents should be wrapped in a block body."); } break; - case 178 /* IfStatement */: + case 180 /* IfStatement */: var ifStatement = node; - if (ifStatement.thenStatement.kind !== 174 /* Block */) { + if (ifStatement.thenStatement.kind !== 176 /* Block */) { report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body."); } if (ifStatement.elseStatement && - ifStatement.elseStatement.kind !== 174 /* Block */ && ifStatement.elseStatement.kind !== 178 /* IfStatement */) { + ifStatement.elseStatement.kind !== 176 /* Block */ && ifStatement.elseStatement.kind !== 180 /* IfStatement */) { report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body."); } break; - case 167 /* BinaryExpression */: + case 169 /* BinaryExpression */: var op = node.operatorToken.kind; if (op === 28 /* EqualsEqualsToken */ || op === 29 /* ExclamationEqualsToken */) { report(node, "Use '===' and '!=='."); diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 0adce16104c7f..6ae63264c4a59 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -497,559 +497,568 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - FromKeyword = 102, + FromKeyword = 103, >FromKeyword : SyntaxKind - ImplementsKeyword = 103, + ImplementsKeyword = 104, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 104, + InterfaceKeyword = 105, >InterfaceKeyword : SyntaxKind - LetKeyword = 105, + LetKeyword = 106, >LetKeyword : SyntaxKind - PackageKeyword = 106, + PackageKeyword = 107, >PackageKeyword : SyntaxKind - PrivateKeyword = 107, + PrivateKeyword = 108, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 108, + ProtectedKeyword = 109, >ProtectedKeyword : SyntaxKind - PublicKeyword = 109, + PublicKeyword = 110, >PublicKeyword : SyntaxKind - StaticKeyword = 110, + StaticKeyword = 111, >StaticKeyword : SyntaxKind - YieldKeyword = 111, + YieldKeyword = 112, >YieldKeyword : SyntaxKind - AnyKeyword = 112, + AnyKeyword = 113, >AnyKeyword : SyntaxKind - BooleanKeyword = 113, + BooleanKeyword = 114, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 114, + ConstructorKeyword = 115, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 115, + DeclareKeyword = 116, >DeclareKeyword : SyntaxKind - GetKeyword = 116, + GetKeyword = 117, >GetKeyword : SyntaxKind - ModuleKeyword = 117, + ModuleKeyword = 118, >ModuleKeyword : SyntaxKind - RequireKeyword = 118, + RequireKeyword = 119, >RequireKeyword : SyntaxKind - NumberKeyword = 119, + NumberKeyword = 120, >NumberKeyword : SyntaxKind - SetKeyword = 120, + SetKeyword = 121, >SetKeyword : SyntaxKind - StringKeyword = 121, + StringKeyword = 122, >StringKeyword : SyntaxKind - SymbolKeyword = 122, + SymbolKeyword = 123, >SymbolKeyword : SyntaxKind - TypeKeyword = 123, + TypeKeyword = 124, >TypeKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + ImportEqualsDeclaration = 204, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 205, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 206, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 207, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 208, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 209, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 210, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 211, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 212, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 213, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + IncompleteDeclaration = 214, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 215, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 216, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 217, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 218, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 219, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 220, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 221, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 222, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 223, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 224, >SyntaxList : SyntaxKind - Count = 222, + Count = 225, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 103, + FirstFutureReservedWord = 104, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 111, + LastFutureReservedWord = 112, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1073,10 +1082,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1142,16 +1151,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1182,6 +1194,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1276,6 +1293,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -3203,6 +3228,33 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getResolvedSignature(node: CallLikeExpression): Signature; +>getResolvedSignature : (node: CallExpression | NewExpression | TaggedTemplateExpression) => Signature +>node : CallExpression | NewExpression | TaggedTemplateExpression +>CallLikeExpression : CallExpression | NewExpression | TaggedTemplateExpression +>Signature : Signature + + serializeTypeOfNode(node: Node): string; +>serializeTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + serializeParameterTypesOfNode(node: Node): string[]; +>serializeParameterTypesOfNode : (node: Node) => string[] +>node : Node +>Node : Node + + serializeReturnTypeOfNode(node: Node): string; +>serializeReturnTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; +>getMetadataForSymbol : (symbol: Symbol) => DecoratorMetadata[] +>symbol : Symbol +>Symbol : Symbol +>DecoratorMetadata : DecoratorMetadata } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3475,6 +3527,10 @@ declare module "typescript" { resolvedExports?: SymbolTable; >resolvedExports : SymbolTable >SymbolTable : SymbolTable + + decoratorMetadata?: DecoratorMetadata[]; +>decoratorMetadata : DecoratorMetadata[] +>DecoratorMetadata : DecoratorMetadata } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol @@ -3514,6 +3570,24 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + EmitDecorate = 256, +>EmitDecorate : NodeCheckFlags + + EmitDecoratedType = 512, +>EmitDecoratedType : NodeCheckFlags + + EmitDecoratedParamTypes = 1024, +>EmitDecoratedParamTypes : NodeCheckFlags + + EmitDecoratedReturnType = 2048, +>EmitDecoratedReturnType : NodeCheckFlags + + AmbientDecorator = 4096, +>AmbientDecorator : NodeCheckFlags + + ConditionallyRemoved = 8192, +>ConditionallyRemoved : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -3530,6 +3604,10 @@ declare module "typescript" { >resolvedSymbol : Symbol >Symbol : Symbol + resolvedDecoratorMetadata?: DecoratorMetadata; +>resolvedDecoratorMetadata : DecoratorMetadata +>DecoratorMetadata : DecoratorMetadata + flags?: NodeCheckFlags; >flags : NodeCheckFlags >NodeCheckFlags : NodeCheckFlags @@ -3905,6 +3983,97 @@ declare module "typescript" { failedTypeParameterIndex?: number; >failedTypeParameterIndex : number + } + interface DecoratorUsage { +>DecoratorUsage : DecoratorUsage + + ambient?: boolean; +>ambient : boolean + + targets?: number; +>targets : number + } + interface DecoratorMetadata { +>DecoratorMetadata : DecoratorMetadata + + symbol: Symbol; +>symbol : Symbol +>Symbol : Symbol + + arguments: any[]; +>arguments : any[] + } + const enum DecoratorFlags { +>DecoratorFlags : DecoratorFlags + + ModuleDeclaration = 1, +>ModuleDeclaration : DecoratorFlags + + ImportDeclaration = 2, +>ImportDeclaration : DecoratorFlags + + ClassDeclaration = 4, +>ClassDeclaration : DecoratorFlags + + InterfaceDeclaration = 8, +>InterfaceDeclaration : DecoratorFlags + + FunctionDeclaration = 16, +>FunctionDeclaration : DecoratorFlags + + EnumDeclaration = 32, +>EnumDeclaration : DecoratorFlags + + EnumMember = 64, +>EnumMember : DecoratorFlags + + Constructor = 128, +>Constructor : DecoratorFlags + + PropertyDeclaration = 256, +>PropertyDeclaration : DecoratorFlags + + MethodDeclaration = 512, +>MethodDeclaration : DecoratorFlags + + AccessorDeclaration = 1024, +>AccessorDeclaration : DecoratorFlags + + ParameterDeclaration = 2048, +>ParameterDeclaration : DecoratorFlags + + VariableDeclaration = 4096, +>VariableDeclaration : DecoratorFlags + + AllTargets = 8191, +>AllTargets : DecoratorFlags + + BuiltIn = 65536, +>BuiltIn : DecoratorFlags + + UserDefinedAmbient = 131072, +>UserDefinedAmbient : DecoratorFlags + + Ambient = 196608, +>Ambient : DecoratorFlags + + DecoratorTargetsMask = 8191, +>DecoratorTargetsMask : DecoratorFlags + + ES3ValidTargetMask = 2052, +>ES3ValidTargetMask : DecoratorFlags + + NonAmbientValidTargetMask = 3844, +>NonAmbientValidTargetMask : DecoratorFlags + + DecoratorFunctionValidTargetMask = 4, +>DecoratorFunctionValidTargetMask : DecoratorFlags + + MemberDecoratorFunctionValidTargetsMask = 1792, +>MemberDecoratorFunctionValidTargetsMask : DecoratorFlags + + ParameterDecoratorFunctionValidTargetsMask = 2048, +>ParameterDecoratorFunctionValidTargetsMask : DecoratorFlags } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -4067,7 +4236,10 @@ declare module "typescript" { stripInternal?: boolean; >stripInternal : boolean - [option: string]: string | number | boolean; + define?: string[]; +>define : string[] + + [option: string]: string | number | boolean | string[]; >option : string } const enum ModuleKind { @@ -4150,6 +4322,9 @@ declare module "typescript" { experimental?: boolean; >experimental : boolean + + multiple?: boolean; +>multiple : boolean } const enum CharacterCodes { >CharacterCodes : CharacterCodes diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 4d9d0def9d91a..224d488ec84e9 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -143,191 +143,194 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - FromKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, - AnyKeyword = 112, - BooleanKeyword = 113, - ConstructorKeyword = 114, - DeclareKeyword = 115, - GetKeyword = 116, - ModuleKeyword = 117, - RequireKeyword = 118, - NumberKeyword = 119, - SetKeyword = 120, - StringKeyword = 121, - SymbolKeyword = 122, - TypeKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + FromKeyword = 103, + ImplementsKeyword = 104, + InterfaceKeyword = 105, + LetKeyword = 106, + PackageKeyword = 107, + PrivateKeyword = 108, + ProtectedKeyword = 109, + PublicKeyword = 110, + StaticKeyword = 111, + YieldKeyword = 112, + AnyKeyword = 113, + BooleanKeyword = 114, + ConstructorKeyword = 115, + DeclareKeyword = 116, + GetKeyword = 117, + ModuleKeyword = 118, + RequireKeyword = 119, + NumberKeyword = 120, + SetKeyword = 121, + StringKeyword = 122, + SymbolKeyword = 123, + TypeKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + ImportEqualsDeclaration = 204, + ImportDeclaration = 205, + ImportClause = 206, + NamespaceImport = 207, + NamedImports = 208, + ImportSpecifier = 209, + ExportAssignment = 210, + ExportDeclaration = 211, + NamedExports = 212, + ExportSpecifier = 213, + IncompleteDeclaration = 214, + ExternalModuleReference = 215, + CaseClause = 216, + DefaultClause = 217, + HeritageClause = 218, + CatchClause = 219, + PropertyAssignment = 220, + ShorthandPropertyAssignment = 221, + EnumMember = 222, + SourceFile = 223, + SyntaxList = 224, + Count = 225, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 104, + LastFutureReservedWord = 112, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -335,8 +338,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -360,10 +363,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -374,6 +378,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -404,6 +409,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -972,6 +980,11 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getResolvedSignature(node: CallLikeExpression): Signature; + serializeTypeOfNode(node: Node): string; + serializeParameterTypesOfNode(node: Node): string[]; + serializeReturnTypeOfNode(node: Node): string; + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1061,6 +1074,7 @@ declare module "typescript" { exportAssignmentSymbol?: Symbol; unionType?: UnionType; resolvedExports?: SymbolTable; + decoratorMetadata?: DecoratorMetadata[]; } interface TransientSymbol extends Symbol, SymbolLinks { } @@ -1076,11 +1090,18 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + EmitDecorate = 256, + EmitDecoratedType = 512, + EmitDecoratedParamTypes = 1024, + EmitDecoratedReturnType = 2048, + AmbientDecorator = 4096, + ConditionallyRemoved = 8192, } interface NodeLinks { resolvedType?: Type; resolvedSignature?: Signature; resolvedSymbol?: Symbol; + resolvedDecoratorMetadata?: DecoratorMetadata; flags?: NodeCheckFlags; enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; @@ -1206,6 +1227,39 @@ declare module "typescript" { inferredTypes: Type[]; failedTypeParameterIndex?: number; } + interface DecoratorUsage { + ambient?: boolean; + targets?: number; + } + interface DecoratorMetadata { + symbol: Symbol; + arguments: any[]; + } + const enum DecoratorFlags { + ModuleDeclaration = 1, + ImportDeclaration = 2, + ClassDeclaration = 4, + InterfaceDeclaration = 8, + FunctionDeclaration = 16, + EnumDeclaration = 32, + EnumMember = 64, + Constructor = 128, + PropertyDeclaration = 256, + MethodDeclaration = 512, + AccessorDeclaration = 1024, + ParameterDeclaration = 2048, + VariableDeclaration = 4096, + AllTargets = 8191, + BuiltIn = 65536, + UserDefinedAmbient = 131072, + Ambient = 196608, + DecoratorTargetsMask = 8191, + ES3ValidTargetMask = 2052, + NonAmbientValidTargetMask = 3844, + DecoratorFunctionValidTargetMask = 4, + MemberDecoratorFunctionValidTargetsMask = 1792, + ParameterDecoratorFunctionValidTargetsMask = 2048, + } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1261,7 +1315,8 @@ declare module "typescript" { version?: boolean; watch?: boolean; stripInternal?: boolean; - [option: string]: string | number | boolean; + define?: string[]; + [option: string]: string | number | boolean | string[]; } const enum ModuleKind { None = 0, @@ -1292,6 +1347,7 @@ declare module "typescript" { paramType?: DiagnosticMessage; error?: DiagnosticMessage; experimental?: boolean; + multiple?: boolean; } const enum CharacterCodes { nullCharacter = 0, diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index ad758be0ab1d8..71d6a76b3feae 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -447,559 +447,568 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - FromKeyword = 102, + FromKeyword = 103, >FromKeyword : SyntaxKind - ImplementsKeyword = 103, + ImplementsKeyword = 104, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 104, + InterfaceKeyword = 105, >InterfaceKeyword : SyntaxKind - LetKeyword = 105, + LetKeyword = 106, >LetKeyword : SyntaxKind - PackageKeyword = 106, + PackageKeyword = 107, >PackageKeyword : SyntaxKind - PrivateKeyword = 107, + PrivateKeyword = 108, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 108, + ProtectedKeyword = 109, >ProtectedKeyword : SyntaxKind - PublicKeyword = 109, + PublicKeyword = 110, >PublicKeyword : SyntaxKind - StaticKeyword = 110, + StaticKeyword = 111, >StaticKeyword : SyntaxKind - YieldKeyword = 111, + YieldKeyword = 112, >YieldKeyword : SyntaxKind - AnyKeyword = 112, + AnyKeyword = 113, >AnyKeyword : SyntaxKind - BooleanKeyword = 113, + BooleanKeyword = 114, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 114, + ConstructorKeyword = 115, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 115, + DeclareKeyword = 116, >DeclareKeyword : SyntaxKind - GetKeyword = 116, + GetKeyword = 117, >GetKeyword : SyntaxKind - ModuleKeyword = 117, + ModuleKeyword = 118, >ModuleKeyword : SyntaxKind - RequireKeyword = 118, + RequireKeyword = 119, >RequireKeyword : SyntaxKind - NumberKeyword = 119, + NumberKeyword = 120, >NumberKeyword : SyntaxKind - SetKeyword = 120, + SetKeyword = 121, >SetKeyword : SyntaxKind - StringKeyword = 121, + StringKeyword = 122, >StringKeyword : SyntaxKind - SymbolKeyword = 122, + SymbolKeyword = 123, >SymbolKeyword : SyntaxKind - TypeKeyword = 123, + TypeKeyword = 124, >TypeKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + ImportEqualsDeclaration = 204, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 205, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 206, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 207, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 208, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 209, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 210, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 211, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 212, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 213, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + IncompleteDeclaration = 214, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 215, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 216, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 217, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 218, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 219, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 220, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 221, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 222, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 223, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 224, >SyntaxList : SyntaxKind - Count = 222, + Count = 225, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 103, + FirstFutureReservedWord = 104, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 111, + LastFutureReservedWord = 112, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1023,10 +1032,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1092,16 +1101,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1132,6 +1144,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1226,6 +1243,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -3153,6 +3178,33 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getResolvedSignature(node: CallLikeExpression): Signature; +>getResolvedSignature : (node: CallExpression | NewExpression | TaggedTemplateExpression) => Signature +>node : CallExpression | NewExpression | TaggedTemplateExpression +>CallLikeExpression : CallExpression | NewExpression | TaggedTemplateExpression +>Signature : Signature + + serializeTypeOfNode(node: Node): string; +>serializeTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + serializeParameterTypesOfNode(node: Node): string[]; +>serializeParameterTypesOfNode : (node: Node) => string[] +>node : Node +>Node : Node + + serializeReturnTypeOfNode(node: Node): string; +>serializeReturnTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; +>getMetadataForSymbol : (symbol: Symbol) => DecoratorMetadata[] +>symbol : Symbol +>Symbol : Symbol +>DecoratorMetadata : DecoratorMetadata } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3425,6 +3477,10 @@ declare module "typescript" { resolvedExports?: SymbolTable; >resolvedExports : SymbolTable >SymbolTable : SymbolTable + + decoratorMetadata?: DecoratorMetadata[]; +>decoratorMetadata : DecoratorMetadata[] +>DecoratorMetadata : DecoratorMetadata } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol @@ -3464,6 +3520,24 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + EmitDecorate = 256, +>EmitDecorate : NodeCheckFlags + + EmitDecoratedType = 512, +>EmitDecoratedType : NodeCheckFlags + + EmitDecoratedParamTypes = 1024, +>EmitDecoratedParamTypes : NodeCheckFlags + + EmitDecoratedReturnType = 2048, +>EmitDecoratedReturnType : NodeCheckFlags + + AmbientDecorator = 4096, +>AmbientDecorator : NodeCheckFlags + + ConditionallyRemoved = 8192, +>ConditionallyRemoved : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -3480,6 +3554,10 @@ declare module "typescript" { >resolvedSymbol : Symbol >Symbol : Symbol + resolvedDecoratorMetadata?: DecoratorMetadata; +>resolvedDecoratorMetadata : DecoratorMetadata +>DecoratorMetadata : DecoratorMetadata + flags?: NodeCheckFlags; >flags : NodeCheckFlags >NodeCheckFlags : NodeCheckFlags @@ -3855,6 +3933,97 @@ declare module "typescript" { failedTypeParameterIndex?: number; >failedTypeParameterIndex : number + } + interface DecoratorUsage { +>DecoratorUsage : DecoratorUsage + + ambient?: boolean; +>ambient : boolean + + targets?: number; +>targets : number + } + interface DecoratorMetadata { +>DecoratorMetadata : DecoratorMetadata + + symbol: Symbol; +>symbol : Symbol +>Symbol : Symbol + + arguments: any[]; +>arguments : any[] + } + const enum DecoratorFlags { +>DecoratorFlags : DecoratorFlags + + ModuleDeclaration = 1, +>ModuleDeclaration : DecoratorFlags + + ImportDeclaration = 2, +>ImportDeclaration : DecoratorFlags + + ClassDeclaration = 4, +>ClassDeclaration : DecoratorFlags + + InterfaceDeclaration = 8, +>InterfaceDeclaration : DecoratorFlags + + FunctionDeclaration = 16, +>FunctionDeclaration : DecoratorFlags + + EnumDeclaration = 32, +>EnumDeclaration : DecoratorFlags + + EnumMember = 64, +>EnumMember : DecoratorFlags + + Constructor = 128, +>Constructor : DecoratorFlags + + PropertyDeclaration = 256, +>PropertyDeclaration : DecoratorFlags + + MethodDeclaration = 512, +>MethodDeclaration : DecoratorFlags + + AccessorDeclaration = 1024, +>AccessorDeclaration : DecoratorFlags + + ParameterDeclaration = 2048, +>ParameterDeclaration : DecoratorFlags + + VariableDeclaration = 4096, +>VariableDeclaration : DecoratorFlags + + AllTargets = 8191, +>AllTargets : DecoratorFlags + + BuiltIn = 65536, +>BuiltIn : DecoratorFlags + + UserDefinedAmbient = 131072, +>UserDefinedAmbient : DecoratorFlags + + Ambient = 196608, +>Ambient : DecoratorFlags + + DecoratorTargetsMask = 8191, +>DecoratorTargetsMask : DecoratorFlags + + ES3ValidTargetMask = 2052, +>ES3ValidTargetMask : DecoratorFlags + + NonAmbientValidTargetMask = 3844, +>NonAmbientValidTargetMask : DecoratorFlags + + DecoratorFunctionValidTargetMask = 4, +>DecoratorFunctionValidTargetMask : DecoratorFlags + + MemberDecoratorFunctionValidTargetsMask = 1792, +>MemberDecoratorFunctionValidTargetsMask : DecoratorFlags + + ParameterDecoratorFunctionValidTargetsMask = 2048, +>ParameterDecoratorFunctionValidTargetsMask : DecoratorFlags } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -4017,7 +4186,10 @@ declare module "typescript" { stripInternal?: boolean; >stripInternal : boolean - [option: string]: string | number | boolean; + define?: string[]; +>define : string[] + + [option: string]: string | number | boolean | string[]; >option : string } const enum ModuleKind { @@ -4100,6 +4272,9 @@ declare module "typescript" { experimental?: boolean; >experimental : boolean + + multiple?: boolean; +>multiple : boolean } const enum CharacterCodes { >CharacterCodes : CharacterCodes diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 25cb4af9e42b4..73157d64aa4cf 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -180,191 +180,194 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - FromKeyword = 102, - ImplementsKeyword = 103, - InterfaceKeyword = 104, - LetKeyword = 105, - PackageKeyword = 106, - PrivateKeyword = 107, - ProtectedKeyword = 108, - PublicKeyword = 109, - StaticKeyword = 110, - YieldKeyword = 111, - AnyKeyword = 112, - BooleanKeyword = 113, - ConstructorKeyword = 114, - DeclareKeyword = 115, - GetKeyword = 116, - ModuleKeyword = 117, - RequireKeyword = 118, - NumberKeyword = 119, - SetKeyword = 120, - StringKeyword = 121, - SymbolKeyword = 122, - TypeKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - ImportEqualsDeclaration = 202, - ImportDeclaration = 203, - ImportClause = 204, - NamespaceImport = 205, - NamedImports = 206, - ImportSpecifier = 207, - ExportAssignment = 208, - ExportDeclaration = 209, - NamedExports = 210, - ExportSpecifier = 211, - ExternalModuleReference = 212, - CaseClause = 213, - DefaultClause = 214, - HeritageClause = 215, - CatchClause = 216, - PropertyAssignment = 217, - ShorthandPropertyAssignment = 218, - EnumMember = 219, - SourceFile = 220, - SyntaxList = 221, - Count = 222, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 103, - LastFutureReservedWord = 111, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + FromKeyword = 103, + ImplementsKeyword = 104, + InterfaceKeyword = 105, + LetKeyword = 106, + PackageKeyword = 107, + PrivateKeyword = 108, + ProtectedKeyword = 109, + PublicKeyword = 110, + StaticKeyword = 111, + YieldKeyword = 112, + AnyKeyword = 113, + BooleanKeyword = 114, + ConstructorKeyword = 115, + DeclareKeyword = 116, + GetKeyword = 117, + ModuleKeyword = 118, + RequireKeyword = 119, + NumberKeyword = 120, + SetKeyword = 121, + StringKeyword = 122, + SymbolKeyword = 123, + TypeKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + ImportEqualsDeclaration = 204, + ImportDeclaration = 205, + ImportClause = 206, + NamespaceImport = 207, + NamedImports = 208, + ImportSpecifier = 209, + ExportAssignment = 210, + ExportDeclaration = 211, + NamedExports = 212, + ExportSpecifier = 213, + IncompleteDeclaration = 214, + ExternalModuleReference = 215, + CaseClause = 216, + DefaultClause = 217, + HeritageClause = 218, + CatchClause = 219, + PropertyAssignment = 220, + ShorthandPropertyAssignment = 221, + EnumMember = 222, + SourceFile = 223, + SyntaxList = 224, + Count = 225, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 104, + LastFutureReservedWord = 112, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -372,8 +375,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -397,10 +400,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -411,6 +415,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -441,6 +446,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -1009,6 +1017,11 @@ declare module "typescript" { isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; + getResolvedSignature(node: CallLikeExpression): Signature; + serializeTypeOfNode(node: Node): string; + serializeParameterTypesOfNode(node: Node): string[]; + serializeReturnTypeOfNode(node: Node): string; + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1098,6 +1111,7 @@ declare module "typescript" { exportAssignmentSymbol?: Symbol; unionType?: UnionType; resolvedExports?: SymbolTable; + decoratorMetadata?: DecoratorMetadata[]; } interface TransientSymbol extends Symbol, SymbolLinks { } @@ -1113,11 +1127,18 @@ declare module "typescript" { SuperStatic = 32, ContextChecked = 64, EnumValuesComputed = 128, + EmitDecorate = 256, + EmitDecoratedType = 512, + EmitDecoratedParamTypes = 1024, + EmitDecoratedReturnType = 2048, + AmbientDecorator = 4096, + ConditionallyRemoved = 8192, } interface NodeLinks { resolvedType?: Type; resolvedSignature?: Signature; resolvedSymbol?: Symbol; + resolvedDecoratorMetadata?: DecoratorMetadata; flags?: NodeCheckFlags; enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; @@ -1243,6 +1264,39 @@ declare module "typescript" { inferredTypes: Type[]; failedTypeParameterIndex?: number; } + interface DecoratorUsage { + ambient?: boolean; + targets?: number; + } + interface DecoratorMetadata { + symbol: Symbol; + arguments: any[]; + } + const enum DecoratorFlags { + ModuleDeclaration = 1, + ImportDeclaration = 2, + ClassDeclaration = 4, + InterfaceDeclaration = 8, + FunctionDeclaration = 16, + EnumDeclaration = 32, + EnumMember = 64, + Constructor = 128, + PropertyDeclaration = 256, + MethodDeclaration = 512, + AccessorDeclaration = 1024, + ParameterDeclaration = 2048, + VariableDeclaration = 4096, + AllTargets = 8191, + BuiltIn = 65536, + UserDefinedAmbient = 131072, + Ambient = 196608, + DecoratorTargetsMask = 8191, + ES3ValidTargetMask = 2052, + NonAmbientValidTargetMask = 3844, + DecoratorFunctionValidTargetMask = 4, + MemberDecoratorFunctionValidTargetsMask = 1792, + ParameterDecoratorFunctionValidTargetsMask = 2048, + } interface DiagnosticMessage { key: string; category: DiagnosticCategory; @@ -1298,7 +1352,8 @@ declare module "typescript" { version?: boolean; watch?: boolean; stripInternal?: boolean; - [option: string]: string | number | boolean; + define?: string[]; + [option: string]: string | number | boolean | string[]; } const enum ModuleKind { None = 0, @@ -1329,6 +1384,7 @@ declare module "typescript" { paramType?: DiagnosticMessage; error?: DiagnosticMessage; experimental?: boolean; + multiple?: boolean; } const enum CharacterCodes { nullCharacter = 0, diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 1283ed8095831..dad8167118ecc 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -620,559 +620,568 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - FromKeyword = 102, + FromKeyword = 103, >FromKeyword : SyntaxKind - ImplementsKeyword = 103, + ImplementsKeyword = 104, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 104, + InterfaceKeyword = 105, >InterfaceKeyword : SyntaxKind - LetKeyword = 105, + LetKeyword = 106, >LetKeyword : SyntaxKind - PackageKeyword = 106, + PackageKeyword = 107, >PackageKeyword : SyntaxKind - PrivateKeyword = 107, + PrivateKeyword = 108, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 108, + ProtectedKeyword = 109, >ProtectedKeyword : SyntaxKind - PublicKeyword = 109, + PublicKeyword = 110, >PublicKeyword : SyntaxKind - StaticKeyword = 110, + StaticKeyword = 111, >StaticKeyword : SyntaxKind - YieldKeyword = 111, + YieldKeyword = 112, >YieldKeyword : SyntaxKind - AnyKeyword = 112, + AnyKeyword = 113, >AnyKeyword : SyntaxKind - BooleanKeyword = 113, + BooleanKeyword = 114, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 114, + ConstructorKeyword = 115, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 115, + DeclareKeyword = 116, >DeclareKeyword : SyntaxKind - GetKeyword = 116, + GetKeyword = 117, >GetKeyword : SyntaxKind - ModuleKeyword = 117, + ModuleKeyword = 118, >ModuleKeyword : SyntaxKind - RequireKeyword = 118, + RequireKeyword = 119, >RequireKeyword : SyntaxKind - NumberKeyword = 119, + NumberKeyword = 120, >NumberKeyword : SyntaxKind - SetKeyword = 120, + SetKeyword = 121, >SetKeyword : SyntaxKind - StringKeyword = 121, + StringKeyword = 122, >StringKeyword : SyntaxKind - SymbolKeyword = 122, + SymbolKeyword = 123, >SymbolKeyword : SyntaxKind - TypeKeyword = 123, + TypeKeyword = 124, >TypeKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - ImportEqualsDeclaration = 202, + ImportEqualsDeclaration = 204, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 203, + ImportDeclaration = 205, >ImportDeclaration : SyntaxKind - ImportClause = 204, + ImportClause = 206, >ImportClause : SyntaxKind - NamespaceImport = 205, + NamespaceImport = 207, >NamespaceImport : SyntaxKind - NamedImports = 206, + NamedImports = 208, >NamedImports : SyntaxKind - ImportSpecifier = 207, + ImportSpecifier = 209, >ImportSpecifier : SyntaxKind - ExportAssignment = 208, + ExportAssignment = 210, >ExportAssignment : SyntaxKind - ExportDeclaration = 209, + ExportDeclaration = 211, >ExportDeclaration : SyntaxKind - NamedExports = 210, + NamedExports = 212, >NamedExports : SyntaxKind - ExportSpecifier = 211, + ExportSpecifier = 213, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 212, + IncompleteDeclaration = 214, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 215, >ExternalModuleReference : SyntaxKind - CaseClause = 213, + CaseClause = 216, >CaseClause : SyntaxKind - DefaultClause = 214, + DefaultClause = 217, >DefaultClause : SyntaxKind - HeritageClause = 215, + HeritageClause = 218, >HeritageClause : SyntaxKind - CatchClause = 216, + CatchClause = 219, >CatchClause : SyntaxKind - PropertyAssignment = 217, + PropertyAssignment = 220, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 218, + ShorthandPropertyAssignment = 221, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 219, + EnumMember = 222, >EnumMember : SyntaxKind - SourceFile = 220, + SourceFile = 223, >SourceFile : SyntaxKind - SyntaxList = 221, + SyntaxList = 224, >SyntaxList : SyntaxKind - Count = 222, + Count = 225, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 103, + FirstFutureReservedWord = 104, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 111, + LastFutureReservedWord = 112, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1196,10 +1205,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1265,16 +1274,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1305,6 +1317,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1399,6 +1416,14 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -3326,6 +3351,33 @@ declare module "typescript" { >location : Node >Node : Node >name : string + + getResolvedSignature(node: CallLikeExpression): Signature; +>getResolvedSignature : (node: CallExpression | NewExpression | TaggedTemplateExpression) => Signature +>node : CallExpression | NewExpression | TaggedTemplateExpression +>CallLikeExpression : CallExpression | NewExpression | TaggedTemplateExpression +>Signature : Signature + + serializeTypeOfNode(node: Node): string; +>serializeTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + serializeParameterTypesOfNode(node: Node): string[]; +>serializeParameterTypesOfNode : (node: Node) => string[] +>node : Node +>Node : Node + + serializeReturnTypeOfNode(node: Node): string; +>serializeReturnTypeOfNode : (node: Node) => string +>node : Node +>Node : Node + + getMetadataForSymbol(symbol: Symbol): DecoratorMetadata[]; +>getMetadataForSymbol : (symbol: Symbol) => DecoratorMetadata[] +>symbol : Symbol +>Symbol : Symbol +>DecoratorMetadata : DecoratorMetadata } const enum SymbolFlags { >SymbolFlags : SymbolFlags @@ -3598,6 +3650,10 @@ declare module "typescript" { resolvedExports?: SymbolTable; >resolvedExports : SymbolTable >SymbolTable : SymbolTable + + decoratorMetadata?: DecoratorMetadata[]; +>decoratorMetadata : DecoratorMetadata[] +>DecoratorMetadata : DecoratorMetadata } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol @@ -3637,6 +3693,24 @@ declare module "typescript" { EnumValuesComputed = 128, >EnumValuesComputed : NodeCheckFlags + + EmitDecorate = 256, +>EmitDecorate : NodeCheckFlags + + EmitDecoratedType = 512, +>EmitDecoratedType : NodeCheckFlags + + EmitDecoratedParamTypes = 1024, +>EmitDecoratedParamTypes : NodeCheckFlags + + EmitDecoratedReturnType = 2048, +>EmitDecoratedReturnType : NodeCheckFlags + + AmbientDecorator = 4096, +>AmbientDecorator : NodeCheckFlags + + ConditionallyRemoved = 8192, +>ConditionallyRemoved : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -3653,6 +3727,10 @@ declare module "typescript" { >resolvedSymbol : Symbol >Symbol : Symbol + resolvedDecoratorMetadata?: DecoratorMetadata; +>resolvedDecoratorMetadata : DecoratorMetadata +>DecoratorMetadata : DecoratorMetadata + flags?: NodeCheckFlags; >flags : NodeCheckFlags >NodeCheckFlags : NodeCheckFlags @@ -4028,6 +4106,97 @@ declare module "typescript" { failedTypeParameterIndex?: number; >failedTypeParameterIndex : number + } + interface DecoratorUsage { +>DecoratorUsage : DecoratorUsage + + ambient?: boolean; +>ambient : boolean + + targets?: number; +>targets : number + } + interface DecoratorMetadata { +>DecoratorMetadata : DecoratorMetadata + + symbol: Symbol; +>symbol : Symbol +>Symbol : Symbol + + arguments: any[]; +>arguments : any[] + } + const enum DecoratorFlags { +>DecoratorFlags : DecoratorFlags + + ModuleDeclaration = 1, +>ModuleDeclaration : DecoratorFlags + + ImportDeclaration = 2, +>ImportDeclaration : DecoratorFlags + + ClassDeclaration = 4, +>ClassDeclaration : DecoratorFlags + + InterfaceDeclaration = 8, +>InterfaceDeclaration : DecoratorFlags + + FunctionDeclaration = 16, +>FunctionDeclaration : DecoratorFlags + + EnumDeclaration = 32, +>EnumDeclaration : DecoratorFlags + + EnumMember = 64, +>EnumMember : DecoratorFlags + + Constructor = 128, +>Constructor : DecoratorFlags + + PropertyDeclaration = 256, +>PropertyDeclaration : DecoratorFlags + + MethodDeclaration = 512, +>MethodDeclaration : DecoratorFlags + + AccessorDeclaration = 1024, +>AccessorDeclaration : DecoratorFlags + + ParameterDeclaration = 2048, +>ParameterDeclaration : DecoratorFlags + + VariableDeclaration = 4096, +>VariableDeclaration : DecoratorFlags + + AllTargets = 8191, +>AllTargets : DecoratorFlags + + BuiltIn = 65536, +>BuiltIn : DecoratorFlags + + UserDefinedAmbient = 131072, +>UserDefinedAmbient : DecoratorFlags + + Ambient = 196608, +>Ambient : DecoratorFlags + + DecoratorTargetsMask = 8191, +>DecoratorTargetsMask : DecoratorFlags + + ES3ValidTargetMask = 2052, +>ES3ValidTargetMask : DecoratorFlags + + NonAmbientValidTargetMask = 3844, +>NonAmbientValidTargetMask : DecoratorFlags + + DecoratorFunctionValidTargetMask = 4, +>DecoratorFunctionValidTargetMask : DecoratorFlags + + MemberDecoratorFunctionValidTargetsMask = 1792, +>MemberDecoratorFunctionValidTargetsMask : DecoratorFlags + + ParameterDecoratorFunctionValidTargetsMask = 2048, +>ParameterDecoratorFunctionValidTargetsMask : DecoratorFlags } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage @@ -4190,7 +4359,10 @@ declare module "typescript" { stripInternal?: boolean; >stripInternal : boolean - [option: string]: string | number | boolean; + define?: string[]; +>define : string[] + + [option: string]: string | number | boolean | string[]; >option : string } const enum ModuleKind { @@ -4273,6 +4445,9 @@ declare module "typescript" { experimental?: boolean; >experimental : boolean + + multiple?: boolean; +>multiple : boolean } const enum CharacterCodes { >CharacterCodes : CharacterCodes diff --git a/tests/baselines/reference/computedPropertyNames23_ES5.js b/tests/baselines/reference/computedPropertyNames23_ES5.js index ad5f6f8da6969..b80b8f20843a6 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES5.js +++ b/tests/baselines/reference/computedPropertyNames23_ES5.js @@ -18,6 +18,6 @@ var C = (function () { C.prototype[(_a = {}, _a[this.bar()] = 1, _a)[0]] = function () { }; + var _a; return C; })(); -var _a; diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 94a933a2d2bfd..0808b7ba478a7 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -37,6 +37,6 @@ var C = (function (_super) { C.prototype[(_a = {}, _a[super.bar.call(this)] = 1, _a)[0]] = function () { }; + var _a; return C; })(Base); -var _a; diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index b8f42ba7c331b..04e7350ad3a7f 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,10 +1,30 @@ -error TS2318: Cannot find global type 'IArguments'. +error TS2468: Cannot find global value 'conditional'. error TS2318: Cannot find global type 'Boolean'. +error TS2468: Cannot find global value 'decorator'. +error TS2318: Cannot find global type 'IArguments'. +error TS2468: Cannot find global value 'type'. +error TS2468: Cannot find global value 'returntype'. +error TS2468: Cannot find global value 'paramtypes'. +error TS2468: Cannot find global value 'obsolete'. +error TS2318: Cannot find global type 'MemberDecoratorFunction'. +error TS2318: Cannot find global type 'DecoratorFunction'. +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'ParameterDecoratorFunction'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). -!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2468: Cannot find global value 'conditional'. !!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2468: Cannot find global value 'decorator'. +!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2468: Cannot find global value 'type'. +!!! error TS2468: Cannot find global value 'returntype'. +!!! error TS2468: Cannot find global value 'paramtypes'. +!!! error TS2468: Cannot find global value 'obsolete'. +!!! error TS2318: Cannot find global type 'MemberDecoratorFunction'. +!!! error TS2318: Cannot find global type 'DecoratorFunction'. +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'ParameterDecoratorFunction'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// var x; diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 85485dd65012a..6a7e9a24f70df 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,21 +1,41 @@ -error TS2318: Cannot find global type 'String'. error TS2318: Cannot find global type 'RegExp'. -error TS2318: Cannot find global type 'Object'. -error TS2318: Cannot find global type 'Number'. +error TS2468: Cannot find global value 'type'. +error TS2318: Cannot find global type 'String'. +error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'DecoratorFunction'. +error TS2468: Cannot find global value 'conditional'. error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'Number'. +error TS2468: Cannot find global value 'returntype'. +error TS2468: Cannot find global value 'paramtypes'. +error TS2468: Cannot find global value 'obsolete'. +error TS2468: Cannot find global value 'decorator'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'MemberDecoratorFunction'. error TS2318: Cannot find global type 'Function'. error TS2318: Cannot find global type 'Boolean'. -error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'ParameterDecoratorFunction'. -!!! error TS2318: Cannot find global type 'String'. !!! error TS2318: Cannot find global type 'RegExp'. -!!! error TS2318: Cannot find global type 'Object'. -!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2468: Cannot find global value 'type'. +!!! error TS2318: Cannot find global type 'String'. +!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'DecoratorFunction'. +!!! error TS2468: Cannot find global value 'conditional'. !!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2468: Cannot find global value 'returntype'. +!!! error TS2468: Cannot find global value 'paramtypes'. +!!! error TS2468: Cannot find global value 'obsolete'. +!!! error TS2468: Cannot find global value 'decorator'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'MemberDecoratorFunction'. !!! error TS2318: Cannot find global type 'Function'. !!! error TS2318: Cannot find global type 'Boolean'. -!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'ParameterDecoratorFunction'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///