diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index f7108c5d2d714..5014c4241622e 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -131,6 +131,7 @@ namespace ts { options = opts; inStrictMode = !!file.externalModuleIndicator; classifiableNames = {}; + Symbol = objectAllocator.getSymbolConstructor(); if (!file.locals) { @@ -191,8 +192,8 @@ namespace ts { // unless it is a well known Symbol. function getDeclarationName(node: Declaration): string { if (node.name) { - if (node.kind === SyntaxKind.ModuleDeclaration && node.name.kind === SyntaxKind.StringLiteral) { - return `"${(node.name).text}"`; + if (isAmbientModule(node)) { + return isGlobalScopeAugmentation(node) ? "__global" : `"${(node.name).text}"`; } if (node.name.kind === SyntaxKind.ComputedPropertyName) { const nameExpression = (node.name).expression; @@ -348,7 +349,12 @@ namespace ts { // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol, // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. - if (hasExportModifier || container.flags & NodeFlags.ExportContext) { + + // NOTE: Nested ambient modules always should go to to 'locals' table to prevent their automatic merge + // during global merging in the checker. Why? The only case when ambient module is permitted inside another module is module augmentation + // and this case is specially handled. Module augmentations should only be merged with original module definition + // and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed. + if (!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) { const exportKind = (symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) | (symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) | @@ -843,7 +849,10 @@ namespace ts { function bindModuleDeclaration(node: ModuleDeclaration) { setExportContextFlag(node); - if (node.name.kind === SyntaxKind.StringLiteral) { + if (isAmbientModule(node)) { + if (node.flags & NodeFlags.Export) { + errorOnFirstToken(node, Diagnostics.export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible); + } declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); } else { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fa447bb7e73b3..1f265e59e06f6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -377,6 +377,32 @@ namespace ts { } } + function mergeModuleAugmentation(moduleName: LiteralExpression): void { + const moduleAugmentation = moduleName.parent; + if (moduleAugmentation.symbol.valueDeclaration !== moduleAugmentation) { + // this is a combined symbol for multiple augmentations within the same file. + // its symbol already has accumulated information for all declarations + // so we need to add it just once - do the work only for first declaration + Debug.assert(moduleAugmentation.symbol.declarations.length > 1); + return; + } + + if (isGlobalScopeAugmentation(moduleAugmentation)) { + mergeSymbolTable(globals, moduleAugmentation.symbol.exports); + } + else { + // find a module that about to be augmented + let mainModule = resolveExternalModuleNameWorker(moduleName, moduleName, Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found); + if (!mainModule) { + return; + } + // if module symbol has already been merged - it is safe to use it. + // otherwise clone it + mainModule = mainModule.flags & SymbolFlags.Merged ? mainModule : cloneSymbol(mainModule); + mergeSymbol(mainModule, moduleAugmentation.symbol); + } + } + function addToSymbolTable(target: SymbolTable, source: SymbolTable, message: DiagnosticMessage) { for (const id in source) { if (hasProperty(source, id)) { @@ -406,10 +432,6 @@ namespace ts { return nodeLinks[nodeId] || (nodeLinks[nodeId] = {}); } - function getSourceFile(node: Node): SourceFile { - return getAncestor(node, SyntaxKind.SourceFile); - } - function isGlobalSourceFile(node: Node) { return node.kind === SyntaxKind.SourceFile && !isExternalOrCommonJsModule(node); } @@ -584,8 +606,7 @@ namespace ts { if (!isExternalOrCommonJsModule(location)) break; case SyntaxKind.ModuleDeclaration: const moduleExports = getSymbolOfNode(location).exports; - if (location.kind === SyntaxKind.SourceFile || - (location.kind === SyntaxKind.ModuleDeclaration && (location).name.kind === SyntaxKind.StringLiteral)) { + if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. @@ -1115,6 +1136,10 @@ namespace ts { } function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression): Symbol { + return resolveExternalModuleNameWorker(location, moduleReferenceExpression, Diagnostics.Cannot_find_module_0); + } + + function resolveExternalModuleNameWorker(location: Node, moduleReferenceExpression: Expression, moduleNotFoundError: DiagnosticMessage): Symbol { if (moduleReferenceExpression.kind !== SyntaxKind.StringLiteral) { return; } @@ -1133,20 +1158,29 @@ namespace ts { if (!isRelative) { const symbol = getSymbol(globals, "\"" + moduleName + "\"", SymbolFlags.ValueModule); if (symbol) { - return symbol; + // merged symbol is module declaration symbol combined with all augmentations + return getMergedSymbol(symbol); } } - const resolvedModule = getResolvedModule(getSourceFile(location), moduleReferenceLiteral.text); + const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReferenceLiteral.text); const sourceFile = resolvedModule && host.getSourceFile(resolvedModule.resolvedFileName); if (sourceFile) { if (sourceFile.symbol) { - return sourceFile.symbol; + // merged symbol is module declaration symbol combined with all augmentations + return getMergedSymbol(sourceFile.symbol); } - error(moduleReferenceLiteral, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); - return; + if (moduleNotFoundError) { + // report errors only if it was requested + error(moduleReferenceLiteral, Diagnostics.File_0_is_not_a_module, sourceFile.fileName); + } + return undefined; + } + if (moduleNotFoundError) { + // report errors only if it was requested + error(moduleReferenceLiteral, moduleNotFoundError, moduleName); } - error(moduleReferenceLiteral, Diagnostics.Cannot_find_module_0, moduleName); + return undefined; } // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration, @@ -1563,8 +1597,7 @@ namespace ts { } function hasExternalModuleSymbol(declaration: Node) { - return (declaration.kind === SyntaxKind.ModuleDeclaration && (declaration).name.kind === SyntaxKind.StringLiteral) || - (declaration.kind === SyntaxKind.SourceFile && isExternalOrCommonJsModule(declaration)); + return isAmbientModule(declaration) || (declaration.kind === SyntaxKind.SourceFile && isExternalOrCommonJsModule(declaration)); } function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult { @@ -1688,6 +1721,12 @@ namespace ts { return undefined; } + function isTopLevelInExternalModuleAugmentation(node: Node): boolean { + return node && node.parent && + node.parent.kind === SyntaxKind.ModuleBlock && + isExternalModuleAugmentation(node.parent.parent); + } + function getSymbolDisplayBuilder(): SymbolDisplayBuilder { function getNameOfSymbol(symbol: Symbol): string { @@ -2270,6 +2309,10 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.ImportEqualsDeclaration: + // external module augmentation is always visible + if (isExternalModuleAugmentation(node)) { + return true; + } const parent = getDeclarationContainer(node); // If the node is not exported or it is not ambient module element (except import declaration) if (!(getCombinedNodeFlags(node) & NodeFlags.Export) && @@ -2447,7 +2490,7 @@ namespace ts { // Every class automatically contains a static property member named 'prototype', // the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. // It is an error to explicitly declare a static property member with the name 'prototype'. - const classType = getDeclaredTypeOfSymbol(prototype.parent); + const classType = getDeclaredTypeOfSymbol(getMergedSymbol(prototype.parent)); return classType.typeParameters ? createTypeReference(classType, map(classType.typeParameters, _ => anyType)) : classType; } @@ -8660,7 +8703,7 @@ namespace ts { function checkIndexedAccess(node: ElementAccessExpression): Type { // Grammar checking if (!node.argumentExpression) { - const sourceFile = getSourceFile(node); + const sourceFile = getSourceFileOfNode(node); if (node.parent.kind === SyntaxKind.NewExpression && (node.parent).expression === node) { const start = skipTrivia(sourceFile.text, node.expression.end); const end = node.end; @@ -12040,7 +12083,7 @@ namespace ts { case SyntaxKind.InterfaceDeclaration: return SymbolFlags.ExportType; case SyntaxKind.ModuleDeclaration: - return (d).name.kind === SyntaxKind.StringLiteral || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated + return isAmbientModule(d) || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated ? SymbolFlags.ExportNamespace | SymbolFlags.ExportValue : SymbolFlags.ExportNamespace; case SyntaxKind.ClassDeclaration: @@ -12496,7 +12539,7 @@ namespace ts { // checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function. const firstDeclaration = forEach(localSymbol.declarations, // Get first non javascript function declaration - declaration => declaration.kind === node.kind && !isSourceFileJavaScript(getSourceFile(declaration)) ? + declaration => declaration.kind === node.kind && !isSourceFileJavaScript(getSourceFileOfNode(declaration)) ? declaration : undefined); // Only type check the symbol once @@ -14182,7 +14225,13 @@ namespace ts { function checkModuleDeclaration(node: ModuleDeclaration) { if (produceDiagnostics) { // Grammar checking - const isAmbientExternalModule = node.name.kind === SyntaxKind.StringLiteral; + const isGlobalAugmentation = isGlobalScopeAugmentation(node); + const inAmbientContext = isInAmbientContext(node); + if (isGlobalAugmentation && !inAmbientContext) { + error(node.name, Diagnostics.Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context); + } + + const isAmbientExternalModule = isAmbientModule(node); const contextErrorMessage = isAmbientExternalModule ? Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file : Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module; @@ -14192,7 +14241,7 @@ namespace ts { } if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { - if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) { + if (!inAmbientContext && node.name.kind === SyntaxKind.StringLiteral) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } } @@ -14205,7 +14254,7 @@ namespace ts { // The following checks only apply on a non-ambient instantiated module declaration. if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 - && !isInAmbientContext(node) + && !inAmbientContext && isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) { const firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (firstNonAmbientClassOrFunc) { @@ -14226,19 +14275,107 @@ namespace ts { } } - // Checks for ambient external modules. if (isAmbientExternalModule) { - if (!isGlobalSourceFile(node.parent)) { - error(node.name, Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces); + if (isExternalModuleAugmentation(node)) { + // body of the augmentation should be checked for consistency only if augmentation was applied to its target (either global scope or module) + // otherwise we'll be swamped in cascading errors. + // We can detect if augmentation was applied using following rules: + // - augmentation for a global scope is always applied + // - augmentation for some external module is applied if symbol for augmentation is merged (it was combined with target module). + const checkBody = isGlobalAugmentation || (getSymbolOfNode(node).flags & SymbolFlags.Merged); + if (checkBody) { + // body of ambient external module is always a module block + for (const statement of (node.body).statements) { + checkModuleAugmentationElement(statement, isGlobalAugmentation); + } + } } - if (isExternalModuleNameRelative(node.name.text)) { - error(node.name, Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name); + else if (isGlobalSourceFile(node.parent)) { + if (isGlobalAugmentation) { + error(node.name, Diagnostics.Augmentations_for_the_global_scope_can_only_be_directly_nested_in_external_modules_or_ambient_module_declarations); + } + else if (isExternalModuleNameRelative(node.name.text)) { + error(node.name, Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name); + } + } + else { + if (isGlobalAugmentation) { + error(node.name, Diagnostics.Augmentations_for_the_global_scope_can_only_be_directly_nested_in_external_modules_or_ambient_module_declarations); + } + else { + // Node is not an augmentation and is not located on the script level. + // This means that this is declaration of ambient module that is located in other module or namespace which is prohibited. + error(node.name, Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces); + } } } } checkSourceElement(node.body); } + function checkModuleAugmentationElement(node: Node, isGlobalAugmentation: boolean): void { + switch (node.kind) { + case SyntaxKind.VariableStatement: + // error each individual name in variable statement instead of marking the entire variable statement + for (const decl of (node).declarationList.declarations) { + checkModuleAugmentationElement(decl, isGlobalAugmentation); + } + break; + case SyntaxKind.ExportAssignment: + case SyntaxKind.ExportDeclaration: + grammarErrorOnFirstToken(node, Diagnostics.Exports_and_export_assignments_are_not_permitted_in_module_augmentations); + break; + case SyntaxKind.ImportEqualsDeclaration: + if ((node).moduleReference.kind !== SyntaxKind.StringLiteral) { + error((node).name, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope); + break; + } + // fallthrough + case SyntaxKind.ImportDeclaration: + grammarErrorOnFirstToken(node, Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module); + break; + case SyntaxKind.BindingElement: + case SyntaxKind.VariableDeclaration: + const name = (node).name; + if (isBindingPattern(name)) { + for (const el of name.elements) { + // mark individual names in binding pattern + checkModuleAugmentationElement(el, isGlobalAugmentation); + } + break; + } + // fallthrough + case SyntaxKind.ClassDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.TypeAliasDeclaration: + const symbol = getSymbolOfNode(node); + if (symbol) { + // module augmentations cannot introduce new names on the top level scope of the module + // this is done it two steps + // 1. quick check - if symbol for node is not merged - this is local symbol to this augmentation - report error + // 2. main check - report error if value declaration of the parent symbol is module augmentation) + let reportError = !(symbol.flags & SymbolFlags.Merged); + if (!reportError) { + if (isGlobalAugmentation) { + // global symbol should not have parent since it is not explicitly exported + reportError = symbol.parent !== undefined; + } + else { + // symbol should not originate in augmentation + reportError = isExternalModuleAugmentation(symbol.parent.valueDeclaration); + } + } + if (reportError) { + error(node, Diagnostics.Module_augmentation_cannot_introduce_new_names_in_the_top_level_scope); + } + } + break; + } + } + function getFirstIdentifier(node: EntityName | Expression): Identifier { while (true) { if (node.kind === SyntaxKind.QualifiedName) { @@ -14261,7 +14398,7 @@ namespace ts { error(moduleName, Diagnostics.String_literal_expected); return false; } - const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; + const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent); if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { error(moduleName, node.kind === SyntaxKind.ExportDeclaration ? Diagnostics.Export_declarations_are_not_permitted_in_a_namespace : @@ -14269,12 +14406,16 @@ namespace ts { return false; } if (inAmbientExternalModule && isExternalModuleNameRelative((moduleName).text)) { - // TypeScript 1.0 spec (April 2013): 12.1.6 - // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference - // other external modules only through top - level external module names. - // Relative external module names are not permitted. - error(node, Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name); - return false; + // we have already reported errors on top level imports\exports in external module augmentations in checkModuleDeclaration + // no need to do this again. + if (!isTopLevelInExternalModuleAugmentation(node)) { + // TypeScript 1.0 spec (April 2013): 12.1.6 + // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference + // other external modules only through top - level external module names. + // Relative external module names are not permitted. + error(node, Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name); + return false; + } } return true; } @@ -14380,7 +14521,7 @@ namespace ts { // export { x, y } from "foo" forEach(node.exportClause.elements, checkExportSpecifier); - const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && (node.parent.parent).name.kind === SyntaxKind.StringLiteral; + const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent); if (node.parent.kind !== SyntaxKind.SourceFile && !inAmbientExternalModule) { error(node, Diagnostics.Export_declarations_are_not_permitted_in_a_namespace); } @@ -14424,7 +14565,7 @@ namespace ts { } const container = node.parent.kind === SyntaxKind.SourceFile ? node.parent : node.parent.parent; - if (container.kind === SyntaxKind.ModuleDeclaration && (container).name.kind === SyntaxKind.Identifier) { + if (container.kind === SyntaxKind.ModuleDeclaration && !isAmbientModule(container)) { error(node, Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace); return; } @@ -14469,7 +14610,9 @@ namespace ts { const exportEqualsSymbol = moduleSymbol.exports["export="]; if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) { const declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration; - error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + if (!isTopLevelInExternalModuleAugmentation(declaration)) { + error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); + } } // Checks for export * conflicts const exports = getExportsOfModule(moduleSymbol); @@ -15553,13 +15696,13 @@ namespace ts { }; } - function getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration): SourceFile { - const specifier = getExternalModuleName(declaration); - const moduleSymbol = getSymbolAtLocation(specifier); - if (!moduleSymbol) { - return undefined; - } - return getDeclarationOfKind(moduleSymbol, SyntaxKind.SourceFile) as SourceFile; + function getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration): SourceFile { + const specifier = getExternalModuleName(declaration); + const moduleSymbol = resolveExternalModuleNameWorker(specifier, specifier, /*moduleNotFoundError*/ undefined); + if (!moduleSymbol) { + return undefined; + } + return getDeclarationOfKind(moduleSymbol, SyntaxKind.SourceFile) as SourceFile; } function initializeTypeChecker() { @@ -15568,13 +15711,27 @@ namespace ts { bindSourceFile(file, compilerOptions); }); + let augmentations: LiteralExpression[][]; // Initialize global symbol table forEach(host.getSourceFiles(), file => { if (!isExternalOrCommonJsModule(file)) { mergeSymbolTable(globals, file.locals); } + if (file.moduleAugmentations) { + (augmentations || (augmentations = [])).push(file.moduleAugmentations); + } }); + if (augmentations) { + // merge module augmentations. + // this needs to be done after global symbol table is initialized to make sure that all ambient modules are indexed + for (const list of augmentations) { + for (const augmentation of list) { + mergeModuleAugmentation(augmentation); + } + } + } + // Setup global builtins addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0); @@ -16390,7 +16547,7 @@ namespace ts { return true; } else if (node.body === undefined) { - return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, Diagnostics._0_expected, "{"); + return grammarErrorAtPos(getSourceFileOfNode(node), node.end - 1, ";".length, Diagnostics._0_expected, "{"); } } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 75319d0ab51ea..9a57b4b1a37c7 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -54,6 +54,7 @@ namespace ts { let writer = createAndSetNewTextWriterWithSymbolWriter(); let enclosingDeclaration: Node; + let resultHasExternalModuleIndicator: boolean; let currentText: string; let currentLineMap: number[]; let currentIdentifiers: Map; @@ -101,6 +102,7 @@ namespace ts { }); } + resultHasExternalModuleIndicator = false; if (!isBundledEmit || !isExternalModule(sourceFile)) { noDeclare = false; emitSourceFile(sourceFile); @@ -139,6 +141,14 @@ namespace ts { allSourcesModuleElementDeclarationEmitInfo = allSourcesModuleElementDeclarationEmitInfo.concat(moduleElementDeclarationEmitInfo); moduleElementDeclarationEmitInfo = []; } + + if (!isBundledEmit && isExternalModule(sourceFile) && sourceFile.moduleAugmentations.length && !resultHasExternalModuleIndicator) { + // if file was external module with augmentations - this fact should be preserved in .d.ts as well. + // in case if we didn't write any external module specifiers in .d.ts we need to emit something + // that will force compiler to think that this file is an external module - 'export {}' is a reasonable choice here. + write("export {};"); + writeLine(); + } }); return { @@ -721,16 +731,25 @@ namespace ts { writer.writeLine(); } - function emitExternalModuleSpecifier(parent: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration) { + function emitExternalModuleSpecifier(parent: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration) { + // emitExternalModuleSpecifier is usually called when we emit something in the.d.ts file that will make it an external module (i.e. import/export declarations). + // the only case when it is not true is when we call it to emit correct name for module augmentation - d.ts files with just module augmentations are not considered + // external modules since they are indistingushable from script files with ambient modules. To fix this in such d.ts files we'll emit top level 'export {}' + // so compiler will treat them as external modules. + resultHasExternalModuleIndicator = resultHasExternalModuleIndicator || parent.kind !== SyntaxKind.ModuleDeclaration; let moduleSpecifier: Node; if (parent.kind === SyntaxKind.ImportEqualsDeclaration) { const node = parent as ImportEqualsDeclaration; moduleSpecifier = getExternalModuleImportEqualsDeclarationExpression(node); } + else if (parent.kind === SyntaxKind.ModuleDeclaration) { + moduleSpecifier = (parent).name; + } else { const node = parent as (ImportDeclaration | ExportDeclaration); moduleSpecifier = node.moduleSpecifier; } + if (moduleSpecifier.kind === SyntaxKind.StringLiteral && isBundledEmit && (compilerOptions.out || compilerOptions.outFile)) { const moduleName = getExternalModuleNameFromDeclaration(host, resolver, parent); if (moduleName) { @@ -784,13 +803,23 @@ namespace ts { function writeModuleDeclaration(node: ModuleDeclaration) { emitJsDocComments(node); emitModuleElementDeclarationFlags(node); - if (node.flags & NodeFlags.Namespace) { - write("namespace "); + if (isGlobalScopeAugmentation(node)) { + write("global "); } else { - write("module "); + if (node.flags & NodeFlags.Namespace) { + write("namespace "); + } + else { + write("module "); + } + if (isExternalModuleAugmentation(node)) { + emitExternalModuleSpecifier(node); + } + else { + writeTextOfNode(currentText, node.name); + } } - writeTextOfNode(currentText, node.name); while (node.body.kind !== SyntaxKind.ModuleBlock) { node = node.body; write("."); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b61fcb5e65029..8fd40f7b42169 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1775,6 +1775,34 @@ "category": "Error", "code": 2663 }, + "Invalid module name in augmentation, module '{0}' cannot be found.": { + "category": "Error", + "code": 2664 + }, + "Module augmentation cannot introduce new names in the top level scope.": { + "category": "Error", + "code": 2665 + }, + "Exports and export assignments are not permitted in module augmentations.": { + "category": "Error", + "code": 2666 + }, + "Imports are not permitted in module augmentations. Consider moving them to the enclosing external module.": { + "category": "Error", + "code": 2667 + }, + "'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible.": { + "category": "Error", + "code": 2668 + }, + "Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.": { + "category": "Error", + "code": 2669 + }, + "Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context.": { + "category": "Error", + "code": 2670 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 420d201adc987..e391408b419ec 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4430,6 +4430,9 @@ namespace ts { } continue; + case SyntaxKind.GlobalKeyword: + return nextToken() === SyntaxKind.OpenBraceToken; + case SyntaxKind.ImportKeyword: nextToken(); return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || @@ -4494,6 +4497,7 @@ namespace ts { case SyntaxKind.ModuleKeyword: case SyntaxKind.NamespaceKeyword: case SyntaxKind.TypeKeyword: + case SyntaxKind.GlobalKeyword: // When these don't start a declaration, they're an identifier in an expression statement return true; @@ -4582,6 +4586,7 @@ namespace ts { case SyntaxKind.PublicKeyword: case SyntaxKind.AbstractKeyword: case SyntaxKind.StaticKeyword: + case SyntaxKind.GlobalKeyword: if (isStartOfDeclaration()) { return parseDeclaration(); } @@ -4609,6 +4614,7 @@ namespace ts { return parseTypeAliasDeclaration(fullStart, decorators, modifiers); case SyntaxKind.EnumKeyword: return parseEnumDeclaration(fullStart, decorators, modifiers); + case SyntaxKind.GlobalKeyword: case SyntaxKind.ModuleKeyword: case SyntaxKind.NamespaceKeyword: return parseModuleDeclaration(fullStart, decorators, modifiers); @@ -5243,14 +5249,25 @@ namespace ts { const node = createNode(SyntaxKind.ModuleDeclaration, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - node.name = parseLiteralNode(/*internName*/ true); + if (token === SyntaxKind.GlobalKeyword) { + // parse 'global' as name of global scope augmentation + node.name = parseIdentifier(); + node.flags |= NodeFlags.GlobalAugmentation; + } + else { + node.name = parseLiteralNode(/*internName*/ true); + } node.body = parseModuleBlock(); return finishNode(node); } function parseModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { let flags = modifiers ? modifiers.flags : 0; - if (parseOptional(SyntaxKind.NamespaceKeyword)) { + if (token === SyntaxKind.GlobalKeyword) { + // global augmentation + return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); + } + else if (parseOptional(SyntaxKind.NamespaceKeyword)) { flags |= NodeFlags.Namespace; } else { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 6905e01b1e62a..52c9fa4ef8437 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -361,7 +361,24 @@ namespace ts { const currentDirectory = host.getCurrentDirectory(); const resolveModuleNamesWorker = host.resolveModuleNames ? ((moduleNames: string[], containingFile: string) => host.resolveModuleNames(moduleNames, containingFile)) - : ((moduleNames: string[], containingFile: string) => map(moduleNames, moduleName => resolveModuleName(moduleName, containingFile, options, host).resolvedModule)); + : ((moduleNames: string[], containingFile: string) => { + const resolvedModuleNames: ResolvedModule[] = []; + // resolveModuleName does not store any results between calls. + // lookup is a local cache to avoid resolving the same module name several times + const lookup: Map = {}; + for (const moduleName of moduleNames) { + let resolvedName: ResolvedModule; + if (hasProperty(lookup, moduleName)) { + resolvedName = lookup[moduleName]; + } + else { + resolvedName = resolveModuleName(moduleName, containingFile, options, host).resolvedModule; + lookup[moduleName] = resolvedName; + } + resolvedModuleNames.push(resolvedName); + } + return resolvedModuleNames; + }); const filesByName = createFileMap(); // stores 'filename -> file association' ignoring case @@ -498,15 +515,19 @@ namespace ts { return false; } - // check imports + // check imports and module augmentations collectExternalModuleReferences(newSourceFile); if (!arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) { // imports has changed return false; } + if (!arrayIsEqualTo(oldSourceFile.moduleAugmentations, newSourceFile.moduleAugmentations, moduleNameIsEqualTo)) { + // moduleAugmentations has changed + return false; + } if (resolveModuleNamesWorker) { - const moduleNames = map(newSourceFile.imports, name => name.text); + const moduleNames = map(concatenate(newSourceFile.imports, newSourceFile.moduleAugmentations), getTextOfLiteral); const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory)); // ensure that module resolution results are still correct for (let i = 0; i < moduleNames.length; i++) { @@ -895,65 +916,85 @@ namespace ts { return a.text === b.text; } + function getTextOfLiteral(literal: LiteralExpression): string { + return literal.text; + } + function collectExternalModuleReferences(file: SourceFile): void { if (file.imports) { return; } const isJavaScriptFile = isSourceFileJavaScript(file); + const isExternalModuleFile = isExternalModule(file); let imports: LiteralExpression[]; + let moduleAugmentations: LiteralExpression[]; + for (const node of file.statements) { - collect(node, /*allowRelativeModuleNames*/ true, /*collectOnlyRequireCalls*/ false); + collectModuleReferences(node, /*inAmbientModule*/ false); + if (isJavaScriptFile) { + collectRequireCalls(node); + } } file.imports = imports || emptyArray; + file.moduleAugmentations = moduleAugmentations || emptyArray; return; - function collect(node: Node, allowRelativeModuleNames: boolean, collectOnlyRequireCalls: boolean): void { - if (!collectOnlyRequireCalls) { - switch (node.kind) { - case SyntaxKind.ImportDeclaration: - case SyntaxKind.ImportEqualsDeclaration: - case SyntaxKind.ExportDeclaration: - let moduleNameExpr = getExternalModuleName(node); - if (!moduleNameExpr || moduleNameExpr.kind !== SyntaxKind.StringLiteral) { - break; - } - if (!(moduleNameExpr).text) { - break; - } + function collectModuleReferences(node: Node, inAmbientModule: boolean): void { + switch (node.kind) { + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.ExportDeclaration: + let moduleNameExpr = getExternalModuleName(node); + if (!moduleNameExpr || moduleNameExpr.kind !== SyntaxKind.StringLiteral) { + break; + } + if (!(moduleNameExpr).text) { + break; + } - if (allowRelativeModuleNames || !isExternalModuleNameRelative((moduleNameExpr).text)) { - (imports || (imports = [])).push(moduleNameExpr); + // TypeScript 1.0 spec (April 2014): 12.1.6 + // An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference other external modules + // only through top - level external module names. Relative external module names are not permitted. + if (!inAmbientModule || !isExternalModuleNameRelative((moduleNameExpr).text)) { + (imports || (imports = [])).push(moduleNameExpr); + } + break; + case SyntaxKind.ModuleDeclaration: + if (isAmbientModule(node) && (inAmbientModule || node.flags & NodeFlags.Ambient || isDeclarationFile(file))) { + const moduleName = (node).name; + // Ambient module declarations can be interpreted as augmentations for some existing external modules. + // This will happen in two cases: + // - if current file is external module then module augmentation is a ambient module declaration defined in the top level scope + // - if current file is not external module then module augmentation is an ambient module declaration with non-relative module name + // immediately nested in top level ambient module declaration . + if (isExternalModuleFile || (inAmbientModule && !isExternalModuleNameRelative(moduleName.text))) { + (moduleAugmentations || (moduleAugmentations = [])).push(moduleName); } - break; - case SyntaxKind.ModuleDeclaration: - if ((node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) { - // TypeScript 1.0 spec (April 2014): 12.1.6 + else if (!inAmbientModule) { // An AmbientExternalModuleDeclaration declares an external module. // This type of declaration is permitted only in the global module. // The StringLiteral must specify a top - level external module name. // Relative external module names are not permitted - forEachChild((node).body, node => { - // TypeScript 1.0 spec (April 2014): 12.1.6 - // An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules - // only through top - level external module names. Relative external module names are not permitted. - collect(node, /*allowRelativeModuleNames*/ false, collectOnlyRequireCalls); - }); + + // NOTE: body of ambient module is always a module block + for (const statement of ((node).body).statements) { + collectModuleReferences(statement, /*inAmbientModule*/ true); + } } - break; - } + } } + } - if (isJavaScriptFile) { - if (isRequireCall(node)) { - (imports || (imports = [])).push((node).arguments[0]); - } - else { - forEachChild(node, node => collect(node, allowRelativeModuleNames, /*collectOnlyRequireCalls*/ true)); - } + function collectRequireCalls(node: Node): void { + if (isRequireCall(node)) { + (imports || (imports = [])).push((node).arguments[0]); + } + else { + forEachChild(node, collectRequireCalls); } } } @@ -1083,14 +1124,22 @@ namespace ts { function processImportedModules(file: SourceFile, basePath: string) { collectExternalModuleReferences(file); - if (file.imports.length) { + if (file.imports.length || file.moduleAugmentations.length) { file.resolvedModules = {}; - const moduleNames = map(file.imports, name => name.text); + const moduleNames = map(concatenate(file.imports, file.moduleAugmentations), getTextOfLiteral); const resolutions = resolveModuleNamesWorker(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory)); - for (let i = 0; i < file.imports.length; i++) { + for (let i = 0; i < moduleNames.length; i++) { const resolution = resolutions[i]; setResolvedModule(file, moduleNames[i], resolution); - if (resolution && !options.noResolve) { + // add file to program only if: + // - resolution was successfull + // - noResolve is falsy + // - module name come from the list fo imports + const shouldAddFile = resolution && + !options.noResolve && + i < file.imports.length; + + if (shouldAddFile) { const importedFile = findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), /*isDefaultLib*/ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); if (importedFile && resolution.isExternalLibraryImport) { diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 8161ea998c43d..7192ba6b40cce 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -94,6 +94,7 @@ namespace ts { "protected": SyntaxKind.ProtectedKeyword, "public": SyntaxKind.PublicKeyword, "require": SyntaxKind.RequireKeyword, + "global": SyntaxKind.GlobalKeyword, "return": SyntaxKind.ReturnKeyword, "set": SyntaxKind.SetKeyword, "static": SyntaxKind.StaticKeyword, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ce4ffe05f92f2..74c1af6ae521f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -170,6 +170,7 @@ namespace ts { SymbolKeyword, TypeKeyword, FromKeyword, + GlobalKeyword, OfKeyword, // LastKeyword and LastToken // Parse tree nodes @@ -389,6 +390,7 @@ namespace ts { ContainsThis = 1 << 18, // Interface contains references to "this" HasImplicitReturn = 1 << 19, // If function implicitly returns on one of codepaths (initialized by binding) HasExplicitReturn = 1 << 20, // If function has explicit reachable return on one of codepaths (initialized by binding) + GlobalAugmentation = 1 << 21, // Set if module declaration is an augmentation for the global scope Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async, AccessibilityModifier = Public | Private | Protected, BlockScoped = Let | Const, @@ -1577,6 +1579,7 @@ namespace ts { // Content of this fiels should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead /* @internal */ resolvedModules: Map; /* @internal */ imports: LiteralExpression[]; + /* @internal */ moduleAugmentations: LiteralExpression[]; } export interface ScriptReferenceHost { @@ -1911,7 +1914,7 @@ namespace ts { isOptionalParameter(node: ParameterDeclaration): boolean; moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean; isArgumentsLocalBinding(node: Identifier): boolean; - getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration): SourceFile; + getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration): SourceFile; } export const enum SymbolFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 3553430bcde76..69941a6095dc4 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -251,6 +251,31 @@ namespace ts { isCatchClauseVariableDeclaration(declaration); } + export function isAmbientModule(node: Node): boolean { + return node && node.kind === SyntaxKind.ModuleDeclaration && + ((node).name.kind === SyntaxKind.StringLiteral || isGlobalScopeAugmentation(node)); + } + + export function isGlobalScopeAugmentation(module: ModuleDeclaration): boolean { + return !!(module.flags & NodeFlags.GlobalAugmentation); + } + + export function isExternalModuleAugmentation(node: Node): boolean { + // external module augmentation is a ambient module declaration that is either: + // - defined in the top level scope and source file is an external module + // - defined inside ambient module declaration located in the top level scope and source file not an external module + if (!node || !isAmbientModule(node)) { + return false; + } + switch (node.parent.kind) { + case SyntaxKind.SourceFile: + return isExternalModule(node.parent); + case SyntaxKind.ModuleBlock: + return isAmbientModule(node.parent.parent) && !isExternalModule(node.parent.parent.parent); + } + return false; + } + // Gets the nearest enclosing block scope container that has the provided node // as a descendant, that is not the provided node. export function getEnclosingBlockScopeContainer(node: Node): Node { @@ -343,6 +368,7 @@ namespace ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.MethodDeclaration: + case SyntaxKind.TypeAliasDeclaration: errorNode = (node).name; break; } @@ -1115,6 +1141,9 @@ namespace ts { if (node.kind === SyntaxKind.ExportDeclaration) { return (node).moduleSpecifier; } + if (node.kind === SyntaxKind.ModuleDeclaration && (node).name.kind === SyntaxKind.StringLiteral) { + return (node).name; + } } export function hasQuestionToken(node: Node) { diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 46ec807a881dd..f62c6cb1700dd 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -387,7 +387,7 @@ namespace ts.NavigationBar { function getModuleName(moduleDeclaration: ModuleDeclaration): string { // We want to maintain quotation marks. - if (moduleDeclaration.name.kind === SyntaxKind.StringLiteral) { + if (isAmbientModule(moduleDeclaration)) { return getTextOfNode(moduleDeclaration.name); } diff --git a/src/services/services.ts b/src/services/services.ts index 8e998760b498b..502f2f41958fa 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -811,6 +811,7 @@ namespace ts { public nameTable: Map; public resolvedModules: Map; public imports: LiteralExpression[]; + public moduleAugmentations: LiteralExpression[]; private namedDeclarations: Map; constructor(kind: SyntaxKind, pos: number, end: number) { @@ -6292,7 +6293,7 @@ namespace ts { return SemanticMeaning.Value | SemanticMeaning.Type; case SyntaxKind.ModuleDeclaration: - if ((node).name.kind === SyntaxKind.StringLiteral) { + if (isAmbientModule(node)) { return SemanticMeaning.Namespace | SemanticMeaning.Value; } else if (getModuleInstanceState(node) === ModuleInstanceState.Instantiated) { diff --git a/tests/baselines/reference/ambientExternalModuleInAnotherExternalModule.errors.txt b/tests/baselines/reference/ambientExternalModuleInAnotherExternalModule.errors.txt index 0e508470b136d..4edf3bf7966f2 100644 --- a/tests/baselines/reference/ambientExternalModuleInAnotherExternalModule.errors.txt +++ b/tests/baselines/reference/ambientExternalModuleInAnotherExternalModule.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(5,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(5,16): error TS2664: Invalid module name in augmentation, module 'ext' cannot be found. tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(10,22): error TS2307: Cannot find module 'ext'. @@ -9,7 +9,7 @@ tests/cases/compiler/ambientExternalModuleInAnotherExternalModule.ts(10,22): err declare module "ext" { ~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'ext' cannot be found. export class C { } } diff --git a/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt b/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt index 7e4ac795d0d57..c892c91bfd70d 100644 --- a/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt +++ b/tests/baselines/reference/ambientExternalModuleInsideNonAmbient.errors.txt @@ -1,9 +1,12 @@ +tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts(2,5): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts(2,27): error TS2435: Ambient modules cannot be nested in other modules or namespaces. -==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts (1 errors) ==== +==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts (2 errors) ==== module M { export declare module "M" { } + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~ !!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. } \ No newline at end of file diff --git a/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt b/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt index e5905aaaf8fa6..1599069e67d7e 100644 --- a/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt +++ b/tests/baselines/reference/ambientExternalModuleInsideNonAmbientExternalModule.errors.txt @@ -1,7 +1,10 @@ -tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts(1,23): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts(1,1): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. +tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts(1,23): error TS2664: Invalid module name in augmentation, module 'M' cannot be found. -==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts (1 errors) ==== +==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts (2 errors) ==== export declare module "M" { } + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. \ No newline at end of file +!!! error TS2664: Invalid module name in augmentation, module 'M' cannot be found. \ No newline at end of file diff --git a/tests/baselines/reference/globalIsContextualKeyword.js b/tests/baselines/reference/globalIsContextualKeyword.js new file mode 100644 index 0000000000000..b6fa566c91a33 --- /dev/null +++ b/tests/baselines/reference/globalIsContextualKeyword.js @@ -0,0 +1,34 @@ +//// [globalIsContextualKeyword.ts] +function a() { + let global = 1; +} +function b() { + class global {} +} + +namespace global { +} + +function foo(global: number) { +} + +let obj = { + global: "123" +} + +//// [globalIsContextualKeyword.js] +function a() { + var global = 1; +} +function b() { + var global = (function () { + function global() { + } + return global; + }()); +} +function foo(global) { +} +var obj = { + global: "123" +}; diff --git a/tests/baselines/reference/globalIsContextualKeyword.symbols b/tests/baselines/reference/globalIsContextualKeyword.symbols new file mode 100644 index 0000000000000..edc1cebbc9594 --- /dev/null +++ b/tests/baselines/reference/globalIsContextualKeyword.symbols @@ -0,0 +1,29 @@ +=== tests/cases/compiler/globalIsContextualKeyword.ts === +function a() { +>a : Symbol(a, Decl(globalIsContextualKeyword.ts, 0, 0)) + + let global = 1; +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 1, 7)) +} +function b() { +>b : Symbol(b, Decl(globalIsContextualKeyword.ts, 2, 1)) + + class global {} +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 3, 14)) +} + +namespace global { +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 5, 1)) +} + +function foo(global: number) { +>foo : Symbol(foo, Decl(globalIsContextualKeyword.ts, 8, 1)) +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 10, 13)) +} + +let obj = { +>obj : Symbol(obj, Decl(globalIsContextualKeyword.ts, 13, 3)) + + global: "123" +>global : Symbol(global, Decl(globalIsContextualKeyword.ts, 13, 11)) +} diff --git a/tests/baselines/reference/globalIsContextualKeyword.types b/tests/baselines/reference/globalIsContextualKeyword.types new file mode 100644 index 0000000000000..d0bf624af6d4c --- /dev/null +++ b/tests/baselines/reference/globalIsContextualKeyword.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/globalIsContextualKeyword.ts === +function a() { +>a : () => void + + let global = 1; +>global : number +>1 : number +} +function b() { +>b : () => void + + class global {} +>global : global +} + +namespace global { +>global : any +} + +function foo(global: number) { +>foo : (global: number) => void +>global : number +} + +let obj = { +>obj : { global: string; } +>{ global: "123"} : { global: string; } + + global: "123" +>global : string +>"123" : string +} diff --git a/tests/baselines/reference/importDeclRefereingExternalModuleWithNoResolve.errors.txt b/tests/baselines/reference/importDeclRefereingExternalModuleWithNoResolve.errors.txt index 34cfe02305fea..5d70b32aa1664 100644 --- a/tests/baselines/reference/importDeclRefereingExternalModuleWithNoResolve.errors.txt +++ b/tests/baselines/reference/importDeclRefereingExternalModuleWithNoResolve.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/importDeclRefereingExternalModuleWithNoResolve.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided. Consider setting the 'module' compiler option in a 'tsconfig.json' file. tests/cases/compiler/importDeclRefereingExternalModuleWithNoResolve.ts(1,20): error TS2307: Cannot find module 'externalModule'. -tests/cases/compiler/importDeclRefereingExternalModuleWithNoResolve.ts(2,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/importDeclRefereingExternalModuleWithNoResolve.ts(2,16): error TS2664: Invalid module name in augmentation, module 'm1' cannot be found. tests/cases/compiler/importDeclRefereingExternalModuleWithNoResolve.ts(3,26): error TS2307: Cannot find module 'externalModule'. @@ -12,7 +12,7 @@ tests/cases/compiler/importDeclRefereingExternalModuleWithNoResolve.ts(3,26): er !!! error TS2307: Cannot find module 'externalModule'. declare module "m1" { ~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'm1' cannot be found. import im2 = require("externalModule"); ~~~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'externalModule'. diff --git a/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt b/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt index bc4d8e903ad62..2b5112e1ce2ed 100644 --- a/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt +++ b/tests/baselines/reference/jsFileCompilationTypeAliasSyntax.errors.txt @@ -1,9 +1,9 @@ error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file. -tests/cases/compiler/a.js(1,1): error TS8008: 'type aliases' can only be used in a .ts file. +tests/cases/compiler/a.js(1,6): error TS8008: 'type aliases' can only be used in a .ts file. !!! error TS5055: Cannot write file 'tests/cases/compiler/a.js' because it would overwrite input file. ==== tests/cases/compiler/a.js (1 errors) ==== type a = b; - ~~~~~~~~~~~ + ~ !!! error TS8008: 'type aliases' can only be used in a .ts file. \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.errors.txt b/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.errors.txt new file mode 100644 index 0000000000000..8e1bc337b3979 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.errors.txt @@ -0,0 +1,40 @@ +tests/cases/compiler/map1.ts(7,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/map2.ts(6,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/map1.ts (1 errors) ==== + + import { Observable } from "./observable" + + (Observable.prototype).map = function() { } + + declare module "./observable" { + interface I {x0} + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + +==== tests/cases/compiler/map2.ts (1 errors) ==== + import { Observable } from "./observable" + + (Observable.prototype).map = function() { } + + declare module "./observable" { + interface I {x1} + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + + +==== tests/cases/compiler/observable.ts (0 errors) ==== + export declare class Observable { + filter(pred: (e:T) => boolean): Observable; + } + +==== tests/cases/compiler/main.ts (0 errors) ==== + import { Observable } from "./observable" + import "./map1"; + import "./map2"; + + let x: Observable; + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js b/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js new file mode 100644 index 0000000000000..60ba2217349e3 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.js @@ -0,0 +1,75 @@ +//// [tests/cases/compiler/moduleAugmentationCollidingNamesInAugmentation1.ts] //// + +//// [map1.ts] + +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface I {x0} +} + +//// [map2.ts] +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface I {x1} +} + + +//// [observable.ts] +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +//// [main.ts] +import { Observable } from "./observable" +import "./map1"; +import "./map2"; + +let x: Observable; + + +//// [observable.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); +//// [map1.js] +define(["require", "exports", "./observable"], function (require, exports, observable_1) { + "use strict"; + observable_1.Observable.prototype.map = function () { }; +}); +//// [map2.js] +define(["require", "exports", "./observable"], function (require, exports, observable_1) { + "use strict"; + observable_1.Observable.prototype.map = function () { }; +}); +//// [main.js] +define(["require", "exports", "./map1", "./map2"], function (require, exports) { + "use strict"; + var x; +}); + + +//// [observable.d.ts] +export declare class Observable { + filter(pred: (e: T) => boolean): Observable; +} +//// [map1.d.ts] +declare module "./observable" { + interface I { + x0: any; + } +} +export {}; +//// [map2.d.ts] +declare module "./observable" { + interface I { + x1: any; + } +} +export {}; +//// [main.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit1.js b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.js new file mode 100644 index 0000000000000..589d0f506e9b9 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.js @@ -0,0 +1,68 @@ +//// [tests/cases/compiler/moduleAugmentationDeclarationEmit1.ts] //// + +//// [map.ts] + +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: number; + } +} + +//// [observable.ts] +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + let someValue: number; +} + + +//// [main.ts] +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); + +//// [observable.js] +"use strict"; +var Observable; +(function (Observable) { + var someValue; +})(Observable = exports.Observable || (exports.Observable = {})); +//// [map.js] +"use strict"; +var observable_1 = require("./observable"); +observable_1.Observable.prototype.map = function () { }; +//// [main.js] +"use strict"; +require("./map"); +var x; +var y = x.map(function (x) { return x + 1; }); + + +//// [observable.d.ts] +export declare class Observable { + filter(pred: (e: T) => boolean): Observable; +} +export declare namespace Observable { +} +//// [map.d.ts] +declare module "./observable" { + interface Observable { + map(proj: (e: T) => U): Observable; + } + namespace Observable { + let someAnotherValue: number; + } +} +export {}; +//// [main.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit1.symbols b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.symbols new file mode 100644 index 0000000000000..eca44ec774d73 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.symbols @@ -0,0 +1,73 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) + +(Observable.prototype).map = function() { } +>Observable.prototype : Symbol(Observable.prototype) +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) +>prototype : Symbol(Observable.prototype) + +declare module "./observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + map(proj: (e:T) => U): Observable +>map : Symbol(map, Decl(map.ts, 6, 29)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>proj : Symbol(proj, Decl(map.ts, 7, 15)) +>e : Symbol(e, Decl(map.ts, 7, 22)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>U : Symbol(U, Decl(map.ts, 7, 12)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + let someAnotherValue: number; +>someAnotherValue : Symbol(someAnotherValue, Decl(map.ts, 10, 11)) + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + filter(pred: (e:T) => boolean): Observable; +>filter : Symbol(filter, Decl(observable.ts, 0, 36)) +>pred : Symbol(pred, Decl(observable.ts, 1, 11)) +>e : Symbol(e, Decl(observable.ts, 1, 18)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +} + +export namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + let someValue: number; +>someValue : Symbol(someValue, Decl(observable.ts, 5, 7)) +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +import "./map"; + +let x: Observable; +>x : Symbol(x, Decl(main.ts, 3, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +let y = x.map(x => x + 1); +>y : Symbol(y, Decl(main.ts, 4, 3)) +>x.map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 3, 3)) +>map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 4, 14)) +>x : Symbol(x, Decl(main.ts, 4, 14)) + diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit1.types b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.types new file mode 100644 index 0000000000000..fad835029c24d --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit1.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : typeof Observable + +(Observable.prototype).map = function() { } +>(Observable.prototype).map = function() { } : () => void +>(Observable.prototype).map : any +>(Observable.prototype) : any +>Observable.prototype : any +>Observable.prototype : Observable +>Observable : typeof Observable +>prototype : Observable +>map : any +>function() { } : () => void + +declare module "./observable" { + interface Observable { +>Observable : Observable +>T : T + + map(proj: (e:T) => U): Observable +>map : (proj: (e: T) => U) => Observable +>U : U +>proj : (e: T) => U +>e : T +>T : T +>U : U +>Observable : Observable +>U : U + } + namespace Observable { +>Observable : typeof Observable + + let someAnotherValue: number; +>someAnotherValue : number + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Observable +>T : T + + filter(pred: (e:T) => boolean): Observable; +>filter : (pred: (e: T) => boolean) => Observable +>pred : (e: T) => boolean +>e : T +>T : T +>Observable : Observable +>T : T +} + +export namespace Observable { +>Observable : typeof Observable + + let someValue: number; +>someValue : number +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : typeof Observable + +import "./map"; + +let x: Observable; +>x : Observable +>Observable : Observable + +let y = x.map(x => x + 1); +>y : Observable +>x.map(x => x + 1) : Observable +>x.map : (proj: (e: number) => U) => Observable +>x : Observable +>map : (proj: (e: number) => U) => Observable +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : number + diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit2.js b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.js new file mode 100644 index 0000000000000..d8fd65a146487 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.js @@ -0,0 +1,73 @@ +//// [tests/cases/compiler/moduleAugmentationDeclarationEmit2.ts] //// + +//// [map.ts] + +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: string; + } +} + +//// [observable.ts] +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + export let someValue: number; +} + + +//// [main.ts] +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); +let z1 = Observable.someValue.toFixed(); +let z2 = Observable.someAnotherValue.toLowerCase(); + +//// [observable.js] +"use strict"; +var Observable; +(function (Observable) { +})(Observable = exports.Observable || (exports.Observable = {})); +//// [map.js] +"use strict"; +var observable_1 = require("./observable"); +observable_1.Observable.prototype.map = function () { }; +//// [main.js] +"use strict"; +var observable_1 = require("./observable"); +require("./map"); +var x; +var y = x.map(function (x) { return x + 1; }); +var z1 = observable_1.Observable.someValue.toFixed(); +var z2 = observable_1.Observable.someAnotherValue.toLowerCase(); + + +//// [observable.d.ts] +export declare class Observable { + filter(pred: (e: T) => boolean): Observable; +} +export declare namespace Observable { + let someValue: number; +} +//// [map.d.ts] +declare module "./observable" { + interface Observable { + map(proj: (e: T) => U): Observable; + } + namespace Observable { + let someAnotherValue: string; + } +} +export {}; +//// [main.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit2.symbols b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.symbols new file mode 100644 index 0000000000000..d0f25f693fe8d --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.symbols @@ -0,0 +1,89 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) + +(Observable.prototype).map = function() { } +>Observable.prototype : Symbol(Observable.prototype) +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) +>prototype : Symbol(Observable.prototype) + +declare module "./observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + map(proj: (e:T) => U): Observable +>map : Symbol(map, Decl(map.ts, 6, 29)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>proj : Symbol(proj, Decl(map.ts, 7, 15)) +>e : Symbol(e, Decl(map.ts, 7, 22)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>U : Symbol(U, Decl(map.ts, 7, 12)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + let someAnotherValue: string; +>someAnotherValue : Symbol(someAnotherValue, Decl(map.ts, 10, 11)) + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + filter(pred: (e:T) => boolean): Observable; +>filter : Symbol(filter, Decl(observable.ts, 0, 36)) +>pred : Symbol(pred, Decl(observable.ts, 1, 11)) +>e : Symbol(e, Decl(observable.ts, 1, 18)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +} + +export namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + export let someValue: number; +>someValue : Symbol(someValue, Decl(observable.ts, 5, 14)) +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +import "./map"; + +let x: Observable; +>x : Symbol(x, Decl(main.ts, 3, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +let y = x.map(x => x + 1); +>y : Symbol(y, Decl(main.ts, 4, 3)) +>x.map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 3, 3)) +>map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 4, 14)) +>x : Symbol(x, Decl(main.ts, 4, 14)) + +let z1 = Observable.someValue.toFixed(); +>z1 : Symbol(z1, Decl(main.ts, 5, 3)) +>Observable.someValue.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>Observable.someValue : Symbol(Observable.someValue, Decl(observable.ts, 5, 14)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) +>someValue : Symbol(Observable.someValue, Decl(observable.ts, 5, 14)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +let z2 = Observable.someAnotherValue.toLowerCase(); +>z2 : Symbol(z2, Decl(main.ts, 6, 3)) +>Observable.someAnotherValue.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>Observable.someAnotherValue : Symbol(Observable.someAnotherValue, Decl(map.ts, 10, 11)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) +>someAnotherValue : Symbol(Observable.someAnotherValue, Decl(map.ts, 10, 11)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/moduleAugmentationDeclarationEmit2.types b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.types new file mode 100644 index 0000000000000..85e4ead2ac0cc --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDeclarationEmit2.types @@ -0,0 +1,101 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : typeof Observable + +(Observable.prototype).map = function() { } +>(Observable.prototype).map = function() { } : () => void +>(Observable.prototype).map : any +>(Observable.prototype) : any +>Observable.prototype : any +>Observable.prototype : Observable +>Observable : typeof Observable +>prototype : Observable +>map : any +>function() { } : () => void + +declare module "./observable" { + interface Observable { +>Observable : Observable +>T : T + + map(proj: (e:T) => U): Observable +>map : (proj: (e: T) => U) => Observable +>U : U +>proj : (e: T) => U +>e : T +>T : T +>U : U +>Observable : Observable +>U : U + } + namespace Observable { +>Observable : typeof Observable + + let someAnotherValue: string; +>someAnotherValue : string + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Observable +>T : T + + filter(pred: (e:T) => boolean): Observable; +>filter : (pred: (e: T) => boolean) => Observable +>pred : (e: T) => boolean +>e : T +>T : T +>Observable : Observable +>T : T +} + +export namespace Observable { +>Observable : typeof Observable + + export let someValue: number; +>someValue : number +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : typeof Observable + +import "./map"; + +let x: Observable; +>x : Observable +>Observable : Observable + +let y = x.map(x => x + 1); +>y : Observable +>x.map(x => x + 1) : Observable +>x.map : (proj: (e: number) => U) => Observable +>x : Observable +>map : (proj: (e: number) => U) => Observable +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : number + +let z1 = Observable.someValue.toFixed(); +>z1 : string +>Observable.someValue.toFixed() : string +>Observable.someValue.toFixed : (fractionDigits?: number) => string +>Observable.someValue : number +>Observable : typeof Observable +>someValue : number +>toFixed : (fractionDigits?: number) => string + +let z2 = Observable.someAnotherValue.toLowerCase(); +>z2 : string +>Observable.someAnotherValue.toLowerCase() : string +>Observable.someAnotherValue.toLowerCase : () => string +>Observable.someAnotherValue : string +>Observable : typeof Observable +>someAnotherValue : string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/moduleAugmentationDisallowedExtensions.errors.txt b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.errors.txt new file mode 100644 index 0000000000000..571b288c04a44 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.errors.txt @@ -0,0 +1,117 @@ +tests/cases/compiler/x.ts(7,9): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(8,9): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(9,11): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(10,10): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(10,14): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(10,23): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(10,38): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(10,43): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(10,48): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(11,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(12,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(15,11): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(16,14): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(17,10): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/x.ts(18,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. +tests/cases/compiler/x.ts(18,26): error TS2307: Cannot find module './x0'. +tests/cases/compiler/x.ts(19,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. +tests/cases/compiler/x.ts(19,21): error TS2307: Cannot find module './x0'. +tests/cases/compiler/x.ts(20,5): error TS2666: Exports and export assignments are not permitted in module augmentations. +tests/cases/compiler/x.ts(20,19): error TS2307: Cannot find module './x0'. +tests/cases/compiler/x.ts(21,5): error TS2666: Exports and export assignments are not permitted in module augmentations. +tests/cases/compiler/x.ts(21,21): error TS2307: Cannot find module './x0'. +tests/cases/compiler/x.ts(25,5): error TS2666: Exports and export assignments are not permitted in module augmentations. + + +==== tests/cases/compiler/x0.ts (0 errors) ==== + + export let a = 1; + +==== tests/cases/compiler/x.ts (23 errors) ==== + + namespace N1 { + export let x = 1; + } + + declare module "./observable" { + var x: number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let y: number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + const z: number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let {x1, y1, z0: {n}, z1: {arr: [el1, el2, el3]}}: {x1: number, y1: string, z0: {n: number}, z1: {arr: number[]} } + ~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + interface A { x } + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + namespace N { + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + export class C {} + } + class Cls {} + ~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + function foo(): number; + ~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + type T = number; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + import * as all from "./x0"; + ~~~~~~ +!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. + ~~~~~~ +!!! error TS2307: Cannot find module './x0'. + import {a} from "./x0"; + ~~~~~~ +!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. + ~~~~~~ +!!! error TS2307: Cannot find module './x0'. + export * from "./x0"; + ~~~~~~ +!!! error TS2666: Exports and export assignments are not permitted in module augmentations. + ~~~~~~ +!!! error TS2307: Cannot find module './x0'. + export {a} from "./x0"; + ~~~~~~ +!!! error TS2666: Exports and export assignments are not permitted in module augmentations. + ~~~~~~ +!!! error TS2307: Cannot find module './x0'. + } + + declare module "./test" { + export = N1; + ~~~~~~ +!!! error TS2666: Exports and export assignments are not permitted in module augmentations. + } + export {} + +==== tests/cases/compiler/observable.ts (0 errors) ==== + export declare class Observable { + filter(pred: (e:T) => boolean): Observable; + } + export var x = 1; + +==== tests/cases/compiler/test.ts (0 errors) ==== + export let b = 1; + +==== tests/cases/compiler/main.ts (0 errors) ==== + import { Observable } from "./observable" + import "./x"; + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationDisallowedExtensions.js b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.js new file mode 100644 index 0000000000000..8c497d63c4255 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationDisallowedExtensions.js @@ -0,0 +1,67 @@ +//// [tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts] //// + +//// [x0.ts] + +export let a = 1; + +//// [x.ts] + +namespace N1 { + export let x = 1; +} + +declare module "./observable" { + var x: number; + let y: number; + const z: number; + let {x1, y1, z0: {n}, z1: {arr: [el1, el2, el3]}}: {x1: number, y1: string, z0: {n: number}, z1: {arr: number[]} } + interface A { x } + namespace N { + export class C {} + } + class Cls {} + function foo(): number; + type T = number; + import * as all from "./x0"; + import {a} from "./x0"; + export * from "./x0"; + export {a} from "./x0"; +} + +declare module "./test" { + export = N1; +} +export {} + +//// [observable.ts] +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} +export var x = 1; + +//// [test.ts] +export let b = 1; + +//// [main.ts] +import { Observable } from "./observable" +import "./x"; + + +//// [x0.js] +"use strict"; +exports.a = 1; +//// [x.js] +"use strict"; +var N1; +(function (N1) { + N1.x = 1; +})(N1 || (N1 = {})); +//// [observable.js] +"use strict"; +exports.x = 1; +//// [test.js] +"use strict"; +exports.b = 1; +//// [main.js] +"use strict"; +require("./x"); diff --git a/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.js b/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.js new file mode 100644 index 0000000000000..0a8b1b0b4b537 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/moduleAugmentationExtendAmbientModule1.ts] //// + +//// [map.ts] + +import { Observable } from "observable" + +(Observable.prototype).map = function() { } + +declare module "observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: number; + } +} + +//// [observable.d.ts] +declare module "observable" { + class Observable { + filter(pred: (e:T) => boolean): Observable; + } + namespace Observable { + let someValue: number; + } +} + +//// [main.ts] + +/// +import { Observable } from "observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); + +//// [map.js] +"use strict"; +var observable_1 = require("observable"); +observable_1.Observable.prototype.map = function () { }; +//// [main.js] +"use strict"; +require("./map"); +var x; +var y = x.map(function (x) { return x + 1; }); diff --git a/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.symbols b/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.symbols new file mode 100644 index 0000000000000..a471651da0b0e --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.symbols @@ -0,0 +1,75 @@ +=== tests/cases/compiler/main.ts === + +/// +import { Observable } from "observable" +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +import "./map"; + +let x: Observable; +>x : Symbol(x, Decl(main.ts, 5, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +let y = x.map(x => x + 1); +>y : Symbol(y, Decl(main.ts, 6, 3)) +>x.map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 5, 3)) +>map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 6, 14)) +>x : Symbol(x, Decl(main.ts, 6, 14)) + +=== tests/cases/compiler/map.ts === + +import { Observable } from "observable" +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) + +(Observable.prototype).map = function() { } +>Observable.prototype : Symbol(Observable.prototype) +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) +>prototype : Symbol(Observable.prototype) + +declare module "observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) + + map(proj: (e:T) => U): Observable +>map : Symbol(map, Decl(map.ts, 6, 29)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>proj : Symbol(proj, Decl(map.ts, 7, 15)) +>e : Symbol(e, Decl(map.ts, 7, 22)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>U : Symbol(U, Decl(map.ts, 7, 12)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) + + let someAnotherValue: number; +>someAnotherValue : Symbol(someAnotherValue, Decl(map.ts, 10, 11)) + } +} + +=== tests/cases/compiler/observable.d.ts === +declare module "observable" { + class Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) + + filter(pred: (e:T) => boolean): Observable; +>filter : Symbol(filter, Decl(observable.d.ts, 1, 25)) +>pred : Symbol(pred, Decl(observable.d.ts, 2, 15)) +>e : Symbol(e, Decl(observable.d.ts, 2, 22)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) + + let someValue: number; +>someValue : Symbol(someValue, Decl(observable.d.ts, 5, 11)) + } +} + diff --git a/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.types b/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.types new file mode 100644 index 0000000000000..e6ee79e358508 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendAmbientModule1.types @@ -0,0 +1,85 @@ +=== tests/cases/compiler/main.ts === + +/// +import { Observable } from "observable" +>Observable : typeof Observable + +import "./map"; + +let x: Observable; +>x : Observable +>Observable : Observable + +let y = x.map(x => x + 1); +>y : Observable +>x.map(x => x + 1) : Observable +>x.map : (proj: (e: number) => U) => Observable +>x : Observable +>map : (proj: (e: number) => U) => Observable +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : number + +=== tests/cases/compiler/map.ts === + +import { Observable } from "observable" +>Observable : typeof Observable + +(Observable.prototype).map = function() { } +>(Observable.prototype).map = function() { } : () => void +>(Observable.prototype).map : any +>(Observable.prototype) : any +>Observable.prototype : any +>Observable.prototype : Observable +>Observable : typeof Observable +>prototype : Observable +>map : any +>function() { } : () => void + +declare module "observable" { + interface Observable { +>Observable : Observable +>T : T + + map(proj: (e:T) => U): Observable +>map : (proj: (e: T) => U) => Observable +>U : U +>proj : (e: T) => U +>e : T +>T : T +>U : U +>Observable : Observable +>U : U + } + namespace Observable { +>Observable : typeof Observable + + let someAnotherValue: number; +>someAnotherValue : number + } +} + +=== tests/cases/compiler/observable.d.ts === +declare module "observable" { + class Observable { +>Observable : Observable +>T : T + + filter(pred: (e:T) => boolean): Observable; +>filter : (pred: (e: T) => boolean) => Observable +>pred : (e: T) => boolean +>e : T +>T : T +>Observable : Observable +>T : T + } + namespace Observable { +>Observable : typeof Observable + + let someValue: number; +>someValue : number + } +} + diff --git a/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js new file mode 100644 index 0000000000000..733f88e61290f --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/moduleAugmentationExtendAmbientModule2.ts] //// + +//// [map.ts] + +import { Observable } from "observable" + +(Observable.prototype).map = function() { } + +declare module "observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: string; + } +} + +//// [observable.d.ts] +declare module "observable" { + class Observable { + filter(pred: (e:T) => boolean): Observable; + } + namespace Observable { + export let someValue: number; + } +} + +//// [main.ts] + +/// +import { Observable } from "observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); +let z1 = Observable.someValue.toFixed(); +let z2 = Observable.someAnotherValue.toLowerCase(); + +//// [map.js] +"use strict"; +var observable_1 = require("observable"); +observable_1.Observable.prototype.map = function () { }; +//// [main.js] +"use strict"; +/// +var observable_1 = require("observable"); +require("./map"); +var x; +var y = x.map(function (x) { return x + 1; }); +var z1 = observable_1.Observable.someValue.toFixed(); +var z2 = observable_1.Observable.someAnotherValue.toLowerCase(); + + +//// [map.d.ts] +declare module "observable" { + interface Observable { + map(proj: (e: T) => U): Observable; + } + namespace Observable { + let someAnotherValue: string; + } +} +export {}; +//// [main.d.ts] +/// diff --git a/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.symbols b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.symbols new file mode 100644 index 0000000000000..f907f4d6979c2 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.symbols @@ -0,0 +1,91 @@ +=== tests/cases/compiler/main.ts === + +/// +import { Observable } from "observable" +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +import "./map"; + +let x: Observable; +>x : Symbol(x, Decl(main.ts, 5, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +let y = x.map(x => x + 1); +>y : Symbol(y, Decl(main.ts, 6, 3)) +>x.map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 5, 3)) +>map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 6, 14)) +>x : Symbol(x, Decl(main.ts, 6, 14)) + +let z1 = Observable.someValue.toFixed(); +>z1 : Symbol(z1, Decl(main.ts, 7, 3)) +>Observable.someValue.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>Observable.someValue : Symbol(Observable.someValue, Decl(observable.d.ts, 5, 18)) +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) +>someValue : Symbol(Observable.someValue, Decl(observable.d.ts, 5, 18)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +let z2 = Observable.someAnotherValue.toLowerCase(); +>z2 : Symbol(z2, Decl(main.ts, 8, 3)) +>Observable.someAnotherValue.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>Observable.someAnotherValue : Symbol(Observable.someAnotherValue, Decl(map.ts, 10, 11)) +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) +>someAnotherValue : Symbol(Observable.someAnotherValue, Decl(map.ts, 10, 11)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + +=== tests/cases/compiler/map.ts === + +import { Observable } from "observable" +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) + +(Observable.prototype).map = function() { } +>Observable.prototype : Symbol(Observable.prototype) +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) +>prototype : Symbol(Observable.prototype) + +declare module "observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) + + map(proj: (e:T) => U): Observable +>map : Symbol(map, Decl(map.ts, 6, 29)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>proj : Symbol(proj, Decl(map.ts, 7, 15)) +>e : Symbol(e, Decl(map.ts, 7, 22)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>U : Symbol(U, Decl(map.ts, 7, 12)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) + + let someAnotherValue: string; +>someAnotherValue : Symbol(someAnotherValue, Decl(map.ts, 10, 11)) + } +} + +=== tests/cases/compiler/observable.d.ts === +declare module "observable" { + class Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) + + filter(pred: (e:T) => boolean): Observable; +>filter : Symbol(filter, Decl(observable.d.ts, 1, 25)) +>pred : Symbol(pred, Decl(observable.d.ts, 2, 15)) +>e : Symbol(e, Decl(observable.d.ts, 2, 22)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.d.ts, 1, 21), Decl(map.ts, 6, 25)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.d.ts, 0, 29), Decl(observable.d.ts, 3, 5), Decl(map.ts, 5, 29), Decl(map.ts, 8, 5)) + + export let someValue: number; +>someValue : Symbol(someValue, Decl(observable.d.ts, 5, 18)) + } +} + diff --git a/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.types b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.types new file mode 100644 index 0000000000000..70288e48f028b --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendAmbientModule2.types @@ -0,0 +1,103 @@ +=== tests/cases/compiler/main.ts === + +/// +import { Observable } from "observable" +>Observable : typeof Observable + +import "./map"; + +let x: Observable; +>x : Observable +>Observable : Observable + +let y = x.map(x => x + 1); +>y : Observable +>x.map(x => x + 1) : Observable +>x.map : (proj: (e: number) => U) => Observable +>x : Observable +>map : (proj: (e: number) => U) => Observable +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : number + +let z1 = Observable.someValue.toFixed(); +>z1 : string +>Observable.someValue.toFixed() : string +>Observable.someValue.toFixed : (fractionDigits?: number) => string +>Observable.someValue : number +>Observable : typeof Observable +>someValue : number +>toFixed : (fractionDigits?: number) => string + +let z2 = Observable.someAnotherValue.toLowerCase(); +>z2 : string +>Observable.someAnotherValue.toLowerCase() : string +>Observable.someAnotherValue.toLowerCase : () => string +>Observable.someAnotherValue : string +>Observable : typeof Observable +>someAnotherValue : string +>toLowerCase : () => string + +=== tests/cases/compiler/map.ts === + +import { Observable } from "observable" +>Observable : typeof Observable + +(Observable.prototype).map = function() { } +>(Observable.prototype).map = function() { } : () => void +>(Observable.prototype).map : any +>(Observable.prototype) : any +>Observable.prototype : any +>Observable.prototype : Observable +>Observable : typeof Observable +>prototype : Observable +>map : any +>function() { } : () => void + +declare module "observable" { + interface Observable { +>Observable : Observable +>T : T + + map(proj: (e:T) => U): Observable +>map : (proj: (e: T) => U) => Observable +>U : U +>proj : (e: T) => U +>e : T +>T : T +>U : U +>Observable : Observable +>U : U + } + namespace Observable { +>Observable : typeof Observable + + let someAnotherValue: string; +>someAnotherValue : string + } +} + +=== tests/cases/compiler/observable.d.ts === +declare module "observable" { + class Observable { +>Observable : Observable +>T : T + + filter(pred: (e:T) => boolean): Observable; +>filter : (pred: (e: T) => boolean) => Observable +>pred : (e: T) => boolean +>e : T +>T : T +>Observable : Observable +>T : T + } + namespace Observable { +>Observable : typeof Observable + + export let someValue: number; +>someValue : number + } +} + diff --git a/tests/baselines/reference/moduleAugmentationExtendFileModule1.js b/tests/baselines/reference/moduleAugmentationExtendFileModule1.js new file mode 100644 index 0000000000000..a539100c2ed87 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendFileModule1.js @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/moduleAugmentationExtendFileModule1.ts] //// + +//// [map.ts] + +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: number; + } +} + +//// [observable.ts] +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + let someValue: number; +} + + +//// [main.ts] +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); + +//// [observable.js] +"use strict"; +var Observable; +(function (Observable) { + var someValue; +})(Observable = exports.Observable || (exports.Observable = {})); +//// [map.js] +"use strict"; +var observable_1 = require("./observable"); +observable_1.Observable.prototype.map = function () { }; +//// [main.js] +"use strict"; +require("./map"); +var x; +var y = x.map(function (x) { return x + 1; }); diff --git a/tests/baselines/reference/moduleAugmentationExtendFileModule1.symbols b/tests/baselines/reference/moduleAugmentationExtendFileModule1.symbols new file mode 100644 index 0000000000000..eca44ec774d73 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendFileModule1.symbols @@ -0,0 +1,73 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) + +(Observable.prototype).map = function() { } +>Observable.prototype : Symbol(Observable.prototype) +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) +>prototype : Symbol(Observable.prototype) + +declare module "./observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + map(proj: (e:T) => U): Observable +>map : Symbol(map, Decl(map.ts, 6, 29)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>proj : Symbol(proj, Decl(map.ts, 7, 15)) +>e : Symbol(e, Decl(map.ts, 7, 22)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>U : Symbol(U, Decl(map.ts, 7, 12)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + let someAnotherValue: number; +>someAnotherValue : Symbol(someAnotherValue, Decl(map.ts, 10, 11)) + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + filter(pred: (e:T) => boolean): Observable; +>filter : Symbol(filter, Decl(observable.ts, 0, 36)) +>pred : Symbol(pred, Decl(observable.ts, 1, 11)) +>e : Symbol(e, Decl(observable.ts, 1, 18)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +} + +export namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + let someValue: number; +>someValue : Symbol(someValue, Decl(observable.ts, 5, 7)) +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +import "./map"; + +let x: Observable; +>x : Symbol(x, Decl(main.ts, 3, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +let y = x.map(x => x + 1); +>y : Symbol(y, Decl(main.ts, 4, 3)) +>x.map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 3, 3)) +>map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 4, 14)) +>x : Symbol(x, Decl(main.ts, 4, 14)) + diff --git a/tests/baselines/reference/moduleAugmentationExtendFileModule1.types b/tests/baselines/reference/moduleAugmentationExtendFileModule1.types new file mode 100644 index 0000000000000..fad835029c24d --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendFileModule1.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : typeof Observable + +(Observable.prototype).map = function() { } +>(Observable.prototype).map = function() { } : () => void +>(Observable.prototype).map : any +>(Observable.prototype) : any +>Observable.prototype : any +>Observable.prototype : Observable +>Observable : typeof Observable +>prototype : Observable +>map : any +>function() { } : () => void + +declare module "./observable" { + interface Observable { +>Observable : Observable +>T : T + + map(proj: (e:T) => U): Observable +>map : (proj: (e: T) => U) => Observable +>U : U +>proj : (e: T) => U +>e : T +>T : T +>U : U +>Observable : Observable +>U : U + } + namespace Observable { +>Observable : typeof Observable + + let someAnotherValue: number; +>someAnotherValue : number + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Observable +>T : T + + filter(pred: (e:T) => boolean): Observable; +>filter : (pred: (e: T) => boolean) => Observable +>pred : (e: T) => boolean +>e : T +>T : T +>Observable : Observable +>T : T +} + +export namespace Observable { +>Observable : typeof Observable + + let someValue: number; +>someValue : number +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : typeof Observable + +import "./map"; + +let x: Observable; +>x : Observable +>Observable : Observable + +let y = x.map(x => x + 1); +>y : Observable +>x.map(x => x + 1) : Observable +>x.map : (proj: (e: number) => U) => Observable +>x : Observable +>map : (proj: (e: number) => U) => Observable +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : number + diff --git a/tests/baselines/reference/moduleAugmentationExtendFileModule2.js b/tests/baselines/reference/moduleAugmentationExtendFileModule2.js new file mode 100644 index 0000000000000..389f2119abaa2 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendFileModule2.js @@ -0,0 +1,53 @@ +//// [tests/cases/compiler/moduleAugmentationExtendFileModule2.ts] //// + +//// [map.ts] + +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: string; + } +} + +//// [observable.ts] +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + export let someValue: number; +} + + +//// [main.ts] +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); +let z1 = Observable.someValue.toFixed(); +let z2 = Observable.someAnotherValue.toLowerCase(); + +//// [observable.js] +"use strict"; +var Observable; +(function (Observable) { +})(Observable = exports.Observable || (exports.Observable = {})); +//// [map.js] +"use strict"; +var observable_1 = require("./observable"); +observable_1.Observable.prototype.map = function () { }; +//// [main.js] +"use strict"; +var observable_1 = require("./observable"); +require("./map"); +var x; +var y = x.map(function (x) { return x + 1; }); +var z1 = observable_1.Observable.someValue.toFixed(); +var z2 = observable_1.Observable.someAnotherValue.toLowerCase(); diff --git a/tests/baselines/reference/moduleAugmentationExtendFileModule2.symbols b/tests/baselines/reference/moduleAugmentationExtendFileModule2.symbols new file mode 100644 index 0000000000000..d0f25f693fe8d --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendFileModule2.symbols @@ -0,0 +1,89 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) + +(Observable.prototype).map = function() { } +>Observable.prototype : Symbol(Observable.prototype) +>Observable : Symbol(Observable, Decl(map.ts, 1, 8)) +>prototype : Symbol(Observable.prototype) + +declare module "./observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + map(proj: (e:T) => U): Observable +>map : Symbol(map, Decl(map.ts, 6, 29)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>proj : Symbol(proj, Decl(map.ts, 7, 15)) +>e : Symbol(e, Decl(map.ts, 7, 22)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>U : Symbol(U, Decl(map.ts, 7, 12)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>U : Symbol(U, Decl(map.ts, 7, 12)) + } + namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + let someAnotherValue: string; +>someAnotherValue : Symbol(someAnotherValue, Decl(map.ts, 10, 11)) + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) + + filter(pred: (e:T) => boolean): Observable; +>filter : Symbol(filter, Decl(observable.ts, 0, 36)) +>pred : Symbol(pred, Decl(observable.ts, 1, 11)) +>e : Symbol(e, Decl(observable.ts, 1, 18)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) +>T : Symbol(T, Decl(observable.ts, 0, 32), Decl(map.ts, 6, 25)) +} + +export namespace Observable { +>Observable : Symbol(Observable, Decl(observable.ts, 0, 0), Decl(observable.ts, 2, 1), Decl(map.ts, 5, 31), Decl(map.ts, 8, 5)) + + export let someValue: number; +>someValue : Symbol(someValue, Decl(observable.ts, 5, 14)) +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +import "./map"; + +let x: Observable; +>x : Symbol(x, Decl(main.ts, 3, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) + +let y = x.map(x => x + 1); +>y : Symbol(y, Decl(main.ts, 4, 3)) +>x.map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 3, 3)) +>map : Symbol(Observable.map, Decl(map.ts, 6, 29)) +>x : Symbol(x, Decl(main.ts, 4, 14)) +>x : Symbol(x, Decl(main.ts, 4, 14)) + +let z1 = Observable.someValue.toFixed(); +>z1 : Symbol(z1, Decl(main.ts, 5, 3)) +>Observable.someValue.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>Observable.someValue : Symbol(Observable.someValue, Decl(observable.ts, 5, 14)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) +>someValue : Symbol(Observable.someValue, Decl(observable.ts, 5, 14)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +let z2 = Observable.someAnotherValue.toLowerCase(); +>z2 : Symbol(z2, Decl(main.ts, 6, 3)) +>Observable.someAnotherValue.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>Observable.someAnotherValue : Symbol(Observable.someAnotherValue, Decl(map.ts, 10, 11)) +>Observable : Symbol(Observable, Decl(main.ts, 0, 8)) +>someAnotherValue : Symbol(Observable.someAnotherValue, Decl(map.ts, 10, 11)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/moduleAugmentationExtendFileModule2.types b/tests/baselines/reference/moduleAugmentationExtendFileModule2.types new file mode 100644 index 0000000000000..85e4ead2ac0cc --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationExtendFileModule2.types @@ -0,0 +1,101 @@ +=== tests/cases/compiler/map.ts === + +import { Observable } from "./observable" +>Observable : typeof Observable + +(Observable.prototype).map = function() { } +>(Observable.prototype).map = function() { } : () => void +>(Observable.prototype).map : any +>(Observable.prototype) : any +>Observable.prototype : any +>Observable.prototype : Observable +>Observable : typeof Observable +>prototype : Observable +>map : any +>function() { } : () => void + +declare module "./observable" { + interface Observable { +>Observable : Observable +>T : T + + map(proj: (e:T) => U): Observable +>map : (proj: (e: T) => U) => Observable +>U : U +>proj : (e: T) => U +>e : T +>T : T +>U : U +>Observable : Observable +>U : U + } + namespace Observable { +>Observable : typeof Observable + + let someAnotherValue: string; +>someAnotherValue : string + } +} + +=== tests/cases/compiler/observable.ts === +export declare class Observable { +>Observable : Observable +>T : T + + filter(pred: (e:T) => boolean): Observable; +>filter : (pred: (e: T) => boolean) => Observable +>pred : (e: T) => boolean +>e : T +>T : T +>Observable : Observable +>T : T +} + +export namespace Observable { +>Observable : typeof Observable + + export let someValue: number; +>someValue : number +} + + +=== tests/cases/compiler/main.ts === +import { Observable } from "./observable" +>Observable : typeof Observable + +import "./map"; + +let x: Observable; +>x : Observable +>Observable : Observable + +let y = x.map(x => x + 1); +>y : Observable +>x.map(x => x + 1) : Observable +>x.map : (proj: (e: number) => U) => Observable +>x : Observable +>map : (proj: (e: number) => U) => Observable +>x => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : number + +let z1 = Observable.someValue.toFixed(); +>z1 : string +>Observable.someValue.toFixed() : string +>Observable.someValue.toFixed : (fractionDigits?: number) => string +>Observable.someValue : number +>Observable : typeof Observable +>someValue : number +>toFixed : (fractionDigits?: number) => string + +let z2 = Observable.someAnotherValue.toLowerCase(); +>z2 : string +>Observable.someAnotherValue.toLowerCase() : string +>Observable.someAnotherValue.toLowerCase : () => string +>Observable.someAnotherValue : string +>Observable : typeof Observable +>someAnotherValue : string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/moduleAugmentationGlobal1.js b/tests/baselines/reference/moduleAugmentationGlobal1.js new file mode 100644 index 0000000000000..99351642a18e2 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal1.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/moduleAugmentationGlobal1.ts] //// + +//// [f1.ts] + +export class A {x: number;} + +//// [f2.ts] +import {A} from "./f1"; + +// change the shape of Array +declare global { + interface Array { + getA(): A; + } +} + +let x = [1]; +let y = x.getA().x; + + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +//// [f2.js] +"use strict"; +var x = [1]; +var y = x.getA().x; + + +//// [f1.d.ts] +export declare class A { + x: number; +} +//// [f2.d.ts] +import { A } from "./f1"; +declare global { + interface Array { + getA(): A; + } +} diff --git a/tests/baselines/reference/moduleAugmentationGlobal1.symbols b/tests/baselines/reference/moduleAugmentationGlobal1.symbols new file mode 100644 index 0000000000000..36139555c9615 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal1.symbols @@ -0,0 +1,35 @@ +=== tests/cases/compiler/f1.ts === + +export class A {x: number;} +>A : Symbol(A, Decl(f1.ts, 0, 0)) +>x : Symbol(x, Decl(f1.ts, 1, 16)) + +=== tests/cases/compiler/f2.ts === +import {A} from "./f1"; +>A : Symbol(A, Decl(f2.ts, 0, 8)) + +// change the shape of Array +declare global { +>global : Symbol(, Decl(f2.ts, 0, 23)) + + interface Array { +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 3, 16)) +>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(f2.ts, 4, 20)) + + getA(): A; +>getA : Symbol(getA, Decl(f2.ts, 4, 24)) +>A : Symbol(A, Decl(f2.ts, 0, 8)) + } +} + +let x = [1]; +>x : Symbol(x, Decl(f2.ts, 9, 3)) + +let y = x.getA().x; +>y : Symbol(y, Decl(f2.ts, 10, 3)) +>x.getA().x : Symbol(A.x, Decl(f1.ts, 1, 16)) +>x.getA : Symbol(Array.getA, Decl(f2.ts, 4, 24)) +>x : Symbol(x, Decl(f2.ts, 9, 3)) +>getA : Symbol(Array.getA, Decl(f2.ts, 4, 24)) +>x : Symbol(A.x, Decl(f1.ts, 1, 16)) + diff --git a/tests/baselines/reference/moduleAugmentationGlobal1.types b/tests/baselines/reference/moduleAugmentationGlobal1.types new file mode 100644 index 0000000000000..c1742edd7c07f --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal1.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/f1.ts === + +export class A {x: number;} +>A : A +>x : number + +=== tests/cases/compiler/f2.ts === +import {A} from "./f1"; +>A : typeof A + +// change the shape of Array +declare global { +>global : typeof + + interface Array { +>Array : T[] +>T : T + + getA(): A; +>getA : () => A +>A : A + } +} + +let x = [1]; +>x : number[] +>[1] : number[] +>1 : number + +let y = x.getA().x; +>y : number +>x.getA().x : number +>x.getA() : A +>x.getA : () => A +>x : number[] +>getA : () => A +>x : number + diff --git a/tests/baselines/reference/moduleAugmentationGlobal2.js b/tests/baselines/reference/moduleAugmentationGlobal2.js new file mode 100644 index 0000000000000..90e8373302e2c --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal2.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/moduleAugmentationGlobal2.ts] //// + +//// [f1.ts] + +export class A {}; +//// [f2.ts] + +// change the shape of Array +import {A} from "./f1"; + +declare global { + interface Array { + getCountAsString(): string; + } +} + +let x = [1]; +let y = x.getCountAsString().toLowerCase(); + + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +; +//// [f2.js] +"use strict"; +var x = [1]; +var y = x.getCountAsString().toLowerCase(); + + +//// [f1.d.ts] +export declare class A { +} +//// [f2.d.ts] +declare global { + interface Array { + getCountAsString(): string; + } +} +export {}; diff --git a/tests/baselines/reference/moduleAugmentationGlobal2.symbols b/tests/baselines/reference/moduleAugmentationGlobal2.symbols new file mode 100644 index 0000000000000..4ee2b9bace8b9 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/compiler/f1.ts === + +export class A {}; +>A : Symbol(A, Decl(f1.ts, 0, 0)) + +=== tests/cases/compiler/f2.ts === + +// change the shape of Array +import {A} from "./f1"; +>A : Symbol(A, Decl(f2.ts, 2, 8)) + +declare global { +>global : Symbol(, Decl(f2.ts, 2, 23)) + + interface Array { +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 4, 16)) +>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(f2.ts, 5, 20)) + + getCountAsString(): string; +>getCountAsString : Symbol(getCountAsString, Decl(f2.ts, 5, 24)) + } +} + +let x = [1]; +>x : Symbol(x, Decl(f2.ts, 10, 3)) + +let y = x.getCountAsString().toLowerCase(); +>y : Symbol(y, Decl(f2.ts, 11, 3)) +>x.getCountAsString().toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>x.getCountAsString : Symbol(Array.getCountAsString, Decl(f2.ts, 5, 24)) +>x : Symbol(x, Decl(f2.ts, 10, 3)) +>getCountAsString : Symbol(Array.getCountAsString, Decl(f2.ts, 5, 24)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/moduleAugmentationGlobal2.types b/tests/baselines/reference/moduleAugmentationGlobal2.types new file mode 100644 index 0000000000000..36ef480d8b29c --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal2.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/f1.ts === + +export class A {}; +>A : A + +=== tests/cases/compiler/f2.ts === + +// change the shape of Array +import {A} from "./f1"; +>A : typeof A + +declare global { +>global : typeof + + interface Array { +>Array : T[] +>T : T + + getCountAsString(): string; +>getCountAsString : () => string + } +} + +let x = [1]; +>x : number[] +>[1] : number[] +>1 : number + +let y = x.getCountAsString().toLowerCase(); +>y : string +>x.getCountAsString().toLowerCase() : string +>x.getCountAsString().toLowerCase : () => string +>x.getCountAsString() : string +>x.getCountAsString : () => string +>x : number[] +>getCountAsString : () => string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/moduleAugmentationGlobal3.js b/tests/baselines/reference/moduleAugmentationGlobal3.js new file mode 100644 index 0000000000000..4cff75f5df006 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal3.js @@ -0,0 +1,52 @@ +//// [tests/cases/compiler/moduleAugmentationGlobal3.ts] //// + +//// [f1.ts] + +export class A {}; +//// [f2.ts] + +// change the shape of Array +import {A} from "./f1"; + +declare global { + interface Array { + getCountAsString(): string; + } +} + +//// [f3.ts] +import "./f2"; + +let x = [1]; +let y = x.getCountAsString().toLowerCase(); + + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +; +//// [f2.js] +"use strict"; +//// [f3.js] +"use strict"; +require("./f2"); +var x = [1]; +var y = x.getCountAsString().toLowerCase(); + + +//// [f1.d.ts] +export declare class A { +} +//// [f2.d.ts] +declare global { + interface Array { + getCountAsString(): string; + } +} +export {}; +//// [f3.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationGlobal3.symbols b/tests/baselines/reference/moduleAugmentationGlobal3.symbols new file mode 100644 index 0000000000000..acb9a7b9e5829 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal3.symbols @@ -0,0 +1,37 @@ +=== tests/cases/compiler/f1.ts === + +export class A {}; +>A : Symbol(A, Decl(f1.ts, 0, 0)) + +=== tests/cases/compiler/f2.ts === + +// change the shape of Array +import {A} from "./f1"; +>A : Symbol(A, Decl(f2.ts, 2, 8)) + +declare global { +>global : Symbol(, Decl(f2.ts, 2, 23)) + + interface Array { +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(f2.ts, 4, 16)) +>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(f2.ts, 5, 20)) + + getCountAsString(): string; +>getCountAsString : Symbol(getCountAsString, Decl(f2.ts, 5, 24)) + } +} + +=== tests/cases/compiler/f3.ts === +import "./f2"; + +let x = [1]; +>x : Symbol(x, Decl(f3.ts, 2, 3)) + +let y = x.getCountAsString().toLowerCase(); +>y : Symbol(y, Decl(f3.ts, 3, 3)) +>x.getCountAsString().toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>x.getCountAsString : Symbol(Array.getCountAsString, Decl(f2.ts, 5, 24)) +>x : Symbol(x, Decl(f3.ts, 2, 3)) +>getCountAsString : Symbol(Array.getCountAsString, Decl(f2.ts, 5, 24)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/moduleAugmentationGlobal3.types b/tests/baselines/reference/moduleAugmentationGlobal3.types new file mode 100644 index 0000000000000..58d7f30faab08 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal3.types @@ -0,0 +1,41 @@ +=== tests/cases/compiler/f1.ts === + +export class A {}; +>A : A + +=== tests/cases/compiler/f2.ts === + +// change the shape of Array +import {A} from "./f1"; +>A : typeof A + +declare global { +>global : typeof + + interface Array { +>Array : T[] +>T : T + + getCountAsString(): string; +>getCountAsString : () => string + } +} + +=== tests/cases/compiler/f3.ts === +import "./f2"; + +let x = [1]; +>x : number[] +>[1] : number[] +>1 : number + +let y = x.getCountAsString().toLowerCase(); +>y : string +>x.getCountAsString().toLowerCase() : string +>x.getCountAsString().toLowerCase : () => string +>x.getCountAsString() : string +>x.getCountAsString : () => string +>x : number[] +>getCountAsString : () => string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/moduleAugmentationGlobal4.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal4.errors.txt new file mode 100644 index 0000000000000..fd3444f56b1ec --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal4.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/f1.ts(3,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/f2.ts(3,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/f1.ts (1 errors) ==== + + declare global { + interface Something {x} + ~~~~~~~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + export {}; +==== tests/cases/compiler/f2.ts (1 errors) ==== + + declare global { + interface Something {y} + ~~~~~~~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + export {}; +==== tests/cases/compiler/f3.ts (0 errors) ==== + import "./f1"; + import "./f2"; + + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal4.js b/tests/baselines/reference/moduleAugmentationGlobal4.js new file mode 100644 index 0000000000000..11c5d968df206 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal4.js @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/moduleAugmentationGlobal4.ts] //// + +//// [f1.ts] + +declare global { + interface Something {x} +} +export {}; +//// [f2.ts] + +declare global { + interface Something {y} +} +export {}; +//// [f3.ts] +import "./f1"; +import "./f2"; + + + +//// [f1.js] +"use strict"; +//// [f2.js] +"use strict"; +//// [f3.js] +"use strict"; +require("./f1"); +require("./f2"); + + +//// [f1.d.ts] +declare global { + interface Something { + x: any; + } +} +export { }; +export {}; +//// [f2.d.ts] +declare global { + interface Something { + y: any; + } +} +export { }; +export {}; +//// [f3.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationGlobal5.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal5.errors.txt new file mode 100644 index 0000000000000..4f1f91337607d --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal5.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/f1.d.ts(4,19): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/f2.d.ts(3,19): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/f3.ts (0 errors) ==== + /// + /// + import "A"; + import "B"; + + +==== tests/cases/compiler/f1.d.ts (1 errors) ==== + + declare module "A" { + global { + interface Something {x} + ~~~~~~~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + } +==== tests/cases/compiler/f2.d.ts (1 errors) ==== + declare module "B" { + global { + interface Something {y} + ~~~~~~~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal5.js b/tests/baselines/reference/moduleAugmentationGlobal5.js new file mode 100644 index 0000000000000..3efdd2dbb9895 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal5.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/moduleAugmentationGlobal5.ts] //// + +//// [f1.d.ts] + +declare module "A" { + global { + interface Something {x} + } +} +//// [f2.d.ts] +declare module "B" { + global { + interface Something {y} + } +} +//// [f3.ts] +/// +/// +import "A"; +import "B"; + + + +//// [f3.js] +"use strict"; +/// +/// +require("A"); +require("B"); + + +//// [f3.d.ts] +/// +/// diff --git a/tests/baselines/reference/moduleAugmentationGlobal6.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal6.errors.txt new file mode 100644 index 0000000000000..849c45111acd9 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal6.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/moduleAugmentationGlobal6.ts(1,9): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + + +==== tests/cases/compiler/moduleAugmentationGlobal6.ts (1 errors) ==== + declare global { + ~~~~~~ +!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + interface Array { x } + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal6.js b/tests/baselines/reference/moduleAugmentationGlobal6.js new file mode 100644 index 0000000000000..ac988f670d203 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal6.js @@ -0,0 +1,6 @@ +//// [moduleAugmentationGlobal6.ts] +declare global { + interface Array { x } +} + +//// [moduleAugmentationGlobal6.js] diff --git a/tests/baselines/reference/moduleAugmentationGlobal6_1.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal6_1.errors.txt new file mode 100644 index 0000000000000..01315f9fcbca3 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal6_1.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/moduleAugmentationGlobal6_1.ts(1,1): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. +tests/cases/compiler/moduleAugmentationGlobal6_1.ts(1,1): error TS2670: Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context. + + +==== tests/cases/compiler/moduleAugmentationGlobal6_1.ts (2 errors) ==== + global { + ~~~~~~ +!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + ~~~~~~ +!!! error TS2670: Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context. + interface Array { x } + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal6_1.js b/tests/baselines/reference/moduleAugmentationGlobal6_1.js new file mode 100644 index 0000000000000..5ae85debbe25f --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal6_1.js @@ -0,0 +1,6 @@ +//// [moduleAugmentationGlobal6_1.ts] +global { + interface Array { x } +} + +//// [moduleAugmentationGlobal6_1.js] diff --git a/tests/baselines/reference/moduleAugmentationGlobal7.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal7.errors.txt new file mode 100644 index 0000000000000..3ba8003288c54 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal7.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/moduleAugmentationGlobal7.ts(2,13): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + + +==== tests/cases/compiler/moduleAugmentationGlobal7.ts (1 errors) ==== + namespace A { + declare global { + ~~~~~~ +!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + interface Array { x } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal7.js b/tests/baselines/reference/moduleAugmentationGlobal7.js new file mode 100644 index 0000000000000..54c6ddc0de70e --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal7.js @@ -0,0 +1,8 @@ +//// [moduleAugmentationGlobal7.ts] +namespace A { + declare global { + interface Array { x } + } +} + +//// [moduleAugmentationGlobal7.js] diff --git a/tests/baselines/reference/moduleAugmentationGlobal7_1.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal7_1.errors.txt new file mode 100644 index 0000000000000..c2e8282f2bfee --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal7_1.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/moduleAugmentationGlobal7_1.ts(2,5): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. +tests/cases/compiler/moduleAugmentationGlobal7_1.ts(2,5): error TS2670: Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context. + + +==== tests/cases/compiler/moduleAugmentationGlobal7_1.ts (2 errors) ==== + namespace A { + global { + ~~~~~~ +!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + ~~~~~~ +!!! error TS2670: Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context. + interface Array { x } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal7_1.js b/tests/baselines/reference/moduleAugmentationGlobal7_1.js new file mode 100644 index 0000000000000..745be0d76a0f1 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal7_1.js @@ -0,0 +1,8 @@ +//// [moduleAugmentationGlobal7_1.ts] +namespace A { + global { + interface Array { x } + } +} + +//// [moduleAugmentationGlobal7_1.js] diff --git a/tests/baselines/reference/moduleAugmentationGlobal8.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal8.errors.txt new file mode 100644 index 0000000000000..09c84fea2c2c0 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal8.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/moduleAugmentationGlobal8.ts(2,13): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + + +==== tests/cases/compiler/moduleAugmentationGlobal8.ts (1 errors) ==== + namespace A { + declare global { + ~~~~~~ +!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + interface Array { x } + } + } + export {} + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal8.js b/tests/baselines/reference/moduleAugmentationGlobal8.js new file mode 100644 index 0000000000000..261dfd21b5806 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal8.js @@ -0,0 +1,13 @@ +//// [moduleAugmentationGlobal8.ts] +namespace A { + declare global { + interface Array { x } + } +} +export {} + + +//// [moduleAugmentationGlobal8.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); diff --git a/tests/baselines/reference/moduleAugmentationGlobal8_1.errors.txt b/tests/baselines/reference/moduleAugmentationGlobal8_1.errors.txt new file mode 100644 index 0000000000000..022a4f5ec1ac1 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal8_1.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/moduleAugmentationGlobal8_1.ts(2,5): error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. +tests/cases/compiler/moduleAugmentationGlobal8_1.ts(2,5): error TS2670: Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context. + + +==== tests/cases/compiler/moduleAugmentationGlobal8_1.ts (2 errors) ==== + namespace A { + global { + ~~~~~~ +!!! error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations. + ~~~~~~ +!!! error TS2670: Augmentations for the global scope should have 'declare' modifier unless they appear in already ambient context. + interface Array { x } + } + } + export {} + \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationGlobal8_1.js b/tests/baselines/reference/moduleAugmentationGlobal8_1.js new file mode 100644 index 0000000000000..2ac585a711b84 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationGlobal8_1.js @@ -0,0 +1,13 @@ +//// [moduleAugmentationGlobal8_1.ts] +namespace A { + global { + interface Array { x } + } +} +export {} + + +//// [moduleAugmentationGlobal8_1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; +}); diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports1.js b/tests/baselines/reference/moduleAugmentationImportsAndExports1.js new file mode 100644 index 0000000000000..7159e7b5d0c47 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports1.js @@ -0,0 +1,71 @@ +//// [tests/cases/compiler/moduleAugmentationImportsAndExports1.ts] //// + +//// [f1.ts] + +export class A {} + +//// [f2.ts] +export class B { + n: number; +} + +//// [f3.ts] +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } +declare module "./f1" { + interface A { + foo(): B; + } +} + +//// [f4.ts] +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +//// [f2.js] +"use strict"; +var B = (function () { + function B() { + } + return B; +}()); +exports.B = B; +//// [f3.js] +"use strict"; +var f1_1 = require("./f1"); +f1_1.A.prototype.foo = function () { return undefined; }; +//// [f4.js] +"use strict"; +require("./f3"); +var a; +var b = a.foo().n; + + +//// [f1.d.ts] +export declare class A { +} +//// [f2.d.ts] +export declare class B { + n: number; +} +//// [f3.d.ts] +import { B } from "./f2"; +declare module "./f1" { + interface A { + foo(): B; + } +} +//// [f4.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports1.symbols b/tests/baselines/reference/moduleAugmentationImportsAndExports1.symbols new file mode 100644 index 0000000000000..c641cad5228f0 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports1.symbols @@ -0,0 +1,56 @@ +=== tests/cases/compiler/f1.ts === + +export class A {} +>A : Symbol(A, Decl(f1.ts, 0, 0), Decl(f3.ts, 4, 23)) + +=== tests/cases/compiler/f2.ts === +export class B { +>B : Symbol(B, Decl(f2.ts, 0, 0)) + + n: number; +>n : Symbol(n, Decl(f2.ts, 0, 16)) +} + +=== tests/cases/compiler/f3.ts === +import {A} from "./f1"; +>A : Symbol(A, Decl(f3.ts, 0, 8)) + +import {B} from "./f2"; +>B : Symbol(B, Decl(f3.ts, 1, 8)) + +A.prototype.foo = function () { return undefined; } +>A.prototype.foo : Symbol(A.foo, Decl(f3.ts, 5, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(f3.ts, 0, 8)) +>prototype : Symbol(A.prototype) +>foo : Symbol(A.foo, Decl(f3.ts, 5, 17)) +>undefined : Symbol(undefined) + +declare module "./f1" { + interface A { +>A : Symbol(A, Decl(f1.ts, 0, 0), Decl(f3.ts, 4, 23)) + + foo(): B; +>foo : Symbol(foo, Decl(f3.ts, 5, 17)) +>B : Symbol(B, Decl(f3.ts, 1, 8)) + } +} + +=== tests/cases/compiler/f4.ts === +import {A} from "./f1"; +>A : Symbol(A, Decl(f4.ts, 0, 8)) + +import "./f3"; + +let a: A; +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>A : Symbol(A, Decl(f4.ts, 0, 8)) + +let b = a.foo().n; +>b : Symbol(b, Decl(f4.ts, 4, 3)) +>a.foo().n : Symbol(B.n, Decl(f2.ts, 0, 16)) +>a.foo : Symbol(A.foo, Decl(f3.ts, 5, 17)) +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>foo : Symbol(A.foo, Decl(f3.ts, 5, 17)) +>n : Symbol(B.n, Decl(f2.ts, 0, 16)) + diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports1.types b/tests/baselines/reference/moduleAugmentationImportsAndExports1.types new file mode 100644 index 0000000000000..886a04b54ef6b --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports1.types @@ -0,0 +1,59 @@ +=== tests/cases/compiler/f1.ts === + +export class A {} +>A : A + +=== tests/cases/compiler/f2.ts === +export class B { +>B : B + + n: number; +>n : number +} + +=== tests/cases/compiler/f3.ts === +import {A} from "./f1"; +>A : typeof A + +import {B} from "./f2"; +>B : typeof B + +A.prototype.foo = function () { return undefined; } +>A.prototype.foo = function () { return undefined; } : () => any +>A.prototype.foo : () => B +>A.prototype : A +>A : typeof A +>prototype : A +>foo : () => B +>function () { return undefined; } : () => any +>undefined : undefined + +declare module "./f1" { + interface A { +>A : A + + foo(): B; +>foo : () => B +>B : B + } +} + +=== tests/cases/compiler/f4.ts === +import {A} from "./f1"; +>A : typeof A + +import "./f3"; + +let a: A; +>a : A +>A : A + +let b = a.foo().n; +>b : number +>a.foo().n : number +>a.foo() : B +>a.foo : () => B +>a : A +>foo : () => B +>n : number + diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt b/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt new file mode 100644 index 0000000000000..deb3881e209dc --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports2.errors.txt @@ -0,0 +1,73 @@ +tests/cases/compiler/f3.ts(3,13): error TS2339: Property 'foo' does not exist on type 'A'. +tests/cases/compiler/f3.ts(11,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. +tests/cases/compiler/f3.ts(11,21): error TS2307: Cannot find module './f2'. +tests/cases/compiler/f3.ts(12,5): error TS2666: Exports and export assignments are not permitted in module augmentations. +tests/cases/compiler/f3.ts(12,21): error TS2307: Cannot find module './f2'. +tests/cases/compiler/f3.ts(13,12): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/f3.ts(13,16): error TS4000: Import declaration 'I' is using private name 'N'. +tests/cases/compiler/f3.ts(14,12): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/f3.ts(14,16): error TS4000: Import declaration 'C' is using private name 'N'. +tests/cases/compiler/f3.ts(16,15): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/f4.ts(5,11): error TS2339: Property 'foo' does not exist on type 'A'. + + +==== tests/cases/compiler/f1.ts (0 errors) ==== + + export class A {} + +==== tests/cases/compiler/f2.ts (0 errors) ==== + export class B { + n: number; + } + +==== tests/cases/compiler/f3.ts (10 errors) ==== + import {A} from "./f1"; + + A.prototype.foo = function () { return undefined; } + ~~~ +!!! error TS2339: Property 'foo' does not exist on type 'A'. + + namespace N { + export interface Ifc { a } + export interface Cls { a } + } + + declare module "./f1" { + import {B} from "./f2"; + ~~~~~~ +!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. + ~~~~~~ +!!! error TS2307: Cannot find module './f2'. + export {B} from "./f2"; + ~~~~~~ +!!! error TS2666: Exports and export assignments are not permitted in module augmentations. + ~~~~~~ +!!! error TS2307: Cannot find module './f2'. + import I = N.Ifc; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~ +!!! error TS4000: Import declaration 'I' is using private name 'N'. + import C = N.Cls; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~ +!!! error TS4000: Import declaration 'C' is using private name 'N'. + // should have explicit export + interface A { + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + foo(): B; + bar(): I; + baz(): C; + } + } + +==== tests/cases/compiler/f4.ts (1 errors) ==== + import {A} from "./f1"; + import "./f3"; + + let a: A; + let b = a.foo().n; + ~~~ +!!! error TS2339: Property 'foo' does not exist on type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports2.js b/tests/baselines/reference/moduleAugmentationImportsAndExports2.js new file mode 100644 index 0000000000000..3a4a807a33421 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports2.js @@ -0,0 +1,76 @@ +//// [tests/cases/compiler/moduleAugmentationImportsAndExports2.ts] //// + +//// [f1.ts] + +export class A {} + +//// [f2.ts] +export class B { + n: number; +} + +//// [f3.ts] +import {A} from "./f1"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a } + export interface Cls { a } +} + +declare module "./f1" { + import {B} from "./f2"; + export {B} from "./f2"; + import I = N.Ifc; + import C = N.Cls; + // should have explicit export + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +//// [f4.ts] +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +//// [f2.js] +"use strict"; +var B = (function () { + function B() { + } + return B; +}()); +exports.B = B; +//// [f3.js] +"use strict"; +var f1_1 = require("./f1"); +f1_1.A.prototype.foo = function () { return undefined; }; +//// [f4.js] +"use strict"; +require("./f3"); +var a; +var b = a.foo().n; + + +//// [f1.d.ts] +export declare class A { +} +//// [f2.d.ts] +export declare class B { + n: number; +} +//// [f4.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt b/tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt new file mode 100644 index 0000000000000..a7c8fa2cff281 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports3.errors.txt @@ -0,0 +1,56 @@ +tests/cases/compiler/f3.ts(11,5): error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. +tests/cases/compiler/f3.ts(11,21): error TS2307: Cannot find module './f2'. +tests/cases/compiler/f3.ts(12,12): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/f3.ts(12,16): error TS4000: Import declaration 'I' is using private name 'N'. +tests/cases/compiler/f3.ts(13,12): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/f3.ts(13,16): error TS4000: Import declaration 'C' is using private name 'N'. + + +==== tests/cases/compiler/f1.ts (0 errors) ==== + + export class A {} + +==== tests/cases/compiler/f2.ts (0 errors) ==== + export class B { + n: number; + } + +==== tests/cases/compiler/f3.ts (6 errors) ==== + import {A} from "./f1"; + + A.prototype.foo = function () { return undefined; } + + namespace N { + export interface Ifc { a } + export interface Cls { a } + } + + declare module "./f1" { + import {B} from "./f2"; + ~~~~~~ +!!! error TS2667: Imports are not permitted in module augmentations. Consider moving them to the enclosing external module. + ~~~~~~ +!!! error TS2307: Cannot find module './f2'. + import I = N.Ifc; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~ +!!! error TS4000: Import declaration 'I' is using private name 'N'. + import C = N.Cls; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~ +!!! error TS4000: Import declaration 'C' is using private name 'N'. + interface A { + foo(): B; + bar(): I; + baz(): C; + } + } + +==== tests/cases/compiler/f4.ts (0 errors) ==== + import {A} from "./f1"; + import "./f3"; + + let a: A; + let b = a.foo().n; \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports3.js b/tests/baselines/reference/moduleAugmentationImportsAndExports3.js new file mode 100644 index 0000000000000..d872a79e98563 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports3.js @@ -0,0 +1,74 @@ +//// [tests/cases/compiler/moduleAugmentationImportsAndExports3.ts] //// + +//// [f1.ts] + +export class A {} + +//// [f2.ts] +export class B { + n: number; +} + +//// [f3.ts] +import {A} from "./f1"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a } + export interface Cls { a } +} + +declare module "./f1" { + import {B} from "./f2"; + import I = N.Ifc; + import C = N.Cls; + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +//// [f4.ts] +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +//// [f2.js] +"use strict"; +var B = (function () { + function B() { + } + return B; +}()); +exports.B = B; +//// [f3.js] +"use strict"; +var f1_1 = require("./f1"); +f1_1.A.prototype.foo = function () { return undefined; }; +//// [f4.js] +"use strict"; +require("./f3"); +var a; +var b = a.foo().n; + + +//// [f1.d.ts] +export declare class A { +} +//// [f2.d.ts] +export declare class B { + n: number; +} +//// [f4.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports4.js b/tests/baselines/reference/moduleAugmentationImportsAndExports4.js new file mode 100644 index 0000000000000..5309555581503 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports4.js @@ -0,0 +1,68 @@ +//// [tests/cases/compiler/moduleAugmentationImportsAndExports4.ts] //// + +//// [f1.ts] + +export class A {} + +//// [f2.ts] +export class B { + n: number; +} + +//// [f3.ts] +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a: number; } + export interface Cls { b: number; } +} +import I = N.Ifc; +import C = N.Cls; + +declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +//// [f4.ts] +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; +let c = a.bar().a; +let d = a.baz().b; + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +//// [f2.js] +"use strict"; +var B = (function () { + function B() { + } + return B; +}()); +exports.B = B; +//// [f3.js] +"use strict"; +var f1_1 = require("./f1"); +f1_1.A.prototype.foo = function () { return undefined; }; +//// [f4.js] +"use strict"; +require("./f3"); +var a; +var b = a.foo().n; +var c = a.bar().a; +var d = a.baz().b; diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports4.symbols b/tests/baselines/reference/moduleAugmentationImportsAndExports4.symbols new file mode 100644 index 0000000000000..94dc05519ddea --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports4.symbols @@ -0,0 +1,101 @@ +=== tests/cases/compiler/f1.ts === + +export class A {} +>A : Symbol(A, Decl(f1.ts, 0, 0), Decl(f3.ts, 12, 23)) + +=== tests/cases/compiler/f2.ts === +export class B { +>B : Symbol(B, Decl(f2.ts, 0, 0)) + + n: number; +>n : Symbol(n, Decl(f2.ts, 0, 16)) +} + +=== tests/cases/compiler/f3.ts === +import {A} from "./f1"; +>A : Symbol(A, Decl(f3.ts, 0, 8)) + +import {B} from "./f2"; +>B : Symbol(B, Decl(f3.ts, 1, 8)) + +A.prototype.foo = function () { return undefined; } +>A.prototype.foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(f3.ts, 0, 8)) +>prototype : Symbol(A.prototype) +>foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>undefined : Symbol(undefined) + +namespace N { +>N : Symbol(N, Decl(f3.ts, 3, 51)) + + export interface Ifc { a: number; } +>Ifc : Symbol(Ifc, Decl(f3.ts, 5, 13)) +>a : Symbol(a, Decl(f3.ts, 6, 26)) + + export interface Cls { b: number; } +>Cls : Symbol(Cls, Decl(f3.ts, 6, 39)) +>b : Symbol(b, Decl(f3.ts, 7, 26)) +} +import I = N.Ifc; +>I : Symbol(I, Decl(f3.ts, 8, 1)) +>N : Symbol(N, Decl(f3.ts, 3, 51)) +>Ifc : Symbol(I, Decl(f3.ts, 5, 13)) + +import C = N.Cls; +>C : Symbol(C, Decl(f3.ts, 9, 17)) +>N : Symbol(N, Decl(f3.ts, 3, 51)) +>Cls : Symbol(C, Decl(f3.ts, 6, 39)) + +declare module "./f1" { + interface A { +>A : Symbol(A, Decl(f1.ts, 0, 0), Decl(f3.ts, 12, 23)) + + foo(): B; +>foo : Symbol(foo, Decl(f3.ts, 13, 17)) +>B : Symbol(B, Decl(f3.ts, 1, 8)) + + bar(): I; +>bar : Symbol(bar, Decl(f3.ts, 14, 17)) +>I : Symbol(I, Decl(f3.ts, 8, 1)) + + baz(): C; +>baz : Symbol(baz, Decl(f3.ts, 15, 17)) +>C : Symbol(C, Decl(f3.ts, 9, 17)) + } +} + +=== tests/cases/compiler/f4.ts === +import {A} from "./f1"; +>A : Symbol(A, Decl(f4.ts, 0, 8)) + +import "./f3"; + +let a: A; +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>A : Symbol(A, Decl(f4.ts, 0, 8)) + +let b = a.foo().n; +>b : Symbol(b, Decl(f4.ts, 4, 3)) +>a.foo().n : Symbol(B.n, Decl(f2.ts, 0, 16)) +>a.foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>n : Symbol(B.n, Decl(f2.ts, 0, 16)) + +let c = a.bar().a; +>c : Symbol(c, Decl(f4.ts, 5, 3)) +>a.bar().a : Symbol(N.Ifc.a, Decl(f3.ts, 6, 26)) +>a.bar : Symbol(A.bar, Decl(f3.ts, 14, 17)) +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>bar : Symbol(A.bar, Decl(f3.ts, 14, 17)) +>a : Symbol(N.Ifc.a, Decl(f3.ts, 6, 26)) + +let d = a.baz().b; +>d : Symbol(d, Decl(f4.ts, 6, 3)) +>a.baz().b : Symbol(N.Cls.b, Decl(f3.ts, 7, 26)) +>a.baz : Symbol(A.baz, Decl(f3.ts, 15, 17)) +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>baz : Symbol(A.baz, Decl(f3.ts, 15, 17)) +>b : Symbol(N.Cls.b, Decl(f3.ts, 7, 26)) + diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports4.types b/tests/baselines/reference/moduleAugmentationImportsAndExports4.types new file mode 100644 index 0000000000000..454dc5d27ecd5 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports4.types @@ -0,0 +1,106 @@ +=== tests/cases/compiler/f1.ts === + +export class A {} +>A : A + +=== tests/cases/compiler/f2.ts === +export class B { +>B : B + + n: number; +>n : number +} + +=== tests/cases/compiler/f3.ts === +import {A} from "./f1"; +>A : typeof A + +import {B} from "./f2"; +>B : typeof B + +A.prototype.foo = function () { return undefined; } +>A.prototype.foo = function () { return undefined; } : () => any +>A.prototype.foo : () => B +>A.prototype : A +>A : typeof A +>prototype : A +>foo : () => B +>function () { return undefined; } : () => any +>undefined : undefined + +namespace N { +>N : any + + export interface Ifc { a: number; } +>Ifc : Ifc +>a : number + + export interface Cls { b: number; } +>Cls : Cls +>b : number +} +import I = N.Ifc; +>I : any +>N : any +>Ifc : I + +import C = N.Cls; +>C : any +>N : any +>Cls : C + +declare module "./f1" { + interface A { +>A : A + + foo(): B; +>foo : () => B +>B : B + + bar(): I; +>bar : () => I +>I : I + + baz(): C; +>baz : () => C +>C : C + } +} + +=== tests/cases/compiler/f4.ts === +import {A} from "./f1"; +>A : typeof A + +import "./f3"; + +let a: A; +>a : A +>A : A + +let b = a.foo().n; +>b : number +>a.foo().n : number +>a.foo() : B +>a.foo : () => B +>a : A +>foo : () => B +>n : number + +let c = a.bar().a; +>c : number +>a.bar().a : number +>a.bar() : N.Ifc +>a.bar : () => N.Ifc +>a : A +>bar : () => N.Ifc +>a : number + +let d = a.baz().b; +>d : number +>a.baz().b : number +>a.baz() : N.Cls +>a.baz : () => N.Cls +>a : A +>baz : () => N.Cls +>b : number + diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports5.errors.txt b/tests/baselines/reference/moduleAugmentationImportsAndExports5.errors.txt new file mode 100644 index 0000000000000..5f783453888c3 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports5.errors.txt @@ -0,0 +1,46 @@ +tests/cases/compiler/f3.ts(10,12): error TS4000: Import declaration 'I' is using private name 'N'. +tests/cases/compiler/f3.ts(11,12): error TS4000: Import declaration 'C' is using private name 'N'. + + +==== tests/cases/compiler/f1.ts (0 errors) ==== + + export class A {} + +==== tests/cases/compiler/f2.ts (0 errors) ==== + export class B { + n: number; + } + +==== tests/cases/compiler/f3.ts (2 errors) ==== + import {A} from "./f1"; + import {B} from "./f2"; + + A.prototype.foo = function () { return undefined; } + + namespace N { + export interface Ifc { a: number; } + export interface Cls { b: number; } + } + import I = N.Ifc; + ~ +!!! error TS4000: Import declaration 'I' is using private name 'N'. + import C = N.Cls; + ~ +!!! error TS4000: Import declaration 'C' is using private name 'N'. + + declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } + } + +==== tests/cases/compiler/f4.ts (0 errors) ==== + import {A} from "./f1"; + import "./f3"; + + let a: A; + let b = a.foo().n; + let c = a.bar().a; + let d = a.baz().b; \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports5.js b/tests/baselines/reference/moduleAugmentationImportsAndExports5.js new file mode 100644 index 0000000000000..c9b622ccf257a --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports5.js @@ -0,0 +1,78 @@ +//// [tests/cases/compiler/moduleAugmentationImportsAndExports5.ts] //// + +//// [f1.ts] + +export class A {} + +//// [f2.ts] +export class B { + n: number; +} + +//// [f3.ts] +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a: number; } + export interface Cls { b: number; } +} +import I = N.Ifc; +import C = N.Cls; + +declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +//// [f4.ts] +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; +let c = a.bar().a; +let d = a.baz().b; + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +//// [f2.js] +"use strict"; +var B = (function () { + function B() { + } + return B; +}()); +exports.B = B; +//// [f3.js] +"use strict"; +var f1_1 = require("./f1"); +f1_1.A.prototype.foo = function () { return undefined; }; +//// [f4.js] +"use strict"; +require("./f3"); +var a; +var b = a.foo().n; +var c = a.bar().a; +var d = a.baz().b; + + +//// [f1.d.ts] +export declare class A { +} +//// [f2.d.ts] +export declare class B { + n: number; +} +//// [f4.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports6.js b/tests/baselines/reference/moduleAugmentationImportsAndExports6.js new file mode 100644 index 0000000000000..f0b297720b36b --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports6.js @@ -0,0 +1,97 @@ +//// [tests/cases/compiler/moduleAugmentationImportsAndExports6.ts] //// + +//// [f1.ts] + +export class A {} + +//// [f2.ts] +export class B { + n: number; +} + +//// [f3.ts] +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } + +export namespace N { + export interface Ifc { a: number; } + export interface Cls { b: number; } +} +import I = N.Ifc; +import C = N.Cls; + +declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +//// [f4.ts] +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; +let c = a.bar().a; +let d = a.baz().b; + +//// [f1.js] +"use strict"; +var A = (function () { + function A() { + } + return A; +}()); +exports.A = A; +//// [f2.js] +"use strict"; +var B = (function () { + function B() { + } + return B; +}()); +exports.B = B; +//// [f3.js] +"use strict"; +var f1_1 = require("./f1"); +f1_1.A.prototype.foo = function () { return undefined; }; +//// [f4.js] +"use strict"; +require("./f3"); +var a; +var b = a.foo().n; +var c = a.bar().a; +var d = a.baz().b; + + +//// [f1.d.ts] +export declare class A { +} +//// [f2.d.ts] +export declare class B { + n: number; +} +//// [f3.d.ts] +import { B } from "./f2"; +export declare namespace N { + interface Ifc { + a: number; + } + interface Cls { + b: number; + } +} +import I = N.Ifc; +import C = N.Cls; +declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} +//// [f4.d.ts] diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports6.symbols b/tests/baselines/reference/moduleAugmentationImportsAndExports6.symbols new file mode 100644 index 0000000000000..92952ef94bc91 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports6.symbols @@ -0,0 +1,101 @@ +=== tests/cases/compiler/f1.ts === + +export class A {} +>A : Symbol(A, Decl(f1.ts, 0, 0), Decl(f3.ts, 12, 23)) + +=== tests/cases/compiler/f2.ts === +export class B { +>B : Symbol(B, Decl(f2.ts, 0, 0)) + + n: number; +>n : Symbol(n, Decl(f2.ts, 0, 16)) +} + +=== tests/cases/compiler/f3.ts === +import {A} from "./f1"; +>A : Symbol(A, Decl(f3.ts, 0, 8)) + +import {B} from "./f2"; +>B : Symbol(B, Decl(f3.ts, 1, 8)) + +A.prototype.foo = function () { return undefined; } +>A.prototype.foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(f3.ts, 0, 8)) +>prototype : Symbol(A.prototype) +>foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>undefined : Symbol(undefined) + +export namespace N { +>N : Symbol(N, Decl(f3.ts, 3, 51)) + + export interface Ifc { a: number; } +>Ifc : Symbol(Ifc, Decl(f3.ts, 5, 20)) +>a : Symbol(a, Decl(f3.ts, 6, 26)) + + export interface Cls { b: number; } +>Cls : Symbol(Cls, Decl(f3.ts, 6, 39)) +>b : Symbol(b, Decl(f3.ts, 7, 26)) +} +import I = N.Ifc; +>I : Symbol(I, Decl(f3.ts, 8, 1)) +>N : Symbol(N, Decl(f3.ts, 3, 51)) +>Ifc : Symbol(I, Decl(f3.ts, 5, 20)) + +import C = N.Cls; +>C : Symbol(C, Decl(f3.ts, 9, 17)) +>N : Symbol(N, Decl(f3.ts, 3, 51)) +>Cls : Symbol(C, Decl(f3.ts, 6, 39)) + +declare module "./f1" { + interface A { +>A : Symbol(A, Decl(f1.ts, 0, 0), Decl(f3.ts, 12, 23)) + + foo(): B; +>foo : Symbol(foo, Decl(f3.ts, 13, 17)) +>B : Symbol(B, Decl(f3.ts, 1, 8)) + + bar(): I; +>bar : Symbol(bar, Decl(f3.ts, 14, 17)) +>I : Symbol(I, Decl(f3.ts, 8, 1)) + + baz(): C; +>baz : Symbol(baz, Decl(f3.ts, 15, 17)) +>C : Symbol(C, Decl(f3.ts, 9, 17)) + } +} + +=== tests/cases/compiler/f4.ts === +import {A} from "./f1"; +>A : Symbol(A, Decl(f4.ts, 0, 8)) + +import "./f3"; + +let a: A; +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>A : Symbol(A, Decl(f4.ts, 0, 8)) + +let b = a.foo().n; +>b : Symbol(b, Decl(f4.ts, 4, 3)) +>a.foo().n : Symbol(B.n, Decl(f2.ts, 0, 16)) +>a.foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>foo : Symbol(A.foo, Decl(f3.ts, 13, 17)) +>n : Symbol(B.n, Decl(f2.ts, 0, 16)) + +let c = a.bar().a; +>c : Symbol(c, Decl(f4.ts, 5, 3)) +>a.bar().a : Symbol(N.Ifc.a, Decl(f3.ts, 6, 26)) +>a.bar : Symbol(A.bar, Decl(f3.ts, 14, 17)) +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>bar : Symbol(A.bar, Decl(f3.ts, 14, 17)) +>a : Symbol(N.Ifc.a, Decl(f3.ts, 6, 26)) + +let d = a.baz().b; +>d : Symbol(d, Decl(f4.ts, 6, 3)) +>a.baz().b : Symbol(N.Cls.b, Decl(f3.ts, 7, 26)) +>a.baz : Symbol(A.baz, Decl(f3.ts, 15, 17)) +>a : Symbol(a, Decl(f4.ts, 3, 3)) +>baz : Symbol(A.baz, Decl(f3.ts, 15, 17)) +>b : Symbol(N.Cls.b, Decl(f3.ts, 7, 26)) + diff --git a/tests/baselines/reference/moduleAugmentationImportsAndExports6.types b/tests/baselines/reference/moduleAugmentationImportsAndExports6.types new file mode 100644 index 0000000000000..0c201599b52a0 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationImportsAndExports6.types @@ -0,0 +1,106 @@ +=== tests/cases/compiler/f1.ts === + +export class A {} +>A : A + +=== tests/cases/compiler/f2.ts === +export class B { +>B : B + + n: number; +>n : number +} + +=== tests/cases/compiler/f3.ts === +import {A} from "./f1"; +>A : typeof A + +import {B} from "./f2"; +>B : typeof B + +A.prototype.foo = function () { return undefined; } +>A.prototype.foo = function () { return undefined; } : () => any +>A.prototype.foo : () => B +>A.prototype : A +>A : typeof A +>prototype : A +>foo : () => B +>function () { return undefined; } : () => any +>undefined : undefined + +export namespace N { +>N : any + + export interface Ifc { a: number; } +>Ifc : Ifc +>a : number + + export interface Cls { b: number; } +>Cls : Cls +>b : number +} +import I = N.Ifc; +>I : any +>N : any +>Ifc : I + +import C = N.Cls; +>C : any +>N : any +>Cls : C + +declare module "./f1" { + interface A { +>A : A + + foo(): B; +>foo : () => B +>B : B + + bar(): I; +>bar : () => I +>I : I + + baz(): C; +>baz : () => C +>C : C + } +} + +=== tests/cases/compiler/f4.ts === +import {A} from "./f1"; +>A : typeof A + +import "./f3"; + +let a: A; +>a : A +>A : A + +let b = a.foo().n; +>b : number +>a.foo().n : number +>a.foo() : B +>a.foo : () => B +>a : A +>foo : () => B +>n : number + +let c = a.bar().a; +>c : number +>a.bar().a : number +>a.bar() : N.Ifc +>a.bar : () => N.Ifc +>a : A +>bar : () => N.Ifc +>a : number + +let d = a.baz().b; +>d : number +>a.baz().b : number +>a.baz() : N.Cls +>a.baz : () => N.Cls +>a : A +>baz : () => N.Cls +>b : number + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule1.js b/tests/baselines/reference/moduleAugmentationInAmbientModule1.js new file mode 100644 index 0000000000000..aecb8954d53d3 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule1.js @@ -0,0 +1,39 @@ +//// [tests/cases/compiler/moduleAugmentationInAmbientModule1.ts] //// + +//// [O.d.ts] + + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +//// [main.ts] +/// + +import {Observable} from "Observable"; +let x: Observable; +x.foo().x; + + +//// [main.js] +/// +"use strict"; +var x; +x.foo().x; + + +//// [main.d.ts] +/// diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule1.symbols b/tests/baselines/reference/moduleAugmentationInAmbientModule1.symbols new file mode 100644 index 0000000000000..b59f0766eea34 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule1.symbols @@ -0,0 +1,46 @@ +=== tests/cases/compiler/main.ts === +/// + +import {Observable} from "Observable"; +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +let x: Observable; +>x : Symbol(x, Decl(main.ts, 3, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +x.foo().x; +>x.foo().x : Symbol(Cls.x, Decl(O.d.ts, 7, 15)) +>x.foo : Symbol(Observable.foo, Decl(O.d.ts, 13, 30)) +>x : Symbol(x, Decl(main.ts, 3, 3)) +>foo : Symbol(Observable.foo, Decl(O.d.ts, 13, 30)) +>x : Symbol(Cls.x, Decl(O.d.ts, 7, 15)) + +=== tests/cases/compiler/O.d.ts === + + +declare module "Observable" { + class Observable {} +>Observable : Symbol(Observable, Decl(O.d.ts, 2, 29), Decl(O.d.ts, 12, 25)) +} + +declare module "M" { + class Cls { x: number } +>Cls : Symbol(Cls, Decl(O.d.ts, 6, 20)) +>x : Symbol(x, Decl(O.d.ts, 7, 15)) +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : Symbol(Cls, Decl(O.d.ts, 11, 12)) + + module "Observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(O.d.ts, 2, 29), Decl(O.d.ts, 12, 25)) + + foo(): Cls; +>foo : Symbol(foo, Decl(O.d.ts, 13, 30)) +>Cls : Symbol(Cls, Decl(O.d.ts, 11, 12)) + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule1.types b/tests/baselines/reference/moduleAugmentationInAmbientModule1.types new file mode 100644 index 0000000000000..0be2a787cb605 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule1.types @@ -0,0 +1,47 @@ +=== tests/cases/compiler/main.ts === +/// + +import {Observable} from "Observable"; +>Observable : typeof Observable + +let x: Observable; +>x : Observable +>Observable : Observable + +x.foo().x; +>x.foo().x : number +>x.foo() : Cls +>x.foo : () => Cls +>x : Observable +>foo : () => Cls +>x : number + +=== tests/cases/compiler/O.d.ts === + + +declare module "Observable" { + class Observable {} +>Observable : Observable +} + +declare module "M" { + class Cls { x: number } +>Cls : Cls +>x : number +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : typeof Cls + + module "Observable" { + interface Observable { +>Observable : Observable + + foo(): Cls; +>foo : () => Cls +>Cls : Cls + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule2.js b/tests/baselines/reference/moduleAugmentationInAmbientModule2.js new file mode 100644 index 0000000000000..5529afc674fb3 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule2.js @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/moduleAugmentationInAmbientModule2.ts] //// + +//// [O.d.ts] + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +//// [main.ts] +/// + +import {Observable} from "Observable"; +import "Map"; +let x: Observable; +x.foo().x; + + +//// [main.js] +/// +"use strict"; +require("Map"); +var x; +x.foo().x; diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule2.symbols b/tests/baselines/reference/moduleAugmentationInAmbientModule2.symbols new file mode 100644 index 0000000000000..6308e67b3b9b5 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule2.symbols @@ -0,0 +1,46 @@ +=== tests/cases/compiler/main.ts === +/// + +import {Observable} from "Observable"; +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +import "Map"; +let x: Observable; +>x : Symbol(x, Decl(main.ts, 4, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +x.foo().x; +>x.foo().x : Symbol(Cls.x, Decl(O.d.ts, 6, 15)) +>x.foo : Symbol(Observable.foo, Decl(O.d.ts, 12, 30)) +>x : Symbol(x, Decl(main.ts, 4, 3)) +>foo : Symbol(Observable.foo, Decl(O.d.ts, 12, 30)) +>x : Symbol(Cls.x, Decl(O.d.ts, 6, 15)) + +=== tests/cases/compiler/O.d.ts === + +declare module "Observable" { + class Observable {} +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25)) +} + +declare module "M" { + class Cls { x: number } +>Cls : Symbol(Cls, Decl(O.d.ts, 5, 20)) +>x : Symbol(x, Decl(O.d.ts, 6, 15)) +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : Symbol(Cls, Decl(O.d.ts, 10, 12)) + + module "Observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25)) + + foo(): Cls; +>foo : Symbol(foo, Decl(O.d.ts, 12, 30)) +>Cls : Symbol(Cls, Decl(O.d.ts, 10, 12)) + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule2.types b/tests/baselines/reference/moduleAugmentationInAmbientModule2.types new file mode 100644 index 0000000000000..31ea8904c2af9 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule2.types @@ -0,0 +1,47 @@ +=== tests/cases/compiler/main.ts === +/// + +import {Observable} from "Observable"; +>Observable : typeof Observable + +import "Map"; +let x: Observable; +>x : Observable +>Observable : Observable + +x.foo().x; +>x.foo().x : number +>x.foo() : Cls +>x.foo : () => Cls +>x : Observable +>foo : () => Cls +>x : number + +=== tests/cases/compiler/O.d.ts === + +declare module "Observable" { + class Observable {} +>Observable : Observable +} + +declare module "M" { + class Cls { x: number } +>Cls : Cls +>x : number +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : typeof Cls + + module "Observable" { + interface Observable { +>Observable : Observable + + foo(): Cls; +>foo : () => Cls +>Cls : Cls + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule3.js b/tests/baselines/reference/moduleAugmentationInAmbientModule3.js new file mode 100644 index 0000000000000..3a94c50ef1f6a --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule3.js @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/moduleAugmentationInAmbientModule3.ts] //// + +//// [O.d.ts] + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +declare module "Map" { + class Cls2 { x2: number } + module "Observable" { + interface Observable { + foo2(): Cls2; + } + } +} + +//// [main.ts] +/// + +import {Observable} from "Observable"; +import "Map"; +let x: Observable; +x.foo().x; +x.foo2().x2; + + +//// [main.js] +/// +"use strict"; +require("Map"); +var x; +x.foo().x; +x.foo2().x2; diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule3.symbols b/tests/baselines/reference/moduleAugmentationInAmbientModule3.symbols new file mode 100644 index 0000000000000..34eea56753fc7 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule3.symbols @@ -0,0 +1,69 @@ +=== tests/cases/compiler/main.ts === +/// + +import {Observable} from "Observable"; +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +import "Map"; +let x: Observable; +>x : Symbol(x, Decl(main.ts, 4, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 2, 8)) + +x.foo().x; +>x.foo().x : Symbol(Cls.x, Decl(O.d.ts, 6, 15)) +>x.foo : Symbol(Observable.foo, Decl(O.d.ts, 12, 30)) +>x : Symbol(x, Decl(main.ts, 4, 3)) +>foo : Symbol(Observable.foo, Decl(O.d.ts, 12, 30)) +>x : Symbol(Cls.x, Decl(O.d.ts, 6, 15)) + +x.foo2().x2; +>x.foo2().x2 : Symbol(Cls2.x2, Decl(O.d.ts, 19, 16)) +>x.foo2 : Symbol(Observable.foo2, Decl(O.d.ts, 21, 30)) +>x : Symbol(x, Decl(main.ts, 4, 3)) +>foo2 : Symbol(Observable.foo2, Decl(O.d.ts, 21, 30)) +>x2 : Symbol(Cls2.x2, Decl(O.d.ts, 19, 16)) + +=== tests/cases/compiler/O.d.ts === + +declare module "Observable" { + class Observable {} +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25), Decl(O.d.ts, 20, 25)) +} + +declare module "M" { + class Cls { x: number } +>Cls : Symbol(Cls, Decl(O.d.ts, 5, 20)) +>x : Symbol(x, Decl(O.d.ts, 6, 15)) +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : Symbol(Cls, Decl(O.d.ts, 10, 12)) + + module "Observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25), Decl(O.d.ts, 20, 25)) + + foo(): Cls; +>foo : Symbol(foo, Decl(O.d.ts, 12, 30)) +>Cls : Symbol(Cls, Decl(O.d.ts, 10, 12)) + } + } +} + +declare module "Map" { + class Cls2 { x2: number } +>Cls2 : Symbol(Cls2, Decl(O.d.ts, 18, 22)) +>x2 : Symbol(x2, Decl(O.d.ts, 19, 16)) + + module "Observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25), Decl(O.d.ts, 20, 25)) + + foo2(): Cls2; +>foo2 : Symbol(foo2, Decl(O.d.ts, 21, 30)) +>Cls2 : Symbol(Cls2, Decl(O.d.ts, 18, 22)) + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule3.types b/tests/baselines/reference/moduleAugmentationInAmbientModule3.types new file mode 100644 index 0000000000000..2cec5edc6bf8f --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule3.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/main.ts === +/// + +import {Observable} from "Observable"; +>Observable : typeof Observable + +import "Map"; +let x: Observable; +>x : Observable +>Observable : Observable + +x.foo().x; +>x.foo().x : number +>x.foo() : Cls +>x.foo : () => Cls +>x : Observable +>foo : () => Cls +>x : number + +x.foo2().x2; +>x.foo2().x2 : number +>x.foo2() : Cls2 +>x.foo2 : () => Cls2 +>x : Observable +>foo2 : () => Cls2 +>x2 : number + +=== tests/cases/compiler/O.d.ts === + +declare module "Observable" { + class Observable {} +>Observable : Observable +} + +declare module "M" { + class Cls { x: number } +>Cls : Cls +>x : number +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : typeof Cls + + module "Observable" { + interface Observable { +>Observable : Observable + + foo(): Cls; +>foo : () => Cls +>Cls : Cls + } + } +} + +declare module "Map" { + class Cls2 { x2: number } +>Cls2 : Cls2 +>x2 : number + + module "Observable" { + interface Observable { +>Observable : Observable + + foo2(): Cls2; +>foo2 : () => Cls2 +>Cls2 : Cls2 + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule4.js b/tests/baselines/reference/moduleAugmentationInAmbientModule4.js new file mode 100644 index 0000000000000..bf0339d31076e --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule4.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/moduleAugmentationInAmbientModule4.ts] //// + +//// [O.d.ts] + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +//// [O2.d.ts] +declare module "Map" { + class Cls2 { x2: number } + module "Observable" { + interface Observable { + foo2(): Cls2; + } + } +} + +//// [main.ts] +/// +/// + +import {Observable} from "Observable"; +import "Map"; +let x: Observable; +x.foo().x; +x.foo2().x2; + + +//// [main.js] +/// +/// +"use strict"; +require("Map"); +var x; +x.foo().x; +x.foo2().x2; diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule4.symbols b/tests/baselines/reference/moduleAugmentationInAmbientModule4.symbols new file mode 100644 index 0000000000000..55658c2a52ebc --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule4.symbols @@ -0,0 +1,71 @@ +=== tests/cases/compiler/main.ts === +/// +/// + +import {Observable} from "Observable"; +>Observable : Symbol(Observable, Decl(main.ts, 3, 8)) + +import "Map"; +let x: Observable; +>x : Symbol(x, Decl(main.ts, 5, 3)) +>Observable : Symbol(Observable, Decl(main.ts, 3, 8)) + +x.foo().x; +>x.foo().x : Symbol(Cls.x, Decl(O.d.ts, 6, 15)) +>x.foo : Symbol(Observable.foo, Decl(O.d.ts, 12, 30)) +>x : Symbol(x, Decl(main.ts, 5, 3)) +>foo : Symbol(Observable.foo, Decl(O.d.ts, 12, 30)) +>x : Symbol(Cls.x, Decl(O.d.ts, 6, 15)) + +x.foo2().x2; +>x.foo2().x2 : Symbol(Cls2.x2, Decl(O2.d.ts, 1, 16)) +>x.foo2 : Symbol(Observable.foo2, Decl(O2.d.ts, 3, 30)) +>x : Symbol(x, Decl(main.ts, 5, 3)) +>foo2 : Symbol(Observable.foo2, Decl(O2.d.ts, 3, 30)) +>x2 : Symbol(Cls2.x2, Decl(O2.d.ts, 1, 16)) + +=== tests/cases/compiler/O.d.ts === + +declare module "Observable" { + class Observable {} +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25), Decl(O2.d.ts, 2, 25)) +} + +declare module "M" { + class Cls { x: number } +>Cls : Symbol(Cls, Decl(O.d.ts, 5, 20)) +>x : Symbol(x, Decl(O.d.ts, 6, 15)) +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : Symbol(Cls, Decl(O.d.ts, 10, 12)) + + module "Observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25), Decl(O2.d.ts, 2, 25)) + + foo(): Cls; +>foo : Symbol(foo, Decl(O.d.ts, 12, 30)) +>Cls : Symbol(Cls, Decl(O.d.ts, 10, 12)) + } + } +} + +=== tests/cases/compiler/O2.d.ts === +declare module "Map" { + class Cls2 { x2: number } +>Cls2 : Symbol(Cls2, Decl(O2.d.ts, 0, 22)) +>x2 : Symbol(x2, Decl(O2.d.ts, 1, 16)) + + module "Observable" { + interface Observable { +>Observable : Symbol(Observable, Decl(O.d.ts, 1, 29), Decl(O.d.ts, 11, 25), Decl(O2.d.ts, 2, 25)) + + foo2(): Cls2; +>foo2 : Symbol(foo2, Decl(O2.d.ts, 3, 30)) +>Cls2 : Symbol(Cls2, Decl(O2.d.ts, 0, 22)) + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule4.types b/tests/baselines/reference/moduleAugmentationInAmbientModule4.types new file mode 100644 index 0000000000000..04791aef860f4 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule4.types @@ -0,0 +1,73 @@ +=== tests/cases/compiler/main.ts === +/// +/// + +import {Observable} from "Observable"; +>Observable : typeof Observable + +import "Map"; +let x: Observable; +>x : Observable +>Observable : Observable + +x.foo().x; +>x.foo().x : number +>x.foo() : Cls +>x.foo : () => Cls +>x : Observable +>foo : () => Cls +>x : number + +x.foo2().x2; +>x.foo2().x2 : number +>x.foo2() : Cls2 +>x.foo2 : () => Cls2 +>x : Observable +>foo2 : () => Cls2 +>x2 : number + +=== tests/cases/compiler/O.d.ts === + +declare module "Observable" { + class Observable {} +>Observable : Observable +} + +declare module "M" { + class Cls { x: number } +>Cls : Cls +>x : number +} + +declare module "Map" { + import { Cls } from "M"; +>Cls : typeof Cls + + module "Observable" { + interface Observable { +>Observable : Observable + + foo(): Cls; +>foo : () => Cls +>Cls : Cls + } + } +} + +=== tests/cases/compiler/O2.d.ts === +declare module "Map" { + class Cls2 { x2: number } +>Cls2 : Cls2 +>x2 : number + + module "Observable" { + interface Observable { +>Observable : Observable + + foo2(): Cls2; +>foo2 : () => Cls2 +>Cls2 : Cls2 + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule5.js b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js new file mode 100644 index 0000000000000..fab9cebb179b6 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule5.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/moduleAugmentationInAmbientModule5.ts] //// + +//// [array.d.ts] + +declare module "A" { + class A { x: number; } +} + +declare module "array" { + import {A} from "A"; + global { + interface Array { + getA(): A; + } + } +} + +//// [f.ts] +/// +import "array"; + +let x = [1]; +let y = x.getA().x; + + +//// [f.js] +"use strict"; +/// +require("array"); +var x = [1]; +var y = x.getA().x; + + +//// [f.d.ts] +/// diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule5.symbols b/tests/baselines/reference/moduleAugmentationInAmbientModule5.symbols new file mode 100644 index 0000000000000..a663efca64d4d --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule5.symbols @@ -0,0 +1,41 @@ +=== tests/cases/compiler/f.ts === +/// +import "array"; + +let x = [1]; +>x : Symbol(x, Decl(f.ts, 3, 3)) + +let y = x.getA().x; +>y : Symbol(y, Decl(f.ts, 4, 3)) +>x.getA().x : Symbol(A.x, Decl(array.d.ts, 2, 13)) +>x.getA : Symbol(Array.getA, Decl(array.d.ts, 8, 28)) +>x : Symbol(x, Decl(f.ts, 3, 3)) +>getA : Symbol(Array.getA, Decl(array.d.ts, 8, 28)) +>x : Symbol(A.x, Decl(array.d.ts, 2, 13)) + +=== tests/cases/compiler/array.d.ts === + +declare module "A" { + class A { x: number; } +>A : Symbol(A, Decl(array.d.ts, 1, 20)) +>x : Symbol(x, Decl(array.d.ts, 2, 13)) +} + +declare module "array" { + import {A} from "A"; +>A : Symbol(A, Decl(array.d.ts, 6, 12)) + + global { +>global : Symbol(, Decl(array.d.ts, 6, 24)) + + interface Array { +>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(array.d.ts, 7, 12)) +>T : Symbol(T, Decl(lib.d.ts, --, --), Decl(array.d.ts, 8, 24)) + + getA(): A; +>getA : Symbol(getA, Decl(array.d.ts, 8, 28)) +>A : Symbol(A, Decl(array.d.ts, 6, 12)) + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationInAmbientModule5.types b/tests/baselines/reference/moduleAugmentationInAmbientModule5.types new file mode 100644 index 0000000000000..d04cdca489324 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationInAmbientModule5.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/f.ts === +/// +import "array"; + +let x = [1]; +>x : number[] +>[1] : number[] +>1 : number + +let y = x.getA().x; +>y : number +>x.getA().x : number +>x.getA() : A +>x.getA : () => A +>x : number[] +>getA : () => A +>x : number + +=== tests/cases/compiler/array.d.ts === + +declare module "A" { + class A { x: number; } +>A : A +>x : number +} + +declare module "array" { + import {A} from "A"; +>A : typeof A + + global { +>global : typeof + + interface Array { +>Array : T[] +>T : T + + getA(): A; +>getA : () => A +>A : A + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationNoNewNames.errors.txt b/tests/baselines/reference/moduleAugmentationNoNewNames.errors.txt new file mode 100644 index 0000000000000..7c7f17cd64135 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationNoNewNames.errors.txt @@ -0,0 +1,47 @@ +tests/cases/compiler/map.ts(10,11): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/map.ts(11,9): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/map.ts(11,20): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/map.ts(12,13): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/map.ts(12,19): error TS2665: Module augmentation cannot introduce new names in the top level scope. +tests/cases/compiler/map.ts(13,12): error TS2665: Module augmentation cannot introduce new names in the top level scope. + + +==== tests/cases/compiler/map.ts (6 errors) ==== + + import { Observable } from "./observable" + + (Observable.prototype).map = function() { } + + declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + class Bar {} + ~~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let y: number, z: string; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + let {a: x, b: x1}: {a: number, b: number}; + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + ~~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + module Z {} + ~ +!!! error TS2665: Module augmentation cannot introduce new names in the top level scope. + } + +==== tests/cases/compiler/observable.ts (0 errors) ==== + export declare class Observable { + filter(pred: (e:T) => boolean): Observable; + } + +==== tests/cases/compiler/main.ts (0 errors) ==== + import { Observable } from "./observable" + import "./map"; + + let x: Observable; + let y = x.map(x => x + 1); \ No newline at end of file diff --git a/tests/baselines/reference/moduleAugmentationNoNewNames.js b/tests/baselines/reference/moduleAugmentationNoNewNames.js new file mode 100644 index 0000000000000..ccd4a668497fa --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationNoNewNames.js @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/moduleAugmentationNoNewNames.ts] //// + +//// [map.ts] + +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + class Bar {} + let y: number, z: string; + let {a: x, b: x1}: {a: number, b: number}; + module Z {} +} + +//// [observable.ts] +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +//// [main.ts] +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); + +//// [observable.js] +"use strict"; +//// [map.js] +"use strict"; +var observable_1 = require("./observable"); +observable_1.Observable.prototype.map = function () { }; +//// [main.js] +"use strict"; +require("./map"); +var x; +var y = x.map(function (x) { return x + 1; }); diff --git a/tests/baselines/reference/moduleAugmentationsBundledOutput1.js b/tests/baselines/reference/moduleAugmentationsBundledOutput1.js new file mode 100644 index 0000000000000..92916206e7655 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsBundledOutput1.js @@ -0,0 +1,142 @@ +//// [tests/cases/compiler/moduleAugmentationsBundledOutput1.ts] //// + +//// [m1.ts] + +export class Cls { +} + +//// [m2.ts] +import {Cls} from "./m1"; +(Cls.prototype).foo = function() { return 1; }; +(Cls.prototype).bar = function() { return "1"; }; + +declare module "./m1" { + interface Cls { + foo(): number; + } +} + +declare module "./m1" { + interface Cls { + bar(): string; + } +} + +//// [m3.ts] +export class C1 { x: number } +export class C2 { x: string } + +//// [m4.ts] +import {Cls} from "./m1"; +import {C1, C2} from "./m3"; +(Cls.prototype).baz1 = function() { return undefined }; +(Cls.prototype).baz2 = function() { return undefined }; + +declare module "./m1" { + interface Cls { + baz1(): C1; + } +} + +declare module "./m1" { + interface Cls { + baz2(): C2; + } +} + +//// [test.ts] +import { Cls } from "./m1"; +import "m2"; +import "m4"; +let c: Cls; +c.foo().toExponential(); +c.bar().toLowerCase(); +c.baz1().x.toExponential(); +c.baz2().x.toLowerCase(); + + +//// [out.js] +define("m1", ["require", "exports"], function (require, exports) { + "use strict"; + var Cls = (function () { + function Cls() { + } + return Cls; + }()); + exports.Cls = Cls; +}); +define("m2", ["require", "exports", "m1"], function (require, exports, m1_1) { + "use strict"; + m1_1.Cls.prototype.foo = function () { return 1; }; + m1_1.Cls.prototype.bar = function () { return "1"; }; +}); +define("m3", ["require", "exports"], function (require, exports) { + "use strict"; + var C1 = (function () { + function C1() { + } + return C1; + }()); + exports.C1 = C1; + var C2 = (function () { + function C2() { + } + return C2; + }()); + exports.C2 = C2; +}); +define("m4", ["require", "exports", "m1"], function (require, exports, m1_2) { + "use strict"; + m1_2.Cls.prototype.baz1 = function () { return undefined; }; + m1_2.Cls.prototype.baz2 = function () { return undefined; }; +}); +define("test", ["require", "exports", "m2", "m4"], function (require, exports) { + "use strict"; + var c; + c.foo().toExponential(); + c.bar().toLowerCase(); + c.baz1().x.toExponential(); + c.baz2().x.toLowerCase(); +}); + + +//// [out.d.ts] +declare module "m1" { + export class Cls { + } +} +declare module "m2" { + module "m1" { + interface Cls { + foo(): number; + } + } + module "m1" { + interface Cls { + bar(): string; + } + } +} +declare module "m3" { + export class C1 { + x: number; + } + export class C2 { + x: string; + } +} +declare module "m4" { + import { C1, C2 } from "m3"; + module "m1" { + interface Cls { + baz1(): C1; + } + } + module "m1" { + interface Cls { + baz2(): C2; + } + } +} +declare module "test" { +} diff --git a/tests/baselines/reference/moduleAugmentationsBundledOutput1.symbols b/tests/baselines/reference/moduleAugmentationsBundledOutput1.symbols new file mode 100644 index 0000000000000..47160cbc17f82 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsBundledOutput1.symbols @@ -0,0 +1,129 @@ +=== tests/cases/compiler/m1.ts === + +export class Cls { +>Cls : Symbol(Cls, Decl(m1.ts, 0, 0), Decl(m2.ts, 4, 23), Decl(m2.ts, 10, 23), Decl(m4.ts, 5, 23), Decl(m4.ts, 11, 23)) +} + +=== tests/cases/compiler/m2.ts === +import {Cls} from "./m1"; +>Cls : Symbol(Cls, Decl(m2.ts, 0, 8)) + +(Cls.prototype).foo = function() { return 1; }; +>Cls.prototype : Symbol(Cls.prototype) +>Cls : Symbol(Cls, Decl(m2.ts, 0, 8)) +>prototype : Symbol(Cls.prototype) + +(Cls.prototype).bar = function() { return "1"; }; +>Cls.prototype : Symbol(Cls.prototype) +>Cls : Symbol(Cls, Decl(m2.ts, 0, 8)) +>prototype : Symbol(Cls.prototype) + +declare module "./m1" { + interface Cls { +>Cls : Symbol(Cls, Decl(m1.ts, 0, 0), Decl(m2.ts, 4, 23), Decl(m2.ts, 10, 23), Decl(m4.ts, 5, 23), Decl(m4.ts, 11, 23)) + + foo(): number; +>foo : Symbol(foo, Decl(m2.ts, 5, 19)) + } +} + +declare module "./m1" { + interface Cls { +>Cls : Symbol(Cls, Decl(m1.ts, 0, 0), Decl(m2.ts, 4, 23), Decl(m2.ts, 10, 23), Decl(m4.ts, 5, 23), Decl(m4.ts, 11, 23)) + + bar(): string; +>bar : Symbol(bar, Decl(m2.ts, 11, 19)) + } +} + +=== tests/cases/compiler/m3.ts === +export class C1 { x: number } +>C1 : Symbol(C1, Decl(m3.ts, 0, 0)) +>x : Symbol(x, Decl(m3.ts, 0, 17)) + +export class C2 { x: string } +>C2 : Symbol(C2, Decl(m3.ts, 0, 29)) +>x : Symbol(x, Decl(m3.ts, 1, 17)) + +=== tests/cases/compiler/m4.ts === +import {Cls} from "./m1"; +>Cls : Symbol(Cls, Decl(m4.ts, 0, 8)) + +import {C1, C2} from "./m3"; +>C1 : Symbol(C1, Decl(m4.ts, 1, 8)) +>C2 : Symbol(C2, Decl(m4.ts, 1, 11)) + +(Cls.prototype).baz1 = function() { return undefined }; +>Cls.prototype : Symbol(Cls.prototype) +>Cls : Symbol(Cls, Decl(m4.ts, 0, 8)) +>prototype : Symbol(Cls.prototype) +>undefined : Symbol(undefined) + +(Cls.prototype).baz2 = function() { return undefined }; +>Cls.prototype : Symbol(Cls.prototype) +>Cls : Symbol(Cls, Decl(m4.ts, 0, 8)) +>prototype : Symbol(Cls.prototype) +>undefined : Symbol(undefined) + +declare module "./m1" { + interface Cls { +>Cls : Symbol(Cls, Decl(m1.ts, 0, 0), Decl(m2.ts, 4, 23), Decl(m2.ts, 10, 23), Decl(m4.ts, 5, 23), Decl(m4.ts, 11, 23)) + + baz1(): C1; +>baz1 : Symbol(baz1, Decl(m4.ts, 6, 19)) +>C1 : Symbol(C1, Decl(m4.ts, 1, 8)) + } +} + +declare module "./m1" { + interface Cls { +>Cls : Symbol(Cls, Decl(m1.ts, 0, 0), Decl(m2.ts, 4, 23), Decl(m2.ts, 10, 23), Decl(m4.ts, 5, 23), Decl(m4.ts, 11, 23)) + + baz2(): C2; +>baz2 : Symbol(baz2, Decl(m4.ts, 12, 19)) +>C2 : Symbol(C2, Decl(m4.ts, 1, 11)) + } +} + +=== tests/cases/compiler/test.ts === +import { Cls } from "./m1"; +>Cls : Symbol(Cls, Decl(test.ts, 0, 8)) + +import "m2"; +import "m4"; +let c: Cls; +>c : Symbol(c, Decl(test.ts, 3, 3)) +>Cls : Symbol(Cls, Decl(test.ts, 0, 8)) + +c.foo().toExponential(); +>c.foo().toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>c.foo : Symbol(Cls.foo, Decl(m2.ts, 5, 19)) +>c : Symbol(c, Decl(test.ts, 3, 3)) +>foo : Symbol(Cls.foo, Decl(m2.ts, 5, 19)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +c.bar().toLowerCase(); +>c.bar().toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>c.bar : Symbol(Cls.bar, Decl(m2.ts, 11, 19)) +>c : Symbol(c, Decl(test.ts, 3, 3)) +>bar : Symbol(Cls.bar, Decl(m2.ts, 11, 19)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + +c.baz1().x.toExponential(); +>c.baz1().x.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) +>c.baz1().x : Symbol(C1.x, Decl(m3.ts, 0, 17)) +>c.baz1 : Symbol(Cls.baz1, Decl(m4.ts, 6, 19)) +>c : Symbol(c, Decl(test.ts, 3, 3)) +>baz1 : Symbol(Cls.baz1, Decl(m4.ts, 6, 19)) +>x : Symbol(C1.x, Decl(m3.ts, 0, 17)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, --, --)) + +c.baz2().x.toLowerCase(); +>c.baz2().x.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>c.baz2().x : Symbol(C2.x, Decl(m3.ts, 1, 17)) +>c.baz2 : Symbol(Cls.baz2, Decl(m4.ts, 12, 19)) +>c : Symbol(c, Decl(test.ts, 3, 3)) +>baz2 : Symbol(Cls.baz2, Decl(m4.ts, 12, 19)) +>x : Symbol(C2.x, Decl(m3.ts, 1, 17)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/moduleAugmentationsBundledOutput1.types b/tests/baselines/reference/moduleAugmentationsBundledOutput1.types new file mode 100644 index 0000000000000..80e9127905d6c --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsBundledOutput1.types @@ -0,0 +1,163 @@ +=== tests/cases/compiler/m1.ts === + +export class Cls { +>Cls : Cls +} + +=== tests/cases/compiler/m2.ts === +import {Cls} from "./m1"; +>Cls : typeof Cls + +(Cls.prototype).foo = function() { return 1; }; +>(Cls.prototype).foo = function() { return 1; } : () => number +>(Cls.prototype).foo : any +>(Cls.prototype) : any +>Cls.prototype : any +>Cls.prototype : Cls +>Cls : typeof Cls +>prototype : Cls +>foo : any +>function() { return 1; } : () => number +>1 : number + +(Cls.prototype).bar = function() { return "1"; }; +>(Cls.prototype).bar = function() { return "1"; } : () => string +>(Cls.prototype).bar : any +>(Cls.prototype) : any +>Cls.prototype : any +>Cls.prototype : Cls +>Cls : typeof Cls +>prototype : Cls +>bar : any +>function() { return "1"; } : () => string +>"1" : string + +declare module "./m1" { + interface Cls { +>Cls : Cls + + foo(): number; +>foo : () => number + } +} + +declare module "./m1" { + interface Cls { +>Cls : Cls + + bar(): string; +>bar : () => string + } +} + +=== tests/cases/compiler/m3.ts === +export class C1 { x: number } +>C1 : C1 +>x : number + +export class C2 { x: string } +>C2 : C2 +>x : string + +=== tests/cases/compiler/m4.ts === +import {Cls} from "./m1"; +>Cls : typeof Cls + +import {C1, C2} from "./m3"; +>C1 : typeof C1 +>C2 : typeof C2 + +(Cls.prototype).baz1 = function() { return undefined }; +>(Cls.prototype).baz1 = function() { return undefined } : () => any +>(Cls.prototype).baz1 : any +>(Cls.prototype) : any +>Cls.prototype : any +>Cls.prototype : Cls +>Cls : typeof Cls +>prototype : Cls +>baz1 : any +>function() { return undefined } : () => any +>undefined : undefined + +(Cls.prototype).baz2 = function() { return undefined }; +>(Cls.prototype).baz2 = function() { return undefined } : () => any +>(Cls.prototype).baz2 : any +>(Cls.prototype) : any +>Cls.prototype : any +>Cls.prototype : Cls +>Cls : typeof Cls +>prototype : Cls +>baz2 : any +>function() { return undefined } : () => any +>undefined : undefined + +declare module "./m1" { + interface Cls { +>Cls : Cls + + baz1(): C1; +>baz1 : () => C1 +>C1 : C1 + } +} + +declare module "./m1" { + interface Cls { +>Cls : Cls + + baz2(): C2; +>baz2 : () => C2 +>C2 : C2 + } +} + +=== tests/cases/compiler/test.ts === +import { Cls } from "./m1"; +>Cls : typeof Cls + +import "m2"; +import "m4"; +let c: Cls; +>c : Cls +>Cls : Cls + +c.foo().toExponential(); +>c.foo().toExponential() : string +>c.foo().toExponential : (fractionDigits?: number) => string +>c.foo() : number +>c.foo : () => number +>c : Cls +>foo : () => number +>toExponential : (fractionDigits?: number) => string + +c.bar().toLowerCase(); +>c.bar().toLowerCase() : string +>c.bar().toLowerCase : () => string +>c.bar() : string +>c.bar : () => string +>c : Cls +>bar : () => string +>toLowerCase : () => string + +c.baz1().x.toExponential(); +>c.baz1().x.toExponential() : string +>c.baz1().x.toExponential : (fractionDigits?: number) => string +>c.baz1().x : number +>c.baz1() : C1 +>c.baz1 : () => C1 +>c : Cls +>baz1 : () => C1 +>x : number +>toExponential : (fractionDigits?: number) => string + +c.baz2().x.toLowerCase(); +>c.baz2().x.toLowerCase() : string +>c.baz2().x.toLowerCase : () => string +>c.baz2().x : string +>c.baz2() : C2 +>c.baz2 : () => C2 +>c : Cls +>baz2 : () => C2 +>x : string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/moduleAugmentationsImports1.js b/tests/baselines/reference/moduleAugmentationsImports1.js new file mode 100644 index 0000000000000..2c635a0719e03 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports1.js @@ -0,0 +1,104 @@ +//// [tests/cases/compiler/moduleAugmentationsImports1.ts] //// + +//// [a.ts] + +export class A {} + +//// [b.ts] +export class B {x: number;} + +//// [c.d.ts] +declare module "C" { + class Cls {y: string; } +} + +//// [d.ts] +/// + +import {A} from "./a"; +import {B} from "./b"; +import {Cls} from "C"; + +A.prototype.getB = function () { return undefined; } +A.prototype.getCls = function () { return undefined; } + +declare module "./a" { + interface A { + getB(): B; + } +} + +declare module "./a" { + interface A { + getCls(): Cls; + } +} + +//// [main.ts] +import {A} from "./a"; +import "d"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); + +//// [f.js] +define("a", ["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + return A; + }()); + exports.A = A; +}); +define("b", ["require", "exports"], function (require, exports) { + "use strict"; + var B = (function () { + function B() { + } + return B; + }()); + exports.B = B; +}); +/// +define("d", ["require", "exports", "a"], function (require, exports, a_1) { + "use strict"; + a_1.A.prototype.getB = function () { return undefined; }; + a_1.A.prototype.getCls = function () { return undefined; }; +}); +define("main", ["require", "exports", "d"], function (require, exports) { + "use strict"; + var a; + var b = a.getB().x.toFixed(); + var c = a.getCls().y.toLowerCase(); +}); + + +//// [f.d.ts] +/// +declare module "a" { + export class A { + } +} +declare module "b" { + export class B { + x: number; + } +} +declare module "d" { + import { B } from "b"; + import { Cls } from "C"; + module "a" { + interface A { + getB(): B; + } + } + module "a" { + interface A { + getCls(): Cls; + } + } +} +declare module "main" { +} diff --git a/tests/baselines/reference/moduleAugmentationsImports1.symbols b/tests/baselines/reference/moduleAugmentationsImports1.symbols new file mode 100644 index 0000000000000..38ef8f5522911 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports1.symbols @@ -0,0 +1,95 @@ +=== tests/cases/compiler/a.ts === + +export class A {} +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.ts, 9, 22), Decl(d.ts, 15, 22)) + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : Symbol(B, Decl(b.ts, 0, 0)) +>x : Symbol(x, Decl(b.ts, 0, 16)) + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Symbol(Cls, Decl(c.d.ts, 0, 20)) +>y : Symbol(y, Decl(c.d.ts, 1, 15)) +} + +=== tests/cases/compiler/d.ts === +/// + +import {A} from "./a"; +>A : Symbol(A, Decl(d.ts, 2, 8)) + +import {B} from "./b"; +>B : Symbol(B, Decl(d.ts, 3, 8)) + +import {Cls} from "C"; +>Cls : Symbol(Cls, Decl(d.ts, 4, 8)) + +A.prototype.getB = function () { return undefined; } +>A.prototype.getB : Symbol(A.getB, Decl(d.ts, 10, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(d.ts, 2, 8)) +>prototype : Symbol(A.prototype) +>getB : Symbol(A.getB, Decl(d.ts, 10, 17)) +>undefined : Symbol(undefined) + +A.prototype.getCls = function () { return undefined; } +>A.prototype.getCls : Symbol(A.getCls, Decl(d.ts, 16, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(d.ts, 2, 8)) +>prototype : Symbol(A.prototype) +>getCls : Symbol(A.getCls, Decl(d.ts, 16, 17)) +>undefined : Symbol(undefined) + +declare module "./a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.ts, 9, 22), Decl(d.ts, 15, 22)) + + getB(): B; +>getB : Symbol(getB, Decl(d.ts, 10, 17)) +>B : Symbol(B, Decl(d.ts, 3, 8)) + } +} + +declare module "./a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.ts, 9, 22), Decl(d.ts, 15, 22)) + + getCls(): Cls; +>getCls : Symbol(getCls, Decl(d.ts, 16, 17)) +>Cls : Symbol(Cls, Decl(d.ts, 4, 8)) + } +} + +=== tests/cases/compiler/main.ts === +import {A} from "./a"; +>A : Symbol(A, Decl(main.ts, 0, 8)) + +import "d"; + +let a: A; +>a : Symbol(a, Decl(main.ts, 3, 3)) +>A : Symbol(A, Decl(main.ts, 0, 8)) + +let b = a.getB().x.toFixed(); +>b : Symbol(b, Decl(main.ts, 4, 3)) +>a.getB().x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>a.getB().x : Symbol(B.x, Decl(b.ts, 0, 16)) +>a.getB : Symbol(A.getB, Decl(d.ts, 10, 17)) +>a : Symbol(a, Decl(main.ts, 3, 3)) +>getB : Symbol(A.getB, Decl(d.ts, 10, 17)) +>x : Symbol(B.x, Decl(b.ts, 0, 16)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +let c = a.getCls().y.toLowerCase(); +>c : Symbol(c, Decl(main.ts, 5, 3)) +>a.getCls().y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>a.getCls().y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>a.getCls : Symbol(A.getCls, Decl(d.ts, 16, 17)) +>a : Symbol(a, Decl(main.ts, 3, 3)) +>getCls : Symbol(A.getCls, Decl(d.ts, 16, 17)) +>y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/moduleAugmentationsImports1.types b/tests/baselines/reference/moduleAugmentationsImports1.types new file mode 100644 index 0000000000000..bf0bfee0a7a6d --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports1.types @@ -0,0 +1,103 @@ +=== tests/cases/compiler/a.ts === + +export class A {} +>A : A + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : B +>x : number + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Cls +>y : string +} + +=== tests/cases/compiler/d.ts === +/// + +import {A} from "./a"; +>A : typeof A + +import {B} from "./b"; +>B : typeof B + +import {Cls} from "C"; +>Cls : typeof Cls + +A.prototype.getB = function () { return undefined; } +>A.prototype.getB = function () { return undefined; } : () => any +>A.prototype.getB : () => B +>A.prototype : A +>A : typeof A +>prototype : A +>getB : () => B +>function () { return undefined; } : () => any +>undefined : undefined + +A.prototype.getCls = function () { return undefined; } +>A.prototype.getCls = function () { return undefined; } : () => any +>A.prototype.getCls : () => Cls +>A.prototype : A +>A : typeof A +>prototype : A +>getCls : () => Cls +>function () { return undefined; } : () => any +>undefined : undefined + +declare module "./a" { + interface A { +>A : A + + getB(): B; +>getB : () => B +>B : B + } +} + +declare module "./a" { + interface A { +>A : A + + getCls(): Cls; +>getCls : () => Cls +>Cls : Cls + } +} + +=== tests/cases/compiler/main.ts === +import {A} from "./a"; +>A : typeof A + +import "d"; + +let a: A; +>a : A +>A : A + +let b = a.getB().x.toFixed(); +>b : string +>a.getB().x.toFixed() : string +>a.getB().x.toFixed : (fractionDigits?: number) => string +>a.getB().x : number +>a.getB() : B +>a.getB : () => B +>a : A +>getB : () => B +>x : number +>toFixed : (fractionDigits?: number) => string + +let c = a.getCls().y.toLowerCase(); +>c : string +>a.getCls().y.toLowerCase() : string +>a.getCls().y.toLowerCase : () => string +>a.getCls().y : string +>a.getCls() : Cls +>a.getCls : () => Cls +>a : A +>getCls : () => Cls +>y : string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/moduleAugmentationsImports2.js b/tests/baselines/reference/moduleAugmentationsImports2.js new file mode 100644 index 0000000000000..f70426b49bd5e --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports2.js @@ -0,0 +1,114 @@ +//// [tests/cases/compiler/moduleAugmentationsImports2.ts] //// + +//// [a.ts] + +export class A {} + +//// [b.ts] +export class B {x: number;} + +//// [c.d.ts] +declare module "C" { + class Cls {y: string; } +} + +//// [d.ts] +/// + +import {A} from "./a"; +import {B} from "./b"; + +A.prototype.getB = function () { return undefined; } + +declare module "./a" { + interface A { + getB(): B; + } +} + +//// [e.ts] +import {A} from "./a"; +import {Cls} from "C"; + +A.prototype.getCls = function () { return undefined; } + +declare module "./a" { + interface A { + getCls(): Cls; + } +} + +//// [main.ts] +import {A} from "./a"; +import "d"; +import "e"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); + +//// [f.js] +define("a", ["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + return A; + }()); + exports.A = A; +}); +define("b", ["require", "exports"], function (require, exports) { + "use strict"; + var B = (function () { + function B() { + } + return B; + }()); + exports.B = B; +}); +/// +define("d", ["require", "exports", "a"], function (require, exports, a_1) { + "use strict"; + a_1.A.prototype.getB = function () { return undefined; }; +}); +define("e", ["require", "exports", "a"], function (require, exports, a_2) { + "use strict"; + a_2.A.prototype.getCls = function () { return undefined; }; +}); +define("main", ["require", "exports", "d", "e"], function (require, exports) { + "use strict"; + var a; + var b = a.getB().x.toFixed(); + var c = a.getCls().y.toLowerCase(); +}); + + +//// [f.d.ts] +/// +declare module "a" { + export class A { + } +} +declare module "b" { + export class B { + x: number; + } +} +declare module "d" { + import { B } from "b"; + module "a" { + interface A { + getB(): B; + } + } +} +declare module "e" { + import { Cls } from "C"; + module "a" { + interface A { + getCls(): Cls; + } + } +} +declare module "main" { +} diff --git a/tests/baselines/reference/moduleAugmentationsImports2.symbols b/tests/baselines/reference/moduleAugmentationsImports2.symbols new file mode 100644 index 0000000000000..643ccf20eb206 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports2.symbols @@ -0,0 +1,100 @@ +=== tests/cases/compiler/a.ts === + +export class A {} +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.ts, 7, 22), Decl(e.ts, 5, 22)) + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : Symbol(B, Decl(b.ts, 0, 0)) +>x : Symbol(x, Decl(b.ts, 0, 16)) + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Symbol(Cls, Decl(c.d.ts, 0, 20)) +>y : Symbol(y, Decl(c.d.ts, 1, 15)) +} + +=== tests/cases/compiler/d.ts === +/// + +import {A} from "./a"; +>A : Symbol(A, Decl(d.ts, 2, 8)) + +import {B} from "./b"; +>B : Symbol(B, Decl(d.ts, 3, 8)) + +A.prototype.getB = function () { return undefined; } +>A.prototype.getB : Symbol(A.getB, Decl(d.ts, 8, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(d.ts, 2, 8)) +>prototype : Symbol(A.prototype) +>getB : Symbol(A.getB, Decl(d.ts, 8, 17)) +>undefined : Symbol(undefined) + +declare module "./a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.ts, 7, 22), Decl(e.ts, 5, 22)) + + getB(): B; +>getB : Symbol(getB, Decl(d.ts, 8, 17)) +>B : Symbol(B, Decl(d.ts, 3, 8)) + } +} + +=== tests/cases/compiler/e.ts === +import {A} from "./a"; +>A : Symbol(A, Decl(e.ts, 0, 8)) + +import {Cls} from "C"; +>Cls : Symbol(Cls, Decl(e.ts, 1, 8)) + +A.prototype.getCls = function () { return undefined; } +>A.prototype.getCls : Symbol(A.getCls, Decl(e.ts, 6, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(e.ts, 0, 8)) +>prototype : Symbol(A.prototype) +>getCls : Symbol(A.getCls, Decl(e.ts, 6, 17)) +>undefined : Symbol(undefined) + +declare module "./a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.ts, 7, 22), Decl(e.ts, 5, 22)) + + getCls(): Cls; +>getCls : Symbol(getCls, Decl(e.ts, 6, 17)) +>Cls : Symbol(Cls, Decl(e.ts, 1, 8)) + } +} + +=== tests/cases/compiler/main.ts === +import {A} from "./a"; +>A : Symbol(A, Decl(main.ts, 0, 8)) + +import "d"; +import "e"; + +let a: A; +>a : Symbol(a, Decl(main.ts, 4, 3)) +>A : Symbol(A, Decl(main.ts, 0, 8)) + +let b = a.getB().x.toFixed(); +>b : Symbol(b, Decl(main.ts, 5, 3)) +>a.getB().x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>a.getB().x : Symbol(B.x, Decl(b.ts, 0, 16)) +>a.getB : Symbol(A.getB, Decl(d.ts, 8, 17)) +>a : Symbol(a, Decl(main.ts, 4, 3)) +>getB : Symbol(A.getB, Decl(d.ts, 8, 17)) +>x : Symbol(B.x, Decl(b.ts, 0, 16)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +let c = a.getCls().y.toLowerCase(); +>c : Symbol(c, Decl(main.ts, 6, 3)) +>a.getCls().y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>a.getCls().y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>a.getCls : Symbol(A.getCls, Decl(e.ts, 6, 17)) +>a : Symbol(a, Decl(main.ts, 4, 3)) +>getCls : Symbol(A.getCls, Decl(e.ts, 6, 17)) +>y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/moduleAugmentationsImports2.types b/tests/baselines/reference/moduleAugmentationsImports2.types new file mode 100644 index 0000000000000..56b40625600aa --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports2.types @@ -0,0 +1,108 @@ +=== tests/cases/compiler/a.ts === + +export class A {} +>A : A + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : B +>x : number + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Cls +>y : string +} + +=== tests/cases/compiler/d.ts === +/// + +import {A} from "./a"; +>A : typeof A + +import {B} from "./b"; +>B : typeof B + +A.prototype.getB = function () { return undefined; } +>A.prototype.getB = function () { return undefined; } : () => any +>A.prototype.getB : () => B +>A.prototype : A +>A : typeof A +>prototype : A +>getB : () => B +>function () { return undefined; } : () => any +>undefined : undefined + +declare module "./a" { + interface A { +>A : A + + getB(): B; +>getB : () => B +>B : B + } +} + +=== tests/cases/compiler/e.ts === +import {A} from "./a"; +>A : typeof A + +import {Cls} from "C"; +>Cls : typeof Cls + +A.prototype.getCls = function () { return undefined; } +>A.prototype.getCls = function () { return undefined; } : () => any +>A.prototype.getCls : () => Cls +>A.prototype : A +>A : typeof A +>prototype : A +>getCls : () => Cls +>function () { return undefined; } : () => any +>undefined : undefined + +declare module "./a" { + interface A { +>A : A + + getCls(): Cls; +>getCls : () => Cls +>Cls : Cls + } +} + +=== tests/cases/compiler/main.ts === +import {A} from "./a"; +>A : typeof A + +import "d"; +import "e"; + +let a: A; +>a : A +>A : A + +let b = a.getB().x.toFixed(); +>b : string +>a.getB().x.toFixed() : string +>a.getB().x.toFixed : (fractionDigits?: number) => string +>a.getB().x : number +>a.getB() : B +>a.getB : () => B +>a : A +>getB : () => B +>x : number +>toFixed : (fractionDigits?: number) => string + +let c = a.getCls().y.toLowerCase(); +>c : string +>a.getCls().y.toLowerCase() : string +>a.getCls().y.toLowerCase : () => string +>a.getCls().y : string +>a.getCls() : Cls +>a.getCls : () => Cls +>a : A +>getCls : () => Cls +>y : string +>toLowerCase : () => string + diff --git a/tests/baselines/reference/moduleAugmentationsImports3.js b/tests/baselines/reference/moduleAugmentationsImports3.js new file mode 100644 index 0000000000000..3654583b5c900 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports3.js @@ -0,0 +1,101 @@ +//// [tests/cases/compiler/moduleAugmentationsImports3.ts] //// + +//// [a.ts] + +export class A {} + +//// [b.ts] +export class B {x: number;} + +//// [c.d.ts] +declare module "C" { + class Cls {y: string; } +} + +//// [d.d.ts] +declare module "D" { + import {A} from "a"; + import {B} from "b"; + module "a" { + interface A { + getB(): B; + } + } +} + +//// [e.ts] +/// +import {A} from "./a"; +import {Cls} from "C"; + +A.prototype.getCls = function () { return undefined; } + +declare module "./a" { + interface A { + getCls(): Cls; + } +} + +//// [main.ts] +/// +import {A} from "./a"; +import "D"; +import "e"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); + +//// [f.js] +define("a", ["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + return A; + }()); + exports.A = A; +}); +define("b", ["require", "exports"], function (require, exports) { + "use strict"; + var B = (function () { + function B() { + } + return B; + }()); + exports.B = B; +}); +define("e", ["require", "exports", "a"], function (require, exports, a_1) { + "use strict"; + a_1.A.prototype.getCls = function () { return undefined; }; +}); +define("main", ["require", "exports", "D", "e"], function (require, exports) { + "use strict"; + var a; + var b = a.getB().x.toFixed(); + var c = a.getCls().y.toLowerCase(); +}); + + +//// [f.d.ts] +/// +/// +declare module "a" { + export class A { + } +} +declare module "b" { + export class B { + x: number; + } +} +declare module "e" { + import { Cls } from "C"; + module "a" { + interface A { + getCls(): Cls; + } + } +} +declare module "main" { +} diff --git a/tests/baselines/reference/moduleAugmentationsImports3.symbols b/tests/baselines/reference/moduleAugmentationsImports3.symbols new file mode 100644 index 0000000000000..db8eee074c015 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports3.symbols @@ -0,0 +1,94 @@ +=== tests/cases/compiler/main.ts === +/// +import {A} from "./a"; +>A : Symbol(A, Decl(main.ts, 1, 8)) + +import "D"; +import "e"; + +let a: A; +>a : Symbol(a, Decl(main.ts, 5, 3)) +>A : Symbol(A, Decl(main.ts, 1, 8)) + +let b = a.getB().x.toFixed(); +>b : Symbol(b, Decl(main.ts, 6, 3)) +>a.getB().x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>a.getB().x : Symbol(B.x, Decl(b.ts, 0, 16)) +>a.getB : Symbol(A.getB, Decl(d.d.ts, 4, 21)) +>a : Symbol(a, Decl(main.ts, 5, 3)) +>getB : Symbol(A.getB, Decl(d.d.ts, 4, 21)) +>x : Symbol(B.x, Decl(b.ts, 0, 16)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +let c = a.getCls().y.toLowerCase(); +>c : Symbol(c, Decl(main.ts, 7, 3)) +>a.getCls().y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>a.getCls().y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>a.getCls : Symbol(A.getCls, Decl(e.ts, 7, 17)) +>a : Symbol(a, Decl(main.ts, 5, 3)) +>getCls : Symbol(A.getCls, Decl(e.ts, 7, 17)) +>y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + +=== tests/cases/compiler/a.ts === + +export class A {} +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.d.ts, 3, 16), Decl(e.ts, 6, 22)) + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : Symbol(B, Decl(b.ts, 0, 0)) +>x : Symbol(x, Decl(b.ts, 0, 16)) + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Symbol(Cls, Decl(c.d.ts, 0, 20)) +>y : Symbol(y, Decl(c.d.ts, 1, 15)) +} + +=== tests/cases/compiler/d.d.ts === +declare module "D" { + import {A} from "a"; +>A : Symbol(A, Decl(d.d.ts, 1, 12)) + + import {B} from "b"; +>B : Symbol(B, Decl(d.d.ts, 2, 12)) + + module "a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.d.ts, 3, 16), Decl(e.ts, 6, 22)) + + getB(): B; +>getB : Symbol(getB, Decl(d.d.ts, 4, 21)) +>B : Symbol(B, Decl(d.d.ts, 2, 12)) + } + } +} + +=== tests/cases/compiler/e.ts === +/// +import {A} from "./a"; +>A : Symbol(A, Decl(e.ts, 1, 8)) + +import {Cls} from "C"; +>Cls : Symbol(Cls, Decl(e.ts, 2, 8)) + +A.prototype.getCls = function () { return undefined; } +>A.prototype.getCls : Symbol(A.getCls, Decl(e.ts, 7, 17)) +>A.prototype : Symbol(A.prototype) +>A : Symbol(A, Decl(e.ts, 1, 8)) +>prototype : Symbol(A.prototype) +>getCls : Symbol(A.getCls, Decl(e.ts, 7, 17)) +>undefined : Symbol(undefined) + +declare module "./a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.d.ts, 3, 16), Decl(e.ts, 6, 22)) + + getCls(): Cls; +>getCls : Symbol(getCls, Decl(e.ts, 7, 17)) +>Cls : Symbol(Cls, Decl(e.ts, 2, 8)) + } +} + diff --git a/tests/baselines/reference/moduleAugmentationsImports3.types b/tests/baselines/reference/moduleAugmentationsImports3.types new file mode 100644 index 0000000000000..04d17296c5694 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports3.types @@ -0,0 +1,100 @@ +=== tests/cases/compiler/main.ts === +/// +import {A} from "./a"; +>A : typeof A + +import "D"; +import "e"; + +let a: A; +>a : A +>A : A + +let b = a.getB().x.toFixed(); +>b : string +>a.getB().x.toFixed() : string +>a.getB().x.toFixed : (fractionDigits?: number) => string +>a.getB().x : number +>a.getB() : B +>a.getB : () => B +>a : A +>getB : () => B +>x : number +>toFixed : (fractionDigits?: number) => string + +let c = a.getCls().y.toLowerCase(); +>c : string +>a.getCls().y.toLowerCase() : string +>a.getCls().y.toLowerCase : () => string +>a.getCls().y : string +>a.getCls() : Cls +>a.getCls : () => Cls +>a : A +>getCls : () => Cls +>y : string +>toLowerCase : () => string + +=== tests/cases/compiler/a.ts === + +export class A {} +>A : A + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : B +>x : number + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Cls +>y : string +} + +=== tests/cases/compiler/d.d.ts === +declare module "D" { + import {A} from "a"; +>A : typeof A + + import {B} from "b"; +>B : typeof B + + module "a" { + interface A { +>A : A + + getB(): B; +>getB : () => B +>B : B + } + } +} + +=== tests/cases/compiler/e.ts === +/// +import {A} from "./a"; +>A : typeof A + +import {Cls} from "C"; +>Cls : typeof Cls + +A.prototype.getCls = function () { return undefined; } +>A.prototype.getCls = function () { return undefined; } : () => any +>A.prototype.getCls : () => Cls +>A.prototype : A +>A : typeof A +>prototype : A +>getCls : () => Cls +>function () { return undefined; } : () => any +>undefined : undefined + +declare module "./a" { + interface A { +>A : A + + getCls(): Cls; +>getCls : () => Cls +>Cls : Cls + } +} + diff --git a/tests/baselines/reference/moduleAugmentationsImports4.js b/tests/baselines/reference/moduleAugmentationsImports4.js new file mode 100644 index 0000000000000..9b64016113f54 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports4.js @@ -0,0 +1,90 @@ +//// [tests/cases/compiler/moduleAugmentationsImports4.ts] //// + +//// [a.ts] + +export class A {} + +//// [b.ts] +export class B {x: number;} + +//// [c.d.ts] +declare module "C" { + class Cls {y: string; } +} + +//// [d.d.ts] +declare module "D" { + import {A} from "a"; + import {B} from "b"; + module "a" { + interface A { + getB(): B; + } + } +} + +//// [e.d.ts] +/// +declare module "E" { + import {A} from "a"; + import {Cls} from "C"; + + module "a" { + interface A { + getCls(): Cls; + } + } +} + +//// [main.ts] +/// +/// +import {A} from "./a"; +import "D"; +import "E"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); + +//// [f.js] +define("a", ["require", "exports"], function (require, exports) { + "use strict"; + var A = (function () { + function A() { + } + return A; + }()); + exports.A = A; +}); +define("b", ["require", "exports"], function (require, exports) { + "use strict"; + var B = (function () { + function B() { + } + return B; + }()); + exports.B = B; +}); +define("main", ["require", "exports", "D", "E"], function (require, exports) { + "use strict"; + var a; + var b = a.getB().x.toFixed(); + var c = a.getCls().y.toLowerCase(); +}); + + +//// [f.d.ts] +/// +/// +declare module "a" { + export class A { + } +} +declare module "b" { + export class B { + x: number; + } +} +declare module "main" { +} diff --git a/tests/baselines/reference/moduleAugmentationsImports4.symbols b/tests/baselines/reference/moduleAugmentationsImports4.symbols new file mode 100644 index 0000000000000..8d203de851995 --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports4.symbols @@ -0,0 +1,89 @@ +=== tests/cases/compiler/main.ts === +/// +/// +import {A} from "./a"; +>A : Symbol(A, Decl(main.ts, 2, 8)) + +import "D"; +import "E"; + +let a: A; +>a : Symbol(a, Decl(main.ts, 6, 3)) +>A : Symbol(A, Decl(main.ts, 2, 8)) + +let b = a.getB().x.toFixed(); +>b : Symbol(b, Decl(main.ts, 7, 3)) +>a.getB().x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>a.getB().x : Symbol(B.x, Decl(b.ts, 0, 16)) +>a.getB : Symbol(A.getB, Decl(d.d.ts, 4, 21)) +>a : Symbol(a, Decl(main.ts, 6, 3)) +>getB : Symbol(A.getB, Decl(d.d.ts, 4, 21)) +>x : Symbol(B.x, Decl(b.ts, 0, 16)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +let c = a.getCls().y.toLowerCase(); +>c : Symbol(c, Decl(main.ts, 8, 3)) +>a.getCls().y.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) +>a.getCls().y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>a.getCls : Symbol(A.getCls, Decl(e.d.ts, 6, 21)) +>a : Symbol(a, Decl(main.ts, 6, 3)) +>getCls : Symbol(A.getCls, Decl(e.d.ts, 6, 21)) +>y : Symbol(Cls.y, Decl(c.d.ts, 1, 15)) +>toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) + +=== tests/cases/compiler/a.ts === + +export class A {} +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.d.ts, 3, 16), Decl(e.d.ts, 5, 16)) + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : Symbol(B, Decl(b.ts, 0, 0)) +>x : Symbol(x, Decl(b.ts, 0, 16)) + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Symbol(Cls, Decl(c.d.ts, 0, 20)) +>y : Symbol(y, Decl(c.d.ts, 1, 15)) +} + +=== tests/cases/compiler/d.d.ts === +declare module "D" { + import {A} from "a"; +>A : Symbol(A, Decl(d.d.ts, 1, 12)) + + import {B} from "b"; +>B : Symbol(B, Decl(d.d.ts, 2, 12)) + + module "a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.d.ts, 3, 16), Decl(e.d.ts, 5, 16)) + + getB(): B; +>getB : Symbol(getB, Decl(d.d.ts, 4, 21)) +>B : Symbol(B, Decl(d.d.ts, 2, 12)) + } + } +} + +=== tests/cases/compiler/e.d.ts === +/// +declare module "E" { + import {A} from "a"; +>A : Symbol(A, Decl(e.d.ts, 2, 12)) + + import {Cls} from "C"; +>Cls : Symbol(Cls, Decl(e.d.ts, 3, 12)) + + module "a" { + interface A { +>A : Symbol(A, Decl(a.ts, 0, 0), Decl(d.d.ts, 3, 16), Decl(e.d.ts, 5, 16)) + + getCls(): Cls; +>getCls : Symbol(getCls, Decl(e.d.ts, 6, 21)) +>Cls : Symbol(Cls, Decl(e.d.ts, 3, 12)) + } + } +} + diff --git a/tests/baselines/reference/moduleAugmentationsImports4.types b/tests/baselines/reference/moduleAugmentationsImports4.types new file mode 100644 index 0000000000000..53d570e14e66f --- /dev/null +++ b/tests/baselines/reference/moduleAugmentationsImports4.types @@ -0,0 +1,93 @@ +=== tests/cases/compiler/main.ts === +/// +/// +import {A} from "./a"; +>A : typeof A + +import "D"; +import "E"; + +let a: A; +>a : A +>A : A + +let b = a.getB().x.toFixed(); +>b : string +>a.getB().x.toFixed() : string +>a.getB().x.toFixed : (fractionDigits?: number) => string +>a.getB().x : number +>a.getB() : B +>a.getB : () => B +>a : A +>getB : () => B +>x : number +>toFixed : (fractionDigits?: number) => string + +let c = a.getCls().y.toLowerCase(); +>c : string +>a.getCls().y.toLowerCase() : string +>a.getCls().y.toLowerCase : () => string +>a.getCls().y : string +>a.getCls() : Cls +>a.getCls : () => Cls +>a : A +>getCls : () => Cls +>y : string +>toLowerCase : () => string + +=== tests/cases/compiler/a.ts === + +export class A {} +>A : A + +=== tests/cases/compiler/b.ts === +export class B {x: number;} +>B : B +>x : number + +=== tests/cases/compiler/c.d.ts === +declare module "C" { + class Cls {y: string; } +>Cls : Cls +>y : string +} + +=== tests/cases/compiler/d.d.ts === +declare module "D" { + import {A} from "a"; +>A : typeof A + + import {B} from "b"; +>B : typeof B + + module "a" { + interface A { +>A : A + + getB(): B; +>getB : () => B +>B : B + } + } +} + +=== tests/cases/compiler/e.d.ts === +/// +declare module "E" { + import {A} from "a"; +>A : typeof A + + import {Cls} from "C"; +>Cls : typeof Cls + + module "a" { + interface A { +>A : A + + getCls(): Cls; +>getCls : () => Cls +>Cls : Cls + } + } +} + diff --git a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt index 236418a10ae28..05bb3559f1a88 100644 --- a/tests/baselines/reference/privacyGloImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyGloImportParseErrors.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/privacyGloImportParseErrors.ts(22,5): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. tests/cases/compiler/privacyGloImportParseErrors.ts(22,27): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyGloImportParseErrors.ts(30,20): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyGloImportParseErrors.ts(49,29): error TS4000: Import declaration 'm1_im2_private' is using private name 'm1_M2_private'. @@ -13,12 +14,12 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(125,45): error TS1147: Impor tests/cases/compiler/privacyGloImportParseErrors.ts(133,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/privacyGloImportParseErrors.ts(133,24): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyGloImportParseErrors.ts(138,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces. -tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/privacyGloImportParseErrors.ts(141,12): error TS2664: Invalid module name in augmentation, module 'abc3' cannot be found. tests/cases/compiler/privacyGloImportParseErrors.ts(146,25): error TS1147: Import declarations in a namespace cannot reference a module. tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Import declarations in a namespace cannot reference a module. -==== tests/cases/compiler/privacyGloImportParseErrors.ts (18 errors) ==== +==== tests/cases/compiler/privacyGloImportParseErrors.ts (19 errors) ==== module m1 { export module m1_M1_public { export class c1 { @@ -41,6 +42,8 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Impor } export declare module "m1_M3_public" { + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~~~~~~~~~~~~ !!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. export function f1(); @@ -191,7 +194,7 @@ tests/cases/compiler/privacyGloImportParseErrors.ts(149,29): error TS1147: Impor } module "abc3" { ~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'abc3' cannot be found. } } diff --git a/tests/baselines/reference/privacyImportParseErrors.errors.txt b/tests/baselines/reference/privacyImportParseErrors.errors.txt index 5bae45f405c82..1826ac7226ad2 100644 --- a/tests/baselines/reference/privacyImportParseErrors.errors.txt +++ b/tests/baselines/reference/privacyImportParseErrors.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/privacyImportParseErrors.ts(22,5): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. tests/cases/compiler/privacyImportParseErrors.ts(22,27): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyImportParseErrors.ts(30,20): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyImportParseErrors.ts(59,37): error TS1147: Import declarations in a namespace cannot reference a module. @@ -6,6 +7,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(69,37): error TS1147: Import de tests/cases/compiler/privacyImportParseErrors.ts(69,37): error TS2307: Cannot find module 'm1_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(81,43): error TS1147: Import declarations in a namespace cannot reference a module. tests/cases/compiler/privacyImportParseErrors.ts(82,43): error TS1147: Import declarations in a namespace cannot reference a module. +tests/cases/compiler/privacyImportParseErrors.ts(106,5): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. tests/cases/compiler/privacyImportParseErrors.ts(106,27): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyImportParseErrors.ts(114,20): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyImportParseErrors.ts(143,37): error TS1147: Import declarations in a namespace cannot reference a module. @@ -14,31 +16,35 @@ tests/cases/compiler/privacyImportParseErrors.ts(153,37): error TS1147: Import d tests/cases/compiler/privacyImportParseErrors.ts(153,37): error TS2307: Cannot find module 'm2_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(166,43): error TS1147: Import declarations in a namespace cannot reference a module. tests/cases/compiler/privacyImportParseErrors.ts(167,43): error TS1147: Import declarations in a namespace cannot reference a module. -tests/cases/compiler/privacyImportParseErrors.ts(180,23): error TS2435: Ambient modules cannot be nested in other modules or namespaces. -tests/cases/compiler/privacyImportParseErrors.ts(198,23): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/privacyImportParseErrors.ts(180,1): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. +tests/cases/compiler/privacyImportParseErrors.ts(180,23): error TS2664: Invalid module name in augmentation, module 'glo_M2_public' cannot be found. +tests/cases/compiler/privacyImportParseErrors.ts(198,1): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. +tests/cases/compiler/privacyImportParseErrors.ts(198,23): error TS2664: Invalid module name in augmentation, module 'glo_M4_private' cannot be found. tests/cases/compiler/privacyImportParseErrors.ts(218,34): error TS2307: Cannot find module 'glo_M2_public'. tests/cases/compiler/privacyImportParseErrors.ts(238,34): error TS2307: Cannot find module 'glo_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(251,40): error TS2307: Cannot find module 'glo_M2_public'. tests/cases/compiler/privacyImportParseErrors.ts(252,40): error TS2307: Cannot find module 'glo_M4_private'. -tests/cases/compiler/privacyImportParseErrors.ts(255,23): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/privacyImportParseErrors.ts(255,1): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. +tests/cases/compiler/privacyImportParseErrors.ts(255,23): error TS2664: Invalid module name in augmentation, module 'use_glo_M1_public' cannot be found. tests/cases/compiler/privacyImportParseErrors.ts(258,45): error TS2304: Cannot find name 'use_glo_M1_public'. tests/cases/compiler/privacyImportParseErrors.ts(261,39): error TS2304: Cannot find name 'use_glo_M1_public'. tests/cases/compiler/privacyImportParseErrors.ts(264,40): error TS2307: Cannot find module 'glo_M2_public'. tests/cases/compiler/privacyImportParseErrors.ts(273,38): error TS1147: Import declarations in a namespace cannot reference a module. tests/cases/compiler/privacyImportParseErrors.ts(277,45): error TS1147: Import declarations in a namespace cannot reference a module. -tests/cases/compiler/privacyImportParseErrors.ts(284,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/privacyImportParseErrors.ts(284,16): error TS2664: Invalid module name in augmentation, module 'use_glo_M3_private' cannot be found. tests/cases/compiler/privacyImportParseErrors.ts(287,46): error TS2304: Cannot find name 'use_glo_M3_private'. tests/cases/compiler/privacyImportParseErrors.ts(290,40): error TS2304: Cannot find name 'use_glo_M3_private'. tests/cases/compiler/privacyImportParseErrors.ts(293,41): error TS2307: Cannot find module 'glo_M4_private'. tests/cases/compiler/privacyImportParseErrors.ts(302,38): error TS1147: Import declarations in a namespace cannot reference a module. tests/cases/compiler/privacyImportParseErrors.ts(306,45): error TS1147: Import declarations in a namespace cannot reference a module. -tests/cases/compiler/privacyImportParseErrors.ts(312,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/privacyImportParseErrors.ts(312,16): error TS2664: Invalid module name in augmentation, module 'anotherParseError' cannot be found. tests/cases/compiler/privacyImportParseErrors.ts(314,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/privacyImportParseErrors.ts(314,24): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyImportParseErrors.ts(319,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyImportParseErrors.ts(322,12): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/privacyImportParseErrors.ts(326,1): error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. tests/cases/compiler/privacyImportParseErrors.ts(326,9): error TS1029: 'export' modifier must precede 'declare' modifier. -tests/cases/compiler/privacyImportParseErrors.ts(326,23): error TS2435: Ambient modules cannot be nested in other modules or namespaces. +tests/cases/compiler/privacyImportParseErrors.ts(326,23): error TS2664: Invalid module name in augmentation, module 'anotherParseError2' cannot be found. tests/cases/compiler/privacyImportParseErrors.ts(328,9): error TS1038: A 'declare' modifier cannot be used in an already ambient context. tests/cases/compiler/privacyImportParseErrors.ts(328,24): error TS2435: Ambient modules cannot be nested in other modules or namespaces. tests/cases/compiler/privacyImportParseErrors.ts(333,16): error TS2435: Ambient modules cannot be nested in other modules or namespaces. @@ -49,7 +55,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(350,25): error TS1147: Import d tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import declarations in a namespace cannot reference a module. -==== tests/cases/compiler/privacyImportParseErrors.ts (49 errors) ==== +==== tests/cases/compiler/privacyImportParseErrors.ts (55 errors) ==== export module m1 { export module m1_M1_public { export class c1 { @@ -72,6 +78,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d } export declare module "m1_M3_public" { + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~~~~~~~~~~~~ !!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. export function f1(); @@ -172,6 +180,8 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d } export declare module "m2_M3_public" { + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~~~~~~~~~~~~ !!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. export function f1(); @@ -262,8 +272,10 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d } export declare module "glo_M2_public" { + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'glo_M2_public' cannot be found. export function f1(); export class c1 { } @@ -282,8 +294,10 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d } export declare module "glo_M4_private" { + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'glo_M4_private' cannot be found. export function f1(); export class c1 { } @@ -349,8 +363,10 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d export declare module "use_glo_M1_public" { + ~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~~~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'use_glo_M1_public' cannot be found. import use_glo_M1_public = glo_M1_public; export var use_glo_M1_public_v1_public: { new (): use_glo_M1_public.c1; }; export var use_glo_M1_public_v2_public: use_glo_M1_public; @@ -391,7 +407,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d declare module "use_glo_M3_private" { ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'use_glo_M3_private' cannot be found. import use_glo_M3_private = glo_M3_private; export var use_glo_M3_private_v1_public: { new (): use_glo_M3_private.c1; }; export var use_glo_M3_private_v2_public: use_glo_M3_private; @@ -431,7 +447,7 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d declare module "anotherParseError" { ~~~~~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'anotherParseError' cannot be found. module m2 { declare module "abc" { ~~~~~~~ @@ -454,10 +470,12 @@ tests/cases/compiler/privacyImportParseErrors.ts(353,29): error TS1147: Import d } declare export module "anotherParseError2" { + ~~~~~~~ +!!! error TS2668: 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible. ~~~~~~ !!! error TS1029: 'export' modifier must precede 'declare' modifier. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2435: Ambient modules cannot be nested in other modules or namespaces. +!!! error TS2664: Invalid module name in augmentation, module 'anotherParseError2' cannot be found. module m2 { declare module "abc" { ~~~~~~~ diff --git a/tests/baselines/reference/undefinedTypeAssignment1.errors.txt b/tests/baselines/reference/undefinedTypeAssignment1.errors.txt index b8dd74a58a8da..61021a463abf4 100644 --- a/tests/baselines/reference/undefinedTypeAssignment1.errors.txt +++ b/tests/baselines/reference/undefinedTypeAssignment1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/undefinedTypeAssignment1.ts(1,1): error TS2397: Declaration name conflicts with built-in global identifier 'undefined'. +tests/cases/compiler/undefinedTypeAssignment1.ts(1,6): error TS2397: Declaration name conflicts with built-in global identifier 'undefined'. ==== tests/cases/compiler/undefinedTypeAssignment1.ts (1 errors) ==== type undefined = string; - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~ !!! error TS2397: Declaration name conflicts with built-in global identifier 'undefined'. function p(undefined = "wat") { return undefined; diff --git a/tests/cases/compiler/globalIsContextualKeyword.ts b/tests/cases/compiler/globalIsContextualKeyword.ts new file mode 100644 index 0000000000000..ceae834a267dc --- /dev/null +++ b/tests/cases/compiler/globalIsContextualKeyword.ts @@ -0,0 +1,16 @@ +function a() { + let global = 1; +} +function b() { + class global {} +} + +namespace global { +} + +function foo(global: number) { +} + +let obj = { + global: "123" +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationCollidingNamesInAugmentation1.ts b/tests/cases/compiler/moduleAugmentationCollidingNamesInAugmentation1.ts new file mode 100644 index 0000000000000..7cbb78a333bb0 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationCollidingNamesInAugmentation1.ts @@ -0,0 +1,33 @@ +// @module: amd +// @declaration: true + +// @filename: map1.ts +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface I {x0} +} + +// @filename: map2.ts +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface I {x1} +} + + +// @filename: observable.ts +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +// @filename: main.ts +import { Observable } from "./observable" +import "./map1"; +import "./map2"; + +let x: Observable; diff --git a/tests/cases/compiler/moduleAugmentationDeclarationEmit1.ts b/tests/cases/compiler/moduleAugmentationDeclarationEmit1.ts new file mode 100644 index 0000000000000..460cdfc53b632 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationDeclarationEmit1.ts @@ -0,0 +1,33 @@ +// @module: commonjs +// @declaration: true + +// @filename: map.ts +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: number; + } +} + +// @filename: observable.ts +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + let someValue: number; +} + + +// @filename: main.ts +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationDeclarationEmit2.ts b/tests/cases/compiler/moduleAugmentationDeclarationEmit2.ts new file mode 100644 index 0000000000000..22cb439267516 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationDeclarationEmit2.ts @@ -0,0 +1,35 @@ +// @module: commonjs +// @declaration: true + +// @filename: map.ts +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: string; + } +} + +// @filename: observable.ts +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + export let someValue: number; +} + + +// @filename: main.ts +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); +let z1 = Observable.someValue.toFixed(); +let z2 = Observable.someAnotherValue.toLowerCase(); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts b/tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts new file mode 100644 index 0000000000000..b4b286db5023e --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationDisallowedExtensions.ts @@ -0,0 +1,46 @@ +// @module: commonjs + +// @filename: x0.ts +export let a = 1; + +// @filename: x.ts + +namespace N1 { + export let x = 1; +} + +declare module "./observable" { + var x: number; + let y: number; + const z: number; + let {x1, y1, z0: {n}, z1: {arr: [el1, el2, el3]}}: {x1: number, y1: string, z0: {n: number}, z1: {arr: number[]} } + interface A { x } + namespace N { + export class C {} + } + class Cls {} + function foo(): number; + type T = number; + import * as all from "./x0"; + import {a} from "./x0"; + export * from "./x0"; + export {a} from "./x0"; +} + +declare module "./test" { + export = N1; +} +export {} + +// @filename: observable.ts +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} +export var x = 1; + +// @filename: test.ts +export let b = 1; + +// @filename: main.ts +import { Observable } from "./observable" +import "./x"; diff --git a/tests/cases/compiler/moduleAugmentationExtendAmbientModule1.ts b/tests/cases/compiler/moduleAugmentationExtendAmbientModule1.ts new file mode 100644 index 0000000000000..b8b144fcc14e7 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationExtendAmbientModule1.ts @@ -0,0 +1,34 @@ +// @module: commonjs + +// @filename: map.ts +import { Observable } from "observable" + +(Observable.prototype).map = function() { } + +declare module "observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: number; + } +} + +// @filename: observable.d.ts +declare module "observable" { + class Observable { + filter(pred: (e:T) => boolean): Observable; + } + namespace Observable { + let someValue: number; + } +} + +// @filename: main.ts + +/// +import { Observable } from "observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationExtendAmbientModule2.ts b/tests/cases/compiler/moduleAugmentationExtendAmbientModule2.ts new file mode 100644 index 0000000000000..6e6614ce9f7d2 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationExtendAmbientModule2.ts @@ -0,0 +1,37 @@ +// @module: commonjs +// @declaration: true + +// @filename: map.ts +import { Observable } from "observable" + +(Observable.prototype).map = function() { } + +declare module "observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: string; + } +} + +// @filename: observable.d.ts +declare module "observable" { + class Observable { + filter(pred: (e:T) => boolean): Observable; + } + namespace Observable { + export let someValue: number; + } +} + +// @filename: main.ts + +/// +import { Observable } from "observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); +let z1 = Observable.someValue.toFixed(); +let z2 = Observable.someAnotherValue.toLowerCase(); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationExtendFileModule1.ts b/tests/cases/compiler/moduleAugmentationExtendFileModule1.ts new file mode 100644 index 0000000000000..f87757b48714e --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationExtendFileModule1.ts @@ -0,0 +1,32 @@ +// @module: commonjs + +// @filename: map.ts +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: number; + } +} + +// @filename: observable.ts +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + let someValue: number; +} + + +// @filename: main.ts +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationExtendFileModule2.ts b/tests/cases/compiler/moduleAugmentationExtendFileModule2.ts new file mode 100644 index 0000000000000..454e51487903b --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationExtendFileModule2.ts @@ -0,0 +1,34 @@ +// @module: commonjs + +// @filename: map.ts +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + namespace Observable { + let someAnotherValue: string; + } +} + +// @filename: observable.ts +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +export namespace Observable { + export let someValue: number; +} + + +// @filename: main.ts +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); +let z1 = Observable.someValue.toFixed(); +let z2 = Observable.someAnotherValue.toLowerCase(); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationGlobal1.ts b/tests/cases/compiler/moduleAugmentationGlobal1.ts new file mode 100644 index 0000000000000..bef373ff139f3 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal1.ts @@ -0,0 +1,18 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {x: number;} + +// @filename: f2.ts +import {A} from "./f1"; + +// change the shape of Array +declare global { + interface Array { + getA(): A; + } +} + +let x = [1]; +let y = x.getA().x; diff --git a/tests/cases/compiler/moduleAugmentationGlobal2.ts b/tests/cases/compiler/moduleAugmentationGlobal2.ts new file mode 100644 index 0000000000000..5a5c44f1109d0 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal2.ts @@ -0,0 +1,18 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {}; +// @filename: f2.ts + +// change the shape of Array +import {A} from "./f1"; + +declare global { + interface Array { + getCountAsString(): string; + } +} + +let x = [1]; +let y = x.getCountAsString().toLowerCase(); diff --git a/tests/cases/compiler/moduleAugmentationGlobal3.ts b/tests/cases/compiler/moduleAugmentationGlobal3.ts new file mode 100644 index 0000000000000..5986b689c5570 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal3.ts @@ -0,0 +1,21 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {}; +// @filename: f2.ts + +// change the shape of Array +import {A} from "./f1"; + +declare global { + interface Array { + getCountAsString(): string; + } +} + +// @filename: f3.ts +import "./f2"; + +let x = [1]; +let y = x.getCountAsString().toLowerCase(); diff --git a/tests/cases/compiler/moduleAugmentationGlobal4.ts b/tests/cases/compiler/moduleAugmentationGlobal4.ts new file mode 100644 index 0000000000000..44ba2ba9c573a --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal4.ts @@ -0,0 +1,18 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +declare global { + interface Something {x} +} +export {}; +// @filename: f2.ts + +declare global { + interface Something {y} +} +export {}; +// @filename: f3.ts +import "./f1"; +import "./f2"; + diff --git a/tests/cases/compiler/moduleAugmentationGlobal5.ts b/tests/cases/compiler/moduleAugmentationGlobal5.ts new file mode 100644 index 0000000000000..6d2920fd55f7f --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal5.ts @@ -0,0 +1,21 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.d.ts +declare module "A" { + global { + interface Something {x} + } +} +// @filename: f2.d.ts +declare module "B" { + global { + interface Something {y} + } +} +// @filename: f3.ts +/// +/// +import "A"; +import "B"; + diff --git a/tests/cases/compiler/moduleAugmentationGlobal6.ts b/tests/cases/compiler/moduleAugmentationGlobal6.ts new file mode 100644 index 0000000000000..37e5e33725b2a --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal6.ts @@ -0,0 +1,3 @@ +declare global { + interface Array { x } +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationGlobal6_1.ts b/tests/cases/compiler/moduleAugmentationGlobal6_1.ts new file mode 100644 index 0000000000000..d255b7f83196c --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal6_1.ts @@ -0,0 +1,3 @@ +global { + interface Array { x } +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationGlobal7.ts b/tests/cases/compiler/moduleAugmentationGlobal7.ts new file mode 100644 index 0000000000000..66dd41c8bc9b1 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal7.ts @@ -0,0 +1,5 @@ +namespace A { + declare global { + interface Array { x } + } +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationGlobal7_1.ts b/tests/cases/compiler/moduleAugmentationGlobal7_1.ts new file mode 100644 index 0000000000000..b7d99dfd413f8 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal7_1.ts @@ -0,0 +1,5 @@ +namespace A { + global { + interface Array { x } + } +} \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationGlobal8.ts b/tests/cases/compiler/moduleAugmentationGlobal8.ts new file mode 100644 index 0000000000000..e28b07d6bfd7a --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal8.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @module: amd +namespace A { + declare global { + interface Array { x } + } +} +export {} diff --git a/tests/cases/compiler/moduleAugmentationGlobal8_1.ts b/tests/cases/compiler/moduleAugmentationGlobal8_1.ts new file mode 100644 index 0000000000000..9031e4742b083 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationGlobal8_1.ts @@ -0,0 +1,8 @@ +// @target: es5 +// @module: amd +namespace A { + global { + interface Array { x } + } +} +export {} diff --git a/tests/cases/compiler/moduleAugmentationImportsAndExports1.ts b/tests/cases/compiler/moduleAugmentationImportsAndExports1.ts new file mode 100644 index 0000000000000..165057cf0259c --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationImportsAndExports1.ts @@ -0,0 +1,28 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {} + +// @filename: f2.ts +export class B { + n: number; +} + +// @filename: f3.ts +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } +declare module "./f1" { + interface A { + foo(): B; + } +} + +// @filename: f4.ts +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationImportsAndExports2.ts b/tests/cases/compiler/moduleAugmentationImportsAndExports2.ts new file mode 100644 index 0000000000000..8e76475c4043a --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationImportsAndExports2.ts @@ -0,0 +1,40 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {} + +// @filename: f2.ts +export class B { + n: number; +} + +// @filename: f3.ts +import {A} from "./f1"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a } + export interface Cls { a } +} + +declare module "./f1" { + import {B} from "./f2"; + export {B} from "./f2"; + import I = N.Ifc; + import C = N.Cls; + // should have explicit export + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +// @filename: f4.ts +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationImportsAndExports3.ts b/tests/cases/compiler/moduleAugmentationImportsAndExports3.ts new file mode 100644 index 0000000000000..ea1d5e435da04 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationImportsAndExports3.ts @@ -0,0 +1,38 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {} + +// @filename: f2.ts +export class B { + n: number; +} + +// @filename: f3.ts +import {A} from "./f1"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a } + export interface Cls { a } +} + +declare module "./f1" { + import {B} from "./f2"; + import I = N.Ifc; + import C = N.Cls; + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +// @filename: f4.ts +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationImportsAndExports4.ts b/tests/cases/compiler/moduleAugmentationImportsAndExports4.ts new file mode 100644 index 0000000000000..3f3b9e1940000 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationImportsAndExports4.ts @@ -0,0 +1,39 @@ +// @module: commonjs + +// @filename: f1.ts +export class A {} + +// @filename: f2.ts +export class B { + n: number; +} + +// @filename: f3.ts +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a: number; } + export interface Cls { b: number; } +} +import I = N.Ifc; +import C = N.Cls; + +declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +// @filename: f4.ts +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; +let c = a.bar().a; +let d = a.baz().b; \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationImportsAndExports5.ts b/tests/cases/compiler/moduleAugmentationImportsAndExports5.ts new file mode 100644 index 0000000000000..8dbff8f7cc9d4 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationImportsAndExports5.ts @@ -0,0 +1,40 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {} + +// @filename: f2.ts +export class B { + n: number; +} + +// @filename: f3.ts +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } + +namespace N { + export interface Ifc { a: number; } + export interface Cls { b: number; } +} +import I = N.Ifc; +import C = N.Cls; + +declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +// @filename: f4.ts +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; +let c = a.bar().a; +let d = a.baz().b; \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationImportsAndExports6.ts b/tests/cases/compiler/moduleAugmentationImportsAndExports6.ts new file mode 100644 index 0000000000000..e9e216cbbbe1b --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationImportsAndExports6.ts @@ -0,0 +1,40 @@ +// @module: commonjs +// @declaration: true + +// @filename: f1.ts +export class A {} + +// @filename: f2.ts +export class B { + n: number; +} + +// @filename: f3.ts +import {A} from "./f1"; +import {B} from "./f2"; + +A.prototype.foo = function () { return undefined; } + +export namespace N { + export interface Ifc { a: number; } + export interface Cls { b: number; } +} +import I = N.Ifc; +import C = N.Cls; + +declare module "./f1" { + interface A { + foo(): B; + bar(): I; + baz(): C; + } +} + +// @filename: f4.ts +import {A} from "./f1"; +import "./f3"; + +let a: A; +let b = a.foo().n; +let c = a.bar().a; +let d = a.baz().b; \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationInAmbientModule1.ts b/tests/cases/compiler/moduleAugmentationInAmbientModule1.ts new file mode 100644 index 0000000000000..07b7ccb99ca0b --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationInAmbientModule1.ts @@ -0,0 +1,28 @@ +// @module: commonjs +// @declaration: true + +// @filename: O.d.ts + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +// @filename: main.ts +/// + +import {Observable} from "Observable"; +let x: Observable; +x.foo().x; diff --git a/tests/cases/compiler/moduleAugmentationInAmbientModule2.ts b/tests/cases/compiler/moduleAugmentationInAmbientModule2.ts new file mode 100644 index 0000000000000..e2979478574db --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationInAmbientModule2.ts @@ -0,0 +1,28 @@ +// @module: commonjs +// @declaration: true; +// @filename: O.d.ts + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +// @filename: main.ts +/// + +import {Observable} from "Observable"; +import "Map"; +let x: Observable; +x.foo().x; diff --git a/tests/cases/compiler/moduleAugmentationInAmbientModule3.ts b/tests/cases/compiler/moduleAugmentationInAmbientModule3.ts new file mode 100644 index 0000000000000..bc233294ed494 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationInAmbientModule3.ts @@ -0,0 +1,38 @@ +// @module: commonjs +// @declaration: true; +// @filename: O.d.ts + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +declare module "Map" { + class Cls2 { x2: number } + module "Observable" { + interface Observable { + foo2(): Cls2; + } + } +} + +// @filename: main.ts +/// + +import {Observable} from "Observable"; +import "Map"; +let x: Observable; +x.foo().x; +x.foo2().x2; diff --git a/tests/cases/compiler/moduleAugmentationInAmbientModule4.ts b/tests/cases/compiler/moduleAugmentationInAmbientModule4.ts new file mode 100644 index 0000000000000..59386ad3d08cb --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationInAmbientModule4.ts @@ -0,0 +1,40 @@ +// @module: commonjs +// @declaration: true; +// @filename: O.d.ts + +declare module "Observable" { + class Observable {} +} + +declare module "M" { + class Cls { x: number } +} + +declare module "Map" { + import { Cls } from "M"; + module "Observable" { + interface Observable { + foo(): Cls; + } + } +} + +// @filename: O2.d.ts +declare module "Map" { + class Cls2 { x2: number } + module "Observable" { + interface Observable { + foo2(): Cls2; + } + } +} + +// @filename: main.ts +/// +/// + +import {Observable} from "Observable"; +import "Map"; +let x: Observable; +x.foo().x; +x.foo2().x2; diff --git a/tests/cases/compiler/moduleAugmentationInAmbientModule5.ts b/tests/cases/compiler/moduleAugmentationInAmbientModule5.ts new file mode 100644 index 0000000000000..5068ba396c324 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationInAmbientModule5.ts @@ -0,0 +1,23 @@ +// @module: commonjs +// @declaration: true + +// @filename: array.d.ts +declare module "A" { + class A { x: number; } +} + +declare module "array" { + import {A} from "A"; + global { + interface Array { + getA(): A; + } + } +} + +// @filename: f.ts +/// +import "array"; + +let x = [1]; +let y = x.getA().x; diff --git a/tests/cases/compiler/moduleAugmentationNoNewNames.ts b/tests/cases/compiler/moduleAugmentationNoNewNames.ts new file mode 100644 index 0000000000000..2ab82ba5f0b5c --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationNoNewNames.ts @@ -0,0 +1,28 @@ +// @module: commonjs + +// @filename: map.ts +import { Observable } from "./observable" + +(Observable.prototype).map = function() { } + +declare module "./observable" { + interface Observable { + map(proj: (e:T) => U): Observable + } + class Bar {} + let y: number, z: string; + let {a: x, b: x1}: {a: number, b: number}; + module Z {} +} + +// @filename: observable.ts +export declare class Observable { + filter(pred: (e:T) => boolean): Observable; +} + +// @filename: main.ts +import { Observable } from "./observable" +import "./map"; + +let x: Observable; +let y = x.map(x => x + 1); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationsBundledOutput1.ts b/tests/cases/compiler/moduleAugmentationsBundledOutput1.ts new file mode 100644 index 0000000000000..e633e355d80b0 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationsBundledOutput1.ts @@ -0,0 +1,57 @@ +// @target: es5 +// @module: amd +// @declaration: true +// @out: out.js + +// @filename: m1.ts +export class Cls { +} + +// @filename: m2.ts +import {Cls} from "./m1"; +(Cls.prototype).foo = function() { return 1; }; +(Cls.prototype).bar = function() { return "1"; }; + +declare module "./m1" { + interface Cls { + foo(): number; + } +} + +declare module "./m1" { + interface Cls { + bar(): string; + } +} + +// @filename: m3.ts +export class C1 { x: number } +export class C2 { x: string } + +// @filename: m4.ts +import {Cls} from "./m1"; +import {C1, C2} from "./m3"; +(Cls.prototype).baz1 = function() { return undefined }; +(Cls.prototype).baz2 = function() { return undefined }; + +declare module "./m1" { + interface Cls { + baz1(): C1; + } +} + +declare module "./m1" { + interface Cls { + baz2(): C2; + } +} + +// @filename: test.ts +import { Cls } from "./m1"; +import "m2"; +import "m4"; +let c: Cls; +c.foo().toExponential(); +c.bar().toLowerCase(); +c.baz1().x.toExponential(); +c.baz2().x.toLowerCase(); diff --git a/tests/cases/compiler/moduleAugmentationsImports1.ts b/tests/cases/compiler/moduleAugmentationsImports1.ts new file mode 100644 index 0000000000000..ad029bdfc4ac2 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationsImports1.ts @@ -0,0 +1,44 @@ +// @module: amd +// @declaration: true +// @out: f.js + +// @filename: a.ts +export class A {} + +// @filename: b.ts +export class B {x: number;} + +// @filename: c.d.ts +declare module "C" { + class Cls {y: string; } +} + +// @filename: d.ts +/// + +import {A} from "./a"; +import {B} from "./b"; +import {Cls} from "C"; + +A.prototype.getB = function () { return undefined; } +A.prototype.getCls = function () { return undefined; } + +declare module "./a" { + interface A { + getB(): B; + } +} + +declare module "./a" { + interface A { + getCls(): Cls; + } +} + +// @filename: main.ts +import {A} from "./a"; +import "d"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationsImports2.ts b/tests/cases/compiler/moduleAugmentationsImports2.ts new file mode 100644 index 0000000000000..bf5b4b1cd17a0 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationsImports2.ts @@ -0,0 +1,49 @@ +// @module: amd +// @declaration: true +// @out: f.js + +// @filename: a.ts +export class A {} + +// @filename: b.ts +export class B {x: number;} + +// @filename: c.d.ts +declare module "C" { + class Cls {y: string; } +} + +// @filename: d.ts +/// + +import {A} from "./a"; +import {B} from "./b"; + +A.prototype.getB = function () { return undefined; } + +declare module "./a" { + interface A { + getB(): B; + } +} + +// @filename: e.ts +import {A} from "./a"; +import {Cls} from "C"; + +A.prototype.getCls = function () { return undefined; } + +declare module "./a" { + interface A { + getCls(): Cls; + } +} + +// @filename: main.ts +import {A} from "./a"; +import "d"; +import "e"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationsImports3.ts b/tests/cases/compiler/moduleAugmentationsImports3.ts new file mode 100644 index 0000000000000..92cc6c73a3c9f --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationsImports3.ts @@ -0,0 +1,48 @@ +// @module: amd +// @declaration: true +// @out: f.js + +// @filename: a.ts +export class A {} + +// @filename: b.ts +export class B {x: number;} + +// @filename: c.d.ts +declare module "C" { + class Cls {y: string; } +} + +// @filename: d.d.ts +declare module "D" { + import {A} from "a"; + import {B} from "b"; + module "a" { + interface A { + getB(): B; + } + } +} + +// @filename: e.ts +/// +import {A} from "./a"; +import {Cls} from "C"; + +A.prototype.getCls = function () { return undefined; } + +declare module "./a" { + interface A { + getCls(): Cls; + } +} + +// @filename: main.ts +/// +import {A} from "./a"; +import "D"; +import "e"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); \ No newline at end of file diff --git a/tests/cases/compiler/moduleAugmentationsImports4.ts b/tests/cases/compiler/moduleAugmentationsImports4.ts new file mode 100644 index 0000000000000..5e48954c09211 --- /dev/null +++ b/tests/cases/compiler/moduleAugmentationsImports4.ts @@ -0,0 +1,49 @@ +// @module: amd +// @declaration: true +// @out: f.js + +// @filename: a.ts +export class A {} + +// @filename: b.ts +export class B {x: number;} + +// @filename: c.d.ts +declare module "C" { + class Cls {y: string; } +} + +// @filename: d.d.ts +declare module "D" { + import {A} from "a"; + import {B} from "b"; + module "a" { + interface A { + getB(): B; + } + } +} + +// @filename: e.d.ts +/// +declare module "E" { + import {A} from "a"; + import {Cls} from "C"; + + module "a" { + interface A { + getCls(): Cls; + } + } +} + +// @filename: main.ts +/// +/// +import {A} from "./a"; +import "D"; +import "E"; + +let a: A; +let b = a.getB().x.toFixed(); +let c = a.getCls().y.toLowerCase(); \ No newline at end of file diff --git a/tests/cases/fourslash/formattingGlobalAugmentation1.ts b/tests/cases/fourslash/formattingGlobalAugmentation1.ts new file mode 100644 index 0000000000000..0499100653474 --- /dev/null +++ b/tests/cases/fourslash/formattingGlobalAugmentation1.ts @@ -0,0 +1,8 @@ +/// + +/////*1*/declare global { +////} + +format.document(); +goTo.marker("1"); +verify.currentLineContentIs("declare global {"); \ No newline at end of file diff --git a/tests/cases/fourslash/formattingGlobalAugmentation2.ts b/tests/cases/fourslash/formattingGlobalAugmentation2.ts new file mode 100644 index 0000000000000..74f05e1a93655 --- /dev/null +++ b/tests/cases/fourslash/formattingGlobalAugmentation2.ts @@ -0,0 +1,10 @@ +/// + +////declare module "A" { +/////*1*/ global { +//// } +////} + +format.document(); +goTo.marker("1"); +verify.currentLineContentIs(" global {"); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts index ba2d9faae8c66..562f42124aeae 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics8.ts @@ -7,8 +7,8 @@ verify.getSemanticDiagnostics(`[ { "message": "'type aliases' can only be used in a .ts file.", - "start": 0, - "length": 11, + "start": 5, + "length": 1, "category": "error", "code": 8008 } diff --git a/tests/cases/fourslash/indentationInAugmentations1.ts b/tests/cases/fourslash/indentationInAugmentations1.ts new file mode 100644 index 0000000000000..8a9b81fdd67b1 --- /dev/null +++ b/tests/cases/fourslash/indentationInAugmentations1.ts @@ -0,0 +1,9 @@ +/// + +// @module: amd +//// export {} +//// declare global {/*1*/ + +goTo.marker("1"); +edit.insertLine(""); +verify.indentationIs(4); \ No newline at end of file diff --git a/tests/cases/fourslash/indentationInAugmentations2.ts b/tests/cases/fourslash/indentationInAugmentations2.ts new file mode 100644 index 0000000000000..df2400207bb56 --- /dev/null +++ b/tests/cases/fourslash/indentationInAugmentations2.ts @@ -0,0 +1,8 @@ +/// + +//// declare module "A" { +//// global {/*1*/ + +goTo.marker("1"); +edit.insertLine(""); +verify.indentationIs(8); \ No newline at end of file