From e0581899fa90e1169ebdaf8a5507ffdd26ed4a62 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 27 Jan 2015 14:42:20 -0800 Subject: [PATCH 01/46] Rename existing import declaration to ImportEqualsDeclaration --- src/compiler/binder.ts | 6 +-- src/compiler/checker.ts | 92 ++++++++++++++++---------------- src/compiler/emitter.ts | 56 +++++++++---------- src/compiler/parser.ts | 16 +++--- src/compiler/program.ts | 12 ++--- src/compiler/types.ts | 10 ++-- src/compiler/utilities.ts | 18 +++---- src/services/breakpoints.ts | 4 +- src/services/formatting/rules.ts | 2 +- src/services/services.ts | 24 ++++----- 10 files changed, 120 insertions(+), 120 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index fe52e26ddd14a..83420091a5a16 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -18,7 +18,7 @@ module ts { return ModuleInstanceState.ConstEnumOnly; } // 3. non - exported import declarations - else if (node.kind === SyntaxKind.ImportDeclaration && !(node.flags & NodeFlags.Export)) { + else if (node.kind === SyntaxKind.ImportEqualsDeclaration && !(node.flags & NodeFlags.Export)) { return ModuleInstanceState.NonInstantiated; } // 4. other uninstantiated module declarations. @@ -200,7 +200,7 @@ module ts { exportKind |= SymbolFlags.ExportNamespace; } - if (getCombinedNodeFlags(node) & NodeFlags.Export || (node.kind !== SyntaxKind.ImportDeclaration && isAmbientContext(container))) { + if (getCombinedNodeFlags(node) & NodeFlags.Export || (node.kind !== SyntaxKind.ImportEqualsDeclaration && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -466,7 +466,7 @@ module ts { case SyntaxKind.ModuleDeclaration: bindModuleDeclaration(node); break; - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.SourceFile: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 75b2a7a16ab2b..4392c1c59b4fa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -444,7 +444,7 @@ module ts { var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfKind(symbol, SyntaxKind.ImportDeclaration); + var node = getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration); // Grammar checking if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) { if ((node.moduleReference).expression.kind !== SyntaxKind.StringLiteral) { @@ -453,8 +453,8 @@ module ts { } var target = node.moduleReference.kind === SyntaxKind.ExternalModuleReference - ? resolveExternalModuleName(node, getExternalModuleImportDeclarationExpression(node)) - : getSymbolOfPartOfRightHandSideOfImport(node.moduleReference, node); + ? resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)) + : getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; } @@ -469,9 +469,9 @@ module ts { } // This function is only for imports with entity names - function getSymbolOfPartOfRightHandSideOfImport(entityName: EntityName, importDeclaration?: ImportDeclaration): Symbol { + function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, importDeclaration?: ImportEqualsDeclaration): Symbol { if (!importDeclaration) { - importDeclaration = getAncestor(entityName, SyntaxKind.ImportDeclaration); + importDeclaration = getAncestor(entityName, SyntaxKind.ImportEqualsDeclaration); Debug.assert(importDeclaration !== undefined); } // There are three things we might try to look for. In the following examples, @@ -490,7 +490,7 @@ module ts { else { // Case 2 in above example // entityName.kind could be a QualifiedName or a Missing identifier - Debug.assert(entityName.parent.kind === SyntaxKind.ImportDeclaration); + Debug.assert(entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration); return resolveEntityName(importDeclaration, entityName, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); } } @@ -808,7 +808,7 @@ module ts { if (symbolFromSymbolTable.flags & SymbolFlags.Import) { if (!useOnlyExternalAliasing || // We can use any type of alias to get the name // Is this external alias, then use it to name - ts.forEach(symbolFromSymbolTable.declarations, isExternalModuleImportDeclaration)) { + ts.forEach(symbolFromSymbolTable.declarations, isExternalModuleImportEqualsDeclaration)) { var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable); if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) { @@ -934,7 +934,7 @@ module ts { } function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult { - var aliasesToMakeVisible: ImportDeclaration[]; + var aliasesToMakeVisible: ImportEqualsDeclaration[]; if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) { return undefined; } @@ -944,17 +944,17 @@ 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.ImportDeclaration && + if (declaration.kind === SyntaxKind.ImportEqualsDeclaration && !(declaration.flags & NodeFlags.Export) && isDeclarationVisible(declaration.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { if (!contains(aliasesToMakeVisible, declaration)) { - aliasesToMakeVisible.push(declaration); + aliasesToMakeVisible.push(declaration); } } else { - aliasesToMakeVisible = [declaration]; + aliasesToMakeVisible = [declaration]; } return true; } @@ -975,7 +975,7 @@ module ts { meaning = SymbolFlags.Value | SymbolFlags.ExportValue; } else if (entityName.kind === SyntaxKind.QualifiedName || - entityName.parent.kind === SyntaxKind.ImportDeclaration) { + entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration) { // Left identifier from type reference or TypeAlias // Entity name of the import declaration meaning = SymbolFlags.Namespace; @@ -1583,11 +1583,11 @@ module ts { case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.FunctionDeclaration: case SyntaxKind.EnumDeclaration: - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: var parent = getDeclarationContainer(node); // If the node is not exported or it is not ambient module element (except import declaration) if (!(getCombinedNodeFlags(node) & NodeFlags.Export) && - !(node.kind !== SyntaxKind.ImportDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) { + !(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) { return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible @@ -4820,7 +4820,7 @@ module ts { } /*Transitively mark all linked imports as referenced*/ - function markLinkedImportsAsReferenced(node: ImportDeclaration): void { + function markLinkedImportsAsReferenced(node: ImportEqualsDeclaration): void { var nodeLinks = getNodeLinks(node); while (nodeLinks.importOnRightSide) { var rightSide = nodeLinks.importOnRightSide; @@ -4829,7 +4829,7 @@ module ts { getSymbolLinks(rightSide).referenced = true; Debug.assert((rightSide.flags & SymbolFlags.Import) !== 0); - nodeLinks = getNodeLinks(getDeclarationOfKind(rightSide, SyntaxKind.ImportDeclaration)) + nodeLinks = getNodeLinks(getDeclarationOfKind(rightSide, SyntaxKind.ImportEqualsDeclaration)) } } @@ -4839,7 +4839,7 @@ module ts { if (symbol.flags & SymbolFlags.Import) { var symbolLinks = getSymbolLinks(symbol); if (!symbolLinks.referenced) { - var importOrExportAssignment = getLeftSideOfImportOrExportAssignment(node); + var importOrExportAssignment = getLeftSideOfImportEqualsOrExportAssignment(node); // decision about whether import is referenced can be made now if // - import that are used anywhere except right side of import declarations @@ -4860,7 +4860,7 @@ module ts { } if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportDeclaration)); + markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration)); } } @@ -7931,7 +7931,7 @@ module ts { case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: return SymbolFlags.ExportType | SymbolFlags.ExportValue; - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: var result: SymbolFlags = 0; var target = resolveImport(getSymbolOfNode(d)); forEach(target.declarations, d => { result |= getDeclarationSpaces(d); }); @@ -9150,8 +9150,8 @@ module ts { // Export assignments are not allowed in an internal module grammarErrorOnNode(statement, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } - else if (isExternalModuleImportDeclaration(statement)) { - grammarErrorOnNode(getExternalModuleImportDeclarationExpression(statement), Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + else if (isExternalModuleImportEqualsDeclaration(statement)) { + grammarErrorOnNode(getExternalModuleImportEqualsDeclarationExpression(statement), Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); } } } @@ -9198,7 +9198,7 @@ module ts { return node; } - function checkImportDeclaration(node: ImportDeclaration) { + function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { // Grammar checking checkGrammarModifiers(node); @@ -9207,7 +9207,7 @@ module ts { var symbol = getSymbolOfNode(node); var target: Symbol; - if (isInternalModuleImportDeclaration(node)) { + if (isInternalModuleImportEqualsDeclaration(node)) { target = resolveImport(symbol); // Import declaration for an internal module if (target !== unknownSymbol) { @@ -9237,8 +9237,8 @@ module ts { // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference // other external modules only through top - level external module names. // Relative external module names are not permitted. - if (getExternalModuleImportDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { - if (isExternalModuleNameRelative((getExternalModuleImportDeclarationExpression(node)).text)) { + if (getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { + if (isExternalModuleNameRelative((getExternalModuleImportEqualsDeclarationExpression(node)).text)) { error(node, Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); target = unknownSymbol; } @@ -9367,8 +9367,8 @@ module ts { return checkEnumDeclaration(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); - case SyntaxKind.ImportDeclaration: - return checkImportDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return checkImportEqualsDeclaration(node); case SyntaxKind.ExportAssignment: return checkExportAssignment(node); case SyntaxKind.EmptyStatement: @@ -9487,7 +9487,7 @@ module ts { // Mark the import as referenced so that we emit it in the final .js file. getSymbolLinks(symbol).referenced = true; // mark any import declarations that depend upon this import as referenced - markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportDeclaration)) + markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration)) } } @@ -9715,13 +9715,13 @@ module ts { return false; } - function getLeftSideOfImportOrExportAssignment(nodeOnRightSide: EntityName): ImportDeclaration | ExportAssignment { + function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide: EntityName): ImportEqualsDeclaration | ExportAssignment { while (nodeOnRightSide.parent.kind === SyntaxKind.QualifiedName) { nodeOnRightSide = nodeOnRightSide.parent; } - if (nodeOnRightSide.parent.kind === SyntaxKind.ImportDeclaration) { - return (nodeOnRightSide.parent).moduleReference === nodeOnRightSide && nodeOnRightSide.parent; + if (nodeOnRightSide.parent.kind === SyntaxKind.ImportEqualsDeclaration) { + return (nodeOnRightSide.parent).moduleReference === nodeOnRightSide && nodeOnRightSide.parent; } if (nodeOnRightSide.parent.kind === SyntaxKind.ExportAssignment) { @@ -9732,7 +9732,7 @@ module ts { } function isInRightSideOfImportOrExportAssignment(node: EntityName) { - return getLeftSideOfImportOrExportAssignment(node) !== undefined; + return getLeftSideOfImportEqualsOrExportAssignment(node) !== undefined; } function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) { @@ -9753,7 +9753,7 @@ module ts { if (entityName.kind !== SyntaxKind.PropertyAccessExpression) { if (isInRightSideOfImportOrExportAssignment(entityName)) { // Since we already checked for ExportAssignment, this really could only be an Import - return getSymbolOfPartOfRightHandSideOfImport(entityName); + return getSymbolOfPartOfRightHandSideOfImportEquals(entityName); } } @@ -9814,7 +9814,7 @@ module ts { if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(node)) { return node.parent.kind === SyntaxKind.ExportAssignment ? getSymbolOfEntityNameOrPropertyAccessExpression(node) - : getSymbolOfPartOfRightHandSideOfImport(node); + : getSymbolOfPartOfRightHandSideOfImportEquals(node); } switch (node.kind) { @@ -9838,8 +9838,8 @@ module ts { case SyntaxKind.StringLiteral: // External module name in an import declaration - if (isExternalModuleImportDeclaration(node.parent.parent) && - getExternalModuleImportDeclarationExpression(node.parent.parent) === node) { + if (isExternalModuleImportEqualsDeclaration(node.parent.parent) && + getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) { var importSymbol = getSymbolOfNode(node.parent.parent); var moduleType = getTypeOfSymbol(importSymbol); return moduleType ? moduleType.symbol : undefined; @@ -9980,8 +9980,8 @@ module ts { // An import can be emitted too, if it is referenced as a value. // Make sure the name in question does not collide with an import. if (symbolWithRelevantName.flags & SymbolFlags.Import) { - var importDeclarationWithRelevantName = getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportDeclaration); - if (isReferencedImportDeclaration(importDeclarationWithRelevantName)) { + var importEqualsDeclarationWithRelevantName = getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportEqualsDeclaration); + if (isReferencedImportEqualsDeclaration(importEqualsDeclarationWithRelevantName)) { return false; } } @@ -10037,8 +10037,8 @@ module ts { return symbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol): undefined; } - function isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean { - if (node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportDeclaration(node)) { + function isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean { + if (node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportEqualsDeclaration(node)) { // parent is not source file or it is not reference to internal module return false; } @@ -10060,7 +10060,7 @@ module ts { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedImportDeclaration(node: ImportDeclaration): boolean { + function isReferencedImportEqualsDeclaration(node: ImportEqualsDeclaration): boolean { var symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { return true; @@ -10140,10 +10140,10 @@ module ts { getLocalNameOfContainer, getExpressionNamePrefix, getExportAssignmentName, - isReferencedImportDeclaration, + isReferencedImportEqualsDeclaration, getNodeCheckFlags, getEnumMemberValue, - isTopLevelValueImportWithEntityName, + isTopLevelValueImportEqualsWithEntityName, hasSemanticErrors, isDeclarationVisible, isImplementationOfOverload, @@ -10210,7 +10210,7 @@ module ts { case SyntaxKind.VariableStatement: case SyntaxKind.FunctionDeclaration: case SyntaxKind.TypeAliasDeclaration: - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.Parameter: break; default: @@ -10315,7 +10315,7 @@ module ts { return grammarErrorOnNode(lastPrivate, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); } } - else if (node.kind === SyntaxKind.ImportDeclaration && flags & NodeFlags.Ambient) { + else if (node.kind === SyntaxKind.ImportEqualsDeclaration && flags & NodeFlags.Ambient) { return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); } else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) { @@ -11037,7 +11037,7 @@ module ts { // export_opt AmbientDeclaration // if (node.kind === SyntaxKind.InterfaceDeclaration || - node.kind === SyntaxKind.ImportDeclaration || + node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportAssignment || (node.flags & NodeFlags.Ambient)) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6626823379b6a..99fa265666a9b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -28,7 +28,7 @@ module ts { } interface AliasDeclarationEmitInfo { - declaration: ImportDeclaration; + declaration: ImportEqualsDeclaration; outputPos: number; indent: number; asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output @@ -381,9 +381,9 @@ module ts { decreaseIndent = newWriter.decreaseIndent; } - function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) { + function writeAsychronousImportEqualsDeclarations(importEqualsDeclarations: ImportEqualsDeclaration[]) { var oldWriter = writer; - forEach(importDeclarations, aliasToWrite => { + forEach(importEqualsDeclarations, aliasToWrite => { var 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 @@ -397,7 +397,7 @@ module ts { for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { increaseIndent(); } - writeImportDeclaration(aliasToWrite); + writeImportEqualsDeclaration(aliasToWrite); aliasEmitInfo.asynchronousOutput = writer.getText(); } }); @@ -408,7 +408,7 @@ module ts { if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { // write the aliases if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); + writeAsychronousImportEqualsDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); } } else { @@ -533,7 +533,7 @@ module ts { function emitEntityName(entityName: EntityName) { var visibilityResult = resolver.isEntityNameVisible(entityName, // Aliases can be written asynchronously so use correct enclosing declaration - entityName.parent.kind === SyntaxKind.ImportDeclaration ? entityName.parent : enclosingDeclaration); + entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration); handleSymbolAccessibilityError(visibilityResult); writeEntityName(entityName); @@ -639,7 +639,7 @@ module ts { } } - function emitImportDeclaration(node: ImportDeclaration) { + function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { var nodeEmitInfo = { declaration: node, outputPos: writer.getTextPos(), @@ -648,11 +648,11 @@ module ts { }; aliasDeclarationEmitInfo.push(nodeEmitInfo); if (nodeEmitInfo.hasWritten) { - writeImportDeclaration(node); + writeImportEqualsDeclaration(node); } } - function writeImportDeclaration(node: ImportDeclaration) { + 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); @@ -662,13 +662,13 @@ module ts { write("import "); writeTextOfNode(currentSourceFile, node.name); write(" = "); - if (isInternalModuleImportDeclaration(node)) { + if (isInternalModuleImportEqualsDeclaration(node)) { emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); write(";"); } else { write("require("); - writeTextOfNode(currentSourceFile, getExternalModuleImportDeclarationExpression(node)); + writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node)); write(");"); } writer.writeLine(); @@ -1393,8 +1393,8 @@ module ts { return emitEnumDeclaration(node); case SyntaxKind.ModuleDeclaration: return emitModuleDeclaration(node); - case SyntaxKind.ImportDeclaration: - return emitImportDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return emitImportEqualsDeclaration(node); case SyntaxKind.ExportAssignment: return emitExportAssignment(node); case SyntaxKind.SourceFile: @@ -2248,7 +2248,7 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: return (parent).name === node; case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: @@ -3791,18 +3791,18 @@ module ts { emitTrailingComments(node); } - function emitImportDeclaration(node: ImportDeclaration) { - var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); + function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { + var emitImportDeclaration = resolver.isReferencedImportEqualsDeclaration(node); if (!emitImportDeclaration) { // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when // - current file is not external module // - import declaration is top level and target is value imported by entity name - emitImportDeclaration = !isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node); + emitImportDeclaration = !isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node); } if (emitImportDeclaration) { - if (isExternalModuleImportDeclaration(node) && node.parent.kind === SyntaxKind.SourceFile && compilerOptions.module === ModuleKind.AMD) { + if (isExternalModuleImportEqualsDeclaration(node) && node.parent.kind === SyntaxKind.SourceFile && compilerOptions.module === ModuleKind.AMD) { if (node.flags & NodeFlags.Export) { writeLine(); emitLeadingComments(node); @@ -3822,11 +3822,11 @@ module ts { if (!(node.flags & NodeFlags.Export)) write("var "); emitModuleMemberName(node); write(" = "); - if (isInternalModuleImportDeclaration(node)) { + if (isInternalModuleImportEqualsDeclaration(node)) { emit(node.moduleReference); } else { - var literal = getExternalModuleImportDeclarationExpression(node); + var literal = getExternalModuleImportEqualsDeclarationExpression(node); write("require("); emitStart(literal); emitLiteral(literal); @@ -3840,11 +3840,11 @@ module ts { } } - function getExternalImportDeclarations(node: SourceFile): ImportDeclaration[] { - var result: ImportDeclaration[] = []; + function getExternalImportEqualsDeclarations(node: SourceFile): ImportEqualsDeclaration[] { + var result: ImportEqualsDeclaration[] = []; forEach(node.statements, statement => { - if (isExternalModuleImportDeclaration(statement) && resolver.isReferencedImportDeclaration(statement)) { - result.push(statement); + if (isExternalModuleImportEqualsDeclaration(statement) && resolver.isReferencedImportEqualsDeclaration(statement)) { + result.push(statement); } }); return result; @@ -3859,7 +3859,7 @@ module ts { } function emitAMDModule(node: SourceFile, startIndex: number) { - var imports = getExternalImportDeclarations(node); + var imports = getExternalImportEqualsDeclarations(node); writeLine(); write("define("); if (node.amdModuleName) { @@ -3868,7 +3868,7 @@ module ts { write("[\"require\", \"exports\""); forEach(imports, imp => { write(", "); - emitLiteral(getExternalModuleImportDeclarationExpression(imp)); + emitLiteral(getExternalModuleImportEqualsDeclarationExpression(imp)); }); forEach(node.amdDependencies, amdDependency => { var text = "\"" + amdDependency + "\""; @@ -4125,8 +4125,8 @@ module ts { return emitEnumDeclaration(node); case SyntaxKind.ModuleDeclaration: return emitModuleDeclaration(node); - case SyntaxKind.ImportDeclaration: - return emitImportDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return emitImportEqualsDeclaration(node); case SyntaxKind.SourceFile: return emitSourceFile(node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5ae44e5ff398a..7453e5597f164 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -246,10 +246,10 @@ module ts { return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).body); - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).moduleReference); + visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).moduleReference); case SyntaxKind.ExportAssignment: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportName); @@ -1745,7 +1745,7 @@ module ts { function isReusableModuleElement(node: Node) { if (node) { switch (node.kind) { - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.ExportAssignment: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -4519,8 +4519,8 @@ module ts { return nextToken() === SyntaxKind.OpenParenToken; } - function parseImportDeclaration(fullStart: number, modifiers: ModifiersArray): ImportDeclaration { - var node = createNode(SyntaxKind.ImportDeclaration, fullStart); + function parseImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration { + var node = createNode(SyntaxKind.ImportEqualsDeclaration, fullStart); setModifiers(node, modifiers); parseExpected(SyntaxKind.ImportKeyword); node.name = parseIdentifier(); @@ -4653,7 +4653,7 @@ module ts { case SyntaxKind.ModuleKeyword: return parseModuleDeclaration(fullStart, modifiers); case SyntaxKind.ImportKeyword: - return parseImportDeclaration(fullStart, modifiers); + return parseImportEqualsDeclaration(fullStart, modifiers); default: Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } @@ -4736,7 +4736,7 @@ module ts { function setExternalModuleIndicator(sourceFile: SourceFile) { sourceFile.externalModuleIndicator = forEach(sourceFile.statements, node => node.flags & NodeFlags.Export - || node.kind === SyntaxKind.ImportDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference + || node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference || node.kind === SyntaxKind.ExportAssignment ? node : undefined); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 06e636352326a..998e251239585 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -276,10 +276,10 @@ module ts { function processImportedModules(file: SourceFile, basePath: string) { forEach(file.statements, node => { - if (isExternalModuleImportDeclaration(node) && - getExternalModuleImportDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { + if (isExternalModuleImportEqualsDeclaration(node) && + getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { - var nameLiteral = getExternalModuleImportDeclarationExpression(node); + var nameLiteral = getExternalModuleImportEqualsDeclarationExpression(node); var moduleName = nameLiteral.text; if (moduleName) { var searchPath = basePath; @@ -304,10 +304,10 @@ module ts { // The StringLiteral must specify a top - level external module name. // Relative external module names are not permitted forEachChild((node).body, node => { - if (isExternalModuleImportDeclaration(node) && - getExternalModuleImportDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { + if (isExternalModuleImportEqualsDeclaration(node) && + getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { - var nameLiteral = getExternalModuleImportDeclarationExpression(node); + var nameLiteral = getExternalModuleImportEqualsDeclarationExpression(node); var moduleName = nameLiteral.text; if (moduleName) { // TypeScript 1.0 spec (April 2014): 12.1.6 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9e86d59104bed..a5144eb88317e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -228,7 +228,7 @@ module ts { EnumDeclaration, ModuleDeclaration, ModuleBlock, - ImportDeclaration, + ImportEqualsDeclaration, ExportAssignment, // Module references @@ -849,7 +849,7 @@ module ts { statements: NodeArray } - export interface ImportDeclaration extends Declaration, ModuleElement { + export interface ImportEqualsDeclaration extends Declaration, ModuleElement { name: Identifier; // 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external @@ -1099,7 +1099,7 @@ module ts { export interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportDeclaration[]; // aliases that need to have this symbol visible + aliasesToMakeVisible?: ImportEqualsDeclaration[]; // 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 } @@ -1112,8 +1112,8 @@ module ts { getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; - isReferencedImportDeclaration(node: ImportDeclaration): boolean; - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; + isReferencedImportEqualsDeclaration(node: ImportEqualsDeclaration): boolean; + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; getEnumMemberValue(node: EnumMember): number; hasSemanticErrors(sourceFile?: SourceFile): boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6c894ad7d9c9f..ec2c2d404dac6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -578,17 +578,17 @@ module ts { (preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly); } - export function isExternalModuleImportDeclaration(node: Node) { - return node.kind === SyntaxKind.ImportDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference; + export function isExternalModuleImportEqualsDeclaration(node: Node) { + return node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference; } - export function getExternalModuleImportDeclarationExpression(node: Node) { - Debug.assert(isExternalModuleImportDeclaration(node)); - return ((node).moduleReference).expression; + export function getExternalModuleImportEqualsDeclarationExpression(node: Node) { + Debug.assert(isExternalModuleImportEqualsDeclaration(node)); + return ((node).moduleReference).expression; } - export function isInternalModuleImportDeclaration(node: Node) { - return node.kind === SyntaxKind.ImportDeclaration && (node).moduleReference.kind !== SyntaxKind.ExternalModuleReference; + export function isInternalModuleImportEqualsDeclaration(node: Node) { + return node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind !== SyntaxKind.ExternalModuleReference; } export function hasDotDotDotToken(node: Node) { @@ -667,7 +667,7 @@ module ts { case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: return true; } return false; @@ -764,7 +764,7 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: // early exit cases - declarations cannot be nested in classes return undefined; default: diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index e49d035559b1f..e9f580be3bcc6 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -175,9 +175,9 @@ module ts.BreakpointResolver { // span on export = id return textSpan(node, (node).exportName); - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: // import statement without including semicolon - return textSpan(node,(node).moduleReference); + return textSpan(node,(node).moduleReference); case SyntaxKind.ModuleDeclaration: // span on complete module if it is instantiated diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 9fcc787030d3c..813254521351a 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -452,7 +452,7 @@ module ts.formatting { return true; // equal in import a = module('a'); - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: // equal in var a = 0; case SyntaxKind.VariableDeclaration: // equal in p = 0; diff --git a/src/services/services.ts b/src/services/services.ts index 2a1fe59d23a8e..54f5edd20bed6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -800,7 +800,7 @@ module ts { case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: case SyntaxKind.TypeLiteral: @@ -1864,7 +1864,7 @@ module ts { function isNameOfExternalModuleImportOrDeclaration(node: Node): boolean { if (node.kind === SyntaxKind.StringLiteral) { return isNameOfModuleDeclaration(node) || - (isExternalModuleImportDeclaration(node.parent.parent) && getExternalModuleImportDeclarationExpression(node.parent.parent) === node); + (isExternalModuleImportEqualsDeclaration(node.parent.parent) && getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node); } return false; @@ -2942,19 +2942,19 @@ module ts { displayParts.push(spacePart()); addFullSymbolName(symbol); ts.forEach(symbol.declarations, declaration => { - if (declaration.kind === SyntaxKind.ImportDeclaration) { - var importDeclaration = declaration; - if (isExternalModuleImportDeclaration(importDeclaration)) { + if (declaration.kind === SyntaxKind.ImportEqualsDeclaration) { + var importEqualsDeclaration = declaration; + if (isExternalModuleImportEqualsDeclaration(importEqualsDeclaration)) { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); displayParts.push(keywordPart(SyntaxKind.RequireKeyword)); displayParts.push(punctuationPart(SyntaxKind.OpenParenToken)); - displayParts.push(displayPart(getTextOfNode(getExternalModuleImportDeclarationExpression(importDeclaration)), SymbolDisplayPartKind.stringLiteral)); + displayParts.push(displayPart(getTextOfNode(getExternalModuleImportEqualsDeclarationExpression(importEqualsDeclaration)), SymbolDisplayPartKind.stringLiteral)); displayParts.push(punctuationPart(SyntaxKind.CloseParenToken)); } else { - var internalAliasSymbol = typeResolver.getSymbolAtLocation(importDeclaration.moduleReference); + var internalAliasSymbol = typeResolver.getSymbolAtLocation(importEqualsDeclaration.moduleReference); if (internalAliasSymbol) { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); @@ -4675,7 +4675,7 @@ module ts { return SemanticMeaning.Namespace; } - case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace; // An external module can be a Value @@ -4710,10 +4710,10 @@ module ts { while (node.parent.kind === SyntaxKind.QualifiedName) { node = node.parent; } - return isInternalModuleImportDeclaration(node.parent) && (node.parent).moduleReference === node; + return isInternalModuleImportEqualsDeclaration(node.parent) && (node.parent).moduleReference === node; } - function getMeaningFromRightHandSideOfImport(node: Node) { + function getMeaningFromRightHandSideOfImportEquals(node: Node) { Debug.assert(node.kind === SyntaxKind.Identifier); // import a = |b|; // Namespace @@ -4722,7 +4722,7 @@ module ts { if (node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node && - node.parent.parent.kind === SyntaxKind.ImportDeclaration) { + node.parent.parent.kind === SyntaxKind.ImportEqualsDeclaration) { return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace; } return SemanticMeaning.Namespace; @@ -4733,7 +4733,7 @@ module ts { return SemanticMeaning.Value | SemanticMeaning.Type | SemanticMeaning.Namespace; } else if (isInRightSideOfImport(node)) { - return getMeaningFromRightHandSideOfImport(node); + return getMeaningFromRightHandSideOfImportEquals(node); } else if (isDeclarationOrFunctionExpressionOrCatchVariableName(node)) { return getMeaningFromDeclaration(node.parent); From 5bd8271f04a7fed9ccfafcc38486e350c07ce44d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 27 Jan 2015 16:16:18 -0800 Subject: [PATCH 02/46] Types for the new es6 style import statement parsing --- src/compiler/types.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a5144eb88317e..88d498695e7b4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -230,6 +230,11 @@ module ts { ModuleBlock, ImportEqualsDeclaration, ExportAssignment, + ImportStatement, + ImportClause, + NamespaceImport, + NamedImports, + ImportSpecifier, // Module references ExternalModuleReference, @@ -861,6 +866,29 @@ module ts { expression?: Expression; } + export interface ImportStatement extends Statement, ModuleElement { + importClause?: ImportClause; + moduleSpecifier: StringLiteralExpression; + } + + export interface ImportClause extends Node { + defaultBinding?: Identifier; + bindings?: NamespaceImport | NamedImports; + } + + export interface NamespaceImport extends Declaration { + name: Identifier; + } + + export interface NamedImports extends Node { + elements: NodeArray; + } + + export interface ImportSpecifier extends Declaration { + propertyName?: Identifier; // Property name to be imported from module + name: Identifier; // element name to be imported in the scope + } + export interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } From 4f1b9082124c1616c9dcac2d0e2766810e087b8f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 27 Jan 2015 15:42:36 -0800 Subject: [PATCH 03/46] Parse import ModuleSpecifier; --- src/compiler/parser.ts | 37 ++++++++++++++++--- .../reference/es6ImportParseErrors.errors.txt | 8 ++++ .../reference/es6ImportWithoutFromClause.js | 12 ++++++ .../es6ImportWithoutFromClause.types | 8 ++++ .../es6ImportWithoutFromClauseInEs5.js | 12 ++++++ .../es6ImportWithoutFromClauseInEs5.types | 8 ++++ tests/cases/compiler/es6ImportParseErrors.ts | 4 ++ .../compiler/es6ImportWithoutFromClause.ts | 8 ++++ .../es6ImportWithoutFromClauseInEs5.ts | 8 ++++ 9 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/es6ImportParseErrors.errors.txt create mode 100644 tests/baselines/reference/es6ImportWithoutFromClause.js create mode 100644 tests/baselines/reference/es6ImportWithoutFromClause.types create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types create mode 100644 tests/cases/compiler/es6ImportParseErrors.ts create mode 100644 tests/cases/compiler/es6ImportWithoutFromClause.ts create mode 100644 tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7453e5597f164..2e6132287d1e1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1511,7 +1511,6 @@ module ts { return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken; case ParsingContext.HeritageClauses: return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken; - } } @@ -4519,10 +4518,14 @@ module ts { return nextToken() === SyntaxKind.OpenParenToken; } - function parseImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration { + function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement { + parseExpected(SyntaxKind.ImportKeyword); + if (token === SyntaxKind.StringLiteral) { + return parseImportStatement(fullStart, modifiers); + } + var node = createNode(SyntaxKind.ImportEqualsDeclaration, fullStart); setModifiers(node, modifiers); - parseExpected(SyntaxKind.ImportKeyword); node.name = parseIdentifier(); parseExpected(SyntaxKind.EqualsToken); node.moduleReference = parseModuleReference(); @@ -4556,6 +4559,30 @@ module ts { return finishNode(node); } + function parseImportStatement(fullStart: number, modifiers: ModifiersArray): ImportStatement { + var node = createNode(SyntaxKind.ImportStatement, fullStart); + setModifiers(node, modifiers); + + // ImportDeclaration: + // import ModuleSpecifier; + node.moduleSpecifier = parseModuleSpecifier(); + parseSemicolon(); + return finishNode(node); + } + + function parseModuleSpecifier(): StringLiteralExpression { + // ModuleSpecifier: + // StringLiteral + if (token === SyntaxKind.StringLiteral) { + // Ensure the string being required is in our 'identifier' table. This will ensure + // that features like 'find refs' will look inside this file when search for its name. + var moduleSpecifier = parseLiteralNode(/*internName*/ true); + return moduleSpecifier; + } + + parseErrorAtCurrentToken(Diagnostics.String_literal_expected); + } + function parseExportAssignmentTail(fullStart: number, modifiers: ModifiersArray): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, fullStart); setModifiers(node, modifiers); @@ -4581,10 +4608,10 @@ module ts { case SyntaxKind.ClassKeyword: case SyntaxKind.InterfaceKeyword: case SyntaxKind.EnumKeyword: - case SyntaxKind.ImportKeyword: case SyntaxKind.TypeKeyword: // Not true keywords so ensure an identifier follows return lookAhead(nextTokenIsIdentifierOrKeyword); + case SyntaxKind.ImportKeyword: case SyntaxKind.ModuleKeyword: // Not a true keyword so ensure an identifier or string literal follows return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); @@ -4653,7 +4680,7 @@ module ts { case SyntaxKind.ModuleKeyword: return parseModuleDeclaration(fullStart, modifiers); case SyntaxKind.ImportKeyword: - return parseImportEqualsDeclaration(fullStart, modifiers); + return parseImportDeclarationOrStatement(fullStart, modifiers); default: Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } diff --git a/tests/baselines/reference/es6ImportParseErrors.errors.txt b/tests/baselines/reference/es6ImportParseErrors.errors.txt new file mode 100644 index 0000000000000..d1e1cb7d00de8 --- /dev/null +++ b/tests/baselines/reference/es6ImportParseErrors.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/es6ImportParseErrors.ts(2,1): error TS1128: Declaration or statement expected. + + +==== tests/cases/compiler/es6ImportParseErrors.ts (1 errors) ==== + + import 10; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js new file mode 100644 index 0000000000000..aa5e25bcd6ff4 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClause.ts] //// + +//// [es6ImportWithoutFromClause_0.ts] + +export var a = 10; + +//// [es6ImportWithoutFromClause_1.ts] +import "es6ImportWithoutFromClause_0"; + +//// [es6ImportWithoutFromClause_0.js] +exports.a = 10; +//// [es6ImportWithoutFromClause_1.js] diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.types b/tests/baselines/reference/es6ImportWithoutFromClause.types new file mode 100644 index 0000000000000..1cd7df9962ee7 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClause.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportWithoutFromClause_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportWithoutFromClause_1.ts === +import "es6ImportWithoutFromClause_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js new file mode 100644 index 0000000000000..3782987c2ffa6 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts] //// + +//// [es6ImportWithoutFromClauseInEs5_0.ts] + +export var a = 10; + +//// [es6ImportWithoutFromClauseInEs5_1.ts] +import "es6ImportWithoutFromClauseInEs5_0"; + +//// [es6ImportWithoutFromClauseInEs5_0.js] +exports.a = 10; +//// [es6ImportWithoutFromClauseInEs5_1.js] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types new file mode 100644 index 0000000000000..3d674f9c22cec --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseInEs5_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseInEs5_1.ts === +import "es6ImportWithoutFromClauseInEs5_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportParseErrors.ts b/tests/cases/compiler/es6ImportParseErrors.ts new file mode 100644 index 0000000000000..2cc21dad7468f --- /dev/null +++ b/tests/cases/compiler/es6ImportParseErrors.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @module: commonjs + +import 10; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClause.ts b/tests/cases/compiler/es6ImportWithoutFromClause.ts new file mode 100644 index 0000000000000..70a15a9bc54f7 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClause.ts @@ -0,0 +1,8 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportWithoutFromClause_0.ts +export var a = 10; + +// @filename: es6ImportWithoutFromClause_1.ts +import "es6ImportWithoutFromClause_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts new file mode 100644 index 0000000000000..339880ee097e3 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportWithoutFromClauseInEs5_0.ts +export var a = 10; + +// @filename: es6ImportWithoutFromClauseInEs5_1.ts +import "es6ImportWithoutFromClauseInEs5_0"; \ No newline at end of file From fdd7032c610f98625eeeaab91368800164a5d815 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 27 Jan 2015 16:04:11 -0800 Subject: [PATCH 04/46] Parsing for import * as ImportedBinding --- src/compiler/parser.ts | 40 ++++++++++++++++++- src/compiler/scanner.ts | 2 + src/compiler/types.ts | 2 + .../reference/es6ImportNameSpaceImport.js | 12 ++++++ .../reference/es6ImportNameSpaceImport.types | 8 ++++ .../es6ImportNameSpaceImportInEs5.js | 12 ++++++ .../es6ImportNameSpaceImportInEs5.types | 8 ++++ .../compiler/es6ImportNameSpaceImport.ts | 8 ++++ .../compiler/es6ImportNameSpaceImportInEs5.ts | 8 ++++ 9 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/es6ImportNameSpaceImport.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImport.types create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportInEs5.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportInEs5.types create mode 100644 tests/cases/compiler/es6ImportNameSpaceImport.ts create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2e6132287d1e1..254e2cb12ca6b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4520,7 +4520,8 @@ module ts { function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement { parseExpected(SyntaxKind.ImportKeyword); - if (token === SyntaxKind.StringLiteral) { + if (token === SyntaxKind.StringLiteral || + token === SyntaxKind.AsteriskToken) { return parseImportStatement(fullStart, modifiers); } @@ -4564,7 +4565,12 @@ module ts { setModifiers(node, modifiers); // ImportDeclaration: + // import ImportClause ModuleSpecifier ; // import ModuleSpecifier; + if (token !== SyntaxKind.StringLiteral) { + // ImportDeclaration: + node.importClause = parseImportClause(); + } node.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); return finishNode(node); @@ -4583,6 +4589,30 @@ module ts { parseErrorAtCurrentToken(Diagnostics.String_literal_expected); } + function parseImportClause(): ImportClause { + //ImportClause: + // ImportedDefaultBinding from + // NameSpaceImport from + // NamedImports from + // ImportedDefaultBinding, NameSpaceImport from + // ImportedDefaultBinding, NamedImports from + + var importClause = createNode(SyntaxKind.ImportClause); + importClause.bindings = parseNamespaceImport(); + parseExpected(SyntaxKind.FromKeyword); + return finishNode(importClause); + } + + function parseNamespaceImport(): NamespaceImport { + // NameSpaceImport: + // * as ImportedBinding + var namespaceImport = createNode(SyntaxKind.NamespaceImport); + parseExpected(SyntaxKind.AsteriskToken); + parseExpected(SyntaxKind.AsKeyword); + namespaceImport.name = parseIdentifier(); + return finishNode(namespaceImport); + } + function parseExportAssignmentTail(fullStart: number, modifiers: ModifiersArray): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, fullStart); setModifiers(node, modifiers); @@ -4612,6 +4642,8 @@ module ts { // Not true keywords so ensure an identifier follows return lookAhead(nextTokenIsIdentifierOrKeyword); case SyntaxKind.ImportKeyword: + // Not true keywords so ensure an identifier follows or is string literal or asterisk + return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsterisk) ; case SyntaxKind.ModuleKeyword: // Not a true keyword so ensure an identifier or string literal follows return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); @@ -4642,6 +4674,12 @@ module ts { return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral; } + function nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsterisk() { + nextToken(); + return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral || + token === SyntaxKind.AsteriskToken; + } + function nextTokenIsEqualsTokenOrDeclarationStart() { nextToken(); return token === SyntaxKind.EqualsToken || isDeclarationStart(); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 4aef773004b1f..3b9cd8b72f0d5 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -38,6 +38,7 @@ module ts { var textToToken: Map = { "any": SyntaxKind.AnyKeyword, + "as": SyntaxKind.AsKeyword, "boolean": SyntaxKind.BooleanKeyword, "break": SyntaxKind.BreakKeyword, "case": SyntaxKind.CaseKeyword, @@ -58,6 +59,7 @@ module ts { "false": SyntaxKind.FalseKeyword, "finally": SyntaxKind.FinallyKeyword, "for": SyntaxKind.ForKeyword, + "from": SyntaxKind.FromKeyword, "function": SyntaxKind.FunctionKeyword, "get": SyntaxKind.GetKeyword, "if": SyntaxKind.IfKeyword, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 88d498695e7b4..3db028e56be5e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -120,6 +120,8 @@ module ts { WhileKeyword, WithKeyword, // Strict mode reserved words + AsKeyword, + FromKeyword, ImplementsKeyword, InterfaceKeyword, LetKeyword, diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js new file mode 100644 index 0000000000000..c6daa3b122255 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImport.ts] //// + +//// [es6ImportNameSpaceImport_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImport_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; + +//// [es6ImportNameSpaceImport_0.js] +exports.a = 10; +//// [es6ImportNameSpaceImport_1.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.types b/tests/baselines/reference/es6ImportNameSpaceImport.types new file mode 100644 index 0000000000000..d7cd562dc2789 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImport.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportNameSpaceImport_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImport_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js new file mode 100644 index 0000000000000..2c7785dec6ed5 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts] //// + +//// [es6ImportNameSpaceImportInEs5_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportInEs5_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; + +//// [es6ImportNameSpaceImportInEs5_0.js] +exports.a = 10; +//// [es6ImportNameSpaceImportInEs5_1.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types new file mode 100644 index 0000000000000..7818a4568e002 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportInEs5_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportInEs5_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImport.ts b/tests/cases/compiler/es6ImportNameSpaceImport.ts new file mode 100644 index 0000000000000..9937606c41ff4 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImport.ts @@ -0,0 +1,8 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNameSpaceImport_0.ts +export var a = 10; + +// @filename: es6ImportNameSpaceImport_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts b/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts new file mode 100644 index 0000000000000..ca00ac3f981e6 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNameSpaceImportInEs5_0.ts +export var a = 10; + +// @filename: es6ImportNameSpaceImportInEs5_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; \ No newline at end of file From 5eb009461e645923cbc7093e28a48afa6d0643ea Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 27 Jan 2015 16:28:28 -0800 Subject: [PATCH 05/46] Parsing for NamedImports NamedImports : { } { ImportsList } { ImportsList , } ImportsList : ImportSpecifier ImportsList , ImportSpecifier ImportSpecifier : ImportedBinding IdentifierName as ImportedBinding Conflicts: src/compiler/parser.ts --- src/compiler/parser.ts | 54 ++++++++++++++++--- .../reference/es6ImportNamedImport.js | 21 ++++++++ .../reference/es6ImportNamedImport.types | 21 ++++++++ .../reference/es6ImportNamedImportInEs5.js | 21 ++++++++ .../reference/es6ImportNamedImportInEs5.types | 21 ++++++++ ...s6ImportNamedImportParsingError.errors.txt | 32 +++++++++++ tests/cases/compiler/es6ImportNamedImport.ts | 15 ++++++ .../compiler/es6ImportNamedImportInEs5.ts | 15 ++++++ .../es6ImportNamedImportParsingError.ts | 11 ++++ 9 files changed, 204 insertions(+), 7 deletions(-) create mode 100644 tests/baselines/reference/es6ImportNamedImport.js create mode 100644 tests/baselines/reference/es6ImportNamedImport.types create mode 100644 tests/baselines/reference/es6ImportNamedImportInEs5.js create mode 100644 tests/baselines/reference/es6ImportNamedImportInEs5.types create mode 100644 tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt create mode 100644 tests/cases/compiler/es6ImportNamedImport.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportInEs5.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportParsingError.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 254e2cb12ca6b..c890ba86ee060 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -287,6 +287,7 @@ module ts { TypeArguments, // Type arguments in type argument list TupleElementTypes, // Element types in tuple element type list HeritageClauses, // Heritage clauses for a class or interface declaration. + ImportSpecifiers, // Named import clause's import specifier list Count // Number of parsing contexts } @@ -306,7 +307,7 @@ module ts { case ParsingContext.TypeMembers: return Diagnostics.Property_or_signature_expected; case ParsingContext.ClassMembers: return Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected; case ParsingContext.EnumMembers: return Diagnostics.Enum_member_expected; - case ParsingContext.TypeReferences: return Diagnostics.Type_reference_expected; + case ParsingContext.TypeReferences: return Diagnostics.Type_reference_expected; case ParsingContext.VariableDeclarations: return Diagnostics.Variable_declaration_expected; case ParsingContext.ObjectBindingElements: return Diagnostics.Property_destructuring_pattern_expected; case ParsingContext.ArrayBindingElements: return Diagnostics.Array_element_destructuring_pattern_expected; @@ -318,6 +319,7 @@ module ts { case ParsingContext.TypeArguments: return Diagnostics.Type_argument_expected; case ParsingContext.TupleElementTypes: return Diagnostics.Type_expected; case ParsingContext.HeritageClauses: return Diagnostics.Unexpected_token_expected; + case ParsingContext.ImportSpecifiers: return Diagnostics.Identifier_expected; } }; @@ -1450,6 +1452,8 @@ module ts { return token === SyntaxKind.CommaToken || isStartOfType(); case ParsingContext.HeritageClauses: return isHeritageClause(); + case ParsingContext.ImportSpecifiers: + return isIdentifierOrKeyword(); } Debug.fail("Non-exhaustive case in 'isListElement'."); @@ -1486,6 +1490,7 @@ module ts { case ParsingContext.EnumMembers: case ParsingContext.ObjectLiteralMembers: case ParsingContext.ObjectBindingElements: + case ParsingContext.ImportSpecifiers: return token === SyntaxKind.CloseBraceToken; case ParsingContext.SwitchClauseStatements: return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; @@ -4521,7 +4526,8 @@ module ts { function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement { parseExpected(SyntaxKind.ImportKeyword); if (token === SyntaxKind.StringLiteral || - token === SyntaxKind.AsteriskToken) { + token === SyntaxKind.AsteriskToken || + token === SyntaxKind.OpenBraceToken) { return parseImportStatement(fullStart, modifiers); } @@ -4598,7 +4604,7 @@ module ts { // ImportedDefaultBinding, NamedImports from var importClause = createNode(SyntaxKind.ImportClause); - importClause.bindings = parseNamespaceImport(); + importClause.bindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); parseExpected(SyntaxKind.FromKeyword); return finishNode(importClause); } @@ -4613,6 +4619,36 @@ module ts { return finishNode(namespaceImport); } + function parseNamedImports(): NamedImports { + var namedImports = createNode(SyntaxKind.NamedImports); + + // NamedImports: + // { } + // { ImportsList } + // { ImportsList, } + + // ImportsList: + // ImportSpecifier + // ImportsList, ImportSpecifier + parseExpected(SyntaxKind.OpenBraceToken); + namedImports.elements = parseDelimitedList(ParsingContext.ImportSpecifiers, parseImportSpecifier); + parseExpected(SyntaxKind.CloseBraceToken); + return finishNode(namedImports); + } + + function parseImportSpecifier(): ImportSpecifier { + var node = createNode(SyntaxKind.ImportSpecifier); + // ImportSpecifier: + // ImportedBinding + // IdentifierName as ImportedBinding + if (lookAhead(nextTokenIsAsKeyword)) { + node.propertyName = parseIdentifierName(); + parseExpected(SyntaxKind.AsKeyword); + } + node.name = parseIdentifier(); + return finishNode(node); + } + function parseExportAssignmentTail(fullStart: number, modifiers: ModifiersArray): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, fullStart); setModifiers(node, modifiers); @@ -4642,8 +4678,8 @@ module ts { // Not true keywords so ensure an identifier follows return lookAhead(nextTokenIsIdentifierOrKeyword); case SyntaxKind.ImportKeyword: - // Not true keywords so ensure an identifier follows or is string literal or asterisk - return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsterisk) ; + // Not true keywords so ensure an identifier follows or is string literal or asterisk or open brace + return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsteriskOrOpenBrace) ; case SyntaxKind.ModuleKeyword: // Not a true keyword so ensure an identifier or string literal follows return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); @@ -4674,10 +4710,10 @@ module ts { return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral; } - function nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsterisk() { + function nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsteriskOrOpenBrace() { nextToken(); return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral || - token === SyntaxKind.AsteriskToken; + token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken; } function nextTokenIsEqualsTokenOrDeclarationStart() { @@ -4690,6 +4726,10 @@ module ts { return isDeclarationStart(); } + function nextTokenIsAsKeyword() { + return nextToken() === SyntaxKind.AsKeyword; + } + function parseDeclaration(): ModuleElement { var fullStart = getNodePos(); var modifiers = parseModifiers(); diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js new file mode 100644 index 0000000000000..e8eee3fba19d1 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportNamedImport.ts] //// + +//// [es6ImportNamedImport_0.ts] + +export var a = 10; +export var x = a; +export var m = a; + +//// [es6ImportNamedImport_1.ts] +import { } from "es6ImportNamedImport_0"; +import { a } from "es6ImportNamedImport_0"; +import { a as b } from "es6ImportNamedImport_0"; +import { x, a as y } from "es6ImportNamedImport_0"; +import { x as z, } from "es6ImportNamedImport_0"; +import { m, } from "es6ImportNamedImport_0"; + +//// [es6ImportNamedImport_0.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +//// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types new file mode 100644 index 0000000000000..1e8c4f5af7ce1 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImport.types @@ -0,0 +1,21 @@ +=== 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 + +=== tests/cases/compiler/es6ImportNamedImport_1.ts === +import { } from "es6ImportNamedImport_0"; +No type information for this code.import { a } from "es6ImportNamedImport_0"; +No type information for this code.import { a as b } from "es6ImportNamedImport_0"; +No type information for this code.import { x, a as y } from "es6ImportNamedImport_0"; +No type information for this code.import { x as z, } from "es6ImportNamedImport_0"; +No type information for this code.import { m, } from "es6ImportNamedImport_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js new file mode 100644 index 0000000000000..4a7a95c6dbd9d --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportNamedImportInEs5.ts] //// + +//// [es6ImportNamedImportInEs5_0.ts] + +export var a = 10; +export var x = a; +export var m = a; + +//// [es6ImportNamedImportInEs5_1.ts] +import { } from "es6ImportNamedImportInEs5_0"; +import { a } from "es6ImportNamedImportInEs5_0"; +import { a as b } from "es6ImportNamedImportInEs5_0"; +import { x, a as y } from "es6ImportNamedImportInEs5_0"; +import { x as z, } from "es6ImportNamedImportInEs5_0"; +import { m, } from "es6ImportNamedImportInEs5_0"; + +//// [es6ImportNamedImportInEs5_0.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +//// [es6ImportNamedImportInEs5_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types new file mode 100644 index 0000000000000..5b8ed7a5e346b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es6ImportNamedImportInEs5_0.ts === + +export var a = 10; +>a : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +=== tests/cases/compiler/es6ImportNamedImportInEs5_1.ts === +import { } from "es6ImportNamedImportInEs5_0"; +No type information for this code.import { a } from "es6ImportNamedImportInEs5_0"; +No type information for this code.import { a as b } from "es6ImportNamedImportInEs5_0"; +No type information for this code.import { x, a as y } from "es6ImportNamedImportInEs5_0"; +No type information for this code.import { x as z, } from "es6ImportNamedImportInEs5_0"; +No type information for this code.import { m, } from "es6ImportNamedImportInEs5_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt new file mode 100644 index 0000000000000..ae1fba6b03868 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -0,0 +1,32 @@ +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: Expression expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,22): error TS1005: '=' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS2304: Cannot find name 'from'. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: ';' expected. + + +==== tests/cases/compiler/es6ImportNamedImportParsingError_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + +==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (7 errors) ==== + import { * } from "es6ImportNamedImportParsingError_0"; + ~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1109: Expression expected. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1005: ';' expected. + import defaultBinding, from "es6ImportNamedImportParsingError_0"; + ~ +!!! error TS1005: '=' expected. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImport.ts b/tests/cases/compiler/es6ImportNamedImport.ts new file mode 100644 index 0000000000000..1b5057d72fb82 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImport.ts @@ -0,0 +1,15 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNamedImport_0.ts +export var a = 10; +export var x = a; +export var m = a; + +// @filename: es6ImportNamedImport_1.ts +import { } from "es6ImportNamedImport_0"; +import { a } from "es6ImportNamedImport_0"; +import { a as b } from "es6ImportNamedImport_0"; +import { x, a as y } from "es6ImportNamedImport_0"; +import { x as z, } from "es6ImportNamedImport_0"; +import { m, } from "es6ImportNamedImport_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportInEs5.ts b/tests/cases/compiler/es6ImportNamedImportInEs5.ts new file mode 100644 index 0000000000000..4acad0bf7cbf0 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportInEs5.ts @@ -0,0 +1,15 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNamedImportInEs5_0.ts +export var a = 10; +export var x = a; +export var m = a; + +// @filename: es6ImportNamedImportInEs5_1.ts +import { } from "es6ImportNamedImportInEs5_0"; +import { a } from "es6ImportNamedImportInEs5_0"; +import { a as b } from "es6ImportNamedImportInEs5_0"; +import { x, a as y } from "es6ImportNamedImportInEs5_0"; +import { x as z, } from "es6ImportNamedImportInEs5_0"; +import { m, } from "es6ImportNamedImportInEs5_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportParsingError.ts b/tests/cases/compiler/es6ImportNamedImportParsingError.ts new file mode 100644 index 0000000000000..2bd9493418c63 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportParsingError.ts @@ -0,0 +1,11 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNamedImportParsingError_0.ts +export var a = 10; +export var x = a; +export var m = a; + +// @filename: es6ImportNamedImportParsingError_1.ts +import { * } from "es6ImportNamedImportParsingError_0"; +import defaultBinding, from "es6ImportNamedImportParsingError_0"; \ No newline at end of file From 69fef6e54425965462f5ca101b7298402e3cd347 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 27 Jan 2015 16:43:46 -0800 Subject: [PATCH 06/46] Parsing for default binding import syntax --- src/compiler/parser.ts | 23 +++++++++++++++++-- .../reference/es6ImportDefaultBinding.js | 12 ++++++++++ .../reference/es6ImportDefaultBinding.types | 8 +++++++ ...rtDefaultBindingFollowedWithNamedImport.js | 21 +++++++++++++++++ ...efaultBindingFollowedWithNamedImport.types | 21 +++++++++++++++++ ...aultBindingFollowedWithNamedImportInEs5.js | 21 +++++++++++++++++ ...tBindingFollowedWithNamedImportInEs5.types | 21 +++++++++++++++++ ...aultBindingFollowedWithNamespaceBinding.js | 12 ++++++++++ ...tBindingFollowedWithNamespaceBinding.types | 8 +++++++ ...indingFollowedWithNamespaceBindingInEs5.js | 12 ++++++++++ ...ingFollowedWithNamespaceBindingInEs5.types | 8 +++++++ .../reference/es6ImportDefaultBindingInEs5.js | 12 ++++++++++ .../es6ImportDefaultBindingInEs5.types | 8 +++++++ ...s6ImportNamedImportParsingError.errors.txt | 13 ++++------- .../cases/compiler/es6ImportDefaultBinding.ts | 8 +++++++ ...rtDefaultBindingFollowedWithNamedImport.ts | 15 ++++++++++++ ...aultBindingFollowedWithNamedImportInEs5.ts | 15 ++++++++++++ ...aultBindingFollowedWithNamespaceBinding.ts | 8 +++++++ ...indingFollowedWithNamespaceBindingInEs5.ts | 8 +++++++ .../compiler/es6ImportDefaultBindingInEs5.ts | 8 +++++++ 20 files changed, 252 insertions(+), 10 deletions(-) create mode 100644 tests/baselines/reference/es6ImportDefaultBinding.js create mode 100644 tests/baselines/reference/es6ImportDefaultBinding.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingInEs5.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingInEs5.types create mode 100644 tests/cases/compiler/es6ImportDefaultBinding.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingInEs5.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c890ba86ee060..57b53d81a0eb2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4523,11 +4523,18 @@ module ts { return nextToken() === SyntaxKind.OpenParenToken; } + function nextTokenIsCommaOrFromKeyword() { + nextToken(); + return token === SyntaxKind.CommaToken || + token === SyntaxKind.FromKeyword; + } + function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement { parseExpected(SyntaxKind.ImportKeyword); if (token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken) { + token === SyntaxKind.OpenBraceToken || + (isIdentifier() && lookAhead(nextTokenIsCommaOrFromKeyword))) { return parseImportStatement(fullStart, modifiers); } @@ -4604,7 +4611,19 @@ module ts { // ImportedDefaultBinding, NamedImports from var importClause = createNode(SyntaxKind.ImportClause); - importClause.bindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); + if (isIdentifier()) { + // ImportedDefaultBinding: + // ImportedBinding + importClause.defaultBinding = parseIdentifier(); + } + + // If there was no default import or if there is comma token after default import + // parse namespace or named imports + if (!importClause.defaultBinding || + parseOptional(SyntaxKind.CommaToken)) { + importClause.bindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); + } + parseExpected(SyntaxKind.FromKeyword); return finishNode(importClause); } diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js new file mode 100644 index 0000000000000..d8d1fa8111dc3 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportDefaultBinding.ts] //// + +//// [es6ImportDefaultBinding_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBinding_1.ts] +import defaultBinding from "es6ImportDefaultBinding_0"; + +//// [es6ImportDefaultBinding_0.js] +exports.a = 10; +//// [es6ImportDefaultBinding_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBinding.types b/tests/baselines/reference/es6ImportDefaultBinding.types new file mode 100644 index 0000000000000..262ce5966b338 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBinding.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportDefaultBinding_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBinding_1.ts === +import defaultBinding from "es6ImportDefaultBinding_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js new file mode 100644 index 0000000000000..a7402bfeb6a8e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport_0.ts] + +export var a = 10; +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"; + +//// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +//// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types new file mode 100644 index 0000000000000..35dacc7d93a48 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts === + +export var a = 10; +>a : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts === +import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +No type information for this code.import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +No type information for this code.import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +No type information for this code.import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +No type information for this code.import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +No type information for this code.import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js new file mode 100644 index 0000000000000..4cf3046532a0a --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts] + +export var a = 10; +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"; + +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types new file mode 100644 index 0000000000000..a98cca1edcf27 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts === + +export var a = 10; +>a : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts === +import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +No type information for this code.import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +No type information for this code.import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +No type information for this code.import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +No type information for this code.import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +No type information for this code.import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js new file mode 100644 index 0000000000000..5ec91279306dd --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] +exports.a = 10; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types new file mode 100644 index 0000000000000..9f9db16a6f41a --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js new file mode 100644 index 0000000000000..abd4736fca706 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] +exports.a = 10; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types new file mode 100644 index 0000000000000..841bb9d68b565 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js new file mode 100644 index 0000000000000..b6d293225fd0b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js @@ -0,0 +1,12 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingInEs5.ts] //// + +//// [es6ImportDefaultBindingInEs5_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBindingInEs5_1.ts] +import defaultBinding from "es6ImportDefaultBindingInEs5_0"; + +//// [es6ImportDefaultBindingInEs5_0.js] +exports.a = 10; +//// [es6ImportDefaultBindingInEs5_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types new file mode 100644 index 0000000000000..1f3c4141f5b38 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts === +import defaultBinding from "es6ImportDefaultBindingInEs5_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt index ae1fba6b03868..f33c218afcde8 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -2,9 +2,8 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1003: tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: Expression expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,22): error TS1005: '=' expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS2304: Cannot find name 'from'. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: ';' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: '{' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: ',' expected. ==== tests/cases/compiler/es6ImportNamedImportParsingError_0.ts (0 errors) ==== @@ -13,7 +12,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (7 errors) ==== +==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (6 errors) ==== import { * } from "es6ImportNamedImportParsingError_0"; ~ !!! error TS1003: Identifier expected. @@ -24,9 +23,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1005: ';' expected. import defaultBinding, from "es6ImportNamedImportParsingError_0"; - ~ -!!! error TS1005: '=' expected. ~~~~ -!!! error TS2304: Cannot find name 'from'. +!!! error TS1005: '{' expected. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1005: ';' expected. \ No newline at end of file +!!! error TS1005: ',' expected. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBinding.ts b/tests/cases/compiler/es6ImportDefaultBinding.ts new file mode 100644 index 0000000000000..dc5b4ab98d61c --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBinding.ts @@ -0,0 +1,8 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportDefaultBinding_0.ts +export var a = 10; + +// @filename: es6ImportDefaultBinding_1.ts +import defaultBinding from "es6ImportDefaultBinding_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts new file mode 100644 index 0000000000000..96b277d6640cd --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts @@ -0,0 +1,15 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport_0.ts +export var a = 10; +export var x = a; +export var m = a; + +// @filename: 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"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts new file mode 100644 index 0000000000000..bf34687f79162 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts @@ -0,0 +1,15 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts +export var a = 10; +export var x = a; +export var m = a; + +// @filename: 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"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts new file mode 100644 index 0000000000000..3d029e28738bd --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts @@ -0,0 +1,8 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts +export var a = 10; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts new file mode 100644 index 0000000000000..5943fa8bfc462 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts +export var a = 10; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts new file mode 100644 index 0000000000000..c037d283dfa74 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportDefaultBindingInEs5_0.ts +export var a = 10; + +// @filename: es6ImportDefaultBindingInEs5_1.ts +import defaultBinding from "es6ImportDefaultBindingInEs5_0"; \ No newline at end of file From d296a100964fcec5208252f50633babc89a97ed1 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 29 Jan 2015 12:48:40 -0800 Subject: [PATCH 07/46] Rename bindings to namedBindings in ImportClause --- src/compiler/parser.ts | 2 +- src/compiler/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 57b53d81a0eb2..01f286fb9c159 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4621,7 +4621,7 @@ module ts { // parse namespace or named imports if (!importClause.defaultBinding || parseOptional(SyntaxKind.CommaToken)) { - importClause.bindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); + importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); } parseExpected(SyntaxKind.FromKeyword); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3db028e56be5e..30a1453959a1b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -875,7 +875,7 @@ module ts { export interface ImportClause extends Node { defaultBinding?: Identifier; - bindings?: NamespaceImport | NamedImports; + namedBindings?: NamespaceImport | NamedImports; } export interface NamespaceImport extends Declaration { From b0f2265fe39b8d0d8dde9f9dfeb750f4f854204c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 29 Jan 2015 13:38:26 -0800 Subject: [PATCH 08/46] Code review feedback --- src/compiler/parser.ts | 116 +++++++++--------- src/compiler/types.ts | 10 ++ ...s6ImportNamedImportParsingError.errors.txt | 7 +- 3 files changed, 68 insertions(+), 65 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 01f286fb9c159..a25f99d59b3ef 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4531,20 +4531,61 @@ module ts { function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement { parseExpected(SyntaxKind.ImportKeyword); - if (token === SyntaxKind.StringLiteral || - token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || - (isIdentifier() && lookAhead(nextTokenIsCommaOrFromKeyword))) { - return parseImportStatement(fullStart, modifiers); + var identifier: Identifier; + if (isIdentifier()) { + identifier = parseIdentifier(); + if (token !== SyntaxKind.CommaToken && token !== SyntaxKind.FromKeyword) { + // ImportEquals declaration of type: + // import x = require("mod"); or + // import x = M.x; + var importEqualsDeclaration = createNode(SyntaxKind.ImportEqualsDeclaration, fullStart); + setModifiers(importEqualsDeclaration, modifiers); + importEqualsDeclaration.name = identifier; + parseExpected(SyntaxKind.EqualsToken); + importEqualsDeclaration.moduleReference = parseModuleReference(); + parseSemicolon(); + return finishNode(importEqualsDeclaration); + } } - var node = createNode(SyntaxKind.ImportEqualsDeclaration, fullStart); - setModifiers(node, modifiers); - node.name = parseIdentifier(); - parseExpected(SyntaxKind.EqualsToken); - node.moduleReference = parseModuleReference(); + // Import statement + var importStatement = createNode(SyntaxKind.ImportStatement, fullStart); + setModifiers(importStatement, modifiers); + + // ImportDeclaration: + // import ImportClause from ModuleSpecifier ; + // import ModuleSpecifier; + if (identifier || // import id + token === SyntaxKind.AsteriskToken || // import * + token === SyntaxKind.OpenBraceToken) { // import { + //ImportClause: + // ImportedDefaultBinding + // NameSpaceImport + // NamedImports + // ImportedDefaultBinding, NameSpaceImport + // ImportedDefaultBinding, NamedImports + + var importClause = createNode(SyntaxKind.ImportClause); + if (identifier) { + // ImportedDefaultBinding: + // ImportedBinding + importClause.defaultBinding = identifier; + } + + // If there was no default import or if there is comma token after default import + // parse namespace or named imports + if (!importClause.defaultBinding || + parseOptional(SyntaxKind.CommaToken)) { + importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); + } + + importStatement.importClause = finishNode(importClause); + parseExpected(SyntaxKind.FromKeyword); + } + + importStatement.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); - return finishNode(node); + return finishNode(importStatement); } function parseModuleReference() { @@ -4573,61 +4614,18 @@ module ts { return finishNode(node); } - function parseImportStatement(fullStart: number, modifiers: ModifiersArray): ImportStatement { - var node = createNode(SyntaxKind.ImportStatement, fullStart); - setModifiers(node, modifiers); - - // ImportDeclaration: - // import ImportClause ModuleSpecifier ; - // import ModuleSpecifier; - if (token !== SyntaxKind.StringLiteral) { - // ImportDeclaration: - node.importClause = parseImportClause(); - } - node.moduleSpecifier = parseModuleSpecifier(); - parseSemicolon(); - return finishNode(node); - } - function parseModuleSpecifier(): StringLiteralExpression { // ModuleSpecifier: // StringLiteral if (token === SyntaxKind.StringLiteral) { // Ensure the string being required is in our 'identifier' table. This will ensure // that features like 'find refs' will look inside this file when search for its name. - var moduleSpecifier = parseLiteralNode(/*internName*/ true); - return moduleSpecifier; + return parseLiteralNode(/*internName*/ true); } parseErrorAtCurrentToken(Diagnostics.String_literal_expected); } - function parseImportClause(): ImportClause { - //ImportClause: - // ImportedDefaultBinding from - // NameSpaceImport from - // NamedImports from - // ImportedDefaultBinding, NameSpaceImport from - // ImportedDefaultBinding, NamedImports from - - var importClause = createNode(SyntaxKind.ImportClause); - if (isIdentifier()) { - // ImportedDefaultBinding: - // ImportedBinding - importClause.defaultBinding = parseIdentifier(); - } - - // If there was no default import or if there is comma token after default import - // parse namespace or named imports - if (!importClause.defaultBinding || - parseOptional(SyntaxKind.CommaToken)) { - importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); - } - - parseExpected(SyntaxKind.FromKeyword); - return finishNode(importClause); - } - function parseNamespaceImport(): NamespaceImport { // NameSpaceImport: // * as ImportedBinding @@ -4649,9 +4647,7 @@ module ts { // ImportsList: // ImportSpecifier // ImportsList, ImportSpecifier - parseExpected(SyntaxKind.OpenBraceToken); - namedImports.elements = parseDelimitedList(ParsingContext.ImportSpecifiers, parseImportSpecifier); - parseExpected(SyntaxKind.CloseBraceToken); + namedImports.elements = parseBracketedList(ParsingContext.ImportSpecifiers, parseImportSpecifier, SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken); return finishNode(namedImports); } @@ -4698,7 +4694,7 @@ module ts { return lookAhead(nextTokenIsIdentifierOrKeyword); case SyntaxKind.ImportKeyword: // Not true keywords so ensure an identifier follows or is string literal or asterisk or open brace - return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsteriskOrOpenBrace) ; + return lookAhead(nextTokenCanFollowImportKeyword); case SyntaxKind.ModuleKeyword: // Not a true keyword so ensure an identifier or string literal follows return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); @@ -4729,7 +4725,7 @@ module ts { return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral; } - function nextTokenIsIdentifierOrKeywordOrStringLiteralOrAsteriskOrOpenBrace() { + function nextTokenCanFollowImportKeyword() { nextToken(); return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 30a1453959a1b..3d5696beec367 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -868,11 +868,21 @@ module ts { expression?: Expression; } + // In case of: + // import "mod" => importClause = undefined, moduleSpecifier = "mod" + // In rest of the cases, module specifier is string literal corresponding to module + // ImportClause information is shown at its declaration below. export interface ImportStatement extends Statement, ModuleElement { importClause?: ImportClause; moduleSpecifier: StringLiteralExpression; } + // In case of: + // import d from "mod" => defaultBinding = d, namedBinding = undefined + // import * as ns from "mod" => defaultBinding = undefined, namedBinding: NamespaceImport = { name: ns } + // import d, * as ns from "mod" => defaultBinding = d, namedBinding: NamespaceImport = { name: ns } + // import { a, b as x } from "mod" => defaultBinding = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} + // import d, { a, b as x } from "mod" => defaultBinding = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} export interface ImportClause extends Node { defaultBinding?: Identifier; namedBindings?: NamespaceImport | NamedImports; diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt index f33c218afcde8..45f2732be255f 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -3,7 +3,6 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: '{' expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: ',' expected. ==== tests/cases/compiler/es6ImportNamedImportParsingError_0.ts (0 errors) ==== @@ -12,7 +11,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (6 errors) ==== +==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (5 errors) ==== import { * } from "es6ImportNamedImportParsingError_0"; ~ !!! error TS1003: Identifier expected. @@ -24,6 +23,4 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,29): error TS1005: !!! error TS1005: ';' expected. import defaultBinding, from "es6ImportNamedImportParsingError_0"; ~~~~ -!!! error TS1005: '{' expected. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1005: ',' expected. \ No newline at end of file +!!! error TS1005: '{' expected. \ No newline at end of file From fc912729f54308c93b4c172aecf805e59a436a63 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 29 Jan 2015 14:14:05 -0800 Subject: [PATCH 09/46] Some refactoring of how import specifiers are parsed as per code review feedback --- src/compiler/parser.ts | 16 +++++++++++++--- ...ortNamedImportIdentifiersParsing.errors.txt | 18 ++++++++++++++++++ .../es6ImportNamedImportIdentifiersParsing.ts | 8 ++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt create mode 100644 tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a25f99d59b3ef..a808fb572f7c1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4656,11 +4656,21 @@ module ts { // ImportSpecifier: // ImportedBinding // IdentifierName as ImportedBinding - if (lookAhead(nextTokenIsAsKeyword)) { - node.propertyName = parseIdentifierName(); + var isfirstIdentifierNameNotAnIdentifier = isKeyword(token) && !isIdentifier(); + var start = scanner.getTokenPos(); + var identifierName = parseIdentifierName(); + if (token === SyntaxKind.AsKeyword) { + node.propertyName = identifierName; parseExpected(SyntaxKind.AsKeyword); + node.name = parseIdentifier(); + } + else { + node.name = identifierName; + if (isfirstIdentifierNameNotAnIdentifier) { + // Report error identifier expected + parseErrorAtPosition(start, identifierName.end - start, Diagnostics.Identifier_expected); + } } - node.name = parseIdentifier(); return finishNode(node); } diff --git a/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt new file mode 100644 index 0000000000000..7d0570aa71613 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(3,10): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(4,19): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(6,21): error TS1003: Identifier expected. + + +==== tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts (3 errors) ==== + + import { yield } from "somemodule"; // Allowed + import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier + ~~~~~~~ +!!! error TS1003: Identifier expected. + import { yield as default } from "somemodule"; // error to use default as binding name + ~~~~~~~ +!!! error TS1003: Identifier expected. + import { default as yield } from "somemodule"; // no error + import { default as default } from "somemodule"; // default as is ok, error of default binding name + ~~~~~~~ +!!! error TS1003: Identifier expected. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts b/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts new file mode 100644 index 0000000000000..e1be293e4468e --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts @@ -0,0 +1,8 @@ +// @target: es6 +// @module: commonjs + +import { yield } from "somemodule"; // Allowed +import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier +import { yield as default } from "somemodule"; // error to use default as binding name +import { default as yield } from "somemodule"; // no error +import { default as default } from "somemodule"; // default as is ok, error of default binding name \ No newline at end of file From 89d0146b1cd1699b0aea80a0bd27ec7b5b1b65ec Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 29 Jan 2015 14:20:03 -0800 Subject: [PATCH 10/46] Tests for more combination of import specifier list --- tests/baselines/reference/es6ImportNamedImport.js | 8 +++++++- tests/baselines/reference/es6ImportNamedImport.types | 8 ++++++++ tests/baselines/reference/es6ImportNamedImportInEs5.js | 8 +++++++- tests/baselines/reference/es6ImportNamedImportInEs5.types | 8 ++++++++ tests/cases/compiler/es6ImportNamedImport.ts | 6 +++++- tests/cases/compiler/es6ImportNamedImportInEs5.ts | 6 +++++- 6 files changed, 40 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index e8eee3fba19d1..c52499ef994a7 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -5,6 +5,8 @@ export var a = 10; export var x = a; export var m = a; +export var a1 = 10; +export var x1 = 10; //// [es6ImportNamedImport_1.ts] import { } from "es6ImportNamedImport_0"; @@ -12,10 +14,14 @@ import { a } from "es6ImportNamedImport_0"; import { a as b } from "es6ImportNamedImport_0"; import { x, a as y } from "es6ImportNamedImport_0"; import { x as z, } from "es6ImportNamedImport_0"; -import { m, } from "es6ImportNamedImport_0"; +import { m, } from "es6ImportNamedImport_0"; +import { a1, x1 } from "es6ImportNamedImport_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; //// [es6ImportNamedImport_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; +exports.a1 = 10; +exports.x1 = 10; //// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types index 1e8c4f5af7ce1..23fc73ef6e9a6 100644 --- a/tests/baselines/reference/es6ImportNamedImport.types +++ b/tests/baselines/reference/es6ImportNamedImport.types @@ -11,6 +11,12 @@ 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"; No type information for this code.import { a } from "es6ImportNamedImport_0"; @@ -18,4 +24,6 @@ No type information for this code.import { a as b } from "es6ImportNamedImport_0 No type information for this code.import { x, a as y } from "es6ImportNamedImport_0"; No type information for this code.import { x as z, } from "es6ImportNamedImport_0"; No type information for this code.import { m, } from "es6ImportNamedImport_0"; +No type information for this code.import { a1, x1 } from "es6ImportNamedImport_0"; +No type information for this code.import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js index 4a7a95c6dbd9d..66f8ce0ef9268 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -5,6 +5,8 @@ export var a = 10; export var x = a; export var m = a; +export var a1 = 10; +export var x1 = 10; //// [es6ImportNamedImportInEs5_1.ts] import { } from "es6ImportNamedImportInEs5_0"; @@ -12,10 +14,14 @@ import { a } from "es6ImportNamedImportInEs5_0"; import { a as b } from "es6ImportNamedImportInEs5_0"; import { x, a as y } from "es6ImportNamedImportInEs5_0"; import { x as z, } from "es6ImportNamedImportInEs5_0"; -import { m, } from "es6ImportNamedImportInEs5_0"; +import { m, } from "es6ImportNamedImportInEs5_0"; +import { a1, x1 } from "es6ImportNamedImportInEs5_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; //// [es6ImportNamedImportInEs5_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; +exports.a1 = 10; +exports.x1 = 10; //// [es6ImportNamedImportInEs5_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types index 5b8ed7a5e346b..7fecc149aa285 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.types +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -11,6 +11,12 @@ export var m = a; >m : number >a : number +export var a1 = 10; +>a1 : number + +export var x1 = 10; +>x1 : number + === tests/cases/compiler/es6ImportNamedImportInEs5_1.ts === import { } from "es6ImportNamedImportInEs5_0"; No type information for this code.import { a } from "es6ImportNamedImportInEs5_0"; @@ -18,4 +24,6 @@ No type information for this code.import { a as b } from "es6ImportNamedImportIn No type information for this code.import { x, a as y } from "es6ImportNamedImportInEs5_0"; No type information for this code.import { x as z, } from "es6ImportNamedImportInEs5_0"; No type information for this code.import { m, } from "es6ImportNamedImportInEs5_0"; +No type information for this code.import { a1, x1 } from "es6ImportNamedImportInEs5_0"; +No type information for this code.import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImport.ts b/tests/cases/compiler/es6ImportNamedImport.ts index 1b5057d72fb82..ed34434bd292c 100644 --- a/tests/cases/compiler/es6ImportNamedImport.ts +++ b/tests/cases/compiler/es6ImportNamedImport.ts @@ -5,6 +5,8 @@ export var a = 10; export var x = a; export var m = a; +export var a1 = 10; +export var x1 = 10; // @filename: es6ImportNamedImport_1.ts import { } from "es6ImportNamedImport_0"; @@ -12,4 +14,6 @@ import { a } from "es6ImportNamedImport_0"; import { a as b } from "es6ImportNamedImport_0"; import { x, a as y } from "es6ImportNamedImport_0"; import { x as z, } from "es6ImportNamedImport_0"; -import { m, } from "es6ImportNamedImport_0"; \ No newline at end of file +import { m, } from "es6ImportNamedImport_0"; +import { a1, x1 } from "es6ImportNamedImport_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportInEs5.ts b/tests/cases/compiler/es6ImportNamedImportInEs5.ts index 4acad0bf7cbf0..22e66bc95fa42 100644 --- a/tests/cases/compiler/es6ImportNamedImportInEs5.ts +++ b/tests/cases/compiler/es6ImportNamedImportInEs5.ts @@ -5,6 +5,8 @@ export var a = 10; export var x = a; export var m = a; +export var a1 = 10; +export var x1 = 10; // @filename: es6ImportNamedImportInEs5_1.ts import { } from "es6ImportNamedImportInEs5_0"; @@ -12,4 +14,6 @@ import { a } from "es6ImportNamedImportInEs5_0"; import { a as b } from "es6ImportNamedImportInEs5_0"; import { x, a as y } from "es6ImportNamedImportInEs5_0"; import { x as z, } from "es6ImportNamedImportInEs5_0"; -import { m, } from "es6ImportNamedImportInEs5_0"; \ No newline at end of file +import { m, } from "es6ImportNamedImportInEs5_0"; +import { a1, x1 } from "es6ImportNamedImportInEs5_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; \ No newline at end of file From 484144bf9818cbe4e7deed685711b1e1d4eb01dc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 29 Jan 2015 14:30:28 -0800 Subject: [PATCH 11/46] More test cases for incorrect named modules specification --- ...s6ImportNamedImportParsingError.errors.txt | 30 +++++++++++++++++-- .../es6ImportNamedImportParsingError.ts | 4 ++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt index 45f2732be255f..fd5a077f64867 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -3,6 +3,14 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: '{' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,1): error TS1128: Declaration or statement expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,8): error TS1128: Declaration or statement expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,12): error TS2304: Cannot find name 'a'. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,16): error TS2304: Cannot find name 'from'. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,21): error TS1005: ';' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,13): error TS1005: 'from' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,15): error TS2304: Cannot find name 'from'. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: ';' expected. ==== tests/cases/compiler/es6ImportNamedImportParsingError_0.ts (0 errors) ==== @@ -11,7 +19,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (5 errors) ==== +==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (13 errors) ==== import { * } from "es6ImportNamedImportParsingError_0"; ~ !!! error TS1003: Identifier expected. @@ -23,4 +31,22 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: !!! error TS1005: ';' expected. import defaultBinding, from "es6ImportNamedImportParsingError_0"; ~~~~ -!!! error TS1005: '{' expected. \ No newline at end of file +!!! error TS1005: '{' expected. + import , { a } from "es6ImportNamedImportParsingError_0"; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS2304: Cannot find name 'a'. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1005: ';' expected. + import { a }, from "es6ImportNamedImportParsingError_0"; + ~ +!!! error TS1005: 'from' expected. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportParsingError.ts b/tests/cases/compiler/es6ImportNamedImportParsingError.ts index 2bd9493418c63..a836acc11405d 100644 --- a/tests/cases/compiler/es6ImportNamedImportParsingError.ts +++ b/tests/cases/compiler/es6ImportNamedImportParsingError.ts @@ -8,4 +8,6 @@ export var m = a; // @filename: es6ImportNamedImportParsingError_1.ts import { * } from "es6ImportNamedImportParsingError_0"; -import defaultBinding, from "es6ImportNamedImportParsingError_0"; \ No newline at end of file +import defaultBinding, from "es6ImportNamedImportParsingError_0"; +import , { a } from "es6ImportNamedImportParsingError_0"; +import { a }, from "es6ImportNamedImportParsingError_0"; \ No newline at end of file From c521fe434e274c30a138833282907f93e224cf5a Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 29 Jan 2015 16:27:33 -0800 Subject: [PATCH 12/46] Rename ImportStatement to ImportDeclaration --- src/compiler/parser.ts | 14 +++++++------- src/compiler/types.ts | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a808fb572f7c1..98d733acd17b3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4529,7 +4529,7 @@ module ts { token === SyntaxKind.FromKeyword; } - function parseImportDeclarationOrStatement(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportStatement { + function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); var identifier: Identifier; if (isIdentifier()) { @@ -4549,8 +4549,8 @@ module ts { } // Import statement - var importStatement = createNode(SyntaxKind.ImportStatement, fullStart); - setModifiers(importStatement, modifiers); + var importDeclaration = createNode(SyntaxKind.ImportDeclaration, fullStart); + setModifiers(importDeclaration, modifiers); // ImportDeclaration: // import ImportClause from ModuleSpecifier ; @@ -4579,13 +4579,13 @@ module ts { importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); } - importStatement.importClause = finishNode(importClause); + importDeclaration.importClause = finishNode(importClause); parseExpected(SyntaxKind.FromKeyword); } - importStatement.moduleSpecifier = parseModuleSpecifier(); + importDeclaration.moduleSpecifier = parseModuleSpecifier(); parseSemicolon(); - return finishNode(importStatement); + return finishNode(importDeclaration); } function parseModuleReference() { @@ -4783,7 +4783,7 @@ module ts { case SyntaxKind.ModuleKeyword: return parseModuleDeclaration(fullStart, modifiers); case SyntaxKind.ImportKeyword: - return parseImportDeclarationOrStatement(fullStart, modifiers); + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); default: Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3d5696beec367..d141024091197 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -232,7 +232,7 @@ module ts { ModuleBlock, ImportEqualsDeclaration, ExportAssignment, - ImportStatement, + ImportDeclaration, ImportClause, NamespaceImport, NamedImports, @@ -872,7 +872,7 @@ module ts { // import "mod" => importClause = undefined, moduleSpecifier = "mod" // In rest of the cases, module specifier is string literal corresponding to module // ImportClause information is shown at its declaration below. - export interface ImportStatement extends Statement, ModuleElement { + export interface ImportDeclaration extends Statement, ModuleElement { importClause?: ImportClause; moduleSpecifier: StringLiteralExpression; } From d85581ba0ef2201244a6fffa17825d6855464dc2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 30 Jan 2015 12:49:20 -0800 Subject: [PATCH 13/46] Do not create Name of the importSpecifier if it isnt identifier, to avoid creating missing symbols Missing symbols are defined when the declaration doesnt have name, so if we created node for missing identifier it would end up binding symbol with name (Missing) --- src/compiler/parser.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 98d733acd17b3..35c74a7ef48dd 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4656,21 +4656,27 @@ module ts { // ImportSpecifier: // ImportedBinding // IdentifierName as ImportedBinding - var isfirstIdentifierNameNotAnIdentifier = isKeyword(token) && !isIdentifier(); + var isFirstIdentifierNameNotAnIdentifier = isKeyword(token) && !isIdentifier(); var start = scanner.getTokenPos(); var identifierName = parseIdentifierName(); if (token === SyntaxKind.AsKeyword) { node.propertyName = identifierName; parseExpected(SyntaxKind.AsKeyword); - node.name = parseIdentifier(); + if (isIdentifier()) { + node.name = parseIdentifierName(); + } + else { + parseErrorAtCurrentToken(Diagnostics.Identifier_expected); + } } else { node.name = identifierName; - if (isfirstIdentifierNameNotAnIdentifier) { + if (isFirstIdentifierNameNotAnIdentifier) { // Report error identifier expected parseErrorAtPosition(start, identifierName.end - start, Diagnostics.Identifier_expected); } } + return finishNode(node); } From 62ed6183d9ceda708a8ce184960d7f25e8d45cf5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 30 Jan 2015 13:02:11 -0800 Subject: [PATCH 14/46] Change the name of defaultBinding to name and make ImportClause as Declaration This helps binder to use it directly to bind the default binding --- src/compiler/parser.ts | 4 ++-- src/compiler/types.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 35c74a7ef48dd..33742378b617c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4569,12 +4569,12 @@ module ts { if (identifier) { // ImportedDefaultBinding: // ImportedBinding - importClause.defaultBinding = identifier; + importClause.name = identifier; } // If there was no default import or if there is comma token after default import // parse namespace or named imports - if (!importClause.defaultBinding || + if (!importClause.name || parseOptional(SyntaxKind.CommaToken)) { importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d141024091197..d46e31dc982d1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -878,13 +878,13 @@ module ts { } // In case of: - // import d from "mod" => defaultBinding = d, namedBinding = undefined - // import * as ns from "mod" => defaultBinding = undefined, namedBinding: NamespaceImport = { name: ns } - // import d, * as ns from "mod" => defaultBinding = d, namedBinding: NamespaceImport = { name: ns } - // import { a, b as x } from "mod" => defaultBinding = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} - // import d, { a, b as x } from "mod" => defaultBinding = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} - export interface ImportClause extends Node { - defaultBinding?: Identifier; + // import d from "mod" => name = d, namedBinding = undefined + // import * as ns from "mod" => name = undefined, namedBinding: NamespaceImport = { name: ns } + // import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns } + // import { a, b as x } from "mod" => name = undefined, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} + // import d, { a, b as x } from "mod" => name = d, namedBinding: NamedImports = { elements: [{ name: a }, { name: x, propertyName: b}]} + export interface ImportClause extends Declaration { + name?: Identifier; // Default binding namedBindings?: NamespaceImport | NamedImports; } From a9575a509eeece18a7f1d311243c0176e43ca4da Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 30 Jan 2015 13:36:17 -0800 Subject: [PATCH 15/46] New Import declaration syntax makes the source file external module --- src/compiler/parser.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 33742378b617c..f53a2e2a6360f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4874,6 +4874,7 @@ module ts { node.flags & NodeFlags.Export || node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference || node.kind === SyntaxKind.ExportAssignment + || node.kind === SyntaxKind.ImportDeclaration ? node : undefined); } From 36c9cf09e647c50121aa76187a63ec6e10485bfc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 06:13:54 -0800 Subject: [PATCH 16/46] Adding new import nodes to forEachChild --- src/compiler/parser.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f53a2e2a6360f..fcdf9be521cd0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -250,6 +250,20 @@ module ts { return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).moduleReference); + case SyntaxKind.ImportDeclaration: + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).importClause) || + visitNode(cbNode, (node).moduleSpecifier); + case SyntaxKind.ImportClause: + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).namedBindings); + case SyntaxKind.NamespaceImport: + return visitNode(cbNode, (node).name); + case SyntaxKind.NamedImports: + return visitNodes(cbNodes, (node).elements); + case SyntaxKind.ImportSpecifier: + return visitNode(cbNode, (node).propertyName) || + visitNode(cbNode, (node).name); case SyntaxKind.ExportAssignment: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportName); From 35583e66948cffb3c1246825eea1f12e989e3d70 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 06:15:03 -0800 Subject: [PATCH 17/46] Process ES6 imports when creating program --- src/compiler/program.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 998e251239585..8b2d899f32108 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -274,13 +274,26 @@ module ts { }); } + function getImportedModuleName(node: Node): StringLiteralExpression { + if (node.kind === SyntaxKind.ImportDeclaration) { + return (node).moduleSpecifier; + } + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + var reference = (node).moduleReference; + if (reference.kind === SyntaxKind.ExternalModuleReference) { + var expr = (reference).expression; + if (expr && expr.kind === SyntaxKind.StringLiteral) { + return expr; + } + } + } + } + function processImportedModules(file: SourceFile, basePath: string) { forEach(file.statements, node => { - if (isExternalModuleImportEqualsDeclaration(node) && - getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { - - var nameLiteral = getExternalModuleImportEqualsDeclarationExpression(node); - var moduleName = nameLiteral.text; + if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) { + var nameLiteral = getImportedModuleName(node); + var moduleName = nameLiteral && nameLiteral.text; if (moduleName) { var searchPath = basePath; while (true) { From c6a6619ce73d6f59416f3a19e89b19787ac0fb18 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 06:15:47 -0800 Subject: [PATCH 18/46] Support ES6 imports in binder --- src/compiler/binder.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 83420091a5a16..bec686e4f8b52 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -467,6 +467,9 @@ module ts { bindModuleDeclaration(node); break; case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportSpecifier: bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.SourceFile: From 6d0db0f401f731de6f0259059cdcbcb2b3c65aaa Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 06:17:06 -0800 Subject: [PATCH 19/46] Resolve ES6 imports in type checker --- src/compiler/checker.ts | 125 ++++++++++++++++++++++++++++------------ 1 file changed, 89 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4392c1c59b4fa..7f1450efac905 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -439,22 +439,65 @@ module ts { return result; } + function getDeclarationOfImportSymbol(symbol: Symbol): Declaration { + return forEach(symbol.declarations, d => + d.kind === SyntaxKind.ImportEqualsDeclaration || + d.kind === SyntaxKind.ImportClause || + d.kind === SyntaxKind.NamespaceImport || + d.kind === SyntaxKind.ImportSpecifier ? d : undefined); + } + + function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol { + return node.moduleReference.kind === SyntaxKind.ExternalModuleReference ? + resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)) : + getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); + } + + function getTargetOfImportClause(node: ImportClause): Symbol { + // TODO: Verify that returned symbol originates in "export default" statement + return resolveExternalModuleName(node, (node.parent).moduleSpecifier); + } + + function getTargetOfNamespaceImport(node: NamespaceImport): Symbol { + // TODO: Verify that returned symbol does not originate in "export default" statement + return resolveExternalModuleName(node, (node.parent.parent).moduleSpecifier); + } + + function getTargetOfImportSpecifier(node: ImportSpecifier): Symbol { + var moduleSymbol = resolveExternalModuleName(node, (node.parent.parent.parent).moduleSpecifier); + if (moduleSymbol) { + var name = node.propertyName || node.name; + if (name.text) { + var symbol = getSymbol(moduleSymbol.exports, name.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + if (!symbol) { + error(name, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), declarationNameToString(name)); + return; + } + return symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace) ? symbol : resolveImport(symbol); + } + } + } + + function getTargetOfImportDeclaration(node: Declaration): Symbol { + switch (node.kind) { + case SyntaxKind.ImportEqualsDeclaration: + return getTargetOfImportEqualsDeclaration(node); + case SyntaxKind.ImportClause: + return getTargetOfImportClause(node); + case SyntaxKind.NamespaceImport: + return getTargetOfNamespaceImport(node); + case SyntaxKind.ImportSpecifier: + return getTargetOfImportSpecifier(node); + } + } + function resolveImport(symbol: Symbol): Symbol { Debug.assert((symbol.flags & SymbolFlags.Import) !== 0, "Should only get Imports here."); var links = getSymbolLinks(symbol); if (!links.target) { links.target = resolvingSymbol; - var node = getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration); - // Grammar checking - if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) { - if ((node.moduleReference).expression.kind !== SyntaxKind.StringLiteral) { - grammarErrorOnNode((node.moduleReference).expression, Diagnostics.String_literal_expected); - } - } - - var target = node.moduleReference.kind === SyntaxKind.ExternalModuleReference - ? resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)) - : getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); + var node = getDeclarationOfImportSymbol(symbol); + var target = getTargetOfImportDeclaration(node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; } @@ -4837,31 +4880,36 @@ module ts { var symbol = getResolvedSymbol(node); if (symbol.flags & SymbolFlags.Import) { + var symbolLinks = getSymbolLinks(symbol); - if (!symbolLinks.referenced) { - var importOrExportAssignment = getLeftSideOfImportEqualsOrExportAssignment(node); - - // decision about whether import is referenced can be made now if - // - import that are used anywhere except right side of import declarations - // - imports that are used on the right side of exported import declarations - // for other cases defer decision until the check of left side - if (!importOrExportAssignment || - (importOrExportAssignment.flags & NodeFlags.Export) || - (importOrExportAssignment.kind === SyntaxKind.ExportAssignment)) { - // Mark the import as referenced so that we emit it in the final .js file. - // exception: identifiers that appear in type queries, const enums, modules that contain only const enums - symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - } - else { - var nodeLinks = getNodeLinks(importOrExportAssignment); - Debug.assert(!nodeLinks.importOnRightSide); - nodeLinks.importOnRightSide = symbol; - } - } + symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); + + // TODO(andersh): Figure out what this does + //var symbolLinks = getSymbolLinks(symbol); + //if (!symbolLinks.referenced) { + // var importOrExportAssignment = getLeftSideOfImportEqualsOrExportAssignment(node); + + // // decision about whether import is referenced can be made now if + // // - import that are used anywhere except right side of import declarations + // // - imports that are used on the right side of exported import declarations + // // for other cases defer decision until the check of left side + // if (!importOrExportAssignment || + // (importOrExportAssignment.flags & NodeFlags.Export) || + // (importOrExportAssignment.kind === SyntaxKind.ExportAssignment)) { + // // Mark the import as referenced so that we emit it in the final .js file. + // // exception: identifiers that appear in type queries, const enums, modules that contain only const enums + // symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); + // } + // else { + // var nodeLinks = getNodeLinks(importOrExportAssignment); + // Debug.assert(!nodeLinks.importOnRightSide); + // nodeLinks.importOnRightSide = symbol; + // } + //} - if (symbolLinks.referenced) { - markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration)); - } + //if (symbolLinks.referenced) { + // markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration)); + //} } checkCollisionWithCapturedSuperVariable(node, node); @@ -9228,6 +9276,10 @@ module ts { } } else { + var moduleNameExpr = getExternalModuleImportEqualsDeclarationExpression(node); + if (moduleNameExpr.kind !== SyntaxKind.StringLiteral) { + grammarErrorOnNode(moduleNameExpr, Diagnostics.String_literal_expected); + } // Import declaration for an external module if (node.parent.kind === SyntaxKind.SourceFile) { target = resolveImport(symbol); @@ -9237,8 +9289,8 @@ module ts { // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference // other external modules only through top - level external module names. // Relative external module names are not permitted. - if (getExternalModuleImportEqualsDeclarationExpression(node).kind === SyntaxKind.StringLiteral) { - if (isExternalModuleNameRelative((getExternalModuleImportEqualsDeclarationExpression(node)).text)) { + if (moduleNameExpr.kind === SyntaxKind.StringLiteral) { + if (isExternalModuleNameRelative((moduleNameExpr).text)) { error(node, Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); target = unknownSymbol; } @@ -11037,6 +11089,7 @@ module ts { // export_opt AmbientDeclaration // if (node.kind === SyntaxKind.InterfaceDeclaration || + node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportAssignment || (node.flags & NodeFlags.Ambient)) { From 930d11bc829461914d7a8419d7e4882a9ce1b58a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 13:50:30 -0800 Subject: [PATCH 20/46] Cleaning up a few things --- src/compiler/checker.ts | 6 ++++-- src/compiler/utilities.ts | 34 +++++----------------------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7f1450efac905..025d3380a206a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4880,11 +4880,13 @@ module ts { var symbol = getResolvedSymbol(node); if (symbol.flags & SymbolFlags.Import) { - var symbolLinks = getSymbolLinks(symbol); symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - // TODO(andersh): Figure out what this does + // TODO: AndersH: This needs to be simplified. In an import of the form "import x = a.b.c;" we only need + // to resolve "a" and mark it as referenced. If "b" and/or "c" are aliases, we would be able to access them + // unless they're exported, and in that case they're already implicitly referenced. + //var symbolLinks = getSymbolLinks(symbol); //if (!symbolLinks.referenced) { // var importOrExportAssignment = getLeftSideOfImportEqualsOrExportAssignment(node); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ec2c2d404dac6..d417bc1d3801f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -753,36 +753,12 @@ module ts { } export function getAncestor(node: Node, kind: SyntaxKind): Node { - switch (kind) { - // special-cases that can be come first - case SyntaxKind.ClassDeclaration: - while (node) { - switch (node.kind) { - case SyntaxKind.ClassDeclaration: - return node; - case SyntaxKind.EnumDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.TypeAliasDeclaration: - case SyntaxKind.ModuleDeclaration: - case SyntaxKind.ImportEqualsDeclaration: - // early exit cases - declarations cannot be nested in classes - return undefined; - default: - node = node.parent; - continue; - } - } - break; - default: - while (node) { - if (node.kind === kind) { - return node; - } - node = node.parent; - } - break; + while (node) { + if (node.kind === kind) { + return node; + } + node = node.parent; } - return undefined; } From 89f58d0982967f000ee9712437143dc9b02ce581 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 14:24:38 -0800 Subject: [PATCH 21/46] Always bind children of import clause --- src/compiler/binder.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index bec686e4f8b52..655bcc276f751 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -467,11 +467,18 @@ module ts { bindModuleDeclaration(node); break; case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ImportClause: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; + case SyntaxKind.ImportClause: + if ((node).name) { + bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); + } + else { + bindChildren(node, 0, /*isBlockScopeContainer*/ false); + } + break; case SyntaxKind.SourceFile: if (isExternalModule(node)) { bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"', /*isBlockScopeContainer*/ true); From 7e187ef75f8173a74270ec8edf2ee864d20605da Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 6 Feb 2015 14:44:24 -0800 Subject: [PATCH 22/46] Correctly set position of import declaration nodes --- src/compiler/parser.ts | 50 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index aa9639b366f01..f062c05f7b217 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4527,6 +4527,8 @@ module ts { function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); + var afterImportPos = scanner.getStartPos(); + var identifier: Identifier; if (isIdentifier()) { identifier = parseIdentifier(); @@ -4554,28 +4556,7 @@ module ts { if (identifier || // import id token === SyntaxKind.AsteriskToken || // import * token === SyntaxKind.OpenBraceToken) { // import { - //ImportClause: - // ImportedDefaultBinding - // NameSpaceImport - // NamedImports - // ImportedDefaultBinding, NameSpaceImport - // ImportedDefaultBinding, NamedImports - - var importClause = createNode(SyntaxKind.ImportClause); - if (identifier) { - // ImportedDefaultBinding: - // ImportedBinding - importClause.name = identifier; - } - - // If there was no default import or if there is comma token after default import - // parse namespace or named imports - if (!importClause.name || - parseOptional(SyntaxKind.CommaToken)) { - importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); - } - - importDeclaration.importClause = finishNode(importClause); + importDeclaration.importClause = parseImportClause(identifier, afterImportPos); parseExpected(SyntaxKind.FromKeyword); } @@ -4584,6 +4565,31 @@ module ts { return finishNode(importDeclaration); } + function parseImportClause(identifier: Identifier, fullStart: number) { + //ImportClause: + // ImportedDefaultBinding + // NameSpaceImport + // NamedImports + // ImportedDefaultBinding, NameSpaceImport + // ImportedDefaultBinding, NamedImports + + var importClause = createNode(SyntaxKind.ImportClause, fullStart); + if (identifier) { + // ImportedDefaultBinding: + // ImportedBinding + importClause.name = identifier; + } + + // If there was no default import or if there is comma token after default import + // parse namespace or named imports + if (!importClause.name || + parseOptional(SyntaxKind.CommaToken)) { + importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); + } + + return finishNode(importClause); + } + function parseModuleReference() { return isExternalModuleReference() ? parseExternalModuleReference() From 69bd05946afa3459aaf9a03df03e4986efff1505 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 8 Feb 2015 08:03:15 -0800 Subject: [PATCH 23/46] CommonJS emit for ES6 import declarations --- src/compiler/binder.ts | 5 +- src/compiler/checker.ts | 100 ++++++++++++---------- src/compiler/emitter.ts | 174 ++++++++++++++++++++++++++++++++++---- src/compiler/parser.ts | 28 ++---- src/compiler/program.ts | 15 ---- src/compiler/types.ts | 4 +- src/compiler/utilities.ts | 19 +++++ 7 files changed, 245 insertions(+), 100 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 75e52f1923a1f..5a4a983537a2e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -20,7 +20,7 @@ module ts { return ModuleInstanceState.ConstEnumOnly; } // 3. non - exported import declarations - else if (node.kind === SyntaxKind.ImportEqualsDeclaration && !(node.flags & NodeFlags.Export)) { + else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && !(node.flags & NodeFlags.Export)) { return ModuleInstanceState.NonInstantiated; } // 4. other uninstantiated module declarations. @@ -207,7 +207,8 @@ module ts { exportKind |= SymbolFlags.ExportNamespace; } - if (getCombinedNodeFlags(node) & NodeFlags.Export || (node.kind !== SyntaxKind.ImportEqualsDeclaration && isAmbientContext(container))) { + if (getCombinedNodeFlags(node) & NodeFlags.Export || + (node.kind !== SyntaxKind.ImportDeclaration && node.kind !== SyntaxKind.ImportEqualsDeclaration && isAmbientContext(container))) { if (exportKind) { var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3163632bafaf8..c3eae1732a8a1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -442,12 +442,15 @@ module ts { return result; } + function isImportSymbolDeclaration(node: Node): boolean { + return node.kind === SyntaxKind.ImportEqualsDeclaration || + node.kind === SyntaxKind.ImportClause && !!(node).name || + node.kind === SyntaxKind.NamespaceImport || + node.kind === SyntaxKind.ImportSpecifier; + } + function getDeclarationOfImportSymbol(symbol: Symbol): Declaration { - return forEach(symbol.declarations, d => - d.kind === SyntaxKind.ImportEqualsDeclaration || - d.kind === SyntaxKind.ImportClause || - d.kind === SyntaxKind.NamespaceImport || - d.kind === SyntaxKind.ImportSpecifier ? d : undefined); + return forEach(symbol.declarations, d => isImportSymbolDeclaration(d) ? d : undefined); } function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol { @@ -4915,42 +4918,47 @@ module ts { // To avoid that we will give an error to users if they use arguments objects in arrow function so that they // can explicitly bound arguments objects if (symbol === argumentsSymbol && getContainingFunction(node).kind === SyntaxKind.ArrowFunction) { - error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression); + error(node, Diagnostics.The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression); } if (symbol.flags & SymbolFlags.Import) { - var symbolLinks = getSymbolLinks(symbol); - symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - - // TODO: AndersH: This needs to be simplified. In an import of the form "import x = a.b.c;" we only need - // to resolve "a" and mark it as referenced. If "b" and/or "c" are aliases, we would be able to access them - // unless they're exported, and in that case they're already implicitly referenced. //var symbolLinks = getSymbolLinks(symbol); //if (!symbolLinks.referenced) { - // var importOrExportAssignment = getLeftSideOfImportEqualsOrExportAssignment(node); - - // // decision about whether import is referenced can be made now if - // // - import that are used anywhere except right side of import declarations - // // - imports that are used on the right side of exported import declarations - // // for other cases defer decision until the check of left side - // if (!importOrExportAssignment || - // (importOrExportAssignment.flags & NodeFlags.Export) || - // (importOrExportAssignment.kind === SyntaxKind.ExportAssignment)) { - // // Mark the import as referenced so that we emit it in the final .js file. - // // exception: identifiers that appear in type queries, const enums, modules that contain only const enums - // symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); - // } - // else { - // var nodeLinks = getNodeLinks(importOrExportAssignment); - // Debug.assert(!nodeLinks.importOnRightSide); - // nodeLinks.importOnRightSide = symbol; + // if (!isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol))) { + // symbolLinks.referenced = true; // } //} + + // TODO: AndersH: This needs to be simplified. In an import of the form "import x = a.b.c;" we only need + // to resolve "a" and mark it as referenced. If "b" and/or "c" are aliases, we would be able to access them + // unless they're exported, and in that case they're already implicitly referenced. + + var symbolLinks = getSymbolLinks(symbol); + if (!symbolLinks.referenced) { + var importOrExportAssignment = getLeftSideOfImportEqualsOrExportAssignment(node); + + // decision about whether import is referenced can be made now if + // - import that are used anywhere except right side of import declarations + // - imports that are used on the right side of exported import declarations + // for other cases defer decision until the check of left side + if (!importOrExportAssignment || + (importOrExportAssignment.flags & NodeFlags.Export) || + (importOrExportAssignment.kind === SyntaxKind.ExportAssignment)) { + // Mark the import as referenced so that we emit it in the final .js file. + // exception: identifiers that appear in type queries, const enums, modules that contain only const enums + symbolLinks.referenced = !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveImport(symbol)); + } + else { + var nodeLinks = getNodeLinks(importOrExportAssignment); + Debug.assert(!nodeLinks.importOnRightSide); + nodeLinks.importOnRightSide = symbol; + } + } - //if (symbolLinks.referenced) { - // markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration)); - //} + if (symbolLinks.referenced) { + markLinkedImportsAsReferenced(getDeclarationOfKind(symbol, SyntaxKind.ImportEqualsDeclaration)); + } } checkCollisionWithCapturedSuperVariable(node, node); @@ -10108,7 +10116,7 @@ module ts { // Make sure the name in question does not collide with an import. if (symbolWithRelevantName.flags & SymbolFlags.Import) { var importEqualsDeclarationWithRelevantName = getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportEqualsDeclaration); - if (isReferencedImportEqualsDeclaration(importEqualsDeclarationWithRelevantName)) { + if (isReferencedImportDeclaration(importEqualsDeclarationWithRelevantName)) { return false; } } @@ -10182,17 +10190,19 @@ module ts { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedImportEqualsDeclaration(node: ImportEqualsDeclaration): boolean { - var symbol = getSymbolOfNode(node); - if (getSymbolLinks(symbol).referenced) { - return true; - } - // logic below will answer 'true' for exported import declaration in a nested module that itself is not exported. - // As a consequence this might cause emitting extra. - if (node.flags & NodeFlags.Export) { - return isImportResolvedToValue(symbol); + function isReferencedImportDeclaration(node: Node): boolean { + if (isImportSymbolDeclaration(node)) { + var symbol = getSymbolOfNode(node); + if (getSymbolLinks(symbol).referenced) { + return true; + } + // logic below will answer 'true' for exported import declaration in a nested module that itself is not exported. + // As a consequence this might cause emitting extra. + if (node.kind === SyntaxKind.ImportEqualsDeclaration && node.flags & NodeFlags.Export && isImportResolvedToValue(symbol)) { + return true; + } } - return false; + return forEachChild(node, isReferencedImportDeclaration); } function isImplementationOfOverload(node: FunctionLikeDeclaration) { @@ -10266,7 +10276,7 @@ module ts { getLocalNameOfContainer, getExpressionNamePrefix, getExportAssignmentName, - isReferencedImportEqualsDeclaration, + isReferencedImportDeclaration, getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName, isDeclarationVisible, @@ -10440,7 +10450,7 @@ module ts { return grammarErrorOnNode(lastPrivate, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); } } - else if (node.kind === SyntaxKind.ImportEqualsDeclaration && flags & NodeFlags.Ambient) { + else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && flags & NodeFlags.Ambient) { return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); } else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0af030cc26f3d..eccfc8df9db1b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -16,6 +16,11 @@ module ts { getIndent(): number; } + interface ExternalImportInfo { + declaration: ImportDeclaration | ImportEqualsDeclaration; + paramName: Identifier; // Callback parameter name for AMD module + } + interface SymbolAccessibilityDiagnostic { errorNode: Node; diagnosticMessage: DiagnosticMessage; @@ -1561,6 +1566,7 @@ module ts { var tempCount = 0; var tempVariables: Identifier[]; var tempParameters: Identifier[]; + var externalImports: ExternalImportInfo[]; /** write emitted output to disk*/ var writeEmittedFiles = writeJavaScriptFile; @@ -3889,8 +3895,103 @@ module ts { emitEnd(node); } + function emitRequire(moduleName: Expression) { + if (moduleName) { + write("require("); + emitStart(moduleName); + emitLiteral(moduleName); + emitEnd(moduleName); + emitToken(SyntaxKind.CloseParenToken, moduleName.end); + write(";"); + } + else { + write("require();"); + } + } + + function emitImportAssignment(node: Declaration, moduleName: Expression) { + if (!(node.flags & NodeFlags.Export)) write("var "); + emitModuleMemberName(node); + write(" = "); + emitRequire(moduleName); + } + + function emitNamedImportAssignments(namedImports: NamedImports, moduleReference: Identifier) { + var elements = namedImports.elements; + for (var i = 0; i < elements.length; i++) { + var element = elements[i]; + if (resolver.isReferencedImportDeclaration(element)) { + writeLine(); + if (!(element.flags & NodeFlags.Export)) write("var "); + emitModuleMemberName(element); + write(" = "); + emit(moduleReference); + write("."); + emit(element.propertyName || element.name); + write(";"); + } + } + } + + function emitExportedImportAssignment(node: Declaration) { + if (node.flags & NodeFlags.Export) { + emitModuleMemberName(node); + write(" = "); + emit(node.name); + write(";"); + } + } + + function emitImportDeclarationAMD(node: ImportDeclaration) { + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + emitExportedImportAssignment(importClause); + } + else if (importClause.namedBindings) { + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + emitExportedImportAssignment(importClause.namedBindings); + } + else { + } + } + } + } + + function emitImportDeclaration(node: ImportDeclaration) { + var importClause = node.importClause; + if (!importClause || resolver.isReferencedImportDeclaration(node)) { + emitLeadingComments(node); + emitStart(node); + var moduleName = getImportedModuleName(node); + if (importClause) { + if (importClause.name) { + emitImportAssignment(importClause, moduleName); + } + else if (importClause.namedBindings) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + emitImportAssignment(importClause.namedBindings, moduleName); + } + else { + var temp = createTempVariable(node); + write("var "); + emit(temp); + write(" = "); + emitRequire(moduleName); + emitNamedImportAssignments(importClause.namedBindings, temp); + } + } + } + else { + emitRequire(moduleName); + } + emitEnd(node); + emitTrailingComments(node); + } + } + function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - var emitImportDeclaration = resolver.isReferencedImportEqualsDeclaration(node); + var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); if (!emitImportDeclaration) { // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when @@ -3917,21 +4018,16 @@ module ts { writeLine(); emitLeadingComments(node); emitStart(node); - if (!(node.flags & NodeFlags.Export)) write("var "); - emitModuleMemberName(node); - write(" = "); if (isInternalModuleImportEqualsDeclaration(node)) { + if (!(node.flags & NodeFlags.Export)) write("var "); + emitModuleMemberName(node); + write(" = "); emit(node.moduleReference); + write(";"); } else { - var literal = getExternalModuleImportEqualsDeclarationExpression(node); - write("require("); - emitStart(literal); - emitLiteral(literal); - emitEnd(literal); - emitToken(SyntaxKind.CloseParenToken, literal.end); + emitImportAssignment(node, getImportedModuleName(node)); } - write(";"); emitEnd(node); emitTrailingComments(node); } @@ -3941,13 +4037,48 @@ module ts { function getExternalImportEqualsDeclarations(node: SourceFile): ImportEqualsDeclaration[] { var result: ImportEqualsDeclaration[] = []; forEach(node.statements, statement => { - if (isExternalModuleImportEqualsDeclaration(statement) && resolver.isReferencedImportEqualsDeclaration(statement)) { + if (isExternalModuleImportEqualsDeclaration(statement) && resolver.isReferencedImportDeclaration(statement)) { result.push(statement); } }); return result; } + function getExternalImportInfo(node: ImportDeclaration | ImportEqualsDeclaration): ExternalImportInfo { + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + var name = (node).name; + } + else { + var importClause = (node).importClause; + if (importClause) { + if (importClause.name) { + var name = importClause.name; + } + else if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + var name = (importClause.namedBindings).name; + } + else { + var name = createTempVariable(node); + } + } + } + return { + declaration: node, + paramName: name + }; + } + + function getExternalImports(sourceFile: SourceFile): ExternalImportInfo[] { + var result: ExternalImportInfo[] = []; + forEach(sourceFile.statements, node => { + if ((node.kind === SyntaxKind.ImportDeclaration || isExternalModuleImportEqualsDeclaration(node)) && + resolver.isReferencedImportDeclaration(node)) { + result.push(getExternalImportInfo(node)); + } + }); + return result; + } + function getFirstExportAssignment(sourceFile: SourceFile) { return forEach(sourceFile.statements, node => { if (node.kind === SyntaxKind.ExportAssignment) { @@ -3957,16 +4088,22 @@ module ts { } function emitAMDModule(node: SourceFile, startIndex: number) { - var imports = getExternalImportEqualsDeclarations(node); + externalImports = getExternalImports(node); writeLine(); write("define("); if (node.amdModuleName) { write("\"" + node.amdModuleName + "\", "); } write("[\"require\", \"exports\""); - forEach(imports, imp => { + forEach(externalImports, imp => { write(", "); - emitLiteral(getExternalModuleImportEqualsDeclarationExpression(imp)); + var moduleName = getImportedModuleName(imp.declaration); + if (moduleName) { + emitLiteral(moduleName); + } + else { + write("\"\""); + } }); forEach(node.amdDependencies, amdDependency => { var text = "\"" + amdDependency + "\""; @@ -3974,9 +4111,9 @@ module ts { write(text); }); write("], function (require, exports"); - forEach(imports, imp => { + forEach(externalImports, imp => { write(", "); - emit(imp.name); + emit(imp.paramName); }); write(") {"); increaseIndent(); @@ -4104,6 +4241,7 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.ExportAssignment: return false; @@ -4265,6 +4403,8 @@ module ts { return emitEnumMember(node); case SyntaxKind.ModuleDeclaration: return emitModuleDeclaration(node); + case SyntaxKind.ImportDeclaration: + return emitImportDeclaration(node); case SyntaxKind.ImportEqualsDeclaration: return emitImportEqualsDeclaration(node); case SyntaxKind.SourceFile: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f062c05f7b217..498b60f2d06e3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4600,32 +4600,22 @@ module ts { var node = createNode(SyntaxKind.ExternalModuleReference); parseExpected(SyntaxKind.RequireKeyword); parseExpected(SyntaxKind.OpenParenToken); + node.expression = parseModuleSpecifier(); + parseExpected(SyntaxKind.CloseParenToken); + return finishNode(node); + } + function parseModuleSpecifier(): Expression { // We allow arbitrary expressions here, even though the grammar only allows string // literals. We check to ensure that it is only a string literal later in the grammar // walker. - node.expression = parseExpression(); - + var result = parseExpression(); // Ensure the string being required is in our 'identifier' table. This will ensure // that features like 'find refs' will look inside this file when search for its name. - if (node.expression.kind === SyntaxKind.StringLiteral) { - internIdentifier((node.expression).text); - } - - parseExpected(SyntaxKind.CloseParenToken); - return finishNode(node); - } - - function parseModuleSpecifier(): StringLiteralExpression { - // ModuleSpecifier: - // StringLiteral - if (token === SyntaxKind.StringLiteral) { - // Ensure the string being required is in our 'identifier' table. This will ensure - // that features like 'find refs' will look inside this file when search for its name. - return parseLiteralNode(/*internName*/ true); + if (result.kind === SyntaxKind.StringLiteral) { + internIdentifier((result).text); } - - parseErrorAtCurrentToken(Diagnostics.String_literal_expected); + return result; } function parseNamespaceImport(): NamespaceImport { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index b6639588bb552..24d2b41b8f255 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -349,21 +349,6 @@ module ts { }); } - function getImportedModuleName(node: Node): StringLiteralExpression { - if (node.kind === SyntaxKind.ImportDeclaration) { - return (node).moduleSpecifier; - } - if (node.kind === SyntaxKind.ImportEqualsDeclaration) { - var reference = (node).moduleReference; - if (reference.kind === SyntaxKind.ExternalModuleReference) { - var expr = (reference).expression; - if (expr && expr.kind === SyntaxKind.StringLiteral) { - return expr; - } - } - } - } - function processImportedModules(file: SourceFile, basePath: string) { forEach(file.statements, node => { if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 18e3e6e0ed375..404a3a89504d6 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -880,7 +880,7 @@ module ts { // ImportClause information is shown at its declaration below. export interface ImportDeclaration extends Statement, ModuleElement { importClause?: ImportClause; - moduleSpecifier: StringLiteralExpression; + moduleSpecifier: Expression; } // In case of: @@ -1166,7 +1166,7 @@ module ts { getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; - isReferencedImportEqualsDeclaration(node: ImportEqualsDeclaration): boolean; + isReferencedImportDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 93b5c864074d6..27e959ca0c414 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -597,6 +597,22 @@ module ts { return node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind !== SyntaxKind.ExternalModuleReference; } + function extractStringLiteral(node: Expression): StringLiteralExpression { + return node && node.kind === SyntaxKind.StringLiteral ? node : undefined; + } + + export function getImportedModuleName(node: Node): StringLiteralExpression { + if (node.kind === SyntaxKind.ImportDeclaration) { + return extractStringLiteral((node).moduleSpecifier); + } + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + var reference = (node).moduleReference; + if (reference.kind === SyntaxKind.ExternalModuleReference) { + return extractStringLiteral((reference).expression); + } + } + } + export function hasDotDotDotToken(node: Node) { return node && node.kind === SyntaxKind.Parameter && (node).dotDotDotToken !== undefined; } @@ -674,6 +690,9 @@ module ts { case SyntaxKind.EnumDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportClause: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.NamespaceImport: return true; } return false; From acaea1c914a67dfa60758ce2a94d6905203eedc2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 8 Feb 2015 08:13:15 -0800 Subject: [PATCH 24/46] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 265 +++++++------- .../reference/APISample_compile.types | 336 +++++++++++------- tests/baselines/reference/APISample_linter.js | 283 ++++++++------- .../reference/APISample_linter.types | 336 +++++++++++------- .../reference/APISample_transform.js | 265 +++++++------- .../reference/APISample_transform.types | 336 +++++++++++------- .../baselines/reference/APISample_watcher.js | 265 +++++++------- .../reference/APISample_watcher.types | 336 +++++++++++------- .../reference/es6ImportDefaultBinding.types | 3 +- ...tBindingFollowedWithNamedImport.errors.txt | 33 ++ ...efaultBindingFollowedWithNamedImport.types | 21 -- ...ingFollowedWithNamedImportInEs5.errors.txt | 33 ++ ...tBindingFollowedWithNamedImportInEs5.types | 21 -- ...tBindingFollowedWithNamespaceBinding.types | 4 +- ...ingFollowedWithNamespaceBindingInEs5.types | 4 +- .../es6ImportDefaultBindingInEs5.types | 3 +- .../reference/es6ImportNameSpaceImport.types | 3 +- .../es6ImportNameSpaceImportInEs5.types | 3 +- .../reference/es6ImportNamedImport.types | 37 +- ...rtNamedImportIdentifiersParsing.errors.txt | 19 +- .../es6ImportNamedImportIdentifiersParsing.js | 9 + .../reference/es6ImportNamedImportInEs5.types | 37 +- ...s6ImportNamedImportParsingError.errors.txt | 52 --- .../reference/es6ImportParseErrors.js | 6 + .../reference/es6ImportWithoutFromClause.js | 1 + .../es6ImportWithoutFromClauseInEs5.js | 1 + 26 files changed, 1585 insertions(+), 1127 deletions(-) create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt delete mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt delete mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types create mode 100644 tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.js delete mode 100644 tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt create mode 100644 tests/baselines/reference/es6ImportParseErrors.js diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 6840f07997247..7725563214d05 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -160,129 +160,136 @@ declare module "typescript" { VoidKeyword = 98, WhileKeyword = 99, WithKeyword = 100, - ImplementsKeyword = 101, - InterfaceKeyword = 102, - LetKeyword = 103, - PackageKeyword = 104, - PrivateKeyword = 105, - ProtectedKeyword = 106, - PublicKeyword = 107, - StaticKeyword = 108, - YieldKeyword = 109, - AnyKeyword = 110, - BooleanKeyword = 111, - ConstructorKeyword = 112, - DeclareKeyword = 113, - GetKeyword = 114, - ModuleKeyword = 115, - RequireKeyword = 116, - NumberKeyword = 117, - SetKeyword = 118, - StringKeyword = 119, - TypeKeyword = 120, - QualifiedName = 121, - ComputedPropertyName = 122, - TypeParameter = 123, - Parameter = 124, - PropertySignature = 125, - PropertyDeclaration = 126, - MethodSignature = 127, - MethodDeclaration = 128, - Constructor = 129, - GetAccessor = 130, - SetAccessor = 131, - CallSignature = 132, - ConstructSignature = 133, - IndexSignature = 134, - TypeReference = 135, - FunctionType = 136, - ConstructorType = 137, - TypeQuery = 138, - TypeLiteral = 139, - ArrayType = 140, - TupleType = 141, - UnionType = 142, - ParenthesizedType = 143, - ObjectBindingPattern = 144, - ArrayBindingPattern = 145, - BindingElement = 146, - ArrayLiteralExpression = 147, - ObjectLiteralExpression = 148, - PropertyAccessExpression = 149, - ElementAccessExpression = 150, - CallExpression = 151, - NewExpression = 152, - TaggedTemplateExpression = 153, - TypeAssertionExpression = 154, - ParenthesizedExpression = 155, - FunctionExpression = 156, - ArrowFunction = 157, - DeleteExpression = 158, - TypeOfExpression = 159, - VoidExpression = 160, - PrefixUnaryExpression = 161, - PostfixUnaryExpression = 162, - BinaryExpression = 163, - ConditionalExpression = 164, - TemplateExpression = 165, - YieldExpression = 166, - SpreadElementExpression = 167, - OmittedExpression = 168, - TemplateSpan = 169, - Block = 170, - VariableStatement = 171, - EmptyStatement = 172, - ExpressionStatement = 173, - IfStatement = 174, - DoStatement = 175, - WhileStatement = 176, - ForStatement = 177, - ForInStatement = 178, - ContinueStatement = 179, - BreakStatement = 180, - ReturnStatement = 181, - WithStatement = 182, - SwitchStatement = 183, - LabeledStatement = 184, - ThrowStatement = 185, - TryStatement = 186, - DebuggerStatement = 187, - VariableDeclaration = 188, - VariableDeclarationList = 189, - FunctionDeclaration = 190, - ClassDeclaration = 191, - InterfaceDeclaration = 192, - TypeAliasDeclaration = 193, - EnumDeclaration = 194, - ModuleDeclaration = 195, - ModuleBlock = 196, - ImportDeclaration = 197, - ExportAssignment = 198, - ExternalModuleReference = 199, - CaseClause = 200, - DefaultClause = 201, - HeritageClause = 202, - CatchClause = 203, - PropertyAssignment = 204, - ShorthandPropertyAssignment = 205, - EnumMember = 206, - SourceFile = 207, - SyntaxList = 208, - Count = 209, + AsKeyword = 101, + FromKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + TypeKeyword = 122, + QualifiedName = 123, + ComputedPropertyName = 124, + TypeParameter = 125, + Parameter = 126, + PropertySignature = 127, + PropertyDeclaration = 128, + MethodSignature = 129, + MethodDeclaration = 130, + Constructor = 131, + GetAccessor = 132, + SetAccessor = 133, + CallSignature = 134, + ConstructSignature = 135, + IndexSignature = 136, + TypeReference = 137, + FunctionType = 138, + ConstructorType = 139, + TypeQuery = 140, + TypeLiteral = 141, + ArrayType = 142, + TupleType = 143, + UnionType = 144, + ParenthesizedType = 145, + ObjectBindingPattern = 146, + ArrayBindingPattern = 147, + BindingElement = 148, + ArrayLiteralExpression = 149, + ObjectLiteralExpression = 150, + PropertyAccessExpression = 151, + ElementAccessExpression = 152, + CallExpression = 153, + NewExpression = 154, + TaggedTemplateExpression = 155, + TypeAssertionExpression = 156, + ParenthesizedExpression = 157, + FunctionExpression = 158, + ArrowFunction = 159, + DeleteExpression = 160, + TypeOfExpression = 161, + VoidExpression = 162, + PrefixUnaryExpression = 163, + PostfixUnaryExpression = 164, + BinaryExpression = 165, + ConditionalExpression = 166, + TemplateExpression = 167, + YieldExpression = 168, + SpreadElementExpression = 169, + OmittedExpression = 170, + TemplateSpan = 171, + Block = 172, + VariableStatement = 173, + EmptyStatement = 174, + ExpressionStatement = 175, + IfStatement = 176, + DoStatement = 177, + WhileStatement = 178, + ForStatement = 179, + ForInStatement = 180, + ContinueStatement = 181, + BreakStatement = 182, + ReturnStatement = 183, + WithStatement = 184, + SwitchStatement = 185, + LabeledStatement = 186, + ThrowStatement = 187, + TryStatement = 188, + DebuggerStatement = 189, + VariableDeclaration = 190, + VariableDeclarationList = 191, + FunctionDeclaration = 192, + ClassDeclaration = 193, + InterfaceDeclaration = 194, + TypeAliasDeclaration = 195, + EnumDeclaration = 196, + ModuleDeclaration = 197, + ModuleBlock = 198, + ImportEqualsDeclaration = 199, + ExportAssignment = 200, + ImportDeclaration = 201, + ImportClause = 202, + NamespaceImport = 203, + NamedImports = 204, + ImportSpecifier = 205, + ExternalModuleReference = 206, + CaseClause = 207, + DefaultClause = 208, + HeritageClause = 209, + CatchClause = 210, + PropertyAssignment = 211, + ShorthandPropertyAssignment = 212, + EnumMember = 213, + SourceFile = 214, + SyntaxList = 215, + Count = 216, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, LastReservedWord = 100, FirstKeyword = 65, - LastKeyword = 120, - FirstFutureReservedWord = 101, - LastFutureReservedWord = 109, - FirstTypeNode = 135, - LastTypeNode = 143, + LastKeyword = 122, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 137, + LastTypeNode = 145, FirstPunctuation = 14, LastPunctuation = 63, FirstToken = 0, - LastToken = 120, + LastToken = 122, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -291,7 +298,7 @@ declare module "typescript" { LastTemplateToken = 13, FirstBinaryOperator = 24, LastBinaryOperator = 63, - FirstNode = 121, + FirstNode = 123, } const enum NodeFlags { Export = 1, @@ -702,13 +709,31 @@ declare module "typescript" { interface ModuleBlock extends Node, ModuleElement { statements: NodeArray; } - interface ImportDeclaration extends Declaration, ModuleElement { + interface ImportEqualsDeclaration extends Declaration, ModuleElement { name: Identifier; moduleReference: EntityName | ExternalModuleReference; } interface ExternalModuleReference extends Node { expression?: Expression; } + interface ImportDeclaration extends Statement, ModuleElement { + importClause?: ImportClause; + moduleSpecifier: Expression; + } + interface ImportClause extends Declaration { + name?: Identifier; + namedBindings?: NamespaceImport | NamedImports; + } + interface NamespaceImport extends Declaration { + name: Identifier; + } + interface NamedImports extends Node { + elements: NodeArray; + } + interface ImportSpecifier extends Declaration { + propertyName?: Identifier; + name: Identifier; + } interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -869,7 +894,7 @@ declare module "typescript" { } interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportDeclaration[]; + aliasesToMakeVisible?: ImportEqualsDeclaration[]; errorSymbolName?: string; errorNode?: Node; } @@ -880,8 +905,8 @@ declare module "typescript" { getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; - isReferencedImportDeclaration(node: ImportDeclaration): boolean; - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; + isReferencedImportDeclaration(node: Node): boolean; + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index d70172377ca4c..ceb647564bc95 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -496,331 +496,352 @@ declare module "typescript" { WithKeyword = 100, >WithKeyword : SyntaxKind - ImplementsKeyword = 101, + AsKeyword = 101, +>AsKeyword : SyntaxKind + + FromKeyword = 102, +>FromKeyword : SyntaxKind + + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 102, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 103, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 104, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 105, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 106, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 107, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 108, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 109, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 110, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 111, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 112, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 113, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 114, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 115, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 116, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 117, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 118, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 119, + StringKeyword = 121, >StringKeyword : SyntaxKind - TypeKeyword = 120, + TypeKeyword = 122, >TypeKeyword : SyntaxKind - QualifiedName = 121, + QualifiedName = 123, >QualifiedName : SyntaxKind - ComputedPropertyName = 122, + ComputedPropertyName = 124, >ComputedPropertyName : SyntaxKind - TypeParameter = 123, + TypeParameter = 125, >TypeParameter : SyntaxKind - Parameter = 124, + Parameter = 126, >Parameter : SyntaxKind - PropertySignature = 125, + PropertySignature = 127, >PropertySignature : SyntaxKind - PropertyDeclaration = 126, + PropertyDeclaration = 128, >PropertyDeclaration : SyntaxKind - MethodSignature = 127, + MethodSignature = 129, >MethodSignature : SyntaxKind - MethodDeclaration = 128, + MethodDeclaration = 130, >MethodDeclaration : SyntaxKind - Constructor = 129, + Constructor = 131, >Constructor : SyntaxKind - GetAccessor = 130, + GetAccessor = 132, >GetAccessor : SyntaxKind - SetAccessor = 131, + SetAccessor = 133, >SetAccessor : SyntaxKind - CallSignature = 132, + CallSignature = 134, >CallSignature : SyntaxKind - ConstructSignature = 133, + ConstructSignature = 135, >ConstructSignature : SyntaxKind - IndexSignature = 134, + IndexSignature = 136, >IndexSignature : SyntaxKind - TypeReference = 135, + TypeReference = 137, >TypeReference : SyntaxKind - FunctionType = 136, + FunctionType = 138, >FunctionType : SyntaxKind - ConstructorType = 137, + ConstructorType = 139, >ConstructorType : SyntaxKind - TypeQuery = 138, + TypeQuery = 140, >TypeQuery : SyntaxKind - TypeLiteral = 139, + TypeLiteral = 141, >TypeLiteral : SyntaxKind - ArrayType = 140, + ArrayType = 142, >ArrayType : SyntaxKind - TupleType = 141, + TupleType = 143, >TupleType : SyntaxKind - UnionType = 142, + UnionType = 144, >UnionType : SyntaxKind - ParenthesizedType = 143, + ParenthesizedType = 145, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 144, + ObjectBindingPattern = 146, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 145, + ArrayBindingPattern = 147, >ArrayBindingPattern : SyntaxKind - BindingElement = 146, + BindingElement = 148, >BindingElement : SyntaxKind - ArrayLiteralExpression = 147, + ArrayLiteralExpression = 149, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 148, + ObjectLiteralExpression = 150, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 149, + PropertyAccessExpression = 151, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 150, + ElementAccessExpression = 152, >ElementAccessExpression : SyntaxKind - CallExpression = 151, + CallExpression = 153, >CallExpression : SyntaxKind - NewExpression = 152, + NewExpression = 154, >NewExpression : SyntaxKind - TaggedTemplateExpression = 153, + TaggedTemplateExpression = 155, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 154, + TypeAssertionExpression = 156, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 155, + ParenthesizedExpression = 157, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 156, + FunctionExpression = 158, >FunctionExpression : SyntaxKind - ArrowFunction = 157, + ArrowFunction = 159, >ArrowFunction : SyntaxKind - DeleteExpression = 158, + DeleteExpression = 160, >DeleteExpression : SyntaxKind - TypeOfExpression = 159, + TypeOfExpression = 161, >TypeOfExpression : SyntaxKind - VoidExpression = 160, + VoidExpression = 162, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 161, + PrefixUnaryExpression = 163, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 162, + PostfixUnaryExpression = 164, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 163, + BinaryExpression = 165, >BinaryExpression : SyntaxKind - ConditionalExpression = 164, + ConditionalExpression = 166, >ConditionalExpression : SyntaxKind - TemplateExpression = 165, + TemplateExpression = 167, >TemplateExpression : SyntaxKind - YieldExpression = 166, + YieldExpression = 168, >YieldExpression : SyntaxKind - SpreadElementExpression = 167, + SpreadElementExpression = 169, >SpreadElementExpression : SyntaxKind - OmittedExpression = 168, + OmittedExpression = 170, >OmittedExpression : SyntaxKind - TemplateSpan = 169, + TemplateSpan = 171, >TemplateSpan : SyntaxKind - Block = 170, + Block = 172, >Block : SyntaxKind - VariableStatement = 171, + VariableStatement = 173, >VariableStatement : SyntaxKind - EmptyStatement = 172, + EmptyStatement = 174, >EmptyStatement : SyntaxKind - ExpressionStatement = 173, + ExpressionStatement = 175, >ExpressionStatement : SyntaxKind - IfStatement = 174, + IfStatement = 176, >IfStatement : SyntaxKind - DoStatement = 175, + DoStatement = 177, >DoStatement : SyntaxKind - WhileStatement = 176, + WhileStatement = 178, >WhileStatement : SyntaxKind - ForStatement = 177, + ForStatement = 179, >ForStatement : SyntaxKind - ForInStatement = 178, + ForInStatement = 180, >ForInStatement : SyntaxKind - ContinueStatement = 179, + ContinueStatement = 181, >ContinueStatement : SyntaxKind - BreakStatement = 180, + BreakStatement = 182, >BreakStatement : SyntaxKind - ReturnStatement = 181, + ReturnStatement = 183, >ReturnStatement : SyntaxKind - WithStatement = 182, + WithStatement = 184, >WithStatement : SyntaxKind - SwitchStatement = 183, + SwitchStatement = 185, >SwitchStatement : SyntaxKind - LabeledStatement = 184, + LabeledStatement = 186, >LabeledStatement : SyntaxKind - ThrowStatement = 185, + ThrowStatement = 187, >ThrowStatement : SyntaxKind - TryStatement = 186, + TryStatement = 188, >TryStatement : SyntaxKind - DebuggerStatement = 187, + DebuggerStatement = 189, >DebuggerStatement : SyntaxKind - VariableDeclaration = 188, + VariableDeclaration = 190, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 189, + VariableDeclarationList = 191, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 190, + FunctionDeclaration = 192, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 191, + ClassDeclaration = 193, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 192, + InterfaceDeclaration = 194, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 193, + TypeAliasDeclaration = 195, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 194, + EnumDeclaration = 196, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 195, + ModuleDeclaration = 197, >ModuleDeclaration : SyntaxKind - ModuleBlock = 196, + ModuleBlock = 198, >ModuleBlock : SyntaxKind - ImportDeclaration = 197, ->ImportDeclaration : SyntaxKind + ImportEqualsDeclaration = 199, +>ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 198, + ExportAssignment = 200, >ExportAssignment : SyntaxKind - ExternalModuleReference = 199, + ImportDeclaration = 201, +>ImportDeclaration : SyntaxKind + + ImportClause = 202, +>ImportClause : SyntaxKind + + NamespaceImport = 203, +>NamespaceImport : SyntaxKind + + NamedImports = 204, +>NamedImports : SyntaxKind + + ImportSpecifier = 205, +>ImportSpecifier : SyntaxKind + + ExternalModuleReference = 206, >ExternalModuleReference : SyntaxKind - CaseClause = 200, + CaseClause = 207, >CaseClause : SyntaxKind - DefaultClause = 201, + DefaultClause = 208, >DefaultClause : SyntaxKind - HeritageClause = 202, + HeritageClause = 209, >HeritageClause : SyntaxKind - CatchClause = 203, + CatchClause = 210, >CatchClause : SyntaxKind - PropertyAssignment = 204, + PropertyAssignment = 211, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 205, + ShorthandPropertyAssignment = 212, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 206, + EnumMember = 213, >EnumMember : SyntaxKind - SourceFile = 207, + SourceFile = 214, >SourceFile : SyntaxKind - SyntaxList = 208, + SyntaxList = 215, >SyntaxList : SyntaxKind - Count = 209, + Count = 216, >Count : SyntaxKind FirstAssignment = 52, @@ -838,19 +859,19 @@ declare module "typescript" { FirstKeyword = 65, >FirstKeyword : SyntaxKind - LastKeyword = 120, + LastKeyword = 122, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 101, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 109, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 135, + FirstTypeNode = 137, >FirstTypeNode : SyntaxKind - LastTypeNode = 143, + LastTypeNode = 145, >LastTypeNode : SyntaxKind FirstPunctuation = 14, @@ -862,7 +883,7 @@ declare module "typescript" { FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 120, + LastToken = 122, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -889,7 +910,7 @@ declare module "typescript" { LastBinaryOperator = 63, >LastBinaryOperator : SyntaxKind - FirstNode = 121, + FirstNode = 123, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -2131,8 +2152,8 @@ declare module "typescript" { >NodeArray : NodeArray >ModuleElement : ModuleElement } - interface ImportDeclaration extends Declaration, ModuleElement { ->ImportDeclaration : ImportDeclaration + interface ImportEqualsDeclaration extends Declaration, ModuleElement { +>ImportEqualsDeclaration : ImportEqualsDeclaration >Declaration : Declaration >ModuleElement : ModuleElement @@ -2152,6 +2173,61 @@ declare module "typescript" { expression?: Expression; >expression : Expression >Expression : Expression + } + interface ImportDeclaration extends Statement, ModuleElement { +>ImportDeclaration : ImportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + importClause?: ImportClause; +>importClause : ImportClause +>ImportClause : ImportClause + + moduleSpecifier: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface ImportClause extends Declaration { +>ImportClause : ImportClause +>Declaration : Declaration + + name?: Identifier; +>name : Identifier +>Identifier : Identifier + + namedBindings?: NamespaceImport | NamedImports; +>namedBindings : NamespaceImport | NamedImports +>NamespaceImport : NamespaceImport +>NamedImports : NamedImports + } + interface NamespaceImport extends Declaration { +>NamespaceImport : NamespaceImport +>Declaration : Declaration + + name: Identifier; +>name : Identifier +>Identifier : Identifier + } + interface NamedImports extends Node { +>NamedImports : NamedImports +>Node : Node + + elements: NodeArray; +>elements : NodeArray +>NodeArray : NodeArray +>ImportSpecifier : ImportSpecifier + } + interface ImportSpecifier extends Declaration { +>ImportSpecifier : ImportSpecifier +>Declaration : Declaration + + propertyName?: Identifier; +>propertyName : Identifier +>Identifier : Identifier + + name: Identifier; +>name : Identifier +>Identifier : Identifier } interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment @@ -2785,9 +2861,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportDeclaration[]; ->aliasesToMakeVisible : ImportDeclaration[] ->ImportDeclaration : ImportDeclaration + aliasesToMakeVisible?: ImportEqualsDeclaration[]; +>aliasesToMakeVisible : ImportEqualsDeclaration[] +>ImportEqualsDeclaration : ImportEqualsDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -2822,15 +2898,15 @@ declare module "typescript" { >node : SourceFile >SourceFile : SourceFile - isReferencedImportDeclaration(node: ImportDeclaration): boolean; ->isReferencedImportDeclaration : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isReferencedImportDeclaration(node: Node): boolean; +>isReferencedImportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; ->isTopLevelValueImportWithEntityName : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; +>isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean +>node : ImportEqualsDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration getNodeCheckFlags(node: Node): NodeCheckFlags; >getNodeCheckFlags : (node: Node) => NodeCheckFlags diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index c8bec722309a3..baaa55c962674 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -191,129 +191,136 @@ declare module "typescript" { VoidKeyword = 98, WhileKeyword = 99, WithKeyword = 100, - ImplementsKeyword = 101, - InterfaceKeyword = 102, - LetKeyword = 103, - PackageKeyword = 104, - PrivateKeyword = 105, - ProtectedKeyword = 106, - PublicKeyword = 107, - StaticKeyword = 108, - YieldKeyword = 109, - AnyKeyword = 110, - BooleanKeyword = 111, - ConstructorKeyword = 112, - DeclareKeyword = 113, - GetKeyword = 114, - ModuleKeyword = 115, - RequireKeyword = 116, - NumberKeyword = 117, - SetKeyword = 118, - StringKeyword = 119, - TypeKeyword = 120, - QualifiedName = 121, - ComputedPropertyName = 122, - TypeParameter = 123, - Parameter = 124, - PropertySignature = 125, - PropertyDeclaration = 126, - MethodSignature = 127, - MethodDeclaration = 128, - Constructor = 129, - GetAccessor = 130, - SetAccessor = 131, - CallSignature = 132, - ConstructSignature = 133, - IndexSignature = 134, - TypeReference = 135, - FunctionType = 136, - ConstructorType = 137, - TypeQuery = 138, - TypeLiteral = 139, - ArrayType = 140, - TupleType = 141, - UnionType = 142, - ParenthesizedType = 143, - ObjectBindingPattern = 144, - ArrayBindingPattern = 145, - BindingElement = 146, - ArrayLiteralExpression = 147, - ObjectLiteralExpression = 148, - PropertyAccessExpression = 149, - ElementAccessExpression = 150, - CallExpression = 151, - NewExpression = 152, - TaggedTemplateExpression = 153, - TypeAssertionExpression = 154, - ParenthesizedExpression = 155, - FunctionExpression = 156, - ArrowFunction = 157, - DeleteExpression = 158, - TypeOfExpression = 159, - VoidExpression = 160, - PrefixUnaryExpression = 161, - PostfixUnaryExpression = 162, - BinaryExpression = 163, - ConditionalExpression = 164, - TemplateExpression = 165, - YieldExpression = 166, - SpreadElementExpression = 167, - OmittedExpression = 168, - TemplateSpan = 169, - Block = 170, - VariableStatement = 171, - EmptyStatement = 172, - ExpressionStatement = 173, - IfStatement = 174, - DoStatement = 175, - WhileStatement = 176, - ForStatement = 177, - ForInStatement = 178, - ContinueStatement = 179, - BreakStatement = 180, - ReturnStatement = 181, - WithStatement = 182, - SwitchStatement = 183, - LabeledStatement = 184, - ThrowStatement = 185, - TryStatement = 186, - DebuggerStatement = 187, - VariableDeclaration = 188, - VariableDeclarationList = 189, - FunctionDeclaration = 190, - ClassDeclaration = 191, - InterfaceDeclaration = 192, - TypeAliasDeclaration = 193, - EnumDeclaration = 194, - ModuleDeclaration = 195, - ModuleBlock = 196, - ImportDeclaration = 197, - ExportAssignment = 198, - ExternalModuleReference = 199, - CaseClause = 200, - DefaultClause = 201, - HeritageClause = 202, - CatchClause = 203, - PropertyAssignment = 204, - ShorthandPropertyAssignment = 205, - EnumMember = 206, - SourceFile = 207, - SyntaxList = 208, - Count = 209, + AsKeyword = 101, + FromKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + TypeKeyword = 122, + QualifiedName = 123, + ComputedPropertyName = 124, + TypeParameter = 125, + Parameter = 126, + PropertySignature = 127, + PropertyDeclaration = 128, + MethodSignature = 129, + MethodDeclaration = 130, + Constructor = 131, + GetAccessor = 132, + SetAccessor = 133, + CallSignature = 134, + ConstructSignature = 135, + IndexSignature = 136, + TypeReference = 137, + FunctionType = 138, + ConstructorType = 139, + TypeQuery = 140, + TypeLiteral = 141, + ArrayType = 142, + TupleType = 143, + UnionType = 144, + ParenthesizedType = 145, + ObjectBindingPattern = 146, + ArrayBindingPattern = 147, + BindingElement = 148, + ArrayLiteralExpression = 149, + ObjectLiteralExpression = 150, + PropertyAccessExpression = 151, + ElementAccessExpression = 152, + CallExpression = 153, + NewExpression = 154, + TaggedTemplateExpression = 155, + TypeAssertionExpression = 156, + ParenthesizedExpression = 157, + FunctionExpression = 158, + ArrowFunction = 159, + DeleteExpression = 160, + TypeOfExpression = 161, + VoidExpression = 162, + PrefixUnaryExpression = 163, + PostfixUnaryExpression = 164, + BinaryExpression = 165, + ConditionalExpression = 166, + TemplateExpression = 167, + YieldExpression = 168, + SpreadElementExpression = 169, + OmittedExpression = 170, + TemplateSpan = 171, + Block = 172, + VariableStatement = 173, + EmptyStatement = 174, + ExpressionStatement = 175, + IfStatement = 176, + DoStatement = 177, + WhileStatement = 178, + ForStatement = 179, + ForInStatement = 180, + ContinueStatement = 181, + BreakStatement = 182, + ReturnStatement = 183, + WithStatement = 184, + SwitchStatement = 185, + LabeledStatement = 186, + ThrowStatement = 187, + TryStatement = 188, + DebuggerStatement = 189, + VariableDeclaration = 190, + VariableDeclarationList = 191, + FunctionDeclaration = 192, + ClassDeclaration = 193, + InterfaceDeclaration = 194, + TypeAliasDeclaration = 195, + EnumDeclaration = 196, + ModuleDeclaration = 197, + ModuleBlock = 198, + ImportEqualsDeclaration = 199, + ExportAssignment = 200, + ImportDeclaration = 201, + ImportClause = 202, + NamespaceImport = 203, + NamedImports = 204, + ImportSpecifier = 205, + ExternalModuleReference = 206, + CaseClause = 207, + DefaultClause = 208, + HeritageClause = 209, + CatchClause = 210, + PropertyAssignment = 211, + ShorthandPropertyAssignment = 212, + EnumMember = 213, + SourceFile = 214, + SyntaxList = 215, + Count = 216, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, LastReservedWord = 100, FirstKeyword = 65, - LastKeyword = 120, - FirstFutureReservedWord = 101, - LastFutureReservedWord = 109, - FirstTypeNode = 135, - LastTypeNode = 143, + LastKeyword = 122, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 137, + LastTypeNode = 145, FirstPunctuation = 14, LastPunctuation = 63, FirstToken = 0, - LastToken = 120, + LastToken = 122, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -322,7 +329,7 @@ declare module "typescript" { LastTemplateToken = 13, FirstBinaryOperator = 24, LastBinaryOperator = 63, - FirstNode = 121, + FirstNode = 123, } const enum NodeFlags { Export = 1, @@ -733,13 +740,31 @@ declare module "typescript" { interface ModuleBlock extends Node, ModuleElement { statements: NodeArray; } - interface ImportDeclaration extends Declaration, ModuleElement { + interface ImportEqualsDeclaration extends Declaration, ModuleElement { name: Identifier; moduleReference: EntityName | ExternalModuleReference; } interface ExternalModuleReference extends Node { expression?: Expression; } + interface ImportDeclaration extends Statement, ModuleElement { + importClause?: ImportClause; + moduleSpecifier: Expression; + } + interface ImportClause extends Declaration { + name?: Identifier; + namedBindings?: NamespaceImport | NamedImports; + } + interface NamespaceImport extends Declaration { + name: Identifier; + } + interface NamedImports extends Node { + elements: NodeArray; + } + interface ImportSpecifier extends Declaration { + propertyName?: Identifier; + name: Identifier; + } interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -900,7 +925,7 @@ declare module "typescript" { } interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportDeclaration[]; + aliasesToMakeVisible?: ImportEqualsDeclaration[]; errorSymbolName?: string; errorNode?: Node; } @@ -911,8 +936,8 @@ declare module "typescript" { getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; - isReferencedImportDeclaration(node: ImportDeclaration): boolean; - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; + isReferencedImportDeclaration(node: Node): boolean; + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; @@ -1951,24 +1976,24 @@ function delint(sourceFile) { delintNode(sourceFile); function delintNode(node) { switch (node.kind) { - case 177 /* ForStatement */: - case 178 /* ForInStatement */: - case 176 /* WhileStatement */: - case 175 /* DoStatement */: - if (node.statement.kind !== 170 /* Block */) { + case 179 /* ForStatement */: + case 180 /* ForInStatement */: + case 178 /* WhileStatement */: + case 177 /* DoStatement */: + if (node.statement.kind !== 172 /* Block */) { report(node, "A looping statement's contents should be wrapped in a block body."); } break; - case 174 /* IfStatement */: + case 176 /* IfStatement */: var ifStatement = node; - if (ifStatement.thenStatement.kind !== 170 /* Block */) { + if (ifStatement.thenStatement.kind !== 172 /* Block */) { report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body."); } - if (ifStatement.elseStatement && ifStatement.elseStatement.kind !== 170 /* Block */ && ifStatement.elseStatement.kind !== 174 /* IfStatement */) { + if (ifStatement.elseStatement && ifStatement.elseStatement.kind !== 172 /* Block */ && ifStatement.elseStatement.kind !== 176 /* IfStatement */) { report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body."); } break; - case 163 /* BinaryExpression */: + case 165 /* BinaryExpression */: var op = node.operator; 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 26254c69d540b..5daa9aca11c78 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -640,331 +640,352 @@ declare module "typescript" { WithKeyword = 100, >WithKeyword : SyntaxKind - ImplementsKeyword = 101, + AsKeyword = 101, +>AsKeyword : SyntaxKind + + FromKeyword = 102, +>FromKeyword : SyntaxKind + + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 102, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 103, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 104, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 105, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 106, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 107, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 108, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 109, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 110, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 111, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 112, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 113, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 114, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 115, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 116, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 117, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 118, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 119, + StringKeyword = 121, >StringKeyword : SyntaxKind - TypeKeyword = 120, + TypeKeyword = 122, >TypeKeyword : SyntaxKind - QualifiedName = 121, + QualifiedName = 123, >QualifiedName : SyntaxKind - ComputedPropertyName = 122, + ComputedPropertyName = 124, >ComputedPropertyName : SyntaxKind - TypeParameter = 123, + TypeParameter = 125, >TypeParameter : SyntaxKind - Parameter = 124, + Parameter = 126, >Parameter : SyntaxKind - PropertySignature = 125, + PropertySignature = 127, >PropertySignature : SyntaxKind - PropertyDeclaration = 126, + PropertyDeclaration = 128, >PropertyDeclaration : SyntaxKind - MethodSignature = 127, + MethodSignature = 129, >MethodSignature : SyntaxKind - MethodDeclaration = 128, + MethodDeclaration = 130, >MethodDeclaration : SyntaxKind - Constructor = 129, + Constructor = 131, >Constructor : SyntaxKind - GetAccessor = 130, + GetAccessor = 132, >GetAccessor : SyntaxKind - SetAccessor = 131, + SetAccessor = 133, >SetAccessor : SyntaxKind - CallSignature = 132, + CallSignature = 134, >CallSignature : SyntaxKind - ConstructSignature = 133, + ConstructSignature = 135, >ConstructSignature : SyntaxKind - IndexSignature = 134, + IndexSignature = 136, >IndexSignature : SyntaxKind - TypeReference = 135, + TypeReference = 137, >TypeReference : SyntaxKind - FunctionType = 136, + FunctionType = 138, >FunctionType : SyntaxKind - ConstructorType = 137, + ConstructorType = 139, >ConstructorType : SyntaxKind - TypeQuery = 138, + TypeQuery = 140, >TypeQuery : SyntaxKind - TypeLiteral = 139, + TypeLiteral = 141, >TypeLiteral : SyntaxKind - ArrayType = 140, + ArrayType = 142, >ArrayType : SyntaxKind - TupleType = 141, + TupleType = 143, >TupleType : SyntaxKind - UnionType = 142, + UnionType = 144, >UnionType : SyntaxKind - ParenthesizedType = 143, + ParenthesizedType = 145, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 144, + ObjectBindingPattern = 146, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 145, + ArrayBindingPattern = 147, >ArrayBindingPattern : SyntaxKind - BindingElement = 146, + BindingElement = 148, >BindingElement : SyntaxKind - ArrayLiteralExpression = 147, + ArrayLiteralExpression = 149, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 148, + ObjectLiteralExpression = 150, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 149, + PropertyAccessExpression = 151, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 150, + ElementAccessExpression = 152, >ElementAccessExpression : SyntaxKind - CallExpression = 151, + CallExpression = 153, >CallExpression : SyntaxKind - NewExpression = 152, + NewExpression = 154, >NewExpression : SyntaxKind - TaggedTemplateExpression = 153, + TaggedTemplateExpression = 155, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 154, + TypeAssertionExpression = 156, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 155, + ParenthesizedExpression = 157, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 156, + FunctionExpression = 158, >FunctionExpression : SyntaxKind - ArrowFunction = 157, + ArrowFunction = 159, >ArrowFunction : SyntaxKind - DeleteExpression = 158, + DeleteExpression = 160, >DeleteExpression : SyntaxKind - TypeOfExpression = 159, + TypeOfExpression = 161, >TypeOfExpression : SyntaxKind - VoidExpression = 160, + VoidExpression = 162, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 161, + PrefixUnaryExpression = 163, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 162, + PostfixUnaryExpression = 164, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 163, + BinaryExpression = 165, >BinaryExpression : SyntaxKind - ConditionalExpression = 164, + ConditionalExpression = 166, >ConditionalExpression : SyntaxKind - TemplateExpression = 165, + TemplateExpression = 167, >TemplateExpression : SyntaxKind - YieldExpression = 166, + YieldExpression = 168, >YieldExpression : SyntaxKind - SpreadElementExpression = 167, + SpreadElementExpression = 169, >SpreadElementExpression : SyntaxKind - OmittedExpression = 168, + OmittedExpression = 170, >OmittedExpression : SyntaxKind - TemplateSpan = 169, + TemplateSpan = 171, >TemplateSpan : SyntaxKind - Block = 170, + Block = 172, >Block : SyntaxKind - VariableStatement = 171, + VariableStatement = 173, >VariableStatement : SyntaxKind - EmptyStatement = 172, + EmptyStatement = 174, >EmptyStatement : SyntaxKind - ExpressionStatement = 173, + ExpressionStatement = 175, >ExpressionStatement : SyntaxKind - IfStatement = 174, + IfStatement = 176, >IfStatement : SyntaxKind - DoStatement = 175, + DoStatement = 177, >DoStatement : SyntaxKind - WhileStatement = 176, + WhileStatement = 178, >WhileStatement : SyntaxKind - ForStatement = 177, + ForStatement = 179, >ForStatement : SyntaxKind - ForInStatement = 178, + ForInStatement = 180, >ForInStatement : SyntaxKind - ContinueStatement = 179, + ContinueStatement = 181, >ContinueStatement : SyntaxKind - BreakStatement = 180, + BreakStatement = 182, >BreakStatement : SyntaxKind - ReturnStatement = 181, + ReturnStatement = 183, >ReturnStatement : SyntaxKind - WithStatement = 182, + WithStatement = 184, >WithStatement : SyntaxKind - SwitchStatement = 183, + SwitchStatement = 185, >SwitchStatement : SyntaxKind - LabeledStatement = 184, + LabeledStatement = 186, >LabeledStatement : SyntaxKind - ThrowStatement = 185, + ThrowStatement = 187, >ThrowStatement : SyntaxKind - TryStatement = 186, + TryStatement = 188, >TryStatement : SyntaxKind - DebuggerStatement = 187, + DebuggerStatement = 189, >DebuggerStatement : SyntaxKind - VariableDeclaration = 188, + VariableDeclaration = 190, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 189, + VariableDeclarationList = 191, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 190, + FunctionDeclaration = 192, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 191, + ClassDeclaration = 193, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 192, + InterfaceDeclaration = 194, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 193, + TypeAliasDeclaration = 195, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 194, + EnumDeclaration = 196, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 195, + ModuleDeclaration = 197, >ModuleDeclaration : SyntaxKind - ModuleBlock = 196, + ModuleBlock = 198, >ModuleBlock : SyntaxKind - ImportDeclaration = 197, ->ImportDeclaration : SyntaxKind + ImportEqualsDeclaration = 199, +>ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 198, + ExportAssignment = 200, >ExportAssignment : SyntaxKind - ExternalModuleReference = 199, + ImportDeclaration = 201, +>ImportDeclaration : SyntaxKind + + ImportClause = 202, +>ImportClause : SyntaxKind + + NamespaceImport = 203, +>NamespaceImport : SyntaxKind + + NamedImports = 204, +>NamedImports : SyntaxKind + + ImportSpecifier = 205, +>ImportSpecifier : SyntaxKind + + ExternalModuleReference = 206, >ExternalModuleReference : SyntaxKind - CaseClause = 200, + CaseClause = 207, >CaseClause : SyntaxKind - DefaultClause = 201, + DefaultClause = 208, >DefaultClause : SyntaxKind - HeritageClause = 202, + HeritageClause = 209, >HeritageClause : SyntaxKind - CatchClause = 203, + CatchClause = 210, >CatchClause : SyntaxKind - PropertyAssignment = 204, + PropertyAssignment = 211, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 205, + ShorthandPropertyAssignment = 212, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 206, + EnumMember = 213, >EnumMember : SyntaxKind - SourceFile = 207, + SourceFile = 214, >SourceFile : SyntaxKind - SyntaxList = 208, + SyntaxList = 215, >SyntaxList : SyntaxKind - Count = 209, + Count = 216, >Count : SyntaxKind FirstAssignment = 52, @@ -982,19 +1003,19 @@ declare module "typescript" { FirstKeyword = 65, >FirstKeyword : SyntaxKind - LastKeyword = 120, + LastKeyword = 122, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 101, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 109, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 135, + FirstTypeNode = 137, >FirstTypeNode : SyntaxKind - LastTypeNode = 143, + LastTypeNode = 145, >LastTypeNode : SyntaxKind FirstPunctuation = 14, @@ -1006,7 +1027,7 @@ declare module "typescript" { FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 120, + LastToken = 122, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1033,7 +1054,7 @@ declare module "typescript" { LastBinaryOperator = 63, >LastBinaryOperator : SyntaxKind - FirstNode = 121, + FirstNode = 123, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -2275,8 +2296,8 @@ declare module "typescript" { >NodeArray : NodeArray >ModuleElement : ModuleElement } - interface ImportDeclaration extends Declaration, ModuleElement { ->ImportDeclaration : ImportDeclaration + interface ImportEqualsDeclaration extends Declaration, ModuleElement { +>ImportEqualsDeclaration : ImportEqualsDeclaration >Declaration : Declaration >ModuleElement : ModuleElement @@ -2296,6 +2317,61 @@ declare module "typescript" { expression?: Expression; >expression : Expression >Expression : Expression + } + interface ImportDeclaration extends Statement, ModuleElement { +>ImportDeclaration : ImportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + importClause?: ImportClause; +>importClause : ImportClause +>ImportClause : ImportClause + + moduleSpecifier: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface ImportClause extends Declaration { +>ImportClause : ImportClause +>Declaration : Declaration + + name?: Identifier; +>name : Identifier +>Identifier : Identifier + + namedBindings?: NamespaceImport | NamedImports; +>namedBindings : NamespaceImport | NamedImports +>NamespaceImport : NamespaceImport +>NamedImports : NamedImports + } + interface NamespaceImport extends Declaration { +>NamespaceImport : NamespaceImport +>Declaration : Declaration + + name: Identifier; +>name : Identifier +>Identifier : Identifier + } + interface NamedImports extends Node { +>NamedImports : NamedImports +>Node : Node + + elements: NodeArray; +>elements : NodeArray +>NodeArray : NodeArray +>ImportSpecifier : ImportSpecifier + } + interface ImportSpecifier extends Declaration { +>ImportSpecifier : ImportSpecifier +>Declaration : Declaration + + propertyName?: Identifier; +>propertyName : Identifier +>Identifier : Identifier + + name: Identifier; +>name : Identifier +>Identifier : Identifier } interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment @@ -2929,9 +3005,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportDeclaration[]; ->aliasesToMakeVisible : ImportDeclaration[] ->ImportDeclaration : ImportDeclaration + aliasesToMakeVisible?: ImportEqualsDeclaration[]; +>aliasesToMakeVisible : ImportEqualsDeclaration[] +>ImportEqualsDeclaration : ImportEqualsDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -2966,15 +3042,15 @@ declare module "typescript" { >node : SourceFile >SourceFile : SourceFile - isReferencedImportDeclaration(node: ImportDeclaration): boolean; ->isReferencedImportDeclaration : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isReferencedImportDeclaration(node: Node): boolean; +>isReferencedImportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; ->isTopLevelValueImportWithEntityName : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; +>isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean +>node : ImportEqualsDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration getNodeCheckFlags(node: Node): NodeCheckFlags; >getNodeCheckFlags : (node: Node) => NodeCheckFlags diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index ad66d289eb774..8e920c476f4ec 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -192,129 +192,136 @@ declare module "typescript" { VoidKeyword = 98, WhileKeyword = 99, WithKeyword = 100, - ImplementsKeyword = 101, - InterfaceKeyword = 102, - LetKeyword = 103, - PackageKeyword = 104, - PrivateKeyword = 105, - ProtectedKeyword = 106, - PublicKeyword = 107, - StaticKeyword = 108, - YieldKeyword = 109, - AnyKeyword = 110, - BooleanKeyword = 111, - ConstructorKeyword = 112, - DeclareKeyword = 113, - GetKeyword = 114, - ModuleKeyword = 115, - RequireKeyword = 116, - NumberKeyword = 117, - SetKeyword = 118, - StringKeyword = 119, - TypeKeyword = 120, - QualifiedName = 121, - ComputedPropertyName = 122, - TypeParameter = 123, - Parameter = 124, - PropertySignature = 125, - PropertyDeclaration = 126, - MethodSignature = 127, - MethodDeclaration = 128, - Constructor = 129, - GetAccessor = 130, - SetAccessor = 131, - CallSignature = 132, - ConstructSignature = 133, - IndexSignature = 134, - TypeReference = 135, - FunctionType = 136, - ConstructorType = 137, - TypeQuery = 138, - TypeLiteral = 139, - ArrayType = 140, - TupleType = 141, - UnionType = 142, - ParenthesizedType = 143, - ObjectBindingPattern = 144, - ArrayBindingPattern = 145, - BindingElement = 146, - ArrayLiteralExpression = 147, - ObjectLiteralExpression = 148, - PropertyAccessExpression = 149, - ElementAccessExpression = 150, - CallExpression = 151, - NewExpression = 152, - TaggedTemplateExpression = 153, - TypeAssertionExpression = 154, - ParenthesizedExpression = 155, - FunctionExpression = 156, - ArrowFunction = 157, - DeleteExpression = 158, - TypeOfExpression = 159, - VoidExpression = 160, - PrefixUnaryExpression = 161, - PostfixUnaryExpression = 162, - BinaryExpression = 163, - ConditionalExpression = 164, - TemplateExpression = 165, - YieldExpression = 166, - SpreadElementExpression = 167, - OmittedExpression = 168, - TemplateSpan = 169, - Block = 170, - VariableStatement = 171, - EmptyStatement = 172, - ExpressionStatement = 173, - IfStatement = 174, - DoStatement = 175, - WhileStatement = 176, - ForStatement = 177, - ForInStatement = 178, - ContinueStatement = 179, - BreakStatement = 180, - ReturnStatement = 181, - WithStatement = 182, - SwitchStatement = 183, - LabeledStatement = 184, - ThrowStatement = 185, - TryStatement = 186, - DebuggerStatement = 187, - VariableDeclaration = 188, - VariableDeclarationList = 189, - FunctionDeclaration = 190, - ClassDeclaration = 191, - InterfaceDeclaration = 192, - TypeAliasDeclaration = 193, - EnumDeclaration = 194, - ModuleDeclaration = 195, - ModuleBlock = 196, - ImportDeclaration = 197, - ExportAssignment = 198, - ExternalModuleReference = 199, - CaseClause = 200, - DefaultClause = 201, - HeritageClause = 202, - CatchClause = 203, - PropertyAssignment = 204, - ShorthandPropertyAssignment = 205, - EnumMember = 206, - SourceFile = 207, - SyntaxList = 208, - Count = 209, + AsKeyword = 101, + FromKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + TypeKeyword = 122, + QualifiedName = 123, + ComputedPropertyName = 124, + TypeParameter = 125, + Parameter = 126, + PropertySignature = 127, + PropertyDeclaration = 128, + MethodSignature = 129, + MethodDeclaration = 130, + Constructor = 131, + GetAccessor = 132, + SetAccessor = 133, + CallSignature = 134, + ConstructSignature = 135, + IndexSignature = 136, + TypeReference = 137, + FunctionType = 138, + ConstructorType = 139, + TypeQuery = 140, + TypeLiteral = 141, + ArrayType = 142, + TupleType = 143, + UnionType = 144, + ParenthesizedType = 145, + ObjectBindingPattern = 146, + ArrayBindingPattern = 147, + BindingElement = 148, + ArrayLiteralExpression = 149, + ObjectLiteralExpression = 150, + PropertyAccessExpression = 151, + ElementAccessExpression = 152, + CallExpression = 153, + NewExpression = 154, + TaggedTemplateExpression = 155, + TypeAssertionExpression = 156, + ParenthesizedExpression = 157, + FunctionExpression = 158, + ArrowFunction = 159, + DeleteExpression = 160, + TypeOfExpression = 161, + VoidExpression = 162, + PrefixUnaryExpression = 163, + PostfixUnaryExpression = 164, + BinaryExpression = 165, + ConditionalExpression = 166, + TemplateExpression = 167, + YieldExpression = 168, + SpreadElementExpression = 169, + OmittedExpression = 170, + TemplateSpan = 171, + Block = 172, + VariableStatement = 173, + EmptyStatement = 174, + ExpressionStatement = 175, + IfStatement = 176, + DoStatement = 177, + WhileStatement = 178, + ForStatement = 179, + ForInStatement = 180, + ContinueStatement = 181, + BreakStatement = 182, + ReturnStatement = 183, + WithStatement = 184, + SwitchStatement = 185, + LabeledStatement = 186, + ThrowStatement = 187, + TryStatement = 188, + DebuggerStatement = 189, + VariableDeclaration = 190, + VariableDeclarationList = 191, + FunctionDeclaration = 192, + ClassDeclaration = 193, + InterfaceDeclaration = 194, + TypeAliasDeclaration = 195, + EnumDeclaration = 196, + ModuleDeclaration = 197, + ModuleBlock = 198, + ImportEqualsDeclaration = 199, + ExportAssignment = 200, + ImportDeclaration = 201, + ImportClause = 202, + NamespaceImport = 203, + NamedImports = 204, + ImportSpecifier = 205, + ExternalModuleReference = 206, + CaseClause = 207, + DefaultClause = 208, + HeritageClause = 209, + CatchClause = 210, + PropertyAssignment = 211, + ShorthandPropertyAssignment = 212, + EnumMember = 213, + SourceFile = 214, + SyntaxList = 215, + Count = 216, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, LastReservedWord = 100, FirstKeyword = 65, - LastKeyword = 120, - FirstFutureReservedWord = 101, - LastFutureReservedWord = 109, - FirstTypeNode = 135, - LastTypeNode = 143, + LastKeyword = 122, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 137, + LastTypeNode = 145, FirstPunctuation = 14, LastPunctuation = 63, FirstToken = 0, - LastToken = 120, + LastToken = 122, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -323,7 +330,7 @@ declare module "typescript" { LastTemplateToken = 13, FirstBinaryOperator = 24, LastBinaryOperator = 63, - FirstNode = 121, + FirstNode = 123, } const enum NodeFlags { Export = 1, @@ -734,13 +741,31 @@ declare module "typescript" { interface ModuleBlock extends Node, ModuleElement { statements: NodeArray; } - interface ImportDeclaration extends Declaration, ModuleElement { + interface ImportEqualsDeclaration extends Declaration, ModuleElement { name: Identifier; moduleReference: EntityName | ExternalModuleReference; } interface ExternalModuleReference extends Node { expression?: Expression; } + interface ImportDeclaration extends Statement, ModuleElement { + importClause?: ImportClause; + moduleSpecifier: Expression; + } + interface ImportClause extends Declaration { + name?: Identifier; + namedBindings?: NamespaceImport | NamedImports; + } + interface NamespaceImport extends Declaration { + name: Identifier; + } + interface NamedImports extends Node { + elements: NodeArray; + } + interface ImportSpecifier extends Declaration { + propertyName?: Identifier; + name: Identifier; + } interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -901,7 +926,7 @@ declare module "typescript" { } interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportDeclaration[]; + aliasesToMakeVisible?: ImportEqualsDeclaration[]; errorSymbolName?: string; errorNode?: Node; } @@ -912,8 +937,8 @@ declare module "typescript" { getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; - isReferencedImportDeclaration(node: ImportDeclaration): boolean; - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; + isReferencedImportDeclaration(node: Node): boolean; + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index c6d74cc811da1..142165ab4ec0d 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -592,331 +592,352 @@ declare module "typescript" { WithKeyword = 100, >WithKeyword : SyntaxKind - ImplementsKeyword = 101, + AsKeyword = 101, +>AsKeyword : SyntaxKind + + FromKeyword = 102, +>FromKeyword : SyntaxKind + + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 102, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 103, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 104, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 105, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 106, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 107, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 108, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 109, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 110, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 111, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 112, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 113, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 114, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 115, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 116, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 117, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 118, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 119, + StringKeyword = 121, >StringKeyword : SyntaxKind - TypeKeyword = 120, + TypeKeyword = 122, >TypeKeyword : SyntaxKind - QualifiedName = 121, + QualifiedName = 123, >QualifiedName : SyntaxKind - ComputedPropertyName = 122, + ComputedPropertyName = 124, >ComputedPropertyName : SyntaxKind - TypeParameter = 123, + TypeParameter = 125, >TypeParameter : SyntaxKind - Parameter = 124, + Parameter = 126, >Parameter : SyntaxKind - PropertySignature = 125, + PropertySignature = 127, >PropertySignature : SyntaxKind - PropertyDeclaration = 126, + PropertyDeclaration = 128, >PropertyDeclaration : SyntaxKind - MethodSignature = 127, + MethodSignature = 129, >MethodSignature : SyntaxKind - MethodDeclaration = 128, + MethodDeclaration = 130, >MethodDeclaration : SyntaxKind - Constructor = 129, + Constructor = 131, >Constructor : SyntaxKind - GetAccessor = 130, + GetAccessor = 132, >GetAccessor : SyntaxKind - SetAccessor = 131, + SetAccessor = 133, >SetAccessor : SyntaxKind - CallSignature = 132, + CallSignature = 134, >CallSignature : SyntaxKind - ConstructSignature = 133, + ConstructSignature = 135, >ConstructSignature : SyntaxKind - IndexSignature = 134, + IndexSignature = 136, >IndexSignature : SyntaxKind - TypeReference = 135, + TypeReference = 137, >TypeReference : SyntaxKind - FunctionType = 136, + FunctionType = 138, >FunctionType : SyntaxKind - ConstructorType = 137, + ConstructorType = 139, >ConstructorType : SyntaxKind - TypeQuery = 138, + TypeQuery = 140, >TypeQuery : SyntaxKind - TypeLiteral = 139, + TypeLiteral = 141, >TypeLiteral : SyntaxKind - ArrayType = 140, + ArrayType = 142, >ArrayType : SyntaxKind - TupleType = 141, + TupleType = 143, >TupleType : SyntaxKind - UnionType = 142, + UnionType = 144, >UnionType : SyntaxKind - ParenthesizedType = 143, + ParenthesizedType = 145, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 144, + ObjectBindingPattern = 146, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 145, + ArrayBindingPattern = 147, >ArrayBindingPattern : SyntaxKind - BindingElement = 146, + BindingElement = 148, >BindingElement : SyntaxKind - ArrayLiteralExpression = 147, + ArrayLiteralExpression = 149, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 148, + ObjectLiteralExpression = 150, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 149, + PropertyAccessExpression = 151, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 150, + ElementAccessExpression = 152, >ElementAccessExpression : SyntaxKind - CallExpression = 151, + CallExpression = 153, >CallExpression : SyntaxKind - NewExpression = 152, + NewExpression = 154, >NewExpression : SyntaxKind - TaggedTemplateExpression = 153, + TaggedTemplateExpression = 155, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 154, + TypeAssertionExpression = 156, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 155, + ParenthesizedExpression = 157, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 156, + FunctionExpression = 158, >FunctionExpression : SyntaxKind - ArrowFunction = 157, + ArrowFunction = 159, >ArrowFunction : SyntaxKind - DeleteExpression = 158, + DeleteExpression = 160, >DeleteExpression : SyntaxKind - TypeOfExpression = 159, + TypeOfExpression = 161, >TypeOfExpression : SyntaxKind - VoidExpression = 160, + VoidExpression = 162, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 161, + PrefixUnaryExpression = 163, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 162, + PostfixUnaryExpression = 164, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 163, + BinaryExpression = 165, >BinaryExpression : SyntaxKind - ConditionalExpression = 164, + ConditionalExpression = 166, >ConditionalExpression : SyntaxKind - TemplateExpression = 165, + TemplateExpression = 167, >TemplateExpression : SyntaxKind - YieldExpression = 166, + YieldExpression = 168, >YieldExpression : SyntaxKind - SpreadElementExpression = 167, + SpreadElementExpression = 169, >SpreadElementExpression : SyntaxKind - OmittedExpression = 168, + OmittedExpression = 170, >OmittedExpression : SyntaxKind - TemplateSpan = 169, + TemplateSpan = 171, >TemplateSpan : SyntaxKind - Block = 170, + Block = 172, >Block : SyntaxKind - VariableStatement = 171, + VariableStatement = 173, >VariableStatement : SyntaxKind - EmptyStatement = 172, + EmptyStatement = 174, >EmptyStatement : SyntaxKind - ExpressionStatement = 173, + ExpressionStatement = 175, >ExpressionStatement : SyntaxKind - IfStatement = 174, + IfStatement = 176, >IfStatement : SyntaxKind - DoStatement = 175, + DoStatement = 177, >DoStatement : SyntaxKind - WhileStatement = 176, + WhileStatement = 178, >WhileStatement : SyntaxKind - ForStatement = 177, + ForStatement = 179, >ForStatement : SyntaxKind - ForInStatement = 178, + ForInStatement = 180, >ForInStatement : SyntaxKind - ContinueStatement = 179, + ContinueStatement = 181, >ContinueStatement : SyntaxKind - BreakStatement = 180, + BreakStatement = 182, >BreakStatement : SyntaxKind - ReturnStatement = 181, + ReturnStatement = 183, >ReturnStatement : SyntaxKind - WithStatement = 182, + WithStatement = 184, >WithStatement : SyntaxKind - SwitchStatement = 183, + SwitchStatement = 185, >SwitchStatement : SyntaxKind - LabeledStatement = 184, + LabeledStatement = 186, >LabeledStatement : SyntaxKind - ThrowStatement = 185, + ThrowStatement = 187, >ThrowStatement : SyntaxKind - TryStatement = 186, + TryStatement = 188, >TryStatement : SyntaxKind - DebuggerStatement = 187, + DebuggerStatement = 189, >DebuggerStatement : SyntaxKind - VariableDeclaration = 188, + VariableDeclaration = 190, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 189, + VariableDeclarationList = 191, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 190, + FunctionDeclaration = 192, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 191, + ClassDeclaration = 193, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 192, + InterfaceDeclaration = 194, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 193, + TypeAliasDeclaration = 195, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 194, + EnumDeclaration = 196, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 195, + ModuleDeclaration = 197, >ModuleDeclaration : SyntaxKind - ModuleBlock = 196, + ModuleBlock = 198, >ModuleBlock : SyntaxKind - ImportDeclaration = 197, ->ImportDeclaration : SyntaxKind + ImportEqualsDeclaration = 199, +>ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 198, + ExportAssignment = 200, >ExportAssignment : SyntaxKind - ExternalModuleReference = 199, + ImportDeclaration = 201, +>ImportDeclaration : SyntaxKind + + ImportClause = 202, +>ImportClause : SyntaxKind + + NamespaceImport = 203, +>NamespaceImport : SyntaxKind + + NamedImports = 204, +>NamedImports : SyntaxKind + + ImportSpecifier = 205, +>ImportSpecifier : SyntaxKind + + ExternalModuleReference = 206, >ExternalModuleReference : SyntaxKind - CaseClause = 200, + CaseClause = 207, >CaseClause : SyntaxKind - DefaultClause = 201, + DefaultClause = 208, >DefaultClause : SyntaxKind - HeritageClause = 202, + HeritageClause = 209, >HeritageClause : SyntaxKind - CatchClause = 203, + CatchClause = 210, >CatchClause : SyntaxKind - PropertyAssignment = 204, + PropertyAssignment = 211, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 205, + ShorthandPropertyAssignment = 212, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 206, + EnumMember = 213, >EnumMember : SyntaxKind - SourceFile = 207, + SourceFile = 214, >SourceFile : SyntaxKind - SyntaxList = 208, + SyntaxList = 215, >SyntaxList : SyntaxKind - Count = 209, + Count = 216, >Count : SyntaxKind FirstAssignment = 52, @@ -934,19 +955,19 @@ declare module "typescript" { FirstKeyword = 65, >FirstKeyword : SyntaxKind - LastKeyword = 120, + LastKeyword = 122, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 101, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 109, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 135, + FirstTypeNode = 137, >FirstTypeNode : SyntaxKind - LastTypeNode = 143, + LastTypeNode = 145, >LastTypeNode : SyntaxKind FirstPunctuation = 14, @@ -958,7 +979,7 @@ declare module "typescript" { FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 120, + LastToken = 122, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -985,7 +1006,7 @@ declare module "typescript" { LastBinaryOperator = 63, >LastBinaryOperator : SyntaxKind - FirstNode = 121, + FirstNode = 123, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -2227,8 +2248,8 @@ declare module "typescript" { >NodeArray : NodeArray >ModuleElement : ModuleElement } - interface ImportDeclaration extends Declaration, ModuleElement { ->ImportDeclaration : ImportDeclaration + interface ImportEqualsDeclaration extends Declaration, ModuleElement { +>ImportEqualsDeclaration : ImportEqualsDeclaration >Declaration : Declaration >ModuleElement : ModuleElement @@ -2248,6 +2269,61 @@ declare module "typescript" { expression?: Expression; >expression : Expression >Expression : Expression + } + interface ImportDeclaration extends Statement, ModuleElement { +>ImportDeclaration : ImportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + importClause?: ImportClause; +>importClause : ImportClause +>ImportClause : ImportClause + + moduleSpecifier: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface ImportClause extends Declaration { +>ImportClause : ImportClause +>Declaration : Declaration + + name?: Identifier; +>name : Identifier +>Identifier : Identifier + + namedBindings?: NamespaceImport | NamedImports; +>namedBindings : NamespaceImport | NamedImports +>NamespaceImport : NamespaceImport +>NamedImports : NamedImports + } + interface NamespaceImport extends Declaration { +>NamespaceImport : NamespaceImport +>Declaration : Declaration + + name: Identifier; +>name : Identifier +>Identifier : Identifier + } + interface NamedImports extends Node { +>NamedImports : NamedImports +>Node : Node + + elements: NodeArray; +>elements : NodeArray +>NodeArray : NodeArray +>ImportSpecifier : ImportSpecifier + } + interface ImportSpecifier extends Declaration { +>ImportSpecifier : ImportSpecifier +>Declaration : Declaration + + propertyName?: Identifier; +>propertyName : Identifier +>Identifier : Identifier + + name: Identifier; +>name : Identifier +>Identifier : Identifier } interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment @@ -2881,9 +2957,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportDeclaration[]; ->aliasesToMakeVisible : ImportDeclaration[] ->ImportDeclaration : ImportDeclaration + aliasesToMakeVisible?: ImportEqualsDeclaration[]; +>aliasesToMakeVisible : ImportEqualsDeclaration[] +>ImportEqualsDeclaration : ImportEqualsDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -2918,15 +2994,15 @@ declare module "typescript" { >node : SourceFile >SourceFile : SourceFile - isReferencedImportDeclaration(node: ImportDeclaration): boolean; ->isReferencedImportDeclaration : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isReferencedImportDeclaration(node: Node): boolean; +>isReferencedImportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; ->isTopLevelValueImportWithEntityName : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; +>isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean +>node : ImportEqualsDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration getNodeCheckFlags(node: Node): NodeCheckFlags; >getNodeCheckFlags : (node: Node) => NodeCheckFlags diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 2add8dfd45e6c..5d9055b357c93 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -229,129 +229,136 @@ declare module "typescript" { VoidKeyword = 98, WhileKeyword = 99, WithKeyword = 100, - ImplementsKeyword = 101, - InterfaceKeyword = 102, - LetKeyword = 103, - PackageKeyword = 104, - PrivateKeyword = 105, - ProtectedKeyword = 106, - PublicKeyword = 107, - StaticKeyword = 108, - YieldKeyword = 109, - AnyKeyword = 110, - BooleanKeyword = 111, - ConstructorKeyword = 112, - DeclareKeyword = 113, - GetKeyword = 114, - ModuleKeyword = 115, - RequireKeyword = 116, - NumberKeyword = 117, - SetKeyword = 118, - StringKeyword = 119, - TypeKeyword = 120, - QualifiedName = 121, - ComputedPropertyName = 122, - TypeParameter = 123, - Parameter = 124, - PropertySignature = 125, - PropertyDeclaration = 126, - MethodSignature = 127, - MethodDeclaration = 128, - Constructor = 129, - GetAccessor = 130, - SetAccessor = 131, - CallSignature = 132, - ConstructSignature = 133, - IndexSignature = 134, - TypeReference = 135, - FunctionType = 136, - ConstructorType = 137, - TypeQuery = 138, - TypeLiteral = 139, - ArrayType = 140, - TupleType = 141, - UnionType = 142, - ParenthesizedType = 143, - ObjectBindingPattern = 144, - ArrayBindingPattern = 145, - BindingElement = 146, - ArrayLiteralExpression = 147, - ObjectLiteralExpression = 148, - PropertyAccessExpression = 149, - ElementAccessExpression = 150, - CallExpression = 151, - NewExpression = 152, - TaggedTemplateExpression = 153, - TypeAssertionExpression = 154, - ParenthesizedExpression = 155, - FunctionExpression = 156, - ArrowFunction = 157, - DeleteExpression = 158, - TypeOfExpression = 159, - VoidExpression = 160, - PrefixUnaryExpression = 161, - PostfixUnaryExpression = 162, - BinaryExpression = 163, - ConditionalExpression = 164, - TemplateExpression = 165, - YieldExpression = 166, - SpreadElementExpression = 167, - OmittedExpression = 168, - TemplateSpan = 169, - Block = 170, - VariableStatement = 171, - EmptyStatement = 172, - ExpressionStatement = 173, - IfStatement = 174, - DoStatement = 175, - WhileStatement = 176, - ForStatement = 177, - ForInStatement = 178, - ContinueStatement = 179, - BreakStatement = 180, - ReturnStatement = 181, - WithStatement = 182, - SwitchStatement = 183, - LabeledStatement = 184, - ThrowStatement = 185, - TryStatement = 186, - DebuggerStatement = 187, - VariableDeclaration = 188, - VariableDeclarationList = 189, - FunctionDeclaration = 190, - ClassDeclaration = 191, - InterfaceDeclaration = 192, - TypeAliasDeclaration = 193, - EnumDeclaration = 194, - ModuleDeclaration = 195, - ModuleBlock = 196, - ImportDeclaration = 197, - ExportAssignment = 198, - ExternalModuleReference = 199, - CaseClause = 200, - DefaultClause = 201, - HeritageClause = 202, - CatchClause = 203, - PropertyAssignment = 204, - ShorthandPropertyAssignment = 205, - EnumMember = 206, - SourceFile = 207, - SyntaxList = 208, - Count = 209, + AsKeyword = 101, + FromKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + TypeKeyword = 122, + QualifiedName = 123, + ComputedPropertyName = 124, + TypeParameter = 125, + Parameter = 126, + PropertySignature = 127, + PropertyDeclaration = 128, + MethodSignature = 129, + MethodDeclaration = 130, + Constructor = 131, + GetAccessor = 132, + SetAccessor = 133, + CallSignature = 134, + ConstructSignature = 135, + IndexSignature = 136, + TypeReference = 137, + FunctionType = 138, + ConstructorType = 139, + TypeQuery = 140, + TypeLiteral = 141, + ArrayType = 142, + TupleType = 143, + UnionType = 144, + ParenthesizedType = 145, + ObjectBindingPattern = 146, + ArrayBindingPattern = 147, + BindingElement = 148, + ArrayLiteralExpression = 149, + ObjectLiteralExpression = 150, + PropertyAccessExpression = 151, + ElementAccessExpression = 152, + CallExpression = 153, + NewExpression = 154, + TaggedTemplateExpression = 155, + TypeAssertionExpression = 156, + ParenthesizedExpression = 157, + FunctionExpression = 158, + ArrowFunction = 159, + DeleteExpression = 160, + TypeOfExpression = 161, + VoidExpression = 162, + PrefixUnaryExpression = 163, + PostfixUnaryExpression = 164, + BinaryExpression = 165, + ConditionalExpression = 166, + TemplateExpression = 167, + YieldExpression = 168, + SpreadElementExpression = 169, + OmittedExpression = 170, + TemplateSpan = 171, + Block = 172, + VariableStatement = 173, + EmptyStatement = 174, + ExpressionStatement = 175, + IfStatement = 176, + DoStatement = 177, + WhileStatement = 178, + ForStatement = 179, + ForInStatement = 180, + ContinueStatement = 181, + BreakStatement = 182, + ReturnStatement = 183, + WithStatement = 184, + SwitchStatement = 185, + LabeledStatement = 186, + ThrowStatement = 187, + TryStatement = 188, + DebuggerStatement = 189, + VariableDeclaration = 190, + VariableDeclarationList = 191, + FunctionDeclaration = 192, + ClassDeclaration = 193, + InterfaceDeclaration = 194, + TypeAliasDeclaration = 195, + EnumDeclaration = 196, + ModuleDeclaration = 197, + ModuleBlock = 198, + ImportEqualsDeclaration = 199, + ExportAssignment = 200, + ImportDeclaration = 201, + ImportClause = 202, + NamespaceImport = 203, + NamedImports = 204, + ImportSpecifier = 205, + ExternalModuleReference = 206, + CaseClause = 207, + DefaultClause = 208, + HeritageClause = 209, + CatchClause = 210, + PropertyAssignment = 211, + ShorthandPropertyAssignment = 212, + EnumMember = 213, + SourceFile = 214, + SyntaxList = 215, + Count = 216, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, LastReservedWord = 100, FirstKeyword = 65, - LastKeyword = 120, - FirstFutureReservedWord = 101, - LastFutureReservedWord = 109, - FirstTypeNode = 135, - LastTypeNode = 143, + LastKeyword = 122, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 137, + LastTypeNode = 145, FirstPunctuation = 14, LastPunctuation = 63, FirstToken = 0, - LastToken = 120, + LastToken = 122, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -360,7 +367,7 @@ declare module "typescript" { LastTemplateToken = 13, FirstBinaryOperator = 24, LastBinaryOperator = 63, - FirstNode = 121, + FirstNode = 123, } const enum NodeFlags { Export = 1, @@ -771,13 +778,31 @@ declare module "typescript" { interface ModuleBlock extends Node, ModuleElement { statements: NodeArray; } - interface ImportDeclaration extends Declaration, ModuleElement { + interface ImportEqualsDeclaration extends Declaration, ModuleElement { name: Identifier; moduleReference: EntityName | ExternalModuleReference; } interface ExternalModuleReference extends Node { expression?: Expression; } + interface ImportDeclaration extends Statement, ModuleElement { + importClause?: ImportClause; + moduleSpecifier: Expression; + } + interface ImportClause extends Declaration { + name?: Identifier; + namedBindings?: NamespaceImport | NamedImports; + } + interface NamespaceImport extends Declaration { + name: Identifier; + } + interface NamedImports extends Node { + elements: NodeArray; + } + interface ImportSpecifier extends Declaration { + propertyName?: Identifier; + name: Identifier; + } interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -938,7 +963,7 @@ declare module "typescript" { } interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportDeclaration[]; + aliasesToMakeVisible?: ImportEqualsDeclaration[]; errorSymbolName?: string; errorNode?: Node; } @@ -949,8 +974,8 @@ declare module "typescript" { getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; getExpressionNamePrefix(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; - isReferencedImportDeclaration(node: ImportDeclaration): boolean; - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; + isReferencedImportDeclaration(node: Node): boolean; + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 3af8537fdb780..8f40648be3802 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -765,331 +765,352 @@ declare module "typescript" { WithKeyword = 100, >WithKeyword : SyntaxKind - ImplementsKeyword = 101, + AsKeyword = 101, +>AsKeyword : SyntaxKind + + FromKeyword = 102, +>FromKeyword : SyntaxKind + + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 102, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 103, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 104, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 105, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 106, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 107, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 108, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 109, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 110, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 111, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 112, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 113, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 114, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 115, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 116, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 117, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 118, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 119, + StringKeyword = 121, >StringKeyword : SyntaxKind - TypeKeyword = 120, + TypeKeyword = 122, >TypeKeyword : SyntaxKind - QualifiedName = 121, + QualifiedName = 123, >QualifiedName : SyntaxKind - ComputedPropertyName = 122, + ComputedPropertyName = 124, >ComputedPropertyName : SyntaxKind - TypeParameter = 123, + TypeParameter = 125, >TypeParameter : SyntaxKind - Parameter = 124, + Parameter = 126, >Parameter : SyntaxKind - PropertySignature = 125, + PropertySignature = 127, >PropertySignature : SyntaxKind - PropertyDeclaration = 126, + PropertyDeclaration = 128, >PropertyDeclaration : SyntaxKind - MethodSignature = 127, + MethodSignature = 129, >MethodSignature : SyntaxKind - MethodDeclaration = 128, + MethodDeclaration = 130, >MethodDeclaration : SyntaxKind - Constructor = 129, + Constructor = 131, >Constructor : SyntaxKind - GetAccessor = 130, + GetAccessor = 132, >GetAccessor : SyntaxKind - SetAccessor = 131, + SetAccessor = 133, >SetAccessor : SyntaxKind - CallSignature = 132, + CallSignature = 134, >CallSignature : SyntaxKind - ConstructSignature = 133, + ConstructSignature = 135, >ConstructSignature : SyntaxKind - IndexSignature = 134, + IndexSignature = 136, >IndexSignature : SyntaxKind - TypeReference = 135, + TypeReference = 137, >TypeReference : SyntaxKind - FunctionType = 136, + FunctionType = 138, >FunctionType : SyntaxKind - ConstructorType = 137, + ConstructorType = 139, >ConstructorType : SyntaxKind - TypeQuery = 138, + TypeQuery = 140, >TypeQuery : SyntaxKind - TypeLiteral = 139, + TypeLiteral = 141, >TypeLiteral : SyntaxKind - ArrayType = 140, + ArrayType = 142, >ArrayType : SyntaxKind - TupleType = 141, + TupleType = 143, >TupleType : SyntaxKind - UnionType = 142, + UnionType = 144, >UnionType : SyntaxKind - ParenthesizedType = 143, + ParenthesizedType = 145, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 144, + ObjectBindingPattern = 146, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 145, + ArrayBindingPattern = 147, >ArrayBindingPattern : SyntaxKind - BindingElement = 146, + BindingElement = 148, >BindingElement : SyntaxKind - ArrayLiteralExpression = 147, + ArrayLiteralExpression = 149, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 148, + ObjectLiteralExpression = 150, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 149, + PropertyAccessExpression = 151, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 150, + ElementAccessExpression = 152, >ElementAccessExpression : SyntaxKind - CallExpression = 151, + CallExpression = 153, >CallExpression : SyntaxKind - NewExpression = 152, + NewExpression = 154, >NewExpression : SyntaxKind - TaggedTemplateExpression = 153, + TaggedTemplateExpression = 155, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 154, + TypeAssertionExpression = 156, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 155, + ParenthesizedExpression = 157, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 156, + FunctionExpression = 158, >FunctionExpression : SyntaxKind - ArrowFunction = 157, + ArrowFunction = 159, >ArrowFunction : SyntaxKind - DeleteExpression = 158, + DeleteExpression = 160, >DeleteExpression : SyntaxKind - TypeOfExpression = 159, + TypeOfExpression = 161, >TypeOfExpression : SyntaxKind - VoidExpression = 160, + VoidExpression = 162, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 161, + PrefixUnaryExpression = 163, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 162, + PostfixUnaryExpression = 164, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 163, + BinaryExpression = 165, >BinaryExpression : SyntaxKind - ConditionalExpression = 164, + ConditionalExpression = 166, >ConditionalExpression : SyntaxKind - TemplateExpression = 165, + TemplateExpression = 167, >TemplateExpression : SyntaxKind - YieldExpression = 166, + YieldExpression = 168, >YieldExpression : SyntaxKind - SpreadElementExpression = 167, + SpreadElementExpression = 169, >SpreadElementExpression : SyntaxKind - OmittedExpression = 168, + OmittedExpression = 170, >OmittedExpression : SyntaxKind - TemplateSpan = 169, + TemplateSpan = 171, >TemplateSpan : SyntaxKind - Block = 170, + Block = 172, >Block : SyntaxKind - VariableStatement = 171, + VariableStatement = 173, >VariableStatement : SyntaxKind - EmptyStatement = 172, + EmptyStatement = 174, >EmptyStatement : SyntaxKind - ExpressionStatement = 173, + ExpressionStatement = 175, >ExpressionStatement : SyntaxKind - IfStatement = 174, + IfStatement = 176, >IfStatement : SyntaxKind - DoStatement = 175, + DoStatement = 177, >DoStatement : SyntaxKind - WhileStatement = 176, + WhileStatement = 178, >WhileStatement : SyntaxKind - ForStatement = 177, + ForStatement = 179, >ForStatement : SyntaxKind - ForInStatement = 178, + ForInStatement = 180, >ForInStatement : SyntaxKind - ContinueStatement = 179, + ContinueStatement = 181, >ContinueStatement : SyntaxKind - BreakStatement = 180, + BreakStatement = 182, >BreakStatement : SyntaxKind - ReturnStatement = 181, + ReturnStatement = 183, >ReturnStatement : SyntaxKind - WithStatement = 182, + WithStatement = 184, >WithStatement : SyntaxKind - SwitchStatement = 183, + SwitchStatement = 185, >SwitchStatement : SyntaxKind - LabeledStatement = 184, + LabeledStatement = 186, >LabeledStatement : SyntaxKind - ThrowStatement = 185, + ThrowStatement = 187, >ThrowStatement : SyntaxKind - TryStatement = 186, + TryStatement = 188, >TryStatement : SyntaxKind - DebuggerStatement = 187, + DebuggerStatement = 189, >DebuggerStatement : SyntaxKind - VariableDeclaration = 188, + VariableDeclaration = 190, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 189, + VariableDeclarationList = 191, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 190, + FunctionDeclaration = 192, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 191, + ClassDeclaration = 193, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 192, + InterfaceDeclaration = 194, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 193, + TypeAliasDeclaration = 195, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 194, + EnumDeclaration = 196, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 195, + ModuleDeclaration = 197, >ModuleDeclaration : SyntaxKind - ModuleBlock = 196, + ModuleBlock = 198, >ModuleBlock : SyntaxKind - ImportDeclaration = 197, ->ImportDeclaration : SyntaxKind + ImportEqualsDeclaration = 199, +>ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 198, + ExportAssignment = 200, >ExportAssignment : SyntaxKind - ExternalModuleReference = 199, + ImportDeclaration = 201, +>ImportDeclaration : SyntaxKind + + ImportClause = 202, +>ImportClause : SyntaxKind + + NamespaceImport = 203, +>NamespaceImport : SyntaxKind + + NamedImports = 204, +>NamedImports : SyntaxKind + + ImportSpecifier = 205, +>ImportSpecifier : SyntaxKind + + ExternalModuleReference = 206, >ExternalModuleReference : SyntaxKind - CaseClause = 200, + CaseClause = 207, >CaseClause : SyntaxKind - DefaultClause = 201, + DefaultClause = 208, >DefaultClause : SyntaxKind - HeritageClause = 202, + HeritageClause = 209, >HeritageClause : SyntaxKind - CatchClause = 203, + CatchClause = 210, >CatchClause : SyntaxKind - PropertyAssignment = 204, + PropertyAssignment = 211, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 205, + ShorthandPropertyAssignment = 212, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 206, + EnumMember = 213, >EnumMember : SyntaxKind - SourceFile = 207, + SourceFile = 214, >SourceFile : SyntaxKind - SyntaxList = 208, + SyntaxList = 215, >SyntaxList : SyntaxKind - Count = 209, + Count = 216, >Count : SyntaxKind FirstAssignment = 52, @@ -1107,19 +1128,19 @@ declare module "typescript" { FirstKeyword = 65, >FirstKeyword : SyntaxKind - LastKeyword = 120, + LastKeyword = 122, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 101, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 109, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 135, + FirstTypeNode = 137, >FirstTypeNode : SyntaxKind - LastTypeNode = 143, + LastTypeNode = 145, >LastTypeNode : SyntaxKind FirstPunctuation = 14, @@ -1131,7 +1152,7 @@ declare module "typescript" { FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 120, + LastToken = 122, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1158,7 +1179,7 @@ declare module "typescript" { LastBinaryOperator = 63, >LastBinaryOperator : SyntaxKind - FirstNode = 121, + FirstNode = 123, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -2400,8 +2421,8 @@ declare module "typescript" { >NodeArray : NodeArray >ModuleElement : ModuleElement } - interface ImportDeclaration extends Declaration, ModuleElement { ->ImportDeclaration : ImportDeclaration + interface ImportEqualsDeclaration extends Declaration, ModuleElement { +>ImportEqualsDeclaration : ImportEqualsDeclaration >Declaration : Declaration >ModuleElement : ModuleElement @@ -2421,6 +2442,61 @@ declare module "typescript" { expression?: Expression; >expression : Expression >Expression : Expression + } + interface ImportDeclaration extends Statement, ModuleElement { +>ImportDeclaration : ImportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + importClause?: ImportClause; +>importClause : ImportClause +>ImportClause : ImportClause + + moduleSpecifier: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface ImportClause extends Declaration { +>ImportClause : ImportClause +>Declaration : Declaration + + name?: Identifier; +>name : Identifier +>Identifier : Identifier + + namedBindings?: NamespaceImport | NamedImports; +>namedBindings : NamespaceImport | NamedImports +>NamespaceImport : NamespaceImport +>NamedImports : NamedImports + } + interface NamespaceImport extends Declaration { +>NamespaceImport : NamespaceImport +>Declaration : Declaration + + name: Identifier; +>name : Identifier +>Identifier : Identifier + } + interface NamedImports extends Node { +>NamedImports : NamedImports +>Node : Node + + elements: NodeArray; +>elements : NodeArray +>NodeArray : NodeArray +>ImportSpecifier : ImportSpecifier + } + interface ImportSpecifier extends Declaration { +>ImportSpecifier : ImportSpecifier +>Declaration : Declaration + + propertyName?: Identifier; +>propertyName : Identifier +>Identifier : Identifier + + name: Identifier; +>name : Identifier +>Identifier : Identifier } interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment @@ -3054,9 +3130,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportDeclaration[]; ->aliasesToMakeVisible : ImportDeclaration[] ->ImportDeclaration : ImportDeclaration + aliasesToMakeVisible?: ImportEqualsDeclaration[]; +>aliasesToMakeVisible : ImportEqualsDeclaration[] +>ImportEqualsDeclaration : ImportEqualsDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3091,15 +3167,15 @@ declare module "typescript" { >node : SourceFile >SourceFile : SourceFile - isReferencedImportDeclaration(node: ImportDeclaration): boolean; ->isReferencedImportDeclaration : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isReferencedImportDeclaration(node: Node): boolean; +>isReferencedImportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node - isTopLevelValueImportWithEntityName(node: ImportDeclaration): boolean; ->isTopLevelValueImportWithEntityName : (node: ImportDeclaration) => boolean ->node : ImportDeclaration ->ImportDeclaration : ImportDeclaration + isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; +>isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean +>node : ImportEqualsDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration getNodeCheckFlags(node: Node): NodeCheckFlags; >getNodeCheckFlags : (node: Node) => NodeCheckFlags diff --git a/tests/baselines/reference/es6ImportDefaultBinding.types b/tests/baselines/reference/es6ImportDefaultBinding.types index 262ce5966b338..bfc01b1f8a7e7 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.types +++ b/tests/baselines/reference/es6ImportDefaultBinding.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportDefaultBinding_1.ts === import defaultBinding from "es6ImportDefaultBinding_0"; -No type information for this code. \ No newline at end of file +>defaultBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt new file mode 100644 index 0000000000000..9a34b2c47c8ea --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. + + +==== 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 (6 errors) ==== + import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types deleted file mode 100644 index 35dacc7d93a48..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts === - -export var a = 10; ->a : number - -export var x = a; ->x : number ->a : number - -export var m = a; ->m : number ->a : number - -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts === -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -No type information for this code.import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -No type information for this code.import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -No type information for this code.import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -No type information for this code.import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -No type information for this code.import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt new file mode 100644 index 0000000000000..49c930272fc13 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (6 errors) ==== + import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. + import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types deleted file mode 100644 index a98cca1edcf27..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.types +++ /dev/null @@ -1,21 +0,0 @@ -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts === - -export var a = 10; ->a : number - -export var x = a; ->x : number ->a : number - -export var m = a; ->m : number ->a : number - -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts === -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -No type information for this code.import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -No type information for this code.import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -No type information for this code.import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -No type information for this code.import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -No type information for this code.import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types index 9f9db16a6f41a..6726447b3c3e9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types @@ -5,4 +5,6 @@ export var a = 10; === tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts === import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; -No type information for this code. \ No newline at end of file +>defaultBinding : typeof defaultBinding +>nameSpaceBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types index 841bb9d68b565..65e3921865bcc 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types @@ -5,4 +5,6 @@ export var a = 10; === tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts === import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; -No type information for this code. \ No newline at end of file +>defaultBinding : typeof defaultBinding +>nameSpaceBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types index 1f3c4141f5b38..3350030cd1dc1 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.types +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts === import defaultBinding from "es6ImportDefaultBindingInEs5_0"; -No type information for this code. \ No newline at end of file +>defaultBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.types b/tests/baselines/reference/es6ImportNameSpaceImport.types index d7cd562dc2789..1e09de42ec6a2 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.types +++ b/tests/baselines/reference/es6ImportNameSpaceImport.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportNameSpaceImport_1.ts === import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; -No type information for this code. \ No newline at end of file +>nameSpaceBinding : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types index 7818a4568e002..cb7b669eea1c0 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportNameSpaceImportInEs5_1.ts === import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; -No type information for this code. \ No newline at end of file +>nameSpaceBinding : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types index 23fc73ef6e9a6..e86955b3c96fb 100644 --- a/tests/baselines/reference/es6ImportNamedImport.types +++ b/tests/baselines/reference/es6ImportNamedImport.types @@ -19,11 +19,32 @@ export var x1 = 10; === tests/cases/compiler/es6ImportNamedImport_1.ts === import { } from "es6ImportNamedImport_0"; -No type information for this code.import { a } from "es6ImportNamedImport_0"; -No type information for this code.import { a as b } from "es6ImportNamedImport_0"; -No type information for this code.import { x, a as y } from "es6ImportNamedImport_0"; -No type information for this code.import { x as z, } from "es6ImportNamedImport_0"; -No type information for this code.import { m, } from "es6ImportNamedImport_0"; -No type information for this code.import { a1, x1 } from "es6ImportNamedImport_0"; -No type information for this code.import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; -No type information for this code. \ No newline at end of file +import { a } from "es6ImportNamedImport_0"; +>a : number + +import { a as b } from "es6ImportNamedImport_0"; +>a : unknown +>b : number + +import { x, a as y } from "es6ImportNamedImport_0"; +>x : number +>a : unknown +>y : number + +import { x as z, } from "es6ImportNamedImport_0"; +>x : unknown +>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 : unknown +>a11 : number +>x1 : unknown +>x11 : number + diff --git a/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt index 7d0570aa71613..d57a163597a88 100644 --- a/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt @@ -1,18 +1,33 @@ +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(2,10): error TS2300: Duplicate identifier 'yield'. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(3,10): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(3,10): error TS2300: Duplicate identifier 'default'. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(4,19): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(4,19): error TS2300: Duplicate identifier 'default'. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(5,21): error TS2300: Duplicate identifier 'yield'. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(6,21): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(6,21): error TS2300: Duplicate identifier 'default'. -==== tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts (3 errors) ==== +==== tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts (8 errors) ==== import { yield } from "somemodule"; // Allowed + ~~~~~ +!!! error TS2300: Duplicate identifier 'yield'. import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier ~~~~~~~ !!! error TS1003: Identifier expected. + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. import { yield as default } from "somemodule"; // error to use default as binding name ~~~~~~~ !!! error TS1003: Identifier expected. + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. import { default as yield } from "somemodule"; // no error + ~~~~~ +!!! error TS2300: Duplicate identifier 'yield'. import { default as default } from "somemodule"; // default as is ok, error of default binding name ~~~~~~~ -!!! error TS1003: Identifier expected. \ No newline at end of file +!!! error TS1003: Identifier expected. + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.js b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.js new file mode 100644 index 0000000000000..8db7fcd6f9c57 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.js @@ -0,0 +1,9 @@ +//// [es6ImportNamedImportIdentifiersParsing.ts] + +import { yield } from "somemodule"; // Allowed +import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier +import { yield as default } from "somemodule"; // error to use default as binding name +import { default as yield } from "somemodule"; // no error +import { default as default } from "somemodule"; // default as is ok, error of default binding name + +//// [es6ImportNamedImportIdentifiersParsing.js] diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types index 7fecc149aa285..4f96b8a4dfad4 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.types +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -19,11 +19,32 @@ export var x1 = 10; === tests/cases/compiler/es6ImportNamedImportInEs5_1.ts === import { } from "es6ImportNamedImportInEs5_0"; -No type information for this code.import { a } from "es6ImportNamedImportInEs5_0"; -No type information for this code.import { a as b } from "es6ImportNamedImportInEs5_0"; -No type information for this code.import { x, a as y } from "es6ImportNamedImportInEs5_0"; -No type information for this code.import { x as z, } from "es6ImportNamedImportInEs5_0"; -No type information for this code.import { m, } from "es6ImportNamedImportInEs5_0"; -No type information for this code.import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -No type information for this code.import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; -No type information for this code. \ No newline at end of file +import { a } from "es6ImportNamedImportInEs5_0"; +>a : number + +import { a as b } from "es6ImportNamedImportInEs5_0"; +>a : unknown +>b : number + +import { x, a as y } from "es6ImportNamedImportInEs5_0"; +>x : number +>a : unknown +>y : number + +import { x as z, } from "es6ImportNamedImportInEs5_0"; +>x : unknown +>z : number + +import { m, } from "es6ImportNamedImportInEs5_0"; +>m : number + +import { a1, x1 } from "es6ImportNamedImportInEs5_0"; +>a1 : number +>x1 : number + +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +>a1 : unknown +>a11 : number +>x1 : unknown +>x11 : number + diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt deleted file mode 100644 index fd5a077f64867..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt +++ /dev/null @@ -1,52 +0,0 @@ -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1003: Identifier expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: Expression expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: '{' expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,1): error TS1128: Declaration or statement expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,8): error TS1128: Declaration or statement expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,12): error TS2304: Cannot find name 'a'. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,16): error TS2304: Cannot find name 'from'. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,21): error TS1005: ';' expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,13): error TS1005: 'from' expected. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,15): error TS2304: Cannot find name 'from'. -tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: ';' expected. - - -==== tests/cases/compiler/es6ImportNamedImportParsingError_0.ts (0 errors) ==== - - export var a = 10; - export var x = a; - export var m = a; - -==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (13 errors) ==== - import { * } from "es6ImportNamedImportParsingError_0"; - ~ -!!! error TS1003: Identifier expected. - ~ -!!! error TS1109: Expression expected. - ~~~~ -!!! error TS2304: Cannot find name 'from'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1005: ';' expected. - import defaultBinding, from "es6ImportNamedImportParsingError_0"; - ~~~~ -!!! error TS1005: '{' expected. - import , { a } from "es6ImportNamedImportParsingError_0"; - ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~ -!!! error TS1128: Declaration or statement expected. - ~ -!!! error TS2304: Cannot find name 'a'. - ~~~~ -!!! error TS2304: Cannot find name 'from'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1005: ';' expected. - import { a }, from "es6ImportNamedImportParsingError_0"; - ~ -!!! error TS1005: 'from' expected. - ~~~~ -!!! error TS2304: Cannot find name 'from'. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportParseErrors.js b/tests/baselines/reference/es6ImportParseErrors.js new file mode 100644 index 0000000000000..a42d65fbc9dcc --- /dev/null +++ b/tests/baselines/reference/es6ImportParseErrors.js @@ -0,0 +1,6 @@ +//// [es6ImportParseErrors.ts] + +import 10; + +//// [es6ImportParseErrors.js] +10; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index aa5e25bcd6ff4..43d21885c2701 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -10,3 +10,4 @@ import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.js] exports.a = 10; //// [es6ImportWithoutFromClause_1.js] +require("es6ImportWithoutFromClause_0"); diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index 3782987c2ffa6..f6610ac5ad295 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -10,3 +10,4 @@ import "es6ImportWithoutFromClauseInEs5_0"; //// [es6ImportWithoutFromClauseInEs5_0.js] exports.a = 10; //// [es6ImportWithoutFromClauseInEs5_1.js] +require("es6ImportWithoutFromClauseInEs5_0"); From c8cc19544e31d21b8ed4d8f0b340a3c22802ace4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 8 Feb 2015 12:13:56 -0800 Subject: [PATCH 25/46] AMD emit for ES6 import declarations --- src/compiler/checker.ts | 16 +-- src/compiler/emitter.ts | 239 +++++++++++++++++++--------------------- 2 files changed, 120 insertions(+), 135 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c3eae1732a8a1..296d18e891a60 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4896,15 +4896,17 @@ module ts { /*Transitively mark all linked imports as referenced*/ function markLinkedImportsAsReferenced(node: ImportEqualsDeclaration): void { - var nodeLinks = getNodeLinks(node); - while (nodeLinks.importOnRightSide) { - var rightSide = nodeLinks.importOnRightSide; - nodeLinks.importOnRightSide = undefined; + if (node) { + var nodeLinks = getNodeLinks(node); + while (nodeLinks.importOnRightSide) { + var rightSide = nodeLinks.importOnRightSide; + nodeLinks.importOnRightSide = undefined; - getSymbolLinks(rightSide).referenced = true; - Debug.assert((rightSide.flags & SymbolFlags.Import) !== 0); + getSymbolLinks(rightSide).referenced = true; + Debug.assert((rightSide.flags & SymbolFlags.Import) !== 0); - nodeLinks = getNodeLinks(getDeclarationOfKind(rightSide, SyntaxKind.ImportEqualsDeclaration)) + nodeLinks = getNodeLinks(getDeclarationOfKind(rightSide, SyntaxKind.ImportEqualsDeclaration)) + } } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index eccfc8df9db1b..0964e78e77010 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -17,8 +17,10 @@ module ts { } interface ExternalImportInfo { - declaration: ImportDeclaration | ImportEqualsDeclaration; - paramName: Identifier; // Callback parameter name for AMD module + importNode: ImportDeclaration | ImportEqualsDeclaration; + declarationNode?: ImportEqualsDeclaration | ImportClause | NamespaceImport; + namedImports?: NamedImports; + tempName?: Identifier; // Temporary name for module instance } interface SymbolAccessibilityDiagnostic { @@ -1748,8 +1750,8 @@ module ts { lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { // Encode the last recordedSpan before assigning new encodeLastRecordedSourceMapSpan(); @@ -2000,7 +2002,7 @@ module ts { break; } // _a .. _h, _j ... _z, _0, _1, ... - name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0: 1) + CharacterCodes.a) : tempCount - 25); + name = "_" + (tempCount < 25 ? String.fromCharCode(tempCount + (tempCount < 8 ? 0 : 1) + CharacterCodes.a) : tempCount - 25); tempCount++; } var result = createNode(SyntaxKind.Identifier); @@ -2128,7 +2130,7 @@ module ts { function emitLiteral(node: LiteralExpression) { var text = languageVersion < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : - node.text; + node.text; if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } @@ -2465,7 +2467,7 @@ module ts { i++; } write("["); - emitList(elements, pos, i - pos, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0, + emitList(elements, pos, i - pos, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, /*trailingComma*/ elements.hasTrailingComma); write("]"); pos = i; @@ -2889,7 +2891,7 @@ module ts { function isOnSameLine(node1: Node, node2: Node) { return getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node1.pos)) === - getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos)); + getLineOfLocalPosition(currentSourceFile, skipTrivia(currentSourceFile.text, node2.pos)); } function emitCaseOrDefaultClause(node: CaseOrDefaultClause) { @@ -3106,7 +3108,7 @@ module ts { function emitDestructuringAssignment(target: Expression, value: Expression) { if (target.kind === SyntaxKind.BinaryExpression && (target).operator === SyntaxKind.EqualsToken) { - value = createDefaultValueCheck(value,(target).right); + value = createDefaultValueCheck(value, (target).right); target = (target).left; } if (target.kind === SyntaxKind.ObjectLiteralExpression) { @@ -3933,150 +3935,131 @@ module ts { } } - function emitExportedImportAssignment(node: Declaration) { - if (node.flags & NodeFlags.Export) { - emitModuleMemberName(node); - write(" = "); - emit(node.name); - write(";"); - } - } - - function emitImportDeclarationAMD(node: ImportDeclaration) { - var importClause = node.importClause; - if (importClause) { - if (importClause.name) { - emitExportedImportAssignment(importClause); - } - else if (importClause.namedBindings) { - if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - emitExportedImportAssignment(importClause.namedBindings); + function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { + var info = getExternalImportInfo(node); + if (info) { + var declarationNode = info.declarationNode; + var namedImports = info.namedImports; + if (compilerOptions.module !== ModuleKind.AMD) { + emitLeadingComments(node); + emitStart(node); + var moduleName = getImportedModuleName(info.importNode); + if (declarationNode) { + if (!(declarationNode.flags & NodeFlags.Export)) write("var "); + emitModuleMemberName(declarationNode); + write(" = "); + emitRequire(moduleName); + } + else if (namedImports) { + write("var "); + emit(info.tempName); + write(" = "); + emitRequire(moduleName); + emitNamedImportAssignments(namedImports, info.tempName); } else { + emitRequire(moduleName); } + emitEnd(node); + emitTrailingComments(node); } - } - } - - function emitImportDeclaration(node: ImportDeclaration) { - var importClause = node.importClause; - if (!importClause || resolver.isReferencedImportDeclaration(node)) { - emitLeadingComments(node); - emitStart(node); - var moduleName = getImportedModuleName(node); - if (importClause) { - if (importClause.name) { - emitImportAssignment(importClause, moduleName); - } - else if (importClause.namedBindings) { - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - emitImportAssignment(importClause.namedBindings, moduleName); - } - else { - var temp = createTempVariable(node); - write("var "); - emit(temp); + else { + if (declarationNode) { + if (declarationNode.flags & NodeFlags.Export) { + emitModuleMemberName(declarationNode); write(" = "); - emitRequire(moduleName); - emitNamedImportAssignments(importClause.namedBindings, temp); + emit(declarationNode.name); + write(";"); } } + else if (namedImports) { + emitNamedImportAssignments(namedImports, info.tempName); + } } - else { - emitRequire(moduleName); - } - emitEnd(node); - emitTrailingComments(node); } } function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - var emitImportDeclaration = resolver.isReferencedImportDeclaration(node); - - if (!emitImportDeclaration) { - // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when - // - current file is not external module - // - import declaration is top level and target is value imported by entity name - emitImportDeclaration = !isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node); + if (isExternalModuleImportEqualsDeclaration(node)) { + emitImportDeclaration(node); + return; } - - if (emitImportDeclaration) { - if (isExternalModuleImportEqualsDeclaration(node) && node.parent.kind === SyntaxKind.SourceFile && compilerOptions.module === ModuleKind.AMD) { - if (node.flags & NodeFlags.Export) { - writeLine(); - emitLeadingComments(node); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emit(node.name); - write(";"); - emitEnd(node); - emitTrailingComments(node); - } - } - else { - writeLine(); - emitLeadingComments(node); - emitStart(node); - if (isInternalModuleImportEqualsDeclaration(node)) { - if (!(node.flags & NodeFlags.Export)) write("var "); - emitModuleMemberName(node); - write(" = "); - emit(node.moduleReference); - write(";"); - } - else { - emitImportAssignment(node, getImportedModuleName(node)); - } - emitEnd(node); - emitTrailingComments(node); - } + // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when + // - current file is not external module + // - import declaration is top level and target is value imported by entity name + if (resolver.isReferencedImportDeclaration(node) || + (!isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { + emitLeadingComments(node); + emitStart(node); + if (!(node.flags & NodeFlags.Export)) write("var "); + emitModuleMemberName(node); + write(" = "); + emit(node.moduleReference); + write(";"); + emitEnd(node); + emitTrailingComments(node); } } - function getExternalImportEqualsDeclarations(node: SourceFile): ImportEqualsDeclaration[] { - var result: ImportEqualsDeclaration[] = []; - forEach(node.statements, statement => { - if (isExternalModuleImportEqualsDeclaration(statement) && resolver.isReferencedImportDeclaration(statement)) { - result.push(statement); - } - }); - return result; - } - - function getExternalImportInfo(node: ImportDeclaration | ImportEqualsDeclaration): ExternalImportInfo { + function createExternalImportInfo(node: Node): ExternalImportInfo { if (node.kind === SyntaxKind.ImportEqualsDeclaration) { - var name = (node).name; + if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { + return { + importNode: node, + declarationNode: node + }; + } } - else { + else if (node.kind === SyntaxKind.ImportDeclaration) { var importClause = (node).importClause; if (importClause) { if (importClause.name) { - var name = importClause.name; + return { + importNode: node, + declarationNode: importClause + }; } - else if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - var name = (importClause.namedBindings).name; - } - else { - var name = createTempVariable(node); + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + return { + importNode: node, + declarationNode: importClause.namedBindings + }; } + return { + importNode: node, + namedImports: importClause.namedBindings + }; + } + return { + importNode: node } } - return { - declaration: node, - paramName: name - }; } - function getExternalImports(sourceFile: SourceFile): ExternalImportInfo[] { - var result: ExternalImportInfo[] = []; + function createExternalImports(sourceFile: SourceFile) { + externalImports = []; forEach(sourceFile.statements, node => { - if ((node.kind === SyntaxKind.ImportDeclaration || isExternalModuleImportEqualsDeclaration(node)) && - resolver.isReferencedImportDeclaration(node)) { - result.push(getExternalImportInfo(node)); + var info = createExternalImportInfo(node); + if (info) { + if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { + if (!info.declarationNode) { + info.tempName = createTempVariable(sourceFile); + } + externalImports.push(info); + } } }); - return result; + } + + function getExternalImportInfo(node: ImportDeclaration | ImportEqualsDeclaration): ExternalImportInfo { + if (externalImports) { + for (var i = 0; i < externalImports.length; i++) { + var info = externalImports[i]; + if (info.importNode === node) { + return info; + } + } + } } function getFirstExportAssignment(sourceFile: SourceFile) { @@ -4088,16 +4071,15 @@ module ts { } function emitAMDModule(node: SourceFile, startIndex: number) { - externalImports = getExternalImports(node); writeLine(); write("define("); if (node.amdModuleName) { write("\"" + node.amdModuleName + "\", "); } write("[\"require\", \"exports\""); - forEach(externalImports, imp => { + forEach(externalImports, info => { write(", "); - var moduleName = getImportedModuleName(imp.declaration); + var moduleName = getImportedModuleName(info.importNode); if (moduleName) { emitLiteral(moduleName); } @@ -4111,9 +4093,9 @@ module ts { write(text); }); write("], function (require, exports"); - forEach(externalImports, imp => { + forEach(externalImports, info => { write(", "); - emit(imp.paramName); + emit(info.declarationNode ? info.declarationNode.name : info.tempName); }); write(") {"); increaseIndent(); @@ -4197,6 +4179,7 @@ module ts { extendsEmitted = true; } if (isExternalModule(node)) { + createExternalImports(node); if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } From e30fc4142ed6bdd0c85ac1ab0f4f6a3cc08f8676 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 8 Feb 2015 12:14:29 -0800 Subject: [PATCH 26/46] Accepting new baselines --- ...s6ImportNamedImportParsingError.errors.txt | 46 +++++++++++++++++++ .../es6ImportNamedImportParsingError.js | 29 ++++++++++++ .../baselines/reference/importInsideModule.js | 1 - .../privacyGloImportParseErrors.errors.txt | 8 +--- .../reference/privacyGloImportParseErrors.js | 2 - .../privacyImportParseErrors.errors.txt | 14 +----- .../reference/privacyImportParseErrors.js | 4 -- .../amd/testGlo.js | 2 - .../node/testGlo.js | 2 - 9 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportParsingError.js diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt new file mode 100644 index 0000000000000..d7776a63b765e --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -0,0 +1,46 @@ +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: Expression expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: '{' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,1): error TS1128: Declaration or statement expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,8): error TS1128: Declaration or statement expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,16): error TS2304: Cannot find name 'from'. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,21): error TS1005: ';' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,13): error TS1005: 'from' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: ';' expected. + + +==== tests/cases/compiler/es6ImportNamedImportParsingError_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + +==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (11 errors) ==== + import { * } from "es6ImportNamedImportParsingError_0"; + ~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1109: Expression expected. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1005: ';' expected. + import defaultBinding, from "es6ImportNamedImportParsingError_0"; + ~~~~ +!!! error TS1005: '{' expected. + import , { a } from "es6ImportNamedImportParsingError_0"; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1005: ';' expected. + import { a }, from "es6ImportNamedImportParsingError_0"; + ~ +!!! error TS1005: 'from' expected. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1005: ';' expected. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js new file mode 100644 index 0000000000000..b1f7f2c295b9f --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/es6ImportNamedImportParsingError.ts] //// + +//// [es6ImportNamedImportParsingError_0.ts] + +export var a = 10; +export var x = a; +export var m = a; + +//// [es6ImportNamedImportParsingError_1.ts] +import { * } from "es6ImportNamedImportParsingError_0"; +import defaultBinding, from "es6ImportNamedImportParsingError_0"; +import , { a } from "es6ImportNamedImportParsingError_0"; +import { a }, from "es6ImportNamedImportParsingError_0"; + +//// [es6ImportNamedImportParsingError_0.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +//// [es6ImportNamedImportParsingError_1.js] +from; +"es6ImportNamedImportParsingError_0"; +{ + a; +} +from; +"es6ImportNamedImportParsingError_0"; +var _a = require(); +var a = _a.a; +"es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/importInsideModule.js b/tests/baselines/reference/importInsideModule.js index b0ba16fa850c2..5151e01f764e1 100644 --- a/tests/baselines/reference/importInsideModule.js +++ b/tests/baselines/reference/importInsideModule.js @@ -12,6 +12,5 @@ export module myModule { //// [importInsideModule_file2.js] var myModule; (function (myModule) { - var foo = require("importInsideModule_file1"); var a = foo.x; })(myModule = exports.myModule || (exports.myModule = {})); diff --git a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt index 2a7c07bfcdbc7..ac19571b8c0d8 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt @@ -7,9 +7,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(69,37): error TS1147: Import tests/cases/compiler/privacyGloImportParseErrors.ts(69,37): error TS2307: Cannot find external module 'm1_M4_private'. tests/cases/compiler/privacyGloImportParseErrors.ts(80,35): error TS4000: Import declaration 'm1_im2_public' is using private name 'm1_M2_private'. tests/cases/compiler/privacyGloImportParseErrors.ts(81,43): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(81,43): error TS2307: Cannot find external module 'm1_M3_public'. tests/cases/compiler/privacyGloImportParseErrors.ts(82,43): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyGloImportParseErrors.ts(82,43): error TS2307: Cannot find external module 'm1_M4_private'. tests/cases/compiler/privacyGloImportParseErrors.ts(121,38): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(125,45): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. @@ -20,7 +18,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(146,25): error TS1147: Impor tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Import declarations in an internal module cannot reference an external module. -==== tests/cases/compiler/privacyGloImportParseErrors.ts (20 errors) ==== +==== tests/cases/compiler/privacyGloImportParseErrors.ts (18 errors) ==== module m1 { export module m1_M1_public { export class c1 { @@ -120,13 +118,9 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Impor export import m1_im3_public = require("m1_M3_public"); ~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. - ~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find external module 'm1_M3_public'. export import m1_im4_public = require("m1_M4_private"); ~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. - ~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find external module 'm1_M4_private'. } module glo_M1_public { diff --git a/tests/baselines/reference/privacyGloImportParseErrors.js b/tests/baselines/reference/privacyGloImportParseErrors.js index 6812b46888258..27e24a1cf38db 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.js +++ b/tests/baselines/reference/privacyGloImportParseErrors.js @@ -203,7 +203,6 @@ var m1; var m1_im2_private_v2_private = new m1_im2_private.c1(); var m1_im2_private_v3_private = m1_im2_private.f1; var m1_im2_private_v4_private = m1_im2_private.f1(); - var m1_im3_private = require("m1_M3_public"); m1.m1_im3_private_v1_public = m1_im3_private.c1; m1.m1_im3_private_v2_public = new m1_im3_private.c1(); m1.m1_im3_private_v3_public = m1_im3_private.f1; @@ -212,7 +211,6 @@ var m1; var m1_im3_private_v2_private = new m1_im3_private.c1(); var m1_im3_private_v3_private = m1_im3_private.f1; var m1_im3_private_v4_private = m1_im3_private.f1(); - var m1_im4_private = require("m1_M4_private"); m1.m1_im4_private_v1_public = m1_im4_private.c1; m1.m1_im4_private_v2_public = new m1_im4_private.c1(); m1.m1_im4_private_v3_public = m1_im4_private.f1; diff --git a/tests/baselines/reference/privacyImportParseErrors.errors.txt b/tests/baselines/reference/privacyImportParseErrors.errors.txt index ca2734fe126ff..a81bfbe738bc9 100644 --- a/tests/baselines/reference/privacyImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyImportParseErrors.errors.txt @@ -5,9 +5,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS2307: Cannot fi tests/cases/compiler/privacyImportParseErrors.ts(69,37): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(69,37): error TS2307: Cannot find external module 'm1_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(81,43): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(81,43): error TS2307: Cannot find external module 'm1_M3_public'. tests/cases/compiler/privacyImportParseErrors.ts(82,43): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(82,43): error TS2307: Cannot find external module 'm1_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(106,27): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(114,20): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(143,37): error TS1147: Import declarations in an internal module cannot reference an external module. @@ -15,9 +13,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(143,37): error TS2307: Cannot f tests/cases/compiler/privacyImportParseErrors.ts(153,37): error TS1147: Import declarations in an internal module cannot reference an external module. tests/cases/compiler/privacyImportParseErrors.ts(153,37): error TS2307: Cannot find external module 'm2_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(166,43): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(166,43): error TS2307: Cannot find external module 'm2_M3_public'. tests/cases/compiler/privacyImportParseErrors.ts(167,43): error TS1147: Import declarations in an internal module cannot reference an external module. -tests/cases/compiler/privacyImportParseErrors.ts(167,43): error TS2307: Cannot find external module 'm2_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(180,23): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(198,23): error TS2435: Ambient external modules cannot be nested in other modules. tests/cases/compiler/privacyImportParseErrors.ts(218,34): error TS2307: Cannot find external module 'glo_M2_public'. @@ -53,7 +49,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(350,25): error TS1147: Import d tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import declarations in an internal module cannot reference an external module. -==== tests/cases/compiler/privacyImportParseErrors.ts (53 errors) ==== +==== tests/cases/compiler/privacyImportParseErrors.ts (49 errors) ==== export module m1 { export module m1_M1_public { export class c1 { @@ -149,13 +145,9 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d export import m1_im3_public = require("m1_M3_public"); ~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. - ~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find external module 'm1_M3_public'. export import m1_im4_public = require("m1_M4_private"); ~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. - ~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find external module 'm1_M4_private'. } module m2 { @@ -254,13 +246,9 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d export import m1_im3_public = require("m2_M3_public"); ~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. - ~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find external module 'm2_M3_public'. export import m1_im4_public = require("m2_M4_private"); ~~~~~~~~~~~~~~~ !!! error TS1147: Import declarations in an internal module cannot reference an external module. - ~~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find external module 'm2_M4_private'. } export module glo_M1_public { diff --git a/tests/baselines/reference/privacyImportParseErrors.js b/tests/baselines/reference/privacyImportParseErrors.js index d32c0255f786a..dd2a0cfe50b62 100644 --- a/tests/baselines/reference/privacyImportParseErrors.js +++ b/tests/baselines/reference/privacyImportParseErrors.js @@ -407,7 +407,6 @@ var m1; var m1_im2_private_v2_private = new m1_im2_private.c1(); var m1_im2_private_v3_private = m1_im2_private.f1; var m1_im2_private_v4_private = m1_im2_private.f1(); - var m1_im3_private = require("m1_M3_public"); m1.m1_im3_private_v1_public = m1_im3_private.c1; m1.m1_im3_private_v2_public = new m1_im3_private.c1(); m1.m1_im3_private_v3_public = m1_im3_private.f1; @@ -416,7 +415,6 @@ var m1; var m1_im3_private_v2_private = new m1_im3_private.c1(); var m1_im3_private_v3_private = m1_im3_private.f1; var m1_im3_private_v4_private = m1_im3_private.f1(); - var m1_im4_private = require("m1_M4_private"); m1.m1_im4_private_v1_public = m1_im4_private.c1; m1.m1_im4_private_v2_public = new m1_im4_private.c1(); m1.m1_im4_private_v3_public = m1_im4_private.f1; @@ -478,7 +476,6 @@ var m2; var m1_im2_private_v2_private = new m1_im2_private.c1(); var m1_im2_private_v3_private = m1_im2_private.f1; var m1_im2_private_v4_private = m1_im2_private.f1(); - var m1_im3_private = require("m2_M3_public"); m2.m1_im3_private_v1_public = m1_im3_private.c1; m2.m1_im3_private_v2_public = new m1_im3_private.c1(); m2.m1_im3_private_v3_public = m1_im3_private.f1; @@ -487,7 +484,6 @@ var m2; var m1_im3_private_v2_private = new m1_im3_private.c1(); var m1_im3_private_v3_private = m1_im3_private.f1; var m1_im3_private_v4_private = m1_im3_private.f1(); - var m1_im4_private = require("m2_M4_private"); m2.m1_im4_private_v1_public = m1_im4_private.c1; m2.m1_im4_private_v2_public = new m1_im4_private.c1(); m2.m1_im4_private_v3_public = m1_im4_private.f1; diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/testGlo.js b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/testGlo.js index ecbd4af1f59ae..7af6249615c67 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/testGlo.js +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/amd/testGlo.js @@ -6,7 +6,6 @@ var __extends = this.__extends || function (d, b) { }; var m2; (function (m2) { - m2.mExported = require("mExported"); m2.c1 = new m2.mExported.me.class1; function f1() { return new m2.mExported.me.class1(); @@ -33,7 +32,6 @@ var m2; } return class2; })(mExported.me.class1); - var mNonExported = require("mNonExported"); m2.c3 = new mNonExported.mne.class1; function f3() { return new mNonExported.mne.class1(); diff --git a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/testGlo.js b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/testGlo.js index ecbd4af1f59ae..7af6249615c67 100644 --- a/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/testGlo.js +++ b/tests/baselines/reference/project/privacyCheckOnImportedModuleDeclarationsInsideModule/node/testGlo.js @@ -6,7 +6,6 @@ var __extends = this.__extends || function (d, b) { }; var m2; (function (m2) { - m2.mExported = require("mExported"); m2.c1 = new m2.mExported.me.class1; function f1() { return new m2.mExported.me.class1(); @@ -33,7 +32,6 @@ var m2; } return class2; })(mExported.me.class1); - var mNonExported = require("mNonExported"); m2.c3 = new mNonExported.mne.class1; function f3() { return new mNonExported.mne.class1(); From 69d47ef85497fc947c4b4051559e360c03d735e4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 8 Feb 2015 12:15:44 -0800 Subject: [PATCH 27/46] Formatting fixes --- src/compiler/emitter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0964e78e77010..65e749ead2f12 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1750,8 +1750,8 @@ module ts { lastRecordedSourceMapSpan.emittedLine != emittedLine || lastRecordedSourceMapSpan.emittedColumn != emittedColumn || (lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex && - (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || - (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { + (lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line || + (lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) { // Encode the last recordedSpan before assigning new encodeLastRecordedSourceMapSpan(); @@ -2130,7 +2130,7 @@ module ts { function emitLiteral(node: LiteralExpression) { var text = languageVersion < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind) ? getTemplateLiteralAsStringLiteral(node) : node.parent ? getSourceTextOfNodeFromSourceFile(currentSourceFile, node) : - node.text; + node.text; if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } @@ -2467,7 +2467,7 @@ module ts { i++; } write("["); - emitList(elements, pos, i - pos, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, + emitList(elements, pos, i - pos, /*multiLine*/ (node.flags & NodeFlags.MultiLine) !== 0, /*trailingComma*/ elements.hasTrailingComma); write("]"); pos = i; From e47f64c5102dd4ffa32425bd99e9d52f340783c6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 8 Feb 2015 17:33:45 -0800 Subject: [PATCH 28/46] Checking of ES6 import declarations --- src/compiler/checker.ts | 119 +++++++++++------- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 + src/compiler/emitter.ts | 6 +- src/compiler/program.ts | 31 ++--- src/compiler/utilities.ts | 10 +- 6 files changed, 100 insertions(+), 71 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 296d18e891a60..5a01a421cea18 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9336,18 +9336,78 @@ module ts { return node; } - function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { - // Grammar checking - checkGrammarModifiers(node); + function checkExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration): boolean { + var moduleName = getImportedModuleName(node); + if (getFullWidth(moduleName) !== 0 && moduleName.kind !== SyntaxKind.StringLiteral) { + error(moduleName, Diagnostics.String_literal_expected); + return false; + } + var inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; + if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { + error(moduleName, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + return false; + } + if (inAmbientExternalModule && isExternalModuleNameRelative((moduleName).text)) { + // TypeScript 1.0 spec (April 2013): 12.1.6 + // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference + // other external modules only through top - level external module names. + // Relative external module names are not permitted. + error(node, Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); + return false; + } + return true; + } + + function checkImportSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { + var symbol = getSymbolOfNode(node); + var target = resolveImport(symbol); + if (target !== unknownSymbol) { + var excludedMeanings = + (symbol.flags & SymbolFlags.Value ? SymbolFlags.Value : 0) | + (symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) | + (symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0); + if (target.flags & excludedMeanings) { + error(node, Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0, symbolToString(symbol)); + } + } + } + function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); - var symbol = getSymbolOfNode(node); - var target: Symbol; - + checkImportSymbol(node); + } + + function checkImportDeclaration(node: ImportDeclaration) { + if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); + } + if (checkExternalImportDeclaration(node)) { + var importClause = node.importClause; + if (importClause) { + if (importClause.name) { + // TODO: Check that import references an export default instance + checkImportBinding(importClause); + } + if (importClause.namedBindings) { + // TODO: Check that import references an export namespace + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + checkImportBinding(importClause.namedBindings); + } + else { + forEach((importClause.namedBindings).elements, checkImportBinding); + } + } + } + } + } + + function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { + checkGrammarModifiers(node); if (isInternalModuleImportEqualsDeclaration(node)) { - target = resolveImport(symbol); - // Import declaration for an internal module + checkImportBinding(node); + var symbol = getSymbolOfNode(node); + var target = resolveImport(symbol); if (target !== unknownSymbol) { if (target.flags & SymbolFlags.Value) { // Target is a value symbol, check that it is not hidden by a local declaration with the same name and @@ -9366,44 +9426,8 @@ module ts { } } else { - var moduleNameExpr = getExternalModuleImportEqualsDeclarationExpression(node); - if (moduleNameExpr.kind !== SyntaxKind.StringLiteral) { - grammarErrorOnNode(moduleNameExpr, Diagnostics.String_literal_expected); - } - // Import declaration for an external module - if (node.parent.kind === SyntaxKind.SourceFile) { - target = resolveImport(symbol); - } - else if (node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral) { - // TypeScript 1.0 spec (April 2013): 12.1.6 - // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference - // other external modules only through top - level external module names. - // Relative external module names are not permitted. - if (moduleNameExpr.kind === SyntaxKind.StringLiteral) { - if (isExternalModuleNameRelative((moduleNameExpr).text)) { - error(node, Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); - target = unknownSymbol; - } - else { - target = resolveImport(symbol); - } - } - else { - target = unknownSymbol; - } - } - else { - // Parent is an internal module (syntax error is already reported) - target = unknownSymbol; - } - } - if (target !== unknownSymbol) { - var excludedMeanings = - (symbol.flags & SymbolFlags.Value ? SymbolFlags.Value : 0) | - (symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) | - (symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0); - if (target.flags & excludedMeanings) { - error(node, Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0, symbolToString(symbol)); + if (checkExternalImportDeclaration(node)) { + checkImportBinding(node); } } } @@ -9509,6 +9533,8 @@ module ts { return checkEnumDeclaration(node); case SyntaxKind.ModuleDeclaration: return checkModuleDeclaration(node); + case SyntaxKind.ImportDeclaration: + return checkImportDeclaration(node); case SyntaxKind.ImportEqualsDeclaration: return checkImportEqualsDeclaration(node); case SyntaxKind.ExportAssignment: @@ -10347,6 +10373,7 @@ module ts { case SyntaxKind.VariableStatement: case SyntaxKind.FunctionDeclaration: case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.ImportDeclaration: case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.Parameter: break; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 1188d34619132..037ef72f48653 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -147,6 +147,7 @@ module ts { Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." }, A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, + An_import_declaration_cannot_have_modifiers: { code: 1188, category: DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b1a794716a489..af509a7d0dae3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -579,6 +579,10 @@ "category": "Error", "code": 1187 }, + "An import declaration cannot have modifiers.": { + "category": "Error", + "code": 1188 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 65e749ead2f12..1ac305cf05563 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3898,7 +3898,7 @@ module ts { } function emitRequire(moduleName: Expression) { - if (moduleName) { + if (moduleName.kind === SyntaxKind.StringLiteral) { write("require("); emitStart(moduleName); emitLiteral(moduleName); @@ -4080,8 +4080,8 @@ module ts { forEach(externalImports, info => { write(", "); var moduleName = getImportedModuleName(info.importNode); - if (moduleName) { - emitLiteral(moduleName); + if (moduleName.kind === SyntaxKind.StringLiteral) { + emitLiteral(moduleName); } else { write("\"\""); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 24d2b41b8f255..ade6141952aad 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -352,21 +352,22 @@ module ts { function processImportedModules(file: SourceFile, basePath: string) { forEach(file.statements, node => { if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) { - var nameLiteral = getImportedModuleName(node); - var moduleName = nameLiteral && nameLiteral.text; - if (moduleName) { - var searchPath = basePath; - while (true) { - var searchName = normalizePath(combinePaths(searchPath, moduleName)); - if (findModuleSourceFile(searchName + ".ts", nameLiteral) || findModuleSourceFile(searchName + ".d.ts", nameLiteral)) { - break; - } - - var parentPath = getDirectoryPath(searchPath); - if (parentPath === searchPath) { - break; + var moduleNameExpr = getImportedModuleName(node); + if (moduleNameExpr && moduleNameExpr.kind === SyntaxKind.StringLiteral) { + var moduleNameText = (moduleNameExpr).text; + if (moduleNameText) { + var searchPath = basePath; + while (true) { + var searchName = normalizePath(combinePaths(searchPath, moduleNameText)); + if (findModuleSourceFile(searchName + ".ts", moduleNameExpr) || findModuleSourceFile(searchName + ".d.ts", moduleNameExpr)) { + break; + } + var parentPath = getDirectoryPath(searchPath); + if (parentPath === searchPath) { + break; + } + searchPath = parentPath; } - searchPath = parentPath; } } } @@ -397,7 +398,7 @@ module ts { } }); - function findModuleSourceFile(fileName: string, nameLiteral: LiteralExpression) { + function findModuleSourceFile(fileName: string, nameLiteral: Expression) { return findSourceFile(fileName, /* isDefaultLib */ false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 27e959ca0c414..6ce615c486998 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -597,18 +597,14 @@ module ts { return node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind !== SyntaxKind.ExternalModuleReference; } - function extractStringLiteral(node: Expression): StringLiteralExpression { - return node && node.kind === SyntaxKind.StringLiteral ? node : undefined; - } - - export function getImportedModuleName(node: Node): StringLiteralExpression { + export function getImportedModuleName(node: Node): Expression { if (node.kind === SyntaxKind.ImportDeclaration) { - return extractStringLiteral((node).moduleSpecifier); + return (node).moduleSpecifier; } if (node.kind === SyntaxKind.ImportEqualsDeclaration) { var reference = (node).moduleReference; if (reference.kind === SyntaxKind.ExternalModuleReference) { - return extractStringLiteral((reference).expression); + return (reference).expression; } } } From a0755256b9eb3642857026d66ec82a4f502c5fe4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 8 Feb 2015 17:34:39 -0800 Subject: [PATCH 29/46] Accepting new baselines --- ...rtNamedImportIdentifiersParsing.errors.txt | 19 +++++++++++++++++-- ...s6ImportNamedImportParsingError.errors.txt | 8 +++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt index d57a163597a88..bba30908b01b0 100644 --- a/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportIdentifiersParsing.errors.txt @@ -1,33 +1,48 @@ tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(2,10): error TS2300: Duplicate identifier 'yield'. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(2,23): error TS2307: Cannot find external module 'somemodule'. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(3,10): error TS1003: Identifier expected. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(3,10): error TS2300: Duplicate identifier 'default'. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(3,25): error TS2307: Cannot find external module 'somemodule'. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(4,19): error TS1003: Identifier expected. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(4,19): error TS2300: Duplicate identifier 'default'. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(4,34): error TS2307: Cannot find external module 'somemodule'. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(5,21): error TS2300: Duplicate identifier 'yield'. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(5,34): error TS2307: Cannot find external module 'somemodule'. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(6,21): error TS1003: Identifier expected. tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(6,21): error TS2300: Duplicate identifier 'default'. +tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts(6,36): error TS2307: Cannot find external module 'somemodule'. -==== tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts (8 errors) ==== +==== tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts (13 errors) ==== import { yield } from "somemodule"; // Allowed ~~~~~ !!! error TS2300: Duplicate identifier 'yield'. + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find external module 'somemodule'. import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier ~~~~~~~ !!! error TS1003: Identifier expected. ~~~~~~~ !!! error TS2300: Duplicate identifier 'default'. + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find external module 'somemodule'. import { yield as default } from "somemodule"; // error to use default as binding name ~~~~~~~ !!! error TS1003: Identifier expected. ~~~~~~~ !!! error TS2300: Duplicate identifier 'default'. + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find external module 'somemodule'. import { default as yield } from "somemodule"; // no error ~~~~~ !!! error TS2300: Duplicate identifier 'yield'. + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find external module 'somemodule'. import { default as default } from "somemodule"; // default as is ok, error of default binding name ~~~~~~~ !!! error TS1003: Identifier expected. ~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. \ No newline at end of file +!!! error TS2300: Duplicate identifier 'default'. + ~~~~~~~~~~~~ +!!! error TS2307: Cannot find external module 'somemodule'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt index d7776a63b765e..121a18b334c39 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -1,4 +1,5 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1003: Identifier expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1141: String literal expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: Expression expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. @@ -8,6 +9,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,8): error TS1128: D tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,16): error TS2304: Cannot find name 'from'. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,21): error TS1005: ';' expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,13): error TS1005: 'from' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,13): error TS1141: String literal expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: ';' expected. @@ -17,10 +19,12 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (11 errors) ==== +==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (13 errors) ==== import { * } from "es6ImportNamedImportParsingError_0"; ~ !!! error TS1003: Identifier expected. + ~ +!!! error TS1141: String literal expected. ~ !!! error TS1109: Expression expected. ~~~~ @@ -42,5 +46,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: import { a }, from "es6ImportNamedImportParsingError_0"; ~ !!! error TS1005: 'from' expected. + ~~~~~~ +!!! error TS1141: String literal expected. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1005: ';' expected. \ No newline at end of file From acfd205a0c831a81da732cca2c063675d1b75cf4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 9 Feb 2015 10:41:53 -0800 Subject: [PATCH 30/46] Check that default import references a default export symbol --- src/compiler/checker.ts | 42 +++++++++++-------- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++ src/compiler/types.ts | 1 + 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5a01a421cea18..61cf3298fd84d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -454,18 +454,26 @@ module ts { } function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol { - return node.moduleReference.kind === SyntaxKind.ExternalModuleReference ? - resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)) : - getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); + if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) { + var moduleSymbol = resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)); + var exportAssignmentSymbol = moduleSymbol && getResolvedExportAssignmentSymbol(moduleSymbol); + return exportAssignmentSymbol || moduleSymbol; + } + return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); } function getTargetOfImportClause(node: ImportClause): Symbol { - // TODO: Verify that returned symbol originates in "export default" statement - return resolveExternalModuleName(node, (node.parent).moduleSpecifier); + var moduleSymbol = resolveExternalModuleName(node, (node.parent).moduleSpecifier); + if (moduleSymbol) { + var exportAssignmentSymbol = getResolvedExportAssignmentSymbol(moduleSymbol); + if (!exportAssignmentSymbol) { + error(node.name, Diagnostics.External_module_0_has_no_default_export_or_export_assignment, symbolToString(moduleSymbol)); + } + return exportAssignmentSymbol; + } } function getTargetOfNamespaceImport(node: NamespaceImport): Symbol { - // TODO: Verify that returned symbol does not originate in "export default" statement return resolveExternalModuleName(node, (node.parent.parent).moduleSpecifier); } @@ -598,7 +606,7 @@ module ts { if (!isRelative) { var symbol = getSymbol(globals, '"' + moduleName + '"', SymbolFlags.ValueModule); if (symbol) { - return getResolvedExportSymbol(symbol); + return symbol; } } while (true) { @@ -611,7 +619,7 @@ module ts { } if (sourceFile) { if (sourceFile.symbol) { - return getResolvedExportSymbol(sourceFile.symbol); + return sourceFile.symbol; } error(moduleReferenceLiteral, Diagnostics.File_0_is_not_an_external_module, sourceFile.fileName); return; @@ -619,7 +627,7 @@ module ts { error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName); } - function getResolvedExportSymbol(moduleSymbol: Symbol): Symbol { + function getResolvedExportAssignmentSymbol(moduleSymbol: Symbol): Symbol { var symbol = getExportAssignmentSymbol(moduleSymbol); if (symbol) { if (symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)) { @@ -629,18 +637,16 @@ module ts { return resolveImport(symbol); } } - return moduleSymbol; } function getExportAssignmentSymbol(symbol: Symbol): Symbol { checkTypeOfExportAssignmentSymbol(symbol); - var symbolLinks = getSymbolLinks(symbol); - return symbolLinks.exportAssignSymbol === unknownSymbol ? undefined : symbolLinks.exportAssignSymbol; + return getSymbolLinks(symbol).exportAssignSymbol; } function checkTypeOfExportAssignmentSymbol(containerSymbol: Symbol): void { var symbolLinks = getSymbolLinks(containerSymbol); - if (!symbolLinks.exportAssignSymbol) { + if (!symbolLinks.exportAssignChecked) { var exportInformation = collectExportInformationForSourceFileOrModule(containerSymbol); if (exportInformation.exportAssignments.length) { if (exportInformation.exportAssignments.length > 1) { @@ -660,8 +666,9 @@ module ts { var meaning = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace; var exportSymbol = resolveName(node, node.exportName.text, meaning, Diagnostics.Cannot_find_name_0, node.exportName); } + symbolLinks.exportAssignSymbol = exportSymbol || unknownSymbol; } - symbolLinks.exportAssignSymbol = exportSymbol || unknownSymbol; + symbolLinks.exportAssignChecked = true; } } @@ -9284,13 +9291,12 @@ module ts { for (var i = 0, n = statements.length; i < n; i++) { var statement = statements[i]; + // TODO: AndersH: No reason to do a separate pass over the statements for this check, we should + // just fold it into checkExportAssignment. if (statement.kind === SyntaxKind.ExportAssignment) { // Export assignments are not allowed in an internal module grammarErrorOnNode(statement, Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module); } - else if (isExternalModuleImportEqualsDeclaration(statement)) { - grammarErrorOnNode(getExternalModuleImportEqualsDeclarationExpression(statement), Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); - } } } } @@ -10197,7 +10203,7 @@ module ts { function getExportAssignmentName(node: SourceFile): string { var symbol = getExportAssignmentSymbol(getSymbolOfNode(node)); - return symbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol): undefined; + return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol): undefined; } function isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 037ef72f48653..5eaeb3ae78da7 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -148,6 +148,7 @@ module ts { A_rest_element_cannot_have_an_initializer: { code: 1186, category: DiagnosticCategory.Error, key: "A rest element cannot have an initializer." }, A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, An_import_declaration_cannot_have_modifiers: { code: 1188, category: DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." }, + External_module_0_has_no_default_export_or_export_assignment: { code: 1189, category: DiagnosticCategory.Error, key: "External module '{0}' has no default export or export assignment." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index af509a7d0dae3..d58cc0c552dec 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -583,6 +583,10 @@ "category": "Error", "code": 1188 }, + "External module '{0}' has no default export or export assignment.": { + "category": "Error", + "code": 1189 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 404a3a89504d6..d50b4bcf33581 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1280,6 +1280,7 @@ module ts { declaredType?: Type; // Type of class, interface, enum, or type parameter mapper?: TypeMapper; // Type mapper for instantiation alias referenced?: boolean; // True if alias symbol has been referenced as a value + exportAssignChecked?: boolean; // True if export assignment was checked exportAssignSymbol?: Symbol; // Symbol exported from external module unionType?: UnionType; // Containing union type for union property } From 67874b4c9edead2ca7db218cf2b10c6249a84c66 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 9 Feb 2015 11:23:32 -0800 Subject: [PATCH 31/46] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 1 + .../reference/APISample_compile.types | 3 +++ tests/baselines/reference/APISample_linter.js | 1 + .../reference/APISample_linter.types | 3 +++ .../reference/APISample_transform.js | 1 + .../reference/APISample_transform.types | 3 +++ .../baselines/reference/APISample_watcher.js | 1 + .../reference/APISample_watcher.types | 3 +++ .../es6ImportDefaultBinding.errors.txt | 11 ++++++++++ .../reference/es6ImportDefaultBinding.types | 9 --------- ...tBindingFollowedWithNamedImport.errors.txt | 20 ++++++++++++++++++- ...ingFollowedWithNamedImportInEs5.errors.txt | 20 ++++++++++++++++++- ...ingFollowedWithNamespaceBinding.errors.txt | 11 ++++++++++ ...tBindingFollowedWithNamespaceBinding.types | 10 ---------- ...llowedWithNamespaceBindingInEs5.errors.txt | 11 ++++++++++ ...ingFollowedWithNamespaceBindingInEs5.types | 10 ---------- .../es6ImportDefaultBindingInEs5.errors.txt | 11 ++++++++++ .../es6ImportDefaultBindingInEs5.types | 9 --------- ...s6ImportNamedImportParsingError.errors.txt | 5 ++++- 19 files changed, 102 insertions(+), 41 deletions(-) create mode 100644 tests/baselines/reference/es6ImportDefaultBinding.errors.txt delete mode 100644 tests/baselines/reference/es6ImportDefaultBinding.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt delete mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt delete mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt delete mode 100644 tests/baselines/reference/es6ImportDefaultBindingInEs5.types diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 7725563214d05..5c74f2fa688f8 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1001,6 +1001,7 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; + exportAssignChecked?: boolean; exportAssignSymbol?: Symbol; unionType?: UnionType; } diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index ceb647564bc95..aebe5ea695a24 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3235,6 +3235,9 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean + exportAssignChecked?: boolean; +>exportAssignChecked : boolean + exportAssignSymbol?: Symbol; >exportAssignSymbol : Symbol >Symbol : Symbol diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index baaa55c962674..8b40586e88bdb 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1032,6 +1032,7 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; + exportAssignChecked?: boolean; exportAssignSymbol?: Symbol; unionType?: UnionType; } diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 5daa9aca11c78..1bada73385fdd 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3379,6 +3379,9 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean + exportAssignChecked?: boolean; +>exportAssignChecked : boolean + exportAssignSymbol?: Symbol; >exportAssignSymbol : Symbol >Symbol : Symbol diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 8e920c476f4ec..74aba68a76c58 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1033,6 +1033,7 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; + exportAssignChecked?: boolean; exportAssignSymbol?: Symbol; unionType?: UnionType; } diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 142165ab4ec0d..6be348b413155 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3331,6 +3331,9 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean + exportAssignChecked?: boolean; +>exportAssignChecked : boolean + exportAssignSymbol?: Symbol; >exportAssignSymbol : Symbol >Symbol : Symbol diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 5d9055b357c93..79e2ac398029f 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1070,6 +1070,7 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; + exportAssignChecked?: boolean; exportAssignSymbol?: Symbol; unionType?: UnionType; } diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 8f40648be3802..429a63daed814 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3504,6 +3504,9 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean + exportAssignChecked?: boolean; +>exportAssignChecked : boolean + exportAssignSymbol?: Symbol; >exportAssignSymbol : Symbol >Symbol : Symbol diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt new file mode 100644 index 0000000000000..3f69c2d7de9ea --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. + + +==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== + import defaultBinding from "es6ImportDefaultBinding_0"; + ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.types b/tests/baselines/reference/es6ImportDefaultBinding.types deleted file mode 100644 index bfc01b1f8a7e7..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBinding.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/es6ImportDefaultBinding_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportDefaultBinding_1.ts === -import defaultBinding from "es6ImportDefaultBinding_0"; ->defaultBinding : typeof defaultBinding - diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index 9a34b2c47c8ea..5fc8e8f905812 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,8 +1,14 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS1189: 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 TS1189: 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 TS1189: 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 TS1189: 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 TS1189: 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 TS1189: 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'. @@ -12,22 +18,34 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): e export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (6 errors) ==== +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (12 errors) ==== import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. + ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt index 49c930272fc13..dc079cac8f7bf 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt @@ -1,8 +1,14 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS1189: 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 TS1189: 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 TS1189: 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 TS1189: 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 TS1189: 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 TS1189: 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'. @@ -12,22 +18,34 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6, export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (6 errors) ==== +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (12 errors) ==== import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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"; ~~~~~~~~~~~~~~ +!!! error TS1189: 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 diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt new file mode 100644 index 0000000000000..c270b9bdd69b7 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (1 errors) ==== + import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; + ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types deleted file mode 100644 index 6726447b3c3e9..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.types +++ /dev/null @@ -1,10 +0,0 @@ -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts === -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; ->defaultBinding : typeof defaultBinding ->nameSpaceBinding : typeof defaultBinding - diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt new file mode 100644 index 0000000000000..37424bc7bd81a --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts (1 errors) ==== + import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; + ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types deleted file mode 100644 index 65e3921865bcc..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.types +++ /dev/null @@ -1,10 +0,0 @@ -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts === -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; ->defaultBinding : typeof defaultBinding ->nameSpaceBinding : typeof defaultBinding - diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt new file mode 100644 index 0000000000000..34439fa91c1be --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1189: 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 TS1189: 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.types b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types deleted file mode 100644 index 3350030cd1dc1..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts === -import defaultBinding from "es6ImportDefaultBindingInEs5_0"; ->defaultBinding : typeof defaultBinding - diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt index 121a18b334c39..89a82e286b7fc 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -3,6 +3,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,10): error TS1141: tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,12): error TS1109: Expression expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,14): error TS2304: Cannot find name 'from'. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(1,19): error TS1005: ';' expected. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,8): error TS1189: External module '"tests/cases/compiler/es6ImportNamedImportParsingError_0"' has no default export or export assignment. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,24): error TS1005: '{' expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,1): error TS1128: Declaration or statement expected. tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(3,8): error TS1128: Declaration or statement expected. @@ -19,7 +20,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (13 errors) ==== +==== tests/cases/compiler/es6ImportNamedImportParsingError_1.ts (14 errors) ==== import { * } from "es6ImportNamedImportParsingError_0"; ~ !!! error TS1003: Identifier expected. @@ -32,6 +33,8 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1005: ';' expected. import defaultBinding, from "es6ImportNamedImportParsingError_0"; + ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/es6ImportNamedImportParsingError_0"' has no default export or export assignment. ~~~~ !!! error TS1005: '{' expected. import , { a } from "es6ImportNamedImportParsingError_0"; From 3523233ae6e2ef4b6c3b4b2d9507875a4ce3f21c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 10 Feb 2015 14:59:20 -0800 Subject: [PATCH 32/46] Rewrite named imports to reference properties on module instance --- src/compiler/checker.ts | 160 +++++++++++++++++++++++++++++--------- src/compiler/emitter.ts | 62 ++++++--------- src/compiler/types.ts | 7 +- src/compiler/utilities.ts | 6 ++ 4 files changed, 156 insertions(+), 79 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61cf3298fd84d..51ea422ee8b29 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10141,62 +10141,149 @@ module ts { function isUniqueLocalName(name: string, container: Node): boolean { for (var node = container; isNodeDescendentOf(node, container); node = node.nextContainer) { if (node.locals && hasProperty(node.locals, name)) { - var symbolWithRelevantName = node.locals[name]; - if (symbolWithRelevantName.flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) { + // We conservatively include import symbols to cover cases where they're emitted as locals + if (node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue | SymbolFlags.Import)) { return false; } - - // An import can be emitted too, if it is referenced as a value. - // Make sure the name in question does not collide with an import. - if (symbolWithRelevantName.flags & SymbolFlags.Import) { - var importEqualsDeclarationWithRelevantName = getDeclarationOfKind(symbolWithRelevantName, SyntaxKind.ImportEqualsDeclaration); - if (isReferencedImportDeclaration(importEqualsDeclarationWithRelevantName)) { - return false; - } - } } } return true; } - function getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string { - var links = getNodeLinks(container); - if (!links.localModuleName) { - var prefix = ""; - var name = unescapeIdentifier(container.name.text); - while (!isUniqueLocalName(escapeIdentifier(prefix + name), container)) { - prefix += "_"; + function getGeneratedNamesForSourceFile(sourceFile: SourceFile): Map { + var links = getNodeLinks(sourceFile); + var generatedNames = links.generatedNames; + if (!generatedNames) { + generatedNames = links.generatedNames = {}; + generateNames(sourceFile); + } + return generatedNames; + + function generateNames(node: Node) { + switch (node.kind) { + case SyntaxKind.ModuleDeclaration: + generateNameForModuleOrEnum(node); + generateNames((node).body); + break; + case SyntaxKind.EnumDeclaration: + generateNameForModuleOrEnum(node); + break; + case SyntaxKind.ImportDeclaration: + generateNameForImportDeclaration(node); + break; + case SyntaxKind.SourceFile: + case SyntaxKind.ModuleBlock: + forEach((node).statements, generateNames); + break; + } + } + + function isExistingName(name: string) { + return hasProperty(sourceFile.identifiers, name) || hasProperty(generatedNames, name); + } + + function makeUniqueName(baseName: string): string { + // First try '_name' + if (baseName.charCodeAt(0) !== CharacterCodes._) { + var 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 += "_"; + } + var i = 1; + while (true) { + name = baseName + i; + if (!isExistingName(name)) { + return name; + } + i++; } - links.localModuleName = prefix + getTextOfNode(container.name); } - return links.localModuleName; + + function assignGeneratedName(node: Node, name: string) { + generatedNames[name] = name; + getNodeLinks(node).generatedName = unescapeIdentifier(name); + } + + function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) { + if (node.name.kind === SyntaxKind.Identifier) { + var 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 generateNameForImportDeclaration(node: ImportDeclaration) { + if (node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === SyntaxKind.NamedImports) { + var expr = getImportedModuleName(node); + var baseName = expr.kind === SyntaxKind.StringLiteral ? + escapeIdentifier(makeIdentifierFromModuleName((expr).text)) : "module"; + assignGeneratedName(node, makeUniqueName(baseName)); + } + } + } + + function getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration) { + var links = getNodeLinks(node); + if (!links.generatedName) { + getGeneratedNamesForSourceFile(getSourceFile(node)); + } + return links.generatedName; } - function getLocalNameForSymbol(symbol: Symbol, location: Node): string { + function getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string { + return getGeneratedNameForNode(container); + } + + function getLocalNameForImportDeclaration(node: ImportDeclaration): string { + return getGeneratedNameForNode(node); + } + + function getImportNameSubstitution(symbol: Symbol): string { + var declaration = getDeclarationOfImportSymbol(symbol); + if (declaration && declaration.kind === SyntaxKind.ImportSpecifier) { + var moduleName = getGeneratedNameForNode(declaration.parent.parent.parent); + var propertyName = (declaration).propertyName || (declaration).name; + return moduleName + "." + unescapeIdentifier(propertyName.text); + } + } + + function getExportNameSubstitution(symbol: Symbol, location: Node): string { + if (isExternalModuleSymbol(symbol.parent)) { + return "exports." + unescapeIdentifier(symbol.name); + } var node = location; + var containerSymbol = getParentOfSymbol(symbol); while (node) { - if ((node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.EnumDeclaration) && getSymbolOfNode(node) === symbol) { - return getLocalNameOfContainer(node); + if ((node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.EnumDeclaration) && getSymbolOfNode(node) === containerSymbol) { + return getGeneratedNameForNode(node) + "." + unescapeIdentifier(symbol.name); } node = node.parent; } - Debug.fail("getLocalNameForSymbol failed"); } - function getExpressionNamePrefix(node: Identifier): string { + function getExpressionNameSubstitution(node: Identifier): string { var symbol = getNodeLinks(node).resolvedSymbol; if (symbol) { - // In general, we need to prefix an identifier with its parent name if it references - // an exported entity from another module declaration. 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. + // 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); + } + // 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. var exportSymbol = getExportSymbolOfValueSymbolIfExported(symbol); if (symbol !== exportSymbol && !(exportSymbol.flags & SymbolFlags.ExportHasLocal)) { - symbol = exportSymbol; + return getExportNameSubstitution(exportSymbol, node.parent); } - if (symbol.parent) { - return isExternalModuleSymbol(symbol.parent) ? "exports" : getLocalNameForSymbol(getParentOfSymbol(symbol), node.parent); + // Named imports from ES6 import declarations are rewritten + if (symbol.flags & SymbolFlags.Import) { + return getImportNameSubstitution(symbol); } } } @@ -10302,13 +10389,14 @@ module ts { } function isUnknownIdentifier(location: Node, name: string): boolean { - return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && + !hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } function createResolver(): EmitResolver { return { - getLocalNameOfContainer, - getExpressionNamePrefix, + getGeneratedNameForNode, + getExpressionNameSubstitution, getExportAssignmentName, isReferencedImportDeclaration, getNodeCheckFlags, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1ac305cf05563..84b033ea94b51 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -20,7 +20,6 @@ module ts { importNode: ImportDeclaration | ImportEqualsDeclaration; declarationNode?: ImportEqualsDeclaration | ImportClause | NamespaceImport; namedImports?: NamedImports; - tempName?: Identifier; // Temporary name for module instance } interface SymbolAccessibilityDiagnostic { @@ -2338,12 +2337,13 @@ module ts { } function emitExpressionIdentifier(node: Identifier) { - var prefix = resolver.getExpressionNamePrefix(node); - if (prefix) { - write(prefix); - write("."); + var substitution = resolver.getExpressionNameSubstitution(node); + if (substitution) { + write(substitution); + } + else { + writeTextOfNode(currentSourceFile, node); } - writeTextOfNode(currentSourceFile, node); } function emitIdentifier(node: Identifier) { @@ -2526,7 +2526,7 @@ module ts { // export var obj = { y }; // } // The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version - if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNamePrefix(node.name)) { + if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNameSubstitution(node.name)) { // Emit identifier as an identifier write(": "); // Even though this is stored as identifier treat it as an expression @@ -2964,7 +2964,7 @@ module ts { emitStart(node.name); if (getCombinedNodeFlags(node) & NodeFlags.Export) { var container = getContainingModule(node); - write(container ? resolver.getLocalNameOfContainer(container) : "exports"); + write(container ? resolver.getGeneratedNameForNode(container) : "exports"); write("."); } emitNode(node.name); @@ -3771,7 +3771,7 @@ module ts { emitStart(node); write("(function ("); emitStart(node.name); - write(resolver.getLocalNameOfContainer(node)); + write(resolver.getGeneratedNameForNode(node)); emitEnd(node.name); write(") {"); increaseIndent(); @@ -3802,9 +3802,9 @@ module ts { function emitEnumMember(node: EnumMember) { var enumParent = node.parent; emitStart(node); - write(resolver.getLocalNameOfContainer(enumParent)); + write(resolver.getGeneratedNameForNode(enumParent)); write("["); - write(resolver.getLocalNameOfContainer(enumParent)); + write(resolver.getGeneratedNameForNode(enumParent)); write("["); emitExpressionForPropertyName(node.name); write("] = "); @@ -3860,7 +3860,7 @@ module ts { emitStart(node); write("(function ("); emitStart(node.name); - write(resolver.getLocalNameOfContainer(node)); + write(resolver.getGeneratedNameForNode(node)); emitEnd(node.name); write(") "); if (node.body.kind === SyntaxKind.ModuleBlock) { @@ -3918,23 +3918,6 @@ module ts { emitRequire(moduleName); } - function emitNamedImportAssignments(namedImports: NamedImports, moduleReference: Identifier) { - var elements = namedImports.elements; - for (var i = 0; i < elements.length; i++) { - var element = elements[i]; - if (resolver.isReferencedImportDeclaration(element)) { - writeLine(); - if (!(element.flags & NodeFlags.Export)) write("var "); - emitModuleMemberName(element); - write(" = "); - emit(moduleReference); - write("."); - emit(element.propertyName || element.name); - write(";"); - } - } - } - function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { var info = getExternalImportInfo(node); if (info) { @@ -3943,7 +3926,7 @@ module ts { if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); - var moduleName = getImportedModuleName(info.importNode); + var moduleName = getImportedModuleName(node); if (declarationNode) { if (!(declarationNode.flags & NodeFlags.Export)) write("var "); emitModuleMemberName(declarationNode); @@ -3952,10 +3935,9 @@ module ts { } else if (namedImports) { write("var "); - emit(info.tempName); + write(resolver.getGeneratedNameForNode(node)); write(" = "); emitRequire(moduleName); - emitNamedImportAssignments(namedImports, info.tempName); } else { emitRequire(moduleName); @@ -3972,9 +3954,6 @@ module ts { write(";"); } } - else if (namedImports) { - emitNamedImportAssignments(namedImports, info.tempName); - } } } } @@ -4027,7 +4006,8 @@ module ts { } return { importNode: node, - namedImports: importClause.namedBindings + namedImports: importClause.namedBindings, + localName: resolver.getGeneratedNameForNode(node) }; } return { @@ -4042,9 +4022,6 @@ module ts { var info = createExternalImportInfo(node); if (info) { if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { - if (!info.declarationNode) { - info.tempName = createTempVariable(sourceFile); - } externalImports.push(info); } } @@ -4095,7 +4072,12 @@ module ts { write("], function (require, exports"); forEach(externalImports, info => { write(", "); - emit(info.declarationNode ? info.declarationNode.name : info.tempName); + if (info.declarationNode) { + emit(info.declarationNode.name); + } + else { + write(resolver.getGeneratedNameForNode(info.importNode)); + } }); write(") {"); increaseIndent(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d50b4bcf33581..eb28e2ddacdd4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1163,8 +1163,8 @@ module ts { } export interface EmitResolver { - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; - getExpressionNamePrefix(node: Identifier): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; @@ -1312,7 +1312,8 @@ module ts { enumMemberValue?: number; // Constant value of enum member isIllegalTypeReferenceInConstraint?: boolean; // Is type reference in constraint refers to the type parameter from the same list isVisible?: boolean; // Is this node visible - localModuleName?: string; // Local name for module instance + generatedName?: string; // Generated name for module, enum, or import declaration + generatedNames?: Map; // Generated names table for source file assignmentChecks?: Map; // Cache of assignment checks hasReportedStatementInAmbientContext?: boolean; // Cache boolean if we report statements in ambient context importOnRightSide?: Symbol; // for import declarations - import that appear on the right side diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6ce615c486998..9283064d7db68 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -181,6 +181,12 @@ module ts { return identifier.length >= 3 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ && identifier.charCodeAt(2) === CharacterCodes._ ? identifier.substr(1) : identifier; } + // Make an identifier from an external module name by extracting the string after the last "/" and replacing + // all non-alphanumeric characters with underscores + export function makeIdentifierFromModuleName(moduleName: string): string { + return getBaseFileName(moduleName).replace(/\W/g, "_"); + } + // Return display name of an identifier // Computed property names will just be emitted as "[]", where is the source // text of the expression in the computed property. From bbab04e64e60dc744d13192e3347be2910aa531d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 10 Feb 2015 15:03:28 -0800 Subject: [PATCH 33/46] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 7 ++- .../reference/APISample_compile.types | 19 +++--- tests/baselines/reference/APISample_linter.js | 7 ++- .../reference/APISample_linter.types | 19 +++--- .../reference/APISample_transform.js | 7 ++- .../reference/APISample_transform.types | 19 +++--- .../baselines/reference/APISample_watcher.js | 7 ++- .../reference/APISample_watcher.types | 19 +++--- ...lisionCodeGenModuleWithAccessorChildren.js | 8 +-- ...ionCodeGenModuleWithConstructorChildren.js | 8 +-- ...lisionCodeGenModuleWithFunctionChildren.js | 8 +-- ...ionCodeGenModuleWithMemberClassConflict.js | 6 +- ...ollisionCodeGenModuleWithMethodChildren.js | 8 +-- ...ollisionCodeGenModuleWithModuleChildren.js | 12 ++-- .../es6ImportNamedImportParsingError.js | 5 +- .../baselines/reference/escapedIdentifiers.js | 4 +- .../isDeclarationVisibleNodeKinds.js | 28 ++++----- ...haresNameWithImportDeclarationInsideIt5.js | 4 +- ...haresNameWithImportDeclarationInsideIt6.js | 4 +- tests/baselines/reference/nameCollision.js | 12 ++-- .../reference/privacyGloImportParseErrors.js | 2 +- .../reference/privacyImportParseErrors.js | 4 +- .../reference/recursiveClassReferenceTest.js | 4 +- .../recursiveClassReferenceTest.js.map | 2 +- .../recursiveClassReferenceTest.sourcemap.txt | 61 +++++++++---------- 25 files changed, 153 insertions(+), 131 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 5c74f2fa688f8..0186edfdf1daf 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -902,8 +902,8 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; - getExpressionNamePrefix(node: Identifier): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; @@ -1028,7 +1028,8 @@ declare module "typescript" { enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; isVisible?: boolean; - localModuleName?: string; + generatedName?: string; + generatedNames?: Map; assignmentChecks?: Map; hasReportedStatementInAmbientContext?: boolean; importOnRightSide?: Symbol; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index aebe5ea695a24..7860dd31c7f3a 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2882,14 +2882,15 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; ->getLocalNameOfContainer : (container: EnumDeclaration | ModuleDeclaration) => string ->container : EnumDeclaration | ModuleDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration +>ImportDeclaration : ImportDeclaration - getExpressionNamePrefix(node: Identifier): string; ->getExpressionNamePrefix : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier): string; +>getExpressionNameSubstitution : (node: Identifier) => string >node : Identifier >Identifier : Identifier @@ -3313,8 +3314,12 @@ declare module "typescript" { isVisible?: boolean; >isVisible : boolean - localModuleName?: string; ->localModuleName : string + generatedName?: string; +>generatedName : string + + generatedNames?: Map; +>generatedNames : Map +>Map : Map assignmentChecks?: Map; >assignmentChecks : Map diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 8b40586e88bdb..3b4ddd6f77de9 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -933,8 +933,8 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; - getExpressionNamePrefix(node: Identifier): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; @@ -1059,7 +1059,8 @@ declare module "typescript" { enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; isVisible?: boolean; - localModuleName?: string; + generatedName?: string; + generatedNames?: Map; assignmentChecks?: Map; hasReportedStatementInAmbientContext?: boolean; importOnRightSide?: Symbol; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 1bada73385fdd..c3e69a2fb18fc 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3026,14 +3026,15 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; ->getLocalNameOfContainer : (container: EnumDeclaration | ModuleDeclaration) => string ->container : EnumDeclaration | ModuleDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration +>ImportDeclaration : ImportDeclaration - getExpressionNamePrefix(node: Identifier): string; ->getExpressionNamePrefix : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier): string; +>getExpressionNameSubstitution : (node: Identifier) => string >node : Identifier >Identifier : Identifier @@ -3457,8 +3458,12 @@ declare module "typescript" { isVisible?: boolean; >isVisible : boolean - localModuleName?: string; ->localModuleName : string + generatedName?: string; +>generatedName : string + + generatedNames?: Map; +>generatedNames : Map +>Map : Map assignmentChecks?: Map; >assignmentChecks : Map diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 74aba68a76c58..af88a03ee5cbc 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -934,8 +934,8 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; - getExpressionNamePrefix(node: Identifier): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; @@ -1060,7 +1060,8 @@ declare module "typescript" { enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; isVisible?: boolean; - localModuleName?: string; + generatedName?: string; + generatedNames?: Map; assignmentChecks?: Map; hasReportedStatementInAmbientContext?: boolean; importOnRightSide?: Symbol; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 6be348b413155..288e7f53bd79c 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2978,14 +2978,15 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; ->getLocalNameOfContainer : (container: EnumDeclaration | ModuleDeclaration) => string ->container : EnumDeclaration | ModuleDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration +>ImportDeclaration : ImportDeclaration - getExpressionNamePrefix(node: Identifier): string; ->getExpressionNamePrefix : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier): string; +>getExpressionNameSubstitution : (node: Identifier) => string >node : Identifier >Identifier : Identifier @@ -3409,8 +3410,12 @@ declare module "typescript" { isVisible?: boolean; >isVisible : boolean - localModuleName?: string; ->localModuleName : string + generatedName?: string; +>generatedName : string + + generatedNames?: Map; +>generatedNames : Map +>Map : Map assignmentChecks?: Map; >assignmentChecks : Map diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 79e2ac398029f..d66c384627c0c 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -971,8 +971,8 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; - getExpressionNamePrefix(node: Identifier): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; @@ -1097,7 +1097,8 @@ declare module "typescript" { enumMemberValue?: number; isIllegalTypeReferenceInConstraint?: boolean; isVisible?: boolean; - localModuleName?: string; + generatedName?: string; + generatedNames?: Map; assignmentChecks?: Map; hasReportedStatementInAmbientContext?: boolean; importOnRightSide?: Symbol; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 429a63daed814..7825898dd5672 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3151,14 +3151,15 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getLocalNameOfContainer(container: ModuleDeclaration | EnumDeclaration): string; ->getLocalNameOfContainer : (container: EnumDeclaration | ModuleDeclaration) => string ->container : EnumDeclaration | ModuleDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration +>ImportDeclaration : ImportDeclaration - getExpressionNamePrefix(node: Identifier): string; ->getExpressionNamePrefix : (node: Identifier) => string + getExpressionNameSubstitution(node: Identifier): string; +>getExpressionNameSubstitution : (node: Identifier) => string >node : Identifier >Identifier : Identifier @@ -3582,8 +3583,12 @@ declare module "typescript" { isVisible?: boolean; >isVisible : boolean - localModuleName?: string; ->localModuleName : string + generatedName?: string; +>generatedName : string + + generatedNames?: Map; +>generatedNames : Map +>Map : Map assignmentChecks?: Map; >assignmentChecks : Map diff --git a/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js index 9db005de9b987..141ef285f037a 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithAccessorChildren.js @@ -63,14 +63,14 @@ var M; })(); })(M || (M = {})); var M; -(function (_M) { +(function (_M_1) { var d = (function () { function d() { } Object.defineProperty(d.prototype, "Z", { set: function (p) { var M = 10; - this.y = _M.x; + this.y = _M_1.x; }, enumerable: true, configurable: true @@ -94,14 +94,14 @@ var M; })(); })(M || (M = {})); var M; -(function (_M) { +(function (_M_2) { var f = (function () { function f() { } Object.defineProperty(f.prototype, "Z", { get: function () { var M = 10; - return _M.x; + return _M_2.x; }, enumerable: true, configurable: true diff --git a/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js index 33a9f97f6d1cc..2158a0562ea2d 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithConstructorChildren.js @@ -35,21 +35,21 @@ var M; })(); })(M || (M = {})); var M; -(function (_M) { +(function (_M_1) { var d = (function () { function d(M, p) { - if (p === void 0) { p = _M.x; } + if (p === void 0) { p = _M_1.x; } this.M = M; } return d; })(); })(M || (M = {})); var M; -(function (_M) { +(function (_M_2) { var d2 = (function () { function d2() { var M = 10; - var p = _M.x; + var p = _M_2.x; } return d2; })(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js index bb1c0e7845bdb..caaa6a59da525 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithFunctionChildren.js @@ -28,17 +28,17 @@ var M; } })(M || (M = {})); var M; -(function (_M) { +(function (_M_1) { function fn2() { var M; - var p = _M.x; + var p = _M_1.x; } })(M || (M = {})); var M; -(function (_M) { +(function (_M_2) { function fn3() { function M() { - var p = _M.x; + var p = _M_2.x; } } })(M || (M = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js b/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js index 3c75d2e57389b..59c2ebf295d52 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMemberClassConflict.js @@ -27,19 +27,19 @@ var m1; })(m1 || (m1 = {})); var foo = new m1.m1(); var m2; -(function (__m2) { +(function (_m2_1) { var m2 = (function () { function m2() { } return m2; })(); - __m2.m2 = m2; + _m2_1.m2 = m2; var _m2 = (function () { function _m2() { } return _m2; })(); - __m2._m2 = _m2; + _m2_1._m2 = _m2; })(m2 || (m2 = {})); var foo = new m2.m2(); var foo = new m2._m2(); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js index 56efb2dcc0279..212364ed30b00 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithMethodChildren.js @@ -46,25 +46,25 @@ var M; })(); })(M || (M = {})); var M; -(function (_M) { +(function (_M_1) { var d = (function () { function d() { } d.prototype.fn2 = function () { var M; - var p = _M.x; + var p = _M_1.x; }; return d; })(); })(M || (M = {})); var M; -(function (_M) { +(function (_M_2) { var e = (function () { function e() { } e.prototype.fn3 = function () { function M() { - var p = _M.x; + var p = _M_2.x; } }; return e; diff --git a/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js b/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js index ecc5fca2e9fe5..3c8b17deadd68 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithModuleChildren.js @@ -53,7 +53,7 @@ var M; })(m1 || (m1 = {})); })(M || (M = {})); var M; -(function (_M) { +(function (_M_1) { var m2; (function (m2) { var M = (function () { @@ -61,17 +61,17 @@ var M; } return M; })(); - var p = _M.x; + var p = _M_1.x; var p2 = new M(); })(m2 || (m2 = {})); })(M || (M = {})); var M; -(function (_M) { +(function (_M_2) { var m3; (function (m3) { function M() { } - var p = _M.x; + var p = _M_2.x; var p2 = M(); })(m3 || (m3 = {})); })(M || (M = {})); @@ -84,12 +84,12 @@ var M; })(m3 || (m3 = {})); })(M || (M = {})); var M; -(function (_M) { +(function (_M_3) { var m4; (function (m4) { var M; (function (M) { - var p = _M.x; + var p = _M_3.x; })(M || (M = {})); })(m4 || (m4 = {})); })(M || (M = {})); diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index b1f7f2c295b9f..f9d8e90f707f1 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -20,10 +20,9 @@ exports.m = exports.a; from; "es6ImportNamedImportParsingError_0"; { - a; + _module_1.a; } from; "es6ImportNamedImportParsingError_0"; -var _a = require(); -var a = _a.a; +var _module_1 = require(); "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/escapedIdentifiers.js b/tests/baselines/reference/escapedIdentifiers.js index 5de505e4cb7fc..7051d8d24339e 100644 --- a/tests/baselines/reference/escapedIdentifiers.js +++ b/tests/baselines/reference/escapedIdentifiers.js @@ -143,8 +143,8 @@ var moduleType1; moduleType1.baz1; })(moduleType1 || (moduleType1 = {})); var moduleType\u0032; -(function (moduleType\u0032) { - moduleType\u0032.baz2; +(function (moduleType2) { + moduleType2.baz2; })(moduleType\u0032 || (moduleType\u0032 = {})); moduleType1.baz1 = 3; moduleType\u0031.baz1 = 3; diff --git a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js index 0d1664c7f59a2..d357922f5bce6 100644 --- a/tests/baselines/reference/isDeclarationVisibleNodeKinds.js +++ b/tests/baselines/reference/isDeclarationVisibleNodeKinds.js @@ -80,59 +80,59 @@ var schema; })(schema || (schema = {})); // Constructor types var schema; -(function (_schema) { +(function (_schema_1) { function createValidator2(schema) { return undefined; } - _schema.createValidator2 = createValidator2; + _schema_1.createValidator2 = createValidator2; })(schema || (schema = {})); // union types var schema; -(function (_schema) { +(function (_schema_2) { function createValidator3(schema) { return undefined; } - _schema.createValidator3 = createValidator3; + _schema_2.createValidator3 = createValidator3; })(schema || (schema = {})); // Array types var schema; -(function (_schema) { +(function (_schema_3) { function createValidator4(schema) { return undefined; } - _schema.createValidator4 = createValidator4; + _schema_3.createValidator4 = createValidator4; })(schema || (schema = {})); // TypeLiterals var schema; -(function (_schema) { +(function (_schema_4) { function createValidator5(schema) { return undefined; } - _schema.createValidator5 = createValidator5; + _schema_4.createValidator5 = createValidator5; })(schema || (schema = {})); // Tuple types var schema; -(function (_schema) { +(function (_schema_5) { function createValidator6(schema) { return undefined; } - _schema.createValidator6 = createValidator6; + _schema_5.createValidator6 = createValidator6; })(schema || (schema = {})); // Paren Types var schema; -(function (_schema) { +(function (_schema_6) { function createValidator7(schema) { return undefined; } - _schema.createValidator7 = createValidator7; + _schema_6.createValidator7 = createValidator7; })(schema || (schema = {})); // Type reference var schema; -(function (_schema) { +(function (_schema_7) { function createValidator8(schema) { return undefined; } - _schema.createValidator8 = createValidator8; + _schema_7.createValidator8 = createValidator8; })(schema || (schema = {})); var schema; (function (schema) { diff --git a/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js b/tests/baselines/reference/moduleSharesNameWithImportDeclarationInsideIt5.js index 0995dcbb9c0b6..0bc314ccc0706 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) { function bar() { } - M.bar = bar; + _M.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 51b2d4f89f959..4ba0a33c29a0c 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) { function bar() { } - M.bar = bar; + _M.bar = bar; })(M = A.M || (A.M = {})); })(A || (A = {})); diff --git a/tests/baselines/reference/nameCollision.js b/tests/baselines/reference/nameCollision.js index 67e6f3afa47c0..fe7bb3a891975 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) { +(function (_A_1) { // these 2 statements force an underscore before the 'A' // in the generated function call. var A = 12; @@ -83,15 +83,15 @@ var X; })(Y = _X.Y || (_X.Y = {})); })(X || (X = {})); var Y; -(function (_Y) { +(function (_Y_1) { var Y; - (function (_Y) { + (function (_Y_2) { (function (Y) { Y[Y["Red"] = 0] = "Red"; Y[Y["Blue"] = 1] = "Blue"; - })(_Y.Y || (_Y.Y = {})); - var Y = _Y.Y; - })(Y = _Y.Y || (_Y.Y = {})); + })(_Y_2.Y || (_Y_2.Y = {})); + var Y = _Y_2.Y; + })(Y = _Y_1.Y || (_Y_1.Y = {})); })(Y || (Y = {})); // no collision, since interface doesn't // generate code. diff --git a/tests/baselines/reference/privacyGloImportParseErrors.js b/tests/baselines/reference/privacyGloImportParseErrors.js index 27e24a1cf38db..3b82d65a07bca 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.js +++ b/tests/baselines/reference/privacyGloImportParseErrors.js @@ -238,7 +238,7 @@ var glo_M1_public; glo_M1_public.v2; })(glo_M1_public || (glo_M1_public = {})); var m2; -(function (m2) { +(function (_m2) { var m4; (function (m4) { var a = 10; diff --git a/tests/baselines/reference/privacyImportParseErrors.js b/tests/baselines/reference/privacyImportParseErrors.js index dd2a0cfe50b62..7a875fa12d11d 100644 --- a/tests/baselines/reference/privacyImportParseErrors.js +++ b/tests/baselines/reference/privacyImportParseErrors.js @@ -566,14 +566,14 @@ var glo_im4_private_v4_private = glo_im4_private.f1(); exports.glo_im1_public = glo_M1_public; exports.glo_im2_public = glo_M3_private; var m2; -(function (m2) { +(function (_m2) { var m4; (function (m4) { var a = 10; })(m4 || (m4 = {})); })(m2 || (m2 = {})); var m3; -(function (m3) { +(function (_m3) { var m4; (function (m4) { var a = 10; diff --git a/tests/baselines/reference/recursiveClassReferenceTest.js b/tests/baselines/reference/recursiveClassReferenceTest.js index 661ecb3a0e782..f565f8f23d08a 100644 --- a/tests/baselines/reference/recursiveClassReferenceTest.js +++ b/tests/baselines/reference/recursiveClassReferenceTest.js @@ -116,7 +116,7 @@ var Sample; var Actions; (function (Actions) { var Thing; - (function (_Thing) { + (function (_Thing_1) { var Find; (function (Find) { var StartFindAction = (function () { @@ -131,7 +131,7 @@ var Sample; return StartFindAction; })(); Find.StartFindAction = StartFindAction; - })(Find = _Thing.Find || (_Thing.Find = {})); + })(Find = _Thing_1.Find || (_Thing_1.Find = {})); })(Thing = Actions.Thing || (Actions.Thing = {})); })(Actions = Sample.Actions || (Sample.Actions = {})); })(Sample || (Sample = {})); diff --git a/tests/baselines/reference/recursiveClassReferenceTest.js.map b/tests/baselines/reference/recursiveClassReferenceTest.js.map index d2e66a925a898..b2478b7f05c52 100644 --- a/tests/baselines/reference/recursiveClassReferenceTest.js.map +++ b/tests/baselines/reference/recursiveClassReferenceTest.js.map @@ -1,2 +1,2 @@ //// [recursiveClassReferenceTest.js.map] -{"version":3,"file":"recursiveClassReferenceTest.js","sourceRoot":"","sources":["recursiveClassReferenceTest.ts"],"names":["Sample","Sample.Actions","Sample.Actions.Thing","Sample.Actions.Thing.Find","Sample.Actions.Thing.Find.StartFindAction","Sample.Actions.Thing.Find.StartFindAction.constructor","Sample.Actions.Thing.Find.StartFindAction.getId","Sample.Actions.Thing.Find.StartFindAction.run","Sample.Thing","Sample.Thing.Widgets","Sample.Thing.Widgets.FindWidget","Sample.Thing.Widgets.FindWidget.constructor","Sample.Thing.Widgets.FindWidget.gar","Sample.Thing.Widgets.FindWidget.getDomNode","Sample.Thing.Widgets.FindWidget.destroy","AbstractMode","AbstractMode.constructor","AbstractMode.getInitialState","Sample.Thing.Languages","Sample.Thing.Languages.PlainText","Sample.Thing.Languages.PlainText.State","Sample.Thing.Languages.PlainText.State.constructor","Sample.Thing.Languages.PlainText.State.clone","Sample.Thing.Languages.PlainText.State.equals","Sample.Thing.Languages.PlainText.State.getMode","Sample.Thing.Languages.PlainText.Mode","Sample.Thing.Languages.PlainText.Mode.constructor","Sample.Thing.Languages.PlainText.Mode.getInitialState"],"mappings":"AAAA,iEAAiE;AACjE,0EAA0E;;;;;;;AA8B1E,IAAO,MAAM,CAUZ;AAVD,WAAO,MAAM;IAACA,IAAAA,OAAOA,CAUpBA;IAVaA,WAAAA,OAAOA;QAACC,IAAAA,KAAKA,CAU1BA;QAVqBA,WAAAA,MAAKA;YAACC,IAAAA,IAAIA,CAU/BA;YAV2BA,WAAAA,IAAIA,EAACA,CAACA;gBACjCC,IAAaA,eAAeA;oBAA5BC,SAAaA,eAAeA;oBAQ5BC,CAACA;oBANOD,+BAAKA,GAAZA;wBAAiBE,MAAMA,CAACA,IAAIA,CAACA;oBAACA,CAACA;oBAExBF,6BAAGA,GAAVA,UAAWA,KAA6BA;wBAEvCG,MAAMA,CAACA,IAAIA,CAACA;oBACbA,CAACA;oBACFH,sBAACA;gBAADA,CAACA,AARDD,IAQCA;gBARYA,oBAAeA,GAAfA,eAQZA,CAAAA;YACFA,CAACA,EAV2BD,IAAIA,GAAJA,WAAIA,KAAJA,WAAIA,QAU/BA;QAADA,CAACA,EAVqBD,KAAKA,GAALA,aAAKA,KAALA,aAAKA,QAU1BA;IAADA,CAACA,EAVaD,OAAOA,GAAPA,cAAOA,KAAPA,cAAOA,QAUpBA;AAADA,CAACA,EAVM,MAAM,KAAN,MAAM,QAUZ;AAED,IAAO,MAAM,CAoBZ;AApBD,WAAO,MAAM;IAACA,IAAAA,KAAKA,CAoBlBA;IApBaA,WAAAA,KAAKA;QAACQ,IAAAA,OAAOA,CAoB1BA;QApBmBA,WAAAA,OAAOA,EAACA,CAACA;YAC5BC,IAAaA,UAAUA;gBAKtBC,SALYA,UAAUA,CAKFA,SAAkCA;oBAAlCC,cAASA,GAATA,SAASA,CAAyBA;oBAD9CA,YAAOA,GAAOA,IAAIA,CAACA;oBAGvBA,AADAA,aAAaA;oBACbA,SAASA,CAACA,SAASA,CAACA,WAAWA,EAAEA,IAAIA,CAACA,CAACA;gBAC3CA,CAACA;gBANMD,wBAAGA,GAAVA,UAAWA,MAAyCA;oBAAIE,EAAEA,CAACA,CAACA,IAAIA,CAACA,CAACA,CAACA;wBAAAA,MAAMA,CAACA,MAAMA,CAACA,IAAIA,CAACA,CAACA;oBAAAA,CAACA;gBAAAA,CAACA;gBAQlFF,+BAAUA,GAAjBA;oBACCG,MAAMA,CAACA,OAAOA,CAACA;gBAChBA,CAACA;gBAEMH,4BAAOA,GAAdA;gBAEAI,CAACA;gBAEFJ,iBAACA;YAADA,CAACA,AAlBDD,IAkBCA;YAlBYA,kBAAUA,GAAVA,UAkBZA,CAAAA;QACFA,CAACA,EApBmBD,OAAOA,GAAPA,aAAOA,KAAPA,aAAOA,QAoB1BA;IAADA,CAACA,EApBaR,KAAKA,GAALA,YAAKA,KAALA,YAAKA,QAoBlBA;AAADA,CAACA,EApBM,MAAM,KAAN,MAAM,QAoBZ;AAGD,IAAM,YAAY;IAAlBe,SAAMA,YAAYA;IAAqEC,CAACA;IAA3CD,sCAAeA,GAAtBA;QAAmCE,MAAMA,CAACA,IAAIA,CAACA;IAAAA,CAACA;IAACF,mBAACA;AAADA,CAACA,AAAxF,IAAwF;AASxF,IAAO,MAAM,CAwBZ;AAxBD,WAAO,MAAM;IAACf,IAAAA,KAAKA,CAwBlBA;IAxBaA,WAAAA,KAAKA;QAACQ,IAAAA,SAASA,CAwB5BA;QAxBmBA,WAAAA,SAASA;YAACU,IAAAA,SAASA,CAwBtCA;YAxB6BA,WAAAA,SAASA,EAACA,CAACA;gBAExCC,IAAaA,KAAKA;oBACXC,SADMA,KAAKA,CACSA,IAAWA;wBAAXC,SAAIA,GAAJA,IAAIA,CAAOA;oBAAIA,CAACA;oBACnCD,qBAAKA,GAAZA;wBACCE,MAAMA,CAACA,IAAIA,CAACA;oBACbA,CAACA;oBAEMF,sBAAMA,GAAbA,UAAcA,KAAYA;wBACzBG,MAAMA,CAACA,IAAIA,KAAKA,KAAKA,CAACA;oBACvBA,CAACA;oBAEMH,uBAAOA,GAAdA;wBAA0BI,MAAMA,CAACA,IAAIA,CAACA;oBAACA,CAACA;oBACzCJ,YAACA;gBAADA,CAACA,AAXDD,IAWCA;gBAXYA,eAAKA,GAALA,KAWZA,CAAAA;gBAEDA,IAAaA,IAAIA;oBAASM,UAAbA,IAAIA,UAAqBA;oBAAtCA,SAAaA,IAAIA;wBAASC,8BAAYA;oBAQtCA,CAACA;oBANAD,aAAaA;oBACNA,8BAAeA,GAAtBA;wBACCE,MAAMA,CAACA,IAAIA,KAAKA,CAACA,IAAIA,CAACA,CAACA;oBACxBA,CAACA;oBAGFF,WAACA;gBAADA,CAACA,AARDN,EAA0BA,YAAYA,EAQrCA;gBARYA,cAAIA,GAAJA,IAQZA,CAAAA;YACFA,CAACA,EAxB6BD,SAASA,GAATA,mBAASA,KAATA,mBAASA,QAwBtCA;QAADA,CAACA,EAxBmBV,SAASA,GAATA,eAASA,KAATA,eAASA,QAwB5BA;IAADA,CAACA,EAxBaR,KAAKA,GAALA,YAAKA,KAALA,YAAKA,QAwBlBA;AAADA,CAACA,EAxBM,MAAM,KAAN,MAAM,QAwBZ"} \ No newline at end of file +{"version":3,"file":"recursiveClassReferenceTest.js","sourceRoot":"","sources":["recursiveClassReferenceTest.ts"],"names":["Sample","Sample.Actions","Sample.Actions.Thing","Sample.Actions.Thing.Find","Sample.Actions.Thing.Find.StartFindAction","Sample.Actions.Thing.Find.StartFindAction.constructor","Sample.Actions.Thing.Find.StartFindAction.getId","Sample.Actions.Thing.Find.StartFindAction.run","Sample.Thing","Sample.Thing.Widgets","Sample.Thing.Widgets.FindWidget","Sample.Thing.Widgets.FindWidget.constructor","Sample.Thing.Widgets.FindWidget.gar","Sample.Thing.Widgets.FindWidget.getDomNode","Sample.Thing.Widgets.FindWidget.destroy","AbstractMode","AbstractMode.constructor","AbstractMode.getInitialState","Sample.Thing.Languages","Sample.Thing.Languages.PlainText","Sample.Thing.Languages.PlainText.State","Sample.Thing.Languages.PlainText.State.constructor","Sample.Thing.Languages.PlainText.State.clone","Sample.Thing.Languages.PlainText.State.equals","Sample.Thing.Languages.PlainText.State.getMode","Sample.Thing.Languages.PlainText.Mode","Sample.Thing.Languages.PlainText.Mode.constructor","Sample.Thing.Languages.PlainText.Mode.getInitialState"],"mappings":"AAAA,iEAAiE;AACjE,0EAA0E;;;;;;;AA8B1E,IAAO,MAAM,CAUZ;AAVD,WAAO,MAAM;IAACA,IAAAA,OAAOA,CAUpBA;IAVaA,WAAAA,OAAOA;QAACC,IAAAA,KAAKA,CAU1BA;QAVqBA,WAAAA,QAAKA;YAACC,IAAAA,IAAIA,CAU/BA;YAV2BA,WAAAA,IAAIA,EAACA,CAACA;gBACjCC,IAAaA,eAAeA;oBAA5BC,SAAaA,eAAeA;oBAQ5BC,CAACA;oBANOD,+BAAKA,GAAZA;wBAAiBE,MAAMA,CAACA,IAAIA,CAACA;oBAACA,CAACA;oBAExBF,6BAAGA,GAAVA,UAAWA,KAA6BA;wBAEvCG,MAAMA,CAACA,IAAIA,CAACA;oBACbA,CAACA;oBACFH,sBAACA;gBAADA,CAACA,AARDD,IAQCA;gBARYA,oBAAeA,GAAfA,eAQZA,CAAAA;YACFA,CAACA,EAV2BD,IAAIA,GAAJA,aAAIA,KAAJA,aAAIA,QAU/BA;QAADA,CAACA,EAVqBD,KAAKA,GAALA,aAAKA,KAALA,aAAKA,QAU1BA;IAADA,CAACA,EAVaD,OAAOA,GAAPA,cAAOA,KAAPA,cAAOA,QAUpBA;AAADA,CAACA,EAVM,MAAM,KAAN,MAAM,QAUZ;AAED,IAAO,MAAM,CAoBZ;AApBD,WAAO,MAAM;IAACA,IAAAA,KAAKA,CAoBlBA;IApBaA,WAAAA,KAAKA;QAACQ,IAAAA,OAAOA,CAoB1BA;QApBmBA,WAAAA,OAAOA,EAACA,CAACA;YAC5BC,IAAaA,UAAUA;gBAKtBC,SALYA,UAAUA,CAKFA,SAAkCA;oBAAlCC,cAASA,GAATA,SAASA,CAAyBA;oBAD9CA,YAAOA,GAAOA,IAAIA,CAACA;oBAGvBA,AADAA,aAAaA;oBACbA,SAASA,CAACA,SAASA,CAACA,WAAWA,EAAEA,IAAIA,CAACA,CAACA;gBAC3CA,CAACA;gBANMD,wBAAGA,GAAVA,UAAWA,MAAyCA;oBAAIE,EAAEA,CAACA,CAACA,IAAIA,CAACA,CAACA,CAACA;wBAAAA,MAAMA,CAACA,MAAMA,CAACA,IAAIA,CAACA,CAACA;oBAAAA,CAACA;gBAAAA,CAACA;gBAQlFF,+BAAUA,GAAjBA;oBACCG,MAAMA,CAACA,OAAOA,CAACA;gBAChBA,CAACA;gBAEMH,4BAAOA,GAAdA;gBAEAI,CAACA;gBAEFJ,iBAACA;YAADA,CAACA,AAlBDD,IAkBCA;YAlBYA,kBAAUA,GAAVA,UAkBZA,CAAAA;QACFA,CAACA,EApBmBD,OAAOA,GAAPA,aAAOA,KAAPA,aAAOA,QAoB1BA;IAADA,CAACA,EApBaR,KAAKA,GAALA,YAAKA,KAALA,YAAKA,QAoBlBA;AAADA,CAACA,EApBM,MAAM,KAAN,MAAM,QAoBZ;AAGD,IAAM,YAAY;IAAlBe,SAAMA,YAAYA;IAAqEC,CAACA;IAA3CD,sCAAeA,GAAtBA;QAAmCE,MAAMA,CAACA,IAAIA,CAACA;IAAAA,CAACA;IAACF,mBAACA;AAADA,CAACA,AAAxF,IAAwF;AASxF,IAAO,MAAM,CAwBZ;AAxBD,WAAO,MAAM;IAACf,IAAAA,KAAKA,CAwBlBA;IAxBaA,WAAAA,KAAKA;QAACQ,IAAAA,SAASA,CAwB5BA;QAxBmBA,WAAAA,SAASA;YAACU,IAAAA,SAASA,CAwBtCA;YAxB6BA,WAAAA,SAASA,EAACA,CAACA;gBAExCC,IAAaA,KAAKA;oBACXC,SADMA,KAAKA,CACSA,IAAWA;wBAAXC,SAAIA,GAAJA,IAAIA,CAAOA;oBAAIA,CAACA;oBACnCD,qBAAKA,GAAZA;wBACCE,MAAMA,CAACA,IAAIA,CAACA;oBACbA,CAACA;oBAEMF,sBAAMA,GAAbA,UAAcA,KAAYA;wBACzBG,MAAMA,CAACA,IAAIA,KAAKA,KAAKA,CAACA;oBACvBA,CAACA;oBAEMH,uBAAOA,GAAdA;wBAA0BI,MAAMA,CAACA,IAAIA,CAACA;oBAACA,CAACA;oBACzCJ,YAACA;gBAADA,CAACA,AAXDD,IAWCA;gBAXYA,eAAKA,GAALA,KAWZA,CAAAA;gBAEDA,IAAaA,IAAIA;oBAASM,UAAbA,IAAIA,UAAqBA;oBAAtCA,SAAaA,IAAIA;wBAASC,8BAAYA;oBAQtCA,CAACA;oBANAD,aAAaA;oBACNA,8BAAeA,GAAtBA;wBACCE,MAAMA,CAACA,IAAIA,KAAKA,CAACA,IAAIA,CAACA,CAACA;oBACxBA,CAACA;oBAGFF,WAACA;gBAADA,CAACA,AARDN,EAA0BA,YAAYA,EAQrCA;gBARYA,cAAIA,GAAJA,IAQZA,CAAAA;YACFA,CAACA,EAxB6BD,SAASA,GAATA,mBAASA,KAATA,mBAASA,QAwBtCA;QAADA,CAACA,EAxBmBV,SAASA,GAATA,eAASA,KAATA,eAASA,QAwB5BA;IAADA,CAACA,EAxBaR,KAAKA,GAALA,YAAKA,KAALA,YAAKA,QAwBlBA;AAADA,CAACA,EAxBM,MAAM,KAAN,MAAM,QAwBZ"} \ No newline at end of file diff --git a/tests/baselines/reference/recursiveClassReferenceTest.sourcemap.txt b/tests/baselines/reference/recursiveClassReferenceTest.sourcemap.txt index d7163bf7760f2..d02743ba29607 100644 --- a/tests/baselines/reference/recursiveClassReferenceTest.sourcemap.txt +++ b/tests/baselines/reference/recursiveClassReferenceTest.sourcemap.txt @@ -139,7 +139,7 @@ sourceFile:recursiveClassReferenceTest.ts 2 > ^^^^ 3 > ^^^^^ 4 > ^ -5 > ^^^^^^^^^^^-> +5 > ^^^^^^^^^^^^^-> 1 >. 2 > 3 > Thing @@ -159,16 +159,16 @@ sourceFile:recursiveClassReferenceTest.ts 3 >Emitted(13, 18) Source(32, 28) + SourceIndex(0) name (Sample.Actions) 4 >Emitted(13, 19) Source(42, 2) + SourceIndex(0) name (Sample.Actions) --- ->>> (function (_Thing) { +>>> (function (_Thing_1) { 1->^^^^^^^^ 2 > ^^^^^^^^^^^ -3 > ^^^^^^ +3 > ^^^^^^^^ 1-> 2 > 3 > Thing 1->Emitted(14, 9) Source(32, 23) + SourceIndex(0) name (Sample.Actions) 2 >Emitted(14, 20) Source(32, 23) + SourceIndex(0) name (Sample.Actions) -3 >Emitted(14, 26) Source(32, 28) + SourceIndex(0) name (Sample.Actions) +3 >Emitted(14, 28) Source(32, 28) + SourceIndex(0) name (Sample.Actions) --- >>> var Find; 1 >^^^^^^^^^^^^ @@ -377,7 +377,7 @@ sourceFile:recursiveClassReferenceTest.ts 3 > ^^^ 4 > ^^^^^^^^^^^^^^^ 5 > ^ -6 > ^^^-> +6 > ^^^^^^^-> 1-> 2 > StartFindAction 3 > @@ -397,17 +397,16 @@ sourceFile:recursiveClassReferenceTest.ts 4 >Emitted(28, 55) Source(41, 3) + SourceIndex(0) name (Sample.Actions.Thing.Find) 5 >Emitted(28, 56) Source(41, 3) + SourceIndex(0) name (Sample.Actions.Thing.Find) --- ->>> })(Find = _Thing.Find || (_Thing.Find = {})); +>>> })(Find = _Thing_1.Find || (_Thing_1.Find = {})); 1->^^^^^^^^^^^^ 2 > ^ 3 > ^^ 4 > ^^^^ 5 > ^^^ -6 > ^^^^^^^^^^^ -7 > ^^^^^ -8 > ^^^^^^^^^^^ -9 > ^^^^^^^^ -10> ^^-> +6 > ^^^^^^^^^^^^^ +7 > ^^^^^ +8 > ^^^^^^^^^^^^^ +9 > ^^^^^^^^ 1-> > 2 > } @@ -415,31 +414,31 @@ sourceFile:recursiveClassReferenceTest.ts 4 > Find 5 > 6 > Find -7 > -8 > Find -9 > { - > export class StartFindAction implements Sample.Thing.IAction { - > - > public getId() { return "yo"; } - > - > public run(Thing:Sample.Thing.ICodeThing):boolean { - > - > return true; - > } - > } - > } +7 > +8 > Find +9 > { + > export class StartFindAction implements Sample.Thing.IAction { + > + > public getId() { return "yo"; } + > + > public run(Thing:Sample.Thing.ICodeThing):boolean { + > + > return true; + > } + > } + > } 1->Emitted(29, 13) Source(42, 1) + SourceIndex(0) name (Sample.Actions.Thing.Find) 2 >Emitted(29, 14) Source(42, 2) + SourceIndex(0) name (Sample.Actions.Thing.Find) 3 >Emitted(29, 16) Source(32, 29) + SourceIndex(0) name (Sample.Actions.Thing) 4 >Emitted(29, 20) Source(32, 33) + SourceIndex(0) name (Sample.Actions.Thing) 5 >Emitted(29, 23) Source(32, 29) + SourceIndex(0) name (Sample.Actions.Thing) -6 >Emitted(29, 34) Source(32, 33) + SourceIndex(0) name (Sample.Actions.Thing) -7 >Emitted(29, 39) Source(32, 29) + SourceIndex(0) name (Sample.Actions.Thing) -8 >Emitted(29, 50) Source(32, 33) + SourceIndex(0) name (Sample.Actions.Thing) -9 >Emitted(29, 58) Source(42, 2) + SourceIndex(0) name (Sample.Actions.Thing) +6 >Emitted(29, 36) Source(32, 33) + SourceIndex(0) name (Sample.Actions.Thing) +7 >Emitted(29, 41) Source(32, 29) + SourceIndex(0) name (Sample.Actions.Thing) +8 >Emitted(29, 54) Source(32, 33) + SourceIndex(0) name (Sample.Actions.Thing) +9 >Emitted(29, 62) Source(42, 2) + SourceIndex(0) name (Sample.Actions.Thing) --- >>> })(Thing = Actions.Thing || (Actions.Thing = {})); -1->^^^^^^^^ +1 >^^^^^^^^ 2 > ^ 3 > ^^ 4 > ^^^^^ @@ -449,7 +448,7 @@ sourceFile:recursiveClassReferenceTest.ts 8 > ^^^^^^^^^^^^^ 9 > ^^^^^^^^ 10> ^-> -1-> +1 > 2 > } 3 > 4 > Thing @@ -468,7 +467,7 @@ sourceFile:recursiveClassReferenceTest.ts > } > } > } -1->Emitted(30, 9) Source(42, 1) + SourceIndex(0) name (Sample.Actions.Thing) +1 >Emitted(30, 9) Source(42, 1) + SourceIndex(0) name (Sample.Actions.Thing) 2 >Emitted(30, 10) Source(42, 2) + SourceIndex(0) name (Sample.Actions.Thing) 3 >Emitted(30, 12) Source(32, 23) + SourceIndex(0) name (Sample.Actions) 4 >Emitted(30, 17) Source(32, 28) + SourceIndex(0) name (Sample.Actions) From 76ce10d1821e9e9a7efaceeffe88ec94d1519f44 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 11 Feb 2015 10:49:56 -0800 Subject: [PATCH 34/46] Addressing CR feedback --- src/compiler/types.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index eb28e2ddacdd4..83cd99392c01b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1270,19 +1270,19 @@ module ts { members?: SymbolTable; // Class, interface or literal instance members exports?: SymbolTable; // Module exports exportSymbol?: Symbol; // Exported symbol associated with this symbol - valueDeclaration?: Declaration // First value declaration of the symbol, - constEnumOnlyModule?: boolean // For modules - if true - module contains only const enums or other modules with only const enums. + valueDeclaration?: Declaration // First value declaration of the symbol + constEnumOnlyModule?: boolean // True if module contains only const enums or other modules with only const enums } export interface SymbolLinks { - target?: Symbol; // Resolved (non-alias) target of an alias - type?: Type; // Type of value symbol - declaredType?: Type; // Type of class, interface, enum, or type parameter - mapper?: TypeMapper; // Type mapper for instantiation alias - referenced?: boolean; // True if alias symbol has been referenced as a value - exportAssignChecked?: boolean; // True if export assignment was checked - exportAssignSymbol?: Symbol; // Symbol exported from external module - unionType?: UnionType; // Containing union type for union property + target?: Symbol; // Resolved (non-alias) target of an alias + type?: Type; // Type of value symbol + declaredType?: Type; // Type of class, interface, enum, or type parameter + mapper?: TypeMapper; // Type mapper for instantiation alias + referenced?: boolean; // True if alias symbol has been referenced as a value + exportAssignmentChecked?: boolean; // True if export assignment was checked + exportAssignmentSymbol?: Symbol; // Symbol exported from external module + unionType?: UnionType; // Containing union type for union property } export interface TransientSymbol extends Symbol, SymbolLinks { } From 9cae8e7a81e4c95cf6a3a9015741ce144a81d447 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 11 Feb 2015 10:51:59 -0800 Subject: [PATCH 35/46] Small fix to recording of generated names --- src/compiler/checker.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 230d7df411083..11b9de61b2631 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -641,12 +641,12 @@ module ts { function getExportAssignmentSymbol(symbol: Symbol): Symbol { checkTypeOfExportAssignmentSymbol(symbol); - return getSymbolLinks(symbol).exportAssignSymbol; + return getSymbolLinks(symbol).exportAssignmentSymbol; } function checkTypeOfExportAssignmentSymbol(containerSymbol: Symbol): void { var symbolLinks = getSymbolLinks(containerSymbol); - if (!symbolLinks.exportAssignChecked) { + if (!symbolLinks.exportAssignmentChecked) { var exportInformation = collectExportInformationForSourceFileOrModule(containerSymbol); if (exportInformation.exportAssignments.length) { if (exportInformation.exportAssignments.length > 1) { @@ -666,9 +666,9 @@ module ts { var meaning = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace; var exportSymbol = resolveName(node, node.exportName.text, meaning, Diagnostics.Cannot_find_name_0, node.exportName); } - symbolLinks.exportAssignSymbol = exportSymbol || unknownSymbol; + symbolLinks.exportAssignmentSymbol = exportSymbol || unknownSymbol; } - symbolLinks.exportAssignChecked = true; + symbolLinks.exportAssignmentChecked = true; } } @@ -10190,7 +10190,7 @@ module ts { if (baseName.charCodeAt(0) !== CharacterCodes._) { var baseName = "_" + baseName; if (!isExistingName(baseName)) { - return baseName; + return generatedNames[baseName] = baseName; } } // Find the first unique '_name_n', where n is a positive number @@ -10201,14 +10201,13 @@ module ts { while (true) { name = baseName + i; if (!isExistingName(name)) { - return name; + return generatedNames[name] = name; } i++; } } function assignGeneratedName(node: Node, name: string) { - generatedNames[name] = name; getNodeLinks(node).generatedName = unescapeIdentifier(name); } From 3b39e9f4a153d9d9c08d27ed141c075c856faef2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 11 Feb 2015 10:52:29 -0800 Subject: [PATCH 36/46] Accepting new baselines --- tests/baselines/reference/APISample_compile.js | 4 ++-- tests/baselines/reference/APISample_compile.types | 8 ++++---- tests/baselines/reference/APISample_linter.js | 4 ++-- tests/baselines/reference/APISample_linter.types | 8 ++++---- tests/baselines/reference/APISample_transform.js | 4 ++-- tests/baselines/reference/APISample_transform.types | 8 ++++---- tests/baselines/reference/APISample_watcher.js | 4 ++-- tests/baselines/reference/APISample_watcher.types | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 271ab680ea3e0..eeb78ce8250b7 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1001,8 +1001,8 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; - exportAssignChecked?: boolean; - exportAssignSymbol?: Symbol; + exportAssignmentChecked?: boolean; + exportAssignmentSymbol?: Symbol; unionType?: UnionType; } interface TransientSymbol extends Symbol, SymbolLinks { diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 2274dbaf7938d..b85d0132a0432 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3236,11 +3236,11 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean - exportAssignChecked?: boolean; ->exportAssignChecked : boolean + exportAssignmentChecked?: boolean; +>exportAssignmentChecked : boolean - exportAssignSymbol?: Symbol; ->exportAssignSymbol : Symbol + exportAssignmentSymbol?: Symbol; +>exportAssignmentSymbol : Symbol >Symbol : Symbol unionType?: UnionType; diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 6d22636f1604c..1a5e652080594 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1032,8 +1032,8 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; - exportAssignChecked?: boolean; - exportAssignSymbol?: Symbol; + exportAssignmentChecked?: boolean; + exportAssignmentSymbol?: Symbol; unionType?: UnionType; } interface TransientSymbol extends Symbol, SymbolLinks { diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 4b89311ad13cc..f8f4b6bd199d1 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3380,11 +3380,11 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean - exportAssignChecked?: boolean; ->exportAssignChecked : boolean + exportAssignmentChecked?: boolean; +>exportAssignmentChecked : boolean - exportAssignSymbol?: Symbol; ->exportAssignSymbol : Symbol + exportAssignmentSymbol?: Symbol; +>exportAssignmentSymbol : Symbol >Symbol : Symbol unionType?: UnionType; diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index f190a748a1251..295d45c220e95 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1033,8 +1033,8 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; - exportAssignChecked?: boolean; - exportAssignSymbol?: Symbol; + exportAssignmentChecked?: boolean; + exportAssignmentSymbol?: Symbol; unionType?: UnionType; } interface TransientSymbol extends Symbol, SymbolLinks { diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index f7c67bdf1375f..90b06ebb8ca8d 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3332,11 +3332,11 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean - exportAssignChecked?: boolean; ->exportAssignChecked : boolean + exportAssignmentChecked?: boolean; +>exportAssignmentChecked : boolean - exportAssignSymbol?: Symbol; ->exportAssignSymbol : Symbol + exportAssignmentSymbol?: Symbol; +>exportAssignmentSymbol : Symbol >Symbol : Symbol unionType?: UnionType; diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index ea1869d0ce85b..d083c54673e8f 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1070,8 +1070,8 @@ declare module "typescript" { declaredType?: Type; mapper?: TypeMapper; referenced?: boolean; - exportAssignChecked?: boolean; - exportAssignSymbol?: Symbol; + exportAssignmentChecked?: boolean; + exportAssignmentSymbol?: Symbol; unionType?: UnionType; } interface TransientSymbol extends Symbol, SymbolLinks { diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index a5855217ea99c..e4cffc16aa1dd 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3505,11 +3505,11 @@ declare module "typescript" { referenced?: boolean; >referenced : boolean - exportAssignChecked?: boolean; ->exportAssignChecked : boolean + exportAssignmentChecked?: boolean; +>exportAssignmentChecked : boolean - exportAssignSymbol?: Symbol; ->exportAssignSymbol : Symbol + exportAssignmentSymbol?: Symbol; +>exportAssignmentSymbol : Symbol >Symbol : Symbol unionType?: UnionType; From 79be0a7d26bcedc2d59b121f5f3cbc47923f5854 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 12 Feb 2015 18:05:02 -0800 Subject: [PATCH 37/46] Support for ES6 export declarations (except export default and export *) --- src/compiler/binder.ts | 58 +++++++------- src/compiler/checker.ts | 47 ++++++++--- src/compiler/emitter.ts | 122 +++++++++++++++++++++++------ src/compiler/parser.ts | 161 ++++++++++++++++++++++++-------------- src/compiler/program.ts | 4 +- src/compiler/types.ts | 28 +++++-- src/compiler/utilities.ts | 6 +- 7 files changed, 293 insertions(+), 133 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5a4a983537a2e..4bd562291d5ef 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -15,11 +15,11 @@ module ts { if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) { return ModuleInstanceState.NonInstantiated; } - // 2. const enum declarations don't make module instantiated + // 2. const enum declarations else if (isConstEnumDeclaration(node)) { return ModuleInstanceState.ConstEnumOnly; } - // 3. non - exported import declarations + // 3. non-exported import declarations else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && !(node.flags & NodeFlags.Export)) { return ModuleInstanceState.NonInstantiated; } @@ -185,42 +185,39 @@ module ts { } function declareModuleMember(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { - // Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue, - // ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set - // on it. There are 2 main reasons: - // - // 1. We treat locals and exports of the same name as mutually exclusive within a container. - // That means the binder will issue a Duplicate Identifier error if you mix locals and exports - // with the same name in the same container. - // TODO: Make this a more specific error and decouple it from the exclusion logic. - // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol, - // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way - // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. - var exportKind = 0; - if (symbolKind & SymbolFlags.Value) { - exportKind |= SymbolFlags.ExportValue; - } - if (symbolKind & SymbolFlags.Type) { - exportKind |= SymbolFlags.ExportType; - } - if (symbolKind & SymbolFlags.Namespace) { - exportKind |= SymbolFlags.ExportNamespace; + var hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export; + if (symbolKind & SymbolFlags.Import) { + if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) { + declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + } + else { + declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + } } - - if (getCombinedNodeFlags(node) & NodeFlags.Export || - (node.kind !== SyntaxKind.ImportDeclaration && node.kind !== SyntaxKind.ImportEqualsDeclaration && isAmbientContext(container))) { - if (exportKind) { + else { + // Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue, + // ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set + // on it. There are 2 main reasons: + // + // 1. We treat locals and exports of the same name as mutually exclusive within a container. + // That means the binder will issue a Duplicate Identifier error if you mix locals and exports + // with the same name in the same container. + // TODO: Make this a more specific error and decouple it from the exclusion logic. + // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol, + // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way + // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. + if (hasExportModifier || isAmbientContext(container)) { + var exportKind = (symbolKind & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) | + (symbolKind & SymbolFlags.Type ? SymbolFlags.ExportType : 0) | + (symbolKind & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0); var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); node.localSymbol = local; } else { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); } } - else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); - } } // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function @@ -477,6 +474,7 @@ module ts { case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportSpecifier: bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.ImportClause: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 11b9de61b2631..743a39b48fc74 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -446,7 +446,8 @@ module ts { return node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ImportClause && !!(node).name || node.kind === SyntaxKind.NamespaceImport || - node.kind === SyntaxKind.ImportSpecifier; + node.kind === SyntaxKind.ImportSpecifier || + node.kind === SyntaxKind.ExportSpecifier; } function getDeclarationOfImportSymbol(symbol: Symbol): Declaration { @@ -477,10 +478,10 @@ module ts { return resolveExternalModuleName(node, (node.parent.parent).moduleSpecifier); } - function getTargetOfImportSpecifier(node: ImportSpecifier): Symbol { - var moduleSymbol = resolveExternalModuleName(node, (node.parent.parent.parent).moduleSpecifier); + function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier): Symbol { + var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); if (moduleSymbol) { - var name = node.propertyName || node.name; + var name = specifier.propertyName || specifier.name; if (name.text) { var symbol = getSymbol(moduleSymbol.exports, name.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); if (!symbol) { @@ -492,6 +493,16 @@ module ts { } } + function getTargetOfImportSpecifier(node: ImportSpecifier): Symbol { + return getExternalModuleMember(node.parent.parent.parent, node); + } + + function getTargetOfExportSpecifier(node: ExportSpecifier): Symbol { + return (node.parent.parent).moduleSpecifier ? + getExternalModuleMember(node.parent.parent, node) : + resolveEntityName(node, node.propertyName || node.name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + } + function getTargetOfImportDeclaration(node: Declaration): Symbol { switch (node.kind) { case SyntaxKind.ImportEqualsDeclaration: @@ -502,6 +513,8 @@ module ts { return getTargetOfNamespaceImport(node); case SyntaxKind.ImportSpecifier: return getTargetOfImportSpecifier(node); + case SyntaxKind.ExportSpecifier: + return getTargetOfExportSpecifier(node); } } @@ -9346,7 +9359,7 @@ module ts { } function checkExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration): boolean { - var moduleName = getImportedModuleName(node); + var moduleName = getExternalModuleName(node); if (getFullWidth(moduleName) !== 0 && moduleName.kind !== SyntaxKind.StringLiteral) { error(moduleName, Diagnostics.String_literal_expected); return false; @@ -10174,6 +10187,9 @@ module ts { case SyntaxKind.ImportDeclaration: generateNameForImportDeclaration(node); break; + case SyntaxKind.ExportDeclaration: + generateNameForExportDeclaration(node); + break; case SyntaxKind.SourceFile: case SyntaxKind.ModuleBlock: forEach((node).statements, generateNames); @@ -10219,17 +10235,27 @@ module ts { } } + function generateNameForImportOrExportDeclaration(node: ImportDeclaration | ExportDeclaration) { + var expr = getExternalModuleName(node); + var 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) { - var expr = getImportedModuleName(node); - var baseName = expr.kind === SyntaxKind.StringLiteral ? - escapeIdentifier(makeIdentifierFromModuleName((expr).text)) : "module"; - assignGeneratedName(node, makeUniqueName(baseName)); + generateNameForImportOrExportDeclaration(node); + } + } + + function generateNameForExportDeclaration(node: ExportDeclaration) { + if (node.moduleSpecifier) { + generateNameForImportOrExportDeclaration(node); } } } - function getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration) { + function getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration) { var links = getNodeLinks(node); if (!links.generatedName) { getGeneratedNamesForSourceFile(getSourceFile(node)); @@ -11322,6 +11348,7 @@ module ts { if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration || + node.kind === SyntaxKind.ExportDeclaration || node.kind === SyntaxKind.ExportAssignment || (node.flags & NodeFlags.Ambient)) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b05dd62a86fed..552c7201279eb 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -17,7 +17,7 @@ module ts { } interface ExternalImportInfo { - importNode: ImportDeclaration | ImportEqualsDeclaration; + rootNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration; declarationNode?: ImportEqualsDeclaration | ImportClause | NamespaceImport; namedImports?: NamedImports; } @@ -1568,6 +1568,7 @@ module ts { var tempVariables: Identifier[]; var tempParameters: Identifier[]; var externalImports: ExternalImportInfo[]; + var exportSpecifiers: Map; /** write emitted output to disk*/ var writeEmittedFiles = writeJavaScriptFile; @@ -3067,6 +3068,20 @@ module ts { emitEnd(node.name); } + function emitExportMemberAssignment(name: Identifier) { + if (exportSpecifiers && hasProperty(exportSpecifiers, name.text)) { + var exportName = exportSpecifiers[name.text].name; + writeLine(); + emitStart(exportName); + write("exports."); + emitNode(exportName); + emitEnd(exportName); + write(" = "); + emitNode(name); + write(";"); + } + } + function emitDestructuring(root: BinaryExpression | VariableDeclaration | ParameterDeclaration, value?: Expression) { var emitCount = 0; // An exported declaration is actually emitted as an assignment (to a property on the module object), so @@ -3299,6 +3314,16 @@ module ts { } } + function emitExportVariableAssignments(node: VariableDeclaration | BindingElement) { + var name = (node).name; + if (name.kind === SyntaxKind.Identifier) { + emitExportMemberAssignment(name); + } + else if (isBindingPattern(name)) { + forEach((name).elements, emitExportVariableAssignments); + } + } + function emitVariableStatement(node: VariableStatement) { if (!(node.flags & NodeFlags.Export)) { if (isLet(node.declarationList)) { @@ -3313,6 +3338,9 @@ module ts { } emitCommaList(node.declarationList.declarations); write(";"); + if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { + forEach(node.declarationList.declarations, emitExportVariableAssignments); + } } function emitParameter(node: ParameterDeclaration) { @@ -3437,6 +3465,9 @@ module ts { emit(node.name); } emitSignatureAndBody(node); + if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile) { + emitExportMemberAssignment((node).name); + } if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { emitTrailingComments(node); } @@ -3773,6 +3804,9 @@ module ts { emitEnd(node); write(";"); } + if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { + emitExportMemberAssignment(node.name); + } function emitConstructorOfClass() { var saveTempCount = tempCount; @@ -3899,6 +3933,9 @@ module ts { emitEnd(node); write(";"); } + if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { + emitExportMemberAssignment(node.name); + } } function emitEnumMember(node: EnumMember) { @@ -3997,6 +4034,9 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); + if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { + emitExportMemberAssignment(node.name); + } } function emitRequire(moduleName: Expression) { @@ -4013,13 +4053,6 @@ module ts { } } - function emitImportAssignment(node: Declaration, moduleName: Expression) { - if (!(node.flags & NodeFlags.Export)) write("var "); - emitModuleMemberName(node); - write(" = "); - emitRequire(moduleName); - } - function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { var info = getExternalImportInfo(node); if (info) { @@ -4028,7 +4061,7 @@ module ts { if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); - var moduleName = getImportedModuleName(node); + var moduleName = getExternalModuleName(node); if (declarationNode) { if (!(declarationNode.flags & NodeFlags.Export)) write("var "); emitModuleMemberName(declarationNode); @@ -4082,11 +4115,35 @@ module ts { } } + function emitExportDeclaration(node: ExportDeclaration) { + if (node.exportClause && node.moduleSpecifier) { + var generatedName = resolver.getGeneratedNameForNode(node); + emitStart(node); + write("var "); + write(generatedName); + write(" = "); + emitRequire(getExternalModuleName(node)); + forEach(node.exportClause.elements, specifier => { + writeLine(); + emitStart(specifier); + write("exports."); + emitNode(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNode(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + }); + emitEnd(node); + } + } + function createExternalImportInfo(node: Node): ExternalImportInfo { if (node.kind === SyntaxKind.ImportEqualsDeclaration) { if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { return { - importNode: node, + rootNode: node, declarationNode: node }; } @@ -4096,35 +4153,50 @@ module ts { if (importClause) { if (importClause.name) { return { - importNode: node, + rootNode: node, declarationNode: importClause }; } if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { return { - importNode: node, + rootNode: node, declarationNode: importClause.namedBindings }; } return { - importNode: node, + rootNode: node, namedImports: importClause.namedBindings, localName: resolver.getGeneratedNameForNode(node) }; } return { - importNode: node + rootNode: node + } + } + else if (node.kind === SyntaxKind.ExportDeclaration) { + if ((node).moduleSpecifier) { + return { + rootNode: node, + }; } } } - function createExternalImports(sourceFile: SourceFile) { + function createExternalModuleInfo(sourceFile: SourceFile) { externalImports = []; + exportSpecifiers = {}; forEach(sourceFile.statements, node => { - var info = createExternalImportInfo(node); - if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { - externalImports.push(info); + if (node.kind === SyntaxKind.ExportDeclaration && !(node).moduleSpecifier) { + forEach((node).exportClause.elements, e => { + exportSpecifiers[(e.propertyName || e.name).text] = e; + }); + } + else { + var info = createExternalImportInfo(node); + if (info) { + if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedImportDeclaration(node)) { + externalImports.push(info); + } } } }); @@ -4134,7 +4206,7 @@ module ts { if (externalImports) { for (var i = 0; i < externalImports.length; i++) { var info = externalImports[i]; - if (info.importNode === node) { + if (info.rootNode === node) { return info; } } @@ -4158,7 +4230,7 @@ module ts { write("[\"require\", \"exports\""); forEach(externalImports, info => { write(", "); - var moduleName = getImportedModuleName(info.importNode); + var moduleName = getExternalModuleName(info.rootNode); if (moduleName.kind === SyntaxKind.StringLiteral) { emitLiteral(moduleName); } @@ -4178,7 +4250,7 @@ module ts { emit(info.declarationNode.name); } else { - write(resolver.getGeneratedNameForNode(info.importNode)); + write(resolver.getGeneratedNameForNode(info.rootNode)); } }); write(") {"); @@ -4263,7 +4335,7 @@ module ts { extendsEmitted = true; } if (isExternalModule(node)) { - createExternalImports(node); + createExternalModuleInfo(node); if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } @@ -4272,6 +4344,8 @@ module ts { } } else { + externalImports = undefined; + exportSpecifiers = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); @@ -4474,6 +4548,8 @@ module ts { return emitImportDeclaration(node); case SyntaxKind.ImportEqualsDeclaration: return emitImportEqualsDeclaration(node); + case SyntaxKind.ExportDeclaration: + return emitExportDeclaration(node); case SyntaxKind.SourceFile: return emitSourceFile(node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 76b1f2cb32b64..a9e2a98bab8c2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -261,10 +261,16 @@ module ts { case SyntaxKind.NamespaceImport: return visitNode(cbNode, (node).name); case SyntaxKind.NamedImports: - return visitNodes(cbNodes, (node).elements); + case SyntaxKind.NamedExports: + return visitNodes(cbNodes, (node).elements); + case SyntaxKind.ExportDeclaration: + return visitNodes(cbNodes, node.modifiers) || + visitNode(cbNode, (node).exportClause) || + visitNode(cbNode, (node).moduleSpecifier); case SyntaxKind.ImportSpecifier: - return visitNode(cbNode, (node).propertyName) || - visitNode(cbNode, (node).name); + case SyntaxKind.ExportSpecifier: + return visitNode(cbNode, (node).propertyName) || + visitNode(cbNode, (node).name); case SyntaxKind.ExportAssignment: return visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportName); @@ -282,28 +288,28 @@ module ts { } const enum ParsingContext { - SourceElements, // Elements in source file - ModuleElements, // Elements in module declaration - BlockStatements, // Statements in block - SwitchClauses, // Clauses in switch statement - SwitchClauseStatements, // Statements in switch clause - TypeMembers, // Members in interface or type literal - ClassMembers, // Members in class declaration - EnumMembers, // Members in enum declaration - TypeReferences, // Type references in extends or implements clause - VariableDeclarations, // Variable declarations in variable statement - ObjectBindingElements, // Binding elements in object binding list - ArrayBindingElements, // Binding elements in array binding list - ArgumentExpressions, // Expressions in argument list - ObjectLiteralMembers, // Members in object literal - ArrayLiteralMembers, // Members in array literal - Parameters, // Parameters in parameter list - TypeParameters, // Type parameters in type parameter list - TypeArguments, // Type arguments in type argument list - TupleElementTypes, // Element types in tuple element type list - HeritageClauses, // Heritage clauses for a class or interface declaration. - ImportSpecifiers, // Named import clause's import specifier list - Count // Number of parsing contexts + SourceElements, // Elements in source file + ModuleElements, // Elements in module declaration + BlockStatements, // Statements in block + SwitchClauses, // Clauses in switch statement + SwitchClauseStatements, // Statements in switch clause + TypeMembers, // Members in interface or type literal + ClassMembers, // Members in class declaration + EnumMembers, // Members in enum declaration + TypeReferences, // Type references in extends or implements clause + VariableDeclarations, // Variable declarations in variable statement + ObjectBindingElements, // Binding elements in object binding list + ArrayBindingElements, // Binding elements in array binding list + ArgumentExpressions, // Expressions in argument list + ObjectLiteralMembers, // Members in object literal + ArrayLiteralMembers, // Members in array literal + Parameters, // Parameters in parameter list + TypeParameters, // Type parameters in type parameter list + TypeArguments, // Type arguments in type argument list + TupleElementTypes, // Element types in tuple element type list + HeritageClauses, // Heritage clauses for a class or interface declaration. + ImportOrExportSpecifiers, // Named import clause's import specifier list + Count // Number of parsing contexts } const enum Tristate { @@ -314,27 +320,27 @@ module ts { function parsingContextErrors(context: ParsingContext): DiagnosticMessage { switch (context) { - case ParsingContext.SourceElements: return Diagnostics.Declaration_or_statement_expected; - case ParsingContext.ModuleElements: return Diagnostics.Declaration_or_statement_expected; - case ParsingContext.BlockStatements: return Diagnostics.Statement_expected; - case ParsingContext.SwitchClauses: return Diagnostics.case_or_default_expected; - case ParsingContext.SwitchClauseStatements: return Diagnostics.Statement_expected; - case ParsingContext.TypeMembers: return Diagnostics.Property_or_signature_expected; - case ParsingContext.ClassMembers: return Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected; - case ParsingContext.EnumMembers: return Diagnostics.Enum_member_expected; - case ParsingContext.TypeReferences: return Diagnostics.Type_reference_expected; - case ParsingContext.VariableDeclarations: return Diagnostics.Variable_declaration_expected; - case ParsingContext.ObjectBindingElements: return Diagnostics.Property_destructuring_pattern_expected; - case ParsingContext.ArrayBindingElements: return Diagnostics.Array_element_destructuring_pattern_expected; - case ParsingContext.ArgumentExpressions: return Diagnostics.Argument_expression_expected; - case ParsingContext.ObjectLiteralMembers: return Diagnostics.Property_assignment_expected; - case ParsingContext.ArrayLiteralMembers: return Diagnostics.Expression_or_comma_expected; - case ParsingContext.Parameters: return Diagnostics.Parameter_declaration_expected; - case ParsingContext.TypeParameters: return Diagnostics.Type_parameter_declaration_expected; - case ParsingContext.TypeArguments: return Diagnostics.Type_argument_expected; - case ParsingContext.TupleElementTypes: return Diagnostics.Type_expected; - case ParsingContext.HeritageClauses: return Diagnostics.Unexpected_token_expected; - case ParsingContext.ImportSpecifiers: return Diagnostics.Identifier_expected; + case ParsingContext.SourceElements: return Diagnostics.Declaration_or_statement_expected; + case ParsingContext.ModuleElements: return Diagnostics.Declaration_or_statement_expected; + case ParsingContext.BlockStatements: return Diagnostics.Statement_expected; + case ParsingContext.SwitchClauses: return Diagnostics.case_or_default_expected; + case ParsingContext.SwitchClauseStatements: return Diagnostics.Statement_expected; + case ParsingContext.TypeMembers: return Diagnostics.Property_or_signature_expected; + case ParsingContext.ClassMembers: return Diagnostics.Unexpected_token_A_constructor_method_accessor_or_property_was_expected; + case ParsingContext.EnumMembers: return Diagnostics.Enum_member_expected; + case ParsingContext.TypeReferences: return Diagnostics.Type_reference_expected; + case ParsingContext.VariableDeclarations: return Diagnostics.Variable_declaration_expected; + case ParsingContext.ObjectBindingElements: return Diagnostics.Property_destructuring_pattern_expected; + case ParsingContext.ArrayBindingElements: return Diagnostics.Array_element_destructuring_pattern_expected; + case ParsingContext.ArgumentExpressions: return Diagnostics.Argument_expression_expected; + case ParsingContext.ObjectLiteralMembers: return Diagnostics.Property_assignment_expected; + case ParsingContext.ArrayLiteralMembers: return Diagnostics.Expression_or_comma_expected; + case ParsingContext.Parameters: return Diagnostics.Parameter_declaration_expected; + case ParsingContext.TypeParameters: return Diagnostics.Type_parameter_declaration_expected; + case ParsingContext.TypeArguments: return Diagnostics.Type_argument_expected; + case ParsingContext.TupleElementTypes: return Diagnostics.Type_expected; + case ParsingContext.HeritageClauses: return Diagnostics.Unexpected_token_expected; + case ParsingContext.ImportOrExportSpecifiers: return Diagnostics.Identifier_expected; } }; @@ -1481,7 +1487,10 @@ module ts { // 'const' is only a modifier if followed by 'enum'. return nextToken() === SyntaxKind.EnumKeyword; } - + if (token === SyntaxKind.ExportKeyword) { + nextToken(); + return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.OpenBraceToken && canFollowModifier(); + } nextToken(); return canFollowModifier(); } @@ -1541,7 +1550,7 @@ module ts { return token === SyntaxKind.CommaToken || isStartOfType(); case ParsingContext.HeritageClauses: return isHeritageClause(); - case ParsingContext.ImportSpecifiers: + case ParsingContext.ImportOrExportSpecifiers: return isIdentifierOrKeyword(); } @@ -1579,7 +1588,7 @@ module ts { case ParsingContext.EnumMembers: case ParsingContext.ObjectLiteralMembers: case ParsingContext.ObjectBindingElements: - case ParsingContext.ImportSpecifiers: + case ParsingContext.ImportOrExportSpecifiers: return token === SyntaxKind.CloseBraceToken; case ParsingContext.SwitchClauseStatements: return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; @@ -4671,7 +4680,7 @@ module ts { // parse namespace or named imports if (!importClause.name || parseOptional(SyntaxKind.CommaToken)) { - importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImports(); + importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImportsOrExports(SyntaxKind.NamedImports); } return finishNode(importClause); @@ -4715,8 +4724,8 @@ module ts { return finishNode(namespaceImport); } - function parseNamedImports(): NamedImports { - var namedImports = createNode(SyntaxKind.NamedImports); + function parseNamedImportsOrExports(kind: SyntaxKind): NamedImportsOrExports { + var node = createNode(kind); // NamedImports: // { } @@ -4726,12 +4735,22 @@ module ts { // ImportsList: // ImportSpecifier // ImportsList, ImportSpecifier - namedImports.elements = parseBracketedList(ParsingContext.ImportSpecifiers, parseImportSpecifier, SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken); - return finishNode(namedImports); + node.elements = parseBracketedList(ParsingContext.ImportOrExportSpecifiers, + kind === SyntaxKind.NamedImports ? parseImportSpecifier : parseExportSpecifier, + SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken); + return finishNode(node); } - function parseImportSpecifier(): ImportSpecifier { - var node = createNode(SyntaxKind.ImportSpecifier); + function parseExportSpecifier() { + return parseImportOrExportSpecifier(SyntaxKind.ExportSpecifier); + } + + function parseImportSpecifier() { + return parseImportOrExportSpecifier(SyntaxKind.ImportSpecifier); + } + + function parseImportOrExportSpecifier(kind: SyntaxKind): ImportOrExportSpecifier { + var node = createNode(kind); // ImportSpecifier: // ImportedBinding // IdentifierName as ImportedBinding @@ -4759,6 +4778,23 @@ module ts { return finishNode(node); } + function parseExportDeclaration(fullStart: number, modifiers: ModifiersArray): ExportDeclaration { + var node = createNode(SyntaxKind.ExportDeclaration, fullStart); + setModifiers(node, modifiers); + if (parseOptional(SyntaxKind.AsteriskToken)) { + parseExpected(SyntaxKind.FromKeyword); + node.moduleSpecifier = parseModuleSpecifier(); + } + else { + node.exportClause = parseNamedImportsOrExports(SyntaxKind.NamedExports); + if (parseOptional(SyntaxKind.FromKeyword)) { + node.moduleSpecifier = parseModuleSpecifier(); + } + } + parseSemicolon(); + return finishNode(node); + } + function parseExportAssignmentTail(fullStart: number, modifiers: ModifiersArray): ExportAssignment { var node = createNode(SyntaxKind.ExportAssignment, fullStart); setModifiers(node, modifiers); @@ -4795,7 +4831,7 @@ module ts { return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); case SyntaxKind.ExportKeyword: // Check for export assignment or modifier on source element - return lookAhead(nextTokenIsEqualsTokenOrDeclarationStart); + return lookAhead(nextTokenCanFollowExportKeyword); case SyntaxKind.DeclareKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: @@ -4826,9 +4862,10 @@ module ts { token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken; } - function nextTokenIsEqualsTokenOrDeclarationStart() { + function nextTokenCanFollowExportKeyword() { nextToken(); - return token === SyntaxKind.EqualsToken || isDeclarationStart(); + return token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || + token === SyntaxKind.OpenBraceToken || isDeclarationStart(); } function nextTokenIsDeclarationStart() { @@ -4848,6 +4885,9 @@ module ts { if (parseOptional(SyntaxKind.EqualsToken)) { return parseExportAssignmentTail(fullStart, modifiers); } + if (token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken) { + return parseExportDeclaration(fullStart, modifiers); + } } switch (token) { @@ -4952,8 +4992,9 @@ module ts { sourceFile.externalModuleIndicator = forEach(sourceFile.statements, node => node.flags & NodeFlags.Export || node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind === SyntaxKind.ExternalModuleReference - || node.kind === SyntaxKind.ExportAssignment || node.kind === SyntaxKind.ImportDeclaration + || node.kind === SyntaxKind.ExportAssignment + || node.kind === SyntaxKind.ExportDeclaration ? node : undefined); } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ade6141952aad..b74ef039fd6d7 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -351,8 +351,8 @@ module ts { function processImportedModules(file: SourceFile, basePath: string) { forEach(file.statements, node => { - if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) { - var moduleNameExpr = getImportedModuleName(node); + if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration) { + var moduleNameExpr = getExternalModuleName(node); if (moduleNameExpr && moduleNameExpr.kind === SyntaxKind.StringLiteral) { var moduleNameText = (moduleNameExpr).text; if (moduleNameText) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 83cd99392c01b..53aa08dae7786 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -231,12 +231,15 @@ module ts { ModuleDeclaration, ModuleBlock, ImportEqualsDeclaration, - ExportAssignment, ImportDeclaration, ImportClause, NamespaceImport, NamedImports, ImportSpecifier, + ExportAssignment, + ExportDeclaration, + NamedExports, + ExportSpecifier, // Module references ExternalModuleReference, @@ -898,15 +901,26 @@ module ts { name: Identifier; } - export interface NamedImports extends Node { - elements: NodeArray; + export interface ExportDeclaration extends Statement, ModuleElement { + exportClause?: NamedExports; + moduleSpecifier?: Expression; + } + + export interface NamedImportsOrExports extends Node { + elements: NodeArray; } - export interface ImportSpecifier extends Declaration { - propertyName?: Identifier; // Property name to be imported from module - name: Identifier; // element name to be imported in the scope + export type NamedImports = NamedImportsOrExports; + export type NamedExports = NamedImportsOrExports; + + export interface ImportOrExportSpecifier extends Declaration { + propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent) + name: Identifier; // Declared name } + export type ImportSpecifier = ImportOrExportSpecifier; + export type ExportSpecifier = ImportOrExportSpecifier; + export interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -1163,7 +1177,7 @@ module ts { } export interface EmitResolver { - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9283064d7db68..7c6b4d0be9605 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -603,7 +603,7 @@ module ts { return node.kind === SyntaxKind.ImportEqualsDeclaration && (node).moduleReference.kind !== SyntaxKind.ExternalModuleReference; } - export function getImportedModuleName(node: Node): Expression { + export function getExternalModuleName(node: Node): Expression { if (node.kind === SyntaxKind.ImportDeclaration) { return (node).moduleSpecifier; } @@ -613,6 +613,9 @@ module ts { return (reference).expression; } } + if (node.kind === SyntaxKind.ExportDeclaration) { + return (node).moduleSpecifier; + } } export function hasDotDotDotToken(node: Node) { @@ -695,6 +698,7 @@ module ts { case SyntaxKind.ImportClause: case SyntaxKind.ImportSpecifier: case SyntaxKind.NamespaceImport: + case SyntaxKind.ExportSpecifier: return true; } return false; From 6c47c326a9b52245edfbad2b2cb2decabcac91a4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 12 Feb 2015 18:05:50 -0800 Subject: [PATCH 38/46] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 53 +++++---- .../reference/APISample_compile.types | 101 ++++++++++++------ tests/baselines/reference/APISample_linter.js | 53 +++++---- .../reference/APISample_linter.types | 101 ++++++++++++------ .../reference/APISample_transform.js | 53 +++++---- .../reference/APISample_transform.types | 101 ++++++++++++------ .../baselines/reference/APISample_watcher.js | 53 +++++---- .../reference/APISample_watcher.types | 101 ++++++++++++------ 8 files changed, 408 insertions(+), 208 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index eeb78ce8250b7..9f75f86dc1c85 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -259,23 +259,26 @@ declare module "typescript" { ModuleDeclaration = 197, ModuleBlock = 198, ImportEqualsDeclaration = 199, - ExportAssignment = 200, - ImportDeclaration = 201, - ImportClause = 202, - NamespaceImport = 203, - NamedImports = 204, - ImportSpecifier = 205, - ExternalModuleReference = 206, - CaseClause = 207, - DefaultClause = 208, - HeritageClause = 209, - CatchClause = 210, - PropertyAssignment = 211, - ShorthandPropertyAssignment = 212, - EnumMember = 213, - SourceFile = 214, - SyntaxList = 215, - Count = 216, + ImportDeclaration = 200, + ImportClause = 201, + NamespaceImport = 202, + NamedImports = 203, + ImportSpecifier = 204, + ExportAssignment = 205, + ExportDeclaration = 206, + NamedExports = 207, + ExportSpecifier = 208, + ExternalModuleReference = 209, + CaseClause = 210, + DefaultClause = 211, + HeritageClause = 212, + CatchClause = 213, + PropertyAssignment = 214, + ShorthandPropertyAssignment = 215, + EnumMember = 216, + SourceFile = 217, + SyntaxList = 218, + Count = 219, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -727,13 +730,21 @@ declare module "typescript" { interface NamespaceImport extends Declaration { name: Identifier; } - interface NamedImports extends Node { - elements: NodeArray; + interface ExportDeclaration extends Statement, ModuleElement { + exportClause?: NamedExports; + moduleSpecifier?: Expression; } - interface ImportSpecifier extends Declaration { + interface NamedImportsOrExports extends Node { + elements: NodeArray; + } + type NamedImports = NamedImportsOrExports; + type NamedExports = NamedImportsOrExports; + interface ImportOrExportSpecifier extends Declaration { propertyName?: Identifier; name: Identifier; } + type ImportSpecifier = ImportOrExportSpecifier; + type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -902,7 +913,7 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index b85d0132a0432..b992b3ba1196a 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -793,55 +793,64 @@ declare module "typescript" { ImportEqualsDeclaration = 199, >ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 200, ->ExportAssignment : SyntaxKind - - ImportDeclaration = 201, + ImportDeclaration = 200, >ImportDeclaration : SyntaxKind - ImportClause = 202, + ImportClause = 201, >ImportClause : SyntaxKind - NamespaceImport = 203, + NamespaceImport = 202, >NamespaceImport : SyntaxKind - NamedImports = 204, + NamedImports = 203, >NamedImports : SyntaxKind - ImportSpecifier = 205, + ImportSpecifier = 204, >ImportSpecifier : SyntaxKind - ExternalModuleReference = 206, + ExportAssignment = 205, +>ExportAssignment : SyntaxKind + + ExportDeclaration = 206, +>ExportDeclaration : SyntaxKind + + NamedExports = 207, +>NamedExports : SyntaxKind + + ExportSpecifier = 208, +>ExportSpecifier : SyntaxKind + + ExternalModuleReference = 209, >ExternalModuleReference : SyntaxKind - CaseClause = 207, + CaseClause = 210, >CaseClause : SyntaxKind - DefaultClause = 208, + DefaultClause = 211, >DefaultClause : SyntaxKind - HeritageClause = 209, + HeritageClause = 212, >HeritageClause : SyntaxKind - CatchClause = 210, + CatchClause = 213, >CatchClause : SyntaxKind - PropertyAssignment = 211, + PropertyAssignment = 214, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 212, + ShorthandPropertyAssignment = 215, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 213, + EnumMember = 216, >EnumMember : SyntaxKind - SourceFile = 214, + SourceFile = 217, >SourceFile : SyntaxKind - SyntaxList = 215, + SyntaxList = 218, >SyntaxList : SyntaxKind - Count = 216, + Count = 219, >Count : SyntaxKind FirstAssignment = 52, @@ -2196,9 +2205,9 @@ declare module "typescript" { >Identifier : Identifier namedBindings?: NamespaceImport | NamedImports; ->namedBindings : NamespaceImport | NamedImports +>namedBindings : NamespaceImport | NamedImportsOrExports >NamespaceImport : NamespaceImport ->NamedImports : NamedImports +>NamedImports : NamedImportsOrExports } interface NamespaceImport extends Declaration { >NamespaceImport : NamespaceImport @@ -2208,17 +2217,38 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } - interface NamedImports extends Node { ->NamedImports : NamedImports + interface ExportDeclaration extends Statement, ModuleElement { +>ExportDeclaration : ExportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + exportClause?: NamedExports; +>exportClause : NamedImportsOrExports +>NamedExports : NamedImportsOrExports + + moduleSpecifier?: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface NamedImportsOrExports extends Node { +>NamedImportsOrExports : NamedImportsOrExports >Node : Node - elements: NodeArray; ->elements : NodeArray + elements: NodeArray; +>elements : NodeArray >NodeArray : NodeArray ->ImportSpecifier : ImportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier } - interface ImportSpecifier extends Declaration { ->ImportSpecifier : ImportSpecifier + type NamedImports = NamedImportsOrExports; +>NamedImports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + type NamedExports = NamedImportsOrExports; +>NamedExports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + interface ImportOrExportSpecifier extends Declaration { +>ImportOrExportSpecifier : ImportOrExportSpecifier >Declaration : Declaration propertyName?: Identifier; @@ -2229,6 +2259,14 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } + type ImportSpecifier = ImportOrExportSpecifier; +>ImportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + + type ExportSpecifier = ImportOrExportSpecifier; +>ExportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment >Statement : Statement @@ -2882,12 +2920,13 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration +>ExportDeclaration : ExportDeclaration getExpressionNameSubstitution(node: Identifier): string; >getExpressionNameSubstitution : (node: Identifier) => string diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 1a5e652080594..0ec2bf4f77c57 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -290,23 +290,26 @@ declare module "typescript" { ModuleDeclaration = 197, ModuleBlock = 198, ImportEqualsDeclaration = 199, - ExportAssignment = 200, - ImportDeclaration = 201, - ImportClause = 202, - NamespaceImport = 203, - NamedImports = 204, - ImportSpecifier = 205, - ExternalModuleReference = 206, - CaseClause = 207, - DefaultClause = 208, - HeritageClause = 209, - CatchClause = 210, - PropertyAssignment = 211, - ShorthandPropertyAssignment = 212, - EnumMember = 213, - SourceFile = 214, - SyntaxList = 215, - Count = 216, + ImportDeclaration = 200, + ImportClause = 201, + NamespaceImport = 202, + NamedImports = 203, + ImportSpecifier = 204, + ExportAssignment = 205, + ExportDeclaration = 206, + NamedExports = 207, + ExportSpecifier = 208, + ExternalModuleReference = 209, + CaseClause = 210, + DefaultClause = 211, + HeritageClause = 212, + CatchClause = 213, + PropertyAssignment = 214, + ShorthandPropertyAssignment = 215, + EnumMember = 216, + SourceFile = 217, + SyntaxList = 218, + Count = 219, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -758,13 +761,21 @@ declare module "typescript" { interface NamespaceImport extends Declaration { name: Identifier; } - interface NamedImports extends Node { - elements: NodeArray; + interface ExportDeclaration extends Statement, ModuleElement { + exportClause?: NamedExports; + moduleSpecifier?: Expression; } - interface ImportSpecifier extends Declaration { + interface NamedImportsOrExports extends Node { + elements: NodeArray; + } + type NamedImports = NamedImportsOrExports; + type NamedExports = NamedImportsOrExports; + interface ImportOrExportSpecifier extends Declaration { propertyName?: Identifier; name: Identifier; } + type ImportSpecifier = ImportOrExportSpecifier; + type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -933,7 +944,7 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index f8f4b6bd199d1..3bb894b55de83 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -937,55 +937,64 @@ declare module "typescript" { ImportEqualsDeclaration = 199, >ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 200, ->ExportAssignment : SyntaxKind - - ImportDeclaration = 201, + ImportDeclaration = 200, >ImportDeclaration : SyntaxKind - ImportClause = 202, + ImportClause = 201, >ImportClause : SyntaxKind - NamespaceImport = 203, + NamespaceImport = 202, >NamespaceImport : SyntaxKind - NamedImports = 204, + NamedImports = 203, >NamedImports : SyntaxKind - ImportSpecifier = 205, + ImportSpecifier = 204, >ImportSpecifier : SyntaxKind - ExternalModuleReference = 206, + ExportAssignment = 205, +>ExportAssignment : SyntaxKind + + ExportDeclaration = 206, +>ExportDeclaration : SyntaxKind + + NamedExports = 207, +>NamedExports : SyntaxKind + + ExportSpecifier = 208, +>ExportSpecifier : SyntaxKind + + ExternalModuleReference = 209, >ExternalModuleReference : SyntaxKind - CaseClause = 207, + CaseClause = 210, >CaseClause : SyntaxKind - DefaultClause = 208, + DefaultClause = 211, >DefaultClause : SyntaxKind - HeritageClause = 209, + HeritageClause = 212, >HeritageClause : SyntaxKind - CatchClause = 210, + CatchClause = 213, >CatchClause : SyntaxKind - PropertyAssignment = 211, + PropertyAssignment = 214, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 212, + ShorthandPropertyAssignment = 215, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 213, + EnumMember = 216, >EnumMember : SyntaxKind - SourceFile = 214, + SourceFile = 217, >SourceFile : SyntaxKind - SyntaxList = 215, + SyntaxList = 218, >SyntaxList : SyntaxKind - Count = 216, + Count = 219, >Count : SyntaxKind FirstAssignment = 52, @@ -2340,9 +2349,9 @@ declare module "typescript" { >Identifier : Identifier namedBindings?: NamespaceImport | NamedImports; ->namedBindings : NamespaceImport | NamedImports +>namedBindings : NamespaceImport | NamedImportsOrExports >NamespaceImport : NamespaceImport ->NamedImports : NamedImports +>NamedImports : NamedImportsOrExports } interface NamespaceImport extends Declaration { >NamespaceImport : NamespaceImport @@ -2352,17 +2361,38 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } - interface NamedImports extends Node { ->NamedImports : NamedImports + interface ExportDeclaration extends Statement, ModuleElement { +>ExportDeclaration : ExportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + exportClause?: NamedExports; +>exportClause : NamedImportsOrExports +>NamedExports : NamedImportsOrExports + + moduleSpecifier?: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface NamedImportsOrExports extends Node { +>NamedImportsOrExports : NamedImportsOrExports >Node : Node - elements: NodeArray; ->elements : NodeArray + elements: NodeArray; +>elements : NodeArray >NodeArray : NodeArray ->ImportSpecifier : ImportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier } - interface ImportSpecifier extends Declaration { ->ImportSpecifier : ImportSpecifier + type NamedImports = NamedImportsOrExports; +>NamedImports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + type NamedExports = NamedImportsOrExports; +>NamedExports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + interface ImportOrExportSpecifier extends Declaration { +>ImportOrExportSpecifier : ImportOrExportSpecifier >Declaration : Declaration propertyName?: Identifier; @@ -2373,6 +2403,14 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } + type ImportSpecifier = ImportOrExportSpecifier; +>ImportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + + type ExportSpecifier = ImportOrExportSpecifier; +>ExportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment >Statement : Statement @@ -3026,12 +3064,13 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration +>ExportDeclaration : ExportDeclaration getExpressionNameSubstitution(node: Identifier): string; >getExpressionNameSubstitution : (node: Identifier) => string diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 295d45c220e95..1627415c83498 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -291,23 +291,26 @@ declare module "typescript" { ModuleDeclaration = 197, ModuleBlock = 198, ImportEqualsDeclaration = 199, - ExportAssignment = 200, - ImportDeclaration = 201, - ImportClause = 202, - NamespaceImport = 203, - NamedImports = 204, - ImportSpecifier = 205, - ExternalModuleReference = 206, - CaseClause = 207, - DefaultClause = 208, - HeritageClause = 209, - CatchClause = 210, - PropertyAssignment = 211, - ShorthandPropertyAssignment = 212, - EnumMember = 213, - SourceFile = 214, - SyntaxList = 215, - Count = 216, + ImportDeclaration = 200, + ImportClause = 201, + NamespaceImport = 202, + NamedImports = 203, + ImportSpecifier = 204, + ExportAssignment = 205, + ExportDeclaration = 206, + NamedExports = 207, + ExportSpecifier = 208, + ExternalModuleReference = 209, + CaseClause = 210, + DefaultClause = 211, + HeritageClause = 212, + CatchClause = 213, + PropertyAssignment = 214, + ShorthandPropertyAssignment = 215, + EnumMember = 216, + SourceFile = 217, + SyntaxList = 218, + Count = 219, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -759,13 +762,21 @@ declare module "typescript" { interface NamespaceImport extends Declaration { name: Identifier; } - interface NamedImports extends Node { - elements: NodeArray; + interface ExportDeclaration extends Statement, ModuleElement { + exportClause?: NamedExports; + moduleSpecifier?: Expression; } - interface ImportSpecifier extends Declaration { + interface NamedImportsOrExports extends Node { + elements: NodeArray; + } + type NamedImports = NamedImportsOrExports; + type NamedExports = NamedImportsOrExports; + interface ImportOrExportSpecifier extends Declaration { propertyName?: Identifier; name: Identifier; } + type ImportSpecifier = ImportOrExportSpecifier; + type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -934,7 +945,7 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 90b06ebb8ca8d..9d0dbdb0768a3 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -889,55 +889,64 @@ declare module "typescript" { ImportEqualsDeclaration = 199, >ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 200, ->ExportAssignment : SyntaxKind - - ImportDeclaration = 201, + ImportDeclaration = 200, >ImportDeclaration : SyntaxKind - ImportClause = 202, + ImportClause = 201, >ImportClause : SyntaxKind - NamespaceImport = 203, + NamespaceImport = 202, >NamespaceImport : SyntaxKind - NamedImports = 204, + NamedImports = 203, >NamedImports : SyntaxKind - ImportSpecifier = 205, + ImportSpecifier = 204, >ImportSpecifier : SyntaxKind - ExternalModuleReference = 206, + ExportAssignment = 205, +>ExportAssignment : SyntaxKind + + ExportDeclaration = 206, +>ExportDeclaration : SyntaxKind + + NamedExports = 207, +>NamedExports : SyntaxKind + + ExportSpecifier = 208, +>ExportSpecifier : SyntaxKind + + ExternalModuleReference = 209, >ExternalModuleReference : SyntaxKind - CaseClause = 207, + CaseClause = 210, >CaseClause : SyntaxKind - DefaultClause = 208, + DefaultClause = 211, >DefaultClause : SyntaxKind - HeritageClause = 209, + HeritageClause = 212, >HeritageClause : SyntaxKind - CatchClause = 210, + CatchClause = 213, >CatchClause : SyntaxKind - PropertyAssignment = 211, + PropertyAssignment = 214, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 212, + ShorthandPropertyAssignment = 215, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 213, + EnumMember = 216, >EnumMember : SyntaxKind - SourceFile = 214, + SourceFile = 217, >SourceFile : SyntaxKind - SyntaxList = 215, + SyntaxList = 218, >SyntaxList : SyntaxKind - Count = 216, + Count = 219, >Count : SyntaxKind FirstAssignment = 52, @@ -2292,9 +2301,9 @@ declare module "typescript" { >Identifier : Identifier namedBindings?: NamespaceImport | NamedImports; ->namedBindings : NamespaceImport | NamedImports +>namedBindings : NamespaceImport | NamedImportsOrExports >NamespaceImport : NamespaceImport ->NamedImports : NamedImports +>NamedImports : NamedImportsOrExports } interface NamespaceImport extends Declaration { >NamespaceImport : NamespaceImport @@ -2304,17 +2313,38 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } - interface NamedImports extends Node { ->NamedImports : NamedImports + interface ExportDeclaration extends Statement, ModuleElement { +>ExportDeclaration : ExportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + exportClause?: NamedExports; +>exportClause : NamedImportsOrExports +>NamedExports : NamedImportsOrExports + + moduleSpecifier?: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface NamedImportsOrExports extends Node { +>NamedImportsOrExports : NamedImportsOrExports >Node : Node - elements: NodeArray; ->elements : NodeArray + elements: NodeArray; +>elements : NodeArray >NodeArray : NodeArray ->ImportSpecifier : ImportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier } - interface ImportSpecifier extends Declaration { ->ImportSpecifier : ImportSpecifier + type NamedImports = NamedImportsOrExports; +>NamedImports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + type NamedExports = NamedImportsOrExports; +>NamedExports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + interface ImportOrExportSpecifier extends Declaration { +>ImportOrExportSpecifier : ImportOrExportSpecifier >Declaration : Declaration propertyName?: Identifier; @@ -2325,6 +2355,14 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } + type ImportSpecifier = ImportOrExportSpecifier; +>ImportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + + type ExportSpecifier = ImportOrExportSpecifier; +>ExportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment >Statement : Statement @@ -2978,12 +3016,13 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration +>ExportDeclaration : ExportDeclaration getExpressionNameSubstitution(node: Identifier): string; >getExpressionNameSubstitution : (node: Identifier) => string diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index d083c54673e8f..6c4c0977aaca5 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -328,23 +328,26 @@ declare module "typescript" { ModuleDeclaration = 197, ModuleBlock = 198, ImportEqualsDeclaration = 199, - ExportAssignment = 200, - ImportDeclaration = 201, - ImportClause = 202, - NamespaceImport = 203, - NamedImports = 204, - ImportSpecifier = 205, - ExternalModuleReference = 206, - CaseClause = 207, - DefaultClause = 208, - HeritageClause = 209, - CatchClause = 210, - PropertyAssignment = 211, - ShorthandPropertyAssignment = 212, - EnumMember = 213, - SourceFile = 214, - SyntaxList = 215, - Count = 216, + ImportDeclaration = 200, + ImportClause = 201, + NamespaceImport = 202, + NamedImports = 203, + ImportSpecifier = 204, + ExportAssignment = 205, + ExportDeclaration = 206, + NamedExports = 207, + ExportSpecifier = 208, + ExternalModuleReference = 209, + CaseClause = 210, + DefaultClause = 211, + HeritageClause = 212, + CatchClause = 213, + PropertyAssignment = 214, + ShorthandPropertyAssignment = 215, + EnumMember = 216, + SourceFile = 217, + SyntaxList = 218, + Count = 219, FirstAssignment = 52, LastAssignment = 63, FirstReservedWord = 65, @@ -796,13 +799,21 @@ declare module "typescript" { interface NamespaceImport extends Declaration { name: Identifier; } - interface NamedImports extends Node { - elements: NodeArray; + interface ExportDeclaration extends Statement, ModuleElement { + exportClause?: NamedExports; + moduleSpecifier?: Expression; } - interface ImportSpecifier extends Declaration { + interface NamedImportsOrExports extends Node { + elements: NodeArray; + } + type NamedImports = NamedImportsOrExports; + type NamedExports = NamedImportsOrExports; + interface ImportOrExportSpecifier extends Declaration { propertyName?: Identifier; name: Identifier; } + type ImportSpecifier = ImportOrExportSpecifier; + type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Statement, ModuleElement { exportName: Identifier; } @@ -971,7 +982,7 @@ declare module "typescript" { errorModuleName?: string; } interface EmitResolver { - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; getExpressionNameSubstitution(node: Identifier): string; getExportAssignmentName(node: SourceFile): string; isReferencedImportDeclaration(node: Node): boolean; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index e4cffc16aa1dd..fb342d09cdda5 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1062,55 +1062,64 @@ declare module "typescript" { ImportEqualsDeclaration = 199, >ImportEqualsDeclaration : SyntaxKind - ExportAssignment = 200, ->ExportAssignment : SyntaxKind - - ImportDeclaration = 201, + ImportDeclaration = 200, >ImportDeclaration : SyntaxKind - ImportClause = 202, + ImportClause = 201, >ImportClause : SyntaxKind - NamespaceImport = 203, + NamespaceImport = 202, >NamespaceImport : SyntaxKind - NamedImports = 204, + NamedImports = 203, >NamedImports : SyntaxKind - ImportSpecifier = 205, + ImportSpecifier = 204, >ImportSpecifier : SyntaxKind - ExternalModuleReference = 206, + ExportAssignment = 205, +>ExportAssignment : SyntaxKind + + ExportDeclaration = 206, +>ExportDeclaration : SyntaxKind + + NamedExports = 207, +>NamedExports : SyntaxKind + + ExportSpecifier = 208, +>ExportSpecifier : SyntaxKind + + ExternalModuleReference = 209, >ExternalModuleReference : SyntaxKind - CaseClause = 207, + CaseClause = 210, >CaseClause : SyntaxKind - DefaultClause = 208, + DefaultClause = 211, >DefaultClause : SyntaxKind - HeritageClause = 209, + HeritageClause = 212, >HeritageClause : SyntaxKind - CatchClause = 210, + CatchClause = 213, >CatchClause : SyntaxKind - PropertyAssignment = 211, + PropertyAssignment = 214, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 212, + ShorthandPropertyAssignment = 215, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 213, + EnumMember = 216, >EnumMember : SyntaxKind - SourceFile = 214, + SourceFile = 217, >SourceFile : SyntaxKind - SyntaxList = 215, + SyntaxList = 218, >SyntaxList : SyntaxKind - Count = 216, + Count = 219, >Count : SyntaxKind FirstAssignment = 52, @@ -2465,9 +2474,9 @@ declare module "typescript" { >Identifier : Identifier namedBindings?: NamespaceImport | NamedImports; ->namedBindings : NamespaceImport | NamedImports +>namedBindings : NamespaceImport | NamedImportsOrExports >NamespaceImport : NamespaceImport ->NamedImports : NamedImports +>NamedImports : NamedImportsOrExports } interface NamespaceImport extends Declaration { >NamespaceImport : NamespaceImport @@ -2477,17 +2486,38 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } - interface NamedImports extends Node { ->NamedImports : NamedImports + interface ExportDeclaration extends Statement, ModuleElement { +>ExportDeclaration : ExportDeclaration +>Statement : Statement +>ModuleElement : ModuleElement + + exportClause?: NamedExports; +>exportClause : NamedImportsOrExports +>NamedExports : NamedImportsOrExports + + moduleSpecifier?: Expression; +>moduleSpecifier : Expression +>Expression : Expression + } + interface NamedImportsOrExports extends Node { +>NamedImportsOrExports : NamedImportsOrExports >Node : Node - elements: NodeArray; ->elements : NodeArray + elements: NodeArray; +>elements : NodeArray >NodeArray : NodeArray ->ImportSpecifier : ImportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier } - interface ImportSpecifier extends Declaration { ->ImportSpecifier : ImportSpecifier + type NamedImports = NamedImportsOrExports; +>NamedImports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + type NamedExports = NamedImportsOrExports; +>NamedExports : NamedImportsOrExports +>NamedImportsOrExports : NamedImportsOrExports + + interface ImportOrExportSpecifier extends Declaration { +>ImportOrExportSpecifier : ImportOrExportSpecifier >Declaration : Declaration propertyName?: Identifier; @@ -2498,6 +2528,14 @@ declare module "typescript" { >name : Identifier >Identifier : Identifier } + type ImportSpecifier = ImportOrExportSpecifier; +>ImportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + + type ExportSpecifier = ImportOrExportSpecifier; +>ExportSpecifier : ImportOrExportSpecifier +>ImportOrExportSpecifier : ImportOrExportSpecifier + interface ExportAssignment extends Statement, ModuleElement { >ExportAssignment : ExportAssignment >Statement : Statement @@ -3151,12 +3189,13 @@ declare module "typescript" { interface EmitResolver { >EmitResolver : EmitResolver - getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration + getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; +>getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string +>node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration +>ExportDeclaration : ExportDeclaration getExpressionNameSubstitution(node: Identifier): string; >getExpressionNameSubstitution : (node: Identifier) => string From 6ef6217c1651850876ab7470b00d249e1efd43a5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Feb 2015 10:07:10 -0800 Subject: [PATCH 39/46] Allow multiple (renaming) exports for same entity --- src/compiler/emitter.ts | 48 ++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 552c7201279eb..1344c34d8866b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1568,7 +1568,7 @@ module ts { var tempVariables: Identifier[]; var tempParameters: Identifier[]; var externalImports: ExternalImportInfo[]; - var exportSpecifiers: Map; + var exportSpecifiers: Map; /** write emitted output to disk*/ var writeEmittedFiles = writeJavaScriptFile; @@ -3068,17 +3068,18 @@ module ts { emitEnd(node.name); } - function emitExportMemberAssignment(name: Identifier) { + function emitExportMemberAssignments(name: Identifier) { if (exportSpecifiers && hasProperty(exportSpecifiers, name.text)) { - var exportName = exportSpecifiers[name.text].name; - writeLine(); - emitStart(exportName); - write("exports."); - emitNode(exportName); - emitEnd(exportName); - write(" = "); - emitNode(name); - write(";"); + forEach(exportSpecifiers[name.text], specifier => { + writeLine(); + emitStart(specifier.name); + write("exports."); + emitNode(specifier.name); + emitEnd(specifier.name); + write(" = "); + emitNode(name); + write(";"); + }); } } @@ -3317,7 +3318,7 @@ module ts { function emitExportVariableAssignments(node: VariableDeclaration | BindingElement) { var name = (node).name; if (name.kind === SyntaxKind.Identifier) { - emitExportMemberAssignment(name); + emitExportMemberAssignments(name); } else if (isBindingPattern(name)) { forEach((name).elements, emitExportVariableAssignments); @@ -3466,7 +3467,7 @@ module ts { } emitSignatureAndBody(node); if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile) { - emitExportMemberAssignment((node).name); + emitExportMemberAssignments((node).name); } if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { emitTrailingComments(node); @@ -3805,7 +3806,7 @@ module ts { write(";"); } if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { - emitExportMemberAssignment(node.name); + emitExportMemberAssignments(node.name); } function emitConstructorOfClass() { @@ -3934,7 +3935,7 @@ module ts { write(";"); } if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { - emitExportMemberAssignment(node.name); + emitExportMemberAssignments(node.name); } } @@ -4035,7 +4036,7 @@ module ts { write(" = {}));"); emitEnd(node); if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { - emitExportMemberAssignment(node.name); + emitExportMemberAssignments(node.name); } } @@ -4119,10 +4120,12 @@ module ts { if (node.exportClause && node.moduleSpecifier) { var generatedName = resolver.getGeneratedNameForNode(node); emitStart(node); - write("var "); - write(generatedName); - write(" = "); - emitRequire(getExternalModuleName(node)); + if (compilerOptions.module !== ModuleKind.AMD) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(getExternalModuleName(node)); + } forEach(node.exportClause.elements, specifier => { writeLine(); emitStart(specifier); @@ -4187,8 +4190,9 @@ module ts { exportSpecifiers = {}; forEach(sourceFile.statements, node => { if (node.kind === SyntaxKind.ExportDeclaration && !(node).moduleSpecifier) { - forEach((node).exportClause.elements, e => { - exportSpecifiers[(e.propertyName || e.name).text] = e; + forEach((node).exportClause.elements, specifier => { + var name = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); }); } else { From 0df69ed1b62945bacf7cb269c9c54501703e1764 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Feb 2015 10:07:37 -0800 Subject: [PATCH 40/46] Static checking for export declarations --- src/compiler/checker.ts | 37 ++++++++++++++----- .../diagnosticInformationMap.generated.ts | 5 ++- src/compiler/diagnosticMessages.json | 14 ++++++- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 743a39b48fc74..b72797daa4a8e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9358,7 +9358,7 @@ module ts { return node; } - function checkExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration): boolean { + function checkExternalImportOrExportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): boolean { var moduleName = getExternalModuleName(node); if (getFullWidth(moduleName) !== 0 && moduleName.kind !== SyntaxKind.StringLiteral) { error(moduleName, Diagnostics.String_literal_expected); @@ -9366,7 +9366,9 @@ module ts { } var inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { - error(moduleName, Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); + error(moduleName, node.kind === SyntaxKind.ExportDeclaration ? + Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module : + Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module); return false; } if (inAmbientExternalModule && isExternalModuleNameRelative((moduleName).text)) { @@ -9374,13 +9376,13 @@ module ts { // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference // other external modules only through top - level external module names. // Relative external module names are not permitted. - error(node, Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); + error(node, Diagnostics.Import_or_export_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name); return false; } return true; } - function checkImportSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { + function checkImportSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier) { var symbol = getSymbolOfNode(node); var target = resolveImport(symbol); if (target !== unknownSymbol) { @@ -9389,7 +9391,10 @@ module ts { (symbol.flags & SymbolFlags.Type ? SymbolFlags.Type : 0) | (symbol.flags & SymbolFlags.Namespace ? SymbolFlags.Namespace : 0); if (target.flags & excludedMeanings) { - error(node, Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0, symbolToString(symbol)); + var message = node.kind === SyntaxKind.ExportSpecifier ? + Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : + Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0; + error(node, message, symbolToString(symbol)); } } } @@ -9404,15 +9409,13 @@ module ts { if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } - if (checkExternalImportDeclaration(node)) { + if (checkExternalImportOrExportDeclaration(node)) { var importClause = node.importClause; if (importClause) { if (importClause.name) { - // TODO: Check that import references an export default instance checkImportBinding(importClause); } if (importClause.namedBindings) { - // TODO: Check that import references an export namespace if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { checkImportBinding(importClause.namedBindings); } @@ -9448,12 +9451,23 @@ module ts { } } else { - if (checkExternalImportDeclaration(node)) { + if (checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); } } } + function checkExportDeclaration(node: ExportDeclaration) { + if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers); + } + if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { + if (node.exportClause) { + forEach(node.exportClause.elements, checkImportSymbol); + } + } + } + function checkExportAssignment(node: ExportAssignment) { // Grammar checking if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { @@ -9559,6 +9573,8 @@ module ts { return checkImportDeclaration(node); case SyntaxKind.ImportEqualsDeclaration: return checkImportEqualsDeclaration(node); + case SyntaxKind.ExportDeclaration: + return checkExportDeclaration(node); case SyntaxKind.ExportAssignment: return checkExportAssignment(node); case SyntaxKind.EmptyStatement: @@ -10491,12 +10507,13 @@ module ts { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.EnumDeclaration: - case SyntaxKind.ExportAssignment: case SyntaxKind.VariableStatement: case SyntaxKind.FunctionDeclaration: case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.ImportDeclaration: case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportDeclaration: + case SyntaxKind.ExportAssignment: case SyntaxKind.Parameter: break; default: diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 495145f1b6bb7..a6c9b5399d164 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -149,6 +149,8 @@ module ts { A_parameter_property_may_not_be_a_binding_pattern: { code: 1187, category: DiagnosticCategory.Error, key: "A parameter property may not be a binding pattern." }, An_import_declaration_cannot_have_modifiers: { code: 1188, category: DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." }, External_module_0_has_no_default_export_or_export_assignment: { code: 1189, category: DiagnosticCategory.Error, key: "External module '{0}' has no default export or export assignment." }, + An_export_declaration_cannot_have_modifiers: { code: 1190, category: DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." }, + Export_declarations_are_not_permitted_in_an_internal_module: { code: 1191, category: DiagnosticCategory.Error, key: "Export declarations are not permitted in an internal module." }, 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." }, @@ -277,7 +279,7 @@ module ts { Ambient_external_module_declaration_cannot_specify_relative_module_name: { code: 2436, category: DiagnosticCategory.Error, key: "Ambient external module declaration cannot specify relative module name." }, Module_0_is_hidden_by_a_local_declaration_with_the_same_name: { code: 2437, category: DiagnosticCategory.Error, key: "Module '{0}' is hidden by a local declaration with the same name" }, Import_name_cannot_be_0: { code: 2438, category: DiagnosticCategory.Error, key: "Import name cannot be '{0}'" }, - Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: { code: 2439, category: DiagnosticCategory.Error, key: "Import declaration in an ambient external module declaration cannot reference external module through relative external module name." }, + Import_or_export_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: { code: 2439, category: DiagnosticCategory.Error, key: "Import or export declaration in an ambient external module declaration cannot reference external module through relative external module name." }, Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" }, Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: { code: 2441, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module." }, Types_have_separate_declarations_of_a_private_property_0: { code: 2442, category: DiagnosticCategory.Error, key: "Types have separate declarations of a private property '{0}'." }, @@ -306,6 +308,7 @@ module ts { super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." }, A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." }, Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2468, category: DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, + Export_declaration_conflicts_with_exported_declaration_of_0: { code: 2469, category: DiagnosticCategory.Error, key: "Export declaration conflicts with exported declaration of '{0}'" }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5bc9eedb386af..16cfe5e10e82d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -587,6 +587,14 @@ "category": "Error", "code": 1189 }, + "An export declaration cannot have modifiers.": { + "category": "Error", + "code": 1190 + }, + "Export declarations are not permitted in an internal module.": { + "category": "Error", + "code": 1191 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -1100,7 +1108,7 @@ "category": "Error", "code": 2438 }, - "Import declaration in an ambient external module declaration cannot reference external module through relative external module name.": { + "Import or export declaration in an ambient external module declaration cannot reference external module through relative external module name.": { "category": "Error", "code": 2439 }, @@ -1216,6 +1224,10 @@ "category": "Error", "code": 2468 }, + "Export declaration conflicts with exported declaration of '{0}'": { + "category": "Error", + "code": 2469 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", From e52ddcb0aa11fdbd8fa2ef9db6463565bebed6d2 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Feb 2015 10:18:58 -0800 Subject: [PATCH 41/46] Accepting new baselines --- ...rnalModuleWithRelativeExternalImportDeclaration.errors.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/ambientExternalModuleWithRelativeExternalImportDeclaration.errors.txt b/tests/baselines/reference/ambientExternalModuleWithRelativeExternalImportDeclaration.errors.txt index 4ebae64b0b857..72d7145969f91 100644 --- a/tests/baselines/reference/ambientExternalModuleWithRelativeExternalImportDeclaration.errors.txt +++ b/tests/baselines/reference/ambientExternalModuleWithRelativeExternalImportDeclaration.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,5): error TS2439: Import declaration in an ambient external module declaration cannot reference external module through relative external module name. +tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,5): error TS2439: Import or export declaration in an ambient external module declaration cannot reference external module through relative external module name. tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration.ts(2,25): error TS2307: Cannot find external module './SubModule'. @@ -6,7 +6,7 @@ tests/cases/compiler/ambientExternalModuleWithRelativeExternalImportDeclaration. declare module "OuterModule" { import m2 = require("./SubModule"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2439: Import declaration in an ambient external module declaration cannot reference external module through relative external module name. +!!! error TS2439: Import or export declaration in an ambient external module declaration cannot reference external module through relative external module name. ~~~~~~~~~~~~~ !!! error TS2307: Cannot find external module './SubModule'. class SubModule { From c60121064a19beef4afcfaa28fe8991cd8398263 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Feb 2015 14:07:20 -0800 Subject: [PATCH 42/46] Re-exported symbols should not be in scope --- src/compiler/checker.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b72797daa4a8e..a97b2090442f4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -316,7 +316,10 @@ module ts { if (!isExternalModule(location)) break; case SyntaxKind.ModuleDeclaration: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.ModuleMember)) { - break loop; + if (!(result.flags & SymbolFlags.Import && getDeclarationOfImportSymbol(result).kind === SyntaxKind.ExportSpecifier)) { + break loop; + } + result = undefined; } break; case SyntaxKind.EnumDeclaration: From a8152b6e503cf681f02941b6cd03313b89cab29b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 15 Feb 2015 08:25:24 -0800 Subject: [PATCH 43/46] Support for 'export *' declarations --- src/compiler/binder.ts | 10 +++++++ src/compiler/checker.ts | 61 +++++++++++++++++++++++++++++++++++------ src/compiler/emitter.ts | 51 +++++++++++++++++++++++----------- src/compiler/types.ts | 11 ++++++-- 4 files changed, 105 insertions(+), 28 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 4bd562291d5ef..d13d7289b9e4d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -316,6 +316,13 @@ module ts { } } + function bindExportDeclaration(node: ExportDeclaration) { + if (!node.exportClause) { + ((container).exportStars || ((container).exportStars = [])).push(node); + } + bindChildren(node, 0, /*isBlockScopeContainer*/ false); + } + function bindFunctionOrConstructorType(node: SignatureDeclaration) { // For a given function symbol "<...>(...) => T" we want to generate a symbol identical // to the one we would get for: { <...>(...): T } @@ -477,6 +484,9 @@ module ts { case SyntaxKind.ExportSpecifier: bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); break; + case SyntaxKind.ExportDeclaration: + bindExportDeclaration(node); + break; case SyntaxKind.ImportClause: if ((node).name) { bindDeclaration(node, SymbolFlags.Import, SymbolFlags.ImportExcludes, /*isBlockScopeContainer*/ false); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a97b2090442f4..828b03c91d7cc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -179,7 +179,7 @@ module ts { return result; } - function extendSymbol(target: Symbol, source: Symbol) { + function mergeSymbol(target: Symbol, source: Symbol) { if (!(target.flags & getExcludedSymbolFlags(source.flags))) { if (source.flags & SymbolFlags.ValueModule && target.flags & SymbolFlags.ValueModule && target.constEnumOnlyModule && !source.constEnumOnlyModule) { // reset flag when merging instantiated module into value module that has only const enums @@ -192,11 +192,11 @@ module ts { }); if (source.members) { if (!target.members) target.members = {}; - extendSymbolTable(target.members, source.members); + mergeSymbolTable(target.members, source.members); } if (source.exports) { if (!target.exports) target.exports = {}; - extendSymbolTable(target.exports, source.exports); + mergeSymbolTable(target.exports, source.exports); } recordMergedSymbol(target, source); } @@ -222,7 +222,7 @@ module ts { return result; } - function extendSymbolTable(target: SymbolTable, source: SymbolTable) { + function mergeSymbolTable(target: SymbolTable, source: SymbolTable) { for (var id in source) { if (hasProperty(source, id)) { if (!hasProperty(target, id)) { @@ -233,12 +233,20 @@ module ts { if (!(symbol.flags & SymbolFlags.Merged)) { target[id] = symbol = cloneSymbol(symbol); } - extendSymbol(symbol, source[id]); + mergeSymbol(symbol, source[id]); } } } } + function extendSymbolTable(target: SymbolTable, source: SymbolTable) { + for (var id in source) { + if (!hasProperty(target, id)) { + target[id] = source[id]; + } + } + } + function getSymbolLinks(symbol: Symbol): SymbolLinks { if (symbol.flags & SymbolFlags.Transient) return symbol; if (!symbol.id) symbol.id = nextSymbolId++; @@ -486,7 +494,7 @@ module ts { if (moduleSymbol) { var name = specifier.propertyName || specifier.name; if (name.text) { - var symbol = getSymbol(moduleSymbol.exports, name.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + var symbol = getSymbol(getExportsOfSymbol(moduleSymbol), name.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); if (!symbol) { error(name, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), declarationNameToString(name)); return; @@ -587,7 +595,7 @@ module ts { else if (name.kind === SyntaxKind.QualifiedName) { var namespace = resolveEntityName(location,(name).left, SymbolFlags.Namespace); if (!namespace || namespace === unknownSymbol || getFullWidth((name).right) === 0) return; - var symbol = getSymbol(namespace.exports,(name).right.text, meaning); + var symbol = getSymbol(getExportsOfSymbol(namespace), (name).right.text, meaning); if (!symbol) { error(location, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), declarationNameToString((name).right)); @@ -708,6 +716,41 @@ module ts { }; } + function getExportsOfSymbol(symbol: Symbol): SymbolTable { + return symbol.flags & SymbolFlags.Module ? getExportsOfModule(symbol) : symbol.exports; + } + + function getExportsOfModule(symbol: Symbol): SymbolTable { + var links = getSymbolLinks(symbol); + return links.resolvedExports || (links.resolvedExports = getExportsForModule(symbol)); + } + + function getExportsForModule(symbol: Symbol): SymbolTable { + var result: SymbolTable; + var visitedSymbols: Symbol[] = []; + visit(symbol); + return result; + + function visit(symbol: Symbol) { + if (!contains(visitedSymbols, symbol)) { + visitedSymbols.push(symbol); + if (!result) { + result = symbol.exports; + } + else { + extendSymbolTable(result, symbol.exports); + } + forEach(symbol.declarations, node => { + if (node.kind === SyntaxKind.SourceFile || node.kind === SyntaxKind.ModuleDeclaration) { + forEach((node).exportStars, exportStar => { + visit(resolveExternalModuleName(exportStar, exportStar.moduleSpecifier)); + }); + } + }); + } + } + } + function getMergedSymbol(symbol: Symbol): Symbol { var merged: Symbol; return symbol && symbol.mergeId && (merged = mergedSymbols[symbol.mergeId]) ? merged : symbol; @@ -2475,7 +2518,7 @@ module ts { var callSignatures: Signature[] = emptyArray; var constructSignatures: Signature[] = emptyArray; if (symbol.flags & SymbolFlags.HasExports) { - members = symbol.exports; + members = getExportsOfSymbol(symbol); } if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) { callSignatures = getSignaturesOfSymbol(symbol); @@ -10468,7 +10511,7 @@ module ts { // Initialize global symbol table forEach(host.getSourceFiles(), file => { if (!isExternalModule(file)) { - extendSymbolTable(globals, file.locals); + mergeSymbolTable(globals, file.locals); } }); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1344c34d8866b..e060d6fcbb87e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3057,11 +3057,15 @@ module ts { return node; } + function emitContainingModuleName(node: Node) { + var container = getContainingModule(node); + write(container ? resolver.getGeneratedNameForNode(container) : "exports"); + } + function emitModuleMemberName(node: Declaration) { emitStart(node.name); if (getCombinedNodeFlags(node) & NodeFlags.Export) { - var container = getContainingModule(node); - write(container ? resolver.getGeneratedNameForNode(container) : "exports"); + emitContainingModuleName(node); write("."); } emitNode(node.name); @@ -3073,7 +3077,8 @@ module ts { forEach(exportSpecifiers[name.text], specifier => { writeLine(); emitStart(specifier.name); - write("exports."); + emitContainingModuleName(specifier); + write("."); emitNode(specifier.name); emitEnd(specifier.name); write(" = "); @@ -4117,27 +4122,41 @@ module ts { } function emitExportDeclaration(node: ExportDeclaration) { - if (node.exportClause && node.moduleSpecifier) { - var generatedName = resolver.getGeneratedNameForNode(node); + if (node.moduleSpecifier) { emitStart(node); + var generatedName = resolver.getGeneratedNameForNode(node); if (compilerOptions.module !== ModuleKind.AMD) { write("var "); write(generatedName); write(" = "); emitRequire(getExternalModuleName(node)); } - forEach(node.exportClause.elements, specifier => { + if (node.exportClause) { + // export { x, y, ... } + forEach(node.exportClause.elements, specifier => { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNode(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNode(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + }); + } + else { + // export * + var tempName = createTempVariable(node).text; writeLine(); - emitStart(specifier); - write("exports."); - emitNode(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNode(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - }); + write("for (var " + tempName + " in " + generatedName + ") if (!"); + emitContainingModuleName(node); + write(".hasOwnProperty(" + tempName + ")) "); + emitContainingModuleName(node); + write("[" + tempName + "] = " + generatedName + "[" + tempName + "];"); + } emitEnd(node); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 53aa08dae7786..810bca9fd5698 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -352,13 +352,13 @@ 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) - modifiers?: ModifiersArray; // Array of modifiers } export interface NodeArray extends Array, TextRange { @@ -856,7 +856,11 @@ module ts { members: NodeArray; } - export interface ModuleDeclaration extends Declaration, ModuleElement { + export interface ExportContainer { + exportStars?: ExportDeclaration[]; // List of 'export *' statements (initialized by binding) + } + + export interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { name: Identifier | LiteralExpression; body: ModuleBlock | ModuleDeclaration; } @@ -934,7 +938,7 @@ module ts { } // Source files are declarations when they are external modules. - export interface SourceFile extends Declaration { + export interface SourceFile extends Declaration, ExportContainer { statements: NodeArray; endOfFileToken: Node; @@ -1297,6 +1301,7 @@ module ts { exportAssignmentChecked?: boolean; // True if export assignment was checked exportAssignmentSymbol?: Symbol; // Symbol exported from external module unionType?: UnionType; // Containing union type for union property + resolvedExports?: SymbolTable; // Resolved exports of module } export interface TransientSymbol extends Symbol, SymbolLinks { } From cc52dcec49fa5af41e0ab8d88bcde55fcf3c2c23 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 15 Feb 2015 08:30:39 -0800 Subject: [PATCH 44/46] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 10 +++++-- .../reference/APISample_compile.types | 29 ++++++++++++++----- tests/baselines/reference/APISample_linter.js | 10 +++++-- .../reference/APISample_linter.types | 29 ++++++++++++++----- .../reference/APISample_transform.js | 10 +++++-- .../reference/APISample_transform.types | 29 ++++++++++++++----- .../baselines/reference/APISample_watcher.js | 10 +++++-- .../reference/APISample_watcher.types | 29 ++++++++++++++----- 8 files changed, 112 insertions(+), 44 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 9f75f86dc1c85..49eed12dc7084 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -339,13 +339,13 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + modifiers?: ModifiersArray; id?: number; parent?: Node; symbol?: Symbol; locals?: SymbolTable; nextContainer?: Node; localSymbol?: Symbol; - modifiers?: ModifiersArray; } interface NodeArray extends Array, TextRange { hasTrailingComma?: boolean; @@ -705,7 +705,10 @@ declare module "typescript" { name: Identifier; members: NodeArray; } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { + exportStars?: ExportDeclaration[]; + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { name: Identifier | LiteralExpression; body: ModuleBlock | ModuleDeclaration; } @@ -754,7 +757,7 @@ declare module "typescript" { interface CommentRange extends TextRange { hasTrailingNewLine?: boolean; } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { statements: NodeArray; endOfFileToken: Node; fileName: string; @@ -1015,6 +1018,7 @@ declare module "typescript" { exportAssignmentChecked?: boolean; exportAssignmentSymbol?: Symbol; unionType?: UnionType; + resolvedExports?: SymbolTable; } interface TransientSymbol extends Symbol, SymbolLinks { } diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index b992b3ba1196a..9232f28194046 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -1025,6 +1025,10 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + modifiers?: ModifiersArray; +>modifiers : ModifiersArray +>ModifiersArray : ModifiersArray + id?: number; >id : number @@ -1047,10 +1051,6 @@ declare module "typescript" { localSymbol?: Symbol; >localSymbol : Symbol >Symbol : Symbol - - modifiers?: ModifiersArray; ->modifiers : ModifiersArray ->ModifiersArray : ModifiersArray } interface NodeArray extends Array, TextRange { >NodeArray : NodeArray @@ -2136,10 +2136,18 @@ declare module "typescript" { >NodeArray : NodeArray >EnumMember : EnumMember } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { +>ExportContainer : ExportContainer + + exportStars?: ExportDeclaration[]; +>exportStars : ExportDeclaration[] +>ExportDeclaration : ExportDeclaration + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { >ModuleDeclaration : ModuleDeclaration >Declaration : Declaration >ModuleElement : ModuleElement +>ExportContainer : ExportContainer name: Identifier | LiteralExpression; >name : Identifier | LiteralExpression @@ -2290,9 +2298,10 @@ declare module "typescript" { hasTrailingNewLine?: boolean; >hasTrailingNewLine : boolean } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { >SourceFile : SourceFile >Declaration : Declaration +>ExportContainer : ExportContainer statements: NodeArray; >statements : NodeArray @@ -2921,8 +2930,8 @@ declare module "typescript" { >EmitResolver : EmitResolver getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration +>getGeneratedNameForNode : (node: EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration @@ -3285,6 +3294,10 @@ declare module "typescript" { unionType?: UnionType; >unionType : UnionType >UnionType : UnionType + + resolvedExports?: SymbolTable; +>resolvedExports : SymbolTable +>SymbolTable : SymbolTable } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 0ec2bf4f77c57..9af13574ae614 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -370,13 +370,13 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + modifiers?: ModifiersArray; id?: number; parent?: Node; symbol?: Symbol; locals?: SymbolTable; nextContainer?: Node; localSymbol?: Symbol; - modifiers?: ModifiersArray; } interface NodeArray extends Array, TextRange { hasTrailingComma?: boolean; @@ -736,7 +736,10 @@ declare module "typescript" { name: Identifier; members: NodeArray; } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { + exportStars?: ExportDeclaration[]; + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { name: Identifier | LiteralExpression; body: ModuleBlock | ModuleDeclaration; } @@ -785,7 +788,7 @@ declare module "typescript" { interface CommentRange extends TextRange { hasTrailingNewLine?: boolean; } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { statements: NodeArray; endOfFileToken: Node; fileName: string; @@ -1046,6 +1049,7 @@ declare module "typescript" { exportAssignmentChecked?: boolean; exportAssignmentSymbol?: Symbol; unionType?: UnionType; + resolvedExports?: SymbolTable; } interface TransientSymbol extends Symbol, SymbolLinks { } diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 3bb894b55de83..dc30fedce35d3 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -1169,6 +1169,10 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + modifiers?: ModifiersArray; +>modifiers : ModifiersArray +>ModifiersArray : ModifiersArray + id?: number; >id : number @@ -1191,10 +1195,6 @@ declare module "typescript" { localSymbol?: Symbol; >localSymbol : Symbol >Symbol : Symbol - - modifiers?: ModifiersArray; ->modifiers : ModifiersArray ->ModifiersArray : ModifiersArray } interface NodeArray extends Array, TextRange { >NodeArray : NodeArray @@ -2280,10 +2280,18 @@ declare module "typescript" { >NodeArray : NodeArray >EnumMember : EnumMember } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { +>ExportContainer : ExportContainer + + exportStars?: ExportDeclaration[]; +>exportStars : ExportDeclaration[] +>ExportDeclaration : ExportDeclaration + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { >ModuleDeclaration : ModuleDeclaration >Declaration : Declaration >ModuleElement : ModuleElement +>ExportContainer : ExportContainer name: Identifier | LiteralExpression; >name : Identifier | LiteralExpression @@ -2434,9 +2442,10 @@ declare module "typescript" { hasTrailingNewLine?: boolean; >hasTrailingNewLine : boolean } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { >SourceFile : SourceFile >Declaration : Declaration +>ExportContainer : ExportContainer statements: NodeArray; >statements : NodeArray @@ -3065,8 +3074,8 @@ declare module "typescript" { >EmitResolver : EmitResolver getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration +>getGeneratedNameForNode : (node: EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration @@ -3429,6 +3438,10 @@ declare module "typescript" { unionType?: UnionType; >unionType : UnionType >UnionType : UnionType + + resolvedExports?: SymbolTable; +>resolvedExports : SymbolTable +>SymbolTable : SymbolTable } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 1627415c83498..4b556d8db0edb 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -371,13 +371,13 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + modifiers?: ModifiersArray; id?: number; parent?: Node; symbol?: Symbol; locals?: SymbolTable; nextContainer?: Node; localSymbol?: Symbol; - modifiers?: ModifiersArray; } interface NodeArray extends Array, TextRange { hasTrailingComma?: boolean; @@ -737,7 +737,10 @@ declare module "typescript" { name: Identifier; members: NodeArray; } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { + exportStars?: ExportDeclaration[]; + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { name: Identifier | LiteralExpression; body: ModuleBlock | ModuleDeclaration; } @@ -786,7 +789,7 @@ declare module "typescript" { interface CommentRange extends TextRange { hasTrailingNewLine?: boolean; } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { statements: NodeArray; endOfFileToken: Node; fileName: string; @@ -1047,6 +1050,7 @@ declare module "typescript" { exportAssignmentChecked?: boolean; exportAssignmentSymbol?: Symbol; unionType?: UnionType; + resolvedExports?: SymbolTable; } interface TransientSymbol extends Symbol, SymbolLinks { } diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 9d0dbdb0768a3..8eb0fd5c34d89 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -1121,6 +1121,10 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + modifiers?: ModifiersArray; +>modifiers : ModifiersArray +>ModifiersArray : ModifiersArray + id?: number; >id : number @@ -1143,10 +1147,6 @@ declare module "typescript" { localSymbol?: Symbol; >localSymbol : Symbol >Symbol : Symbol - - modifiers?: ModifiersArray; ->modifiers : ModifiersArray ->ModifiersArray : ModifiersArray } interface NodeArray extends Array, TextRange { >NodeArray : NodeArray @@ -2232,10 +2232,18 @@ declare module "typescript" { >NodeArray : NodeArray >EnumMember : EnumMember } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { +>ExportContainer : ExportContainer + + exportStars?: ExportDeclaration[]; +>exportStars : ExportDeclaration[] +>ExportDeclaration : ExportDeclaration + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { >ModuleDeclaration : ModuleDeclaration >Declaration : Declaration >ModuleElement : ModuleElement +>ExportContainer : ExportContainer name: Identifier | LiteralExpression; >name : Identifier | LiteralExpression @@ -2386,9 +2394,10 @@ declare module "typescript" { hasTrailingNewLine?: boolean; >hasTrailingNewLine : boolean } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { >SourceFile : SourceFile >Declaration : Declaration +>ExportContainer : ExportContainer statements: NodeArray; >statements : NodeArray @@ -3017,8 +3026,8 @@ declare module "typescript" { >EmitResolver : EmitResolver getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration +>getGeneratedNameForNode : (node: EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration @@ -3381,6 +3390,10 @@ declare module "typescript" { unionType?: UnionType; >unionType : UnionType >UnionType : UnionType + + resolvedExports?: SymbolTable; +>resolvedExports : SymbolTable +>SymbolTable : SymbolTable } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 6c4c0977aaca5..c97effc3458c2 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -408,13 +408,13 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + modifiers?: ModifiersArray; id?: number; parent?: Node; symbol?: Symbol; locals?: SymbolTable; nextContainer?: Node; localSymbol?: Symbol; - modifiers?: ModifiersArray; } interface NodeArray extends Array, TextRange { hasTrailingComma?: boolean; @@ -774,7 +774,10 @@ declare module "typescript" { name: Identifier; members: NodeArray; } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { + exportStars?: ExportDeclaration[]; + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { name: Identifier | LiteralExpression; body: ModuleBlock | ModuleDeclaration; } @@ -823,7 +826,7 @@ declare module "typescript" { interface CommentRange extends TextRange { hasTrailingNewLine?: boolean; } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { statements: NodeArray; endOfFileToken: Node; fileName: string; @@ -1084,6 +1087,7 @@ declare module "typescript" { exportAssignmentChecked?: boolean; exportAssignmentSymbol?: Symbol; unionType?: UnionType; + resolvedExports?: SymbolTable; } interface TransientSymbol extends Symbol, SymbolLinks { } diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index fb342d09cdda5..cb46e45347e06 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1294,6 +1294,10 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + modifiers?: ModifiersArray; +>modifiers : ModifiersArray +>ModifiersArray : ModifiersArray + id?: number; >id : number @@ -1316,10 +1320,6 @@ declare module "typescript" { localSymbol?: Symbol; >localSymbol : Symbol >Symbol : Symbol - - modifiers?: ModifiersArray; ->modifiers : ModifiersArray ->ModifiersArray : ModifiersArray } interface NodeArray extends Array, TextRange { >NodeArray : NodeArray @@ -2405,10 +2405,18 @@ declare module "typescript" { >NodeArray : NodeArray >EnumMember : EnumMember } - interface ModuleDeclaration extends Declaration, ModuleElement { + interface ExportContainer { +>ExportContainer : ExportContainer + + exportStars?: ExportDeclaration[]; +>exportStars : ExportDeclaration[] +>ExportDeclaration : ExportDeclaration + } + interface ModuleDeclaration extends Declaration, ModuleElement, ExportContainer { >ModuleDeclaration : ModuleDeclaration >Declaration : Declaration >ModuleElement : ModuleElement +>ExportContainer : ExportContainer name: Identifier | LiteralExpression; >name : Identifier | LiteralExpression @@ -2559,9 +2567,10 @@ declare module "typescript" { hasTrailingNewLine?: boolean; >hasTrailingNewLine : boolean } - interface SourceFile extends Declaration { + interface SourceFile extends Declaration, ExportContainer { >SourceFile : SourceFile >Declaration : Declaration +>ExportContainer : ExportContainer statements: NodeArray; >statements : NodeArray @@ -3190,8 +3199,8 @@ declare module "typescript" { >EmitResolver : EmitResolver getGeneratedNameForNode(node: ModuleDeclaration | EnumDeclaration | ImportDeclaration | ExportDeclaration): string; ->getGeneratedNameForNode : (node: EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration) => string ->node : EnumDeclaration | ModuleDeclaration | ImportDeclaration | ExportDeclaration +>getGeneratedNameForNode : (node: EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration) => string +>node : EnumDeclaration | ExportDeclaration | ModuleDeclaration | ImportDeclaration >ModuleDeclaration : ModuleDeclaration >EnumDeclaration : EnumDeclaration >ImportDeclaration : ImportDeclaration @@ -3554,6 +3563,10 @@ declare module "typescript" { unionType?: UnionType; >unionType : UnionType >UnionType : UnionType + + resolvedExports?: SymbolTable; +>resolvedExports : SymbolTable +>SymbolTable : SymbolTable } interface TransientSymbol extends Symbol, SymbolLinks { >TransientSymbol : TransientSymbol From 7cca6519ef5eeccedd45536d7555c547961503ac Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 15 Feb 2015 18:46:41 -0800 Subject: [PATCH 45/46] Include globals in check for existing identifiers --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 828b03c91d7cc..bb250c3f9d589 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10260,7 +10260,7 @@ module ts { } function isExistingName(name: string) { - return hasProperty(sourceFile.identifiers, name) || hasProperty(generatedNames, name); + return hasProperty(globals, name) || hasProperty(sourceFile.identifiers, name) || hasProperty(generatedNames, name); } function makeUniqueName(baseName: string): string { From 27529f1d38584189b98e57a526d3854216ab5c45 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Feb 2015 11:23:40 -0800 Subject: [PATCH 46/46] Addressing CR feedback --- src/compiler/parser.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 33ab1dd1f131e..309eac2b504de 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1858,7 +1858,9 @@ module ts { function isReusableModuleElement(node: Node) { if (node) { switch (node.kind) { + case SyntaxKind.ImportDeclaration: case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportDeclaration: case SyntaxKind.ExportAssignment: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: