diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d88c135a22c70..0b19d7806ff07 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -56,9 +56,10 @@ namespace ts { break; // 4. Export alias declarations pointing at only uninstantiated modules or things uninstantiated modules contain case SyntaxKind.ExportDeclaration: - if (!(node as ExportDeclaration).moduleSpecifier && !!(node as ExportDeclaration).exportClause) { + const exportDeclaration = node as ExportDeclaration; + if (!exportDeclaration.moduleSpecifier && exportDeclaration.exportClause && exportDeclaration.exportClause.kind === SyntaxKind.NamedExports) { let state = ModuleInstanceState.NonInstantiated; - for (const specifier of (node as ExportDeclaration).exportClause!.elements) { + for (const specifier of exportDeclaration.exportClause.elements) { const specifierState = getModuleInstanceStateForAliasTarget(specifier, visited); if (specifierState > state) { state = specifierState; @@ -2575,6 +2576,9 @@ namespace ts { // All export * declarations are collected in an __export symbol declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); } + else if (isNamespaceExport(node.exportClause)) { + declareSymbol(container.symbol.exports, container.symbol, node.exportClause, SymbolFlags.Alias, SymbolFlags.AliasExcludes); + } } function bindImportClause(node: ImportClause) { @@ -4111,6 +4115,10 @@ namespace ts { case SyntaxKind.SourceFile: break; + case SyntaxKind.NamespaceExport: + transformFlags |= TransformFlags.AssertESNext; + break; + case SyntaxKind.ReturnStatement: // Return statements may require an `await` in ES2018. transformFlags |= TransformFlags.ContainsHoistedDeclarationOrCompletion | TransformFlags.AssertES2018; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b8bea6e87f24a..1feb30b9a3889 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1547,7 +1547,7 @@ namespace ts { const moduleExport = moduleExports.get(name); if (moduleExport && moduleExport.flags === SymbolFlags.Alias && - getDeclarationOfKind(moduleExport, SyntaxKind.ExportSpecifier)) { + (getDeclarationOfKind(moduleExport, SyntaxKind.ExportSpecifier) || getDeclarationOfKind(moduleExport, SyntaxKind.NamespaceExport))) { break; } } @@ -2217,6 +2217,11 @@ namespace ts { return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias, /*suppressUsageError*/ false); } + function getTargetOfNamespaceExport(node: NamespaceExport, dontResolveAlias: boolean): Symbol | undefined { + const moduleSpecifier = node.parent.moduleSpecifier; + return moduleSpecifier && resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias, /*suppressUsageError*/ false); + } + // This function creates a synthetic symbol that combines the value side of one symbol with the // type/namespace side of another symbol. Consider this example: // @@ -2382,6 +2387,8 @@ namespace ts { return getTargetOfImportClause(node, dontRecursivelyResolve); case SyntaxKind.NamespaceImport: return getTargetOfNamespaceImport(node, dontRecursivelyResolve); + case SyntaxKind.NamespaceExport: + return getTargetOfNamespaceExport(node, dontRecursivelyResolve); case SyntaxKind.ImportSpecifier: return getTargetOfImportSpecifier(node, dontRecursivelyResolve); case SyntaxKind.ExportSpecifier: @@ -5077,18 +5084,18 @@ namespace ts { function mergeExportDeclarations(statements: Statement[]) { // Pass 2: Combine all `export {}` declarations - const exports = filter(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration[]; + const exports = filter(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause && isNamedExports(d.exportClause)) as ExportDeclaration[]; if (length(exports) > 1) { const nonExports = filter(statements, d => !isExportDeclaration(d) || !!d.moduleSpecifier || !d.exportClause); statements = [...nonExports, createExportDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, - createNamedExports(flatMap(exports, e => e.exportClause!.elements)), + createNamedExports(flatMap(exports, e => cast(e.exportClause, isNamedExports).elements)), /*moduleSpecifier*/ undefined )]; } // Pass 2b: Also combine all `export {} from "..."` declarations as needed - const reexports = filter(statements, d => isExportDeclaration(d) && !!d.moduleSpecifier && !!d.exportClause) as ExportDeclaration[]; + const reexports = filter(statements, d => isExportDeclaration(d) && !!d.moduleSpecifier && !!d.exportClause && isNamedExports(d.exportClause)) as ExportDeclaration[]; if (length(reexports) > 1) { const groups = group(reexports, decl => isStringLiteral(decl.moduleSpecifier!) ? ">" + decl.moduleSpecifier.text : ">"); if (groups.length !== reexports.length) { @@ -5100,7 +5107,7 @@ namespace ts { createExportDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, - createNamedExports(flatMap(group, e => e.exportClause!.elements)), + createNamedExports(flatMap(group, e => cast(e.exportClause, isNamedExports).elements)), group[0].moduleSpecifier ) ]; @@ -5114,8 +5121,8 @@ namespace ts { function inlineExportModifiers(statements: Statement[]) { // Pass 3: Move all `export {}`'s to `export` modifiers where possible const exportDecl = find(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration | undefined; - if (exportDecl) { - const replacements = mapDefined(exportDecl.exportClause!.elements, e => { + if (exportDecl && exportDecl.exportClause && isNamedExports(exportDecl.exportClause)) { + const replacements = mapDefined(exportDecl.exportClause.elements, e => { if (!e.propertyName) { // export {name} - look thru `statements` for `name`, and if all results can take an `export` modifier, do so and filter it const associated = filter(statements, s => nodeHasName(s, e.name)); @@ -5133,7 +5140,7 @@ namespace ts { else { // some items filtered, others not - update the export declaration // (mutating because why not, we're building a whole new tree here anyway) - exportDecl.exportClause!.elements = createNodeArray(replacements); + exportDecl.exportClause.elements = createNodeArray(replacements); } } return statements; @@ -5649,6 +5656,14 @@ namespace ts { createLiteral(getSpecifierForModuleSymbol(target, context)) ), ModifierFlags.None); break; + case SyntaxKind.NamespaceExport: + addResult(createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamespaceExport(createIdentifier(localName)), + createLiteral(getSpecifierForModuleSymbol(target, context)) + ), ModifierFlags.None); + break; case SyntaxKind.ImportSpecifier: addResult(createImportDeclaration( /*decorators*/ undefined, @@ -32600,7 +32615,7 @@ namespace ts { return true; } - function checkAliasSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier) { + function checkAliasSymbol(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier | ExportSpecifier | NamespaceExport) { let symbol = getSymbolOfNode(node); const target = resolveAlias(symbol); @@ -32719,7 +32734,12 @@ namespace ts { if (node.exportClause) { // export { x, y } // export { x, y } from "foo" - forEach(node.exportClause.elements, checkExportSpecifier); + if (isNamedExports(node.exportClause)) { + forEach(node.exportClause.elements, checkExportSpecifier); + } + else if(!isNamespaceExport(node.exportClause)) { + checkImportBinding(node.exportClause); + } const inAmbientExternalModule = node.parent.kind === SyntaxKind.ModuleBlock && isAmbientModule(node.parent.parent); const inAmbientNamespaceDeclaration = !inAmbientExternalModule && node.parent.kind === SyntaxKind.ModuleBlock && @@ -34149,7 +34169,10 @@ namespace ts { return isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol); case SyntaxKind.ExportDeclaration: const exportClause = (node).exportClause; - return !!exportClause && some(exportClause.elements, isValueAliasDeclaration); + return !!exportClause && ( + isNamespaceExport(exportClause) || + some(exportClause.elements, isValueAliasDeclaration) + ); case SyntaxKind.ExportAssignment: return (node).expression && (node).expression.kind === SyntaxKind.Identifier ? isAliasResolvedToValue(getSymbolOfNode(node) || unknownSymbol) : diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 703bc0365be14..84b0a801f5f7d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1435,6 +1435,8 @@ namespace ts { return emitImportClause(node); case SyntaxKind.NamespaceImport: return emitNamespaceImport(node); + case SyntaxKind.NamespaceExport: + return emitNamespaceExport(node); case SyntaxKind.NamedImports: return emitNamedImports(node); case SyntaxKind.ImportSpecifier: @@ -3104,6 +3106,14 @@ namespace ts { writeTrailingSemicolon(); } + function emitNamespaceExport(node: NamespaceExport) { + const asPos = emitTokenWithComment(SyntaxKind.AsteriskToken, node.pos, writePunctuation, node); + writeSpace(); + emitTokenWithComment(SyntaxKind.AsKeyword, asPos, writeKeyword, node); + writeSpace(); + emit(node.name); + } + function emitNamedExports(node: NamedExports) { emitNamedImportsOrExports(node); } @@ -4408,6 +4418,9 @@ namespace ts { case SyntaxKind.NamespaceImport: generateNameIfNeeded((node).name); break; + case SyntaxKind.NamespaceExport: + generateNameIfNeeded((node).name); + break; case SyntaxKind.NamedImports: forEach((node).elements, generateNames); break; diff --git a/src/compiler/factoryPublic.ts b/src/compiler/factoryPublic.ts index 3c17ce2bdab7f..a5a99d179db7a 100644 --- a/src/compiler/factoryPublic.ts +++ b/src/compiler/factoryPublic.ts @@ -2278,12 +2278,24 @@ namespace ts { return node; } + export function createNamespaceExport(name: Identifier): NamespaceExport { + const node = createSynthesizedNode(SyntaxKind.NamespaceExport); + node.name = name; + return node; + } + export function updateNamespaceImport(node: NamespaceImport, name: Identifier) { return node.name !== name ? updateNode(createNamespaceImport(name), node) : node; } + export function updateNamespaceExport(node: NamespaceExport, name: Identifier) { + return node.name !== name + ? updateNode(createNamespaceExport(name), node) + : node; + } + export function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports { const node = createSynthesizedNode(SyntaxKind.NamedImports); node.elements = createNodeArray(elements); @@ -2327,7 +2339,7 @@ namespace ts { : node; } - export function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier?: Expression) { + export function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression) { const node = createSynthesizedNode(SyntaxKind.ExportDeclaration); node.decorators = asNodeArray(decorators); node.modifiers = asNodeArray(modifiers); @@ -2340,7 +2352,7 @@ namespace ts { node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, - exportClause: NamedExports | undefined, + exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined) { return node.decorators !== decorators || node.modifiers !== modifiers diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1ed276dddc8a4..6b7c887edfe8d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -390,6 +390,8 @@ namespace ts { case SyntaxKind.NamespaceImport: return visitNode(cbNode, (node).name); + case SyntaxKind.NamespaceExport: + return visitNode(cbNode, (node).name); case SyntaxKind.NamedImports: case SyntaxKind.NamedExports: return visitNodes(cbNode, cbNodes, (node).elements); @@ -6470,9 +6472,18 @@ namespace ts { return finishNode(node); } + function parseNamespaceExport(): NamespaceExport { + const node = createNode(SyntaxKind.NamespaceExport); + node.name = parseIdentifier(); + return finishNode(node); + } + function parseExportDeclaration(node: ExportDeclaration): ExportDeclaration { node.kind = SyntaxKind.ExportDeclaration; if (parseOptional(SyntaxKind.AsteriskToken)) { + if (parseOptional(SyntaxKind.AsKeyword)) { + node.exportClause = parseNamespaceExport(); + } parseExpected(SyntaxKind.FromKeyword); node.moduleSpecifier = parseModuleSpecifier(); } diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index bd8f34ee128c6..f4932b8fa419c 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -4,7 +4,7 @@ namespace ts { switch (moduleKind) { case ModuleKind.ESNext: case ModuleKind.ES2015: - return transformES2015Module; + return transformECMAScriptModule; case ModuleKind.System: return transformSystemModule; default: diff --git a/src/compiler/transformers/module/es2015.ts b/src/compiler/transformers/module/esnextAnd2015.ts similarity index 68% rename from src/compiler/transformers/module/es2015.ts rename to src/compiler/transformers/module/esnextAnd2015.ts index e1123d1248d9f..722c0ca770862 100644 --- a/src/compiler/transformers/module/es2015.ts +++ b/src/compiler/transformers/module/esnextAnd2015.ts @@ -1,6 +1,6 @@ /*@internal*/ namespace ts { - export function transformES2015Module(context: TransformationContext) { + export function transformECMAScriptModule(context: TransformationContext) { const compilerOptions = context.getCompilerOptions(); const previousOnEmitNode = context.onEmitNode; const previousOnSubstituteNode = context.onSubstituteNode; @@ -44,6 +44,9 @@ namespace ts { return undefined; case SyntaxKind.ExportAssignment: return visitExportAssignment(node); + case SyntaxKind.ExportDeclaration: + const exportDecl = (node as ExportDeclaration); + return visitExportDeclaration(exportDecl); } return node; @@ -54,6 +57,41 @@ namespace ts { return node.isExportEquals ? undefined : node; } + function visitExportDeclaration(node: ExportDeclaration) { + // `export * as ns` only needs to be transformed in ES2015 + if (compilerOptions.module !== undefined && compilerOptions.module > ModuleKind.ES2015) { + return node; + } + + // Either ill-formed or don't need to be tranformed. + if (!node.exportClause || !isNamespaceExport(node.exportClause) || !node.moduleSpecifier) { + return node; + } + + const oldIdentifier = node.exportClause.name; + const synthName = getGeneratedNameForNode(oldIdentifier); + const importDecl = createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(/*name*/ undefined, + createNamespaceImport( + synthName + ) + ), + node.moduleSpecifier, + ); + setOriginalNode(importDecl, node.exportClause); + + const exportDecl = createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports([createExportSpecifier(synthName, oldIdentifier)]), + ); + setOriginalNode(exportDecl, node); + + return [importDecl, exportDecl]; + } + // // Emit Notification // diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 9726c6402e168..0e90ad2eb2bb4 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -747,6 +747,17 @@ namespace ts { return createCall(createPropertyAccess(promiseResolveCall, "then"), /*typeArguments*/ undefined, [func]); } + function getHelperExpressionForExport(node: ExportDeclaration, innerExpr: Expression) { + if (!compilerOptions.esModuleInterop || getEmitFlags(node) & EmitFlags.NeverApplyImportHelper) { + return innerExpr; + } + if (getExportNeedsImportStarHelper(node)) { + context.requestEmitHelper(importStarHelper); + return createCall(getUnscopedHelperName("__importStar"), /*typeArguments*/ undefined, [innerExpr]); + } + return innerExpr; + } + function getHelperExpressionForImport(node: ImportDeclaration, innerExpr: Expression) { if (!compilerOptions.esModuleInterop || getEmitFlags(node) & EmitFlags.NeverApplyImportHelper) { return innerExpr; @@ -967,7 +978,7 @@ namespace ts { const generatedName = getGeneratedNameForNode(node); - if (node.exportClause) { + if (node.exportClause && isNamedExports(node.exportClause)) { const statements: Statement[] = []; // export { x, y } from "mod"; if (moduleKind !== ModuleKind.AMD) { @@ -1008,6 +1019,28 @@ namespace ts { return singleOrMany(statements); } + else if (node.exportClause) { + const statements: Statement[] = []; + // export * as ns from "mod"; + statements.push( + setOriginalNode( + setTextRange( + createExpressionStatement( + createExportExpression( + getSynthesizedClone(node.exportClause.name), + moduleKind !== ModuleKind.AMD ? + getHelperExpressionForExport(node, createRequireCall(node)) : + createIdentifier(idText(node.exportClause.name)) + ) + ), + node + ), + node + ) + ); + + return singleOrMany(statements); + } else { // export * from "mod"; return setOriginalNode( diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 731ed6ef4fefe..7c4755924510c 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -346,11 +346,21 @@ namespace ts { continue; } - for (const element of externalImport.exportClause.elements) { - // write name of indirectly exported entry, i.e. 'export {x} from ...' + if (isNamedExports(externalImport.exportClause)) { + for (const element of externalImport.exportClause.elements) { + // write name of indirectly exported entry, i.e. 'export {x} from ...' + exportedNames.push( + createPropertyAssignment( + createLiteral(idText(element.name || element.propertyName)), + createTrue() + ) + ); + } + } + else { exportedNames.push( createPropertyAssignment( - createLiteral(idText(element.name || element.propertyName)), + createLiteral(idText(externalImport.exportClause.name)), createTrue() ) ); @@ -489,36 +499,52 @@ namespace ts { case SyntaxKind.ExportDeclaration: Debug.assert(importVariableName !== undefined); if (entry.exportClause) { - // export {a, b as c} from 'foo' - // - // emit as: - // - // exports_({ - // "a": _["a"], - // "c": _["b"] - // }); - const properties: PropertyAssignment[] = []; - for (const e of entry.exportClause.elements) { - properties.push( - createPropertyAssignment( - createLiteral(idText(e.name)), - createElementAccess( - parameterName, - createLiteral(idText(e.propertyName || e.name)) + if (isNamedExports(entry.exportClause)) { + // export {a, b as c} from 'foo' + // + // emit as: + // + // exports_({ + // "a": _["a"], + // "c": _["b"] + // }); + const properties: PropertyAssignment[] = []; + for (const e of entry.exportClause.elements) { + properties.push( + createPropertyAssignment( + createLiteral(idText(e.name)), + createElementAccess( + parameterName, + createLiteral(idText(e.propertyName || e.name)) + ) + ) + ); + } + + statements.push( + createExpressionStatement( + createCall( + exportFunction, + /*typeArguments*/ undefined, + [createObjectLiteral(properties, /*multiline*/ true)] ) ) ); } - - statements.push( - createExpressionStatement( - createCall( - exportFunction, - /*typeArguments*/ undefined, - [createObjectLiteral(properties, /*multiline*/ true)] + else { + statements.push( + createExpressionStatement( + createCall( + exportFunction, + /*typeArguments*/ undefined, + [ + createLiteral(idText(entry.exportClause.name)), + parameterName + ] + ) ) - ) - ); + ); + } } else { // export * from 'foo' @@ -574,9 +600,7 @@ namespace ts { return visitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: - // ExportDeclarations are elided as they are handled via - // `appendExportsOfDeclaration`. - return undefined; + return visitExportDeclaration(node); case SyntaxKind.ExportAssignment: return visitExportAssignment(node); @@ -609,6 +633,11 @@ namespace ts { return singleOrMany(statements); } + function visitExportDeclaration(node: ExportDeclaration): VisitResult { + Debug.assertDefined(node); + return undefined; + } + /** * Visits an ImportEqualsDeclaration node. * diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 85c907cf76f2d..ed4cbcbd0dfca 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2849,7 +2849,7 @@ namespace ts { } // Elide the export declaration if all of its named exports are elided. - const exportClause = visitNode(node.exportClause, visitNamedExports, isNamedExports); + const exportClause = visitNode(node.exportClause, visitNamedExportBindings, isNamedImportBindings); return exportClause ? updateExportDeclaration( node, @@ -2872,6 +2872,14 @@ namespace ts { return some(elements) ? updateNamedExports(node, elements) : undefined; } + function visitNamespaceExports(node: NamespaceExport): VisitResult { + return updateNamespaceExport(node, visitNode(node.name, visitor, isIdentifier)); + } + + function visitNamedExportBindings(node: NamedExportBindings): VisitResult { + return isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node); + } + /** * Visits an export specifier, eliding it if it does not resolve to a value. * diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index e2029ff7b602e..c47b033014b0b 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -37,6 +37,10 @@ namespace ts { } } + export function getExportNeedsImportStarHelper(node: ExportDeclaration): boolean { + return !!getNamespaceDeclarationNode(node); + } + export function getImportNeedsImportStarHelper(node: ImportDeclaration): boolean { if (!!getNamespaceDeclarationNode(node)) { return true; @@ -105,13 +109,14 @@ namespace ts { hasExportStarsToExportValues = true; } else { + // export * as ns from "mod" // export { x, y } from "mod" externalImports.push(node); } } else { // export { x, y } - for (const specifier of (node).exportClause!.elements) { + for (const specifier of cast((node).exportClause, isNamedExports).elements) { if (!uniqueExports.get(idText(specifier.name))) { const name = specifier.propertyName || specifier.name; exportSpecifiers.add(idText(name), specifier); diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index ac072239eebb6..41048b59fdb22 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -51,7 +51,7 @@ "transformers/generators.ts", "transformers/module/module.ts", "transformers/module/system.ts", - "transformers/module/es2015.ts", + "transformers/module/esnextAnd2015.ts", "transformers/declarations/diagnostics.ts", "transformers/declarations.ts", "transformer.ts", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 075dbb9a6e6e8..89c166b19804f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -403,6 +403,7 @@ namespace ts { ExportAssignment, ExportDeclaration, NamedExports, + NamespaceExport, ExportSpecifier, MissingDeclaration, @@ -2442,6 +2443,7 @@ namespace ts { } export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedExportBindings = NamespaceExport | NamedExports; // In case of: // import d from "mod" => name = d, namedBinding = undefined @@ -2462,6 +2464,12 @@ namespace ts { name: Identifier; } + export interface NamespaceExport extends NamedDeclaration { + kind: SyntaxKind.NamespaceExport; + parent: ExportDeclaration; + name: Identifier + } + export interface NamespaceExportDeclaration extends DeclarationStatement { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; @@ -2471,7 +2479,7 @@ namespace ts { kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index d095541d4ca6c..d5149b80eca15 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2237,14 +2237,14 @@ namespace ts { } } - export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): ImportEqualsDeclaration | NamespaceImport | undefined { + export function getNamespaceDeclarationNode(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): ImportEqualsDeclaration | NamespaceImport | NamespaceExport | undefined { switch (node.kind) { case SyntaxKind.ImportDeclaration: return node.importClause && tryCast(node.importClause.namedBindings, isNamespaceImport); case SyntaxKind.ImportEqualsDeclaration: return node; case SyntaxKind.ExportDeclaration: - return undefined; + return node.exportClause && tryCast(node.exportClause, isNamespaceExport); default: return Debug.assertNever(node); } @@ -2681,6 +2681,7 @@ namespace ts { // import * as from ... // import { x as } from ... // export { x as } from ... + // export * as ns from ... // export = // export default // module.exports = @@ -2691,6 +2692,7 @@ namespace ts { node.kind === SyntaxKind.NamespaceExportDeclaration || node.kind === SyntaxKind.ImportClause && !!(node).name || node.kind === SyntaxKind.NamespaceImport || + node.kind === SyntaxKind.NamespaceExport || node.kind === SyntaxKind.ImportSpecifier || node.kind === SyntaxKind.ExportSpecifier || node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node) || diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index cf5f444260c65..c67abd16d8697 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1366,6 +1366,14 @@ namespace ts { return node.kind === SyntaxKind.NamespaceImport; } + export function isNamespaceExport(node: Node): node is NamespaceExport { + return node.kind === SyntaxKind.NamespaceExport; + } + + export function isNamedExportBindings(node: Node): node is NamedExportBindings { + return node.kind === SyntaxKind.NamespaceExport || node.kind === SyntaxKind.NamedExports; + } + export function isNamedImports(node: Node): node is NamedImports { return node.kind === SyntaxKind.NamedImports; } @@ -2263,6 +2271,7 @@ namespace ts { || kind === SyntaxKind.ModuleDeclaration || kind === SyntaxKind.NamespaceExportDeclaration || kind === SyntaxKind.NamespaceImport + || kind === SyntaxKind.NamespaceExport || kind === SyntaxKind.Parameter || kind === SyntaxKind.PropertyAssignment || kind === SyntaxKind.PropertyDeclaration diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index cbbd3c1924131..54ea4ea060a3f 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -386,6 +386,10 @@ namespace ts { result = reduceNode((node).name, cbNode, result); break; + case SyntaxKind.NamespaceExport: + result = reduceNode((node).name, cbNode, result); + break; + case SyntaxKind.NamedImports: case SyntaxKind.NamedExports: result = reduceNodes((node).elements, cbNodes, result); diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 7d21af87ef90c..c48b27bdce01c 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -798,6 +798,10 @@ namespace ts { return updateNamespaceImport(node, visitNode((node).name, visitor, isIdentifier)); + case SyntaxKind.NamespaceExport: + return updateNamespaceExport(node, + visitNode((node).name, visitor, isIdentifier)); + case SyntaxKind.NamedImports: return updateNamedImports(node, nodesVisitor((node).elements, visitor, isImportSpecifier)); @@ -817,7 +821,7 @@ namespace ts { return updateExportDeclaration(node, nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), - visitNode((node).exportClause, visitor, isNamedExports), + visitNode((node).exportClause, visitor, isNamedExportBindings), visitNode((node).moduleSpecifier, visitor, isExpression)); case SyntaxKind.NamedExports: diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index 24273cf815a65..7e8955f8c9c3e 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -240,7 +240,9 @@ namespace ts.FindAllReferences { } if (decl.kind === SyntaxKind.ExportDeclaration) { - searchForNamedImport(decl.exportClause); + if (decl.exportClause && isNamedExports(decl.exportClause)) { + searchForNamedImport(decl.exportClause); + } return; } @@ -326,7 +328,7 @@ namespace ts.FindAllReferences { return !!forEachPossibleImportOrExportStatement(sourceFileLike, statement => { if (!isExportDeclaration(statement)) return; const { exportClause, moduleSpecifier } = statement; - return !moduleSpecifier && exportClause && + return !moduleSpecifier && exportClause && isNamedExports(exportClause) && exportClause.elements.some(element => checker.getExportSpecifierLocalTargetSymbol(element) === namespaceImportSymbol); }); } diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index 6db5c9eeadc8c..232f2c1ba9509 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -307,7 +307,7 @@ namespace ts.OrganizeImports { } const newExportSpecifiers: ExportSpecifier[] = []; - newExportSpecifiers.push(...flatMap(namedExports, i => (i.exportClause!).elements)); + newExportSpecifiers.push(...flatMap(namedExports, i => i.exportClause && isNamedExports(i.exportClause) ? i.exportClause.elements : emptyArray)); const sortedExportSpecifiers = sortSpecifiers(newExportSpecifiers); @@ -317,7 +317,11 @@ namespace ts.OrganizeImports { exportDecl, exportDecl.decorators, exportDecl.modifiers, - updateNamedExports(exportDecl.exportClause!, sortedExportSpecifiers), + exportDecl.exportClause && ( + isNamedExports(exportDecl.exportClause) ? + updateNamedExports(exportDecl.exportClause, sortedExportSpecifiers) : + updateNamespaceExport(exportDecl.exportClause, exportDecl.exportClause.name) + ), exportDecl.moduleSpecifier)); return coalescedExports; diff --git a/src/services/services.ts b/src/services/services.ts index 72f1eed4ef88f..d43a288f90c7e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -752,8 +752,14 @@ namespace ts { case SyntaxKind.ExportDeclaration: // Handle named exports case e.g.: // export {a, b as B} from "mod"; - if ((node).exportClause) { - forEach((node).exportClause!.elements, visit); + const exportDeclaration = (node); + if (exportDeclaration.exportClause) { + if (isNamedExports(exportDeclaration.exportClause)) { + forEach(exportDeclaration.exportClause.elements, visit); + } + else { + visit(exportDeclaration.exportClause.name); + } } break; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 5034fe0dc752e..6a1f621bb9ca6 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -373,6 +373,7 @@ namespace ts { case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: case SyntaxKind.NamespaceImport: + case SyntaxKind.NamespaceExport: return ScriptElementKind.alias; case SyntaxKind.BinaryExpression: const kind = getAssignmentDeclarationKind(node as BinaryExpression); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index bb9a42a783705..b8296531deb7a 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -336,74 +336,75 @@ declare namespace ts { ExportAssignment = 258, ExportDeclaration = 259, NamedExports = 260, - ExportSpecifier = 261, - MissingDeclaration = 262, - ExternalModuleReference = 263, - JsxElement = 264, - JsxSelfClosingElement = 265, - JsxOpeningElement = 266, - JsxClosingElement = 267, - JsxFragment = 268, - JsxOpeningFragment = 269, - JsxClosingFragment = 270, - JsxAttribute = 271, - JsxAttributes = 272, - JsxSpreadAttribute = 273, - JsxExpression = 274, - CaseClause = 275, - DefaultClause = 276, - HeritageClause = 277, - CatchClause = 278, - PropertyAssignment = 279, - ShorthandPropertyAssignment = 280, - SpreadAssignment = 281, - EnumMember = 282, - UnparsedPrologue = 283, - UnparsedPrepend = 284, - UnparsedText = 285, - UnparsedInternalText = 286, - UnparsedSyntheticReference = 287, - SourceFile = 288, - Bundle = 289, - UnparsedSource = 290, - InputFiles = 291, - JSDocTypeExpression = 292, - JSDocAllType = 293, - JSDocUnknownType = 294, - JSDocNullableType = 295, - JSDocNonNullableType = 296, - JSDocOptionalType = 297, - JSDocFunctionType = 298, - JSDocVariadicType = 299, - JSDocNamepathType = 300, - JSDocComment = 301, - JSDocTypeLiteral = 302, - JSDocSignature = 303, - JSDocTag = 304, - JSDocAugmentsTag = 305, - JSDocAuthorTag = 306, - JSDocClassTag = 307, - JSDocPublicTag = 308, - JSDocPrivateTag = 309, - JSDocProtectedTag = 310, - JSDocReadonlyTag = 311, - JSDocCallbackTag = 312, - JSDocEnumTag = 313, - JSDocParameterTag = 314, - JSDocReturnTag = 315, - JSDocThisTag = 316, - JSDocTypeTag = 317, - JSDocTemplateTag = 318, - JSDocTypedefTag = 319, - JSDocPropertyTag = 320, - SyntaxList = 321, - NotEmittedStatement = 322, - PartiallyEmittedExpression = 323, - CommaListExpression = 324, - MergeDeclarationMarker = 325, - EndOfDeclarationMarker = 326, - SyntheticReferenceExpression = 327, - Count = 328, + NamespaceExport = 261, + ExportSpecifier = 262, + MissingDeclaration = 263, + ExternalModuleReference = 264, + JsxElement = 265, + JsxSelfClosingElement = 266, + JsxOpeningElement = 267, + JsxClosingElement = 268, + JsxFragment = 269, + JsxOpeningFragment = 270, + JsxClosingFragment = 271, + JsxAttribute = 272, + JsxAttributes = 273, + JsxSpreadAttribute = 274, + JsxExpression = 275, + CaseClause = 276, + DefaultClause = 277, + HeritageClause = 278, + CatchClause = 279, + PropertyAssignment = 280, + ShorthandPropertyAssignment = 281, + SpreadAssignment = 282, + EnumMember = 283, + UnparsedPrologue = 284, + UnparsedPrepend = 285, + UnparsedText = 286, + UnparsedInternalText = 287, + UnparsedSyntheticReference = 288, + SourceFile = 289, + Bundle = 290, + UnparsedSource = 291, + InputFiles = 292, + JSDocTypeExpression = 293, + JSDocAllType = 294, + JSDocUnknownType = 295, + JSDocNullableType = 296, + JSDocNonNullableType = 297, + JSDocOptionalType = 298, + JSDocFunctionType = 299, + JSDocVariadicType = 300, + JSDocNamepathType = 301, + JSDocComment = 302, + JSDocTypeLiteral = 303, + JSDocSignature = 304, + JSDocTag = 305, + JSDocAugmentsTag = 306, + JSDocAuthorTag = 307, + JSDocClassTag = 308, + JSDocPublicTag = 309, + JSDocPrivateTag = 310, + JSDocProtectedTag = 311, + JSDocReadonlyTag = 312, + JSDocCallbackTag = 313, + JSDocEnumTag = 314, + JSDocParameterTag = 315, + JSDocReturnTag = 316, + JSDocThisTag = 317, + JSDocTypeTag = 318, + JSDocTemplateTag = 319, + JSDocTypedefTag = 320, + JSDocPropertyTag = 321, + SyntaxList = 322, + NotEmittedStatement = 323, + PartiallyEmittedExpression = 324, + CommaListExpression = 325, + MergeDeclarationMarker = 326, + EndOfDeclarationMarker = 327, + SyntheticReferenceExpression = 328, + Count = 329, FirstAssignment = 62, LastAssignment = 74, FirstCompoundAssignment = 63, @@ -431,10 +432,10 @@ declare namespace ts { FirstStatement = 224, LastStatement = 240, FirstNode = 152, - FirstJSDocNode = 292, - LastJSDocNode = 320, - FirstJSDocTagNode = 304, - LastJSDocTagNode = 320, + FirstJSDocNode = 293, + LastJSDocNode = 321, + FirstJSDocTagNode = 305, + LastJSDocTagNode = 321, } export enum NodeFlags { None = 0, @@ -1484,6 +1485,7 @@ declare namespace ts { moduleSpecifier: Expression; } export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedExportBindings = NamespaceExport | NamedExports; export interface ImportClause extends NamedDeclaration { kind: SyntaxKind.ImportClause; parent: ImportDeclaration; @@ -1495,6 +1497,11 @@ declare namespace ts { parent: ImportClause; name: Identifier; } + export interface NamespaceExport extends NamedDeclaration { + kind: SyntaxKind.NamespaceExport; + parent: ExportDeclaration; + name: Identifier; + } export interface NamespaceExportDeclaration extends DeclarationStatement { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; @@ -1503,7 +1510,7 @@ declare namespace ts { kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } @@ -3637,6 +3644,8 @@ declare namespace ts { function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; function isNamespaceImport(node: Node): node is NamespaceImport; + function isNamespaceExport(node: Node): node is NamespaceExport; + function isNamedExportBindings(node: Node): node is NamedExportBindings; function isNamedImports(node: Node): node is NamedImports; function isImportSpecifier(node: Node): node is ImportSpecifier; function isExportAssignment(node: Node): node is ExportAssignment; @@ -4157,15 +4166,17 @@ declare namespace ts { function createImportClause(name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function createNamespaceImport(name: Identifier): NamespaceImport; + function createNamespaceExport(name: Identifier): NamespaceExport; function updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; + function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports; function updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports; function createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; function updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; function createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; function updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; - function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier?: Expression): ExportDeclaration; - function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; + function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration; + function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; function createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; function updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; function createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 5ec4c0010fad4..19bd663279d62 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -336,74 +336,75 @@ declare namespace ts { ExportAssignment = 258, ExportDeclaration = 259, NamedExports = 260, - ExportSpecifier = 261, - MissingDeclaration = 262, - ExternalModuleReference = 263, - JsxElement = 264, - JsxSelfClosingElement = 265, - JsxOpeningElement = 266, - JsxClosingElement = 267, - JsxFragment = 268, - JsxOpeningFragment = 269, - JsxClosingFragment = 270, - JsxAttribute = 271, - JsxAttributes = 272, - JsxSpreadAttribute = 273, - JsxExpression = 274, - CaseClause = 275, - DefaultClause = 276, - HeritageClause = 277, - CatchClause = 278, - PropertyAssignment = 279, - ShorthandPropertyAssignment = 280, - SpreadAssignment = 281, - EnumMember = 282, - UnparsedPrologue = 283, - UnparsedPrepend = 284, - UnparsedText = 285, - UnparsedInternalText = 286, - UnparsedSyntheticReference = 287, - SourceFile = 288, - Bundle = 289, - UnparsedSource = 290, - InputFiles = 291, - JSDocTypeExpression = 292, - JSDocAllType = 293, - JSDocUnknownType = 294, - JSDocNullableType = 295, - JSDocNonNullableType = 296, - JSDocOptionalType = 297, - JSDocFunctionType = 298, - JSDocVariadicType = 299, - JSDocNamepathType = 300, - JSDocComment = 301, - JSDocTypeLiteral = 302, - JSDocSignature = 303, - JSDocTag = 304, - JSDocAugmentsTag = 305, - JSDocAuthorTag = 306, - JSDocClassTag = 307, - JSDocPublicTag = 308, - JSDocPrivateTag = 309, - JSDocProtectedTag = 310, - JSDocReadonlyTag = 311, - JSDocCallbackTag = 312, - JSDocEnumTag = 313, - JSDocParameterTag = 314, - JSDocReturnTag = 315, - JSDocThisTag = 316, - JSDocTypeTag = 317, - JSDocTemplateTag = 318, - JSDocTypedefTag = 319, - JSDocPropertyTag = 320, - SyntaxList = 321, - NotEmittedStatement = 322, - PartiallyEmittedExpression = 323, - CommaListExpression = 324, - MergeDeclarationMarker = 325, - EndOfDeclarationMarker = 326, - SyntheticReferenceExpression = 327, - Count = 328, + NamespaceExport = 261, + ExportSpecifier = 262, + MissingDeclaration = 263, + ExternalModuleReference = 264, + JsxElement = 265, + JsxSelfClosingElement = 266, + JsxOpeningElement = 267, + JsxClosingElement = 268, + JsxFragment = 269, + JsxOpeningFragment = 270, + JsxClosingFragment = 271, + JsxAttribute = 272, + JsxAttributes = 273, + JsxSpreadAttribute = 274, + JsxExpression = 275, + CaseClause = 276, + DefaultClause = 277, + HeritageClause = 278, + CatchClause = 279, + PropertyAssignment = 280, + ShorthandPropertyAssignment = 281, + SpreadAssignment = 282, + EnumMember = 283, + UnparsedPrologue = 284, + UnparsedPrepend = 285, + UnparsedText = 286, + UnparsedInternalText = 287, + UnparsedSyntheticReference = 288, + SourceFile = 289, + Bundle = 290, + UnparsedSource = 291, + InputFiles = 292, + JSDocTypeExpression = 293, + JSDocAllType = 294, + JSDocUnknownType = 295, + JSDocNullableType = 296, + JSDocNonNullableType = 297, + JSDocOptionalType = 298, + JSDocFunctionType = 299, + JSDocVariadicType = 300, + JSDocNamepathType = 301, + JSDocComment = 302, + JSDocTypeLiteral = 303, + JSDocSignature = 304, + JSDocTag = 305, + JSDocAugmentsTag = 306, + JSDocAuthorTag = 307, + JSDocClassTag = 308, + JSDocPublicTag = 309, + JSDocPrivateTag = 310, + JSDocProtectedTag = 311, + JSDocReadonlyTag = 312, + JSDocCallbackTag = 313, + JSDocEnumTag = 314, + JSDocParameterTag = 315, + JSDocReturnTag = 316, + JSDocThisTag = 317, + JSDocTypeTag = 318, + JSDocTemplateTag = 319, + JSDocTypedefTag = 320, + JSDocPropertyTag = 321, + SyntaxList = 322, + NotEmittedStatement = 323, + PartiallyEmittedExpression = 324, + CommaListExpression = 325, + MergeDeclarationMarker = 326, + EndOfDeclarationMarker = 327, + SyntheticReferenceExpression = 328, + Count = 329, FirstAssignment = 62, LastAssignment = 74, FirstCompoundAssignment = 63, @@ -431,10 +432,10 @@ declare namespace ts { FirstStatement = 224, LastStatement = 240, FirstNode = 152, - FirstJSDocNode = 292, - LastJSDocNode = 320, - FirstJSDocTagNode = 304, - LastJSDocTagNode = 320, + FirstJSDocNode = 293, + LastJSDocNode = 321, + FirstJSDocTagNode = 305, + LastJSDocTagNode = 321, } export enum NodeFlags { None = 0, @@ -1484,6 +1485,7 @@ declare namespace ts { moduleSpecifier: Expression; } export type NamedImportBindings = NamespaceImport | NamedImports; + export type NamedExportBindings = NamespaceExport | NamedExports; export interface ImportClause extends NamedDeclaration { kind: SyntaxKind.ImportClause; parent: ImportDeclaration; @@ -1495,6 +1497,11 @@ declare namespace ts { parent: ImportClause; name: Identifier; } + export interface NamespaceExport extends NamedDeclaration { + kind: SyntaxKind.NamespaceExport; + parent: ExportDeclaration; + name: Identifier; + } export interface NamespaceExportDeclaration extends DeclarationStatement { kind: SyntaxKind.NamespaceExportDeclaration; name: Identifier; @@ -1503,7 +1510,7 @@ declare namespace ts { kind: SyntaxKind.ExportDeclaration; parent: SourceFile | ModuleBlock; /** Will not be assigned in the case of `export * from "foo";` */ - exportClause?: NamedExports; + exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ moduleSpecifier?: Expression; } @@ -3637,6 +3644,8 @@ declare namespace ts { function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; function isNamespaceImport(node: Node): node is NamespaceImport; + function isNamespaceExport(node: Node): node is NamespaceExport; + function isNamedExportBindings(node: Node): node is NamedExportBindings; function isNamedImports(node: Node): node is NamedImports; function isImportSpecifier(node: Node): node is ImportSpecifier; function isExportAssignment(node: Node): node is ExportAssignment; @@ -4157,15 +4166,17 @@ declare namespace ts { function createImportClause(name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; function createNamespaceImport(name: Identifier): NamespaceImport; + function createNamespaceExport(name: Identifier): NamespaceExport; function updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; + function updateNamespaceExport(node: NamespaceExport, name: Identifier): NamespaceExport; function createNamedImports(elements: readonly ImportSpecifier[]): NamedImports; function updateNamedImports(node: NamedImports, elements: readonly ImportSpecifier[]): NamedImports; function createImportSpecifier(propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; function updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; function createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; function updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; - function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier?: Expression): ExportDeclaration; - function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExports | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; + function createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration; + function updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; function createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; function updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; function createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; diff --git a/tests/baselines/reference/exportAsNamespace1(module=amd).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=amd).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=amd).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=amd).js b/tests/baselines/reference/exportAsNamespace1(module=amd).js new file mode 100644 index 0000000000000..ca45e03288c29 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=amd).js @@ -0,0 +1,48 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; +}); +//// [2.js] +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=amd).symbols b/tests/baselines/reference/exportAsNamespace1(module=amd).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=amd).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=amd).types b/tests/baselines/reference/exportAsNamespace1(module=amd).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=amd).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=commonjs).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=commonjs).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=commonjs).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=commonjs).js b/tests/baselines/reference/exportAsNamespace1(module=commonjs).js new file mode 100644 index 0000000000000..04171c4d75f05 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=commonjs).js @@ -0,0 +1,43 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +"use strict"; +exports.__esModule = true; +exports.a = 1; +exports.b = 2; +//// [1.js] +"use strict"; +exports.__esModule = true; +exports.ns = require("./0"); +ns.a; +ns.b; +//// [2.js] +"use strict"; +exports.__esModule = true; +var foo = require("./1"); +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=commonjs).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=commonjs).types b/tests/baselines/reference/exportAsNamespace1(module=commonjs).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=commonjs).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=es2015).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).js b/tests/baselines/reference/exportAsNamespace1(module=es2015).js new file mode 100644 index 0000000000000..98017e97f3c42 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).js @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +import * as ns_1 from './0'; +export { ns_1 as ns }; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=es2015).types b/tests/baselines/reference/exportAsNamespace1(module=es2015).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=es2015).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=esnext).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).js b/tests/baselines/reference/exportAsNamespace1(module=esnext).js new file mode 100644 index 0000000000000..3deaebf27ef64 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=esnext).types b/tests/baselines/reference/exportAsNamespace1(module=esnext).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=esnext).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=system).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).js b/tests/baselines/reference/exportAsNamespace1(module=system).js new file mode 100644 index 0000000000000..e40fec7232fe7 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).js @@ -0,0 +1,72 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).symbols b/tests/baselines/reference/exportAsNamespace1(module=system).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=system).types b/tests/baselines/reference/exportAsNamespace1(module=system).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=system).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).errors.txt b/tests/baselines/reference/exportAsNamespace1(module=umd).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).js b/tests/baselines/reference/exportAsNamespace1(module=umd).js new file mode 100644 index 0000000000000..14ae069e61a88 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).js @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = require("./0"); + ns.a; + ns.b; +}); +//// [2.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = require("./1"); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).symbols b/tests/baselines/reference/exportAsNamespace1(module=umd).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1(module=umd).types b/tests/baselines/reference/exportAsNamespace1(module=umd).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1(module=umd).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1_amd.errors.txt b/tests/baselines/reference/exportAsNamespace1_amd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_amd.js b/tests/baselines/reference/exportAsNamespace1_amd.js new file mode 100644 index 0000000000000..240bf93cdc9dc --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.js @@ -0,0 +1,48 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_amd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; +}); +//// [2.js] +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_amd.symbols b/tests/baselines/reference/exportAsNamespace1_amd.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_amd.types b/tests/baselines/reference/exportAsNamespace1_amd.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_amd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.errors.txt b/tests/baselines/reference/exportAsNamespace1_esnext.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.js b/tests/baselines/reference/exportAsNamespace1_esnext.js new file mode 100644 index 0000000000000..e662998bb926f --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_esnext.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.symbols b/tests/baselines/reference/exportAsNamespace1_esnext.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_esnext.types b/tests/baselines/reference/exportAsNamespace1_esnext.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_esnext.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1_system.errors.txt b/tests/baselines/reference/exportAsNamespace1_system.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_system.js b/tests/baselines/reference/exportAsNamespace1_system.js new file mode 100644 index 0000000000000..f326d4ad7fc20 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.js @@ -0,0 +1,72 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_system.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_system.symbols b/tests/baselines/reference/exportAsNamespace1_system.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_system.types b/tests/baselines/reference/exportAsNamespace1_system.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_system.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace1_umd.errors.txt b/tests/baselines/reference/exportAsNamespace1_umd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace1_umd.js b/tests/baselines/reference/exportAsNamespace1_umd.js new file mode 100644 index 0000000000000..35d797c66b79a --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.js @@ -0,0 +1,73 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace1_umd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = require("./0"); + ns.a; + ns.b; +}); +//// [2.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = require("./1"); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace1_umd.symbols b/tests/baselines/reference/exportAsNamespace1_umd.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace1_umd.types b/tests/baselines/reference/exportAsNamespace1_umd.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace1_umd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=amd).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).js b/tests/baselines/reference/exportAsNamespace2(module=amd).js new file mode 100644 index 0000000000000..623de698072cd --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).js @@ -0,0 +1,56 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo = __importStar(foo); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).symbols b/tests/baselines/reference/exportAsNamespace2(module=amd).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=amd).types b/tests/baselines/reference/exportAsNamespace2(module=amd).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=amd).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=commonjs).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).js b/tests/baselines/reference/exportAsNamespace2(module=commonjs).js new file mode 100644 index 0000000000000..80341d5a5b396 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).js @@ -0,0 +1,57 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +"use strict"; +exports.__esModule = true; +exports.a = 1; +exports.b = 2; +//// [1.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +exports.ns = __importStar(require("./0")); +ns.a; +ns.b; +//// [2.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +var foo = __importStar(require("./1")); +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=commonjs).types b/tests/baselines/reference/exportAsNamespace2(module=commonjs).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=commonjs).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=es2015).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).js b/tests/baselines/reference/exportAsNamespace2(module=es2015).js new file mode 100644 index 0000000000000..468d7968c5ccc --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).js @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +import * as ns_1 from './0'; +export { ns_1 as ns }; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=es2015).types b/tests/baselines/reference/exportAsNamespace2(module=es2015).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=es2015).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=esnext).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).js b/tests/baselines/reference/exportAsNamespace2(module=esnext).js new file mode 100644 index 0000000000000..5d2f1c65b3833 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).js @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=esnext).types b/tests/baselines/reference/exportAsNamespace2(module=esnext).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=esnext).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=system).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).js b/tests/baselines/reference/exportAsNamespace2(module=system).js new file mode 100644 index 0000000000000..a7f324958e4a9 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).js @@ -0,0 +1,72 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).symbols b/tests/baselines/reference/exportAsNamespace2(module=system).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=system).types b/tests/baselines/reference/exportAsNamespace2(module=system).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=system).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).errors.txt b/tests/baselines/reference/exportAsNamespace2(module=umd).errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).js b/tests/baselines/reference/exportAsNamespace2(module=umd).js new file mode 100644 index 0000000000000..dda2e48a8ab9a --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).js @@ -0,0 +1,87 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = __importStar(require("./0")); + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = __importStar(require("./1")); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).symbols b/tests/baselines/reference/exportAsNamespace2(module=umd).symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2(module=umd).types b/tests/baselines/reference/exportAsNamespace2(module=umd).types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2(module=umd).types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_amd.errors.txt b/tests/baselines/reference/exportAsNamespace2_amd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_amd.js b/tests/baselines/reference/exportAsNamespace2_amd.js new file mode 100644 index 0000000000000..9bb659b380087 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.js @@ -0,0 +1,56 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_amd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo = __importStar(foo); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2_amd.symbols b/tests/baselines/reference/exportAsNamespace2_amd.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_amd.types b/tests/baselines/reference/exportAsNamespace2_amd.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_amd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.errors.txt b/tests/baselines/reference/exportAsNamespace2_esnext.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_esnext.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.symbols b/tests/baselines/reference/exportAsNamespace2_esnext.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_esnext.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_esnext.types b/tests/baselines/reference/exportAsNamespace2_esnext.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_esnext.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_system.errors.txt b/tests/baselines/reference/exportAsNamespace2_system.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_system.js b/tests/baselines/reference/exportAsNamespace2_system.js new file mode 100644 index 0000000000000..8a4582bd4ce8b --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.js @@ -0,0 +1,72 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_system.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2_system.symbols b/tests/baselines/reference/exportAsNamespace2_system.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_system.types b/tests/baselines/reference/exportAsNamespace2_system.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_system.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace2_umd.errors.txt b/tests/baselines/reference/exportAsNamespace2_umd.errors.txt new file mode 100644 index 0000000000000..90b3756336ae0 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2304: Cannot find name 'ns'. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2304: Cannot find name 'ns'. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2304: Cannot find name 'ns'. + ns.b; + ~~ +!!! error TS2304: Cannot find name 'ns'. + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace2_umd.js b/tests/baselines/reference/exportAsNamespace2_umd.js new file mode 100644 index 0000000000000..e01ba1ae3771e --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.js @@ -0,0 +1,87 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace2_umd.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = __importStar(require("./0")); + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = __importStar(require("./1")); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace2_umd.symbols b/tests/baselines/reference/exportAsNamespace2_umd.symbols new file mode 100644 index 0000000000000..3c6b7529361ba --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.symbols @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +ns.b; + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace2_umd.types b/tests/baselines/reference/exportAsNamespace2_umd.types new file mode 100644 index 0000000000000..43e33efa82b30 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace2_umd.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof ns + +ns.a; +>ns.a : any +>ns : any +>a : any + +ns.b; +>ns.b : any +>ns : any +>b : any + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=amd).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=amd).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=amd).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=amd).js b/tests/baselines/reference/exportAsNamespace3(module=amd).js new file mode 100644 index 0000000000000..0935ee0c33b18 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=amd).js @@ -0,0 +1,62 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +define(["require", "exports", "./0"], function (require, exports, ns) { + "use strict"; + exports.__esModule = true; + exports.ns = ns; + ns.a; + ns.b; + var ns = { a: 1, b: 2 }; + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +define(["require", "exports", "./1"], function (require, exports, foo) { + "use strict"; + exports.__esModule = true; + foo = __importStar(foo); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=amd).symbols b/tests/baselines/reference/exportAsNamespace3(module=amd).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=amd).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=amd).types b/tests/baselines/reference/exportAsNamespace3(module=amd).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=amd).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=commonjs).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).js b/tests/baselines/reference/exportAsNamespace3(module=commonjs).js new file mode 100644 index 0000000000000..b05708a69df8d --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +"use strict"; +exports.__esModule = true; +exports.a = 1; +exports.b = 2; +//// [1.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +exports.ns = __importStar(require("./0")); +ns.a; +ns.b; +var ns = { a: 1, b: 2 }; +ns.a; +ns.b; +//// [2.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +exports.__esModule = true; +var foo = __importStar(require("./1")); +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols b/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=commonjs).types b/tests/baselines/reference/exportAsNamespace3(module=commonjs).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=commonjs).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=es2015).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).js b/tests/baselines/reference/exportAsNamespace3(module=es2015).js new file mode 100644 index 0000000000000..46dd633b42b53 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).js @@ -0,0 +1,44 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +import * as ns_1 from './0'; +export { ns_1 as ns }; +ns.a; +ns.b; +var ns = { a: 1, b: 2 }; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols b/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=es2015).types b/tests/baselines/reference/exportAsNamespace3(module=es2015).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=es2015).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=esnext).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).js b/tests/baselines/reference/exportAsNamespace3(module=esnext).js new file mode 100644 index 0000000000000..af04da95e0d7e --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).js @@ -0,0 +1,43 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +export var a = 1; +export var b = 2; +//// [1.js] +export * as ns from './0'; +ns.a; +ns.b; +var ns = { a: 1, b: 2 }; +ns.a; +ns.b; +//// [2.js] +import * as foo from './1'; +foo.ns.a; +foo.ns.b; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols b/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=esnext).types b/tests/baselines/reference/exportAsNamespace3(module=esnext).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=esnext).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=system).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).js b/tests/baselines/reference/exportAsNamespace3(module=system).js new file mode 100644 index 0000000000000..2d153f8e6d246 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).js @@ -0,0 +1,79 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var a, b; + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + exports_1("a", a = 1); + exports_1("b", b = 2); + } + }; +}); +//// [1.js] +System.register(["./0"], function (exports_1, context_1) { + "use strict"; + var ns; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (ns_1) { + exports_1("ns", ns_1); + } + ], + execute: function () { + ns.a; + ns.b; + ns = { a: 1, b: 2 }; + ns.a; + ns.b; + } + }; +}); +//// [2.js] +System.register(["./1"], function (exports_1, context_1) { + "use strict"; + var foo; + var __moduleName = context_1 && context_1.id; + return { + setters: [ + function (foo_1) { + foo = foo_1; + } + ], + execute: function () { + foo.ns.a; + foo.ns.b; + } + }; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).symbols b/tests/baselines/reference/exportAsNamespace3(module=system).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=system).types b/tests/baselines/reference/exportAsNamespace3(module=system).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=system).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).errors.txt b/tests/baselines/reference/exportAsNamespace3(module=umd).errors.txt new file mode 100644 index 0000000000000..eb0dcccdc79ed --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es2020/modules/1.ts(2,1): error TS2448: Block-scoped variable 'ns' used before its declaration. +tests/cases/conformance/es2020/modules/1.ts(3,1): error TS2448: Block-scoped variable 'ns' used before its declaration. + + +==== tests/cases/conformance/es2020/modules/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/es2020/modules/1.ts (2 errors) ==== + export * as ns from './0'; + ns.a; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + ns.b; + ~~ +!!! error TS2448: Block-scoped variable 'ns' used before its declaration. +!!! related TS2728 tests/cases/conformance/es2020/modules/1.ts:4:5: 'ns' is declared here. + let ns = {a: 1, b: 2} + ns.a; + ns.b; + +==== tests/cases/conformance/es2020/modules/2.ts (0 errors) ==== + import * as foo from './1' + + foo.ns.a; + foo.ns.b; \ No newline at end of file diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).js b/tests/baselines/reference/exportAsNamespace3(module=umd).js new file mode 100644 index 0000000000000..11eed84883f3f --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).js @@ -0,0 +1,93 @@ +//// [tests/cases/conformance/es2020/modules/exportAsNamespace3.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +//// [2.ts] +import * as foo from './1' + +foo.ns.a; +foo.ns.b; + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.a = 1; + exports.b = 2; +}); +//// [1.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./0"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + exports.ns = __importStar(require("./0")); + ns.a; + ns.b; + var ns = { a: 1, b: 2 }; + ns.a; + ns.b; +}); +//// [2.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports", "./1"], factory); + } +})(function (require, exports) { + "use strict"; + exports.__esModule = true; + var foo = __importStar(require("./1")); + foo.ns.a; + foo.ns.b; +}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export * as ns from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).symbols b/tests/baselines/reference/exportAsNamespace3(module=umd).symbols new file mode 100644 index 0000000000000..0414e93a36357 --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : Symbol(ns, Decl(1.ts, 0, 11)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +let ns = {a: 1, b: 2} +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +ns.a; +>ns.a : Symbol(a, Decl(1.ts, 3, 10)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>a : Symbol(a, Decl(1.ts, 3, 10)) + +ns.b; +>ns.b : Symbol(b, Decl(1.ts, 3, 15)) +>ns : Symbol(ns, Decl(1.ts, 3, 3)) +>b : Symbol(b, Decl(1.ts, 3, 15)) + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : Symbol(foo, Decl(2.ts, 0, 6)) + +foo.ns.a; +>foo.ns.a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>a : Symbol(foo.ns.a, Decl(0.ts, 0, 12)) + +foo.ns.b; +>foo.ns.b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) +>foo.ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>foo : Symbol(foo, Decl(2.ts, 0, 6)) +>ns : Symbol(foo.ns, Decl(1.ts, 0, 11)) +>b : Symbol(foo.ns.b, Decl(0.ts, 1, 12)) + diff --git a/tests/baselines/reference/exportAsNamespace3(module=umd).types b/tests/baselines/reference/exportAsNamespace3(module=umd).types new file mode 100644 index 0000000000000..b6a314299970c --- /dev/null +++ b/tests/baselines/reference/exportAsNamespace3(module=umd).types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/es2020/modules/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/es2020/modules/1.ts === +export * as ns from './0'; +>ns : typeof import("tests/cases/conformance/es2020/modules/0") + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +let ns = {a: 1, b: 2} +>ns : { a: number; b: number; } +>{a: 1, b: 2} : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + +ns.a; +>ns.a : number +>ns : { a: number; b: number; } +>a : number + +ns.b; +>ns.b : number +>ns : { a: number; b: number; } +>b : number + +=== tests/cases/conformance/es2020/modules/2.ts === +import * as foo from './1' +>foo : typeof foo + +foo.ns.a; +>foo.ns.a : 1 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>a : 1 + +foo.ns.b; +>foo.ns.b : 2 +>foo.ns : typeof foo.ns +>foo : typeof foo +>ns : typeof foo.ns +>b : 2 + diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts new file mode 100644 index 0000000000000..6e6b5959e9709 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace1.ts @@ -0,0 +1,16 @@ +// @module: esnext, es2015, commonjs, amd, system, umd +// @filename: 0.ts +// @declaration: true +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts new file mode 100644 index 0000000000000..f5ca1df13b278 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace2.ts @@ -0,0 +1,17 @@ +// @module: esnext, es2015, commonjs, amd, system, umd +// @filename: 0.ts +// @declaration: true +// @esModuleInterop: true +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file diff --git a/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts b/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts new file mode 100644 index 0000000000000..f652a0ca6c695 --- /dev/null +++ b/tests/cases/conformance/es2020/modules/exportAsNamespace3.ts @@ -0,0 +1,20 @@ +// @module: esnext, es2015, commonjs, amd, system, umd +// @filename: 0.ts +// @declaration: true +// @esModuleInterop: true +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export * as ns from './0'; +ns.a; +ns.b; +let ns = {a: 1, b: 2} +ns.a; +ns.b; + +// @filename: 2.ts +import * as foo from './1' + +foo.ns.a; +foo.ns.b; \ No newline at end of file