From c39dfdc238ae14e436c0ff96bd94054c37e6cf52 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 17 Mar 2015 06:15:23 -0700 Subject: [PATCH 01/24] Introduce NodeFlags.ExportContext --- src/compiler/binder.ts | 43 ++++++++++++++++++++++++++++++++--------- src/compiler/checker.ts | 9 --------- src/compiler/types.ts | 1 + 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 7c1e4c57a4cd1..edf5233e47dbf 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -188,14 +188,6 @@ module ts { return symbol; } - function isAmbientContext(node: Node): boolean { - while (node) { - if (node.flags & NodeFlags.Ambient) return true; - node = node.parent; - } - return false; - } - function declareModuleMember(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { let hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export; if (symbolKind & SymbolFlags.Alias) { @@ -218,7 +210,7 @@ module ts { // 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)) { + if (hasExportModifier || container.flags & NodeFlags.ExportContext) { let exportKind = (symbolKind & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) | (symbolKind & SymbolFlags.Type ? SymbolFlags.ExportType : 0) | (symbolKind & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0); @@ -311,7 +303,39 @@ module ts { bindChildren(node, symbolKind, isBlockScopeContainer); } + function isAmbientContext(node: Node): boolean { + while (node) { + if (node.flags & NodeFlags.Ambient) return true; + node = node.parent; + } + return false; + } + + function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean { + var body = node.kind === SyntaxKind.SourceFile ? node : (node).body; + if (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock) { + for (let stat of (body).statements) { + if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) { + return true; + } + } + } + return false; + } + + function setExportContextFlag(node: ModuleDeclaration | SourceFile) { + // A declaration source file or ambient module declaration that contains no export declarations (but possibly regular + // declarations with export modifiers) is an export context in which declarations are implicitly exported. + if (isAmbientContext(node) && !hasExportDeclarations(node)) { + node.flags |= NodeFlags.ExportContext; + } + else { + node.flags &= ~NodeFlags.ExportContext; + } + } + function bindModuleDeclaration(node: ModuleDeclaration) { + setExportContextFlag(node); if (node.name.kind === SyntaxKind.StringLiteral) { bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } @@ -516,6 +540,7 @@ module ts { bindChildren(node, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.SourceFile: + setExportContextFlag(node); if (isExternalModule(node)) { bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).fileName) + '"', /*isBlockScopeContainer*/ true); break; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0dacb20ece41c..baeb1b59ba856 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -784,15 +784,6 @@ module ts { } function getExportsForModule(moduleSymbol: Symbol): SymbolTable { - if (compilerOptions.target < ScriptTarget.ES6) { - // A default export hides all other exports in CommonJS and AMD modules - let defaultSymbol = getExportAssignmentSymbol(moduleSymbol); - if (defaultSymbol) { - return { - "default": defaultSymbol - }; - } - } let result: SymbolTable; let visitedSymbols: Symbol[] = []; visit(moduleSymbol); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c43591911abd4..1631cc46a008a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -307,6 +307,7 @@ module ts { Let = 0x00001000, // Variable declaration Const = 0x00002000, // Variable declaration OctalLiteral = 0x00004000, + ExportContext = 0x00008000, // Export context (initialized by binding) Modifier = Export | Ambient | Public | Private | Protected | Static | Default, AccessibilityModifier = Public | Private | Protected, From 57a9fc54c89716b0e2494d39afe7dde74f3bff47 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 21 Mar 2015 13:12:39 -0700 Subject: [PATCH 02/24] Separate 'export default' and 'export =' --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 238 ++++++++++++------ src/compiler/core.ts | 10 - .../diagnosticInformationMap.generated.ts | 4 +- src/compiler/diagnosticMessages.json | 10 +- src/compiler/emitter.ts | 145 ++++++----- src/compiler/parser.ts | 31 +-- src/compiler/types.ts | 2 +- .../fourslash/goToDefinitionImportedNames7.ts | 2 +- 9 files changed, 261 insertions(+), 183 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index edf5233e47dbf..008bb5b319772 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -123,7 +123,7 @@ module ts { case SyntaxKind.ExportDeclaration: return "__export"; case SyntaxKind.ExportAssignment: - return "default"; + return (node).isExportEquals ? "export=" : "default"; case SyntaxKind.FunctionDeclaration: case SyntaxKind.ClassDeclaration: return node.flags & NodeFlags.Default ? "default" : undefined; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index baeb1b59ba856..a68a53436e3de 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -275,7 +275,6 @@ module ts { if (symbol.flags & meaning) { return symbol; } - if (symbol.flags & SymbolFlags.Alias) { let target = resolveAlias(symbol); // Unknown symbol means an error occurred in alias resolution, treat it as positive answer to avoid cascading errors @@ -284,7 +283,6 @@ module ts { } } } - // return undefined if we can't find a symbol. } @@ -503,6 +501,7 @@ module ts { // import * as from ... // import { x as } from ... // export { x as } from ... + // export = ... // export default ... function isAliasSymbolDeclaration(node: Node): boolean { return node.kind === SyntaxKind.ImportEqualsDeclaration || @@ -519,9 +518,7 @@ module ts { function getTargetOfImportEqualsDeclaration(node: ImportEqualsDeclaration): Symbol { if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) { - let moduleSymbol = resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)); - let exportAssignmentSymbol = moduleSymbol && getResolvedExportAssignmentSymbol(moduleSymbol); - return exportAssignmentSymbol || moduleSymbol; + return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node))); } return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); } @@ -529,29 +526,74 @@ module ts { function getTargetOfImportClause(node: ImportClause): Symbol { let moduleSymbol = resolveExternalModuleName(node, (node.parent).moduleSpecifier); if (moduleSymbol) { - let exportAssignmentSymbol = getResolvedExportAssignmentSymbol(moduleSymbol); - if (!exportAssignmentSymbol) { - error(node.name, Diagnostics.External_module_0_has_no_default_export_or_export_assignment, symbolToString(moduleSymbol)); + let exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]); + if (!exportDefaultSymbol) { + error(node.name, Diagnostics.External_module_0_has_no_default_export, symbolToString(moduleSymbol)); } - return exportAssignmentSymbol; + return exportDefaultSymbol; } } function getTargetOfNamespaceImport(node: NamespaceImport): Symbol { - return resolveExternalModuleName(node, (node.parent.parent).moduleSpecifier); + var moduleSpecifier = (node.parent.parent).moduleSpecifier; + return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier); + } + + function getMemberOfModuleVariable(moduleSymbol: Symbol, name: string): Symbol { + if (moduleSymbol.flags & SymbolFlags.Variable) { + let typeAnnotation = (moduleSymbol.valueDeclaration).type; + if (typeAnnotation) { + return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name); + } + } + } + + function combineValueAndTypeSymbols(valueSymbol: Symbol, typeSymbol: Symbol): Symbol { + if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) { + return valueSymbol; + } + let result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.name); + result.declarations = concatenate(valueSymbol.declarations, typeSymbol.declarations); + result.parent = valueSymbol.parent || typeSymbol.parent; + if (valueSymbol.valueDeclaration) result.valueDeclaration = valueSymbol.valueDeclaration; + if (typeSymbol.members) result.members = typeSymbol.members; + if (valueSymbol.exports) result.exports = valueSymbol.exports; + return result; + } + + function getExportOfModule(symbol: Symbol, name: string): Symbol { + if (symbol.flags & SymbolFlags.Module) { + let exports = getExportsOfSymbol(symbol); + if (hasProperty(exports, name)) { + return resolveSymbol(exports[name]); + } + } + } + + function getPropertyOfVariable(symbol: Symbol, name: string): Symbol { + if (symbol.flags & SymbolFlags.Variable) { + var typeAnnotation = (symbol.valueDeclaration).type; + if (typeAnnotation) { + return resolveSymbol(getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name)); + } + } } function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier): Symbol { let moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); - if (moduleSymbol) { + let targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); + if (targetSymbol) { let name = specifier.propertyName || specifier.name; if (name.text) { - let symbol = getSymbol(getExportsOfSymbol(moduleSymbol), name.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + let symbolFromModule = getExportOfModule(targetSymbol, name.text); + let symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text); + let symbol = symbolFromModule && symbolFromVariable ? + combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : + symbolFromModule || symbolFromVariable; 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 : resolveAlias(symbol); + return symbol; } } } @@ -587,6 +629,10 @@ module ts { } } + function resolveSymbol(symbol: Symbol): Symbol { + return symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)) ? resolveAlias(symbol) : symbol; + } + function resolveAlias(symbol: Symbol): Symbol { Debug.assert((symbol.flags & SymbolFlags.Alias) !== 0, "Should only get Alias here."); let links = getSymbolLinks(symbol); @@ -724,7 +770,6 @@ module ts { return symbol; } } - let sourceFile: SourceFile; while (true) { let fileName = normalizePath(combinePaths(searchPath, moduleName)); @@ -732,12 +777,10 @@ module ts { if (sourceFile || isRelative) { break; } - let parentPath = getDirectoryPath(searchPath); if (parentPath === searchPath) { break; } - searchPath = parentPath; } if (sourceFile) { @@ -750,24 +793,25 @@ module ts { error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName); } - function getExportAssignmentSymbol(moduleSymbol: Symbol): Symbol { - return moduleSymbol.exports["default"]; + function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol { + return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol; } - function getResolvedExportAssignmentSymbol(moduleSymbol: Symbol): Symbol { - let symbol = getExportAssignmentSymbol(moduleSymbol); - if (symbol) { - if (symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)) { - return symbol; - } - if (symbol.flags & SymbolFlags.Alias) { - return resolveAlias(symbol); - } + function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol { + let symbol = resolveExternalModuleSymbol(moduleSymbol); + if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) { + error(moduleReferenceExpression, Diagnostics.External_module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol)); + symbol = undefined; } + return symbol; + } + + function getExportAssignmentSymbol(moduleSymbol: Symbol): Symbol { + return moduleSymbol.exports["export="]; } function getExportsOfSymbol(symbol: Symbol): SymbolTable { - return symbol.flags & SymbolFlags.Module ? getExportsOfModule(symbol) : symbol.exports; + return symbol.flags & SymbolFlags.Module ? getExportsOfModule(symbol) : symbol.exports || emptySymbols; } function getExportsOfModule(moduleSymbol: Symbol): SymbolTable { @@ -792,7 +836,7 @@ module ts { // The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example, // module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error. function visit(symbol: Symbol) { - if (!contains(visitedSymbols, symbol)) { + if (symbol.flags & SymbolFlags.HasExports && !contains(visitedSymbols, symbol)) { visitedSymbols.push(symbol); if (symbol !== moduleSymbol) { if (!result) { @@ -803,9 +847,9 @@ module ts { // All export * declarations are collected in an __export symbol by the binder let exportStars = symbol.exports["__export"]; if (exportStars) { - forEach(exportStars.declarations, node => { + for (let node of exportStars.declarations) { visit(resolveExternalModuleName(node, (node).moduleSpecifier)); - }); + } } } } @@ -2826,17 +2870,25 @@ module ts { return result; } - function getExportsOfExternalModule(node: ImportDeclaration): Symbol[]{ + function symbolsToArray(symbols: SymbolTable): Symbol[] { + let result: Symbol[] = []; + for (let id in symbols) { + if (!isReservedMemberName(id)) { + result.push(symbols[id]); + } + } + return result; + } + + function getExportsOfExternalModule(node: ImportDeclaration): Symbol[] { if (!node.moduleSpecifier) { return emptyArray; } - let module = resolveExternalModuleName(node, node.moduleSpecifier); - if (!module || !module.exports) { + if (!module) { return emptyArray; } - - return mapToArray(getExportsOfModule(module)) + return symbolsToArray(getExportsOfModule(module)); } function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature { @@ -4406,7 +4458,7 @@ module ts { * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. */ - function isTupleType(type: Type) : boolean { + function isTupleType(type: Type): boolean { return (type.flags & TypeFlags.Tuple) && !!(type).elementTypes; } @@ -7488,7 +7540,7 @@ module ts { if (!checkForDisallowedESSymbolOperand(operator)) { return booleanType; } - // Fall through + // Fall through case SyntaxKind.EqualsEqualsToken: case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: @@ -9503,7 +9555,7 @@ module ts { if (derived) { let baseDeclarationFlags = getDeclarationFlagsFromSymbol(base); let derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived); - if ((baseDeclarationFlags & NodeFlags.Private) || (derivedDeclarationFlags & NodeFlags.Private)) { + if ((baseDeclarationFlags & NodeFlags.Private) || (derivedDeclarationFlags & NodeFlags.Private)) { // either base or derived property is private - not override, skip it continue; } @@ -9634,7 +9686,7 @@ module ts { // run subsequent checks only if first set succeeded if (checkInheritedPropertiesAreIdentical(type, node.name)) { forEach(type.baseTypes, baseType => { - checkTypeAssignableTo(type, baseType, node.name , Diagnostics.Interface_0_incorrectly_extends_interface_1); + checkTypeAssignableTo(type, baseType, node.name, Diagnostics.Interface_0_incorrectly_extends_interface_1); }); checkIndexConstraints(type); } @@ -10032,8 +10084,17 @@ module ts { } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { if (node.exportClause) { + // export { x, y } + // export { x, y } from "foo" forEach(node.exportClause.elements, checkExportSpecifier); } + else { + // export * from "foo" + let moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); + if (moduleSymbol && moduleSymbol.exports["export="]) { + error(node.moduleSpecifier, Diagnostics.External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol)); + } + } } } @@ -10073,40 +10134,47 @@ module ts { return emptyArray; } + //function hasExportedMembers(moduleSymbol: Symbol) { + // let declarations = moduleSymbol.declarations; + // for (let current of declarations) { + // let statements = getModuleStatements(current); + // for (let node of statements) { + // if (node.kind === SyntaxKind.ExportDeclaration) { + // let exportClause = (node).exportClause; + // if (!exportClause) { + // return true; + // } + // let specifiers = exportClause.elements; + // for (let specifier of specifiers) { + // if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { + // return true; + // } + // } + // } + // else if (node.kind !== SyntaxKind.ExportAssignment && node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { + // return true; + // } + // } + // } + //} + function hasExportedMembers(moduleSymbol: Symbol) { - let declarations = moduleSymbol.declarations; - for (let current of declarations) { - let statements = getModuleStatements(current); - for (let node of statements) { - if (node.kind === SyntaxKind.ExportDeclaration) { - let exportClause = (node).exportClause; - if (!exportClause) { - return true; - } - let specifiers = exportClause.elements; - for (let specifier of specifiers) { - if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { - return true; - } - } - } - else if (node.kind !== SyntaxKind.ExportAssignment && node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { - return true; - } + for (var id in moduleSymbol.exports) { + if (id !== "export=") { + return true; } } + return false; } function checkExternalModuleExports(node: SourceFile | ModuleDeclaration) { let moduleSymbol = getSymbolOfNode(node); let links = getSymbolLinks(moduleSymbol); if (!links.exportsChecked) { - let defaultSymbol = getExportAssignmentSymbol(moduleSymbol); - if (defaultSymbol) { - if (hasExportedMembers(moduleSymbol)) { - let declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; - error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); - } + let exportEqualsSymbol = moduleSymbol.exports["export="]; + if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) { + let declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration; + error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); } links.exportsChecked = true; } @@ -10436,7 +10504,7 @@ module ts { location = location.parent; } copySymbols(globals, meaning); - return mapToArray(symbols); + return symbolsToArray(symbols); } function isTypeDeclarationName(name: Node): boolean { @@ -10847,7 +10915,7 @@ module ts { } function isExistingName(name: string) { - return hasProperty(globals, name) || hasProperty(sourceFile.identifiers, name) || hasProperty(generatedNames, name); + return hasProperty(globals, name) || hasProperty(sourceFile.identifiers, name) || hasProperty(generatedNames, name); } function makeUniqueName(baseName: string): string { @@ -10881,7 +10949,7 @@ module ts { } function generateNameForImportDeclaration(node: ImportDeclaration) { - if (node.importClause && node.importClause.namedBindings && node.importClause.namedBindings.kind === SyntaxKind.NamedImports) { + if (node.importClause) { generateNameForImportOrExportDeclaration(node); } } @@ -10916,11 +10984,16 @@ module ts { } function getAliasNameSubstitution(symbol: Symbol): string { - let declaration = getDeclarationOfAliasSymbol(symbol); - if (declaration && declaration.kind === SyntaxKind.ImportSpecifier) { - let moduleName = getGeneratedNameForNode(declaration.parent.parent.parent); - let propertyName = (declaration).propertyName || (declaration).name; - return moduleName + "." + unescapeIdentifier(propertyName.text); + let node = getDeclarationOfAliasSymbol(symbol); + if (node) { + if (node.kind === SyntaxKind.ImportClause) { + return unescapeIdentifier(symbol.name) + ".default"; + } + if (node.kind === SyntaxKind.ImportSpecifier) { + let moduleName = getGeneratedNameForNode(node.parent.parent.parent); + let propertyName = (node).propertyName || (node).name; + return moduleName + "." + unescapeIdentifier(propertyName.text); + } } } @@ -10960,9 +11033,18 @@ module ts { } } - function hasExportDefaultValue(node: SourceFile): boolean { - let symbol = getResolvedExportAssignmentSymbol(getSymbolOfNode(node)); - return symbol && symbol !== unknownSymbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol); + function isValueExportDeclaration(node: Node): boolean { + if (node.kind === SyntaxKind.ExportAssignment) { + return (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; + } + if (node.kind === SyntaxKind.ExportDeclaration) { + let exportClause = (node).exportClause; + return exportClause && forEach(exportClause.elements, isValueExportDeclaration); + } + if (node.kind === SyntaxKind.ExportSpecifier) { + return isAliasResolvedToValue(getSymbolOfNode(node)); + } + return false; } function isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean { @@ -11105,7 +11187,7 @@ module ts { return { getGeneratedNameForNode, getExpressionNameSubstitution, - hasExportDefaultValue, + isValueExportDeclaration, isReferencedAliasDeclaration, getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName, diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 27fc152f534ed..2362c96bbb7f3 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -220,16 +220,6 @@ module ts { return hasProperty(map, key) ? map[key] : undefined; } - export function mapToArray(map: Map): T[] { - let result: T[] = []; - - for (let id in map) { - result.push(map[id]); - } - - return result; - } - export function copyMap(source: Map, target: Map): void { for (let p in source) { target[p] = source[p]; diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index d40fcd25ce089..361f656fc9168 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -149,7 +149,7 @@ module ts { The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer: { code: 1189, category: DiagnosticCategory.Error, key: "The variable declaration of a 'for...in' statement cannot have an initializer." }, The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer: { code: 1190, category: DiagnosticCategory.Error, key: "The variable declaration of a 'for...of' statement cannot have an initializer." }, An_import_declaration_cannot_have_modifiers: { code: 1191, category: DiagnosticCategory.Error, key: "An import declaration cannot have modifiers." }, - External_module_0_has_no_default_export_or_export_assignment: { code: 1192, category: DiagnosticCategory.Error, key: "External module '{0}' has no default export or export assignment." }, + External_module_0_has_no_default_export: { code: 1192, category: DiagnosticCategory.Error, key: "External module '{0}' has no default export." }, An_export_declaration_cannot_have_modifiers: { code: 1193, category: DiagnosticCategory.Error, key: "An export declaration cannot have modifiers." }, Export_declarations_are_not_permitted_in_an_internal_module: { code: 1194, category: DiagnosticCategory.Error, key: "Export declarations are not permitted in an internal module." }, Catch_clause_variable_name_must_be_an_identifier: { code: 1195, category: DiagnosticCategory.Error, key: "Catch clause variable name must be an identifier." }, @@ -340,6 +340,8 @@ module ts { Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." }, Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." }, Type_0_is_not_an_array_type_or_a_string_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." }, + External_module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct: { code: 2496, category: DiagnosticCategory.Error, key: "External module '{0}' resolves to a non-module entity and cannot be imported using this construct." }, + External_module_0_uses_export_and_cannot_be_used_with_export_Asterisk: { code: 2497, category: DiagnosticCategory.Error, key: "External module '{0}' uses 'export =' and cannot be used with 'export *'." }, 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 c4121e92251b2..6133642865a59 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -587,7 +587,7 @@ "category": "Error", "code": 1191 }, - "External module '{0}' has no default export or export assignment.": { + "External module '{0}' has no default export.": { "category": "Error", "code": 1192 }, @@ -1351,6 +1351,14 @@ "category": "Error", "code": 2461 }, + "External module '{0}' resolves to a non-module entity and cannot be imported using this construct.": { + "category": "Error", + "code": 2496 + }, + "External module '{0}' uses 'export =' and cannot be used with 'export *'.": { + "category": "Error", + "code": 2497 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 54ec39a5b5568..8270c74127aca 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1589,7 +1589,7 @@ module ts { let tempParameters: Identifier[]; let externalImports: ExternalImportInfo[]; let exportSpecifiers: Map; - let exportDefault: FunctionDeclaration | ClassDeclaration | ExportAssignment | ExportSpecifier; + let exportEquals: ExportAssignment; /** write emitted output to disk*/ let writeEmittedFiles = writeJavaScriptFile; @@ -3851,9 +3851,26 @@ module ts { return result; } + function emitExportMemberAssignment(node: FunctionLikeDeclaration | ClassDeclaration) { + if (node.flags & NodeFlags.Export) { + writeLine(); + emitStart(node); + if (node.name) { + emitModuleMemberName(node); + } + else { + write("exports.default"); + } + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } + } + function emitExportMemberAssignments(name: Identifier) { - if (!exportDefault && exportSpecifiers && hasProperty(exportSpecifiers, name.text)) { - forEach(exportSpecifiers[name.text], specifier => { + if (!exportEquals && exportSpecifiers && hasProperty(exportSpecifiers, name.text)) { + for (let specifier of exportSpecifiers[name.text]) { writeLine(); emitStart(specifier.name); emitContainingModuleName(specifier); @@ -3863,7 +3880,7 @@ module ts { write(" = "); emitNodeWithoutSourceMap(name); write(";"); - }); + } } } @@ -4400,15 +4417,7 @@ module ts { emitExpressionFunctionBody(node, node.body); } - if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emitDeclarationName(node); - emitEnd(node); - write(";"); - } + emitExportMemberAssignment(node); exitNameScope(popFrame); @@ -4725,15 +4734,7 @@ module ts { } write(");"); emitEnd(node); - if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { - writeLine(); - emitStart(node); - emitModuleMemberName(node); - write(" = "); - emitDeclarationName(node); - emitEnd(node); - write(";"); - } + emitExportMemberAssignment(node); if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } @@ -5057,7 +5058,7 @@ module ts { } function emitExportDeclaration(node: ExportDeclaration) { - if (node.moduleSpecifier) { + if (node.moduleSpecifier && (!node.exportClause || resolver.isValueExportDeclaration(node))) { emitStart(node); let generatedName = resolver.getGeneratedNameForNode(node); if (compilerOptions.module !== ModuleKind.AMD) { @@ -5067,23 +5068,25 @@ module ts { emitRequire(getExternalModuleName(node)); } if (node.exportClause) { - // export { x, y, ... } - forEach(node.exportClause.elements, specifier => { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithoutSourceMap(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - }); + // export { x, y, ... } from "foo" + for (let specifier of node.exportClause.elements) { + if (resolver.isValueExportDeclaration(specifier)) { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithoutSourceMap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + } + } } else { - // export * + // export * from "foo" let tempName = createTempVariable(node).text; writeLine(); write("for (var " + tempName + " in " + generatedName + ") if (!"); @@ -5096,6 +5099,18 @@ module ts { } } + function emitExportAssignment(node: ExportAssignment) { + if (!node.isExportEquals && resolver.isValueExportDeclaration(node)) { + writeLine(); + emitStart(node); + emitContainingModuleName(node); + write(".default = "); + emit(node.expression); + write(";"); + emitEnd(node); + } + } + function createExternalImportInfo(node: Node): ExternalImportInfo { if (node.kind === SyntaxKind.ImportEqualsDeclaration) { if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { @@ -5142,25 +5157,19 @@ module ts { function createExternalModuleInfo(sourceFile: SourceFile) { externalImports = []; exportSpecifiers = {}; - exportDefault = undefined; + exportEquals = undefined; forEach(sourceFile.statements, node => { - if (node.kind === SyntaxKind.ExportDeclaration && !(node).moduleSpecifier) { + if (node.kind === SyntaxKind.ExportAssignment) { + if ((node).isExportEquals && !exportEquals) { + exportEquals = node; + } + } + else if (node.kind === SyntaxKind.ExportDeclaration && !(node).moduleSpecifier) { forEach((node).exportClause.elements, specifier => { - if (specifier.name.text === "default") { - exportDefault = exportDefault || specifier; - } let name = (specifier.propertyName || specifier.name).text; (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); }); } - else if (node.kind === SyntaxKind.ExportAssignment) { - exportDefault = exportDefault || node; - } - else if (node.kind === SyntaxKind.FunctionDeclaration || node.kind === SyntaxKind.ClassDeclaration) { - if (node.flags & NodeFlags.Export && node.flags & NodeFlags.Default) { - exportDefault = exportDefault || node; - } - } else { let info = createExternalImportInfo(node); if (info) { @@ -5182,14 +5191,6 @@ module ts { } } - function getFirstExportAssignment(sourceFile: SourceFile) { - return forEach(sourceFile.statements, node => { - if (node.kind === SyntaxKind.ExportAssignment) { - return node; - } - }); - } - function sortAMDModules(amdModules: {name: string; path: string}[]) { // AMD modules with declared variable names go first return amdModules.sort((moduleA, moduleB) => { @@ -5247,7 +5248,7 @@ module ts { emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); - emitExportDefault(node, /*emitAsReturn*/ true); + emitExportEquals(/*emitAsReturn*/ true); decreaseIndent(); writeLine(); write("});"); @@ -5257,25 +5258,17 @@ module ts { emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); - emitExportDefault(node, /*emitAsReturn*/ false); + emitExportEquals(/*emitAsReturn*/ false); } - function emitExportDefault(sourceFile: SourceFile, emitAsReturn: boolean) { - if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { + function emitExportEquals(emitAsReturn: boolean) { + if (exportEquals && resolver.isValueExportDeclaration(exportEquals)) { writeLine(); - emitStart(exportDefault); + emitStart(exportEquals); write(emitAsReturn ? "return " : "module.exports = "); - if (exportDefault.kind === SyntaxKind.ExportAssignment) { - emit((exportDefault).expression); - } - else if (exportDefault.kind === SyntaxKind.ExportSpecifier) { - emit((exportDefault).propertyName); - } - else { - emitDeclarationName(exportDefault); - } + emit((exportEquals).expression); write(";"); - emitEnd(exportDefault); + emitEnd(exportEquals); } } @@ -5331,7 +5324,7 @@ module ts { else { externalImports = undefined; exportSpecifiers = undefined; - exportDefault = undefined; + exportEquals = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); @@ -5549,6 +5542,8 @@ module ts { return emitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: return emitExportDeclaration(node); + case SyntaxKind.ExportAssignment: + return emitExportAssignment(node); case SyntaxKind.SourceFile: return emitSourceFileNode(node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7f89ff6153bc3..0031c7ebd22aa 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4820,29 +4820,30 @@ module ts { function parseImportOrExportSpecifier(kind: SyntaxKind): ImportOrExportSpecifier { let node = createNode(kind); // ImportSpecifier: - // ImportedBinding - // IdentifierName as ImportedBinding - let isFirstIdentifierNameNotAnIdentifier = isKeyword(token) && !isIdentifier(); - let start = scanner.getTokenPos(); + // BindingIdentifier + // IdentifierName as BindingIdentifier + // ExportSpecififer: + // IdentifierName + // IdentifierName as IdentifierName + let checkIdentifierIsKeyword = isKeyword(token) && !isIdentifier(); + let checkIdentifierStart = scanner.getTokenPos(); + let checkIdentifierEnd = scanner.getTextPos(); let identifierName = parseIdentifierName(); if (token === SyntaxKind.AsKeyword) { node.propertyName = identifierName; parseExpected(SyntaxKind.AsKeyword); - if (isIdentifier()) { - node.name = parseIdentifierName(); - } - else { - parseErrorAtCurrentToken(Diagnostics.Identifier_expected); - } + checkIdentifierIsKeyword = isKeyword(token) && !isIdentifier(); + checkIdentifierStart = scanner.getTokenPos(); + checkIdentifierEnd = scanner.getTextPos(); + node.name = parseIdentifierName(); } else { node.name = identifierName; - if (isFirstIdentifierNameNotAnIdentifier) { - // Report error identifier expected - parseErrorAtPosition(start, identifierName.end - start, Diagnostics.Identifier_expected); - } } - + if (kind === SyntaxKind.ImportSpecifier && checkIdentifierIsKeyword) { + // Report error identifier expected + parseErrorAtPosition(checkIdentifierStart, checkIdentifierEnd - checkIdentifierStart, Diagnostics.Identifier_expected); + } return finishNode(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1631cc46a008a..75b1364aa5de9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1199,7 +1199,7 @@ module ts { export interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - hasExportDefaultValue(node: SourceFile): boolean; + isValueExportDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/cases/fourslash/goToDefinitionImportedNames7.ts b/tests/cases/fourslash/goToDefinitionImportedNames7.ts index 46d09012d4099..3c367600b1f8e 100644 --- a/tests/cases/fourslash/goToDefinitionImportedNames7.ts +++ b/tests/cases/fourslash/goToDefinitionImportedNames7.ts @@ -8,7 +8,7 @@ /////*classDefinition*/class Class { //// private f; ////} -////export = Class; +////export default Class; goTo.file("b.ts"); From f3fb85fa46887e7b1418f300d8e94c0a0751ae18 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 21 Mar 2015 13:18:11 -0700 Subject: [PATCH 03/24] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 3 +- .../reference/APISample_compile.types | 11 +++-- tests/baselines/reference/APISample_linter.js | 3 +- .../reference/APISample_linter.types | 11 +++-- .../reference/APISample_transform.js | 3 +- .../reference/APISample_transform.types | 11 +++-- .../baselines/reference/APISample_watcher.js | 3 +- .../reference/APISample_watcher.types | 11 +++-- ...lModuleWithInternalImportDeclaration.types | 10 ++--- ...FileImportModuleWithExportAssignment.types | 14 +++--- ...ernalModuleWithExportAssignedFundule.types | 2 +- .../declareFileExportAssignment.types | 14 +++--- ...signmentWithVarFromVariableStatement.types | 14 +++--- .../duplicateExportAssignments.errors.txt | 44 +++++++++---------- .../es6ImportDefaultBinding.errors.txt | 4 +- ...tBindingFollowedWithNamedImport.errors.txt | 24 +++++----- ...ingFollowedWithNamedImportInEs5.errors.txt | 24 +++++----- ...ingFollowedWithNamespaceBinding.errors.txt | 4 +- ...llowedWithNamespaceBindingInEs5.errors.txt | 4 +- .../es6ImportDefaultBindingInEs5.errors.txt | 4 +- ...s6ImportNamedImportParsingError.errors.txt | 4 +- .../exportAssignClassAndModule.types | 4 +- .../reference/exportEqualNamespaces.types | 2 +- .../multipleExportAssignments.errors.txt | 8 ++-- ...AssignmentsInAmbientDeclaration.errors.txt | 8 ++-- ...ssignmentOnExportedGenericInterface1.types | 4 +- 26 files changed, 132 insertions(+), 116 deletions(-) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 985718231810c..84ee9ef859d4a 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -321,6 +321,7 @@ declare module "typescript" { Let = 4096, Const = 8192, OctalLiteral = 16384, + ExportContext = 32768, Modifier = 499, AccessibilityModifier = 112, BlockScoped = 12288, @@ -935,7 +936,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - hasExportDefaultValue(node: SourceFile): boolean; + isValueExportDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 087c0389d0fce..d6ac61eb94a52 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -978,6 +978,9 @@ declare module "typescript" { OctalLiteral = 16384, >OctalLiteral : NodeFlags + ExportContext = 32768, +>ExportContext : NodeFlags + Modifier = 499, >Modifier : NodeFlags @@ -2995,10 +2998,10 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - hasExportDefaultValue(node: SourceFile): boolean; ->hasExportDefaultValue : (node: SourceFile) => boolean ->node : SourceFile ->SourceFile : SourceFile + isValueExportDeclaration(node: Node): boolean; +>isValueExportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node isReferencedAliasDeclaration(node: Node): boolean; >isReferencedAliasDeclaration : (node: Node) => boolean diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index d43d622007210..931d9473a17cb 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -352,6 +352,7 @@ declare module "typescript" { Let = 4096, Const = 8192, OctalLiteral = 16384, + ExportContext = 32768, Modifier = 499, AccessibilityModifier = 112, BlockScoped = 12288, @@ -966,7 +967,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - hasExportDefaultValue(node: SourceFile): boolean; + isValueExportDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 14eb2936242bd..6f7da4147f2e3 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -1124,6 +1124,9 @@ declare module "typescript" { OctalLiteral = 16384, >OctalLiteral : NodeFlags + ExportContext = 32768, +>ExportContext : NodeFlags + Modifier = 499, >Modifier : NodeFlags @@ -3141,10 +3144,10 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - hasExportDefaultValue(node: SourceFile): boolean; ->hasExportDefaultValue : (node: SourceFile) => boolean ->node : SourceFile ->SourceFile : SourceFile + isValueExportDeclaration(node: Node): boolean; +>isValueExportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node isReferencedAliasDeclaration(node: Node): boolean; >isReferencedAliasDeclaration : (node: Node) => boolean diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index bfe62135a0db3..3f739c9931d76 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -353,6 +353,7 @@ declare module "typescript" { Let = 4096, Const = 8192, OctalLiteral = 16384, + ExportContext = 32768, Modifier = 499, AccessibilityModifier = 112, BlockScoped = 12288, @@ -967,7 +968,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - hasExportDefaultValue(node: SourceFile): boolean; + isValueExportDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index baa497c95fa50..ba8cde8001cee 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -1074,6 +1074,9 @@ declare module "typescript" { OctalLiteral = 16384, >OctalLiteral : NodeFlags + ExportContext = 32768, +>ExportContext : NodeFlags + Modifier = 499, >Modifier : NodeFlags @@ -3091,10 +3094,10 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - hasExportDefaultValue(node: SourceFile): boolean; ->hasExportDefaultValue : (node: SourceFile) => boolean ->node : SourceFile ->SourceFile : SourceFile + isValueExportDeclaration(node: Node): boolean; +>isValueExportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node isReferencedAliasDeclaration(node: Node): boolean; >isReferencedAliasDeclaration : (node: Node) => boolean diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index ee1fd06251576..1328ce98e67b2 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -390,6 +390,7 @@ declare module "typescript" { Let = 4096, Const = 8192, OctalLiteral = 16384, + ExportContext = 32768, Modifier = 499, AccessibilityModifier = 112, BlockScoped = 12288, @@ -1004,7 +1005,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - hasExportDefaultValue(node: SourceFile): boolean; + isValueExportDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index a8b534439d546..7a82d7052313b 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1247,6 +1247,9 @@ declare module "typescript" { OctalLiteral = 16384, >OctalLiteral : NodeFlags + ExportContext = 32768, +>ExportContext : NodeFlags + Modifier = 499, >Modifier : NodeFlags @@ -3264,10 +3267,10 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - hasExportDefaultValue(node: SourceFile): boolean; ->hasExportDefaultValue : (node: SourceFile) => boolean ->node : SourceFile ->SourceFile : SourceFile + isValueExportDeclaration(node: Node): boolean; +>isValueExportDeclaration : (node: Node) => boolean +>node : Node +>Node : Node isReferencedAliasDeclaration(node: Node): boolean; >isReferencedAliasDeclaration : (node: Node) => boolean diff --git a/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.types b/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.types index 22e4b19fb25fc..4e9043d1b75f8 100644 --- a/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.types +++ b/tests/baselines/reference/ambientExternalModuleWithInternalImportDeclaration.types @@ -11,23 +11,23 @@ var c = new A(); === tests/cases/compiler/ambientExternalModuleWithInternalImportDeclaration_0.ts === declare module 'M' { module C { ->C : typeof X +>C : typeof C export var f: number; >f : number } class C { ->C : X +>C : C foo(): void; >foo : () => void } import X = C; ->X : typeof X ->C : X +>X : typeof C +>C : C export = X; ->X : X +>X : C } diff --git a/tests/baselines/reference/declFileImportModuleWithExportAssignment.types b/tests/baselines/reference/declFileImportModuleWithExportAssignment.types index 94f3e57b1a6e7..a2ae5c0768719 100644 --- a/tests/baselines/reference/declFileImportModuleWithExportAssignment.types +++ b/tests/baselines/reference/declFileImportModuleWithExportAssignment.types @@ -42,23 +42,23 @@ module m2 { } var m2: { ->m2 : { (): default.connectExport; test1: default.connectModule; test2(): default.connectModule; } +>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; } (): m2.connectExport; >m2 : unknown ->connectExport : default.connectExport +>connectExport : export=.connectExport test1: m2.connectModule; ->test1 : default.connectModule +>test1 : export=.connectModule >m2 : unknown ->connectModule : default.connectModule +>connectModule : export=.connectModule test2(): m2.connectModule; ->test2 : () => default.connectModule +>test2 : () => export=.connectModule >m2 : unknown ->connectModule : default.connectModule +>connectModule : export=.connectModule }; export = m2; ->m2 : { (): default.connectExport; test1: default.connectModule; test2(): default.connectModule; } +>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; } diff --git a/tests/baselines/reference/declareExternalModuleWithExportAssignedFundule.types b/tests/baselines/reference/declareExternalModuleWithExportAssignedFundule.types index ff496f678f215..e861059af75f0 100644 --- a/tests/baselines/reference/declareExternalModuleWithExportAssignedFundule.types +++ b/tests/baselines/reference/declareExternalModuleWithExportAssignedFundule.types @@ -7,7 +7,7 @@ declare module "express" { function express(): express.ExpressServer; >express : typeof express >express : unknown ->ExpressServer : default.ExpressServer +>ExpressServer : export=.ExpressServer module express { >express : typeof express diff --git a/tests/baselines/reference/declareFileExportAssignment.types b/tests/baselines/reference/declareFileExportAssignment.types index 5853663634cdf..80cfbf82387b3 100644 --- a/tests/baselines/reference/declareFileExportAssignment.types +++ b/tests/baselines/reference/declareFileExportAssignment.types @@ -27,24 +27,24 @@ module m2 { } var m2: { ->m2 : { (): default.connectExport; test1: default.connectModule; test2(): default.connectModule; } +>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; } (): m2.connectExport; >m2 : unknown ->connectExport : default.connectExport +>connectExport : export=.connectExport test1: m2.connectModule; ->test1 : default.connectModule +>test1 : export=.connectModule >m2 : unknown ->connectModule : default.connectModule +>connectModule : export=.connectModule test2(): m2.connectModule; ->test2 : () => default.connectModule +>test2 : () => export=.connectModule >m2 : unknown ->connectModule : default.connectModule +>connectModule : export=.connectModule }; export = m2; ->m2 : { (): default.connectExport; test1: default.connectModule; test2(): default.connectModule; } +>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; } diff --git a/tests/baselines/reference/declareFileExportAssignmentWithVarFromVariableStatement.types b/tests/baselines/reference/declareFileExportAssignmentWithVarFromVariableStatement.types index baa9fa1170c09..376a9d7ba6f4d 100644 --- a/tests/baselines/reference/declareFileExportAssignmentWithVarFromVariableStatement.types +++ b/tests/baselines/reference/declareFileExportAssignmentWithVarFromVariableStatement.types @@ -28,24 +28,24 @@ module m2 { var x = 10, m2: { >x : number ->m2 : { (): default.connectExport; test1: default.connectModule; test2(): default.connectModule; } +>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; } (): m2.connectExport; >m2 : unknown ->connectExport : default.connectExport +>connectExport : export=.connectExport test1: m2.connectModule; ->test1 : default.connectModule +>test1 : export=.connectModule >m2 : unknown ->connectModule : default.connectModule +>connectModule : export=.connectModule test2(): m2.connectModule; ->test2 : () => default.connectModule +>test2 : () => export=.connectModule >m2 : unknown ->connectModule : default.connectModule +>connectModule : export=.connectModule }; export = m2; ->m2 : { (): default.connectExport; test1: default.connectModule; test2(): default.connectModule; } +>m2 : { (): export=.connectExport; test1: export=.connectModule; test2(): export=.connectModule; } diff --git a/tests/baselines/reference/duplicateExportAssignments.errors.txt b/tests/baselines/reference/duplicateExportAssignments.errors.txt index 1fc844fcaadae..c0a93076981fe 100644 --- a/tests/baselines/reference/duplicateExportAssignments.errors.txt +++ b/tests/baselines/reference/duplicateExportAssignments.errors.txt @@ -1,15 +1,15 @@ tests/cases/conformance/externalModules/foo1.ts(3,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. -tests/cases/conformance/externalModules/foo1.ts(3,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo1.ts(4,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo2.ts(3,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo2.ts(4,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo3.ts(7,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo3.ts(8,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo4.ts(1,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo4.ts(8,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo5.ts(4,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo5.ts(5,1): error TS2300: Duplicate identifier 'default'. -tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate identifier 'default'. +tests/cases/conformance/externalModules/foo1.ts(3,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo1.ts(4,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo2.ts(3,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo2.ts(4,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo3.ts(7,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo3.ts(8,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo4.ts(1,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo4.ts(8,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo5.ts(4,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo5.ts(5,1): error TS2300: Duplicate identifier 'export='. +tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo1.ts (3 errors) ==== @@ -19,20 +19,20 @@ tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate id ~~~~~~~~~~~ !!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. export = y; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo2.ts (2 errors) ==== var x = 10; class y {}; export = x; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. export = y; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo3.ts (2 errors) ==== module x { @@ -43,15 +43,15 @@ tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate id } export = x; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. export = y; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo4.ts (2 errors) ==== export = x; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. function x(){ return 42; } @@ -60,7 +60,7 @@ tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate id } export = y; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. ==== tests/cases/conformance/externalModules/foo5.ts (3 errors) ==== var x = 5; @@ -68,11 +68,11 @@ tests/cases/conformance/externalModules/foo5.ts(6,1): error TS2300: Duplicate id var z = {}; export = x; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. export = y; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. export = z; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt index 85390ecce4b8a..a35606749b3bb 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export. ==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (0 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External m ==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== import defaultBinding from "es6ImportDefaultBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index bd8714cb86fe1..d9cc779419356 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. @@ -21,31 +21,31 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): e ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (12 errors) ==== import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export. ~~~~~~~~~~~~~~ !!! 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 157360f52382d..cc41e2c707d2e 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt @@ -1,14 +1,14 @@ -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. @@ -21,31 +21,31 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6, ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (12 errors) ==== import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. ~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'defaultBinding'. import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export. ~~~~~~~~~~~~~~ !!! 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 index 98371eb91988f..50302a5331dc0 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts (0 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1, ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt index f1d20dccc59e3..ae4587e07dc9a 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts (0 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt index 5d656094a8c72..506793103f810 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export. ==== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts (0 errors) ==== @@ -8,4 +8,4 @@ tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1192: Exter ==== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts (1 errors) ==== import defaultBinding from "es6ImportDefaultBindingInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt index 2242810098540..c9586d0169369 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.errors.txt @@ -3,7 +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 TS1192: External module '"tests/cases/compiler/es6ImportNamedImportParsingError_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportNamedImportParsingError_0"' has no default export. 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. @@ -34,7 +34,7 @@ tests/cases/compiler/es6ImportNamedImportParsingError_1.ts(4,20): error TS1005: !!! error TS1005: ';' expected. import defaultBinding, from "es6ImportNamedImportParsingError_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportNamedImportParsingError_0"' has no default export or export assignment. +!!! error TS1192: External module '"tests/cases/compiler/es6ImportNamedImportParsingError_0"' has no default export. ~~~~ !!! error TS1005: '{' expected. import , { a } from "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/exportAssignClassAndModule.types b/tests/baselines/reference/exportAssignClassAndModule.types index 9087ac096337e..05a5cbf07ae39 100644 --- a/tests/baselines/reference/exportAssignClassAndModule.types +++ b/tests/baselines/reference/exportAssignClassAndModule.types @@ -22,9 +22,9 @@ class Foo { >Foo : Foo x: Foo.Bar; ->x : default.Bar +>x : export=.Bar >Foo : unknown ->Bar : default.Bar +>Bar : export=.Bar } module Foo { >Foo : typeof Foo diff --git a/tests/baselines/reference/exportEqualNamespaces.types b/tests/baselines/reference/exportEqualNamespaces.types index b60ba5a85c0a4..b94770837a414 100644 --- a/tests/baselines/reference/exportEqualNamespaces.types +++ b/tests/baselines/reference/exportEqualNamespaces.types @@ -12,7 +12,7 @@ interface server { (): server.Server; >server : unknown ->Server : default.Server +>Server : export=.Server startTime: Date; >startTime : Date diff --git a/tests/baselines/reference/multipleExportAssignments.errors.txt b/tests/baselines/reference/multipleExportAssignments.errors.txt index 604236a051681..5fbabc2b4db16 100644 --- a/tests/baselines/reference/multipleExportAssignments.errors.txt +++ b/tests/baselines/reference/multipleExportAssignments.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/multipleExportAssignments.ts(13,1): error TS2300: Duplicate identifier 'default'. -tests/cases/compiler/multipleExportAssignments.ts(14,1): error TS2300: Duplicate identifier 'default'. +tests/cases/compiler/multipleExportAssignments.ts(13,1): error TS2300: Duplicate identifier 'export='. +tests/cases/compiler/multipleExportAssignments.ts(14,1): error TS2300: Duplicate identifier 'export='. ==== tests/cases/compiler/multipleExportAssignments.ts (2 errors) ==== @@ -17,9 +17,9 @@ tests/cases/compiler/multipleExportAssignments.ts(14,1): error TS2300: Duplicate }; export = server; ~~~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. export = connectExport; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. \ No newline at end of file diff --git a/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt b/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt index ac076e7016cdb..c6427a5cc28e5 100644 --- a/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt +++ b/tests/baselines/reference/multipleExportAssignmentsInAmbientDeclaration.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(4,5): error TS2300: Duplicate identifier 'default'. -tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(5,5): error TS2300: Duplicate identifier 'default'. +tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(4,5): error TS2300: Duplicate identifier 'export='. +tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(5,5): error TS2300: Duplicate identifier 'export='. ==== tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts (2 errors) ==== @@ -8,8 +8,8 @@ tests/cases/compiler/multipleExportAssignmentsInAmbientDeclaration.ts(5,5): erro var b: number; export = a; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. export = b; ~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'default'. +!!! error TS2300: Duplicate identifier 'export='. } \ No newline at end of file diff --git a/tests/baselines/reference/privacyCheckExportAssignmentOnExportedGenericInterface1.types b/tests/baselines/reference/privacyCheckExportAssignmentOnExportedGenericInterface1.types index b0af8ae0b6e4d..f0c8c25be291e 100644 --- a/tests/baselines/reference/privacyCheckExportAssignmentOnExportedGenericInterface1.types +++ b/tests/baselines/reference/privacyCheckExportAssignmentOnExportedGenericInterface1.types @@ -12,9 +12,9 @@ interface Foo { >T : T } var Foo: new () => Foo.A>; ->Foo : new () => default.A> +>Foo : new () => export=.A> >Foo : unknown ->A : default.A +>A : export=.A >Foo : Foo export = Foo; From 6838d47834648d5453261039ac4bbd5efc8af7ba Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 21 Mar 2015 15:09:54 -0700 Subject: [PATCH 04/24] Simplify collection of external module info in emitter --- src/compiler/emitter.ts | 201 ++++++++++++++++++---------------------- 1 file changed, 88 insertions(+), 113 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8270c74127aca..56904aab80cce 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -16,12 +16,6 @@ module ts { getIndent(): number; } - interface ExternalImportInfo { - rootNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration; - declarationNode?: ImportEqualsDeclaration | ImportClause | NamespaceImport; - namedImports?: NamedImports; - } - interface SymbolAccessibilityDiagnostic { errorNode: Node; diagnosticMessage: DiagnosticMessage; @@ -1587,9 +1581,10 @@ module ts { let tempCount = 0; let tempVariables: Identifier[]; let tempParameters: Identifier[]; - let externalImports: ExternalImportInfo[]; + let externalImports: (ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration)[]; let exportSpecifiers: Map; let exportEquals: ExportAssignment; + let hasExportStars: boolean; /** write emitted output to disk*/ let writeEmittedFiles = writeJavaScriptFile; @@ -4995,41 +4990,47 @@ module ts { } } + function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) { + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + return node; + } + let importClause = (node).importClause; + if (importClause && importClause.namedBindings && importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + return importClause.namedBindings; + } + } + + function isNakedImport(node: ImportDeclaration | ImportEqualsDeclaration) { + return node.kind === SyntaxKind.ImportDeclaration && !(node).importClause; + } + function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { - let info = getExternalImportInfo(node); - if (info) { - let declarationNode = info.declarationNode; - let namedImports = info.namedImports; + if (contains(externalImports, node)) { + let exportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; + let namespaceDeclaration = getNamespaceDeclarationNode(node); if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); - let moduleName = getExternalModuleName(node); - if (declarationNode) { - if (!(declarationNode.flags & NodeFlags.Export)) write("var "); - emitModuleMemberName(declarationNode); + if (namespaceDeclaration) { + if (!exportedImport) write("var "); + emitModuleMemberName(namespaceDeclaration); write(" = "); - emitRequire(moduleName); } - else if (namedImports) { + else if (!isNakedImport(node)) { write("var "); write(resolver.getGeneratedNameForNode(node)); write(" = "); - emitRequire(moduleName); - } - else { - emitRequire(moduleName); } + emitRequire(getExternalModuleName(node)); emitEnd(node); emitTrailingComments(node); } else { - if (declarationNode) { - if (declarationNode.flags & NodeFlags.Export) { - emitModuleMemberName(declarationNode); - write(" = "); - emit(declarationNode.name); - write(";"); - } + if (exportedImport) { + emitModuleMemberName(namespaceDeclaration); + write(" = "); + emit(namespaceDeclaration.name); + write(";"); } } } @@ -5111,82 +5112,54 @@ module ts { } } - function createExternalImportInfo(node: Node): ExternalImportInfo { - if (node.kind === SyntaxKind.ImportEqualsDeclaration) { - if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { - return { - rootNode: node, - declarationNode: node - }; - } - } - else if (node.kind === SyntaxKind.ImportDeclaration) { - let importClause = (node).importClause; - if (importClause) { - if (importClause.name) { - return { - rootNode: node, - declarationNode: importClause - }; - } - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - return { - rootNode: node, - declarationNode: importClause.namedBindings - }; - } - return { - rootNode: node, - namedImports: importClause.namedBindings, - localName: resolver.getGeneratedNameForNode(node) - }; - } - return { - rootNode: node - } - } - else if (node.kind === SyntaxKind.ExportDeclaration) { - if ((node).moduleSpecifier) { - return { - rootNode: node, - }; - } - } - } - - function createExternalModuleInfo(sourceFile: SourceFile) { + function collectExternalModuleInfo(sourceFile: SourceFile) { externalImports = []; exportSpecifiers = {}; exportEquals = undefined; - forEach(sourceFile.statements, node => { - if (node.kind === SyntaxKind.ExportAssignment) { - if ((node).isExportEquals && !exportEquals) { - exportEquals = node; - } - } - else if (node.kind === SyntaxKind.ExportDeclaration && !(node).moduleSpecifier) { - forEach((node).exportClause.elements, specifier => { - let name = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); - }); - } - else { - let info = createExternalImportInfo(node); - if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedAliasDeclaration(node)) { - externalImports.push(info); + hasExportStars = false; + for (let node of sourceFile.statements) { + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + if (!(node).importClause || resolver.isReferencedAliasDeclaration(node)) { + // import "mod" + // import x from "mod" where x is referenced + // import * as x from "mod" where x is referenced + // import { x, y } from "mod" where at least one import is referenced + externalImports.push(node); } - } - } - }); - } - - function getExternalImportInfo(node: ImportDeclaration | ImportEqualsDeclaration): ExternalImportInfo { - if (externalImports) { - for (let info of externalImports) { - if (info.rootNode === node) { - return info; - } + break; + case SyntaxKind.ImportEqualsDeclaration: + if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference && resolver.isReferencedAliasDeclaration(node)) { + // import x = require("mod") where x is referenced + externalImports.push(node); + } + break; + case SyntaxKind.ExportDeclaration: + if ((node).moduleSpecifier) { + if (!(node).exportClause) { + // export * from "mod" + externalImports.push(node); + hasExportStars = true; + } + else if (resolver.isValueExportDeclaration(node)) { + // export { x, y } from "mod" where at least one export is a value symbol + externalImports.push(node); + } + } + else { + // export { x, y } + for (let specifier of (node).exportClause.elements) { + let name = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier); + } + } + break; + case SyntaxKind.ExportAssignment: + if ((node).isExportEquals && !exportEquals) { + // export = x + exportEquals = node; + } + break; } } } @@ -5212,37 +5185,38 @@ module ts { write("\"" + node.amdModuleName + "\", "); } write("[\"require\", \"exports\""); - forEach(externalImports, info => { + for (let importNode of externalImports) { write(", "); - let moduleName = getExternalModuleName(info.rootNode); + let moduleName = getExternalModuleName(importNode); if (moduleName.kind === SyntaxKind.StringLiteral) { emitLiteral(moduleName); } else { write("\"\""); } - }); - forEach(node.amdDependencies, amdDependency => { + } + for (let amdDependency of node.amdDependencies) { let text = "\"" + amdDependency.path + "\""; write(", "); write(text); - }); + } write("], function (require, exports"); - forEach(externalImports, info => { + for (let importNode of externalImports) { write(", "); - if (info.declarationNode) { - emit(info.declarationNode.name); + let namespaceDeclaration = getNamespaceDeclarationNode(importNode); + if (namespaceDeclaration) { + emit(namespaceDeclaration.name); } else { - write(resolver.getGeneratedNameForNode(info.rootNode)); + write(resolver.getGeneratedNameForNode(importNode)); } - }); - forEach(node.amdDependencies, amdDependency => { + } + for (let amdDependency of node.amdDependencies) { if (amdDependency.name) { write(", "); write(amdDependency.name); } - }); + } write(") {"); increaseIndent(); emitCaptureThisForNodeIfNecessary(node); @@ -5313,7 +5287,7 @@ module ts { extendsEmitted = true; } if (isExternalModule(node)) { - createExternalModuleInfo(node); + collectExternalModuleInfo(node); if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } @@ -5325,6 +5299,7 @@ module ts { externalImports = undefined; exportSpecifiers = undefined; exportEquals = undefined; + hasExportStars = false; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); From a1525157c7162aee2e615053edde0f3316237a70 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 21 Mar 2015 15:46:16 -0700 Subject: [PATCH 05/24] Emit and use '__export' helper for 'export *' declarations --- src/compiler/emitter.ts | 46 ++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 56904aab80cce..bcc9e19d696bf 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4983,10 +4983,9 @@ module ts { emitLiteral(moduleName); emitEnd(moduleName); emitToken(SyntaxKind.CloseParenToken, moduleName.end); - write(";"); } else { - write("require();"); + write("require()"); } } @@ -5022,6 +5021,7 @@ module ts { write(" = "); } emitRequire(getExternalModuleName(node)); + write(";"); emitEnd(node); emitTrailingComments(node); } @@ -5062,14 +5062,15 @@ module ts { if (node.moduleSpecifier && (!node.exportClause || resolver.isValueExportDeclaration(node))) { emitStart(node); let generatedName = resolver.getGeneratedNameForNode(node); - if (compilerOptions.module !== ModuleKind.AMD) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(getExternalModuleName(node)); - } if (node.exportClause) { // export { x, y, ... } from "foo" + if (compilerOptions.module !== ModuleKind.AMD) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(getExternalModuleName(node)); + write(";"); + } for (let specifier of node.exportClause.elements) { if (resolver.isValueExportDeclaration(specifier)) { writeLine(); @@ -5088,13 +5089,15 @@ module ts { } else { // export * from "foo" - let tempName = createTempVariable(node).text; writeLine(); - write("for (var " + tempName + " in " + generatedName + ") if (!"); - emitContainingModuleName(node); - write(".hasOwnProperty(" + tempName + ")) "); - emitContainingModuleName(node); - write("[" + tempName + "] = " + generatedName + "[" + tempName + "];"); + write("__export("); + if (compilerOptions.module !== ModuleKind.AMD) { + emitRequire(getExternalModuleName(node)); + } + else { + write(generatedName); + } + write(");"); } emitEnd(node); } @@ -5177,6 +5180,19 @@ module ts { }); } + function emitExportStarHelper() { + if (hasExportStars) { + writeLine(); + write("function __export(m) {"); + increaseIndent(); + writeLine(); + write("for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];"); + decreaseIndent(); + writeLine(); + write("}"); + } + } + function emitAMDModule(node: SourceFile, startIndex: number) { writeLine(); write("define("); @@ -5219,6 +5235,7 @@ module ts { } write(") {"); increaseIndent(); + emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); @@ -5229,6 +5246,7 @@ module ts { } function emitCommonJSModule(node: SourceFile, startIndex: number) { + emitExportStarHelper(); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); From 20d1f730870511d4c1e647d88a615a18824cd686 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 09:10:10 -0700 Subject: [PATCH 06/24] Add support for exporting imported symbols --- src/compiler/checker.ts | 48 ++++++++++++++------------------------- src/compiler/emitter.ts | 27 +++++++++++++++++----- src/compiler/types.ts | 2 +- src/compiler/utilities.ts | 17 ++++++++++++++ 4 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a68a53436e3de..facf729775586 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -323,7 +323,7 @@ module ts { if (!isExternalModule(location)) break; case SyntaxKind.ModuleDeclaration: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & SymbolFlags.ModuleMember)) { - if (!(result.flags & SymbolFlags.Alias && getDeclarationOfAliasSymbol(result).kind === SyntaxKind.ExportSpecifier)) { + if (result.flags & meaning || !(result.flags & SymbolFlags.Alias && getDeclarationOfAliasSymbol(result).kind === SyntaxKind.ExportSpecifier)) { break loop; } result = undefined; @@ -495,23 +495,6 @@ module ts { return false; } - // An alias symbol is created by one of the following declarations: - // import = ... - // import from ... - // import * as from ... - // import { x as } from ... - // export { x as } from ... - // export = ... - // export default ... - function isAliasSymbolDeclaration(node: Node): boolean { - return node.kind === SyntaxKind.ImportEqualsDeclaration || - node.kind === SyntaxKind.ImportClause && !!(node).name || - node.kind === SyntaxKind.NamespaceImport || - node.kind === SyntaxKind.ImportSpecifier || - node.kind === SyntaxKind.ExportSpecifier || - node.kind === SyntaxKind.ExportAssignment; - } - function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration { return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined); } @@ -10987,7 +10970,7 @@ module ts { let node = getDeclarationOfAliasSymbol(symbol); if (node) { if (node.kind === SyntaxKind.ImportClause) { - return unescapeIdentifier(symbol.name) + ".default"; + return getGeneratedNameForNode(node.parent) + ".default"; } if (node.kind === SyntaxKind.ImportSpecifier) { let moduleName = getGeneratedNameForNode(node.parent.parent.parent); @@ -11012,7 +10995,7 @@ module ts { } function getExpressionNameSubstitution(node: Identifier): string { - let symbol = getNodeLinks(node).resolvedSymbol; + let symbol = getNodeLinks(node).resolvedSymbol || (isDeclarationName(node) ? getSymbolOfNode(node.parent) : undefined); if (symbol) { // Whan an identifier resolves to a parented symbol, it references an exported entity from // another declaration of the same internal module. @@ -11033,16 +11016,19 @@ module ts { } } - function isValueExportDeclaration(node: Node): boolean { - if (node.kind === SyntaxKind.ExportAssignment) { - return (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; - } - if (node.kind === SyntaxKind.ExportDeclaration) { - let exportClause = (node).exportClause; - return exportClause && forEach(exportClause.elements, isValueExportDeclaration); - } - if (node.kind === SyntaxKind.ExportSpecifier) { - return isAliasResolvedToValue(getSymbolOfNode(node)); + function isValueAliasDeclaration(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportSpecifier: + return isAliasResolvedToValue(getSymbolOfNode(node)); + case SyntaxKind.ExportDeclaration: + let exportClause = (node).exportClause; + return exportClause && forEach(exportClause.elements, isValueAliasDeclaration); + case SyntaxKind.ExportAssignment: + return (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node)) : true; } return false; } @@ -11187,7 +11173,7 @@ module ts { return { getGeneratedNameForNode, getExpressionNameSubstitution, - isValueExportDeclaration, + isValueAliasDeclaration, isReferencedAliasDeclaration, getNodeCheckFlags, isTopLevelValueImportEqualsWithEntityName, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bcc9e19d696bf..03d4cc74facdd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2598,7 +2598,12 @@ module ts { case SyntaxKind.EnumDeclaration: case SyntaxKind.ModuleDeclaration: case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: return (parent).name === node; + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportSpecifier: + return (parent).name === node || (parent).propertyName === node; case SyntaxKind.BreakStatement: case SyntaxKind.ContinueStatement: case SyntaxKind.ExportAssignment: @@ -3873,7 +3878,7 @@ module ts { emitNodeWithoutSourceMap(specifier.name); emitEnd(specifier.name); write(" = "); - emitNodeWithoutSourceMap(name); + emitExpressionIdentifier(name); write(";"); } } @@ -5003,6 +5008,13 @@ module ts { return node.kind === SyntaxKind.ImportDeclaration && !(node).importClause; } + function emitExportImportAssignments(node: Node) { + if (isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { + emitExportMemberAssignments((node).name); + } + forEachChild(node, emitExportImportAssignments); + } + function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { if (contains(externalImports, node)) { let exportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; @@ -5023,6 +5035,7 @@ module ts { emitRequire(getExternalModuleName(node)); write(";"); emitEnd(node); + emitExportImportAssignments(node); emitTrailingComments(node); } else { @@ -5032,6 +5045,7 @@ module ts { emit(namespaceDeclaration.name); write(";"); } + emitExportImportAssignments(node); } } } @@ -5054,12 +5068,13 @@ module ts { emit(node.moduleReference); write(";"); emitEnd(node); + emitExportImportAssignments(node); emitTrailingComments(node); } } function emitExportDeclaration(node: ExportDeclaration) { - if (node.moduleSpecifier && (!node.exportClause || resolver.isValueExportDeclaration(node))) { + if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { emitStart(node); let generatedName = resolver.getGeneratedNameForNode(node); if (node.exportClause) { @@ -5072,7 +5087,7 @@ module ts { write(";"); } for (let specifier of node.exportClause.elements) { - if (resolver.isValueExportDeclaration(specifier)) { + if (resolver.isValueAliasDeclaration(specifier)) { writeLine(); emitStart(specifier); emitContainingModuleName(specifier); @@ -5104,7 +5119,7 @@ module ts { } function emitExportAssignment(node: ExportAssignment) { - if (!node.isExportEquals && resolver.isValueExportDeclaration(node)) { + if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { writeLine(); emitStart(node); emitContainingModuleName(node); @@ -5144,7 +5159,7 @@ module ts { externalImports.push(node); hasExportStars = true; } - else if (resolver.isValueExportDeclaration(node)) { + else if (resolver.isValueAliasDeclaration(node)) { // export { x, y } from "mod" where at least one export is a value symbol externalImports.push(node); } @@ -5254,7 +5269,7 @@ module ts { } function emitExportEquals(emitAsReturn: boolean) { - if (exportEquals && resolver.isValueExportDeclaration(exportEquals)) { + if (exportEquals && resolver.isValueAliasDeclaration(exportEquals)) { writeLine(); emitStart(exportEquals); write(emitAsReturn ? "return " : "module.exports = "); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 75b1364aa5de9..359af6828c19c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1199,7 +1199,7 @@ module ts { export interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4fce9c928f7b7..bf9c38188d39f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -834,6 +834,23 @@ module ts { return false; } + // An alias symbol is created by one of the following declarations: + // import = ... + // import from ... + // import * as from ... + // import { x as } from ... + // export { x as } from ... + // export = ... + // export default ... + export function isAliasSymbolDeclaration(node: Node): boolean { + return node.kind === SyntaxKind.ImportEqualsDeclaration || + node.kind === SyntaxKind.ImportClause && !!(node).name || + node.kind === SyntaxKind.NamespaceImport || + node.kind === SyntaxKind.ImportSpecifier || + node.kind === SyntaxKind.ExportSpecifier || + node.kind === SyntaxKind.ExportAssignment; + } + export function getClassBaseTypeNode(node: ClassDeclaration) { let heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ExtendsKeyword); return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined; From 956d7a82f337f50b8778fbc1578abf8897ceccd6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 12:18:38 -0700 Subject: [PATCH 07/24] Fixing emit for import d, * as foo from "foo" case --- src/compiler/emitter.ts | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 03d4cc74facdd..299ac0a2b6c49 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5004,10 +5004,6 @@ module ts { } } - function isNakedImport(node: ImportDeclaration | ImportEqualsDeclaration) { - return node.kind === SyntaxKind.ImportDeclaration && !(node).importClause; - } - function emitExportImportAssignments(node: Node) { if (isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { emitExportMemberAssignments((node).name); @@ -5017,29 +5013,47 @@ module ts { function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { if (contains(externalImports, node)) { - let exportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; + let isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; let namespaceDeclaration = getNamespaceDeclarationNode(node); if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); - if (namespaceDeclaration) { - if (!exportedImport) write("var "); + let isDefaultImport = node.kind === SyntaxKind.ImportDeclaration && (node).importClause && !!(node).importClause.name; + if (namespaceDeclaration && !isDefaultImport) { + // import x = require("foo") + // import * as x from "foo" + if (!isExportedImport) write("var "); emitModuleMemberName(namespaceDeclaration); write(" = "); } - else if (!isNakedImport(node)) { - write("var "); - write(resolver.getGeneratedNameForNode(node)); - write(" = "); + else { + // import "foo" + // import x from "foo" + // import { x, y } from "foo" + // import d, * as x from "foo" + // import d, { x, y } from "foo" + let isNakedImport = SyntaxKind.ImportDeclaration && !(node).importClause; + if (!isNakedImport) { + write("var "); + write(resolver.getGeneratedNameForNode(node)); + write(" = "); + } } emitRequire(getExternalModuleName(node)); + if (namespaceDeclaration && isDefaultImport) { + // import d, * as x from "foo" + write(", "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(resolver.getGeneratedNameForNode(node)); + } write(";"); emitEnd(node); emitExportImportAssignments(node); emitTrailingComments(node); } else { - if (exportedImport) { + if (isExportedImport) { emitModuleMemberName(namespaceDeclaration); write(" = "); emit(namespaceDeclaration.name); From e63854b40e6e2bfa53ab9571ebd7f49662f63904 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 12:18:56 -0700 Subject: [PATCH 08/24] Adding basic tests --- .../cases/compiler/es6ExportEqualsInterop.ts | 206 ++++++++++++++++++ .../conformance/es6/modules/exportStar-amd.ts | 28 +++ .../conformance/es6/modules/exportStar.ts | 28 +++ .../es6/modules/exportsAndImports1-amd.ts | 33 +++ .../es6/modules/exportsAndImports1.ts | 33 +++ .../es6/modules/exportsAndImports2-amd.ts | 12 + .../es6/modules/exportsAndImports2.ts | 12 + .../es6/modules/exportsAndImports3-amd.ts | 33 +++ .../es6/modules/exportsAndImports3.ts | 33 +++ .../es6/modules/exportsAndImports4-amd.ts | 38 ++++ .../es6/modules/exportsAndImports4.ts | 38 ++++ 11 files changed, 494 insertions(+) create mode 100644 tests/cases/compiler/es6ExportEqualsInterop.ts create mode 100644 tests/cases/conformance/es6/modules/exportStar-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportStar.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports1.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports2.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports3.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts create mode 100644 tests/cases/conformance/es6/modules/exportsAndImports4.ts diff --git a/tests/cases/compiler/es6ExportEqualsInterop.ts b/tests/cases/compiler/es6ExportEqualsInterop.ts new file mode 100644 index 0000000000000..7b1f6700dd98b --- /dev/null +++ b/tests/cases/compiler/es6ExportEqualsInterop.ts @@ -0,0 +1,206 @@ +// @module: commonjs + +// @filename: modules.d.ts +declare module "interface" { + interface Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "variable" { + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "interface-variable" { + interface Foo { + x: number; + y: number; + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "module" { + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "interface-module" { + interface Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "variable-module" { + module Foo { + interface Bar { + x: number; + y: number; + } + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "function" { + function foo(); + export = foo; +} + +declare module "function-module" { + function foo(); + module foo { + export var a: number; + export var b: number; + } + export = foo; +} + +declare module "class" { + class Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "class-module" { + class Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +// @filename: main.ts +/// + +// import-equals +import z1 = require("interface"); +import z2 = require("variable"); +import z3 = require("interface-variable"); +import z4 = require("module"); +import z5 = require("interface-module"); +import z6 = require("variable-module"); +import z7 = require("function"); +import z8 = require("function-module"); +import z9 = require("class"); +import z0 = require("class-module"); + +z1.a; +z2.a; +z3.a; +z4.a; +z5.a; +z6.a; +z7.a; +z8.a; +z9.a; +z0.a; + +// default import +import x1 from "interface"; +import x2 from "variable"; +import x3 from "interface-variable"; +import x4 from "module"; +import x5 from "interface-module"; +import x6 from "variable-module"; +import x7 from "function"; +import x8 from "function-module"; +import x9 from "class"; +import x0 from "class-module"; + +// namespace import +import * as y1 from "interface"; +import * as y2 from "variable"; +import * as y3 from "interface-variable"; +import * as y4 from "module"; +import * as y5 from "interface-module"; +import * as y6 from "variable-module"; +import * as y7 from "function"; +import * as y8 from "function-module"; +import * as y9 from "class"; +import * as y0 from "class-module"; + +y1.a; +y2.a; +y3.a; +y4.a; +y5.a; +y6.a; +y7.a; +y8.a; +y9.a; +y0.a; + +// named import +import { a as a1 } from "interface"; +import { a as a2 } from "variable"; +import { a as a3 } from "interface-variable"; +import { a as a4 } from "module"; +import { a as a5 } from "interface-module"; +import { a as a6 } from "variable-module"; +import { a as a7 } from "function"; +import { a as a8 } from "function-module"; +import { a as a9 } from "class"; +import { a as a0 } from "class-module"; + +a1; +a2; +a3; +a4; +a5; +a6; +a7; +a8; +a9; +a0; + +// named export +export { a as a1 } from "interface"; +export { a as a2 } from "variable"; +export { a as a3 } from "interface-variable"; +export { a as a4 } from "module"; +export { a as a5 } from "interface-module"; +export { a as a6 } from "variable-module"; +export { a as a7 } from "function"; +export { a as a8 } from "function-module"; +export { a as a9 } from "class"; +export { a as a0 } from "class-module"; + +// export-star +export * from "interface"; +export * from "variable"; +export * from "interface-variable"; +export * from "module"; +export * from "interface-module"; +export * from "variable-module"; +export * from "function"; +export * from "function-module"; +export * from "class"; +export * from "class-module"; diff --git a/tests/cases/conformance/es6/modules/exportStar-amd.ts b/tests/cases/conformance/es6/modules/exportStar-amd.ts new file mode 100644 index 0000000000000..ffa8b0a7f1070 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportStar-amd.ts @@ -0,0 +1,28 @@ +// @module: amd + +// @filename: t1.ts +export var x = 1; +export var y = 2; + +// @filename: t2.ts +export default "hello"; +export function foo() { } + +// @filename: t3.ts +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +// @filename: t4.ts +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +// @filename: main.ts +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; diff --git a/tests/cases/conformance/es6/modules/exportStar.ts b/tests/cases/conformance/es6/modules/exportStar.ts new file mode 100644 index 0000000000000..6d820d9c424c0 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportStar.ts @@ -0,0 +1,28 @@ +// @module: commonjs + +// @filename: t1.ts +export var x = 1; +export var y = 2; + +// @filename: t2.ts +export default "hello"; +export function foo() { } + +// @filename: t3.ts +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +// @filename: t4.ts +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +// @filename: main.ts +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts new file mode 100644 index 0000000000000..0c4d1de1e6b4d --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts @@ -0,0 +1,33 @@ +// @module: amd + +// @filename: t1.ts +var v = 1; +function f() { } +class C { +} +interface I { +} +enum E { + A, B, C +} +const enum D { + A, B, C +} +module M { + export var x; +} +module N { + export interface I { + } +} +type T = number; +import a = M.x; + +export { v, f, C, I, E, D, M, N, T, a }; + +// @filename: t2.ts +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; + +// @filename: t3.ts +import { v, f, C, I, E, D, M, N, T, a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports1.ts b/tests/cases/conformance/es6/modules/exportsAndImports1.ts new file mode 100644 index 0000000000000..5b91d1d6ccd97 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports1.ts @@ -0,0 +1,33 @@ +// @module: commonjs + +// @filename: t1.ts +var v = 1; +function f() { } +class C { +} +interface I { +} +enum E { + A, B, C +} +const enum D { + A, B, C +} +module M { + export var x; +} +module N { + export interface I { + } +} +type T = number; +import a = M.x; + +export { v, f, C, I, E, D, M, N, T, a }; + +// @filename: t2.ts +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; + +// @filename: t3.ts +import { v, f, C, I, E, D, M, N, T, a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts new file mode 100644 index 0000000000000..72e462f0eed05 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts @@ -0,0 +1,12 @@ +// @module: amd + +// @filename: t1.ts +export var x = "x"; +export var y = "y"; + +// @filename: t2.ts +export { x as y, y as x } from "./t1"; + +// @filename: t3.ts +import { x, y } from "./t1"; +export { x as y, y as x }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports2.ts b/tests/cases/conformance/es6/modules/exportsAndImports2.ts new file mode 100644 index 0000000000000..719f74ede5554 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports2.ts @@ -0,0 +1,12 @@ +// @module: commonjs + +// @filename: t1.ts +export var x = "x"; +export var y = "y"; + +// @filename: t2.ts +export { x as y, y as x } from "./t1"; + +// @filename: t3.ts +import { x, y } from "./t1"; +export { x as y, y as x }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts new file mode 100644 index 0000000000000..b634f6f7764d3 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts @@ -0,0 +1,33 @@ +// @module: amd + +// @filename: t1.ts +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +// @filename: t2.ts +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +// @filename: t3.ts +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports3.ts b/tests/cases/conformance/es6/modules/exportsAndImports3.ts new file mode 100644 index 0000000000000..806a5e2779e6f --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports3.ts @@ -0,0 +1,33 @@ +// @module: commonjs + +// @filename: t1.ts +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +// @filename: t2.ts +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +// @filename: t3.ts +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts b/tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts new file mode 100644 index 0000000000000..d542a5ae71814 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts @@ -0,0 +1,38 @@ +// @module: amd + +// @filename: t1.ts +export default "hello"; + +// @filename: t2.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +// @filename: t3.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; diff --git a/tests/cases/conformance/es6/modules/exportsAndImports4.ts b/tests/cases/conformance/es6/modules/exportsAndImports4.ts new file mode 100644 index 0000000000000..f077067419626 --- /dev/null +++ b/tests/cases/conformance/es6/modules/exportsAndImports4.ts @@ -0,0 +1,38 @@ +// @module: commonjs + +// @filename: t1.ts +export default "hello"; + +// @filename: t2.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +// @filename: t3.ts +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; From df03c686c438125a5e30ae50bd814f4f469d2c78 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 12:19:38 -0700 Subject: [PATCH 09/24] Accepting new baselines --- .../baselines/reference/APISample_compile.js | 2 +- .../reference/APISample_compile.types | 4 +- tests/baselines/reference/APISample_linter.js | 2 +- .../reference/APISample_linter.types | 4 +- .../reference/APISample_transform.js | 2 +- .../reference/APISample_transform.types | 4 +- .../baselines/reference/APISample_watcher.js | 2 +- .../reference/APISample_watcher.types | 4 +- .../es6ExportEqualsInterop.errors.txt | 304 ++++++++++++++++++ .../reference/es6ExportEqualsInterop.js | 301 +++++++++++++++++ .../reference/exportStar-amd.errors.txt | 33 ++ tests/baselines/reference/exportStar-amd.js | 69 ++++ .../baselines/reference/exportStar.errors.txt | 33 ++ tests/baselines/reference/exportStar.js | 60 ++++ .../reference/exportsAndImports1-amd.js | 82 +++++ .../reference/exportsAndImports1-amd.types | 101 ++++++ .../baselines/reference/exportsAndImports1.js | 78 +++++ .../reference/exportsAndImports1.types | 101 ++++++ .../reference/exportsAndImports2-amd.js | 30 ++ .../reference/exportsAndImports2-amd.types | 26 ++ .../baselines/reference/exportsAndImports2.js | 26 ++ .../reference/exportsAndImports2.types | 26 ++ .../reference/exportsAndImports3-amd.js | 84 +++++ .../reference/exportsAndImports3-amd.types | 131 ++++++++ .../baselines/reference/exportsAndImports3.js | 80 +++++ .../reference/exportsAndImports3.types | 131 ++++++++ .../reference/exportsAndImports4-amd.js | 64 ++++ .../reference/exportsAndImports4-amd.types | 68 ++++ .../baselines/reference/exportsAndImports4.js | 66 ++++ .../reference/exportsAndImports4.types | 68 ++++ 30 files changed, 1974 insertions(+), 12 deletions(-) create mode 100644 tests/baselines/reference/es6ExportEqualsInterop.errors.txt create mode 100644 tests/baselines/reference/es6ExportEqualsInterop.js create mode 100644 tests/baselines/reference/exportStar-amd.errors.txt create mode 100644 tests/baselines/reference/exportStar-amd.js create mode 100644 tests/baselines/reference/exportStar.errors.txt create mode 100644 tests/baselines/reference/exportStar.js create mode 100644 tests/baselines/reference/exportsAndImports1-amd.js create mode 100644 tests/baselines/reference/exportsAndImports1-amd.types create mode 100644 tests/baselines/reference/exportsAndImports1.js create mode 100644 tests/baselines/reference/exportsAndImports1.types create mode 100644 tests/baselines/reference/exportsAndImports2-amd.js create mode 100644 tests/baselines/reference/exportsAndImports2-amd.types create mode 100644 tests/baselines/reference/exportsAndImports2.js create mode 100644 tests/baselines/reference/exportsAndImports2.types create mode 100644 tests/baselines/reference/exportsAndImports3-amd.js create mode 100644 tests/baselines/reference/exportsAndImports3-amd.types create mode 100644 tests/baselines/reference/exportsAndImports3.js create mode 100644 tests/baselines/reference/exportsAndImports3.types create mode 100644 tests/baselines/reference/exportsAndImports4-amd.js create mode 100644 tests/baselines/reference/exportsAndImports4-amd.types create mode 100644 tests/baselines/reference/exportsAndImports4.js create mode 100644 tests/baselines/reference/exportsAndImports4.types diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 84ee9ef859d4a..86cd5b5ff44ac 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -936,7 +936,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index d6ac61eb94a52..33b0ab2228b8b 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2998,8 +2998,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 931d9473a17cb..6c57165bdb431 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -967,7 +967,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 6f7da4147f2e3..f6ed3b80eafe9 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3144,8 +3144,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 3f739c9931d76..b18b0e385c019 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -968,7 +968,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index ba8cde8001cee..55064457fad26 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3094,8 +3094,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 1328ce98e67b2..b61ed3fdc9f6c 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1005,7 +1005,7 @@ declare module "typescript" { interface EmitResolver { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; - isValueExportDeclaration(node: Node): boolean; + isValueAliasDeclaration(node: Node): boolean; isReferencedAliasDeclaration(node: Node): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 7a82d7052313b..aaba39c6b8d23 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3267,8 +3267,8 @@ declare module "typescript" { >node : Identifier >Identifier : Identifier - isValueExportDeclaration(node: Node): boolean; ->isValueExportDeclaration : (node: Node) => boolean + isValueAliasDeclaration(node: Node): boolean; +>isValueAliasDeclaration : (node: Node) => boolean >node : Node >Node : Node diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt new file mode 100644 index 0000000000000..6351a3ee89b9c --- /dev/null +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -0,0 +1,304 @@ +tests/cases/compiler/main.ts(15,1): error TS2304: Cannot find name 'z1'. +tests/cases/compiler/main.ts(21,4): error TS2339: Property 'a' does not exist on type '() => any'. +tests/cases/compiler/main.ts(23,4): error TS2339: Property 'a' does not exist on type 'typeof Foo'. +tests/cases/compiler/main.ts(27,8): error TS1192: External module '"interface"' has no default export. +tests/cases/compiler/main.ts(28,8): error TS1192: External module '"variable"' has no default export. +tests/cases/compiler/main.ts(29,8): error TS1192: External module '"interface-variable"' has no default export. +tests/cases/compiler/main.ts(30,8): error TS1192: External module '"module"' has no default export. +tests/cases/compiler/main.ts(31,8): error TS1192: External module '"interface-module"' has no default export. +tests/cases/compiler/main.ts(32,8): error TS1192: External module '"variable-module"' has no default export. +tests/cases/compiler/main.ts(33,8): error TS1192: External module '"function"' has no default export. +tests/cases/compiler/main.ts(34,8): error TS1192: External module '"function-module"' has no default export. +tests/cases/compiler/main.ts(35,8): error TS1192: External module '"class"' has no default export. +tests/cases/compiler/main.ts(36,8): error TS1192: External module '"class-module"' has no default export. +tests/cases/compiler/main.ts(39,21): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(45,21): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(47,21): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(62,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(68,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(70,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(85,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(91,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(93,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(97,15): error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(98,15): error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(99,15): error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(100,15): error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(101,15): error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(102,15): error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(103,15): error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(104,15): error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(105,15): error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. + + +==== tests/cases/compiler/main.ts (32 errors) ==== + /// + + // import-equals + import z1 = require("interface"); + import z2 = require("variable"); + import z3 = require("interface-variable"); + import z4 = require("module"); + import z5 = require("interface-module"); + import z6 = require("variable-module"); + import z7 = require("function"); + import z8 = require("function-module"); + import z9 = require("class"); + import z0 = require("class-module"); + + z1.a; + ~~ +!!! error TS2304: Cannot find name 'z1'. + z2.a; + z3.a; + z4.a; + z5.a; + z6.a; + z7.a; + ~ +!!! error TS2339: Property 'a' does not exist on type '() => any'. + z8.a; + z9.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'typeof Foo'. + z0.a; + + // default import + import x1 from "interface"; + ~~ +!!! error TS1192: External module '"interface"' has no default export. + import x2 from "variable"; + ~~ +!!! error TS1192: External module '"variable"' has no default export. + import x3 from "interface-variable"; + ~~ +!!! error TS1192: External module '"interface-variable"' has no default export. + import x4 from "module"; + ~~ +!!! error TS1192: External module '"module"' has no default export. + import x5 from "interface-module"; + ~~ +!!! error TS1192: External module '"interface-module"' has no default export. + import x6 from "variable-module"; + ~~ +!!! error TS1192: External module '"variable-module"' has no default export. + import x7 from "function"; + ~~ +!!! error TS1192: External module '"function"' has no default export. + import x8 from "function-module"; + ~~ +!!! error TS1192: External module '"function-module"' has no default export. + import x9 from "class"; + ~~ +!!! error TS1192: External module '"class"' has no default export. + import x0 from "class-module"; + ~~ +!!! error TS1192: External module '"class-module"' has no default export. + + // namespace import + import * as y1 from "interface"; + ~~~~~~~~~~~ +!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. + import * as y2 from "variable"; + import * as y3 from "interface-variable"; + import * as y4 from "module"; + import * as y5 from "interface-module"; + import * as y6 from "variable-module"; + import * as y7 from "function"; + ~~~~~~~~~~ +!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. + import * as y8 from "function-module"; + import * as y9 from "class"; + ~~~~~~~ +!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. + import * as y0 from "class-module"; + + y1.a; + y2.a; + y3.a; + y4.a; + y5.a; + y6.a; + y7.a; + y8.a; + y9.a; + y0.a; + + // named import + import { a as a1 } from "interface"; + ~~~~~~~~~~~ +!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. + import { a as a2 } from "variable"; + import { a as a3 } from "interface-variable"; + import { a as a4 } from "module"; + import { a as a5 } from "interface-module"; + import { a as a6 } from "variable-module"; + import { a as a7 } from "function"; + ~~~~~~~~~~ +!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. + import { a as a8 } from "function-module"; + import { a as a9 } from "class"; + ~~~~~~~ +!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. + import { a as a0 } from "class-module"; + + a1; + a2; + a3; + a4; + a5; + a6; + a7; + a8; + a9; + a0; + + // named export + export { a as a1 } from "interface"; + ~~~~~~~~~~~ +!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. + export { a as a2 } from "variable"; + export { a as a3 } from "interface-variable"; + export { a as a4 } from "module"; + export { a as a5 } from "interface-module"; + export { a as a6 } from "variable-module"; + export { a as a7 } from "function"; + ~~~~~~~~~~ +!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. + export { a as a8 } from "function-module"; + export { a as a9 } from "class"; + ~~~~~~~ +!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. + export { a as a0 } from "class-module"; + + // export-star + export * from "interface"; + ~~~~~~~~~~~ +!!! error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. + export * from "variable"; + ~~~~~~~~~~ +!!! error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. + export * from "interface-variable"; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. + export * from "module"; + ~~~~~~~~ +!!! error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. + export * from "interface-module"; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. + export * from "variable-module"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. + export * from "function"; + ~~~~~~~~~~ +!!! error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. + export * from "function-module"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. + export * from "class"; + ~~~~~~~ +!!! error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. + export * from "class-module"; + ~~~~~~~~~~~~~~ +!!! error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. + +==== tests/cases/compiler/modules.d.ts (0 errors) ==== + + declare module "interface" { + interface Foo { + x: number; + y: number; + } + export = Foo; + } + + declare module "variable" { + var Foo: { + a: number; + b: number; + } + export = Foo; + } + + declare module "interface-variable" { + interface Foo { + x: number; + y: number; + } + var Foo: { + a: number; + b: number; + } + export = Foo; + } + + declare module "module" { + module Foo { + export var a: number; + export var b: number; + } + export = Foo; + } + + declare module "interface-module" { + interface Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; + } + + declare module "variable-module" { + module Foo { + interface Bar { + x: number; + y: number; + } + } + var Foo: { + a: number; + b: number; + } + export = Foo; + } + + declare module "function" { + function foo(); + export = foo; + } + + declare module "function-module" { + function foo(); + module foo { + export var a: number; + export var b: number; + } + export = foo; + } + + declare module "class" { + class Foo { + x: number; + y: number; + } + export = Foo; + } + + declare module "class-module" { + class Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportEqualsInterop.js b/tests/baselines/reference/es6ExportEqualsInterop.js new file mode 100644 index 0000000000000..6775bb8c6bbe6 --- /dev/null +++ b/tests/baselines/reference/es6ExportEqualsInterop.js @@ -0,0 +1,301 @@ +//// [tests/cases/compiler/es6ExportEqualsInterop.ts] //// + +//// [modules.d.ts] + +declare module "interface" { + interface Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "variable" { + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "interface-variable" { + interface Foo { + x: number; + y: number; + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "module" { + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "interface-module" { + interface Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +declare module "variable-module" { + module Foo { + interface Bar { + x: number; + y: number; + } + } + var Foo: { + a: number; + b: number; + } + export = Foo; +} + +declare module "function" { + function foo(); + export = foo; +} + +declare module "function-module" { + function foo(); + module foo { + export var a: number; + export var b: number; + } + export = foo; +} + +declare module "class" { + class Foo { + x: number; + y: number; + } + export = Foo; +} + +declare module "class-module" { + class Foo { + x: number; + y: number; + } + module Foo { + export var a: number; + export var b: number; + } + export = Foo; +} + +//// [main.ts] +/// + +// import-equals +import z1 = require("interface"); +import z2 = require("variable"); +import z3 = require("interface-variable"); +import z4 = require("module"); +import z5 = require("interface-module"); +import z6 = require("variable-module"); +import z7 = require("function"); +import z8 = require("function-module"); +import z9 = require("class"); +import z0 = require("class-module"); + +z1.a; +z2.a; +z3.a; +z4.a; +z5.a; +z6.a; +z7.a; +z8.a; +z9.a; +z0.a; + +// default import +import x1 from "interface"; +import x2 from "variable"; +import x3 from "interface-variable"; +import x4 from "module"; +import x5 from "interface-module"; +import x6 from "variable-module"; +import x7 from "function"; +import x8 from "function-module"; +import x9 from "class"; +import x0 from "class-module"; + +// namespace import +import * as y1 from "interface"; +import * as y2 from "variable"; +import * as y3 from "interface-variable"; +import * as y4 from "module"; +import * as y5 from "interface-module"; +import * as y6 from "variable-module"; +import * as y7 from "function"; +import * as y8 from "function-module"; +import * as y9 from "class"; +import * as y0 from "class-module"; + +y1.a; +y2.a; +y3.a; +y4.a; +y5.a; +y6.a; +y7.a; +y8.a; +y9.a; +y0.a; + +// named import +import { a as a1 } from "interface"; +import { a as a2 } from "variable"; +import { a as a3 } from "interface-variable"; +import { a as a4 } from "module"; +import { a as a5 } from "interface-module"; +import { a as a6 } from "variable-module"; +import { a as a7 } from "function"; +import { a as a8 } from "function-module"; +import { a as a9 } from "class"; +import { a as a0 } from "class-module"; + +a1; +a2; +a3; +a4; +a5; +a6; +a7; +a8; +a9; +a0; + +// named export +export { a as a1 } from "interface"; +export { a as a2 } from "variable"; +export { a as a3 } from "interface-variable"; +export { a as a4 } from "module"; +export { a as a5 } from "interface-module"; +export { a as a6 } from "variable-module"; +export { a as a7 } from "function"; +export { a as a8 } from "function-module"; +export { a as a9 } from "class"; +export { a as a0 } from "class-module"; + +// export-star +export * from "interface"; +export * from "variable"; +export * from "interface-variable"; +export * from "module"; +export * from "interface-module"; +export * from "variable-module"; +export * from "function"; +export * from "function-module"; +export * from "class"; +export * from "class-module"; + + +//// [main.js] +/// +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +var z2 = require("variable"); +var z3 = require("interface-variable"); +var z4 = require("module"); +var z5 = require("interface-module"); +var z6 = require("variable-module"); +var z7 = require("function"); +var z8 = require("function-module"); +var z9 = require("class"); +var z0 = require("class-module"); +z1.a; +z2.a; +z3.a; +z4.a; +z5.a; +z6.a; +z7.a; +z8.a; +z9.a; +z0.a; +// namespace import +var y1 = require("interface"); +var y2 = require("variable"); +var y3 = require("interface-variable"); +var y4 = require("module"); +var y5 = require("interface-module"); +var y6 = require("variable-module"); +var y7 = require("function"); +var y8 = require("function-module"); +var y9 = require("class"); +var y0 = require("class-module"); +y1.a; +y2.a; +y3.a; +y4.a; +y5.a; +y6.a; +y7.a; +y8.a; +y9.a; +y0.a; +// named import +var _interface_2 = require("interface"); +var _variable_2 = require("variable"); +var _interface_variable_2 = require("interface-variable"); +var _module_2 = require("module"); +var _interface_module_2 = require("interface-module"); +var _variable_module_2 = require("variable-module"); +var _function_2 = require("function"); +var _function_module_2 = require("function-module"); +var _class_2 = require("class"); +var _class_module_2 = require("class-module"); +_interface_2.a; +_variable_2.a; +_interface_variable_2.a; +_module_2.a; +_interface_module_2.a; +_variable_module_2.a; +_function_2.a; +_function_module_2.a; +_class_2.a; +_class_module_2.a; +// named export +var _variable_3 = require("variable"); +exports.a2 = _variable_3.a; +var _interface_variable_3 = require("interface-variable"); +exports.a3 = _interface_variable_3.a; +var _module_3 = require("module"); +exports.a4 = _module_3.a; +var _interface_module_3 = require("interface-module"); +exports.a5 = _interface_module_3.a; +var _variable_module_3 = require("variable-module"); +exports.a6 = _variable_module_3.a; +var _function_module_3 = require("function-module"); +exports.a8 = _function_module_3.a; +var _class_module_3 = require("class-module"); +exports.a0 = _class_module_3.a; +// export-star +__export(require("interface")); +__export(require("variable")); +__export(require("interface-variable")); +__export(require("module")); +__export(require("interface-module")); +__export(require("variable-module")); +__export(require("function")); +__export(require("function-module")); +__export(require("class")); +__export(require("class-module")); diff --git a/tests/baselines/reference/exportStar-amd.errors.txt b/tests/baselines/reference/exportStar-amd.errors.txt new file mode 100644 index 0000000000000..87e4c4740a094 --- /dev/null +++ b/tests/baselines/reference/exportStar-amd.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/es6/modules/main.ts(1,8): error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + + +==== tests/cases/conformance/es6/modules/t1.ts (0 errors) ==== + + export var x = 1; + export var y = 2; + +==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== + export default "hello"; + export function foo() { } + +==== tests/cases/conformance/es6/modules/t3.ts (0 errors) ==== + var x = "x"; + var y = "y"; + var z = "z"; + export { x, y, z }; + +==== tests/cases/conformance/es6/modules/t4.ts (0 errors) ==== + export * from "./t1"; + export * from "./t2"; + export * from "./t3"; + +==== tests/cases/conformance/es6/modules/main.ts (1 errors) ==== + import hello, { x, y, z, foo } from "./t4"; + ~~~~~ +!!! error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + hello; + x; + y; + z; + foo; + \ No newline at end of file diff --git a/tests/baselines/reference/exportStar-amd.js b/tests/baselines/reference/exportStar-amd.js new file mode 100644 index 0000000000000..36d0904a1860d --- /dev/null +++ b/tests/baselines/reference/exportStar-amd.js @@ -0,0 +1,69 @@ +//// [tests/cases/conformance/es6/modules/exportStar-amd.ts] //// + +//// [t1.ts] + +export var x = 1; +export var y = 2; + +//// [t2.ts] +export default "hello"; +export function foo() { } + +//// [t3.ts] +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +//// [t4.ts] +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +//// [main.ts] +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + exports.x = 1; + exports.y = 2; +}); +//// [t2.js] +define(["require", "exports"], function (require, exports) { + exports.default = "hello"; + function foo() { + } + exports.foo = foo; +}); +//// [t3.js] +define(["require", "exports"], function (require, exports) { + var x = "x"; + exports.x = x; + var y = "y"; + exports.y = y; + var z = "z"; + exports.z = z; +}); +//// [t4.js] +define(["require", "exports", "./t1", "./t2", "./t3"], function (require, exports, _t1, _t2, _t3) { + function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; + } + __export(_t1); + __export(_t2); + __export(_t3); +}); +//// [main.js] +define(["require", "exports", "./t4"], function (require, exports, _t4) { + _t4.default; + _t4.x; + _t4.y; + _t4.z; + _t4.foo; +}); diff --git a/tests/baselines/reference/exportStar.errors.txt b/tests/baselines/reference/exportStar.errors.txt new file mode 100644 index 0000000000000..87e4c4740a094 --- /dev/null +++ b/tests/baselines/reference/exportStar.errors.txt @@ -0,0 +1,33 @@ +tests/cases/conformance/es6/modules/main.ts(1,8): error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + + +==== tests/cases/conformance/es6/modules/t1.ts (0 errors) ==== + + export var x = 1; + export var y = 2; + +==== tests/cases/conformance/es6/modules/t2.ts (0 errors) ==== + export default "hello"; + export function foo() { } + +==== tests/cases/conformance/es6/modules/t3.ts (0 errors) ==== + var x = "x"; + var y = "y"; + var z = "z"; + export { x, y, z }; + +==== tests/cases/conformance/es6/modules/t4.ts (0 errors) ==== + export * from "./t1"; + export * from "./t2"; + export * from "./t3"; + +==== tests/cases/conformance/es6/modules/main.ts (1 errors) ==== + import hello, { x, y, z, foo } from "./t4"; + ~~~~~ +!!! error TS1192: External module '"tests/cases/conformance/es6/modules/t4"' has no default export. + hello; + x; + y; + z; + foo; + \ No newline at end of file diff --git a/tests/baselines/reference/exportStar.js b/tests/baselines/reference/exportStar.js new file mode 100644 index 0000000000000..070dd90b1dbd2 --- /dev/null +++ b/tests/baselines/reference/exportStar.js @@ -0,0 +1,60 @@ +//// [tests/cases/conformance/es6/modules/exportStar.ts] //// + +//// [t1.ts] + +export var x = 1; +export var y = 2; + +//// [t2.ts] +export default "hello"; +export function foo() { } + +//// [t3.ts] +var x = "x"; +var y = "y"; +var z = "z"; +export { x, y, z }; + +//// [t4.ts] +export * from "./t1"; +export * from "./t2"; +export * from "./t3"; + +//// [main.ts] +import hello, { x, y, z, foo } from "./t4"; +hello; +x; +y; +z; +foo; + + +//// [t1.js] +exports.x = 1; +exports.y = 2; +//// [t2.js] +exports.default = "hello"; +function foo() { +} +exports.foo = foo; +//// [t3.js] +var x = "x"; +exports.x = x; +var y = "y"; +exports.y = y; +var z = "z"; +exports.z = z; +//// [t4.js] +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +__export(require("./t1")); +__export(require("./t2")); +__export(require("./t3")); +//// [main.js] +var _t4 = require("./t4"); +_t4.default; +_t4.x; +_t4.y; +_t4.z; +_t4.foo; diff --git a/tests/baselines/reference/exportsAndImports1-amd.js b/tests/baselines/reference/exportsAndImports1-amd.js new file mode 100644 index 0000000000000..ac0d56769bb42 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1-amd.js @@ -0,0 +1,82 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports1-amd.ts] //// + +//// [t1.ts] + +var v = 1; +function f() { } +class C { +} +interface I { +} +enum E { + A, B, C +} +const enum D { + A, B, C +} +module M { + export var x; +} +module N { + export interface I { + } +} +type T = number; +import a = M.x; + +export { v, f, C, I, E, D, M, N, T, a }; + +//// [t2.ts] +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; + +//// [t3.ts] +import { v, f, C, I, E, D, M, N, T, a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + var v = 1; + exports.v = v; + function f() { + } + exports.f = f; + var C = (function () { + function C() { + } + return C; + })(); + exports.C = C; + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + exports.E = E; + var M; + (function (M) { + M.x; + })(M || (M = {})); + exports.M = M; + var a = M.x; + exports.a = a; +}); +//// [t2.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v; + exports.f = _t1.f; + exports.C = _t1.C; + exports.E = _t1.E; + exports.M = _t1.M; + exports.a = _t1.a; +}); +//// [t3.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v; + exports.f = _t1.f; + exports.C = _t1.C; + exports.E = _t1.E; + exports.M = _t1.M; + exports.a = _t1.a; +}); diff --git a/tests/baselines/reference/exportsAndImports1-amd.types b/tests/baselines/reference/exportsAndImports1-amd.types new file mode 100644 index 0000000000000..0b35b04e22e85 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1-amd.types @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +var v = 1; +>v : number + +function f() { } +>f : () => void + +class C { +>C : C +} +interface I { +>I : I +} +enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E +} +const enum D { +>D : D + + A, B, C +>A : D +>B : D +>C : D +} +module M { +>M : typeof M + + export var x; +>x : any +} +module N { +>N : unknown + + export interface I { +>I : I + } +} +type T = number; +>T : number + +import a = M.x; +>a : any +>M : typeof M +>x : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +=== tests/cases/conformance/es6/modules/t2.ts === +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +=== tests/cases/conformance/es6/modules/t3.ts === +import { v, f, C, I, E, D, M, N, T, a } from "./t1"; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports1.js b/tests/baselines/reference/exportsAndImports1.js new file mode 100644 index 0000000000000..2e396c1c72b1a --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1.js @@ -0,0 +1,78 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports1.ts] //// + +//// [t1.ts] + +var v = 1; +function f() { } +class C { +} +interface I { +} +enum E { + A, B, C +} +const enum D { + A, B, C +} +module M { + export var x; +} +module N { + export interface I { + } +} +type T = number; +import a = M.x; + +export { v, f, C, I, E, D, M, N, T, a }; + +//// [t2.ts] +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; + +//// [t3.ts] +import { v, f, C, I, E, D, M, N, T, a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; + + +//// [t1.js] +var v = 1; +exports.v = v; +function f() { +} +exports.f = f; +var C = (function () { + function C() { + } + return C; +})(); +exports.C = C; +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(E || (E = {})); +exports.E = E; +var M; +(function (M) { + M.x; +})(M || (M = {})); +exports.M = M; +var a = M.x; +exports.a = a; +//// [t2.js] +var _t1 = require("./t1"); +exports.v = _t1.v; +exports.f = _t1.f; +exports.C = _t1.C; +exports.E = _t1.E; +exports.M = _t1.M; +exports.a = _t1.a; +//// [t3.js] +var _t1 = require("./t1"); +exports.v = _t1.v; +exports.f = _t1.f; +exports.C = _t1.C; +exports.E = _t1.E; +exports.M = _t1.M; +exports.a = _t1.a; diff --git a/tests/baselines/reference/exportsAndImports1.types b/tests/baselines/reference/exportsAndImports1.types new file mode 100644 index 0000000000000..0b35b04e22e85 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports1.types @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +var v = 1; +>v : number + +function f() { } +>f : () => void + +class C { +>C : C +} +interface I { +>I : I +} +enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E +} +const enum D { +>D : D + + A, B, C +>A : D +>B : D +>C : D +} +module M { +>M : typeof M + + export var x; +>x : any +} +module N { +>N : unknown + + export interface I { +>I : I + } +} +type T = number; +>T : number + +import a = M.x; +>a : any +>M : typeof M +>x : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +=== tests/cases/conformance/es6/modules/t2.ts === +export { v, f, C, I, E, D, M, N, T, a } from "./t1"; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +=== tests/cases/conformance/es6/modules/t3.ts === +import { v, f, C, I, E, D, M, N, T, a } from "./t1"; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports2-amd.js b/tests/baselines/reference/exportsAndImports2-amd.js new file mode 100644 index 0000000000000..a958c5dd77192 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2-amd.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports2-amd.ts] //// + +//// [t1.ts] + +export var x = "x"; +export var y = "y"; + +//// [t2.ts] +export { x as y, y as x } from "./t1"; + +//// [t3.ts] +import { x, y } from "./t1"; +export { x as y, y as x }; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + exports.x = "x"; + exports.y = "y"; +}); +//// [t2.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.y = _t1.x; + exports.x = _t1.y; +}); +//// [t3.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.y = _t1.x; + exports.x = _t1.y; +}); diff --git a/tests/baselines/reference/exportsAndImports2-amd.types b/tests/baselines/reference/exportsAndImports2-amd.types new file mode 100644 index 0000000000000..ebfc097da5abc --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2-amd.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var x = "x"; +>x : string + +export var y = "y"; +>y : string + +=== tests/cases/conformance/es6/modules/t2.ts === +export { x as y, y as x } from "./t1"; +>x : string +>y : string +>y : string +>x : string + +=== tests/cases/conformance/es6/modules/t3.ts === +import { x, y } from "./t1"; +>x : string +>y : string + +export { x as y, y as x }; +>x : string +>y : string +>y : string +>x : string + diff --git a/tests/baselines/reference/exportsAndImports2.js b/tests/baselines/reference/exportsAndImports2.js new file mode 100644 index 0000000000000..3773dc624c87b --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2.js @@ -0,0 +1,26 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports2.ts] //// + +//// [t1.ts] + +export var x = "x"; +export var y = "y"; + +//// [t2.ts] +export { x as y, y as x } from "./t1"; + +//// [t3.ts] +import { x, y } from "./t1"; +export { x as y, y as x }; + + +//// [t1.js] +exports.x = "x"; +exports.y = "y"; +//// [t2.js] +var _t1 = require("./t1"); +exports.y = _t1.x; +exports.x = _t1.y; +//// [t3.js] +var _t1 = require("./t1"); +exports.y = _t1.x; +exports.x = _t1.y; diff --git a/tests/baselines/reference/exportsAndImports2.types b/tests/baselines/reference/exportsAndImports2.types new file mode 100644 index 0000000000000..ebfc097da5abc --- /dev/null +++ b/tests/baselines/reference/exportsAndImports2.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var x = "x"; +>x : string + +export var y = "y"; +>y : string + +=== tests/cases/conformance/es6/modules/t2.ts === +export { x as y, y as x } from "./t1"; +>x : string +>y : string +>y : string +>x : string + +=== tests/cases/conformance/es6/modules/t3.ts === +import { x, y } from "./t1"; +>x : string +>y : string + +export { x as y, y as x }; +>x : string +>y : string +>y : string +>x : string + diff --git a/tests/baselines/reference/exportsAndImports3-amd.js b/tests/baselines/reference/exportsAndImports3-amd.js new file mode 100644 index 0000000000000..443358eafd021 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3-amd.js @@ -0,0 +1,84 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports3-amd.ts] //// + +//// [t1.ts] + +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +//// [t2.ts] +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +//// [t3.ts] +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + exports.v = 1; + exports.v1 = exports.v; + function f() { + } + exports.f = f; + exports.f1 = exports.f; + var C = (function () { + function C() { + } + return C; + })(); + exports.C = C; + exports.C1 = exports.C; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(exports.E || (exports.E = {})); + var E = exports.E; + exports.E1 = exports.E; + var M; + (function (M) { + M.x; + })(M = exports.M || (exports.M = {})); + exports.M1 = exports.M; + exports.a = M.x; + exports.a1 = exports.a; +}); +//// [t2.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v1; + exports.f = _t1.f1; + exports.C = _t1.C1; + exports.E = _t1.E1; + exports.M = _t1.M1; + exports.a = _t1.a1; +}); +//// [t3.js] +define(["require", "exports", "./t1"], function (require, exports, _t1) { + exports.v = _t1.v1; + exports.f = _t1.f1; + exports.C = _t1.C1; + exports.E = _t1.E1; + exports.M = _t1.M1; + exports.a = _t1.a1; +}); diff --git a/tests/baselines/reference/exportsAndImports3-amd.types b/tests/baselines/reference/exportsAndImports3-amd.types new file mode 100644 index 0000000000000..86e21cfd08402 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3-amd.types @@ -0,0 +1,131 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var v = 1; +>v : number + +export function f() { } +>f : () => void + +export class C { +>C : C +} +export interface I { +>I : I +} +export enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E +} +export const enum D { +>D : D + + A, B, C +>A : D +>B : D +>C : D +} +export module M { +>M : typeof M + + export var x; +>x : any +} +export module N { +>N : unknown + + export interface I { +>I : I + } +} +export type T = number; +>T : number + +export import a = M.x; +>a : any +>M : typeof M +>x : any + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; +>v : number +>v1 : number +>f : () => void +>f1 : () => void +>C : typeof C +>C1 : typeof C +>I : unknown +>I1 : unknown +>E : typeof E +>E1 : typeof E +>D : typeof D +>D1 : typeof D +>M : typeof M +>M1 : typeof M +>N : unknown +>N1 : unknown +>T : unknown +>T1 : unknown +>a : any +>a1 : any + +=== tests/cases/conformance/es6/modules/t2.ts === +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +=== tests/cases/conformance/es6/modules/t3.ts === +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports3.js b/tests/baselines/reference/exportsAndImports3.js new file mode 100644 index 0000000000000..d4ebe982f895d --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3.js @@ -0,0 +1,80 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports3.ts] //// + +//// [t1.ts] + +export var v = 1; +export function f() { } +export class C { +} +export interface I { +} +export enum E { + A, B, C +} +export const enum D { + A, B, C +} +export module M { + export var x; +} +export module N { + export interface I { + } +} +export type T = number; +export import a = M.x; + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; + +//// [t2.ts] +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; + +//// [t3.ts] +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +export { v, f, C, I, E, D, M, N, T, a }; + + +//// [t1.js] +exports.v = 1; +exports.v1 = exports.v; +function f() { +} +exports.f = f; +exports.f1 = exports.f; +var C = (function () { + function C() { + } + return C; +})(); +exports.C = C; +exports.C1 = exports.C; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(exports.E || (exports.E = {})); +var E = exports.E; +exports.E1 = exports.E; +var M; +(function (M) { + M.x; +})(M = exports.M || (exports.M = {})); +exports.M1 = exports.M; +exports.a = M.x; +exports.a1 = exports.a; +//// [t2.js] +var _t1 = require("./t1"); +exports.v = _t1.v1; +exports.f = _t1.f1; +exports.C = _t1.C1; +exports.E = _t1.E1; +exports.M = _t1.M1; +exports.a = _t1.a1; +//// [t3.js] +var _t1 = require("./t1"); +exports.v = _t1.v1; +exports.f = _t1.f1; +exports.C = _t1.C1; +exports.E = _t1.E1; +exports.M = _t1.M1; +exports.a = _t1.a1; diff --git a/tests/baselines/reference/exportsAndImports3.types b/tests/baselines/reference/exportsAndImports3.types new file mode 100644 index 0000000000000..86e21cfd08402 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports3.types @@ -0,0 +1,131 @@ +=== tests/cases/conformance/es6/modules/t1.ts === + +export var v = 1; +>v : number + +export function f() { } +>f : () => void + +export class C { +>C : C +} +export interface I { +>I : I +} +export enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E +} +export const enum D { +>D : D + + A, B, C +>A : D +>B : D +>C : D +} +export module M { +>M : typeof M + + export var x; +>x : any +} +export module N { +>N : unknown + + export interface I { +>I : I + } +} +export type T = number; +>T : number + +export import a = M.x; +>a : any +>M : typeof M +>x : any + +export { v as v1, f as f1, C as C1, I as I1, E as E1, D as D1, M as M1, N as N1, T as T1, a as a1 }; +>v : number +>v1 : number +>f : () => void +>f1 : () => void +>C : typeof C +>C1 : typeof C +>I : unknown +>I1 : unknown +>E : typeof E +>E1 : typeof E +>D : typeof D +>D1 : typeof D +>M : typeof M +>M1 : typeof M +>N : unknown +>N1 : unknown +>T : unknown +>T1 : unknown +>a : any +>a1 : any + +=== tests/cases/conformance/es6/modules/t2.ts === +export { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +=== tests/cases/conformance/es6/modules/t3.ts === +import { v1 as v, f1 as f, C1 as C, I1 as I, E1 as E, D1 as D, M1 as M, N1 as N, T1 as T, a1 as a } from "./t1"; +>v1 : number +>v : number +>f1 : () => void +>f : () => void +>C1 : typeof C +>C : typeof C +>I1 : unknown +>I : unknown +>E1 : typeof E +>E : typeof E +>D1 : typeof D +>D : typeof D +>M1 : typeof M +>M : typeof M +>N1 : unknown +>N : unknown +>T1 : unknown +>T : unknown +>a1 : any +>a : any + +export { v, f, C, I, E, D, M, N, T, a }; +>v : number +>f : () => void +>C : typeof C +>I : unknown +>E : typeof E +>D : typeof D +>M : typeof M +>N : unknown +>T : unknown +>a : any + diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js new file mode 100644 index 0000000000000..d915f4786a6cb --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -0,0 +1,64 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports4-amd.ts] //// + +//// [t1.ts] + +export default "hello"; + +//// [t2.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +//// [t3.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; + + +//// [t1.js] +define(["require", "exports"], function (require, exports) { + exports.default = "hello"; +}); +//// [t3.js] +define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], function (require, exports, a, _t1, c, _t1_2, e2, _t1_4) { + exports.a = a; + a.default; + exports.b = _t1.default; + _t1.default; + exports.c = c; + c.default; + exports.d = _t1_2.default; + _t1_2.default; + exports.e1 = _t1_3.default; + exports.e2 = e2; + _t1_3.default; + e2.default; + exports.f1 = _t1_4.default; + exports.f2 = _t1_4.default; + _t1_4.default; + _t1_4.default; +}); diff --git a/tests/baselines/reference/exportsAndImports4-amd.types b/tests/baselines/reference/exportsAndImports4-amd.types new file mode 100644 index 0000000000000..4bd6f8c0e1eee --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4-amd.types @@ -0,0 +1,68 @@ +=== tests/cases/conformance/es6/modules/t3.ts === +import a = require("./t1"); +>a : typeof a + +a.default; +>a.default : string +>a : typeof a +>default : string + +import b from "./t1"; +>b : string + +b; +>b : string + +import * as c from "./t1"; +>c : typeof a + +c.default; +>c.default : string +>c : typeof a +>default : string + +import { default as d } from "./t1"; +>default : string +>d : string + +d; +>d : string + +import e1, * as e2 from "./t1"; +>e1 : string +>e2 : typeof a + +e1; +>e1 : string + +e2.default; +>e2.default : string +>e2 : typeof a +>default : string + +import f1, { default as f2 } from "./t1"; +>f1 : string +>default : string +>f2 : string + +f1; +>f1 : string + +f2; +>f2 : string + +export { a, b, c, d, e1, e2, f1, f2 }; +>a : typeof a +>b : string +>c : typeof a +>d : string +>e1 : string +>e2 : typeof a +>f1 : string +>f2 : string + +=== tests/cases/conformance/es6/modules/t1.ts === + +No type information for this code.export default "hello"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/exportsAndImports4.js b/tests/baselines/reference/exportsAndImports4.js new file mode 100644 index 0000000000000..05f0285472964 --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4.js @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/es6/modules/exportsAndImports4.ts] //// + +//// [t1.ts] + +export default "hello"; + +//// [t2.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +import "./t1"; + +//// [t3.ts] +import a = require("./t1"); +a.default; +import b from "./t1"; +b; +import * as c from "./t1"; +c.default; +import { default as d } from "./t1"; +d; +import e1, * as e2 from "./t1"; +e1; +e2.default; +import f1, { default as f2 } from "./t1"; +f1; +f2; +export { a, b, c, d, e1, e2, f1, f2 }; + + +//// [t1.js] +exports.default = "hello"; +//// [t3.js] +var a = require("./t1"); +exports.a = a; +a.default; +var _t1 = require("./t1"); +exports.b = _t1.default; +_t1.default; +var c = require("./t1"); +exports.c = c; +c.default; +var _t1_2 = require("./t1"); +exports.d = _t1_2.default; +_t1_2.default; +var _t1_3 = require("./t1"), e2 = _t1_3; +exports.e1 = _t1_3.default; +exports.e2 = e2; +_t1_3.default; +e2.default; +var _t1_4 = require("./t1"); +exports.f1 = _t1_4.default; +exports.f2 = _t1_4.default; +_t1_4.default; +_t1_4.default; diff --git a/tests/baselines/reference/exportsAndImports4.types b/tests/baselines/reference/exportsAndImports4.types new file mode 100644 index 0000000000000..4bd6f8c0e1eee --- /dev/null +++ b/tests/baselines/reference/exportsAndImports4.types @@ -0,0 +1,68 @@ +=== tests/cases/conformance/es6/modules/t3.ts === +import a = require("./t1"); +>a : typeof a + +a.default; +>a.default : string +>a : typeof a +>default : string + +import b from "./t1"; +>b : string + +b; +>b : string + +import * as c from "./t1"; +>c : typeof a + +c.default; +>c.default : string +>c : typeof a +>default : string + +import { default as d } from "./t1"; +>default : string +>d : string + +d; +>d : string + +import e1, * as e2 from "./t1"; +>e1 : string +>e2 : typeof a + +e1; +>e1 : string + +e2.default; +>e2.default : string +>e2 : typeof a +>default : string + +import f1, { default as f2 } from "./t1"; +>f1 : string +>default : string +>f2 : string + +f1; +>f1 : string + +f2; +>f2 : string + +export { a, b, c, d, e1, e2, f1, f2 }; +>a : typeof a +>b : string +>c : typeof a +>d : string +>e1 : string +>e2 : typeof a +>f1 : string +>f2 : string + +=== tests/cases/conformance/es6/modules/t1.ts === + +No type information for this code.export default "hello"; +No type information for this code. +No type information for this code. \ No newline at end of file From b2656b0d78465501256ce942534b44571f6050b1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 14:32:42 -0700 Subject: [PATCH 10/24] Deleting unused code --- src/compiler/checker.ts | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index facf729775586..ee4f5d85e772e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10117,30 +10117,6 @@ module ts { return emptyArray; } - //function hasExportedMembers(moduleSymbol: Symbol) { - // let declarations = moduleSymbol.declarations; - // for (let current of declarations) { - // let statements = getModuleStatements(current); - // for (let node of statements) { - // if (node.kind === SyntaxKind.ExportDeclaration) { - // let exportClause = (node).exportClause; - // if (!exportClause) { - // return true; - // } - // let specifiers = exportClause.elements; - // for (let specifier of specifiers) { - // if (!(specifier.propertyName && specifier.name && specifier.name.text === "default")) { - // return true; - // } - // } - // } - // else if (node.kind !== SyntaxKind.ExportAssignment && node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { - // return true; - // } - // } - // } - //} - function hasExportedMembers(moduleSymbol: Symbol) { for (var id in moduleSymbol.exports) { if (id !== "export=") { From 3f0cfe3619ac05d0f349de6b36b69bb85cdb1be3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 22 Mar 2015 15:35:08 -0700 Subject: [PATCH 11/24] Adding a few comments --- src/compiler/checker.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ee4f5d85e772e..fa7706cb82385 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -531,6 +531,24 @@ module ts { } } + // This function creates a synthetic symbol that combines the value side of one symbol with the + // type/namespace side of another symbol. Consider this example: + // + // declare module graphics { + // interface Point { + // x: number; + // y: number; + // } + // } + // declare var graphics: { + // Point: new (x: number, y: number) => graphics.Point; + // } + // declare module "graphics" { + // export = graphics; + // } + // + // An 'import { Point } from "graphics"' needs to create a symbol that combines the value side 'Point' + // property with the type/namespace side interface 'Point'. function combineValueAndTypeSymbols(valueSymbol: Symbol, typeSymbol: Symbol): Symbol { if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) { return valueSymbol; @@ -776,10 +794,15 @@ module ts { error(moduleReferenceLiteral, Diagnostics.Cannot_find_external_module_0, moduleName); } + // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration, + // and an external module with no 'export =' declaration resolves to the module itself. function resolveExternalModuleSymbol(moduleSymbol: Symbol): Symbol { return moduleSymbol && resolveSymbol(moduleSymbol.exports["export="]) || moduleSymbol; } + // An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export =' + // references a symbol that is at least declared as a module or a variable. The target of the 'export =' may + // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable). function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression): Symbol { let symbol = resolveExternalModuleSymbol(moduleSymbol); if (symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) { From 6074b3ea24077ab36ea4ce731d0512e752c32c8f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Mar 2015 11:05:03 -0700 Subject: [PATCH 12/24] Consistently error on more than one 'export default' --- src/compiler/binder.ts | 4 ++-- src/compiler/checker.ts | 4 ++-- src/compiler/utilities.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 008bb5b319772..ae0bb3a03022f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -531,11 +531,11 @@ module ts { case SyntaxKind.ExportAssignment: if ((node).expression.kind === SyntaxKind.Identifier) { // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); } else { // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); } bindChildren(node, 0, /*isBlockScopeContainer*/ false); break; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fa7706cb82385..a84d0a6a8c959 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -613,7 +613,7 @@ module ts { return resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); } - function getTargetOfImportDeclaration(node: Declaration): Symbol { + function getTargetOfAliasDeclaration(node: Declaration): Symbol { switch (node.kind) { case SyntaxKind.ImportEqualsDeclaration: return getTargetOfImportEqualsDeclaration(node); @@ -640,7 +640,7 @@ module ts { if (!links.target) { links.target = resolvingSymbol; let node = getDeclarationOfAliasSymbol(symbol); - let target = getTargetOfImportDeclaration(node); + let target = getTargetOfAliasDeclaration(node); if (links.target === resolvingSymbol) { links.target = target || unknownSymbol; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bf9c38188d39f..3c61ad66f8392 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -848,7 +848,7 @@ module ts { node.kind === SyntaxKind.NamespaceImport || node.kind === SyntaxKind.ImportSpecifier || node.kind === SyntaxKind.ExportSpecifier || - node.kind === SyntaxKind.ExportAssignment; + node.kind === SyntaxKind.ExportAssignment && (node).expression.kind === SyntaxKind.Identifier; } export function getClassBaseTypeNode(node: ClassDeclaration) { From 86d561d2bea592d329944d4f869e27501544f684 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 23 Mar 2015 11:17:40 -0700 Subject: [PATCH 13/24] Check for instantiation on export default in ES6 --- src/compiler/emitter.ts | 38 ++++++++++--------- .../reference/es6ExportAssignment.js | 1 - tests/baselines/reference/es6ExportEquals.js | 1 - .../reference/es6ImportEqualsDeclaration.js | 1 - .../es6ImportNamedImportInExportAssignment.js | 1 - .../exportDefaultForNonInstantiatedModule.js | 10 +++++ ...xportDefaultForNonInstantiatedModule.types | 13 +++++++ .../exportDefaultForNonInstantiatedModule.ts | 8 ++++ 8 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 tests/baselines/reference/exportDefaultForNonInstantiatedModule.js create mode 100644 tests/baselines/reference/exportDefaultForNonInstantiatedModule.types create mode 100644 tests/cases/compiler/exportDefaultForNonInstantiatedModule.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9ddd690b96fe9..9a82e69c3fab3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3924,26 +3924,28 @@ module ts { } function emitExportAssignment(node: ExportAssignment) { - if (languageVersion >= ScriptTarget.ES6) { - writeLine(); - emitStart(node); - write("export default "); - var expression = node.expression; - emit(expression); - if (expression.kind !== SyntaxKind.FunctionDeclaration && - expression.kind !== SyntaxKind.ClassDeclaration) { + if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { + if (languageVersion >= ScriptTarget.ES6) { + writeLine(); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== SyntaxKind.FunctionDeclaration && + expression.kind !== SyntaxKind.ClassDeclaration) { + write(";"); + } + emitEnd(node); + } + else { + writeLine(); + emitStart(node); + emitContainingModuleName(node); + write(".default = "); + emit(node.expression); write(";"); + emitEnd(node); } - emitEnd(node); - } - else if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) { - writeLine(); - emitStart(node); - emitContainingModuleName(node); - write(".default = "); - emit(node.expression); - write(";"); - emitEnd(node); } } diff --git a/tests/baselines/reference/es6ExportAssignment.js b/tests/baselines/reference/es6ExportAssignment.js index 113e28108b166..4a4e0368bb7e8 100644 --- a/tests/baselines/reference/es6ExportAssignment.js +++ b/tests/baselines/reference/es6ExportAssignment.js @@ -5,4 +5,3 @@ export = a; //// [es6ExportAssignment.js] var a = 10; -export default a; diff --git a/tests/baselines/reference/es6ExportEquals.js b/tests/baselines/reference/es6ExportEquals.js index d51f8740da076..68c5788c89b04 100644 --- a/tests/baselines/reference/es6ExportEquals.js +++ b/tests/baselines/reference/es6ExportEquals.js @@ -8,7 +8,6 @@ export = f; //// [es6ExportEquals.js] export function f() { } -export default f; //// [es6ExportEquals.d.ts] diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.js b/tests/baselines/reference/es6ImportEqualsDeclaration.js index b8e9777a894c5..5195bdc631b30 100644 --- a/tests/baselines/reference/es6ImportEqualsDeclaration.js +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.js @@ -10,5 +10,4 @@ import a = require("server"); //// [server.js] var a = 10; -export default a; //// [client.js] diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js index ea9e65db34aab..eab345e4e7f30 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -12,7 +12,6 @@ export = a; export var a = 10; //// [es6ImportNamedImportInExportAssignment_1.js] import { a } from "es6ImportNamedImportInExportAssignment_0"; -export default a; //// [es6ImportNamedImportInExportAssignment_0.d.ts] diff --git a/tests/baselines/reference/exportDefaultForNonInstantiatedModule.js b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.js new file mode 100644 index 0000000000000..f2b98e6eb4459 --- /dev/null +++ b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.js @@ -0,0 +1,10 @@ +//// [exportDefaultForNonInstantiatedModule.ts] + +module m { + export interface foo { + } +} +// Should not be emitted +export default m; + +//// [exportDefaultForNonInstantiatedModule.js] diff --git a/tests/baselines/reference/exportDefaultForNonInstantiatedModule.types b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.types new file mode 100644 index 0000000000000..940bb44658e8a --- /dev/null +++ b/tests/baselines/reference/exportDefaultForNonInstantiatedModule.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/exportDefaultForNonInstantiatedModule.ts === + +module m { +>m : unknown + + export interface foo { +>foo : foo + } +} +// Should not be emitted +export default m; +>m : unknown + diff --git a/tests/cases/compiler/exportDefaultForNonInstantiatedModule.ts b/tests/cases/compiler/exportDefaultForNonInstantiatedModule.ts new file mode 100644 index 0000000000000..a1d1cab94b6aa --- /dev/null +++ b/tests/cases/compiler/exportDefaultForNonInstantiatedModule.ts @@ -0,0 +1,8 @@ +// @target: ES6 + +module m { + export interface foo { + } +} +// Should not be emitted +export default m; \ No newline at end of file From b9e503d891edc70d25114670d6f7abf5c1e8cdff Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 23 Mar 2015 12:37:22 -0700 Subject: [PATCH 14/24] Ellide uninstantiated exports in ES6 --- src/compiler/emitter.ts | 77 ++++++++++--------- tests/baselines/reference/es6ExportClause.js | 3 +- .../es6ExportClauseWithoutModuleSpecifier.js | 3 +- .../es6ImportNamedImportParsingError.js | 2 +- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9a82e69c3fab3..fe72f174124a9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3706,18 +3706,7 @@ module ts { } else { write("{ "); - let importSpecifiers = (node.importClause.namedBindings).elements; - let currentTextPos = writer.getTextPos(); - let needsComma = false; - for (var i = 0, n = importSpecifiers.length; i < n; i++) { - if (resolver.isReferencedAliasDeclaration(importSpecifiers[i])) { - if (needsComma) { - write(", "); - } - needsComma = true; - emit(importSpecifiers[i]); - } - } + emitExportOrImportSpecifierList((node.importClause.namedBindings).elements); write(" }"); } emitEnd(node.importClause.namedBindings); @@ -3758,15 +3747,6 @@ module ts { } } - function emitImportOrExportSpecifier(node: ImportSpecifier) { - Debug.assert(languageVersion >= ScriptTarget.ES6); - if (node.propertyName) { - emit(node.propertyName); - write(" as "); - } - emit(node.name); - } - function emitExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { if (contains(externalImports, node)) { let exportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; @@ -3902,24 +3882,50 @@ module ts { } write(");"); } + emitEnd(node); } } else { - write("export "); - if (node.exportClause) { - // export { x, y, ... } - write("{ "); - emitCommaList(node.exportClause.elements); - write(" }"); - } - else { - write("*"); + if (!node.exportClause || resolver.isValueAliasDeclaration(node)) { + emitStart(node); + write("export "); + if (node.exportClause) { + // export { x, y, ... } + write("{ "); + emitExportOrImportSpecifierList(node.exportClause.elements); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + emitNodeWithoutSourceMap(node.moduleSpecifier); + } + write(";"); + emitEnd(node); } - if (node.moduleSpecifier) { - write(" from "); - emit(node.moduleSpecifier); + } + } + + function emitExportOrImportSpecifierList(specifiers: ImportOrExportSpecifier[]) { + Debug.assert(languageVersion >= ScriptTarget.ES6); + + let needsComma = false; + for (let specifier of specifiers) { + if (resolver.isValueAliasDeclaration(specifier)) { + if (needsComma) { + write(", "); + } + emitStart(specifier); + if (specifier.propertyName) { + emitNodeWithoutSourceMap(specifier.propertyName); + write(" as "); + } + emitNodeWithoutSourceMap(specifier.name); + emitEnd(specifier); + needsComma = true; } - write(";"); } } @@ -4386,9 +4392,6 @@ module ts { return emitModuleDeclaration(node); case SyntaxKind.ImportDeclaration: return emitImportDeclaration(node); - case SyntaxKind.ImportSpecifier: - case SyntaxKind.ExportSpecifier: - return emitImportOrExportSpecifier(node); case SyntaxKind.ImportEqualsDeclaration: return emitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: diff --git a/tests/baselines/reference/es6ExportClause.js b/tests/baselines/reference/es6ExportClause.js index 4fba47ea7d1d0..f0d9bbe8cfffe 100644 --- a/tests/baselines/reference/es6ExportClause.js +++ b/tests/baselines/reference/es6ExportClause.js @@ -26,8 +26,7 @@ var m; var x = 10; export { c }; export { c as c2 }; -export { i, m as instantiatedModule }; -export { uninstantiated }; +export { m as instantiatedModule }; export { x }; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js index 7952bdb0bcc4b..c8528895462d5 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -32,8 +32,7 @@ export var x = 10; //// [client.js] export { c } from "server"; export { c as c2 } from "server"; -export { i, m as instantiatedModule } from "server"; -export { uninstantiated } from "server"; +export { m as instantiatedModule } from "server"; export { x } from "server"; diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index 81f141b3dd858..1be56ef4a0851 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -24,5 +24,5 @@ from; } from; "es6ImportNamedImportParsingError_0"; -import { a } from , from; +import { } from , from; "es6ImportNamedImportParsingError_0"; From d2ead157679de4bda174cb574d8a7a76be503c8d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 23 Mar 2015 12:47:39 -0700 Subject: [PATCH 15/24] Accept baseline changes --- .../es6ExportEqualsInterop.errors.txt | 76 +++++++++---------- ...ndingFollowedWithNamespaceBinding1InEs5.js | 2 +- ...tBindingFollowedWithNamespaceBindingDts.js | 2 +- ...indingFollowedWithNamespaceBindingInEs5.js | 2 +- ...gFollowedWithNamespaceBindingWithExport.js | 2 +- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt index 6351a3ee89b9c..7cc8418714580 100644 --- a/tests/baselines/reference/es6ExportEqualsInterop.errors.txt +++ b/tests/baselines/reference/es6ExportEqualsInterop.errors.txt @@ -11,25 +11,25 @@ tests/cases/compiler/main.ts(33,8): error TS1192: External module '"function"' h tests/cases/compiler/main.ts(34,8): error TS1192: External module '"function-module"' has no default export. tests/cases/compiler/main.ts(35,8): error TS1192: External module '"class"' has no default export. tests/cases/compiler/main.ts(36,8): error TS1192: External module '"class-module"' has no default export. -tests/cases/compiler/main.ts(39,21): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(45,21): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(47,21): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(62,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(68,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(70,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(85,25): error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(91,25): error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(93,25): error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. -tests/cases/compiler/main.ts(97,15): error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(98,15): error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(99,15): error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(100,15): error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(101,15): error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(102,15): error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(103,15): error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(104,15): error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(105,15): error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. -tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(39,21): error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(45,21): error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(47,21): error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(62,25): error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(68,25): error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(70,25): error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(85,25): error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(91,25): error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(93,25): error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +tests/cases/compiler/main.ts(97,15): error TS2498: External module '"interface"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(98,15): error TS2498: External module '"variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(99,15): error TS2498: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(100,15): error TS2498: External module '"module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(101,15): error TS2498: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(102,15): error TS2498: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(103,15): error TS2498: External module '"function"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(104,15): error TS2498: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(105,15): error TS2498: External module '"class"' uses 'export =' and cannot be used with 'export *'. +tests/cases/compiler/main.ts(106,15): error TS2498: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. ==== tests/cases/compiler/main.ts (32 errors) ==== @@ -99,7 +99,7 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu // namespace import import * as y1 from "interface"; ~~~~~~~~~~~ -!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. import * as y2 from "variable"; import * as y3 from "interface-variable"; import * as y4 from "module"; @@ -107,11 +107,11 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu import * as y6 from "variable-module"; import * as y7 from "function"; ~~~~~~~~~~ -!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. import * as y8 from "function-module"; import * as y9 from "class"; ~~~~~~~ -!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. import * as y0 from "class-module"; y1.a; @@ -128,7 +128,7 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu // named import import { a as a1 } from "interface"; ~~~~~~~~~~~ -!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. import { a as a2 } from "variable"; import { a as a3 } from "interface-variable"; import { a as a4 } from "module"; @@ -136,11 +136,11 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu import { a as a6 } from "variable-module"; import { a as a7 } from "function"; ~~~~~~~~~~ -!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. import { a as a8 } from "function-module"; import { a as a9 } from "class"; ~~~~~~~ -!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. import { a as a0 } from "class-module"; a1; @@ -157,7 +157,7 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu // named export export { a as a1 } from "interface"; ~~~~~~~~~~~ -!!! error TS2496: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"interface"' resolves to a non-module entity and cannot be imported using this construct. export { a as a2 } from "variable"; export { a as a3 } from "interface-variable"; export { a as a4 } from "module"; @@ -165,44 +165,44 @@ tests/cases/compiler/main.ts(106,15): error TS2497: External module '"class-modu export { a as a6 } from "variable-module"; export { a as a7 } from "function"; ~~~~~~~~~~ -!!! error TS2496: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"function"' resolves to a non-module entity and cannot be imported using this construct. export { a as a8 } from "function-module"; export { a as a9 } from "class"; ~~~~~~~ -!!! error TS2496: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. +!!! error TS2497: External module '"class"' resolves to a non-module entity and cannot be imported using this construct. export { a as a0 } from "class-module"; // export-star export * from "interface"; ~~~~~~~~~~~ -!!! error TS2497: External module '"interface"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"interface"' uses 'export =' and cannot be used with 'export *'. export * from "variable"; ~~~~~~~~~~ -!!! error TS2497: External module '"variable"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"variable"' uses 'export =' and cannot be used with 'export *'. export * from "interface-variable"; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"interface-variable"' uses 'export =' and cannot be used with 'export *'. export * from "module"; ~~~~~~~~ -!!! error TS2497: External module '"module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"module"' uses 'export =' and cannot be used with 'export *'. export * from "interface-module"; ~~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"interface-module"' uses 'export =' and cannot be used with 'export *'. export * from "variable-module"; ~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"variable-module"' uses 'export =' and cannot be used with 'export *'. export * from "function"; ~~~~~~~~~~ -!!! error TS2497: External module '"function"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"function"' uses 'export =' and cannot be used with 'export *'. export * from "function-module"; ~~~~~~~~~~~~~~~~~ -!!! error TS2497: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"function-module"' uses 'export =' and cannot be used with 'export *'. export * from "class"; ~~~~~~~ -!!! error TS2497: External module '"class"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"class"' uses 'export =' and cannot be used with 'export *'. export * from "class-module"; ~~~~~~~~~~~~~~ -!!! error TS2497: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. +!!! error TS2498: External module '"class-module"' uses 'export =' and cannot be used with 'export *'. ==== tests/cases/compiler/modules.d.ts (0 errors) ==== diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js index d16752f2d6899..8481420ac9415 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -13,7 +13,7 @@ var x: number = defaultBinding; var a = 10; exports.default = a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] -var nameSpaceBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var _es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0 = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"), nameSpaceBinding = _es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0; var x = _es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.default; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js index 4bde6e25b10c1..dc068451677c2 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js @@ -16,7 +16,7 @@ var a = (function () { })(); exports.a = a; //// [client.js] -var nameSpaceBinding = require("server"); +var _server = require("server"), nameSpaceBinding = _server; exports.x = new nameSpaceBinding.a(); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js index 9131fcc75db80..a37e732ca40db 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js @@ -11,7 +11,7 @@ var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] -var nameSpaceBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var _es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0 = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"), nameSpaceBinding = _es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0; var x = nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js index b219b5e7876d4..27bde8dde01a5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js @@ -11,7 +11,7 @@ export var x: number = nameSpaceBinding.a; //// [server.js] exports.a = 10; //// [client.js] -var nameSpaceBinding = require("server"); +var _server = require("server"), nameSpaceBinding = _server; exports.x = nameSpaceBinding.a; From 580bb83c3797d8246324cc5af4e8da34b1864744 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Mar 2015 16:56:29 -0700 Subject: [PATCH 16/24] Fix issue with AMD emit for 'import d, * as x from "foo"' --- src/compiler/emitter.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 299ac0a2b6c49..d4271c2383023 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5004,6 +5004,10 @@ module ts { } } + function isDefaultImport(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration) { + return node.kind === SyntaxKind.ImportDeclaration && (node).importClause && !!(node).importClause.name; + } + function emitExportImportAssignments(node: Node) { if (isAliasSymbolDeclaration(node) && resolver.isValueAliasDeclaration(node)) { emitExportMemberAssignments((node).name); @@ -5018,8 +5022,7 @@ module ts { if (compilerOptions.module !== ModuleKind.AMD) { emitLeadingComments(node); emitStart(node); - let isDefaultImport = node.kind === SyntaxKind.ImportDeclaration && (node).importClause && !!(node).importClause.name; - if (namespaceDeclaration && !isDefaultImport) { + if (namespaceDeclaration && !isDefaultImport(node)) { // import x = require("foo") // import * as x from "foo" if (!isExportedImport) write("var "); @@ -5040,7 +5043,7 @@ module ts { } } emitRequire(getExternalModuleName(node)); - if (namespaceDeclaration && isDefaultImport) { + if (namespaceDeclaration && isDefaultImport(node)) { // import d, * as x from "foo" write(", "); emitModuleMemberName(namespaceDeclaration); @@ -5059,6 +5062,14 @@ module ts { emit(namespaceDeclaration.name); write(";"); } + else if (namespaceDeclaration && isDefaultImport(node)) { + // import d, * as x from "foo" + write("var "); + emitModuleMemberName(namespaceDeclaration); + write(" = "); + write(resolver.getGeneratedNameForNode(node)); + write(";"); + } emitExportImportAssignments(node); } } @@ -5249,7 +5260,7 @@ module ts { for (let importNode of externalImports) { write(", "); let namespaceDeclaration = getNamespaceDeclarationNode(importNode); - if (namespaceDeclaration) { + if (namespaceDeclaration && !isDefaultImport(importNode)) { emit(namespaceDeclaration.name); } else { From 73567756fa186881e2bb5d286b2424afcaefd375 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 23 Mar 2015 17:03:54 -0700 Subject: [PATCH 17/24] Accepting new baselines --- tests/baselines/reference/exportsAndImports4-amd.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/exportsAndImports4-amd.js b/tests/baselines/reference/exportsAndImports4-amd.js index d915f4786a6cb..08342c566007b 100644 --- a/tests/baselines/reference/exportsAndImports4-amd.js +++ b/tests/baselines/reference/exportsAndImports4-amd.js @@ -44,7 +44,7 @@ define(["require", "exports"], function (require, exports) { exports.default = "hello"; }); //// [t3.js] -define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], function (require, exports, a, _t1, c, _t1_2, e2, _t1_4) { +define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], function (require, exports, a, _t1, c, _t1_2, _t1_3, _t1_4) { exports.a = a; a.default; exports.b = _t1.default; @@ -53,6 +53,7 @@ define(["require", "exports", "./t1", "./t1", "./t1", "./t1", "./t1", "./t1"], f c.default; exports.d = _t1_2.default; _t1_2.default; + var e2 = _t1_3; exports.e1 = _t1_3.default; exports.e2 = e2; _t1_3.default; From 515cdcdd782f726ea0e3e3a68b6e7981de3dd717 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Mar 2015 14:55:00 -0700 Subject: [PATCH 18/24] return undefined if we are not renaming to ensure we get the correct text --- 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 589c76065dfa3..cb85104fb7904 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11142,7 +11142,7 @@ module ts { // If this is es6 or higher, just use the name of the export // no need to qualify it. if (languageVersion >= ScriptTarget.ES6) { - return symbolName; + return undefined; } else { return "exports." + symbolName; From 352633dfda64f4d8383ee38b75b56fd804a13a58 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Mar 2015 20:36:02 -0700 Subject: [PATCH 19/24] Rename isES6ModuleMemberDeclaration to isES6ExportedDeclaration. --- src/compiler/emitter.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fced002c62735..2892059061f1f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2707,7 +2707,7 @@ module ts { generatedBlockScopeNames[variableId] = generatedName; } - function isES6ModuleMemberDeclaration(node: Node) { + function isES6ExportedDeclaration(node: Node) { return !!(node.flags & NodeFlags.Export) && languageVersion >= ScriptTarget.ES6 && node.parent.kind === SyntaxKind.SourceFile; @@ -2866,7 +2866,7 @@ module ts { // For targeting below es6, emit functions-like declaration including arrow function using function keyword. // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead if (!shouldEmitAsArrowFunction(node)) { - if (isES6ModuleMemberDeclaration(node)) { + if (isES6ExportedDeclaration(node)) { write("export "); if (node.flags & NodeFlags.Default) { write("default "); @@ -2949,7 +2949,7 @@ module ts { emitExpressionFunctionBody(node, node.body); } - if (!isES6ModuleMemberDeclaration(node)) { + if (!isES6ExportedDeclaration(node)) { emitExportMemberAssignment(node); } @@ -3372,7 +3372,7 @@ module ts { } function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { - if (isES6ModuleMemberDeclaration(node)) { + if (isES6ExportedDeclaration(node)) { write("export "); if (node.flags & NodeFlags.Default) { @@ -3411,7 +3411,7 @@ module ts { // If this is an exported class, but not on the top level (i.e. on an internal // module), export it - if (!isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Export)) { + if (!isES6ExportedDeclaration(node) && (node.flags & NodeFlags.Export)) { writeLine(); emitStart(node); emitModuleMemberName(node); @@ -3485,7 +3485,7 @@ module ts { return; } - if (!(node.flags & NodeFlags.Export) || isES6ModuleMemberDeclaration(node)) { + if (!(node.flags & NodeFlags.Export) || isES6ExportedDeclaration(node)) { emitStart(node); write("var "); emit(node.name); @@ -3512,7 +3512,7 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (isES6ModuleMemberDeclaration(node)) { + if (isES6ExportedDeclaration(node)) { emitES6NamedExportForDeclaration(node); } else if (node.flags & NodeFlags.Export) { @@ -3619,7 +3619,7 @@ module ts { } write(")("); // write moduleDecl = containingModule.m only if it is not exported es6 module member - if ((node.flags & NodeFlags.Export) && !isES6ModuleMemberDeclaration(node)) { + if ((node.flags & NodeFlags.Export) && !isES6ExportedDeclaration(node)) { emit(node.name); write(" = "); } @@ -3628,7 +3628,7 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (isES6ModuleMemberDeclaration(node)) { + if (isES6ExportedDeclaration(node)) { emitES6NamedExportForDeclaration(node); } else if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { @@ -3820,7 +3820,7 @@ module ts { (!isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); - if (isES6ModuleMemberDeclaration(node)) { + if (isES6ExportedDeclaration(node)) { write("export "); write("var "); } From 27c5d6fa503e8fc439ced7173a41794dd22c22d2 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Mar 2015 20:50:42 -0700 Subject: [PATCH 20/24] use the correct check for import and export specifiers --- src/compiler/emitter.ts | 8 ++++---- .../reference/es6ImportNamedImportParsingError.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2892059061f1f..93ff34fef8eef 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3706,7 +3706,7 @@ module ts { } else { write("{ "); - emitExportOrImportSpecifierList((node.importClause.namedBindings).elements); + emitExportOrImportSpecifierList((node.importClause.namedBindings).elements, resolver.isReferencedAliasDeclaration); write(" }"); } emitEnd(node.importClause.namedBindings); @@ -3917,7 +3917,7 @@ module ts { if (node.exportClause) { // export { x, y, ... } write("{ "); - emitExportOrImportSpecifierList(node.exportClause.elements); + emitExportOrImportSpecifierList(node.exportClause.elements, resolver.isValueAliasDeclaration); write(" }"); } else { @@ -3933,12 +3933,12 @@ module ts { } } - function emitExportOrImportSpecifierList(specifiers: ImportOrExportSpecifier[]) { + function emitExportOrImportSpecifierList(specifiers: ImportOrExportSpecifier[], shouldEmit: (node: Node) => boolean) { Debug.assert(languageVersion >= ScriptTarget.ES6); let needsComma = false; for (let specifier of specifiers) { - if (resolver.isValueAliasDeclaration(specifier)) { + if (shouldEmit(specifier)) { if (needsComma) { write(", "); } diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index 1be56ef4a0851..81f141b3dd858 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -24,5 +24,5 @@ from; } from; "es6ImportNamedImportParsingError_0"; -import { } from , from; +import { a } from , from; "es6ImportNamedImportParsingError_0"; From 6c40c953138ea885f4d5f0fd257cba18310d2199 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Mar 2015 21:17:11 -0700 Subject: [PATCH 21/24] Disallow export declarations in internal modules --- src/compiler/checker.ts | 5 ++ src/compiler/emitter.ts | 30 +------ .../es5ModuleInternalNamedImports.errors.txt | 59 ++++++++++++++ .../es5ModuleInternalNamedImports.js | 6 -- .../es5ModuleInternalNamedImports.types | 77 ------------------ .../es6ModuleInternalNamedImports.errors.txt | 59 ++++++++++++++ .../es6ModuleInternalNamedImports.js | 12 +-- .../es6ModuleInternalNamedImports.types | 77 ------------------ .../es6ModuleInternalNamedImports2.errors.txt | 61 ++++++++++++++ .../es6ModuleInternalNamedImports2.js | 12 +-- .../es6ModuleInternalNamedImports2.types | 81 ------------------- .../reference/multipleExports.errors.txt | 5 +- tests/baselines/reference/multipleExports.js | 1 - 13 files changed, 201 insertions(+), 284 deletions(-) create mode 100644 tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt delete mode 100644 tests/baselines/reference/es5ModuleInternalNamedImports.types create mode 100644 tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt delete mode 100644 tests/baselines/reference/es6ModuleInternalNamedImports.types create mode 100644 tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt delete mode 100644 tests/baselines/reference/es6ModuleInternalNamedImports2.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cb85104fb7904..1f152a83b995b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10236,6 +10236,11 @@ module ts { // export { x, y } // export { x, y } from "foo" forEach(node.exportClause.elements, checkExportSpecifier); + + let inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; + if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { + error(node, Diagnostics.Export_declarations_are_not_permitted_in_an_internal_module); + } } else { // export * from "foo" diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 93ff34fef8eef..3d80a9eb08ad9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3838,35 +3838,7 @@ module ts { } function emitExportDeclaration(node: ExportDeclaration) { - if (node.parent.kind !== SyntaxKind.SourceFile) { - // internal module - if (node.exportClause) { - // export { x, y, ... } - for (let specifier of node.exportClause.elements) { - if (resolver.isValueAliasDeclaration(specifier)) { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithoutSourceMap(specifier.name); - write(" = "); - - var name = specifier.propertyName || specifier.name; - var generatedName = getGeneratedNameForIdentifier(name); - if (generatedName) { - write(generatedName); - } - else { - emitExpressionIdentifier(name); - } - - write(";"); - emitEnd(specifier); - } - } - } - } - else if (languageVersion < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { emitStart(node); let generatedName = resolver.getGeneratedNameForNode(node); diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt new file mode 100644 index 0000000000000..65f29984d593a --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.errors.txt @@ -0,0 +1,59 @@ +tests/cases/compiler/es5ModuleInternalNamedImports.ts(23,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(24,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(25,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(26,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(27,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(28,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(29,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es5ModuleInternalNamedImports.ts(30,5): error TS1194: Export declarations are not permitted in an internal module. + + +==== tests/cases/compiler/es5ModuleInternalNamedImports.ts (8 errors) ==== + + export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_I as i}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_C as c}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_M as m}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_MU as mu}; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_F as f}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_E as e}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_A as a}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.js b/tests/baselines/reference/es5ModuleInternalNamedImports.js index 66e94204c5a76..456ad30523b79 100644 --- a/tests/baselines/reference/es5ModuleInternalNamedImports.js +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.js @@ -61,11 +61,5 @@ define(["require", "exports"], function (require, exports) { // alias M.M_A = M_M; // Reexports - M.v = M.M_V; - M.c = M_C; - M.m = M_M; - M.f = M_F; - M.e = M_E; - M.a = M.M_A; })(M = exports.M || (exports.M = {})); }); diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.types b/tests/baselines/reference/es5ModuleInternalNamedImports.types deleted file mode 100644 index fa88ab399a3fc..0000000000000 --- a/tests/baselines/reference/es5ModuleInternalNamedImports.types +++ /dev/null @@ -1,77 +0,0 @@ -=== tests/cases/compiler/es5ModuleInternalNamedImports.ts === - -export module M { ->M : typeof M - - // variable - export var M_V = 0; ->M_V : number - - // interface - export interface M_I { } ->M_I : M_I - - //calss - export class M_C { } ->M_C : M_C - - // instantiated module - export module M_M { var x; } ->M_M : typeof M_M ->x : any - - // uninstantiated module - export module M_MU { } ->M_MU : unknown - - // function - export function M_F() { } ->M_F : () => void - - // enum - export enum M_E { } ->M_E : M_E - - // type - export type M_T = number; ->M_T : number - - // alias - export import M_A = M_M; ->M_A : typeof M_M ->M_M : typeof M_M - - // Reexports - export {M_V as v}; ->M_V : number ->v : number - - export {M_I as i}; ->M_I : unknown ->i : unknown - - export {M_C as c}; ->M_C : typeof M_C ->c : typeof M_C - - export {M_M as m}; ->M_M : typeof M_M ->m : typeof M_M - - export {M_MU as mu}; ->M_MU : unknown ->mu : unknown - - export {M_F as f}; ->M_F : () => void ->f : () => void - - export {M_E as e}; ->M_E : typeof M_E ->e : typeof M_E - - export {M_A as a}; ->M_A : typeof M_M ->a : typeof M_M -} - diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt b/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt new file mode 100644 index 0000000000000..4e097ec1a3383 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.errors.txt @@ -0,0 +1,59 @@ +tests/cases/compiler/es6ModuleInternalNamedImports.ts(23,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(24,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(25,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(26,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(27,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(28,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(29,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports.ts(30,5): error TS1194: Export declarations are not permitted in an internal module. + + +==== tests/cases/compiler/es6ModuleInternalNamedImports.ts (8 errors) ==== + + export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_I as i}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_C as c}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_M as m}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_MU as mu}; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_F as f}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_E as e}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_A as a}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.js b/tests/baselines/reference/es6ModuleInternalNamedImports.js index 096cdd1ca404a..e4881d7ec4e05 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.js @@ -57,11 +57,11 @@ var M; // alias M.M_A = M_M; // Reexports - M.v = M.M_V; - M.c = M_C; - M.m = M_M; - M.f = M_F; - M.e = M_E; - M.a = M.M_A; + export { M_V as v }; + export { M_C as c }; + export { M_M as m }; + export { M_F as f }; + export { M_E as e }; + export { M_A as a }; })(M || (M = {})); export { M }; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.types b/tests/baselines/reference/es6ModuleInternalNamedImports.types deleted file mode 100644 index 6b614926a0af6..0000000000000 --- a/tests/baselines/reference/es6ModuleInternalNamedImports.types +++ /dev/null @@ -1,77 +0,0 @@ -=== tests/cases/compiler/es6ModuleInternalNamedImports.ts === - -export module M { ->M : typeof M - - // variable - export var M_V = 0; ->M_V : number - - // interface - export interface M_I { } ->M_I : M_I - - //calss - export class M_C { } ->M_C : M_C - - // instantiated module - export module M_M { var x; } ->M_M : typeof M_M ->x : any - - // uninstantiated module - export module M_MU { } ->M_MU : unknown - - // function - export function M_F() { } ->M_F : () => void - - // enum - export enum M_E { } ->M_E : M_E - - // type - export type M_T = number; ->M_T : number - - // alias - export import M_A = M_M; ->M_A : typeof M_M ->M_M : typeof M_M - - // Reexports - export {M_V as v}; ->M_V : number ->v : number - - export {M_I as i}; ->M_I : unknown ->i : unknown - - export {M_C as c}; ->M_C : typeof M_C ->c : typeof M_C - - export {M_M as m}; ->M_M : typeof M_M ->m : typeof M_M - - export {M_MU as mu}; ->M_MU : unknown ->mu : unknown - - export {M_F as f}; ->M_F : () => void ->f : () => void - - export {M_E as e}; ->M_E : typeof M_E ->e : typeof M_E - - export {M_A as a}; ->M_A : typeof M_M ->a : typeof M_M -} - diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt b/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt new file mode 100644 index 0000000000000..77ee76cf9c86a --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.errors.txt @@ -0,0 +1,61 @@ +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(25,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(26,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(27,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(28,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(29,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(30,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(31,5): error TS1194: Export declarations are not permitted in an internal module. +tests/cases/compiler/es6ModuleInternalNamedImports2.ts(32,5): error TS1194: Export declarations are not permitted in an internal module. + + +==== tests/cases/compiler/es6ModuleInternalNamedImports2.ts (8 errors) ==== + + export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + } + + export module M { + // Reexports + export {M_V as v}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_I as i}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_C as c}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_M as m}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_MU as mu}; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_F as f}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_E as e}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + export {M_A as a}; + ~~~~~~~~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.js b/tests/baselines/reference/es6ModuleInternalNamedImports2.js index c48d321440150..3f86def1d4241 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports2.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.js @@ -63,11 +63,11 @@ export { M }; var M; (function (M) { // Reexports - M.v = M.M_V; - M.c = M.M_C; - M.m = M.M_M; - M.f = M.M_F; - M.e = M.M_E; - M.a = M.M_A; + export { M_V as v }; + export { M_C as c }; + export { M_M as m }; + export { M_F as f }; + export { M_E as e }; + export { M_A as a }; })(M || (M = {})); export { M }; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.types b/tests/baselines/reference/es6ModuleInternalNamedImports2.types deleted file mode 100644 index 3612b1922efca..0000000000000 --- a/tests/baselines/reference/es6ModuleInternalNamedImports2.types +++ /dev/null @@ -1,81 +0,0 @@ -=== tests/cases/compiler/es6ModuleInternalNamedImports2.ts === - -export module M { ->M : typeof M - - // variable - export var M_V = 0; ->M_V : number - - // interface - export interface M_I { } ->M_I : M_I - - //calss - export class M_C { } ->M_C : M_C - - // instantiated module - export module M_M { var x; } ->M_M : typeof M_M ->x : any - - // uninstantiated module - export module M_MU { } ->M_MU : unknown - - // function - export function M_F() { } ->M_F : () => void - - // enum - export enum M_E { } ->M_E : M_E - - // type - export type M_T = number; ->M_T : number - - // alias - export import M_A = M_M; ->M_A : typeof M_M ->M_M : typeof M_M -} - -export module M { ->M : typeof M - - // Reexports - export {M_V as v}; ->M_V : number ->v : number - - export {M_I as i}; ->M_I : unknown ->i : unknown - - export {M_C as c}; ->M_C : typeof M_C ->c : typeof M_C - - export {M_M as m}; ->M_M : typeof M_M ->m : typeof M_M - - export {M_MU as mu}; ->M_MU : unknown ->mu : unknown - - export {M_F as f}; ->M_F : () => void ->f : () => void - - export {M_E as e}; ->M_E : typeof M_E ->e : typeof M_E - - export {M_A as a}; ->M_A : typeof M_M ->a : typeof M_M -} - diff --git a/tests/baselines/reference/multipleExports.errors.txt b/tests/baselines/reference/multipleExports.errors.txt index d0750b65313d4..254717843cfb4 100644 --- a/tests/baselines/reference/multipleExports.errors.txt +++ b/tests/baselines/reference/multipleExports.errors.txt @@ -1,7 +1,8 @@ +tests/cases/compiler/multipleExports.ts(10,5): error TS1194: Export declarations are not permitted in an internal module. tests/cases/compiler/multipleExports.ts(10,13): error TS2484: Export declaration conflicts with exported declaration of 'x' -==== tests/cases/compiler/multipleExports.ts (1 errors) ==== +==== tests/cases/compiler/multipleExports.ts (2 errors) ==== export module M { export var v = 0; @@ -12,6 +13,8 @@ tests/cases/compiler/multipleExports.ts(10,13): error TS2484: Export declaration export module M { v; export {x}; + ~~~~~~~~~~~ +!!! error TS1194: Export declarations are not permitted in an internal module. ~ !!! error TS2484: Export declaration conflicts with exported declaration of 'x' } diff --git a/tests/baselines/reference/multipleExports.js b/tests/baselines/reference/multipleExports.js index 12ee1590ceffe..b8c08952b67a8 100644 --- a/tests/baselines/reference/multipleExports.js +++ b/tests/baselines/reference/multipleExports.js @@ -22,5 +22,4 @@ var x = 0; var M; (function (M) { M.v; - M.x = M.x; })(M = exports.M || (exports.M = {})); From ab5c09a9a67203cf7a80e2a1d04c838a57498f79 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Mar 2015 21:43:03 -0700 Subject: [PATCH 22/24] Make isReferencedAliasDeclaration check children --- src/compiler/checker.ts | 7 ++++- src/compiler/emitter.ts | 30 +++---------------- src/compiler/types.ts | 2 +- .../baselines/reference/APISample_compile.js | 2 +- .../reference/APISample_compile.types | 5 ++-- tests/baselines/reference/APISample_linter.js | 2 +- .../reference/APISample_linter.types | 5 ++-- .../reference/APISample_transform.js | 2 +- .../reference/APISample_transform.types | 5 ++-- .../baselines/reference/APISample_watcher.js | 2 +- .../reference/APISample_watcher.types | 5 ++-- 11 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1f152a83b995b..bd993d0217fb1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11220,13 +11220,18 @@ module ts { return isConstEnumSymbol(s) || s.constEnumOnlyModule; } - function isReferencedAliasDeclaration(node: Node): boolean { + function isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean { if (isAliasSymbolDeclaration(node)) { let symbol = getSymbolOfNode(node); if (getSymbolLinks(symbol).referenced) { return true; } } + + if (checkChildren) { + return forEachChild(node, node => isReferencedAliasDeclaration(node, checkChildren)); + } + return false; } function isImplementationOfOverload(node: FunctionLikeDeclaration) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3d80a9eb08ad9..2cced08c60a8f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2717,7 +2717,7 @@ module ts { if (!(node.flags & NodeFlags.Export)) { emitStartOfVariableDeclarationList(node.declarationList); } - else if (languageVersion >= ScriptTarget.ES6 && node.parent.kind === SyntaxKind.SourceFile) { + else if (isES6ExportedDeclaration(node)) { // Exported ES6 module member write("export "); emitStartOfVariableDeclarationList(node.declarationList); @@ -3686,8 +3686,8 @@ module ts { // ES6 import if (node.importClause) { - let shouldEmitDefaultBindings = hasReferencedDefaultName(node.importClause); - let shouldEmitNamedBindings = hasReferencedNamedBindings(node.importClause); + let shouldEmitDefaultBindings = resolver.isReferencedAliasDeclaration(node.importClause); + let shouldEmitNamedBindings = node.importClause.namedBindings && resolver.isReferencedAliasDeclaration(node.importClause.namedBindings, /* checkChildren */ true); if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { write("import "); emitStart(node.importClause); @@ -3726,27 +3726,6 @@ module ts { } } - function hasReferencedDefaultName(importClause: ImportClause) { - // If the default import is used, the mark will be on the importClause, - // as the alias declaration. - // If there are other named bindings on the import clause, we will - // will mark either the namedBindings(import * as n) or the NamedImport - // in the case of import {a} - return resolver.isReferencedAliasDeclaration(importClause); - } - - function hasReferencedNamedBindings(importClause: ImportClause) { - if (importClause && importClause.namedBindings) { - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - return resolver.isReferencedAliasDeclaration(importClause.namedBindings); - } - else { - return forEach((importClause.namedBindings).elements, - namedImport => resolver.isReferencedAliasDeclaration(namedImport)); - } - } - } - function emitExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { if (contains(externalImports, node)) { let isExportedImport = node.kind === SyntaxKind.ImportEqualsDeclaration && (node.flags & NodeFlags.Export) !== 0; @@ -3961,8 +3940,7 @@ module ts { switch (node.kind) { case SyntaxKind.ImportDeclaration: if (!(node).importClause || - hasReferencedDefaultName((node).importClause) || - hasReferencedNamedBindings((node).importClause)) { + resolver.isReferencedAliasDeclaration((node).importClause, /*checkChildren*/ true)) { // import "mod" // import x from "mod" where x is referenced // import * as x from "mod" where x is referenced diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bc61eaf01d933..63db8e6be0a81 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1207,7 +1207,7 @@ module ts { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 9fb87e68517ef..cc6a2d6b70f48 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -942,7 +942,7 @@ declare module "typescript" { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index d0c895fd031d1..0798444f9c5f4 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3021,10 +3021,11 @@ declare module "typescript" { >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 6167cd99cb1d1..7adc64a083e21 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -973,7 +973,7 @@ declare module "typescript" { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 3e44508c62313..4d63f8b9a6e66 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3167,10 +3167,11 @@ declare module "typescript" { >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index a0f984ed22ba7..447bbec9af8eb 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -974,7 +974,7 @@ declare module "typescript" { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 1c415af859926..c599e6653dfe3 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3117,10 +3117,11 @@ declare module "typescript" { >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index ed372a7e876c4..3db6132e36339 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1011,7 +1011,7 @@ declare module "typescript" { getGeneratedNameForNode(node: Node): string; getExpressionNameSubstitution(node: Identifier): string; isValueAliasDeclaration(node: Node): boolean; - isReferencedAliasDeclaration(node: Node): boolean; + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 72cde72f1ae8d..a51d148634fdf 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3290,10 +3290,11 @@ declare module "typescript" { >node : Node >Node : Node - isReferencedAliasDeclaration(node: Node): boolean; ->isReferencedAliasDeclaration : (node: Node) => boolean + isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean; +>isReferencedAliasDeclaration : (node: Node, checkChildren?: boolean) => boolean >node : Node >Node : Node +>checkChildren : boolean isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; >isTopLevelValueImportEqualsWithEntityName : (node: ImportEqualsDeclaration) => boolean From bc51dd1e7775836baf4e36fbf187e2a7f8675d48 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Mar 2015 21:54:36 -0700 Subject: [PATCH 23/24] In ES6 use "export var x" for internal modules and enums instead of an after the fact "export {x};" --- src/compiler/emitter.ts | 25 ++++++------------- tests/baselines/reference/es6ExportAll.js | 3 +-- .../es6ExportClauseWithoutModuleSpecifier.js | 3 +-- .../reference/es6ModuleClassDeclaration.js | 3 +-- tests/baselines/reference/es6ModuleConst.js | 3 +-- .../es6ModuleConstEnumDeclaration.js | 3 +-- .../es6ModuleConstEnumDeclaration2.js | 6 ++--- .../reference/es6ModuleEnumDeclaration.js | 6 ++--- .../reference/es6ModuleFunctionDeclaration.js | 3 +-- .../reference/es6ModuleInternalImport.js | 6 ++--- .../es6ModuleInternalNamedImports.js | 3 +-- .../es6ModuleInternalNamedImports2.js | 6 ++--- tests/baselines/reference/es6ModuleLet.js | 3 +-- .../reference/es6ModuleModuleDeclaration.js | 3 +-- .../reference/es6ModuleVariableStatement.js | 3 +-- 15 files changed, 26 insertions(+), 53 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2cced08c60a8f..1b939980e9ab0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3487,6 +3487,9 @@ module ts { if (!(node.flags & NodeFlags.Export) || isES6ExportedDeclaration(node)) { emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } write("var "); emit(node.name); emitEnd(node); @@ -3512,10 +3515,7 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (isES6ExportedDeclaration(node)) { - emitES6NamedExportForDeclaration(node); - } - else if (node.flags & NodeFlags.Export) { + if (!isES6ExportedDeclaration(node) && node.flags & NodeFlags.Export) { writeLine(); emitStart(node); write("var "); @@ -3580,6 +3580,9 @@ module ts { } emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } write("var "); emit(node.name); write(";"); @@ -3628,23 +3631,11 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (isES6ExportedDeclaration(node)) { - emitES6NamedExportForDeclaration(node); - } - else if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { + if (!isES6ExportedDeclaration(node) && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { emitExportMemberAssignments(node.name); } } - function emitES6NamedExportForDeclaration(node: Declaration) { - writeLine(); - emitStart(node); - write("export { "); - emit(node.name); - write(" };"); - emitEnd(node); - } - function emitRequire(moduleName: Expression) { if (moduleName.kind === SyntaxKind.StringLiteral) { write("require("); diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js index 05c8a794e9127..afa07c39d8ff9 100644 --- a/tests/baselines/reference/es6ExportAll.js +++ b/tests/baselines/reference/es6ExportAll.js @@ -19,11 +19,10 @@ export * from "server"; //// [server.js] export class c { } -var m; +export var m; (function (m) { m.x = 10; })(m || (m = {})); -export { m }; export var x = 10; //// [client.js] export * from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js index c8528895462d5..ccdd32d99c0ad 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -23,11 +23,10 @@ export { x } from "server"; //// [server.js] export class c { } -var m; +export var m; (function (m) { m.x = 10; })(m || (m = {})); -export { m }; export var x = 10; //// [client.js] export { c } from "server"; diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.js b/tests/baselines/reference/es6ModuleClassDeclaration.js index 9676720fd0f1a..a228739abbfb7 100644 --- a/tests/baselines/reference/es6ModuleClassDeclaration.js +++ b/tests/baselines/reference/es6ModuleClassDeclaration.js @@ -147,7 +147,7 @@ c2.k = 20; c2.l = 30; new c(); new c2(); -var m1; +export var m1; (function (m1) { class c3 { constructor() { @@ -187,7 +187,6 @@ var m1; new c3(); new c4(); })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { class c3 { diff --git a/tests/baselines/reference/es6ModuleConst.js b/tests/baselines/reference/es6ModuleConst.js index 2a11ec638a16c..117bf0fb4d0d2 100644 --- a/tests/baselines/reference/es6ModuleConst.js +++ b/tests/baselines/reference/es6ModuleConst.js @@ -21,14 +21,13 @@ export const a = "hello"; export const x = a, y = x; const b = y; const c = b, d = c; -var m1; +export var m1; (function (m1) { m1.k = a; m1.l = b, m1.m = m1.k; const n = m1.k; const o = n, p = m1.k; })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { m2.k = a; diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js index c8096c76c8e20..1900db57b6037 100644 --- a/tests/baselines/reference/es6ModuleConstEnumDeclaration.js +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js @@ -48,14 +48,13 @@ module m2 { //// [es6ModuleConstEnumDeclaration.js] var x = 0 /* a */; var y = 0 /* x */; -var m1; +export var m1; (function (m1) { var x1 = 0 /* a */; var y1 = 0 /* x */; var x2 = 0 /* a */; var y2 = 0 /* x */; })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { var x1 = 0 /* a */; diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js index 5ec953aca88a1..539ec121b6b57 100644 --- a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js @@ -47,13 +47,12 @@ module m2 { } //// [es6ModuleConstEnumDeclaration2.js] -var e1; +export var e1; (function (e1) { e1[e1["a"] = 0] = "a"; e1[e1["b"] = 1] = "b"; e1[e1["c"] = 2] = "c"; })(e1 || (e1 = {})); -export { e1 }; var e2; (function (e2) { e2[e2["x"] = 0] = "x"; @@ -62,7 +61,7 @@ var e2; })(e2 || (e2 = {})); var x = 0 /* a */; var y = 0 /* x */; -var m1; +export var m1; (function (m1) { (function (e3) { e3[e3["a"] = 0] = "a"; @@ -81,7 +80,6 @@ var m1; var x2 = 0 /* a */; var y2 = 0 /* x */; })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { (function (e5) { diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.js b/tests/baselines/reference/es6ModuleEnumDeclaration.js index 0879214981896..30c382a4508bc 100644 --- a/tests/baselines/reference/es6ModuleEnumDeclaration.js +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.js @@ -46,13 +46,12 @@ module m2 { } //// [es6ModuleEnumDeclaration.js] -var e1; +export var e1; (function (e1) { e1[e1["a"] = 0] = "a"; e1[e1["b"] = 1] = "b"; e1[e1["c"] = 2] = "c"; })(e1 || (e1 = {})); -export { e1 }; var e2; (function (e2) { e2[e2["x"] = 0] = "x"; @@ -61,7 +60,7 @@ var e2; })(e2 || (e2 = {})); var x = e1.a; var y = e2.x; -var m1; +export var m1; (function (m1) { (function (e3) { e3[e3["a"] = 0] = "a"; @@ -80,7 +79,6 @@ var m1; var x2 = e3.a; var y2 = e4.x; })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { (function (e5) { diff --git a/tests/baselines/reference/es6ModuleFunctionDeclaration.js b/tests/baselines/reference/es6ModuleFunctionDeclaration.js index 4c1fc33647c71..1305d0a4e1904 100644 --- a/tests/baselines/reference/es6ModuleFunctionDeclaration.js +++ b/tests/baselines/reference/es6ModuleFunctionDeclaration.js @@ -35,7 +35,7 @@ function foo2() { } foo(); foo2(); -var m1; +export var m1; (function (m1) { function foo3() { } @@ -47,7 +47,6 @@ var m1; foo3(); foo4(); })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { function foo3() { diff --git a/tests/baselines/reference/es6ModuleInternalImport.js b/tests/baselines/reference/es6ModuleInternalImport.js index 4a1659cb90167..3f28ddb2b6095 100644 --- a/tests/baselines/reference/es6ModuleInternalImport.js +++ b/tests/baselines/reference/es6ModuleInternalImport.js @@ -20,22 +20,20 @@ module m2 { } //// [es6ModuleInternalImport.js] -var m; +export var m; (function (m) { m.a = 10; })(m || (m = {})); -export { m }; export var a1 = m.a; var a2 = m.a; var x = a1 + a2; -var m1; +export var m1; (function (m1) { m1.a3 = m.a; var a4 = m.a; var x = a1 + a2; var x2 = m1.a3 + a4; })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { m2.a3 = m.a; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.js b/tests/baselines/reference/es6ModuleInternalNamedImports.js index e4881d7ec4e05..db7c771eaba21 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.js @@ -33,7 +33,7 @@ export module M { //// [es6ModuleInternalNamedImports.js] -var M; +export var M; (function (M) { // variable M.M_V = 0; @@ -64,4 +64,3 @@ var M; export { M_E as e }; export { M_A as a }; })(M || (M = {})); -export { M }; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports2.js b/tests/baselines/reference/es6ModuleInternalNamedImports2.js index 3f86def1d4241..b080064306067 100644 --- a/tests/baselines/reference/es6ModuleInternalNamedImports2.js +++ b/tests/baselines/reference/es6ModuleInternalNamedImports2.js @@ -35,7 +35,7 @@ export module M { //// [es6ModuleInternalNamedImports2.js] -var M; +export var M; (function (M) { // variable M.M_V = 0; @@ -59,8 +59,7 @@ var M; // alias M.M_A = M_M; })(M || (M = {})); -export { M }; -var M; +export var M; (function (M) { // Reexports export { M_V as v }; @@ -70,4 +69,3 @@ var M; export { M_E as e }; export { M_A as a }; })(M || (M = {})); -export { M }; diff --git a/tests/baselines/reference/es6ModuleLet.js b/tests/baselines/reference/es6ModuleLet.js index 275fd39579e71..29d2a73bcf19d 100644 --- a/tests/baselines/reference/es6ModuleLet.js +++ b/tests/baselines/reference/es6ModuleLet.js @@ -21,14 +21,13 @@ export let a = "hello"; export let x = a, y = x; let b = y; let c = b, d = c; -var m1; +export var m1; (function (m1) { m1.k = a; m1.l = b, m1.m = m1.k; let n = m1.k; let o = n, p = m1.k; })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { m2.k = a; diff --git a/tests/baselines/reference/es6ModuleModuleDeclaration.js b/tests/baselines/reference/es6ModuleModuleDeclaration.js index 1e3716ac8c20e..c240545239f85 100644 --- a/tests/baselines/reference/es6ModuleModuleDeclaration.js +++ b/tests/baselines/reference/es6ModuleModuleDeclaration.js @@ -25,7 +25,7 @@ module m2 { } //// [es6ModuleModuleDeclaration.js] -var m1; +export var m1; (function (m1) { m1.a = 10; var b = 10; @@ -40,7 +40,6 @@ var m1; var y = 10; })(innerNonExportedModule = m1.innerNonExportedModule || (m1.innerNonExportedModule = {})); })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { m2.a = 10; diff --git a/tests/baselines/reference/es6ModuleVariableStatement.js b/tests/baselines/reference/es6ModuleVariableStatement.js index 11b60555b0dba..50c9c3fb4a84b 100644 --- a/tests/baselines/reference/es6ModuleVariableStatement.js +++ b/tests/baselines/reference/es6ModuleVariableStatement.js @@ -21,14 +21,13 @@ export var a = "hello"; export var x = a, y = x; var b = y; var c = b, d = c; -var m1; +export var m1; (function (m1) { m1.k = a; m1.l = b, m1.m = m1.k; var n = m1.k; var o = n, p = m1.k; })(m1 || (m1 = {})); -export { m1 }; var m2; (function (m2) { m2.k = a; From aa01dcd1a341480c643987f318543c8417bdff0c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 24 Mar 2015 22:20:42 -0700 Subject: [PATCH 24/24] Move es6 alias name handeling to getAliasNameSubstitution to match getExportNameSubstitution --- src/compiler/checker.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bd993d0217fb1..90f13e2c96cd5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11128,6 +11128,12 @@ module ts { } function getAliasNameSubstitution(symbol: Symbol): string { + // If this is es6 or higher, just use the name of the export + // no need to qualify it. + if (languageVersion >= ScriptTarget.ES6) { + return undefined; + } + let node = getDeclarationOfAliasSymbol(symbol); if (node) { if (node.kind === SyntaxKind.ImportClause) { @@ -11143,15 +11149,12 @@ module ts { function getExportNameSubstitution(symbol: Symbol, location: Node): string { if (isExternalModuleSymbol(symbol.parent)) { - var symbolName = unescapeIdentifier(symbol.name); // If this is es6 or higher, just use the name of the export // no need to qualify it. if (languageVersion >= ScriptTarget.ES6) { return undefined; } - else { - return "exports." + symbolName; - } + return "exports." + unescapeIdentifier(symbol.name); } let node = location; let containerSymbol = getParentOfSymbol(symbol); @@ -11179,7 +11182,7 @@ module ts { return getExportNameSubstitution(exportSymbol, node.parent); } // Named imports from ES6 import declarations are rewritten - if (symbol.flags & SymbolFlags.Alias && languageVersion < ScriptTarget.ES6) { + if (symbol.flags & SymbolFlags.Alias) { return getAliasNameSubstitution(symbol); } }