diff --git a/Jakefile b/Jakefile index 3a19812b958a5..dd09085800cae 100644 --- a/Jakefile +++ b/Jakefile @@ -39,6 +39,7 @@ var compilerSources = [ "utilities.ts", "binder.ts", "checker.ts", + "declarationEmitter.ts", "emitter.ts", "program.ts", "commandLineParser.ts", @@ -57,6 +58,7 @@ var servicesSources = [ "utilities.ts", "binder.ts", "checker.ts", + "declarationEmitter.ts", "emitter.ts", "program.ts", "commandLineParser.ts", @@ -65,7 +67,7 @@ var servicesSources = [ return path.join(compilerDirectory, f); }).concat([ "breakpoints.ts", - "navigateTo.ts", + "navigateTo.ts", "navigationBar.ts", "outliningElementsCollector.ts", "patternMatcher.ts", @@ -539,7 +541,7 @@ function cleanTestDirs() { } jake.mkdirP(localRwcBaseline); - jake.mkdirP(localTest262Baseline); + jake.mkdirP(localTest262Baseline); jake.mkdirP(localBaseline); } @@ -718,7 +720,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() { var instrumenterPath = harnessDirectory + 'instrumenter.ts'; var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js'; -compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], /*useBuiltCompiler*/ true); +compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true); desc("Builds an instrumented tsc.js"); task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 423c3c316275a..88874f1741a5d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5,8 +5,23 @@ module ts { let nextNodeId = 1; let nextMergeId = 1; + // @internal + export function getNodeId(node: Node): number { + if (!node.id) node.id = nextNodeId++; + return node.id; + } + /* @internal */ export let checkTime = 0; + /* @internal */ + export function getSymbolId(symbol: Symbol): number { + if (!symbol.id) { + symbol.id = nextSymbolId++; + } + + return symbol.id; + } + export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker { let Symbol = objectAllocator.getSymbolConstructor(); let Type = objectAllocator.getTypeConstructor(); @@ -100,11 +115,17 @@ module ts { let globalIterableType: ObjectType; let anyArrayType: Type; - + let globalTypedPropertyDescriptorType: ObjectType; + let globalClassDecoratorType: ObjectType; + let globalParameterDecoratorType: ObjectType; + let globalPropertyDecoratorType: ObjectType; + let globalMethodDecoratorType: ObjectType; + let tupleTypes: Map = {}; let unionTypes: Map = {}; let stringLiteralTypes: Map = {}; let emitExtends = false; + let emitDecorate = false; let mergedSymbols: Symbol[] = []; let symbolLinks: SymbolLinks[] = []; @@ -250,13 +271,13 @@ module ts { function getSymbolLinks(symbol: Symbol): SymbolLinks { if (symbol.flags & SymbolFlags.Transient) return symbol; - if (!symbol.id) symbol.id = nextSymbolId++; - return symbolLinks[symbol.id] || (symbolLinks[symbol.id] = {}); + var id = getSymbolId(symbol); + return symbolLinks[id] || (symbolLinks[id] = {}); } function getNodeLinks(node: Node): NodeLinks { - if (!node.id) node.id = nextNodeId++; - return nodeLinks[node.id] || (nodeLinks[node.id] = {}); + let nodeId = getNodeId(node); + return nodeLinks[nodeId] || (nodeLinks[nodeId] = {}); } function getSourceFile(node: Node): SourceFile { @@ -408,6 +429,28 @@ module ts { break loop; } break; + case SyntaxKind.Decorator: + // Decorators are resolved at the class declaration. Resolving at the parameter + // or member would result in looking up locals in the method. + // + // function y() {} + // class C { + // method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter. + // } + // + if (location.parent && location.parent.kind === SyntaxKind.Parameter) { + location = location.parent; + } + // + // function y() {} + // class C { + // @y method(x, y) {} // <-- decorator y should be resolved at the class declaration, not the method. + // } + // + if (location.parent && isClassElement(location.parent)) { + location = location.parent; + } + break; } lastLocation = location; location = location.parent; @@ -512,6 +555,19 @@ module ts { node.kind === SyntaxKind.ExportAssignment; } + function getAnyImportSyntax(node: Node): AnyImportSyntax { + if (isAliasSymbolDeclaration(node)) { + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + return node; + } + + while (node.kind !== SyntaxKind.ImportDeclaration) { + node = node.parent; + } + return node; + } + } + function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration { return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined); } @@ -1122,7 +1178,7 @@ module ts { } function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult { - let aliasesToMakeVisible: ImportEqualsDeclaration[]; + let aliasesToMakeVisible: AnyImportSyntax[]; if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) { return undefined; } @@ -1132,17 +1188,19 @@ module ts { if (!isDeclarationVisible(declaration)) { // Mark the unexported alias as visible if its parent is visible // because these kind of aliases can be used to name types in declaration file - if (declaration.kind === SyntaxKind.ImportEqualsDeclaration && - !(declaration.flags & NodeFlags.Export) && - isDeclarationVisible(declaration.parent)) { + + var anyImportSyntax = getAnyImportSyntax(declaration); + if (anyImportSyntax && + !(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export + isDeclarationVisible(anyImportSyntax.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { - if (!contains(aliasesToMakeVisible, declaration)) { - aliasesToMakeVisible.push(declaration); + if (!contains(aliasesToMakeVisible, anyImportSyntax)) { + aliasesToMakeVisible.push(anyImportSyntax); } } else { - aliasesToMakeVisible = [declaration]; + aliasesToMakeVisible = [anyImportSyntax]; } return true; } @@ -1766,8 +1824,15 @@ module ts { function determineIfDeclarationIsVisible() { switch (node.kind) { - case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: + return isDeclarationVisible(node.parent.parent); + case SyntaxKind.VariableDeclaration: + if (isBindingPattern(node.name) && + !(node.name).elements.length) { + // If the binding pattern is empty, this variable declaration is not visible + return false; + } + // Otherwise fall through case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -1779,7 +1844,7 @@ module ts { // If the node is not exported or it is not ambient module element (except import declaration) if (!(getCombinedNodeFlags(node) & NodeFlags.Export) && !(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) { - return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); + return isGlobalSourceFile(parent); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent); @@ -1812,6 +1877,8 @@ module ts { case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); + // Default binding, import specifier and namespace import is visible + // only on demand so by default it is not visible case SyntaxKind.ImportClause: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: @@ -1837,6 +1904,40 @@ module ts { } } + function collectLinkedAliases(node: Identifier): Node[]{ + var exportSymbol: Symbol; + if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { + exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); + } + else if (node.parent.kind === SyntaxKind.ExportSpecifier) { + exportSymbol = getTargetOfExportSpecifier(node.parent); + } + var result: Node[] = []; + if (exportSymbol) { + buildVisibleNodeList(exportSymbol.declarations); + } + return result; + + function buildVisibleNodeList(declarations: Declaration[]) { + forEach(declarations, declaration => { + getNodeLinks(declaration).isVisible = true; + var resultNode = getAnyImportSyntax(declaration) || declaration; + if (!contains(result, resultNode)) { + result.push(resultNode); + } + + if (isInternalModuleImportEqualsDeclaration(declaration)) { + // Add the referenced top container visible + var internalModuleReference = (declaration).moduleReference; + var firstIdentifier = getFirstIdentifier(internalModuleReference); + var importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, + Diagnostics.Cannot_find_name_0, firstIdentifier); + buildVisibleNodeList(importSymbol.declarations); + } + }); + } + } + function getRootDeclaration(node: Node): Node { while (node.kind === SyntaxKind.BindingElement) { node = node.parent.parent; @@ -7181,7 +7282,6 @@ module ts { case SyntaxKind.ElementAccessExpression: { let index = (n).argumentExpression; let symbol = findSymbol((n).expression); - if (symbol && index && index.kind === SyntaxKind.StringLiteral) { let name = (index).text; let prop = getPropertyOfType(getTypeOfSymbol(symbol), name); @@ -7196,14 +7296,37 @@ module ts { } } + function isImportedNameFromExternalModule(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.PropertyAccessExpression: { + // all bindings for external module should be immutable + // so attempt to use a.b or a[b] as lhs will always fail + // no matter what b is + let symbol = findSymbol((n).expression); + return symbol && symbol.flags & SymbolFlags.Alias && isExternalModuleSymbol(resolveAlias(symbol)); + } + case SyntaxKind.ParenthesizedExpression: + return isImportedNameFromExternalModule((n).expression); + default: + return false; + } + } + if (!isReferenceOrErrorExpression(n)) { error(n, invalidReferenceMessage); return false; } + if (isConstVariableReference(n)) { error(n, constantVariableMessage); return false; } + + if (isImportedNameFromExternalModule(n)) { + error(n, invalidReferenceMessage); + } + return true; } @@ -7852,7 +7975,7 @@ module ts { // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) // Grammar checking - checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); checkVariableLikeDeclaration(node); let func = getContainingFunction(node); @@ -7954,7 +8077,7 @@ module ts { function checkPropertyDeclaration(node: PropertyDeclaration) { // Grammar checking - checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); } @@ -8093,6 +8216,10 @@ module ts { checkFunctionLikeDeclaration(node); } + function checkMissingDeclaration(node: Node) { + checkDecorators(node); + } + function checkTypeReference(node: TypeReferenceNode) { // Grammar checking checkGrammarTypeArguments(node, node.typeArguments); @@ -8484,6 +8611,60 @@ module ts { } } + /** Check a decorator */ + function checkDecorator(node: Decorator): void { + let expression: Expression = node.expression; + let exprType = checkExpression(expression); + + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + let classSymbol = getSymbolOfNode(node.parent); + let classConstructorType = getTypeOfSymbol(classSymbol); + let classDecoratorType = instantiateSingleCallFunctionType(globalClassDecoratorType, [classConstructorType]); + checkTypeAssignableTo(exprType, classDecoratorType, node); + break; + + case SyntaxKind.PropertyDeclaration: + checkTypeAssignableTo(exprType, globalPropertyDecoratorType, node); + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + let methodType = getTypeOfNode(node.parent); + let methodDecoratorType = instantiateSingleCallFunctionType(globalMethodDecoratorType, [methodType]); + checkTypeAssignableTo(exprType, methodDecoratorType, node); + break; + + case SyntaxKind.Parameter: + checkTypeAssignableTo(exprType, globalParameterDecoratorType, node); + break; + } + } + + /** Check the decorators of a node */ + function checkDecorators(node: Node): void { + if (!node.decorators) { + return; + } + + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + emitDecorate = true; + break; + + default: + return; + } + + forEach(node.decorators, checkDecorator); + } + function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || @@ -8498,6 +8679,7 @@ module ts { } function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { + checkDecorators(node); checkSignatureDeclaration(node); // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -8780,6 +8962,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 // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -8852,7 +9035,7 @@ module ts { function checkVariableStatement(node: VariableStatement) { // Grammar checking - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); forEach(node.declarationList.declarations, checkSourceElement); } @@ -9483,7 +9666,7 @@ module ts { function checkClassDeclaration(node: ClassDeclaration) { // Grammar checking checkGrammarClassDeclarationHeritageClauses(node); - + checkDecorators(node); if (node.name) { checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -9688,7 +9871,7 @@ module ts { function checkInterfaceDeclaration(node: InterfaceDeclaration) { // Grammar checking - checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { @@ -9725,7 +9908,7 @@ module ts { function checkTypeAliasDeclaration(node: TypeAliasDeclaration) { // Grammar checking - checkGrammarModifiers(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0); checkSourceElement(node.type); @@ -9747,7 +9930,7 @@ module ts { } let initializer = member.initializer; if (initializer) { - autoValue = getConstantValueForEnumMemberInitializer(initializer, enumIsConst); + autoValue = getConstantValueForEnumMemberInitializer(initializer); if (autoValue === undefined) { if (enumIsConst) { error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); @@ -9782,7 +9965,7 @@ module ts { nodeLinks.flags |= NodeCheckFlags.EnumValuesComputed; } - function getConstantValueForEnumMemberInitializer(initializer: Expression, enumIsConst: boolean): number { + function getConstantValueForEnumMemberInitializer(initializer: Expression): number { return evalConstant(initializer); function evalConstant(e: Node): number { @@ -9795,14 +9978,10 @@ module ts { switch ((e).operator) { case SyntaxKind.PlusToken: return value; case SyntaxKind.MinusToken: return -value; - case SyntaxKind.TildeToken: return enumIsConst ? ~value : undefined; + case SyntaxKind.TildeToken: return ~value; } return undefined; case SyntaxKind.BinaryExpression: - if (!enumIsConst) { - return undefined; - } - let left = evalConstant((e).left); if (left === undefined) { return undefined; @@ -9828,14 +10007,10 @@ module ts { case SyntaxKind.NumericLiteral: return +(e).text; case SyntaxKind.ParenthesizedExpression: - return enumIsConst ? evalConstant((e).expression) : undefined; + return evalConstant((e).expression); case SyntaxKind.Identifier: case SyntaxKind.ElementAccessExpression: case SyntaxKind.PropertyAccessExpression: - if (!enumIsConst) { - return undefined; - } - let member = initializer.parent; let currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); let enumType: Type; @@ -9848,19 +10023,37 @@ module ts { propertyName = (e).text; } else { + let expression: Expression; if (e.kind === SyntaxKind.ElementAccessExpression) { if ((e).argumentExpression === undefined || (e).argumentExpression.kind !== SyntaxKind.StringLiteral) { return undefined; } - enumType = getTypeOfNode((e).expression); + expression = (e).expression; propertyName = ((e).argumentExpression).text; } else { - enumType = getTypeOfNode((e).expression); + expression = (e).expression; propertyName = (e).name.text; } - if (enumType !== currentType) { + + // expression part in ElementAccess\PropertyAccess should be either identifier or dottedName + var current = expression; + while (current) { + if (current.kind === SyntaxKind.Identifier) { + break; + } + else if (current.kind === SyntaxKind.PropertyAccessExpression) { + current = (current).expression; + } + else { + return undefined; + } + } + + enumType = checkExpression(expression); + // allow references to constant members of other enums + if (!(enumType.symbol && (enumType.symbol.flags & SymbolFlags.Enum))) { return undefined; } } @@ -9868,10 +10061,12 @@ module ts { if (propertyName === undefined) { return undefined; } + let property = getPropertyOfObjectType(enumType, propertyName); if (!property || !(property.flags & SymbolFlags.EnumMember)) { return undefined; } + let propertyDecl = property.valueDeclaration; // self references are illegal if (member === propertyDecl) { @@ -9882,6 +10077,7 @@ module ts { if (!isDefinedBefore(propertyDecl, member)) { return undefined; } + return getNodeLinks(propertyDecl).enumMemberValue; } } @@ -9894,7 +10090,7 @@ module ts { } // Grammar checking - checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -9960,7 +10156,7 @@ module ts { function checkModuleDeclaration(node: ModuleDeclaration) { if (produceDiagnostics) { // Grammar checking - if (!checkGrammarModifiers(node)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -10055,7 +10251,7 @@ module ts { } function checkImportDeclaration(node: ImportDeclaration) { - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -10077,7 +10273,7 @@ module ts { } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { - checkGrammarModifiers(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & NodeFlags.Export) { @@ -10108,7 +10304,7 @@ module ts { } function checkExportDeclaration(node: ExportDeclaration) { - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers); } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { @@ -10132,7 +10328,7 @@ module ts { return; } // Grammar checking - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } if (node.expression) { @@ -10310,6 +10506,8 @@ module ts { case SyntaxKind.DebuggerStatement: checkGrammarStatementInAmbientContext(node); return; + case SyntaxKind.MissingDeclaration: + return checkMissingDeclaration(node); } } @@ -10436,6 +10634,10 @@ module ts { links.flags |= NodeCheckFlags.EmitExtends; } + if (emitDecorate) { + links.flags |= NodeCheckFlags.EmitDecorate; + } + links.flags |= NodeCheckFlags.TypeChecked; } } @@ -10883,134 +11085,7 @@ module ts { return symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length === 1 && symbol.declarations[0].kind === SyntaxKind.SourceFile; } - function isNodeDescendentOf(node: Node, ancestor: Node): boolean { - while (node) { - if (node === ancestor) return true; - node = node.parent; - } - return false; - } - - function isUniqueLocalName(name: string, container: Node): boolean { - for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { - if (node.locals && hasProperty(node.locals, name)) { - // We conservatively include alias symbols to cover cases where they're emitted as locals - if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { - return false; - } - } - } - return true; - } - - function getGeneratedNamesForSourceFile(sourceFile: SourceFile): Map { - let links = getNodeLinks(sourceFile); - let generatedNames = links.generatedNames; - if (!generatedNames) { - generatedNames = links.generatedNames = {}; - generateNames(sourceFile); - } - return generatedNames; - - function generateNames(node: Node) { - switch (node.kind) { - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.ClassDeclaration: - generateNameForFunctionOrClassDeclaration(node); - break; - case SyntaxKind.ModuleDeclaration: - generateNameForModuleOrEnum(node); - generateNames((node).body); - break; - case SyntaxKind.EnumDeclaration: - generateNameForModuleOrEnum(node); - break; - case SyntaxKind.ImportDeclaration: - generateNameForImportDeclaration(node); - break; - case SyntaxKind.ExportDeclaration: - generateNameForExportDeclaration(node); - break; - case SyntaxKind.ExportAssignment: - generateNameForExportAssignment(node); - break; - case SyntaxKind.SourceFile: - case SyntaxKind.ModuleBlock: - forEach((node).statements, generateNames); - break; - } - } - - function isExistingName(name: string) { - return hasProperty(globals, name) || hasProperty(sourceFile.identifiers, name) || hasProperty(generatedNames, name); - } - - function makeUniqueName(baseName: string): string { - let name = generateUniqueName(baseName, isExistingName); - return generatedNames[name] = name; - } - - function assignGeneratedName(node: Node, name: string) { - getNodeLinks(node).generatedName = unescapeIdentifier(name); - } - - function generateNameForFunctionOrClassDeclaration(node: Declaration) { - if (!node.name) { - assignGeneratedName(node, makeUniqueName("default")); - } - } - - function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { - if (node.name.kind === SyntaxKind.Identifier) { - let name = node.name.text; - // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name, node) ? name : makeUniqueName(name)); - } - } - - function generateNameForImportOrExportDeclaration(node: ImportDeclaration | ExportDeclaration) { - let expr = getExternalModuleName(node); - let baseName = expr.kind === SyntaxKind.StringLiteral ? - escapeIdentifier(makeIdentifierFromModuleName((expr).text)) : "module"; - assignGeneratedName(node, makeUniqueName(baseName)); - } - - function generateNameForImportDeclaration(node: ImportDeclaration) { - if (node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === SyntaxKind.NamedImports) { - generateNameForImportOrExportDeclaration(node); - } - } - - function generateNameForExportDeclaration(node: ExportDeclaration) { - if (node.moduleSpecifier) { - generateNameForImportOrExportDeclaration(node); - } - } - - function generateNameForExportAssignment(node: ExportAssignment) { - if (node.expression && node.expression.kind !== SyntaxKind.Identifier) { - assignGeneratedName(node, makeUniqueName("default")); - } - } - } - - function getGeneratedNameForNode(node: Node) { - let links = getNodeLinks(node); - if (!links.generatedName) { - getGeneratedNamesForSourceFile(getSourceFile(node)); - } - return links.generatedName; - } - - function getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string { - return getGeneratedNameForNode(container); - } - - function getLocalNameForImportDeclaration(node: ImportDeclaration): string { - return getGeneratedNameForNode(node); - } - - function getAliasNameSubstitution(symbol: Symbol): string { + function getAliasNameSubstitution(symbol: Symbol, getGeneratedNameForNode: (Node: Node) => string): string { let declaration = getDeclarationOfAliasSymbol(symbol); if (declaration && declaration.kind === SyntaxKind.ImportSpecifier) { let moduleName = getGeneratedNameForNode(declaration.parent.parent.parent); @@ -11019,7 +11094,7 @@ module ts { } } - function getExportNameSubstitution(symbol: Symbol, location: Node): string { + function getExportNameSubstitution(symbol: Symbol, location: Node, getGeneratedNameForNode: (Node: Node) => string): string { if (isExternalModuleSymbol(symbol.parent)) { var symbolName = unescapeIdentifier(symbol.name); // If this is es6 or higher, just use the name of the export @@ -11041,24 +11116,24 @@ module ts { } } - function getExpressionNameSubstitution(node: Identifier): string { + function getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (Node: Node) => string): string { let symbol = getNodeLinks(node).resolvedSymbol; if (symbol) { // Whan an identifier resolves to a parented symbol, it references an exported entity from // another declaration of the same internal module. if (symbol.parent) { - return getExportNameSubstitution(symbol, node.parent); + return getExportNameSubstitution(symbol, node.parent, getGeneratedNameForNode); } // If we reference an exported entity within the same module declaration, then whether // we prefix depends on the kind of entity. SymbolFlags.ExportHasLocal encompasses all the // kinds that we do NOT prefix. let exportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); if (symbol !== exportSymbol && !(exportSymbol.flags & SymbolFlags.ExportHasLocal)) { - return getExportNameSubstitution(exportSymbol, node.parent); + return getExportNameSubstitution(exportSymbol, node.parent, getGeneratedNameForNode); } // Named imports from ES6 import declarations are rewritten if (symbol.flags & SymbolFlags.Alias && languageVersion < ScriptTarget.ES6) { - return getAliasNameSubstitution(symbol); + return getAliasNameSubstitution(symbol, getGeneratedNameForNode); } } } @@ -11132,10 +11207,9 @@ module ts { let symbol = getNodeLinks(node).resolvedSymbol; if (symbol && (symbol.flags & SymbolFlags.EnumMember)) { - let declaration = symbol.valueDeclaration; - let constantValue: number; - if (declaration.kind === SyntaxKind.EnumMember) { - return getEnumMemberValue(declaration); + // inline property\index accesses only for const enums + if (isConstEnumDeclaration(symbol.valueDeclaration.parent)) { + return getEnumMemberValue(symbol.valueDeclaration); } } @@ -11157,10 +11231,18 @@ module ts { getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } - function isUnknownIdentifier(location: Node, name: string): boolean { - Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location"); - return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && - !hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); + function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { + var type = getTypeOfExpression(expr); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + } + + function hasGlobalName(name: string): boolean { + return hasProperty(globals, name); + } + + function resolvesToSomeValue(location: Node, name: string): boolean { + Debug.assert(!nodeIsSynthesized(location), "resolvesToSomeValue called with a synthesized location"); + return !!resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); } function getBlockScopedVariableId(n: Identifier): number { @@ -11188,10 +11270,24 @@ module ts { return undefined; } + function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type { + if (functionType === unknownType) { + return unknownType; + } + + let signature = getSingleCallSignature(functionType); + if (!signature) { + return unknownType; + } + + let instantiatedSignature = getSignatureInstantiation(signature, typeArguments); + return getOrCreateTypeFromSignature(instantiatedSignature); + } + function createResolver(): EmitResolver { return { - getGeneratedNameForNode, getExpressionNameSubstitution, + hasGlobalName, hasExportDefaultValue, isReferencedAliasDeclaration, getNodeCheckFlags, @@ -11200,10 +11296,12 @@ module ts { isImplementationOfOverload, writeTypeOfDeclaration, writeReturnTypeOfSignatureDeclaration, + writeTypeOfExpression, isSymbolAccessible, isEntityNameVisible, getConstantValue, - isUnknownIdentifier, + resolvesToSomeValue, + collectLinkedAliases, getBlockScopedVariableId, }; } @@ -11235,6 +11333,11 @@ module ts { globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); + globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalTypeSymbol("TypedPropertyDescriptor"), 1); + globalClassDecoratorType = getGlobalType("ClassDecorator"); + globalPropertyDecoratorType = getGlobalType("PropertyDecorator"); + globalMethodDecoratorType = getGlobalType("MethodDecorator"); + globalParameterDecoratorType = getGlobalType("ParameterDecorator"); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. @@ -11259,6 +11362,25 @@ module ts { // GRAMMAR CHECKING + function checkGrammarDecorators(node: Node): boolean { + if (!node.decorators) { + return false; + } + if (!nodeCanBeDecorated(node)) { + return grammarErrorOnNode(node, Diagnostics.Decorators_are_not_valid_here); + } + else if (languageVersion < ScriptTarget.ES5) { + return grammarErrorOnNode(node, Diagnostics.Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher); + } + else if (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor) { + let accessors = getAllAccessorDeclarations((node.parent).members, node); + if (accessors.firstAccessor.decorators && node === accessors.secondAccessor) { + return grammarErrorOnNode(node, Diagnostics.Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name); + } + } + return false; + } + function checkGrammarModifiers(node: Node): boolean { switch (node.kind) { case SyntaxKind.GetAccessor: @@ -11455,7 +11577,7 @@ module ts { function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { // Prevent cascading error by short-circuit let file = getSourceFileOfNode(node); - return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) || + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) || checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } @@ -11512,7 +11634,7 @@ module ts { function checkGrammarIndexSignature(node: SignatureDeclaration) { // Prevent cascading error by short-circuit - checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); } function checkGrammarForAtLeastOneTypeArgument(node: Node, typeArguments: NodeArray): boolean { @@ -11561,7 +11683,7 @@ module ts { let seenExtendsClause = false; let seenImplementsClause = false; - if (!checkGrammarModifiers(node) && node.heritageClauses) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) { for (let heritageClause of node.heritageClauses) { if (heritageClause.token === SyntaxKind.ExtendsKeyword) { if (seenExtendsClause) { @@ -12141,8 +12263,8 @@ module ts { } function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean { - // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: - // categories: + // A declare modifier is required for any top level .d.ts declaration except export=, export default, + // interfaces and imports categories: // // DeclarationElement: // ExportAssignment @@ -12156,7 +12278,8 @@ module ts { node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration || node.kind === SyntaxKind.ExportAssignment || - (node.flags & NodeFlags.Ambient)) { + (node.flags & NodeFlags.Ambient) || + (node.flags & (NodeFlags.Export | NodeFlags.Default))) { return false; } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 27fc152f534ed..23a183775e784 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -122,8 +122,10 @@ module ts { } export function addRange(to: T[], from: T[]): void { - for (let v of from) { - to.push(v); + if (to && from) { + for (let v of from) { + to.push(v); + } } } @@ -160,6 +162,39 @@ module ts { return ~low; } + export function reduceLeft(array: T[], f: (a: T, x: T) => T): T; + export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial: U): U; + export function reduceLeft(array: T[], f: (a: U, x: T) => U, initial?: U): U { + if (array) { + var count = array.length; + if (count > 0) { + var pos = 0; + var result = arguments.length <= 2 ? array[pos++] : initial; + while (pos < count) { + result = f(result, array[pos++]); + } + return result; + } + } + return initial; + } + + export function reduceRight(array: T[], f: (a: T, x: T) => T): T; + export function reduceRight(array: T[], f: (a: U, x: T) => U, initial: U): U; + export function reduceRight(array: T[], f: (a: U, x: T) => U, initial?: U): U { + if (array) { + var pos = array.length - 1; + if (pos >= 0) { + var result = arguments.length <= 2 ? array[pos--] : initial; + while (pos >= 0) { + result = f(result, array[pos--]); + } + return result; + } + } + return initial; + } + let hasOwnProperty = Object.prototype.hasOwnProperty; export function hasProperty(map: Map, key: string): boolean { diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts new file mode 100644 index 0000000000000..cf75467e1c5b4 --- /dev/null +++ b/src/compiler/declarationEmitter.ts @@ -0,0 +1,1466 @@ +/// + +module ts { + + interface ModuleElementDeclarationEmitInfo { + node: Node; + outputPos: number; + indent: number; + asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output + subModuleElementDeclarationEmitInfo?: ModuleElementDeclarationEmitInfo[]; + isVisible?: boolean; + } + + interface DeclarationEmit { + reportedDeclarationError: boolean; + moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; + synchronousDeclarationOutput: string; + referencePathsOutput: string; + } + + type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; + + interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { + getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; + } + + interface SymbolAccessibilityDiagnostic { + errorNode: Node; + diagnosticMessage: DiagnosticMessage; + typeName?: DeclarationName; + } + + export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { + let diagnostics: Diagnostic[] = []; + let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); + emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); + return diagnostics; + } + + function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { + let newLine = host.getNewLine(); + let compilerOptions = host.getCompilerOptions(); + let languageVersion = compilerOptions.target || ScriptTarget.ES3; + + let write: (s: string) => void; + let writeLine: () => void; + let increaseIndent: () => void; + let decreaseIndent: () => void; + let writeTextOfNode: (sourceFile: SourceFile, node: Node) => void; + + let writer = createAndSetNewTextWriterWithSymbolWriter(); + + let enclosingDeclaration: Node; + let currentSourceFile: SourceFile; + let reportedDeclarationError = false; + let emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; + let emit = compilerOptions.stripInternal ? stripInternal : emitNode; + + let moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = []; + let asynchronousSubModuleDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; + + // Contains the reference paths that needs to go in the declaration file. + // Collecting this separately because reference paths need to be first thing in the declaration file + // and we could be collecting these paths from multiple files into single one with --out option + let referencePathsOutput = ""; + + if (root) { + // Emitting just a single file, so emit references in this file only + if (!compilerOptions.noResolve) { + let addedGlobalFileReference = false; + forEach(root.referencedFiles, fileReference => { + let referencedFile = tryResolveScriptReference(host, root, fileReference); + + // All the references that are not going to be part of same file + if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference + shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file + !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added + + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } + } + }); + } + + emitSourceFile(root); + + // create asynchronous output for the importDeclarations + if (moduleElementDeclarationEmitInfo.length) { + let oldWriter = writer; + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.isVisible) { + Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration); + createAndSetNewTextWriterWithSymbolWriter(); + Debug.assert(aliasEmitInfo.indent === 0); + writeImportDeclaration(aliasEmitInfo.node); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + }); + setWriter(oldWriter); + } + } + else { + // Emit references corresponding to this file + let emittedReferencedFiles: SourceFile[] = []; + forEach(host.getSourceFiles(), sourceFile => { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + // Check what references need to be added + if (!compilerOptions.noResolve) { + forEach(sourceFile.referencedFiles, fileReference => { + let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); + + // If the reference file is a declaration file or an external module, emit that reference + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && + !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted + + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } + + emitSourceFile(sourceFile); + } + }); + } + + return { + reportedDeclarationError, + moduleElementDeclarationEmitInfo, + synchronousDeclarationOutput: writer.getText(), + referencePathsOutput, + } + + function hasInternalAnnotation(range: CommentRange) { + let text = currentSourceFile.text; + let comment = text.substring(range.pos, range.end); + return comment.indexOf("@internal") >= 0; + } + + function stripInternal(node: Node) { + if (node) { + let leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos); + if (forEach(leadingCommentRanges, hasInternalAnnotation)) { + return; + } + + emitNode(node); + } + } + + function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { + let writer = createTextWriter(newLine); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + setWriter(writer); + return writer; + } + + function setWriter(newWriter: EmitTextWriterWithSymbolWriter) { + writer = newWriter; + write = newWriter.write; + writeTextOfNode = newWriter.writeTextOfNode; + writeLine = newWriter.writeLine; + increaseIndent = newWriter.increaseIndent; + decreaseIndent = newWriter.decreaseIndent; + } + + function writeAsynchronousModuleElements(nodes: Node[]) { + let oldWriter = writer; + forEach(nodes, declaration => { + let nodeToCheck: Node; + if (declaration.kind === SyntaxKind.VariableDeclaration) { + nodeToCheck = declaration.parent.parent; + } else if (declaration.kind === SyntaxKind.NamedImports || declaration.kind === SyntaxKind.ImportSpecifier || declaration.kind === SyntaxKind.ImportClause) { + Debug.fail("We should be getting ImportDeclaration instead to write"); + } else { + nodeToCheck = declaration; + } + + let moduleElementEmitInfo = forEach(moduleElementDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) { + moduleElementEmitInfo = forEach(asynchronousSubModuleDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + } + + // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration + // then we don't need to write it at this point. We will write it when we actually see its declaration + // Eg. + // export function bar(a: foo.Foo) { } + // import foo = require("foo"); + // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, + // we would write alias foo declaration when we visit it since it would now be marked as visible + if (moduleElementEmitInfo) { + if (moduleElementEmitInfo.node.kind === SyntaxKind.ImportDeclaration) { + // we have to create asynchronous output only after we have collected complete information + // because it is possible to enable multiple bindings as asynchronously visible + moduleElementEmitInfo.isVisible = true; + } + else { + createAndSetNewTextWriterWithSymbolWriter(); + for (let declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); + asynchronousSubModuleDeclarationEmitInfo = []; + } + writeModuleElement(nodeToCheck); + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; + asynchronousSubModuleDeclarationEmitInfo = undefined; + } + moduleElementEmitInfo.asynchronousOutput = writer.getText(); + } + } + }); + setWriter(oldWriter); + } + + function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { + if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { + // write the aliases + if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { + writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible); + } + } + else { + // Report error + reportedDeclarationError = true; + let errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); + if (errorInfo) { + if (errorInfo.typeName) { + diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), + symbolAccesibilityResult.errorSymbolName, + symbolAccesibilityResult.errorModuleName)); + } + else { + diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + symbolAccesibilityResult.errorSymbolName, + symbolAccesibilityResult.errorModuleName)); + } + } + } + } + + function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); + } + + function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (type) { + // Write the type + emitType(type); + } + else { + resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + + function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (signature.type) { + // Write the type + emitType(signature.type); + } + else { + resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + + function emitLines(nodes: Node[]) { + for (let node of nodes) { + emit(node); + } + } + + function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + let currentWriterPos = writer.getTextPos(); + for (let node of nodes) { + if (!canEmitFn || canEmitFn(node)) { + if (currentWriterPos !== writer.getTextPos()) { + write(separator); + } + currentWriterPos = writer.getTextPos(); + eachNodeEmitFn(node); + } + } + } + + function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn); + } + + function writeJsDocComments(declaration: Node) { + if (declaration) { + let jsDocComments = getJsDocComments(declaration, currentSourceFile); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); + // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space + emitComments(currentSourceFile, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange); + } + } + + function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + emitType(type); + } + + function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName) { + switch (type.kind) { + case SyntaxKind.AnyKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.StringLiteral: + return writeTextOfNode(currentSourceFile, type); + case SyntaxKind.TypeReference: + return emitTypeReference(type); + case SyntaxKind.TypeQuery: + return emitTypeQuery(type); + case SyntaxKind.ArrayType: + return emitArrayType(type); + case SyntaxKind.TupleType: + return emitTupleType(type); + case SyntaxKind.UnionType: + return emitUnionType(type); + case SyntaxKind.ParenthesizedType: + return emitParenType(type); + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return emitSignatureDeclarationWithJsDocComments(type); + case SyntaxKind.TypeLiteral: + return emitTypeLiteral(type); + case SyntaxKind.Identifier: + return emitEntityName(type); + case SyntaxKind.QualifiedName: + return emitEntityName(type); + default: + Debug.fail("Unknown type annotation: " + type.kind); + } + + function emitEntityName(entityName: EntityName) { + let visibilityResult = resolver.isEntityNameVisible(entityName, + // Aliases can be written asynchronously so use correct enclosing declaration + entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration); + + handleSymbolAccessibilityError(visibilityResult); + writeEntityName(entityName); + + function writeEntityName(entityName: EntityName) { + if (entityName.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, entityName); + } + else { + let qualifiedName = entityName; + writeEntityName(qualifiedName.left); + write("."); + writeTextOfNode(currentSourceFile, qualifiedName.right); + } + } + } + + function emitTypeReference(type: TypeReferenceNode) { + emitEntityName(type.typeName); + if (type.typeArguments) { + write("<"); + emitCommaList(type.typeArguments, emitType); + write(">"); + } + } + + function emitTypeQuery(type: TypeQueryNode) { + write("typeof "); + emitEntityName(type.exprName); + } + + function emitArrayType(type: ArrayTypeNode) { + emitType(type.elementType); + write("[]"); + } + + function emitTupleType(type: TupleTypeNode) { + write("["); + emitCommaList(type.elementTypes, emitType); + write("]"); + } + + function emitUnionType(type: UnionTypeNode) { + emitSeparatedList(type.types, " | ", emitType); + } + + function emitParenType(type: ParenthesizedTypeNode) { + write("("); + emitType(type.type); + write(")"); + } + + function emitTypeLiteral(type: TypeLiteralNode) { + write("{"); + if (type.members.length) { + writeLine(); + increaseIndent(); + // write members + emitLines(type.members); + decreaseIndent(); + } + write("}"); + } + } + + function emitSourceFile(node: SourceFile) { + currentSourceFile = node; + enclosingDeclaration = node; + emitLines(node.statements); + } + + function emitExportAssignment(node: ExportAssignment) { + write(node.isExportEquals ? "export = " : "export default "); + if (node.expression.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, node.expression); + } + else { + write(": "); + if (node.type) { + emitType(node.type); + } + else { + writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; + resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + write(";"); + writeLine(); + + // Make all the declarations visible for the export name + if (node.expression.kind === SyntaxKind.Identifier) { + let nodes = resolver.collectLinkedAliases(node.expression); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: node + }; + } + } + + function isModuleElementVisible(node: Declaration) { + return resolver.isDeclarationVisible(node); + } + + function emitModuleElement(node: Node, isModuleElementVisible: boolean) { + if (isModuleElementVisible) { + writeModuleElement(node); + } + // Import equals declaration in internal module can become visible as part of any emit so lets make sure we add these irrespective + else if (node.kind === SyntaxKind.ImportEqualsDeclaration || + (node.parent.kind === SyntaxKind.SourceFile && isExternalModule(currentSourceFile))) { + let isVisible: boolean; + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== SyntaxKind.SourceFile) { + // Import declaration of another module that is visited async so lets put it in right spot + asynchronousSubModuleDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + else { + if (node.kind === SyntaxKind.ImportDeclaration) { + let importDeclaration = node; + if (importDeclaration.importClause) { + isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || + isVisibleNamedBinding(importDeclaration.importClause.namedBindings); + } + } + moduleElementDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + } + } + + function writeModuleElement(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + return writeFunctionDeclaration(node); + case SyntaxKind.VariableStatement: + return writeVariableStatement(node); + case SyntaxKind.InterfaceDeclaration: + return writeInterfaceDeclaration(node); + case SyntaxKind.ClassDeclaration: + return writeClassDeclaration(node); + case SyntaxKind.TypeAliasDeclaration: + return writeTypeAliasDeclaration(node); + case SyntaxKind.EnumDeclaration: + return writeEnumDeclaration(node); + case SyntaxKind.ModuleDeclaration: + return writeModuleDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return writeImportEqualsDeclaration(node); + case SyntaxKind.ImportDeclaration: + return writeImportDeclaration(node); + default: + Debug.fail("Unknown symbol kind"); + } + } + + function emitModuleElementDeclarationFlags(node: Node) { + // If the node is parented in the current source file we need to emit export declare or just export + if (node.parent === currentSourceFile) { + // If the node is exported + if (node.flags & NodeFlags.Export) { + write("export "); + } + + if (node.flags & NodeFlags.Default) { + write("default "); + } + else if (node.kind !== SyntaxKind.InterfaceDeclaration) { + write("declare "); + } + } + } + + function emitClassMemberDeclarationFlags(node: Declaration) { + if (node.flags & NodeFlags.Private) { + write("private "); + } + else if (node.flags & NodeFlags.Protected) { + write("protected "); + } + + if (node.flags & NodeFlags.Static) { + write("static "); + } + } + + function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { + // note usage of writer. methods instead of aliases created, just to make sure we are using + // correct writer especially to handle asynchronous alias writing + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + if (isInternalModuleImportEqualsDeclaration(node)) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); + write(";"); + } + else { + write("require("); + writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node)); + write(");"); + } + writer.writeLine(); + + function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, + errorNode: node, + typeName: node.name + }; + } + } + + function isVisibleNamedBinding(namedBindings: NamespaceImport | NamedImports): boolean { + if (namedBindings) { + if (namedBindings.kind === SyntaxKind.NamespaceImport) { + return resolver.isDeclarationVisible(namedBindings); + } + else { + return forEach((namedBindings).elements, namedImport => resolver.isDeclarationVisible(namedImport)); + } + } + } + + function writeImportDeclaration(node: ImportDeclaration) { + if (!node.importClause && !(node.flags & NodeFlags.Export)) { + // do not write non-exported import declarations that don't have import clauses + return; + } + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + if (node.importClause) { + let currentWriterPos = writer.getTextPos(); + if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) { + writeTextOfNode(currentSourceFile, node.importClause.name); + } + if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) { + if (currentWriterPos !== writer.getTextPos()) { + // If the default binding was emitted, write the separated + write(", "); + } + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + write("* as "); + writeTextOfNode(currentSourceFile, (node.importClause.namedBindings).name); + } + else { + write("{ "); + emitCommaList((node.importClause.namedBindings).elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible); + write(" }"); + } + } + write(" from "); + } + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + write(";"); + writer.writeLine(); + } + + function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) { + if (node.propertyName) { + writeTextOfNode(currentSourceFile, node.propertyName); + write(" as "); + } + writeTextOfNode(currentSourceFile, node.name); + } + + function emitExportSpecifier(node: ExportSpecifier) { + emitImportOrExportSpecifier(node); + + // Make all the declarations visible for the export name + let nodes = resolver.collectLinkedAliases(node.propertyName || node.name); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function emitExportDeclaration(node: ExportDeclaration) { + emitJsDocComments(node); + write("export "); + if (node.exportClause) { + write("{ "); + emitCommaList(node.exportClause.elements, emitExportSpecifier); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + } + write(";"); + writer.writeLine(); + } + + function writeModuleDeclaration(node: ModuleDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("module "); + writeTextOfNode(currentSourceFile, node.name); + while (node.body.kind !== SyntaxKind.ModuleBlock) { + node = node.body; + write("."); + writeTextOfNode(currentSourceFile, node.name); + } + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + write(" {"); + writeLine(); + increaseIndent(); + emitLines((node.body).statements); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + function writeTypeAliasDeclaration(node: TypeAliasDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("type "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); + write(";"); + writeLine(); + + function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, + errorNode: node.type, + typeName: node.name + }; + } + } + + function writeEnumDeclaration(node: EnumDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isConst(node)) { + write("const ") + } + write("enum "); + writeTextOfNode(currentSourceFile, node.name); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + } + + function emitEnumMemberDeclaration(node: EnumMember) { + emitJsDocComments(node); + writeTextOfNode(currentSourceFile, node.name); + let enumMemberValue = resolver.getConstantValue(node); + if (enumMemberValue !== undefined) { + write(" = "); + write(enumMemberValue.toString()); + } + write(","); + writeLine(); + } + + function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { + return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); + } + + function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { + function emitTypeParameter(node: TypeParameterDeclaration) { + increaseIndent(); + emitJsDocComments(node); + decreaseIndent(); + writeTextOfNode(currentSourceFile, node.name); + // If there is constraint present and this is not a type parameter of the private method emit the constraint + if (node.constraint && !isPrivateMethodTypeParameter(node)) { + write(" extends "); + if (node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { + Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || + node.parent.kind === SyntaxKind.MethodSignature || + node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + node.parent.kind === SyntaxKind.CallSignature || + node.parent.kind === SyntaxKind.ConstructSignature); + emitType(node.constraint); + } + else { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); + } + } + + function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + // Type parameter constraints are named by user so we should always be able to name it + let diagnosticMessage: DiagnosticMessage; + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; + break; + + case SyntaxKind.InterfaceDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.ConstructSignature: + diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.CallSignature: + diagnosticMessage = Diagnostics.Type_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 = Diagnostics.Type_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 = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + + default: + Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); + } + + return { + diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + + if (typeParameters) { + write("<"); + emitCommaList(typeParameters, emitTypeParameter); + write(">"); + } + } + + function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { + if (typeReferences) { + write(isImplementsList ? " implements " : " extends "); + emitCommaList(typeReferences, emitTypeOfTypeReference); + } + + function emitTypeOfTypeReference(node: TypeReferenceNode) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); + + function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + // Heritage clause is written by user so it can always be named + if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + // Class or Interface implemented/extended is inaccessible + diagnosticMessage = isImplementsList ? + Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : + Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; + } + else { + // interface is inaccessible + diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; + } + + return { + diagnosticMessage, + errorNode: node, + typeName: (node.parent.parent).name + }; + } + } + } + + function writeClassDeclaration(node: ClassDeclaration) { + function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { + if (constructorDeclaration) { + forEach(constructorDeclaration.parameters, param => { + if (param.flags & NodeFlags.AccessibilityModifier) { + emitPropertyDeclaration(param); + } + }); + } + } + + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("class "); + writeTextOfNode(currentSourceFile, node.name); + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + let baseTypeNode = getClassBaseTypeNode(node); + if (baseTypeNode) { + emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); + } + emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); + write(" {"); + writeLine(); + increaseIndent(); + emitParameterProperties(getFirstConstructorWithBody(node)); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + function writeInterfaceDeclaration(node: InterfaceDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("interface "); + writeTextOfNode(currentSourceFile, node.name); + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + function emitPropertyDeclaration(node: Declaration) { + if (hasDynamicName(node)) { + return; + } + + emitJsDocComments(node); + emitClassMemberDeclarationFlags(node); + emitVariableDeclaration(node); + write(";"); + writeLine(); + } + + function emitVariableDeclaration(node: VariableDeclaration) { + // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted + // so there is no check needed to see if declaration is visible + if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { + if (isBindingPattern(node.name)) { + emitBindingPattern(node.name); + } + else { + // If this node is a computed name, it can only be a symbol, because we've already skipped + // it if it's not a well known symbol. In that case, the text of the name will be exactly + // what we want, namely the name expression enclosed in brackets. + writeTextOfNode(currentSourceFile, node.name); + // If optional property emit ? + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { + write("?"); + } + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + } + } + } + + function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { + if (node.kind === SyntaxKind.VariableDeclaration) { + return 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; + } + // 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) { + return 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; + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + return 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; + } + else { + // Interfaces cannot have types that cannot be named + return 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; + } + } + } + + function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: node, + typeName: node.name + } : undefined; + } + + function emitBindingPattern(bindingPattern: BindingPattern) { + emitCommaList(bindingPattern.elements, emitBindingElement); + } + + function emitBindingElement(bindingElement: BindingElement) { + function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: bindingElement, + typeName: bindingElement.name + } : undefined; + } + + if (bindingElement.name) { + if (isBindingPattern(bindingElement.name)) { + emitBindingPattern(bindingElement.name); + } + else { + writeTextOfNode(currentSourceFile, bindingElement.name); + writeTypeOfDeclaration(bindingElement, /*type*/ undefined, getBindingElementTypeVisibilityError); + } + } + } + } + + function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) { + // if this is property of type literal, + // or is parameter of method/call/construct/index signature of type literal + // emit only if type is specified + if (node.type) { + write(": "); + emitType(node.type); + } + } + + function isVariableStatementVisible(node: VariableStatement) { + return forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); + } + + function writeVariableStatement(node: VariableStatement) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isLet(node.declarationList)) { + write("let "); + } + else if (isConst(node.declarationList)) { + write("const "); + } + else { + write("var "); + } + emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible); + write(";"); + writeLine(); + } + + function emitAccessorDeclaration(node: AccessorDeclaration) { + if (hasDynamicName(node)) { + return; + } + + let accessors = getAllAccessorDeclarations((node.parent).members, node); + let accessorWithTypeAnnotation: AccessorDeclaration; + + if (node === accessors.firstAccessor) { + emitJsDocComments(accessors.getAccessor); + emitJsDocComments(accessors.setAccessor); + emitClassMemberDeclarationFlags(node); + writeTextOfNode(currentSourceFile, node.name); + if (!(node.flags & NodeFlags.Private)) { + accessorWithTypeAnnotation = node; + let type = getTypeAnnotationFromAccessor(node); + if (!type) { + // couldn't get type for the first accessor, try the another one + let anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor; + type = getTypeAnnotationFromAccessor(anotherAccessor); + if (type) { + accessorWithTypeAnnotation = anotherAccessor; + } + } + writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); + } + write(";"); + writeLine(); + } + + function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression { + if (accessor) { + return accessor.kind === SyntaxKind.GetAccessor + ? accessor.type // Getter - return type + : accessor.parameters.length > 0 + ? accessor.parameters[0].type // Setter parameter type + : undefined; + } + } + + function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { + // 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; + } + 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; + } + return { + diagnosticMessage, + errorNode: accessorWithTypeAnnotation.parameters[0], + // TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name + typeName: accessorWithTypeAnnotation.name + }; + } + 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; + } + 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; + } + return { + diagnosticMessage, + errorNode: accessorWithTypeAnnotation.name, + typeName: undefined + }; + } + } + } + + function writeFunctionDeclaration(node: FunctionLikeDeclaration) { + if (hasDynamicName(node)) { + return; + } + + // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting + // so no need to verify if the declaration is visible + if (!resolver.isImplementationOfOverload(node)) { + emitJsDocComments(node); + if (node.kind === SyntaxKind.FunctionDeclaration) { + emitModuleElementDeclarationFlags(node); + } + else if (node.kind === SyntaxKind.MethodDeclaration) { + emitClassMemberDeclarationFlags(node); + } + if (node.kind === SyntaxKind.FunctionDeclaration) { + write("function "); + writeTextOfNode(currentSourceFile, node.name); + } + else if (node.kind === SyntaxKind.Constructor) { + write("constructor"); + } + else { + writeTextOfNode(currentSourceFile, node.name); + if (hasQuestionToken(node)) { + write("?"); + } + } + emitSignatureDeclaration(node); + } + } + + function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) { + emitJsDocComments(node); + emitSignatureDeclaration(node); + } + + function emitSignatureDeclaration(node: SignatureDeclaration) { + // Construct signature or constructor type write new Signature + if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { + write("new "); + } + emitTypeParameters(node.typeParameters); + if (node.kind === SyntaxKind.IndexSignature) { + write("["); + } + else { + write("("); + } + + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + + // Parameters + emitCommaList(node.parameters, emitParameterDeclaration); + + if (node.kind === SyntaxKind.IndexSignature) { + write("]"); + } + else { + write(")"); + } + + // If this is not a constructor and is not private, emit the return type + let isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType; + if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) { + // Emit type literal signature return type only if specified + if (node.type) { + write(isFunctionTypeOrConstructorType ? " => " : ": "); + emitType(node.type); + } + } + else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) { + writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); + } + + enclosingDeclaration = prevEnclosingDeclaration; + + if (!isFunctionTypeOrConstructorType) { + write(";"); + writeLine(); + } + + function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + switch (node.kind) { + 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; + 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; + 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; + 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; + } + 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; + } + 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; + } + 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; + break; + + default: + Debug.fail("This is unknown kind for signature: " + node.kind); + } + + return { + diagnosticMessage, + errorNode: node.name || node, + }; + } + } + + function emitParameterDeclaration(node: ParameterDeclaration) { + increaseIndent(); + emitJsDocComments(node); + if (node.dotDotDotToken) { + write("..."); + } + if (isBindingPattern(node.name)) { + write("_" + indexOf((node.parent).parameters, node)); + } + else { + writeTextOfNode(currentSourceFile, node.name); + } + if (node.initializer || hasQuestionToken(node)) { + write("?"); + } + decreaseIndent(); + + if (node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + node.parent.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.parent.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); + } + + function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + 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; + 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; + 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; + 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; + } + 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; + } + 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; + } + 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; + break; + + default: + Debug.fail("This is unknown parent for parameter: " + node.parent.kind); + } + + return { + diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + + function emitNode(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + return emitModuleElement(node, isModuleElementVisible(node)); + case SyntaxKind.VariableStatement: + return emitModuleElement(node, isVariableStatementVisible(node)); + case SyntaxKind.ImportDeclaration: + // Import declaration without import clause is visible, otherwise it is not visible + return emitModuleElement(node, /*isModuleElementVisible*/!(node).importClause); + case SyntaxKind.ExportDeclaration: + return emitExportDeclaration(node); + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + return writeFunctionDeclaration(node); + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.IndexSignature: + return emitSignatureDeclarationWithJsDocComments(node); + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return emitAccessorDeclaration(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return emitPropertyDeclaration(node); + case SyntaxKind.EnumMember: + return emitEnumMemberDeclaration(node); + case SyntaxKind.ExportAssignment: + return emitExportAssignment(node); + case SyntaxKind.SourceFile: + return emitSourceFile(node); + } + } + + function writeReferencePath(referencedFile: SourceFile) { + let declFileName = referencedFile.flags & NodeFlags.DeclarationFile + ? referencedFile.fileName // Declaration file, use declaration file name + : shouldEmitToOwnFile(referencedFile, compilerOptions) + ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file + : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file + + declFileName = getRelativePathToDirectoryOrUrl( + getDirectoryPath(normalizeSlashes(jsFilePath)), + declFileName, + host.getCurrentDirectory(), + host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ false); + + referencePathsOutput += "/// " + newLine; + } + } + + // @internal + export function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[]) { + let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); + // TODO(shkamat): Should we not write any declaration file if any of them can produce error, + // or should we just not write this file like we are doing now + if (!emitDeclarationResult.reportedDeclarationError) { + let declarationOutput = emitDeclarationResult.referencePathsOutput + + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo); + writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, host.getCompilerOptions().emitBOM); + } + + function getDeclarationOutput(synchronousDeclarationOutput: string, moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]) { + let appliedSyncOutputPos = 0; + let declarationOutput = ""; + // apply asynchronous additions to the synchronous output + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.asynchronousOutput) { + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); + declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo); + appliedSyncOutputPos = aliasEmitInfo.outputPos; + } + }); + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); + return declarationOutput; + } + } +} \ No newline at end of file diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index dd26ef281c4bb..d6feb59cc4c5b 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -162,6 +162,9 @@ module ts { Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, + Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, + Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, + Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, 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." }, @@ -344,7 +347,8 @@ module ts { Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" }, Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." }, Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." }, - Type_0_is_not_an_array_type_or_a_string_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." }, + Type_0_is_not_an_array_type_or_a_string_type: { code: 2495, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." }, + The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 2496, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, 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}'." }, @@ -414,6 +418,7 @@ module ts { Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4082, category: DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." }, Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, @@ -491,6 +496,5 @@ module ts { You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, - The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e1767fe8de044..789d467a08934 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -639,6 +639,18 @@ "category": "Error", "code": 1204 }, + "Decorators are only available when targeting ECMAScript 5 and higher.": { + "category": "Error", + "code": 1205 + }, + "Decorators are not valid here.": { + "category": "Error", + "code": 1206 + }, + "Decorators cannot be applied to multiple get/set accessors of the same name.": { + "category": "Error", + "code": 1207 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -1370,7 +1382,11 @@ }, "Type '{0}' is not an array type or a string type.": { "category": "Error", - "code": 2461 + "code": 2495 + }, + "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": { + "category": "Error", + "code": 2496 }, "Import declaration '{0}' is using private name '{1}'.": { @@ -1649,6 +1665,10 @@ "category": "Error", "code": 4081 }, + "Default export of the module has or is using private name '{0}'.": { + "category": "Error", + "code": 4082 + }, "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": { "category": "Error", "code": 4091 @@ -1957,9 +1977,5 @@ "Generators are not currently supported.": { "category": "Error", "code": 9001 - }, - "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": { - "category": "Error", - "code": 9002 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 205f2fe2945ef..eae0381752a18 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1,1529 +1,30 @@ /// +/// module ts { - interface EmitTextWriter { - write(s: string): void; - writeTextOfNode(sourceFile: SourceFile, node: Node): void; - writeLine(): void; - increaseIndent(): void; - decreaseIndent(): void; - getText(): string; - rawWrite(s: string): void; - writeLiteral(s: string): void; - getTextPos(): number; - getLine(): number; - getColumn(): number; - getIndent(): number; - } - - interface ExternalImportInfo { - rootNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration; - declarationNode?: ImportEqualsDeclaration | ImportClause | NamespaceImport; - namedImports?: NamedImports; - } - - interface SymbolAccessibilityDiagnostic { - errorNode: Node; - diagnosticMessage: DiagnosticMessage; - typeName?: DeclarationName; - } - - // represents one LexicalEnvironment frame to store unique generated names - interface ScopeFrame { - names: Map; - previous: ScopeFrame; - } - - type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; - - interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { - getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; - } - - interface AliasDeclarationEmitInfo { - declaration: ImportEqualsDeclaration; - outputPos: number; - indent: number; - asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output - } - - interface DeclarationEmit { - reportedDeclarationError: boolean; - aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[]; - synchronousDeclarationOutput: string; - referencePathsOutput: string; - } - - let indentStrings: string[] = ["", " "]; - export function getIndentString(level: number) { - if (indentStrings[level] === undefined) { - indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; - } - return indentStrings[level]; - } - - function getIndentSize() { - return indentStrings[1].length; - } - - export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { - if (!isDeclarationFile(sourceFile)) { - if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.fileName, ".js")) { - return true; - } - return false; - } - return false; - } - - export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { - return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); - } - - function createTextWriter(newLine: String): EmitTextWriter { - let output = ""; - let indent = 0; - let lineStart = true; - let lineCount = 0; - let linePos = 0; - - function write(s: string) { - if (s && s.length) { - if (lineStart) { - output += getIndentString(indent); - lineStart = false; - } - output += s; - } - } - - function rawWrite(s: string) { - if (s !== undefined) { - if (lineStart) { - lineStart = false; - } - output += s; - } - } - - function writeLiteral(s: string) { - if (s && s.length) { - write(s); - let lineStartsOfS = computeLineStarts(s); - if (lineStartsOfS.length > 1) { - lineCount = lineCount + lineStartsOfS.length - 1; - linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; - } - } - } - - function writeLine() { - if (!lineStart) { - output += newLine; - lineCount++; - linePos = output.length; - lineStart = true; - } - } - - function writeTextOfNode(sourceFile: SourceFile, node: Node) { - write(getSourceTextOfNodeFromSourceFile(sourceFile, node)); - } - - return { - write, - rawWrite, - writeTextOfNode, - writeLiteral, - writeLine, - increaseIndent: () => indent++, - decreaseIndent: () => indent--, - getIndent: () => indent, - getTextPos: () => output.length, - getLine: () => lineCount + 1, - getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, - getText: () => output, - }; - } - - function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { - return getLineAndCharacterOfPosition(currentSourceFile, pos).line; - } - - function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { - // If the leading comments start on different line than the start of node, write new line - if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && - getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { - writer.writeLine(); - } - } - - function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, - writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { - let emitLeadingSpace = !trailingSeparator; - forEach(comments, comment => { - if (emitLeadingSpace) { - writer.write(" "); - emitLeadingSpace = false; - } - writeComment(currentSourceFile, writer, comment, newLine); - if (comment.hasTrailingNewLine) { - writer.writeLine(); - } - else if (trailingSeparator) { - writer.write(" "); - } - else { - // Emit leading space to separate comment during next comment emit - emitLeadingSpace = true; - } - }); - } - - function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - let firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); - let lineCount = getLineStarts(currentSourceFile).length; - let firstCommentLineIndent: number; - for (let pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - let nextLineStart = (currentLine + 1) === lineCount - ? currentSourceFile.text.length + 1 - : getStartPositionOfLine(currentLine + 1, currentSourceFile); - - if (pos !== comment.pos) { - // If we are not emitting first line, we need to write the spaces to adjust the alignment - if (firstCommentLineIndent === undefined) { - firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); - } - - // These are number of spaces writer is going to write at current indent - let currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); - - // Number of spaces we want to be writing - // eg: Assume writer indent - // module m { - // /* starts at character 9 this is line 1 - // * starts at character pos 4 line --1 = 8 - 8 + 3 - // More left indented comment */ --2 = 8 - 8 + 2 - // class c { } - // } - // module m { - // /* this is line 1 -- Assume current writer indent 8 - // * line --3 = 8 - 4 + 5 - // More right indented comment */ --4 = 8 - 4 + 11 - // class c { } - // } - let spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); - if (spacesToEmit > 0) { - let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); - let indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); - - // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces - writer.rawWrite(indentSizeSpaceString); - - // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces) - while (numberOfSingleSpacesToEmit) { - writer.rawWrite(" "); - numberOfSingleSpacesToEmit--; - } - } - else { - // No spaces to emit write empty string - writer.rawWrite(""); - } - } - - // Write the comment line text - writeTrimmedCurrentLine(pos, nextLineStart); - - pos = nextLineStart; - } - } - else { - // Single line comment of style //.... - writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); - } - - function writeTrimmedCurrentLine(pos: number, nextLineStart: number) { - let end = Math.min(comment.end, nextLineStart - 1); - let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); - if (currentLineText) { - // trimmed forward and ending spaces text - writer.write(currentLineText); - if (end !== comment.end) { - writer.writeLine(); - } - } - else { - // Empty string - make sure we write empty line - writer.writeLiteral(newLine); - } - } - - function calculateIndent(pos: number, end: number) { - let currentLineIndent = 0; - for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { - if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) { - // Tabs = TabSize = indent size and go to next tabStop - currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); - } - else { - // Single space - currentLineIndent++; - } - } - - return currentLineIndent; - } - } - - function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { - return forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { - return member; - } - }); - } - - function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration) { - let firstAccessor: AccessorDeclaration; - let getAccessor: AccessorDeclaration; - let setAccessor: AccessorDeclaration; - if (hasDynamicName(accessor)) { - firstAccessor = accessor; - if (accessor.kind === SyntaxKind.GetAccessor) { - getAccessor = accessor; - } - else if (accessor.kind === SyntaxKind.SetAccessor) { - setAccessor = accessor; - } - else { - Debug.fail("Accessor has wrong kind"); - } - } - else { - forEach(declarations, (member: Declaration) => { - if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) - && (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) { - let memberName = getPropertyNameForPropertyNameNode(member.name); - let accessorName = getPropertyNameForPropertyNameNode(accessor.name); - if (memberName === accessorName) { - if (!firstAccessor) { - firstAccessor = member; - } - - if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { - getAccessor = member; - } - - if (member.kind === SyntaxKind.SetAccessor && !setAccessor) { - setAccessor = member; - } - } - } - }); - } - return { - firstAccessor, - getAccessor, - setAccessor - }; - } - - function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { - let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); - return combinePaths(newDirPath, sourceFilePath); - } - - function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string){ - let compilerOptions = host.getCompilerOptions(); - let emitOutputFilePathWithoutExtension: string; - if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); - } - else { - emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName); - } - - return emitOutputFilePathWithoutExtension + extension; - } - - function writeFile(host: EmitHost, diagnostics: Diagnostic[], fileName: string, data: string, writeByteOrderMark: boolean) { - host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => { - diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); - }); - } - - function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { - let newLine = host.getNewLine(); - let compilerOptions = host.getCompilerOptions(); - let languageVersion = compilerOptions.target || ScriptTarget.ES3; - - let write: (s: string) => void; - let writeLine: () => void; - let increaseIndent: () => void; - let decreaseIndent: () => void; - let writeTextOfNode: (sourceFile: SourceFile, node: Node) => void; - - let writer = createAndSetNewTextWriterWithSymbolWriter(); - - let enclosingDeclaration: Node; - let currentSourceFile: SourceFile; - let reportedDeclarationError = false; - let emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; - let emit = compilerOptions.stripInternal ? stripInternal : emitNode; - - let aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[] = []; - - // Contains the reference paths that needs to go in the declaration file. - // Collecting this separately because reference paths need to be first thing in the declaration file - // and we could be collecting these paths from multiple files into single one with --out option - let referencePathsOutput = ""; - - if (root) { - // Emitting just a single file, so emit references in this file only - if (!compilerOptions.noResolve) { - let addedGlobalFileReference = false; - forEach(root.referencedFiles, fileReference => { - let referencedFile = tryResolveScriptReference(host, root, fileReference); - - // All the references that are not going to be part of same file - if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference - shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file - !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added - - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; - } - } - }); - } - - emitSourceFile(root); - } - else { - // Emit references corresponding to this file - let emittedReferencedFiles: SourceFile[] = []; - forEach(host.getSourceFiles(), sourceFile => { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - // Check what references need to be added - if (!compilerOptions.noResolve) { - forEach(sourceFile.referencedFiles, fileReference => { - let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); - - // If the reference file is a declaration file or an external module, emit that reference - if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && - !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted - - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); - } - - emitSourceFile(sourceFile); - } - }); - } - - return { - reportedDeclarationError, - aliasDeclarationEmitInfo, - synchronousDeclarationOutput: writer.getText(), - referencePathsOutput, - } - - function hasInternalAnnotation(range: CommentRange) { - let text = currentSourceFile.text; - let comment = text.substring(range.pos, range.end); - return comment.indexOf("@internal") >= 0; - } - - function stripInternal(node: Node) { - if (node) { - let leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos); - if (forEach(leadingCommentRanges, hasInternalAnnotation)) { - return; - } - - emitNode(node); - } - } - - function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { - let writer = createTextWriter(newLine); - writer.trackSymbol = trackSymbol; - writer.writeKeyword = writer.write; - writer.writeOperator = writer.write; - writer.writePunctuation = writer.write; - writer.writeSpace = writer.write; - writer.writeStringLiteral = writer.writeLiteral; - writer.writeParameter = writer.write; - writer.writeSymbol = writer.write; - setWriter(writer); - return writer; - } - - function setWriter(newWriter: EmitTextWriterWithSymbolWriter) { - writer = newWriter; - write = newWriter.write; - writeTextOfNode = newWriter.writeTextOfNode; - writeLine = newWriter.writeLine; - increaseIndent = newWriter.increaseIndent; - decreaseIndent = newWriter.decreaseIndent; - } - - function writeAsychronousImportEqualsDeclarations(importEqualsDeclarations: ImportEqualsDeclaration[]) { - let oldWriter = writer; - forEach(importEqualsDeclarations, aliasToWrite => { - let aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); - // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration - // then we don't need to write it at this point. We will write it when we actually see its declaration - // Eg. - // export function bar(a: foo.Foo) { } - // import foo = require("foo"); - // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, - // we would write alias foo declaration when we visit it since it would now be marked as visible - if (aliasEmitInfo) { - createAndSetNewTextWriterWithSymbolWriter(); - for (let declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); - } - writeImportEqualsDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); - } - }); - setWriter(oldWriter); - } - - function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { - // write the aliases - if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsychronousImportEqualsDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); - } - } - else { - // Report error - reportedDeclarationError = true; - let errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); - if (errorInfo) { - if (errorInfo.typeName) { - diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); - } - else { - diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); - } - } - } - } - - function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); - } - - function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (type) { - // Write the type - emitType(type); - } - else { - resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); - } - } - - function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (signature.type) { - // Write the type - emitType(signature.type); - } - else { - resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); - } - } - - function emitLines(nodes: Node[]) { - for (let node of nodes) { - emit(node); - } - } - - function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void) { - let currentWriterPos = writer.getTextPos(); - for (let node of nodes) { - if (currentWriterPos !== writer.getTextPos()) { - write(separator); - } - currentWriterPos = writer.getTextPos(); - eachNodeEmitFn(node); - } - } - - function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void) { - emitSeparatedList(nodes, ", ", eachNodeEmitFn); - } - - function writeJsDocComments(declaration: Node) { - if (declaration) { - let jsDocComments = getJsDocComments(declaration, currentSourceFile); - emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); - // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange); - } - } - - function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - emitType(type); - } - - function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName) { - switch (type.kind) { - case SyntaxKind.AnyKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.StringLiteral: - return writeTextOfNode(currentSourceFile, type); - case SyntaxKind.TypeReference: - return emitTypeReference(type); - case SyntaxKind.TypeQuery: - return emitTypeQuery(type); - case SyntaxKind.ArrayType: - return emitArrayType(type); - case SyntaxKind.TupleType: - return emitTupleType(type); - case SyntaxKind.UnionType: - return emitUnionType(type); - case SyntaxKind.ParenthesizedType: - return emitParenType(type); - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return emitSignatureDeclarationWithJsDocComments(type); - case SyntaxKind.TypeLiteral: - return emitTypeLiteral(type); - case SyntaxKind.Identifier: - return emitEntityName(type); - case SyntaxKind.QualifiedName: - return emitEntityName(type); - default: - Debug.fail("Unknown type annotation: " + type.kind); - } - - function emitEntityName(entityName: EntityName) { - let visibilityResult = resolver.isEntityNameVisible(entityName, - // Aliases can be written asynchronously so use correct enclosing declaration - entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration); - - handleSymbolAccessibilityError(visibilityResult); - writeEntityName(entityName); - - function writeEntityName(entityName: EntityName) { - if (entityName.kind === SyntaxKind.Identifier) { - writeTextOfNode(currentSourceFile, entityName); - } - else { - let qualifiedName = entityName; - writeEntityName(qualifiedName.left); - write("."); - writeTextOfNode(currentSourceFile, qualifiedName.right); - } - } - } - - function emitTypeReference(type: TypeReferenceNode) { - emitEntityName(type.typeName); - if (type.typeArguments) { - write("<"); - emitCommaList(type.typeArguments, emitType); - write(">"); - } - } - - function emitTypeQuery(type: TypeQueryNode) { - write("typeof "); - emitEntityName(type.exprName); - } - - function emitArrayType(type: ArrayTypeNode) { - emitType(type.elementType); - write("[]"); - } - - function emitTupleType(type: TupleTypeNode) { - write("["); - emitCommaList(type.elementTypes, emitType); - write("]"); - } - - function emitUnionType(type: UnionTypeNode) { - emitSeparatedList(type.types, " | ", emitType); - } - - function emitParenType(type: ParenthesizedTypeNode) { - write("("); - emitType(type.type); - write(")"); - } - - function emitTypeLiteral(type: TypeLiteralNode) { - write("{"); - if (type.members.length) { - writeLine(); - increaseIndent(); - // write members - emitLines(type.members); - decreaseIndent(); - } - write("}"); - } - } - - function emitSourceFile(node: SourceFile) { - currentSourceFile = node; - enclosingDeclaration = node; - emitLines(node.statements); - } - - function emitExportAssignment(node: ExportAssignment) { - write(node.isExportEquals ? "export = " : "export default "); - writeTextOfNode(currentSourceFile, node.expression); - write(";"); - writeLine(); - } - - function emitModuleElementDeclarationFlags(node: Node) { - // If the node is parented in the current source file we need to emit export declare or just export - if (node.parent === currentSourceFile) { - // If the node is exported - if (node.flags & NodeFlags.Export) { - write("export "); - } - - if (node.kind !== SyntaxKind.InterfaceDeclaration) { - write("declare "); - } - } - } - - function emitClassMemberDeclarationFlags(node: Declaration) { - if (node.flags & NodeFlags.Private) { - write("private "); - } - else if (node.flags & NodeFlags.Protected) { - write("protected "); - } - - if (node.flags & NodeFlags.Static) { - write("static "); - } - } - - function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - let nodeEmitInfo = { - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - hasWritten: resolver.isDeclarationVisible(node) - }; - aliasDeclarationEmitInfo.push(nodeEmitInfo); - if (nodeEmitInfo.hasWritten) { - writeImportEqualsDeclaration(node); - } - } - - function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { - // note usage of writer. methods instead of aliases created, just to make sure we are using - // correct writer especially to handle asynchronous alias writing - emitJsDocComments(node); - if (node.flags & NodeFlags.Export) { - write("export "); - } - write("import "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - if (isInternalModuleImportEqualsDeclaration(node)) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); - write(";"); - } - else { - write("require("); - writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node)); - write(");"); - } - writer.writeLine(); - - function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - return { - diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, - errorNode: node, - typeName: node.name - }; - } - } - - function emitModuleDeclaration(node: ModuleDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("module "); - writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== SyntaxKind.ModuleBlock) { - node = node.body; - write("."); - writeTextOfNode(currentSourceFile, node.name); - } - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - write(" {"); - writeLine(); - increaseIndent(); - emitLines((node.body).statements); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - - function emitTypeAliasDeclaration(node: TypeAliasDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("type "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); - write(";"); - writeLine(); - } - function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - return { - diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, - errorNode: node.type, - typeName: node.name - }; - } - } - - function emitEnumDeclaration(node: EnumDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isConst(node)) { - write("const ") - } - write("enum "); - writeTextOfNode(currentSourceFile, node.name); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - } - } - - function emitEnumMemberDeclaration(node: EnumMember) { - emitJsDocComments(node); - writeTextOfNode(currentSourceFile, node.name); - let enumMemberValue = resolver.getConstantValue(node); - if (enumMemberValue !== undefined) { - write(" = "); - write(enumMemberValue.toString()); - } - write(","); - writeLine(); - } - - function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { - return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); - } - - function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { - function emitTypeParameter(node: TypeParameterDeclaration) { - increaseIndent(); - emitJsDocComments(node); - decreaseIndent(); - writeTextOfNode(currentSourceFile, node.name); - // If there is constraint present and this is not a type parameter of the private method emit the constraint - if (node.constraint && !isPrivateMethodTypeParameter(node)) { - write(" extends "); - if (node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { - Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || - node.parent.kind === SyntaxKind.MethodSignature || - node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - node.parent.kind === SyntaxKind.CallSignature || - node.parent.kind === SyntaxKind.ConstructSignature); - emitType(node.constraint); - } - else { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); - } - } - - function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - // Type parameter constraints are named by user so we should always be able to name it - let diagnosticMessage: DiagnosticMessage; - switch (node.parent.kind) { - case SyntaxKind.ClassDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; - break; - - case SyntaxKind.InterfaceDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.ConstructSignature: - diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.CallSignature: - diagnosticMessage = Diagnostics.Type_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 = Diagnostics.Type_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 = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; - } - break; - - case SyntaxKind.FunctionDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; - - default: - Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); - } - - return { - diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - - if (typeParameters) { - write("<"); - emitCommaList(typeParameters, emitTypeParameter); - write(">"); - } - } - - function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { - if (typeReferences) { - write(isImplementsList ? " implements " : " extends "); - emitCommaList(typeReferences, emitTypeOfTypeReference); - } - - function emitTypeOfTypeReference(node: TypeReferenceNode) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); - - function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - // Heritage clause is written by user so it can always be named - if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - // Class or Interface implemented/extended is inaccessible - diagnosticMessage = isImplementsList ? - Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : - Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; - } - else { - // interface is inaccessible - diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; - } - - return { - diagnosticMessage, - errorNode: node, - typeName: (node.parent.parent).name - }; - } - } - } - - function emitClassDeclaration(node: ClassDeclaration) { - function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { - if (constructorDeclaration) { - forEach(constructorDeclaration.parameters, param => { - if (param.flags & NodeFlags.AccessibilityModifier) { - emitPropertyDeclaration(param); - } - }); - } - } - - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("class "); - writeTextOfNode(currentSourceFile, node.name); - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - let baseTypeNode = getClassBaseTypeNode(node); - if (baseTypeNode) { - emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); - } - emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); - write(" {"); - writeLine(); - increaseIndent(); - emitParameterProperties(getFirstConstructorWithBody(node)); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - - function emitInterfaceDeclaration(node: InterfaceDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("interface "); - writeTextOfNode(currentSourceFile, node.name); - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - } - - function emitPropertyDeclaration(node: Declaration) { - if (hasDynamicName(node)) { - return; - } - - emitJsDocComments(node); - emitClassMemberDeclarationFlags(node); - emitVariableDeclaration(node); - write(";"); - writeLine(); - } - - function emitVariableDeclaration(node: VariableDeclaration) { - // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted - // so there is no check needed to see if declaration is visible - if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { - // If this node is a computed name, it can only be a symbol, because we've already skipped - // it if it's not a well known symbol. In that case, the text of the name will be exactly - // what we want, namely the name expression enclosed in brackets. - writeTextOfNode(currentSourceFile, node.name); - // If optional property emit ? - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { - write("?"); - } - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); - } - } - - function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let 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; - } - // 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; - } - 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; - } - 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; - } - } - - return diagnosticMessage !== undefined ? { - diagnosticMessage, - errorNode: node, - typeName: node.name - } : undefined; - } - } - - function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) { - // if this is property of type literal, - // or is parameter of method/call/construct/index signature of type literal - // emit only if type is specified - if (node.type) { - write(": "); - emitType(node.type); - } - } - - function emitVariableStatement(node: VariableStatement) { - let hasDeclarationWithEmit = forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); - if (hasDeclarationWithEmit) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isLet(node.declarationList)) { - write("let "); - } - else if (isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } - emitCommaList(node.declarationList.declarations, emitVariableDeclaration); - write(";"); - writeLine(); - } - } - - function emitAccessorDeclaration(node: AccessorDeclaration) { - if (hasDynamicName(node)) { - return; - } - - let accessors = getAllAccessorDeclarations((node.parent).members, node); - let accessorWithTypeAnnotation: AccessorDeclaration; - - if (node === accessors.firstAccessor) { - emitJsDocComments(accessors.getAccessor); - emitJsDocComments(accessors.setAccessor); - emitClassMemberDeclarationFlags(node); - writeTextOfNode(currentSourceFile, node.name); - if (!(node.flags & NodeFlags.Private)) { - accessorWithTypeAnnotation = node; - let type = getTypeAnnotationFromAccessor(node); - if (!type) { - // couldn't get type for the first accessor, try the another one - let anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor; - type = getTypeAnnotationFromAccessor(anotherAccessor); - if (type) { - accessorWithTypeAnnotation = anotherAccessor; - } - } - writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); - } - write(";"); - writeLine(); - } - - function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression { - if (accessor) { - return accessor.kind === SyntaxKind.GetAccessor - ? accessor.type // Getter - return type - : accessor.parameters.length > 0 - ? accessor.parameters[0].type // Setter parameter type - : undefined; - } - } - - function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { - // 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; - } - 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; - } - return { - diagnosticMessage, - errorNode: accessorWithTypeAnnotation.parameters[0], - // TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name - typeName: accessorWithTypeAnnotation.name - }; - } - 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; - } - 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; - } - return { - diagnosticMessage, - errorNode: accessorWithTypeAnnotation.name, - typeName: undefined - }; - } - } - } - - function emitFunctionDeclaration(node: FunctionLikeDeclaration) { - if (hasDynamicName(node)) { - return; - } - - // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting - // so no need to verify if the declaration is visible - if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) && - !resolver.isImplementationOfOverload(node)) { - emitJsDocComments(node); - if (node.kind === SyntaxKind.FunctionDeclaration) { - emitModuleElementDeclarationFlags(node); - } - else if (node.kind === SyntaxKind.MethodDeclaration) { - emitClassMemberDeclarationFlags(node); - } - if (node.kind === SyntaxKind.FunctionDeclaration) { - write("function "); - writeTextOfNode(currentSourceFile, node.name); - } - else if (node.kind === SyntaxKind.Constructor) { - write("constructor"); - } - else { - writeTextOfNode(currentSourceFile, node.name); - if (hasQuestionToken(node)) { - write("?"); - } - } - emitSignatureDeclaration(node); - } - } - - function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) { - emitJsDocComments(node); - emitSignatureDeclaration(node); - } - - function emitSignatureDeclaration(node: SignatureDeclaration) { - // Construct signature or constructor type write new Signature - if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { - write("new "); - } - emitTypeParameters(node.typeParameters); - if (node.kind === SyntaxKind.IndexSignature) { - write("["); - } - else { - write("("); - } - - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - - // Parameters - emitCommaList(node.parameters, emitParameterDeclaration); - - if (node.kind === SyntaxKind.IndexSignature) { - write("]"); - } - else { - write(")"); - } - - // If this is not a constructor and is not private, emit the return type - let isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType; - if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) { - // Emit type literal signature return type only if specified - if (node.type) { - write(isFunctionTypeOrConstructorType ? " => " : ": "); - emitType(node.type); - } - } - else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) { - writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); - } - - enclosingDeclaration = prevEnclosingDeclaration; - - if (!isFunctionTypeOrConstructorType) { - write(";"); - writeLine(); - } - - function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - switch (node.kind) { - 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; - 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; - 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; - 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; - } - 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; - } - 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; - } - 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; - break; - - default: - Debug.fail("This is unknown kind for signature: " + node.kind); - } - - return { - diagnosticMessage, - errorNode: node.name || node, - }; - } - } - - function emitParameterDeclaration(node: ParameterDeclaration) { - increaseIndent(); - emitJsDocComments(node); - if (node.dotDotDotToken) { - write("..."); - } - if (isBindingPattern(node.name)) { - write("_" + indexOf((node.parent).parameters, node)); - } - else { - writeTextOfNode(currentSourceFile, node.name); - } - if (node.initializer || hasQuestionToken(node)) { - write("?"); - } - decreaseIndent(); - - if (node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - node.parent.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.parent.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); - } - function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - 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; - 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; - 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; - 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; - } - 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; - } - 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; - } - 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; - break; - - default: - Debug.fail("This is unknown parent for parameter: " + node.parent.kind); - } - - return { - diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } + interface ExternalImportInfo { + rootNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration; + declarationNode?: ImportEqualsDeclaration | ImportClause | NamespaceImport; + namedImports?: NamedImports; + } - function emitNode(node: Node) { - switch (node.kind) { - case SyntaxKind.Constructor: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - return emitFunctionDeclaration(node); - case SyntaxKind.ConstructSignature: - case SyntaxKind.CallSignature: - case SyntaxKind.IndexSignature: - return emitSignatureDeclarationWithJsDocComments(node); - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return emitAccessorDeclaration(node); - case SyntaxKind.VariableStatement: - return emitVariableStatement(node); - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - return emitPropertyDeclaration(node); - case SyntaxKind.InterfaceDeclaration: - return emitInterfaceDeclaration(node); - case SyntaxKind.ClassDeclaration: - return emitClassDeclaration(node); - case SyntaxKind.TypeAliasDeclaration: - return emitTypeAliasDeclaration(node); - case SyntaxKind.EnumMember: - return emitEnumMemberDeclaration(node); - case SyntaxKind.EnumDeclaration: - return emitEnumDeclaration(node); - case SyntaxKind.ModuleDeclaration: - return emitModuleDeclaration(node); - case SyntaxKind.ImportEqualsDeclaration: - return emitImportEqualsDeclaration(node); - case SyntaxKind.ExportAssignment: - return emitExportAssignment(node); - case SyntaxKind.SourceFile: - return emitSourceFile(node); - } - } + // represents one LexicalEnvironment frame to store unique generated names + interface ScopeFrame { + names: Map; + previous: ScopeFrame; + } - function writeReferencePath(referencedFile: SourceFile) { - let declFileName = referencedFile.flags & NodeFlags.DeclarationFile - ? referencedFile.fileName // Declaration file, use declaration file name - : shouldEmitToOwnFile(referencedFile, compilerOptions) - ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file - : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file - - declFileName = getRelativePathToDirectoryOrUrl( - getDirectoryPath(normalizeSlashes(jsFilePath)), - declFileName, - host.getCurrentDirectory(), - host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ false); - - referencePathsOutput += "/// " + newLine; - } + export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { + return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); } - export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { - let diagnostics: Diagnostic[] = []; - let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); - emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); - return diagnostics; + // flag enum used to request and track usages of few dedicated temp variables + // enum values are used to set/check bit values and thus should not have bit collisions. + const enum TempVariableKind { + auto = 0, + _i = 1, + _n = 2, } // @internal @@ -1567,6 +68,26 @@ module ts { sourceMaps: sourceMapDataList }; + function isNodeDescendentOf(node: Node, ancestor: Node): boolean { + while (node) { + if (node === ancestor) return true; + node = node.parent; + } + return false; + } + + function isUniqueLocalName(name: string, container: Node): boolean { + for (let node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { + if (node.locals && hasProperty(node.locals, name)) { + // We conservatively include alias symbols to cover cases where they're emitted as locals + if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Alias)) { + return false; + } + } + } + return true; + } + function emitJavaScript(jsFilePath: string, root?: SourceFile) { let writer = createTextWriter(newLine); let write = writer.write; @@ -1578,15 +99,18 @@ module ts { let currentSourceFile: SourceFile; - let lastFrame: ScopeFrame; - let currentScopeNames: Map; - - let generatedBlockScopeNames: string[]; + let generatedNameSet: Map; + let nodeToGeneratedName: string[]; + let blockScopedVariableToGeneratedName: string[]; + let computedPropertyNameToGeneratedName: string[]; let extendsEmitted = false; + let decorateEmitted = false; let tempCount = 0; let tempVariables: Identifier[]; let tempParameters: Identifier[]; + let predefinedTempsInUse = TempVariableKind.auto; + let externalImports: ExternalImportInfo[]; let exportSpecifiers: Map; let exportDefault: FunctionDeclaration | ClassDeclaration | ExportAssignment | ExportSpecifier; @@ -1594,25 +118,12 @@ module ts { /** write emitted output to disk*/ let writeEmittedFiles = writeJavaScriptFile; - /** Emit leading comments of the node */ - let emitLeadingComments = compilerOptions.removeComments ? (node: Node) => { } : emitLeadingDeclarationComments; - - /** Emit Trailing comments of the node */ - let emitTrailingComments = compilerOptions.removeComments ? (node: Node) => { } : emitTrailingDeclarationComments; - - let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? (pos: number) => { } : emitLeadingCommentsOfLocalPosition; - let detachedCommentsInfo: { nodePos: number; detachedCommentEndPos: number }[]; - /** Emit detached comments of the node */ - let emitDetachedComments = compilerOptions.removeComments ? (node: TextRange) => { } : emitDetachedCommentsAtPosition; - let writeComment = writeCommentRange; /** Emit a node */ - let emitNodeWithoutSourceMap = compilerOptions.removeComments ? emitNodeWithoutSourceMapWithoutComments : emitNodeWithoutSourceMapWithComments; let emit = emitNodeWithoutSourceMap; - let emitWithoutComments = emitNodeWithoutSourceMapWithoutComments; /** Called just before starting emit of a node */ let emitStart = function (node: Node) { }; @@ -1664,81 +175,197 @@ module ts { emit(sourceFile); } - // enters the new lexical environment - // return value should be passed to matching call to exitNameScope. - function enterNameScope(): boolean { - let names = currentScopeNames; - currentScopeNames = undefined; - if (names) { - lastFrame = { names, previous: lastFrame }; - return true; + function generateNameForNode(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ClassDeclaration: + generateNameForFunctionOrClassDeclaration(node); + break; + case SyntaxKind.ModuleDeclaration: + generateNameForModuleOrEnum(node); + generateNameForNode((node).body); + break; + case SyntaxKind.EnumDeclaration: + generateNameForModuleOrEnum(node); + break; + case SyntaxKind.ImportDeclaration: + generateNameForImportDeclaration(node); + break; + case SyntaxKind.ExportDeclaration: + generateNameForExportDeclaration(node); + break; + case SyntaxKind.ExportAssignment: + generateNameForExportAssignment(node); + break; + case SyntaxKind.SourceFile: + case SyntaxKind.ModuleBlock: + forEach((node).statements, generateNameForNode); + break; } - return false; } - function exitNameScope(popFrame: boolean): void { - if (popFrame) { - currentScopeNames = lastFrame.names; - lastFrame = lastFrame.previous; + function isUniqueName(name: string): boolean { + return !resolver.hasGlobalName(name) && + !hasProperty(currentSourceFile.identifiers, name) && + (!generatedNameSet || !hasProperty(generatedNameSet, name)) + } + + // in cases like + // for (var x of []) { + // _i; + // } + // we should be able to detect if let _i was shadowed by some temp variable that was allocated in scope + function nameConflictsWithSomeTempVariable(name: string): boolean { + // temp variable names always start with '_' + if (name.length < 2 || name.charCodeAt(0) !== CharacterCodes._) { + return false; + } + + if (name === "_i") { + return !!(predefinedTempsInUse & TempVariableKind._i); + } + + if (name === "_n") { + return !!(predefinedTempsInUse & TempVariableKind._n); + } + + if (name.length === 2 && name.charCodeAt(1) >= CharacterCodes.a && name.charCodeAt(1) <= CharacterCodes.z) { + // handles _a .. _z + let n = name.charCodeAt(1) - CharacterCodes.a; + return n < tempCount; } else { - currentScopeNames = undefined; + // handles _1, _2... + let n = +name.substring(1); + return !isNaN(n) && n >= 0 && n < (tempCount - 26); } } - function generateUniqueNameForLocation(location: Node, baseName: string): string { - let name: string - // first try to check if base name can be used as is - if (!isExistingName(location, baseName)) { - name = baseName; + // This function generates a name using the following pattern: + // _a .. _h, _j ... _z, _0, _1, ... + // It is guaranteed that generated name will not shadow any existing user-defined names, + // however it can hide another name generated by this function higher in the scope. + // NOTE: names generated by 'makeTempVariableName' and 'makeUniqueName' will never conflict. + // see comment for 'makeTempVariableName' for more information. + function makeTempVariableName(location: Node, tempVariableKind: TempVariableKind): string { + let tempName: string; + if (tempVariableKind !== TempVariableKind.auto && !(predefinedTempsInUse & tempVariableKind)) { + tempName = tempVariableKind === TempVariableKind._i ? "_i" : "_n"; + if (!resolver.resolvesToSomeValue(location, tempName)) { + predefinedTempsInUse |= tempVariableKind; + return tempName; + } } - else { - name = generateUniqueName(baseName, n => isExistingName(location, n)); + + do { + // Note: we avoid generating _i and _n as those are common names we want in other places. + var char = CharacterCodes.a + tempCount; + if (char !== CharacterCodes.i && char !== CharacterCodes.n) { + if (tempCount < 26) { + tempName = "_" + String.fromCharCode(char); + } + else { + tempName = "_" + (tempCount - 26); + } + } + + tempCount++; } - - return recordNameInCurrentScope(name); + while (resolver.resolvesToSomeValue(location, tempName)); + + return tempName; } - - function recordNameInCurrentScope(name: string): string { - if (!currentScopeNames) { - currentScopeNames = {}; + + // Generates a name that is unique within current file and does not collide with + // any names in global scope. + // NOTE: names generated by 'makeTempVariableName' and 'makeUniqueName' will never conflict + // because of the way how these names are generated + // - makeUniqueName builds a name by picking a base name (which should not be empty string) + // and appending suffix '_' + // - makeTempVariableName creates a name using the following pattern: + // _a .. _h, _j ... _z, _0, _1, ... + // This means that names from 'makeTempVariableName' will have only one underscore at the beginning + // and names from 'makeUniqieName' will have at least one underscore in the middle + // so they will never collide. + function makeUniqueName(baseName: string): string { + Debug.assert(!!baseName); + + // Find the first unique 'name_n', where n is a positive number + if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { + baseName += "_"; + } + + let i = 1; + let generatedName: string; + while (true) { + generatedName = baseName + i; + if (isUniqueName(generatedName)) { + break; + } + i++; } - return currentScopeNames[name] = name; + if (!generatedNameSet) { + generatedNameSet = {}; + } + return generatedNameSet[generatedName] = generatedName; } - function isExistingName(location: Node, name: string) { - // check if resolver is aware of this name (if name was seen during the typecheck) - if (!resolver.isUnknownIdentifier(location, name)) { - return true; + function renameNode(node: Node, name: string): string { + var nodeId = getNodeId(node); + + if (!nodeToGeneratedName) { + nodeToGeneratedName = []; } - // check if name is present in generated names that were introduced by the emitter - if (currentScopeNames && hasProperty(currentScopeNames, name)) { - return true; + return nodeToGeneratedName[nodeId] = unescapeIdentifier(name); + } + + function generateNameForFunctionOrClassDeclaration(node: Declaration) { + if (!node.name) { + renameNode(node, makeUniqueName("default")); } + } - // check generated names in outer scopes - // let x; - // function foo() { - // let x; // 1 - // function bar() { - // { - // let x; // 2 - // } - // console.log(x); // 3 - // } - //} - // here both x(1) and x(2) should be renamed and their names should be different - // so x in (3) will refer to x(1) - let frame = lastFrame; - while (frame) { - if (hasProperty(frame.names, name)) { - return true; - } - frame = frame.previous; + function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { + if (node.name.kind === SyntaxKind.Identifier) { + let name = node.name.text; + // Use module/enum name itself if it is unique, otherwise make a unique variation + renameNode(node, isUniqueLocalName(name, node) ? name : makeUniqueName(name)); + } + } + + function generateNameForImportOrExportDeclaration(node: ImportDeclaration | ExportDeclaration) { + let expr = getExternalModuleName(node); + let baseName = expr.kind === SyntaxKind.StringLiteral ? + escapeIdentifier(makeIdentifierFromModuleName((expr).text)) : "module"; + renameNode(node, makeUniqueName(baseName)); + } + + function generateNameForImportDeclaration(node: ImportDeclaration) { + if (node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === SyntaxKind.NamedImports) { + generateNameForImportOrExportDeclaration(node); + } + } + + function generateNameForExportDeclaration(node: ExportDeclaration) { + if (node.moduleSpecifier) { + generateNameForImportOrExportDeclaration(node); + } + } + + function generateNameForExportAssignment(node: ExportAssignment) { + if (node.expression && node.expression.kind !== SyntaxKind.Identifier) { + renameNode(node, makeUniqueName("default")); } - return false; + } + + function getGeneratedNameForNode(node: Node) { + let nodeId = getNodeId(node); + if (!nodeToGeneratedName || !nodeToGeneratedName[nodeId]) { + generateNameForNode(node); + } + return nodeToGeneratedName ? nodeToGeneratedName[nodeId] : undefined; } function initializeEmitterWithSourceMaps() { @@ -2091,17 +718,8 @@ module ts { } } - function emitNodeWithSourceMapWithoutComments(node: Node) { - if (node) { - recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMapWithoutComments(node); - recordEmitNodeEndSpan(node); - } - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; emit = emitNodeWithSourceMap; - emitWithoutComments = emitNodeWithSourceMapWithoutComments; emitStart = recordEmitNodeStartSpan; emitEnd = recordEmitNodeEndSpan; emitToken = writeTextWithSpanRecord; @@ -2114,32 +732,10 @@ module ts { writeFile(host, diagnostics, jsFilePath, emitOutput, writeByteOrderMark); } - // Create a temporary variable with a unique unused name. The forLoopVariable parameter signals that the - // name should be one that is appropriate for a for loop variable. - function createTempVariable(location: Node, preferredName?: string): Identifier { - for (var name = preferredName; !name || isExistingName(location, name); tempCount++) { - // _a .. _h, _j ... _z, _0, _1, ... - - // Note: we avoid generating _i and _n as those are common names we want in other places. - var char = CharacterCodes.a + tempCount; - if (char === CharacterCodes.i || char === CharacterCodes.n) { - continue; - } - - if (tempCount < 26) { - name = "_" + String.fromCharCode(char); - } - else { - name = "_" + (tempCount - 26); - } - } - - // This is necessary so that a name generated via renameNonTopLevelLetAndConst will see the name - // we just generated. - recordNameInCurrentScope(name); - + // Create a temporary variable with a unique unused name. + function createTempVariable(location: Node, tempVariableKind = TempVariableKind.auto): Identifier { let result = createSynthesizedNode(SyntaxKind.Identifier); - result.text = name; + result.text = makeTempVariableName(location, tempVariableKind); return result; } @@ -2150,8 +746,8 @@ module ts { tempVariables.push(name); } - function createAndRecordTempVariable(location: Node, preferredName?: string): Identifier { - let temp = createTempVariable(location, preferredName); + function createAndRecordTempVariable(location: Node, tempVariableKind?: TempVariableKind): Identifier { + let temp = createTempVariable(location, tempVariableKind); recordTempDeclaration(temp); return temp; @@ -2561,10 +1157,42 @@ module ts { function emitExpressionForPropertyName(node: DeclarationName) { Debug.assert(node.kind !== SyntaxKind.BindingElement); - if (node.kind === SyntaxKind.StringLiteral) { - emitLiteral(node); - } - else if (node.kind === SyntaxKind.ComputedPropertyName) { + if (node.kind === SyntaxKind.StringLiteral) { + emitLiteral(node); + } + else if (node.kind === SyntaxKind.ComputedPropertyName) { + // if this is a decorated computed property, we will need to capture the result + // of the property expression so that we can apply decorators later. This is to ensure + // we don't introduce unintended side effects: + // + // class C { + // [_a = x]() { } + // } + // + // The emit for the decorated computed property decorator is: + // + // Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); + // + if (nodeIsDecorated(node.parent)) { + if (!computedPropertyNameToGeneratedName) { + computedPropertyNameToGeneratedName = []; + } + + let generatedName = computedPropertyNameToGeneratedName[node.id]; + if (generatedName) { + // we have already generated a variable for this node, write that value instead. + write(generatedName); + return; + } + + let generatedVariable = createTempVariable(node); + generatedName = generatedVariable.text; + recordTempDeclaration(generatedVariable); + computedPropertyNameToGeneratedName[node.id] = generatedName; + write(generatedName); + write(" = "); + } + emit((node).expression); } else { @@ -2614,7 +1242,7 @@ module ts { } function emitExpressionIdentifier(node: Identifier) { - let substitution = resolver.getExpressionNameSubstitution(node); + let substitution = resolver.getExpressionNameSubstitution(node, getGeneratedNameForNode); if (substitution) { write(substitution); } @@ -2624,7 +1252,7 @@ module ts { } function getGeneratedNameForIdentifier(node: Identifier): string { - if (nodeIsSynthesized(node) || !generatedBlockScopeNames) { + if (nodeIsSynthesized(node) || !blockScopedVariableToGeneratedName) { return undefined; } @@ -2633,7 +1261,7 @@ module ts { return undefined; } - return generatedBlockScopeNames[variableId]; + return blockScopedVariableToGeneratedName[variableId]; } function emitIdentifier(node: Identifier, allowGeneratedIdentifiers: boolean) { @@ -2861,7 +1489,7 @@ module ts { // manage by just emitting strings (which is a lot more performant). //let prefix = createIdentifier(resolver.getExpressionNamePrefix((property).name)); //return createPropertyAccessExpression(prefix, (property).name); - return createIdentifier(resolver.getExpressionNameSubstitution((property).name)); + return createIdentifier(resolver.getExpressionNameSubstitution((property).name, getGeneratedNameForNode)); case SyntaxKind.MethodDeclaration: return createFunctionExpression((property).parameters, (property).body); @@ -3034,7 +1662,7 @@ module ts { function emitComputedPropertyName(node: ComputedPropertyName) { write("["); - emit(node.expression); + emitExpressionForPropertyName(node); write("]"); } @@ -3075,7 +1703,7 @@ module ts { emitExpressionIdentifier(node.name); } } - else if (resolver.getExpressionNameSubstitution(node.name)) { + else if (resolver.getExpressionNameSubstitution(node.name, getGeneratedNameForNode)) { // Emit identifier as an identifier write(": "); // Even though this is stored as identifier treat it as an expression @@ -3608,10 +2236,10 @@ module ts { // // we don't want to emit a temporary variable for the RHS, just use it directly. let rhsIsIdentifier = node.expression.kind === SyntaxKind.Identifier; - let counter = createTempVariable(node, /*preferredName*/ "_i"); + let counter = createTempVariable(node, TempVariableKind._i); let rhsReference = rhsIsIdentifier ? node.expression : createTempVariable(node); - var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, /*preferredName:*/ "_n") : undefined; + var cachedLength = compilerOptions.cacheDownlevelForOfLength ? createTempVariable(node, TempVariableKind._n) : undefined; // This is the let keyword for the counter and rhsReference. The let keyword for // the LHS will be emitted inside the body. @@ -3852,7 +2480,7 @@ module ts { function emitContainingModuleName(node: Node) { let container = getContainingModule(node); - write(container ? resolver.getGeneratedNameForNode(container) : "exports"); + write(container ? getGeneratedNameForNode(container) : "exports"); } function emitModuleMemberName(node: Declaration) { @@ -3860,7 +2488,7 @@ module ts { if (getCombinedNodeFlags(node) & NodeFlags.Export) { var container = getContainingModule(node); if (container) { - write(resolver.getGeneratedNameForNode(container)); + write(getGeneratedNameForNode(container)); write("."); } else if (languageVersion < ScriptTarget.ES6) { @@ -4160,7 +2788,10 @@ module ts { } function emitExportVariableAssignments(node: VariableDeclaration | BindingElement) { - let name = (node).name; + if (node.kind === SyntaxKind.OmittedExpression) { + return; + } + let name = node.name; if (name.kind === SyntaxKind.Identifier) { emitExportMemberAssignments(name); } @@ -4199,9 +2830,14 @@ module ts { // here it is known that node is a block scoped variable let list = getAncestor(node, SyntaxKind.VariableDeclarationList); - if (list.parent.kind === SyntaxKind.VariableStatement && list.parent.parent.kind === SyntaxKind.SourceFile) { - // do not rename variables that are defined on source file level - return; + if (list.parent.kind === SyntaxKind.VariableStatement) { + let isSourceFileLevelBinding = list.parent.parent.kind === SyntaxKind.SourceFile; + let isModuleLevelBinding = list.parent.parent.kind === SyntaxKind.ModuleBlock; + let isFunctionLevelBinding = + list.parent.parent.kind === SyntaxKind.Block && isFunctionLike(list.parent.parent.parent); + if (isSourceFileLevelBinding || isModuleLevelBinding || isFunctionLevelBinding) { + return; + } } let blockScopeContainer = getEnclosingBlockScopeContainer(node); @@ -4209,12 +2845,19 @@ module ts { ? blockScopeContainer : blockScopeContainer.parent; - let generatedName = generateUniqueNameForLocation(parent, (node).text); - let variableId = resolver.getBlockScopedVariableId(node); - if (!generatedBlockScopeNames) { - generatedBlockScopeNames = []; + var hasConflictsInEnclosingScope = + resolver.resolvesToSomeValue(parent, (node).text) || + nameConflictsWithSomeTempVariable((node).text); + + if (hasConflictsInEnclosingScope) { + let variableId = resolver.getBlockScopedVariableId(node); + if (!blockScopedVariableToGeneratedName) { + blockScopedVariableToGeneratedName = []; + } + + let generatedName = makeUniqueName((node).text); + blockScopedVariableToGeneratedName[variableId] = generatedName; } - generatedBlockScopeNames[variableId] = generatedName; } function isES6ModuleMemberDeclaration(node: Node) { @@ -4296,7 +2939,7 @@ module ts { if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) { let restIndex = node.parameters.length - 1; let restParam = node.parameters[restIndex]; - let tempName = createTempVariable(node, /*preferredName:*/ "_i").text; + let tempName = createTempVariable(node, TempVariableKind._i).text; writeLine(); emitLeadingComments(restParam); emitStart(restParam); @@ -4346,7 +2989,7 @@ module ts { emitNodeWithoutSourceMap(node.name); } else { - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); } } @@ -4365,7 +3008,7 @@ module ts { function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (nodeIsMissing(node.body)) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { @@ -4432,11 +3075,12 @@ module ts { let saveTempCount = tempCount; let saveTempVariables = tempVariables; let saveTempParameters = tempParameters; + let savePredefinedTempsInUse = predefinedTempsInUse; + tempCount = 0; tempVariables = undefined; tempParameters = undefined; - - let popFrame = enterNameScope() + predefinedTempsInUse = TempVariableKind.auto; // When targeting ES6, emit arrow function natively in ES6 if (shouldEmitAsArrowFunction(node)) { @@ -4469,8 +3113,7 @@ module ts { write(";"); } - exitNameScope(popFrame); - + predefinedTempsInUse = savePredefinedTempsInUse; tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; @@ -4521,10 +3164,7 @@ module ts { write(" "); emitStart(body); write("return "); - - // Don't emit comments on this body. We'll have already taken care of it above - // when we called emitDetachedComments. - emitWithoutComments(body); + emit(body); emitEnd(body); write(";"); emitTempDeclarations(/*newLine*/ false); @@ -4535,10 +3175,7 @@ module ts { writeLine(); emitLeadingComments(node.body); write("return "); - - // Don't emit comments on this body. We'll have already taken care of it above - // when we called emitDetachedComments. - emitWithoutComments(node.body); + emit(body); write(";"); emitTrailingComments(node.body); @@ -4670,17 +3307,14 @@ module ts { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { - return emitPinnedOrTripleSlashComments(member); + return emitOnlyPinnedOrTripleSlashComments(member); } writeLine(); emitLeadingComments(member); emitStart(member); emitStart((member).name); - emitDeclarationName(node); - if (!(member.flags & NodeFlags.Static)) { - write(".prototype"); - } + emitClassMemberPrefix(node, member); emitMemberAccessForPropertyName((member).name); emitEnd((member).name); write(" = "); @@ -4698,10 +3332,7 @@ module ts { emitStart(member); write("Object.defineProperty("); emitStart((member).name); - emitDeclarationName(node); - if (!(member.flags & NodeFlags.Static)) { - write(".prototype"); - } + emitClassMemberPrefix(node, member); write(", "); emitExpressionForPropertyName((member).name); emitEnd((member).name); @@ -4745,7 +3376,7 @@ module ts { function emitMemberFunctionsForES6AndHigher(node: ClassDeclaration) { for (let member of node.members) { if ((member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && !(member).body) { - emitPinnedOrTripleSlashComments(member); + emitOnlyPinnedOrTripleSlashComments(member); } else if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { writeLine(); @@ -4773,11 +3404,12 @@ module ts { let saveTempCount = tempCount; let saveTempVariables = tempVariables; let saveTempParameters = tempParameters; + let savePredefinedTempsInUse = predefinedTempsInUse; tempCount = 0; tempVariables = undefined; tempParameters = undefined; + predefinedTempsInUse = TempVariableKind.auto; - let popFrame = enterNameScope(); // Check if we have property assignment inside class declaration. // If there is property assignment, we need to emit constructor whether users define it or not // If there is no property assignment, we can omit constructor if users do not define it @@ -4786,7 +3418,7 @@ module ts { // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { - emitPinnedOrTripleSlashComments(member); + emitOnlyPinnedOrTripleSlashComments(member); } // Check if there is any non-static property assignment if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer && (member.flags & NodeFlags.Static) === 0) { @@ -4886,32 +3518,106 @@ module ts { emitTrailingComments(ctor); } - exitNameScope(popFrame); - + predefinedTempsInUse = savePredefinedTempsInUse; tempCount = saveTempCount; tempVariables = saveTempVariables; tempParameters = saveTempParameters; } + function emitClassDeclaration(node: ClassDeclaration) { + if (languageVersion < ScriptTarget.ES6) { + emitClassDeclarationBelowES6(node); + } + else { + emitClassDeclarationForES6AndHigher(node); + } + } + function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { - if (isES6ModuleMemberDeclaration(node)) { - write("export "); + let thisNodeIsDecorated = nodeIsDecorated(node); + if (thisNodeIsDecorated) { + // To preserve the correct runtime semantics when decorators are applied to the class, + // the emit needs to follow one of the following rules: + // + // * For a local class declaration: + // + // @dec class C { + // } + // + // The emit should be: + // + // let C = class { + // }; + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // C = __decorate([dec], C); + // + // * For an exported class declaration: + // + // @dec export class C { + // } + // + // The emit should be: + // + // export let C = class { + // }; + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // C = __decorate([dec], C); + // + // * For a default export of a class declaration with a name: + // + // @dec default export class C { + // } + // + // The emit should be: + // + // let C = class { + // } + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // C = __decorate([dec], C); + // export default C; + // + // * For a default export of a class declaration without a name: + // + // @dec default export class { + // } + // + // The emit should be: + // + // let _default = class { + // } + // _default = __decorate([dec], _default); + // export default _default; + // + + if (isES6ModuleMemberDeclaration(node) && !(node.flags & NodeFlags.Default)) { + write("export "); + } + write("let "); + emitDeclarationName(node); + write(" = "); + } + else if (isES6ModuleMemberDeclaration(node)) { + write("export "); if (node.flags & NodeFlags.Default) { write("default "); } } - - write("class "); - // check if this is an "export default class" as it may not have a name - if (node.name || !(node.flags & NodeFlags.Default)) { + + write("class"); + + // check if this is an "export default class" as it may not have a name. Do not emit the name if the class is decorated. + if ((node.name || !(node.flags & NodeFlags.Default)) && !thisNodeIsDecorated) { + write(" "); emitDeclarationName(node); } + var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); emit(baseTypeNode.typeName); } + write(" {"); increaseIndent(); scopeEmitStart(node); @@ -4923,6 +3629,26 @@ module ts { emitToken(SyntaxKind.CloseBraceToken, node.members.end); scopeEmitEnd(); + // For a decorated class, we need to assign its name (if it has one). This is because we emit + // the class as a class expression to avoid the double-binding of the identifier: + // + // let C = class { + // } + // Object.defineProperty(C, "name", { value: "C", configurable: true }); + // + if (thisNodeIsDecorated) { + write(";"); + if (node.name) { + writeLine(); + write("Object.defineProperty("); + emitDeclarationName(node); + write(", \"name\", { value: \""); + emitDeclarationName(node); + write("\", configurable: true });"); + writeLine(); + } + } + // Emit static property assignment. Because classDeclaration is lexically evaluated, // it is safe to emit static property assignment after classDeclaration // From ES6 specification: @@ -4930,10 +3656,11 @@ module ts { // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. writeLine(); emitMemberAssignments(node, NodeFlags.Static); + emitDecoratorsOfClass(node); - // If this is an exported class, but not on the top level (i.e. on an internal - // module), export it if (!isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Export)) { + // If this is an exported class, but not on the top level (i.e. on an internal + // module), export it writeLine(); emitStart(node); emitModuleMemberName(node); @@ -4942,6 +3669,13 @@ module ts { emitEnd(node); write(";"); } + else if (isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Default) && thisNodeIsDecorated) { + // if this is a top level default export of decorated class, write the export after the declaration. + writeLine(); + write("export default "); + emitDeclarationName(node); + write(";"); + } } function emitClassDeclarationBelowES6(node: ClassDeclaration) { @@ -4953,6 +3687,14 @@ module ts { write("_super"); } write(") {"); + let saveTempCount = tempCount; + let saveTempVariables = tempVariables; + let saveTempParameters = tempParameters; + let saveGeneratedComputedPropertyNames = computedPropertyNameToGeneratedName; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + computedPropertyNameToGeneratedName = undefined; increaseIndent(); scopeEmitStart(node); if (baseTypeNode) { @@ -4968,11 +3710,18 @@ module ts { emitMemberFunctionsForES5AndLower(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); + emitDecoratorsOfClass(node); + writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { write("return "); emitDeclarationName(node); }); write(";"); + emitTempDeclarations(/*newLine*/ true); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + computedPropertyNameToGeneratedName = saveGeneratedComputedPropertyNames; decreaseIndent(); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end); @@ -5000,8 +3749,227 @@ module ts { } } + function emitClassMemberPrefix(node: ClassDeclaration, member: Node) { + emitDeclarationName(node); + if (!(member.flags & NodeFlags.Static)) { + write(".prototype"); + } + } + + function emitDecoratorsOfClass(node: ClassDeclaration) { + if (languageVersion < ScriptTarget.ES5) { + return; + } + + emitDecoratorsOfMembers(node, /*staticFlag*/ 0); + emitDecoratorsOfMembers(node, NodeFlags.Static); + emitDecoratorsOfConstructor(node); + } + + function emitDecoratorsOfConstructor(node: ClassDeclaration) { + let constructor = getFirstConstructorWithBody(node); + if (constructor) { + emitDecoratorsOfParameters(node, constructor); + } + + if (!nodeIsDecorated(node)) { + return; + } + + // Emit the call to __decorate. Given the class: + // + // @dec + // class C { + // } + // + // The emit for the class is: + // + // C = __decorate([dec], C); + // + + writeLine(); + emitStart(node); + emitDeclarationName(node); + write(" = "); + emitDecorateStart(node.decorators); + emitDeclarationName(node); + write(");"); + emitEnd(node); + writeLine(); + } + + function emitDecoratorsOfMembers(node: ClassDeclaration, staticFlag: NodeFlags) { + forEach(node.members, member => { + if ((member.flags & NodeFlags.Static) !== staticFlag) { + return; + } + + let decorators: NodeArray; + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + // emit decorators of the method's parameters + emitDecoratorsOfParameters(node, member); + decorators = member.decorators; + break; + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + let accessors = getAllAccessorDeclarations(node.members, member); + if (member !== accessors.firstAccessor) { + // skip the second accessor as we processed it with the first. + return; + } + + if (accessors.setAccessor) { + // emit decorators of the set accessor parameter + emitDecoratorsOfParameters(node, accessors.setAccessor); + } + + // get the decorators from the first decorated accessor. + decorators = accessors.firstAccessor.decorators; + if (!decorators && accessors.secondAccessor) { + decorators = accessors.secondAccessor.decorators; + } + break; + + case SyntaxKind.PropertyDeclaration: + decorators = member.decorators; + break; + + default: + // Constructor cannot be decorated, and its parameters are handled in emitDecoratorsOfConstructor + // Other members (i.e. IndexSignature) cannot be decorated. + return; + } + + if (!decorators) { + return; + } + + // Emit the call to __decorate. Given the following: + // + // class C { + // @dec method() {} + // @dec get accessor() {} + // @dec prop; + // } + // + // The emit for a method is: + // + // Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + // + // The emit for an accessor is: + // + // Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + // + // The emit for a property is: + // + // __decorate([dec], C.prototype, "prop"); + // + + writeLine(); + emitStart(member); + if (member.kind !== SyntaxKind.PropertyDeclaration) { + write("Object.defineProperty("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write(", "); + } + + emitDecorateStart(decorators); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + + if (member.kind !== SyntaxKind.PropertyDeclaration) { + write(", Object.getOwnPropertyDescriptor("); + emitStart(member.name); + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + emitEnd(member.name); + write("))"); + } + + write(");"); + emitEnd(member); + writeLine(); + }); + } + + function emitDecoratorsOfParameters(node: ClassDeclaration, member: FunctionLikeDeclaration) { + forEach(member.parameters, (parameter, parameterIndex) => { + if (!nodeIsDecorated(parameter)) { + return; + } + + // Emit the decorators for a parameter. Given the following: + // + // class C { + // constructor(@dec p) { } + // method(@dec p) { } + // set accessor(@dec value) { } + // } + // + // The emit for a constructor is: + // + // __decorate([dec], C, void 0, 0); + // + // The emit for a parameter is: + // + // __decorate([dec], C.prototype, "method", 0); + // + // The emit for an accessor is: + // + // __decorate([dec], C.prototype, "accessor", 0); + // + + writeLine(); + emitStart(parameter); + emitDecorateStart(parameter.decorators); + emitStart(parameter.name); + + if (member.kind === SyntaxKind.Constructor) { + emitDeclarationName(node); + write(", void 0"); + } + else { + emitClassMemberPrefix(node, member); + write(", "); + emitExpressionForPropertyName(member.name); + } + + write(", "); + write(String(parameterIndex)); + emitEnd(parameter.name); + write(");"); + emitEnd(parameter); + writeLine(); + }); + } + + function emitDecorateStart(decorators: Decorator[]): void { + write("__decorate(["); + let decoratorCount = decorators.length; + for (let i = 0; i < decoratorCount; i++) { + if (i > 0) { + write(", "); + } + let decorator = decorators[i]; + emitStart(decorator); + emit(decorator.expression); + emitEnd(decorator); + } + write("], "); + } + function emitInterfaceDeclaration(node: InterfaceDeclaration) { - emitPinnedOrTripleSlashComments(node); + emitOnlyPinnedOrTripleSlashComments(node); } function shouldEmitEnumDeclaration(node: EnumDeclaration) { @@ -5026,7 +3994,7 @@ module ts { emitStart(node); write("(function ("); emitStart(node.name); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); emitEnd(node.name); write(") {"); increaseIndent(); @@ -5063,9 +4031,9 @@ module ts { function emitEnumMember(node: EnumMember) { let enumParent = node.parent; emitStart(node); - write(resolver.getGeneratedNameForNode(enumParent)); + write(getGeneratedNameForNode(enumParent)); write("["); - write(resolver.getGeneratedNameForNode(enumParent)); + write(getGeneratedNameForNode(enumParent)); write("["); emitExpressionForPropertyName(node.name); write("] = "); @@ -5077,15 +4045,12 @@ module ts { } function writeEnumMemberDeclarationValue(member: EnumMember) { - if (!member.initializer || isConst(member.parent)) { - let value = resolver.getConstantValue(member); - if (value !== undefined) { - write(value.toString()); - return; - } + let value = resolver.getConstantValue(member); + if (value !== undefined) { + write(value.toString()); + return; } - - if (member.initializer) { + else if (member.initializer) { emit(member.initializer); } else { @@ -5109,7 +4074,7 @@ module ts { let shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } emitStart(node); @@ -5121,19 +4086,20 @@ module ts { emitStart(node); write("(function ("); emitStart(node.name); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); emitEnd(node.name); write(") "); if (node.body.kind === SyntaxKind.ModuleBlock) { let saveTempCount = tempCount; let saveTempVariables = tempVariables; + let savePredefinedTempsInUse = predefinedTempsInUse; tempCount = 0; tempVariables = undefined; - let popFrame = enterNameScope(); + predefinedTempsInUse = TempVariableKind.auto; emit(node.body); - exitNameScope(popFrame); + predefinedTempsInUse = savePredefinedTempsInUse; tempCount = saveTempCount; tempVariables = saveTempVariables; } @@ -5297,7 +4263,7 @@ module ts { } else if (namedImports) { write("var "); - write(resolver.getGeneratedNameForNode(node)); + write(getGeneratedNameForNode(node)); write(" = "); emitRequire(moduleName); } @@ -5352,7 +4318,7 @@ module ts { if (languageVersion < ScriptTarget.ES6 || node.parent.kind !== SyntaxKind.SourceFile) { if (node.moduleSpecifier) { emitStart(node); - let generatedName = resolver.getGeneratedNameForNode(node); + let generatedName = getGeneratedNameForNode(node); if (compilerOptions.module !== ModuleKind.AMD) { write("var "); write(generatedName); @@ -5455,7 +4421,7 @@ module ts { return { rootNode: node, namedImports: importClause.namedBindings, - localName: resolver.getGeneratedNameForNode(node) + localName: getGeneratedNameForNode(node) }; } } @@ -5560,7 +4526,7 @@ module ts { emit(info.declarationNode.name); } else { - write(resolver.getGeneratedNameForNode(info.rootNode)); + write(getGeneratedNameForNode(info.rootNode)); } }); forEach(node.amdDependencies, amdDependency => { @@ -5596,12 +4562,12 @@ module ts { emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); // Emit exportDefault if it exists will happen as part - // or normal statment emit. + // or normal statement emit. } function emitExportAssignment(node: ExportAssignment) { // Only emit exportAssignment/export default if we are in ES6 - // Other modules will handel it diffrentlly + // Other modules will handle it differently if (languageVersion >= ScriptTarget.ES6) { writeLine(); emitStart(node); @@ -5654,6 +4620,17 @@ module ts { return statements.length; } + function writeHelper(text: string): void { + let lines = text.split(/\r\n|\r|\n/g); + for (let i = 0; i < lines.length; ++i) { + let line = lines[i]; + if (line.length) { + writeLine(); + write(line); + } + } + } + function emitSourceFileNode(node: SourceFile) { // Start new file on new line writeLine(); @@ -5680,6 +4657,23 @@ module ts { write("};"); extendsEmitted = true; } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate) { + writeHelper(` +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +};`); + decorateEmitted = true; + } if (isExternalModule(node)) { if (languageVersion >= ScriptTarget.ES6) { emitES6Module(node, startIndex); @@ -5703,13 +4697,13 @@ module ts { emitLeadingComments(node.endOfFileToken); } - function emitNodeWithoutSourceMapWithComments(node: Node, allowGeneratedIdentifiers?: boolean): void { + function emitNodeWithoutSourceMap(node: Node, allowGeneratedIdentifiers?: boolean): void { if (!node) { return; } if (node.flags & NodeFlags.Ambient) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } let emitComments = shouldEmitLeadingAndTrailingComments(node); @@ -5724,22 +4718,10 @@ module ts { } } - function emitNodeWithoutSourceMapWithoutComments(node: Node, allowGeneratedIdentifiers?: boolean): void { - if (!node) { - return; - } - - if (node.flags & NodeFlags.Ambient) { - return emitPinnedOrTripleSlashComments(node); - } - - emitJavaScriptWorker(node, allowGeneratedIdentifiers); - } - function shouldEmitLeadingAndTrailingComments(node: Node) { switch (node.kind) { // All of these entities are emitted in a specialized fashion. As such, we allow - // the specilized methods for each to handle the comments on the nodes. + // the specialized methods for each to handle the comments on the nodes. case SyntaxKind.InterfaceDeclaration: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ImportDeclaration: @@ -5759,6 +4741,19 @@ module ts { return shouldEmitEnumDeclaration(node); } + // If this is the expression body of an arrow function that we're down-leveling, + // then we don't want to emit comments when we emit the body. It will have already + // been taken care of when we emitted the 'return' statement for the function + // expression body. + if (node.kind !== SyntaxKind.Block && + node.parent && + node.parent.kind === SyntaxKind.ArrowFunction && + (node.parent).body === node && + compilerOptions.target <= ScriptTarget.ES5) { + + return false; + } + // Emit comments for everything else. return true; } @@ -5897,7 +4892,7 @@ module ts { case SyntaxKind.VariableDeclaration: return emitVariableDeclaration(node); case SyntaxKind.ClassDeclaration: - return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationForES6AndHigher(node); + return emitClassDeclaration(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); case SyntaxKind.EnumDeclaration: @@ -5928,7 +4923,8 @@ module ts { function getLeadingCommentsWithoutDetachedComments() { // get the leading comments from detachedPos - let leadingComments = getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + let leadingComments = getLeadingCommentRanges(currentSourceFile.text, + detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); if (detachedCommentsInfo.length - 1) { detachedCommentsInfo.pop(); } @@ -5939,43 +4935,72 @@ module ts { return leadingComments; } + function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { + // If we're removing comments, then we want to strip out all but the pinned or + // triple slash comments. + if (ranges && onlyPinnedOrTripleSlashComments) { + ranges = filter(ranges, isPinnedOrTripleSlashComment); + if (ranges.length === 0) { + return undefined; + } + } + + return ranges; + } + function getLeadingCommentsToEmit(node: Node) { // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments if (node.parent) { if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) { - let leadingComments: CommentRange[]; if (hasDetachedComments(node.pos)) { // get comments without detached comments - leadingComments = getLeadingCommentsWithoutDetachedComments(); + return getLeadingCommentsWithoutDetachedComments(); } else { // get the leading comments from the node - leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile); + return getLeadingCommentRangesOfNode(node, currentSourceFile); } - return leadingComments; } } } - function emitLeadingDeclarationComments(node: Node) { - let leadingComments = getLeadingCommentsToEmit(node); + function getTrailingCommentsToEmit(node: Node) { + // Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { + return getTrailingCommentRanges(currentSourceFile.text, node.end); + } + } + } + + function emitOnlyPinnedOrTripleSlashComments(node: Node) { + emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ true); + } + + function emitLeadingComments(node: Node) { + return emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + } + + function emitLeadingCommentsWorker(node: Node, onlyPinnedOrTripleSlashComments: boolean) { + // If the caller only wants pinned or triple slash comments, then always filter + // down to that set. Otherwise, filter based on the current compiler options. + let leadingComments = filterComments(getLeadingCommentsToEmit(node), onlyPinnedOrTripleSlashComments); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); } - function emitTrailingDeclarationComments(node: Node) { + function emitTrailingComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match - if (node.parent) { - if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { - let trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); - } - } + var trailingComments = filterComments(getTrailingCommentsToEmit(node), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); } - function emitLeadingCommentsOfLocalPosition(pos: number) { + function emitLeadingCommentsOfPosition(pos: number) { let leadingComments: CommentRange[]; if (hasDetachedComments(pos)) { // get comments without detached comments @@ -5985,12 +5010,15 @@ module ts { // get the leading comments from the node leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } + + leadingComments = filterComments(leadingComments, compilerOptions.removeComments); 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); } - function emitDetachedCommentsAtPosition(node: TextRange) { + function emitDetachedComments(node: TextRange) { let leadingComments = getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { let detachedComments: CommentRange[] = []; @@ -6035,47 +5063,18 @@ module ts { } } - /** Emits /// or pinned which is comment starting with /*! comments */ - function emitPinnedOrTripleSlashComments(node: Node) { - let pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment); - - function isPinnedOrTripleSlashComment(comment: CommentRange) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; - } - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && - currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { - return true; - } + function isPinnedOrTripleSlashComment(comment: CommentRange) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { + return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; + } + // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text + // so that we don't end up computing comment string and doing match for all // comments + else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && + currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { + return true; } - - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments); - // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, pinnedComments, /*trailingSeparator*/ true, newLine, writeComment); - } - } - - function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile) { - let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); - // TODO(shkamat): Should we not write any declaration file if any of them can produce error, - // or should we just not write this file like we are doing now - if (!emitDeclarationResult.reportedDeclarationError) { - let declarationOutput = emitDeclarationResult.referencePathsOutput; - // apply additions - let appliedSyncOutputPos = 0; - forEach(emitDeclarationResult.aliasDeclarationEmitInfo, aliasEmitInfo => { - if (aliasEmitInfo.asynchronousOutput) { - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); - declarationOutput += aliasEmitInfo.asynchronousOutput; - appliedSyncOutputPos = aliasEmitInfo.outputPos; - } - }); - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); } } @@ -6083,7 +5082,7 @@ module ts { emitJavaScript(jsFilePath, sourceFile); if (compilerOptions.declaration) { - writeDeclarationFile(jsFilePath, sourceFile); + writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); } } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9eae67a29b843..b78f61853e88e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -64,7 +64,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) || @@ -76,7 +77,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); @@ -88,7 +90,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) || @@ -171,7 +174,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); @@ -230,39 +234,48 @@ module ts { case SyntaxKind.CatchClause: return visitNode(cbNode, (node).variableDeclaration) || visitNode(cbNode, (node).block); + case SyntaxKind.Decorator: + return visitNode(cbNode, (node).expression); case SyntaxKind.ClassDeclaration: - 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.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.ImportEqualsDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).moduleReference); case SyntaxKind.ImportDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).importClause) || visitNode(cbNode, (node).moduleSpecifier); case SyntaxKind.ImportClause: @@ -274,7 +287,8 @@ module ts { case SyntaxKind.NamedExports: return visitNodes(cbNodes, (node).elements); case SyntaxKind.ExportDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportClause) || visitNode(cbNode, (node).moduleSpecifier); case SyntaxKind.ImportSpecifier: @@ -282,7 +296,8 @@ module ts { return visitNode(cbNode, (node).propertyName) || visitNode(cbNode, (node).name); case SyntaxKind.ExportAssignment: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).expression) || visitNode(cbNode, (node).type); case SyntaxKind.TemplateExpression: @@ -295,6 +310,8 @@ module ts { return visitNodes(cbNodes, (node).types); case SyntaxKind.ExternalModuleReference: return visitNode(cbNode, (node).expression); + case SyntaxKind.MissingDeclaration: + return visitNodes(cbNodes, node.decorators); } } @@ -987,6 +1004,8 @@ module ts { } function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: SyntaxCursor, setParentNodes = false): SourceFile { + const disallowInAndDecoratorContext = ParserContextFlags.DisallowIn | ParserContextFlags.Decorator; + let parsingContext: ParsingContext = 0; let identifiers: Map = {}; let identifierCount = 0; @@ -1130,6 +1149,23 @@ module ts { setContextFlag(val, ParserContextFlags.GeneratorParameter); } + function setDecoratorContext(val: boolean) { + setContextFlag(val, ParserContextFlags.Decorator); + } + + function doOutsideOfContext(flags: ParserContextFlags, func: () => T): T { + let currentContextFlags = contextFlags & flags; + if (currentContextFlags) { + setContextFlag(false, currentContextFlags); + let result = func(); + setContextFlag(true, currentContextFlags); + return result; + } + + // no need to do anything special as we are not in any of the requested contexts + return func(); + } + function allowInAnd(func: () => T): T { if (contextFlags & ParserContextFlags.DisallowIn) { setDisallowInContext(false); @@ -1178,6 +1214,18 @@ module ts { return func(); } + function doInDecoratorContext(func: () => T): T { + if (contextFlags & ParserContextFlags.Decorator) { + // no need to do anything special if we're already in the [Decorator] context. + return func(); + } + + setDecoratorContext(true); + let result = func(); + setDecoratorContext(false); + return result; + } + function inYieldContext() { return (contextFlags & ParserContextFlags.Yield) !== 0; } @@ -1194,6 +1242,10 @@ module ts { return (contextFlags & ParserContextFlags.DisallowIn) !== 0; } + function inDecoratorContext() { + return (contextFlags & ParserContextFlags.Decorator) !== 0; + } + function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { let start = scanner.getTokenPos(); let length = scanner.getTextPos() - start; @@ -1403,7 +1455,7 @@ module ts { return node; } - + function createMissingNode(kind: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { if (reportAtCurrentPosition) { parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0); @@ -2273,7 +2325,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) { @@ -2285,6 +2337,7 @@ module ts { function parseParameter(): ParameterDeclaration { let node = createNode(SyntaxKind.Parameter); + node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); @@ -2473,9 +2526,9 @@ module ts { return token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBracketToken; } - function parseIndexSignatureDeclaration(modifiers: ModifiersArray): IndexSignatureDeclaration { - let fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); + function parseIndexSignatureDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): IndexSignatureDeclaration { let node = createNode(SyntaxKind.IndexSignature, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); @@ -2552,7 +2605,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)) { @@ -2583,9 +2636,11 @@ module ts { } function parseIndexSignatureWithModifiers() { + let fullStart = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); return isIndexSignature() - ? parseIndexSignatureDeclaration(modifiers) + ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers) : undefined; } @@ -2841,7 +2896,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 { @@ -2849,11 +2904,21 @@ module ts { // AssignmentExpression[in] // Expression[in] , AssignmentExpression[in] + // clear the decorator context when parsing Expression, as it should be unambiguous when parsing a decorator + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } + let expr = parseAssignmentExpressionOrHigher(); let operatorToken: Node; while ((operatorToken = parseOptionalToken(SyntaxKind.CommaToken))) { expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher()); } + + if (saveDecoratorContext) { + setDecoratorContext(true); + } return expr; } @@ -3209,7 +3274,7 @@ module ts { let node = createNode(SyntaxKind.ConditionalExpression, leftOperand.pos); node.condition = leftOperand; node.questionToken = questionToken; - node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); + node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition:*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken)); node.whenFalse = parseAssignmentExpressionOrHigher(); @@ -3500,7 +3565,8 @@ module ts { continue; } - if (parseOptional(SyntaxKind.OpenBracketToken)) { + // when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName + if (!inDecoratorContext() && parseOptional(SyntaxKind.OpenBracketToken)) { let indexedAccess = createNode(SyntaxKind.ElementAccessExpression, expression.pos); indexedAccess.expression = expression; @@ -3536,7 +3602,6 @@ module ts { function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { while (true) { expression = parseMemberExpressionRest(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 @@ -3683,7 +3748,7 @@ module ts { } function parseArgumentExpression(): Expression { - return allowInAnd(parseArgumentOrArrayLiteralElement); + return doOutsideOfContext(disallowInAndDecoratorContext, parseArgumentOrArrayLiteralElement); } function parseArrayLiteralExpression(): ArrayLiteralExpression { @@ -3695,12 +3760,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; @@ -3708,9 +3773,10 @@ module ts { function parseObjectLiteralElement(): ObjectLiteralElement { let fullStart = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); - let accessor = tryParseAccessorDeclaration(fullStart, modifiers); + let accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers); if (accessor) { return accessor; } @@ -3723,7 +3789,7 @@ module ts { // Disallowing of optional property assignments happens in the grammar checker. let 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 @@ -3760,12 +3826,19 @@ module ts { // function * BindingIdentifier[Yield]opt (FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] } // FunctionExpression: // function BindingIdentifieropt(FormalParameters) { FunctionBody } + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } let 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); } @@ -3802,8 +3875,19 @@ module ts { let savedYieldContext = inYieldContext(); setYieldContext(allowYield); + // We may be in a [Decorator] context when parsing a function expression or + // arrow function. The body of the function is not in [Decorator] context. + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } + let block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage); + if (saveDecoratorContext) { + setDecoratorContext(true); + } + setYieldContext(savedYieldContext); return block; @@ -4051,7 +4135,7 @@ module ts { // 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)) { - let result = lookAhead(parseVariableStatementOrFunctionDeclarationWithModifiers); + let result = lookAhead(parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers); if (result) { return true; } @@ -4135,9 +4219,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: @@ -4170,7 +4254,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: @@ -4180,8 +4264,10 @@ 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)) { - let result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); + // 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) { + let result = tryParse(parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers); if (result) { return result; } @@ -4191,8 +4277,9 @@ module ts { } } - function parseVariableStatementOrFunctionDeclarationWithModifiers(): FunctionDeclaration | VariableStatement { + function parseVariableStatementOrFunctionDeclarationWithDecoratorsOrModifiers(): FunctionDeclaration | VariableStatement { let start = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); switch (token) { case SyntaxKind.ConstKeyword: @@ -4200,18 +4287,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; @@ -4341,16 +4428,18 @@ module ts { return nextTokenIsIdentifier() && nextToken() === SyntaxKind.CloseParenToken; } - function parseVariableStatement(fullStart: number, modifiers: ModifiersArray): VariableStatement { + function parseVariableStatement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): VariableStatement { let node = createNode(SyntaxKind.VariableStatement, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer:*/ false); parseSemicolon(); return finishNode(node); } - function parseFunctionDeclaration(fullStart: number, modifiers: ModifiersArray): FunctionDeclaration { + function parseFunctionDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): FunctionDeclaration { let node = createNode(SyntaxKind.FunctionDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -4360,8 +4449,9 @@ module ts { return finishNode(node); } - function parseConstructorDeclaration(pos: number, modifiers: ModifiersArray): ConstructorDeclaration { + function parseConstructorDeclaration(pos: number, decorators: NodeArray, modifiers: ModifiersArray): ConstructorDeclaration { let node = createNode(SyntaxKind.Constructor, pos); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ConstructorKeyword); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4369,8 +4459,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 { let method = createNode(SyntaxKind.MethodDeclaration, fullStart); + method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; @@ -4380,25 +4471,30 @@ module ts { return finishNode(method); } - function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { + function parsePropertyDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, name: DeclarationName, questionToken: Node): ClassElement { + let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; + setModifiers(property, modifiers); + property.name = name; + property.questionToken = questionToken; + property.type = parseTypeAnnotation(); + property.initializer = allowInAnd(parseNonParameterInitializer); + parseSemicolon(); + return finishNode(property); + } + + function parsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { let asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); let name = parsePropertyName(); - + // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. let 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 { - let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); - setModifiers(property, modifiers); - property.name = name; - property.questionToken = questionToken; - property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); - parseSemicolon(); - return finishNode(property); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name, questionToken); } } @@ -4406,8 +4502,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 { let node = createNode(kind, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4418,6 +4515,10 @@ module ts { function isClassMemberStart(): boolean { let 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; @@ -4469,6 +4570,29 @@ module ts { return false; } + function parseDecorators(): NodeArray { + let decorators: NodeArray; + while (true) { + let decoratorStart = getNodePos(); + if (!parseOptional(SyntaxKind.AtToken)) { + break; + } + + if (!decorators) { + decorators = >[]; + decorators.pos = scanner.getStartPos(); + } + + let decorator = createNode(SyntaxKind.Decorator, decoratorStart); + decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); + decorators.push(finishNode(decorator)); + } + if (decorators) { + decorators.end = getNodeEnd(); + } + return decorators; + } + function parseModifiers(): ModifiersArray { let flags = 0; let modifiers: ModifiersArray; @@ -4496,19 +4620,20 @@ module ts { function parseClassElement(): ClassElement { let fullStart = getNodePos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); - let accessor = tryParseAccessorDeclaration(fullStart, modifiers); + let 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 @@ -4519,14 +4644,20 @@ module ts { token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBracketToken) { - return parsePropertyOrMethodDeclaration(fullStart, modifiers); + return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); + } + + if (decorators) { + // treat this as a property declaration with a missing name. + let name = createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name, /*questionToken*/ undefined); } // '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 { // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code let savedStrictModeContext = inStrictModeContext(); if (languageVersion >= ScriptTarget.ES6) { @@ -4534,6 +4665,7 @@ module ts { } var node = createNode(SyntaxKind.ClassDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); node.name = node.flags & NodeFlags.Default ? parseOptionalIdentifier() : parseIdentifier(); @@ -4597,8 +4729,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 { let node = createNode(SyntaxKind.InterfaceDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); @@ -4608,8 +4741,9 @@ module ts { return finishNode(node); } - function parseTypeAliasDeclaration(fullStart: number, modifiers: ModifiersArray): TypeAliasDeclaration { + function parseTypeAliasDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): TypeAliasDeclaration { let node = createNode(SyntaxKind.TypeAliasDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.TypeKeyword); node.name = parseIdentifier(); @@ -4630,8 +4764,9 @@ module ts { return finishNode(node); } - function parseEnumDeclaration(fullStart: number, modifiers: ModifiersArray): EnumDeclaration { + function parseEnumDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): EnumDeclaration { let node = createNode(SyntaxKind.EnumDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.EnumKeyword); node.name = parseIdentifier(); @@ -4657,30 +4792,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 { let 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 { let 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() { @@ -4698,7 +4835,7 @@ module ts { token === SyntaxKind.FromKeyword; } - function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { + function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); let afterImportPos = scanner.getStartPos(); @@ -4710,6 +4847,7 @@ module ts { // import x = require("mod"); or // import x = M.x; let importEqualsDeclaration = createNode(SyntaxKind.ImportEqualsDeclaration, fullStart); + importEqualsDeclaration.decorators = decorators; setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; parseExpected(SyntaxKind.EqualsToken); @@ -4721,6 +4859,7 @@ module ts { // Import statement let importDeclaration = createNode(SyntaxKind.ImportDeclaration, fullStart); + importDeclaration.decorators = decorators; setModifiers(importDeclaration, modifiers); // ImportDeclaration: @@ -4855,8 +4994,9 @@ module ts { return finishNode(node); } - function parseExportDeclaration(fullStart: number, modifiers: ModifiersArray): ExportDeclaration { + function parseExportDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportDeclaration { let node = createNode(SyntaxKind.ExportDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(SyntaxKind.AsteriskToken)) { parseExpected(SyntaxKind.FromKeyword); @@ -4872,8 +5012,9 @@ module ts { return finishNode(node); } - function parseExportAssignment(fullStart: number, modifiers: ModifiersArray): ExportAssignment { + function parseExportAssignment(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportAssignment { let node = createNode(SyntaxKind.ExportAssignment, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(SyntaxKind.EqualsToken)) { node.isExportEquals = true; @@ -4898,7 +5039,7 @@ module ts { return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } - function isDeclarationStart(): boolean { + function isDeclarationStart(followsModifier?: boolean): boolean { switch (token) { case SyntaxKind.VarKeyword: case SyntaxKind.ConstKeyword: @@ -4928,6 +5069,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 !followsModifier; } } @@ -4954,12 +5099,12 @@ module ts { function nextTokenCanFollowExportKeyword() { nextToken(); return token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || isDeclarationStart(); + token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || isDeclarationStart(/*followsModifier*/ true); } function nextTokenIsDeclarationStart() { nextToken(); - return isDeclarationStart(); + return isDeclarationStart(/*followsModifier*/ true); } function nextTokenIsAsKeyword() { @@ -4968,14 +5113,15 @@ module ts { function parseDeclaration(): ModuleElement { let fullStart = getNodePos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); if (token === SyntaxKind.ExportKeyword) { nextToken(); if (token === SyntaxKind.DefaultKeyword || token === SyntaxKind.EqualsToken) { - return parseExportAssignment(fullStart, modifiers); + return parseExportAssignment(fullStart, decorators, modifiers); } if (token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken) { - return parseExportDeclaration(fullStart, modifiers); + return parseExportDeclaration(fullStart, decorators, modifiers); } } @@ -4983,22 +5129,31 @@ 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 parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); + return parseImportDeclarationOrImportEqualsDeclaration(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. + let node = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + node.pos = fullStart; + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 253daff86d392..cb12e6da4d5db 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -10,7 +10,23 @@ module ts { /** The version of the TypeScript compiler release */ export let version = "1.5.0.0"; - export function createCompilerHost(options: CompilerOptions): CompilerHost { + export function findConfigFile(searchPath: string): string { + var fileName = "tsconfig.json"; + while (true) { + if (sys.fileExists(fileName)) { + return fileName; + } + var parentPath = getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; + fileName = "../" + fileName; + } + return undefined; + } + + export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost { let currentDirectory: string; let existingDirectories: Map = {}; @@ -38,7 +54,7 @@ module ts { } text = ""; } - return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined; + return text !== undefined ? createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined; } function directoryExists(directoryPath: string): boolean { @@ -87,6 +103,11 @@ module ts { export function getPreEmitDiagnostics(program: Program): Diagnostic[] { let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics()); + + if (program.getCompilerOptions().declaration) { + diagnostics.concat(program.getDeclarationDiagnostics()); + } + return sortAndDeduplicateDiagnostics(diagnostics); } @@ -178,11 +199,6 @@ module ts { return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false)); } - function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] { - let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile); - return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); - } - function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback): EmitResult { // If the noEmitOnError flag is set, then check if we have any errors so far. If so, // immediately bail out. @@ -232,6 +248,10 @@ module ts { return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile); } + function getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile); + } + function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { return sourceFile.parseDiagnostics; } @@ -247,6 +267,15 @@ module ts { return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); } + function getDeclarationDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { + if (!isDeclarationFile(sourceFile)) { + let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); + // Don't actually write any files since we're just getting diagnostics. + var writeFile: WriteFileCallback = () => { }; + return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); + } + } + function getGlobalDiagnostics(): Diagnostic[] { let typeChecker = getDiagnosticsProducingTypeChecker(); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index fbcadab8c1d85..73d65d9206e55 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -148,6 +148,7 @@ module ts { "&=": SyntaxKind.AmpersandEqualsToken, "|=": SyntaxKind.BarEqualsToken, "^=": SyntaxKind.CaretEqualsToken, + "@": SyntaxKind.AtToken, }; /* @@ -318,13 +319,38 @@ module ts { let hasOwnProperty = Object.prototype.hasOwnProperty; export function isWhiteSpace(ch: number): boolean { - return ch === CharacterCodes.space || ch === CharacterCodes.tab || ch === CharacterCodes.verticalTab || ch === CharacterCodes.formFeed || - ch === CharacterCodes.nonBreakingSpace || ch === CharacterCodes.ogham || ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || - ch === CharacterCodes.narrowNoBreakSpace || ch === CharacterCodes.mathematicalSpace || ch === CharacterCodes.ideographicSpace || ch === CharacterCodes.byteOrderMark; + // Note: nextLine is in the Zs space, and should be considered to be a whitespace. + // It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript. + return ch === CharacterCodes.space || + ch === CharacterCodes.tab || + ch === CharacterCodes.verticalTab || + ch === CharacterCodes.formFeed || + ch === CharacterCodes.nonBreakingSpace || + ch === CharacterCodes.nextLine || + ch === CharacterCodes.ogham || + ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || + ch === CharacterCodes.narrowNoBreakSpace || + ch === CharacterCodes.mathematicalSpace || + ch === CharacterCodes.ideographicSpace || + ch === CharacterCodes.byteOrderMark; } export function isLineBreak(ch: number): boolean { - return ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn || ch === CharacterCodes.lineSeparator || ch === CharacterCodes.paragraphSeparator || ch === CharacterCodes.nextLine; + // ES5 7.3: + // The ECMAScript line terminator characters are listed in Table 3. + // Table 3 Line Terminator Characters + // Code Unit Value Name Formal Name + // \u000A Line Feed + // \u000D Carriage Return + // \u2028 Line separator + // \u2029 Paragraph separator + // Only the characters in Table 3 are treated as line terminators. Other new line or line + // breaking characters are treated as white space but not as line terminators. + + return ch === CharacterCodes.lineFeed || + ch === CharacterCodes.carriageReturn || + ch === CharacterCodes.lineSeparator || + ch === CharacterCodes.paragraphSeparator; } function isDigit(ch: number): boolean { @@ -455,11 +481,13 @@ module ts { return pos; } - // Extract comments from the given source text starting at the given position. If trailing is false, whitespace is skipped until - // the first line break and comments between that location and the next token are returned. If trailing is true, comments occurring - // between the given position and the next line break are returned. The return value is an array containing a TextRange for each - // comment. Single-line comment ranges include the beginning '//' characters but not the ending line break. Multi-line comment - // ranges include the beginning '/* and ending '*/' characters. The return value is undefined if no comments were found. + // Extract comments from the given source text starting at the given position. If trailing is + // false, whitespace is skipped until the first line break and comments between that location + // and the next token are returned.If trailing is true, comments occurring between the given + // position and the next line break are returned.The return value is an array containing a + // TextRange for each comment. Single-line comment ranges include the beginning '//' characters + // but not the ending line break. Multi - line comment ranges include the beginning '/* and + // ending '*/' characters.The return value is undefined if no comments were found. function getCommentRanges(text: string, pos: number, trailing: boolean): CommentRange[] { let result: CommentRange[]; let collecting = trailing || pos === 0; @@ -467,7 +495,9 @@ module ts { let ch = text.charCodeAt(pos); switch (ch) { case CharacterCodes.carriageReturn: - if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) pos++; + if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { + pos++; + } case CharacterCodes.lineFeed: pos++; if (trailing) { @@ -509,7 +539,10 @@ module ts { } } if (collecting) { - if (!result) result = []; + if (!result) { + result = []; + } + result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine }); } continue; @@ -1247,6 +1280,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: let cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar)) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 3f82d6c8cf509..a0d21106f4357 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -132,23 +132,6 @@ module ts { return typeof JSON === "object" && typeof JSON.parse === "function"; } - function findConfigFile(): string { - var searchPath = normalizePath(sys.getCurrentDirectory()); - var fileName = "tsconfig.json"; - while (true) { - if (sys.fileExists(fileName)) { - return fileName; - } - var parentPath = getDirectoryPath(searchPath); - if (parentPath === searchPath) { - break; - } - searchPath = parentPath; - fileName = "../" + fileName; - } - return undefined; - } - export function executeCommandLine(args: string[]): void { var commandLine = parseCommandLine(args); var configFileName: string; // Configuration file name (if any) @@ -198,7 +181,8 @@ module ts { } } else if (commandLine.fileNames.length === 0 && isJSONSupported()) { - configFileName = findConfigFile(); + var searchPath = normalizePath(sys.getCurrentDirectory()); + configFileName = findConfigFile(searchPath); } if (commandLine.fileNames.length === 0 && !configFileName) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 87d219c2e844a..a18cc84ba5f58 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -67,6 +67,7 @@ module ts { BarBarToken, QuestionToken, ColonToken, + AtToken, // Assignments EqualsToken, PlusEqualsToken, @@ -154,6 +155,7 @@ module ts { // Signature elements TypeParameter, Parameter, + Decorator, // TypeMember PropertySignature, PropertyDeclaration, @@ -244,6 +246,7 @@ module ts { ExportDeclaration, NamedExports, ExportSpecifier, + MissingDeclaration, // Module references ExternalModuleReference, @@ -327,22 +330,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 { @@ -357,13 +363,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; - 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 (in document order) + 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) } export interface NodeArray extends Array, TextRange { @@ -397,6 +404,10 @@ module ts { expression: Expression; } + export interface Decorator extends Node { + expression: LeftHandSideExpression; + } + export interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -1005,14 +1016,14 @@ module ts { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; @@ -1189,9 +1200,11 @@ module ts { CannotBeNamed } + export type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; + export interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; // aliases that need to have this symbol visible + aliasesToMakeVisible?: AnyImportSyntax[]; // aliases that need to have this symbol visible errorSymbolName?: string; // Optional symbol name that results in error errorNode?: Node; // optional node that results in error } @@ -1201,21 +1214,23 @@ module ts { } export interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; hasExportDefaultValue(node: SourceFile): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } @@ -1330,17 +1345,18 @@ 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, - BlockScopedBindingInLoop = 0x00000100, + EnumValuesComputed = 0x00000080, + BlockScopedBindingInLoop = 0x00000100, + EmitDecorate = 0x00000200, // Emit __decorate } export interface NodeLinks { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4fce9c928f7b7..bbe156cbd3c92 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1,4 +1,4 @@ -/// +/// module ts { export interface ReferencePathMatchResult { @@ -361,16 +361,16 @@ module ts { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; } - export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode?: SourceFile) { - sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); - + export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { // If parameter/type parameter, the prev token trailing comments are part of this node too if (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter) { // e.g. (/** blah */ a, /** blah */ b); - return concatenate(getTrailingCommentRanges(sourceFileOfNode.text, node.pos), - // e.g.: ( - // /** blah */ a, - // /** blah */ b); + + // e.g.: ( + // /** blah */ a, + // /** blah */ b); + return concatenate( + getTrailingCommentRanges(sourceFileOfNode.text, node.pos), getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { @@ -575,6 +575,83 @@ module ts { return (node).expression; } + export function nodeCanBeDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + // classes are valid targets + return true; + + case SyntaxKind.PropertyDeclaration: + // property declarations are valid if their parent is a class declaration. + return node.parent.kind === SyntaxKind.ClassDeclaration; + + case SyntaxKind.Parameter: + // if the parameter's parent has a body and its grandparent is a class declaration, this is a valid target; + return (node.parent).body && node.parent.parent.kind === SyntaxKind.ClassDeclaration; + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.MethodDeclaration: + // if this method has a body and its parent is a class declaration, this is a valid target. + return (node).body && node.parent.kind === SyntaxKind.ClassDeclaration; + } + + return false; + } + + export function nodeIsDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + if (node.decorators) { + return true; + } + + return false; + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + if (node.decorators) { + return true; + } + + return false; + + case SyntaxKind.GetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return false; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.SetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return false; + } + + return false; + } + + export function childIsDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + return forEach((node).members, nodeOrChildIsDecorated); + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.SetAccessor: + return forEach((node).parameters, nodeIsDecorated); + } + + return false; + } + + export function nodeOrChildIsDecorated(node: Node): boolean { + return nodeIsDecorated(node) || childIsDecorated(node); + } + export function isExpression(node: Node): boolean { switch (node.kind) { case SyntaxKind.ThisKeyword: @@ -814,6 +891,20 @@ module ts { } } + export function isClassElement(n: Node): boolean { + switch (n.kind) { + case SyntaxKind.Constructor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.IndexSignature: + return true; + default: + return false; + } + } + // True if the given identifier, string literal, or number literal is the name of a declaration node export function isDeclarationName(name: Node): boolean { if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral && name.kind !== SyntaxKind.NumericLiteral) { @@ -1212,28 +1303,6 @@ module ts { return node; } - export function generateUniqueName(baseName: string, isExistingName: (name: string) => boolean): string { - // First try '_name' - if (baseName.charCodeAt(0) !== CharacterCodes._) { - baseName = "_" + baseName; - if (!isExistingName(baseName)) { - return baseName; - } - } - // Find the first unique '_name_n', where n is a positive number - if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) { - baseName += "_"; - } - let i = 1; - while (true) { - let name = baseName + i; - if (!isExistingName(name)) { - return name; - } - i++; - } - } - // @internal export function createDiagnosticCollection(): DiagnosticCollection { let nonFileDiagnostics: Diagnostic[] = []; @@ -1364,4 +1433,322 @@ module ts { s.replace(nonAsciiCharacters, c => get16BitUnicodeEscapeSequence(c.charCodeAt(0))) : s; } + + export interface EmitTextWriter { + write(s: string): void; + writeTextOfNode(sourceFile: SourceFile, node: Node): void; + writeLine(): void; + increaseIndent(): void; + decreaseIndent(): void; + getText(): string; + rawWrite(s: string): void; + writeLiteral(s: string): void; + getTextPos(): number; + getLine(): number; + getColumn(): number; + getIndent(): number; + } + + let indentStrings: string[] = ["", " "]; + export function getIndentString(level: number) { + if (indentStrings[level] === undefined) { + indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + } + return indentStrings[level]; + } + + export function getIndentSize() { + return indentStrings[1].length; + } + + export function createTextWriter(newLine: String): EmitTextWriter { + let output = ""; + let indent = 0; + let lineStart = true; + let lineCount = 0; + let linePos = 0; + + function write(s: string) { + if (s && s.length) { + if (lineStart) { + output += getIndentString(indent); + lineStart = false; + } + output += s; + } + } + + function rawWrite(s: string) { + if (s !== undefined) { + if (lineStart) { + lineStart = false; + } + output += s; + } + } + + function writeLiteral(s: string) { + if (s && s.length) { + write(s); + let lineStartsOfS = computeLineStarts(s); + if (lineStartsOfS.length > 1) { + lineCount = lineCount + lineStartsOfS.length - 1; + linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; + } + } + } + + function writeLine() { + if (!lineStart) { + output += newLine; + lineCount++; + linePos = output.length; + lineStart = true; + } + } + + function writeTextOfNode(sourceFile: SourceFile, node: Node) { + write(getSourceTextOfNodeFromSourceFile(sourceFile, node)); + } + + return { + write, + rawWrite, + writeTextOfNode, + writeLiteral, + writeLine, + increaseIndent: () => indent++, + decreaseIndent: () => indent--, + getIndent: () => indent, + getTextPos: () => output.length, + getLine: () => lineCount + 1, + getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, + getText: () => output, + }; + } + + export function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) { + let compilerOptions = host.getCompilerOptions(); + let emitOutputFilePathWithoutExtension: string; + if (compilerOptions.outDir) { + emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + } + else { + emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName); + } + + return emitOutputFilePathWithoutExtension + extension; + } + + export function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { + let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); + sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); + return combinePaths(newDirPath, sourceFilePath); + } + + export function writeFile(host: EmitHost, diagnostics: Diagnostic[], fileName: string, data: string, writeByteOrderMark: boolean) { + host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => { + diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); + }); + } + + export function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { + return getLineAndCharacterOfPosition(currentSourceFile, pos).line; + } + + export function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { + return forEach(node.members, member => { + if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { + return member; + } + }); + } + + export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { + if (!isDeclarationFile(sourceFile)) { + if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.fileName, ".js")) { + return true; + } + return false; + } + return false; + } + + export function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration) { + let firstAccessor: AccessorDeclaration; + let secondAccessor: AccessorDeclaration; + let getAccessor: AccessorDeclaration; + let setAccessor: AccessorDeclaration; + if (hasDynamicName(accessor)) { + firstAccessor = accessor; + if (accessor.kind === SyntaxKind.GetAccessor) { + getAccessor = accessor; + } + else if (accessor.kind === SyntaxKind.SetAccessor) { + setAccessor = accessor; + } + else { + Debug.fail("Accessor has wrong kind"); + } + } + else { + forEach(declarations, (member: Declaration) => { + if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) + && (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) { + let memberName = getPropertyNameForPropertyNameNode(member.name); + let accessorName = getPropertyNameForPropertyNameNode(accessor.name); + if (memberName === accessorName) { + if (!firstAccessor) { + firstAccessor = member; + } + else if (!secondAccessor) { + secondAccessor = member; + } + + if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { + getAccessor = member; + } + + if (member.kind === SyntaxKind.SetAccessor && !setAccessor) { + setAccessor = member; + } + } + } + }); + } + return { + firstAccessor, + secondAccessor, + getAccessor, + setAccessor + }; + } + + export function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { + // If the leading comments start on different line than the start of node, write new line + if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && + getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { + writer.writeLine(); + } + } + + export function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, + writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { + let emitLeadingSpace = !trailingSeparator; + forEach(comments, comment => { + if (emitLeadingSpace) { + writer.write(" "); + emitLeadingSpace = false; + } + writeComment(currentSourceFile, writer, comment, newLine); + if (comment.hasTrailingNewLine) { + writer.writeLine(); + } + else if (trailingSeparator) { + writer.write(" "); + } + else { + // Emit leading space to separate comment during next comment emit + emitLeadingSpace = true; + } + }); + } + + export function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { + let firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); + let lineCount = getLineStarts(currentSourceFile).length; + let firstCommentLineIndent: number; + for (let pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { + let nextLineStart = (currentLine + 1) === lineCount + ? currentSourceFile.text.length + 1 + : getStartPositionOfLine(currentLine + 1, currentSourceFile); + + if (pos !== comment.pos) { + // If we are not emitting first line, we need to write the spaces to adjust the alignment + if (firstCommentLineIndent === undefined) { + firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); + } + + // These are number of spaces writer is going to write at current indent + let currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); + + // Number of spaces we want to be writing + // eg: Assume writer indent + // module m { + // /* starts at character 9 this is line 1 + // * starts at character pos 4 line --1 = 8 - 8 + 3 + // More left indented comment */ --2 = 8 - 8 + 2 + // class c { } + // } + // module m { + // /* this is line 1 -- Assume current writer indent 8 + // * line --3 = 8 - 4 + 5 + // More right indented comment */ --4 = 8 - 4 + 11 + // class c { } + // } + let spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); + if (spacesToEmit > 0) { + let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); + let indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); + + // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces + writer.rawWrite(indentSizeSpaceString); + + // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces) + while (numberOfSingleSpacesToEmit) { + writer.rawWrite(" "); + numberOfSingleSpacesToEmit--; + } + } + else { + // No spaces to emit write empty string + writer.rawWrite(""); + } + } + + // Write the comment line text + writeTrimmedCurrentLine(pos, nextLineStart); + + pos = nextLineStart; + } + } + else { + // Single line comment of style //.... + writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); + } + + function writeTrimmedCurrentLine(pos: number, nextLineStart: number) { + let end = Math.min(comment.end, nextLineStart - 1); + let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); + if (currentLineText) { + // trimmed forward and ending spaces text + writer.write(currentLineText); + if (end !== comment.end) { + writer.writeLine(); + } + } + else { + // Empty string - make sure we write empty line + writer.writeLiteral(newLine); + } + } + + function calculateIndent(pos: number, end: number) { + let currentLineIndent = 0; + for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { + if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) { + // Tabs = TabSize = indent size and go to next tabStop + currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); + } + else { + // Single space + currentLineIndent++; + } + } + + return currentLineIndent; + } + } + } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 95a320ac052c6..5d488259a365b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -620,7 +620,7 @@ module FourSlash { this.scenarioActions.push(''); var members = this.getMemberListAtCaret(); - if (members.entries.filter(e => e.name === symbol).length !== 0) { + if (members && members.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Member list did contain ' + symbol); } } @@ -691,7 +691,12 @@ module FourSlash { public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { var completions = this.getCompletionListAtCaret(); - this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + if (completions) { + this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + } + else { + this.raiseError(`No completions at position '${ this.currentCaretPosition }' when looking for '${ symbol }'.`); + } } public verifyCompletionListDoesNotContain(symbol: string) { @@ -699,7 +704,7 @@ module FourSlash { this.scenarioActions.push(''); var completions = this.getCompletionListAtCaret(); - if (completions && completions.entries && completions.entries.filter(e => e.name === symbol).length !== 0) { + if (completions && completions.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Completion list did contain ' + symbol); } } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 68ac8d916fbcc..299ba52bdebd9 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -330,6 +330,9 @@ module Harness.LanguageService { getReferencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] { return unwrapJSONCallResult(this.shim.getReferencesAtPosition(fileName, position)); } + findReferences(fileName: string, position: number): ts.ReferencedSymbol[] { + return unwrapJSONCallResult(this.shim.findReferences(fileName, position)); + } getOccurrencesAtPosition(fileName: string, position: number): ts.ReferenceEntry[] { return unwrapJSONCallResult(this.shim.getOccurrencesAtPosition(fileName, position)); } diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 040eb69ae9613..2096fa839dfcc 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1155,3 +1155,17 @@ interface ArrayConstructor { } declare var Array: ArrayConstructor; + +interface TypedPropertyDescriptor { + enumerable?: boolean; + configurable?: boolean; + writable?: boolean; + value?: T; + get?: () => T; + set?: (value: T) => void; +} + +declare type ClassDecorator = (target: TFunction) => TFunction | void; +declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void; +declare type MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void; +declare type ParameterDecorator = (target: Function, propertyKey: string | symbol, parameterIndex: number) => void; diff --git a/src/server/client.ts b/src/server/client.ts index c8e7f2fdcb1a6..875e3ffdb5b7b 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -46,21 +46,21 @@ module ts.server { return lineMap; } - private lineColToPosition(fileName: string, lineCol: protocol.Location): number { - return ts.computePositionOfLineAndCharacter(this.getLineMap(fileName), lineCol.line - 1, lineCol.col - 1); + private lineOffsetToPosition(fileName: string, lineOffset: protocol.Location): number { + return ts.computePositionOfLineAndCharacter(this.getLineMap(fileName), lineOffset.line - 1, lineOffset.offset - 1); } - private positionToOneBasedLineCol(fileName: string, position: number): protocol.Location { - var lineCol = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position); + private positionToOneBasedLineOffset(fileName: string, position: number): protocol.Location { + var lineOffset = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position); return { - line: lineCol.line + 1, - col: lineCol.character + 1 + line: lineOffset.line + 1, + offset: lineOffset.character + 1 }; } private convertCodeEditsToTextChange(fileName: string, codeEdit: protocol.CodeEdit): ts.TextChange { - var start = this.lineColToPosition(fileName, codeEdit.start); - var end = this.lineColToPosition(fileName, codeEdit.end); + var start = this.lineOffsetToPosition(fileName, codeEdit.start); + var end = this.lineOffsetToPosition(fileName, codeEdit.end); return { span: ts.createTextSpanFromBounds(start, end), @@ -134,15 +134,15 @@ module ts.server { // clear the line map after an edit this.lineMaps[fileName] = undefined; - var lineCol = this.positionToOneBasedLineCol(fileName, start); - var endLineCol = this.positionToOneBasedLineCol(fileName, end); + var lineOffset = this.positionToOneBasedLineOffset(fileName, start); + var endLineOffset = this.positionToOneBasedLineOffset(fileName, end); var args: protocol.ChangeRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, - endLine: endLineCol.line, - endCol: endLineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, + endLine: endLineOffset.line, + endOffset: endLineOffset.offset, insertString: newText }; @@ -150,18 +150,18 @@ module ts.server { } getQuickInfoAtPosition(fileName: string, position: number): QuickInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col + line: lineOffset.line, + offset: lineOffset.offset }; var request = this.processRequest(CommandNames.Quickinfo, args); var response = this.processResponse(request); - var start = this.lineColToPosition(fileName, response.body.start); - var end = this.lineColToPosition(fileName, response.body.end); + var start = this.lineOffsetToPosition(fileName, response.body.start); + var end = this.lineOffsetToPosition(fileName, response.body.end); return { kind: response.body.kind, @@ -173,11 +173,11 @@ module ts.server { } getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.CompletionsRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, prefix: undefined }; @@ -194,11 +194,11 @@ module ts.server { } getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.CompletionDetailsRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, entryNames: [entryName] }; @@ -219,8 +219,8 @@ module ts.server { return response.body.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { name: entry.name, @@ -237,14 +237,14 @@ module ts.server { } getFormattingEditsForRange(fileName: string, start: number, end: number, options: ts.FormatCodeOptions): ts.TextChange[] { - var startLineCol = this.positionToOneBasedLineCol(fileName, start); - var endLineCol = this.positionToOneBasedLineCol(fileName, end); + var startLineOffset = this.positionToOneBasedLineOffset(fileName, start); + var endLineOffset = this.positionToOneBasedLineOffset(fileName, end); var args: protocol.FormatRequestArgs = { file: fileName, - line: startLineCol.line, - col: startLineCol.col, - endLine: endLineCol.line, - endCol: endLineCol.col, + line: startLineOffset.line, + offset: startLineOffset.offset, + endLine: endLineOffset.line, + endOffset: endLineOffset.offset, }; // TODO: handle FormatCodeOptions @@ -259,11 +259,11 @@ module ts.server { } getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): ts.TextChange[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FormatOnKeyRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, key: key }; @@ -275,11 +275,11 @@ module ts.server { } getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.Definition, args); @@ -287,8 +287,8 @@ module ts.server { return response.body.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { containerKind: "", containerName: "", @@ -300,12 +300,17 @@ module ts.server { }); } + findReferences(fileName: string, position: number): ReferencedSymbol[]{ + // Not yet implemented. + return []; + } + getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.References, args); @@ -313,8 +318,8 @@ module ts.server { return response.body.refs.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { fileName: fileName, textSpan: ts.createTextSpanFromBounds(start, end), @@ -340,11 +345,11 @@ module ts.server { } getRenameInfo(fileName: string, position: number, findInStrings?: boolean, findInComments?: boolean): RenameInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.RenameRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, findInStrings, findInComments }; @@ -355,8 +360,8 @@ module ts.server { response.body.locs.map((entry: protocol.SpanGroup) => { var fileName = entry.file; entry.locs.map((loc: protocol.TextSpan) => { - var start = this.lineColToPosition(fileName, loc.start); - var end = this.lineColToPosition(fileName, loc.end); + var start = this.lineOffsetToPosition(fileName, loc.start); + var end = this.lineOffsetToPosition(fileName, loc.end); locations.push({ textSpan: ts.createTextSpanFromBounds(start, end), fileName: fileName @@ -400,7 +405,7 @@ module ts.server { text: item.text, kind: item.kind, kindModifiers: item.kindModifiers || "", - spans: item.spans.map(span=> createTextSpanFromBounds(this.lineColToPosition(fileName, span.start), this.lineColToPosition(fileName, span.end))), + spans: item.spans.map(span=> createTextSpanFromBounds(this.lineOffsetToPosition(fileName, span.start), this.lineOffsetToPosition(fileName, span.end))), childItems: this.decodeNavigationBarItems(item.childItems, fileName), indent: 0, bolded: false, @@ -444,19 +449,19 @@ module ts.server { } getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.Brace, args); var response = this.processResponse(request); return response.body.map(entry => { - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { start: start, length: end - start, diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 7c9ccfa785464..034549ab464fe 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -19,15 +19,23 @@ module ts.server { class ScriptInfo { svc: ScriptVersionCache; children: ScriptInfo[] = []; // files referenced by this file - defaultProject: Project; // project to use by default for file - fileWatcher: FileWatcher; + formatCodeOptions = ts.clone(CompilerService.defaultFormatCodeOptions); constructor(private host: ServerHost, public fileName: string, public content: string, public isOpen = false) { this.svc = ScriptVersionCache.fromString(content); } + setFormatOptions(tabSize?: number, indentSize?: number) { + if (tabSize) { + this.formatCodeOptions.TabSize = tabSize; + } + if (indentSize) { + this.formatCodeOptions.IndentSize = indentSize; + } + } + close() { this.isOpen = false; } @@ -200,33 +208,33 @@ module ts.server { } else { var nextLineInfo = index.lineNumberToInfo(line + 2); - len = nextLineInfo.col - lineInfo.col; + len = nextLineInfo.offset - lineInfo.offset; } - return ts.createTextSpan(lineInfo.col, len); + return ts.createTextSpan(lineInfo.offset, len); } /** * @param line 1 based index - * @param col 1 based index + * @param offset 1 based index */ - lineColToPosition(filename: string, line: number, col: number): number { + lineOffsetToPosition(filename: string, line: number, offset: number): number { var script: ScriptInfo = this.filenameToScript[filename]; var index = script.snap().index; var lineInfo = index.lineNumberToInfo(line); - // TODO: assert this column is actually on the line - return (lineInfo.col + col - 1); + // TODO: assert this offset is actually on the line + return (lineInfo.offset + offset - 1); } /** * @param line 1-based index - * @param col 1-based index + * @param offset 1-based index */ - positionToLineCol(filename: string, position: number): ILineInfo { + positionToLineOffset(filename: string, position: number): ILineInfo { var script: ScriptInfo = this.filenameToScript[filename]; var index = script.snap().index; - var lineCol = index.charOffsetToLineNumberAndPos(position); - return { line: lineCol.line, col: lineCol.col + 1 }; + var lineOffset = index.charOffsetToLineNumberAndPos(position); + return { line: lineOffset.line, offset: lineOffset.offset + 1 }; } } @@ -259,20 +267,29 @@ module ts.server { interface ProjectOptions { // these fields can be present in the project file files?: string[]; - formatCodeOptions?: ts.FormatCodeOptions; compilerOptions?: ts.CompilerOptions; } export class Project { compilerService: CompilerService; - projectOptions: ProjectOptions; projectFilename: string; program: ts.Program; filenameToSourceFile: ts.Map = {}; updateGraphSeq = 0; + /** Used for configured projects which may have multiple open roots */ + openRefCount = 0; - constructor(public projectService: ProjectService) { - this.compilerService = new CompilerService(this); + constructor(public projectService: ProjectService, public projectOptions?: ProjectOptions) { + this.compilerService = new CompilerService(this,projectOptions && projectOptions.compilerOptions); + } + + addOpenRef() { + this.openRefCount++; + } + + deleteOpenRef() { + this.openRefCount--; + return this.openRefCount; } openReferencedFile(filename: string) { @@ -292,6 +309,10 @@ module ts.server { } } + isRoot(info: ScriptInfo) { + return this.compilerService.host.roots.some(root => root === info); + } + removeReferencedFile(info: ScriptInfo) { this.compilerService.host.removeReferencedFile(info); this.updateGraph(); @@ -338,7 +359,6 @@ module ts.server { if (projectOptions.compilerOptions) { this.compilerService.setCompilerOptions(projectOptions.compilerOptions); } - // TODO: format code options } } @@ -362,16 +382,45 @@ module ts.server { (eventName: string, project: Project, fileName: string): void; } + interface HostConfiguration { + formatCodeOptions: ts.FormatCodeOptions; + hostInfo: string; + } + export class ProjectService { filenameToScriptInfo: ts.Map = {}; - // open, non-configured files in two lists + // open, non-configured root files openFileRoots: ScriptInfo[] = []; - openFilesReferenced: ScriptInfo[] = []; - // projects covering open files + // projects built from openFileRoots inferredProjects: Project[] = []; + // projects specified by a tsconfig.json file + configuredProjects: Project[] = []; + // open files referenced by a project + openFilesReferenced: ScriptInfo[] = []; + // open files that are roots of a configured project + openFileRootsConfigured: ScriptInfo[] = []; + hostConfiguration: HostConfiguration; constructor(public host: ServerHost, public psLogger: Logger, public eventHandler?: ProjectServiceEventHandler) { // ts.disableIncrementalParsing = true; + this.addDefaultHostConfiguration(); + } + + addDefaultHostConfiguration() { + this.hostConfiguration = { + formatCodeOptions: ts.clone(CompilerService.defaultFormatCodeOptions), + hostInfo: "Unknown host" + } + } + + getFormatCodeOptions(file?: string) { + if (file) { + var info = this.filenameToScriptInfo[file]; + if (info) { + return info.formatCodeOptions; + } + } + return this.hostConfiguration.formatCodeOptions; } watchedFileChanged(fileName: string) { @@ -395,6 +444,22 @@ module ts.server { this.psLogger.msg(msg, type); } + setHostConfiguration(args: ts.server.protocol.ConfigureRequestArguments) { + if (args.file) { + var info = this.filenameToScriptInfo[args.file]; + if (info) { + info.setFormatOptions(args.tabSize, args.indentSize); + this.log("Host configuration update for file " + args.file + " tab size " + args.tabSize); + } + } + else { + this.hostConfiguration.formatCodeOptions.TabSize = args.tabSize; + this.hostConfiguration.formatCodeOptions.IndentSize = args.indentSize; + this.hostConfiguration.hostInfo = args.hostInfo; + this.log("Host information " + args.hostInfo, "Info"); + } + } + closeLog() { this.psLogger.close(); } @@ -438,44 +503,77 @@ module ts.server { this.printProjects(); } + updateConfiguredProjectList() { + var configuredProjects: Project[] = []; + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + if (this.configuredProjects[i].openRefCount > 0) { + configuredProjects.push(this.configuredProjects[i]); + } + } + this.configuredProjects = configuredProjects; + } + + setConfiguredProjectRoot(info: ScriptInfo) { + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + let configuredProject = this.configuredProjects[i]; + if (configuredProject.isRoot(info)) { + info.defaultProject = configuredProject; + configuredProject.addOpenRef(); + return true; + } + } + return false; + } + addOpenFile(info: ScriptInfo) { - this.findReferencingProjects(info); - if (info.defaultProject) { - this.openFilesReferenced.push(info); + if (this.setConfiguredProjectRoot(info)) { + this.openFileRootsConfigured.push(info); } else { - // create new inferred project p with the newly opened file as root - info.defaultProject = this.createInferredProject(info); - var openFileRoots: ScriptInfo[] = []; - // for each inferred project root r - for (var i = 0, len = this.openFileRoots.length; i < len; i++) { - var r = this.openFileRoots[i]; - // if r referenced by the new project - if (info.defaultProject.getSourceFile(r)) { - // remove project rooted at r - this.inferredProjects = - copyListRemovingItem(r.defaultProject, this.inferredProjects); - // put r in referenced open file list - this.openFilesReferenced.push(r); - // set default project of r to the new project - r.defaultProject = info.defaultProject; - } - else { - // otherwise, keep r as root of inferred project - openFileRoots.push(r); + this.findReferencingProjects(info); + if (info.defaultProject) { + this.openFilesReferenced.push(info); + } + else { + // create new inferred project p with the newly opened file as root + info.defaultProject = this.createInferredProject(info); + var openFileRoots: ScriptInfo[] = []; + // for each inferred project root r + for (var i = 0, len = this.openFileRoots.length; i < len; i++) { + var r = this.openFileRoots[i]; + // if r referenced by the new project + if (info.defaultProject.getSourceFile(r)) { + // remove project rooted at r + this.inferredProjects = + copyListRemovingItem(r.defaultProject, this.inferredProjects); + // put r in referenced open file list + this.openFilesReferenced.push(r); + // set default project of r to the new project + r.defaultProject = info.defaultProject; + } + else { + // otherwise, keep r as root of inferred project + openFileRoots.push(r); + } } + this.openFileRoots = openFileRoots; + this.openFileRoots.push(info); } - this.openFileRoots = openFileRoots; - this.openFileRoots.push(info); } + this.updateConfiguredProjectList(); } + /** + * Remove this file from the set of open, non-configured files. + * @param info The file that has been closed or newly configured + * @param openedByConfig True if info has become a root of a configured project + */ closeOpenFile(info: ScriptInfo) { var openFileRoots: ScriptInfo[] = []; var removedProject: Project; for (var i = 0, len = this.openFileRoots.length; i < len; i++) { // if closed file is root of project - if (info == this.openFileRoots[i]) { + if (info === this.openFileRoots[i]) { // remove that project and remember it removedProject = info.defaultProject; } @@ -484,9 +582,29 @@ module ts.server { } } this.openFileRoots = openFileRoots; + if (!removedProject) { + var openFileRootsConfigured: ScriptInfo[] = []; + + for (var i = 0, len = this.openFileRootsConfigured.length; i < len; i++) { + if (info === this.openFileRootsConfigured[i]) { + if (info.defaultProject.deleteOpenRef() === 0) { + removedProject = info.defaultProject; + } + } + else { + openFileRootsConfigured.push(this.openFileRootsConfigured[i]); + } + } + + this.openFileRootsConfigured = openFileRootsConfigured; + } if (removedProject) { - // remove project from inferred projects list - this.inferredProjects = copyListRemovingItem(removedProject, this.inferredProjects); + if (removedProject.isConfiguredProject()) { + this.configuredProjects = copyListRemovingItem(removedProject, this.configuredProjects); + } + else { + this.inferredProjects = copyListRemovingItem(removedProject, this.inferredProjects); + } var openFilesReferenced: ScriptInfo[] = []; var orphanFiles: ScriptInfo[] = []; // for all open, referenced files f @@ -518,14 +636,22 @@ module ts.server { var referencingProjects: Project[] = []; info.defaultProject = undefined; for (var i = 0, len = this.inferredProjects.length; i < len; i++) { - this.inferredProjects[i].updateGraph(); - if (this.inferredProjects[i] != excludedProject) { - if (this.inferredProjects[i].getSourceFile(info)) { - info.defaultProject = this.inferredProjects[i]; - referencingProjects.push(this.inferredProjects[i]); + var inferredProject = this.inferredProjects[i]; + inferredProject.updateGraph(); + if (inferredProject != excludedProject) { + if (inferredProject.getSourceFile(info)) { + info.defaultProject = inferredProject; + referencingProjects.push(inferredProject); } } } + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + var configuredProject = this.configuredProjects[i]; + configuredProject.updateGraph(); + if (configuredProject.getSourceFile(info)) { + info.defaultProject = configuredProject; + } + } return referencingProjects; } @@ -595,7 +721,7 @@ module ts.server { /** * @param filename is absolute pathname */ - openFile(fileName: string, openedByClient = false) { + openFile(fileName: string, openedByClient: boolean) { fileName = ts.normalizePath(fileName); var info = ts.lookUp(this.filenameToScriptInfo, fileName); if (!info) { @@ -609,6 +735,7 @@ module ts.server { } } if (content !== undefined) { + var indentSize: number; info = new ScriptInfo(this.host, fileName, content, openedByClient); this.filenameToScriptInfo[fileName] = info; if (!info.isOpen) { @@ -629,9 +756,23 @@ module ts.server { * @param filename is absolute pathname */ - openClientFile(filename: string) { - // TODO: tsconfig check - var info = this.openFile(filename, true); + openClientFile(fileName: string) { + var searchPath = ts.normalizePath(getDirectoryPath(fileName)); + var configFileName = ts.findConfigFile(searchPath); + if (configFileName) { + configFileName = getAbsolutePath(configFileName, searchPath); + } + if (configFileName && (!this.configProjectIsActive(configFileName))) { + var configResult = this.openConfigFile(configFileName, fileName); + if (!configResult.success) { + this.log("Error opening config file " + configFileName + " " + configResult.errorMsg); + } + else { + this.log("Opened configuration file " + configFileName,"Info"); + this.configuredProjects.push(configResult.project); + } + } + var info = this.openFile(fileName, true); this.addOpenFile(info); this.printProjects(); return info; @@ -652,19 +793,6 @@ module ts.server { this.printProjects(); } - getProjectsReferencingFile(filename: string) { - var scriptInfo = ts.lookUp(this.filenameToScriptInfo, filename); - if (scriptInfo) { - var projects: Project[] = []; - for (var i = 0, len = this.inferredProjects.length; i < len; i++) { - if (this.inferredProjects[i].getSourceFile(scriptInfo)) { - projects.push(this.inferredProjects[i]); - } - } - return projects; - } - } - getProjectForFile(filename: string) { var scriptInfo = ts.lookUp(this.filenameToScriptInfo, filename); if (scriptInfo) { @@ -677,9 +805,9 @@ module ts.server { if (scriptInfo) { this.psLogger.startGroup(); this.psLogger.info("Projects for " + filename) - var projects = this.getProjectsReferencingFile(filename); + var projects = this.findReferencingProjects(scriptInfo); for (var i = 0, len = projects.length; i < len; i++) { - this.psLogger.info("Inferred Project " + i.toString()); + this.psLogger.info("Project " + i.toString()); } this.psLogger.endGroup(); } @@ -697,18 +825,42 @@ module ts.server { this.psLogger.info(project.filesToString()); this.psLogger.info("-----------------------------------------------"); } - this.psLogger.info("Open file roots: ") + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + var project = this.configuredProjects[i]; + project.updateGraph(); + this.psLogger.info("Project (configured) " + (i+this.inferredProjects.length).toString()); + this.psLogger.info(project.filesToString()); + this.psLogger.info("-----------------------------------------------"); + } + this.psLogger.info("Open file roots of inferred projects: ") for (var i = 0, len = this.openFileRoots.length; i < len; i++) { this.psLogger.info(this.openFileRoots[i].fileName); } - this.psLogger.info("Open files referenced: ") + this.psLogger.info("Open files referenced by inferred or configured projects: ") for (var i = 0, len = this.openFilesReferenced.length; i < len; i++) { - this.psLogger.info(this.openFilesReferenced[i].fileName); + var fileInfo = this.openFilesReferenced[i].fileName; + if (this.openFilesReferenced[i].defaultProject.isConfiguredProject()) { + fileInfo += " (configured)"; + } + this.psLogger.info(fileInfo); + } + this.psLogger.info("Open file roots of configured projects: ") + for (var i = 0, len = this.openFileRootsConfigured.length; i < len; i++) { + this.psLogger.info(this.openFileRootsConfigured[i].fileName); } this.psLogger.endGroup(); } - openConfigFile(configFilename: string): ProjectOpenResult { + configProjectIsActive(fileName: string) { + for (var i = 0, len = this.configuredProjects.length; i < len; i++) { + if (this.configuredProjects[i].projectFilename == fileName) { + return true; + } + } + return false; + } + + openConfigFile(configFilename: string, clientFileName?: string): ProjectOpenResult { configFilename = ts.normalizePath(configFilename); // file references will be relative to dirPath (or absolute) var dirPath = ts.getDirectoryPath(configFilename); @@ -717,35 +869,27 @@ module ts.server { return { errorMsg: "tsconfig syntax error" }; } else { - // REVIEW: specify no base path so can get absolute path below - var parsedCommandLine = ts.parseConfigFile(rawConfig); - - if (parsedCommandLine.errors) { - // TODO: gather diagnostics and transmit + var parsedCommandLine = ts.parseConfigFile(rawConfig, dirPath); + if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) { return { errorMsg: "tsconfig option errors" }; } else if (parsedCommandLine.fileNames) { - var proj = this.createProject(configFilename); + var projectOptions: ProjectOptions = { + files: parsedCommandLine.fileNames, + compilerOptions: parsedCommandLine.options + }; + var proj = this.createProject(configFilename, projectOptions); for (var i = 0, len = parsedCommandLine.fileNames.length; i < len; i++) { var rootFilename = parsedCommandLine.fileNames[i]; - var normRootFilename = ts.normalizePath(rootFilename); - normRootFilename = getAbsolutePath(normRootFilename, dirPath); - if (this.host.fileExists(normRootFilename)) { - var info = this.openFile(normRootFilename); + if (ts.sys.fileExists(rootFilename)) { + var info = this.openFile(rootFilename, clientFileName == rootFilename); proj.addRoot(info); } else { return { errorMsg: "specified file " + rootFilename + " not found" }; } } - var projectOptions: ProjectOptions = { - files: parsedCommandLine.fileNames, - compilerOptions: parsedCommandLine.options - }; - if (rawConfig.formatCodeOptions) { - projectOptions.formatCodeOptions = rawConfig.formatCodeOptions; - } - proj.setProjectOptions(projectOptions); + proj.finishGraph(); return { success: true, project: proj }; } else { @@ -754,10 +898,10 @@ module ts.server { } } - createProject(projectFilename: string) { - var eproj = new Project(this); - eproj.projectFilename = projectFilename; - return eproj; + createProject(projectFilename: string, projectOptions?: ProjectOptions) { + var project = new Project(this, projectOptions); + project.projectFilename = projectFilename; + return project; } } @@ -766,15 +910,17 @@ module ts.server { host: LSHost; languageService: ts.LanguageService; classifier: ts.Classifier; - settings = ts.getDefaultCompilerOptions(); + settings: ts.CompilerOptions; documentRegistry = ts.createDocumentRegistry(); - formatCodeOptions: ts.FormatCodeOptions = CompilerService.defaultFormatCodeOptions; - constructor(public project: Project) { + constructor(public project: Project, opt?: ts.CompilerOptions) { this.host = new LSHost(project.projectService.host, project); - // override default ES6 (remove when compiler default back at ES5) - this.settings.target = ts.ScriptTarget.ES5; - this.host.setCompilationSettings(this.settings); + if (opt) { + this.setCompilerOptions(opt); + } + else { + this.setCompilerOptions(ts.getDefaultCompilerOptions()); + } this.languageService = ts.createLanguageService(this.host, this.documentRegistry); this.classifier = ts.createClassifier(); } @@ -815,7 +961,7 @@ module ts.server { export interface ILineInfo { line: number; - col: number; + offset: number; text?: string; leaf?: LineLeaf; } @@ -1208,7 +1354,7 @@ module ts.server { getLineMapper() { return ((line: number) => { - return this.index.lineNumberToInfo(line).col; + return this.index.lineNumberToInfo(line).offset; }); } @@ -1245,7 +1391,7 @@ module ts.server { else { return { line: lineNumber, - col: this.root.charCount() + offset: this.root.charCount() } } } @@ -1331,7 +1477,7 @@ module ts.server { // check whether last characters deleted are line break var e = pos + deleteLength; var lineInfo = this.charOffsetToLineNumberAndPos(e); - if ((lineInfo && (lineInfo.col == 0))) { + if ((lineInfo && (lineInfo.offset == 0))) { // move range end just past line that will merge with previous line deleteLength += lineInfo.text.length; // store text by appending to end of insertedText @@ -1507,14 +1653,14 @@ module ts.server { if (!childInfo.child) { return { line: lineNumber, - col: charOffset, + offset: charOffset, } } else if (childInfo.childIndex < this.children.length) { if (childInfo.child.isLeaf()) { return { line: childInfo.lineNumber, - col: childInfo.charOffset, + offset: childInfo.charOffset, text: ((childInfo.child)).text, leaf: ((childInfo.child)) }; @@ -1526,7 +1672,7 @@ module ts.server { } else { var lineInfo = this.lineNumberToInfo(this.lineCount(), 0); - return { line: this.lineCount(), col: lineInfo.leaf.charCount() }; + return { line: this.lineCount(), offset: lineInfo.leaf.charCount() }; } } @@ -1535,13 +1681,13 @@ module ts.server { if (!childInfo.child) { return { line: lineNumber, - col: charOffset + offset: charOffset } - } + } else if (childInfo.child.isLeaf()) { return { line: lineNumber, - col: childInfo.charOffset, + offset: childInfo.charOffset, text: ((childInfo.child)).text, leaf: ((childInfo.child)) } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 23ef00d6b44c7..d63aa53ba125b 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -96,7 +96,7 @@ declare module ts.server.protocol { /** * Instances of this interface specify a location in a source file: - * (file, line, col), where line and column are 1-based. + * (file, line, character offset), where line and character offset are 1-based. */ export interface FileLocationRequestArgs extends FileRequestArgs { /** @@ -105,9 +105,9 @@ declare module ts.server.protocol { line: number; /** - * The column for the request (1-based). + * The character offset (on the line) for the request (1-based). */ - col: number; + offset: number; } /** @@ -126,11 +126,11 @@ declare module ts.server.protocol { } /** - * Location in source code expressed as (one-based) line and column. + * Location in source code expressed as (one-based) line and character offset. */ export interface Location { line: number; - col: number; + offset: number; } /** @@ -202,9 +202,9 @@ declare module ts.server.protocol { symbolName: string; /** - * The start column of the symbol (on the line provided by the references request). + * The start character offset of the symbol (on the line provided by the references request). */ - symbolStartCol: number; + symbolStartOffset: number; /** * The full display name of the symbol. @@ -299,6 +299,50 @@ declare module ts.server.protocol { body?: RenameResponseBody; } + /** + * Information found in a configure request. + */ + export interface ConfigureRequestArguments { + /** Number of spaces for each tab */ + tabSize: number; + /** Number of spaces to indent during formatting */ + indentSize: number; + /** + * Information about the host, for example 'Emacs 24.4' or + * 'Sublime Text version 3075' + */ + hostInfo: string; + /** + * If present, tab settings apply only to this file. + */ + file?: string; + } + + /** + * Configure request; value of command field is "configure". Specifies + * host information, such as host type, tab size, and indent size. + */ + export interface ConfigureRequest extends Request { + arguments: ConfigureRequestArguments; + } + + /** + * Response to "configure" request. This is just an acknowledgement, so + * no body field is required. + */ + export interface ConfigureResponse extends Response { + } + + /** + * Information found in an "open" request. + */ + export interface OpenRequestArgs extends FileRequestArgs { + /** Initial tab size of file. */ + tabSize?: number; + /** Number of spaces to indent during formatting */ + indentSize?: number; + } + /** * Open request; value of command field is "open". Notify the * server that the client has file open. The server will not @@ -307,7 +351,8 @@ declare module ts.server.protocol { * reload messages) when the file changes. Server does not currently * send a response to an open request. */ - export interface OpenRequest extends FileRequest { + export interface OpenRequest extends Request { + arguments: OpenRequestArgs; } /** @@ -381,9 +426,9 @@ declare module ts.server.protocol { endLine: number; /** - * Last column of range for which to format text in file. + * Character offset on last line of range for which to format text in file. */ - endCol: number; + endOffset: number; } /** @@ -762,7 +807,7 @@ declare module ts.server.protocol { */ export interface ChangeRequestArgs extends FormatRequestArgs { /** - * Optional string to insert at location (file, line, col). + * Optional string to insert at location (file, line, offset). */ insertString?: string; } @@ -786,7 +831,7 @@ declare module ts.server.protocol { /** * Brace matching request; value of command field is "brace". * Return response giving the file locations of matching braces - * found in file at location line, col. + * found in file at location line, offset. */ export interface BraceRequest extends FileLocationRequest { } diff --git a/src/server/session.ts b/src/server/session.ts index cc705d64d5e93..47ef40a880977 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -5,13 +5,13 @@ /// module ts.server { - var spaceCache = [" ", " ", " ", " "]; + var spaceCache:string[] = []; interface StackTraceError extends Error { stack?: string; } - function generateSpaces(n: number): string { + export function generateSpaces(n: number): string { if (!spaceCache[n]) { var strBuilder = ""; for (var i = 0; i < n; i++) { @@ -44,7 +44,7 @@ module ts.server { else if (a.file == b.file) { var n = compareNumber(a.start.line, b.start.line); if (n == 0) { - return compareNumber(a.start.col, b.start.col); + return compareNumber(a.start.offset, b.start.offset); } else return n; } @@ -55,8 +55,8 @@ module ts.server { function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic) { return { - start: project.compilerService.host.positionToLineCol(fileName, diag.start), - end: project.compilerService.host.positionToLineCol(fileName, diag.start + diag.length), + start: project.compilerService.host.positionToLineOffset(fileName, diag.start), + end: project.compilerService.host.positionToLineOffset(fileName, diag.start + diag.length), text: ts.flattenDiagnosticMessageText(diag.messageText, "\n") }; } @@ -80,6 +80,7 @@ module ts.server { export var Close = "close"; export var Completions = "completions"; export var CompletionDetails = "completionEntryDetails"; + export var Configure = "configure"; export var Definition = "definition"; export var Format = "format"; export var Formatonkey = "formatonkey"; @@ -259,7 +260,7 @@ module ts.server { } } - getDefinition(line: number, col: number, fileName: string): protocol.FileSpan[] { + getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -267,7 +268,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var definitions = compilerService.languageService.getDefinitionAtPosition(file, position); if (!definitions) { @@ -276,12 +277,12 @@ module ts.server { return definitions.map(def => ({ file: def.fileName, - start: compilerService.host.positionToLineCol(def.fileName, def.textSpan.start), - end: compilerService.host.positionToLineCol(def.fileName, ts.textSpanEnd(def.textSpan)) + start: compilerService.host.positionToLineOffset(def.fileName, def.textSpan.start), + end: compilerService.host.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan)) })); } - getRenameLocations(line: number, col: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { + getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -289,7 +290,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var renameInfo = compilerService.languageService.getRenameInfo(file, position); if (!renameInfo) { return undefined; @@ -309,8 +310,8 @@ module ts.server { var bakedRenameLocs = renameLocations.map(location => ({ file: location.fileName, - start: compilerService.host.positionToLineCol(location.fileName, location.textSpan.start), - end: compilerService.host.positionToLineCol(location.fileName, ts.textSpanEnd(location.textSpan)), + start: compilerService.host.positionToLineOffset(location.fileName, location.textSpan.start), + end: compilerService.host.positionToLineOffset(location.fileName, ts.textSpanEnd(location.textSpan)), })).sort((a, b) => { if (a.file < b.file) { return -1; @@ -327,7 +328,7 @@ module ts.server { return -1; } else { - return b.start.col - a.start.col; + return b.start.offset - a.start.offset; } } }).reduce((accum: protocol.SpanGroup[], cur: protocol.FileSpan) => { @@ -349,7 +350,7 @@ module ts.server { return { info: renameInfo, locs: bakedRenameLocs }; } - getReferences(line: number, col: number, fileName: string): protocol.ReferencesResponseBody { + getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody { // TODO: get all projects for this file; report refs for all projects deleting duplicates // can avoid duplicates by eliminating same ref file from subsequent projects var file = ts.normalizePath(fileName); @@ -359,7 +360,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var references = compilerService.languageService.getReferencesAtPosition(file, position); if (!references) { @@ -373,10 +374,10 @@ module ts.server { var displayString = ts.displayPartsToString(nameInfo.displayParts); var nameSpan = nameInfo.textSpan; - var nameColStart = compilerService.host.positionToLineCol(file, nameSpan.start).col; + var nameColStart = compilerService.host.positionToLineOffset(file, nameSpan.start).offset; var nameText = compilerService.host.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan)); var bakedRefs: protocol.ReferencesResponseItem[] = references.map((ref) => { - var start = compilerService.host.positionToLineCol(ref.fileName, ref.textSpan.start); + var start = compilerService.host.positionToLineOffset(ref.fileName, ref.textSpan.start); var refLineSpan = compilerService.host.lineToTextSpan(ref.fileName, start.line - 1); var snap = compilerService.host.getScriptSnapshot(ref.fileName); var lineText = snap.getText(refLineSpan.start, ts.textSpanEnd(refLineSpan)).replace(/\r|\n/g, ""); @@ -384,24 +385,27 @@ module ts.server { file: ref.fileName, start: start, lineText: lineText, - end: compilerService.host.positionToLineCol(ref.fileName, ts.textSpanEnd(ref.textSpan)), + end: compilerService.host.positionToLineOffset(ref.fileName, ts.textSpanEnd(ref.textSpan)), isWriteAccess: ref.isWriteAccess }; }).sort(compareFileStart); return { refs: bakedRefs, symbolName: nameText, - symbolStartCol: nameColStart, + symbolStartOffset: nameColStart, symbolDisplayString: displayString }; } - openClientFile(fileName: string) { + openClientFile(fileName: string, tabSize?: number, indentSize?: number) { var file = ts.normalizePath(fileName); - this.projectService.openClientFile(file); + var info = this.projectService.openClientFile(file); + if (info) { + info.setFormatOptions(tabSize, indentSize); + } } - getQuickInfo(line: number, col: number, fileName: string): protocol.QuickInfoResponseBody { + getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -409,7 +413,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var quickInfo = compilerService.languageService.getQuickInfoAtPosition(file, position); if (!quickInfo) { return undefined; @@ -420,14 +424,14 @@ module ts.server { return { kind: quickInfo.kind, kindModifiers: quickInfo.kindModifiers, - start: compilerService.host.positionToLineCol(file, quickInfo.textSpan.start), - end: compilerService.host.positionToLineCol(file, ts.textSpanEnd(quickInfo.textSpan)), + start: compilerService.host.positionToLineOffset(file, quickInfo.textSpan.start), + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(quickInfo.textSpan)), displayString: displayString, documentation: docString, }; } - getFormattingEditsForRange(line: number, col: number, endLine: number, endCol: number, fileName: string): protocol.CodeEdit[] { + getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -435,25 +439,26 @@ module ts.server { } var compilerService = project.compilerService; - var startPosition = compilerService.host.lineColToPosition(file, line, col); - var endPosition = compilerService.host.lineColToPosition(file, endLine, endCol); + var startPosition = compilerService.host.lineOffsetToPosition(file, line, offset); + var endPosition = compilerService.host.lineOffsetToPosition(file, endLine, endOffset); // TODO: avoid duplicate code (with formatonkey) - var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition, compilerService.formatCodeOptions); + var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition, + this.projectService.getFormatCodeOptions(file)); if (!edits) { return undefined; } return edits.map((edit) => { return { - start: compilerService.host.positionToLineCol(file, edit.span.start), - end: compilerService.host.positionToLineCol(file, ts.textSpanEnd(edit.span)), + start: compilerService.host.positionToLineOffset(file, edit.span.start), + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(edit.span)), newText: edit.newText ? edit.newText : "" }; }); } - getFormattingEditsAfterKeystroke(line: number, col: number, key: string, fileName: string): protocol.CodeEdit[] { + getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -462,9 +467,10 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); + var formatOptions = this.projectService.getFormatCodeOptions(file); var edits = compilerService.languageService.getFormattingEditsAfterKeystroke(file, position, key, - compilerService.formatCodeOptions); + formatOptions); // Check whether we should auto-indent. This will be when // the position is on a line containing only whitespace. // This should leave the edits returned from @@ -480,8 +486,8 @@ module ts.server { if (lineText.search("\\S") < 0) { // TODO: get these options from host var editorOptions: ts.EditorOptions = { - IndentSize: 4, - TabSize: 4, + IndentSize: formatOptions.IndentSize, + TabSize: formatOptions.TabSize, NewLineCharacter: "\n", ConvertTabsToSpaces: true, }; @@ -516,16 +522,16 @@ module ts.server { return edits.map((edit) => { return { - start: compilerService.host.positionToLineCol(file, + start: compilerService.host.positionToLineOffset(file, edit.span.start), - end: compilerService.host.positionToLineCol(file, + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(edit.span)), newText: edit.newText ? edit.newText : "" }; }); } - getCompletions(line: number, col: number, prefix: string, fileName: string): protocol.CompletionEntry[] { + getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] { if (!prefix) { prefix = ""; } @@ -536,7 +542,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var completions = compilerService.languageService.getCompletionsAtPosition(file, position); if (!completions) { @@ -544,14 +550,14 @@ module ts.server { } return completions.entries.reduce((result: protocol.CompletionEntry[], entry: ts.CompletionEntry) => { - if (completions.isMemberCompletion || entry.name.indexOf(prefix) == 0) { + if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) == 0)) { result.push(entry); } return result; - }, []); + }, []).sort((a, b) => a.name.localeCompare(b.name)); } - getCompletionEntryDetails(line: number, col: number, + getCompletionEntryDetails(line: number, offset: number, entryNames: string[], fileName: string): protocol.CompletionEntryDetails[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -560,7 +566,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); return entryNames.reduce((accum: protocol.CompletionEntryDetails[], entryName: string) => { var details = compilerService.languageService.getCompletionEntryDetails(file, position, entryName); @@ -586,13 +592,13 @@ module ts.server { } } - change(line: number, col: number, endLine: number, endCol: number, insertString: string, fileName: string) { + change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (project) { var compilerService = project.compilerService; - var start = compilerService.host.lineColToPosition(file, line, col); - var end = compilerService.host.lineColToPosition(file, endLine, endCol); + var start = compilerService.host.lineOffsetToPosition(file, line, offset); + var end = compilerService.host.lineOffsetToPosition(file, endLine, endOffset); if (start >= 0) { compilerService.host.editScript(file, start, end, insertString); this.changeSeq++; @@ -608,7 +614,7 @@ module ts.server { if (project) { this.changeSeq++; // make sure no changes happen before this one is finished - project.compilerService.host.reloadScript(file, tmpfile,() => { + project.compilerService.host.reloadScript(file, tmpfile, () => { this.output(undefined, CommandNames.Reload, reqSeq); }); } @@ -641,8 +647,8 @@ module ts.server { kind: item.kind, kindModifiers: item.kindModifiers, spans: item.spans.map(span => ({ - start: compilerService.host.positionToLineCol(fileName, span.start), - end: compilerService.host.positionToLineCol(fileName, ts.textSpanEnd(span)) + start: compilerService.host.positionToLineOffset(fileName, span.start), + end: compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(span)) })), childItems: this.decorateNavigationBarItem(project, fileName, item.childItems) })); @@ -678,8 +684,8 @@ module ts.server { } return navItems.map((navItem) => { - var start = compilerService.host.positionToLineCol(navItem.fileName, navItem.textSpan.start); - var end = compilerService.host.positionToLineCol(navItem.fileName, ts.textSpanEnd(navItem.textSpan)); + var start = compilerService.host.positionToLineOffset(navItem.fileName, navItem.textSpan.start); + var end = compilerService.host.positionToLineOffset(navItem.fileName, ts.textSpanEnd(navItem.textSpan)); var bakedItem: protocol.NavtoItem = { name: navItem.name, kind: navItem.kind, @@ -703,7 +709,7 @@ module ts.server { }); } - getBraceMatching(line: number, col: number, fileName: string): protocol.TextSpan[] { + getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -712,7 +718,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var spans = compilerService.languageService.getBraceMatchingAtPosition(file, position); if (!spans) { @@ -720,8 +726,8 @@ module ts.server { } return spans.map(span => ({ - start: compilerService.host.positionToLineCol(file, span.start), - end: compilerService.host.positionToLineCol(file, span.start + span.length) + start: compilerService.host.positionToLineOffset(file, span.start), + end: compilerService.host.positionToLineOffset(file, span.start + span.length) })); } @@ -738,49 +744,50 @@ module ts.server { switch (request.command) { case CommandNames.Definition: { var defArgs = request.arguments; - response = this.getDefinition(defArgs.line, defArgs.col, defArgs.file); + response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file); break; } case CommandNames.References: { var refArgs = request.arguments; - response = this.getReferences(refArgs.line, refArgs.col, refArgs.file); + response = this.getReferences(refArgs.line, refArgs.offset, refArgs.file); break; } case CommandNames.Rename: { var renameArgs = request.arguments; - response = this.getRenameLocations(renameArgs.line, renameArgs.col, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); + response = this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); break; } case CommandNames.Open: { - var openArgs = request.arguments; - this.openClientFile(openArgs.file); + var openArgs = request.arguments; + this.openClientFile(openArgs.file,openArgs.tabSize, openArgs.indentSize); responseRequired = false; break; } case CommandNames.Quickinfo: { var quickinfoArgs = request.arguments; - response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.col, quickinfoArgs.file); + response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file); break; } case CommandNames.Format: { var formatArgs = request.arguments; - response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.col, formatArgs.endLine, formatArgs.endCol, formatArgs.file); + response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file); break; } case CommandNames.Formatonkey: { var formatOnKeyArgs = request.arguments; - response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.col, formatOnKeyArgs.key, formatOnKeyArgs.file); + response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file); break; } case CommandNames.Completions: { var completionsArgs = request.arguments; - response = this.getCompletions(request.arguments.line, request.arguments.col, completionsArgs.prefix, request.arguments.file); + response = this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file); break; } case CommandNames.CompletionDetails: { var completionDetailsArgs = request.arguments; - response = this.getCompletionEntryDetails(request.arguments.line, request.arguments.col, completionDetailsArgs.entryNames, - request.arguments.file); + response = + this.getCompletionEntryDetails(completionDetailsArgs.line,completionDetailsArgs.offset, + completionDetailsArgs.entryNames,completionDetailsArgs.file); break; } case CommandNames.Geterr: { @@ -791,14 +798,22 @@ module ts.server { } case CommandNames.Change: { var changeArgs = request.arguments; - this.change(changeArgs.line, changeArgs.col, changeArgs.endLine, changeArgs.endCol, + this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset, changeArgs.insertString, changeArgs.file); responseRequired = false; break; } + case CommandNames.Configure: { + var configureArgs = request.arguments; + this.projectService.setHostConfiguration(configureArgs); + this.output(undefined, CommandNames.Configure, request.seq); + responseRequired = false; + break; + } case CommandNames.Reload: { var reloadArgs = request.arguments; this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq); + responseRequired = false; break; } case CommandNames.Saveto: { @@ -820,7 +835,7 @@ module ts.server { } case CommandNames.Brace: { var braceArguments = request.arguments; - response = this.getBraceMatching(braceArguments.line, braceArguments.col, braceArguments.file); + response = this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file); break; } case CommandNames.NavBar: { diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json new file mode 100644 index 0000000000000..2c8538c61e32a --- /dev/null +++ b/src/server/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": true, + "removeComments": true, + "preserveConstEnums": true, + "out": "../../built/local/tsserver.js", + "sourceMap": true + }, + "files": [ + "node.d.ts", + "editorServices.ts", + "protocol.d.ts", + "server.ts", + "session.ts" + ] +} diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 24ddabc2b2b14..6a5ed25459e9d 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,6 +457,12 @@ 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 case SyntaxKind.OpenBraceToken: @@ -442,6 +471,7 @@ module ts.formatting { 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 @@ -1008,10 +1038,20 @@ module ts.formatting { return SyntaxKind.Unknown; } - let internedTabsIndentation: string[]; - let internedSpacesIndentation: string[]; + var internedSizes: { tabSize: number; indentSize: number }; + var internedTabsIndentation: string[]; + var internedSpacesIndentation: string[]; export function getIndentationString(indentation: number, options: FormatCodeOptions): string { + // reset interned strings if FormatCodeOptions were changed + let resetInternedStrings = + !internedSizes || (internedSizes.tabSize !== options.TabSize || internedSizes.indentSize !== options.IndentSize); + + if (resetInternedStrings) { + internedSizes = { tabSize: options.TabSize, indentSize: options.IndentSize }; + internedTabsIndentation = internedSpacesIndentation = undefined; + } + if (!options.ConvertTabsToSpaces) { let tabs = Math.floor(indentation / options.TabSize); let spaces = indentation - tabs * options.TabSize; diff --git a/src/services/formatting/indentation.ts b/src/services/formatting/indentation.ts deleted file mode 100644 index f6f8fc0319fe6..0000000000000 --- a/src/services/formatting/indentation.ts +++ /dev/null @@ -1,54 +0,0 @@ -module ts.formatting { - - var internedTabsIndentation: string[]; - var internedSpacesIndentation: string[]; - - export function getIndentationString(indentation: number, options: FormatCodeOptions): string { - if (!options.ConvertTabsToSpaces) { - var tabs = Math.floor(indentation / options.TabSize); - var spaces = indentation - tabs * options.TabSize; - - var tabString: string; - if (!internedTabsIndentation) { - internedTabsIndentation = []; - } - - if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); - } - else { - tabString = internedTabsIndentation[tabs]; - } - - return spaces ? tabString + repeat(" ", spaces) : tabString; - } - else { - var spacesString: string; - var quotient = Math.floor(indentation / options.IndentSize); - var remainder = indentation % options.IndentSize; - if (!internedSpacesIndentation) { - internedSpacesIndentation = []; - } - - if (internedSpacesIndentation[quotient] === undefined) { - spacesString = repeat(" ", options.IndentSize * quotient); - internedSpacesIndentation[quotient] = spacesString; - } - else { - spacesString = internedSpacesIndentation[quotient]; - } - - - return remainder ? spacesString + repeat(" ", remainder) : spacesString; - } - - function repeat(value: string, count: number): string { - var s = ""; - for (var i = 0; i < count; ++i) { - s += value; - } - - return s; - } - } -} \ No newline at end of file diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 1a52c72c9d8d7..8508e3b932d73 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -215,11 +215,7 @@ module ts.formatting { function getStartLineAndCharacterForNode(n: Node, sourceFile: SourceFile): LineAndCharacter { return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); } - - function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { - return candidate.end > position || !isCompletedNode(candidate, sourceFile); - } - + export function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean { if (parent.kind === SyntaxKind.IfStatement && (parent).elseStatement === child) { let elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile); @@ -403,128 +399,5 @@ module ts.formatting { return false; } } - - /* - * Checks if node ends with 'expectedLastToken'. - * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. - */ - function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { - let children = n.getChildren(sourceFile); - if (children.length) { - let last = children[children.length - 1]; - if (last.kind === expectedLastToken) { - return true; - } - else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { - return children[children.length - 2].kind === expectedLastToken; - } - } - return false; - } - - /* - * This function is always called when position of the cursor is located after the node - */ - function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { - if (n.getFullWidth() === 0) { - return false; - } - - switch (n.kind) { - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.ObjectBindingPattern: - case SyntaxKind.TypeLiteral: - case SyntaxKind.Block: - case SyntaxKind.ModuleBlock: - case SyntaxKind.CaseBlock: - return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); - case SyntaxKind.CatchClause: - return isCompletedNode((n).block, sourceFile); - case SyntaxKind.NewExpression: - if (!(n).arguments) { - return true; - } - // fall through - case SyntaxKind.CallExpression: - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.ParenthesizedType: - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return isCompletedNode((n).type, sourceFile); - - case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.ConstructSignature: - case SyntaxKind.CallSignature: - case SyntaxKind.ArrowFunction: - if ((n).body) { - return isCompletedNode((n).body, sourceFile); - } - - if ((n).type) { - return isCompletedNode((n).type, sourceFile); - } - - // Even though type parameters can be unclosed, we can get away with - // having at least a closing paren. - return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); - - case SyntaxKind.ModuleDeclaration: - return (n).body && isCompletedNode((n).body, sourceFile); - - case SyntaxKind.IfStatement: - if ((n).elseStatement) { - return isCompletedNode((n).elseStatement, sourceFile); - } - return isCompletedNode((n).thenStatement, sourceFile); - - case SyntaxKind.ExpressionStatement: - return isCompletedNode((n).expression, sourceFile); - - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.ArrayBindingPattern: - case SyntaxKind.ComputedPropertyName: - case SyntaxKind.TupleType: - return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); - - case SyntaxKind.IndexSignature: - if ((n).type) { - return isCompletedNode((n).type, sourceFile); - } - - return hasChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile); - - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed - return false; - - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - case SyntaxKind.WhileStatement: - return isCompletedNode((n).statement, sourceFile); - case SyntaxKind.DoStatement: - // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; - let hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); - if (hasWhileKeyword) { - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - } - return isCompletedNode((n).statement, sourceFile); - - default: - return true; - } - } } } \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 1bf5f6336d4c9..658f29f5ae78a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -937,6 +937,7 @@ module ts { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; @@ -1042,6 +1043,11 @@ module ts { containerName: string; } + export interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } + export enum SymbolDisplayPartKind { aliasName, className, @@ -2389,7 +2395,7 @@ module ts { // If '-d' is enabled, check for emitter error. One example of emitter error is export class implements non-export interface let declarationDiagnostics = program.getDeclarationDiagnostics(targetSourceFile); - return semanticDiagnostics.concat(declarationDiagnostics); + return concatenate(semanticDiagnostics, declarationDiagnostics); } function getCompilerOptionsDiagnostics() { @@ -2597,8 +2603,9 @@ module ts { isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); /// TODO filter meaning based on the current context + let scopeNode = getScopeNode(previousToken, position, sourceFile); let symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; - let symbols = typeInfoResolver.getSymbolsInScope(node, symbolMeanings); + let symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } @@ -2613,10 +2620,22 @@ module ts { return { isMemberCompletion, isNewIdentifierLocation, - isBuilder : isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation + isBuilder: isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation entries: activeCompletionSession.entries }; + /** + * Finds the first node that "embraces" the position, so that one may + * accurately aggregate locals from the closest containing scope. + */ + function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { + var scope = initialToken; + while (scope && !positionBelongsToNode(scope, position, sourceFile)) { + scope = scope.parent; + } + return scope; + } + function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void { let start = new Date().getTime(); forEach(symbols, symbol => { @@ -3425,6 +3444,17 @@ module ts { }; } + function createDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo { + return { + fileName: node.getSourceFile().fileName, + textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()), + kind: symbolKind, + name: symbolName, + containerKind: undefined, + containerName + }; + } + /// Goto definition function getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { synchronizeHostData(); @@ -3440,7 +3470,7 @@ module ts { if (isJumpStatementTarget(node)) { let labelName = (node).text; let label = getTargetLabel((node.parent), (node).text); - return label ? [getDefinitionInfo(label, ScriptElementKind.label, labelName, /*containerName*/ undefined)] : undefined; + return label ? [createDefinitionInfo(label, ScriptElementKind.label, labelName, /*containerName*/ undefined)] : undefined; } /// Triple slash reference comments @@ -3471,7 +3501,7 @@ module ts { // If this is an alias, and the request came at the declaration location // get the aliased symbol instead. This allows for goto def on an import e.g. // import {A, B} from "mod"; - // to jump to the implementation directelly. + // to jump to the implementation directly. if (symbol.flags & SymbolFlags.Alias) { let declaration = symbol.declarations[0]; if (node.kind === SyntaxKind.Identifier && node.parent === declaration) { @@ -3479,8 +3509,6 @@ module ts { } } - let result: DefinitionInfo[] = []; - // Because name in short-hand property assignment has two different meanings: property name and property value, // using go-to-definition at such position should go to the variable declaration of the property value rather than // go to the declaration of the property name (in this case stay at the same position). However, if go-to-definition @@ -3488,16 +3516,19 @@ module ts { // assignment. This case and others are handled by the following code. if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { let shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + if (!shorthandSymbol) { + return []; + } + let shorthandDeclarations = shorthandSymbol.getDeclarations(); let shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); let shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); let shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); - forEach(shorthandDeclarations, declaration => { - result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); - }); - return result + return map(shorthandDeclarations, + declaration => createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); } + let result: DefinitionInfo[] = []; let declarations = symbol.getDeclarations(); let symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol let symbolKind = getSymbolKind(symbol, typeInfoResolver, node); @@ -3508,21 +3539,31 @@ module ts { !tryAddCallSignature(symbol, node, symbolKind, symbolName, containerName, result)) { // Just add all the declarations. forEach(declarations, declaration => { - result.push(getDefinitionInfo(declaration, symbolKind, symbolName, containerName)); + result.push(createDefinitionInfo(declaration, symbolKind, symbolName, containerName)); }); } return result; - function getDefinitionInfo(node: Node, symbolKind: string, symbolName: string, containerName: string): DefinitionInfo { - return { - fileName: node.getSourceFile().fileName, - textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()), - kind: symbolKind, - name: symbolName, - containerKind: undefined, - containerName - }; + function tryAddConstructSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { + // Applicable only if we are in a new expression, or we are on a constructor declaration + // and in either case the symbol has a construct signature definition, i.e. class + if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) { + if (symbol.flags & SymbolFlags.Class) { + let classDeclaration = symbol.getDeclarations()[0]; + Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration); + + return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result); + } + } + return false; + } + + function tryAddCallSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { + if (isCallExpressionTarget(location) || isNewExpressionTarget(location) || isNameOfFunctionDeclaration(location)) { + return tryAddSignature(symbol.declarations, /*selectConstructors*/ false, symbolKind, symbolName, containerName, result); + } + return false; } function tryAddSignature(signatureDeclarations: Declaration[], selectConstructors: boolean, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { @@ -3538,37 +3579,16 @@ module ts { }); if (definition) { - result.push(getDefinitionInfo(definition, symbolKind, symbolName, containerName)); + result.push(createDefinitionInfo(definition, symbolKind, symbolName, containerName)); return true; } else if (declarations.length) { - result.push(getDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName)); + result.push(createDefinitionInfo(declarations[declarations.length - 1], symbolKind, symbolName, containerName)); return true; } return false; } - - function tryAddConstructSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { - // Applicable only if we are in a new expression, or we are on a constructor declaration - // and in either case the symbol has a construct signature definition, i.e. class - if (isNewExpressionTarget(location) || location.kind === SyntaxKind.ConstructorKeyword) { - if (symbol.flags & SymbolFlags.Class) { - let classDeclaration = symbol.getDeclarations()[0]; - Debug.assert(classDeclaration && classDeclaration.kind === SyntaxKind.ClassDeclaration); - - return tryAddSignature(classDeclaration.members, /*selectConstructors*/ true, symbolKind, symbolName, containerName, result); - } - } - return false; - } - - function tryAddCallSignature(symbol: Symbol, location: Node, symbolKind: string, symbolName: string, containerName: string, result: DefinitionInfo[]) { - if (isCallExpressionTarget(location) || isNewExpressionTarget(location) || isNameOfFunctionDeclaration(location)) { - return tryAddSignature(symbol.declarations, /*selectConstructors*/ false, symbolKind, symbolName, containerName, result); - } - return false; - } } /// References and Occurrences @@ -3584,7 +3604,7 @@ module ts { if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.SuperKeyword || isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) { - return getReferencesForNode(node, [sourceFile], /*searchOnlyInCurrentFile*/ true, /*findInStrings:*/ false, /*findInComments:*/ false); + return convertReferences(getReferencesForNode(node, [sourceFile], /*searchOnlyInCurrentFile*/ true, /*findInStrings:*/ false, /*findInComments:*/ false)); } switch (node.kind) { @@ -3884,7 +3904,7 @@ module ts { return map(keywords, getReferenceEntryFromNode); } - function getSwitchCaseDefaultOccurrences(switchStatement: SwitchStatement) { + function getSwitchCaseDefaultOccurrences(switchStatement: SwitchStatement): ReferenceEntry[] { let keywords: Node[] = []; pushKeywordIf(keywords, switchStatement.getFirstToken(), SyntaxKind.SwitchKeyword); @@ -4007,22 +4027,22 @@ module ts { } } - function getModifierOccurrences(modifier: SyntaxKind, declaration: Node) { + function getModifierOccurrences(modifier: SyntaxKind, declaration: Node): ReferenceEntry[] { let container = declaration.parent; // Make sure we only highlight the keyword when it makes sense to do so. - if (declaration.flags & NodeFlags.AccessibilityModifier) { + if (isAccessibilityModifier(modifier)) { if (!(container.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.Parameter && hasKind(container, SyntaxKind.Constructor)))) { return undefined; } } - else if (declaration.flags & NodeFlags.Static) { + else if (modifier === SyntaxKind.StaticKeyword) { if (container.kind !== SyntaxKind.ClassDeclaration) { return undefined; } } - else if (declaration.flags & (NodeFlags.Export | NodeFlags.Ambient)) { + else if (modifier === SyntaxKind.ExportKeyword || modifier === SyntaxKind.DeclareKeyword) { if (!(container.kind === SyntaxKind.ModuleBlock || container.kind === SyntaxKind.SourceFile)) { return undefined; } @@ -4063,7 +4083,7 @@ module ts { default: Debug.fail("Invalid container kind.") } - + forEach(nodes, node => { if (node.modifiers && node.flags & modifierFlag) { forEach(node.modifiers, child => pushKeywordIf(keywords, child, modifier)); @@ -4112,15 +4132,36 @@ module ts { } } - function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[] { - return findReferences(fileName, position, findInStrings, findInComments); + function convertReferences(referenceSymbols: ReferencedSymbol[]): ReferenceEntry[]{ + if (!referenceSymbols) { + return undefined; + } + + let referenceEntries: ReferenceEntry[] = []; + for (let referenceSymbol of referenceSymbols) { + addRange(referenceEntries, referenceSymbol.references); + } + return referenceEntries; + } + + function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[]{ + var referencedSymbols = findReferencedSymbols(fileName, position, findInStrings, findInComments); + return convertReferences(referencedSymbols); } function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - return findReferences(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + return convertReferences(referencedSymbols); } - function findReferences(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { + function findReferences(fileName: string, position: number): ReferencedSymbol[]{ + var referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings:*/ false, /*findInComments:*/ false); + + // Only include referenced symbols that have a valid definition. + return filter(referencedSymbols, rs => !!rs.definition); + } + + function findReferencedSymbols(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): ReferencedSymbol[] { synchronizeHostData(); let sourceFile = getValidSourceFile(fileName); @@ -4143,14 +4184,14 @@ module ts { return getReferencesForNode(node, program.getSourceFiles(), /*searchOnlyInCurrentFile*/ false, findInStrings, findInComments); } - function getReferencesForNode(node: Node, sourceFiles: SourceFile[], searchOnlyInCurrentFile: boolean, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] { + function getReferencesForNode(node: Node, sourceFiles: SourceFile[], searchOnlyInCurrentFile: boolean, findInStrings: boolean, findInComments: boolean): ReferencedSymbol[]{ // Labels if (isLabelName(node)) { if (isJumpStatementTarget(node)) { let labelDefinition = getTargetLabel((node.parent), (node).text); // if we have a label definition, look within its statement for references, if not, then - // the label is undefined, just return a set of one for the current node. - return labelDefinition ? getLabelReferencesInNode(labelDefinition.parent, labelDefinition) : [getReferenceEntryFromNode(node)]; + // the label is undefined and we have no results.. + return labelDefinition ? getLabelReferencesInNode(labelDefinition.parent, labelDefinition) : undefined; } else { // it is a label definition and not a target, search within the parent labeledStatement @@ -4170,9 +4211,8 @@ module ts { // Could not find a symbol e.g. unknown identifier if (!symbol) { - // Even if we did not find a symbol, we have an identifier, so there is at least - // one reference that we know of. return that instead of undefined. - return [getReferenceEntryFromNode(node)]; + // Can't have references to something that we have no symbol for. + return undefined; } let declarations = symbol.declarations; @@ -4182,7 +4222,7 @@ module ts { return undefined; } - let result: ReferenceEntry[]; + let result: ReferencedSymbol[]; // Compute the meaning from the location and the symbol it references let searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations); @@ -4194,15 +4234,18 @@ module ts { // otherwise we'll need to search globally (i.e. include each file). let scope = getSymbolScope(symbol); + // Maps from a symbol ID to the ReferencedSymbol entry in 'result'. + let symbolToIndex: number[] = []; + if (scope) { result = []; - getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } else { if (searchOnlyInCurrentFile) { Debug.assert(sourceFiles.length === 1); result = []; - getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } else { let internedName = getInternedName(symbol, node, declarations) @@ -4213,7 +4256,7 @@ module ts { if (lookUp(nameTable, internedName)) { result = result || []; - getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result); + getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result, symbolToIndex); } }); } @@ -4221,6 +4264,24 @@ module ts { return result; + function getDefinition(symbol: Symbol): DefinitionInfo { + let info = getSymbolDisplayPartsDocumentationAndSymbolKind(symbol, node.getSourceFile(), getContainerNode(node), typeInfoResolver, node); + let name = map(info.displayParts, p => p.text).join(""); + let declarations = symbol.declarations; + if (!declarations || declarations.length === 0) { + return undefined; + } + + return { + containerKind: "", + containerName: "", + name, + kind: info.symbolKind, + fileName: declarations[0].getSourceFile().fileName, + textSpan: createTextSpan(declarations[0].getStart(), 0) + }; + } + function isImportOrExportSpecifierName(location: Node): boolean { return location.parent && (location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) && @@ -4378,8 +4439,8 @@ module ts { return positions; } - function getLabelReferencesInNode(container: Node, targetLabel: Identifier): ReferenceEntry[] { - let result: ReferenceEntry[] = []; + function getLabelReferencesInNode(container: Node, targetLabel: Identifier): ReferencedSymbol[] { + let references: ReferenceEntry[] = []; let sourceFile = container.getSourceFile(); let labelName = targetLabel.text; let possiblePositions = getPossibleSymbolReferencePositions(sourceFile, labelName, container.getStart(), container.getEnd()); @@ -4394,10 +4455,20 @@ module ts { // Only pick labels that are either the target label, or have a target that is the target label if (node === targetLabel || (isJumpStatementTarget(node) && getTargetLabel(node, labelName) === targetLabel)) { - result.push(getReferenceEntryFromNode(node)); + references.push(getReferenceEntryFromNode(node)); } }); - return result; + + var definition: DefinitionInfo = { + containerKind: "", + containerName: "", + fileName: targetLabel.getSourceFile().fileName, + kind: ScriptElementKind.label, + name: labelName, + textSpan: createTextSpanFromBounds(targetLabel.getStart(), targetLabel.getEnd()) + } + + return [{ definition, references }]; } function isValidReferencePosition(node: Node, searchSymbolName: string): boolean { @@ -4437,7 +4508,9 @@ module ts { searchMeaning: SemanticMeaning, findInStrings: boolean, findInComments: boolean, - result: ReferenceEntry[]): void { + result: ReferencedSymbol[], + symbolToIndex: number[]): void { + let sourceFile = container.getSourceFile(); let tripleSlashDirectivePrefixRegex = /^\/\/\/\s*= 0) { - result.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name)); + var referencedSymbol = getReferencedSymbol(shorthandValueSymbol); + referencedSymbol.references.push(getReferenceEntryFromNode(referenceSymbolDeclaration.name)); } } }); } + return; + + function getReferencedSymbol(symbol: Symbol): ReferencedSymbol { + var symbolId = getSymbolId(symbol); + var index = symbolToIndex[symbolId]; + if (index === undefined) { + index = result.length; + symbolToIndex[symbolId] = index; + + result.push({ + definition: getDefinition(symbol), + references: [] + }); + } + + return result[index]; + } + function isInString(position: number) { let token = getTokenAtPosition(sourceFile, position); return token && token.kind === SyntaxKind.StringLiteral && position > token.getStart(); @@ -4517,7 +4620,7 @@ module ts { } } - function getReferencesForSuperKeyword(superKeyword: Node): ReferenceEntry[] { + function getReferencesForSuperKeyword(superKeyword: Node): ReferencedSymbol[] { let searchSpaceNode = getSuperContainer(superKeyword, /*includeFunctions*/ false); if (!searchSpaceNode) { return undefined; @@ -4540,7 +4643,7 @@ module ts { return undefined; } - let result: ReferenceEntry[] = []; + let references: ReferenceEntry[] = []; let sourceFile = searchSpaceNode.getSourceFile(); let possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "super", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); @@ -4559,14 +4662,15 @@ module ts { // Now make sure the owning class is the same as the search-space // and has the same static qualifier as the original 'super's owner. if (container && (NodeFlags.Static & container.flags) === staticFlag && container.parent.symbol === searchSpaceNode.symbol) { - result.push(getReferenceEntryFromNode(node)); + references.push(getReferenceEntryFromNode(node)); } }); - return result; + var definition = getDefinition(searchSpaceNode.symbol); + return [{ definition, references }]; } - function getReferencesForThisKeyword(thisOrSuperKeyword: Node, sourceFiles: SourceFile[]): ReferenceEntry[] { + function getReferencesForThisKeyword(thisOrSuperKeyword: Node, sourceFiles: SourceFile[]): ReferencedSymbol[] { let searchSpaceNode = getThisContainer(thisOrSuperKeyword, /* includeArrowFunctions */ false); // Whether 'this' occurs in a static context within a class. @@ -4601,22 +4705,32 @@ module ts { return undefined; } - let result: ReferenceEntry[] = []; + let references: ReferenceEntry[] = []; let possiblePositions: number[]; if (searchSpaceNode.kind === SyntaxKind.SourceFile) { forEach(sourceFiles, sourceFile => { possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd()); - getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, result); + getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, references); }); } else { let sourceFile = searchSpaceNode.getSourceFile(); possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", searchSpaceNode.getStart(), searchSpaceNode.getEnd()); - getThisReferencesInFile(sourceFile, searchSpaceNode, possiblePositions, result); + getThisReferencesInFile(sourceFile, searchSpaceNode, possiblePositions, references); } - return result; + return [{ + definition: { + containerKind: "", + containerName: "", + fileName: node.getSourceFile().fileName, + kind: ScriptElementKind.variableElement, + name: "this", + textSpan: createTextSpanFromBounds(node.getStart(), node.getEnd()) + }, + references: references + }]; function getThisReferencesInFile(sourceFile: SourceFile, searchSpaceNode: Node, possiblePositions: number[], result: ReferenceEntry[]): void { forEach(possiblePositions, position => { @@ -4739,16 +4853,18 @@ module ts { } } - function isRelatableToSearchSet(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): boolean { + function getRelatedSymbol(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node): Symbol { if (searchSymbols.indexOf(referenceSymbol) >= 0) { - return true; + return referenceSymbol; } // If the reference symbol is an alias, check if what it is aliasing is one of the search // symbols. - if (isImportOrExportSpecifierImportSymbol(referenceSymbol) && - searchSymbols.indexOf(typeInfoResolver.getAliasedSymbol(referenceSymbol)) >= 0) { - return true; + if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) { + var aliasedSymbol = typeInfoResolver.getAliasedSymbol(referenceSymbol); + if (searchSymbols.indexOf(aliasedSymbol) >= 0) { + return aliasedSymbol; + } } // If the reference location is in an object literal, try to get the contextual type for the @@ -4756,7 +4872,7 @@ module ts { // compare to our searchSymbol if (isNameOfPropertyAssignment(referenceLocation)) { return forEach(getPropertySymbolsFromContextualType(referenceLocation), contextualSymbol => { - return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0); + return forEach(typeInfoResolver.getRootSymbols(contextualSymbol), s => searchSymbols.indexOf(s) >= 0 ? s : undefined); }); } @@ -4765,7 +4881,7 @@ module ts { return forEach(typeInfoResolver.getRootSymbols(referenceSymbol), rootSymbol => { // if it is in the list, then we are done if (searchSymbols.indexOf(rootSymbol) >= 0) { - return true; + return rootSymbol; } // Finally, try all properties with the same name in any type the containing type extended or implemented, and @@ -4773,10 +4889,10 @@ module ts { if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { let result: Symbol[] = []; getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result); - return forEach(result, s => searchSymbols.indexOf(s) >= 0); + return forEach(result, s => searchSymbols.indexOf(s) >= 0 ? s : undefined); } - return false; + return undefined; }); } @@ -4899,7 +5015,6 @@ module ts { synchronizeHostData(); let sourceFile = getValidSourceFile(fileName); - let outputFiles: OutputFile[] = []; function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) { @@ -5733,6 +5848,7 @@ module ts { getQuickInfoAtPosition, getDefinitionAtPosition, getReferencesAtPosition, + findReferences, getOccurrencesAtPosition, getNameOrDottedNameSpan, getBreakpointStatementAtPosition, @@ -5843,17 +5959,6 @@ module ts { // a string literal, and a template end consisting of '} } `'. let templateStack: SyntaxKind[] = []; - function isAccessibilityModifier(kind: SyntaxKind) { - switch (kind) { - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - return true; - } - - return false; - } - /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */ function canFollow(keyword1: SyntaxKind, keyword2: SyntaxKind) { if (isAccessibilityModifier(keyword1)) { diff --git a/src/services/shims.ts b/src/services/shims.ts index fc47ff95280e7..adcec5ada2b60 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -127,6 +127,12 @@ module ts { * { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[] */ getReferencesAtPosition(fileName: string, position: number): string; + + /** + * Returns a JSON-encoded value of the type: + * { definition: ; references: [] }[] + */ + findReferences(fileName: string, position: number): string; /** * Returns a JSON-encoded value of the type: @@ -555,11 +561,6 @@ module ts { /// GET REFERENCES - /** - * Return references to a symbol at the requested position. - * References are separated by "\n". - * Each reference is a "fileindex min lim" sub-string. - */ public getReferencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( "getReferencesAtPosition('" + fileName + "', " + position + ")", @@ -568,6 +569,14 @@ module ts { }); } + public findReferences(fileName: string, position: number): string { + return this.forwardJSONCall( + "findReferences('" + fileName + "', " + position + ")", + () => { + return this.languageService.findReferences(fileName, position); + }); + } + public getOccurrencesAtPosition(fileName: string, position: number): string { return this.forwardJSONCall( "getOccurrencesAtPosition('" + fileName + "', " + position + ")", @@ -833,3 +842,5 @@ module ts { module TypeScript.Services { export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory; } + +let toolsVersion = "1.4"; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 7671ee3f88d53..2a9af04409e89 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -59,6 +59,157 @@ module ts { return start < end; } + export function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { + return candidate.end > position || !isCompletedNode(candidate, sourceFile); + } + + export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { + if (nodeIsMissing(n)) { + return false; + } + + switch (n.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.TypeLiteral: + case SyntaxKind.Block: + case SyntaxKind.ModuleBlock: + case SyntaxKind.CaseBlock: + return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); + case SyntaxKind.CatchClause: + return isCompletedNode((n).block, sourceFile); + case SyntaxKind.NewExpression: + if (!(n).arguments) { + return true; + } + // fall through + case SyntaxKind.CallExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ParenthesizedType: + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return isCompletedNode((n).type, sourceFile); + + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.ArrowFunction: + if ((n).body) { + return isCompletedNode((n).body, sourceFile); + } + + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + // Even though type parameters can be unclosed, we can get away with + // having at least a closing paren. + return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.ModuleDeclaration: + return (n).body && isCompletedNode((n).body, sourceFile); + + case SyntaxKind.IfStatement: + if ((n).elseStatement) { + return isCompletedNode((n).elseStatement, sourceFile); + } + return isCompletedNode((n).thenStatement, sourceFile); + + case SyntaxKind.ExpressionStatement: + return isCompletedNode((n).expression, sourceFile); + + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.ElementAccessExpression: + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.TupleType: + return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); + + case SyntaxKind.IndexSignature: + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + return hasChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile); + + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed + return false; + + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.WhileStatement: + return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.DoStatement: + // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; + let hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); + if (hasWhileKeyword) { + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + } + return isCompletedNode((n).statement, sourceFile); + + case SyntaxKind.TypeQuery: + return isCompletedNode((n).exprName, sourceFile); + + case SyntaxKind.TypeOfExpression: + case SyntaxKind.DeleteExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.YieldExpression: + case SyntaxKind.SpreadElementExpression: + let unaryWordExpression = (n); + return isCompletedNode(unaryWordExpression.expression, sourceFile); + + case SyntaxKind.TaggedTemplateExpression: + return isCompletedNode((n).template, sourceFile); + case SyntaxKind.TemplateExpression: + let lastSpan = lastOrUndefined((n).templateSpans); + return isCompletedNode(lastSpan, sourceFile); + case SyntaxKind.TemplateSpan: + return nodeIsPresent((n).literal); + + case SyntaxKind.PrefixUnaryExpression: + return isCompletedNode((n).operand, sourceFile); + case SyntaxKind.BinaryExpression: + return isCompletedNode((n).right, sourceFile); + case SyntaxKind.ConditionalExpression: + return isCompletedNode((n).whenFalse, sourceFile); + + default: + return true; + } + } + + /* + * Checks if node ends with 'expectedLastToken'. + * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. + */ + function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { + let children = n.getChildren(sourceFile); + if (children.length) { + let last = children[children.length - 1]; + if (last.kind === expectedLastToken) { + return true; + } + else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { + return children[children.length - 2].kind === expectedLastToken; + } + } + return false; + } + export function findListItemInfo(node: Node): ListItemInfo { let list = findContainingList(node); @@ -320,6 +471,17 @@ module ts { && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } + export function isAccessibilityModifier(kind: SyntaxKind) { + switch (kind) { + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + return true; + } + + return false; + } + export function compareDataObjects(dst: any, src: any): boolean { for (let e in dst) { if (typeof dst[e] === "object") { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 575c2bdaf36d1..8fe06ca08b9c3 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -111,192 +111,195 @@ 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, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 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, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - 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, + 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, + FromKeyword = 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, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -304,8 +307,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -330,10 +333,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, @@ -344,6 +348,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -374,6 +379,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -801,14 +809,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -927,9 +935,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -937,20 +946,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; hasExportDefaultValue(node: SourceFile): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1057,6 +1068,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1472,7 +1484,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1586,6 +1599,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1672,6 +1686,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 336d70aa1a196..899c08166efd9 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -351,562 +351,571 @@ 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 - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : 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 - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >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 = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >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, @@ -930,10 +939,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1002,16 +1011,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 { @@ -1042,6 +1054,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1136,6 +1153,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 @@ -2440,14 +2465,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -2970,6 +2995,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -2977,9 +3007,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -2998,15 +3028,17 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node hasExportDefaultValue(node: SourceFile): boolean; >hasExportDefaultValue : (node: SourceFile) => boolean @@ -3034,6 +3066,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3060,6 +3098,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3087,8 +3136,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3410,6 +3459,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4714,10 +4766,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5131,6 +5188,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5401,6 +5464,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index e7145e2407059..268751c25c752 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -142,192 +142,195 @@ 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, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 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, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - 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, + 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, + FromKeyword = 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, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + 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, @@ -361,10 +364,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, @@ -375,6 +379,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -405,6 +410,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -832,14 +840,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -958,9 +966,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -968,20 +977,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; hasExportDefaultValue(node: SourceFile): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1088,6 +1099,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1503,7 +1515,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1617,6 +1630,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1703,6 +1717,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, @@ -2023,24 +2041,24 @@ 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 */) { + if (ifStatement.elseStatement && 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 a40848b9e4c63..da2a475311283 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -497,562 +497,571 @@ 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 - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : 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 - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >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 = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >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, @@ -1076,10 +1085,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1148,16 +1157,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 { @@ -1188,6 +1200,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1282,6 +1299,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 @@ -2586,14 +2611,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -3116,6 +3141,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3123,9 +3153,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3144,15 +3174,17 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node hasExportDefaultValue(node: SourceFile): boolean; >hasExportDefaultValue : (node: SourceFile) => boolean @@ -3180,6 +3212,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3206,6 +3244,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3233,8 +3282,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3556,6 +3605,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4860,10 +4912,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5277,6 +5334,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5547,6 +5610,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index da8fe979d1700..1955c175b9373 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -143,192 +143,195 @@ 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, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 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, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - 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, + 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, + FromKeyword = 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, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -336,8 +339,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -362,10 +365,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, @@ -376,6 +380,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -406,6 +411,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -833,14 +841,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -959,9 +967,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -969,20 +978,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; hasExportDefaultValue(node: SourceFile): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1089,6 +1100,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1504,7 +1516,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1618,6 +1631,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1704,6 +1718,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index b694678d4cb9a..e7ebaee5dfad9 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -447,562 +447,571 @@ 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 - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : 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 - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >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 = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >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, @@ -1026,10 +1035,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1098,16 +1107,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 { @@ -1138,6 +1150,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1232,6 +1249,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 @@ -2536,14 +2561,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -3066,6 +3091,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3073,9 +3103,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3094,15 +3124,17 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node hasExportDefaultValue(node: SourceFile): boolean; >hasExportDefaultValue : (node: SourceFile) => boolean @@ -3130,6 +3162,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3156,6 +3194,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3183,8 +3232,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3506,6 +3555,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4810,10 +4862,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5227,6 +5284,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5497,6 +5560,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index f380994eba888..d9188afe74fa1 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -180,192 +180,195 @@ 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, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 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, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - 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, + 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, + FromKeyword = 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, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + MissingDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -373,8 +376,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -399,10 +402,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, @@ -413,6 +417,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -443,6 +448,9 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -870,14 +878,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; @@ -996,9 +1004,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -1006,20 +1015,22 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: Node): string; - getExpressionNameSubstitution(node: Identifier): string; + hasGlobalName(name: string): boolean; + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; hasExportDefaultValue(node: SourceFile): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; - isUnknownIdentifier(location: Node, name: string): boolean; + resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; } const enum SymbolFlags { @@ -1126,6 +1137,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1541,7 +1553,8 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function findConfigFile(searchPath: string): string; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; @@ -1655,6 +1668,7 @@ declare module "typescript" { getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; getOutliningSpans(fileName: string): OutliningSpan[]; @@ -1741,6 +1755,10 @@ declare module "typescript" { containerKind: string; containerName: string; } + interface ReferencedSymbol { + definition: DefinitionInfo; + references: ReferenceEntry[]; + } enum SymbolDisplayPartKind { aliasName = 0, className = 1, diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 06329de5c961f..66caf523789da 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -620,562 +620,571 @@ 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 - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : 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 - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + MissingDeclaration = 215, +>MissingDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >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 = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >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, @@ -1199,10 +1208,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1271,16 +1280,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 { @@ -1311,6 +1323,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1405,6 +1422,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 @@ -2709,14 +2734,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then - * the javascript and declaration files will be produced for all the files in this program. - * If targetSourceFile is specified, then only the javascript and declaration for that + * Emits the JavaScript and declaration files. If targetSourceFile is not specified, then + * the JavaScript and declaration files will be produced for all the files in this program. + * If targetSourceFile is specified, then only the JavaScript and declaration for that * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be - * used for writing the javascript and declaration files. Otherwise, the writeFile parameter - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult @@ -3239,6 +3264,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3246,9 +3276,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3267,15 +3297,17 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: Node): string; ->getGeneratedNameForNode : (node: Node) => string ->node : Node ->Node : Node + hasGlobalName(name: string): boolean; +>hasGlobalName : (name: string) => boolean +>name : string - getExpressionNameSubstitution(node: Identifier): string; ->getExpressionNameSubstitution : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (node: Node) => string): string; +>getExpressionNameSubstitution : (node: Identifier, getGeneratedNameForNode: (node: Node) => string) => string >node : Identifier >Identifier : Identifier +>getGeneratedNameForNode : (node: Node) => string +>node : Node +>Node : Node hasExportDefaultValue(node: SourceFile): boolean; >hasExportDefaultValue : (node: SourceFile) => boolean @@ -3303,6 +3335,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3329,6 +3367,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; @@ -3356,8 +3405,8 @@ declare module "typescript" { >PropertyAccessExpression : PropertyAccessExpression >ElementAccessExpression : ElementAccessExpression - isUnknownIdentifier(location: Node, name: string): boolean; ->isUnknownIdentifier : (location: Node, name: string) => boolean + resolvesToSomeValue(location: Node, name: string): boolean; +>resolvesToSomeValue : (location: Node, name: string) => boolean >location : Node >Node : Node >name : string @@ -3679,6 +3728,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4983,10 +5035,15 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function findConfigFile(searchPath: string): string; +>findConfigFile : (searchPath: string) => string +>searchPath : string + + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; @@ -5400,6 +5457,12 @@ declare module "typescript" { >position : number >ReferenceEntry : ReferenceEntry + findReferences(fileName: string, position: number): ReferencedSymbol[]; +>findReferences : (fileName: string, position: number) => ReferencedSymbol[] +>fileName : string +>position : number +>ReferencedSymbol : ReferencedSymbol + getNavigateToItems(searchValue: string, maxResultCount?: number): NavigateToItem[]; >getNavigateToItems : (searchValue: string, maxResultCount?: number) => NavigateToItem[] >searchValue : string @@ -5670,6 +5733,17 @@ declare module "typescript" { containerName: string; >containerName : string + } + interface ReferencedSymbol { +>ReferencedSymbol : ReferencedSymbol + + definition: DefinitionInfo; +>definition : DefinitionInfo +>DefinitionInfo : DefinitionInfo + + references: ReferenceEntry[]; +>references : ReferenceEntry[] +>ReferenceEntry : ReferenceEntry } enum SymbolDisplayPartKind { >SymbolDisplayPartKind : SymbolDisplayPartKind diff --git a/tests/baselines/reference/ES5For-of15.js b/tests/baselines/reference/ES5For-of15.js index 46d3dbd1d6e3e..5a1b8327107c7 100644 --- a/tests/baselines/reference/ES5For-of15.js +++ b/tests/baselines/reference/ES5For-of15.js @@ -11,7 +11,7 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; v; for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - var x = _v; + var v_1 = _c[_b]; + var x = v_1; } } diff --git a/tests/baselines/reference/ES5For-of16.js b/tests/baselines/reference/ES5For-of16.js index 1649e4481f27d..88f2c39414aa4 100644 --- a/tests/baselines/reference/ES5For-of16.js +++ b/tests/baselines/reference/ES5For-of16.js @@ -12,8 +12,8 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; v; for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - var x = _v; - _v++; + var v_1 = _c[_b]; + var x = v_1; + v_1++; } } diff --git a/tests/baselines/reference/ES5For-of17.js b/tests/baselines/reference/ES5For-of17.js index b728074ae939d..4752f1be90f30 100644 --- a/tests/baselines/reference/ES5For-of17.js +++ b/tests/baselines/reference/ES5For-of17.js @@ -14,8 +14,8 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { for (var _b = 0, _c = [ v ]; _b < _c.length; _b++) { - var _v = _c[_b]; - var x = _v; - _v++; + var v_1 = _c[_b]; + var x = v_1; + v_1++; } } diff --git a/tests/baselines/reference/ES5For-of18.js b/tests/baselines/reference/ES5For-of18.js index a135b8b04639e..0d4809ed72d06 100644 --- a/tests/baselines/reference/ES5For-of18.js +++ b/tests/baselines/reference/ES5For-of18.js @@ -13,6 +13,6 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { v; } for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - _v; + var v = _c[_b]; + v; } diff --git a/tests/baselines/reference/ES5For-of19.js b/tests/baselines/reference/ES5For-of19.js index 7af9418f04f69..2714574ab5bc8 100644 --- a/tests/baselines/reference/ES5For-of19.js +++ b/tests/baselines/reference/ES5For-of19.js @@ -14,9 +14,9 @@ for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; v; function foo() { - for (var _b = 0, _c = []; _b < _c.length; _b++) { - var _v = _c[_b]; - _v; + for (var _i = 0, _a = []; _i < _a.length; _i++) { + var v_1 = _a[_i]; + v_1; } } } diff --git a/tests/baselines/reference/ES5For-of20.js b/tests/baselines/reference/ES5For-of20.js index 3dd707805d8bc..d3f44e4922a1e 100644 --- a/tests/baselines/reference/ES5For-of20.js +++ b/tests/baselines/reference/ES5For-of20.js @@ -9,11 +9,11 @@ for (let v of []) { //// [ES5For-of20.js] for (var _i = 0, _a = []; _i < _a.length; _i++) { var v = _a[_i]; - var _v; + var v_1; for (var _b = 0, _c = [ v ]; _b < _c.length; _b++) { - var _v_1 = _c[_b]; - var _v_2; + var v_2 = _c[_b]; + var v_3; } } diff --git a/tests/baselines/reference/ES5For-of24.js b/tests/baselines/reference/ES5For-of24.js index 418ccc2005c47..00cd24ea28062 100644 --- a/tests/baselines/reference/ES5For-of24.js +++ b/tests/baselines/reference/ES5For-of24.js @@ -12,5 +12,5 @@ var a = [ ]; for (var _i = 0; _i < a.length; _i++) { var v = a[_i]; - var _a = 0; + var a_1 = 0; } diff --git a/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt index 9551d0467e9ba..b762db8a04b4b 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(1,15): error TS2461: Type 'StringIterator' is not an array type or a string type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(1,15): error TS2495: Type 'StringIterator' is not an array type or a string type. tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(11,6): error TS2304: Cannot find name 'Symbol'. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts (2 errors) ==== for (var v of new StringIterator) { } ~~~~~~~~~~~~~~~~~~ -!!! error TS2461: Type 'StringIterator' is not an array type or a string type. +!!! error TS2495: Type 'StringIterator' is not an array type or a string type. // In ES3/5, you cannot for...of over an arbitrary iterable. class StringIterator { diff --git a/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt index b726aaad6c7c5..67af1f4f40116 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2461: Type 'number' is not an array type or a string type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2495: Type 'number' is not an array type or a string type. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts (1 errors) ==== for (const v of 0) { } ~ -!!! error TS2461: Type 'number' is not an array type or a string type. \ No newline at end of file +!!! error TS2495: Type 'number' is not an array type or a string type. \ No newline at end of file diff --git a/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js b/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js index d9fdb511fa213..4ca0b4cd5f740 100644 --- a/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js +++ b/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js @@ -34,6 +34,6 @@ var enumdule; enumdule.Point = Point; })(enumdule || (enumdule = {})); var x; -var x = 0 /* Red */; +var x = enumdule.Red; var y; var y = new enumdule.Point(0, 0); diff --git a/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js b/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js index 533843d294732..96df9812bc638 100644 --- a/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js +++ b/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js @@ -34,6 +34,6 @@ var enumdule; enumdule[enumdule["Blue"] = 1] = "Blue"; })(enumdule || (enumdule = {})); var x; -var x = 0 /* Red */; +var x = enumdule.Red; var y; var y = new enumdule.Point(0, 0); diff --git a/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js b/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js index 7555ae217e575..06e5427a87958 100644 --- a/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js +++ b/tests/baselines/reference/ModuleWithExportedAndNonExportedClasses.js @@ -35,19 +35,19 @@ var ag2 = new A.A2(); //// [ModuleWithExportedAndNonExportedClasses.js] var A; -(function (_A) { +(function (A_1) { var A = (function () { function A() { } return A; })(); - _A.A = A; + A_1.A = A; var AG = (function () { function AG() { } return AG; })(); - _A.AG = AG; + A_1.AG = AG; var A2 = (function () { function A2() { } diff --git a/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js b/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js index afcef6bbb5c3c..3cd522d3c2c2f 100644 --- a/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js +++ b/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js @@ -26,6 +26,6 @@ var A; })(Day || (Day = {})); })(A || (A = {})); // not an error since exported -var a = 0 /* Red */; +var a = A.Color.Red; // error not exported var b = A.Day.Monday; diff --git a/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js b/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js index ca3e8435e0570..d68af6c23c3b6 100644 --- a/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js +++ b/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js @@ -81,7 +81,7 @@ var r11 = a + foo(); var r12 = a + C; var r13 = a + new C(); var r14 = a + E; -var r15 = a + 0 /* a */; +var r15 = a + E.a; var r16 = a + M; var r17 = a + ''; var r18 = a + 123; diff --git a/tests/baselines/reference/additionOperatorWithInvalidOperands.js b/tests/baselines/reference/additionOperatorWithInvalidOperands.js index baf4fadedb30e..f2403bc16708f 100644 --- a/tests/baselines/reference/additionOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/additionOperatorWithInvalidOperands.js @@ -85,6 +85,6 @@ var r14 = b + d; var r15 = b + foo; var r16 = b + foo(); var r17 = b + C; -var r18 = 0 /* a */ + new C(); -var r19 = 0 /* a */ + C.foo(); -var r20 = 0 /* a */ + M; +var r18 = E.a + new C(); +var r19 = E.a + C.foo(); +var r20 = E.a + M; diff --git a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js index 1ba54d47f1cb3..1b5cb877d21bc 100644 --- a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js +++ b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js @@ -49,13 +49,13 @@ var r2 = a + null; var r3 = null + b; var r4 = null + 1; var r5 = null + c; -var r6 = null + 0 /* a */; -var r7 = null + 0 /* 'a' */; +var r6 = null + E.a; +var r7 = null + E['a']; var r8 = b + null; var r9 = 1 + null; var r10 = c + null; -var r11 = 0 /* a */ + null; -var r12 = 0 /* 'a' */ + null; +var r11 = E.a + null; +var r12 = E['a'] + null; // null + string var r13 = null + d; var r14 = null + ''; diff --git a/tests/baselines/reference/additionOperatorWithNumberAndEnum.js b/tests/baselines/reference/additionOperatorWithNumberAndEnum.js index 231831518e6c7..d559e98dc3eff 100644 --- a/tests/baselines/reference/additionOperatorWithNumberAndEnum.js +++ b/tests/baselines/reference/additionOperatorWithNumberAndEnum.js @@ -43,10 +43,10 @@ var r2 = a + b; var r3 = b + a; var r4 = b + b; var r5 = 0 + a; -var r6 = 0 /* a */ + 0; -var r7 = 0 /* a */ + 1 /* b */; -var r8 = 0 /* 'a' */ + 1 /* 'b' */; -var r9 = 0 /* 'a' */ + 0 /* 'c' */; +var r6 = E.a + 0; +var r7 = E.a + E.b; +var r8 = E['a'] + E['b']; +var r9 = E['a'] + F['c']; var r10 = a + c; var r11 = c + a; var r12 = b + c; diff --git a/tests/baselines/reference/additionOperatorWithStringAndEveryType.js b/tests/baselines/reference/additionOperatorWithStringAndEveryType.js index 35c6056574e73..56949533e0922 100644 --- a/tests/baselines/reference/additionOperatorWithStringAndEveryType.js +++ b/tests/baselines/reference/additionOperatorWithStringAndEveryType.js @@ -72,7 +72,7 @@ var r13 = f + x; var r14 = g + x; // other cases var r15 = x + E; -var r16 = x + 0 /* a */; +var r16 = x + E.a; var r17 = x + ''; var r18 = x + 0; var r19 = x + { diff --git a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js index cb89d242a18a6..68804694449e1 100644 --- a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js +++ b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js @@ -49,13 +49,13 @@ var r2 = a + undefined; var r3 = undefined + b; var r4 = undefined + 1; var r5 = undefined + c; -var r6 = undefined + 0 /* a */; -var r7 = undefined + 0 /* 'a' */; +var r6 = undefined + E.a; +var r7 = undefined + E['a']; var r8 = b + undefined; var r9 = 1 + undefined; var r10 = c + undefined; -var r11 = 0 /* a */ + undefined; -var r12 = 0 /* 'a' */ + undefined; +var r11 = E.a + undefined; +var r12 = E['a'] + undefined; // undefined + string var r13 = undefined + d; var r14 = undefined + ''; diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.js b/tests/baselines/reference/amdImportAsPrimaryExpression.js index 4704b32d9891c..fc8d0420842e7 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.js @@ -23,6 +23,6 @@ define(["require", "exports"], function (require, exports) { }); //// [foo_1.js] define(["require", "exports", "./foo_0"], function (require, exports, foo) { - if (0 /* A */ === 0) { + if (foo.E1.A === 0) { } }); diff --git a/tests/baselines/reference/arithmeticOperatorWithEnum.js b/tests/baselines/reference/arithmeticOperatorWithEnum.js index 9ef2790b4cef1..3572f3ecc41e4 100644 --- a/tests/baselines/reference/arithmeticOperatorWithEnum.js +++ b/tests/baselines/reference/arithmeticOperatorWithEnum.js @@ -166,127 +166,127 @@ var ra2 = c * b; var ra3 = c * c; var ra4 = a * c; var ra5 = b * c; -var ra6 = 0 /* a */ * a; -var ra7 = 0 /* a */ * b; -var ra8 = 0 /* a */ * 1 /* b */; -var ra9 = 0 /* a */ * 1; -var ra10 = a * 1 /* b */; -var ra11 = b * 1 /* b */; -var ra12 = 1 * 1 /* b */; +var ra6 = E.a * a; +var ra7 = E.a * b; +var ra8 = E.a * E.b; +var ra9 = E.a * 1; +var ra10 = a * E.b; +var ra11 = b * E.b; +var ra12 = 1 * E.b; // operator / var rb1 = c / a; var rb2 = c / b; var rb3 = c / c; var rb4 = a / c; var rb5 = b / c; -var rb6 = 0 /* a */ / a; -var rb7 = 0 /* a */ / b; -var rb8 = 0 /* a */ / 1 /* b */; -var rb9 = 0 /* a */ / 1; -var rb10 = a / 1 /* b */; -var rb11 = b / 1 /* b */; -var rb12 = 1 / 1 /* b */; +var rb6 = E.a / a; +var rb7 = E.a / b; +var rb8 = E.a / E.b; +var rb9 = E.a / 1; +var rb10 = a / E.b; +var rb11 = b / E.b; +var rb12 = 1 / E.b; // operator % var rc1 = c % a; var rc2 = c % b; var rc3 = c % c; var rc4 = a % c; var rc5 = b % c; -var rc6 = 0 /* a */ % a; -var rc7 = 0 /* a */ % b; -var rc8 = 0 /* a */ % 1 /* b */; -var rc9 = 0 /* a */ % 1; -var rc10 = a % 1 /* b */; -var rc11 = b % 1 /* b */; -var rc12 = 1 % 1 /* b */; +var rc6 = E.a % a; +var rc7 = E.a % b; +var rc8 = E.a % E.b; +var rc9 = E.a % 1; +var rc10 = a % E.b; +var rc11 = b % E.b; +var rc12 = 1 % E.b; // operator - var rd1 = c - a; var rd2 = c - b; var rd3 = c - c; var rd4 = a - c; var rd5 = b - c; -var rd6 = 0 /* a */ - a; -var rd7 = 0 /* a */ - b; -var rd8 = 0 /* a */ - 1 /* b */; -var rd9 = 0 /* a */ - 1; -var rd10 = a - 1 /* b */; -var rd11 = b - 1 /* b */; -var rd12 = 1 - 1 /* b */; +var rd6 = E.a - a; +var rd7 = E.a - b; +var rd8 = E.a - E.b; +var rd9 = E.a - 1; +var rd10 = a - E.b; +var rd11 = b - E.b; +var rd12 = 1 - E.b; // operator << var re1 = c << a; var re2 = c << b; var re3 = c << c; var re4 = a << c; var re5 = b << c; -var re6 = 0 /* a */ << a; -var re7 = 0 /* a */ << b; -var re8 = 0 /* a */ << 1 /* b */; -var re9 = 0 /* a */ << 1; -var re10 = a << 1 /* b */; -var re11 = b << 1 /* b */; -var re12 = 1 << 1 /* b */; +var re6 = E.a << a; +var re7 = E.a << b; +var re8 = E.a << E.b; +var re9 = E.a << 1; +var re10 = a << E.b; +var re11 = b << E.b; +var re12 = 1 << E.b; // operator >> var rf1 = c >> a; var rf2 = c >> b; var rf3 = c >> c; var rf4 = a >> c; var rf5 = b >> c; -var rf6 = 0 /* a */ >> a; -var rf7 = 0 /* a */ >> b; -var rf8 = 0 /* a */ >> 1 /* b */; -var rf9 = 0 /* a */ >> 1; -var rf10 = a >> 1 /* b */; -var rf11 = b >> 1 /* b */; -var rf12 = 1 >> 1 /* b */; +var rf6 = E.a >> a; +var rf7 = E.a >> b; +var rf8 = E.a >> E.b; +var rf9 = E.a >> 1; +var rf10 = a >> E.b; +var rf11 = b >> E.b; +var rf12 = 1 >> E.b; // operator >>> var rg1 = c >>> a; var rg2 = c >>> b; var rg3 = c >>> c; var rg4 = a >>> c; var rg5 = b >>> c; -var rg6 = 0 /* a */ >>> a; -var rg7 = 0 /* a */ >>> b; -var rg8 = 0 /* a */ >>> 1 /* b */; -var rg9 = 0 /* a */ >>> 1; -var rg10 = a >>> 1 /* b */; -var rg11 = b >>> 1 /* b */; -var rg12 = 1 >>> 1 /* b */; +var rg6 = E.a >>> a; +var rg7 = E.a >>> b; +var rg8 = E.a >>> E.b; +var rg9 = E.a >>> 1; +var rg10 = a >>> E.b; +var rg11 = b >>> E.b; +var rg12 = 1 >>> E.b; // operator & var rh1 = c & a; var rh2 = c & b; var rh3 = c & c; var rh4 = a & c; var rh5 = b & c; -var rh6 = 0 /* a */ & a; -var rh7 = 0 /* a */ & b; -var rh8 = 0 /* a */ & 1 /* b */; -var rh9 = 0 /* a */ & 1; -var rh10 = a & 1 /* b */; -var rh11 = b & 1 /* b */; -var rh12 = 1 & 1 /* b */; +var rh6 = E.a & a; +var rh7 = E.a & b; +var rh8 = E.a & E.b; +var rh9 = E.a & 1; +var rh10 = a & E.b; +var rh11 = b & E.b; +var rh12 = 1 & E.b; // operator ^ var ri1 = c ^ a; var ri2 = c ^ b; var ri3 = c ^ c; var ri4 = a ^ c; var ri5 = b ^ c; -var ri6 = 0 /* a */ ^ a; -var ri7 = 0 /* a */ ^ b; -var ri8 = 0 /* a */ ^ 1 /* b */; -var ri9 = 0 /* a */ ^ 1; -var ri10 = a ^ 1 /* b */; -var ri11 = b ^ 1 /* b */; -var ri12 = 1 ^ 1 /* b */; +var ri6 = E.a ^ a; +var ri7 = E.a ^ b; +var ri8 = E.a ^ E.b; +var ri9 = E.a ^ 1; +var ri10 = a ^ E.b; +var ri11 = b ^ E.b; +var ri12 = 1 ^ E.b; // operator | var rj1 = c | a; var rj2 = c | b; var rj3 = c | c; var rj4 = a | c; var rj5 = b | c; -var rj6 = 0 /* a */ | a; -var rj7 = 0 /* a */ | b; -var rj8 = 0 /* a */ | 1 /* b */; -var rj9 = 0 /* a */ | 1; -var rj10 = a | 1 /* b */; -var rj11 = b | 1 /* b */; -var rj12 = 1 | 1 /* b */; +var rj6 = E.a | a; +var rj7 = E.a | b; +var rj8 = E.a | E.b; +var rj9 = E.a | 1; +var rj10 = a | E.b; +var rj11 = b | E.b; +var rj12 = 1 | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js b/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js index 315f7dd237b7f..95bc0b866c91c 100644 --- a/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js +++ b/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js @@ -175,127 +175,127 @@ var ra2 = c * b; var ra3 = c * c; var ra4 = a * c; var ra5 = b * c; -var ra6 = 0 /* a */ * a; -var ra7 = 0 /* a */ * b; -var ra8 = 0 /* a */ * 1 /* b */; -var ra9 = 0 /* a */ * 1; -var ra10 = a * 1 /* b */; -var ra11 = b * 1 /* b */; -var ra12 = 1 * 1 /* b */; +var ra6 = E.a * a; +var ra7 = E.a * b; +var ra8 = E.a * E.b; +var ra9 = E.a * 1; +var ra10 = a * E.b; +var ra11 = b * E.b; +var ra12 = 1 * E.b; // operator / var rb1 = c / a; var rb2 = c / b; var rb3 = c / c; var rb4 = a / c; var rb5 = b / c; -var rb6 = 0 /* a */ / a; -var rb7 = 0 /* a */ / b; -var rb8 = 0 /* a */ / 1 /* b */; -var rb9 = 0 /* a */ / 1; -var rb10 = a / 1 /* b */; -var rb11 = b / 1 /* b */; -var rb12 = 1 / 1 /* b */; +var rb6 = E.a / a; +var rb7 = E.a / b; +var rb8 = E.a / E.b; +var rb9 = E.a / 1; +var rb10 = a / E.b; +var rb11 = b / E.b; +var rb12 = 1 / E.b; // operator % var rc1 = c % a; var rc2 = c % b; var rc3 = c % c; var rc4 = a % c; var rc5 = b % c; -var rc6 = 0 /* a */ % a; -var rc7 = 0 /* a */ % b; -var rc8 = 0 /* a */ % 1 /* b */; -var rc9 = 0 /* a */ % 1; -var rc10 = a % 1 /* b */; -var rc11 = b % 1 /* b */; -var rc12 = 1 % 1 /* b */; +var rc6 = E.a % a; +var rc7 = E.a % b; +var rc8 = E.a % E.b; +var rc9 = E.a % 1; +var rc10 = a % E.b; +var rc11 = b % E.b; +var rc12 = 1 % E.b; // operator - var rd1 = c - a; var rd2 = c - b; var rd3 = c - c; var rd4 = a - c; var rd5 = b - c; -var rd6 = 0 /* a */ - a; -var rd7 = 0 /* a */ - b; -var rd8 = 0 /* a */ - 1 /* b */; -var rd9 = 0 /* a */ - 1; -var rd10 = a - 1 /* b */; -var rd11 = b - 1 /* b */; -var rd12 = 1 - 1 /* b */; +var rd6 = E.a - a; +var rd7 = E.a - b; +var rd8 = E.a - E.b; +var rd9 = E.a - 1; +var rd10 = a - E.b; +var rd11 = b - E.b; +var rd12 = 1 - E.b; // operator << var re1 = c << a; var re2 = c << b; var re3 = c << c; var re4 = a << c; var re5 = b << c; -var re6 = 0 /* a */ << a; -var re7 = 0 /* a */ << b; -var re8 = 0 /* a */ << 1 /* b */; -var re9 = 0 /* a */ << 1; -var re10 = a << 1 /* b */; -var re11 = b << 1 /* b */; -var re12 = 1 << 1 /* b */; +var re6 = E.a << a; +var re7 = E.a << b; +var re8 = E.a << E.b; +var re9 = E.a << 1; +var re10 = a << E.b; +var re11 = b << E.b; +var re12 = 1 << E.b; // operator >> var rf1 = c >> a; var rf2 = c >> b; var rf3 = c >> c; var rf4 = a >> c; var rf5 = b >> c; -var rf6 = 0 /* a */ >> a; -var rf7 = 0 /* a */ >> b; -var rf8 = 0 /* a */ >> 1 /* b */; -var rf9 = 0 /* a */ >> 1; -var rf10 = a >> 1 /* b */; -var rf11 = b >> 1 /* b */; -var rf12 = 1 >> 1 /* b */; +var rf6 = E.a >> a; +var rf7 = E.a >> b; +var rf8 = E.a >> E.b; +var rf9 = E.a >> 1; +var rf10 = a >> E.b; +var rf11 = b >> E.b; +var rf12 = 1 >> E.b; // operator >>> var rg1 = c >>> a; var rg2 = c >>> b; var rg3 = c >>> c; var rg4 = a >>> c; var rg5 = b >>> c; -var rg6 = 0 /* a */ >>> a; -var rg7 = 0 /* a */ >>> b; -var rg8 = 0 /* a */ >>> 1 /* b */; -var rg9 = 0 /* a */ >>> 1; -var rg10 = a >>> 1 /* b */; -var rg11 = b >>> 1 /* b */; -var rg12 = 1 >>> 1 /* b */; +var rg6 = E.a >>> a; +var rg7 = E.a >>> b; +var rg8 = E.a >>> E.b; +var rg9 = E.a >>> 1; +var rg10 = a >>> E.b; +var rg11 = b >>> E.b; +var rg12 = 1 >>> E.b; // operator & var rh1 = c & a; var rh2 = c & b; var rh3 = c & c; var rh4 = a & c; var rh5 = b & c; -var rh6 = 0 /* a */ & a; -var rh7 = 0 /* a */ & b; -var rh8 = 0 /* a */ & 1 /* b */; -var rh9 = 0 /* a */ & 1; -var rh10 = a & 1 /* b */; -var rh11 = b & 1 /* b */; -var rh12 = 1 & 1 /* b */; +var rh6 = E.a & a; +var rh7 = E.a & b; +var rh8 = E.a & E.b; +var rh9 = E.a & 1; +var rh10 = a & E.b; +var rh11 = b & E.b; +var rh12 = 1 & E.b; // operator ^ var ri1 = c ^ a; var ri2 = c ^ b; var ri3 = c ^ c; var ri4 = a ^ c; var ri5 = b ^ c; -var ri6 = 0 /* a */ ^ a; -var ri7 = 0 /* a */ ^ b; -var ri8 = 0 /* a */ ^ 1 /* b */; -var ri9 = 0 /* a */ ^ 1; -var ri10 = a ^ 1 /* b */; -var ri11 = b ^ 1 /* b */; -var ri12 = 1 ^ 1 /* b */; +var ri6 = E.a ^ a; +var ri7 = E.a ^ b; +var ri8 = E.a ^ E.b; +var ri9 = E.a ^ 1; +var ri10 = a ^ E.b; +var ri11 = b ^ E.b; +var ri12 = 1 ^ E.b; // operator | var rj1 = c | a; var rj2 = c | b; var rj3 = c | c; var rj4 = a | c; var rj5 = b | c; -var rj6 = 0 /* a */ | a; -var rj7 = 0 /* a */ | b; -var rj8 = 0 /* a */ | 1 /* b */; -var rj9 = 0 /* a */ | 1; -var rj10 = a | 1 /* b */; -var rj11 = b | 1 /* b */; -var rj12 = 1 | 1 /* b */; +var rj6 = E.a | a; +var rj7 = E.a | b; +var rj8 = E.a | E.b; +var rj9 = E.a | 1; +var rj10 = a | E.b; +var rj11 = b | E.b; +var rj12 = 1 | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js b/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js index 8a9e65491446b..974e9930103d7 100644 --- a/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js @@ -634,18 +634,18 @@ var r1f3 = f * c; var r1f4 = f * d; var r1f5 = f * e; var r1f6 = f * f; -var r1g1 = 0 /* a */ * a; //ok -var r1g2 = 0 /* a */ * b; -var r1g3 = 0 /* a */ * c; //ok -var r1g4 = 0 /* a */ * d; -var r1g5 = 0 /* a */ * e; -var r1g6 = 0 /* a */ * f; -var r1h1 = a * 1 /* b */; //ok -var r1h2 = b * 1 /* b */; -var r1h3 = c * 1 /* b */; //ok -var r1h4 = d * 1 /* b */; -var r1h5 = e * 1 /* b */; -var r1h6 = f * 1 /* b */; +var r1g1 = E.a * a; //ok +var r1g2 = E.a * b; +var r1g3 = E.a * c; //ok +var r1g4 = E.a * d; +var r1g5 = E.a * e; +var r1g6 = E.a * f; +var r1h1 = a * E.b; //ok +var r1h2 = b * E.b; +var r1h3 = c * E.b; //ok +var r1h4 = d * E.b; +var r1h5 = e * E.b; +var r1h6 = f * E.b; // operator / var r2a1 = a / a; //ok var r2a2 = a / b; @@ -683,18 +683,18 @@ var r2f3 = f / c; var r2f4 = f / d; var r2f5 = f / e; var r2f6 = f / f; -var r2g1 = 0 /* a */ / a; //ok -var r2g2 = 0 /* a */ / b; -var r2g3 = 0 /* a */ / c; //ok -var r2g4 = 0 /* a */ / d; -var r2g5 = 0 /* a */ / e; -var r2g6 = 0 /* a */ / f; -var r2h1 = a / 1 /* b */; //ok -var r2h2 = b / 1 /* b */; -var r2h3 = c / 1 /* b */; //ok -var r2h4 = d / 1 /* b */; -var r2h5 = e / 1 /* b */; -var r2h6 = f / 1 /* b */; +var r2g1 = E.a / a; //ok +var r2g2 = E.a / b; +var r2g3 = E.a / c; //ok +var r2g4 = E.a / d; +var r2g5 = E.a / e; +var r2g6 = E.a / f; +var r2h1 = a / E.b; //ok +var r2h2 = b / E.b; +var r2h3 = c / E.b; //ok +var r2h4 = d / E.b; +var r2h5 = e / E.b; +var r2h6 = f / E.b; // operator % var r3a1 = a % a; //ok var r3a2 = a % b; @@ -732,18 +732,18 @@ var r3f3 = f % c; var r3f4 = f % d; var r3f5 = f % e; var r3f6 = f % f; -var r3g1 = 0 /* a */ % a; //ok -var r3g2 = 0 /* a */ % b; -var r3g3 = 0 /* a */ % c; //ok -var r3g4 = 0 /* a */ % d; -var r3g5 = 0 /* a */ % e; -var r3g6 = 0 /* a */ % f; -var r3h1 = a % 1 /* b */; //ok -var r3h2 = b % 1 /* b */; -var r3h3 = c % 1 /* b */; //ok -var r3h4 = d % 1 /* b */; -var r3h5 = e % 1 /* b */; -var r3h6 = f % 1 /* b */; +var r3g1 = E.a % a; //ok +var r3g2 = E.a % b; +var r3g3 = E.a % c; //ok +var r3g4 = E.a % d; +var r3g5 = E.a % e; +var r3g6 = E.a % f; +var r3h1 = a % E.b; //ok +var r3h2 = b % E.b; +var r3h3 = c % E.b; //ok +var r3h4 = d % E.b; +var r3h5 = e % E.b; +var r3h6 = f % E.b; // operator - var r4a1 = a - a; //ok var r4a2 = a - b; @@ -781,18 +781,18 @@ var r4f3 = f - c; var r4f4 = f - d; var r4f5 = f - e; var r4f6 = f - f; -var r4g1 = 0 /* a */ - a; //ok -var r4g2 = 0 /* a */ - b; -var r4g3 = 0 /* a */ - c; //ok -var r4g4 = 0 /* a */ - d; -var r4g5 = 0 /* a */ - e; -var r4g6 = 0 /* a */ - f; -var r4h1 = a - 1 /* b */; //ok -var r4h2 = b - 1 /* b */; -var r4h3 = c - 1 /* b */; //ok -var r4h4 = d - 1 /* b */; -var r4h5 = e - 1 /* b */; -var r4h6 = f - 1 /* b */; +var r4g1 = E.a - a; //ok +var r4g2 = E.a - b; +var r4g3 = E.a - c; //ok +var r4g4 = E.a - d; +var r4g5 = E.a - e; +var r4g6 = E.a - f; +var r4h1 = a - E.b; //ok +var r4h2 = b - E.b; +var r4h3 = c - E.b; //ok +var r4h4 = d - E.b; +var r4h5 = e - E.b; +var r4h6 = f - E.b; // operator << var r5a1 = a << a; //ok var r5a2 = a << b; @@ -830,18 +830,18 @@ var r5f3 = f << c; var r5f4 = f << d; var r5f5 = f << e; var r5f6 = f << f; -var r5g1 = 0 /* a */ << a; //ok -var r5g2 = 0 /* a */ << b; -var r5g3 = 0 /* a */ << c; //ok -var r5g4 = 0 /* a */ << d; -var r5g5 = 0 /* a */ << e; -var r5g6 = 0 /* a */ << f; -var r5h1 = a << 1 /* b */; //ok -var r5h2 = b << 1 /* b */; -var r5h3 = c << 1 /* b */; //ok -var r5h4 = d << 1 /* b */; -var r5h5 = e << 1 /* b */; -var r5h6 = f << 1 /* b */; +var r5g1 = E.a << a; //ok +var r5g2 = E.a << b; +var r5g3 = E.a << c; //ok +var r5g4 = E.a << d; +var r5g5 = E.a << e; +var r5g6 = E.a << f; +var r5h1 = a << E.b; //ok +var r5h2 = b << E.b; +var r5h3 = c << E.b; //ok +var r5h4 = d << E.b; +var r5h5 = e << E.b; +var r5h6 = f << E.b; // operator >> var r6a1 = a >> a; //ok var r6a2 = a >> b; @@ -879,18 +879,18 @@ var r6f3 = f >> c; var r6f4 = f >> d; var r6f5 = f >> e; var r6f6 = f >> f; -var r6g1 = 0 /* a */ >> a; //ok -var r6g2 = 0 /* a */ >> b; -var r6g3 = 0 /* a */ >> c; //ok -var r6g4 = 0 /* a */ >> d; -var r6g5 = 0 /* a */ >> e; -var r6g6 = 0 /* a */ >> f; -var r6h1 = a >> 1 /* b */; //ok -var r6h2 = b >> 1 /* b */; -var r6h3 = c >> 1 /* b */; //ok -var r6h4 = d >> 1 /* b */; -var r6h5 = e >> 1 /* b */; -var r6h6 = f >> 1 /* b */; +var r6g1 = E.a >> a; //ok +var r6g2 = E.a >> b; +var r6g3 = E.a >> c; //ok +var r6g4 = E.a >> d; +var r6g5 = E.a >> e; +var r6g6 = E.a >> f; +var r6h1 = a >> E.b; //ok +var r6h2 = b >> E.b; +var r6h3 = c >> E.b; //ok +var r6h4 = d >> E.b; +var r6h5 = e >> E.b; +var r6h6 = f >> E.b; // operator >>> var r7a1 = a >>> a; //ok var r7a2 = a >>> b; @@ -928,18 +928,18 @@ var r7f3 = f >>> c; var r7f4 = f >>> d; var r7f5 = f >>> e; var r7f6 = f >>> f; -var r7g1 = 0 /* a */ >>> a; //ok -var r7g2 = 0 /* a */ >>> b; -var r7g3 = 0 /* a */ >>> c; //ok -var r7g4 = 0 /* a */ >>> d; -var r7g5 = 0 /* a */ >>> e; -var r7g6 = 0 /* a */ >>> f; -var r7h1 = a >>> 1 /* b */; //ok -var r7h2 = b >>> 1 /* b */; -var r7h3 = c >>> 1 /* b */; //ok -var r7h4 = d >>> 1 /* b */; -var r7h5 = e >>> 1 /* b */; -var r7h6 = f >>> 1 /* b */; +var r7g1 = E.a >>> a; //ok +var r7g2 = E.a >>> b; +var r7g3 = E.a >>> c; //ok +var r7g4 = E.a >>> d; +var r7g5 = E.a >>> e; +var r7g6 = E.a >>> f; +var r7h1 = a >>> E.b; //ok +var r7h2 = b >>> E.b; +var r7h3 = c >>> E.b; //ok +var r7h4 = d >>> E.b; +var r7h5 = e >>> E.b; +var r7h6 = f >>> E.b; // operator & var r8a1 = a & a; //ok var r8a2 = a & b; @@ -977,18 +977,18 @@ var r8f3 = f & c; var r8f4 = f & d; var r8f5 = f & e; var r8f6 = f & f; -var r8g1 = 0 /* a */ & a; //ok -var r8g2 = 0 /* a */ & b; -var r8g3 = 0 /* a */ & c; //ok -var r8g4 = 0 /* a */ & d; -var r8g5 = 0 /* a */ & e; -var r8g6 = 0 /* a */ & f; -var r8h1 = a & 1 /* b */; //ok -var r8h2 = b & 1 /* b */; -var r8h3 = c & 1 /* b */; //ok -var r8h4 = d & 1 /* b */; -var r8h5 = e & 1 /* b */; -var r8h6 = f & 1 /* b */; +var r8g1 = E.a & a; //ok +var r8g2 = E.a & b; +var r8g3 = E.a & c; //ok +var r8g4 = E.a & d; +var r8g5 = E.a & e; +var r8g6 = E.a & f; +var r8h1 = a & E.b; //ok +var r8h2 = b & E.b; +var r8h3 = c & E.b; //ok +var r8h4 = d & E.b; +var r8h5 = e & E.b; +var r8h6 = f & E.b; // operator ^ var r9a1 = a ^ a; //ok var r9a2 = a ^ b; @@ -1026,18 +1026,18 @@ var r9f3 = f ^ c; var r9f4 = f ^ d; var r9f5 = f ^ e; var r9f6 = f ^ f; -var r9g1 = 0 /* a */ ^ a; //ok -var r9g2 = 0 /* a */ ^ b; -var r9g3 = 0 /* a */ ^ c; //ok -var r9g4 = 0 /* a */ ^ d; -var r9g5 = 0 /* a */ ^ e; -var r9g6 = 0 /* a */ ^ f; -var r9h1 = a ^ 1 /* b */; //ok -var r9h2 = b ^ 1 /* b */; -var r9h3 = c ^ 1 /* b */; //ok -var r9h4 = d ^ 1 /* b */; -var r9h5 = e ^ 1 /* b */; -var r9h6 = f ^ 1 /* b */; +var r9g1 = E.a ^ a; //ok +var r9g2 = E.a ^ b; +var r9g3 = E.a ^ c; //ok +var r9g4 = E.a ^ d; +var r9g5 = E.a ^ e; +var r9g6 = E.a ^ f; +var r9h1 = a ^ E.b; //ok +var r9h2 = b ^ E.b; +var r9h3 = c ^ E.b; //ok +var r9h4 = d ^ E.b; +var r9h5 = e ^ E.b; +var r9h6 = f ^ E.b; // operator | var r10a1 = a | a; //ok var r10a2 = a | b; @@ -1075,15 +1075,15 @@ var r10f3 = f | c; var r10f4 = f | d; var r10f5 = f | e; var r10f6 = f | f; -var r10g1 = 0 /* a */ | a; //ok -var r10g2 = 0 /* a */ | b; -var r10g3 = 0 /* a */ | c; //ok -var r10g4 = 0 /* a */ | d; -var r10g5 = 0 /* a */ | e; -var r10g6 = 0 /* a */ | f; -var r10h1 = a | 1 /* b */; //ok -var r10h2 = b | 1 /* b */; -var r10h3 = c | 1 /* b */; //ok -var r10h4 = d | 1 /* b */; -var r10h5 = e | 1 /* b */; -var r10h6 = f | 1 /* b */; +var r10g1 = E.a | a; //ok +var r10g2 = E.a | b; +var r10g3 = E.a | c; //ok +var r10g4 = E.a | d; +var r10g5 = E.a | e; +var r10g6 = E.a | f; +var r10h1 = a | E.b; //ok +var r10h2 = b | E.b; +var r10h3 = c | E.b; //ok +var r10h4 = d | E.b; +var r10h5 = e | E.b; +var r10h6 = f | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js b/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js index 40676ef449586..0c30e8d048492 100644 --- a/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js @@ -124,89 +124,89 @@ var b; var ra1 = null * a; var ra2 = null * b; var ra3 = null * 1; -var ra4 = null * 0 /* a */; +var ra4 = null * E.a; var ra5 = a * null; var ra6 = b * null; var ra7 = 0 * null; -var ra8 = 1 /* b */ * null; +var ra8 = E.b * null; // operator / var rb1 = null / a; var rb2 = null / b; var rb3 = null / 1; -var rb4 = null / 0 /* a */; +var rb4 = null / E.a; var rb5 = a / null; var rb6 = b / null; var rb7 = 0 / null; -var rb8 = 1 /* b */ / null; +var rb8 = E.b / null; // operator % var rc1 = null % a; var rc2 = null % b; var rc3 = null % 1; -var rc4 = null % 0 /* a */; +var rc4 = null % E.a; var rc5 = a % null; var rc6 = b % null; var rc7 = 0 % null; -var rc8 = 1 /* b */ % null; +var rc8 = E.b % null; // operator - var rd1 = null - a; var rd2 = null - b; var rd3 = null - 1; -var rd4 = null - 0 /* a */; +var rd4 = null - E.a; var rd5 = a - null; var rd6 = b - null; var rd7 = 0 - null; -var rd8 = 1 /* b */ - null; +var rd8 = E.b - null; // operator << var re1 = null << a; var re2 = null << b; var re3 = null << 1; -var re4 = null << 0 /* a */; +var re4 = null << E.a; var re5 = a << null; var re6 = b << null; var re7 = 0 << null; -var re8 = 1 /* b */ << null; +var re8 = E.b << null; // operator >> var rf1 = null >> a; var rf2 = null >> b; var rf3 = null >> 1; -var rf4 = null >> 0 /* a */; +var rf4 = null >> E.a; var rf5 = a >> null; var rf6 = b >> null; var rf7 = 0 >> null; -var rf8 = 1 /* b */ >> null; +var rf8 = E.b >> null; // operator >>> var rg1 = null >>> a; var rg2 = null >>> b; var rg3 = null >>> 1; -var rg4 = null >>> 0 /* a */; +var rg4 = null >>> E.a; var rg5 = a >>> null; var rg6 = b >>> null; var rg7 = 0 >>> null; -var rg8 = 1 /* b */ >>> null; +var rg8 = E.b >>> null; // operator & var rh1 = null & a; var rh2 = null & b; var rh3 = null & 1; -var rh4 = null & 0 /* a */; +var rh4 = null & E.a; var rh5 = a & null; var rh6 = b & null; var rh7 = 0 & null; -var rh8 = 1 /* b */ & null; +var rh8 = E.b & null; // operator ^ var ri1 = null ^ a; var ri2 = null ^ b; var ri3 = null ^ 1; -var ri4 = null ^ 0 /* a */; +var ri4 = null ^ E.a; var ri5 = a ^ null; var ri6 = b ^ null; var ri7 = 0 ^ null; -var ri8 = 1 /* b */ ^ null; +var ri8 = E.b ^ null; // operator | var rj1 = null | a; var rj2 = null | b; var rj3 = null | 1; -var rj4 = null | 0 /* a */; +var rj4 = null | E.a; var rj5 = a | null; var rj6 = b | null; var rj7 = 0 | null; -var rj8 = 1 /* b */ | null; +var rj8 = E.b | null; diff --git a/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js b/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js index ddc2c87dd7a60..60ea9af32c2b5 100644 --- a/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js @@ -124,89 +124,89 @@ var b; var ra1 = undefined * a; var ra2 = undefined * b; var ra3 = undefined * 1; -var ra4 = undefined * 0 /* a */; +var ra4 = undefined * E.a; var ra5 = a * undefined; var ra6 = b * undefined; var ra7 = 0 * undefined; -var ra8 = 1 /* b */ * undefined; +var ra8 = E.b * undefined; // operator / var rb1 = undefined / a; var rb2 = undefined / b; var rb3 = undefined / 1; -var rb4 = undefined / 0 /* a */; +var rb4 = undefined / E.a; var rb5 = a / undefined; var rb6 = b / undefined; var rb7 = 0 / undefined; -var rb8 = 1 /* b */ / undefined; +var rb8 = E.b / undefined; // operator % var rc1 = undefined % a; var rc2 = undefined % b; var rc3 = undefined % 1; -var rc4 = undefined % 0 /* a */; +var rc4 = undefined % E.a; var rc5 = a % undefined; var rc6 = b % undefined; var rc7 = 0 % undefined; -var rc8 = 1 /* b */ % undefined; +var rc8 = E.b % undefined; // operator - var rd1 = undefined - a; var rd2 = undefined - b; var rd3 = undefined - 1; -var rd4 = undefined - 0 /* a */; +var rd4 = undefined - E.a; var rd5 = a - undefined; var rd6 = b - undefined; var rd7 = 0 - undefined; -var rd8 = 1 /* b */ - undefined; +var rd8 = E.b - undefined; // operator << var re1 = undefined << a; var re2 = undefined << b; var re3 = undefined << 1; -var re4 = undefined << 0 /* a */; +var re4 = undefined << E.a; var re5 = a << undefined; var re6 = b << undefined; var re7 = 0 << undefined; -var re8 = 1 /* b */ << undefined; +var re8 = E.b << undefined; // operator >> var rf1 = undefined >> a; var rf2 = undefined >> b; var rf3 = undefined >> 1; -var rf4 = undefined >> 0 /* a */; +var rf4 = undefined >> E.a; var rf5 = a >> undefined; var rf6 = b >> undefined; var rf7 = 0 >> undefined; -var rf8 = 1 /* b */ >> undefined; +var rf8 = E.b >> undefined; // operator >>> var rg1 = undefined >>> a; var rg2 = undefined >>> b; var rg3 = undefined >>> 1; -var rg4 = undefined >>> 0 /* a */; +var rg4 = undefined >>> E.a; var rg5 = a >>> undefined; var rg6 = b >>> undefined; var rg7 = 0 >>> undefined; -var rg8 = 1 /* b */ >>> undefined; +var rg8 = E.b >>> undefined; // operator & var rh1 = undefined & a; var rh2 = undefined & b; var rh3 = undefined & 1; -var rh4 = undefined & 0 /* a */; +var rh4 = undefined & E.a; var rh5 = a & undefined; var rh6 = b & undefined; var rh7 = 0 & undefined; -var rh8 = 1 /* b */ & undefined; +var rh8 = E.b & undefined; // operator ^ var ri1 = undefined ^ a; var ri2 = undefined ^ b; var ri3 = undefined ^ 1; -var ri4 = undefined ^ 0 /* a */; +var ri4 = undefined ^ E.a; var ri5 = a ^ undefined; var ri6 = b ^ undefined; var ri7 = 0 ^ undefined; -var ri8 = 1 /* b */ ^ undefined; +var ri8 = E.b ^ undefined; // operator | var rj1 = undefined | a; var rj2 = undefined | b; var rj3 = undefined | 1; -var rj4 = undefined | 0 /* a */; +var rj4 = undefined | E.a; var rj5 = a | undefined; var rj6 = b | undefined; var rj7 = 0 | undefined; -var rj8 = 1 /* b */ | undefined; +var rj8 = E.b | undefined; diff --git a/tests/baselines/reference/assignAnyToEveryType.js b/tests/baselines/reference/assignAnyToEveryType.js index 47093cd085290..94b8067ddd786 100644 --- a/tests/baselines/reference/assignAnyToEveryType.js +++ b/tests/baselines/reference/assignAnyToEveryType.js @@ -61,7 +61,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); var g = x; -var g2 = 0 /* A */; +var g2 = E.A; g2 = x; var C = (function () { function C() { diff --git a/tests/baselines/reference/assignEveryTypeToAny.js b/tests/baselines/reference/assignEveryTypeToAny.js index afe0d17cea1c2..ed1911ef99541 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.js +++ b/tests/baselines/reference/assignEveryTypeToAny.js @@ -77,8 +77,8 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -x = 0 /* A */; -var f = 0 /* A */; +x = E.A; +var f = E.A; x = f; var g; x = g; diff --git a/tests/baselines/reference/assignToEnum.js b/tests/baselines/reference/assignToEnum.js index 153068738d197..5f7048894fa32 100644 --- a/tests/baselines/reference/assignToEnum.js +++ b/tests/baselines/reference/assignToEnum.js @@ -14,6 +14,6 @@ var A; A[A["bar"] = 1] = "bar"; })(A || (A = {})); A = undefined; // invalid LHS -A = 1 /* bar */; // invalid LHS -0 /* foo */ = 1; // invalid LHS -0 /* foo */ = 1 /* bar */; // invalid LHS +A = A.bar; // invalid LHS +A.foo = 1; // invalid LHS +A.foo = A.bar; // invalid LHS diff --git a/tests/baselines/reference/assignments.js b/tests/baselines/reference/assignments.js index f9bb008ccacb3..f6ca508384b53 100644 --- a/tests/baselines/reference/assignments.js +++ b/tests/baselines/reference/assignments.js @@ -52,7 +52,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); E = null; // Error -0 /* A */ = null; // OK per spec, Error per implementation (509581) +E.A = null; // OK per spec, Error per implementation (509581) function fn() { } fn = null; // Should be error diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.js b/tests/baselines/reference/bestCommonTypeOfTuple.js index 704cae200a4e5..d5cbe7e67c826 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.js +++ b/tests/baselines/reference/bestCommonTypeOfTuple.js @@ -53,16 +53,16 @@ t1 = [ f2 ]; t2 = [ - 0 /* one */, - 0 /* two */ + E1.one, + E2.two ]; t3 = [ 5, undefined ]; t4 = [ - 0 /* one */, - 0 /* two */, + E1.one, + E2.two, 20 ]; var e1 = t1[2]; // {} diff --git a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js index 710af4edfa779..0bcf2fa39569b 100644 --- a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js +++ b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js @@ -30,11 +30,11 @@ var ENUM1; // enum type var var ResultIsNumber1 = ~ENUM1; // enum type expressions -var ResultIsNumber2 = ~0 /* "A" */; -var ResultIsNumber3 = ~(0 /* A */ + 1 /* "B" */); +var ResultIsNumber2 = ~ENUM1["A"]; +var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]); // multiple ~ operators -var ResultIsNumber4 = ~~~(0 /* "A" */ + 1 /* B */); +var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B); // miss assignment operators ~ENUM1; -~0 /* "A" */; -~0 /* A */, ~1 /* "B" */; +~ENUM1["A"]; +~ENUM1.A, ~ENUM1["B"]; diff --git a/tests/baselines/reference/castingTuple.js b/tests/baselines/reference/castingTuple.js index bea141968a6d2..e615590ea7d96 100644 --- a/tests/baselines/reference/castingTuple.js +++ b/tests/baselines/reference/castingTuple.js @@ -97,8 +97,8 @@ var classCDATuple = classCDTuple; var eleFromCDA1 = classCDATuple[2]; // A var eleFromCDA2 = classCDATuple[5]; // C | D | A var t10 = [ - 0 /* one */, - 0 /* one */ + E1.one, + E2.one ]; var t11 = t10; var array1 = emptyObjTuple; diff --git a/tests/baselines/reference/cloduleWithRecursiveReference.js b/tests/baselines/reference/cloduleWithRecursiveReference.js index 1b8a91b3c6817..1a688712270e1 100644 --- a/tests/baselines/reference/cloduleWithRecursiveReference.js +++ b/tests/baselines/reference/cloduleWithRecursiveReference.js @@ -17,7 +17,7 @@ var M; })(); M.C = C; var C; - (function (_C) { - _C.C = M.C; + (function (C_1) { + C_1.C = M.C; })(C = M.C || (M.C = {})); })(M || (M = {})); diff --git a/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js b/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js index 454fddf6fa87c..1e56eb8bd9f3d 100644 --- a/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js +++ b/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js @@ -8,5 +8,5 @@ enum Color { var Color; (function (Color) { Color[Color["Color"] = 0] = "Color"; - Color[Color["Thing"] = Color.Color] = "Thing"; + Color[Color["Thing"] = 0] = "Thing"; })(Color || (Color = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js index 141ef285f037a..8152a9c27215e 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js @@ -47,14 +47,14 @@ module M { // Shouldnt be _M //// [collisionCodeGenModuleWithAccessorChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var c = (function () { function c() { } Object.defineProperty(c.prototype, "Z", { set: function (M) { - this.y = _M.x; + this.y = M_1.x; }, enumerable: true, configurable: true @@ -63,14 +63,14 @@ var M; })(); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var d = (function () { function d() { } Object.defineProperty(d.prototype, "Z", { set: function (p) { var M = 10; - this.y = _M_1.x; + this.y = M_2.x; }, enumerable: true, configurable: true @@ -94,14 +94,14 @@ var M; })(); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var f = (function () { function f() { } Object.defineProperty(f.prototype, "Z", { get: function () { var M = 10; - return _M_2.x; + return M_3.x; }, enumerable: true, configurable: true diff --git a/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js index 2158a0562ea2d..2aa705c914123 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js @@ -25,31 +25,31 @@ module M { //// [collisionCodeGenModuleWithConstructorChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var c = (function () { function c(M, p) { - if (p === void 0) { p = _M.x; } + if (p === void 0) { p = M_1.x; } } return c; })(); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var d = (function () { function d(M, p) { - if (p === void 0) { p = _M_1.x; } + if (p === void 0) { p = M_2.x; } this.M = M; } return d; })(); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var d2 = (function () { function d2() { var M = 10; - var p = _M_2.x; + var p = M_3.x; } return d2; })(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js b/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js index 0dc8e508d45ca..3662f5d6ddd44 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js @@ -12,6 +12,6 @@ var m1; var e; (function (e) { e[e["m1"] = 0] = "m1"; - e[e["m2"] = e.m1] = "m2"; + e[e["m2"] = 0] = "m2"; })(e || (e = {})); })(m1 || (m1 = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js index caaa6a59da525..252ad2c63dc65 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js @@ -21,24 +21,24 @@ module M { //// [collisionCodeGenModuleWithFunctionChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; function fn(M, p) { - if (p === void 0) { p = _M.x; } + if (p === void 0) { p = M_1.x; } } })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { function fn2() { var M; - var p = _M_1.x; + var p = M_2.x; } })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { function fn3() { function M() { - var p = _M_2.x; + var p = M_3.x; } } })(M || (M = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js b/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js index 59c2ebf295d52..05ae475e7d234 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js @@ -17,29 +17,29 @@ var foo = new m2._m2(); //// [collisionCodeGenModuleWithMemberClassConflict.js] var m1; -(function (_m1) { +(function (m1_1) { var m1 = (function () { function m1() { } return m1; })(); - _m1.m1 = m1; + m1_1.m1 = m1; })(m1 || (m1 = {})); var foo = new m1.m1(); var m2; -(function (_m2_1) { +(function (m2_1) { var m2 = (function () { function m2() { } return m2; })(); - _m2_1.m2 = m2; + m2_1.m2 = m2; var _m2 = (function () { function _m2() { } return _m2; })(); - _m2_1._m2 = _m2; + m2_1._m2 = _m2; })(m2 || (m2 = {})); var foo = new m2.m2(); var foo = new m2._m2(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js b/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js index d57de06dfa73d..1a23b81c139e2 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMemberVariable.js @@ -7,8 +7,8 @@ var foo = m1.m1; //// [collisionCodeGenModuleWithMemberVariable.js] var m1; -(function (_m1) { - _m1.m1 = 10; - var b = _m1.m1; +(function (m1_1) { + m1_1.m1 = 10; + var b = m1_1.m1; })(m1 || (m1 = {})); var foo = m1.m1; diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js index 212364ed30b00..53807f1cabd52 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js @@ -34,37 +34,37 @@ module M { // Shouldnt bn _M //// [collisionCodeGenModuleWithMethodChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var c = (function () { function c() { } c.prototype.fn = function (M, p) { - if (p === void 0) { p = _M.x; } + if (p === void 0) { p = M_1.x; } }; return c; })(); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var d = (function () { function d() { } d.prototype.fn2 = function () { var M; - var p = _M_1.x; + var p = M_2.x; }; return d; })(); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var e = (function () { function e() { } e.prototype.fn3 = function () { function M() { - var p = _M_2.x; + var p = M_3.x; } }; return e; diff --git a/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js index 3c8b17deadd68..2862a84406786 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js @@ -44,16 +44,16 @@ module M { //// [collisionCodeGenModuleWithModuleChildren.js] var M; -(function (_M) { - _M.x = 3; +(function (M_1) { + M_1.x = 3; var m1; (function (m1) { var M = 10; - var p = _M.x; + var p = M_1.x; })(m1 || (m1 = {})); })(M || (M = {})); var M; -(function (_M_1) { +(function (M_2) { var m2; (function (m2) { var M = (function () { @@ -61,17 +61,17 @@ var M; } return M; })(); - var p = _M_1.x; + var p = M_2.x; var p2 = new M(); })(m2 || (m2 = {})); })(M || (M = {})); var M; -(function (_M_2) { +(function (M_3) { var m3; (function (m3) { function M() { } - var p = _M_2.x; + var p = M_3.x; var p2 = M(); })(m3 || (m3 = {})); })(M || (M = {})); @@ -84,12 +84,12 @@ var M; })(m3 || (m3 = {})); })(M || (M = {})); var M; -(function (_M_3) { +(function (M_4) { var m4; (function (m4) { var M; (function (M) { - var p = _M_3.x; + var p = M_4.x; })(M || (M = {})); })(m4 || (m4 = {})); })(M || (M = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js b/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js index 4c3d60230635d..710c09e4558ae 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithModuleReopening.js @@ -31,13 +31,13 @@ var foo2 = new m2.m2(); //// [collisionCodeGenModuleWithModuleReopening.js] var m1; -(function (_m1) { +(function (m1_1) { var m1 = (function () { function m1() { } return m1; })(); - _m1.m1 = m1; + m1_1.m1 = m1; })(m1 || (m1 = {})); var foo = new m1.m1(); var m1; @@ -65,16 +65,16 @@ var m2; })(m2 || (m2 = {})); var foo3 = new m2.c1(); var m2; -(function (_m2) { +(function (m2_1) { var m2 = (function () { function m2() { } return m2; })(); - _m2.m2 = m2; + m2_1.m2 = m2; var b = new m2(); - var d = _m2.b10; - var c = new _m2.c1(); + var d = m2_1.b10; + var c = new m2_1.c1(); })(m2 || (m2 = {})); var foo3 = new m2.c1(); var foo2 = new m2.m2(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js b/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js index 28901bd11e829..4b4d6aa7afb1b 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithPrivateMember.js @@ -10,7 +10,7 @@ var foo = new m1.c1(); //// [collisionCodeGenModuleWithPrivateMember.js] var m1; -(function (_m1) { +(function (m1_1) { var m1 = (function () { function m1() { } @@ -22,6 +22,6 @@ var m1; } return c1; })(); - _m1.c1 = c1; + m1_1.c1 = c1; })(m1 || (m1 = {})); var foo = new m1.c1(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js b/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js index d4e919e0a17ae..3204a05bc7575 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithUnicodeNames.js @@ -11,12 +11,12 @@ var x = new 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكو //// [collisionCodeGenModuleWithUnicodeNames.js] var 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; -(function (_才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123) { +(function (才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123_1) { var 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = (function () { function 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123() { } return 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; })(); - _才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123.才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; + 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123_1.才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123; })(才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 || (才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123 = {})); var x = new 才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123.才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüß才能ソЫⅨ蒤郳र्क्ड्राüışğİliيونيكودöÄüßAbcd123(); diff --git a/tests/baselines/reference/commentsEnums.js b/tests/baselines/reference/commentsEnums.js index c8bba8a4f776d..7be17f085b0ac 100644 --- a/tests/baselines/reference/commentsEnums.js +++ b/tests/baselines/reference/commentsEnums.js @@ -21,8 +21,8 @@ var Colors; /** Fancy name for 'pink'*/ Colors[Colors["FancyPink"] = 1] = "FancyPink"; })(Colors || (Colors = {})); // trailing comment -var x = 0 /* Cornflower */; -x = 1 /* FancyPink */; +var x = Colors.Cornflower; +x = Colors.FancyPink; //// [commentsEnums.d.ts] diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js index e0c1f33cb4ada..fc0323a89aa08 100644 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js @@ -80,56 +80,56 @@ var b; // operator < var ra1 = a < b; var ra2 = b < a; -var ra3 = 0 /* a */ < b; -var ra4 = b < 0 /* a */; -var ra5 = 0 /* a */ < 0; -var ra6 = 0 < 0 /* a */; +var ra3 = E.a < b; +var ra4 = b < E.a; +var ra5 = E.a < 0; +var ra6 = 0 < E.a; // operator > var rb1 = a > b; var rb2 = b > a; -var rb3 = 0 /* a */ > b; -var rb4 = b > 0 /* a */; -var rb5 = 0 /* a */ > 0; -var rb6 = 0 > 0 /* a */; +var rb3 = E.a > b; +var rb4 = b > E.a; +var rb5 = E.a > 0; +var rb6 = 0 > E.a; // operator <= var rc1 = a <= b; var rc2 = b <= a; -var rc3 = 0 /* a */ <= b; -var rc4 = b <= 0 /* a */; -var rc5 = 0 /* a */ <= 0; -var rc6 = 0 <= 0 /* a */; +var rc3 = E.a <= b; +var rc4 = b <= E.a; +var rc5 = E.a <= 0; +var rc6 = 0 <= E.a; // operator >= var rd1 = a >= b; var rd2 = b >= a; -var rd3 = 0 /* a */ >= b; -var rd4 = b >= 0 /* a */; -var rd5 = 0 /* a */ >= 0; -var rd6 = 0 >= 0 /* a */; +var rd3 = E.a >= b; +var rd4 = b >= E.a; +var rd5 = E.a >= 0; +var rd6 = 0 >= E.a; // operator == var re1 = a == b; var re2 = b == a; -var re3 = 0 /* a */ == b; -var re4 = b == 0 /* a */; -var re5 = 0 /* a */ == 0; -var re6 = 0 == 0 /* a */; +var re3 = E.a == b; +var re4 = b == E.a; +var re5 = E.a == 0; +var re6 = 0 == E.a; // operator != var rf1 = a != b; var rf2 = b != a; -var rf3 = 0 /* a */ != b; -var rf4 = b != 0 /* a */; -var rf5 = 0 /* a */ != 0; -var rf6 = 0 != 0 /* a */; +var rf3 = E.a != b; +var rf4 = b != E.a; +var rf5 = E.a != 0; +var rf6 = 0 != E.a; // operator === var rg1 = a === b; var rg2 = b === a; -var rg3 = 0 /* a */ === b; -var rg4 = b === 0 /* a */; -var rg5 = 0 /* a */ === 0; -var rg6 = 0 === 0 /* a */; +var rg3 = E.a === b; +var rg4 = b === E.a; +var rg5 = E.a === 0; +var rg6 = 0 === E.a; // operator !== var rh1 = a !== b; var rh2 = b !== a; -var rh3 = 0 /* a */ !== b; -var rh4 = b !== 0 /* a */; -var rh5 = 0 /* a */ !== 0; -var rh6 = 0 !== 0 /* a */; +var rh3 = E.a !== b; +var rh4 = b !== E.a; +var rh5 = E.a !== 0; +var rh6 = 0 !== E.a; diff --git a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js index aebacb8882780..ae53d0641783a 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js +++ b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js @@ -64,7 +64,7 @@ x1 += b; x1 += true; x1 += 0; x1 += ''; -x1 += 0 /* a */; +x1 += E.a; x1 += {}; x1 += null; x1 += undefined; @@ -74,20 +74,20 @@ x2 += b; x2 += true; x2 += 0; x2 += ''; -x2 += 0 /* a */; +x2 += E.a; x2 += {}; x2 += null; x2 += undefined; var x3; x3 += a; x3 += 0; -x3 += 0 /* a */; +x3 += E.a; x3 += null; x3 += undefined; var x4; x4 += a; x4 += 0; -x4 += 0 /* a */; +x4 += E.a; x4 += null; x4 += undefined; var x5; diff --git a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js index af4f1bc152193..cef1d3e424e97 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js +++ b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js @@ -51,7 +51,7 @@ var x1; x1 += a; x1 += true; x1 += 0; -x1 += 0 /* a */; +x1 += E.a; x1 += {}; x1 += null; x1 += undefined; @@ -59,7 +59,7 @@ var x2; x2 += a; x2 += true; x2 += 0; -x2 += 0 /* a */; +x2 += E.a; x2 += {}; x2 += null; x2 += undefined; @@ -67,7 +67,7 @@ var x3; x3 += a; x3 += true; x3 += 0; -x3 += 0 /* a */; +x3 += E.a; x3 += {}; x3 += null; x3 += undefined; diff --git a/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js b/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js index 61722df0fb043..5c71f717bb237 100644 --- a/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js +++ b/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js @@ -74,7 +74,7 @@ x1 *= b; x1 *= true; x1 *= 0; x1 *= ''; -x1 *= 0 /* a */; +x1 *= E.a; x1 *= {}; x1 *= null; x1 *= undefined; @@ -84,7 +84,7 @@ x2 *= b; x2 *= true; x2 *= 0; x2 *= ''; -x2 *= 0 /* a */; +x2 *= E.a; x2 *= {}; x2 *= null; x2 *= undefined; @@ -94,7 +94,7 @@ x3 *= b; x3 *= true; x3 *= 0; x3 *= ''; -x3 *= 0 /* a */; +x3 *= E.a; x3 *= {}; x3 *= null; x3 *= undefined; @@ -104,7 +104,7 @@ x4 *= b; x4 *= true; x4 *= 0; x4 *= ''; -x4 *= 0 /* a */; +x4 *= E.a; x4 *= {}; x4 *= null; x4 *= undefined; diff --git a/tests/baselines/reference/computedPropertyNames23_ES5.js b/tests/baselines/reference/computedPropertyNames23_ES5.js index c3024a7fbbfde..34eb0896376df 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES5.js +++ b/tests/baselines/reference/computedPropertyNames23_ES5.js @@ -20,5 +20,5 @@ var C = (function () { _a)[0]] = function () { }; return C; + var _a; })(); -var _a; diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 5651ee266c94e..cac71f734a693 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -35,5 +35,5 @@ var C = (function (_super) { _a)[0]] = function () { }; return C; + var _a; })(Base); -var _a; diff --git a/tests/baselines/reference/computedPropertyNames47_ES5.js b/tests/baselines/reference/computedPropertyNames47_ES5.js index 7d839e16ffb7d..a2fff2110b49f 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES5.js +++ b/tests/baselines/reference/computedPropertyNames47_ES5.js @@ -15,6 +15,6 @@ var E2; E2[E2["x"] = 0] = "x"; })(E2 || (E2 = {})); var o = (_a = {}, - _a[0 /* x */ || 0 /* x */] = 0, + _a[E1.x || E2.x] = 0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames47_ES6.js b/tests/baselines/reference/computedPropertyNames47_ES6.js index e104d33e7d37c..0b6cb352999c3 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES6.js +++ b/tests/baselines/reference/computedPropertyNames47_ES6.js @@ -15,5 +15,5 @@ var E2; E2[E2["x"] = 0] = "x"; })(E2 || (E2 = {})); var o = { - [0 /* x */ || 0 /* x */]: 0 + [E1.x || E2.x]: 0 }; diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.js b/tests/baselines/reference/computedPropertyNames48_ES5.js index c5ca0d5b241a2..55b08ef8301d3 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.js +++ b/tests/baselines/reference/computedPropertyNames48_ES5.js @@ -27,7 +27,7 @@ extractIndexer((_a = {}, _a[a] = "", _a)); // Should return string extractIndexer((_b = {}, - _b[0 /* x */] = "", + _b[E.x] = "", _b)); // Should return string extractIndexer((_c = {}, _c["" || 0] = "", diff --git a/tests/baselines/reference/computedPropertyNames48_ES6.js b/tests/baselines/reference/computedPropertyNames48_ES6.js index 2782164756580..8e54d67238c21 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES6.js +++ b/tests/baselines/reference/computedPropertyNames48_ES6.js @@ -27,7 +27,7 @@ extractIndexer({ [a]: "" }); // Should return string extractIndexer({ - [0 /* x */]: "" + [E.x]: "" }); // Should return string extractIndexer({ ["" || 0]: "" diff --git a/tests/baselines/reference/computedPropertyNames7_ES5.js b/tests/baselines/reference/computedPropertyNames7_ES5.js index 9c23dcab20d04..01cf2efc030b8 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES5.js +++ b/tests/baselines/reference/computedPropertyNames7_ES5.js @@ -12,6 +12,6 @@ var E; E[E["member"] = 0] = "member"; })(E || (E = {})); var v = (_a = {}, - _a[0 /* member */] = 0, + _a[E.member] = 0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames7_ES6.js b/tests/baselines/reference/computedPropertyNames7_ES6.js index 5714fb747a6a3..ee1e1c85c06a8 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES6.js +++ b/tests/baselines/reference/computedPropertyNames7_ES6.js @@ -12,5 +12,5 @@ var E; E[E["member"] = 0] = "member"; })(E || (E = {})); var v = { - [0 /* member */]: 0 + [E.member]: 0 }; diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js index 566213887f46d..0bc51e90c5cce 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js @@ -369,7 +369,7 @@ var BasicFeatures = (function () { return 'objLit{42}'; } }; - var weekday = 0 /* Monday */; + var weekday = Weekdays.Monday; var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday; // var any = 0 ^= ; diff --git a/tests/baselines/reference/declFileEnums.js b/tests/baselines/reference/declFileEnums.js index 97559f05574bc..34f1e386a964a 100644 --- a/tests/baselines/reference/declFileEnums.js +++ b/tests/baselines/reference/declFileEnums.js @@ -46,14 +46,14 @@ var e1; var e2; (function (e2) { e2[e2["a"] = 10] = "a"; - e2[e2["b"] = e2.a + 2] = "b"; + e2[e2["b"] = 12] = "b"; e2[e2["c"] = 10] = "c"; })(e2 || (e2 = {})); var e3; (function (e3) { e3[e3["a"] = 10] = "a"; e3[e3["b"] = Math.PI] = "b"; - e3[e3["c"] = e3.a + 3] = "c"; + e3[e3["c"] = 13] = "c"; })(e3 || (e3 = {})); var e4; (function (e4) { @@ -80,13 +80,13 @@ declare enum e1 { } declare enum e2 { a = 10, - b, + b = 12, c = 10, } declare enum e3 { a = 10, b, - c, + c = 13, } declare enum e4 { a = 0, diff --git a/tests/baselines/reference/declFileImportChainInExportAssignment.js b/tests/baselines/reference/declFileImportChainInExportAssignment.js index c8773889a7d0b..4ec3893d02fa8 100644 --- a/tests/baselines/reference/declFileImportChainInExportAssignment.js +++ b/tests/baselines/reference/declFileImportChainInExportAssignment.js @@ -13,13 +13,13 @@ export = b; var m; (function (m) { var c; - (function (_c) { + (function (c_1) { var c = (function () { function c() { } return c; })(); - _c.c = c; + c_1.c = c; })(c = m.c || (m.c = {})); })(m || (m = {})); var a = m.c; diff --git a/tests/baselines/reference/declFileTypeofEnum.js b/tests/baselines/reference/declFileTypeofEnum.js index 8ced6f9e59554..5b1c697747230 100644 --- a/tests/baselines/reference/declFileTypeofEnum.js +++ b/tests/baselines/reference/declFileTypeofEnum.js @@ -25,7 +25,7 @@ var days; days[days["saturday"] = 5] = "saturday"; days[days["sunday"] = 6] = "sunday"; })(days || (days = {})); -var weekendDay = 5 /* saturday */; +var weekendDay = days.saturday; var daysOfMonth = days; var daysOfYear; diff --git a/tests/baselines/reference/declFileTypeofInAnonymousType.js b/tests/baselines/reference/declFileTypeofInAnonymousType.js index ab812720d9a21..1a5071fd2197d 100644 --- a/tests/baselines/reference/declFileTypeofInAnonymousType.js +++ b/tests/baselines/reference/declFileTypeofInAnonymousType.js @@ -56,7 +56,7 @@ var d = { me: { en: m1.e }, - mh: 2 /* holiday */ + mh: m1.e.holiday }; diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.js b/tests/baselines/reference/declarationEmitDefaultExport1.js new file mode 100644 index 0000000000000..197e4fc9cc833 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.js @@ -0,0 +1,12 @@ +//// [declarationEmitDefaultExport1.ts] +export default class C { +} + +//// [declarationEmitDefaultExport1.js] +export default class C { +} + + +//// [declarationEmitDefaultExport1.d.ts] +export default class C { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.types b/tests/baselines/reference/declarationEmitDefaultExport1.types new file mode 100644 index 0000000000000..41dd3547b6d66 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport1.ts === +export default class C { +>C : C +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.js b/tests/baselines/reference/declarationEmitDefaultExport2.js new file mode 100644 index 0000000000000..687c6d67cdbaf --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.js @@ -0,0 +1,12 @@ +//// [declarationEmitDefaultExport2.ts] +export default class { +} + +//// [declarationEmitDefaultExport2.js] +export default class { +} + + +//// [declarationEmitDefaultExport2.d.ts] +export default class { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.types b/tests/baselines/reference/declarationEmitDefaultExport2.types new file mode 100644 index 0000000000000..b82e6cfb92376 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport2.ts === +export default class { +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.js b/tests/baselines/reference/declarationEmitDefaultExport3.js new file mode 100644 index 0000000000000..ba412a1b4b727 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.js @@ -0,0 +1,13 @@ +//// [declarationEmitDefaultExport3.ts] +export default function foo() { + return "" +} + +//// [declarationEmitDefaultExport3.js] +export default function foo() { + return ""; +} + + +//// [declarationEmitDefaultExport3.d.ts] +export default function foo(): string; diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.types b/tests/baselines/reference/declarationEmitDefaultExport3.types new file mode 100644 index 0000000000000..0bde6eff91587 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/declarationEmitDefaultExport3.ts === +export default function foo() { +>foo : () => string + + return "" +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.js b/tests/baselines/reference/declarationEmitDefaultExport4.js new file mode 100644 index 0000000000000..92f8ef8bb8125 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.js @@ -0,0 +1,13 @@ +//// [declarationEmitDefaultExport4.ts] +export default function () { + return 1; +} + +//// [declarationEmitDefaultExport4.js] +export default function () { + return 1; +} + + +//// [declarationEmitDefaultExport4.d.ts] +export default function (): number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.types b/tests/baselines/reference/declarationEmitDefaultExport4.types new file mode 100644 index 0000000000000..8043af36b7620 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/declarationEmitDefaultExport4.ts === +export default function () { +No type information for this code. return 1; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.js b/tests/baselines/reference/declarationEmitDefaultExport5.js new file mode 100644 index 0000000000000..a8794d92c6386 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.js @@ -0,0 +1,10 @@ +//// [declarationEmitDefaultExport5.ts] +export default 1 + 2; + + +//// [declarationEmitDefaultExport5.js] +export default 1 + 2; + + +//// [declarationEmitDefaultExport5.d.ts] +export default : number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.types b/tests/baselines/reference/declarationEmitDefaultExport5.types new file mode 100644 index 0000000000000..702cc51f71ebf --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport5.ts === +export default 1 + 2; +>1 + 2 : number + diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.js b/tests/baselines/reference/declarationEmitDefaultExport6.js new file mode 100644 index 0000000000000..d328458366efb --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.js @@ -0,0 +1,15 @@ +//// [declarationEmitDefaultExport6.ts] +export class A {} +export default new A(); + + +//// [declarationEmitDefaultExport6.js] +export class A { +} +export default new A(); + + +//// [declarationEmitDefaultExport6.d.ts] +export declare class A { +} +export default : A; diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.types b/tests/baselines/reference/declarationEmitDefaultExport6.types new file mode 100644 index 0000000000000..9c839edb1a9aa --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/declarationEmitDefaultExport6.ts === +export class A {} +>A : A + +export default new A(); +>new A() : A +>A : typeof A + diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt new file mode 100644 index 0000000000000..f19766cbb0093 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS4082: Default export of the module has or is using private name 'A'. + + +==== tests/cases/compiler/declarationEmitDefaultExport7.ts (1 errors) ==== + class A {} + export default new A(); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4082: Default export of the module has or is using private name 'A'. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.js b/tests/baselines/reference/declarationEmitDefaultExport7.js new file mode 100644 index 0000000000000..99751113dd66d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.js @@ -0,0 +1,9 @@ +//// [declarationEmitDefaultExport7.ts] +class A {} +export default new A(); + + +//// [declarationEmitDefaultExport7.js] +class A { +} +export default new A(); diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js new file mode 100644 index 0000000000000..7ee32cab16c36 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js @@ -0,0 +1,44 @@ +//// [declarationEmitDestructuringArrayPattern1.ts] + +var [] = [1, "hello"]; // Dont emit anything +var [x] = [1, "hello"]; // emit x: number +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +var [, , z1] = [0, 1, 2]; // emit z1: number + +var a = [1, "hello"]; +var [x2] = a; // emit x2: number | string +var [x3, y3, z3] = a; // emit x3, y3, z3 + +//// [declarationEmitDestructuringArrayPattern1.js] +var _a = [ + 1, + "hello" +]; // Dont emit anything +var x = ([ + 1, + "hello" +])[0]; // emit x: number +var _b = [ + 1, + "hello" +], x1 = _b[0], y1 = _b[1]; // emit x1: number, y1: string +var _c = [ + 0, + 1, + 2 +], z1 = _c[2]; // emit z1: number +var a = [ + 1, + "hello" +]; +var x2 = a[0]; // emit x2: number | string +var x3 = a[0], y3 = a[1], z3 = a[2]; // emit x3, y3, z3 + + +//// [declarationEmitDestructuringArrayPattern1.d.ts] +declare var x: number; +declare var x1: number, y1: string; +declare var z1: number; +declare var a: (string | number)[]; +declare var x2: string | number; +declare var x3: string | number, y3: string | number, z3: string | number; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types new file mode 100644 index 0000000000000..9f6f4c9857d7d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts === + +var [] = [1, "hello"]; // Dont emit anything +>[1, "hello"] : (string | number)[] + +var [x] = [1, "hello"]; // emit x: number +>x : number +>[1, "hello"] : [number, string] + +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +>x1 : number +>y1 : string +>[1, "hello"] : [number, string] + +var [, , z1] = [0, 1, 2]; // emit z1: number +>z1 : number +>[0, 1, 2] : [number, number, number] + +var a = [1, "hello"]; +>a : (string | number)[] +>[1, "hello"] : (string | number)[] + +var [x2] = a; // emit x2: number | string +>x2 : string | number +>a : (string | number)[] + +var [x3, y3, z3] = a; // emit x3, y3, z3 +>x3 : string | number +>y3 : string | number +>z3 : string | number +>a : (string | number)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js new file mode 100644 index 0000000000000..5734b9bc6f9db --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js @@ -0,0 +1,69 @@ +//// [declarationEmitDestructuringArrayPattern2.ts] +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + +var [x11 = 0, y11 = ""] = [1, "hello"]; +var [a11, b11, c11] = []; + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + +var [x13, y13] = [1, "hello"]; +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; + + +//// [declarationEmitDestructuringArrayPattern2.js] +var _a = [ + 1, + [ + "hello", + [ + true + ] + ] +], x10 = _a[0], _b = _a[1], y10 = _b[0], z10 = _b[1][0]; +var _c = [ + 1, + "hello" +], _d = _c[0], x11 = _d === void 0 ? 0 : _d, _e = _c[1], y11 = _e === void 0 ? "" : _e; +var _f = [], a11 = _f[0], b11 = _f[1], c11 = _f[2]; +var _g = [ + 1, + [ + "hello", + { + x12: 5, + y12: true + } + ] +], a2 = _g[0], _h = _g[1], _j = _h === void 0 ? [ + "abc", + { + x12: 10, + y12: false + } +] : _h, b2 = _j[0], _k = _j[1], x12 = _k.x12, c2 = _k.y12; +var _l = [ + 1, + "hello" +], x13 = _l[0], y13 = _l[1]; +var _m = [ + [ + x13, + y13 + ], + { + x: x13, + y: y13 + } +], a3 = _m[0], b3 = _m[1]; + + +//// [declarationEmitDestructuringArrayPattern2.d.ts] +declare var x10: number, y10: string, z10: boolean; +declare var x11: number, y11: string; +declare var a11: any, b11: any, c11: any; +declare var a2: number, b2: string, x12: number, c2: boolean; +declare var x13: number, y13: string; +declare var a3: (string | number)[], b3: { + x: number; + y: string; +}; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types new file mode 100644 index 0000000000000..2b40a388e3ba9 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -0,0 +1,54 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; +>x10 : number +>y10 : string +>z10 : boolean +>[1, ["hello", [true]]] : [number, [string, [boolean]]] +>["hello", [true]] : [string, [boolean]] +>[true] : [boolean] + +var [x11 = 0, y11 = ""] = [1, "hello"]; +>x11 : number +>y11 : string +>[1, "hello"] : [number, string] + +var [a11, b11, c11] = []; +>a11 : any +>b11 : any +>c11 : any +>[] : undefined[] + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; +>a2 : number +>b2 : string +>x12 : number +>y12 : unknown +>c2 : boolean +>["abc", { x12: 10, y12: false }] : [string, { x12: number; y12: boolean; }] +>{ x12: 10, y12: false } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean +>[1, ["hello", { x12: 5, y12: true }]] : [number, [string, { x12: number; y12: boolean; }]] +>["hello", { x12: 5, y12: true }] : [string, { x12: number; y12: boolean; }] +>{ x12: 5, y12: true } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean + +var [x13, y13] = [1, "hello"]; +>x13 : number +>y13 : string +>[1, "hello"] : [number, string] + +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; +>a3 : (string | number)[] +>b3 : { x: number; y: string; } +>[[x13, y13], { x: x13, y: y13 }] : [(string | number)[], { x: number; y: string; }] +>[x13, y13] : (string | number)[] +>x13 : number +>y13 : string +>{ x: x13, y: y13 } : { x: number; y: string; } +>x : number +>x13 : number +>y : string +>y13 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js new file mode 100644 index 0000000000000..258fa17d7ffbe --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js @@ -0,0 +1,20 @@ +//// [declarationEmitDestructuringArrayPattern3.ts] +module M { + export var [a, b] = [1, 2]; +} + +//// [declarationEmitDestructuringArrayPattern3.js] +var M; +(function (M) { + _a = [ + 1, + 2 + ], M.a = _a[0], M.b = _a[1]; + var _a; +})(M || (M = {})); + + +//// [declarationEmitDestructuringArrayPattern3.d.ts] +declare module M { + var a: number, b: number; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types new file mode 100644 index 0000000000000..4852a7e37fb02 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts === +module M { +>M : typeof M + + export var [a, b] = [1, 2]; +>a : number +>b : number +>[1, 2] : [number, number] +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js new file mode 100644 index 0000000000000..97a8c20b73bc3 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -0,0 +1,63 @@ +//// [declarationEmitDestructuringArrayPattern4.ts] +var [...a5] = [1, 2, 3]; +var [x14, ...a6] = [1, 2, 3]; +var [x15, y15, ...a7] = [1, 2, 3]; +var [x16, y16, z16, ...a8] = [1, 2, 3]; + +var [...a9] = [1, "hello", true]; +var [x17, ...a10] = [1, "hello", true]; +var [x18, y18, ...a12] = [1, "hello", true]; +var [x19, y19, z19, ...a13] = [1, "hello", true]; + +//// [declarationEmitDestructuringArrayPattern4.js] +var _a = [ + 1, + 2, + 3 +], a5 = _a.slice(0); +var _b = [ + 1, + 2, + 3 +], x14 = _b[0], a6 = _b.slice(1); +var _c = [ + 1, + 2, + 3 +], x15 = _c[0], y15 = _c[1], a7 = _c.slice(2); +var _d = [ + 1, + 2, + 3 +], x16 = _d[0], y16 = _d[1], z16 = _d[2], a8 = _d.slice(3); +var _e = [ + 1, + "hello", + true +], a9 = _e.slice(0); +var _f = [ + 1, + "hello", + true +], x17 = _f[0], a10 = _f.slice(1); +var _g = [ + 1, + "hello", + true +], x18 = _g[0], y18 = _g[1], a12 = _g.slice(2); +var _h = [ + 1, + "hello", + true +], x19 = _h[0], y19 = _h[1], z19 = _h[2], a13 = _h.slice(3); + + +//// [declarationEmitDestructuringArrayPattern4.d.ts] +declare var a5: number[]; +declare var x14: number, a6: number[]; +declare var x15: number, y15: number, a7: number[]; +declare var x16: number, y16: number, z16: number, a8: number[]; +declare var a9: (string | number | boolean)[]; +declare var x17: string | number | boolean, a10: (string | number | boolean)[]; +declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[]; +declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types new file mode 100644 index 0000000000000..d6d0fa758d7b2 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts === +var [...a5] = [1, 2, 3]; +>a5 : number[] +>[1, 2, 3] : number[] + +var [x14, ...a6] = [1, 2, 3]; +>x14 : number +>a6 : number[] +>[1, 2, 3] : number[] + +var [x15, y15, ...a7] = [1, 2, 3]; +>x15 : number +>y15 : number +>a7 : number[] +>[1, 2, 3] : number[] + +var [x16, y16, z16, ...a8] = [1, 2, 3]; +>x16 : number +>y16 : number +>z16 : number +>a8 : number[] +>[1, 2, 3] : number[] + +var [...a9] = [1, "hello", true]; +>a9 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x17, ...a10] = [1, "hello", true]; +>x17 : string | number | boolean +>a10 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x18, y18, ...a12] = [1, "hello", true]; +>x18 : string | number | boolean +>y18 : string | number | boolean +>a12 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x19, y19, z19, ...a13] = [1, "hello", true]; +>x19 : string | number | boolean +>y19 : string | number | boolean +>z19 : string | number | boolean +>a13 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js new file mode 100644 index 0000000000000..9b48f418f5ad5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js @@ -0,0 +1,97 @@ +//// [declarationEmitDestructuringObjectLiteralPattern.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern.js] +var _a = { + x: 5, + y: "hello" +}; +var x4 = ({ + x4: 5, + y4: "hello" +}).x4; +var y5 = ({ + x5: 5, + y5: "hello" +}).y5; +var _b = { + x6: 5, + y6: "hello" +}, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ + x7: 5, + y7: "hello" +}).x7; +var b1 = ({ + x8: 5, + y8: "hello" +}).y8; +var _c = { + x9: 5, + y9: "hello" +}, a2 = _c.x9, b2 = _c.y9; +var _d = { + a: 1, + b: { + a: "hello", + b: { + a: true + } + } +}, x11 = _d.a, _e = _d.b, y11 = _e.a, z11 = _e.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { + a4: a4, + b4: b4, + c4: c4 + }; +} +var _f = f15(), a4 = _f.a4, b4 = _f.b4, c4 = _f.c4; +var m; +(function (m) { + _a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4; + var _a; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types new file mode 100644 index 0000000000000..b3c422e495842 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types @@ -0,0 +1,102 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js new file mode 100644 index 0000000000000..889047185e7e0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js @@ -0,0 +1,48 @@ +//// [declarationEmitDestructuringObjectLiteralPattern1.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +//// [declarationEmitDestructuringObjectLiteralPattern1.js] +var _a = { + x: 5, + y: "hello" +}; +var x4 = ({ + x4: 5, + y4: "hello" +}).x4; +var y5 = ({ + x5: 5, + y5: "hello" +}).y5; +var _b = { + x6: 5, + y6: "hello" +}, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ + x7: 5, + y7: "hello" +}).x7; +var b1 = ({ + x8: 5, + y8: "hello" +}).y8; +var _c = { + x9: 5, + y9: "hello" +}, a2 = _c.x9, b2 = _c.y9; + + +//// [declarationEmitDestructuringObjectLiteralPattern1.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types new file mode 100644 index 0000000000000..cc2094c68f4d6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js new file mode 100644 index 0000000000000..140fc03780a05 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js @@ -0,0 +1,55 @@ +//// [declarationEmitDestructuringObjectLiteralPattern2.ts] + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern2.js] +var _a = { + a: 1, + b: { + a: "hello", + b: { + a: true + } + } +}, x11 = _a.a, _b = _a.b, y11 = _b.a, z11 = _b.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { + a4: a4, + b4: b4, + c4: c4 + }; +} +var _c = f15(), a4 = _c.a4, b4 = _c.b4, c4 = _c.c4; +var m; +(function (m) { + _a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4; + var _a; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern2.d.ts] +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types new file mode 100644 index 0000000000000..68394686e31a0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts === + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js new file mode 100644 index 0000000000000..c907add11f776 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -0,0 +1,33 @@ +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.ts] + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +function foo2(...rest: any[]) { + +} + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.js] +function foo() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} +function foo2() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} + + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts] +declare function foo(_0?: [string, number, boolean]): any; +declare function foo2(_0?: { + x: string; + y: number; + z: boolean; +}): any; diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types new file mode 100644 index 0000000000000..1c75466f0c37c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts === + +function foo([x, y, z] ?: [string, number, boolean]); +>foo : ([x, y, z]?: [string, number, boolean]) => any +>x : string +>y : number +>z : boolean + +function foo(...rest: any[]) { +>foo : ([x, y, z]?: [string, number, boolean]) => any +>rest : any[] +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>x : string +>y : number +>z : boolean +>x : string +>y : number +>z : boolean + +function foo2(...rest: any[]) { +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>rest : any[] + +} diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt new file mode 100644 index 0000000000000..83785e86f6585 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern. + + +==== tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts (3 errors) ==== + class C1 { + constructor(public [x, y, z]: string[]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type TupleType1 =[string, number, boolean]; + class C2 { + constructor(public [x, y, z]: TupleType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type ObjType1 = { x: number; y: string; z: boolean } + class C3 { + constructor(public { x, y, z }: ObjType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js new file mode 100644 index 0000000000000..cfe4acc1733d0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js @@ -0,0 +1,61 @@ +//// [declarationEmitDestructuringParameterProperties.ts] +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 =[string, number, boolean]; +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +//// [declarationEmitDestructuringParameterProperties.js] +var C1 = (function () { + function C1(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C1; +})(); +var C2 = (function () { + function C2(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C2; +})(); +var C3 = (function () { + function C3(_a) { + var x = _a.x, y = _a.y, z = _a.z; + this.{ x, y, z } = { x, y, z }; + } + return C3; +})(); + + +//// [declarationEmitDestructuringParameterProperties.d.ts] +declare class C1 { + x: string, y: string, z: string; + constructor(_0: string[]); +} +declare type TupleType1 = [string, number, boolean]; +declare class C2 { + x: string, y: number, z: boolean; + constructor(_0: TupleType1); +} +declare type ObjType1 = { + x: number; + y: string; + z: boolean; +}; +declare class C3 { + x: number, y: string, z: boolean; + constructor(_0: ObjType1); +} diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt new file mode 100644 index 0000000000000..e464b96a8bf77 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts(4,20): error TS4025: Exported variable 'y' has or is using private name 'c'. + + +==== tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts (1 errors) ==== + module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; + ~ +!!! error TS4025: Exported variable 'y' has or is using private name 'c'. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js new file mode 100644 index 0000000000000..c076dca665add --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuringPrivacyError.ts] +module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; +} + +//// [declarationEmitDestructuringPrivacyError.js] +var m; +(function (m) { + var c = (function () { + function c() { + } + return c; + })(); + _a = [ + 10, + new c(), + 30 + ], m.x = _a[0], m.y = _a[1], m.z = _a[2]; + var _a; +})(m || (m = {})); diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt new file mode 100644 index 0000000000000..7b8a70ae8f16c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(1,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(3,16): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + +==== tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts (2 errors) ==== + function foo([x,y,z]?: [string, number, boolean]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } + function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js new file mode 100644 index 0000000000000..284cf107782f0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuringWithOptionalBindingParameters.ts] +function foo([x,y,z]?: [string, number, boolean]) { +} +function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { +} + +//// [declarationEmitDestructuringWithOptionalBindingParameters.js] +function foo(_a) { + var x = _a[0], y = _a[1], z = _a[2]; +} +function foo1(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} + + +//// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts] +declare function foo(_0?: [string, number, boolean]): void; +declare function foo1(_0?: { + x: string; + y: number; + z: boolean; +}): void; diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js new file mode 100644 index 0000000000000..9b580bcd7a4e3 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js @@ -0,0 +1,39 @@ +//// [declarationEmitImportInExportAssignmentModule.ts] + +module m { + export module c { + export class c { + } + } + import x = c; + export var a: typeof x; +} +export = m; + +//// [declarationEmitImportInExportAssignmentModule.js] +var m; +(function (m) { + var c; + (function (c_1) { + var c = (function () { + function c() { + } + return c; + })(); + c_1.c = c; + })(c = m.c || (m.c = {})); + m.a; +})(m || (m = {})); +module.exports = m; + + +//// [declarationEmitImportInExportAssignmentModule.d.ts] +declare module m { + module c { + class c { + } + } + import x = c; + var a: typeof x; +} +export = m; diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types new file mode 100644 index 0000000000000..23176a0abe2e1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts === + +module m { +>m : typeof m + + export module c { +>c : typeof x + + export class c { +>c : c + } + } + import x = c; +>x : typeof x +>c : typeof x + + export var a: typeof x; +>a : typeof x +>x : typeof x +} +export = m; +>m : typeof m + diff --git a/tests/baselines/reference/decoratorOnArrowFunction.errors.txt b/tests/baselines/reference/decoratorOnArrowFunction.errors.txt new file mode 100644 index 0000000000000..14bde1e49bf27 --- /dev/null +++ b/tests/baselines/reference/decoratorOnArrowFunction.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,9): error TS1109: Expression expected. +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts(3,17): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnArrowFunction.ts (3 errors) ==== + declare function dec(target: T): T; + + var F = @dec () => { + ~ +!!! error TS1109: Expression expected. + +!!! error TS1146: Declaration expected. + ~~ +!!! error TS1128: Declaration or statement expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnArrowFunction.js b/tests/baselines/reference/decoratorOnArrowFunction.js new file mode 100644 index 0000000000000..c45f43a9bbe91 --- /dev/null +++ b/tests/baselines/reference/decoratorOnArrowFunction.js @@ -0,0 +1,10 @@ +//// [decoratorOnArrowFunction.ts] +declare function dec(target: T): T; + +var F = @dec () => { +} + +//// [decoratorOnArrowFunction.js] +var F = ; +{ +} diff --git a/tests/baselines/reference/decoratorOnClass1.js b/tests/baselines/reference/decoratorOnClass1.js new file mode 100644 index 0000000000000..24be2517469fc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass1.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass1.ts] +declare function dec(target: T): T; + +@dec +class C { +} + +//// [decoratorOnClass1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass1.types b/tests/baselines/reference/decoratorOnClass1.types new file mode 100644 index 0000000000000..e8b25519149dc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass1.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass1.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass10.js b/tests/baselines/reference/decoratorOnClass10.js new file mode 100644 index 0000000000000..6a1b8b7c3546d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass10.js @@ -0,0 +1,25 @@ +//// [decoratorOnClass10.ts] +declare function dec(target: T): T; + +@dec +export class C { +} + +//// [decoratorOnClass10.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +export let C = class { +}; +Object.defineProperty(C, "name", { value: "C", configurable: true }); +C = __decorate([dec], C); diff --git a/tests/baselines/reference/decoratorOnClass10.types b/tests/baselines/reference/decoratorOnClass10.types new file mode 100644 index 0000000000000..b9d605ead9e2a --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass10.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass10.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +export class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass11.js b/tests/baselines/reference/decoratorOnClass11.js new file mode 100644 index 0000000000000..689f7cb3888ea --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass11.js @@ -0,0 +1,25 @@ +//// [decoratorOnClass11.ts] +declare function dec(target: T): T; + +@dec +export default class { +} + +//// [decoratorOnClass11.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +let default_1 = class { +}; +default_1 = __decorate([dec], default_1); +export default default_1; diff --git a/tests/baselines/reference/decoratorOnClass11.types b/tests/baselines/reference/decoratorOnClass11.types new file mode 100644 index 0000000000000..c415f8e96b9d5 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass11.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass11.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +export default class { +} diff --git a/tests/baselines/reference/decoratorOnClass12.js b/tests/baselines/reference/decoratorOnClass12.js new file mode 100644 index 0000000000000..52fbfa3fbeef5 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass12.js @@ -0,0 +1,26 @@ +//// [decoratorOnClass12.ts] +declare function dec(target: T): T; + +@dec +export default class C { +} + +//// [decoratorOnClass12.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +let C = class { +}; +Object.defineProperty(C, "name", { value: "C", configurable: true }); +C = __decorate([dec], C); +export default C; diff --git a/tests/baselines/reference/decoratorOnClass12.types b/tests/baselines/reference/decoratorOnClass12.types new file mode 100644 index 0000000000000..76112e041f217 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass12.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass12.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +export default class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass13.js b/tests/baselines/reference/decoratorOnClass13.js new file mode 100644 index 0000000000000..b89f909b47263 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass13.js @@ -0,0 +1,31 @@ +//// [decoratorOnClass13.ts] +declare function dec(target: T): T; + +module Outer { + @dec + export class C { + } +} + +//// [decoratorOnClass13.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var Outer; +(function (Outer) { + let C = class { + }; + Object.defineProperty(C, "name", { value: "C", configurable: true }); + C = __decorate([dec], C); + Outer.C = C; +})(Outer || (Outer = {})); diff --git a/tests/baselines/reference/decoratorOnClass13.types b/tests/baselines/reference/decoratorOnClass13.types new file mode 100644 index 0000000000000..c2c8f38ba10b8 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass13.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass13.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +module Outer { +>Outer : typeof Outer + + @dec +>dec : unknown + + export class C { +>C : C + } +} diff --git a/tests/baselines/reference/decoratorOnClass2.js b/tests/baselines/reference/decoratorOnClass2.js new file mode 100644 index 0000000000000..92741819e9449 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass2.js @@ -0,0 +1,28 @@ +//// [decoratorOnClass2.ts] +declare function dec(target: T): T; + +@dec +export class C { +} + +//// [decoratorOnClass2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec], C); + return C; +})(); +exports.C = C; diff --git a/tests/baselines/reference/decoratorOnClass2.types b/tests/baselines/reference/decoratorOnClass2.types new file mode 100644 index 0000000000000..e696f699068de --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass2.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass2.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +export class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass3.errors.txt b/tests/baselines/reference/decoratorOnClass3.errors.txt new file mode 100644 index 0000000000000..3453a58fc9d8d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass3.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/decorators/class/decoratorOnClass3.ts(3,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/decoratorOnClass3.ts (1 errors) ==== + declare function dec(target: T): T; + + export + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + @dec + class C { + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClass3.js b/tests/baselines/reference/decoratorOnClass3.js new file mode 100644 index 0000000000000..766acc42072ed --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass3.js @@ -0,0 +1,28 @@ +//// [decoratorOnClass3.ts] +declare function dec(target: T): T; + +export +@dec +class C { +} + +//// [decoratorOnClass3.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass4.js b/tests/baselines/reference/decoratorOnClass4.js new file mode 100644 index 0000000000000..95bde549379e8 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass4.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass4.ts] +declare function dec(): (target: T) => T; + +@dec() +class C { +} + +//// [decoratorOnClass4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec()], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass4.types b/tests/baselines/reference/decoratorOnClass4.types new file mode 100644 index 0000000000000..8875de5d992c7 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass4.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass4.ts === +declare function dec(): (target: T) => T; +>dec : () => (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec() +>dec() : (target: T) => T +>dec : () => (target: T) => T + +class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass5.js b/tests/baselines/reference/decoratorOnClass5.js new file mode 100644 index 0000000000000..a93d625f49136 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass5.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass5.ts] +declare function dec(): (target: T) => T; + +@dec() +class C { +} + +//// [decoratorOnClass5.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec()], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass5.types b/tests/baselines/reference/decoratorOnClass5.types new file mode 100644 index 0000000000000..afd12d42d3719 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass5.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass5.ts === +declare function dec(): (target: T) => T; +>dec : () => (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec() +>dec() : (target: T) => T +>dec : () => (target: T) => T + +class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClass8.errors.txt b/tests/baselines/reference/decoratorOnClass8.errors.txt new file mode 100644 index 0000000000000..0a9fbf2956c11 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass8.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/decoratorOnClass8.ts(3,1): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'. + + +==== tests/cases/conformance/decorators/class/decoratorOnClass8.ts (1 errors) ==== + declare function dec(): (target: Function, paramIndex: number) => void; + + @dec() + ~~~~~~ +!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: typeof C) => void | typeof C'. + class C { + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClass8.js b/tests/baselines/reference/decoratorOnClass8.js new file mode 100644 index 0000000000000..0e782d45e1158 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass8.js @@ -0,0 +1,27 @@ +//// [decoratorOnClass8.ts] +declare function dec(): (target: Function, paramIndex: number) => void; + +@dec() +class C { +} + +//// [decoratorOnClass8.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C = __decorate([dec()], C); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClass9.js b/tests/baselines/reference/decoratorOnClass9.js new file mode 100644 index 0000000000000..581f440f2e860 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass9.js @@ -0,0 +1,25 @@ +//// [decoratorOnClass9.ts] +declare function dec(target: T): T; + +@dec +class C { +} + +//// [decoratorOnClass9.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +let C = class { +}; +Object.defineProperty(C, "name", { value: "C", configurable: true }); +C = __decorate([dec], C); diff --git a/tests/baselines/reference/decoratorOnClass9.types b/tests/baselines/reference/decoratorOnClass9.types new file mode 100644 index 0000000000000..016009e7c8997 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClass9.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/decoratorOnClass9.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +@dec +>dec : unknown + +class C { +>C : C +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor1.js b/tests/baselines/reference/decoratorOnClassAccessor1.js new file mode 100644 index 0000000000000..d78e776cb96bc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor1.js @@ -0,0 +1,34 @@ +//// [decoratorOnClassAccessor1.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec get accessor() { return 1; } +} + +//// [decoratorOnClassAccessor1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + get: function () { + return 1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor1.types b/tests/baselines/reference/decoratorOnClassAccessor1.types new file mode 100644 index 0000000000000..8bc4f661abcfe --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor1.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor1.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec get accessor() { return 1; } +>dec : unknown +>accessor : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor2.js b/tests/baselines/reference/decoratorOnClassAccessor2.js new file mode 100644 index 0000000000000..f1bfce9ea6dce --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor2.js @@ -0,0 +1,34 @@ +//// [decoratorOnClassAccessor2.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public get accessor() { return 1; } +} + +//// [decoratorOnClassAccessor2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + get: function () { + return 1; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor2.types b/tests/baselines/reference/decoratorOnClassAccessor2.types new file mode 100644 index 0000000000000..1278486593f43 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor2.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor2.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public get accessor() { return 1; } +>dec : unknown +>accessor : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt new file mode 100644 index 0000000000000..b75b7e0d8b63a --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor3.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,17): error TS2304: Cannot find name 'get'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(4,32): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts (9 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec get accessor() { return 1; } + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'get'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.js b/tests/baselines/reference/decoratorOnClassAccessor3.js new file mode 100644 index 0000000000000..d37656cb0e740 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor3.js @@ -0,0 +1,19 @@ +//// [decoratorOnClassAccessor3.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + public @dec get accessor() { return 1; } +} + +//// [decoratorOnClassAccessor3.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +get; +accessor(); +{ + return 1; +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor4.js b/tests/baselines/reference/decoratorOnClassAccessor4.js new file mode 100644 index 0000000000000..77dbc569e5aaa --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor4.js @@ -0,0 +1,33 @@ +//// [decoratorOnClassAccessor4.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec set accessor(value: number) { } +} + +//// [decoratorOnClassAccessor4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + set: function (value) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor4.types b/tests/baselines/reference/decoratorOnClassAccessor4.types new file mode 100644 index 0000000000000..127719117e217 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor4.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor4.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec set accessor(value: number) { } +>dec : unknown +>accessor : number +>value : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor5.js b/tests/baselines/reference/decoratorOnClassAccessor5.js new file mode 100644 index 0000000000000..bfd6518c59bd6 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor5.js @@ -0,0 +1,33 @@ +//// [decoratorOnClassAccessor5.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public set accessor(value: number) { } +} + +//// [decoratorOnClassAccessor5.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + set: function (value) { + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "accessor", __decorate([dec], C.prototype, "accessor", Object.getOwnPropertyDescriptor(C.prototype, "accessor"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessor5.types b/tests/baselines/reference/decoratorOnClassAccessor5.types new file mode 100644 index 0000000000000..63bb9159dd05d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor5.types @@ -0,0 +1,20 @@ +=== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor5.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public set accessor(value: number) { } +>dec : unknown +>accessor : number +>value : number +} diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt new file mode 100644 index 0000000000000..ec22ae0b3e139 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor6.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,17): error TS2304: Cannot find name 'set'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,21): error TS2304: Cannot find name 'accessor'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,30): error TS2304: Cannot find name 'value'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,35): error TS1005: ',' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,37): error TS2304: Cannot find name 'number'. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(4,45): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts (12 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec set accessor(value: number) { } + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~ +!!! error TS2304: Cannot find name 'set'. + ~~~~~~~~ +!!! error TS1005: ';' expected. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'accessor'. + ~~~~~ +!!! error TS2304: Cannot find name 'value'. + ~ +!!! error TS1005: ',' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'number'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.js b/tests/baselines/reference/decoratorOnClassAccessor6.js new file mode 100644 index 0000000000000..7335374b3c915 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessor6.js @@ -0,0 +1,18 @@ +//// [decoratorOnClassAccessor6.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + public @dec set accessor(value: number) { } +} + +//// [decoratorOnClassAccessor6.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +set; +accessor(value, number); +{ +} diff --git a/tests/baselines/reference/decoratorOnClassAccessorParameter1.js b/tests/baselines/reference/decoratorOnClassAccessorParameter1.js new file mode 100644 index 0000000000000..080acba4ebfa1 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessorParameter1.js @@ -0,0 +1,33 @@ +//// [decoratorOnClassAccessorParameter1.ts] +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + +class C { + set accessor(@dec p: number) {} +} + +//// [decoratorOnClassAccessorParameter1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "accessor", { + set: function (p) { + }, + enumerable: true, + configurable: true + }); + __decorate([dec], C.prototype, "accessor", 0); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassAccessorParameter1.types b/tests/baselines/reference/decoratorOnClassAccessorParameter1.types new file mode 100644 index 0000000000000..94fc1bb3ef810 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassAccessorParameter1.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/decorators/class/accessor/parameter/decoratorOnClassAccessorParameter1.ts === +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void +>target : Function +>Function : Function +>propertyKey : string | symbol +>parameterIndex : number + +class C { +>C : C + + set accessor(@dec p: number) {} +>accessor : number +>dec : unknown +>p : number +} diff --git a/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt b/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt new file mode 100644 index 0000000000000..14a164eccb429 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructor1.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts(4,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts (1 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + @dec constructor() {} + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassConstructor1.js b/tests/baselines/reference/decoratorOnClassConstructor1.js new file mode 100644 index 0000000000000..cfe9afaa3a1f5 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructor1.js @@ -0,0 +1,13 @@ +//// [decoratorOnClassConstructor1.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec constructor() {} +} + +//// [decoratorOnClassConstructor1.js] +var C = (function () { + function C() { + } + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter1.js b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js new file mode 100644 index 0000000000000..0c86a1ccf7aa7 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassConstructorParameter1.ts] +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + +class C { + constructor(@dec p: number) {} +} + +//// [decoratorOnClassConstructorParameter1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C(p) { + } + __decorate([dec], C, void 0, 0); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter1.types b/tests/baselines/reference/decoratorOnClassConstructorParameter1.types new file mode 100644 index 0000000000000..d5ce51269bc3d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter1.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter1.ts === +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void +>target : Function +>Function : Function +>propertyKey : string | symbol +>parameterIndex : number + +class C { +>C : C + + constructor(@dec p: number) {} +>dec : unknown +>p : number +} diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt new file mode 100644 index 0000000000000..5969cfca06973 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts(4,24): error TS1005: ',' expected. + + +==== tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts (1 errors) ==== + declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + + class C { + constructor(public @dec p: number) {} + ~ +!!! error TS1005: ',' expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js new file mode 100644 index 0000000000000..07dc7cae0750a --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassConstructorParameter4.ts] +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + +class C { + constructor(public @dec p: number) {} +} + +//// [decoratorOnClassConstructorParameter4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C(public, p) { + } + __decorate([dec], C, void 0, 1); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod1.js b/tests/baselines/reference/decoratorOnClassMethod1.js new file mode 100644 index 0000000000000..be9c00290fbb9 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod1.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod1.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec method() {} +} + +//// [decoratorOnClassMethod1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod1.types b/tests/baselines/reference/decoratorOnClassMethod1.types new file mode 100644 index 0000000000000..0ca111a9b4d9e --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod1.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod1.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec method() {} +>dec : unknown +>method : () => void +} diff --git a/tests/baselines/reference/decoratorOnClassMethod10.errors.txt b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt new file mode 100644 index 0000000000000..cd331473b7cda --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod10.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts(4,5): error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<() => void>) => void | TypedPropertyDescriptor<() => void>'. + Types of parameters 'paramIndex' and 'propertyKey' are incompatible. + Type 'number' is not assignable to type 'string | symbol'. + Type 'number' is not assignable to type 'symbol'. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts (1 errors) ==== + declare function dec(target: Function, paramIndex: number): void; + + class C { + @dec method() {} + ~~~~ +!!! error TS2322: Type '(target: Function, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<() => void>) => void | TypedPropertyDescriptor<() => void>'. +!!! error TS2322: Types of parameters 'paramIndex' and 'propertyKey' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string | symbol'. +!!! error TS2322: Type 'number' is not assignable to type 'symbol'. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod10.js b/tests/baselines/reference/decoratorOnClassMethod10.js new file mode 100644 index 0000000000000..3dd38f806bdc6 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod10.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod10.ts] +declare function dec(target: Function, paramIndex: number): void; + +class C { + @dec method() {} +} + +//// [decoratorOnClassMethod10.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod2.js b/tests/baselines/reference/decoratorOnClassMethod2.js new file mode 100644 index 0000000000000..b7df7b9ba9c4e --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod2.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod2.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public method() {} +} + +//// [decoratorOnClassMethod2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod2.types b/tests/baselines/reference/decoratorOnClassMethod2.types new file mode 100644 index 0000000000000..eb46c00b8c579 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod2.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod2.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public method() {} +>dec : unknown +>method : () => void +} diff --git a/tests/baselines/reference/decoratorOnClassMethod3.errors.txt b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt new file mode 100644 index 0000000000000..b2173dedf9ef9 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod3.errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,17): error TS2304: Cannot find name 'method'. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(4,26): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts (7 errors) ==== + declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + + class C { + public @dec method() {} + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'method'. + ~ +!!! error TS1005: ';' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassMethod3.js b/tests/baselines/reference/decoratorOnClassMethod3.js new file mode 100644 index 0000000000000..f2a385a30e5ce --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod3.js @@ -0,0 +1,17 @@ +//// [decoratorOnClassMethod3.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + public @dec method() {} +} + +//// [decoratorOnClassMethod3.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +method(); +{ +} diff --git a/tests/baselines/reference/decoratorOnClassMethod4.js b/tests/baselines/reference/decoratorOnClassMethod4.js new file mode 100644 index 0000000000000..7021e5af32836 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod4.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod4.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec ["method"]() {} +} + +//// [decoratorOnClassMethod4.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod4.types b/tests/baselines/reference/decoratorOnClassMethod4.types new file mode 100644 index 0000000000000..5d89a5ac7dd9d --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod4.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod4.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec ["method"]() {} +>dec : unknown +} diff --git a/tests/baselines/reference/decoratorOnClassMethod5.js b/tests/baselines/reference/decoratorOnClassMethod5.js new file mode 100644 index 0000000000000..3bde0968eab7b --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod5.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod5.ts] +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec() ["method"]() {} +} + +//// [decoratorOnClassMethod5.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec()], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod5.types b/tests/baselines/reference/decoratorOnClassMethod5.types new file mode 100644 index 0000000000000..ed57518087bc4 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod5.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod5.ts === +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec() ["method"]() {} +>dec() : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +} diff --git a/tests/baselines/reference/decoratorOnClassMethod6.js b/tests/baselines/reference/decoratorOnClassMethod6.js new file mode 100644 index 0000000000000..126dc47ad2f7b --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod6.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod6.ts] +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; + +class C { + @dec ["method"]() {} +} + +//// [decoratorOnClassMethod6.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod6.types b/tests/baselines/reference/decoratorOnClassMethod6.types new file mode 100644 index 0000000000000..ffaff625bb615 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod6.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts === +declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; +>dec : () => (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec ["method"]() {} +>dec : unknown +} diff --git a/tests/baselines/reference/decoratorOnClassMethod7.js b/tests/baselines/reference/decoratorOnClassMethod7.js new file mode 100644 index 0000000000000..34fbdb53ca5dd --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod7.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassMethod7.ts] +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; + +class C { + @dec public ["method"]() {} +} + +//// [decoratorOnClassMethod7.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +class C { + [_a = "method"]() { + } +} +Object.defineProperty(C.prototype, _a, __decorate([dec], C.prototype, _a, Object.getOwnPropertyDescriptor(C.prototype, _a))); +var _a; diff --git a/tests/baselines/reference/decoratorOnClassMethod7.types b/tests/baselines/reference/decoratorOnClassMethod7.types new file mode 100644 index 0000000000000..0fd1c2086748f --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod7.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod7.ts === +declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; +>dec : (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor +>T : T +>target : any +>propertyKey : string +>descriptor : TypedPropertyDescriptor +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T +>TypedPropertyDescriptor : TypedPropertyDescriptor +>T : T + +class C { +>C : C + + @dec public ["method"]() {} +>dec : unknown +} diff --git a/tests/baselines/reference/decoratorOnClassMethod8.js b/tests/baselines/reference/decoratorOnClassMethod8.js new file mode 100644 index 0000000000000..629ff4e253bba --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod8.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethod8.ts] +declare function dec(target: T): T; + +class C { + @dec method() {} +} + +//// [decoratorOnClassMethod8.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + Object.defineProperty(C.prototype, "method", __decorate([dec], C.prototype, "method", Object.getOwnPropertyDescriptor(C.prototype, "method"))); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethod8.types b/tests/baselines/reference/decoratorOnClassMethod8.types new file mode 100644 index 0000000000000..de5fce22ba69b --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethod8.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts === +declare function dec(target: T): T; +>dec : (target: T) => T +>T : T +>target : T +>T : T +>T : T + +class C { +>C : C + + @dec method() {} +>dec : unknown +>method : () => void +} diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.js b/tests/baselines/reference/decoratorOnClassMethodParameter1.js new file mode 100644 index 0000000000000..1dcb057e53038 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.js @@ -0,0 +1,29 @@ +//// [decoratorOnClassMethodParameter1.ts] +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; + +class C { + method(@dec p: number) {} +} + +//// [decoratorOnClassMethodParameter1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + C.prototype.method = function (p) { + }; + __decorate([dec], C.prototype, "method", 0); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.types b/tests/baselines/reference/decoratorOnClassMethodParameter1.types new file mode 100644 index 0000000000000..cf7bfd352bfee --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts === +declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; +>dec : (target: Function, propertyKey: string | symbol, parameterIndex: number) => void +>target : Function +>Function : Function +>propertyKey : string | symbol +>parameterIndex : number + +class C { +>C : C + + method(@dec p: number) {} +>method : (p: number) => void +>dec : unknown +>p : number +} diff --git a/tests/baselines/reference/decoratorOnClassProperty1.js b/tests/baselines/reference/decoratorOnClassProperty1.js new file mode 100644 index 0000000000000..efc6a2c04dbf5 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty1.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty1.ts] +declare function dec(target: any, propertyKey: string): void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty1.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty1.types b/tests/baselines/reference/decoratorOnClassProperty1.types new file mode 100644 index 0000000000000..651085c7ac49b --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty1.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty1.ts === +declare function dec(target: any, propertyKey: string): void; +>dec : (target: any, propertyKey: string) => void +>target : any +>propertyKey : string + +class C { +>C : C + + @dec prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty10.js b/tests/baselines/reference/decoratorOnClassProperty10.js new file mode 100644 index 0000000000000..d55eb71e3c637 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty10.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty10.ts] +declare function dec(): (target: any, propertyKey: string) => void; + +class C { + @dec() prop; +} + +//// [decoratorOnClassProperty10.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec()], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty10.types b/tests/baselines/reference/decoratorOnClassProperty10.types new file mode 100644 index 0000000000000..d0aa05589ff13 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty10.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty10.ts === +declare function dec(): (target: any, propertyKey: string) => void; +>dec : () => (target: any, propertyKey: string) => void +>T : T +>target : any +>propertyKey : string + +class C { +>C : C + + @dec() prop; +>dec() : (target: any, propertyKey: string) => void +>dec : () => (target: any, propertyKey: string) => void +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty11.js b/tests/baselines/reference/decoratorOnClassProperty11.js new file mode 100644 index 0000000000000..63e5f8d02e94c --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty11.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty11.ts] +declare function dec(): (target: any, propertyKey: string) => void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty11.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty11.types b/tests/baselines/reference/decoratorOnClassProperty11.types new file mode 100644 index 0000000000000..5377e53c31c4a --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty11.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts === +declare function dec(): (target: any, propertyKey: string) => void; +>dec : () => (target: any, propertyKey: string) => void +>T : T +>target : any +>propertyKey : string + +class C { +>C : C + + @dec prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty2.js b/tests/baselines/reference/decoratorOnClassProperty2.js new file mode 100644 index 0000000000000..d52baa7920273 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty2.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty2.ts] +declare function dec(target: any, propertyKey: string): void; + +class C { + @dec public prop; +} + +//// [decoratorOnClassProperty2.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty2.types b/tests/baselines/reference/decoratorOnClassProperty2.types new file mode 100644 index 0000000000000..2d5c9fe07d770 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty2.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty2.ts === +declare function dec(target: any, propertyKey: string): void; +>dec : (target: any, propertyKey: string) => void +>target : any +>propertyKey : string + +class C { +>C : C + + @dec public prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty3.errors.txt b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt new file mode 100644 index 0000000000000..29438bd67a9e5 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty3.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,5): error TS2304: Cannot find name 'public'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,12): error TS1005: ';' expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,16): error TS1146: Declaration expected. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(4,17): error TS2304: Cannot find name 'prop'. +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts (6 errors) ==== + declare function dec(target: any, propertyKey: string): void; + + class C { + public @dec prop; + ~~~~~~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + +!!! error TS1146: Declaration expected. + ~~~~ +!!! error TS2304: Cannot find name 'prop'. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty3.js b/tests/baselines/reference/decoratorOnClassProperty3.js new file mode 100644 index 0000000000000..6c9945677ca51 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty3.js @@ -0,0 +1,15 @@ +//// [decoratorOnClassProperty3.ts] +declare function dec(target: any, propertyKey: string): void; + +class C { + public @dec prop; +} + +//// [decoratorOnClassProperty3.js] +var C = (function () { + function C() { + } + return C; +})(); +public; +prop; diff --git a/tests/baselines/reference/decoratorOnClassProperty6.js b/tests/baselines/reference/decoratorOnClassProperty6.js new file mode 100644 index 0000000000000..7f087156bc7a1 --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty6.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty6.ts] +declare function dec(target: Function): void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty6.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnClassProperty6.types b/tests/baselines/reference/decoratorOnClassProperty6.types new file mode 100644 index 0000000000000..77367c0893b5e --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty6.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts === +declare function dec(target: Function): void; +>dec : (target: Function) => void +>target : Function +>Function : Function + +class C { +>C : C + + @dec prop; +>dec : unknown +>prop : any +} diff --git a/tests/baselines/reference/decoratorOnClassProperty7.errors.txt b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt new file mode 100644 index 0000000000000..8b93d0ab38ebc --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty7.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts(4,5): error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'. + + +==== tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts (1 errors) ==== + declare function dec(target: Function, propertyKey: string | symbol, paramIndex: number): void; + + class C { + @dec prop; + ~~~~ +!!! error TS2322: Type '(target: Function, propertyKey: string | symbol, paramIndex: number) => void' is not assignable to type '(target: Object, propertyKey: string | symbol) => void'. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnClassProperty7.js b/tests/baselines/reference/decoratorOnClassProperty7.js new file mode 100644 index 0000000000000..ba2c8383a2cce --- /dev/null +++ b/tests/baselines/reference/decoratorOnClassProperty7.js @@ -0,0 +1,27 @@ +//// [decoratorOnClassProperty7.ts] +declare function dec(target: Function, propertyKey: string | symbol, paramIndex: number): void; + +class C { + @dec prop; +} + +//// [decoratorOnClassProperty7.js] +var __decorate = this.__decorate || function (decorators, target, key, value) { + var kind = typeof (arguments.length == 2 ? value = target : value); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + switch (kind) { + case "function": value = decorator(value) || value; break; + case "number": decorator(target, key, value); break; + case "undefined": decorator(target, key); break; + case "object": value = decorator(target, key, value) || value; break; + } + } + return value; +}; +var C = (function () { + function C() { + } + __decorate([dec], C.prototype, "prop"); + return C; +})(); diff --git a/tests/baselines/reference/decoratorOnEnum.errors.txt b/tests/baselines/reference/decoratorOnEnum.errors.txt new file mode 100644 index 0000000000000..21a6d39aab501 --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts(4,6): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnEnum.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + enum E { + ~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnEnum.js b/tests/baselines/reference/decoratorOnEnum.js new file mode 100644 index 0000000000000..6a7fe81480bbf --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum.js @@ -0,0 +1,11 @@ +//// [decoratorOnEnum.ts] +declare function dec(target: T): T; + +@dec +enum E { +} + +//// [decoratorOnEnum.js] +var E; +(function (E) { +})(E || (E = {})); diff --git a/tests/baselines/reference/decoratorOnEnum2.errors.txt b/tests/baselines/reference/decoratorOnEnum2.errors.txt new file mode 100644 index 0000000000000..3a643bc861ada --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum2.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,5): error TS1132: Enum member expected. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,9): error TS1146: Declaration expected. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(4,10): error TS2304: Cannot find name 'A'. +tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts(5,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnEnum2.ts (4 errors) ==== + declare function dec(target: T): T; + + enum E { + @dec A + ~ +!!! error TS1132: Enum member expected. + +!!! error TS1146: Declaration expected. + ~ +!!! error TS2304: Cannot find name 'A'. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnEnum2.js b/tests/baselines/reference/decoratorOnEnum2.js new file mode 100644 index 0000000000000..a99e908bddbdc --- /dev/null +++ b/tests/baselines/reference/decoratorOnEnum2.js @@ -0,0 +1,12 @@ +//// [decoratorOnEnum2.ts] +declare function dec(target: T): T; + +enum E { + @dec A +} + +//// [decoratorOnEnum2.js] +var E; +(function (E) { +})(E || (E = {})); +A; diff --git a/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt b/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt new file mode 100644 index 0000000000000..bda00f1a85f82 --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionDeclaration.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts(4,10): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnFunctionDeclaration.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + function F() { + ~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnFunctionDeclaration.js b/tests/baselines/reference/decoratorOnFunctionDeclaration.js new file mode 100644 index 0000000000000..59d36731548c8 --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionDeclaration.js @@ -0,0 +1,10 @@ +//// [decoratorOnFunctionDeclaration.ts] +declare function dec(target: T): T; + +@dec +function F() { +} + +//// [decoratorOnFunctionDeclaration.js] +function F() { +} diff --git a/tests/baselines/reference/decoratorOnFunctionExpression.errors.txt b/tests/baselines/reference/decoratorOnFunctionExpression.errors.txt new file mode 100644 index 0000000000000..95103a7c68735 --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionExpression.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/decorators/invalid/decoratorOnFunctionExpression.ts(3,9): error TS1109: Expression expected. +tests/cases/conformance/decorators/invalid/decoratorOnFunctionExpression.ts(3,23): error TS1003: Identifier expected. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnFunctionExpression.ts (2 errors) ==== + declare function dec(target: T): T; + + var F = @dec function () { + ~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1003: Identifier expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnFunctionExpression.js b/tests/baselines/reference/decoratorOnFunctionExpression.js new file mode 100644 index 0000000000000..9a15aa699a14f --- /dev/null +++ b/tests/baselines/reference/decoratorOnFunctionExpression.js @@ -0,0 +1,10 @@ +//// [decoratorOnFunctionExpression.ts] +declare function dec(target: T): T; + +var F = @dec function () { +} + +//// [decoratorOnFunctionExpression.js] +var F = ; +function () { +} diff --git a/tests/baselines/reference/decoratorOnImportEquals1.errors.txt b/tests/baselines/reference/decoratorOnImportEquals1.errors.txt new file mode 100644 index 0000000000000..a09a0b014278d --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals1.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts(8,5): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals1.ts (1 errors) ==== + declare function dec(target: T): T; + + module M1 { + export var X: number; + } + + module M2 { + @dec + ~~~~ + import X = M1.X; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnImportEquals1.js b/tests/baselines/reference/decoratorOnImportEquals1.js new file mode 100644 index 0000000000000..08ad26af2b264 --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals1.js @@ -0,0 +1,17 @@ +//// [decoratorOnImportEquals1.ts] +declare function dec(target: T): T; + +module M1 { + export var X: number; +} + +module M2 { + @dec + import X = M1.X; +} + +//// [decoratorOnImportEquals1.js] +var M1; +(function (M1) { + M1.X; +})(M1 || (M1 = {})); diff --git a/tests/baselines/reference/decoratorOnImportEquals2.errors.txt b/tests/baselines/reference/decoratorOnImportEquals2.errors.txt new file mode 100644 index 0000000000000..5701afe569be2 --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals2.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts(1,1): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_1.ts (1 errors) ==== + @dec + ~~~~ + import lib = require('./decoratorOnImportEquals2_0'); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. + + declare function dec(target: T): T; +==== tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2_0.ts (0 errors) ==== + export var X; + \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnImportEquals2.js b/tests/baselines/reference/decoratorOnImportEquals2.js new file mode 100644 index 0000000000000..c05d17590267c --- /dev/null +++ b/tests/baselines/reference/decoratorOnImportEquals2.js @@ -0,0 +1,14 @@ +//// [tests/cases/conformance/decorators/invalid/decoratorOnImportEquals2.ts] //// + +//// [decoratorOnImportEquals2_0.ts] +export var X; + +//// [decoratorOnImportEquals2_1.ts] +@dec +import lib = require('./decoratorOnImportEquals2_0'); + +declare function dec(target: T): T; + +//// [decoratorOnImportEquals2_0.js] +exports.X; +//// [decoratorOnImportEquals2_1.js] diff --git a/tests/baselines/reference/decoratorOnInterface.errors.txt b/tests/baselines/reference/decoratorOnInterface.errors.txt new file mode 100644 index 0000000000000..055b43fa877a4 --- /dev/null +++ b/tests/baselines/reference/decoratorOnInterface.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts(4,11): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnInterface.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + interface I { + ~ +!!! error TS1206: Decorators are not valid here. + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnInterface.js b/tests/baselines/reference/decoratorOnInterface.js new file mode 100644 index 0000000000000..b775b4348e9fb --- /dev/null +++ b/tests/baselines/reference/decoratorOnInterface.js @@ -0,0 +1,8 @@ +//// [decoratorOnInterface.ts] +declare function dec(target: T): T; + +@dec +interface I { +} + +//// [decoratorOnInterface.js] diff --git a/tests/baselines/reference/decoratorOnInternalModule.errors.txt b/tests/baselines/reference/decoratorOnInternalModule.errors.txt new file mode 100644 index 0000000000000..2fd92dfb2500a --- /dev/null +++ b/tests/baselines/reference/decoratorOnInternalModule.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts(4,8): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnInternalModule.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + module M { + ~ +!!! error TS1206: Decorators are not valid here. + + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnInternalModule.js b/tests/baselines/reference/decoratorOnInternalModule.js new file mode 100644 index 0000000000000..1274d9983e5d3 --- /dev/null +++ b/tests/baselines/reference/decoratorOnInternalModule.js @@ -0,0 +1,9 @@ +//// [decoratorOnInternalModule.ts] +declare function dec(target: T): T; + +@dec +module M { + +} + +//// [decoratorOnInternalModule.js] diff --git a/tests/baselines/reference/decoratorOnTypeAlias.errors.txt b/tests/baselines/reference/decoratorOnTypeAlias.errors.txt new file mode 100644 index 0000000000000..0d3109fe463f2 --- /dev/null +++ b/tests/baselines/reference/decoratorOnTypeAlias.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts(3,1): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnTypeAlias.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + ~~~~ + type T = number; + ~~~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnTypeAlias.js b/tests/baselines/reference/decoratorOnTypeAlias.js new file mode 100644 index 0000000000000..c43928fe80b1f --- /dev/null +++ b/tests/baselines/reference/decoratorOnTypeAlias.js @@ -0,0 +1,7 @@ +//// [decoratorOnTypeAlias.ts] +declare function dec(target: T): T; + +@dec +type T = number; + +//// [decoratorOnTypeAlias.js] diff --git a/tests/baselines/reference/decoratorOnVar.errors.txt b/tests/baselines/reference/decoratorOnVar.errors.txt new file mode 100644 index 0000000000000..bd87357edad6a --- /dev/null +++ b/tests/baselines/reference/decoratorOnVar.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/decorators/invalid/decoratorOnVar.ts(3,1): error TS1206: Decorators are not valid here. + + +==== tests/cases/conformance/decorators/invalid/decoratorOnVar.ts (1 errors) ==== + declare function dec(target: T): T; + + @dec + ~~~~ + var x: number; + ~~~~~~~~~~~~~~ +!!! error TS1206: Decorators are not valid here. \ No newline at end of file diff --git a/tests/baselines/reference/decoratorOnVar.js b/tests/baselines/reference/decoratorOnVar.js new file mode 100644 index 0000000000000..92cd7f432bc5a --- /dev/null +++ b/tests/baselines/reference/decoratorOnVar.js @@ -0,0 +1,8 @@ +//// [decoratorOnVar.ts] +declare function dec(target: T): T; + +@dec +var x: number; + +//// [decoratorOnVar.js] +var x; diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.js b/tests/baselines/reference/decrementOperatorWithEnumType.js index 15247ea4225b6..27cb376cc05d9 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.js +++ b/tests/baselines/reference/decrementOperatorWithEnumType.js @@ -22,8 +22,8 @@ var ENUM1; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = --0 /* "A" */; -var ResultIsNumber2 = 0 /* A */--; +var ResultIsNumber1 = --ENUM1["A"]; +var ResultIsNumber2 = ENUM1.A--; // miss assignment operator ---0 /* "A" */; +--ENUM1["A"]; ENUM1[A]--; diff --git a/tests/baselines/reference/deleteOperatorWithEnumType.js b/tests/baselines/reference/deleteOperatorWithEnumType.js index b87ab8298a725..0a17b300d3d80 100644 --- a/tests/baselines/reference/deleteOperatorWithEnumType.js +++ b/tests/baselines/reference/deleteOperatorWithEnumType.js @@ -39,13 +39,13 @@ var ENUM1; var ResultIsBoolean1 = delete ENUM; var ResultIsBoolean2 = delete ENUM1; // enum type expressions -var ResultIsBoolean3 = delete 0 /* "A" */; -var ResultIsBoolean4 = delete (ENUM[0] + 1 /* "B" */); +var ResultIsBoolean3 = delete ENUM1["A"]; +var ResultIsBoolean4 = delete (ENUM[0] + ENUM1["B"]); // multiple delete operators var ResultIsBoolean5 = delete delete ENUM; -var ResultIsBoolean6 = delete delete delete (ENUM[0] + 1 /* "B" */); +var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1["B"]); // miss assignment operators delete ENUM; delete ENUM1; -delete 1 /* B */; +delete ENUM1.B; delete ENUM, ENUM1; diff --git a/tests/baselines/reference/downlevelLetConst14.js b/tests/baselines/reference/downlevelLetConst14.js index ffe667eda3f4c..ac9444f9facca 100644 --- a/tests/baselines/reference/downlevelLetConst14.js +++ b/tests/baselines/reference/downlevelLetConst14.js @@ -59,24 +59,24 @@ use(y); var x = 10; var z0, z1, z2, z3; { - var _x = 20; - use(_x); - var _z0 = ([ + var x_1 = 20; + use(x_1); + var z0_1 = ([ 1 ])[0]; - use(_z0); - var _z1 = ([ + use(z0_1); + var z1_1 = ([ 1 ])[0]; - use(_z1); - var _z2 = ({ + use(z1_1); + var z2_1 = ({ a: 1 }).a; - use(_z2); - var _z3 = ({ + use(z2_1); + var z3_1 = ({ a: 1 }).a; - use(_z3); + use(z3_1); } use(x); use(z0); @@ -86,38 +86,38 @@ use(z3); var z6; var y = true; { - var _y = ""; - var _z6 = ([ + var y_1 = ""; + var z6_1 = ([ true ])[0]; { - var _y_1 = 1; - var _z6_1 = ({ + var y_2 = 1; + var z6_2 = ({ a: 1 }).a; - use(_y_1); - use(_z6_1); + use(y_2); + use(z6_2); } - use(_y); - use(_z6); + use(y_1); + use(z6_1); } use(y); use(z6); var z = false; var z5 = 1; { - var _z = ""; - var _z5 = ([ + var z_1 = ""; + var z5_1 = ([ 5 ])[0]; { - var _z_1 = 1; - var _z5_1 = ({ + var _z = 1; + var _z5 = ({ a: 1 }).a; // try to step on generated name - use(_z_1); + use(_z); } - use(_z); + use(z_1); } use(y); diff --git a/tests/baselines/reference/downlevelLetConst15.js b/tests/baselines/reference/downlevelLetConst15.js index 94fcb1b03a008..f1b476c017612 100644 --- a/tests/baselines/reference/downlevelLetConst15.js +++ b/tests/baselines/reference/downlevelLetConst15.js @@ -59,28 +59,28 @@ use(y); var x = 10; var z0, z1, z2, z3; { - var _x = 20; - use(_x); - var _z0 = ([ + var x_1 = 20; + use(x_1); + var z0_1 = ([ 1 ])[0]; - use(_z0); - var _z1 = ([ + use(z0_1); + var z1_1 = ([ { a: 1 } ])[0].a; - use(_z1); - var _z2 = ({ + use(z1_1); + var z2_1 = ({ a: 1 }).a; - use(_z2); - var _z3 = ({ + use(z2_1); + var z3_1 = ({ a: { b: 1 } }).a.b; - use(_z3); + use(z3_1); } use(x); use(z0); @@ -90,38 +90,38 @@ use(z3); var z6; var y = true; { - var _y = ""; - var _z6 = ([ + var y_1 = ""; + var z6_1 = ([ true ])[0]; { - var _y_1 = 1; - var _z6_1 = ({ + var y_2 = 1; + var z6_2 = ({ a: 1 }).a; - use(_y_1); - use(_z6_1); + use(y_2); + use(z6_2); } - use(_y); - use(_z6); + use(y_1); + use(z6_1); } use(y); use(z6); var z = false; var z5 = 1; { - var _z = ""; - var _z5 = ([ + var z_1 = ""; + var z5_1 = ([ 5 ])[0]; { - var _z_1 = 1; - var _z5_1 = ({ + var _z = 1; + var _z5 = ({ a: 1 }).a; // try to step on generated name - use(_z_1); + use(_z); } - use(_z); + use(z_1); } use(y); diff --git a/tests/baselines/reference/downlevelLetConst16.js b/tests/baselines/reference/downlevelLetConst16.js index f83e745c55403..aefe2830adc2f 100644 --- a/tests/baselines/reference/downlevelLetConst16.js +++ b/tests/baselines/reference/downlevelLetConst16.js @@ -236,29 +236,29 @@ use(x); use(y); use(z); function foo1() { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); } function foo2() { { - var _x = 1; - use(_x); - var _y = ([ + var x_1 = 1; + use(x_1); + var y_1 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_1); + var z_1 = ({ a: 1 }).a; - use(_z); + use(z_1); } use(x); } @@ -266,29 +266,29 @@ var A = (function () { function A() { } A.prototype.m1 = function () { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); }; A.prototype.m2 = function () { { - var _x = 1; - use(_x); - var _y = ([ + var x_2 = 1; + use(x_2); + var y_2 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_2); + var z_2 = ({ a: 1 }).a; - use(_z); + use(z_2); } use(x); }; @@ -298,200 +298,200 @@ var B = (function () { function B() { } B.prototype.m1 = function () { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); }; B.prototype.m2 = function () { { - var _x = 1; - use(_x); - var _y = ([ + var x_3 = 1; + use(x_3); + var y_3 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_3); + var z_3 = ({ a: 1 }).a; - use(_z); + use(z_3); } use(x); }; return B; })(); function bar1() { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); } function bar2() { { - var _x = 1; - use(_x); - var _y = ([ + var x_4 = 1; + use(x_4); + var y_4 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_4); + var z_4 = ({ a: 1 }).a; - use(_z); + use(z_4); } use(x); } var M1; (function (M1) { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); })(M1 || (M1 = {})); var M2; (function (M2) { { - var _x = 1; - use(_x); - var _y = ([ + var x_5 = 1; + use(x_5); + var y_5 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_5); + var z_5 = ({ a: 1 }).a; - use(_z); + use(z_5); } use(x); })(M2 || (M2 = {})); var M3; (function (M3) { - var _x = 1; - use(_x); - var _y = ([ + var x = 1; + use(x); + var y = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y); + var z = ({ a: 1 }).a; - use(_z); + use(z); })(M3 || (M3 = {})); var M4; (function (M4) { { - var _x = 1; - use(_x); - var _y = ([ + var x_6 = 1; + use(x_6); + var y_6 = ([ 1 ])[0]; - use(_y); - var _z = ({ + use(y_6); + var z_6 = ({ a: 1 }).a; - use(_z); + use(z_6); } use(x); use(y); use(z); })(M4 || (M4 = {})); function foo3() { - for (var _x = void 0;;) { - use(_x); + for (var x_7 = void 0;;) { + use(x_7); } - for (var _y = ([])[0];;) { - use(_y); + for (var y_7 = ([])[0];;) { + use(y_7); } - for (var _z = ({ + for (var z_7 = ({ a: 1 }).a;;) { - use(_z); + use(z_7); } use(x); } function foo4() { - for (var _x = 1;;) { - use(_x); + for (var x_8 = 1;;) { + use(x_8); } - for (var _y = ([])[0];;) { - use(_y); + for (var y_8 = ([])[0];;) { + use(y_8); } - for (var _z = ({ + for (var z_8 = ({ a: 1 }).a;;) { - use(_z); + use(z_8); } use(x); } function foo5() { - for (var _x in []) { - use(_x); + for (var x_9 in []) { + use(x_9); } use(x); } function foo6() { - for (var _x in []) { - use(_x); + for (var x_10 in []) { + use(x_10); } use(x); } function foo7() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i]; - use(_x); + var x_11 = _a[_i]; + use(x_11); } use(x); } function foo8() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i][0]; - use(_x); + var x_12 = _a[_i][0]; + use(x_12); } use(x); } function foo9() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i].a; - use(_x); + var x_13 = _a[_i].a; + use(x_13); } use(x); } function foo10() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i]; - use(_x); + var x_14 = _a[_i]; + use(x_14); } use(x); } function foo11() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i][0]; - use(_x); + var x_15 = _a[_i][0]; + use(x_15); } use(x); } function foo12() { for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x = _a[_i].a; - use(_x); + var x_16 = _a[_i].a; + use(x_16); } use(x); } diff --git a/tests/baselines/reference/downlevelLetConst17.js b/tests/baselines/reference/downlevelLetConst17.js index d38ec3fde08c8..56ab1e6df54c6 100644 --- a/tests/baselines/reference/downlevelLetConst17.js +++ b/tests/baselines/reference/downlevelLetConst17.js @@ -70,54 +70,54 @@ for (const x of []) { //// [downlevelLetConst17.js] 'use strict'; var x; -for (var _x = 10;;) { - use(_x); +for (var x_1 = 10;;) { + use(x_1); } use(x); -for (var _x_1 = 10;;) { - use(_x_1); +for (var x_2 = 10;;) { + use(x_2); } for (;;) { - var _x_2 = 10; - use(_x_2); - _x_2 = 1; + var x_3 = 10; + use(x_3); + x_3 = 1; } for (;;) { - var _x_3 = 10; - use(_x_3); + var x_4 = 10; + use(x_4); } -for (var _x_4 = void 0;;) { - use(_x_4); - _x_4 = 1; +for (var x_5 = void 0;;) { + use(x_5); + x_5 = 1; } for (;;) { - var _x_5 = void 0; - use(_x_5); - _x_5 = 1; + var x_6 = void 0; + use(x_6); + x_6 = 1; } while (true) { - var _x_6 = void 0; - use(_x_6); + var x_7 = void 0; + use(x_7); } while (true) { - var _x_7 = true; - use(_x_7); + var x_8 = true; + use(x_8); } do { - var _x_8 = void 0; - use(_x_8); + var x_9 = void 0; + use(x_9); } while (true); do { - var _x_9 = void 0; - use(_x_9); + var x_10 = void 0; + use(x_10); } while (true); -for (var _x_10 in []) { - use(_x_10); +for (var x_11 in []) { + use(x_11); } -for (var _x_11 in []) { - use(_x_11); +for (var x_12 in []) { + use(x_12); } for (var _i = 0, _a = []; _i < _a.length; _i++) { - var _x_12 = _a[_i]; - use(_x_12); + var x_13 = _a[_i]; + use(x_13); } diff --git a/tests/baselines/reference/downlevelLetConst18.js b/tests/baselines/reference/downlevelLetConst18.js index 0c025573e209b..f3b2306d62b33 100644 --- a/tests/baselines/reference/downlevelLetConst18.js +++ b/tests/baselines/reference/downlevelLetConst18.js @@ -38,40 +38,40 @@ for (var x = void 0;;) { } ; } -for (var _x = void 0;;) { +for (var x = void 0;;) { function foo() { - _x; + x; } ; } -for (var _x_1 = void 0;;) { +for (var x = void 0;;) { (function () { - _x_1; + x; })(); } -for (var _x_2 = 1;;) { +for (var x = 1;;) { (function () { - _x_2; + x; })(); } -for (var _x_3 = void 0;;) { +for (var x = void 0;;) { ({ foo: function () { - _x_3; + x; } }); } -for (var _x_4 = void 0;;) { +for (var x = void 0;;) { ({ get foo() { - return _x_4; + return x; } }); } -for (var _x_5 = void 0;;) { +for (var x = void 0;;) { ({ set foo(v) { - _x_5; + x; } }); } diff --git a/tests/baselines/reference/downlevelLetConst19.js b/tests/baselines/reference/downlevelLetConst19.js index adcc2e256a81d..2b3ec8036cbdb 100644 --- a/tests/baselines/reference/downlevelLetConst19.js +++ b/tests/baselines/reference/downlevelLetConst19.js @@ -24,14 +24,14 @@ use(x) var x; function a() { { - var _x; - use(_x); + var x_1; + use(x_1); function b() { { - var _x_1; - use(_x_1); + var x_2; + use(x_2); } - use(_x); + use(x_1); } } use(x); diff --git a/tests/baselines/reference/duplicateExportAssignments.js b/tests/baselines/reference/duplicateExportAssignments.js index 7d2776962f7ad..3742a5f1fe54f 100644 --- a/tests/baselines/reference/duplicateExportAssignments.js +++ b/tests/baselines/reference/duplicateExportAssignments.js @@ -56,8 +56,8 @@ var y = (function () { module.exports = x; //// [foo3.js] var x; -(function (_x) { - _x.x = 10; +(function (x_1) { + x_1.x = 10; })(x || (x = {})); var y = (function () { function y() { diff --git a/tests/baselines/reference/duplicateLocalVariable4.js b/tests/baselines/reference/duplicateLocalVariable4.js index d7d67f28d5099..34fe30a1f1c12 100644 --- a/tests/baselines/reference/duplicateLocalVariable4.js +++ b/tests/baselines/reference/duplicateLocalVariable4.js @@ -12,4 +12,4 @@ var E; E[E["a"] = 0] = "a"; })(E || (E = {})); var x = E; -var x = 0 /* a */; +var x = E.a; diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt index 3a0ab0e597c9b..2f5ca2a387c84 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. ==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts (4 errors) ==== var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } var b = function () { var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -23,7 +23,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts () => { var arg = arguments[0]; ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -31,7 +31,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts foo(() => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. }); function bar() { diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt b/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt index f879f11799b15..26f204d3ee6e3 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. ==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts (4 errors) ==== var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } var b = function () { var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -23,7 +23,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6 () => { var arg = arguments[0]; ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -31,7 +31,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6 foo(() => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. }); function bar() { diff --git a/tests/baselines/reference/enumAssignability.js b/tests/baselines/reference/enumAssignability.js index 874c177c4e6cd..5bf639d9cf1ad 100644 --- a/tests/baselines/reference/enumAssignability.js +++ b/tests/baselines/reference/enumAssignability.js @@ -64,8 +64,8 @@ var F; (function (F) { F[F["B"] = 0] = "B"; })(F || (F = {})); -var e = 0 /* A */; -var f = 0 /* B */; +var e = E.A; +var f = F.B; e = f; f = e; e = 1; // ok diff --git a/tests/baselines/reference/enumAssignabilityInInheritance.js b/tests/baselines/reference/enumAssignabilityInInheritance.js index bec59a3d0de9d..065c561d9eb01 100644 --- a/tests/baselines/reference/enumAssignabilityInInheritance.js +++ b/tests/baselines/reference/enumAssignabilityInInheritance.js @@ -115,42 +115,42 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -var r = foo(0 /* A */); // E +var r = foo(E.A); // E var r2 = foo(1); // number var r3 = foo(null); // any -var r4 = foo2(0 /* A */); -var r4 = foo3(0 /* A */); -var r4 = foo4(0 /* A */); -var r4 = foo5(0 /* A */); -var r4 = foo6(0 /* A */); -var r4 = foo7(0 /* A */); -var r4 = foo8(0 /* A */); +var r4 = foo2(E.A); +var r4 = foo3(E.A); +var r4 = foo4(E.A); +var r4 = foo5(E.A); +var r4 = foo6(E.A); +var r4 = foo7(E.A); +var r4 = foo8(E.A); var A = (function () { function A() { } return A; })(); -var r4 = foo9(0 /* A */); +var r4 = foo9(E.A); var A2 = (function () { function A2() { } return A2; })(); -var r4 = foo10(0 /* A */); -var r4 = foo11(0 /* A */); -var r4 = foo12(0 /* A */); +var r4 = foo10(E.A); +var r4 = foo11(E.A); +var r4 = foo12(E.A); var E2; (function (E2) { E2[E2["A"] = 0] = "A"; })(E2 || (E2 = {})); -var r4 = foo13(0 /* A */); +var r4 = foo13(E.A); function f() { } var f; (function (f) { f.bar = 1; })(f || (f = {})); -var r4 = foo14(0 /* A */); +var r4 = foo14(E.A); var CC = (function () { function CC() { } @@ -160,6 +160,6 @@ var CC; (function (CC) { CC.bar = 1; })(CC || (CC = {})); -var r4 = foo15(0 /* A */); -var r4 = foo16(0 /* A */); -var r4 = foo16(0 /* A */); +var r4 = foo15(E.A); +var r4 = foo16(E.A); +var r4 = foo16(E.A); diff --git a/tests/baselines/reference/enumAssignmentCompat.js b/tests/baselines/reference/enumAssignmentCompat.js index 24f65bc96a96f..f56b1f300ed53 100644 --- a/tests/baselines/reference/enumAssignmentCompat.js +++ b/tests/baselines/reference/enumAssignmentCompat.js @@ -57,15 +57,15 @@ var W; var x = W; var y = W; var z = W; // error -var a = 0 /* a */; -var b = 0 /* a */; // error -var c = 0 /* a */; +var a = W.a; +var b = W.a; // error +var c = W.a; var d = 3; // error var e = 4; -var f = 0 /* a */; // error +var f = W.a; // error var g = 5; // error var h = 3; -var i = 0 /* a */; -i = 0 /* a */; +var i = W.a; +i = W.a; W.D; var p; diff --git a/tests/baselines/reference/enumAssignmentCompat2.js b/tests/baselines/reference/enumAssignmentCompat2.js index 7ded9416c1116..1fb7eb65e3696 100644 --- a/tests/baselines/reference/enumAssignmentCompat2.js +++ b/tests/baselines/reference/enumAssignmentCompat2.js @@ -56,15 +56,15 @@ var W; var x = W; var y = W; var z = W; // error -var a = 0 /* a */; -var b = 0 /* a */; // error -var c = 0 /* a */; +var a = W.a; +var b = W.a; // error +var c = W.a; var d = 3; // error var e = 4; -var f = 0 /* a */; // error +var f = W.a; // error var g = 5; // error var h = 3; -var i = 0 /* a */; -i = 0 /* a */; +var i = W.a; +i = W.a; W.D; var p; diff --git a/tests/baselines/reference/enumBasics.js b/tests/baselines/reference/enumBasics.js index 6f1a039ca6ea9..f6548f99b9582 100644 --- a/tests/baselines/reference/enumBasics.js +++ b/tests/baselines/reference/enumBasics.js @@ -89,13 +89,13 @@ var E1; E1[E1["C"] = 2] = "C"; })(E1 || (E1 = {})); // Enum type is a subtype of Number -var x = 0 /* A */; +var x = E1.A; // Enum object type is anonymous with properties of the enum type and numeric indexer var e = E1; var e; var e; // Reverse mapping of enum returns string name of property -var s = E1[0 /* A */]; +var s = E1[e.A]; var s; // Enum with only constant members var E2; @@ -108,7 +108,7 @@ var E2; var E3; (function (E3) { E3[E3["X"] = 'foo'.length] = "X"; - E3[E3["Y"] = 4 + 3] = "Y"; + E3[E3["Y"] = 7] = "Y"; E3[E3["Z"] = +'foo'] = "Z"; })(E3 || (E3 = {})); // Enum with constant members followed by computed members @@ -145,7 +145,7 @@ var E8; var E9; (function (E9) { E9[E9["A"] = 0] = "A"; - E9[E9["B"] = E9.A] = "B"; + E9[E9["B"] = 0] = "B"; })(E9 || (E9 = {})); // (refer to .js to validate) // Enum constant members are propagated @@ -159,12 +159,12 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ - 0 /* A */, + E9.A, E9.B, - 0 /* B */, - 1 /* C */, - 0 /* A */, - 0 /* A */, - 3 /* B */, - 4 /* C */ + E6.B, + E6.C, + E6.A, + E5.A, + E5.B, + E5.C ]; diff --git a/tests/baselines/reference/enumBasics1.js b/tests/baselines/reference/enumBasics1.js index 13b6da353b9b4..e5c9c6d29d4a6 100644 --- a/tests/baselines/reference/enumBasics1.js +++ b/tests/baselines/reference/enumBasics1.js @@ -63,7 +63,7 @@ class C { var e = E; // shouldn't error */ -1 /* A */.A; // should error +E.A.A; // should error var E2; (function (E2) { E2[E2["A"] = 0] = "A"; diff --git a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js index 67d9a020bb60f..d463073bb81c5 100644 --- a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js +++ b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js @@ -12,4 +12,4 @@ var Position; Position[Position["IgnoreRulesSpecific"] = 0] = "IgnoreRulesSpecific"; })(Position || (Position = {})); var x = IgnoreRulesSpecific.; -var y = 0 /* IgnoreRulesSpecific */; +var y = Position.IgnoreRulesSpecific; diff --git a/tests/baselines/reference/enumErrors.errors.txt b/tests/baselines/reference/enumErrors.errors.txt index ca13ceba4aeff..14cad3cb53b06 100644 --- a/tests/baselines/reference/enumErrors.errors.txt +++ b/tests/baselines/reference/enumErrors.errors.txt @@ -3,15 +3,13 @@ tests/cases/conformance/enums/enumErrors.ts(3,6): error TS2431: Enum name cannot tests/cases/conformance/enums/enumErrors.ts(4,6): error TS2431: Enum name cannot be 'string' tests/cases/conformance/enums/enumErrors.ts(5,6): error TS2431: Enum name cannot be 'boolean' tests/cases/conformance/enums/enumErrors.ts(9,9): error TS2322: Type 'Number' is not assignable to type 'E5'. -tests/cases/conformance/enums/enumErrors.ts(20,9): error TS2322: Type 'E9' is not assignable to type 'E10'. -tests/cases/conformance/enums/enumErrors.ts(21,9): error TS2322: Type 'E9' is not assignable to type 'E10'. tests/cases/conformance/enums/enumErrors.ts(26,9): error TS2322: Type 'string' is not assignable to type 'E11'. tests/cases/conformance/enums/enumErrors.ts(27,9): error TS2322: Type 'Date' is not assignable to type 'E11'. tests/cases/conformance/enums/enumErrors.ts(28,9): error TS2304: Cannot find name 'window'. tests/cases/conformance/enums/enumErrors.ts(29,9): error TS2322: Type '{}' is not assignable to type 'E11'. -==== tests/cases/conformance/enums/enumErrors.ts (11 errors) ==== +==== tests/cases/conformance/enums/enumErrors.ts (9 errors) ==== // Enum named with PredefinedTypes enum any { } ~~~ @@ -42,11 +40,7 @@ tests/cases/conformance/enums/enumErrors.ts(29,9): error TS2322: Type '{}' is no // Bug 707850: This should be allowed enum E10 { A = E9.A, - ~~~~ -!!! error TS2322: Type 'E9' is not assignable to type 'E10'. B = E9.B - ~~~~ -!!! error TS2322: Type 'E9' is not assignable to type 'E10'. } // Enum with computed member intializer of other types diff --git a/tests/baselines/reference/enumErrors.js b/tests/baselines/reference/enumErrors.js index 44aa2f90162fe..a8ecdf2470a4c 100644 --- a/tests/baselines/reference/enumErrors.js +++ b/tests/baselines/reference/enumErrors.js @@ -53,14 +53,14 @@ var E5; var E9; (function (E9) { E9[E9["A"] = 0] = "A"; - E9[E9["B"] = E9.A] = "B"; + E9[E9["B"] = 0] = "B"; })(E9 || (E9 = {})); //Enum with computed member intializer of different enum type // Bug 707850: This should be allowed var E10; (function (E10) { - E10[E10["A"] = 0 /* A */] = "A"; - E10[E10["B"] = E9.B] = "B"; + E10[E10["A"] = 0] = "A"; + E10[E10["B"] = 0] = "B"; })(E10 || (E10 = {})); // Enum with computed member intializer of other types var E11; diff --git a/tests/baselines/reference/enumFromExternalModule.js b/tests/baselines/reference/enumFromExternalModule.js index 8e92cbbbda771..ed2a1f3926a34 100644 --- a/tests/baselines/reference/enumFromExternalModule.js +++ b/tests/baselines/reference/enumFromExternalModule.js @@ -18,4 +18,4 @@ var Mode = exports.Mode; //// [enumFromExternalModule_1.js] /// var f = require('enumFromExternalModule_0'); -var x = 0 /* Open */; +var x = f.Mode.Open; diff --git a/tests/baselines/reference/enumIndexer.js b/tests/baselines/reference/enumIndexer.js index 77c2708dab367..9862d787d233b 100644 --- a/tests/baselines/reference/enumIndexer.js +++ b/tests/baselines/reference/enumIndexer.js @@ -21,7 +21,7 @@ var _arr = [ key: 'bar' } ]; -var enumValue = 0 /* foo */; +var enumValue = MyEnumType.foo; var x = _arr.map(function (o) { return MyEnumType[o.key] === enumValue; }); // these are not same type diff --git a/tests/baselines/reference/enumMapBackIntoItself.js b/tests/baselines/reference/enumMapBackIntoItself.js index 2d177731b9572..80a4b88479f5d 100644 --- a/tests/baselines/reference/enumMapBackIntoItself.js +++ b/tests/baselines/reference/enumMapBackIntoItself.js @@ -16,7 +16,7 @@ var TShirtSize; TShirtSize[TShirtSize["Medium"] = 1] = "Medium"; TShirtSize[TShirtSize["Large"] = 2] = "Large"; })(TShirtSize || (TShirtSize = {})); -var mySize = 2 /* Large */; +var mySize = TShirtSize.Large; var test = TShirtSize[mySize]; // specifically checking output here, bug was that test used to be undefined at runtime test + ''; diff --git a/tests/baselines/reference/enumMemberResolution.js b/tests/baselines/reference/enumMemberResolution.js index e1d79ebeb92e8..c021eb8d47aed 100644 --- a/tests/baselines/reference/enumMemberResolution.js +++ b/tests/baselines/reference/enumMemberResolution.js @@ -14,4 +14,4 @@ var Position2; })(Position2 || (Position2 = {})); var x = IgnoreRulesSpecific.; // error var y = 1; -var z = 0 /* IgnoreRulesSpecific */; // no error +var z = Position2.IgnoreRulesSpecific; // no error diff --git a/tests/baselines/reference/enumMerging.js b/tests/baselines/reference/enumMerging.js index b76f789da1daf..d8d9373d3ffe5 100644 --- a/tests/baselines/reference/enumMerging.js +++ b/tests/baselines/reference/enumMerging.js @@ -96,12 +96,12 @@ var M1; })(M1.EConst1 || (M1.EConst1 = {})); var EConst1 = M1.EConst1; var x = [ - 3 /* A */, - 2 /* B */, - 1 /* C */, - 7 /* D */, - 9 /* E */, - 8 /* F */ + EConst1.A, + EConst1.B, + EConst1.C, + EConst1.D, + EConst1.E, + EConst1.F ]; })(M1 || (M1 = {})); // Enum with only computed members across 2 declarations with the same root module @@ -183,6 +183,6 @@ var M6; })(A.Color || (A.Color = {})); var Color = A.Color; })(A = M6.A || (M6.A = {})); - var t = 1 /* Yellow */; - t = 0 /* Red */; + var t = A.Color.Yellow; + t = A.Color.Red; })(M6 || (M6 = {})); diff --git a/tests/baselines/reference/enumOperations.js b/tests/baselines/reference/enumOperations.js index 902079c04c08d..96d9ace576c08 100644 --- a/tests/baselines/reference/enumOperations.js +++ b/tests/baselines/reference/enumOperations.js @@ -21,7 +21,7 @@ var Enum; (function (Enum) { Enum[Enum["None"] = 0] = "None"; })(Enum || (Enum = {})); -var enumType = 0 /* None */; +var enumType = Enum.None; var numberType = 0; var anyType = 0; enumType ^ numberType; diff --git a/tests/baselines/reference/enumPropertyAccess.js b/tests/baselines/reference/enumPropertyAccess.js index 4c2a7df3c94c9..1ac82b0a3de27 100644 --- a/tests/baselines/reference/enumPropertyAccess.js +++ b/tests/baselines/reference/enumPropertyAccess.js @@ -20,7 +20,7 @@ var Colors; Colors[Colors["Red"] = 0] = "Red"; Colors[Colors["Green"] = 1] = "Green"; })(Colors || (Colors = {})); -var x = 0 /* Red */; // type of 'x' should be 'Colors' +var x = Colors.Red; // type of 'x' should be 'Colors' var p = x.Green; // error x.toFixed(); // ok // Now with generics diff --git a/tests/baselines/reference/enumWithParenthesizedInitializer1.js b/tests/baselines/reference/enumWithParenthesizedInitializer1.js index 0c125b3d8b2b2..f81af2c4dda62 100644 --- a/tests/baselines/reference/enumWithParenthesizedInitializer1.js +++ b/tests/baselines/reference/enumWithParenthesizedInitializer1.js @@ -6,5 +6,5 @@ enum E { //// [enumWithParenthesizedInitializer1.js] var E; (function (E) { - E[E["e"] = -(3)] = "e"; + E[E["e"] = -3] = "e"; })(E || (E = {})); diff --git a/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js b/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js index ef9192c1c90f0..8d203e9fd71ae 100644 --- a/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js +++ b/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js @@ -9,6 +9,6 @@ enum E { var E; (function (E) { E[E["a"] = 0] = "a"; - E[E["b"] = E.a] = "b"; - E[E["c"] = undefined] = "c"; + E[E["b"] = 0] = "b"; + E[E["c"] = 1] = "c"; })(E || (E = {})); diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js index 3ac92c5d9eaa5..0a7ad4520c1d8 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -17,6 +17,6 @@ module.exports = C; //// [es5ExportDefaultClassDeclaration.d.ts] -export declare class C { +export default class C { method(): void; } diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js index 8c07ff12599cc..6687d8dd2d98c 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -6,47 +6,17 @@ export default class { //// [es5ExportDefaultClassDeclaration2.js] -var _default = (function () { - function _default() { +var default_1 = (function () { + function default_1() { } - _default.prototype.method = function () { + default_1.prototype.method = function () { }; - return _default; + return default_1; })(); -module.exports = _default; +module.exports = default_1; //// [es5ExportDefaultClassDeclaration2.d.ts] -export declare class { +export default class { method(): void; } - - -//// [DtsFileErrors] - - -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,1): error TS1128: Declaration or statement expected. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,8): error TS2304: Cannot find name 'declare'. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,16): error TS1005: ';' expected. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,5): error TS2304: Cannot find name 'method'. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,13): error TS1005: ';' expected. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,19): error TS1109: Expression expected. - - -==== tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts (6 errors) ==== - export declare class { - ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~~~~~~~ -!!! error TS2304: Cannot find name 'declare'. - ~~~~~ -!!! error TS1005: ';' expected. - method(): void; - ~~~~~~ -!!! error TS2304: Cannot find name 'method'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1109: Expression expected. - } - \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js index f0c3da6657bdd..43f8257899913 100644 --- a/tests/baselines/reference/es5ExportDefaultExpression.js +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -8,4 +8,4 @@ module.exports = (1 + 2); //// [es5ExportDefaultExpression.d.ts] -export default (1 + 2); +export default : number; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js index 015767435817d..a23eb361fd404 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -10,4 +10,4 @@ module.exports = f; //// [es5ExportDefaultFunctionDeclaration.d.ts] -export declare function f(): void; +export default function f(): void; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js index 6a99726655ff6..696efe5fbb14f 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -6,21 +6,8 @@ export default function () { } //// [es5ExportDefaultFunctionDeclaration2.js] function () { } -module.exports = _default; +module.exports = default_1; //// [es5ExportDefaultFunctionDeclaration2.d.ts] -export declare function (): void; - - -//// [DtsFileErrors] - - -tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.d.ts(1,25): error TS1003: Identifier expected. - - -==== tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.d.ts (1 errors) ==== - export declare function (): void; - ~ -!!! error TS1003: Identifier expected. - \ No newline at end of file +export default function (): void; diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js index 4c223545e8a28..05c8a794e9127 100644 --- a/tests/baselines/reference/es6ExportAll.js +++ b/tests/baselines/reference/es6ExportAll.js @@ -41,3 +41,4 @@ export declare var x: number; export declare module uninstantiated { } //// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js index 9fd8c1c4b33e7..073fbdaab38ed 100644 --- a/tests/baselines/reference/es6ExportAllInEs5.js +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -29,8 +29,8 @@ var m; })(m = exports.m || (exports.m = {})); exports.x = 10; //// [client.js] -var _server = require("server"); -for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; +var server_1 = require("server"); +for (var _a in server_1) if (!exports.hasOwnProperty(_a)) exports[_a] = server_1[_a]; //// [server.d.ts] @@ -45,3 +45,4 @@ export declare var x: number; export declare module uninstantiated { } //// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportClause.js b/tests/baselines/reference/es6ExportClause.js index 9fd7a71554d5b..4fba47ea7d1d0 100644 --- a/tests/baselines/reference/es6ExportClause.js +++ b/tests/baselines/reference/es6ExportClause.js @@ -32,3 +32,18 @@ export { x }; //// [es6ExportClause.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClauseInEs5.js b/tests/baselines/reference/es6ExportClauseInEs5.js new file mode 100644 index 0000000000000..93c1015d20785 --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.js @@ -0,0 +1,57 @@ +//// [es6ExportClauseInEs5.ts] + +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + +//// [es6ExportClauseInEs5.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +exports.c2 = c; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +exports.instantiatedModule = m; +var x = 10; +exports.x = x; +exports.c = c; +exports.c2 = c; +exports.i = i; +exports.instantiatedModule = m; +exports.uninstantiated = uninstantiated; +exports.x = x; + + +//// [es6ExportClauseInEs5.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClauseInEs5.types b/tests/baselines/reference/es6ExportClauseInEs5.types new file mode 100644 index 0000000000000..8caedfa5ceb9e --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/es6ExportClauseInEs5.ts === + +class c { +>c : c +} +interface i { +>i : i +} +module m { +>m : typeof m + + export var x = 10; +>x : number +} +var x = 10; +>x : number + +module uninstantiated { +>uninstantiated : unknown +} +export { c }; +>c : typeof c + +export { c as c2 }; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule }; +>i : unknown +>m : typeof m +>instantiatedModule : typeof m + +export { uninstantiated }; +>uninstantiated : unknown + +export { x }; +>x : number + diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js index 29cdc655397c4..7952bdb0bcc4b 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -49,3 +49,8 @@ export declare var x: number; export declare module uninstantiated { } //// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js new file mode 100644 index 0000000000000..2bc573ce77f9e --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var server_1 = require("server"); +exports.c = server_1.c; +var server_2 = require("server"); +exports.c2 = server_2.c; +var server_3 = require("server"); +exports.i = server_3.i; +exports.instantiatedModule = server_3.m; +var server_4 = require("server"); +exports.uninstantiated = server_4.uninstantiated; +var server_5 = require("server"); +exports.x = server_5.x; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types new file mode 100644 index 0000000000000..c0087dccd943a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export { c } from "server"; +>c : typeof c + +export { c as c2 } from "server"; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule } from "server"; +>i : unknown +>m : typeof instantiatedModule +>instantiatedModule : typeof instantiatedModule + +export { uninstantiated } from "server"; +>uninstantiated : unknown + +export { x } from "server"; +>x : number + diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js index f2682f0a18866..2a25b5ac34974 100644 --- a/tests/baselines/reference/es6ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js @@ -13,6 +13,6 @@ export default class C { //// [es6ExportDefaultClassDeclaration.d.ts] -export declare class C { +export default class C { method(): void; } diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js index a975d4322f53a..ac5d92b6c129d 100644 --- a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js @@ -6,43 +6,13 @@ export default class { //// [es6ExportDefaultClassDeclaration2.js] -export default class { +export default class { method() { } } //// [es6ExportDefaultClassDeclaration2.d.ts] -export declare class { +export default class { method(): void; } - - -//// [DtsFileErrors] - - -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,1): error TS1128: Declaration or statement expected. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,8): error TS2304: Cannot find name 'declare'. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,16): error TS1005: ';' expected. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,5): error TS2304: Cannot find name 'method'. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,13): error TS1005: ';' expected. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,19): error TS1109: Expression expected. - - -==== tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts (6 errors) ==== - export declare class { - ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~~~~~~~ -!!! error TS2304: Cannot find name 'declare'. - ~~~~~ -!!! error TS1005: ';' expected. - method(): void; - ~~~~~~ -!!! error TS2304: Cannot find name 'method'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1109: Expression expected. - } - \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportDefaultExpression.js b/tests/baselines/reference/es6ExportDefaultExpression.js index e0d910437662d..322e09bc46fe3 100644 --- a/tests/baselines/reference/es6ExportDefaultExpression.js +++ b/tests/baselines/reference/es6ExportDefaultExpression.js @@ -8,4 +8,4 @@ export default (1 + 2); //// [es6ExportDefaultExpression.d.ts] -export default (1 + 2); +export default : number; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js index fafc5a114f5a2..ec5789203d0ae 100644 --- a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js @@ -9,4 +9,4 @@ export default function f() { //// [es6ExportDefaultFunctionDeclaration.d.ts] -export declare function f(): void; +export default function f(): void; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js index 2071e56c539b1..80e37f18d21b6 100644 --- a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js @@ -9,17 +9,4 @@ export default function () { //// [es6ExportDefaultFunctionDeclaration2.d.ts] -export declare function (): void; - - -//// [DtsFileErrors] - - -tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.d.ts(1,25): error TS1003: Identifier expected. - - -==== tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.d.ts (1 errors) ==== - export declare function (): void; - ~ -!!! error TS1003: Identifier expected. - \ No newline at end of file +export default function (): void; diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt index c07a84bb810d9..9ff3c1b3f0430 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt @@ -1,12 +1,15 @@ -tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBinding_0.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (0 errors) ==== +==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (1 errors) ==== - export var a = 10; + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== +==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (0 errors) ==== import defaultBinding from "es6ImportDefaultBinding_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. + var x = defaultBinding; + import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index c7a320b76aabb..b169f9e80e4c7 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -2,17 +2,24 @@ //// [es6ImportDefaultBinding_0.ts] -export var a = 10; +var a = 10; +export = a; //// [es6ImportDefaultBinding_1.ts] import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used //// [es6ImportDefaultBinding_0.js] -export var a = 10; +var a = 10; +export default a; //// [es6ImportDefaultBinding_1.js] +import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; //// [es6ImportDefaultBinding_0.d.ts] -export declare var a: number; +declare var a: number; +export = a; //// [es6ImportDefaultBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt deleted file mode 100644 index fc1e1a1925c63..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. - - -==== tests/cases/compiler/server.ts (0 errors) ==== - - class c { } - export = c; - -==== tests/cases/compiler/client.ts (1 errors) ==== - import defaultBinding from "server"; - export var x = new defaultBinding(); - ~ -!!! error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. - import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used - \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js index ad58abd8125a8..4e9719892db40 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -27,3 +27,6 @@ exports.x = new defaultBinding(); declare class c { } export = c; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.types b/tests/baselines/reference/es6ImportDefaultBindingDts.types new file mode 100644 index 0000000000000..62f54168c3631 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/server.ts === + +class c { } +>c : c + +export = c; +>c : c + +=== tests/cases/compiler/client.ts === +import defaultBinding from "server"; +>defaultBinding : typeof defaultBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index c755b8207e7d8..5e71478e5a11a 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,52 +1,42 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(9,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(11,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== export var a = 10; export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. + var x1: number = m; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index d7196f86eaa7e..7d0d4b2582da5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -7,12 +7,18 @@ export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = m; //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] @@ -20,6 +26,17 @@ export var a = 10; export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] +import { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = a; +import { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = b; +import { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = x; +var x1 = y; +import { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = z; +import { m } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = m; //// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt new file mode 100644 index 0000000000000..9783ad4921e10 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + var x: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + var x: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + var x: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js new file mode 100644 index 0000000000000..2690e7a7f5166 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.js] +var defaultBinding1 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding1; +var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding2; +var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding3; +var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding4; +var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding5; +var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt new file mode 100644 index 0000000000000..9b246f803a0c6 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt @@ -0,0 +1,57 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(5,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(7,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,37): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = defaultBinding1; + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding2; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding3; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding4; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x1: number = defaultBinding5; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js new file mode 100644 index 0000000000000..0239b68194fba --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export var x1: number = defaultBinding1; +export import defaultBinding2, { a } from "server"; +export var x1: number = defaultBinding2; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = defaultBinding3; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = defaultBinding4; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = defaultBinding5; +export import defaultBinding6, { m, } from "server"; +export var x1: number = defaultBinding6; + + +//// [server.js] +var a = 10; +module.exports = a; +//// [client.js] +var defaultBinding1 = require("server"); +exports.x1 = defaultBinding1; +var defaultBinding2 = require("server"); +exports.x1 = defaultBinding2; +var defaultBinding3 = require("server"); +exports.x1 = defaultBinding3; +var defaultBinding4 = require("server"); +exports.x1 = defaultBinding4; +var defaultBinding5 = require("server"); +exports.x1 = defaultBinding5; +var defaultBinding6 = require("server"); +exports.x1 = defaultBinding6; + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt index 91d51d5f7ef64..bff47ba36ef82 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt @@ -1,15 +1,9 @@ tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. tests/cases/compiler/client.ts(2,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(3,12): error TS4025: Exported variable 'x1' has or is using private name 'a'. tests/cases/compiler/client.ts(4,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(5,12): error TS4025: Exported variable 'x2' has or is using private name 'b'. tests/cases/compiler/client.ts(6,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(7,12): error TS4025: Exported variable 'x4' has or is using private name 'x'. -tests/cases/compiler/client.ts(8,12): error TS4025: Exported variable 'x5' has or is using private name 'y'. tests/cases/compiler/client.ts(9,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(10,12): error TS4025: Exported variable 'x3' has or is using private name 'z'. tests/cases/compiler/client.ts(11,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(12,12): error TS4025: Exported variable 'x6' has or is using private name 'm'. ==== tests/cases/compiler/server.ts (0 errors) ==== @@ -21,7 +15,7 @@ tests/cases/compiler/client.ts(12,12): error TS4025: Exported variable 'x6' has export class a12 { } export class x11 { } -==== tests/cases/compiler/client.ts (12 errors) ==== +==== tests/cases/compiler/client.ts (6 errors) ==== import defaultBinding1, { } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. @@ -29,33 +23,21 @@ tests/cases/compiler/client.ts(12,12): error TS4025: Exported variable 'x6' has ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x1 = new a(); - ~~ -!!! error TS4025: Exported variable 'x1' has or is using private name 'a'. import defaultBinding3, { a11 as b } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x2 = new b(); - ~~ -!!! error TS4025: Exported variable 'x2' has or is using private name 'b'. import defaultBinding4, { x, a12 as y } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x4 = new x(); - ~~ -!!! error TS4025: Exported variable 'x4' has or is using private name 'x'. export var x5 = new y(); - ~~ -!!! error TS4025: Exported variable 'x5' has or is using private name 'y'. import defaultBinding5, { x11 as z, } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x3 = new z(); - ~~ -!!! error TS4025: Exported variable 'x3' has or is using private name 'z'. import defaultBinding6, { m, } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x6 = new m(); - ~~ -!!! error TS4025: Exported variable 'x6' has or is using private name 'm'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js index a6b2c9a16701a..8cf9ab1ffb129 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -62,17 +62,17 @@ var x11 = (function () { })(); exports.x11 = x11; //// [client.js] -var _server_1 = require("server"); -exports.x1 = new _server_1.a(); -var _server_2 = require("server"); -exports.x2 = new _server_2.a11(); -var _server_3 = require("server"); -exports.x4 = new _server_3.x(); -exports.x5 = new _server_3.a12(); -var _server_4 = require("server"); -exports.x3 = new _server_4.x11(); -var _server_5 = require("server"); -exports.x6 = new _server_5.m(); +var server_1 = require("server"); +exports.x1 = new server_1.a(); +var server_2 = require("server"); +exports.x2 = new server_2.a11(); +var server_3 = require("server"); +exports.x4 = new server_3.x(); +exports.x5 = new server_3.a12(); +var server_4 = require("server"); +exports.x3 = new server_4.x11(); +var server_5 = require("server"); +exports.x6 = new server_5.m(); //// [server.d.ts] @@ -88,3 +88,15 @@ export declare class a12 { } export declare class x11 { } +//// [client.d.ts] +import { a } from "server"; +export declare var x1: a; +import { a11 as b } from "server"; +export declare var x2: b; +import { x, a12 as y } from "server"; +export declare var x4: x; +export declare var x5: y; +import { x11 as z } from "server"; +export declare var x3: z; +import { m } from "server"; +export declare var x6: m; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt new file mode 100644 index 0000000000000..405fab0de509e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/client.ts(3,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,30): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + class a { } + export = a; + +==== tests/cases/compiler/client.ts (6 errors) ==== + import defaultBinding1, { } from "server"; + export var x1 = new defaultBinding1(); + import defaultBinding2, { a } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x2 = new defaultBinding2(); + import defaultBinding3, { a as b } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x3 = new defaultBinding3(); + import defaultBinding4, { x, a as y } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x4 = new defaultBinding4(); + import defaultBinding5, { x as z, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x5 = new defaultBinding5(); + import defaultBinding6, { m, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x6 = new defaultBinding6(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js new file mode 100644 index 0000000000000..21ddcbc71d6c2 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts] //// + +//// [server.ts] + +class a { } +export = a; + +//// [client.ts] +import defaultBinding1, { } from "server"; +export var x1 = new defaultBinding1(); +import defaultBinding2, { a } from "server"; +export var x2 = new defaultBinding2(); +import defaultBinding3, { a as b } from "server"; +export var x3 = new defaultBinding3(); +import defaultBinding4, { x, a as y } from "server"; +export var x4 = new defaultBinding4(); +import defaultBinding5, { x as z, } from "server"; +export var x5 = new defaultBinding5(); +import defaultBinding6, { m, } from "server"; +export var x6 = new defaultBinding6(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +module.exports = a; +//// [client.js] +var defaultBinding1 = require("server"); +exports.x1 = new defaultBinding1(); +var defaultBinding2 = require("server"); +exports.x2 = new defaultBinding2(); +var defaultBinding3 = require("server"); +exports.x3 = new defaultBinding3(); +var defaultBinding4 = require("server"); +exports.x4 = new defaultBinding4(); +var defaultBinding5 = require("server"); +exports.x5 = new defaultBinding5(); +var defaultBinding6 = require("server"); +exports.x6 = new defaultBinding6(); + + +//// [server.d.ts] +declare class a { +} +export = a; +//// [client.d.ts] +import defaultBinding1 from "server"; +export declare var x1: defaultBinding1; +export declare var x2: defaultBinding1; +export declare var x3: defaultBinding1; +export declare var x4: defaultBinding1; +export declare var x5: defaultBinding1; +export declare var x6: defaultBinding1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt index 157360f52382d..0377e543973f9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt @@ -1,15 +1,9 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(9,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(11,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts (0 errors) ==== @@ -18,34 +12,29 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6, export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file + var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js index 4cf3046532a0a..1c65fadbe1d43 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js @@ -7,15 +7,40 @@ export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = m; + //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.js] +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_1.a; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_2 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_2.a; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.x; +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.a; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_4 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_4.x; +var es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_5 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_5.m; + + +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..a9a2ed4974d44 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt @@ -0,0 +1,58 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(2,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(4,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(6,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = a; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = b; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = x; + export var x1: number = y; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = z; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js new file mode 100644 index 0000000000000..af73279126f61 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -0,0 +1,51 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export import defaultBinding2, { a } from "server"; +export var x1: number = a; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = b; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = x; +export var x1: number = y; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = z; +export import defaultBinding6, { m, } from "server"; +export var x1: number = m; + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; +}); +//// [client.js] +define(["require", "exports", "server", "server", "server", "server", "server"], function (require, exports, server_1, server_2, server_3, server_4, server_5) { + exports.x1 = server_1.a; + exports.x1 = server_2.a; + exports.x1 = server_3.x; + exports.x1 = server_3.a; + exports.x1 = server_4.x; + exports.x1 = server_5.m; +}); + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt new file mode 100644 index 0000000000000..5df6817e897a9 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js new file mode 100644 index 0000000000000..d1dd565c81b48 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = defaultBinding; + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = defaultBinding; +}); + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt index b82fb1155e94b..f8dd391fe0ebf 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt @@ -1,15 +1,12 @@ tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'nameSpaceBinding.a'. ==== tests/cases/compiler/server.ts (0 errors) ==== export class a { } -==== tests/cases/compiler/client.ts (2 errors) ==== +==== tests/cases/compiler/client.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "server"; ~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. - export var x = new nameSpaceBinding.a(); - ~ -!!! error TS4025: Exported variable 'x' has or is using private name 'nameSpaceBinding.a'. \ No newline at end of file + export var x = new nameSpaceBinding.a(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js index 3068fb6d39dc7..4bde6e25b10c1 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js @@ -23,3 +23,6 @@ exports.x = new nameSpaceBinding.a(); //// [server.d.ts] export declare class a { } +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt deleted file mode 100644 index 3b09108bbfc3a..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. - - -==== tests/cases/compiler/server.ts (0 errors) ==== - - class a { } - export = a; - -==== tests/cases/compiler/client.ts (1 errors) ==== - import defaultBinding, * as nameSpaceBinding from "server"; - export var x = new defaultBinding(); - ~ -!!! error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js index 708cffca29d1d..69b76d79fbbd5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -28,3 +28,6 @@ define(["require", "exports", "server"], function (require, exports, defaultBind declare class a { } export = a; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types new file mode 100644 index 0000000000000..e40d3893ee216 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/server.ts === + +class a { } +>a : a + +export = a; +>a : a + +=== tests/cases/compiler/client.ts === +import defaultBinding, * as nameSpaceBinding from "server"; +>defaultBinding : typeof defaultBinding +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt index f1d20dccc59e3..d4d51e4d5abf4 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js index abd4736fca706..9131fcc75db80 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js @@ -5,8 +5,16 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var nameSpaceBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt new file mode 100644 index 0000000000000..3e06e7acae870 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js new file mode 100644 index 0000000000000..b219b5e7876d4 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = nameSpaceBinding.a; + +//// [server.js] +exports.a = 10; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = nameSpaceBinding.a; + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt deleted file mode 100644 index 5d656094a8c72..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. - - -==== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts (0 errors) ==== - - export var a = 10; - -==== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts (1 errors) ==== - import defaultBinding from "es6ImportDefaultBindingInEs5_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js index b6d293225fd0b..0b703f829ca31 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js @@ -2,11 +2,19 @@ //// [es6ImportDefaultBindingInEs5_0.ts] -export var a = 10; +var a = 10; +export = a; //// [es6ImportDefaultBindingInEs5_1.ts] import defaultBinding from "es6ImportDefaultBindingInEs5_0"; //// [es6ImportDefaultBindingInEs5_0.js] -exports.a = 10; +var a = 10; +module.exports = a; //// [es6ImportDefaultBindingInEs5_1.js] + + +//// [es6ImportDefaultBindingInEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types new file mode 100644 index 0000000000000..03243fc014d86 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts === +import defaultBinding from "es6ImportDefaultBindingInEs5_0"; +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt new file mode 100644 index 0000000000000..e0dfdc00e07a0 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x = defaultBinding; + export import defaultBinding2 from "server"; // non referenced + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js new file mode 100644 index 0000000000000..a3f8dd11c6c51 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingWithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding from "server"; +export var x = defaultBinding; +export import defaultBinding2 from "server"; // non referenced + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = defaultBinding; +}); + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt new file mode 100644 index 0000000000000..635bb955c00f6 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt @@ -0,0 +1,13 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNameSpaceImport_1.ts (0 errors) ==== + import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; + var x = nameSpaceBinding.a; + import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index 4f03e9a0ae29d..653feeb22b7c5 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -6,11 +6,15 @@ export var a = 10; //// [es6ImportNameSpaceImport_1.ts] import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this //// [es6ImportNameSpaceImport_0.js] export var a = 10; //// [es6ImportNameSpaceImport_1.js] +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; //// [es6ImportNameSpaceImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.types b/tests/baselines/reference/es6ImportNameSpaceImport.types deleted file mode 100644 index 1e09de42ec6a2..0000000000000 --- a/tests/baselines/reference/es6ImportNameSpaceImport.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/es6ImportNameSpaceImport_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportNameSpaceImport_1.ts === -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; ->nameSpaceBinding : typeof nameSpaceBinding - diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.js b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js new file mode 100644 index 0000000000000..e7d0eae9ca96b --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportAmd.ts] //// + +//// [es6ImportNameSpaceImportAmd_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportAmd_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this + + +//// [es6ImportNameSpaceImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportNameSpaceImportAmd_1.js] +define(["require", "exports", "es6ImportNameSpaceImportAmd_0"], function (require, exports, nameSpaceBinding) { + var x = nameSpaceBinding.a; +}); + + +//// [es6ImportNameSpaceImportAmd_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.types b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types new file mode 100644 index 0000000000000..623a7e8e160df --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +>nameSpaceBinding : typeof nameSpaceBinding + +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.js b/tests/baselines/reference/es6ImportNameSpaceImportDts.js new file mode 100644 index 0000000000000..91e927428a166 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportDts.ts] //// + +//// [server.ts] + +export class c { }; + +//// [client.ts] +import * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.c(); +import * as nameSpaceBinding2 from "server"; // unreferenced + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = new nameSpaceBinding.c(); + + +//// [server.d.ts] +export declare class c { +} +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.c; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.types b/tests/baselines/reference/es6ImportNameSpaceImportDts.types new file mode 100644 index 0000000000000..345d593b1437b --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/server.ts === + +export class c { }; +>c : c + +=== tests/cases/compiler/client.ts === +import * as nameSpaceBinding from "server"; +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new nameSpaceBinding.c(); +>x : nameSpaceBinding.c +>new nameSpaceBinding.c() : nameSpaceBinding.c +>nameSpaceBinding.c : typeof nameSpaceBinding.c +>nameSpaceBinding : typeof nameSpaceBinding +>c : typeof nameSpaceBinding.c + +import * as nameSpaceBinding2 from "server"; // unreferenced +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js index 2c7785dec6ed5..50a03972cc225 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js @@ -5,8 +5,18 @@ export var a = 10; //// [es6ImportNameSpaceImportInEs5_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this + //// [es6ImportNameSpaceImportInEs5_0.js] exports.a = 10; //// [es6ImportNameSpaceImportInEs5_1.js] +var nameSpaceBinding = require("es6ImportNameSpaceImportInEs5_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportNameSpaceImportInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types index cb7b669eea1c0..6ba725f2494ce 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types @@ -7,3 +7,12 @@ export var a = 10; import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; >nameSpaceBinding : typeof nameSpaceBinding +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt new file mode 100644 index 0000000000000..901556e73bd73 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x = nameSpaceBinding.a; + export import * as nameSpaceBinding2 from "server"; // Not referenced imports + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js new file mode 100644 index 0000000000000..84f6936d4b0f1 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import * as nameSpaceBinding from "server"; +export var x = nameSpaceBinding.a; +export import * as nameSpaceBinding2 from "server"; // Not referenced imports + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, nameSpaceBinding) { + exports.x = nameSpaceBinding.a; +}); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportNamedImport.errors.txt b/tests/baselines/reference/es6ImportNamedImport.errors.txt new file mode 100644 index 0000000000000..5723b5c20d4f8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImport.errors.txt @@ -0,0 +1,44 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export var a1 = 10; + export var x1 = 10; + export var z1 = 10; + export var z2 = 10; + export var aaaa = 10; + +==== tests/cases/compiler/es6ImportNamedImport_1.ts (0 errors) ==== + import { } from "es6ImportNamedImport_0"; + import { a } from "es6ImportNamedImport_0"; + var xxxx = a; + import { a as b } from "es6ImportNamedImport_0"; + var xxxx = b; + import { x, a as y } from "es6ImportNamedImport_0"; + var xxxx = x; + var xxxx = y; + import { x as z, } from "es6ImportNamedImport_0"; + var xxxx = z; + import { m, } from "es6ImportNamedImport_0"; + var xxxx = m; + import { a1, x1 } from "es6ImportNamedImport_0"; + var xxxx = a1; + var xxxx = x1; + import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; + var xxxx = a11; + var xxxx = x11; + import { z1 } from "es6ImportNamedImport_0"; + var z111 = z1; + import { z2 as z3 } from "es6ImportNamedImport_0"; + var z2 = z3; // z2 shouldn't give redeclare error + + // These are elided + import { aaaa } from "es6ImportNamedImport_0"; + // These are elided + import { aaaa as bbbb } from "es6ImportNamedImport_0"; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index 7993af7fb079f..9606c59351b52 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -7,16 +7,38 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImport_1.ts] import { } from "es6ImportNamedImport_0"; import { a } from "es6ImportNamedImport_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImport_0"; +var xxxx = z; import { m, } from "es6ImportNamedImport_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImport_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImport_0"; //// [es6ImportNamedImport_0.js] @@ -25,7 +47,31 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImport_1.js] +import { a } from "es6ImportNamedImport_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; +import { x as z } from "es6ImportNamedImport_0"; +var xxxx = z; +import { m } from "es6ImportNamedImport_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error //// [es6ImportNamedImport_0.d.ts] @@ -34,4 +80,7 @@ export declare var x: number; export declare var m: number; export declare var a1: number; export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; //// [es6ImportNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types deleted file mode 100644 index cb06c9918eab0..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImport.types +++ /dev/null @@ -1,50 +0,0 @@ -=== tests/cases/compiler/es6ImportNamedImport_0.ts === - -export var a = 10; ->a : number - -export var x = a; ->x : number ->a : number - -export var m = a; ->m : number ->a : number - -export var a1 = 10; ->a1 : number - -export var x1 = 10; ->x1 : number - -=== tests/cases/compiler/es6ImportNamedImport_1.ts === -import { } from "es6ImportNamedImport_0"; -import { a } from "es6ImportNamedImport_0"; ->a : number - -import { a as b } from "es6ImportNamedImport_0"; ->a : number ->b : number - -import { x, a as y } from "es6ImportNamedImport_0"; ->x : number ->a : number ->y : number - -import { x as z, } from "es6ImportNamedImport_0"; ->x : number ->z : number - -import { m, } from "es6ImportNamedImport_0"; ->m : number - -import { a1, x1 } from "es6ImportNamedImport_0"; ->a1 : number ->x1 : number - -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; ->a1 : number ->a11 : number ->x1 : number ->x11 : number - diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.js b/tests/baselines/reference/es6ImportNamedImportAmd.js new file mode 100644 index 0000000000000..c335337325e51 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.js @@ -0,0 +1,81 @@ +//// [tests/cases/compiler/es6ImportNamedImportAmd.ts] //// + +//// [es6ImportNamedImportAmd_0.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [es6ImportNamedImportAmd_1.ts] +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImportAmd_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImportAmd_0"; +var xxxx = x; +var xxxx = y; +import { x as z, } from "es6ImportNamedImportAmd_0"; +var xxxx = z; +import { m, } from "es6ImportNamedImportAmd_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportAmd_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; + + +//// [es6ImportNamedImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; + exports.a1 = 10; + exports.x1 = 10; + exports.z1 = 10; + exports.z2 = 10; + exports.aaaa = 10; +}); +//// [es6ImportNamedImportAmd_1.js] +define(["require", "exports", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0"], function (require, exports, es6ImportNamedImportAmd_0_1, es6ImportNamedImportAmd_0_2, es6ImportNamedImportAmd_0_3, es6ImportNamedImportAmd_0_4, es6ImportNamedImportAmd_0_5, es6ImportNamedImportAmd_0_6, es6ImportNamedImportAmd_0_7, es6ImportNamedImportAmd_0_8, es6ImportNamedImportAmd_0_9) { + var xxxx = es6ImportNamedImportAmd_0_1.a; + var xxxx = es6ImportNamedImportAmd_0_2.a; + var xxxx = es6ImportNamedImportAmd_0_3.x; + var xxxx = es6ImportNamedImportAmd_0_3.a; + var xxxx = es6ImportNamedImportAmd_0_4.x; + var xxxx = es6ImportNamedImportAmd_0_5.m; + var xxxx = es6ImportNamedImportAmd_0_6.a1; + var xxxx = es6ImportNamedImportAmd_0_6.x1; + var xxxx = es6ImportNamedImportAmd_0_7.a1; + var xxxx = es6ImportNamedImportAmd_0_7.x1; + var z111 = es6ImportNamedImportAmd_0_8.z1; + var z2 = es6ImportNamedImportAmd_0_9.z2; // z2 shouldn't give redeclare error +}); + + +//// [es6ImportNamedImportAmd_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.types b/tests/baselines/reference/es6ImportNamedImportAmd.types new file mode 100644 index 0000000000000..4a0abe853e025 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.types @@ -0,0 +1,123 @@ +=== tests/cases/compiler/es6ImportNamedImportAmd_0.ts === + +export var a = 10; +>a : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +export var a1 = 10; +>a1 : number + +export var x1 = 10; +>x1 : number + +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + +=== tests/cases/compiler/es6ImportNamedImportAmd_1.ts === +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +>a : number + +var xxxx = a; +>xxxx : number +>a : number + +import { a as b } from "es6ImportNamedImportAmd_0"; +>a : number +>b : number + +var xxxx = b; +>xxxx : number +>b : number + +import { x, a as y } from "es6ImportNamedImportAmd_0"; +>x : number +>a : number +>y : number + +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + +import { x as z, } from "es6ImportNamedImportAmd_0"; +>x : number +>z : number + +var xxxx = z; +>xxxx : number +>z : number + +import { m, } from "es6ImportNamedImportAmd_0"; +>m : number + +var xxxx = m; +>xxxx : number +>m : number + +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +>a1 : number +>x1 : number + +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +>a1 : number +>a11 : number +>x1 : number +>x11 : number + +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportAmd_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +>z2 : number +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; +>aaaa : number +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportDts.js b/tests/baselines/reference/es6ImportNamedImportDts.js new file mode 100644 index 0000000000000..a72632a737e7a --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.js @@ -0,0 +1,208 @@ +//// [tests/cases/compiler/es6ImportNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class a11 { } +export class a12 { } +export class x { } +export class x11 { } +export class m { } +export class a1 { } +export class x1 { } +export class a111 { } +export class x111 { } +export class z1 { } +export class z2 { } +export class aaaa { } +export class aaaa1 { } + +//// [client.ts] +import { } from "server"; +import { a } from "server"; +export var xxxx = new a(); +import { a11 as b } from "server"; +export var xxxx1 = new b(); +import { x, a12 as y } from "server"; +export var xxxx2 = new x(); +export var xxxx3 = new y(); +import { x11 as z, } from "server"; +export var xxxx4 = new z(); +import { m, } from "server"; +export var xxxx5 = new m(); +import { a1, x1 } from "server"; +export var xxxx6 = new a1(); +export var xxxx7 = new x1(); +import { a111 as a11, x111 as x11 } from "server"; +export var xxxx8 = new a11(); +export var xxxx9 = new x11(); +import { z1 } from "server"; +export var z111 = new z1(); +import { z2 as z3 } from "server"; +export var z2 = new z3(); // z2 shouldn't give redeclare error + +// not referenced +import { aaaa } from "server"; +import { aaaa1 as bbbb } from "server"; + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a1 = (function () { + function a1() { + } + return a1; +})(); +exports.a1 = a1; +var x1 = (function () { + function x1() { + } + return x1; +})(); +exports.x1 = x1; +var a111 = (function () { + function a111() { + } + return a111; +})(); +exports.a111 = a111; +var x111 = (function () { + function x111() { + } + return x111; +})(); +exports.x111 = x111; +var z1 = (function () { + function z1() { + } + return z1; +})(); +exports.z1 = z1; +var z2 = (function () { + function z2() { + } + return z2; +})(); +exports.z2 = z2; +var aaaa = (function () { + function aaaa() { + } + return aaaa; +})(); +exports.aaaa = aaaa; +var aaaa1 = (function () { + function aaaa1() { + } + return aaaa1; +})(); +exports.aaaa1 = aaaa1; +//// [client.js] +var server_1 = require("server"); +exports.xxxx = new server_1.a(); +var server_2 = require("server"); +exports.xxxx1 = new server_2.a11(); +var server_3 = require("server"); +exports.xxxx2 = new server_3.x(); +exports.xxxx3 = new server_3.a12(); +var server_4 = require("server"); +exports.xxxx4 = new server_4.x11(); +var server_5 = require("server"); +exports.xxxx5 = new server_5.m(); +var server_6 = require("server"); +exports.xxxx6 = new server_6.a1(); +exports.xxxx7 = new server_6.x1(); +var server_7 = require("server"); +exports.xxxx8 = new server_7.a111(); +exports.xxxx9 = new server_7.x111(); +var server_8 = require("server"); +exports.z111 = new server_8.z1(); +var server_9 = require("server"); +exports.z2 = new server_9.z2(); // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare class a { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x { +} +export declare class x11 { +} +export declare class m { +} +export declare class a1 { +} +export declare class x1 { +} +export declare class a111 { +} +export declare class x111 { +} +export declare class z1 { +} +export declare class z2 { +} +export declare class aaaa { +} +export declare class aaaa1 { +} +//// [client.d.ts] +import { a } from "server"; +export declare var xxxx: a; +import { a11 as b } from "server"; +export declare var xxxx1: b; +import { x, a12 as y } from "server"; +export declare var xxxx2: x; +export declare var xxxx3: y; +import { x11 as z } from "server"; +export declare var xxxx4: z; +import { m } from "server"; +export declare var xxxx5: m; +import { a1, x1 } from "server"; +export declare var xxxx6: a1; +export declare var xxxx7: x1; +import { a111 as a11, x111 as x11 } from "server"; +export declare var xxxx8: a11; +export declare var xxxx9: x11; +import { z1 } from "server"; +export declare var z111: z1; +import { z2 as z3 } from "server"; +export declare var z2: z3; diff --git a/tests/baselines/reference/es6ImportNamedImportDts.types b/tests/baselines/reference/es6ImportNamedImportDts.types new file mode 100644 index 0000000000000..93bd55716a514 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.types @@ -0,0 +1,150 @@ +=== tests/cases/compiler/server.ts === + +export class a { } +>a : a + +export class a11 { } +>a11 : a11 + +export class a12 { } +>a12 : a12 + +export class x { } +>x : x + +export class x11 { } +>x11 : x11 + +export class m { } +>m : m + +export class a1 { } +>a1 : a1 + +export class x1 { } +>x1 : x1 + +export class a111 { } +>a111 : a111 + +export class x111 { } +>x111 : x111 + +export class z1 { } +>z1 : z1 + +export class z2 { } +>z2 : z2 + +export class aaaa { } +>aaaa : aaaa + +export class aaaa1 { } +>aaaa1 : aaaa1 + +=== tests/cases/compiler/client.ts === +import { } from "server"; +import { a } from "server"; +>a : typeof a + +export var xxxx = new a(); +>xxxx : a +>new a() : a +>a : typeof a + +import { a11 as b } from "server"; +>a11 : typeof b +>b : typeof b + +export var xxxx1 = new b(); +>xxxx1 : b +>new b() : b +>b : typeof b + +import { x, a12 as y } from "server"; +>x : typeof x +>a12 : typeof y +>y : typeof y + +export var xxxx2 = new x(); +>xxxx2 : x +>new x() : x +>x : typeof x + +export var xxxx3 = new y(); +>xxxx3 : y +>new y() : y +>y : typeof y + +import { x11 as z, } from "server"; +>x11 : typeof z +>z : typeof z + +export var xxxx4 = new z(); +>xxxx4 : z +>new z() : z +>z : typeof z + +import { m, } from "server"; +>m : typeof m + +export var xxxx5 = new m(); +>xxxx5 : m +>new m() : m +>m : typeof m + +import { a1, x1 } from "server"; +>a1 : typeof a1 +>x1 : typeof x1 + +export var xxxx6 = new a1(); +>xxxx6 : a1 +>new a1() : a1 +>a1 : typeof a1 + +export var xxxx7 = new x1(); +>xxxx7 : x1 +>new x1() : x1 +>x1 : typeof x1 + +import { a111 as a11, x111 as x11 } from "server"; +>a111 : typeof a11 +>a11 : typeof a11 +>x111 : typeof x11 +>x11 : typeof x11 + +export var xxxx8 = new a11(); +>xxxx8 : a11 +>new a11() : a11 +>a11 : typeof a11 + +export var xxxx9 = new x11(); +>xxxx9 : x11 +>new x11() : x11 +>x11 : typeof x11 + +import { z1 } from "server"; +>z1 : typeof z1 + +export var z111 = new z1(); +>z111 : z1 +>new z1() : z1 +>z1 : typeof z1 + +import { z2 as z3 } from "server"; +>z2 : typeof z3 +>z3 : typeof z3 + +export var z2 = new z3(); // z2 shouldn't give redeclare error +>z2 : z3 +>new z3() : z3 +>z3 : typeof z3 + +// not referenced +import { aaaa } from "server"; +>aaaa : typeof aaaa + +import { aaaa1 as bbbb } from "server"; +>aaaa1 : typeof bbbb +>bbbb : typeof bbbb + diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js index 66f8ce0ef9268..9992508c00be5 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -7,16 +7,39 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImportInEs5_1.ts] import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImportInEs5_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImportInEs5_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImportInEs5_0"; +var xxxx = z; import { m, } from "es6ImportNamedImportInEs5_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportInEs5_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; + //// [es6ImportNamedImportInEs5_0.js] exports.a = 10; @@ -24,4 +47,40 @@ exports.x = exports.a; exports.m = exports.a; exports.a1 = 10; exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; //// [es6ImportNamedImportInEs5_1.js] +var es6ImportNamedImportInEs5_0_1 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_1.a; +var es6ImportNamedImportInEs5_0_2 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_2.a; +var es6ImportNamedImportInEs5_0_3 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_3.x; +var xxxx = es6ImportNamedImportInEs5_0_3.a; +var es6ImportNamedImportInEs5_0_4 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_4.x; +var es6ImportNamedImportInEs5_0_5 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_5.m; +var es6ImportNamedImportInEs5_0_6 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_6.a1; +var xxxx = es6ImportNamedImportInEs5_0_6.x1; +var es6ImportNamedImportInEs5_0_7 = require("es6ImportNamedImportInEs5_0"); +var xxxx = es6ImportNamedImportInEs5_0_7.a1; +var xxxx = es6ImportNamedImportInEs5_0_7.x1; +var es6ImportNamedImportInEs5_0_8 = require("es6ImportNamedImportInEs5_0"); +var z111 = es6ImportNamedImportInEs5_0_8.z1; +var es6ImportNamedImportInEs5_0_9 = require("es6ImportNamedImportInEs5_0"); +var z2 = es6ImportNamedImportInEs5_0_9.z2; // z2 shouldn't give redeclare error + + +//// [es6ImportNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types index 334ae905e952e..f60644b262103 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.types +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -17,34 +17,107 @@ export var a1 = 10; export var x1 = 10; >x1 : number +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + === tests/cases/compiler/es6ImportNamedImportInEs5_1.ts === import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; >a : number +var xxxx = a; +>xxxx : number +>a : number + import { a as b } from "es6ImportNamedImportInEs5_0"; >a : number >b : number +var xxxx = b; +>xxxx : number +>b : number + import { x, a as y } from "es6ImportNamedImportInEs5_0"; >x : number >a : number >y : number +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + import { x as z, } from "es6ImportNamedImportInEs5_0"; >x : number >z : number +var xxxx = z; +>xxxx : number +>z : number + import { m, } from "es6ImportNamedImportInEs5_0"; >m : number +var xxxx = m; +>xxxx : number +>m : number + import { a1, x1 } from "es6ImportNamedImportInEs5_0"; >a1 : number >x1 : number +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; >a1 : number >a11 : number >x1 : number >x11 : number +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportInEs5_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +>z2 : number +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; +>aaaa : number +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt new file mode 100644 index 0000000000000..41d3f160938eb --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt @@ -0,0 +1,14 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts (1 errors) ==== + import { a } from "es6ImportNamedImportInExportAssignment_0"; + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js index cd2d5ef6922e8..ea9e65db34aab 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -9,29 +9,14 @@ import { a } from "es6ImportNamedImportInExportAssignment_0"; export = a; //// [es6ImportNamedImportInExportAssignment_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportNamedImportInExportAssignment_1.js] -var _es6ImportNamedImportInExportAssignment_0 = require("es6ImportNamedImportInExportAssignment_0"); -module.exports = _es6ImportNamedImportInExportAssignment_0.a; +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export default a; //// [es6ImportNamedImportInExportAssignment_0.d.ts] export declare var a: number; //// [es6ImportNamedImportInExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; export = a; - - -//// [DtsFileErrors] - - -tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.d.ts(1,10): error TS2304: Cannot find name 'a'. - - -==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.d.ts (0 errors) ==== - export declare var a: number; - -==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.d.ts (1 errors) ==== - export = a; - ~ -!!! error TS2304: Cannot find name 'a'. - \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types deleted file mode 100644 index cd72f35c8bf8b..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types +++ /dev/null @@ -1,12 +0,0 @@ -=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts === -import { a } from "es6ImportNamedImportInExportAssignment_0"; ->a : number - -export = a; ->a : number - diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt deleted file mode 100644 index e896a1a88a143..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts(2,12): error TS4000: Import declaration 'x' is using private name 'a'. - - -==== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_0.ts (0 errors) ==== - - export module a { - export class c { - } - } - -==== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts (1 errors) ==== - import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; - import x = a; - ~ -!!! error TS4000: Import declaration 'x' is using private name 'a'. - export = x; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js index 332be6074ad40..f457e31f53c82 100644 --- a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -23,8 +23,8 @@ var a; a.c = c; })(a = exports.a || (exports.a = {})); //// [es6ImportNamedImportInIndirectExportAssignment_1.js] -var _es6ImportNamedImportInIndirectExportAssignment_0 = require("es6ImportNamedImportInIndirectExportAssignment_0"); -var x = _es6ImportNamedImportInIndirectExportAssignment_0.a; +var es6ImportNamedImportInIndirectExportAssignment_0_1 = require("es6ImportNamedImportInIndirectExportAssignment_0"); +var x = es6ImportNamedImportInIndirectExportAssignment_0_1.a; module.exports = x; @@ -33,3 +33,7 @@ export declare module a { class c { } } +//// [es6ImportNamedImportInIndirectExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types new file mode 100644 index 0000000000000..36792ece82e45 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_0.ts === + +export module a { +>a : typeof a + + export class c { +>c : c + } +} + +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts === +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +>a : typeof a + +import x = a; +>x : typeof a +>a : typeof a + +export = x; +>x : typeof a + diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..ff8fe604622ea --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt @@ -0,0 +1,77 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(13,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(16,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(19,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(21,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(25,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(26,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export var a1 = 10; + export var x1 = 10; + export var z1 = 10; + export var z2 = 10; + export var aaaa = 10; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export import { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a; + export import { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = b; + export import { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = x; + export var xxxx = y; + export import { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = z; + export import { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = m; + export import { a1, x1 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a1; + export var xxxx = x1; + export import { a1 as a11, x1 as x11 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a11; + export var xxxx = x11; + export import { z1 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var z111 = z1; + export import { z2 as z3 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var z2 = z3; // z2 shouldn't give redeclare error + + // Non referenced imports + export import { aaaa } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export import { aaaa as bbbb } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.js b/tests/baselines/reference/es6ImportNamedImportWithExport.js new file mode 100644 index 0000000000000..60ba6bf706be4 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.js @@ -0,0 +1,97 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [client.ts] +export import { } from "server"; +export import { a } from "server"; +export var xxxx = a; +export import { a as b } from "server"; +export var xxxx = b; +export import { x, a as y } from "server"; +export var xxxx = x; +export var xxxx = y; +export import { x as z, } from "server"; +export var xxxx = z; +export import { m, } from "server"; +export var xxxx = m; +export import { a1, x1 } from "server"; +export var xxxx = a1; +export var xxxx = x1; +export import { a1 as a11, x1 as x11 } from "server"; +export var xxxx = a11; +export var xxxx = x11; +export import { z1 } from "server"; +export var z111 = z1; +export import { z2 as z3 } from "server"; +export var z2 = z3; // z2 shouldn't give redeclare error + +// Non referenced imports +export import { aaaa } from "server"; +export import { aaaa as bbbb } from "server"; + + +//// [server.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +exports.a1 = 10; +exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; +//// [client.js] +var server_1 = require("server"); +exports.xxxx = server_1.a; +var server_2 = require("server"); +exports.xxxx = server_2.a; +var server_3 = require("server"); +exports.xxxx = server_3.x; +exports.xxxx = server_3.a; +var server_4 = require("server"); +exports.xxxx = server_4.x; +var server_5 = require("server"); +exports.xxxx = server_5.m; +var server_6 = require("server"); +exports.xxxx = server_6.a1; +exports.xxxx = server_6.x1; +var server_7 = require("server"); +exports.xxxx = server_7.a1; +exports.xxxx = server_7.x1; +var server_8 = require("server"); +exports.z111 = server_8.z1; +var server_9 = require("server"); +exports.z2 = server_9.z2; // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [client.d.ts] +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var z111: number; +export declare var z2: number; diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js new file mode 100644 index 0000000000000..dcf99c5359a81 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js @@ -0,0 +1,59 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts] //// + +//// [server.ts] + +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export class C implements I { + prop = "hello"; +} +export class C2 implements I2 { + prop2 = "world"; +} + +//// [client.ts] +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +export type cValInterface = I; +export var cVal = new C(); + +//// [server.js] +var C = (function () { + function C() { + this.prop = "hello"; + } + return C; +})(); +exports.C = C; +var C2 = (function () { + function C2() { + this.prop2 = "world"; + } + return C2; +})(); +exports.C2 = C2; +//// [client.js] +var server_1 = require("server"); // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +exports.cVal = new server_1.C(); + + +//// [server.d.ts] +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export declare class C implements I { + prop: string; +} +export declare class C2 implements I2 { + prop2: string; +} +//// [client.d.ts] +import { C, I } from "server"; +export declare type cValInterface = I; +export declare var cVal: C; diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types new file mode 100644 index 0000000000000..62917e5ff36b5 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/server.ts === + +export interface I { +>I : I + + prop: string; +>prop : string +} +export interface I2 { +>I2 : I2 + + prop2: string; +>prop2 : string +} +export class C implements I { +>C : C +>I : I + + prop = "hello"; +>prop : string +} +export class C2 implements I2 { +>C2 : C2 +>I2 : I2 + + prop2 = "world"; +>prop2 : string +} + +=== tests/cases/compiler/client.ts === +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +>C : typeof C +>I : unknown +>C2 : typeof C2 + +export type cValInterface = I; +>cValInterface : I +>I : I + +export var cVal = new C(); +>cVal : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js new file mode 100644 index 0000000000000..7b10da7cc9fc3 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts] //// + +//// [es6ImportWithoutFromClauseAmd_0.ts] + +export var a = 10; + +//// [es6ImportWithoutFromClauseAmd_1.ts] +export var b = 10; + +//// [es6ImportWithoutFromClauseAmd_2.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; + +//// [es6ImportWithoutFromClauseAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportWithoutFromClauseAmd_1.js] +define(["require", "exports"], function (require, exports) { + exports.b = 10; +}); +//// [es6ImportWithoutFromClauseAmd_2.js] +define(["require", "exports", "es6ImportWithoutFromClauseAmd_0", "es6ImportWithoutFromClauseAmd_2"], function (require, exports, , ) { + var _a = 10; + var _b = 10; +}); + + +//// [es6ImportWithoutFromClauseAmd_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseAmd_1.d.ts] +export declare var b: number; +//// [es6ImportWithoutFromClauseAmd_2.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types new file mode 100644 index 0000000000000..c3d09388916bc --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_1.ts === +export var b = 10; +>b : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_2.ts === +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +>_a : number + +var _b = 10; +>_b : number + diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index f6610ac5ad295..aacb936ab3619 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -11,3 +11,8 @@ import "es6ImportWithoutFromClauseInEs5_0"; exports.a = 10; //// [es6ImportWithoutFromClauseInEs5_1.js] require("es6ImportWithoutFromClauseInEs5_0"); + + +//// [es6ImportWithoutFromClauseInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt new file mode 100644 index 0000000000000..da865698e56a8 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js new file mode 100644 index 0000000000000..208f71bcbfe9f --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import "server"; + +//// [server.js] +exports.a = 10; +//// [client.js] +require("server"); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export import "server"; diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.js b/tests/baselines/reference/es6ModuleEnumDeclaration.js index 955fe3ed8d3f8..0879214981896 100644 --- a/tests/baselines/reference/es6ModuleEnumDeclaration.js +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.js @@ -59,8 +59,8 @@ var e2; e2[e2["y"] = 1] = "y"; e2[e2["z"] = 2] = "z"; })(e2 || (e2 = {})); -var x = 0 /* a */; -var y = 0 /* x */; +var x = e1.a; +var y = e2.x; var m1; (function (m1) { (function (e3) { @@ -75,10 +75,10 @@ var m1; e4[e4["y"] = 1] = "y"; e4[e4["z"] = 2] = "z"; })(e4 || (e4 = {})); - var x1 = 0 /* a */; - var y1 = 0 /* x */; - var x2 = 0 /* a */; - var y2 = 0 /* x */; + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; })(m1 || (m1 = {})); export { m1 }; var m2; @@ -95,9 +95,9 @@ var m2; e6[e6["y"] = 1] = "y"; e6[e6["z"] = 2] = "z"; })(e6 || (e6 = {})); - var x1 = 0 /* a */; - var y1 = 0 /* x */; - var x2 = 0 /* a */; - var y2 = 0 /* x */; - var x3 = 0 /* a */; + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; })(m2 || (m2 = {})); diff --git a/tests/baselines/reference/exportAssignmentEnum.js b/tests/baselines/reference/exportAssignmentEnum.js index 7b9981d97337c..a484e43738fda 100644 --- a/tests/baselines/reference/exportAssignmentEnum.js +++ b/tests/baselines/reference/exportAssignmentEnum.js @@ -26,6 +26,6 @@ var E; module.exports = E; //// [exportAssignmentEnum_B.js] var EnumE = require("exportAssignmentEnum_A"); -var a = 0 /* A */; -var b = 1 /* B */; -var c = 2 /* C */; +var a = EnumE.A; +var b = EnumE.B; +var c = EnumE.C; diff --git a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js index fe6b80292d5e5..791fc4fbd7f96 100644 --- a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js +++ b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js @@ -34,7 +34,7 @@ define(["require", "exports"], function (require, exports) { //// [foo_1.js] define(["require", "exports", "./foo_0"], function (require, exports, foo) { var color; - if (color === 1 /* green */) { + if (color === foo.green) { color = foo.answer; } }); diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation3.js b/tests/baselines/reference/exportDefaultTypeAnnoation3.js index 069c8385e77e6..b29e7d2d9bc06 100644 --- a/tests/baselines/reference/exportDefaultTypeAnnoation3.js +++ b/tests/baselines/reference/exportDefaultTypeAnnoation3.js @@ -18,5 +18,5 @@ var s: string = d; // Error var d = require("mod"); var s = d; // Error //// [reference2.js] -var _mod = require("mod"); -var s = _mod.default; // Error +var mod_1 = require("mod"); +var s = mod_1.default; // Error diff --git a/tests/baselines/reference/externalModuleImmutableBindings.errors.txt b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt new file mode 100644 index 0000000000000..09cc7b3329578 --- /dev/null +++ b/tests/baselines/reference/externalModuleImmutableBindings.errors.txt @@ -0,0 +1,164 @@ +tests/cases/compiler/f2.ts(5,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(6,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(7,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(7,7): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(8,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(10,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(11,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(12,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(13,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(15,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(16,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(17,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(17,8): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(18,1): error TS2364: Invalid left-hand side of assignment expression. +tests/cases/compiler/f2.ts(20,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(21,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(22,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(23,1): error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. +tests/cases/compiler/f2.ts(25,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(26,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(27,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(28,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(29,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(29,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(30,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(30,12): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(31,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(32,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(34,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(35,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(36,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. +tests/cases/compiler/f2.ts(37,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(38,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(38,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(39,6): error TS2487: Invalid left-hand side in 'for...of' statement. +tests/cases/compiler/f2.ts(39,13): error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. +tests/cases/compiler/f2.ts(40,6): error TS2406: Invalid left-hand side in 'for...in' statement. +tests/cases/compiler/f2.ts(41,6): error TS2487: Invalid left-hand side in 'for...of' statement. + + +==== tests/cases/compiler/f1.ts (0 errors) ==== + export var x = 1; + +==== tests/cases/compiler/f2.ts (38 errors) ==== + import * as stuff from 'f1'; + + var n = 'baz'; + + stuff.x = 0; + ~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + stuff['x'] = 1; + ~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + stuff.blah = 2; + ~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + stuff[n] = 3; + ~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + + stuff.x++; + ~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + stuff['x']++; + ~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + stuff['blah']++; + ~~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + stuff[n]++; + ~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + (stuff.x) = 0; + ~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + (stuff['x']) = 1; + ~~~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + (stuff.blah) = 2; + ~~~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + (stuff[n]) = 3; + ~~~~~~~~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + + (stuff.x)++; + ~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + (stuff['x'])++; + ~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + (stuff['blah'])++; + ~~~~~~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + (stuff[n])++; + ~~~~~~~~~~ +!!! error TS2357: The operand of an increment or decrement operator must be a variable, property or indexer. + + for (stuff.x in []) {} + ~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for (stuff.x of []) {} + ~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for (stuff['x'] in []) {} + ~~~~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for (stuff['x'] of []) {} + ~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for (stuff.blah in []) {} + ~~~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for (stuff.blah of []) {} + ~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for (stuff[n] in []) {} + ~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + for (stuff[n] of []) {} + ~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + + for ((stuff.x) in []) {} + ~~~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for ((stuff.x) of []) {} + ~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for ((stuff['x']) in []) {} + ~~~~~~~~~~~~ +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. + for ((stuff['x']) of []) {} + ~~~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + for ((stuff.blah) in []) {} + ~~~~~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for ((stuff.blah) of []) {} + ~~~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + ~~~~ +!!! error TS2339: Property 'blah' does not exist on type 'typeof "tests/cases/compiler/f1"'. + for ((stuff[n]) in []) {} + ~~~~~~~~~~ +!!! error TS2406: Invalid left-hand side in 'for...in' statement. + for ((stuff[n]) of []) {} + ~~~~~~~~~~ +!!! error TS2487: Invalid left-hand side in 'for...of' statement. + + + \ No newline at end of file diff --git a/tests/baselines/reference/externalModuleImmutableBindings.js b/tests/baselines/reference/externalModuleImmutableBindings.js new file mode 100644 index 0000000000000..546b593fa77b7 --- /dev/null +++ b/tests/baselines/reference/externalModuleImmutableBindings.js @@ -0,0 +1,112 @@ +//// [tests/cases/compiler/externalModuleImmutableBindings.ts] //// + +//// [f1.ts] +export var x = 1; + +//// [f2.ts] +import * as stuff from 'f1'; + +var n = 'baz'; + +stuff.x = 0; +stuff['x'] = 1; +stuff.blah = 2; +stuff[n] = 3; + +stuff.x++; +stuff['x']++; +stuff['blah']++; +stuff[n]++; + +(stuff.x) = 0; +(stuff['x']) = 1; +(stuff.blah) = 2; +(stuff[n]) = 3; + +(stuff.x)++; +(stuff['x'])++; +(stuff['blah'])++; +(stuff[n])++; + +for (stuff.x in []) {} +for (stuff.x of []) {} +for (stuff['x'] in []) {} +for (stuff['x'] of []) {} +for (stuff.blah in []) {} +for (stuff.blah of []) {} +for (stuff[n] in []) {} +for (stuff[n] of []) {} + +for ((stuff.x) in []) {} +for ((stuff.x) of []) {} +for ((stuff['x']) in []) {} +for ((stuff['x']) of []) {} +for ((stuff.blah) in []) {} +for ((stuff.blah) of []) {} +for ((stuff[n]) in []) {} +for ((stuff[n]) of []) {} + + + + +//// [f1.js] +exports.x = 1; +//// [f2.js] +var stuff = require('f1'); +var n = 'baz'; +stuff.x = 0; +stuff['x'] = 1; +stuff.blah = 2; +stuff[n] = 3; +stuff.x++; +stuff['x']++; +stuff['blah']++; +stuff[n]++; +(stuff.x) = 0; +(stuff['x']) = 1; +(stuff.blah) = 2; +(stuff[n]) = 3; +(stuff.x)++; +(stuff['x'])++; +(stuff['blah'])++; +(stuff[n])++; +for (stuff.x in []) { +} +for (var _i = 0, _a = []; _i < _a.length; _i++) { + stuff.x = _a[_i]; +} +for (stuff['x'] in []) { +} +for (var _b = 0, _c = []; _b < _c.length; _b++) { + stuff['x'] = _c[_b]; +} +for (stuff.blah in []) { +} +for (var _d = 0, _e = []; _d < _e.length; _d++) { + stuff.blah = _e[_d]; +} +for (stuff[n] in []) { +} +for (var _f = 0, _g = []; _f < _g.length; _f++) { + stuff[n] = _g[_f]; +} +for ((stuff.x) in []) { +} +for (var _h = 0, _j = []; _h < _j.length; _h++) { + (stuff.x) = _j[_h]; +} +for ((stuff['x']) in []) { +} +for (var _k = 0, _l = []; _k < _l.length; _k++) { + (stuff['x']) = _l[_k]; +} +for ((stuff.blah) in []) { +} +for (var _m = 0, _o = []; _m < _o.length; _m++) { + (stuff.blah) = _o[_m]; +} +for ((stuff[n]) in []) { +} +for (var _p = 0, _q = []; _p < _q.length; _p++) { + (stuff[n]) = _q[_p]; +} diff --git a/tests/baselines/reference/fileWithNextLine1.js b/tests/baselines/reference/fileWithNextLine1.js new file mode 100644 index 0000000000000..a89c5b3e2077d --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine1.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine1.ts] +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = '…'; + +//// [fileWithNextLine1.js] +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = '…'; diff --git a/tests/baselines/reference/fileWithNextLine1.types b/tests/baselines/reference/fileWithNextLine1.types new file mode 100644 index 0000000000000..721b3d6fb101e --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine1.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/fileWithNextLine1.ts === +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = '…'; +>v : string + diff --git a/tests/baselines/reference/fileWithNextLine2.js b/tests/baselines/reference/fileWithNextLine2.js new file mode 100644 index 0000000000000..439b9bd42f902 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine2.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine2.ts] +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v =…0; + +//// [fileWithNextLine2.js] +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v = 0; diff --git a/tests/baselines/reference/fileWithNextLine2.types b/tests/baselines/reference/fileWithNextLine2.types new file mode 100644 index 0000000000000..8a6de1a4b2f99 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/fileWithNextLine2.ts === +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v =…0; +>v : number + diff --git a/tests/baselines/reference/fileWithNextLine3.errors.txt b/tests/baselines/reference/fileWithNextLine3.errors.txt new file mode 100644 index 0000000000000..647ec722549ab --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine3.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/fileWithNextLine3.ts(3,1): error TS1108: A 'return' statement can only be used within a function body. + + +==== tests/cases/compiler/fileWithNextLine3.ts (1 errors) ==== + // Note: there is a nextline (0x85) between the return and the + // 0. It should be counted as a space and should not trigger ASI + return…0; + ~~~~~~ +!!! error TS1108: A 'return' statement can only be used within a function body. \ No newline at end of file diff --git a/tests/baselines/reference/fileWithNextLine3.js b/tests/baselines/reference/fileWithNextLine3.js new file mode 100644 index 0000000000000..c1d4204bcaeea --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine3.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine3.ts] +// Note: there is a nextline (0x85) between the return and the +// 0. It should be counted as a space and should not trigger ASI +return…0; + +//// [fileWithNextLine3.js] +// Note: there is a nextline (0x85) between the return and the +// 0. It should be counted as a space and should not trigger ASI +return 0; diff --git a/tests/baselines/reference/for-inStatements.js b/tests/baselines/reference/for-inStatements.js index 08ef1dbcccd15..3787887923cd7 100644 --- a/tests/baselines/reference/for-inStatements.js +++ b/tests/baselines/reference/for-inStatements.js @@ -200,5 +200,5 @@ var Color; })(Color || (Color = {})); for (var x in Color) { } -for (var x in 1 /* Blue */) { +for (var x in Color.Blue) { } diff --git a/tests/baselines/reference/for-of47.js b/tests/baselines/reference/for-of47.js index f5e03dce571c2..f1e9295c3676f 100644 --- a/tests/baselines/reference/for-of47.js +++ b/tests/baselines/reference/for-of47.js @@ -21,7 +21,7 @@ var E; })(E || (E = {})); for ({ x, - y: y = 0 /* x */ + y: y = E.x } of array) { x; y; diff --git a/tests/baselines/reference/for-of48.js b/tests/baselines/reference/for-of48.js index 3b96f460e97ec..3030f07e605ae 100644 --- a/tests/baselines/reference/for-of48.js +++ b/tests/baselines/reference/for-of48.js @@ -21,7 +21,7 @@ var E; })(E || (E = {})); for ({ x, - y: = 0 /* x */ + y: = E.x } of array) { x; y; diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js index 4c0d57b9acfce..758852a918bc4 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js @@ -125,10 +125,10 @@ var onlyT; var r; return r; } - var r7 = foo3(0 /* A */, function (x) { - return 0 /* A */; + var r7 = foo3(E.A, function (x) { + return E.A; }, function (x) { - return 0 /* A */; + return F.A; }); // error })(onlyT || (onlyT = {})); var TU; @@ -179,9 +179,9 @@ var TU; var r; return r; } - var r7 = foo3(0 /* A */, function (x) { - return 0 /* A */; + var r7 = foo3(E.A, function (x) { + return E.A; }, function (x) { - return 0 /* A */; + return F.A; }); })(TU || (TU = {})); diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js index 8f691d936ec3b..b7cc833b9d903 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js @@ -78,10 +78,10 @@ var F; (function (F) { F[F["A"] = 0] = "A"; })(F || (F = {})); -var r6 = foo(0 /* A */, function (x) { - return 0 /* A */; +var r6 = foo(E.A, function (x) { + return E.A; }, function (x) { - return 0 /* A */; + return F.A; }); // number => number function foo2(x, a, b) { var r; diff --git a/tests/baselines/reference/giant.js b/tests/baselines/reference/giant.js index 9de46f76b1bb8..cc532ff43d955 100644 --- a/tests/baselines/reference/giant.js +++ b/tests/baselines/reference/giant.js @@ -754,7 +754,7 @@ define(["require", "exports"], function (require, exports) { return C; })(); var M; - (function (_M) { + (function (M_1) { var V; function F() { } @@ -844,10 +844,10 @@ define(["require", "exports"], function (require, exports) { ; ; })(M || (M = {})); - _M.eV; + M_1.eV; function eF() { } - _M.eF = eF; + M_1.eF = eF; ; var eC = (function () { function eC() { @@ -902,7 +902,7 @@ define(["require", "exports"], function (require, exports) { }); return eC; })(); - _M.eC = eC; + M_1.eC = eC; var eM; (function (eM) { var V; @@ -934,7 +934,7 @@ define(["require", "exports"], function (require, exports) { ; ; ; - })(eM = _M.eM || (_M.eM = {})); + })(eM = M_1.eM || (M_1.eM = {})); ; })(M || (M = {})); exports.eV; @@ -997,7 +997,7 @@ define(["require", "exports"], function (require, exports) { })(); exports.eC = eC; var eM; - (function (_eM) { + (function (eM_1) { var V; function F() { } @@ -1087,10 +1087,10 @@ define(["require", "exports"], function (require, exports) { ; ; })(M || (M = {})); - _eM.eV; + eM_1.eV; function eF() { } - _eM.eF = eF; + eM_1.eF = eF; ; var eC = (function () { function eC() { @@ -1145,7 +1145,7 @@ define(["require", "exports"], function (require, exports) { }); return eC; })(); - _eM.eC = eC; + eM_1.eC = eC; var eM; (function (eM) { var V; @@ -1177,7 +1177,7 @@ define(["require", "exports"], function (require, exports) { ; ; ; - })(eM = _eM.eM || (_eM.eM = {})); + })(eM = eM_1.eM || (eM_1.eM = {})); ; })(eM = exports.eM || (exports.eM = {})); ; diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict1.js b/tests/baselines/reference/importAndVariableDeclarationConflict1.js index 78484b2c295a1..b812deec0ef45 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict1.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict1.js @@ -9,8 +9,8 @@ var x = ''; //// [importAndVariableDeclarationConflict1.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = m.m; var x = ''; diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict2.js b/tests/baselines/reference/importAndVariableDeclarationConflict2.js index bea146fe9bf0e..6d188b373b74a 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict2.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict2.js @@ -13,8 +13,8 @@ class C { //// [importAndVariableDeclarationConflict2.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = m.m; var C = (function () { diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict3.js b/tests/baselines/reference/importAndVariableDeclarationConflict3.js index 426d44bab2173..887aec16c59b0 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict3.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict3.js @@ -9,8 +9,8 @@ import x = m.m; //// [importAndVariableDeclarationConflict3.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = m.m; var x = m.m; diff --git a/tests/baselines/reference/importAndVariableDeclarationConflict4.js b/tests/baselines/reference/importAndVariableDeclarationConflict4.js index 2adb78594a23a..4949df6366a42 100644 --- a/tests/baselines/reference/importAndVariableDeclarationConflict4.js +++ b/tests/baselines/reference/importAndVariableDeclarationConflict4.js @@ -9,8 +9,8 @@ import x = m.m; //// [importAndVariableDeclarationConflict4.js] var m; -(function (_m) { - _m.m = ''; +(function (m_1) { + m_1.m = ''; })(m || (m = {})); var x = ''; var x = m.m; diff --git a/tests/baselines/reference/importedModuleAddToGlobal.js b/tests/baselines/reference/importedModuleAddToGlobal.js index 6685bec69e374..a848ccb504bde 100644 --- a/tests/baselines/reference/importedModuleAddToGlobal.js +++ b/tests/baselines/reference/importedModuleAddToGlobal.js @@ -18,13 +18,13 @@ module C { //// [importedModuleAddToGlobal.js] var B; -(function (_B) { +(function (B_1) { var B = (function () { function B() { } return B; })(); - _B.B = B; + B_1.B = B; })(B || (B = {})); var C; (function (C) { diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.js b/tests/baselines/reference/inOperatorWithInvalidOperands.js index 29293f880ed94..005681b62857b 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.js @@ -61,7 +61,7 @@ var ra3 = a3 in x; var ra4 = a4 in x; var ra5 = null in x; var ra6 = undefined in x; -var ra7 = 0 /* a */ in x; +var ra7 = E.a in x; var ra8 = false in x; var ra9 = {} in x; // invalid right operands diff --git a/tests/baselines/reference/incrementAndDecrement.js b/tests/baselines/reference/incrementAndDecrement.js index 96794e3c956d2..09c0b3ae490bf 100644 --- a/tests/baselines/reference/incrementAndDecrement.js +++ b/tests/baselines/reference/incrementAndDecrement.js @@ -70,7 +70,7 @@ var E; })(E || (E = {})); ; var x = 4; -var e = 1 /* B */; +var e = E.B; var a; var w = window; // Assign to expression++ diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.js b/tests/baselines/reference/incrementOperatorWithEnumType.js index 590815ffec55a..e3e843a45da57 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.js +++ b/tests/baselines/reference/incrementOperatorWithEnumType.js @@ -22,8 +22,8 @@ var ENUM1; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = ++1 /* "B" */; -var ResultIsNumber2 = 1 /* B */++; +var ResultIsNumber1 = ++ENUM1["B"]; +var ResultIsNumber2 = ENUM1.B++; // miss assignment operator -++1 /* "B" */; -1 /* B */++; +++ENUM1["B"]; +ENUM1.B++; diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.js b/tests/baselines/reference/initializePropertiesWithRenamedLet.js index 902a23f5886e0..1d34d7c13fc86 100644 --- a/tests/baselines/reference/initializePropertiesWithRenamedLet.js +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.js @@ -19,28 +19,28 @@ if (true) { //// [initializePropertiesWithRenamedLet.js] var x0; if (true) { - var _x0; + var x0_1; var obj1 = { - x0: _x0 + x0: x0_1 }; var obj2 = { - x0: _x0 + x0: x0_1 }; } var x, y, z; if (true) { - var _x = ({ + var x_1 = ({ x: 0 }).x; - var _y = ({ + var y_1 = ({ y: 0 }).y; - var _z; + var z_1; (_a = { z: 0 - }, _z = _a.z, _a); + }, z_1 = _a.z, _a); (_b = { z: 0 - }, _z = _b.z, _b); + }, z_1 = _b.z, _b); } var _a, _b; diff --git a/tests/baselines/reference/instantiatedModule.js b/tests/baselines/reference/instantiatedModule.js index 7993628f89897..2b1871aea9d75 100644 --- a/tests/baselines/reference/instantiatedModule.js +++ b/tests/baselines/reference/instantiatedModule.js @@ -115,7 +115,7 @@ var m3 = M3; var a3; var a3 = m3.Color; var a3 = M3.Color; -var blue = 0 /* Blue */; +var blue = a3.Blue; var p3; -var p3 = 1 /* Red */; -var p3 = 0 /* Blue */; +var p3 = M3.Color.Red; +var p3 = m3.Color.Blue; diff --git a/tests/baselines/reference/interfaceAssignmentCompat.js b/tests/baselines/reference/interfaceAssignmentCompat.js index dbad8eabd78d5..7ddd22ee863eb 100644 --- a/tests/baselines/reference/interfaceAssignmentCompat.js +++ b/tests/baselines/reference/interfaceAssignmentCompat.js @@ -73,13 +73,13 @@ var M; var x = []; var result = ""; x[0] = { - color: 2 /* Brown */ + color: Color.Brown }; x[1] = { - color: 1 /* Blue */ + color: Color.Blue }; x[2] = { - color: 0 /* Green */ + color: Color.Green }; x = x.sort(CompareYeux); // parameter mismatch // type of z inferred from specialized array type diff --git a/tests/baselines/reference/interfaceWithPropertyOfEveryType.js b/tests/baselines/reference/interfaceWithPropertyOfEveryType.js index 4f8d8919563fb..e10b83297bccd 100644 --- a/tests/baselines/reference/interfaceWithPropertyOfEveryType.js +++ b/tests/baselines/reference/interfaceWithPropertyOfEveryType.js @@ -79,5 +79,5 @@ var a = { l: f1, m: M, n: {}, - o: 0 /* A */ + o: E.A }; diff --git a/tests/baselines/reference/internalAliasEnum.js b/tests/baselines/reference/internalAliasEnum.js index b5c68ea5c1663..6400cf26ddcff 100644 --- a/tests/baselines/reference/internalAliasEnum.js +++ b/tests/baselines/reference/internalAliasEnum.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c || (c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js index e21dd35532271..f2223b197e00f 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { c.b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = c.b.Sunday; })(c = exports.c || (exports.c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js index 3d60e055edeed..afd6597869be6 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c = exports.c || (exports.c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js index f050d6f9a553c..acd3f4c61b185 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js @@ -27,6 +27,6 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c = exports.c || (exports.c = {})); var happyFriday = c.b.Friday; diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js index e4dc73b2403f2..96e17c6f6e305 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js @@ -23,7 +23,7 @@ define(["require", "exports"], function (require, exports) { var weekend = a.weekend; })(a = exports.a || (exports.a = {})); exports.b = a.weekend; - exports.bVal = 2 /* Sunday */; + exports.bVal = exports.b.Sunday; }); diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js index e81093147e881..b224c22f45e1a 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js @@ -23,7 +23,7 @@ define(["require", "exports"], function (require, exports) { var weekend = a.weekend; })(a = exports.a || (exports.a = {})); var b = a.weekend; - exports.bVal = 2 /* Sunday */; + exports.bVal = b.Sunday; }); diff --git a/tests/baselines/reference/invalidEnumAssignments.js b/tests/baselines/reference/invalidEnumAssignments.js index b9bb9e12cedd6..dfdd0600ed0ce 100644 --- a/tests/baselines/reference/invalidEnumAssignments.js +++ b/tests/baselines/reference/invalidEnumAssignments.js @@ -35,8 +35,8 @@ var E2; })(E2 || (E2 = {})); var e; var e2; -e = 0 /* A */; -e2 = 0 /* A */; +e = E2.A; +e2 = E.A; e = null; e = {}; e = ''; diff --git a/tests/baselines/reference/invalidUndefinedAssignments.js b/tests/baselines/reference/invalidUndefinedAssignments.js index 0b37316e0855d..7617e5eae8e2c 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.js +++ b/tests/baselines/reference/invalidUndefinedAssignments.js @@ -28,7 +28,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); E = x; -0 /* A */ = x; +E.A = x; var C = (function () { function C() { } diff --git a/tests/baselines/reference/invalidUndefinedValues.js b/tests/baselines/reference/invalidUndefinedValues.js index b4751cf25d817..9361f43bbae68 100644 --- a/tests/baselines/reference/invalidUndefinedValues.js +++ b/tests/baselines/reference/invalidUndefinedValues.js @@ -67,4 +67,4 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; diff --git a/tests/baselines/reference/invalidVoidAssignments.js b/tests/baselines/reference/invalidVoidAssignments.js index c8c395b0e4fdb..b821b0ca79649 100644 --- a/tests/baselines/reference/invalidVoidAssignments.js +++ b/tests/baselines/reference/invalidVoidAssignments.js @@ -58,7 +58,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; x = { f: function () { } diff --git a/tests/baselines/reference/invalidVoidValues.js b/tests/baselines/reference/invalidVoidValues.js index 6740eb3fc1bce..13f2d681f2622 100644 --- a/tests/baselines/reference/invalidVoidValues.js +++ b/tests/baselines/reference/invalidVoidValues.js @@ -36,7 +36,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; var C = (function () { function C() { } diff --git a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js index d357922f5bce6..8604ec493a2ab 100644 --- a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js +++ b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js @@ -72,67 +72,67 @@ module schema { //// [isDeclarationVisibleNodeKinds.js] // Function types var schema; -(function (_schema) { +(function (schema_1) { function createValidator1(schema) { return undefined; } - _schema.createValidator1 = createValidator1; + schema_1.createValidator1 = createValidator1; })(schema || (schema = {})); // Constructor types var schema; -(function (_schema_1) { +(function (schema_2) { function createValidator2(schema) { return undefined; } - _schema_1.createValidator2 = createValidator2; + schema_2.createValidator2 = createValidator2; })(schema || (schema = {})); // union types var schema; -(function (_schema_2) { +(function (schema_3) { function createValidator3(schema) { return undefined; } - _schema_2.createValidator3 = createValidator3; + schema_3.createValidator3 = createValidator3; })(schema || (schema = {})); // Array types var schema; -(function (_schema_3) { +(function (schema_4) { function createValidator4(schema) { return undefined; } - _schema_3.createValidator4 = createValidator4; + schema_4.createValidator4 = createValidator4; })(schema || (schema = {})); // TypeLiterals var schema; -(function (_schema_4) { +(function (schema_5) { function createValidator5(schema) { return undefined; } - _schema_4.createValidator5 = createValidator5; + schema_5.createValidator5 = createValidator5; })(schema || (schema = {})); // Tuple types var schema; -(function (_schema_5) { +(function (schema_6) { function createValidator6(schema) { return undefined; } - _schema_5.createValidator6 = createValidator6; + schema_6.createValidator6 = createValidator6; })(schema || (schema = {})); // Paren Types var schema; -(function (_schema_6) { +(function (schema_7) { function createValidator7(schema) { return undefined; } - _schema_6.createValidator7 = createValidator7; + schema_7.createValidator7 = createValidator7; })(schema || (schema = {})); // Type reference var schema; -(function (_schema_7) { +(function (schema_8) { function createValidator8(schema) { return undefined; } - _schema_7.createValidator8 = createValidator8; + schema_8.createValidator8 = createValidator8; })(schema || (schema = {})); var schema; (function (schema) { diff --git a/tests/baselines/reference/letConstInCaseClauses.js b/tests/baselines/reference/letConstInCaseClauses.js index 94840a11a2c74..33650dcaf4caf 100644 --- a/tests/baselines/reference/letConstInCaseClauses.js +++ b/tests/baselines/reference/letConstInCaseClauses.js @@ -34,28 +34,28 @@ var y = 20; var x = 10; var y = 20; { - var _x = 1; - var _y = 2; - console.log(_x); - switch (_x) { + var x_1 = 1; + var y_1 = 2; + console.log(x_1); + switch (x_1) { case 10: - var _x_1 = 20; + var x_2 = 20; } - switch (_y) { + switch (y_1) { case 10: - var _y_1 = 20; + var y_2 = 20; } } { - var _x_2 = 1; - var _y_2 = 2; - console.log(_x_2); - switch (_x_2) { + var x_3 = 1; + var y_3 = 2; + console.log(x_3); + switch (x_3) { case 10: - var _x_3 = 20; + var x_4 = 20; } - switch (_y_2) { + switch (y_3) { case 10: - var _y_3 = 20; + var y_4 = 20; } } diff --git a/tests/baselines/reference/letConstMatchingParameterNames.js b/tests/baselines/reference/letConstMatchingParameterNames.js index a11405b9f83c7..392f0e7ae943e 100644 --- a/tests/baselines/reference/letConstMatchingParameterNames.js +++ b/tests/baselines/reference/letConstMatchingParameterNames.js @@ -19,8 +19,8 @@ function a() { var parent = true; var parent2 = true; function a() { - var _parent = 1; - var _parent2 = 2; + var parent = 1; + var parent2 = 2; function b(parent, parent2) { use(parent); use(parent2); diff --git a/tests/baselines/reference/letDeclarations-es5.js b/tests/baselines/reference/letDeclarations-es5.js index 5246e91edfb76..1d4eb4afcbfef 100644 --- a/tests/baselines/reference/letDeclarations-es5.js +++ b/tests/baselines/reference/letDeclarations-es5.js @@ -20,7 +20,7 @@ var l3, l4, l5, l6; var l7 = false; var l8 = 23; var l9 = 0, l10 = "", l11 = null; -for (var _l11 in {}) { +for (var l11_1 in {}) { } for (var l12 = 0; l12 < 9; l12++) { } diff --git a/tests/baselines/reference/letKeepNamesOfTopLevelItems.js b/tests/baselines/reference/letKeepNamesOfTopLevelItems.js new file mode 100644 index 0000000000000..96fd31ae536dd --- /dev/null +++ b/tests/baselines/reference/letKeepNamesOfTopLevelItems.js @@ -0,0 +1,19 @@ +//// [letKeepNamesOfTopLevelItems.ts] +let x; +function foo() { + let x; +} + +module A { + let x; +} + +//// [letKeepNamesOfTopLevelItems.js] +var x; +function foo() { + var x; +} +var A; +(function (A) { + var x; +})(A || (A = {})); diff --git a/tests/baselines/reference/letKeepNamesOfTopLevelItems.types b/tests/baselines/reference/letKeepNamesOfTopLevelItems.types new file mode 100644 index 0000000000000..952be1512a984 --- /dev/null +++ b/tests/baselines/reference/letKeepNamesOfTopLevelItems.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/letKeepNamesOfTopLevelItems.ts === +let x; +>x : any + +function foo() { +>foo : () => void + + let x; +>x : any +} + +module A { +>A : typeof A + + let x; +>x : any +} diff --git a/tests/baselines/reference/letShadowedByNameInNestedScope.errors.txt b/tests/baselines/reference/letShadowedByNameInNestedScope.errors.txt new file mode 100644 index 0000000000000..b47e194f93eb1 --- /dev/null +++ b/tests/baselines/reference/letShadowedByNameInNestedScope.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/letShadowedByNameInNestedScope.ts(6,9): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/letShadowedByNameInNestedScope.ts (1 errors) ==== + var x; + function foo() { + let x = 0; + (function () { + var _x = 1; + console.log(x); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + })(); + } \ No newline at end of file diff --git a/tests/baselines/reference/letShadowedByNameInNestedScope.js b/tests/baselines/reference/letShadowedByNameInNestedScope.js new file mode 100644 index 0000000000000..648fe0b8e94df --- /dev/null +++ b/tests/baselines/reference/letShadowedByNameInNestedScope.js @@ -0,0 +1,19 @@ +//// [letShadowedByNameInNestedScope.ts] +var x; +function foo() { + let x = 0; + (function () { + var _x = 1; + console.log(x); + })(); +} + +//// [letShadowedByNameInNestedScope.js] +var x; +function foo() { + var x = 0; + (function () { + var _x = 1; + console.log(x); + })(); +} diff --git a/tests/baselines/reference/localImportNameVsGlobalName.js b/tests/baselines/reference/localImportNameVsGlobalName.js index f27e7d648d10c..8ba7ec567a0d9 100644 --- a/tests/baselines/reference/localImportNameVsGlobalName.js +++ b/tests/baselines/reference/localImportNameVsGlobalName.js @@ -30,7 +30,7 @@ var App; function foo(key) { } App.foo = foo; - foo(0 /* UP */); - foo(1 /* DOWN */); - foo(2 /* LEFT */); + foo(Key.UP); + foo(Key.DOWN); + foo(Key.LEFT); })(App || (App = {})); diff --git a/tests/baselines/reference/logicalNotOperatorWithEnumType.js b/tests/baselines/reference/logicalNotOperatorWithEnumType.js index 89ee1a148335a..382cf577713bc 100644 --- a/tests/baselines/reference/logicalNotOperatorWithEnumType.js +++ b/tests/baselines/reference/logicalNotOperatorWithEnumType.js @@ -37,13 +37,13 @@ var ENUM1; // enum type var var ResultIsBoolean1 = !ENUM; // enum type expressions -var ResultIsBoolean2 = !1 /* "B" */; -var ResultIsBoolean3 = !(1 /* B */ + 2 /* "C" */); +var ResultIsBoolean2 = !ENUM["B"]; +var ResultIsBoolean3 = !(ENUM.B + ENUM["C"]); // multiple ! operators var ResultIsBoolean4 = !!ENUM; -var ResultIsBoolean5 = !!!(1 /* "B" */ + 2 /* C */); +var ResultIsBoolean5 = !!!(ENUM["B"] + ENUM.C); // miss assignment operators !ENUM; !ENUM1; -!1 /* B */; +!ENUM.B; !ENUM, ENUM1; diff --git a/tests/baselines/reference/mergedDeclarations2.js b/tests/baselines/reference/mergedDeclarations2.js index 1e9254bb0bb75..962346541cc6c 100644 --- a/tests/baselines/reference/mergedDeclarations2.js +++ b/tests/baselines/reference/mergedDeclarations2.js @@ -17,7 +17,7 @@ var Foo; })(Foo || (Foo = {})); var Foo; (function (Foo) { - Foo[Foo["a"] = Foo.b] = "a"; + Foo[Foo["a"] = 0] = "a"; })(Foo || (Foo = {})); var Foo; (function (Foo) { diff --git a/tests/baselines/reference/mergedEnumDeclarationCodeGen.js b/tests/baselines/reference/mergedEnumDeclarationCodeGen.js index 574ef6fa2d040..57b6e8051f8e8 100644 --- a/tests/baselines/reference/mergedEnumDeclarationCodeGen.js +++ b/tests/baselines/reference/mergedEnumDeclarationCodeGen.js @@ -11,9 +11,9 @@ enum E { var E; (function (E) { E[E["a"] = 0] = "a"; - E[E["b"] = E.a] = "b"; + E[E["b"] = 0] = "b"; })(E || (E = {})); var E; (function (E) { - E[E["c"] = E.a] = "c"; + E[E["c"] = 0] = "c"; })(E || (E = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen.js index 88b949dd92023..d5cda7c91099d 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen.js @@ -19,10 +19,10 @@ export module X { var X; (function (X) { var Y; - (function (_Y) { + (function (Y_1) { var A = (function () { function A(Y) { - new _Y.B(); + new Y_1.B(); } return A; })(); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js index 457bd12b8f082..06a590194f5f5 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen2.js @@ -22,11 +22,11 @@ var my; })(data = my.data || (my.data = {})); })(my || (my = {})); var my; -(function (_my) { +(function (my_1) { var data; - (function (_data) { + (function (data_1) { function data(my) { - _data.foo.buz(); + data_1.foo.buz(); } - })(data = _my.data || (_my.data = {})); + })(data = my_1.data || (my_1.data = {})); })(my || (my = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js index 0618346dd75ea..43c55ed8291af 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen3.js @@ -19,14 +19,14 @@ var my; })(data = my.data || (my.data = {})); })(my || (my = {})); var my; -(function (_my) { +(function (my_1) { var data; - (function (_data) { + (function (data_1) { var foo; - (function (_foo) { + (function (foo_1) { function data(my, foo) { - _data.buz(); + data_1.buz(); } - })(foo = _data.foo || (_data.foo = {})); - })(data = _my.data || (_my.data = {})); + })(foo = data_1.foo || (data_1.foo = {})); + })(data = my_1.data || (my_1.data = {})); })(my || (my = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js index 2463c9cae906a..af7f5bacef73b 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen4.js @@ -20,7 +20,7 @@ module superContain { var superContain; (function (superContain) { var contain; - (function (_contain) { + (function (contain_1) { var my; (function (my) { var buz; @@ -32,19 +32,19 @@ var superContain; data.foo = foo; })(data = buz.data || (buz.data = {})); })(buz = my.buz || (my.buz = {})); - })(my = _contain.my || (_contain.my = {})); + })(my = contain_1.my || (contain_1.my = {})); var my; - (function (_my) { + (function (my_1) { var buz; - (function (_buz) { + (function (buz_1) { var data; - (function (_data) { + (function (data_1) { function bar(contain, my, buz, data) { - _data.foo(); + data_1.foo(); } - _data.bar = bar; - })(data = _buz.data || (_buz.data = {})); - })(buz = _my.buz || (_my.buz = {})); - })(my = _contain.my || (_contain.my = {})); + data_1.bar = bar; + })(data = buz_1.data || (buz_1.data = {})); + })(buz = my_1.buz || (my_1.buz = {})); + })(my = contain_1.my || (contain_1.my = {})); })(contain = superContain.contain || (superContain.contain = {})); })(superContain || (superContain = {})); diff --git a/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js b/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js index 2c8e0bb79e4fb..4bbad2e567868 100644 --- a/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js +++ b/tests/baselines/reference/mergedModuleDeclarationCodeGen5.js @@ -20,7 +20,7 @@ module M.buz.plop { //// [mergedModuleDeclarationCodeGen5.js] var M; -(function (_M) { +(function (M_1) { var buz; (function (buz) { var plop; @@ -32,14 +32,14 @@ var M; } plop.M = M; })(plop = buz.plop || (buz.plop = {})); - })(buz = _M.buz || (_M.buz = {})); + })(buz = M_1.buz || (M_1.buz = {})); })(M || (M = {})); var M; (function (M) { var buz; - (function (_buz) { + (function (buz_1) { var plop; - (function (_plop) { + (function (plop_1) { function gunk() { } function buz() { @@ -49,17 +49,17 @@ var M; } return fudge; })(); - _plop.fudge = fudge; + plop_1.fudge = fudge; (function (plop) { - })(_plop.plop || (_plop.plop = {})); - var plop = _plop.plop; + })(plop_1.plop || (plop_1.plop = {})); + var plop = plop_1.plop; // Emit these references as follows var v1 = gunk; // gunk var v2 = buz; // buz - _plop.v3 = _plop.doom; // _plop.doom - _plop.v4 = _plop.M; // _plop.M - _plop.v5 = fudge; // fudge - _plop.v6 = plop; // plop - })(plop = _buz.plop || (_buz.plop = {})); + plop_1.v3 = plop_1.doom; // _plop.doom + plop_1.v4 = plop_1.M; // _plop.M + plop_1.v5 = fudge; // fudge + plop_1.v6 = plop; // plop + })(plop = buz_1.plop || (buz_1.plop = {})); })(buz = M.buz || (M.buz = {})); })(M || (M = {})); diff --git a/tests/baselines/reference/moduleCodeGenTest5.js b/tests/baselines/reference/moduleCodeGenTest5.js index 6f5f0a4e91295..6f56f44c6849e 100644 --- a/tests/baselines/reference/moduleCodeGenTest5.js +++ b/tests/baselines/reference/moduleCodeGenTest5.js @@ -50,9 +50,9 @@ var C2 = (function () { E1[E1["A"] = 0] = "A"; })(exports.E1 || (exports.E1 = {})); var E1 = exports.E1; -var u = 0 /* A */; +var u = E1.A; var E2; (function (E2) { E2[E2["B"] = 0] = "B"; })(E2 || (E2 = {})); -var v = 0 /* B */; +var v = E2.B; diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js index 983dc004acf31..f9a90fd515155 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt.js @@ -25,11 +25,11 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { var M = Z.M; function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js index c11b36f643a30..efdcebe84e96d 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt3.js @@ -30,11 +30,11 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { var M = Z.M; function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js index c61f3d4dd9d73..e9cd456f3f3f8 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt4.js @@ -26,11 +26,11 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { var M = Z.M; function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js index 0bc314ccc0706..72aa36022634d 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js @@ -30,10 +30,10 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { function bar() { } - _M.bar = bar; + M_1.bar = bar; M.bar(); // Should call Z.M.bar })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js index 4ba0a33c29a0c..fbad13359b8eb 100644 --- a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js +++ b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt6.js @@ -24,9 +24,9 @@ var Z; var A; (function (A) { var M; - (function (_M) { + (function (M_1) { function bar() { } - _M.bar = bar; + M_1.bar = bar; })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/moduleVisibilityTest1.js b/tests/baselines/reference/moduleVisibilityTest1.js index d8bdedfafe257..8f129f545de21 100644 --- a/tests/baselines/reference/moduleVisibilityTest1.js +++ b/tests/baselines/reference/moduleVisibilityTest1.js @@ -137,11 +137,11 @@ var M; var M; (function (M) { M.c = M.x; - M.meb = 1 /* B */; + M.meb = M.E.B; })(M || (M = {})); var cprime = null; var c = new M.C(); var z = M.x; -var alpha = 0 /* A */; +var alpha = M.E.A; var omega = M.exported_var; c.someMethodThatCallsAnOuterMethod(); diff --git a/tests/baselines/reference/moduleWithStatementsOfEveryKind.js b/tests/baselines/reference/moduleWithStatementsOfEveryKind.js index 5161f72d5f023..cab0d35aa5a20 100644 --- a/tests/baselines/reference/moduleWithStatementsOfEveryKind.js +++ b/tests/baselines/reference/moduleWithStatementsOfEveryKind.js @@ -66,7 +66,7 @@ var __extends = this.__extends || function (d, b) { d.prototype = new __(); }; var A; -(function (_A) { +(function (A_1) { var A = (function () { function A() { } diff --git a/tests/baselines/reference/nameCollision.js b/tests/baselines/reference/nameCollision.js index fe7bb3a891975..0e559b7091cc8 100644 --- a/tests/baselines/reference/nameCollision.js +++ b/tests/baselines/reference/nameCollision.js @@ -48,7 +48,7 @@ module D { //// [nameCollision.js] var A; -(function (_A_1) { +(function (A_1) { // these 2 statements force an underscore before the 'A' // in the generated function call. var A = 12; @@ -59,7 +59,7 @@ var B; var A = 12; })(B || (B = {})); var B; -(function (_B) { +(function (B_1) { // re-opened module with colliding name // this should add an underscore. var B = (function () { @@ -69,29 +69,29 @@ var B; })(); })(B || (B = {})); var X; -(function (_X) { +(function (X_1) { var X = 13; var Y; - (function (_Y) { + (function (Y_1) { var Y = 13; var Z; - (function (_Z) { + (function (Z_1) { var X = 12; var Y = 12; var Z = 12; - })(Z = _Y.Z || (_Y.Z = {})); - })(Y = _X.Y || (_X.Y = {})); + })(Z = Y_1.Z || (Y_1.Z = {})); + })(Y = X_1.Y || (X_1.Y = {})); })(X || (X = {})); var Y; -(function (_Y_1) { +(function (Y_2) { var Y; - (function (_Y_2) { + (function (Y_3) { (function (Y) { Y[Y["Red"] = 0] = "Red"; Y[Y["Blue"] = 1] = "Blue"; - })(_Y_2.Y || (_Y_2.Y = {})); - var Y = _Y_2.Y; - })(Y = _Y_1.Y || (_Y_1.Y = {})); + })(Y_3.Y || (Y_3.Y = {})); + var Y = Y_3.Y; + })(Y = Y_2.Y || (Y_2.Y = {})); })(Y || (Y = {})); // no collision, since interface doesn't // generate code. diff --git a/tests/baselines/reference/negateOperatorWithEnumType.js b/tests/baselines/reference/negateOperatorWithEnumType.js index 77458f442df9a..e33e78110772b 100644 --- a/tests/baselines/reference/negateOperatorWithEnumType.js +++ b/tests/baselines/reference/negateOperatorWithEnumType.js @@ -33,10 +33,10 @@ var ENUM1; // enum type var var ResultIsNumber1 = -ENUM; // expressions -var ResultIsNumber2 = -1 /* "B" */; -var ResultIsNumber3 = -(1 /* B */ + 2 /* "" */); +var ResultIsNumber2 = -ENUM1["B"]; +var ResultIsNumber3 = -(ENUM1.B + ENUM1[""]); // miss assignment operators -ENUM; -ENUM1; --1 /* "B" */; +-ENUM1["B"]; -ENUM, ENUM1; diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index b8f42ba7c331b..c73f3e0b9487e 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,9 +1,19 @@ +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'PropertyDecorator'. +error TS2318: Cannot find global type 'ParameterDecorator'. +error TS2318: Cannot find global type 'MethodDecorator'. error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'ClassDecorator'. error TS2318: Cannot find global type 'Boolean'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'PropertyDecorator'. +!!! error TS2318: Cannot find global type 'ParameterDecorator'. +!!! error TS2318: Cannot find global type 'MethodDecorator'. !!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'ClassDecorator'. !!! error TS2318: Cannot find global type 'Boolean'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// diff --git a/tests/baselines/reference/noImplicitAnyIndexing.js b/tests/baselines/reference/noImplicitAnyIndexing.js index 91dbcae730c93..8451a1426a609 100644 --- a/tests/baselines/reference/noImplicitAnyIndexing.js +++ b/tests/baselines/reference/noImplicitAnyIndexing.js @@ -57,11 +57,11 @@ var MyEmusEnum; // Should be okay; should be a string. var strRepresentation1 = MyEmusEnum[0]; // Should be okay; should be a string. -var strRepresentation2 = MyEmusEnum[0 /* emu */]; +var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]; // Should be implicit 'any' ; property access fails, no string indexer. var strRepresentation3 = MyEmusEnum["monehh"]; // Should be okay; should be a MyEmusEnum -var strRepresentation4 = 0 /* "emu" */; +var strRepresentation4 = MyEmusEnum["emu"]; // Should report an implicit 'any'. var x = {}["hi"]; // Should report an implicit 'any'. @@ -77,6 +77,6 @@ var m = { "2": 2, "Okay that's enough for today.": NaN }; -var mResult1 = m[0 /* emu */]; -var mResult2 = m[MyEmusEnum[0 /* emu */]]; +var mResult1 = m[MyEmusEnum.emu]; +var mResult2 = m[MyEmusEnum[MyEmusEnum.emu]]; var mResult3 = m[hi]; diff --git a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js index 5185a9b8db846..6d91d8eb83888 100644 --- a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js +++ b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js @@ -56,11 +56,11 @@ var MyEmusEnum; // Should be okay; should be a string. var strRepresentation1 = MyEmusEnum[0]; // Should be okay; should be a string. -var strRepresentation2 = MyEmusEnum[0 /* emu */]; +var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]; // Should be okay, as we suppress implicit 'any' property access checks var strRepresentation3 = MyEmusEnum["monehh"]; // Should be okay; should be a MyEmusEnum -var strRepresentation4 = 0 /* "emu" */; +var strRepresentation4 = MyEmusEnum["emu"]; // Should be okay, as we suppress implicit 'any' property access checks var x = {}["hi"]; // Should be okay, as we suppress implicit 'any' property access checks @@ -76,6 +76,6 @@ var m = { "2": 2, "Okay that's enough for today.": NaN }; -var mResult1 = m[0 /* emu */]; -var mResult2 = m[MyEmusEnum[0 /* emu */]]; +var mResult1 = m[MyEmusEnum.emu]; +var mResult2 = m[MyEmusEnum[MyEmusEnum.emu]]; var mResult3 = m[hi]; diff --git a/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js b/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js index f69fe668f34d5..b47a591444c04 100644 --- a/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js +++ b/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js @@ -149,8 +149,8 @@ var E; })(E || (E = {})); var r13 = true ? E : null; var r13 = true ? null : E; -var r14 = true ? 0 /* A */ : null; -var r14 = true ? null : 0 /* A */; +var r14 = true ? E.A : null; +var r14 = true ? null : E.A; function f() { } var f; diff --git a/tests/baselines/reference/objectTypesIdentity2.js b/tests/baselines/reference/objectTypesIdentity2.js index bdd20d8ac5e08..f721fb04b52d2 100644 --- a/tests/baselines/reference/objectTypesIdentity2.js +++ b/tests/baselines/reference/objectTypesIdentity2.js @@ -88,7 +88,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); var b = { - foo: 0 /* A */ + foo: E.A }; function foo5(x) { } diff --git a/tests/baselines/reference/operatorAddNullUndefined.js b/tests/baselines/reference/operatorAddNullUndefined.js index f6b4fd240b257..4d52dbb234c68 100644 --- a/tests/baselines/reference/operatorAddNullUndefined.js +++ b/tests/baselines/reference/operatorAddNullUndefined.js @@ -34,7 +34,7 @@ var x9 = "test" + null; var x10 = "test" + undefined; var x11 = null + "test"; var x12 = undefined + "test"; -var x13 = null + 0 /* x */; -var x14 = undefined + 0 /* x */; -var x15 = 0 /* x */ + null; -var x16 = 0 /* x */ + undefined; +var x13 = null + E.x; +var x14 = undefined + E.x; +var x15 = E.x + null; +var x16 = E.x + undefined; diff --git a/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js b/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js index d0ced9921469c..86e84ced58f0f 100644 --- a/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js +++ b/tests/baselines/reference/overloadResolutionOverNonCTLambdas.js @@ -39,8 +39,8 @@ var Bugs; } var result = message.replace(/\{(\d+)\}/g, function (match) { var rest = []; - for (var _a = 1; _a < arguments.length; _a++) { - rest[_a - 1] = arguments[_a]; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; } var index = rest[0]; return typeof args[index] !== 'undefined' ? args[index] : match; diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 85485dd65012a..3dd70275e5c7a 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,21 +1,31 @@ +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'ClassDecorator'. 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 TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'PropertyDecorator'. +error TS2318: Cannot find global type 'ParameterDecorator'. 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 'MethodDecorator'. +error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'ClassDecorator'. !!! 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 TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'PropertyDecorator'. +!!! error TS2318: Cannot find global type 'ParameterDecorator'. !!! 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 'MethodDecorator'. +!!! error TS2318: Cannot find global type 'IArguments'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///