diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 62fc1a7cc418f..1ff692b088103 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2822,6 +2822,11 @@ namespace ts { isDeclarationVisible(declaration.parent.parent.parent)) { return addVisibleAlias(declaration, declaration.parent.parent); } + else if (isLateVisibilityPaintedStatement(declaration) // unexported top-level statement + && !hasModifier(declaration, ModifierFlags.Export) + && isDeclarationVisible(declaration.parent)) { + return addVisibleAlias(declaration, declaration); + } // Declaration is not visible return false; @@ -3679,7 +3684,17 @@ namespace ts { return typeParameterNodes; } - function symbolToTypeNode(symbol: Symbol, context: NodeBuilderContext, meaning: SymbolFlags): TypeQueryNode | TypeReferenceNode | ImportTypeNode { + /** + * Given A[B][C][D], finds A[B] + */ + function getTopmostIndexedAccessType(top: IndexedAccessTypeNode): IndexedAccessTypeNode { + if (isIndexedAccessTypeNode(top.objectType)) { + return getTopmostIndexedAccessType(top.objectType); + } + return top; + } + + function symbolToTypeNode(symbol: Symbol, context: NodeBuilderContext, meaning: SymbolFlags): TypeNode { const chain = lookupSymbolChain(symbol, context, meaning); context.flags |= NodeBuilderFlags.InInitialEntityName; @@ -3689,15 +3704,26 @@ namespace ts { const isTypeOf = meaning === SymbolFlags.Value; if (ambientModuleSymbolRegex.test(rootName)) { // module is root, must use `ImportTypeNode` - const nonRootParts = chain.length > 1 ? createEntityNameFromSymbolChain(chain, chain.length - 1, 1) : undefined; + const nonRootParts = chain.length > 1 ? createAccessFromSymbolChain(chain, chain.length - 1, 1) : undefined; const typeParameterNodes = lookupTypeParameterNodes(chain, 0, context); - return createImportTypeNode(createLiteralTypeNode(createLiteral(rootName.substring(1, rootName.length - 1))), nonRootParts, typeParameterNodes as ReadonlyArray, isTypeOf); + const lit = createLiteralTypeNode(createLiteral(rootName.substring(1, rootName.length - 1))); + if (!nonRootParts || isEntityName(nonRootParts)) { + return createImportTypeNode(lit, nonRootParts as EntityName, typeParameterNodes as ReadonlyArray, isTypeOf); + } + else { + const splitNode = getTopmostIndexedAccessType(nonRootParts); + const qualifier = (splitNode.objectType as TypeReferenceNode).typeName; + return createIndexedAccessTypeNode(createImportTypeNode(lit, qualifier, typeParameterNodes as ReadonlyArray, isTypeOf), splitNode.indexType); + } } - const entityName = createEntityNameFromSymbolChain(chain, chain.length - 1, 0); + const entityName = createAccessFromSymbolChain(chain, chain.length - 1, 0); + if (isIndexedAccessTypeNode(entityName)) { + return entityName; // Indexed accesses can never be `typeof` + } return isTypeOf ? createTypeQueryNode(entityName) : createTypeReferenceNode(entityName, /*typeArguments*/ undefined); - function createEntityNameFromSymbolChain(chain: Symbol[], index: number, stopper: number): EntityName { + function createAccessFromSymbolChain(chain: Symbol[], index: number, stopper: number): EntityName | IndexedAccessTypeNode { const typeParameterNodes = lookupTypeParameterNodes(chain, index, context); const symbol = chain[index]; @@ -3708,10 +3734,30 @@ namespace ts { if (index === 0) { context.flags ^= NodeBuilderFlags.InInitialEntityName; } + + const parent = chain[index - 1]; + if (parent && getMembersOfSymbol(parent) && getMembersOfSymbol(parent).get(symbol.escapedName) === symbol) { + // Should use an indexed access + const LHS = createAccessFromSymbolChain(chain, index - 1, stopper); + if (isIndexedAccessTypeNode(LHS)) { + return createIndexedAccessTypeNode(LHS, createLiteralTypeNode(createLiteral(symbolName))); + } + else { + return createIndexedAccessTypeNode(createTypeReferenceNode(LHS, typeParameterNodes as ReadonlyArray), createLiteralTypeNode(createLiteral(symbolName))); + } + } + const identifier = setEmitFlags(createIdentifier(symbolName, typeParameterNodes), EmitFlags.NoAsciiEscaping); identifier.symbol = symbol; - return index > stopper ? createQualifiedName(createEntityNameFromSymbolChain(chain, index - 1, stopper), identifier) : identifier; + if (index > stopper) { + const LHS = createAccessFromSymbolChain(chain, index - 1, stopper); + if (!isEntityName(LHS)) { + return Debug.fail("Impossible construct - an export of an indexed access cannot be reachable"); + } + return createQualifiedName(LHS, identifier); + } + return identifier; } } @@ -26566,7 +26612,22 @@ namespace ts { const symbol = node && getSymbolOfNode(node); return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late); }, - getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity + getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity, + getAllAccessorDeclarations(accessor: AccessorDeclaration): AllAccessorDeclarations { + accessor = getParseTreeNode(accessor, isGetOrSetAccessorDeclaration); + const otherKind = accessor.kind === SyntaxKind.SetAccessor ? SyntaxKind.GetAccessor : SyntaxKind.SetAccessor; + const otherAccessor = getDeclarationOfKind(getSymbolOfNode(accessor), otherKind); + const firstAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? otherAccessor : accessor; + const secondAccessor = otherAccessor && (otherAccessor.pos < accessor.pos) ? accessor : otherAccessor; + const setAccessor = accessor.kind === SyntaxKind.SetAccessor ? accessor : otherAccessor; + const getAccessor = accessor.kind === SyntaxKind.GetAccessor ? accessor : otherAccessor; + return { + firstAccessor, + secondAccessor, + setAccessor, + getAccessor + }; + } }; function isInHeritageClause(node: PropertyAccessEntityNameExpression) { diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 67e4fa31cb249..5e37bc56eaa48 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -28,7 +28,7 @@ namespace ts { let enclosingDeclaration: Node; let necessaryTypeRefernces: Map; let lateMarkedStatements: LateVisibilityPaintedStatement[]; - let lateStatementReplacementMap: Map; + let lateStatementReplacementMap: Map>; let suppressNewDiagnosticContexts: boolean; const symbolTracker: SymbolTracker = { @@ -155,13 +155,13 @@ namespace ts { [], [createModifier(SyntaxKind.DeclareKeyword)], createLiteral(getResolvedExternalModuleName(context.getEmitHost(), sourceFile)), - createModuleBlock(setTextRange(createNodeArray(filterCandidateImports(statements)), sourceFile.statements)) + createModuleBlock(setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), sourceFile.statements)) )], /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false); return newFile; } needsDeclare = true; const updated = visitNodes(sourceFile.statements, visitDeclarationStatements); - return updateSourceFileNode(sourceFile, filterCandidateImports(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false); + return updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false); } )); bundle.syntheticFileReferences = []; @@ -192,7 +192,7 @@ namespace ts { const referenceVisitor = mapReferencesIntoArray(references, outputFilePath); refs.forEach(referenceVisitor); const statements = visitNodes(node.statements, visitDeclarationStatements); - let combinedStatements = setTextRange(createNodeArray(filterCandidateImports(statements)), node.statements); + let combinedStatements = setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements); const emittedImports = filter(combinedStatements, isAnyImportSyntax); if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) { combinedStatements = setTextRange(createNodeArray([...combinedStatements, createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createNamedExports([]), /*moduleSpecifier*/ undefined)]), combinedStatements); @@ -254,7 +254,7 @@ namespace ts { forEach(sourceFile.referencedFiles, f => { const elem = tryResolveScriptReference(host, sourceFile, f); if (elem) { - ret.set("" + getNodeId(elem), elem); + ret.set("" + getOriginalNodeId(elem), elem); } }); return ret; @@ -534,7 +534,7 @@ namespace ts { // Nothing visible } - function filterCandidateImports(statements: NodeArray): NodeArray { + function transformAndReplaceLatePaintedStatements(statements: NodeArray): NodeArray { // This is a `while` loop because `handleSymbolAccessibilityError` can see additional import aliases marked as visible during // error handling which must now be included in the output and themselves checked for errors. // For example: @@ -549,65 +549,50 @@ namespace ts { // In such a scenario, only Q and D are initially visible, but we don't consider imports as private names - instead we say they if they are referenced they must // be recorded. So while checking D's visibility we mark C as visible, then we must check C which in turn marks B, completing the chain of // dependent imports and allowing a valid declaration file output. Today, this dependent alias marking only happens for internal import aliases. - const unconsideredStatements: LateVisibilityPaintedStatement[] = []; while (length(lateMarkedStatements)) { const i = lateMarkedStatements.shift(); - if ((isSourceFile(i.parent) ? i.parent : i.parent.parent) !== enclosingDeclaration) { // Filter to only declarations in the current scope - unconsideredStatements.push(i); - continue; - } if (!isLateVisibilityPaintedStatement(i)) { - return Debug.fail(`Late replaced statement was foudn which is not handled by the declaration transformer!: ${(ts as any).SyntaxKind ? (ts as any).SyntaxKind[(i as any).kind] : (i as any).kind}`); - } - switch (i.kind) { - case SyntaxKind.ImportEqualsDeclaration: { - const result = transformImportEqualsDeclaration(i); - lateStatementReplacementMap.set("" + getNodeId(i), result); - break; - } - case SyntaxKind.ImportDeclaration: { - const result = transformImportDeclaration(i); - lateStatementReplacementMap.set("" + getNodeId(i), result); - break; - } - case SyntaxKind.VariableStatement: { - const result = transformVariableStatement(i, /*privateDeclaration*/ true); // Transform the statement (potentially again, possibly revealing more sub-nodes) - lateStatementReplacementMap.set("" + getNodeId(i), result); - break; - } - default: Debug.assertNever(i, "Unhandled late painted statement!"); + return Debug.fail(`Late replaced statement was found which is not handled by the declaration transformer!: ${(ts as any).SyntaxKind ? (ts as any).SyntaxKind[(i as any).kind] : (i as any).kind}`); } + const result = transformTopLevelDeclaration(i, /*privateDeclaration*/ true); + lateStatementReplacementMap.set("" + getOriginalNodeId(i), result); } - // Filtering available imports is the last thing done within a scope, so the possible set becomes those which could not - // be considered in the child scope - lateMarkedStatements = unconsideredStatements; // And lastly, we need to get the final form of all those indetermine import declarations from before and add them to the output list // (and remove them from the set to examine for outter declarations) return visitNodes(statements, visitLateVisibilityMarkedStatements); - } - function visitLateVisibilityMarkedStatements(statement: Statement) { - if (isLateVisibilityPaintedStatement(statement)) { - const key = "" + getNodeId(statement); - if (lateStatementReplacementMap.has(key)) { - const result = lateStatementReplacementMap.get(key); - lateStatementReplacementMap.delete(key); - if (result && isSourceFile(statement.parent) && !isAnyImportOrReExport(result) && !isExportAssignment(result) && !hasModifier(result, ModifierFlags.Export)) { - // Top-level declarations in .d.ts files are always considered exported even without a modifier unless there's an export assignment or specifier - needsScopeFixMarker = true; + function visitLateVisibilityMarkedStatements(statement: Statement) { + if (isLateVisibilityPaintedStatement(statement)) { + const key = "" + getOriginalNodeId(statement); + if (lateStatementReplacementMap.has(key)) { + const result = lateStatementReplacementMap.get(key); + lateStatementReplacementMap.delete(key); + if (result && isSourceFile(statement.parent)) { + if (isArray(result) ? some(result, needsScopeMarker) : needsScopeMarker(result)) { + // Top-level declarations in .d.ts files are always considered exported even without a modifier unless there's an export assignment or specifier + needsScopeFixMarker = true; + } + if (isArray(result) ? some(result, isExternalModuleIndicator) : isExternalModuleIndicator(result)) { + resultHasExternalModuleIndicator = true; + } + } + return result; } - return result; } - else { - return getParseTreeNode(statement) ? undefined : statement; - } - } - else { return statement; } } + function isExternalModuleIndicator(result: LateVisibilityPaintedStatement) { + // Exported top-level member indicates moduleness + return isAnyImportOrReExport(result) || isExportAssignment(result) || hasModifier(result, ModifierFlags.Export); + } + + function needsScopeMarker(result: LateVisibilityPaintedStatement) { + return !isAnyImportOrReExport(result) && !isExportAssignment(result) && !hasModifier(result, ModifierFlags.Export) && !isAmbientModule(result); + } + function visitDeclarationSubtree(input: Node): VisitResult { if (shouldStripInternal(input)) return; if (isDeclaration(input)) { @@ -862,13 +847,22 @@ namespace ts { return [statement, updateExportAssignment(input, input.decorators, input.modifiers, newId)]; } } - case SyntaxKind.ImportEqualsDeclaration: + } + + const result = transformTopLevelDeclaration(input); + // Don't actually transform yet; just leave as original node - will be elided/swapped by late pass + lateStatementReplacementMap.set("" + getOriginalNodeId(input), result); + return input; + } + + function transformTopLevelDeclaration(input: LateVisibilityPaintedStatement, isPrivate?: boolean) { + if (shouldStripInternal(input)) return; + switch (input.kind) { + case SyntaxKind.ImportEqualsDeclaration: { + return transformImportEqualsDeclaration(input); + } case SyntaxKind.ImportDeclaration: { - // Different parts of the import may be marked visible at different times (via visibility checking), so we defer our first look until later - // to reduce the likelihood we need to rewrite it - lateMarkedStatements = lateMarkedStatements || []; - pushIfUnique(lateMarkedStatements, input); - return input; + return transformImportDeclaration(input); } } if (isDeclaration(input) && isDeclarationAndNotVisible(input)) return; @@ -881,21 +875,20 @@ namespace ts { previousEnclosingDeclaration = enclosingDeclaration; enclosingDeclaration = input as Declaration; } - let previousNeedsDeclare: typeof needsDeclare; const canProdiceDiagnostic = canProduceDiagnostics(input); const oldDiag = getSymbolAccessibilityDiagnostic; if (canProdiceDiagnostic) { getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(input as DeclarationDiagnosticProducing); } - let oldPossibleImports: typeof lateMarkedStatements; + const previousNeedsDeclare = needsDeclare; switch (input.kind) { case SyntaxKind.TypeAliasDeclaration: // Type aliases get `declare`d if need be (for legacy support), but that's all return cleanup(updateTypeAliasDeclaration( input, /*decorators*/ undefined, - ensureModifiers(input), + ensureModifiers(input, isPrivate), input.name, visitNodes(input.typeParameters, visitDeclarationSubtree, isTypeParameterDeclaration), visitNode(input.type, visitDeclarationSubtree, isTypeNode) @@ -904,7 +897,7 @@ namespace ts { return cleanup(updateInterfaceDeclaration( input, /*decorators*/ undefined, - ensureModifiers(input), + ensureModifiers(input, isPrivate), input.name, ensureTypeParams(input, input.typeParameters), transformHeritageClauses(input.heritageClauses), @@ -916,7 +909,7 @@ namespace ts { return cleanup(updateFunctionDeclaration( input, /*decorators*/ undefined, - ensureModifiers(input), + ensureModifiers(input, isPrivate), /*asteriskToken*/ undefined, input.name, ensureTypeParams(input, input.typeParameters), @@ -926,16 +919,13 @@ namespace ts { )); } case SyntaxKind.ModuleDeclaration: { - previousNeedsDeclare = needsDeclare; needsDeclare = false; - oldPossibleImports = lateMarkedStatements; - lateMarkedStatements = undefined; const inner = input.body; if (inner && inner.kind === SyntaxKind.ModuleBlock) { const statements = visitNodes(inner.statements, visitDeclarationStatements); - const body = updateModuleBlock(inner, filterCandidateImports(statements)); + const body = updateModuleBlock(inner, transformAndReplaceLatePaintedStatements(statements)); needsDeclare = previousNeedsDeclare; - const mods = ensureModifiers(input); + const mods = ensureModifiers(input, isPrivate); return cleanup(updateModuleDeclaration( input, /*decorators*/ undefined, @@ -946,19 +936,24 @@ namespace ts { } else { needsDeclare = previousNeedsDeclare; - const mods = ensureModifiers(input); + const mods = ensureModifiers(input, isPrivate); needsDeclare = false; + visitNode(inner, visitDeclarationStatements); + // eagerly transform nested namespaces (the nesting doesn't need any elision or painting done) + const id = "" + getOriginalNodeId(inner); + const body = lateStatementReplacementMap.get(id); + lateStatementReplacementMap.delete(id); return cleanup(updateModuleDeclaration( input, /*decorators*/ undefined, mods, input.name, - visitNode(inner, visitDeclarationStatements) + body as ModuleBody )); } } case SyntaxKind.ClassDeclaration: { - const modifiers = createNodeArray(ensureModifiers(input)); + const modifiers = createNodeArray(ensureModifiers(input, isPrivate)); const typeParameters = ensureTypeParams(input, input.typeParameters); const ctor = getFirstConstructorWithBody(input); let parameterProperties: PropertyDeclaration[]; @@ -1051,12 +1046,10 @@ namespace ts { } } case SyntaxKind.VariableStatement: { - const result = transformVariableStatement(input); - lateStatementReplacementMap.set("" + getNodeId(input), result); // Don't actually elide yet; just leave as original node - will be elided/swapped by late pass - return cleanup(input); + return cleanup(transformVariableStatement(input, isPrivate)); } case SyntaxKind.EnumDeclaration: { - return cleanup(updateEnumDeclaration(input, /*decorators*/ undefined, createNodeArray(ensureModifiers(input)), input.name, createNodeArray(mapDefined(input.members, m => { + return cleanup(updateEnumDeclaration(input, /*decorators*/ undefined, createNodeArray(ensureModifiers(input, isPrivate)), input.name, createNodeArray(mapDefined(input.members, m => { if (shouldStripInternal(m)) return; // Rewrite enum values to their constants, if available const constValue = resolver.getConstantValue(m); @@ -1064,31 +1057,23 @@ namespace ts { })))); } } - // Anything left unhandled is an error, so this should be unreachable return Debug.assertNever(input, `Unhandled top-level node in declaration emit: ${(ts as any).SyntaxKind[(input as any).kind]}`); - function cleanup(returnValue: T | undefined): T { + function cleanup(node: T | undefined): T { if (isEnclosingDeclaration(input)) { enclosingDeclaration = previousEnclosingDeclaration; } - if (input.kind === SyntaxKind.ModuleDeclaration) { - needsDeclare = previousNeedsDeclare; - lateMarkedStatements = concatenate(oldPossibleImports, lateMarkedStatements); - } if (canProdiceDiagnostic) { getSymbolAccessibilityDiagnostic = oldDiag; } - if (returnValue && (!isLateVisibilityPaintedStatement(input) || lateStatementReplacementMap.get("" + getNodeId(input)))) { - if (!resultHasExternalModuleIndicator && hasModifier(input, ModifierFlags.Export) && isSourceFile(input.parent)) { - // Exported top-level member indicates moduleness - resultHasExternalModuleIndicator = true; - } + if (input.kind === SyntaxKind.ModuleDeclaration) { + needsDeclare = previousNeedsDeclare; } - if (returnValue === input) { - return returnValue; + if (node as Node === input) { + return node; } - return returnValue && setOriginalNode(preserveJsDoc(returnValue, input), input); + return node && setOriginalNode(preserveJsDoc(node, input), input); } } @@ -1171,7 +1156,7 @@ namespace ts { } function ensureAccessor(node: AccessorDeclaration): PropertyDeclaration | undefined { - const accessors = getAllAccessorDeclarations((node.parent as ClassDeclaration).members, node); + const accessors = resolver.getAllAccessorDeclarations(node); if (node.kind !== accessors.firstAccessor.kind) { return; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d59ea7dfbfd3b..064773e4b7126 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3220,7 +3220,15 @@ namespace ts { export type RequireOrImportCall = CallExpression & { arguments: [StringLiteralLike] }; /* @internal */ - export type LateVisibilityPaintedStatement = AnyImportSyntax | VariableStatement; + export type LateVisibilityPaintedStatement = + | AnyImportSyntax + | VariableStatement + | ClassDeclaration + | FunctionDeclaration + | ModuleDeclaration + | TypeAliasDeclaration + | InterfaceDeclaration + | EnumDeclaration; /* @internal */ export interface SymbolVisibilityResult { @@ -3235,6 +3243,14 @@ namespace ts { errorModuleName?: string; // If the symbol is not visible from module, module's name } + /* @internal */ + export interface AllAccessorDeclarations { + firstAccessor: AccessorDeclaration; + secondAccessor: AccessorDeclaration; + getAccessor: AccessorDeclaration; + setAccessor: AccessorDeclaration; + } + /** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator metadata */ /* @internal */ export enum TypeReferenceSerializationKind { @@ -3291,6 +3307,7 @@ namespace ts { getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[]; isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean; getJsxFactoryEntity(location?: Node): EntityName; + getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; } export const enum SymbolFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ae6bfb5ac135e..fc30081346fde 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -549,6 +549,12 @@ namespace ts { case SyntaxKind.ImportDeclaration: case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.VariableStatement: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.EnumDeclaration: return true; default: return false; @@ -2983,13 +2989,6 @@ namespace ts { return id.originalKeywordKind === SyntaxKind.ThisKeyword; } - export interface AllAccessorDeclarations { - firstAccessor: AccessorDeclaration; - secondAccessor: AccessorDeclaration; - getAccessor: AccessorDeclaration; - setAccessor: AccessorDeclaration; - } - export function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration): AllAccessorDeclarations { let firstAccessor: AccessorDeclaration; let secondAccessor: AccessorDeclaration; @@ -4865,6 +4864,11 @@ namespace ts { return node.kind === SyntaxKind.IndexSignature; } + /* @internal */ + export function isGetOrSetAccessorDeclaration(node: Node): node is AccessorDeclaration { + return node.kind === SyntaxKind.SetAccessor || node.kind === SyntaxKind.GetAccessor; + } + // Type export function isTypePredicateNode(node: Node): node is TypePredicateNode { diff --git a/tests/baselines/reference/DeclarationErrorsNoEmitOnError.errors.txt b/tests/baselines/reference/DeclarationErrorsNoEmitOnError.errors.txt deleted file mode 100644 index 0a8f03a504a52..0000000000000 --- a/tests/baselines/reference/DeclarationErrorsNoEmitOnError.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts(3,8): error TS4033: Property 'f' of exported interface has or is using private name 'T'. - - -==== tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts (1 errors) ==== - type T = { x : number } - export interface I { - f: T; - ~ -!!! error TS4033: Property 'f' of exported interface has or is using private name 'T'. - } \ No newline at end of file diff --git a/tests/baselines/reference/DeclarationErrorsNoEmitOnError.js b/tests/baselines/reference/DeclarationErrorsNoEmitOnError.js new file mode 100644 index 0000000000000..73c312a018b95 --- /dev/null +++ b/tests/baselines/reference/DeclarationErrorsNoEmitOnError.js @@ -0,0 +1,19 @@ +//// [DeclarationErrorsNoEmitOnError.ts] +type T = { x : number } +export interface I { + f: T; +} + +//// [DeclarationErrorsNoEmitOnError.js] +"use strict"; +exports.__esModule = true; + + +//// [DeclarationErrorsNoEmitOnError.d.ts] +declare type T = { + x: number; +}; +export interface I { + f: T; +} +export {}; diff --git a/tests/baselines/reference/DeclarationErrorsNoEmitOnError.types b/tests/baselines/reference/DeclarationErrorsNoEmitOnError.types index 08a65d9c146b8..d2598dfe7486a 100644 --- a/tests/baselines/reference/DeclarationErrorsNoEmitOnError.types +++ b/tests/baselines/reference/DeclarationErrorsNoEmitOnError.types @@ -1,12 +1,12 @@ === tests/cases/compiler/DeclarationErrorsNoEmitOnError.ts === type T = { x : number } ->T : { x: number; } +>T : T >x : number export interface I { >I : I f: T; ->f : { x: number; } ->T : { x: number; } +>f : T +>T : T } diff --git a/tests/baselines/reference/aliasInaccessibleModule.errors.txt b/tests/baselines/reference/aliasInaccessibleModule.errors.txt deleted file mode 100644 index 3a9c64e50ab46..0000000000000 --- a/tests/baselines/reference/aliasInaccessibleModule.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/aliasInaccessibleModule.ts(4,23): error TS4000: Import declaration 'X' is using private name 'N'. - - -==== tests/cases/compiler/aliasInaccessibleModule.ts (1 errors) ==== - module M { - module N { - } - export import X = N; - ~ -!!! error TS4000: Import declaration 'X' is using private name 'N'. - } \ No newline at end of file diff --git a/tests/baselines/reference/aliasInaccessibleModule.js b/tests/baselines/reference/aliasInaccessibleModule.js index a0ecf3361fc1f..66a59a9f0ee80 100644 --- a/tests/baselines/reference/aliasInaccessibleModule.js +++ b/tests/baselines/reference/aliasInaccessibleModule.js @@ -9,3 +9,11 @@ module M { var M; (function (M) { })(M || (M = {})); + + +//// [aliasInaccessibleModule.d.ts] +declare module M { + module N { + } + export import X = N; +} diff --git a/tests/baselines/reference/aliasInaccessibleModule2.errors.txt b/tests/baselines/reference/aliasInaccessibleModule2.errors.txt deleted file mode 100644 index 03a37147aba10..0000000000000 --- a/tests/baselines/reference/aliasInaccessibleModule2.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/aliasInaccessibleModule2.ts(7,16): error TS4000: Import declaration 'R' is using private name 'N'. - - -==== tests/cases/compiler/aliasInaccessibleModule2.ts (1 errors) ==== - module M { - module N { - class C { - } - - } - import R = N; - ~ -!!! error TS4000: Import declaration 'R' is using private name 'N'. - export import X = R; - } \ No newline at end of file diff --git a/tests/baselines/reference/aliasInaccessibleModule2.js b/tests/baselines/reference/aliasInaccessibleModule2.js index be208c07ca275..324581ce62295 100644 --- a/tests/baselines/reference/aliasInaccessibleModule2.js +++ b/tests/baselines/reference/aliasInaccessibleModule2.js @@ -23,3 +23,12 @@ var M; var R = N; M.X = R; })(M || (M = {})); + + +//// [aliasInaccessibleModule2.d.ts] +declare module M { + module N { + } + import R = N; + export import X = R; +} diff --git a/tests/baselines/reference/allowJscheckJsTypeParameterNoCrash.types b/tests/baselines/reference/allowJscheckJsTypeParameterNoCrash.types index 396cdd4445eeb..e1b331019bf1e 100644 --- a/tests/baselines/reference/allowJscheckJsTypeParameterNoCrash.types +++ b/tests/baselines/reference/allowJscheckJsTypeParameterNoCrash.types @@ -4,12 +4,12 @@ interface ComponentOptions { >V : V watch: Record>; ->watch : Record void> +>watch : Record> >Record : Record ->WatchHandler : (val: T) => void +>WatchHandler : WatchHandler } type WatchHandler = (val: T) => void; ->WatchHandler : (val: T) => void +>WatchHandler : WatchHandler >T : T >val : T >T : T diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.types b/tests/baselines/reference/controlFlowBinaryOrExpression.types index e843844ebf1e4..2cdf6b6bc19fb 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.types +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.types @@ -62,21 +62,21 @@ declare function isHTMLCollection(sourceObj: any): sourceObj is HTMLCollection; >HTMLCollection : HTMLCollection type EventTargetLike = {a: string} | HTMLCollection | NodeList; ->EventTargetLike : NodeList | HTMLCollection | { a: string; } +>EventTargetLike : EventTargetLike >a : string >HTMLCollection : HTMLCollection >NodeList : NodeList var sourceObj: EventTargetLike = undefined; ->sourceObj : NodeList | HTMLCollection | { a: string; } ->EventTargetLike : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike +>EventTargetLike : EventTargetLike >undefined : any >undefined : undefined if (isNodeList(sourceObj)) { >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike sourceObj.length; >sourceObj.length : number @@ -87,7 +87,7 @@ if (isNodeList(sourceObj)) { if (isHTMLCollection(sourceObj)) { >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection ->sourceObj : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike sourceObj.length; >sourceObj.length : number @@ -99,7 +99,7 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { >isNodeList(sourceObj) || isHTMLCollection(sourceObj) : boolean >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection >sourceObj : { a: string; } diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.errors.txt b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.errors.txt deleted file mode 100644 index 4ea18c1590100..0000000000000 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.errors.txt +++ /dev/null @@ -1,132 +0,0 @@ -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(15,21): error TS4043: Return type of public getter 'foo1' from exported class has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(20,13): error TS4043: Return type of public getter 'foo2' from exported class has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(25,25): error TS4037: Parameter type of public setter 'foo3' from exported class has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(32,25): error TS4037: Parameter type of public setter 'foo4' from exported class has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(36,21): error TS4043: Return type of public getter 'foo5' from exported class has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(71,23): error TS4043: Return type of public getter 'foo111' from exported class has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(76,13): error TS4042: Return type of public getter 'foo112' from exported class has or is using name 'm2.public2' from private module 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(81,27): error TS4037: Parameter type of public setter 'foo113' from exported class has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(88,27): error TS4037: Parameter type of public setter 'foo114' from exported class has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts(92,23): error TS4043: Return type of public getter 'foo115' from exported class has or is using private name 'm2'. - - -==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorAccessors.ts (10 errors) ==== - module m { - class private1 { - } - - export class public1 { - } - - module m2 { - export class public2 { - } - } - - export class c { - // getter with annotation - get foo1(): private1 { - ~~~~~~~~ -!!! error TS4043: Return type of public getter 'foo1' from exported class has or is using private name 'private1'. - return; - } - - // getter without annotation - get foo2() { - ~~~~ -!!! error TS4043: Return type of public getter 'foo2' from exported class has or is using private name 'private1'. - return new private1(); - } - - // setter with annotation - set foo3(param: private1) { - ~~~~~~~~ -!!! error TS4037: Parameter type of public setter 'foo3' from exported class has or is using private name 'private1'. - } - - // Both - getter without annotation, setter with annotation - get foo4() { - return new private1(); - } - set foo4(param: private1) { - ~~~~~~~~ -!!! error TS4037: Parameter type of public setter 'foo4' from exported class has or is using private name 'private1'. - } - - // Both - with annotation - get foo5(): private1 { - ~~~~~~~~ -!!! error TS4043: Return type of public getter 'foo5' from exported class has or is using private name 'private1'. - return; - } - set foo5(param: private1) { - } - - // getter with annotation - get foo11(): public1 { - return; - } - - // getter without annotation - get foo12() { - return new public1(); - } - - // setter with annotation - set foo13(param: public1) { - } - - // Both - getter without annotation, setter with annotation - get foo14() { - return new public1(); - } - set foo14(param: public1) { - } - - // Both - with annotation - get foo15(): public1 { - return; - } - set foo15(param: public1) { - } - - // getter with annotation - get foo111(): m2.public2 { - ~~ -!!! error TS4043: Return type of public getter 'foo111' from exported class has or is using private name 'm2'. - return; - } - - // getter without annotation - get foo112() { - ~~~~~~ -!!! error TS4042: Return type of public getter 'foo112' from exported class has or is using name 'm2.public2' from private module 'm2'. - return new m2.public2(); - } - - // setter with annotation - set foo113(param: m2.public2) { - ~~ -!!! error TS4037: Parameter type of public setter 'foo113' from exported class has or is using private name 'm2'. - } - - // Both - getter without annotation, setter with annotation - get foo114() { - return new m2.public2(); - } - set foo114(param: m2.public2) { - ~~ -!!! error TS4037: Parameter type of public setter 'foo114' from exported class has or is using private name 'm2'. - } - - // Both - with annotation - get foo115(): m2.public2 { - ~~ -!!! error TS4043: Return type of public getter 'foo115' from exported class has or is using private name 'm2'. - return; - } - set foo115(param: m2.public2) { - } - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js index c02807207ca63..20d784489d99a 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorAccessors.js @@ -258,3 +258,33 @@ var m; }()); m.c = c; })(m || (m = {})); + + +//// [declFileTypeAnnotationVisibilityErrorAccessors.d.ts] +declare module m { + class private1 { + } + class public1 { + } + module m2 { + class public2 { + } + } + class c { + readonly foo1: private1; + readonly foo2: private1; + foo3: private1; + foo4: private1; + foo5: private1; + readonly foo11: public1; + readonly foo12: public1; + foo13: public1; + foo14: public1; + foo15: public1; + readonly foo111: m2.public2; + readonly foo112: m2.public2; + foo113: m2.public2; + foo114: m2.public2; + foo115: m2.public2; + } +} diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorParameterOfFunction.errors.txt b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorParameterOfFunction.errors.txt deleted file mode 100644 index 339ae67eea4c1..0000000000000 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorParameterOfFunction.errors.txt +++ /dev/null @@ -1,59 +0,0 @@ -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(14,34): error TS4078: Parameter 'param' of exported function has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(16,26): error TS4078: Parameter 'param' of exported function has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(39,35): error TS4078: Parameter 'param' of exported function has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts(41,28): error TS4077: Parameter 'param' of exported function has or is using name 'm2.public2' from private module 'm2'. - - -==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorParameterOfFunction.ts (4 errors) ==== - module m { - class private1 { - } - - export class public1 { - } - - // Directly using names from this module - function foo1(param: private1) { - } - function foo2(param = new private1()) { - } - - export function foo3(param : private1) { - ~~~~~~~~ -!!! error TS4078: Parameter 'param' of exported function has or is using private name 'private1'. - } - export function foo4(param = new private1()) { - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4078: Parameter 'param' of exported function has or is using private name 'private1'. - } - - function foo11(param: public1) { - } - function foo12(param = new public1()) { - } - - export function foo13(param: public1) { - } - export function foo14(param = new public1()) { - } - - module m2 { - export class public2 { - } - } - - function foo111(param: m2.public2) { - } - function foo112(param = new m2.public2()) { - } - - export function foo113(param: m2.public2) { - ~~ -!!! error TS4078: Parameter 'param' of exported function has or is using private name 'm2'. - } - export function foo114(param = new m2.public2()) { - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4077: Parameter 'param' of exported function has or is using name 'm2.public2' from private module 'm2'. - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorParameterOfFunction.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorParameterOfFunction.js index 1c4a27cee6142..4e1edd7fe396e 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorParameterOfFunction.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorParameterOfFunction.js @@ -105,3 +105,22 @@ var m; } m.foo114 = foo114; })(m || (m = {})); + + +//// [declFileTypeAnnotationVisibilityErrorParameterOfFunction.d.ts] +declare module m { + class private1 { + } + class public1 { + } + function foo3(param: private1): void; + function foo4(param?: private1): void; + function foo13(param: public1): void; + function foo14(param?: public1): void; + module m2 { + class public2 { + } + } + function foo113(param: m2.public2): void; + function foo114(param?: m2.public2): void; +} diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.errors.txt b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.errors.txt deleted file mode 100644 index 492e6615efa15..0000000000000 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.errors.txt +++ /dev/null @@ -1,71 +0,0 @@ -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(16,29): error TS4060: Return type of exported function has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(19,21): error TS4060: Return type of exported function has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(49,31): error TS4060: Return type of exported function has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts(52,21): error TS4059: Return type of exported function has or is using name 'm2.public2' from private module 'm2'. - - -==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.ts (4 errors) ==== - module m { - class private1 { - } - - export class public1 { - } - - // Directly using names from this module - function foo1(): private1 { - return; - } - function foo2() { - return new private1(); - } - - export function foo3(): private1 { - ~~~~~~~~ -!!! error TS4060: Return type of exported function has or is using private name 'private1'. - return; - } - export function foo4() { - ~~~~ -!!! error TS4060: Return type of exported function has or is using private name 'private1'. - return new private1(); - } - - function foo11(): public1 { - return; - } - function foo12() { - return new public1(); - } - - export function foo13(): public1 { - return; - } - export function foo14() { - return new public1(); - } - - module m2 { - export class public2 { - } - } - - function foo111(): m2.public2 { - return; - } - function foo112() { - return new m2.public2(); - } - - export function foo113(): m2.public2 { - ~~ -!!! error TS4060: Return type of exported function has or is using private name 'm2'. - return; - } - export function foo114() { - ~~~~~~ -!!! error TS4059: Return type of exported function has or is using name 'm2.public2' from private module 'm2'. - return new m2.public2(); - } - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.js index a0e43b6521dcd..8a2437a2ac41b 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.js @@ -123,3 +123,22 @@ var m; } m.foo114 = foo114; })(m || (m = {})); + + +//// [declFileTypeAnnotationVisibilityErrorReturnTypeOfFunction.d.ts] +declare module m { + class private1 { + } + class public1 { + } + function foo3(): private1; + function foo4(): private1; + function foo13(): public1; + function foo14(): public1; + module m2 { + class public2 { + } + } + function foo113(): m2.public2; + function foo114(): m2.public2; +} diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.errors.txt b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.errors.txt deleted file mode 100644 index 919fd5cd6571d..0000000000000 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.errors.txt +++ /dev/null @@ -1,55 +0,0 @@ -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(9,23): error TS4025: Exported variable 'p' has or is using private name 'W'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(32,22): error TS4081: Exported type alias 't2' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(35,23): error TS4081: Exported type alias 't12' has or is using private name 'public1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts(38,24): error TS4081: Exported type alias 't112' has or is using private name 'm3'. - - -==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeAlias.ts (4 errors) ==== - interface Window { - someMethod(); - } - - module M { - type W = Window | string; - export module N { - export class Window { } - export var p: W; // Should report error that W is private - ~ -!!! error TS4025: Exported variable 'p' has or is using private name 'W'. - } - } - - module M1 { - export type W = Window | string; - export module N { - export class Window { } - export var p: W; // No error - } - } - - module M2 { - class private1 { - } - class public1 { - } - module m3 { - export class public1 { - } - } - - type t1 = private1; - export type t2 = private1; // error - ~~~~~~~~ -!!! error TS4081: Exported type alias 't2' has or is using private name 'private1'. - - type t11 = public1; - export type t12 = public1; - ~~~~~~~ -!!! error TS4081: Exported type alias 't12' has or is using private name 'public1'. - - type t111 = m3.public1; - export type t112 = m3.public1; // error - ~~ -!!! error TS4081: Exported type alias 't112' has or is using private name 'm3'. - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js index 2d1e3d1880eac..fd39a6e20d968 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js @@ -87,3 +87,38 @@ var M2; m3.public1 = public1; })(m3 || (m3 = {})); })(M2 || (M2 = {})); + + +//// [declFileTypeAnnotationVisibilityErrorTypeAlias.d.ts] +interface Window { + someMethod(): any; +} +declare module M { + type W = Window | string; + module N { + class Window { + } + var p: W; + } +} +declare module M1 { + type W = Window | string; + module N { + class Window { + } + var p: W; + } +} +declare module M2 { + class private1 { + } + class public1 { + } + module m3 { + class public1 { + } + } + type t2 = private1; + type t12 = public1; + type t112 = m3.public1; +} diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.types b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.types index 5d467f07df4df..24911343beaa6 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.types +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.types @@ -10,7 +10,7 @@ module M { >M : typeof M type W = Window | string; ->W : string | Window +>W : W >Window : Window export module N { @@ -20,8 +20,8 @@ module M { >Window : Window export var p: W; // Should report error that W is private ->p : string | Window ->W : string | Window +>p : W +>W : W } } diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.errors.txt b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.errors.txt deleted file mode 100644 index a8d8023e8304b..0000000000000 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.errors.txt +++ /dev/null @@ -1,90 +0,0 @@ -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(10,12): error TS4025: Exported variable 'x' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(11,12): error TS4025: Exported variable 'x' has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(12,13): error TS4025: Exported variable 'x' has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(13,19): error TS4025: Exported variable 'x' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(14,22): error TS4025: Exported variable 'x' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(15,22): error TS4025: Exported variable 'x' has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(17,16): error TS4024: Exported variable 'x2' has or is using name 'm2.public1' from private module 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(17,16): error TS4025: Exported variable 'x2' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(24,16): error TS4024: Exported variable 'x3' has or is using name 'm2.public1' from private module 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(24,16): error TS4025: Exported variable 'x3' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(27,23): error TS4025: Exported variable 'y' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(27,36): error TS4025: Exported variable 'y' has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(28,16): error TS4024: Exported variable 'y2' has or is using name 'm2.public1' from private module 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(28,16): error TS4025: Exported variable 'y2' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(31,27): error TS4025: Exported variable 'z' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(31,40): error TS4025: Exported variable 'z' has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(32,16): error TS4024: Exported variable 'z2' has or is using name 'm2.public1' from private module 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts(32,16): error TS4025: Exported variable 'z2' has or is using private name 'private1'. - - -==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorTypeLiteral.ts (18 errors) ==== - module m { - class private1 { - } - module m2 { - export class public1 { - } - } - - export var x: { - x: private1; - ~~~~~~~~ -!!! error TS4025: Exported variable 'x' has or is using private name 'private1'. - y: m2.public1; - ~~ -!!! error TS4025: Exported variable 'x' has or is using private name 'm2'. - (): m2.public1[]; - ~~ -!!! error TS4025: Exported variable 'x' has or is using private name 'm2'. - method(): private1; - ~~~~~~~~ -!!! error TS4025: Exported variable 'x' has or is using private name 'private1'. - [n: number]: private1; - ~~~~~~~~ -!!! error TS4025: Exported variable 'x' has or is using private name 'private1'. - [s: string]: m2.public1; - ~~ -!!! error TS4025: Exported variable 'x' has or is using private name 'm2'. - }; - export var x2 = { - ~~ -!!! error TS4024: Exported variable 'x2' has or is using name 'm2.public1' from private module 'm2'. - ~~ -!!! error TS4025: Exported variable 'x2' has or is using private name 'private1'. - x: new private1(), - y: new m2.public1(), - method() { - return new private1(); - } - }; - export var x3 = x; - ~~ -!!! error TS4024: Exported variable 'x3' has or is using name 'm2.public1' from private module 'm2'. - ~~ -!!! error TS4025: Exported variable 'x3' has or is using private name 'private1'. - - // Function type - export var y: (a: private1) => m2.public1; - ~~~~~~~~ -!!! error TS4025: Exported variable 'y' has or is using private name 'private1'. - ~~ -!!! error TS4025: Exported variable 'y' has or is using private name 'm2'. - export var y2 = y; - ~~ -!!! error TS4024: Exported variable 'y2' has or is using name 'm2.public1' from private module 'm2'. - ~~ -!!! error TS4025: Exported variable 'y2' has or is using private name 'private1'. - - // constructor type - export var z: new (a: private1) => m2.public1; - ~~~~~~~~ -!!! error TS4025: Exported variable 'z' has or is using private name 'private1'. - ~~ -!!! error TS4025: Exported variable 'z' has or is using private name 'm2'. - export var z2 = z; - ~~ -!!! error TS4024: Exported variable 'z2' has or is using name 'm2.public1' from private module 'm2'. - ~~ -!!! error TS4025: Exported variable 'z2' has or is using private name 'private1'. - } \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js index 687ab02fdb6ac..ecb3e035e2a39 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js @@ -61,3 +61,39 @@ var m; m.y2 = m.y; m.z2 = m.z; })(m || (m = {})); + + +//// [declFileTypeAnnotationVisibilityErrorTypeLiteral.d.ts] +declare module m { + class private1 { + } + module m2 { + class public1 { + } + } + var x: { + x: private1; + y: m2.public1; + (): m2.public1[]; + method(): private1; + [n: number]: private1; + [s: string]: m2.public1; + }; + var x2: { + x: private1; + y: m2.public1; + method(): private1; + }; + var x3: { + (): m2.public1[]; + [s: string]: m2.public1; + [n: number]: private1; + x: private1; + y: m2.public1; + method(): private1; + }; + var y: (a: private1) => m2.public1; + var y2: (a: private1) => m2.public1; + var z: new (a: private1) => m2.public1; + var z2: new (a: private1) => m2.public1; +} diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorVariableDeclaration.errors.txt b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorVariableDeclaration.errors.txt deleted file mode 100644 index 6a9e596183133..0000000000000 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorVariableDeclaration.errors.txt +++ /dev/null @@ -1,47 +0,0 @@ -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(12,19): error TS4025: Exported variable 'k' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(13,16): error TS4025: Exported variable 'l' has or is using private name 'private1'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(29,20): error TS4025: Exported variable 'k3' has or is using private name 'm2'. -tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts(30,16): error TS4024: Exported variable 'l3' has or is using name 'm2.public2' from private module 'm2'. - - -==== tests/cases/compiler/declFileTypeAnnotationVisibilityErrorVariableDeclaration.ts (4 errors) ==== - module m { - class private1 { - } - - export class public1 { - } - - // Directly using names from this module - var x: private1; - var y = new private1(); - - export var k: private1; - ~~~~~~~~ -!!! error TS4025: Exported variable 'k' has or is using private name 'private1'. - export var l = new private1(); - ~ -!!! error TS4025: Exported variable 'l' has or is using private name 'private1'. - - var x2: public1; - var y2 = new public1(); - - export var k2: public1; - export var l2 = new public1(); - - module m2 { - export class public2 { - } - } - - var x3: m2.public2; - var y3 = new m2.public2(); - - export var k3: m2.public2; - ~~ -!!! error TS4025: Exported variable 'k3' has or is using private name 'm2'. - export var l3 = new m2.public2(); - ~~ -!!! error TS4024: Exported variable 'l3' has or is using name 'm2.public2' from private module 'm2'. - } - \ No newline at end of file diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorVariableDeclaration.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorVariableDeclaration.js index 56f959a135616..6bdcedae7d70c 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorVariableDeclaration.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorVariableDeclaration.js @@ -66,3 +66,22 @@ var m; var y3 = new m2.public2(); m.l3 = new m2.public2(); })(m || (m = {})); + + +//// [declFileTypeAnnotationVisibilityErrorVariableDeclaration.d.ts] +declare module m { + class private1 { + } + class public1 { + } + var k: private1; + var l: private1; + var k2: public1; + var l2: public1; + module m2 { + class public2 { + } + } + var k3: m2.public2; + var l3: m2.public2; +} diff --git a/tests/baselines/reference/declInput-2.errors.txt b/tests/baselines/reference/declInput-2.errors.txt deleted file mode 100644 index f151f3e712205..0000000000000 --- a/tests/baselines/reference/declInput-2.errors.txt +++ /dev/null @@ -1,39 +0,0 @@ -tests/cases/compiler/declInput-2.ts(10,21): error TS4031: Public property 'm22' of exported class has or is using private name 'C'. -tests/cases/compiler/declInput-2.ts(13,21): error TS4031: Public property 'm25' of exported class has or is using private name 'I2'. -tests/cases/compiler/declInput-2.ts(16,24): error TS4055: Return type of public method from exported class has or is using private name 'I2'. -tests/cases/compiler/declInput-2.ts(18,23): error TS4073: Parameter 'i' of public method from exported class has or is using private name 'I2'. -tests/cases/compiler/declInput-2.ts(19,21): error TS4055: Return type of public method from exported class has or is using private name 'C'. - - -==== tests/cases/compiler/declInput-2.ts (5 errors) ==== - module M { - class C { } - export class E {} - export interface I1 {} - interface I2 {} - export class D { - private c: C; // don't generate - public m1: number; - public m2: string; - public m22: C; // don't generate - ~ -!!! error TS4031: Public property 'm22' of exported class has or is using private name 'C'. - public m23: E; - public m24: I1; - public m25: I2; // don't generate - ~~ -!!! error TS4031: Public property 'm25' of exported class has or is using private name 'I2'. - public m232(): E { return null;} - public m242(): I1 { return null; } - public m252(): I2 { return null; } // don't generate - ~~ -!!! error TS4055: Return type of public method from exported class has or is using private name 'I2'. - public m26(i:I1) {} - public m262(i:I2) {} - ~~ -!!! error TS4073: Parameter 'i' of public method from exported class has or is using private name 'I2'. - public m3():C { return new C(); } - ~ -!!! error TS4055: Return type of public method from exported class has or is using private name 'C'. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/declInput-2.js b/tests/baselines/reference/declInput-2.js index 02dc3cd281959..f1f23b7f22ef8 100644 --- a/tests/baselines/reference/declInput-2.js +++ b/tests/baselines/reference/declInput-2.js @@ -48,3 +48,31 @@ var M; }()); M.D = D; })(M || (M = {})); + + +//// [declInput-2.d.ts] +declare module M { + class C { + } + class E { + } + interface I1 { + } + interface I2 { + } + class D { + private c; + m1: number; + m2: string; + m22: C; + m23: E; + m24: I1; + m25: I2; + m232(): E; + m242(): I1; + m252(): I2; + m26(i: I1): void; + m262(i: I2): void; + m3(): C; + } +} diff --git a/tests/baselines/reference/declarationEmitClassPrivateConstructor2.errors.txt b/tests/baselines/reference/declarationEmitClassPrivateConstructor2.errors.txt deleted file mode 100644 index a31454a476037..0000000000000 --- a/tests/baselines/reference/declarationEmitClassPrivateConstructor2.errors.txt +++ /dev/null @@ -1,20 +0,0 @@ -tests/cases/compiler/declarationEmitClassPrivateConstructor2.ts(5,38): error TS4031: Public property 'data' of exported class has or is using private name 'PrivateInterface'. -tests/cases/compiler/declarationEmitClassPrivateConstructor2.ts(10,33): error TS4063: Parameter 'data' of constructor from exported class has or is using private name 'PrivateInterface'. - - -==== tests/cases/compiler/declarationEmitClassPrivateConstructor2.ts (2 errors) ==== - interface PrivateInterface { - } - - export class ExportedClass1 { - private constructor(public data: PrivateInterface) { } - ~~~~~~~~~~~~~~~~ -!!! error TS4031: Public property 'data' of exported class has or is using private name 'PrivateInterface'. - } - - - export class ExportedClass2 { - protected constructor(data: PrivateInterface) { } - ~~~~~~~~~~~~~~~~ -!!! error TS4063: Parameter 'data' of constructor from exported class has or is using private name 'PrivateInterface'. - } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitClassPrivateConstructor2.js b/tests/baselines/reference/declarationEmitClassPrivateConstructor2.js index 863b295751f0b..445270e00c533 100644 --- a/tests/baselines/reference/declarationEmitClassPrivateConstructor2.js +++ b/tests/baselines/reference/declarationEmitClassPrivateConstructor2.js @@ -27,3 +27,16 @@ var ExportedClass2 = /** @class */ (function () { return ExportedClass2; }()); exports.ExportedClass2 = ExportedClass2; + + +//// [declarationEmitClassPrivateConstructor2.d.ts] +interface PrivateInterface { +} +export declare class ExportedClass1 { + data: PrivateInterface; + private constructor(); +} +export declare class ExportedClass2 { + protected constructor(data: PrivateInterface); +} +export {}; diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt deleted file mode 100644 index f19766cbb0093..0000000000000 --- a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS4082: Default export of the module has or is using private name 'A'. - - -==== tests/cases/compiler/declarationEmitDefaultExport7.ts (1 errors) ==== - class A {} - export default new A(); - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4082: Default export of the module has or is using private name 'A'. - \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.js b/tests/baselines/reference/declarationEmitDefaultExport7.js index 99751113dd66d..e0c72ee422555 100644 --- a/tests/baselines/reference/declarationEmitDefaultExport7.js +++ b/tests/baselines/reference/declarationEmitDefaultExport7.js @@ -7,3 +7,10 @@ export default new A(); class A { } export default new A(); + + +//// [declarationEmitDefaultExport7.d.ts] +declare class A { +} +declare const _default: A; +export default _default; diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt deleted file mode 100644 index e464b96a8bf77..0000000000000 --- a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts(4,20): error TS4025: Exported variable 'y' has or is using private name 'c'. - - -==== tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts (1 errors) ==== - module m { - class c { - } - export var [x, y, z] = [10, new c(), 30]; - ~ -!!! error TS4025: Exported variable 'y' has or is using private name 'c'. - } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js index 23b93d14e15bc..0d1e16af79773 100644 --- a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js @@ -16,3 +16,11 @@ var m; _a = [10, new c(), 30], m.x = _a[0], m.y = _a[1], m.z = _a[2]; var _a; })(m || (m = {})); + + +//// [declarationEmitDestructuringPrivacyError.d.ts] +declare module m { + class c { + } + var x: number, y: c, z: number; +} diff --git a/tests/baselines/reference/declarationEmitExpressionInExtends3.errors.txt b/tests/baselines/reference/declarationEmitExpressionInExtends3.errors.txt deleted file mode 100644 index 4864a3bcdc22e..0000000000000 --- a/tests/baselines/reference/declarationEmitExpressionInExtends3.errors.txt +++ /dev/null @@ -1,51 +0,0 @@ -tests/cases/compiler/declarationEmitExpressionInExtends3.ts(28,30): error TS4020: 'extends' clause of exported class 'MyClass' has or is using private name 'LocalClass'. -tests/cases/compiler/declarationEmitExpressionInExtends3.ts(36,75): error TS4020: 'extends' clause of exported class 'MyClass3' has or is using private name 'LocalInterface'. - - -==== tests/cases/compiler/declarationEmitExpressionInExtends3.ts (2 errors) ==== - export class ExportedClass { - x: T; - } - - class LocalClass { - x: T; - y: U; - } - - export interface ExportedInterface { - x: number; - } - - interface LocalInterface { - x: number; - } - - function getLocalClass(c: T) { - return LocalClass; - } - - function getExportedClass(c: T) { - return ExportedClass; - } - - - - export class MyClass extends getLocalClass(undefined) { // error LocalClass is inaccisible - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4020: 'extends' clause of exported class 'MyClass' has or is using private name 'LocalClass'. - } - - - export class MyClass2 extends getExportedClass(undefined) { // OK - } - - - export class MyClass3 extends getExportedClass(undefined) { // Error LocalInterface is inaccisble - ~~~~~~~~~~~~~~ -!!! error TS4020: 'extends' clause of exported class 'MyClass3' has or is using private name 'LocalInterface'. - } - - - export class MyClass4 extends getExportedClass(undefined) { // OK - } - \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitExpressionInExtends3.js b/tests/baselines/reference/declarationEmitExpressionInExtends3.js index c97587620fd7e..c73268f7c55cd 100644 --- a/tests/baselines/reference/declarationEmitExpressionInExtends3.js +++ b/tests/baselines/reference/declarationEmitExpressionInExtends3.js @@ -104,3 +104,32 @@ var MyClass4 = /** @class */ (function (_super) { return MyClass4; }(getExportedClass(undefined))); exports.MyClass4 = MyClass4; + + +//// [declarationEmitExpressionInExtends3.d.ts] +export declare class ExportedClass { + x: T; +} +declare class LocalClass { + x: T; + y: U; +} +export interface ExportedInterface { + x: number; +} +interface LocalInterface { + x: number; +} +declare const MyClass_base: typeof LocalClass; +export declare class MyClass extends MyClass_base { +} +declare const MyClass2_base: typeof ExportedClass; +export declare class MyClass2 extends MyClass2_base { +} +declare const MyClass3_base: typeof ExportedClass; +export declare class MyClass3 extends MyClass3_base { +} +declare const MyClass4_base: typeof ExportedClass; +export declare class MyClass4 extends MyClass4_base { +} +export {}; diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.errors.txt b/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.errors.txt deleted file mode 100644 index 37a4853b6496f..0000000000000 --- a/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts(5,33): error TS4060: Return type of exported function has or is using private name 'I'. - - -==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitIdentifierPredicatesWithPrivateName01.ts (1 errors) ==== - interface I { - a: number; - } - - export function f(x: any): x is I { - ~ -!!! error TS4060: Return type of exported function has or is using private name 'I'. - return typeof x.a === "number"; - } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.js b/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.js index 74da01ce683ca..1531d09a88f63 100644 --- a/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.js +++ b/tests/baselines/reference/declarationEmitIdentifierPredicatesWithPrivateName01.js @@ -14,3 +14,11 @@ function f(x) { return typeof x.a === "number"; } exports.f = f; + + +//// [declarationEmitIdentifierPredicatesWithPrivateName01.d.ts] +interface I { + a: number; +} +export declare function f(x: any): x is I; +export {}; diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias9.js b/tests/baselines/reference/declarationEmitInferredTypeAlias9.js index 8d03c6b70d2d1..8539cfaf03e50 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias9.js +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias9.js @@ -17,6 +17,8 @@ exports.returnSomeGlobalValue = returnSomeGlobalValue; //// [declarationEmitInferredTypeAlias9.d.ts] -export declare function returnSomeGlobalValue(): number[] | { - x: number[] | any; +declare type Foo = T | { + x: Foo; }; +export declare function returnSomeGlobalValue(): Foo; +export {}; diff --git a/tests/baselines/reference/declarationEmitInferredTypeAlias9.types b/tests/baselines/reference/declarationEmitInferredTypeAlias9.types index 30a15aff6fb72..ab03db6da4f2f 100644 --- a/tests/baselines/reference/declarationEmitInferredTypeAlias9.types +++ b/tests/baselines/reference/declarationEmitInferredTypeAlias9.types @@ -1,19 +1,19 @@ === tests/cases/compiler/declarationEmitInferredTypeAlias9.ts === type Foo = T | { x: Foo }; ->Foo : T | { x: T | any; } +>Foo : Foo >T : T >T : T ->x : T | { x: T | any; } ->Foo : T | { x: T | any; } +>x : Foo +>Foo : Foo >T : T var x: Foo; ->x : number[] | { x: number[] | any; } ->Foo : T | { x: T | any; } +>x : Foo +>Foo : Foo export function returnSomeGlobalValue() { ->returnSomeGlobalValue : () => number[] | { x: number[] | any; } +>returnSomeGlobalValue : () => Foo return x; ->x : number[] | { x: number[] | any; } +>x : Foo } diff --git a/tests/baselines/reference/declarationEmitLocalClassDeclarationMixin.js b/tests/baselines/reference/declarationEmitLocalClassDeclarationMixin.js index 352520ff575e6..3cbbc0e076361 100644 --- a/tests/baselines/reference/declarationEmitLocalClassDeclarationMixin.js +++ b/tests/baselines/reference/declarationEmitLocalClassDeclarationMixin.js @@ -107,3 +107,4 @@ declare const FilteredThing_base: { export declare class FilteredThing extends FilteredThing_base { match(path: string): boolean; } +export {}; diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.errors.txt b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.errors.txt deleted file mode 100644 index ea59c8fa9e8aa..0000000000000 --- a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts(2,18): error TS4055: Return type of public method from exported class has or is using private name 'D'. - - -==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName01.ts (1 errors) ==== - export class C { - m(): this is D { - ~ -!!! error TS4055: Return type of public method from exported class has or is using private name 'D'. - return this instanceof D; - } - } - - class D extends C { - } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.js b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.js index 5bb662b5907c3..10305b8ed6431 100644 --- a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.js +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName01.js @@ -37,3 +37,12 @@ var D = /** @class */ (function (_super) { } return D; }(C)); + + +//// [declarationEmitThisPredicatesWithPrivateName01.d.ts] +export declare class C { + m(): this is D; +} +declare class D extends C { +} +export {}; diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt index f80c2bd0d6fd0..a01ebbb486466 100644 --- a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.errors.txt @@ -1,8 +1,7 @@ -tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(7,14): error TS4025: Exported variable 'obj' has or is using private name 'Foo'. tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts(8,10): error TS2526: A 'this' type is available only in a non-static member of a class or interface. -==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts (2 errors) ==== +==== tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredicatesWithPrivateName02.ts (1 errors) ==== interface Foo { a: string; b: number; @@ -10,8 +9,6 @@ tests/cases/conformance/declarationEmit/typePredicates/declarationEmitThisPredic } export const obj = { - ~~~ -!!! error TS4025: Exported variable 'obj' has or is using private name 'Foo'. m(): this is Foo { ~~~~ !!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. diff --git a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.js b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.js index 86fb2e0560711..96b580a68b9e1 100644 --- a/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.js +++ b/tests/baselines/reference/declarationEmitThisPredicatesWithPrivateName02.js @@ -21,3 +21,15 @@ exports.obj = { return dis.a != null && dis.b != null && dis.c != null; } }; + + +//// [declarationEmitThisPredicatesWithPrivateName02.d.ts] +interface Foo { + a: string; + b: number; + c: boolean; +} +export declare const obj: { + m(): this is Foo; +}; +export {}; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt deleted file mode 100644 index 9552adfc0af98..0000000000000 --- a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts(4,25): error TS4081: Exported type alias 'SubFoo' has or is using private name 'Foo'. - - -==== tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts (1 errors) ==== - type Foo = { - foo(): Foo - }; - export type SubFoo = Foo; - ~~~ -!!! error TS4081: Exported type alias 'SubFoo' has or is using private name 'Foo'. - - function foo() { - return {} as SubFoo; - } - \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js index cee701c045588..1b29acc164e70 100644 --- a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.js @@ -15,3 +15,11 @@ exports.__esModule = true; function foo() { return {}; } + + +//// [declarationEmitTypeAliasWithTypeParameters5.d.ts] +declare type Foo = { + foo(): Foo; +}; +export declare type SubFoo = Foo; +export {}; diff --git a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.types b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.types index 18ef901dbdc94..cd98b3706f687 100644 --- a/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.types +++ b/tests/baselines/reference/declarationEmitTypeAliasWithTypeParameters5.types @@ -1,30 +1,30 @@ === tests/cases/compiler/declarationEmitTypeAliasWithTypeParameters5.ts === type Foo = { ->Foo : { foo(): Foo; } +>Foo : Foo >T : T >Y : Y foo(): Foo ->foo : () => { foo(): Foo; } +>foo : () => Foo >U : U >J : J ->Foo : { foo(): Foo; } +>Foo : Foo >U : U >J : J }; export type SubFoo = Foo; ->SubFoo : { foo(): Foo; } +>SubFoo : Foo >R : R ->Foo : { foo(): Foo; } +>Foo : Foo >R : R function foo() { ->foo : () => { foo(): Foo; } +>foo : () => Foo return {} as SubFoo; ->{} as SubFoo : { foo(): Foo; } +>{} as SubFoo : Foo >{} : {} ->SubFoo : { foo(): Foo; } +>SubFoo : Foo } diff --git a/tests/baselines/reference/declarationFunctionTypeNonlocalShouldNotBeAnError.js b/tests/baselines/reference/declarationFunctionTypeNonlocalShouldNotBeAnError.js index 6faa0bfca6039..88343a7d08e5c 100644 --- a/tests/baselines/reference/declarationFunctionTypeNonlocalShouldNotBeAnError.js +++ b/tests/baselines/reference/declarationFunctionTypeNonlocalShouldNotBeAnError.js @@ -20,7 +20,8 @@ var foo; //// [declarationFunctionTypeNonlocalShouldNotBeAnError.d.ts] declare namespace foo { + function bar(): void; const obj: { - bar: () => void; + bar: typeof bar; }; } diff --git a/tests/baselines/reference/declarationNoDanglingGenerics.js b/tests/baselines/reference/declarationNoDanglingGenerics.js index 9045be6827bdb..fdd7f05564a7f 100644 --- a/tests/baselines/reference/declarationNoDanglingGenerics.js +++ b/tests/baselines/reference/declarationNoDanglingGenerics.js @@ -123,3 +123,4 @@ declare const CKind_base: { }; export declare class CKind extends CKind_base { } +export {}; diff --git a/tests/baselines/reference/dynamicNames.types b/tests/baselines/reference/dynamicNames.types index 8535d7454a1dc..174aff77424c9 100644 --- a/tests/baselines/reference/dynamicNames.types +++ b/tests/baselines/reference/dynamicNames.types @@ -213,7 +213,7 @@ declare class T10 extends T9 { >T9 : T9 } declare type T11 = { ->T11 : { [c4]: number; [c5]: string; [s2]: boolean; } +>T11 : T11 [c4]: number; >[c4] : number @@ -261,7 +261,7 @@ declare class T14 extends T13 { >T13 : T13 } declare type T15 = { ->T15 : { a: number; 1: string; [s2]: boolean; } +>T15 : T15 a: number; >a : number @@ -341,9 +341,9 @@ let t6: N.T6; >T6 : N.T6 let t7: N.T7; ->t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t7 : N.T7 >N : any ->T7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>T7 : N.T7 let t8: T8; >t8 : T8 @@ -358,8 +358,8 @@ let t10: T10; >T10 : T10 let t11: T11; ->t11 : { [c4]: number; [c5]: string; [s2]: boolean; } ->T11 : { [c4]: number; [c5]: string; [s2]: boolean; } +>t11 : T11 +>T11 : T11 let t12: T12; >t12 : T12 @@ -374,8 +374,8 @@ let t14: T14; >T14 : T14 let t15: T15; ->t15 : { a: number; 1: string; [s2]: boolean; } ->T15 : { a: number; 1: string; [s2]: boolean; } +>t15 : T15 +>T15 : T15 // assignability t0 = t1, t0 = t2, t0 = t3, t1 = t0, t1 = t2, t1 = t3, t2 = t0, t2 = t1, t2 = t3, t3 = t0, t3 = t1, t3 = t2; @@ -431,13 +431,13 @@ t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5, t6 = t7, >t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5, t6 = t7, t7 = t4, t7 = t5, t7 = t6 : N.T6 >t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5, t6 = t7, t7 = t4, t7 = t5 : N.T5 >t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5, t6 = t7, t7 = t4 : N.T4 ->t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5, t6 = t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5, t6 = t7 : N.T7 >t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5 : N.T5 >t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4 : N.T4 ->t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7 : N.T7 >t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6 : N.T6 >t4 = t5, t4 = t6, t4 = t7, t5 = t4 : N.T4 ->t4 = t5, t4 = t6, t4 = t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t4 = t5, t4 = t6, t4 = t7 : N.T7 >t4 = t5, t4 = t6 : N.T6 >t4 = t5 : N.T5 >t4 : N.T4 @@ -445,35 +445,35 @@ t4 = t5, t4 = t6, t4 = t7, t5 = t4, t5 = t6, t5 = t7, t6 = t4, t6 = t5, t6 = t7, >t4 = t6 : N.T6 >t4 : N.T4 >t6 : N.T6 ->t4 = t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t4 = t7 : N.T7 >t4 : N.T4 ->t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t7 : N.T7 >t5 = t4 : N.T4 >t5 : N.T5 >t4 : N.T4 >t5 = t6 : N.T6 >t5 : N.T5 >t6 : N.T6 ->t5 = t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t5 = t7 : N.T7 >t5 : N.T5 ->t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t7 : N.T7 >t6 = t4 : N.T4 >t6 : N.T6 >t4 : N.T4 >t6 = t5 : N.T5 >t6 : N.T6 >t5 : N.T5 ->t6 = t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t6 = t7 : N.T7 >t6 : N.T6 ->t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t7 : N.T7 >t7 = t4 : N.T4 ->t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t7 : N.T7 >t4 : N.T4 >t7 = t5 : N.T5 ->t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t7 : N.T7 >t5 : N.T5 >t7 = t6 : N.T6 ->t7 : { [N.c2]: number; [N.c3]: string; [N.s1]: boolean; } +>t7 : N.T7 >t6 : N.T6 t0 = t12, t0 = t13, t0 = t14, t0 = t15, t12 = t0, t13 = t0, t14 = t0, t15 = t0; @@ -481,7 +481,7 @@ t0 = t12, t0 = t13, t0 = t14, t0 = t15, t12 = t0, t13 = t0, t14 = t0, t15 = t0; >t0 = t12, t0 = t13, t0 = t14, t0 = t15, t12 = t0, t13 = t0, t14 = t0 : T0 >t0 = t12, t0 = t13, t0 = t14, t0 = t15, t12 = t0, t13 = t0 : T0 >t0 = t12, t0 = t13, t0 = t14, t0 = t15, t12 = t0 : T0 ->t0 = t12, t0 = t13, t0 = t14, t0 = t15 : { a: number; 1: string; [s2]: boolean; } +>t0 = t12, t0 = t13, t0 = t14, t0 = t15 : T15 >t0 = t12, t0 = t13, t0 = t14 : T14 >t0 = t12, t0 = t13 : T13 >t0 = t12 : T12 @@ -493,9 +493,9 @@ t0 = t12, t0 = t13, t0 = t14, t0 = t15, t12 = t0, t13 = t0, t14 = t0, t15 = t0; >t0 = t14 : T14 >t0 : T0 >t14 : T14 ->t0 = t15 : { a: number; 1: string; [s2]: boolean; } +>t0 = t15 : T15 >t0 : T0 ->t15 : { a: number; 1: string; [s2]: boolean; } +>t15 : T15 >t12 = t0 : T0 >t12 : T12 >t0 : T0 @@ -506,7 +506,7 @@ t0 = t12, t0 = t13, t0 = t14, t0 = t15, t12 = t0, t13 = t0, t14 = t0, t15 = t0; >t14 : T14 >t0 : T0 >t15 = t0 : T0 ->t15 : { a: number; 1: string; [s2]: boolean; } +>t15 : T15 >t0 : T0 t0 = C; // static side diff --git a/tests/baselines/reference/emitClassExpressionInDeclarationFile.js b/tests/baselines/reference/emitClassExpressionInDeclarationFile.js index 53fead2d9879e..cc8848a1a2012 100644 --- a/tests/baselines/reference/emitClassExpressionInDeclarationFile.js +++ b/tests/baselines/reference/emitClassExpressionInDeclarationFile.js @@ -130,3 +130,4 @@ declare const Test_base: { } & typeof FooItem; export declare class Test extends Test_base { } +export {}; diff --git a/tests/baselines/reference/exportClassExtendingIntersection.js b/tests/baselines/reference/exportClassExtendingIntersection.js index 9b99e90d511c7..70ea0b3b53a11 100644 --- a/tests/baselines/reference/exportClassExtendingIntersection.js +++ b/tests/baselines/reference/exportClassExtendingIntersection.js @@ -118,5 +118,6 @@ declare const MyExtendedClass_base: typeof MyBaseClass & (new (...args: any[]) = export declare class MyExtendedClass extends MyExtendedClass_base { extendedClassProperty: number; } +export {}; //// [Main.d.ts] export {}; diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline index e21f677a7eab6..d2b26ca48c89b 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors.baseline @@ -1,6 +1,4 @@ -EmitSkipped: true -Diagnostics: - Exported variable 'foo' has or is using private name 'C'. +EmitSkipped: false FileName : /tests/cases/fourslash/inputFile.js var M; (function (M) { @@ -11,4 +9,10 @@ var M; }()); M.foo = new C(); })(M || (M = {})); +FileName : /tests/cases/fourslash/inputFile.d.ts +declare module M { + class C { + } + var foo: C; +} diff --git a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline index 5cc4df243d07f..77131f89dd5ef 100644 --- a/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline +++ b/tests/baselines/reference/getEmitOutputWithEmitterErrors2.baseline @@ -1,6 +1,4 @@ -EmitSkipped: true -Diagnostics: - Exported variable 'foo' has or is using private name 'C'. +EmitSkipped: false FileName : /tests/cases/fourslash/inputFile.js define(["require", "exports"], function (require, exports) { "use strict"; @@ -15,4 +13,11 @@ define(["require", "exports"], function (require, exports) { M.foo = new C(); })(M = exports.M || (exports.M = {})); }); +FileName : /tests/cases/fourslash/inputFile.d.ts +class C { +} +export declare module M { + var foo: C; +} +export {}; diff --git a/tests/baselines/reference/indexedAccessTypeConstraints.types b/tests/baselines/reference/indexedAccessTypeConstraints.types index dad5fd7d61710..f2002aff90095 100644 --- a/tests/baselines/reference/indexedAccessTypeConstraints.types +++ b/tests/baselines/reference/indexedAccessTypeConstraints.types @@ -11,7 +11,7 @@ interface IData { } type Data = { ->Data : { get: (prop: K) => T[K]; } +>Data : Data >T : T get: (prop: K) => T[K]; @@ -30,19 +30,19 @@ class Parent { >M : M constructor(private data: Data) {} ->data : { get: (prop: K) => M[K]; } ->Data : { get: (prop: K) => T[K]; } +>data : Data +>Data : Data >M : M getData(): Data { ->getData : () => { get: (prop: K) => M[K]; } ->Data : { get: (prop: K) => T[K]; } +>getData : () => Data +>Data : Data >M : M return this.data; ->this.data : { get: (prop: K) => M[K]; } +>this.data : Data >this : this ->data : { get: (prop: K) => M[K]; } +>data : Data } } @@ -60,10 +60,10 @@ export class Foo extends Parent> { return this.getData().get('content'); >this.getData().get('content') : C >this.getData().get : (prop: K) => IData[K] ->this.getData() : { get: (prop: K) => IData[K]; } ->this.getData : () => { get: (prop: K) => IData[K]; } +>this.getData() : Data> +>this.getData : () => Data> >this : this ->getData : () => { get: (prop: K) => IData[K]; } +>getData : () => Data> >get : (prop: K) => IData[K] >'content' : "content" } @@ -85,10 +85,10 @@ export class Bar> extends Parent { return this.getData().get('content'); >this.getData().get('content') : T["content"] >this.getData().get : (prop: K) => T[K] ->this.getData() : { get: (prop: K) => T[K]; } ->this.getData : () => { get: (prop: K) => T[K]; } +>this.getData() : Data +>this.getData : () => Data >this : this ->getData : () => { get: (prop: K) => T[K]; } +>getData : () => Data >get : (prop: K) => T[K] >'content' : "content" } diff --git a/tests/baselines/reference/jsxSpreadFirstUnionNoErrors.types b/tests/baselines/reference/jsxSpreadFirstUnionNoErrors.types index d96c88d1c410b..0e97c588a643f 100644 --- a/tests/baselines/reference/jsxSpreadFirstUnionNoErrors.types +++ b/tests/baselines/reference/jsxSpreadFirstUnionNoErrors.types @@ -3,7 +3,7 @@ import React from "react"; >React : typeof React type InfoProps = ->InfoProps : { status: "hidden"; } | { status: "visible"; content: string; } +>InfoProps : InfoProps | { status: "hidden" } >status : "hidden" @@ -13,16 +13,16 @@ type InfoProps = >content : string const Info = (props: InfoProps) => ->Info : (props: { status: "hidden"; } | { status: "visible"; content: string; }) => JSX.Element ->(props: InfoProps) =>props.status === "hidden" ?