diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 0d32c605fdc08..b97e4a2ea5427 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -65,8 +65,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ' ' + convertPropertyName(nameMap[name]) + ': { code: ' + diagnosticDetails.code + ', category: DiagnosticCategory.' + diagnosticDetails.category + - ', key: "' + name.replace('"', '\\"') + '"' + - (diagnosticDetails.isEarly ? ', isEarly: true' : '') + + ', key: "' + name.replace(/[\"]/g, '\\"') + '"' + ' },\r\n'; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4f11923247657..423c3c316275a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -783,7 +783,7 @@ module ts { } function getExportsForModule(moduleSymbol: Symbol): SymbolTable { - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { // A default export hides all other exports in CommonJS and AMD modules let defaultSymbol = getExportAssignmentSymbol(moduleSymbol); if (defaultSymbol) { @@ -1812,6 +1812,11 @@ module ts { case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportSpecifier: + return false; + // Type parameters are always visible case SyntaxKind.TypeParameter: // Source file is always visible @@ -10093,6 +10098,12 @@ module ts { } } } + else { + if (languageVersion >= ScriptTarget.ES6) { + // Import equals declaration is deprecated in es6 or above + grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + } + } } } @@ -10140,6 +10151,11 @@ module ts { } checkExternalModuleExports(container); + + if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) { + // export assignment is deprecated in es6 or above + grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + } } function getModuleStatements(node: Declaration): ModuleElement[] { @@ -10182,7 +10198,7 @@ module ts { if (!links.exportsChecked) { let defaultSymbol = getExportAssignmentSymbol(moduleSymbol); if (defaultSymbol) { - if (hasExportedMembers(moduleSymbol)) { + if (languageVersion < ScriptTarget.ES6 && hasExportedMembers(moduleSymbol)) { let declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); } @@ -11005,7 +11021,15 @@ module ts { function getExportNameSubstitution(symbol: Symbol, location: Node): string { if (isExternalModuleSymbol(symbol.parent)) { - return "exports." + unescapeIdentifier(symbol.name); + var symbolName = unescapeIdentifier(symbol.name); + // If this is es6 or higher, just use the name of the export + // no need to qualify it. + if (languageVersion >= ScriptTarget.ES6) { + return symbolName; + } + else { + return "exports." + symbolName; + } } let node = location; let containerSymbol = getParentOfSymbol(symbol); @@ -11033,7 +11057,7 @@ module ts { return getExportNameSubstitution(exportSymbol, node.parent); } // Named imports from ES6 import declarations are rewritten - if (symbol.flags & SymbolFlags.Alias) { + if (symbol.flags & SymbolFlags.Alias && languageVersion < ScriptTarget.ES6) { return getAliasNameSubstitution(symbol); } } @@ -11069,7 +11093,6 @@ module ts { return true; } } - return forEachChild(node, isReferencedAliasDeclaration); } function isImplementationOfOverload(node: FunctionLikeDeclaration) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 622b28d5f182d..dd26ef281c4bb 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -159,6 +159,9 @@ module ts { Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1201, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, + Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, + Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 410cce54d173d..e1767fe8de044 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -627,6 +627,18 @@ "category": "Error", "code": 1201 }, + "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": { + "category": "Error", + "code": 1202 + }, + "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.": { + "category": "Error", + "code": 1203 + }, + "Cannot compile external modules into amd or commonjs when targeting es6 or higher.": { + "category": "Error", + "code": 1204 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e585f258ef6b6..205f2fe2945ef 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3258,7 +3258,7 @@ module ts { } function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void { - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { emit(node.tag); write(" "); emit(node.template); @@ -3858,8 +3858,14 @@ module ts { function emitModuleMemberName(node: Declaration) { emitStart(node.name); if (getCombinedNodeFlags(node) & NodeFlags.Export) { - emitContainingModuleName(node); - write("."); + var container = getContainingModule(node); + if (container) { + write(resolver.getGeneratedNameForNode(container)); + write("."); + } + else if (languageVersion < ScriptTarget.ES6) { + write("exports."); + } } emitNodeWithoutSourceMap(node.name); emitEnd(node.name); @@ -4211,10 +4217,21 @@ module ts { generatedBlockScopeNames[variableId] = generatedName; } + function isES6ModuleMemberDeclaration(node: Node) { + return !!(node.flags & NodeFlags.Export) && + languageVersion >= ScriptTarget.ES6 && + node.parent.kind === SyntaxKind.SourceFile; + } + function emitVariableStatement(node: VariableStatement) { if (!(node.flags & NodeFlags.Export)) { emitStartOfVariableDeclarationList(node.declarationList); } + else if (languageVersion >= ScriptTarget.ES6 && node.parent.kind === SyntaxKind.SourceFile) { + // Exported ES6 module member + write("export "); + emitStartOfVariableDeclarationList(node.declarationList); + } emitCommaList(node.declarationList.declarations); write(";"); if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { @@ -4333,6 +4350,19 @@ module ts { } } + function shouldEmitFunctionName(node: Declaration): boolean { + // Emit a declaration name for the function iff: + // it is a function expression with a name provided + // it is a function declaration with a name provided + // it is a function declaration is not the default export, and is missing a name (emit a generated name for it) + if (node.kind === SyntaxKind.FunctionExpression) { + return !!node.name; + } + else if (node.kind === SyntaxKind.FunctionDeclaration) { + return !!node.name || (languageVersion >= ScriptTarget.ES6 && !(node.flags & NodeFlags.Default)); + } + } + function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); @@ -4346,12 +4376,19 @@ module ts { // For targeting below es6, emit functions-like declaration including arrow function using function keyword. // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead if (!shouldEmitAsArrowFunction(node)) { + if (isES6ModuleMemberDeclaration(node)) { + write("export "); + if (node.flags & NodeFlags.Default) { + write("default "); + } + } write("function "); } - if (node.kind === SyntaxKind.FunctionDeclaration || (node.kind === SyntaxKind.FunctionExpression && node.name)) { + if (shouldEmitFunctionName(node)) { emitDeclarationName(node); } + emitSignatureAndBody(node); if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments((node).name); @@ -4422,7 +4459,7 @@ module ts { emitExpressionFunctionBody(node, node.body); } - if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { + if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default) && !isES6ModuleMemberDeclaration(node)) { writeLine(); emitStart(node); emitModuleMemberName(node); @@ -4857,7 +4894,7 @@ module ts { } function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { - if (node.flags & NodeFlags.Export) { + if (isES6ModuleMemberDeclaration(node)) { write("export "); if (node.flags & NodeFlags.Default) { @@ -4866,7 +4903,10 @@ module ts { } write("class "); - emitDeclarationName(node); + // check if this is an "export default class" as it may not have a name + if (node.name || !(node.flags & NodeFlags.Default)) { + emitDeclarationName(node); + } var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); @@ -4890,6 +4930,18 @@ module ts { // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. writeLine(); emitMemberAssignments(node, NodeFlags.Static); + + // If this is an exported class, but not on the top level (i.e. on an internal + // module), export it + if (!isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Export)) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } } function emitClassDeclarationBelowES6(node: ClassDeclaration) { @@ -4932,6 +4984,7 @@ module ts { } write(");"); emitEnd(node); + if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { writeLine(); emitStart(node); @@ -4941,6 +4994,7 @@ module ts { emitEnd(node); write(";"); } + if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } @@ -4961,7 +5015,7 @@ module ts { return; } - if (!(node.flags & NodeFlags.Export)) { + if (!(node.flags & NodeFlags.Export) || isES6ModuleMemberDeclaration(node)) { emitStart(node); write("var "); emit(node.name); @@ -4988,7 +5042,10 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (node.flags & NodeFlags.Export) { + if (isES6ModuleMemberDeclaration(node)) { + emitES6NamedExportForDeclaration(node); + } + else if (node.flags & NodeFlags.Export) { writeLine(); emitStart(node); write("var "); @@ -5094,7 +5151,8 @@ module ts { scopeEmitEnd(); } write(")("); - if (node.flags & NodeFlags.Export) { + // write moduleDecl = containingModule.m only if it is not exported es6 module member + if ((node.flags & NodeFlags.Export) && !isES6ModuleMemberDeclaration(node)) { emit(node.name); write(" = "); } @@ -5103,11 +5161,23 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { + if (isES6ModuleMemberDeclaration(node)) { + emitES6NamedExportForDeclaration(node); + } + else if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { emitExportMemberAssignments(node.name); } } + function emitES6NamedExportForDeclaration(node: Declaration) { + writeLine(); + emitStart(node); + write("export { "); + emit(node.name); + write(" };"); + emitEnd(node); + } + function emitRequire(moduleName: Expression) { if (moduleName.kind === SyntaxKind.StringLiteral) { write("require("); @@ -5122,7 +5192,95 @@ module ts { } } - function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { + function emitImportDeclaration(node: ImportDeclaration) { + if (languageVersion < ScriptTarget.ES6) { + return emitExternalImportDeclaration(node); + } + + // ES6 import + if (node.importClause) { + let shouldEmitDefaultBindings = hasReferencedDefaultName(node.importClause); + let shouldEmitNamedBindings = hasReferencedNamedBindings(node.importClause); + if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { + write("import "); + emitStart(node.importClause); + if (shouldEmitDefaultBindings) { + emit(node.importClause.name); + if (shouldEmitNamedBindings) { + write(", "); + } + } + if (shouldEmitNamedBindings) { + emitLeadingComments(node.importClause.namedBindings); + emitStart(node.importClause.namedBindings); + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + write("* as "); + emit((node.importClause.namedBindings).name); + } + else { + write("{ "); + let importSpecifiers = (node.importClause.namedBindings).elements; + let currentTextPos = writer.getTextPos(); + let needsComma = false; + for (var i = 0, n = importSpecifiers.length; i < n; i++) { + if (resolver.isReferencedAliasDeclaration(importSpecifiers[i])) { + if (needsComma) { + write(", "); + } + needsComma = true; + emit(importSpecifiers[i]); + } + } + write(" }"); + } + emitEnd(node.importClause.namedBindings); + emitTrailingComments(node.importClause.namedBindings); + } + + emitEnd(node.importClause); + write(" from "); + emit(node.moduleSpecifier); + write(";"); + } + } + else { + write("import "); + emit(node.moduleSpecifier); + write(";"); + } + } + + function hasReferencedDefaultName(importClause: ImportClause) { + // If the default import is used, the mark will be on the importClause, + // as the alias declaration. + // If there are other named bindings on the import clause, we will + // will mark either the namedBindings(import * as n) or the NamedImport + // in the case of import {a} + return resolver.isReferencedAliasDeclaration(importClause); + } + + function hasReferencedNamedBindings(importClause: ImportClause) { + if (importClause && importClause.namedBindings) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + return resolver.isReferencedAliasDeclaration(importClause.namedBindings); + } + else { + return forEach((importClause.namedBindings).elements, + namedImport => resolver.isReferencedAliasDeclaration(namedImport)); + } + } + } + + function emitImportOrExportSpecifier(node: ImportSpecifier) { + Debug.assert(languageVersion >= ScriptTarget.ES6); + if (node.propertyName) { + emit(node.propertyName); + write(" as "); + } + emit(node.name); + } + + function emitExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { let info = getExternalImportInfo(node); if (info) { let declarationNode = info.declarationNode; @@ -5164,7 +5322,7 @@ module ts { function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { if (isExternalModuleImportEqualsDeclaration(node)) { - emitImportDeclaration(node); + emitExternalImportDeclaration(node); return; } // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when @@ -5174,7 +5332,13 @@ module ts { (!isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); - if (!(node.flags & NodeFlags.Export)) write("var "); + if (isES6ModuleMemberDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & NodeFlags.Export)) { + write("var "); + } emitModuleMemberName(node); write(" = "); emit(node.moduleReference); @@ -5185,78 +5349,122 @@ module ts { } function emitExportDeclaration(node: ExportDeclaration) { - if (node.moduleSpecifier) { - emitStart(node); - let generatedName = resolver.getGeneratedNameForNode(node); - if (compilerOptions.module !== ModuleKind.AMD) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(getExternalModuleName(node)); + if (languageVersion < ScriptTarget.ES6 || node.parent.kind !== SyntaxKind.SourceFile) { + if (node.moduleSpecifier) { + emitStart(node); + let generatedName = resolver.getGeneratedNameForNode(node); + if (compilerOptions.module !== ModuleKind.AMD) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(getExternalModuleName(node)); + } + if (node.exportClause) { + // export { x, y, ... } + forEach(node.exportClause.elements, specifier => { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithoutSourceMap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + }); + } + else { + // export * + let tempName = createTempVariable(node).text; + writeLine(); + write("for (var " + tempName + " in " + generatedName + ") if (!"); + emitContainingModuleName(node); + write(".hasOwnProperty(" + tempName + ")) "); + emitContainingModuleName(node); + write("[" + tempName + "] = " + generatedName + "[" + tempName + "];"); + } + emitEnd(node); + } + else { + // internal module + if (node.exportClause) { + // export { x, y, ... } + forEach(node.exportClause.elements, specifier => { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithoutSourceMap(specifier.name); + write(" = "); + emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + }); + } } + } + else { + write("export "); if (node.exportClause) { // export { x, y, ... } - forEach(node.exportClause.elements, specifier => { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithoutSourceMap(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - }); + write("{ "); + emitCommaList(node.exportClause.elements); + write(" }"); } else { - // export * - let tempName = createTempVariable(node).text; - writeLine(); - write("for (var " + tempName + " in " + generatedName + ") if (!"); - emitContainingModuleName(node); - write(".hasOwnProperty(" + tempName + ")) "); - emitContainingModuleName(node); - write("[" + tempName + "] = " + generatedName + "[" + tempName + "];"); + write("*"); } - emitEnd(node); + if (node.moduleSpecifier) { + write(" from "); + emit(node.moduleSpecifier); + } + write(";"); } } function createExternalImportInfo(node: Node): ExternalImportInfo { if (node.kind === SyntaxKind.ImportEqualsDeclaration) { if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { - return { - rootNode: node, - declarationNode: node - }; + if (resolver.isReferencedAliasDeclaration(node)) { + return { + rootNode: node, + declarationNode: node + }; + } } } else if (node.kind === SyntaxKind.ImportDeclaration) { let importClause = (node).importClause; if (importClause) { - if (importClause.name) { + if (importClause.name && resolver.isReferencedAliasDeclaration(importClause)) { return { rootNode: node, declarationNode: importClause }; } - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - return { - rootNode: node, - declarationNode: importClause.namedBindings - }; + if (hasReferencedNamedBindings(importClause)) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + return { + rootNode: node, + declarationNode: importClause.namedBindings + }; + } + else { + return { + rootNode: node, + namedImports: importClause.namedBindings, + localName: resolver.getGeneratedNameForNode(node) + }; + } } + } + else { return { - rootNode: node, - namedImports: importClause.namedBindings, - localName: resolver.getGeneratedNameForNode(node) + rootNode: node }; } - return { - rootNode: node - } } else if (node.kind === SyntaxKind.ExportDeclaration) { if ((node).moduleSpecifier) { @@ -5292,9 +5500,7 @@ module ts { else { let info = createExternalImportInfo(node); if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedAliasDeclaration(node)) { - externalImports.push(info); - } + externalImports.push(info); } } }); @@ -5324,6 +5530,7 @@ module ts { } function emitAMDModule(node: SourceFile, startIndex: number) { + createExternalModuleInfo(node); writeLine(); write("define("); sortAMDModules(node.amdDependencies); @@ -5374,28 +5581,60 @@ module ts { } function emitCommonJSModule(node: SourceFile, startIndex: number) { + createExternalModuleInfo(node); emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); emitExportDefault(node, /*emitAsReturn*/ false); } - function emitExportDefault(sourceFile: SourceFile, emitAsReturn: boolean) { - if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { + function emitES6Module(node: SourceFile, startIndex: number) { + externalImports = undefined; + exportSpecifiers = undefined; + exportDefault = undefined; + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + // Emit exportDefault if it exists will happen as part + // or normal statment emit. + } + + function emitExportAssignment(node: ExportAssignment) { + // Only emit exportAssignment/export default if we are in ES6 + // Other modules will handel it diffrentlly + if (languageVersion >= ScriptTarget.ES6) { writeLine(); - emitStart(exportDefault); - write(emitAsReturn ? "return " : "module.exports = "); - if (exportDefault.kind === SyntaxKind.ExportAssignment) { - emit((exportDefault).expression); - } - else if (exportDefault.kind === SyntaxKind.ExportSpecifier) { - emit((exportDefault).propertyName); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== SyntaxKind.FunctionDeclaration && + expression.kind !== SyntaxKind.ClassDeclaration) { + write(";"); } - else { - emitDeclarationName(exportDefault); + emitEnd(node); + } + } + + function emitExportDefault(sourceFile: SourceFile, emitAsReturn: boolean) { + // ES6 emit is handled in emitExportAssignment + if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { + if (languageVersion < ScriptTarget.ES6) { + writeLine(); + emitStart(exportDefault); + write(emitAsReturn ? "return " : "module.exports = "); + if (exportDefault.kind === SyntaxKind.ExportAssignment) { + emit((exportDefault).expression); + } + else if (exportDefault.kind === SyntaxKind.ExportSpecifier) { + emit((exportDefault).propertyName); + } + else { + emitDeclarationName(exportDefault); + } + write(";"); + emitEnd(exportDefault); } - write(";"); - emitEnd(exportDefault); } } @@ -5442,8 +5681,10 @@ module ts { extendsEmitted = true; } if (isExternalModule(node)) { - createExternalModuleInfo(node); - if (compilerOptions.module === ModuleKind.AMD) { + if (languageVersion >= ScriptTarget.ES6) { + emitES6Module(node, startIndex); + } + else if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } else { @@ -5667,10 +5908,15 @@ module ts { return emitModuleDeclaration(node); case SyntaxKind.ImportDeclaration: return emitImportDeclaration(node); + case SyntaxKind.ImportSpecifier: + case SyntaxKind.ExportSpecifier: + return emitImportOrExportSpecifier(node); case SyntaxKind.ImportEqualsDeclaration: return emitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: return emitExportDeclaration(node); + case SyntaxKind.ExportAssignment: + return emitExportAssignment(node); case SyntaxKind.SourceFile: return emitSourceFileNode(node); } @@ -5842,3 +6088,4 @@ module ts { } } } + diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 0851ad1690f0e..253daff86d392 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -436,11 +436,20 @@ module ts { return; } + let languageVersion = options.target || ScriptTarget.ES3; + let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (firstExternalModuleSourceFile && !options.module) { - // We cannot use createDiagnosticFromNode because nodes do not have parents yet - let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + if (!options.module && languageVersion < ScriptTarget.ES6) { + // We cannot use createDiagnosticFromNode because nodes do not have parents yet + let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + } + } + + // Cannot specify module gen target when in es6 or above + if (options.module && languageVersion >= ScriptTarget.ES6) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourcRoot diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 23200e50ee42b..a098b0e72c672 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,3 +1,5 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. @@ -18,9 +20,12 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ==== /// import m = require('constDeclarations_access_1'); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. // Errors m.x = 1; ~~~ diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js index 7acc95ad05501..313ce3db21a8c 100644 --- a/tests/baselines/reference/constDeclarations-access5.js +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -49,41 +49,37 @@ m.x.toString(); //// [constDeclarations_access_1.js] -define(["require", "exports"], function (require, exports) { - exports.x = 0; -}); +export const x = 0; //// [constDeclarations_access_2.js] -define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) { - // Errors - m.x = 1; - m.x += 2; - m.x -= 3; - m.x *= 4; - m.x /= 5; - m.x %= 6; - m.x <<= 7; - m.x >>= 8; - m.x >>>= 9; - m.x &= 10; - m.x |= 11; - m.x ^= 12; - m; - m.x++; - m.x--; - ++m.x; - --m.x; - ++((m.x)); - m["x"] = 0; - // OK - var a = m.x + 1; - function f(v) { - } - f(m.x); - if (m.x) { - } - m.x; - (m.x); - -m.x; - +m.x; - m.x.toString(); -}); +// Errors +m.x = 1; +m.x += 2; +m.x -= 3; +m.x *= 4; +m.x /= 5; +m.x %= 6; +m.x <<= 7; +m.x >>= 8; +m.x >>>= 9; +m.x &= 10; +m.x |= 11; +m.x ^= 12; +m; +m.x++; +m.x--; +++m.x; +--m.x; +++((m.x)); +m["x"] = 0; +// OK +var a = m.x + 1; +function f(v) { +} +f(m.x); +if (m.x) { +} +m.x; +(m.x); +-m.x; ++m.x; +m.x.toString(); diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js new file mode 100644 index 0000000000000..3ac92c5d9eaa5 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -0,0 +1,22 @@ +//// [es5ExportDefaultClassDeclaration.ts] + +export default class C { + method() { } +} + + +//// [es5ExportDefaultClassDeclaration.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + return C; +})(); +module.exports = C; + + +//// [es5ExportDefaultClassDeclaration.d.ts] +export declare class C { + method(): void; +} diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.types b/tests/baselines/reference/es5ExportDefaultClassDeclaration.types new file mode 100644 index 0000000000000..34fb87fcbb2bb --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es5ExportDefaultClassDeclaration.ts === + +export default class C { +>C : C + + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js new file mode 100644 index 0000000000000..8c07ff12599cc --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -0,0 +1,52 @@ +//// [es5ExportDefaultClassDeclaration2.ts] + +export default class { + method() { } +} + + +//// [es5ExportDefaultClassDeclaration2.js] +var _default = (function () { + function _default() { + } + _default.prototype.method = function () { + }; + return _default; +})(); +module.exports = _default; + + +//// [es5ExportDefaultClassDeclaration2.d.ts] +export declare 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/es5ExportDefaultClassDeclaration2.types b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types new file mode 100644 index 0000000000000..e4c7a59e0e740 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts === + +export default class { + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js new file mode 100644 index 0000000000000..f0c3da6657bdd --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -0,0 +1,11 @@ +//// [es5ExportDefaultExpression.ts] + +export default (1 + 2); + + +//// [es5ExportDefaultExpression.js] +module.exports = (1 + 2); + + +//// [es5ExportDefaultExpression.d.ts] +export default (1 + 2); diff --git a/tests/baselines/reference/es5ExportDefaultExpression.types b/tests/baselines/reference/es5ExportDefaultExpression.types new file mode 100644 index 0000000000000..2f4e2b5728499 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultExpression.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5ExportDefaultExpression.ts === + +export default (1 + 2); +>(1 + 2) : number +>1 + 2 : number + diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js new file mode 100644 index 0000000000000..015767435817d --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -0,0 +1,13 @@ +//// [es5ExportDefaultFunctionDeclaration.ts] + +export default function f() { } + + +//// [es5ExportDefaultFunctionDeclaration.js] +function f() { +} +module.exports = f; + + +//// [es5ExportDefaultFunctionDeclaration.d.ts] +export declare function f(): void; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types new file mode 100644 index 0000000000000..446bd8e2a3144 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts === + +export default function f() { } +>f : () => void + diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js new file mode 100644 index 0000000000000..6a99726655ff6 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -0,0 +1,26 @@ +//// [es5ExportDefaultFunctionDeclaration2.ts] + +export default function () { } + + +//// [es5ExportDefaultFunctionDeclaration2.js] +function () { +} +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 diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types new file mode 100644 index 0000000000000..1b9f9d2615114 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts === + +No type information for this code.export default function () { } +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.errors.txt b/tests/baselines/reference/es5ExportDefaultIdentifier.errors.txt new file mode 100644 index 0000000000000..7a4fdf52e887b --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es5ExportDefaultIdentifier.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/compiler/es5ExportDefaultIdentifier.ts (1 errors) ==== + + export function f() { } + + export default f; + ~~~~~~~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.js b/tests/baselines/reference/es5ExportDefaultIdentifier.js new file mode 100644 index 0000000000000..0c3a601308bf3 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.js @@ -0,0 +1,17 @@ +//// [es5ExportDefaultIdentifier.ts] + +export function f() { } + +export default f; + + +//// [es5ExportDefaultIdentifier.js] +function f() { +} +exports.f = f; +module.exports = f; + + +//// [es5ExportDefaultIdentifier.d.ts] +export declare function f(): void; +export default f; diff --git a/tests/baselines/reference/es5ExportEquals.errors.txt b/tests/baselines/reference/es5ExportEquals.errors.txt new file mode 100644 index 0000000000000..89197aca632c0 --- /dev/null +++ b/tests/baselines/reference/es5ExportEquals.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es5ExportEquals.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/compiler/es5ExportEquals.ts (1 errors) ==== + + export function f() { } + + export = f; + ~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportEquals.js b/tests/baselines/reference/es5ExportEquals.js new file mode 100644 index 0000000000000..04a34b1e23b0e --- /dev/null +++ b/tests/baselines/reference/es5ExportEquals.js @@ -0,0 +1,17 @@ +//// [es5ExportEquals.ts] + +export function f() { } + +export = f; + + +//// [es5ExportEquals.js] +function f() { +} +exports.f = f; +module.exports = f; + + +//// [es5ExportEquals.d.ts] +export declare function f(): void; +export = f; diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.js b/tests/baselines/reference/es5ModuleInternalNamedImports.js new file mode 100644 index 0000000000000..3d9966be7ddc4 --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.js @@ -0,0 +1,73 @@ +//// [es5ModuleInternalNamedImports.ts] + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} + + +//// [es5ModuleInternalNamedImports.js] +define(["require", "exports"], function (require, exports) { + var M; + (function (M) { + // variable + M.M_V = 0; + //calss + var M_C = (function () { + function M_C() { + } + return M_C; + })(); + M.M_C = M_C; + // instantiated module + var M_M; + (function (M_M) { + var x; + })(M_M = M.M_M || (M.M_M = {})); + // function + function M_F() { + } + M.M_F = M_F; + // enum + (function (M_E) { + })(M.M_E || (M.M_E = {})); + var M_E = M.M_E; + // alias + M.M_A = M_M; + // Reexports + M.v = M.M_V; + M.i = M_I; + M.c = M_C; + M.m = M_M; + M.mu = M_MU; + M.f = M_F; + M.e = M_E; + M.a = M.M_A; + })(M = exports.M || (exports.M = {})); +}); diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.types b/tests/baselines/reference/es5ModuleInternalNamedImports.types new file mode 100644 index 0000000000000..fa88ab399a3fc --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.types @@ -0,0 +1,77 @@ +=== tests/cases/compiler/es5ModuleInternalNamedImports.ts === + +export module M { +>M : typeof M + + // variable + export var M_V = 0; +>M_V : number + + // interface + export interface M_I { } +>M_I : M_I + + //calss + export class M_C { } +>M_C : M_C + + // instantiated module + export module M_M { var x; } +>M_M : typeof M_M +>x : any + + // uninstantiated module + export module M_MU { } +>M_MU : unknown + + // function + export function M_F() { } +>M_F : () => void + + // enum + export enum M_E { } +>M_E : M_E + + // type + export type M_T = number; +>M_T : number + + // alias + export import M_A = M_M; +>M_A : typeof M_M +>M_M : typeof M_M + + // Reexports + export {M_V as v}; +>M_V : number +>v : number + + export {M_I as i}; +>M_I : unknown +>i : unknown + + export {M_C as c}; +>M_C : typeof M_C +>c : typeof M_C + + export {M_M as m}; +>M_M : typeof M_M +>m : typeof M_M + + export {M_MU as mu}; +>M_MU : unknown +>mu : unknown + + export {M_F as f}; +>M_F : () => void +>f : () => void + + export {M_E as e}; +>M_E : typeof M_E +>e : typeof M_E + + export {M_A as a}; +>M_A : typeof M_M +>a : typeof M_M +} + diff --git a/tests/baselines/reference/es5ModuleWithModuleGenAmd.js b/tests/baselines/reference/es5ModuleWithModuleGenAmd.js new file mode 100644 index 0000000000000..f4757b539eb49 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithModuleGenAmd.js @@ -0,0 +1,25 @@ +//// [es5ModuleWithModuleGenAmd.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithModuleGenAmd.js] +define(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.A = A; +}); diff --git a/tests/baselines/reference/es6-declaration-amd.types b/tests/baselines/reference/es5ModuleWithModuleGenAmd.types similarity index 55% rename from tests/baselines/reference/es6-declaration-amd.types rename to tests/baselines/reference/es5ModuleWithModuleGenAmd.types index e275fc5243961..e3453587a121b 100644 --- a/tests/baselines/reference/es6-declaration-amd.types +++ b/tests/baselines/reference/es5ModuleWithModuleGenAmd.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-declaration-amd.ts === - -class A +=== tests/cases/compiler/es5ModuleWithModuleGenAmd.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js new file mode 100644 index 0000000000000..b4ca020f56677 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js @@ -0,0 +1,23 @@ +//// [es5ModuleWithModuleGenCommonjs.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithModuleGenCommonjs.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/baselines/reference/es6-sourcemap-amd.types b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types similarity index 53% rename from tests/baselines/reference/es6-sourcemap-amd.types rename to tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types index 661ab2e7cddfc..721df9afe58ef 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.types +++ b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-sourcemap-amd.ts === - -class A +=== tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt new file mode 100644 index 0000000000000..25e64fc72d0b7 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts (1 errors) ==== + export class A + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js new file mode 100644 index 0000000000000..4f663875adee9 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js @@ -0,0 +1,23 @@ +//// [es5ModuleWithoutModuleGenTarget.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithoutModuleGenTarget.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/baselines/reference/es6-amd.errors.txt b/tests/baselines/reference/es6-amd.errors.txt new file mode 100644 index 0000000000000..cb1ef4b1287aa --- /dev/null +++ b/tests/baselines/reference/es6-amd.errors.txt @@ -0,0 +1,18 @@ +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/es6-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.errors.txt b/tests/baselines/reference/es6-declaration-amd.errors.txt new file mode 100644 index 0000000000000..18319504dc9fd --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.errors.txt @@ -0,0 +1,18 @@ +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/es6-declaration-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.errors.txt b/tests/baselines/reference/es6-sourcemap-amd.errors.txt new file mode 100644 index 0000000000000..24a83f8ee12bf --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.errors.txt @@ -0,0 +1,18 @@ +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/es6-sourcemap-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js new file mode 100644 index 0000000000000..4c223545e8a28 --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.js @@ -0,0 +1,43 @@ +//// [tests/cases/compiler/es6ExportAll.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 * from "server"; + +//// [server.js] +export class c { +} +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export { m }; +export var x = 10; +//// [client.js] +export * from "server"; + + +//// [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] diff --git a/tests/baselines/reference/es6ExportAll.types b/tests/baselines/reference/es6ExportAll.types new file mode 100644 index 0000000000000..99e8fde9d4047 --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.types @@ -0,0 +1,24 @@ +=== 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 * from "server"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js new file mode 100644 index 0000000000000..9fd8c1c4b33e7 --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/es6ExportAllInEs5.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 * 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"); +for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; + + +//// [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] diff --git a/tests/baselines/reference/es6ExportAllInEs5.types b/tests/baselines/reference/es6ExportAllInEs5.types new file mode 100644 index 0000000000000..99e8fde9d4047 --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.types @@ -0,0 +1,24 @@ +=== 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 * from "server"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAssignment.errors.txt b/tests/baselines/reference/es6ExportAssignment.errors.txt new file mode 100644 index 0000000000000..1db7d04e05e9f --- /dev/null +++ b/tests/baselines/reference/es6ExportAssignment.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/es6ExportAssignment.ts (1 errors) ==== + + var a = 10; + 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/es6ExportAssignment.js b/tests/baselines/reference/es6ExportAssignment.js new file mode 100644 index 0000000000000..113e28108b166 --- /dev/null +++ b/tests/baselines/reference/es6ExportAssignment.js @@ -0,0 +1,8 @@ +//// [es6ExportAssignment.ts] + +var a = 10; +export = a; + +//// [es6ExportAssignment.js] +var a = 10; +export default a; diff --git a/tests/baselines/reference/es6ExportClause.js b/tests/baselines/reference/es6ExportClause.js new file mode 100644 index 0000000000000..9fd7a71554d5b --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.js @@ -0,0 +1,34 @@ +//// [es6ExportClause.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 }; + +//// [es6ExportClause.js] +class c { +} +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +var x = 10; +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + + +//// [es6ExportClause.d.ts] diff --git a/tests/baselines/reference/es6ExportClause.types b/tests/baselines/reference/es6ExportClause.types new file mode 100644 index 0000000000000..24b9859e0e84c --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/es6ExportClause.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 new file mode 100644 index 0000000000000..29cdc655397c4 --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -0,0 +1,51 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.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] +export class c { +} +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export { m }; +export var x = 10; +//// [client.js] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + + +//// [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] diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types new file mode 100644 index 0000000000000..c0087dccd943a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.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 new file mode 100644 index 0000000000000..f2682f0a18866 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js @@ -0,0 +1,18 @@ +//// [es6ExportDefaultClassDeclaration.ts] + +export default class C { + method() { } +} + + +//// [es6ExportDefaultClassDeclaration.js] +export default class C { + method() { + } +} + + +//// [es6ExportDefaultClassDeclaration.d.ts] +export declare class C { + method(): void; +} diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration.types b/tests/baselines/reference/es6ExportDefaultClassDeclaration.types new file mode 100644 index 0000000000000..59e74fc1257c5 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ExportDefaultClassDeclaration.ts === + +export default class C { +>C : C + + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js new file mode 100644 index 0000000000000..a975d4322f53a --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js @@ -0,0 +1,48 @@ +//// [es6ExportDefaultClassDeclaration2.ts] + +export default class { + method() { } +} + + +//// [es6ExportDefaultClassDeclaration2.js] +export default class { + method() { + } +} + + +//// [es6ExportDefaultClassDeclaration2.d.ts] +export declare 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/es6ExportDefaultClassDeclaration2.types b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types new file mode 100644 index 0000000000000..513cacf05e4d0 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts === + +export default class { + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es6ExportDefaultExpression.js b/tests/baselines/reference/es6ExportDefaultExpression.js new file mode 100644 index 0000000000000..e0d910437662d --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultExpression.js @@ -0,0 +1,11 @@ +//// [es6ExportDefaultExpression.ts] + +export default (1 + 2); + + +//// [es6ExportDefaultExpression.js] +export default (1 + 2); + + +//// [es6ExportDefaultExpression.d.ts] +export default (1 + 2); diff --git a/tests/baselines/reference/es6ExportDefaultExpression.types b/tests/baselines/reference/es6ExportDefaultExpression.types new file mode 100644 index 0000000000000..3b056b8d9f920 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultExpression.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es6ExportDefaultExpression.ts === + +export default (1 + 2); +>(1 + 2) : number +>1 + 2 : number + diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js new file mode 100644 index 0000000000000..fafc5a114f5a2 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js @@ -0,0 +1,12 @@ +//// [es6ExportDefaultFunctionDeclaration.ts] + +export default function f() { } + + +//// [es6ExportDefaultFunctionDeclaration.js] +export default function f() { +} + + +//// [es6ExportDefaultFunctionDeclaration.d.ts] +export declare function f(): void; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types new file mode 100644 index 0000000000000..6179bde9613aa --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts === + +export default function f() { } +>f : () => void + diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js new file mode 100644 index 0000000000000..2071e56c539b1 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js @@ -0,0 +1,25 @@ +//// [es6ExportDefaultFunctionDeclaration2.ts] + +export default function () { } + + +//// [es6ExportDefaultFunctionDeclaration2.js] +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 diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types new file mode 100644 index 0000000000000..3cb2fc9b1cd0c --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts === + +No type information for this code.export default function () { } +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportDefaultIdentifier.js b/tests/baselines/reference/es6ExportDefaultIdentifier.js new file mode 100644 index 0000000000000..5785220dfeefb --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultIdentifier.js @@ -0,0 +1,16 @@ +//// [es6ExportDefaultIdentifier.ts] + +export function f() { } + +export default f; + + +//// [es6ExportDefaultIdentifier.js] +export function f() { +} +export default f; + + +//// [es6ExportDefaultIdentifier.d.ts] +export declare function f(): void; +export default f; diff --git a/tests/baselines/reference/es6ExportDefaultIdentifier.types b/tests/baselines/reference/es6ExportDefaultIdentifier.types new file mode 100644 index 0000000000000..81dc168efd0cf --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultIdentifier.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ExportDefaultIdentifier.ts === + +export function f() { } +>f : () => void + +export default f; +>f : () => void + diff --git a/tests/baselines/reference/es6ExportEquals.errors.txt b/tests/baselines/reference/es6ExportEquals.errors.txt new file mode 100644 index 0000000000000..cc4206e2a5f3c --- /dev/null +++ b/tests/baselines/reference/es6ExportEquals.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es6ExportEquals.ts(4,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/es6ExportEquals.ts (1 errors) ==== + + export function f() { } + + export = f; + ~~~~~~~~~~~ +!!! 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/es6ExportEquals.js b/tests/baselines/reference/es6ExportEquals.js new file mode 100644 index 0000000000000..d51f8740da076 --- /dev/null +++ b/tests/baselines/reference/es6ExportEquals.js @@ -0,0 +1,16 @@ +//// [es6ExportEquals.ts] + +export function f() { } + +export = f; + + +//// [es6ExportEquals.js] +export function f() { +} +export default f; + + +//// [es6ExportEquals.d.ts] +export declare function f(): void; +export = f; diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt index 85390ecce4b8a..c07a84bb810d9 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External m ==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== import defaultBinding from "es6ImportDefaultBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index d8d1fa8111dc3..c7a320b76aabb 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -5,8 +5,14 @@ export var a = 10; //// [es6ImportDefaultBinding_1.ts] -import defaultBinding from "es6ImportDefaultBinding_0"; +import defaultBinding from "es6ImportDefaultBinding_0"; + //// [es6ImportDefaultBinding_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportDefaultBinding_1.js] + + +//// [es6ImportDefaultBinding_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js new file mode 100644 index 0000000000000..34b39cda4b77b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingAmd.ts] //// + +//// [es6ImportDefaultBindingAmd_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingAmd_1.ts] +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used + + +//// [es6ImportDefaultBindingAmd_0.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [es6ImportDefaultBindingAmd_1.js] +define(["require", "exports", "es6ImportDefaultBindingAmd_0"], function (require, exports, defaultBinding) { + var x = defaultBinding; +}); + + +//// [es6ImportDefaultBindingAmd_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.types b/tests/baselines/reference/es6ImportDefaultBindingAmd.types new file mode 100644 index 0000000000000..9b067ef27a405 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es6ImportDefaultBindingAmd_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingAmd_1.ts === +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +>defaultBinding : number + +var x = defaultBinding; +>x : number +>defaultBinding : number + +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt new file mode 100644 index 0000000000000..fc1e1a1925c63 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt @@ -0,0 +1,15 @@ +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 new file mode 100644 index 0000000000000..ad58abd8125a8 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingDts.ts] //// + +//// [server.ts] + +class c { } +export = c; + +//// [client.ts] +import defaultBinding from "server"; +export var x = new defaultBinding(); +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used + + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +module.exports = c; +//// [client.js] +var defaultBinding = require("server"); +exports.x = new defaultBinding(); + + +//// [server.d.ts] +declare class c { +} +export = c; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index bd8714cb86fe1..c755b8207e7d8 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -48,4 +48,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): e ~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file +!!! error TS2300: Duplicate identifier 'defaultBinding'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index a7402bfeb6a8e..d7196f86eaa7e 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -12,10 +12,18 @@ import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImpor 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 defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; +export var a = 10; +export var x = a; +export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] + + +//// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [es6ImportDefaultBindingFollowedWithNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt new file mode 100644 index 0000000000000..a780f7cec30f6 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt @@ -0,0 +1,42 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_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/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0.ts (1 errors) ==== + + 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/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + var x1: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + var x1: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js new file mode 100644 index 0000000000000..3c8a4080ba77b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js] +var a = 10; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js] +import defaultBinding1 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding1; +import defaultBinding2 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding2; +import defaultBinding3 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding3; +import defaultBinding4 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding4; +import defaultBinding5 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding5; +import defaultBinding6 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1 = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt new file mode 100644 index 0000000000000..91d51d5f7ef64 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt @@ -0,0 +1,61 @@ +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) ==== + + export class a { } + export class x { } + export class m { } + export class a11 { } + export class a12 { } + export class x11 { } + +==== tests/cases/compiler/client.ts (12 errors) ==== + import defaultBinding1, { } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + import defaultBinding2, { a } from "server"; + ~~~~~~~~~~~~~~~ +!!! 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 new file mode 100644 index 0000000000000..a6b2c9a16701a --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -0,0 +1,90 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class x { } +export class m { } +export class a11 { } +export class a12 { } +export class x11 { } + +//// [client.ts] +import defaultBinding1, { } from "server"; +import defaultBinding2, { a } from "server"; +export var x1 = new a(); +import defaultBinding3, { a11 as b } from "server"; +export var x2 = new b(); +import defaultBinding4, { x, a12 as y } from "server"; +export var x4 = new x(); +export var x5 = new y(); +import defaultBinding5, { x11 as z, } from "server"; +export var x3 = new z(); +import defaultBinding6, { m, } from "server"; +export var x6 = new m(); + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +//// [client.js] +var _server_1 = require("server"); +exports.x1 = new _server_1.a(); +var _server_2 = require("server"); +exports.x2 = new _server_2.a11(); +var _server_3 = require("server"); +exports.x4 = new _server_3.x(); +exports.x5 = new _server_3.a12(); +var _server_4 = require("server"); +exports.x3 = new _server_4.x11(); +var _server_5 = require("server"); +exports.x6 = new _server_5.m(); + + +//// [server.d.ts] +export declare class a { +} +export declare class x { +} +export declare class m { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x11 { +} diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt index 98371eb91988f..851a5189a5447 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1, ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 5ec91279306dd..2b24fda075559 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -5,8 +5,16 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +import * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.errors.txt new file mode 100644 index 0000000000000..2a0f3ad54850c --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_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/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts (1 errors) ==== + + 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/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (0 errors) ==== + import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; + var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js new file mode 100644 index 0000000000000..927ed3243e78b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] +var a = 10; +export default a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +import defaultBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x = defaultBinding; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js new file mode 100644 index 0000000000000..00166b1bc41fc --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var x = defaultBinding; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types new file mode 100644 index 0000000000000..dfbc8c0be07ce --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +>defaultBinding : number +>nameSpaceBinding : typeof nameSpaceBinding + +var x: number = defaultBinding; +>x : number +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt new file mode 100644 index 0000000000000..b82fb1155e94b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt @@ -0,0 +1,15 @@ +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) ==== + 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 diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js new file mode 100644 index 0000000000000..3068fb6d39dc7 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts] //// + +//// [server.ts] + +export class a { } + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.a(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = new nameSpaceBinding.a(); + + +//// [server.d.ts] +export declare class a { +} diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt new file mode 100644 index 0000000000000..3b09108bbfc3a --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt @@ -0,0 +1,13 @@ +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 new file mode 100644 index 0000000000000..708cffca29d1d --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts] //// + +//// [server.ts] + +class a { } +export = a; + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new defaultBinding(); + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = (function () { + function a() { + } + return a; + })(); + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = new defaultBinding(); +}); + + +//// [server.d.ts] +declare class a { +} +export = a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt new file mode 100644 index 0000000000000..d6aacf0ba4062 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(5,8): error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(7,8): error TS2300: Duplicate identifier 'defaultBinding3'. +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(8,8): error TS2300: Duplicate identifier 'defaultBinding3'. + + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts (3 errors) ==== + import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; + interface defaultBinding { // This is ok + } + var x = defaultBinding; + import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' + var defaultBinding2 = "hello world"; + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js new file mode 100644 index 0000000000000..628faec6c27cc --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts] //// + +//// [es6ImportDefaultBindingMergeErrors_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingMergeErrors_1.ts] +import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; +interface defaultBinding { // This is ok +} +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +var defaultBinding2 = "hello world"; +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + + +//// [es6ImportDefaultBindingMergeErrors_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingMergeErrors_1.js] +var defaultBinding = require("es6ImportDefaultBindingMergeErrors_0"); +var x = defaultBinding; +var defaultBinding2 = "hello world"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt new file mode 100644 index 0000000000000..a6aaf9f550866 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export or export assignment. + + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts (1 errors) ==== + import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export or export assignment. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js new file mode 100644 index 0000000000000..f824dbf71d56e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts] //// + +//// [es6ImportDefaultBindingNoDefaultProperty_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBindingNoDefaultProperty_1.ts] +import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + + +//// [es6ImportDefaultBindingNoDefaultProperty_0.js] +exports.a = 10; +//// [es6ImportDefaultBindingNoDefaultProperty_1.js] diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt new file mode 100644 index 0000000000000..d3351ee97b22c --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +tests/cases/compiler/server.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/client.ts (1 errors) ==== + import a = require("server"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1202: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +==== tests/cases/compiler/server.ts (1 errors) ==== + + var a = 10; + 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/es6ImportEqualsDeclaration.js b/tests/baselines/reference/es6ImportEqualsDeclaration.js new file mode 100644 index 0000000000000..b8e9777a894c5 --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/es6ImportEqualsDeclaration.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +import a = require("server"); + +//// [server.js] +var a = 10; +export default a; +//// [client.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index c6daa3b122255..4f03e9a0ae29d 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -5,8 +5,14 @@ export var a = 10; //// [es6ImportNameSpaceImport_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; + //// [es6ImportNameSpaceImport_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportNameSpaceImport_1.js] + + +//// [es6ImportNameSpaceImport_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..98a6887083390 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(4,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(5,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(7,8): error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts (3 errors) ==== + import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; + interface nameSpaceBinding { } // this should be ok + + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + + import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + var nameSpaceBinding3 = 10; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js new file mode 100644 index 0000000000000..3c8461fba2b70 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts] //// + +//// [es6ImportNameSpaceImportMergeErrors_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportMergeErrors_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; +interface nameSpaceBinding { } // this should be ok + +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + +import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +var nameSpaceBinding3 = 10; + + +//// [es6ImportNameSpaceImportMergeErrors_0.js] +exports.a = 10; +//// [es6ImportNameSpaceImportMergeErrors_1.js] +var nameSpaceBinding3 = 10; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js new file mode 100644 index 0000000000000..3d6dab177851d --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts] //// + +//// [es6ImportNameSpaceImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNameSpaceImportNoNamedExports_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error + +//// [es6ImportNameSpaceImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNameSpaceImportNoNamedExports_1.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types new file mode 100644 index 0000000000000..3ba19cef9b443 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error +>nameSpaceBinding : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index c52499ef994a7..7993af7fb079f 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -16,12 +16,22 @@ import { x, a as y } from "es6ImportNamedImport_0"; import { x as z, } from "es6ImportNamedImport_0"; import { m, } from "es6ImportNamedImport_0"; import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; + //// [es6ImportNamedImport_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; -exports.a1 = 10; -exports.x1 = 10; +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; //// [es6ImportNamedImport_1.js] + + +//// [es6ImportNamedImport_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; +//// [es6ImportNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js new file mode 100644 index 0000000000000..cd2d5ef6922e8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts] //// + +//// [es6ImportNamedImportInExportAssignment_0.ts] + +export var a = 10; + +//// [es6ImportNamedImportInExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; + +//// [es6ImportNamedImportInExportAssignment_0.js] +exports.a = 10; +//// [es6ImportNamedImportInExportAssignment_1.js] +var _es6ImportNamedImportInExportAssignment_0 = require("es6ImportNamedImportInExportAssignment_0"); +module.exports = _es6ImportNamedImportInExportAssignment_0.a; + + +//// [es6ImportNamedImportInExportAssignment_0.d.ts] +export declare var a: number; +//// [es6ImportNamedImportInExportAssignment_1.d.ts] +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 new file mode 100644 index 0000000000000..cd72f35c8bf8b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types @@ -0,0 +1,12 @@ +=== 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 new file mode 100644 index 0000000000000..e896a1a88a143 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt @@ -0,0 +1,16 @@ +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 new file mode 100644 index 0000000000000..332be6074ad40 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts] //// + +//// [es6ImportNamedImportInIndirectExportAssignment_0.ts] + +export module a { + export class c { + } +} + +//// [es6ImportNamedImportInIndirectExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; + +//// [es6ImportNamedImportInIndirectExportAssignment_0.js] +var a; +(function (a) { + var c = (function () { + function c() { + } + return c; + })(); + a.c = c; +})(a = exports.a || (exports.a = {})); +//// [es6ImportNamedImportInIndirectExportAssignment_1.js] +var _es6ImportNamedImportInIndirectExportAssignment_0 = require("es6ImportNamedImportInIndirectExportAssignment_0"); +var x = _es6ImportNamedImportInIndirectExportAssignment_0.a; +module.exports = x; + + +//// [es6ImportNamedImportInIndirectExportAssignment_0.d.ts] +export declare module a { + class c { + } +} diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..b9461b6caca06 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'x' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(7,10): error TS2440: Import declaration conflicts with local declaration of 'x44' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(9,10): error TS2300: Duplicate identifier 'z'. +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(10,16): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var z = a; + export var z1 = a; + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts (4 errors) ==== + import { a } from "es6ImportNamedImportMergeErrors_0"; + interface a { } // shouldnt be error + import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; + interface x1 { } // shouldnt be error + import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x' + var x = 10; + import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x44' + var x44 = 10; + import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.js b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js new file mode 100644 index 0000000000000..fad411f557d55 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNamedImportMergeErrors.ts] //// + +//// [es6ImportNamedImportMergeErrors_0.ts] + +export var a = 10; +export var x = a; +export var z = a; +export var z1 = a; + +//// [es6ImportNamedImportMergeErrors_1.ts] +import { a } from "es6ImportNamedImportMergeErrors_0"; +interface a { } // shouldnt be error +import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; +interface x1 { } // shouldnt be error +import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x = 10; +import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x44 = 10; +import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error +import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + + +//// [es6ImportNamedImportMergeErrors_0.js] +exports.a = 10; +exports.x = exports.a; +exports.z = exports.a; +exports.z1 = exports.a; +//// [es6ImportNamedImportMergeErrors_1.js] +var x = 10; +var x44 = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt new file mode 100644 index 0000000000000..57a77410cb24b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImport_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. +tests/cases/compiler/es6ImportNamedImport_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. + + +==== tests/cases/compiler/es6ImportNamedImportNoExportMember_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + +==== tests/cases/compiler/es6ImportNamedImport_1.ts (2 errors) ==== + import { a1 } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. + import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.js b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js new file mode 100644 index 0000000000000..da473fa42a38d --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoExportMember.ts] //// + +//// [es6ImportNamedImportNoExportMember_0.ts] + +export var a = 10; +export var x = a; + +//// [es6ImportNamedImport_1.ts] +import { a1 } from "es6ImportNamedImportNoExportMember_0"; +import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + +//// [es6ImportNamedImportNoExportMember_0.js] +exports.a = 10; +exports.x = exports.a; +//// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt new file mode 100644 index 0000000000000..a5abd986ee857 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts (2 errors) ==== + import { a } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js new file mode 100644 index 0000000000000..524860827e6e8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts] //// + +//// [es6ImportNamedImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNamedImportNoNamedExports_1.ts] +import { a } from "es6ImportNamedImportNoNamedExports_0"; +import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + +//// [es6ImportNamedImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNamedImportNoNamedExports_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index f9d8e90f707f1..81f141b3dd858 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -13,16 +13,16 @@ import , { a } from "es6ImportNamedImportParsingError_0"; import { a }, from "es6ImportNamedImportParsingError_0"; //// [es6ImportNamedImportParsingError_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; +export var a = 10; +export var x = a; +export var m = a; //// [es6ImportNamedImportParsingError_1.js] from; "es6ImportNamedImportParsingError_0"; { - _module_1.a; + a; } from; "es6ImportNamedImportParsingError_0"; -var _module_1 = require(); +import { a } from , from; "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 43d21885c2701..9666409b9249a 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -5,9 +5,15 @@ export var a = 10; //// [es6ImportWithoutFromClause_1.ts] -import "es6ImportWithoutFromClause_0"; +import "es6ImportWithoutFromClause_0"; + //// [es6ImportWithoutFromClause_0.js] -exports.a = 10; +export var a = 10; //// [es6ImportWithoutFromClause_1.js] -require("es6ImportWithoutFromClause_0"); +import "es6ImportWithoutFromClause_0"; + + +//// [es6ImportWithoutFromClause_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClause_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.types b/tests/baselines/reference/es6ImportWithoutFromClause.types index 1cd7df9962ee7..3cc5067891ad2 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.types +++ b/tests/baselines/reference/es6ImportWithoutFromClause.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportWithoutFromClause_1.ts === import "es6ImportWithoutFromClause_0"; +No type information for this code. No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js new file mode 100644 index 0000000000000..e63dd4bb53a0e --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts] //// + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.ts] + +export interface i { +} + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js] +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; + + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts] +export interface i { +} +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types new file mode 100644 index 0000000000000..2be3f67f1e963 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_0.ts === + +export interface i { +>i : i +} + +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_1.ts === +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6Module.js b/tests/baselines/reference/es6Module.js new file mode 100644 index 0000000000000..d3141572c924a --- /dev/null +++ b/tests/baselines/reference/es6Module.js @@ -0,0 +1,21 @@ +//// [es6Module.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6Module.js] +export class A { + constructor() { + } + B() { + return 42; + } +} diff --git a/tests/baselines/reference/es6-amd.types b/tests/baselines/reference/es6Module.types similarity index 60% rename from tests/baselines/reference/es6-amd.types rename to tests/baselines/reference/es6Module.types index 62815911f7f97..9391020021526 100644 --- a/tests/baselines/reference/es6-amd.types +++ b/tests/baselines/reference/es6Module.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-amd.ts === - -class A +=== tests/cases/compiler/es6Module.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.js b/tests/baselines/reference/es6ModuleClassDeclaration.js new file mode 100644 index 0000000000000..9676720fd0f1a --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.js @@ -0,0 +1,231 @@ +//// [es6ModuleClassDeclaration.ts] +export class c { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +class c2 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +new c(); +new c2(); + +export module m1 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); +} +module m2 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +} + +//// [es6ModuleClassDeclaration.js] +export class c { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } +} +c.k = 20; +c.l = 30; +class c2 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } +} +c2.k = 20; +c2.l = 30; +new c(); +new c2(); +var m1; +(function (m1) { + class c3 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c3.k = 20; + c3.l = 30; + m1.c3 = c3; + class c4 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c4.k = 20; + c4.l = 30; + new c(); + new c2(); + new c3(); + new c4(); +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + class c3 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c3.k = 20; + c3.l = 30; + m2.c3 = c3; + class c4 { + constructor() { + this.x = 10; + this.y = 30; + } + method1() { + } + method2() { + } + static method3() { + } + static method4() { + } + } + c4.k = 20; + c4.l = 30; + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.types b/tests/baselines/reference/es6ModuleClassDeclaration.types new file mode 100644 index 0000000000000..09d50c4e542d5 --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.types @@ -0,0 +1,233 @@ +=== tests/cases/compiler/es6ModuleClassDeclaration.ts === +export class c { +>c : c + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +class c2 { +>c2 : c2 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +new c(); +>new c() : c +>c : typeof c + +new c2(); +>new c2() : c2 +>c2 : typeof c2 + +export module m1 { +>m1 : typeof m1 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 +} +module m2 { +>m2 : typeof m2 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 + + new m1.c3(); +>new m1.c3() : m1.c3 +>m1.c3 : typeof m1.c3 +>m1 : typeof m1 +>c3 : typeof m1.c3 +} diff --git a/tests/baselines/reference/es6ModuleConst.js b/tests/baselines/reference/es6ModuleConst.js new file mode 100644 index 0000000000000..2a11ec638a16c --- /dev/null +++ b/tests/baselines/reference/es6ModuleConst.js @@ -0,0 +1,38 @@ +//// [es6ModuleConst.ts] +export const a = "hello"; +export const x: string = a, y = x; +const b = y; +const c: string = b, d = c; +export module m1 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} +module m2 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} + +//// [es6ModuleConst.js] +export const a = "hello"; +export const x = a, y = x; +const b = y; +const c = b, d = c; +var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + const n = m1.k; + const o = n, p = m1.k; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + const n = m1.k; + const o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConst.types b/tests/baselines/reference/es6ModuleConst.types new file mode 100644 index 0000000000000..cceb74a5e1ed5 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConst.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleConst.ts === +export const a = "hello"; +>a : string + +export const x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +const b = y; +>b : string +>y : string + +const c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export const k = a; +>k : string +>a : string + + export const l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + const n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + const o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export const k = a; +>k : string +>a : string + + export const l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + const n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + const o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js new file mode 100644 index 0000000000000..c8096c76c8e20 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js @@ -0,0 +1,66 @@ +//// [es6ModuleConstEnumDeclaration.ts] +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleConstEnumDeclaration.js] +var x = 0 /* a */; +var y = 0 /* x */; +var m1; +(function (m1) { + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration.types b/tests/baselines/reference/es6ModuleConstEnumDeclaration.types new file mode 100644 index 0000000000000..fae819f93b06f --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration.types @@ -0,0 +1,147 @@ +=== tests/cases/compiler/es6ModuleConstEnumDeclaration.ts === +export const enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +const enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export const enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + const enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export const enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + const enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js new file mode 100644 index 0000000000000..5ec953aca88a1 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js @@ -0,0 +1,104 @@ +//// [es6ModuleConstEnumDeclaration2.ts] + +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleConstEnumDeclaration2.js] +var e1; +(function (e1) { + e1[e1["a"] = 0] = "a"; + e1[e1["b"] = 1] = "b"; + e1[e1["c"] = 2] = "c"; +})(e1 || (e1 = {})); +export { e1 }; +var e2; +(function (e2) { + e2[e2["x"] = 0] = "x"; + e2[e2["y"] = 1] = "y"; + e2[e2["z"] = 2] = "z"; +})(e2 || (e2 = {})); +var x = 0 /* a */; +var y = 0 /* x */; +var m1; +(function (m1) { + (function (e3) { + e3[e3["a"] = 0] = "a"; + e3[e3["b"] = 1] = "b"; + e3[e3["c"] = 2] = "c"; + })(m1.e3 || (m1.e3 = {})); + var e3 = m1.e3; + var e4; + (function (e4) { + e4[e4["x"] = 0] = "x"; + e4[e4["y"] = 1] = "y"; + e4[e4["z"] = 2] = "z"; + })(e4 || (e4 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + (function (e5) { + e5[e5["a"] = 0] = "a"; + e5[e5["b"] = 1] = "b"; + e5[e5["c"] = 2] = "c"; + })(m2.e5 || (m2.e5 = {})); + var e5 = m2.e5; + var e6; + (function (e6) { + e6[e6["x"] = 0] = "x"; + e6[e6["y"] = 1] = "y"; + e6[e6["z"] = 2] = "z"; + })(e6 || (e6 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types new file mode 100644 index 0000000000000..c43a938c9b6a8 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types @@ -0,0 +1,148 @@ +=== tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts === + +export const enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +const enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export const enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + const enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export const enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + const enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.js b/tests/baselines/reference/es6ModuleEnumDeclaration.js new file mode 100644 index 0000000000000..955fe3ed8d3f8 --- /dev/null +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.js @@ -0,0 +1,103 @@ +//// [es6ModuleEnumDeclaration.ts] +export enum e1 { + a, + b, + c +} +enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export enum e3 { + a, + b, + c + } + enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export enum e5 { + a, + b, + c + } + enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleEnumDeclaration.js] +var e1; +(function (e1) { + e1[e1["a"] = 0] = "a"; + e1[e1["b"] = 1] = "b"; + e1[e1["c"] = 2] = "c"; +})(e1 || (e1 = {})); +export { e1 }; +var e2; +(function (e2) { + e2[e2["x"] = 0] = "x"; + e2[e2["y"] = 1] = "y"; + e2[e2["z"] = 2] = "z"; +})(e2 || (e2 = {})); +var x = 0 /* a */; +var y = 0 /* x */; +var m1; +(function (m1) { + (function (e3) { + e3[e3["a"] = 0] = "a"; + e3[e3["b"] = 1] = "b"; + e3[e3["c"] = 2] = "c"; + })(m1.e3 || (m1.e3 = {})); + var e3 = m1.e3; + var e4; + (function (e4) { + e4[e4["x"] = 0] = "x"; + e4[e4["y"] = 1] = "y"; + e4[e4["z"] = 2] = "z"; + })(e4 || (e4 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + (function (e5) { + e5[e5["a"] = 0] = "a"; + e5[e5["b"] = 1] = "b"; + e5[e5["c"] = 2] = "c"; + })(m2.e5 || (m2.e5 = {})); + var e5 = m2.e5; + var e6; + (function (e6) { + e6[e6["x"] = 0] = "x"; + e6[e6["y"] = 1] = "y"; + e6[e6["z"] = 2] = "z"; + })(e6 || (e6 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.types b/tests/baselines/reference/es6ModuleEnumDeclaration.types new file mode 100644 index 0000000000000..4b856fee00902 --- /dev/null +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.types @@ -0,0 +1,147 @@ +=== tests/cases/compiler/es6ModuleEnumDeclaration.ts === +export enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleFunctionDeclaration.js b/tests/baselines/reference/es6ModuleFunctionDeclaration.js new file mode 100644 index 0000000000000..4c1fc33647c71 --- /dev/null +++ b/tests/baselines/reference/es6ModuleFunctionDeclaration.js @@ -0,0 +1,63 @@ +//// [es6ModuleFunctionDeclaration.ts] +export function foo() { +} +function foo2() { +} +foo(); +foo2(); + +export module m1 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +} +module m2 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +} + +//// [es6ModuleFunctionDeclaration.js] +export function foo() { +} +function foo2() { +} +foo(); +foo2(); +var m1; +(function (m1) { + function foo3() { + } + m1.foo3 = foo3; + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + function foo3() { + } + m2.foo3 = foo3; + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleFunctionDeclaration.types b/tests/baselines/reference/es6ModuleFunctionDeclaration.types new file mode 100644 index 0000000000000..b1252c1e8bcd3 --- /dev/null +++ b/tests/baselines/reference/es6ModuleFunctionDeclaration.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/es6ModuleFunctionDeclaration.ts === +export function foo() { +>foo : () => void +} +function foo2() { +>foo2 : () => void +} +foo(); +>foo() : void +>foo : () => void + +foo2(); +>foo2() : void +>foo2 : () => void + +export module m1 { +>m1 : typeof m1 + + export function foo3() { +>foo3 : () => void + } + function foo4() { +>foo4 : () => void + } + foo(); +>foo() : void +>foo : () => void + + foo2(); +>foo2() : void +>foo2 : () => void + + foo3(); +>foo3() : void +>foo3 : () => void + + foo4(); +>foo4() : void +>foo4 : () => void +} +module m2 { +>m2 : typeof m2 + + export function foo3() { +>foo3 : () => void + } + function foo4() { +>foo4 : () => void + } + foo(); +>foo() : void +>foo : () => void + + foo2(); +>foo2() : void +>foo2 : () => void + + foo3(); +>foo3() : void +>foo3 : () => void + + foo4(); +>foo4() : void +>foo4 : () => void + + m1.foo3(); +>m1.foo3() : void +>m1.foo3 : () => void +>m1 : typeof m1 +>foo3 : () => void +} diff --git a/tests/baselines/reference/es6ModuleInternalImport.js b/tests/baselines/reference/es6ModuleInternalImport.js new file mode 100644 index 0000000000000..4a1659cb90167 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalImport.js @@ -0,0 +1,46 @@ +//// [es6ModuleInternalImport.ts] +export module m { + export var a = 10; +} +export import a1 = m.a; +import a2 = m.a; +var x = a1 + a2; +export module m1 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; +} +module m2 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; + var x4 = m1.a3 + m2.a3; +} + +//// [es6ModuleInternalImport.js] +var m; +(function (m) { + m.a = 10; +})(m || (m = {})); +export { m }; +export var a1 = m.a; +var a2 = m.a; +var x = a1 + a2; +var m1; +(function (m1) { + m1.a3 = m.a; + var a4 = m.a; + var x = a1 + a2; + var x2 = m1.a3 + a4; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + m2.a3 = m.a; + var a4 = m.a; + var x = a1 + a2; + var x2 = m2.a3 + a4; + var x4 = m1.a3 + m2.a3; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleInternalImport.types b/tests/baselines/reference/es6ModuleInternalImport.types new file mode 100644 index 0000000000000..50db69d8edb22 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalImport.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/es6ModuleInternalImport.ts === +export module m { +>m : typeof m + + export var a = 10; +>a : number +} +export import a1 = m.a; +>a1 : number +>m : typeof m +>a : number + +import a2 = m.a; +>a2 : number +>m : typeof m +>a : number + +var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + +export module m1 { +>m1 : typeof m1 + + export import a3 = m.a; +>a3 : number +>m : typeof m +>a : number + + import a4 = m.a; +>a4 : number +>m : typeof m +>a : number + + var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + + var x2 = a3 + a4; +>x2 : number +>a3 + a4 : number +>a3 : number +>a4 : number +} +module m2 { +>m2 : typeof m2 + + export import a3 = m.a; +>a3 : number +>m : typeof m +>a : number + + import a4 = m.a; +>a4 : number +>m : typeof m +>a : number + + var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + + var x2 = a3 + a4; +>x2 : number +>a3 + a4 : number +>a3 : number +>a4 : number + + var x4 = m1.a3 + m2.a3; +>x4 : number +>m1.a3 + m2.a3 : number +>m1.a3 : number +>m1 : typeof m1 +>a3 : number +>m2.a3 : number +>m2 : typeof m2 +>a3 : number +} diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.js b/tests/baselines/reference/es6ModuleInternalNamedImports.js new file mode 100644 index 0000000000000..532025c4ee68d --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.js @@ -0,0 +1,69 @@ +//// [es6ModuleInternalNamedImports.ts] + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} + + +//// [es6ModuleInternalNamedImports.js] +var M; +(function (M) { + // variable + M.M_V = 0; + //calss + class M_C { + } + M.M_C = M_C; + // instantiated module + var M_M; + (function (M_M) { + var x; + })(M_M = M.M_M || (M.M_M = {})); + // function + function M_F() { + } + M.M_F = M_F; + // enum + (function (M_E) { + })(M.M_E || (M.M_E = {})); + var M_E = M.M_E; + // alias + M.M_A = M_M; + // Reexports + M.v = M.M_V; + M.i = M_I; + M.c = M_C; + M.m = M_M; + M.mu = M_MU; + M.f = M_F; + M.e = M_E; + M.a = M.M_A; +})(M || (M = {})); +export { M }; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.types b/tests/baselines/reference/es6ModuleInternalNamedImports.types new file mode 100644 index 0000000000000..6b614926a0af6 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.types @@ -0,0 +1,77 @@ +=== tests/cases/compiler/es6ModuleInternalNamedImports.ts === + +export module M { +>M : typeof M + + // variable + export var M_V = 0; +>M_V : number + + // interface + export interface M_I { } +>M_I : M_I + + //calss + export class M_C { } +>M_C : M_C + + // instantiated module + export module M_M { var x; } +>M_M : typeof M_M +>x : any + + // uninstantiated module + export module M_MU { } +>M_MU : unknown + + // function + export function M_F() { } +>M_F : () => void + + // enum + export enum M_E { } +>M_E : M_E + + // type + export type M_T = number; +>M_T : number + + // alias + export import M_A = M_M; +>M_A : typeof M_M +>M_M : typeof M_M + + // Reexports + export {M_V as v}; +>M_V : number +>v : number + + export {M_I as i}; +>M_I : unknown +>i : unknown + + export {M_C as c}; +>M_C : typeof M_C +>c : typeof M_C + + export {M_M as m}; +>M_M : typeof M_M +>m : typeof M_M + + export {M_MU as mu}; +>M_MU : unknown +>mu : unknown + + export {M_F as f}; +>M_F : () => void +>f : () => void + + export {M_E as e}; +>M_E : typeof M_E +>e : typeof M_E + + export {M_A as a}; +>M_A : typeof M_M +>a : typeof M_M +} + diff --git a/tests/baselines/reference/es6ModuleLet.js b/tests/baselines/reference/es6ModuleLet.js new file mode 100644 index 0000000000000..275fd39579e71 --- /dev/null +++ b/tests/baselines/reference/es6ModuleLet.js @@ -0,0 +1,38 @@ +//// [es6ModuleLet.ts] +export let a = "hello"; +export let x: string = a, y = x; +let b = y; +let c: string = b, d = c; +export module m1 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} +module m2 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} + +//// [es6ModuleLet.js] +export let a = "hello"; +export let x = a, y = x; +let b = y; +let c = b, d = c; +var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + let n = m1.k; + let o = n, p = m1.k; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + let n = m1.k; + let o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleLet.types b/tests/baselines/reference/es6ModuleLet.types new file mode 100644 index 0000000000000..4b30c89cc819c --- /dev/null +++ b/tests/baselines/reference/es6ModuleLet.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleLet.ts === +export let a = "hello"; +>a : string + +export let x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +let b = y; +>b : string +>y : string + +let c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export let k = a; +>k : string +>a : string + + export let l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + let n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + let o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export let k = a; +>k : string +>a : string + + export let l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + let n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + let o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleModuleDeclaration.js b/tests/baselines/reference/es6ModuleModuleDeclaration.js new file mode 100644 index 0000000000000..1e3716ac8c20e --- /dev/null +++ b/tests/baselines/reference/es6ModuleModuleDeclaration.js @@ -0,0 +1,58 @@ +//// [es6ModuleModuleDeclaration.ts] +export module m1 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} +module m2 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} + +//// [es6ModuleModuleDeclaration.js] +var m1; +(function (m1) { + m1.a = 10; + var b = 10; + var innerExportedModule; + (function (innerExportedModule) { + innerExportedModule.k = 10; + var l = 10; + })(innerExportedModule = m1.innerExportedModule || (m1.innerExportedModule = {})); + var innerNonExportedModule; + (function (innerNonExportedModule) { + innerNonExportedModule.x = 10; + var y = 10; + })(innerNonExportedModule = m1.innerNonExportedModule || (m1.innerNonExportedModule = {})); +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + m2.a = 10; + var b = 10; + var innerExportedModule; + (function (innerExportedModule) { + innerExportedModule.k = 10; + var l = 10; + })(innerExportedModule = m2.innerExportedModule || (m2.innerExportedModule = {})); + var innerNonExportedModule; + (function (innerNonExportedModule) { + innerNonExportedModule.x = 10; + var y = 10; + })(innerNonExportedModule = m2.innerNonExportedModule || (m2.innerNonExportedModule = {})); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleModuleDeclaration.types b/tests/baselines/reference/es6ModuleModuleDeclaration.types new file mode 100644 index 0000000000000..c174fe6f8c7c6 --- /dev/null +++ b/tests/baselines/reference/es6ModuleModuleDeclaration.types @@ -0,0 +1,57 @@ +=== tests/cases/compiler/es6ModuleModuleDeclaration.ts === +export module m1 { +>m1 : typeof m1 + + export var a = 10; +>a : number + + var b = 10; +>b : number + + export module innerExportedModule { +>innerExportedModule : typeof innerExportedModule + + export var k = 10; +>k : number + + var l = 10; +>l : number + } + export module innerNonExportedModule { +>innerNonExportedModule : typeof innerNonExportedModule + + export var x = 10; +>x : number + + var y = 10; +>y : number + } +} +module m2 { +>m2 : typeof m2 + + export var a = 10; +>a : number + + var b = 10; +>b : number + + export module innerExportedModule { +>innerExportedModule : typeof innerExportedModule + + export var k = 10; +>k : number + + var l = 10; +>l : number + } + export module innerNonExportedModule { +>innerNonExportedModule : typeof innerNonExportedModule + + export var x = 10; +>x : number + + var y = 10; +>y : number + } +} diff --git a/tests/baselines/reference/es6ModuleVariableStatement.js b/tests/baselines/reference/es6ModuleVariableStatement.js new file mode 100644 index 0000000000000..11b60555b0dba --- /dev/null +++ b/tests/baselines/reference/es6ModuleVariableStatement.js @@ -0,0 +1,38 @@ +//// [es6ModuleVariableStatement.ts] +export var a = "hello"; +export var x: string = a, y = x; +var b = y; +var c: string = b, d = c; +export module m1 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} +module m2 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} + +//// [es6ModuleVariableStatement.js] +export var a = "hello"; +export var x = a, y = x; +var b = y; +var c = b, d = c; +var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + var n = m1.k; + var o = n, p = m1.k; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + var n = m1.k; + var o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleVariableStatement.types b/tests/baselines/reference/es6ModuleVariableStatement.types new file mode 100644 index 0000000000000..a10d8f6cacbc4 --- /dev/null +++ b/tests/baselines/reference/es6ModuleVariableStatement.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleVariableStatement.ts === +export var a = "hello"; +>a : string + +export var x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +var b = y; +>b : string +>y : string + +var c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export var k = a; +>k : string +>a : string + + export var l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + var n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + var o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export var k = a; +>k : string +>a : string + + export var l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + var n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + var o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt new file mode 100644 index 0000000000000..bbe0d8b78b65f --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt @@ -0,0 +1,16 @@ +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/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ==== + export class A + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js new file mode 100644 index 0000000000000..8757bd1c88f52 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -0,0 +1,21 @@ +//// [es6ModuleWithModuleGenTargetAmd.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6ModuleWithModuleGenTargetAmd.js] +export class A { + constructor() { + } + B() { + return 42; + } +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt new file mode 100644 index 0000000000000..87f53cb781041 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt @@ -0,0 +1,16 @@ +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/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ==== + export class A + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js new file mode 100644 index 0000000000000..2df98e20826aa --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js @@ -0,0 +1,21 @@ +//// [es6ModuleWithModuleGenTargetCommonjs.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6ModuleWithModuleGenTargetCommonjs.js] +export class A { + constructor() { + } + B() { + return 42; + } +} diff --git a/tests/baselines/reference/symbolDeclarationEmit12.js b/tests/baselines/reference/symbolDeclarationEmit12.js index 9a75f6d573cb8..ab930b41580a3 100644 --- a/tests/baselines/reference/symbolDeclarationEmit12.js +++ b/tests/baselines/reference/symbolDeclarationEmit12.js @@ -15,7 +15,7 @@ module M { //// [symbolDeclarationEmit12.js] var M; (function (M) { - export class C { + class C { [Symbol.toPrimitive](x) { } [Symbol.isConcatSpreadable]() { @@ -27,4 +27,5 @@ var M; set [Symbol.isRegExp](x) { } } + M.C = C; })(M || (M = {})); diff --git a/tests/cases/compiler/es5ExportDefaultClassDeclaration.ts b/tests/cases/compiler/es5ExportDefaultClassDeclaration.ts new file mode 100644 index 0000000000000..bea07832cd564 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultClassDeclaration.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default class C { + method() { } +} diff --git a/tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts b/tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts new file mode 100644 index 0000000000000..e7ae24f5d879f --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default class { + method() { } +} diff --git a/tests/cases/compiler/es5ExportDefaultExpression.ts b/tests/cases/compiler/es5ExportDefaultExpression.ts new file mode 100644 index 0000000000000..772998decefa6 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultExpression.ts @@ -0,0 +1,5 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default (1 + 2); diff --git a/tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts new file mode 100644 index 0000000000000..ef9da753ab063 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts @@ -0,0 +1,5 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default function f() { } diff --git a/tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts new file mode 100644 index 0000000000000..2b8a99a381780 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts @@ -0,0 +1,5 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default function () { } diff --git a/tests/cases/compiler/es5ExportDefaultIdentifier.ts b/tests/cases/compiler/es5ExportDefaultIdentifier.ts new file mode 100644 index 0000000000000..8f34253208ed7 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultIdentifier.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export function f() { } + +export default f; diff --git a/tests/cases/compiler/es5ExportEquals.ts b/tests/cases/compiler/es5ExportEquals.ts new file mode 100644 index 0000000000000..5016bdb7b1ba0 --- /dev/null +++ b/tests/cases/compiler/es5ExportEquals.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export function f() { } + +export = f; diff --git a/tests/cases/compiler/es5ModuleInternalNamedImports.ts b/tests/cases/compiler/es5ModuleInternalNamedImports.ts new file mode 100644 index 0000000000000..05943d1c67e7a --- /dev/null +++ b/tests/cases/compiler/es5ModuleInternalNamedImports.ts @@ -0,0 +1,33 @@ +// @target: ES5 +// @module: AMD + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} diff --git a/tests/cases/compiler/es5ModuleWithModuleGenAmd.ts b/tests/cases/compiler/es5ModuleWithModuleGenAmd.ts new file mode 100644 index 0000000000000..051c77f808e07 --- /dev/null +++ b/tests/cases/compiler/es5ModuleWithModuleGenAmd.ts @@ -0,0 +1,13 @@ +// @target: ES5 +// @module: amd +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts b/tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts new file mode 100644 index 0000000000000..31720bddbcbbe --- /dev/null +++ b/tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts @@ -0,0 +1,13 @@ +// @target: ES5 +// @module: commonjs +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts b/tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts new file mode 100644 index 0000000000000..c9504ef9fcbd9 --- /dev/null +++ b/tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts @@ -0,0 +1,12 @@ +// @target: ES5 +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportAll.ts b/tests/cases/compiler/es6ExportAll.ts new file mode 100644 index 0000000000000..ed2b47c23c454 --- /dev/null +++ b/tests/cases/compiler/es6ExportAll.ts @@ -0,0 +1,17 @@ +// @target: es6 +// @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 * from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportAllInEs5.ts b/tests/cases/compiler/es6ExportAllInEs5.ts new file mode 100644 index 0000000000000..ed754e5cacbb5 --- /dev/null +++ b/tests/cases/compiler/es6ExportAllInEs5.ts @@ -0,0 +1,18 @@ +// @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 * from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportAssignment.ts b/tests/cases/compiler/es6ExportAssignment.ts new file mode 100644 index 0000000000000..f1f2cce99235b --- /dev/null +++ b/tests/cases/compiler/es6ExportAssignment.ts @@ -0,0 +1,4 @@ +// @target: es6 + +var a = 10; +export = a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClause.ts b/tests/cases/compiler/es6ExportClause.ts new file mode 100644 index 0000000000000..a16e2c9e7aa69 --- /dev/null +++ b/tests/cases/compiler/es6ExportClause.ts @@ -0,0 +1,19 @@ +// @target: es6 +// @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/es6ExportClauseWithoutModuleSpecifier.ts b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts new file mode 100644 index 0000000000000..22a6cef420322 --- /dev/null +++ b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts @@ -0,0 +1,21 @@ +// @target: es6 +// @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/es6ExportDefaultClassDeclaration.ts b/tests/cases/compiler/es6ExportDefaultClassDeclaration.ts new file mode 100644 index 0000000000000..3d731753ee46d --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultClassDeclaration.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export default class C { + method() { } +} diff --git a/tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts b/tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts new file mode 100644 index 0000000000000..7092d15ef52ec --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export default class { + method() { } +} diff --git a/tests/cases/compiler/es6ExportDefaultExpression.ts b/tests/cases/compiler/es6ExportDefaultExpression.ts new file mode 100644 index 0000000000000..ef47621054160 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultExpression.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @declaration: true + +export default (1 + 2); diff --git a/tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts new file mode 100644 index 0000000000000..19984bde2a6f6 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @declaration: true + +export default function f() { } diff --git a/tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts new file mode 100644 index 0000000000000..022fbd81233c3 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @declaration: true + +export default function () { } diff --git a/tests/cases/compiler/es6ExportDefaultIdentifier.ts b/tests/cases/compiler/es6ExportDefaultIdentifier.ts new file mode 100644 index 0000000000000..1590677d4ce93 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultIdentifier.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export function f() { } + +export default f; diff --git a/tests/cases/compiler/es6ExportEquals.ts b/tests/cases/compiler/es6ExportEquals.ts new file mode 100644 index 0000000000000..5dfc98b4c93fa --- /dev/null +++ b/tests/cases/compiler/es6ExportEquals.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export function f() { } + +export = f; diff --git a/tests/cases/compiler/es6ImportDefaultBinding.ts b/tests/cases/compiler/es6ImportDefaultBinding.ts index dc5b4ab98d61c..9e779e8664d79 100644 --- a/tests/cases/compiler/es6ImportDefaultBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBinding.ts @@ -1,8 +1,8 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBinding_0.ts export var a = 10; // @filename: es6ImportDefaultBinding_1.ts -import defaultBinding from "es6ImportDefaultBinding_0"; \ No newline at end of file +import defaultBinding from "es6ImportDefaultBinding_0"; diff --git a/tests/cases/compiler/es6ImportDefaultBindingAmd.ts b/tests/cases/compiler/es6ImportDefaultBindingAmd.ts new file mode 100644 index 0000000000000..85e06b8c99d8c --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingAmd.ts @@ -0,0 +1,11 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportDefaultBindingAmd_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingAmd_1.ts +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingDts.ts b/tests/cases/compiler/es6ImportDefaultBindingDts.ts new file mode 100644 index 0000000000000..4700782b78e73 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingDts.ts @@ -0,0 +1,11 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +class c { } +export = c; + +// @filename: client.ts +import defaultBinding from "server"; +export var x = new defaultBinding(); +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts index 96b277d6640cd..20f0f122e99e0 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts @@ -1,5 +1,5 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamedImport_0.ts export var a = 10; @@ -12,4 +12,4 @@ import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImpor import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; \ No newline at end of file +import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts new file mode 100644 index 0000000000000..c1ac752426e00 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1_1.ts +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding6; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts new file mode 100644 index 0000000000000..a84dab940338d --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts @@ -0,0 +1,24 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } +export class x { } +export class m { } +export class a11 { } +export class a12 { } +export class x11 { } + +// @filename: client.ts +import defaultBinding1, { } from "server"; +import defaultBinding2, { a } from "server"; +export var x1 = new a(); +import defaultBinding3, { a11 as b } from "server"; +export var x2 = new b(); +import defaultBinding4, { x, a12 as y } from "server"; +export var x4 = new x(); +export var x5 = new y(); +import defaultBinding5, { x11 as z, } from "server"; +export var x3 = new z(); +import defaultBinding6, { m, } from "server"; +export var x6 = new m(); diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts index 3d029e28738bd..3e2cdd3409257 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts @@ -1,8 +1,9 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts export var a = 10; // @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; \ No newline at end of file +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts new file mode 100644 index 0000000000000..81113b776b4eb --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts new file mode 100644 index 0000000000000..db076b87c9a92 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts @@ -0,0 +1,11 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts new file mode 100644 index 0000000000000..732f7ef7ba00b --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } + +// @filename: client.ts +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.a(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts new file mode 100644 index 0000000000000..1f026af8f34df --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +class a { } +export = a; + +// @filename: client.ts +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new defaultBinding(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts b/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts new file mode 100644 index 0000000000000..cd1bad8371680 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts @@ -0,0 +1,15 @@ +// @module: commonjs + +// @filename: es6ImportDefaultBindingMergeErrors_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingMergeErrors_1.ts +import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; +interface defaultBinding { // This is ok +} +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +var defaultBinding2 = "hello world"; +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error diff --git a/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts b/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts new file mode 100644 index 0000000000000..5ab1c74372174 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts @@ -0,0 +1,7 @@ +// @module: commonjs + +// @filename: es6ImportDefaultBindingNoDefaultProperty_0.ts +export var a = 10; + +// @filename: es6ImportDefaultBindingNoDefaultProperty_1.ts +import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; diff --git a/tests/cases/compiler/es6ImportEqualsDeclaration.ts b/tests/cases/compiler/es6ImportEqualsDeclaration.ts new file mode 100644 index 0000000000000..7df85a31d75cd --- /dev/null +++ b/tests/cases/compiler/es6ImportEqualsDeclaration.ts @@ -0,0 +1,8 @@ +// @target: es6 + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +import a = require("server"); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImport.ts b/tests/cases/compiler/es6ImportNameSpaceImport.ts index 9937606c41ff4..58ef52daf53c0 100644 --- a/tests/cases/compiler/es6ImportNameSpaceImport.ts +++ b/tests/cases/compiler/es6ImportNameSpaceImport.ts @@ -1,8 +1,8 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportNameSpaceImport_0.ts export var a = 10; // @filename: es6ImportNameSpaceImport_1.ts -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; \ No newline at end of file +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; diff --git a/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts b/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts new file mode 100644 index 0000000000000..d4b69e8bcf4dc --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts @@ -0,0 +1,15 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNameSpaceImportMergeErrors_0.ts +export var a = 10; + +// @filename: es6ImportNameSpaceImportMergeErrors_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; +interface nameSpaceBinding { } // this should be ok + +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + +import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +var nameSpaceBinding3 = 10; diff --git a/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts b/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts new file mode 100644 index 0000000000000..7d3bdcec94c27 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts @@ -0,0 +1,9 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNameSpaceImportNoNamedExports_0.ts +var a = 10; +export = a; + +// @filename: es6ImportNameSpaceImportNoNamedExports_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImport.ts b/tests/cases/compiler/es6ImportNamedImport.ts index ed34434bd292c..df5de47897577 100644 --- a/tests/cases/compiler/es6ImportNamedImport.ts +++ b/tests/cases/compiler/es6ImportNamedImport.ts @@ -1,5 +1,5 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportNamedImport_0.ts export var a = 10; @@ -16,4 +16,4 @@ import { x, a as y } from "es6ImportNamedImport_0"; import { x as z, } from "es6ImportNamedImport_0"; import { m, } from "es6ImportNamedImport_0"; import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; \ No newline at end of file +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts b/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts index e1be293e4468e..ea1ed5cbff65a 100644 --- a/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts +++ b/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts @@ -1,5 +1,4 @@ // @target: es6 -// @module: commonjs import { yield } from "somemodule"; // Allowed import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier diff --git a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts new file mode 100644 index 0000000000000..a27391757701d --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @declaration: true + +// @filename: es6ImportNamedImportInExportAssignment_0.ts +export var a = 10; + +// @filename: es6ImportNamedImportInExportAssignment_1.ts +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts new file mode 100644 index 0000000000000..16d11d4e19fcd --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @declaration: true + +// @filename: es6ImportNamedImportInIndirectExportAssignment_0.ts +export module a { + export class c { + } +} + +// @filename: es6ImportNamedImportInIndirectExportAssignment_1.ts +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts b/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts new file mode 100644 index 0000000000000..54e30be1e2352 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts @@ -0,0 +1,19 @@ +// @module: commonjs + +// @filename: es6ImportNamedImportMergeErrors_0.ts +export var a = 10; +export var x = a; +export var z = a; +export var z1 = a; + +// @filename: es6ImportNamedImportMergeErrors_1.ts +import { a } from "es6ImportNamedImportMergeErrors_0"; +interface a { } // shouldnt be error +import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; +interface x1 { } // shouldnt be error +import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x = 10; +import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x44 = 10; +import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error +import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error diff --git a/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts b/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts new file mode 100644 index 0000000000000..bd507308d8d6f --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts @@ -0,0 +1,9 @@ +// @module: commonjs + +// @filename: es6ImportNamedImportNoExportMember_0.ts +export var a = 10; +export var x = a; + +// @filename: es6ImportNamedImport_1.ts +import { a1 } from "es6ImportNamedImportNoExportMember_0"; +import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts b/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts new file mode 100644 index 0000000000000..9dd243ff36d2e --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts @@ -0,0 +1,10 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNamedImportNoNamedExports_0.ts +var a = 10; +export = a; + +// @filename: es6ImportNamedImportNoNamedExports_1.ts +import { a } from "es6ImportNamedImportNoNamedExports_0"; +import { a as x } from "es6ImportNamedImportNoNamedExports_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportParsingError.ts b/tests/cases/compiler/es6ImportNamedImportParsingError.ts index a836acc11405d..26bd9b6915376 100644 --- a/tests/cases/compiler/es6ImportNamedImportParsingError.ts +++ b/tests/cases/compiler/es6ImportNamedImportParsingError.ts @@ -1,5 +1,4 @@ // @target: es6 -// @module: commonjs // @filename: es6ImportNamedImportParsingError_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportParseErrors.ts b/tests/cases/compiler/es6ImportParseErrors.ts index 2cc21dad7468f..9eb3ccba82a63 100644 --- a/tests/cases/compiler/es6ImportParseErrors.ts +++ b/tests/cases/compiler/es6ImportParseErrors.ts @@ -1,4 +1,3 @@ // @target: es6 -// @module: commonjs import 10; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClause.ts b/tests/cases/compiler/es6ImportWithoutFromClause.ts index 70a15a9bc54f7..0a38cda093c44 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClause.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClause.ts @@ -1,8 +1,8 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportWithoutFromClause_0.ts export var a = 10; // @filename: es6ImportWithoutFromClause_1.ts -import "es6ImportWithoutFromClause_0"; \ No newline at end of file +import "es6ImportWithoutFromClause_0"; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts new file mode 100644 index 0000000000000..22b250435c821 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts @@ -0,0 +1,9 @@ +// @target: es6 +// @declaration: true + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_0.ts +export interface i { +} + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_1.ts +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6Module.ts b/tests/cases/compiler/es6Module.ts new file mode 100644 index 0000000000000..33d70cd133f97 --- /dev/null +++ b/tests/cases/compiler/es6Module.ts @@ -0,0 +1,12 @@ +// @target: ES6 +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleClassDeclaration.ts b/tests/cases/compiler/es6ModuleClassDeclaration.ts new file mode 100644 index 0000000000000..3b36e53037f30 --- /dev/null +++ b/tests/cases/compiler/es6ModuleClassDeclaration.ts @@ -0,0 +1,113 @@ +// @target: ES6 +export class c { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +class c2 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +new c(); +new c2(); + +export module m1 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); +} +module m2 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleConst.ts b/tests/cases/compiler/es6ModuleConst.ts new file mode 100644 index 0000000000000..42bf24698a943 --- /dev/null +++ b/tests/cases/compiler/es6ModuleConst.ts @@ -0,0 +1,17 @@ +// @target: ES6 +export const a = "hello"; +export const x: string = a, y = x; +const b = y; +const c: string = b, d = c; +export module m1 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} +module m2 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleConstEnumDeclaration.ts b/tests/cases/compiler/es6ModuleConstEnumDeclaration.ts new file mode 100644 index 0000000000000..c3490093d3ecd --- /dev/null +++ b/tests/cases/compiler/es6ModuleConstEnumDeclaration.ts @@ -0,0 +1,46 @@ +// @target: ES6 +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts b/tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts new file mode 100644 index 0000000000000..6dddea09d8a65 --- /dev/null +++ b/tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts @@ -0,0 +1,48 @@ +// @target: ES6 +// @preserveConstEnums: true + +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleEnumDeclaration.ts b/tests/cases/compiler/es6ModuleEnumDeclaration.ts new file mode 100644 index 0000000000000..a0cebde9947e1 --- /dev/null +++ b/tests/cases/compiler/es6ModuleEnumDeclaration.ts @@ -0,0 +1,46 @@ +// @target: ES6 +export enum e1 { + a, + b, + c +} +enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export enum e3 { + a, + b, + c + } + enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export enum e5 { + a, + b, + c + } + enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleFunctionDeclaration.ts b/tests/cases/compiler/es6ModuleFunctionDeclaration.ts new file mode 100644 index 0000000000000..82eebb1580ef7 --- /dev/null +++ b/tests/cases/compiler/es6ModuleFunctionDeclaration.ts @@ -0,0 +1,29 @@ +// @target: ES6 +export function foo() { +} +function foo2() { +} +foo(); +foo2(); + +export module m1 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +} +module m2 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleInternalImport.ts b/tests/cases/compiler/es6ModuleInternalImport.ts new file mode 100644 index 0000000000000..24e209a87f656 --- /dev/null +++ b/tests/cases/compiler/es6ModuleInternalImport.ts @@ -0,0 +1,20 @@ +// @target: ES6 +export module m { + export var a = 10; +} +export import a1 = m.a; +import a2 = m.a; +var x = a1 + a2; +export module m1 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; +} +module m2 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; + var x4 = m1.a3 + m2.a3; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleInternalNamedImports.ts b/tests/cases/compiler/es6ModuleInternalNamedImports.ts new file mode 100644 index 0000000000000..f696cee0aa350 --- /dev/null +++ b/tests/cases/compiler/es6ModuleInternalNamedImports.ts @@ -0,0 +1,32 @@ +// @target: ES6 + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} diff --git a/tests/cases/compiler/es6ModuleLet.ts b/tests/cases/compiler/es6ModuleLet.ts new file mode 100644 index 0000000000000..fc5dfc94bd50a --- /dev/null +++ b/tests/cases/compiler/es6ModuleLet.ts @@ -0,0 +1,17 @@ +// @target: ES6 +export let a = "hello"; +export let x: string = a, y = x; +let b = y; +let c: string = b, d = c; +export module m1 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} +module m2 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleModuleDeclaration.ts b/tests/cases/compiler/es6ModuleModuleDeclaration.ts new file mode 100644 index 0000000000000..99868f6087b23 --- /dev/null +++ b/tests/cases/compiler/es6ModuleModuleDeclaration.ts @@ -0,0 +1,25 @@ +// @target: ES6 +export module m1 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} +module m2 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleVariableStatement.ts b/tests/cases/compiler/es6ModuleVariableStatement.ts new file mode 100644 index 0000000000000..a3ae29fbe6a22 --- /dev/null +++ b/tests/cases/compiler/es6ModuleVariableStatement.ts @@ -0,0 +1,17 @@ +// @target: ES6 +export var a = "hello"; +export var x: string = a, y = x; +var b = y; +var c: string = b, d = c; +export module m1 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} +module m2 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts b/tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts new file mode 100644 index 0000000000000..9521ec6cbdb39 --- /dev/null +++ b/tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts @@ -0,0 +1,13 @@ +// @target: ES6 +// @module: amd +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts b/tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts new file mode 100644 index 0000000000000..616a375d9700d --- /dev/null +++ b/tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts @@ -0,0 +1,13 @@ +// @target: ES6 +// @module: commonjs +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file