diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 423c3c316275a..a21cd936ad1a1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -512,6 +512,19 @@ module ts { node.kind === SyntaxKind.ExportAssignment; } + function getAnyImportSyntax(node: Node): AnyImportSyntax { + if (isAliasSymbolDeclaration(node)) { + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + return node; + } + + while (node.kind !== SyntaxKind.ImportDeclaration) { + node = node.parent; + } + return node; + } + } + function getDeclarationOfAliasSymbol(symbol: Symbol): Declaration { return forEach(symbol.declarations, d => isAliasSymbolDeclaration(d) ? d : undefined); } @@ -1122,7 +1135,7 @@ module ts { } function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult { - let aliasesToMakeVisible: ImportEqualsDeclaration[]; + let aliasesToMakeVisible: AnyImportSyntax[]; if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) { return undefined; } @@ -1132,17 +1145,19 @@ module ts { if (!isDeclarationVisible(declaration)) { // Mark the unexported alias as visible if its parent is visible // because these kind of aliases can be used to name types in declaration file - if (declaration.kind === SyntaxKind.ImportEqualsDeclaration && - !(declaration.flags & NodeFlags.Export) && - isDeclarationVisible(declaration.parent)) { + + var anyImportSyntax = getAnyImportSyntax(declaration); + if (anyImportSyntax && + !(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export + isDeclarationVisible(anyImportSyntax.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { - if (!contains(aliasesToMakeVisible, declaration)) { - aliasesToMakeVisible.push(declaration); + if (!contains(aliasesToMakeVisible, anyImportSyntax)) { + aliasesToMakeVisible.push(anyImportSyntax); } } else { - aliasesToMakeVisible = [declaration]; + aliasesToMakeVisible = [anyImportSyntax]; } return true; } @@ -1766,8 +1781,15 @@ module ts { function determineIfDeclarationIsVisible() { switch (node.kind) { - case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: + return isDeclarationVisible(node.parent.parent); + case SyntaxKind.VariableDeclaration: + if (isBindingPattern(node.name) && + !(node.name).elements.length) { + // If the binding pattern is empty, this variable declaration is not visible + return false; + } + // Otherwise fall through case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: @@ -1779,7 +1801,7 @@ module ts { // If the node is not exported or it is not ambient module element (except import declaration) if (!(getCombinedNodeFlags(node) & NodeFlags.Export) && !(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) { - return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); + return isGlobalSourceFile(parent); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent); @@ -1812,6 +1834,8 @@ module ts { case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); + // Default binding, import specifier and namespace import is visible + // only on demand so by default it is not visible case SyntaxKind.ImportClause: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: @@ -1837,6 +1861,40 @@ module ts { } } + function collectLinkedAliases(node: Identifier): Node[]{ + var exportSymbol: Symbol; + if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { + exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); + } + else if (node.parent.kind === SyntaxKind.ExportSpecifier) { + exportSymbol = getTargetOfExportSpecifier(node.parent); + } + var result: Node[] = []; + if (exportSymbol) { + buildVisibleNodeList(exportSymbol.declarations); + } + return result; + + function buildVisibleNodeList(declarations: Declaration[]) { + forEach(declarations, declaration => { + getNodeLinks(declaration).isVisible = true; + var resultNode = getAnyImportSyntax(declaration) || declaration; + if (!contains(result, resultNode)) { + result.push(resultNode); + } + + if (isInternalModuleImportEqualsDeclaration(declaration)) { + // Add the referenced top container visible + var internalModuleReference = (declaration).moduleReference; + var firstIdentifier = getFirstIdentifier(internalModuleReference); + var importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, + Diagnostics.Cannot_find_name_0, firstIdentifier); + buildVisibleNodeList(importSymbol.declarations); + } + }); + } + } + function getRootDeclaration(node: Node): Node { while (node.kind === SyntaxKind.BindingElement) { node = node.parent.parent; @@ -11157,6 +11215,11 @@ module ts { getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } + function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { + var type = getTypeOfExpression(expr); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + } + function isUnknownIdentifier(location: Node, name: string): boolean { Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location"); return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && @@ -11200,10 +11263,12 @@ module ts { isImplementationOfOverload, writeTypeOfDeclaration, writeReturnTypeOfSignatureDeclaration, + writeTypeOfExpression, isSymbolAccessible, isEntityNameVisible, getConstantValue, isUnknownIdentifier, + collectLinkedAliases, getBlockScopedVariableId, }; } @@ -12141,8 +12206,8 @@ module ts { } function checkGrammarTopLevelElementForRequiredDeclareModifier(node: Node): boolean { - // A declare modifier is required for any top level .d.ts declaration except export=, interfaces and imports: - // categories: + // A declare modifier is required for any top level .d.ts declaration except export=, export default, + // interfaces and imports categories: // // DeclarationElement: // ExportAssignment @@ -12156,7 +12221,8 @@ module ts { node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.ExportDeclaration || node.kind === SyntaxKind.ExportAssignment || - (node.flags & NodeFlags.Ambient)) { + (node.flags & NodeFlags.Ambient) || + (node.flags & (NodeFlags.Export | NodeFlags.Default))) { return false; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index dd26ef281c4bb..777639c6b34d0 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -414,6 +414,7 @@ module ts { Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4082, category: DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." }, Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e1767fe8de044..27275b041daa5 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1649,6 +1649,10 @@ "category": "Error", "code": 4081 }, + "Default export of the module has or is using private name '{0}'.": { + "category": "Error", + "code": 4082 + }, "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": { "category": "Error", "code": 4091 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 205f2fe2945ef..4d077709d2cbd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -40,16 +40,18 @@ module ts { getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; } - interface AliasDeclarationEmitInfo { - declaration: ImportEqualsDeclaration; + interface ModuleElementDeclarationEmitInfo { + node: Node; outputPos: number; indent: number; asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output + subModuleElementDeclarationEmitInfo?: ModuleElementDeclarationEmitInfo[]; + isVisible?: boolean; } interface DeclarationEmit { reportedDeclarationError: boolean; - aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[]; + moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; synchronousDeclarationOutput: string; referencePathsOutput: string; } @@ -374,7 +376,8 @@ module ts { let emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; let emit = compilerOptions.stripInternal ? stripInternal : emitNode; - let aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[] = []; + let moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = []; + let asynchronousSubModuleDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; // Contains the reference paths that needs to go in the declaration file. // Collecting this separately because reference paths need to be first thing in the declaration file @@ -402,6 +405,21 @@ module ts { } emitSourceFile(root); + + // create asynchronous output for the importDeclarations + if (moduleElementDeclarationEmitInfo.length) { + let oldWriter = writer; + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.isVisible) { + Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration); + createAndSetNewTextWriterWithSymbolWriter(); + Debug.assert(aliasEmitInfo.indent === 0); + writeImportDeclaration(aliasEmitInfo.node); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + }); + setWriter(oldWriter); + } } else { // Emit references corresponding to this file @@ -430,7 +448,7 @@ module ts { return { reportedDeclarationError, - aliasDeclarationEmitInfo, + moduleElementDeclarationEmitInfo, synchronousDeclarationOutput: writer.getText(), referencePathsOutput, } @@ -475,10 +493,23 @@ module ts { decreaseIndent = newWriter.decreaseIndent; } - function writeAsychronousImportEqualsDeclarations(importEqualsDeclarations: ImportEqualsDeclaration[]) { + function writeAsynchronousModuleElements(nodes: Node[]) { let oldWriter = writer; - forEach(importEqualsDeclarations, aliasToWrite => { - let aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); + forEach(nodes, declaration => { + let nodeToCheck: Node; + if (declaration.kind === SyntaxKind.VariableDeclaration) { + nodeToCheck = declaration.parent.parent; + } else if (declaration.kind === SyntaxKind.NamedImports || declaration.kind === SyntaxKind.ImportSpecifier || declaration.kind === SyntaxKind.ImportClause) { + Debug.fail("We should be getting ImportDeclaration instead to write"); + } else { + nodeToCheck = declaration; + } + + let moduleElementEmitInfo = forEach(moduleElementDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) { + moduleElementEmitInfo = forEach(asynchronousSubModuleDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + } + // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration // then we don't need to write it at this point. We will write it when we actually see its declaration // Eg. @@ -486,13 +517,29 @@ module ts { // import foo = require("foo"); // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, // we would write alias foo declaration when we visit it since it would now be marked as visible - if (aliasEmitInfo) { - createAndSetNewTextWriterWithSymbolWriter(); - for (let declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); + if (moduleElementEmitInfo) { + if (moduleElementEmitInfo.node.kind === SyntaxKind.ImportDeclaration) { + // we have to create asynchronous output only after we have collected complete information + // because it is possible to enable multiple bindings as asynchronously visible + moduleElementEmitInfo.isVisible = true; + } + else { + createAndSetNewTextWriterWithSymbolWriter(); + for (let declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); + asynchronousSubModuleDeclarationEmitInfo = []; + } + writeModuleElement(nodeToCheck); + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; + asynchronousSubModuleDeclarationEmitInfo = undefined; + } + moduleElementEmitInfo.asynchronousOutput = writer.getText(); } - writeImportEqualsDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); } }); setWriter(oldWriter); @@ -502,7 +549,7 @@ module ts { if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { // write the aliases if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsychronousImportEqualsDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); + writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible); } } else { @@ -561,19 +608,21 @@ module ts { } } - function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void) { + function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { let currentWriterPos = writer.getTextPos(); for (let node of nodes) { - if (currentWriterPos !== writer.getTextPos()) { - write(separator); + if (!canEmitFn || canEmitFn(node)) { + if (currentWriterPos !== writer.getTextPos()) { + write(separator); + } + currentWriterPos = writer.getTextPos(); + eachNodeEmitFn(node); } - currentWriterPos = writer.getTextPos(); - eachNodeEmitFn(node); } } - function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void) { - emitSeparatedList(nodes, ", ", eachNodeEmitFn); + function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn); } function writeJsDocComments(declaration: Node) { @@ -702,9 +751,100 @@ module ts { function emitExportAssignment(node: ExportAssignment) { write(node.isExportEquals ? "export = " : "export default "); - writeTextOfNode(currentSourceFile, node.expression); + if (node.expression.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, node.expression); + } + else { + write(": "); + if (node.type) { + emitType(node.type); + } + else { + writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; + resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } write(";"); writeLine(); + + // Make all the declarations visible for the export name + if (node.expression.kind === SyntaxKind.Identifier) { + let nodes = resolver.collectLinkedAliases(node.expression); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: node + }; + } + } + + function isModuleElementVisible(node: Declaration) { + return resolver.isDeclarationVisible(node); + } + + function emitModuleElement(node: Node, isModuleElementVisible: boolean) { + if (isModuleElementVisible) { + writeModuleElement(node); + } + // Import equals declaration in internal module can become visible as part of any emit so lets make sure we add these irrespective + else if (node.kind === SyntaxKind.ImportEqualsDeclaration || + (node.parent.kind === SyntaxKind.SourceFile && isExternalModule(currentSourceFile))) { + let isVisible: boolean; + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== SyntaxKind.SourceFile) { + // Import declaration of another module that is visited async so lets put it in right spot + asynchronousSubModuleDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + else { + if (node.kind === SyntaxKind.ImportDeclaration) { + let importDeclaration = node; + if (importDeclaration.importClause) { + isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || + isVisibleNamedBinding(importDeclaration.importClause.namedBindings); + } + } + moduleElementDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + } + } + + function writeModuleElement(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + return writeFunctionDeclaration(node); + case SyntaxKind.VariableStatement: + return writeVariableStatement(node); + case SyntaxKind.InterfaceDeclaration: + return writeInterfaceDeclaration(node); + case SyntaxKind.ClassDeclaration: + return writeClassDeclaration(node); + case SyntaxKind.TypeAliasDeclaration: + return writeTypeAliasDeclaration(node); + case SyntaxKind.EnumDeclaration: + return writeEnumDeclaration(node); + case SyntaxKind.ModuleDeclaration: + return writeModuleDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return writeImportEqualsDeclaration(node); + case SyntaxKind.ImportDeclaration: + return writeImportDeclaration(node); + default: + Debug.fail("Unknown symbol kind"); + } } function emitModuleElementDeclarationFlags(node: Node) { @@ -715,7 +855,10 @@ module ts { write("export "); } - if (node.kind !== SyntaxKind.InterfaceDeclaration) { + if (node.flags & NodeFlags.Default) { + write("default "); + } + else if (node.kind !== SyntaxKind.InterfaceDeclaration) { write("declare "); } } @@ -734,19 +877,6 @@ module ts { } } - function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - let nodeEmitInfo = { - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - hasWritten: resolver.isDeclarationVisible(node) - }; - aliasDeclarationEmitInfo.push(nodeEmitInfo); - if (nodeEmitInfo.hasWritten) { - writeImportEqualsDeclaration(node); - } - } - function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { // note usage of writer. methods instead of aliases created, just to make sure we are using // correct writer especially to handle asynchronous alias writing @@ -777,41 +907,123 @@ module ts { } } - function emitModuleDeclaration(node: ModuleDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("module "); - writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== SyntaxKind.ModuleBlock) { - node = node.body; - write("."); - writeTextOfNode(currentSourceFile, node.name); + function isVisibleNamedBinding(namedBindings: NamespaceImport | NamedImports): boolean { + if (namedBindings) { + if (namedBindings.kind === SyntaxKind.NamespaceImport) { + return resolver.isDeclarationVisible(namedBindings); + } + else { + return forEach((namedBindings).elements, namedImport => resolver.isDeclarationVisible(namedImport)); } - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - write(" {"); - writeLine(); - increaseIndent(); - emitLines((node.body).statements); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; } } - function emitTypeAliasDeclaration(node: TypeAliasDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("type "); + function writeImportDeclaration(node: ImportDeclaration) { + if (!node.importClause && !(node.flags & NodeFlags.Export)) { + // do not write non-exported import declarations that don't have import clauses + return; + } + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + if (node.importClause) { + let currentWriterPos = writer.getTextPos(); + if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) { + writeTextOfNode(currentSourceFile, node.importClause.name); + } + if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) { + if (currentWriterPos !== writer.getTextPos()) { + // If the default binding was emitted, write the separated + write(", "); + } + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + write("* as "); + writeTextOfNode(currentSourceFile, (node.importClause.namedBindings).name); + } + else { + write("{ "); + emitCommaList((node.importClause.namedBindings).elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible); + write(" }"); + } + } + write(" from "); + } + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + write(";"); + writer.writeLine(); + } + + function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) { + if (node.propertyName) { + writeTextOfNode(currentSourceFile, node.propertyName); + write(" as "); + } + writeTextOfNode(currentSourceFile, node.name); + } + + function emitExportSpecifier(node: ExportSpecifier) { + emitImportOrExportSpecifier(node); + + // Make all the declarations visible for the export name + let nodes = resolver.collectLinkedAliases(node.propertyName || node.name); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function emitExportDeclaration(node: ExportDeclaration) { + emitJsDocComments(node); + write("export "); + if (node.exportClause) { + write("{ "); + emitCommaList(node.exportClause.elements, emitExportSpecifier); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + } + write(";"); + writer.writeLine(); + } + + function writeModuleDeclaration(node: ModuleDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("module "); + writeTextOfNode(currentSourceFile, node.name); + while (node.body.kind !== SyntaxKind.ModuleBlock) { + node = node.body; + write("."); writeTextOfNode(currentSourceFile, node.name); - write(" = "); - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); - write(";"); - writeLine(); } + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + write(" {"); + writeLine(); + increaseIndent(); + emitLines((node.body).statements); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + function writeTypeAliasDeclaration(node: TypeAliasDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("type "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); + write(";"); + writeLine(); + function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, @@ -821,23 +1033,21 @@ module ts { } } - function emitEnumDeclaration(node: EnumDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isConst(node)) { - write("const ") - } - write("enum "); - writeTextOfNode(currentSourceFile, node.name); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); + function writeEnumDeclaration(node: EnumDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isConst(node)) { + write("const ") } + write("enum "); + writeTextOfNode(currentSourceFile, node.name); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); } function emitEnumMemberDeclaration(node: EnumMember) { @@ -969,7 +1179,7 @@ module ts { } } - function emitClassDeclaration(node: ClassDeclaration) { + function writeClassDeclaration(node: ClassDeclaration) { function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { if (constructorDeclaration) { forEach(constructorDeclaration.parameters, param => { @@ -980,50 +1190,46 @@ module ts { } } - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("class "); - writeTextOfNode(currentSourceFile, node.name); - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - let baseTypeNode = getClassBaseTypeNode(node); - if (baseTypeNode) { - emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); - } - emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); - write(" {"); - writeLine(); - increaseIndent(); - emitParameterProperties(getFirstConstructorWithBody(node)); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("class "); + writeTextOfNode(currentSourceFile, node.name); + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + let baseTypeNode = getClassBaseTypeNode(node); + if (baseTypeNode) { + emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); } + emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); + write(" {"); + writeLine(); + increaseIndent(); + emitParameterProperties(getFirstConstructorWithBody(node)); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; } - function emitInterfaceDeclaration(node: InterfaceDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("interface "); - writeTextOfNode(currentSourceFile, node.name); - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } + function writeInterfaceDeclaration(node: InterfaceDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("interface "); + writeTextOfNode(currentSourceFile, node.name); + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; } function emitPropertyDeclaration(node: Declaration) { @@ -1042,62 +1248,94 @@ module ts { // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted // so there is no check needed to see if declaration is visible if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { - // If this node is a computed name, it can only be a symbol, because we've already skipped - // it if it's not a well known symbol. In that case, the text of the name will be exactly - // what we want, namely the name expression enclosed in brackets. - writeTextOfNode(currentSourceFile, node.name); - // If optional property emit ? - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { - write("?"); - } - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); + if (isBindingPattern(node.name)) { + emitBindingPattern(node.name); } - else if (!(node.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + else { + // If this node is a computed name, it can only be a symbol, because we've already skipped + // it if it's not a well known symbol. In that case, the text of the name will be exactly + // what we want, namely the name expression enclosed in brackets. + writeTextOfNode(currentSourceFile, node.name); + // If optional property emit ? + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { + write("?"); + } + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + } } } - function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; + function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { if (node.kind === SyntaxKind.VariableDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } + } + function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); return diagnosticMessage !== undefined ? { diagnosticMessage, errorNode: node, typeName: node.name } : undefined; } + + function emitBindingPattern(bindingPattern: BindingPattern) { + emitCommaList(bindingPattern.elements, emitBindingElement); + } + + function emitBindingElement(bindingElement: BindingElement) { + function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: bindingElement, + typeName: bindingElement.name + } : undefined; + } + + if (bindingElement.name) { + if (isBindingPattern(bindingElement.name)) { + emitBindingPattern(bindingElement.name); + } + else { + writeTextOfNode(currentSourceFile, bindingElement.name); + writeTypeOfDeclaration(bindingElement, /*type*/ undefined, getBindingElementTypeVisibilityError); + } + } + } } function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) { @@ -1110,24 +1348,25 @@ module ts { } } - function emitVariableStatement(node: VariableStatement) { - let hasDeclarationWithEmit = forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); - if (hasDeclarationWithEmit) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isLet(node.declarationList)) { - write("let "); - } - else if (isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } - emitCommaList(node.declarationList.declarations, emitVariableDeclaration); - write(";"); - writeLine(); + function isVariableStatementVisible(node: VariableStatement) { + return forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); + } + + function writeVariableStatement(node: VariableStatement) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isLet(node.declarationList)) { + write("let "); + } + else if (isConst(node.declarationList)) { + write("const "); + } + else { + write("var "); } + emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible); + write(";"); + writeLine(); } function emitAccessorDeclaration(node: AccessorDeclaration) { @@ -1215,15 +1454,14 @@ module ts { } } - function emitFunctionDeclaration(node: FunctionLikeDeclaration) { + function writeFunctionDeclaration(node: FunctionLikeDeclaration) { if (hasDynamicName(node)) { return; } // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting // so no need to verify if the declaration is visible - if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) && - !resolver.isImplementationOfOverload(node)) { + if (!resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); if (node.kind === SyntaxKind.FunctionDeclaration) { emitModuleElementDeclarationFlags(node); @@ -1463,11 +1701,25 @@ module ts { function emitNode(node: Node) { switch (node.kind) { - case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + return emitModuleElement(node, isModuleElementVisible(node)); + case SyntaxKind.VariableStatement: + return emitModuleElement(node, isVariableStatementVisible(node)); + case SyntaxKind.ImportDeclaration: + // Import declaration without import clause is visible, otherwise it is not visible + return emitModuleElement(node, /*isModuleElementVisible*/!(node).importClause); + case SyntaxKind.ExportDeclaration: + return emitExportDeclaration(node); + case SyntaxKind.Constructor: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - return emitFunctionDeclaration(node); + return writeFunctionDeclaration(node); case SyntaxKind.ConstructSignature: case SyntaxKind.CallSignature: case SyntaxKind.IndexSignature: @@ -1475,25 +1727,11 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return emitAccessorDeclaration(node); - case SyntaxKind.VariableStatement: - return emitVariableStatement(node); case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: return emitPropertyDeclaration(node); - case SyntaxKind.InterfaceDeclaration: - return emitInterfaceDeclaration(node); - case SyntaxKind.ClassDeclaration: - return emitClassDeclaration(node); - case SyntaxKind.TypeAliasDeclaration: - return emitTypeAliasDeclaration(node); case SyntaxKind.EnumMember: return emitEnumMemberDeclaration(node); - case SyntaxKind.EnumDeclaration: - return emitEnumDeclaration(node); - case SyntaxKind.ModuleDeclaration: - return emitModuleDeclaration(node); - case SyntaxKind.ImportEqualsDeclaration: - return emitImportEqualsDeclaration(node); case SyntaxKind.ExportAssignment: return emitExportAssignment(node); case SyntaxKind.SourceFile: @@ -4160,7 +4398,10 @@ module ts { } function emitExportVariableAssignments(node: VariableDeclaration | BindingElement) { - let name = (node).name; + if (node.kind === SyntaxKind.OmittedExpression) { + return; + } + let name = node.name; if (name.kind === SyntaxKind.Identifier) { emitExportMemberAssignments(name); } @@ -6064,18 +6305,24 @@ module ts { // TODO(shkamat): Should we not write any declaration file if any of them can produce error, // or should we just not write this file like we are doing now if (!emitDeclarationResult.reportedDeclarationError) { - let declarationOutput = emitDeclarationResult.referencePathsOutput; - // apply additions + let declarationOutput = emitDeclarationResult.referencePathsOutput + + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo); + writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + } + + function getDeclarationOutput(synchronousDeclarationOutput: string, moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]) { let appliedSyncOutputPos = 0; - forEach(emitDeclarationResult.aliasDeclarationEmitInfo, aliasEmitInfo => { + let declarationOutput = ""; + // apply asynchronous additions to the synchronous output + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { if (aliasEmitInfo.asynchronousOutput) { - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); - declarationOutput += aliasEmitInfo.asynchronousOutput; + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); + declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo); appliedSyncOutputPos = aliasEmitInfo.outputPos; } }); - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); + return declarationOutput; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 87d219c2e844a..2f2d6f47f9376 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1189,9 +1189,11 @@ module ts { CannotBeNamed } + export type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; + export interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; // aliases that need to have this symbol visible + aliasesToMakeVisible?: AnyImportSyntax[]; // aliases that need to have this symbol visible errorSymbolName?: string; // Optional symbol name that results in error errorNode?: Node; // optional node that results in error } @@ -1208,9 +1210,11 @@ module ts { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; // Returns the constant value this property access resolves to, or 'undefined' for a non-constant diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 575c2bdaf36d1..611230cf118f6 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -927,9 +927,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -944,9 +945,11 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 336d70aa1a196..cd924fe677c41 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2970,6 +2970,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -2977,9 +2982,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3034,6 +3039,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3060,6 +3071,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index e7145e2407059..1ac1ec35da7ab 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -958,9 +958,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -975,9 +976,11 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index a40848b9e4c63..c993153b7b6fe 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3116,6 +3116,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3123,9 +3128,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3180,6 +3185,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3206,6 +3217,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index da8fe979d1700..5e8048680a0f8 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -959,9 +959,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -976,9 +977,11 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index b694678d4cb9a..b34bbdd936e1f 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3066,6 +3066,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3073,9 +3078,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3130,6 +3135,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3156,6 +3167,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index f380994eba888..95803d31906b4 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -996,9 +996,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } @@ -1013,9 +1014,11 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + collectLinkedAliases(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 06329de5c961f..31b762d04842c 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3239,6 +3239,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3246,9 +3251,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string @@ -3303,6 +3308,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration @@ -3329,6 +3340,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.js b/tests/baselines/reference/declarationEmitDefaultExport1.js new file mode 100644 index 0000000000000..197e4fc9cc833 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.js @@ -0,0 +1,12 @@ +//// [declarationEmitDefaultExport1.ts] +export default class C { +} + +//// [declarationEmitDefaultExport1.js] +export default class C { +} + + +//// [declarationEmitDefaultExport1.d.ts] +export default class C { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.types b/tests/baselines/reference/declarationEmitDefaultExport1.types new file mode 100644 index 0000000000000..41dd3547b6d66 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport1.ts === +export default class C { +>C : C +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.js b/tests/baselines/reference/declarationEmitDefaultExport2.js new file mode 100644 index 0000000000000..388bd41e4f885 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.js @@ -0,0 +1,12 @@ +//// [declarationEmitDefaultExport2.ts] +export default class { +} + +//// [declarationEmitDefaultExport2.js] +export default class { +} + + +//// [declarationEmitDefaultExport2.d.ts] +export default class { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.types b/tests/baselines/reference/declarationEmitDefaultExport2.types new file mode 100644 index 0000000000000..b82e6cfb92376 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport2.ts === +export default class { +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.js b/tests/baselines/reference/declarationEmitDefaultExport3.js new file mode 100644 index 0000000000000..ba412a1b4b727 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.js @@ -0,0 +1,13 @@ +//// [declarationEmitDefaultExport3.ts] +export default function foo() { + return "" +} + +//// [declarationEmitDefaultExport3.js] +export default function foo() { + return ""; +} + + +//// [declarationEmitDefaultExport3.d.ts] +export default function foo(): string; diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.types b/tests/baselines/reference/declarationEmitDefaultExport3.types new file mode 100644 index 0000000000000..0bde6eff91587 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/declarationEmitDefaultExport3.ts === +export default function foo() { +>foo : () => string + + return "" +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.js b/tests/baselines/reference/declarationEmitDefaultExport4.js new file mode 100644 index 0000000000000..92f8ef8bb8125 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.js @@ -0,0 +1,13 @@ +//// [declarationEmitDefaultExport4.ts] +export default function () { + return 1; +} + +//// [declarationEmitDefaultExport4.js] +export default function () { + return 1; +} + + +//// [declarationEmitDefaultExport4.d.ts] +export default function (): number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.types b/tests/baselines/reference/declarationEmitDefaultExport4.types new file mode 100644 index 0000000000000..8043af36b7620 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/declarationEmitDefaultExport4.ts === +export default function () { +No type information for this code. return 1; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.js b/tests/baselines/reference/declarationEmitDefaultExport5.js new file mode 100644 index 0000000000000..a8794d92c6386 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.js @@ -0,0 +1,10 @@ +//// [declarationEmitDefaultExport5.ts] +export default 1 + 2; + + +//// [declarationEmitDefaultExport5.js] +export default 1 + 2; + + +//// [declarationEmitDefaultExport5.d.ts] +export default : number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.types b/tests/baselines/reference/declarationEmitDefaultExport5.types new file mode 100644 index 0000000000000..702cc51f71ebf --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/declarationEmitDefaultExport5.ts === +export default 1 + 2; +>1 + 2 : number + diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.js b/tests/baselines/reference/declarationEmitDefaultExport6.js new file mode 100644 index 0000000000000..d328458366efb --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.js @@ -0,0 +1,15 @@ +//// [declarationEmitDefaultExport6.ts] +export class A {} +export default new A(); + + +//// [declarationEmitDefaultExport6.js] +export class A { +} +export default new A(); + + +//// [declarationEmitDefaultExport6.d.ts] +export declare class A { +} +export default : A; diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.types b/tests/baselines/reference/declarationEmitDefaultExport6.types new file mode 100644 index 0000000000000..9c839edb1a9aa --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/declarationEmitDefaultExport6.ts === +export class A {} +>A : A + +export default new A(); +>new A() : A +>A : typeof A + diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt new file mode 100644 index 0000000000000..f19766cbb0093 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS4082: Default export of the module has or is using private name 'A'. + + +==== tests/cases/compiler/declarationEmitDefaultExport7.ts (1 errors) ==== + class A {} + export default new A(); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4082: Default export of the module has or is using private name 'A'. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.js b/tests/baselines/reference/declarationEmitDefaultExport7.js new file mode 100644 index 0000000000000..99751113dd66d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.js @@ -0,0 +1,9 @@ +//// [declarationEmitDefaultExport7.ts] +class A {} +export default new A(); + + +//// [declarationEmitDefaultExport7.js] +class A { +} +export default new A(); diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js new file mode 100644 index 0000000000000..7ee32cab16c36 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js @@ -0,0 +1,44 @@ +//// [declarationEmitDestructuringArrayPattern1.ts] + +var [] = [1, "hello"]; // Dont emit anything +var [x] = [1, "hello"]; // emit x: number +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +var [, , z1] = [0, 1, 2]; // emit z1: number + +var a = [1, "hello"]; +var [x2] = a; // emit x2: number | string +var [x3, y3, z3] = a; // emit x3, y3, z3 + +//// [declarationEmitDestructuringArrayPattern1.js] +var _a = [ + 1, + "hello" +]; // Dont emit anything +var x = ([ + 1, + "hello" +])[0]; // emit x: number +var _b = [ + 1, + "hello" +], x1 = _b[0], y1 = _b[1]; // emit x1: number, y1: string +var _c = [ + 0, + 1, + 2 +], z1 = _c[2]; // emit z1: number +var a = [ + 1, + "hello" +]; +var x2 = a[0]; // emit x2: number | string +var x3 = a[0], y3 = a[1], z3 = a[2]; // emit x3, y3, z3 + + +//// [declarationEmitDestructuringArrayPattern1.d.ts] +declare var x: number; +declare var x1: number, y1: string; +declare var z1: number; +declare var a: (string | number)[]; +declare var x2: string | number; +declare var x3: string | number, y3: string | number, z3: string | number; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types new file mode 100644 index 0000000000000..9f6f4c9857d7d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts === + +var [] = [1, "hello"]; // Dont emit anything +>[1, "hello"] : (string | number)[] + +var [x] = [1, "hello"]; // emit x: number +>x : number +>[1, "hello"] : [number, string] + +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +>x1 : number +>y1 : string +>[1, "hello"] : [number, string] + +var [, , z1] = [0, 1, 2]; // emit z1: number +>z1 : number +>[0, 1, 2] : [number, number, number] + +var a = [1, "hello"]; +>a : (string | number)[] +>[1, "hello"] : (string | number)[] + +var [x2] = a; // emit x2: number | string +>x2 : string | number +>a : (string | number)[] + +var [x3, y3, z3] = a; // emit x3, y3, z3 +>x3 : string | number +>y3 : string | number +>z3 : string | number +>a : (string | number)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js new file mode 100644 index 0000000000000..5734b9bc6f9db --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js @@ -0,0 +1,69 @@ +//// [declarationEmitDestructuringArrayPattern2.ts] +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + +var [x11 = 0, y11 = ""] = [1, "hello"]; +var [a11, b11, c11] = []; + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + +var [x13, y13] = [1, "hello"]; +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; + + +//// [declarationEmitDestructuringArrayPattern2.js] +var _a = [ + 1, + [ + "hello", + [ + true + ] + ] +], x10 = _a[0], _b = _a[1], y10 = _b[0], z10 = _b[1][0]; +var _c = [ + 1, + "hello" +], _d = _c[0], x11 = _d === void 0 ? 0 : _d, _e = _c[1], y11 = _e === void 0 ? "" : _e; +var _f = [], a11 = _f[0], b11 = _f[1], c11 = _f[2]; +var _g = [ + 1, + [ + "hello", + { + x12: 5, + y12: true + } + ] +], a2 = _g[0], _h = _g[1], _j = _h === void 0 ? [ + "abc", + { + x12: 10, + y12: false + } +] : _h, b2 = _j[0], _k = _j[1], x12 = _k.x12, c2 = _k.y12; +var _l = [ + 1, + "hello" +], x13 = _l[0], y13 = _l[1]; +var _m = [ + [ + x13, + y13 + ], + { + x: x13, + y: y13 + } +], a3 = _m[0], b3 = _m[1]; + + +//// [declarationEmitDestructuringArrayPattern2.d.ts] +declare var x10: number, y10: string, z10: boolean; +declare var x11: number, y11: string; +declare var a11: any, b11: any, c11: any; +declare var a2: number, b2: string, x12: number, c2: boolean; +declare var x13: number, y13: string; +declare var a3: (string | number)[], b3: { + x: number; + y: string; +}; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types new file mode 100644 index 0000000000000..2b40a388e3ba9 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -0,0 +1,54 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; +>x10 : number +>y10 : string +>z10 : boolean +>[1, ["hello", [true]]] : [number, [string, [boolean]]] +>["hello", [true]] : [string, [boolean]] +>[true] : [boolean] + +var [x11 = 0, y11 = ""] = [1, "hello"]; +>x11 : number +>y11 : string +>[1, "hello"] : [number, string] + +var [a11, b11, c11] = []; +>a11 : any +>b11 : any +>c11 : any +>[] : undefined[] + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; +>a2 : number +>b2 : string +>x12 : number +>y12 : unknown +>c2 : boolean +>["abc", { x12: 10, y12: false }] : [string, { x12: number; y12: boolean; }] +>{ x12: 10, y12: false } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean +>[1, ["hello", { x12: 5, y12: true }]] : [number, [string, { x12: number; y12: boolean; }]] +>["hello", { x12: 5, y12: true }] : [string, { x12: number; y12: boolean; }] +>{ x12: 5, y12: true } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean + +var [x13, y13] = [1, "hello"]; +>x13 : number +>y13 : string +>[1, "hello"] : [number, string] + +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; +>a3 : (string | number)[] +>b3 : { x: number; y: string; } +>[[x13, y13], { x: x13, y: y13 }] : [(string | number)[], { x: number; y: string; }] +>[x13, y13] : (string | number)[] +>x13 : number +>y13 : string +>{ x: x13, y: y13 } : { x: number; y: string; } +>x : number +>x13 : number +>y : string +>y13 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js new file mode 100644 index 0000000000000..258fa17d7ffbe --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js @@ -0,0 +1,20 @@ +//// [declarationEmitDestructuringArrayPattern3.ts] +module M { + export var [a, b] = [1, 2]; +} + +//// [declarationEmitDestructuringArrayPattern3.js] +var M; +(function (M) { + _a = [ + 1, + 2 + ], M.a = _a[0], M.b = _a[1]; + var _a; +})(M || (M = {})); + + +//// [declarationEmitDestructuringArrayPattern3.d.ts] +declare module M { + var a: number, b: number; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types new file mode 100644 index 0000000000000..4852a7e37fb02 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts === +module M { +>M : typeof M + + export var [a, b] = [1, 2]; +>a : number +>b : number +>[1, 2] : [number, number] +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js new file mode 100644 index 0000000000000..97a8c20b73bc3 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -0,0 +1,63 @@ +//// [declarationEmitDestructuringArrayPattern4.ts] +var [...a5] = [1, 2, 3]; +var [x14, ...a6] = [1, 2, 3]; +var [x15, y15, ...a7] = [1, 2, 3]; +var [x16, y16, z16, ...a8] = [1, 2, 3]; + +var [...a9] = [1, "hello", true]; +var [x17, ...a10] = [1, "hello", true]; +var [x18, y18, ...a12] = [1, "hello", true]; +var [x19, y19, z19, ...a13] = [1, "hello", true]; + +//// [declarationEmitDestructuringArrayPattern4.js] +var _a = [ + 1, + 2, + 3 +], a5 = _a.slice(0); +var _b = [ + 1, + 2, + 3 +], x14 = _b[0], a6 = _b.slice(1); +var _c = [ + 1, + 2, + 3 +], x15 = _c[0], y15 = _c[1], a7 = _c.slice(2); +var _d = [ + 1, + 2, + 3 +], x16 = _d[0], y16 = _d[1], z16 = _d[2], a8 = _d.slice(3); +var _e = [ + 1, + "hello", + true +], a9 = _e.slice(0); +var _f = [ + 1, + "hello", + true +], x17 = _f[0], a10 = _f.slice(1); +var _g = [ + 1, + "hello", + true +], x18 = _g[0], y18 = _g[1], a12 = _g.slice(2); +var _h = [ + 1, + "hello", + true +], x19 = _h[0], y19 = _h[1], z19 = _h[2], a13 = _h.slice(3); + + +//// [declarationEmitDestructuringArrayPattern4.d.ts] +declare var a5: number[]; +declare var x14: number, a6: number[]; +declare var x15: number, y15: number, a7: number[]; +declare var x16: number, y16: number, z16: number, a8: number[]; +declare var a9: (string | number | boolean)[]; +declare var x17: string | number | boolean, a10: (string | number | boolean)[]; +declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[]; +declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types new file mode 100644 index 0000000000000..d6d0fa758d7b2 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts === +var [...a5] = [1, 2, 3]; +>a5 : number[] +>[1, 2, 3] : number[] + +var [x14, ...a6] = [1, 2, 3]; +>x14 : number +>a6 : number[] +>[1, 2, 3] : number[] + +var [x15, y15, ...a7] = [1, 2, 3]; +>x15 : number +>y15 : number +>a7 : number[] +>[1, 2, 3] : number[] + +var [x16, y16, z16, ...a8] = [1, 2, 3]; +>x16 : number +>y16 : number +>z16 : number +>a8 : number[] +>[1, 2, 3] : number[] + +var [...a9] = [1, "hello", true]; +>a9 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x17, ...a10] = [1, "hello", true]; +>x17 : string | number | boolean +>a10 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x18, y18, ...a12] = [1, "hello", true]; +>x18 : string | number | boolean +>y18 : string | number | boolean +>a12 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x19, y19, z19, ...a13] = [1, "hello", true]; +>x19 : string | number | boolean +>y19 : string | number | boolean +>z19 : string | number | boolean +>a13 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js new file mode 100644 index 0000000000000..de3045be1ccc5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js @@ -0,0 +1,97 @@ +//// [declarationEmitDestructuringObjectLiteralPattern.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern.js] +var _a = { + x: 5, + y: "hello" +}; +var x4 = ({ + x4: 5, + y4: "hello" +}).x4; +var y5 = ({ + x5: 5, + y5: "hello" +}).y5; +var _b = { + x6: 5, + y6: "hello" +}, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ + x7: 5, + y7: "hello" +}).x7; +var b1 = ({ + x8: 5, + y8: "hello" +}).y8; +var _c = { + x9: 5, + y9: "hello" +}, a2 = _c.x9, b2 = _c.y9; +var _d = { + a: 1, + b: { + a: "hello", + b: { + a: true + } + } +}, x11 = _d.a, _e = _d.b, y11 = _e.a, z11 = _e.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { + a4: a4, + b4: b4, + c4: c4 + }; +} +var _f = f15(), a4 = _f.a4, b4 = _f.b4, c4 = _f.c4; +var m; +(function (m) { + _g = f15(), m.a4 = _g.a4, m.b4 = _g.b4, m.c4 = _g.c4; + var _g; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types new file mode 100644 index 0000000000000..b3c422e495842 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types @@ -0,0 +1,102 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js new file mode 100644 index 0000000000000..889047185e7e0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js @@ -0,0 +1,48 @@ +//// [declarationEmitDestructuringObjectLiteralPattern1.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +//// [declarationEmitDestructuringObjectLiteralPattern1.js] +var _a = { + x: 5, + y: "hello" +}; +var x4 = ({ + x4: 5, + y4: "hello" +}).x4; +var y5 = ({ + x5: 5, + y5: "hello" +}).y5; +var _b = { + x6: 5, + y6: "hello" +}, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ + x7: 5, + y7: "hello" +}).x7; +var b1 = ({ + x8: 5, + y8: "hello" +}).y8; +var _c = { + x9: 5, + y9: "hello" +}, a2 = _c.x9, b2 = _c.y9; + + +//// [declarationEmitDestructuringObjectLiteralPattern1.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types new file mode 100644 index 0000000000000..cc2094c68f4d6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js new file mode 100644 index 0000000000000..509edfa6c87f1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js @@ -0,0 +1,55 @@ +//// [declarationEmitDestructuringObjectLiteralPattern2.ts] + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern2.js] +var _a = { + a: 1, + b: { + a: "hello", + b: { + a: true + } + } +}, x11 = _a.a, _b = _a.b, y11 = _b.a, z11 = _b.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { + a4: a4, + b4: b4, + c4: c4 + }; +} +var _c = f15(), a4 = _c.a4, b4 = _c.b4, c4 = _c.c4; +var m; +(function (m) { + _d = f15(), m.a4 = _d.a4, m.b4 = _d.b4, m.c4 = _d.c4; + var _d; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern2.d.ts] +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types new file mode 100644 index 0000000000000..68394686e31a0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts === + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js new file mode 100644 index 0000000000000..c907add11f776 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -0,0 +1,33 @@ +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.ts] + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +function foo2(...rest: any[]) { + +} + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.js] +function foo() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} +function foo2() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} + + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts] +declare function foo(_0?: [string, number, boolean]): any; +declare function foo2(_0?: { + x: string; + y: number; + z: boolean; +}): any; diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types new file mode 100644 index 0000000000000..1c75466f0c37c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts === + +function foo([x, y, z] ?: [string, number, boolean]); +>foo : ([x, y, z]?: [string, number, boolean]) => any +>x : string +>y : number +>z : boolean + +function foo(...rest: any[]) { +>foo : ([x, y, z]?: [string, number, boolean]) => any +>rest : any[] +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>x : string +>y : number +>z : boolean +>x : string +>y : number +>z : boolean + +function foo2(...rest: any[]) { +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>rest : any[] + +} diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt new file mode 100644 index 0000000000000..83785e86f6585 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern. + + +==== tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts (3 errors) ==== + class C1 { + constructor(public [x, y, z]: string[]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type TupleType1 =[string, number, boolean]; + class C2 { + constructor(public [x, y, z]: TupleType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type ObjType1 = { x: number; y: string; z: boolean } + class C3 { + constructor(public { x, y, z }: ObjType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js new file mode 100644 index 0000000000000..cfe4acc1733d0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js @@ -0,0 +1,61 @@ +//// [declarationEmitDestructuringParameterProperties.ts] +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 =[string, number, boolean]; +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +//// [declarationEmitDestructuringParameterProperties.js] +var C1 = (function () { + function C1(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C1; +})(); +var C2 = (function () { + function C2(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C2; +})(); +var C3 = (function () { + function C3(_a) { + var x = _a.x, y = _a.y, z = _a.z; + this.{ x, y, z } = { x, y, z }; + } + return C3; +})(); + + +//// [declarationEmitDestructuringParameterProperties.d.ts] +declare class C1 { + x: string, y: string, z: string; + constructor(_0: string[]); +} +declare type TupleType1 = [string, number, boolean]; +declare class C2 { + x: string, y: number, z: boolean; + constructor(_0: TupleType1); +} +declare type ObjType1 = { + x: number; + y: string; + z: boolean; +}; +declare class C3 { + x: number, y: string, z: boolean; + constructor(_0: ObjType1); +} diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt new file mode 100644 index 0000000000000..e464b96a8bf77 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts(4,20): error TS4025: Exported variable 'y' has or is using private name 'c'. + + +==== tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts (1 errors) ==== + module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; + ~ +!!! error TS4025: Exported variable 'y' has or is using private name 'c'. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js new file mode 100644 index 0000000000000..c076dca665add --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuringPrivacyError.ts] +module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; +} + +//// [declarationEmitDestructuringPrivacyError.js] +var m; +(function (m) { + var c = (function () { + function c() { + } + return c; + })(); + _a = [ + 10, + new c(), + 30 + ], m.x = _a[0], m.y = _a[1], m.z = _a[2]; + var _a; +})(m || (m = {})); diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt new file mode 100644 index 0000000000000..7b8a70ae8f16c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(1,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(3,16): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + +==== tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts (2 errors) ==== + function foo([x,y,z]?: [string, number, boolean]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } + function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js new file mode 100644 index 0000000000000..284cf107782f0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuringWithOptionalBindingParameters.ts] +function foo([x,y,z]?: [string, number, boolean]) { +} +function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { +} + +//// [declarationEmitDestructuringWithOptionalBindingParameters.js] +function foo(_a) { + var x = _a[0], y = _a[1], z = _a[2]; +} +function foo1(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} + + +//// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts] +declare function foo(_0?: [string, number, boolean]): void; +declare function foo1(_0?: { + x: string; + y: number; + z: boolean; +}): void; diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js new file mode 100644 index 0000000000000..b41ca177b0558 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js @@ -0,0 +1,39 @@ +//// [declarationEmitImportInExportAssignmentModule.ts] + +module m { + export module c { + export class c { + } + } + import x = c; + export var a: typeof x; +} +export = m; + +//// [declarationEmitImportInExportAssignmentModule.js] +var m; +(function (m) { + var c; + (function (_c) { + var c = (function () { + function c() { + } + return c; + })(); + _c.c = c; + })(c = m.c || (m.c = {})); + m.a; +})(m || (m = {})); +module.exports = m; + + +//// [declarationEmitImportInExportAssignmentModule.d.ts] +declare module m { + module c { + class c { + } + } + import x = c; + var a: typeof x; +} +export = m; diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types new file mode 100644 index 0000000000000..23176a0abe2e1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts === + +module m { +>m : typeof m + + export module c { +>c : typeof x + + export class c { +>c : c + } + } + import x = c; +>x : typeof x +>c : typeof x + + export var a: typeof x; +>a : typeof x +>x : typeof x +} +export = m; +>m : typeof m + diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js index 3ac92c5d9eaa5..0a7ad4520c1d8 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -17,6 +17,6 @@ module.exports = C; //// [es5ExportDefaultClassDeclaration.d.ts] -export declare class C { +export default class C { method(): void; } diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js index 8c07ff12599cc..3e4e4d9eed692 100644 --- a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -17,36 +17,6 @@ module.exports = _default; //// [es5ExportDefaultClassDeclaration2.d.ts] -export declare class { +export default class { method(): void; } - - -//// [DtsFileErrors] - - -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,1): error TS1128: Declaration or statement expected. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,8): error TS2304: Cannot find name 'declare'. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,16): error TS1005: ';' expected. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,5): error TS2304: Cannot find name 'method'. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,13): error TS1005: ';' expected. -tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,19): error TS1109: Expression expected. - - -==== tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts (6 errors) ==== - export declare class { - ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~~~~~~~ -!!! error TS2304: Cannot find name 'declare'. - ~~~~~ -!!! error TS1005: ';' expected. - method(): void; - ~~~~~~ -!!! error TS2304: Cannot find name 'method'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1109: Expression expected. - } - \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js index f0c3da6657bdd..43f8257899913 100644 --- a/tests/baselines/reference/es5ExportDefaultExpression.js +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -8,4 +8,4 @@ module.exports = (1 + 2); //// [es5ExportDefaultExpression.d.ts] -export default (1 + 2); +export default : number; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js index 015767435817d..a23eb361fd404 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -10,4 +10,4 @@ module.exports = f; //// [es5ExportDefaultFunctionDeclaration.d.ts] -export declare function f(): void; +export default function f(): void; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js index 6a99726655ff6..dedb36b7e643f 100644 --- a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -10,17 +10,4 @@ module.exports = _default; //// [es5ExportDefaultFunctionDeclaration2.d.ts] -export declare function (): void; - - -//// [DtsFileErrors] - - -tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.d.ts(1,25): error TS1003: Identifier expected. - - -==== tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.d.ts (1 errors) ==== - export declare function (): void; - ~ -!!! error TS1003: Identifier expected. - \ No newline at end of file +export default function (): void; diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js index 4c223545e8a28..05c8a794e9127 100644 --- a/tests/baselines/reference/es6ExportAll.js +++ b/tests/baselines/reference/es6ExportAll.js @@ -41,3 +41,4 @@ export declare var x: number; export declare module uninstantiated { } //// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js index 9fd8c1c4b33e7..dd83c31b72a7f 100644 --- a/tests/baselines/reference/es6ExportAllInEs5.js +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -45,3 +45,4 @@ export declare var x: number; export declare module uninstantiated { } //// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportClause.js b/tests/baselines/reference/es6ExportClause.js index 9fd7a71554d5b..4fba47ea7d1d0 100644 --- a/tests/baselines/reference/es6ExportClause.js +++ b/tests/baselines/reference/es6ExportClause.js @@ -32,3 +32,18 @@ export { x }; //// [es6ExportClause.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClauseInEs5.js b/tests/baselines/reference/es6ExportClauseInEs5.js new file mode 100644 index 0000000000000..93c1015d20785 --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.js @@ -0,0 +1,57 @@ +//// [es6ExportClauseInEs5.ts] + +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + +//// [es6ExportClauseInEs5.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +exports.c2 = c; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +exports.instantiatedModule = m; +var x = 10; +exports.x = x; +exports.c = c; +exports.c2 = c; +exports.i = i; +exports.instantiatedModule = m; +exports.uninstantiated = uninstantiated; +exports.x = x; + + +//// [es6ExportClauseInEs5.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClauseInEs5.types b/tests/baselines/reference/es6ExportClauseInEs5.types new file mode 100644 index 0000000000000..8caedfa5ceb9e --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/es6ExportClauseInEs5.ts === + +class c { +>c : c +} +interface i { +>i : i +} +module m { +>m : typeof m + + export var x = 10; +>x : number +} +var x = 10; +>x : number + +module uninstantiated { +>uninstantiated : unknown +} +export { c }; +>c : typeof c + +export { c as c2 }; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule }; +>i : unknown +>m : typeof m +>instantiatedModule : typeof m + +export { uninstantiated }; +>uninstantiated : unknown + +export { x }; +>x : number + diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js index 29cdc655397c4..7952bdb0bcc4b 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -49,3 +49,8 @@ export declare var x: number; export declare module uninstantiated { } //// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js new file mode 100644 index 0000000000000..3e412c13a329a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var _server = require("server"); +exports.c = _server.c; +var _server_1 = require("server"); +exports.c2 = _server_1.c; +var _server_2 = require("server"); +exports.i = _server_2.i; +exports.instantiatedModule = _server_2.m; +var _server_3 = require("server"); +exports.uninstantiated = _server_3.uninstantiated; +var _server_4 = require("server"); +exports.x = _server_4.x; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types new file mode 100644 index 0000000000000..c0087dccd943a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export { c } from "server"; +>c : typeof c + +export { c as c2 } from "server"; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule } from "server"; +>i : unknown +>m : typeof instantiatedModule +>instantiatedModule : typeof instantiatedModule + +export { uninstantiated } from "server"; +>uninstantiated : unknown + +export { x } from "server"; +>x : number + diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js index f2682f0a18866..2a25b5ac34974 100644 --- a/tests/baselines/reference/es6ExportDefaultClassDeclaration.js +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js @@ -13,6 +13,6 @@ export default class C { //// [es6ExportDefaultClassDeclaration.d.ts] -export declare class C { +export default class C { method(): void; } diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js index a975d4322f53a..045de615c8666 100644 --- a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js @@ -13,36 +13,6 @@ export default class { //// [es6ExportDefaultClassDeclaration2.d.ts] -export declare class { +export default class { method(): void; } - - -//// [DtsFileErrors] - - -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,1): error TS1128: Declaration or statement expected. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,8): error TS2304: Cannot find name 'declare'. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,16): error TS1005: ';' expected. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,5): error TS2304: Cannot find name 'method'. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,13): error TS1005: ';' expected. -tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,19): error TS1109: Expression expected. - - -==== tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts (6 errors) ==== - export declare class { - ~~~~~~ -!!! error TS1128: Declaration or statement expected. - ~~~~~~~ -!!! error TS2304: Cannot find name 'declare'. - ~~~~~ -!!! error TS1005: ';' expected. - method(): void; - ~~~~~~ -!!! error TS2304: Cannot find name 'method'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1109: Expression expected. - } - \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportDefaultExpression.js b/tests/baselines/reference/es6ExportDefaultExpression.js index e0d910437662d..322e09bc46fe3 100644 --- a/tests/baselines/reference/es6ExportDefaultExpression.js +++ b/tests/baselines/reference/es6ExportDefaultExpression.js @@ -8,4 +8,4 @@ export default (1 + 2); //// [es6ExportDefaultExpression.d.ts] -export default (1 + 2); +export default : number; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js index fafc5a114f5a2..ec5789203d0ae 100644 --- a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js @@ -9,4 +9,4 @@ export default function f() { //// [es6ExportDefaultFunctionDeclaration.d.ts] -export declare function f(): void; +export default function f(): void; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js index 2071e56c539b1..80e37f18d21b6 100644 --- a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js @@ -9,17 +9,4 @@ export default function () { //// [es6ExportDefaultFunctionDeclaration2.d.ts] -export declare function (): void; - - -//// [DtsFileErrors] - - -tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.d.ts(1,25): error TS1003: Identifier expected. - - -==== tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.d.ts (1 errors) ==== - export declare function (): void; - ~ -!!! error TS1003: Identifier expected. - \ No newline at end of file +export default function (): void; diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt index c07a84bb810d9..9ff3c1b3f0430 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt @@ -1,12 +1,15 @@ -tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBinding_0.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (0 errors) ==== +==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (1 errors) ==== - export var a = 10; + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== +==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (0 errors) ==== import defaultBinding from "es6ImportDefaultBinding_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. + var x = defaultBinding; + import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index c7a320b76aabb..b169f9e80e4c7 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -2,17 +2,24 @@ //// [es6ImportDefaultBinding_0.ts] -export var a = 10; +var a = 10; +export = a; //// [es6ImportDefaultBinding_1.ts] import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used //// [es6ImportDefaultBinding_0.js] -export var a = 10; +var a = 10; +export default a; //// [es6ImportDefaultBinding_1.js] +import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; //// [es6ImportDefaultBinding_0.d.ts] -export declare var a: number; +declare var a: number; +export = a; //// [es6ImportDefaultBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt deleted file mode 100644 index fc1e1a1925c63..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. - - -==== tests/cases/compiler/server.ts (0 errors) ==== - - class c { } - export = c; - -==== tests/cases/compiler/client.ts (1 errors) ==== - import defaultBinding from "server"; - export var x = new defaultBinding(); - ~ -!!! error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. - import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used - \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js index ad58abd8125a8..4e9719892db40 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -27,3 +27,6 @@ exports.x = new defaultBinding(); declare class c { } export = c; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.types b/tests/baselines/reference/es6ImportDefaultBindingDts.types new file mode 100644 index 0000000000000..62f54168c3631 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/server.ts === + +class c { } +>c : c + +export = c; +>c : c + +=== tests/cases/compiler/client.ts === +import defaultBinding from "server"; +>defaultBinding : typeof defaultBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index c755b8207e7d8..5e71478e5a11a 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,52 +1,42 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(9,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(11,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== export var a = 10; export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. + var x1: number = m; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index d7196f86eaa7e..7d0d4b2582da5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -7,12 +7,18 @@ export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = m; //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] @@ -20,6 +26,17 @@ export var a = 10; export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] +import { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = a; +import { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = b; +import { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = x; +var x1 = y; +import { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = z; +import { m } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1 = m; //// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt new file mode 100644 index 0000000000000..9783ad4921e10 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + var x: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + var x: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + var x: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js new file mode 100644 index 0000000000000..2690e7a7f5166 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.js] +var defaultBinding1 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding1; +var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding2; +var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding3; +var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding4; +var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding5; +var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt new file mode 100644 index 0000000000000..9b246f803a0c6 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt @@ -0,0 +1,57 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(5,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(7,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,37): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x1: number = defaultBinding1; + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding2; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding3; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding4; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x1: number = defaultBinding5; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js new file mode 100644 index 0000000000000..0239b68194fba --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export var x1: number = defaultBinding1; +export import defaultBinding2, { a } from "server"; +export var x1: number = defaultBinding2; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = defaultBinding3; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = defaultBinding4; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = defaultBinding5; +export import defaultBinding6, { m, } from "server"; +export var x1: number = defaultBinding6; + + +//// [server.js] +var a = 10; +module.exports = a; +//// [client.js] +var defaultBinding1 = require("server"); +exports.x1 = defaultBinding1; +var defaultBinding2 = require("server"); +exports.x1 = defaultBinding2; +var defaultBinding3 = require("server"); +exports.x1 = defaultBinding3; +var defaultBinding4 = require("server"); +exports.x1 = defaultBinding4; +var defaultBinding5 = require("server"); +exports.x1 = defaultBinding5; +var defaultBinding6 = require("server"); +exports.x1 = defaultBinding6; + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt index 91d51d5f7ef64..bff47ba36ef82 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt @@ -1,15 +1,9 @@ tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. tests/cases/compiler/client.ts(2,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(3,12): error TS4025: Exported variable 'x1' has or is using private name 'a'. tests/cases/compiler/client.ts(4,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(5,12): error TS4025: Exported variable 'x2' has or is using private name 'b'. tests/cases/compiler/client.ts(6,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(7,12): error TS4025: Exported variable 'x4' has or is using private name 'x'. -tests/cases/compiler/client.ts(8,12): error TS4025: Exported variable 'x5' has or is using private name 'y'. tests/cases/compiler/client.ts(9,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(10,12): error TS4025: Exported variable 'x3' has or is using private name 'z'. tests/cases/compiler/client.ts(11,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(12,12): error TS4025: Exported variable 'x6' has or is using private name 'm'. ==== tests/cases/compiler/server.ts (0 errors) ==== @@ -21,7 +15,7 @@ tests/cases/compiler/client.ts(12,12): error TS4025: Exported variable 'x6' has export class a12 { } export class x11 { } -==== tests/cases/compiler/client.ts (12 errors) ==== +==== tests/cases/compiler/client.ts (6 errors) ==== import defaultBinding1, { } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. @@ -29,33 +23,21 @@ tests/cases/compiler/client.ts(12,12): error TS4025: Exported variable 'x6' has ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x1 = new a(); - ~~ -!!! error TS4025: Exported variable 'x1' has or is using private name 'a'. import defaultBinding3, { a11 as b } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x2 = new b(); - ~~ -!!! error TS4025: Exported variable 'x2' has or is using private name 'b'. import defaultBinding4, { x, a12 as y } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x4 = new x(); - ~~ -!!! error TS4025: Exported variable 'x4' has or is using private name 'x'. export var x5 = new y(); - ~~ -!!! error TS4025: Exported variable 'x5' has or is using private name 'y'. import defaultBinding5, { x11 as z, } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x3 = new z(); - ~~ -!!! error TS4025: Exported variable 'x3' has or is using private name 'z'. import defaultBinding6, { m, } from "server"; ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. export var x6 = new m(); - ~~ -!!! error TS4025: Exported variable 'x6' has or is using private name 'm'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js index a6b2c9a16701a..6c85e281150de 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -88,3 +88,15 @@ export declare class a12 { } export declare class x11 { } +//// [client.d.ts] +import { a } from "server"; +export declare var x1: a; +import { a11 as b } from "server"; +export declare var x2: b; +import { x, a12 as y } from "server"; +export declare var x4: x; +export declare var x5: y; +import { x11 as z } from "server"; +export declare var x3: z; +import { m } from "server"; +export declare var x6: m; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt new file mode 100644 index 0000000000000..405fab0de509e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/client.ts(3,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,30): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + class a { } + export = a; + +==== tests/cases/compiler/client.ts (6 errors) ==== + import defaultBinding1, { } from "server"; + export var x1 = new defaultBinding1(); + import defaultBinding2, { a } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x2 = new defaultBinding2(); + import defaultBinding3, { a as b } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x3 = new defaultBinding3(); + import defaultBinding4, { x, a as y } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x4 = new defaultBinding4(); + import defaultBinding5, { x as z, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x5 = new defaultBinding5(); + import defaultBinding6, { m, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x6 = new defaultBinding6(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js new file mode 100644 index 0000000000000..21ddcbc71d6c2 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts] //// + +//// [server.ts] + +class a { } +export = a; + +//// [client.ts] +import defaultBinding1, { } from "server"; +export var x1 = new defaultBinding1(); +import defaultBinding2, { a } from "server"; +export var x2 = new defaultBinding2(); +import defaultBinding3, { a as b } from "server"; +export var x3 = new defaultBinding3(); +import defaultBinding4, { x, a as y } from "server"; +export var x4 = new defaultBinding4(); +import defaultBinding5, { x as z, } from "server"; +export var x5 = new defaultBinding5(); +import defaultBinding6, { m, } from "server"; +export var x6 = new defaultBinding6(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +module.exports = a; +//// [client.js] +var defaultBinding1 = require("server"); +exports.x1 = new defaultBinding1(); +var defaultBinding2 = require("server"); +exports.x2 = new defaultBinding2(); +var defaultBinding3 = require("server"); +exports.x3 = new defaultBinding3(); +var defaultBinding4 = require("server"); +exports.x4 = new defaultBinding4(); +var defaultBinding5 = require("server"); +exports.x5 = new defaultBinding5(); +var defaultBinding6 = require("server"); +exports.x6 = new defaultBinding6(); + + +//// [server.d.ts] +declare class a { +} +export = a; +//// [client.d.ts] +import defaultBinding1 from "server"; +export declare var x1: defaultBinding1; +export declare var x2: defaultBinding1; +export declare var x3: defaultBinding1; +export declare var x4: defaultBinding1; +export declare var x5: defaultBinding1; +export declare var x6: defaultBinding1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt index 157360f52382d..0377e543973f9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt @@ -1,15 +1,9 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(9,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(11,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts (0 errors) ==== @@ -18,34 +12,29 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6, export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file + var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js index 4cf3046532a0a..1c63005bb0680 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js @@ -7,15 +7,40 @@ export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = m; + //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.js] +var _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_1 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_1.a; +var _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_2 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_2.a; +var _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.x; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.a; +var _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_4 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_4.x; +var _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_5 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_5.m; + + +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..a9a2ed4974d44 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt @@ -0,0 +1,58 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(2,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(4,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(6,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = a; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = b; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = x; + export var x1: number = y; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = z; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js new file mode 100644 index 0000000000000..5497a82b04151 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -0,0 +1,51 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export import defaultBinding2, { a } from "server"; +export var x1: number = a; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = b; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = x; +export var x1: number = y; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = z; +export import defaultBinding6, { m, } from "server"; +export var x1: number = m; + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; +}); +//// [client.js] +define(["require", "exports", "server", "server", "server", "server", "server"], function (require, exports, _server_1, _server_2, _server_3, _server_4, _server_5) { + exports.x1 = _server_1.a; + exports.x1 = _server_2.a; + exports.x1 = _server_3.x; + exports.x1 = _server_3.a; + exports.x1 = _server_4.x; + exports.x1 = _server_5.m; +}); + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt new file mode 100644 index 0000000000000..5df6817e897a9 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js new file mode 100644 index 0000000000000..d1dd565c81b48 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = defaultBinding; + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = defaultBinding; +}); + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt index b82fb1155e94b..f8dd391fe0ebf 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt @@ -1,15 +1,12 @@ tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. -tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'nameSpaceBinding.a'. ==== tests/cases/compiler/server.ts (0 errors) ==== export class a { } -==== tests/cases/compiler/client.ts (2 errors) ==== +==== tests/cases/compiler/client.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "server"; ~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. - export var x = new nameSpaceBinding.a(); - ~ -!!! error TS4025: Exported variable 'x' has or is using private name 'nameSpaceBinding.a'. \ No newline at end of file + export var x = new nameSpaceBinding.a(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js index 3068fb6d39dc7..4bde6e25b10c1 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js @@ -23,3 +23,6 @@ exports.x = new nameSpaceBinding.a(); //// [server.d.ts] export declare class a { } +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt deleted file mode 100644 index 3b09108bbfc3a..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. - - -==== tests/cases/compiler/server.ts (0 errors) ==== - - class a { } - export = a; - -==== tests/cases/compiler/client.ts (1 errors) ==== - import defaultBinding, * as nameSpaceBinding from "server"; - export var x = new defaultBinding(); - ~ -!!! error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js index 708cffca29d1d..69b76d79fbbd5 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -28,3 +28,6 @@ define(["require", "exports", "server"], function (require, exports, defaultBind declare class a { } export = a; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types new file mode 100644 index 0000000000000..e40d3893ee216 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/server.ts === + +class a { } +>a : a + +export = a; +>a : a + +=== tests/cases/compiler/client.ts === +import defaultBinding, * as nameSpaceBinding from "server"; +>defaultBinding : typeof defaultBinding +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt index f1d20dccc59e3..d4d51e4d5abf4 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js index abd4736fca706..9131fcc75db80 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js @@ -5,8 +5,16 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var nameSpaceBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt new file mode 100644 index 0000000000000..3e06e7acae870 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js new file mode 100644 index 0000000000000..b219b5e7876d4 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = nameSpaceBinding.a; + +//// [server.js] +exports.a = 10; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = nameSpaceBinding.a; + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt deleted file mode 100644 index 5d656094a8c72..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. - - -==== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts (0 errors) ==== - - export var a = 10; - -==== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts (1 errors) ==== - import defaultBinding from "es6ImportDefaultBindingInEs5_0"; - ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js index b6d293225fd0b..0b703f829ca31 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js @@ -2,11 +2,19 @@ //// [es6ImportDefaultBindingInEs5_0.ts] -export var a = 10; +var a = 10; +export = a; //// [es6ImportDefaultBindingInEs5_1.ts] import defaultBinding from "es6ImportDefaultBindingInEs5_0"; //// [es6ImportDefaultBindingInEs5_0.js] -exports.a = 10; +var a = 10; +module.exports = a; //// [es6ImportDefaultBindingInEs5_1.js] + + +//// [es6ImportDefaultBindingInEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types new file mode 100644 index 0000000000000..03243fc014d86 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts === +import defaultBinding from "es6ImportDefaultBindingInEs5_0"; +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt new file mode 100644 index 0000000000000..e0dfdc00e07a0 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x = defaultBinding; + export import defaultBinding2 from "server"; // non referenced + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js new file mode 100644 index 0000000000000..a3f8dd11c6c51 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingWithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding from "server"; +export var x = defaultBinding; +export import defaultBinding2 from "server"; // non referenced + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = defaultBinding; +}); + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt new file mode 100644 index 0000000000000..635bb955c00f6 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt @@ -0,0 +1,13 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNameSpaceImport_1.ts (0 errors) ==== + import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; + var x = nameSpaceBinding.a; + import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index 4f03e9a0ae29d..653feeb22b7c5 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -6,11 +6,15 @@ export var a = 10; //// [es6ImportNameSpaceImport_1.ts] import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this //// [es6ImportNameSpaceImport_0.js] export var a = 10; //// [es6ImportNameSpaceImport_1.js] +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; //// [es6ImportNameSpaceImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.types b/tests/baselines/reference/es6ImportNameSpaceImport.types deleted file mode 100644 index 1e09de42ec6a2..0000000000000 --- a/tests/baselines/reference/es6ImportNameSpaceImport.types +++ /dev/null @@ -1,9 +0,0 @@ -=== tests/cases/compiler/es6ImportNameSpaceImport_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportNameSpaceImport_1.ts === -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; ->nameSpaceBinding : typeof nameSpaceBinding - diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.js b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js new file mode 100644 index 0000000000000..e7d0eae9ca96b --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportAmd.ts] //// + +//// [es6ImportNameSpaceImportAmd_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportAmd_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this + + +//// [es6ImportNameSpaceImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportNameSpaceImportAmd_1.js] +define(["require", "exports", "es6ImportNameSpaceImportAmd_0"], function (require, exports, nameSpaceBinding) { + var x = nameSpaceBinding.a; +}); + + +//// [es6ImportNameSpaceImportAmd_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.types b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types new file mode 100644 index 0000000000000..623a7e8e160df --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +>nameSpaceBinding : typeof nameSpaceBinding + +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.js b/tests/baselines/reference/es6ImportNameSpaceImportDts.js new file mode 100644 index 0000000000000..91e927428a166 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportDts.ts] //// + +//// [server.ts] + +export class c { }; + +//// [client.ts] +import * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.c(); +import * as nameSpaceBinding2 from "server"; // unreferenced + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = new nameSpaceBinding.c(); + + +//// [server.d.ts] +export declare class c { +} +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.c; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.types b/tests/baselines/reference/es6ImportNameSpaceImportDts.types new file mode 100644 index 0000000000000..345d593b1437b --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/server.ts === + +export class c { }; +>c : c + +=== tests/cases/compiler/client.ts === +import * as nameSpaceBinding from "server"; +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new nameSpaceBinding.c(); +>x : nameSpaceBinding.c +>new nameSpaceBinding.c() : nameSpaceBinding.c +>nameSpaceBinding.c : typeof nameSpaceBinding.c +>nameSpaceBinding : typeof nameSpaceBinding +>c : typeof nameSpaceBinding.c + +import * as nameSpaceBinding2 from "server"; // unreferenced +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js index 2c7785dec6ed5..50a03972cc225 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js @@ -5,8 +5,18 @@ export var a = 10; //// [es6ImportNameSpaceImportInEs5_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this + //// [es6ImportNameSpaceImportInEs5_0.js] exports.a = 10; //// [es6ImportNameSpaceImportInEs5_1.js] +var nameSpaceBinding = require("es6ImportNameSpaceImportInEs5_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportNameSpaceImportInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types index cb7b669eea1c0..6ba725f2494ce 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types @@ -7,3 +7,12 @@ export var a = 10; import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; >nameSpaceBinding : typeof nameSpaceBinding +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt new file mode 100644 index 0000000000000..901556e73bd73 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var x = nameSpaceBinding.a; + export import * as nameSpaceBinding2 from "server"; // Not referenced imports + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js new file mode 100644 index 0000000000000..84f6936d4b0f1 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import * as nameSpaceBinding from "server"; +export var x = nameSpaceBinding.a; +export import * as nameSpaceBinding2 from "server"; // Not referenced imports + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, nameSpaceBinding) { + exports.x = nameSpaceBinding.a; +}); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportNamedImport.errors.txt b/tests/baselines/reference/es6ImportNamedImport.errors.txt new file mode 100644 index 0000000000000..5723b5c20d4f8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImport.errors.txt @@ -0,0 +1,44 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export var a1 = 10; + export var x1 = 10; + export var z1 = 10; + export var z2 = 10; + export var aaaa = 10; + +==== tests/cases/compiler/es6ImportNamedImport_1.ts (0 errors) ==== + import { } from "es6ImportNamedImport_0"; + import { a } from "es6ImportNamedImport_0"; + var xxxx = a; + import { a as b } from "es6ImportNamedImport_0"; + var xxxx = b; + import { x, a as y } from "es6ImportNamedImport_0"; + var xxxx = x; + var xxxx = y; + import { x as z, } from "es6ImportNamedImport_0"; + var xxxx = z; + import { m, } from "es6ImportNamedImport_0"; + var xxxx = m; + import { a1, x1 } from "es6ImportNamedImport_0"; + var xxxx = a1; + var xxxx = x1; + import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; + var xxxx = a11; + var xxxx = x11; + import { z1 } from "es6ImportNamedImport_0"; + var z111 = z1; + import { z2 as z3 } from "es6ImportNamedImport_0"; + var z2 = z3; // z2 shouldn't give redeclare error + + // These are elided + import { aaaa } from "es6ImportNamedImport_0"; + // These are elided + import { aaaa as bbbb } from "es6ImportNamedImport_0"; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index 7993af7fb079f..9606c59351b52 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -7,16 +7,38 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImport_1.ts] import { } from "es6ImportNamedImport_0"; import { a } from "es6ImportNamedImport_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImport_0"; +var xxxx = z; import { m, } from "es6ImportNamedImport_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImport_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImport_0"; //// [es6ImportNamedImport_0.js] @@ -25,7 +47,31 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImport_1.js] +import { a } from "es6ImportNamedImport_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; +import { x as z } from "es6ImportNamedImport_0"; +var xxxx = z; +import { m } from "es6ImportNamedImport_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error //// [es6ImportNamedImport_0.d.ts] @@ -34,4 +80,7 @@ export declare var x: number; export declare var m: number; export declare var a1: number; export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; //// [es6ImportNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types deleted file mode 100644 index cb06c9918eab0..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImport.types +++ /dev/null @@ -1,50 +0,0 @@ -=== tests/cases/compiler/es6ImportNamedImport_0.ts === - -export var a = 10; ->a : number - -export var x = a; ->x : number ->a : number - -export var m = a; ->m : number ->a : number - -export var a1 = 10; ->a1 : number - -export var x1 = 10; ->x1 : number - -=== tests/cases/compiler/es6ImportNamedImport_1.ts === -import { } from "es6ImportNamedImport_0"; -import { a } from "es6ImportNamedImport_0"; ->a : number - -import { a as b } from "es6ImportNamedImport_0"; ->a : number ->b : number - -import { x, a as y } from "es6ImportNamedImport_0"; ->x : number ->a : number ->y : number - -import { x as z, } from "es6ImportNamedImport_0"; ->x : number ->z : number - -import { m, } from "es6ImportNamedImport_0"; ->m : number - -import { a1, x1 } from "es6ImportNamedImport_0"; ->a1 : number ->x1 : number - -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; ->a1 : number ->a11 : number ->x1 : number ->x11 : number - diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.js b/tests/baselines/reference/es6ImportNamedImportAmd.js new file mode 100644 index 0000000000000..5e3ddc433083a --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.js @@ -0,0 +1,81 @@ +//// [tests/cases/compiler/es6ImportNamedImportAmd.ts] //// + +//// [es6ImportNamedImportAmd_0.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [es6ImportNamedImportAmd_1.ts] +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImportAmd_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImportAmd_0"; +var xxxx = x; +var xxxx = y; +import { x as z, } from "es6ImportNamedImportAmd_0"; +var xxxx = z; +import { m, } from "es6ImportNamedImportAmd_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportAmd_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; + + +//// [es6ImportNamedImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; + exports.a1 = 10; + exports.x1 = 10; + exports.z1 = 10; + exports.z2 = 10; + exports.aaaa = 10; +}); +//// [es6ImportNamedImportAmd_1.js] +define(["require", "exports", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0"], function (require, exports, _es6ImportNamedImportAmd_0_1, _es6ImportNamedImportAmd_0_2, _es6ImportNamedImportAmd_0_3, _es6ImportNamedImportAmd_0_4, _es6ImportNamedImportAmd_0_5, _es6ImportNamedImportAmd_0_6, _es6ImportNamedImportAmd_0_7, _es6ImportNamedImportAmd_0_8, _es6ImportNamedImportAmd_0_9) { + var xxxx = _es6ImportNamedImportAmd_0_1.a; + var xxxx = _es6ImportNamedImportAmd_0_2.a; + var xxxx = _es6ImportNamedImportAmd_0_3.x; + var xxxx = _es6ImportNamedImportAmd_0_3.a; + var xxxx = _es6ImportNamedImportAmd_0_4.x; + var xxxx = _es6ImportNamedImportAmd_0_5.m; + var xxxx = _es6ImportNamedImportAmd_0_6.a1; + var xxxx = _es6ImportNamedImportAmd_0_6.x1; + var xxxx = _es6ImportNamedImportAmd_0_7.a1; + var xxxx = _es6ImportNamedImportAmd_0_7.x1; + var z111 = _es6ImportNamedImportAmd_0_8.z1; + var z2 = _es6ImportNamedImportAmd_0_9.z2; // z2 shouldn't give redeclare error +}); + + +//// [es6ImportNamedImportAmd_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.types b/tests/baselines/reference/es6ImportNamedImportAmd.types new file mode 100644 index 0000000000000..4a0abe853e025 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.types @@ -0,0 +1,123 @@ +=== tests/cases/compiler/es6ImportNamedImportAmd_0.ts === + +export var a = 10; +>a : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +export var a1 = 10; +>a1 : number + +export var x1 = 10; +>x1 : number + +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + +=== tests/cases/compiler/es6ImportNamedImportAmd_1.ts === +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +>a : number + +var xxxx = a; +>xxxx : number +>a : number + +import { a as b } from "es6ImportNamedImportAmd_0"; +>a : number +>b : number + +var xxxx = b; +>xxxx : number +>b : number + +import { x, a as y } from "es6ImportNamedImportAmd_0"; +>x : number +>a : number +>y : number + +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + +import { x as z, } from "es6ImportNamedImportAmd_0"; +>x : number +>z : number + +var xxxx = z; +>xxxx : number +>z : number + +import { m, } from "es6ImportNamedImportAmd_0"; +>m : number + +var xxxx = m; +>xxxx : number +>m : number + +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +>a1 : number +>x1 : number + +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +>a1 : number +>a11 : number +>x1 : number +>x11 : number + +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportAmd_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +>z2 : number +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; +>aaaa : number +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportDts.js b/tests/baselines/reference/es6ImportNamedImportDts.js new file mode 100644 index 0000000000000..877ae6fab74f3 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.js @@ -0,0 +1,208 @@ +//// [tests/cases/compiler/es6ImportNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class a11 { } +export class a12 { } +export class x { } +export class x11 { } +export class m { } +export class a1 { } +export class x1 { } +export class a111 { } +export class x111 { } +export class z1 { } +export class z2 { } +export class aaaa { } +export class aaaa1 { } + +//// [client.ts] +import { } from "server"; +import { a } from "server"; +export var xxxx = new a(); +import { a11 as b } from "server"; +export var xxxx1 = new b(); +import { x, a12 as y } from "server"; +export var xxxx2 = new x(); +export var xxxx3 = new y(); +import { x11 as z, } from "server"; +export var xxxx4 = new z(); +import { m, } from "server"; +export var xxxx5 = new m(); +import { a1, x1 } from "server"; +export var xxxx6 = new a1(); +export var xxxx7 = new x1(); +import { a111 as a11, x111 as x11 } from "server"; +export var xxxx8 = new a11(); +export var xxxx9 = new x11(); +import { z1 } from "server"; +export var z111 = new z1(); +import { z2 as z3 } from "server"; +export var z2 = new z3(); // z2 shouldn't give redeclare error + +// not referenced +import { aaaa } from "server"; +import { aaaa1 as bbbb } from "server"; + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a1 = (function () { + function a1() { + } + return a1; +})(); +exports.a1 = a1; +var x1 = (function () { + function x1() { + } + return x1; +})(); +exports.x1 = x1; +var a111 = (function () { + function a111() { + } + return a111; +})(); +exports.a111 = a111; +var x111 = (function () { + function x111() { + } + return x111; +})(); +exports.x111 = x111; +var z1 = (function () { + function z1() { + } + return z1; +})(); +exports.z1 = z1; +var z2 = (function () { + function z2() { + } + return z2; +})(); +exports.z2 = z2; +var aaaa = (function () { + function aaaa() { + } + return aaaa; +})(); +exports.aaaa = aaaa; +var aaaa1 = (function () { + function aaaa1() { + } + return aaaa1; +})(); +exports.aaaa1 = aaaa1; +//// [client.js] +var _server_1 = require("server"); +exports.xxxx = new _server_1.a(); +var _server_2 = require("server"); +exports.xxxx1 = new _server_2.a11(); +var _server_3 = require("server"); +exports.xxxx2 = new _server_3.x(); +exports.xxxx3 = new _server_3.a12(); +var _server_4 = require("server"); +exports.xxxx4 = new _server_4.x11(); +var _server_5 = require("server"); +exports.xxxx5 = new _server_5.m(); +var _server_6 = require("server"); +exports.xxxx6 = new _server_6.a1(); +exports.xxxx7 = new _server_6.x1(); +var _server_7 = require("server"); +exports.xxxx8 = new _server_7.a111(); +exports.xxxx9 = new _server_7.x111(); +var _server_8 = require("server"); +exports.z111 = new _server_8.z1(); +var _server_9 = require("server"); +exports.z2 = new _server_9.z2(); // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare class a { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x { +} +export declare class x11 { +} +export declare class m { +} +export declare class a1 { +} +export declare class x1 { +} +export declare class a111 { +} +export declare class x111 { +} +export declare class z1 { +} +export declare class z2 { +} +export declare class aaaa { +} +export declare class aaaa1 { +} +//// [client.d.ts] +import { a } from "server"; +export declare var xxxx: a; +import { a11 as b } from "server"; +export declare var xxxx1: b; +import { x, a12 as y } from "server"; +export declare var xxxx2: x; +export declare var xxxx3: y; +import { x11 as z } from "server"; +export declare var xxxx4: z; +import { m } from "server"; +export declare var xxxx5: m; +import { a1, x1 } from "server"; +export declare var xxxx6: a1; +export declare var xxxx7: x1; +import { a111 as a11, x111 as x11 } from "server"; +export declare var xxxx8: a11; +export declare var xxxx9: x11; +import { z1 } from "server"; +export declare var z111: z1; +import { z2 as z3 } from "server"; +export declare var z2: z3; diff --git a/tests/baselines/reference/es6ImportNamedImportDts.types b/tests/baselines/reference/es6ImportNamedImportDts.types new file mode 100644 index 0000000000000..93bd55716a514 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.types @@ -0,0 +1,150 @@ +=== tests/cases/compiler/server.ts === + +export class a { } +>a : a + +export class a11 { } +>a11 : a11 + +export class a12 { } +>a12 : a12 + +export class x { } +>x : x + +export class x11 { } +>x11 : x11 + +export class m { } +>m : m + +export class a1 { } +>a1 : a1 + +export class x1 { } +>x1 : x1 + +export class a111 { } +>a111 : a111 + +export class x111 { } +>x111 : x111 + +export class z1 { } +>z1 : z1 + +export class z2 { } +>z2 : z2 + +export class aaaa { } +>aaaa : aaaa + +export class aaaa1 { } +>aaaa1 : aaaa1 + +=== tests/cases/compiler/client.ts === +import { } from "server"; +import { a } from "server"; +>a : typeof a + +export var xxxx = new a(); +>xxxx : a +>new a() : a +>a : typeof a + +import { a11 as b } from "server"; +>a11 : typeof b +>b : typeof b + +export var xxxx1 = new b(); +>xxxx1 : b +>new b() : b +>b : typeof b + +import { x, a12 as y } from "server"; +>x : typeof x +>a12 : typeof y +>y : typeof y + +export var xxxx2 = new x(); +>xxxx2 : x +>new x() : x +>x : typeof x + +export var xxxx3 = new y(); +>xxxx3 : y +>new y() : y +>y : typeof y + +import { x11 as z, } from "server"; +>x11 : typeof z +>z : typeof z + +export var xxxx4 = new z(); +>xxxx4 : z +>new z() : z +>z : typeof z + +import { m, } from "server"; +>m : typeof m + +export var xxxx5 = new m(); +>xxxx5 : m +>new m() : m +>m : typeof m + +import { a1, x1 } from "server"; +>a1 : typeof a1 +>x1 : typeof x1 + +export var xxxx6 = new a1(); +>xxxx6 : a1 +>new a1() : a1 +>a1 : typeof a1 + +export var xxxx7 = new x1(); +>xxxx7 : x1 +>new x1() : x1 +>x1 : typeof x1 + +import { a111 as a11, x111 as x11 } from "server"; +>a111 : typeof a11 +>a11 : typeof a11 +>x111 : typeof x11 +>x11 : typeof x11 + +export var xxxx8 = new a11(); +>xxxx8 : a11 +>new a11() : a11 +>a11 : typeof a11 + +export var xxxx9 = new x11(); +>xxxx9 : x11 +>new x11() : x11 +>x11 : typeof x11 + +import { z1 } from "server"; +>z1 : typeof z1 + +export var z111 = new z1(); +>z111 : z1 +>new z1() : z1 +>z1 : typeof z1 + +import { z2 as z3 } from "server"; +>z2 : typeof z3 +>z3 : typeof z3 + +export var z2 = new z3(); // z2 shouldn't give redeclare error +>z2 : z3 +>new z3() : z3 +>z3 : typeof z3 + +// not referenced +import { aaaa } from "server"; +>aaaa : typeof aaaa + +import { aaaa1 as bbbb } from "server"; +>aaaa1 : typeof bbbb +>bbbb : typeof bbbb + diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js index 66f8ce0ef9268..fcb88d55b333a 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -7,16 +7,39 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImportInEs5_1.ts] import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImportInEs5_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImportInEs5_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImportInEs5_0"; +var xxxx = z; import { m, } from "es6ImportNamedImportInEs5_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportInEs5_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; + //// [es6ImportNamedImportInEs5_0.js] exports.a = 10; @@ -24,4 +47,40 @@ exports.x = exports.a; exports.m = exports.a; exports.a1 = 10; exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; //// [es6ImportNamedImportInEs5_1.js] +var _es6ImportNamedImportInEs5_0_1 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_1.a; +var _es6ImportNamedImportInEs5_0_2 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_2.a; +var _es6ImportNamedImportInEs5_0_3 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_3.x; +var xxxx = _es6ImportNamedImportInEs5_0_3.a; +var _es6ImportNamedImportInEs5_0_4 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_4.x; +var _es6ImportNamedImportInEs5_0_5 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_5.m; +var _es6ImportNamedImportInEs5_0_6 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_6.a1; +var xxxx = _es6ImportNamedImportInEs5_0_6.x1; +var _es6ImportNamedImportInEs5_0_7 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_7.a1; +var xxxx = _es6ImportNamedImportInEs5_0_7.x1; +var _es6ImportNamedImportInEs5_0_8 = require("es6ImportNamedImportInEs5_0"); +var z111 = _es6ImportNamedImportInEs5_0_8.z1; +var _es6ImportNamedImportInEs5_0_9 = require("es6ImportNamedImportInEs5_0"); +var z2 = _es6ImportNamedImportInEs5_0_9.z2; // z2 shouldn't give redeclare error + + +//// [es6ImportNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types index 334ae905e952e..f60644b262103 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.types +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -17,34 +17,107 @@ export var a1 = 10; export var x1 = 10; >x1 : number +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + === tests/cases/compiler/es6ImportNamedImportInEs5_1.ts === import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; >a : number +var xxxx = a; +>xxxx : number +>a : number + import { a as b } from "es6ImportNamedImportInEs5_0"; >a : number >b : number +var xxxx = b; +>xxxx : number +>b : number + import { x, a as y } from "es6ImportNamedImportInEs5_0"; >x : number >a : number >y : number +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + import { x as z, } from "es6ImportNamedImportInEs5_0"; >x : number >z : number +var xxxx = z; +>xxxx : number +>z : number + import { m, } from "es6ImportNamedImportInEs5_0"; >m : number +var xxxx = m; +>xxxx : number +>m : number + import { a1, x1 } from "es6ImportNamedImportInEs5_0"; >a1 : number >x1 : number +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; >a1 : number >a11 : number >x1 : number >x11 : number +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportInEs5_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +>z2 : number +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; +>aaaa : number +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt new file mode 100644 index 0000000000000..41d3f160938eb --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt @@ -0,0 +1,14 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts (1 errors) ==== + import { a } from "es6ImportNamedImportInExportAssignment_0"; + export = a; + ~~~~~~~~~~~ +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js index cd2d5ef6922e8..ea9e65db34aab 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -9,29 +9,14 @@ import { a } from "es6ImportNamedImportInExportAssignment_0"; export = a; //// [es6ImportNamedImportInExportAssignment_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportNamedImportInExportAssignment_1.js] -var _es6ImportNamedImportInExportAssignment_0 = require("es6ImportNamedImportInExportAssignment_0"); -module.exports = _es6ImportNamedImportInExportAssignment_0.a; +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export default a; //// [es6ImportNamedImportInExportAssignment_0.d.ts] export declare var a: number; //// [es6ImportNamedImportInExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; export = a; - - -//// [DtsFileErrors] - - -tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.d.ts(1,10): error TS2304: Cannot find name 'a'. - - -==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.d.ts (0 errors) ==== - export declare var a: number; - -==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.d.ts (1 errors) ==== - export = a; - ~ -!!! error TS2304: Cannot find name 'a'. - \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types deleted file mode 100644 index cd72f35c8bf8b..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types +++ /dev/null @@ -1,12 +0,0 @@ -=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts === - -export var a = 10; ->a : number - -=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts === -import { a } from "es6ImportNamedImportInExportAssignment_0"; ->a : number - -export = a; ->a : number - diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt deleted file mode 100644 index e896a1a88a143..0000000000000 --- a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts(2,12): error TS4000: Import declaration 'x' is using private name 'a'. - - -==== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_0.ts (0 errors) ==== - - export module a { - export class c { - } - } - -==== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts (1 errors) ==== - import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; - import x = a; - ~ -!!! error TS4000: Import declaration 'x' is using private name 'a'. - export = x; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js index 332be6074ad40..9c383ab3e3b36 100644 --- a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -33,3 +33,7 @@ export declare module a { class c { } } +//// [es6ImportNamedImportInIndirectExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types new file mode 100644 index 0000000000000..36792ece82e45 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_0.ts === + +export module a { +>a : typeof a + + export class c { +>c : c + } +} + +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts === +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +>a : typeof a + +import x = a; +>x : typeof a +>a : typeof a + +export = x; +>x : typeof a + diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..ff8fe604622ea --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt @@ -0,0 +1,77 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(13,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(16,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(19,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(21,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(25,1): error TS1191: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(26,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export var a1 = 10; + export var x1 = 10; + export var z1 = 10; + export var z2 = 10; + export var aaaa = 10; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import { } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export import { a } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a; + export import { a as b } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = b; + export import { x, a as y } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = x; + export var xxxx = y; + export import { x as z, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = z; + export import { m, } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = m; + export import { a1, x1 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a1; + export var xxxx = x1; + export import { a1 as a11, x1 as x11 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var xxxx = a11; + export var xxxx = x11; + export import { z1 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var z111 = z1; + export import { z2 as z3 } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export var z2 = z3; // z2 shouldn't give redeclare error + + // Non referenced imports + export import { aaaa } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + export import { aaaa as bbbb } from "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.js b/tests/baselines/reference/es6ImportNamedImportWithExport.js new file mode 100644 index 0000000000000..71f4af721788c --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.js @@ -0,0 +1,97 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [client.ts] +export import { } from "server"; +export import { a } from "server"; +export var xxxx = a; +export import { a as b } from "server"; +export var xxxx = b; +export import { x, a as y } from "server"; +export var xxxx = x; +export var xxxx = y; +export import { x as z, } from "server"; +export var xxxx = z; +export import { m, } from "server"; +export var xxxx = m; +export import { a1, x1 } from "server"; +export var xxxx = a1; +export var xxxx = x1; +export import { a1 as a11, x1 as x11 } from "server"; +export var xxxx = a11; +export var xxxx = x11; +export import { z1 } from "server"; +export var z111 = z1; +export import { z2 as z3 } from "server"; +export var z2 = z3; // z2 shouldn't give redeclare error + +// Non referenced imports +export import { aaaa } from "server"; +export import { aaaa as bbbb } from "server"; + + +//// [server.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +exports.a1 = 10; +exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; +//// [client.js] +var _server_1 = require("server"); +exports.xxxx = _server_1.a; +var _server_2 = require("server"); +exports.xxxx = _server_2.a; +var _server_3 = require("server"); +exports.xxxx = _server_3.x; +exports.xxxx = _server_3.a; +var _server_4 = require("server"); +exports.xxxx = _server_4.x; +var _server_5 = require("server"); +exports.xxxx = _server_5.m; +var _server_6 = require("server"); +exports.xxxx = _server_6.a1; +exports.xxxx = _server_6.x1; +var _server_7 = require("server"); +exports.xxxx = _server_7.a1; +exports.xxxx = _server_7.x1; +var _server_8 = require("server"); +exports.z111 = _server_8.z1; +var _server_9 = require("server"); +exports.z2 = _server_9.z2; // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [client.d.ts] +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var z111: number; +export declare var z2: number; diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js new file mode 100644 index 0000000000000..7852d2991bc8a --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js @@ -0,0 +1,59 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts] //// + +//// [server.ts] + +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export class C implements I { + prop = "hello"; +} +export class C2 implements I2 { + prop2 = "world"; +} + +//// [client.ts] +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +export type cValInterface = I; +export var cVal = new C(); + +//// [server.js] +var C = (function () { + function C() { + this.prop = "hello"; + } + return C; +})(); +exports.C = C; +var C2 = (function () { + function C2() { + this.prop2 = "world"; + } + return C2; +})(); +exports.C2 = C2; +//// [client.js] +var _server = require("server"); // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +exports.cVal = new _server.C(); + + +//// [server.d.ts] +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export declare class C implements I { + prop: string; +} +export declare class C2 implements I2 { + prop2: string; +} +//// [client.d.ts] +import { C, I } from "server"; +export declare type cValInterface = I; +export declare var cVal: C; diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types new file mode 100644 index 0000000000000..62917e5ff36b5 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/server.ts === + +export interface I { +>I : I + + prop: string; +>prop : string +} +export interface I2 { +>I2 : I2 + + prop2: string; +>prop2 : string +} +export class C implements I { +>C : C +>I : I + + prop = "hello"; +>prop : string +} +export class C2 implements I2 { +>C2 : C2 +>I2 : I2 + + prop2 = "world"; +>prop2 : string +} + +=== tests/cases/compiler/client.ts === +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +>C : typeof C +>I : unknown +>C2 : typeof C2 + +export type cValInterface = I; +>cValInterface : I +>I : I + +export var cVal = new C(); +>cVal : C +>new C() : C +>C : typeof C + diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js new file mode 100644 index 0000000000000..7b10da7cc9fc3 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts] //// + +//// [es6ImportWithoutFromClauseAmd_0.ts] + +export var a = 10; + +//// [es6ImportWithoutFromClauseAmd_1.ts] +export var b = 10; + +//// [es6ImportWithoutFromClauseAmd_2.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; + +//// [es6ImportWithoutFromClauseAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportWithoutFromClauseAmd_1.js] +define(["require", "exports"], function (require, exports) { + exports.b = 10; +}); +//// [es6ImportWithoutFromClauseAmd_2.js] +define(["require", "exports", "es6ImportWithoutFromClauseAmd_0", "es6ImportWithoutFromClauseAmd_2"], function (require, exports, , ) { + var _a = 10; + var _b = 10; +}); + + +//// [es6ImportWithoutFromClauseAmd_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseAmd_1.d.ts] +export declare var b: number; +//// [es6ImportWithoutFromClauseAmd_2.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types new file mode 100644 index 0000000000000..c3d09388916bc --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_1.ts === +export var b = 10; +>b : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_2.ts === +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +>_a : number + +var _b = 10; +>_b : number + diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index f6610ac5ad295..aacb936ab3619 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -11,3 +11,8 @@ import "es6ImportWithoutFromClauseInEs5_0"; exports.a = 10; //// [es6ImportWithoutFromClauseInEs5_1.js] require("es6ImportWithoutFromClauseInEs5_0"); + + +//// [es6ImportWithoutFromClauseInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt new file mode 100644 index 0000000000000..da865698e56a8 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/client.ts(1,1): error TS1191: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import "server"; + ~~~~~~ +!!! error TS1191: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js new file mode 100644 index 0000000000000..208f71bcbfe9f --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import "server"; + +//// [server.js] +exports.a = 10; +//// [client.js] +require("server"); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export import "server"; diff --git a/tests/cases/compiler/declarationEmitDefaultExport1.ts b/tests/cases/compiler/declarationEmitDefaultExport1.ts new file mode 100644 index 0000000000000..3ce76e2f3b333 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport1.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +export default class C { +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport2.ts b/tests/cases/compiler/declarationEmitDefaultExport2.ts new file mode 100644 index 0000000000000..ee691f3bdcf99 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport2.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +export default class { +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport3.ts b/tests/cases/compiler/declarationEmitDefaultExport3.ts new file mode 100644 index 0000000000000..fceefe32f7d64 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport3.ts @@ -0,0 +1,5 @@ +// @declaration: true +// @target: es6 +export default function foo() { + return "" +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport4.ts b/tests/cases/compiler/declarationEmitDefaultExport4.ts new file mode 100644 index 0000000000000..9daad837f73f5 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport4.ts @@ -0,0 +1,5 @@ +// @declaration: true +// @target: es6 +export default function () { + return 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport5.ts b/tests/cases/compiler/declarationEmitDefaultExport5.ts new file mode 100644 index 0000000000000..3265753c514ac --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport5.ts @@ -0,0 +1,3 @@ +// @declaration: true +// @target: es6 +export default 1 + 2; diff --git a/tests/cases/compiler/declarationEmitDefaultExport6.ts b/tests/cases/compiler/declarationEmitDefaultExport6.ts new file mode 100644 index 0000000000000..468486b9bb041 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport6.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +export class A {} +export default new A(); diff --git a/tests/cases/compiler/declarationEmitDefaultExport7.ts b/tests/cases/compiler/declarationEmitDefaultExport7.ts new file mode 100644 index 0000000000000..960c203dcab0d --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport7.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +class A {} +export default new A(); diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts new file mode 100644 index 0000000000000..fc3dac87ae0f5 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts @@ -0,0 +1,10 @@ +// @declaration: true + +var [] = [1, "hello"]; // Dont emit anything +var [x] = [1, "hello"]; // emit x: number +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +var [, , z1] = [0, 1, 2]; // emit z1: number + +var a = [1, "hello"]; +var [x2] = a; // emit x2: number | string +var [x3, y3, z3] = a; // emit x3, y3, z3 \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts new file mode 100644 index 0000000000000..f116423715aff --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts @@ -0,0 +1,10 @@ +// @declaration: true +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + +var [x11 = 0, y11 = ""] = [1, "hello"]; +var [a11, b11, c11] = []; + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + +var [x13, y13] = [1, "hello"]; +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts new file mode 100644 index 0000000000000..9cdc6c2ec90ff --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts @@ -0,0 +1,4 @@ +// @declaration: true +module M { + export var [a, b] = [1, 2]; +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts new file mode 100644 index 0000000000000..8f162e33da3d9 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts @@ -0,0 +1,10 @@ +// @declaration: true +var [...a5] = [1, 2, 3]; +var [x14, ...a6] = [1, 2, 3]; +var [x15, y15, ...a7] = [1, 2, 3]; +var [x16, y16, z16, ...a8] = [1, 2, 3]; + +var [...a9] = [1, "hello", true]; +var [x17, ...a10] = [1, "hello", true]; +var [x18, y18, ...a12] = [1, "hello", true]; +var [x19, y19, z19, ...a13] = [1, "hello", true]; \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts new file mode 100644 index 0000000000000..89e5b65a9d3b3 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts @@ -0,0 +1,23 @@ +// @declaration: true + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts new file mode 100644 index 0000000000000..6a65c92546504 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts @@ -0,0 +1,9 @@ +// @declaration: true + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts new file mode 100644 index 0000000000000..f700e68e39727 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts @@ -0,0 +1,15 @@ +// @declaration: true + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts b/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts new file mode 100644 index 0000000000000..020a29ba21997 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts @@ -0,0 +1,10 @@ +// @declaration: true + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +function foo2(...rest: any[]) { + +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts b/tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts new file mode 100644 index 0000000000000..597497feac0b2 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts @@ -0,0 +1,17 @@ +// @declaration: true +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 =[string, number, boolean]; +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts b/tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts new file mode 100644 index 0000000000000..987fb67a08ba4 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts @@ -0,0 +1,6 @@ +// @declaration: true +module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts b/tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts new file mode 100644 index 0000000000000..c3785acd09a7e --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts @@ -0,0 +1,5 @@ +// @declaration: true +function foo([x,y,z]?: [string, number, boolean]) { +} +function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts b/tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts new file mode 100644 index 0000000000000..b246ba32ba4b6 --- /dev/null +++ b/tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts @@ -0,0 +1,12 @@ +// @declaration: true +// @module: commonjs + +module m { + export module c { + export class c { + } + } + import x = c; + export var a: typeof x; +} +export = m; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClauseInEs5.ts b/tests/cases/compiler/es6ExportClauseInEs5.ts new file mode 100644 index 0000000000000..675f302bcb613 --- /dev/null +++ b/tests/cases/compiler/es6ExportClauseInEs5.ts @@ -0,0 +1,20 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: server.ts +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts new file mode 100644 index 0000000000000..6361c0133671c --- /dev/null +++ b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts @@ -0,0 +1,22 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBinding.ts b/tests/cases/compiler/es6ImportDefaultBinding.ts index 9e779e8664d79..3007a9e82fa09 100644 --- a/tests/cases/compiler/es6ImportDefaultBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBinding.ts @@ -1,8 +1,12 @@ // @target: es6 // @declaration: true +// @declaration: true // @filename: es6ImportDefaultBinding_0.ts -export var a = 10; +var a = 10; +export = a; // @filename: es6ImportDefaultBinding_1.ts import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts index 20f0f122e99e0..a0524dd2138d5 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts @@ -1,4 +1,5 @@ // @target: es6 +// @module: commonjs // @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamedImport_0.ts @@ -7,9 +8,15 @@ export var x = a; export var m = a; // @filename: es6ImportDefaultBindingFollowedWithNamedImport_1.ts -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = m; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts new file mode 100644 index 0000000000000..80bc2a4474e0c --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts @@ -0,0 +1,21 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding6; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts new file mode 100644 index 0000000000000..fef56560dcf81 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts @@ -0,0 +1,20 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +export import defaultBinding1, { } from "server"; +export var x1: number = defaultBinding1; +export import defaultBinding2, { a } from "server"; +export var x1: number = defaultBinding2; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = defaultBinding3; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = defaultBinding4; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = defaultBinding5; +export import defaultBinding6, { m, } from "server"; +export var x1: number = defaultBinding6; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts new file mode 100644 index 0000000000000..1951a8a6b30e6 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts @@ -0,0 +1,20 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +class a { } +export = a; + +// @filename: client.ts +import defaultBinding1, { } from "server"; +export var x1 = new defaultBinding1(); +import defaultBinding2, { a } from "server"; +export var x2 = new defaultBinding2(); +import defaultBinding3, { a as b } from "server"; +export var x3 = new defaultBinding3(); +import defaultBinding4, { x, a as y } from "server"; +export var x4 = new defaultBinding4(); +import defaultBinding5, { x as z, } from "server"; +export var x5 = new defaultBinding5(); +import defaultBinding6, { m, } from "server"; +export var x6 = new defaultBinding6(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts index bf34687f79162..6e42898d1bca5 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts @@ -1,5 +1,6 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts export var a = 10; @@ -7,9 +8,15 @@ export var x = a; export var m = a; // @filename: es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; \ No newline at end of file +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = m; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts new file mode 100644 index 0000000000000..6e3ac5786d1e1 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts @@ -0,0 +1,21 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +export var a = 10; +export var x = a; +export var m = a; + +// @filename: client.ts +export import defaultBinding1, { } from "server"; +export import defaultBinding2, { a } from "server"; +export var x1: number = a; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = b; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = x; +export var x1: number = y; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = z; +export import defaultBinding6, { m, } from "server"; +export var x1: number = m; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts index 3e2cdd3409257..e0f9d953afe62 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts @@ -1,5 +1,6 @@ // @target: es6 // @declaration: true +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts new file mode 100644 index 0000000000000..ce42814a91818 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts index 5943fa8bfc462..c58ba286e0a39 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts @@ -1,8 +1,10 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts export var a = 10; // @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; \ No newline at end of file +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts new file mode 100644 index 0000000000000..cafcace08a03d --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export var a = 10; + +// @filename: client.ts +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts index c037d283dfa74..e0877bd74c1e8 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts @@ -1,8 +1,10 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingInEs5_0.ts -export var a = 10; +var a = 10; +export = a; // @filename: es6ImportDefaultBindingInEs5_1.ts import defaultBinding from "es6ImportDefaultBindingInEs5_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingWithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingWithExport.ts new file mode 100644 index 0000000000000..87494c8a62275 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingWithExport.ts @@ -0,0 +1,11 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +export import defaultBinding from "server"; +export var x = defaultBinding; +export import defaultBinding2 from "server"; // non referenced \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImport.ts b/tests/cases/compiler/es6ImportNameSpaceImport.ts index 58ef52daf53c0..0c831d323d14a 100644 --- a/tests/cases/compiler/es6ImportNameSpaceImport.ts +++ b/tests/cases/compiler/es6ImportNameSpaceImport.ts @@ -1,4 +1,5 @@ // @target: es6 +// @module: commonjs // @declaration: true // @filename: es6ImportNameSpaceImport_0.ts @@ -6,3 +7,5 @@ export var a = 10; // @filename: es6ImportNameSpaceImport_1.ts import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this diff --git a/tests/cases/compiler/es6ImportNameSpaceImportAmd.ts b/tests/cases/compiler/es6ImportNameSpaceImportAmd.ts new file mode 100644 index 0000000000000..89a5ad7bc2c0b --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportAmd.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportNameSpaceImportAmd_0.ts +export var a = 10; + +// @filename: es6ImportNameSpaceImportAmd_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this diff --git a/tests/cases/compiler/es6ImportNameSpaceImportDts.ts b/tests/cases/compiler/es6ImportNameSpaceImportDts.ts new file mode 100644 index 0000000000000..95b85e53edc2a --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportDts.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class c { }; + +// @filename: client.ts +import * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.c(); +import * as nameSpaceBinding2 from "server"; // unreferenced \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts b/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts index ca00ac3f981e6..8104fe8b3c0ef 100644 --- a/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts +++ b/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts @@ -1,8 +1,11 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportNameSpaceImportInEs5_0.ts export var a = 10; // @filename: es6ImportNameSpaceImportInEs5_1.ts -import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; \ No newline at end of file +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this diff --git a/tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts b/tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts new file mode 100644 index 0000000000000..4110270d7ddb8 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +export var a = 10; + +// @filename: client.ts +export import * as nameSpaceBinding from "server"; +export var x = nameSpaceBinding.a; +export import * as nameSpaceBinding2 from "server"; // Not referenced imports diff --git a/tests/cases/compiler/es6ImportNamedImport.ts b/tests/cases/compiler/es6ImportNamedImport.ts index df5de47897577..0a12e10169bd0 100644 --- a/tests/cases/compiler/es6ImportNamedImport.ts +++ b/tests/cases/compiler/es6ImportNamedImport.ts @@ -1,4 +1,5 @@ // @target: es6 +// @module: commonjs // @declaration: true // @filename: es6ImportNamedImport_0.ts @@ -7,13 +8,35 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; // @filename: es6ImportNamedImport_1.ts import { } from "es6ImportNamedImport_0"; import { a } from "es6ImportNamedImport_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImport_0"; +var xxxx = z; import { m, } from "es6ImportNamedImport_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImport_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImport_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportAmd.ts b/tests/cases/compiler/es6ImportNamedImportAmd.ts new file mode 100644 index 0000000000000..3ddf1a4cf5219 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportAmd.ts @@ -0,0 +1,41 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportNamedImportAmd_0.ts +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +// @filename: es6ImportNamedImportAmd_1.ts +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImportAmd_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImportAmd_0"; +var xxxx = x; +var xxxx = y; +import { x as z, } from "es6ImportNamedImportAmd_0"; +var xxxx = z; +import { m, } from "es6ImportNamedImportAmd_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportAmd_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportDts.ts b/tests/cases/compiler/es6ImportNamedImportDts.ts new file mode 100644 index 0000000000000..d83672f375446 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportDts.ts @@ -0,0 +1,46 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } +export class a11 { } +export class a12 { } +export class x { } +export class x11 { } +export class m { } +export class a1 { } +export class x1 { } +export class a111 { } +export class x111 { } +export class z1 { } +export class z2 { } +export class aaaa { } +export class aaaa1 { } + +// @filename: client.ts +import { } from "server"; +import { a } from "server"; +export var xxxx = new a(); +import { a11 as b } from "server"; +export var xxxx1 = new b(); +import { x, a12 as y } from "server"; +export var xxxx2 = new x(); +export var xxxx3 = new y(); +import { x11 as z, } from "server"; +export var xxxx4 = new z(); +import { m, } from "server"; +export var xxxx5 = new m(); +import { a1, x1 } from "server"; +export var xxxx6 = new a1(); +export var xxxx7 = new x1(); +import { a111 as a11, x111 as x11 } from "server"; +export var xxxx8 = new a11(); +export var xxxx9 = new x11(); +import { z1 } from "server"; +export var z111 = new z1(); +import { z2 as z3 } from "server"; +export var z2 = new z3(); // z2 shouldn't give redeclare error + +// not referenced +import { aaaa } from "server"; +import { aaaa1 as bbbb } from "server"; diff --git a/tests/cases/compiler/es6ImportNamedImportInEs5.ts b/tests/cases/compiler/es6ImportNamedImportInEs5.ts index 22e66bc95fa42..e12a8d032d3d3 100644 --- a/tests/cases/compiler/es6ImportNamedImportInEs5.ts +++ b/tests/cases/compiler/es6ImportNamedImportInEs5.ts @@ -1,5 +1,6 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportNamedImportInEs5_0.ts export var a = 10; @@ -7,13 +8,35 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; // @filename: es6ImportNamedImportInEs5_1.ts import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImportInEs5_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImportInEs5_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImportInEs5_0"; +var xxxx = z; import { m, } from "es6ImportNamedImportInEs5_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; \ No newline at end of file +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportInEs5_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts index a27391757701d..7a4519c68bba7 100644 --- a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts +++ b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts @@ -1,3 +1,4 @@ +// @target: es6 // @module: commonjs // @declaration: true diff --git a/tests/cases/compiler/es6ImportNamedImportWithExport.ts b/tests/cases/compiler/es6ImportNamedImportWithExport.ts new file mode 100644 index 0000000000000..f25a3779b990e --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportWithExport.ts @@ -0,0 +1,40 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +// @filename: client.ts +export import { } from "server"; +export import { a } from "server"; +export var xxxx = a; +export import { a as b } from "server"; +export var xxxx = b; +export import { x, a as y } from "server"; +export var xxxx = x; +export var xxxx = y; +export import { x as z, } from "server"; +export var xxxx = z; +export import { m, } from "server"; +export var xxxx = m; +export import { a1, x1 } from "server"; +export var xxxx = a1; +export var xxxx = x1; +export import { a1 as a11, x1 as x11 } from "server"; +export var xxxx = a11; +export var xxxx = x11; +export import { z1 } from "server"; +export var z111 = z1; +export import { z2 as z3 } from "server"; +export var z2 = z3; // z2 shouldn't give redeclare error + +// Non referenced imports +export import { aaaa } from "server"; +export import { aaaa as bbbb } from "server"; diff --git a/tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts b/tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts new file mode 100644 index 0000000000000..08294e572325d --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts @@ -0,0 +1,21 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export class C implements I { + prop = "hello"; +} +export class C2 implements I2 { + prop2 = "world"; +} + +// @filename: client.ts +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +export type cValInterface = I; +export var cVal = new C(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClause.ts b/tests/cases/compiler/es6ImportWithoutFromClause.ts index 0a38cda093c44..657532e7a4ba0 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClause.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClause.ts @@ -1,5 +1,6 @@ // @target: es6 // @declaration: true +// @declaration: true // @filename: es6ImportWithoutFromClause_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts b/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts new file mode 100644 index 0000000000000..8c43a19e4093e --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts @@ -0,0 +1,14 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportWithoutFromClauseAmd_0.ts +export var a = 10; + +// @filename: es6ImportWithoutFromClauseAmd_1.ts +export var b = 10; + +// @filename: es6ImportWithoutFromClauseAmd_2.ts +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts index 339880ee097e3..08c21c236443a 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts @@ -1,5 +1,6 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportWithoutFromClauseInEs5_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts b/tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts new file mode 100644 index 0000000000000..8c7ec10853830 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts @@ -0,0 +1,8 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export var a = 10; + +// @filename: client.ts +export import "server"; \ No newline at end of file