From e42c1d6256cb1dc4e728080aa9b271bdf198dfc6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 26 Jan 2021 11:38:03 -0800 Subject: [PATCH 1/5] @typedef: Improve error spans from declaration emit This is a proof-of-concept fix. I think it could be expanded for all of jsdoc, but I only set it up for jsdoc type aliases. It could use a lot of polish too. --- src/compiler/checker.ts | 17 +++++++++++------ src/compiler/transformers/declarations.ts | 12 ++++++------ .../transformers/declarations/diagnostics.ts | 2 +- src/compiler/types.ts | 2 +- ...arameterTagReusesInputNodeInEmit1.errors.txt | 6 +++--- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 06fc5a6d396f0..be729d7f43bfa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5411,12 +5411,12 @@ namespace ts { const firstIdentifier = getFirstIdentifier(accessExpression); const name = resolveName(firstIdentifier, firstIdentifier.escapedText, SymbolFlags.Value | SymbolFlags.ExportValue, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true); if (name) { - context.tracker.trackSymbol(name, enclosingDeclaration, SymbolFlags.Value); + context.tracker.trackSymbol(name, enclosingDeclaration, SymbolFlags.Value, context.trueErrorNode); } } function lookupSymbolChain(symbol: Symbol, context: NodeBuilderContext, meaning: SymbolFlags, yieldModuleSymbol?: boolean) { - context.tracker.trackSymbol!(symbol, context.enclosingDeclaration, meaning); // TODO: GH#18217 + context.tracker.trackSymbol!(symbol, context.enclosingDeclaration, meaning, context.trueErrorNode); // TODO: GH#18217 return lookupSymbolChainWorker(symbol, context, meaning, yieldModuleSymbol); } @@ -5971,7 +5971,7 @@ namespace ts { introducesError = true; } else { - context.tracker?.trackSymbol?.(sym, context.enclosingDeclaration, SymbolFlags.All); + context.tracker?.trackSymbol?.(sym, context.enclosingDeclaration, SymbolFlags.All, context.trueErrorNode); includePrivateSymbol?.(sym); } if (isIdentifier(node)) { @@ -6182,7 +6182,7 @@ namespace ts { remappedSymbolNames: new Map(), tracker: { ...oldcontext.tracker, - trackSymbol: (sym, decl, meaning) => { + trackSymbol: (sym, decl, meaning, trueErrorNode) => { const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeALiases*/ false); if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { // Lookup the root symbol of the chain of refs we'll use to access it and serialize it @@ -6192,7 +6192,7 @@ namespace ts { } } else if (oldcontext.tracker && oldcontext.tracker.trackSymbol) { - oldcontext.tracker.trackSymbol(sym, decl, meaning); + oldcontext.tracker.trackSymbol(sym, decl, meaning, trueErrorNode); } } } @@ -6505,7 +6505,7 @@ namespace ts { ), ModifierFlags.None ); - context.tracker.trackSymbol!(type.symbol, context.enclosingDeclaration, SymbolFlags.Value); + context.tracker.trackSymbol!(type.symbol, context.enclosingDeclaration, SymbolFlags.Value, context.trueErrorNode); } else { const statement = setTextRange(factory.createVariableStatement(/*modifiers*/ undefined, factory.createVariableDeclarationList([ @@ -6654,8 +6654,11 @@ namespace ts { const typeParams = getSymbolLinks(symbol).typeParameters; const typeParamDecls = map(typeParams, p => typeParameterToDeclaration(p, context)); const jsdocAliasDecl = find(symbol.declarations, isJSDocTypeAlias); + const commentText = jsdocAliasDecl ? jsdocAliasDecl.comment || jsdocAliasDecl.parent.comment : undefined; const oldFlags = context.flags; + const oldTrueErrorNode = context.trueErrorNode; + context.trueErrorNode = jsdocAliasDecl; context.flags |= NodeBuilderFlags.InTypeAlias; const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) @@ -6666,6 +6669,7 @@ namespace ts { !commentText ? [] : [{ kind: SyntaxKind.MultiLineCommentTrivia, text: "*\n * " + commentText.replace(/\n/g, "\n * ") + "\n ", pos: -1, end: -1, hasTrailingNewLine: true }] ), modifierFlags); context.flags = oldFlags; + context.trueErrorNode = oldTrueErrorNode; } function serializeInterface(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) { @@ -7628,6 +7632,7 @@ namespace ts { inferTypeParameters: TypeParameter[] | undefined; approximateLength: number; truncating?: boolean; + trueErrorNode?: Node; typeParameterSymbolList?: Set; typeParameterNames?: ESMap; typeParameterNamesByText?: Set; diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 0ca8840059801..bbebb06759410 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -111,7 +111,7 @@ namespace ts { refs.set(getOriginalNodeId(container), container); } - function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { + function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult, trueErrorNode?: Node) { if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) { // Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info if (symbolAccessibilityResult && symbolAccessibilityResult.aliasesToMakeVisible) { @@ -129,7 +129,7 @@ namespace ts { } else { // Report error - const errorInfo = getSymbolAccessibilityDiagnostic(symbolAccessibilityResult); + const errorInfo = getSymbolAccessibilityDiagnostic(symbolAccessibilityResult, trueErrorNode); if (errorInfo) { if (errorInfo.typeName) { context.addDiagnostic(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, @@ -154,9 +154,9 @@ namespace ts { } } - function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { + function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, trueErrorNode?: Node) { if (symbol.flags & SymbolFlags.TypeParameter) return; - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true)); + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true), trueErrorNode); recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning)); } @@ -217,11 +217,11 @@ namespace ts { function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) { const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = (s) => ({ + getSymbolAccessibilityDiagnostic = (s, trueErrorNode) => ({ diagnosticMessage: s.errorModuleName ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, - errorNode: s.errorNode || sourceFile + errorNode: s.errorNode || trueErrorNode || sourceFile }); const result = resolver.getDeclarationStatementsForSourceFile(sourceFile, declarationEmitNodeBuilderFlags, symbolTracker, bundled); getSymbolAccessibilityDiagnostic = oldDiag; diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index ebb453ee83d9a..d2461f750e61c 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -1,6 +1,6 @@ /* @internal */ namespace ts { - export type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult) => (SymbolAccessibilityDiagnostic | undefined); + export type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult, trueErrorNode: Node | undefined) => (SymbolAccessibilityDiagnostic | undefined); export interface SymbolAccessibilityDiagnostic { errorNode: Node; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4352e2f2171e3..aa54e7b87dac0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7966,7 +7966,7 @@ namespace ts { // Called when the symbol writer encounters a symbol to write. Currently only used by the // declaration emitter to help determine if it should patch up the final declaration file // with import statements it previously saw (but chose not to emit). - trackSymbol?(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags): void; + trackSymbol?(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, trueErrorNode: Node | undefined): void; reportInaccessibleThisError?(): void; reportPrivateInBaseOfClassExpression?(propertyName: string): void; reportInaccessibleUniqueSymbolError?(): void; diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt index a231ff1aaf495..525c1997ffff0 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsdoc/declarations/file.js(8,1): error TS9006: Declaration emit for this file requires using private name 'Base' from module '"tests/cases/conformance/jsdoc/declarations/base"'. An explicit type annotation may unblock declaration emit. +tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS9006: Declaration emit for this file requires using private name 'Base' from module '"tests/cases/conformance/jsdoc/declarations/base"'. An explicit type annotation may unblock declaration emit. ==== tests/cases/conformance/jsdoc/declarations/base.js (0 errors) ==== @@ -16,6 +16,8 @@ tests/cases/conformance/jsdoc/declarations/file.js(8,1): error TS9006: Declarati ==== tests/cases/conformance/jsdoc/declarations/file.js (1 errors) ==== /** @typedef {import('./base')} BaseFactory */ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS9006: Declaration emit for this file requires using private name 'Base' from module '"tests/cases/conformance/jsdoc/declarations/base"'. An explicit type annotation may unblock declaration emit. /** * @@ -23,8 +25,6 @@ tests/cases/conformance/jsdoc/declarations/file.js(8,1): error TS9006: Declarati * @returns {InstanceType} */ const test = (base) => { - ~~~~~ -!!! error TS9006: Declaration emit for this file requires using private name 'Base' from module '"tests/cases/conformance/jsdoc/declarations/base"'. An explicit type annotation may unblock declaration emit. return base; }; \ No newline at end of file From 3b6b0a4d6198bf61210e6fe6b3953a9047950d96 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 26 Jan 2021 12:07:35 -0800 Subject: [PATCH 2/5] track error node in isSymbolAccessible instead --- src/compiler/checker.ts | 42 ++++++++++--------- src/compiler/transformers/declarations.ts | 10 ++--- .../transformers/declarations/diagnostics.ts | 2 +- src/compiler/types.ts | 4 +- src/services/utilities.ts | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index be729d7f43bfa..553130ae1fcfa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4072,18 +4072,18 @@ namespace ts { return false; } - function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined): boolean { - const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true); + function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, trueErrorNode: Node | undefined): boolean { + const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true, trueErrorNode); return access.accessibility === SymbolAccessibility.Accessible; } - function isValueSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined): boolean { - const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Value, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true); + function isValueSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, trueErrorNode: Node | undefined): boolean { + const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Value, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true, trueErrorNode); return access.accessibility === SymbolAccessibility.Accessible; } - function isSymbolAccessibleByFlags(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, flags: SymbolFlags): boolean { - const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, flags, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ false); + function isSymbolAccessibleByFlags(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, flags: SymbolFlags, trueErrorNode: Node | undefined): boolean { + const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, flags, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ false, trueErrorNode); return access.accessibility === SymbolAccessibility.Accessible; } @@ -4162,11 +4162,11 @@ namespace ts { * @param meaning a SymbolFlags to check if such meaning of the symbol is accessible * @param shouldComputeAliasToMakeVisible a boolean value to indicate whether to return aliases to be mark visible in case the symbol is accessible */ - function isSymbolAccessible(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean): SymbolAccessibilityResult { - return isSymbolAccessibleWorker(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible, /*allowModules*/ true); + function isSymbolAccessible(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult { + return isSymbolAccessibleWorker(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible, /*allowModules*/ true, trueErrorNode); } - function isSymbolAccessibleWorker(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, allowModules: boolean): SymbolAccessibilityResult { + function isSymbolAccessibleWorker(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, allowModules: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult { if (symbol && enclosingDeclaration) { const result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible, allowModules); if (result) { @@ -4183,7 +4183,8 @@ namespace ts { return { accessibility: SymbolAccessibility.CannotBeNamed, errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), - errorModuleName: symbolToString(symbolExternalModule) + errorModuleName: symbolToString(symbolExternalModule), + errorNode: trueErrorNode, }; } } @@ -4192,6 +4193,7 @@ namespace ts { return { accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), + errorNode: trueErrorNode, }; } @@ -4537,7 +4539,7 @@ namespace ts { } if (type.flags & TypeFlags.UniqueESSymbol) { if (!(context.flags & NodeBuilderFlags.AllowUniqueESSymbolType)) { - if (isValueSymbolAccessible(type.symbol, context.enclosingDeclaration)) { + if (isValueSymbolAccessible(type.symbol, context.enclosingDeclaration, context.trueErrorNode)) { context.approximateLength += 6; return symbolToTypeNode(type.symbol, context, SymbolFlags.Value); } @@ -4585,7 +4587,7 @@ namespace ts { return factory.createThisTypeNode(); } - if (!inTypeAlias && type.aliasSymbol && (context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) { + if (!inTypeAlias && type.aliasSymbol && (context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration, context.trueErrorNode))) { const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context); if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & SymbolFlags.Class)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes); return symbolToTypeNode(type.aliasSymbol, context, SymbolFlags.Type, typeArgumentNodes); @@ -4604,7 +4606,7 @@ namespace ts { } if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams && type.flags & TypeFlags.TypeParameter && - !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration)) { + !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration, context.trueErrorNode)) { const name = typeParameterToName(type, context); context.approximateLength += idText(name).length; return factory.createTypeReferenceNode(factory.createIdentifier(idText(name)), /*typeArguments*/ undefined); @@ -4699,7 +4701,7 @@ namespace ts { function createMappedTypeNodeFromType(type: MappedType) { Debug.assert(!!(type.flags & TypeFlags.Object)); - const readonlyToken = type.declaration.readonlyToken ? factory.createToken(type.declaration.readonlyToken.kind) : undefined; + const readonlyToken = type.declaration.readonlyToken ? factory.createToken(type.declaration.readonlyToken.kind) : undefined; const questionToken = type.declaration.questionToken ? factory.createToken(type.declaration.questionToken.kind) : undefined; let appropriateConstraintTypeNode: TypeNode; if (isMappedTypeWithKeyofConstraintDeclaration(type)) { @@ -4762,7 +4764,7 @@ namespace ts { if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { // typeof is allowed only for static/non local functions return (!!(context.flags & NodeBuilderFlags.UseTypeOfFunction) || (context.visitedTypes?.has(typeId))) && // it is type of the symbol uses itself recursively - (!(context.flags & NodeBuilderFlags.UseStructuralFallback) || isValueSymbolAccessible(symbol, context.enclosingDeclaration)); // And the build is going to succeed without visibility error or there is no structural fallback allowed + (!(context.flags & NodeBuilderFlags.UseStructuralFallback) || isValueSymbolAccessible(symbol, context.enclosingDeclaration, context.trueErrorNode)); // And the build is going to succeed without visibility error or there is no structural fallback allowed } } } @@ -4910,7 +4912,7 @@ namespace ts { else if (context.flags & NodeBuilderFlags.WriteClassExpressionAsTypeLiteral && type.symbol.valueDeclaration && isClassLike(type.symbol.valueDeclaration) && - !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration) + !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration, context.trueErrorNode) ) { return createAnonymousTypeNode(type); } @@ -5967,7 +5969,7 @@ namespace ts { } const sym = resolveEntityName(leftmost, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveALias*/ true); if (sym) { - if (isSymbolAccessible(sym, context.enclosingDeclaration, SymbolFlags.All, /*shouldComputeAliasesToMakeVisible*/ false).accessibility !== SymbolAccessibility.Accessible) { + if (isSymbolAccessible(sym, context.enclosingDeclaration, SymbolFlags.All, /*shouldComputeAliasesToMakeVisible*/ false, context.trueErrorNode).accessibility !== SymbolAccessibility.Accessible) { introducesError = true; } else { @@ -6183,7 +6185,7 @@ namespace ts { tracker: { ...oldcontext.tracker, trackSymbol: (sym, decl, meaning, trueErrorNode) => { - const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeALiases*/ false); + const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeAliases*/ false, trueErrorNode); if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { // Lookup the root symbol of the chain of refs we'll use to access it and serialize it const chain = lookupSymbolChainWorker(sym, context, meaning); @@ -7476,11 +7478,11 @@ namespace ts { // We don't use `isValueSymbolAccessible` below. since that considers alternative containers (like modules) // which we can't write out in a syntactically valid way as an expression - if ((t as TypeReference).target && isSymbolAccessibleByFlags((t as TypeReference).target.symbol, enclosingDeclaration, flags)) { + if ((t as TypeReference).target && isSymbolAccessibleByFlags((t as TypeReference).target.symbol, enclosingDeclaration, flags, context.trueErrorNode)) { typeArgs = map(getTypeArguments(t as TypeReference), t => typeToTypeNodeHelper(t, context)); reference = symbolToExpression((t as TypeReference).target.symbol, context, SymbolFlags.Type); } - else if (t.symbol && isSymbolAccessibleByFlags(t.symbol, enclosingDeclaration, flags)) { + else if (t.symbol && isSymbolAccessibleByFlags(t.symbol, enclosingDeclaration, flags, context.trueErrorNode)) { reference = symbolToExpression(t.symbol, context, SymbolFlags.Type); } if (reference) { diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index bbebb06759410..de3b307576af9 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -111,7 +111,7 @@ namespace ts { refs.set(getOriginalNodeId(container), container); } - function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult, trueErrorNode?: Node) { + function handleSymbolAccessibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) { if (symbolAccessibilityResult.accessibility === SymbolAccessibility.Accessible) { // Add aliases back onto the possible imports list if they're not there so we can try them again with updated visibility info if (symbolAccessibilityResult && symbolAccessibilityResult.aliasesToMakeVisible) { @@ -129,7 +129,7 @@ namespace ts { } else { // Report error - const errorInfo = getSymbolAccessibilityDiagnostic(symbolAccessibilityResult, trueErrorNode); + const errorInfo = getSymbolAccessibilityDiagnostic(symbolAccessibilityResult); if (errorInfo) { if (errorInfo.typeName) { context.addDiagnostic(createDiagnosticForNode(symbolAccessibilityResult.errorNode || errorInfo.errorNode, @@ -156,7 +156,7 @@ namespace ts { function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, trueErrorNode?: Node) { if (symbol.flags & SymbolFlags.TypeParameter) return; - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true), trueErrorNode); + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true, trueErrorNode)); recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning)); } @@ -217,11 +217,11 @@ namespace ts { function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) { const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = (s, trueErrorNode) => ({ + getSymbolAccessibilityDiagnostic = (s) => ({ diagnosticMessage: s.errorModuleName ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, - errorNode: s.errorNode || trueErrorNode || sourceFile + errorNode: s.errorNode || sourceFile }); const result = resolver.getDeclarationStatementsForSourceFile(sourceFile, declarationEmitNodeBuilderFlags, symbolTracker, bundled); getSymbolAccessibilityDiagnostic = oldDiag; diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index d2461f750e61c..ebb453ee83d9a 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -1,6 +1,6 @@ /* @internal */ namespace ts { - export type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult, trueErrorNode: Node | undefined) => (SymbolAccessibilityDiagnostic | undefined); + export type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult) => (SymbolAccessibilityDiagnostic | undefined); export interface SymbolAccessibilityDiagnostic { errorNode: Node; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index aa54e7b87dac0..d83c72f78648e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4171,7 +4171,7 @@ namespace ts { ): Signature; /* @internal */ createSymbol(flags: SymbolFlags, name: __String): TransientSymbol; /* @internal */ createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo; - /* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult; + /* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult; /* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined; /* @internal */ getSymbolWalker(accept?: (symbol: Symbol) => boolean): SymbolWalker; @@ -4598,7 +4598,7 @@ namespace ts { createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; createTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, tracker: SymbolTracker): Expression; - isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags | undefined, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult; + isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags | undefined, shouldComputeAliasToMarkVisible: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult; isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult; // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 8344c3e60ff87..ebbafbb72c15c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2538,7 +2538,7 @@ namespace ts { const notAccessible = () => { typeIsAccessible = false; }; const res = checker.typeToTypeNode(type, enclosingScope, NodeBuilderFlags.NoTruncation, { trackSymbol: (symbol, declaration, meaning) => { - typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning, /*shouldComputeAliasToMarkVisible*/ false).accessibility === SymbolAccessibility.Accessible; + typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning, /*shouldComputeAliasToMarkVisible*/ false, /*trueErrorNode*/undefined).accessibility === SymbolAccessibility.Accessible; }, reportInaccessibleThisError: notAccessible, reportPrivateInBaseOfClassExpression: notAccessible, From 70343e4b729ebe876f7b55e1bd07f54afd8a07b9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 26 Jan 2021 16:38:58 -0800 Subject: [PATCH 3/5] Switch to using enclosingDeclaration Remove trueErrorNode --- src/compiler/checker.ts | 65 +++++++++---------- src/compiler/transformers/declarations.ts | 8 +-- .../transformers/declarations/diagnostics.ts | 10 ++- src/compiler/types.ts | 6 +- src/services/utilities.ts | 2 +- ...onsClassImplementsGenericsSerialization.js | 2 +- ...ationsImportAliasExposedWithinNamespace.js | 2 +- ...onsImportAliasExposedWithinNamespaceCjs.js | 2 +- ...ameterTagReusesInputNodeInEmit1.errors.txt | 4 +- 9 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 553130ae1fcfa..e9a915a4cc111 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4072,18 +4072,18 @@ namespace ts { return false; } - function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, trueErrorNode: Node | undefined): boolean { - const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true, trueErrorNode); + function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined): boolean { + const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true); return access.accessibility === SymbolAccessibility.Accessible; } - function isValueSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, trueErrorNode: Node | undefined): boolean { - const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Value, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true, trueErrorNode); + function isValueSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined): boolean { + const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Value, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true); return access.accessibility === SymbolAccessibility.Accessible; } - function isSymbolAccessibleByFlags(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, flags: SymbolFlags, trueErrorNode: Node | undefined): boolean { - const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, flags, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ false, trueErrorNode); + function isSymbolAccessibleByFlags(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, flags: SymbolFlags): boolean { + const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, flags, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ false); return access.accessibility === SymbolAccessibility.Accessible; } @@ -4162,11 +4162,11 @@ namespace ts { * @param meaning a SymbolFlags to check if such meaning of the symbol is accessible * @param shouldComputeAliasToMakeVisible a boolean value to indicate whether to return aliases to be mark visible in case the symbol is accessible */ - function isSymbolAccessible(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult { - return isSymbolAccessibleWorker(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible, /*allowModules*/ true, trueErrorNode); + function isSymbolAccessible(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean): SymbolAccessibilityResult { + return isSymbolAccessibleWorker(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible, /*allowModules*/ true); } - function isSymbolAccessibleWorker(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, allowModules: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult { + function isSymbolAccessibleWorker(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, allowModules: boolean): SymbolAccessibilityResult { if (symbol && enclosingDeclaration) { const result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible, allowModules); if (result) { @@ -4184,7 +4184,7 @@ namespace ts { accessibility: SymbolAccessibility.CannotBeNamed, errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), errorModuleName: symbolToString(symbolExternalModule), - errorNode: trueErrorNode, + errorNode: isInJSFile(enclosingDeclaration) ? enclosingDeclaration : undefined, }; } } @@ -4193,7 +4193,6 @@ namespace ts { return { accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: symbolToString(symbol, enclosingDeclaration, meaning), - errorNode: trueErrorNode, }; } @@ -4539,7 +4538,7 @@ namespace ts { } if (type.flags & TypeFlags.UniqueESSymbol) { if (!(context.flags & NodeBuilderFlags.AllowUniqueESSymbolType)) { - if (isValueSymbolAccessible(type.symbol, context.enclosingDeclaration, context.trueErrorNode)) { + if (isValueSymbolAccessible(type.symbol, context.enclosingDeclaration)) { context.approximateLength += 6; return symbolToTypeNode(type.symbol, context, SymbolFlags.Value); } @@ -4587,7 +4586,7 @@ namespace ts { return factory.createThisTypeNode(); } - if (!inTypeAlias && type.aliasSymbol && (context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration, context.trueErrorNode))) { + if (!inTypeAlias && type.aliasSymbol && (context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) { const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context); if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & SymbolFlags.Class)) return factory.createTypeReferenceNode(factory.createIdentifier(""), typeArgumentNodes); return symbolToTypeNode(type.aliasSymbol, context, SymbolFlags.Type, typeArgumentNodes); @@ -4606,7 +4605,7 @@ namespace ts { } if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams && type.flags & TypeFlags.TypeParameter && - !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration, context.trueErrorNode)) { + !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration)) { const name = typeParameterToName(type, context); context.approximateLength += idText(name).length; return factory.createTypeReferenceNode(factory.createIdentifier(idText(name)), /*typeArguments*/ undefined); @@ -4764,7 +4763,7 @@ namespace ts { if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { // typeof is allowed only for static/non local functions return (!!(context.flags & NodeBuilderFlags.UseTypeOfFunction) || (context.visitedTypes?.has(typeId))) && // it is type of the symbol uses itself recursively - (!(context.flags & NodeBuilderFlags.UseStructuralFallback) || isValueSymbolAccessible(symbol, context.enclosingDeclaration, context.trueErrorNode)); // And the build is going to succeed without visibility error or there is no structural fallback allowed + (!(context.flags & NodeBuilderFlags.UseStructuralFallback) || isValueSymbolAccessible(symbol, context.enclosingDeclaration)); // And the build is going to succeed without visibility error or there is no structural fallback allowed } } } @@ -4912,7 +4911,7 @@ namespace ts { else if (context.flags & NodeBuilderFlags.WriteClassExpressionAsTypeLiteral && type.symbol.valueDeclaration && isClassLike(type.symbol.valueDeclaration) && - !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration, context.trueErrorNode) + !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration) ) { return createAnonymousTypeNode(type); } @@ -5413,12 +5412,12 @@ namespace ts { const firstIdentifier = getFirstIdentifier(accessExpression); const name = resolveName(firstIdentifier, firstIdentifier.escapedText, SymbolFlags.Value | SymbolFlags.ExportValue, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ true); if (name) { - context.tracker.trackSymbol(name, enclosingDeclaration, SymbolFlags.Value, context.trueErrorNode); + context.tracker.trackSymbol(name, enclosingDeclaration, SymbolFlags.Value); } } function lookupSymbolChain(symbol: Symbol, context: NodeBuilderContext, meaning: SymbolFlags, yieldModuleSymbol?: boolean) { - context.tracker.trackSymbol!(symbol, context.enclosingDeclaration, meaning, context.trueErrorNode); // TODO: GH#18217 + context.tracker.trackSymbol!(symbol, context.enclosingDeclaration, meaning); // TODO: GH#18217 return lookupSymbolChainWorker(symbol, context, meaning, yieldModuleSymbol); } @@ -5969,11 +5968,11 @@ namespace ts { } const sym = resolveEntityName(leftmost, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveALias*/ true); if (sym) { - if (isSymbolAccessible(sym, context.enclosingDeclaration, SymbolFlags.All, /*shouldComputeAliasesToMakeVisible*/ false, context.trueErrorNode).accessibility !== SymbolAccessibility.Accessible) { + if (isSymbolAccessible(sym, context.enclosingDeclaration, SymbolFlags.All, /*shouldComputeAliasesToMakeVisible*/ false).accessibility !== SymbolAccessibility.Accessible) { introducesError = true; } else { - context.tracker?.trackSymbol?.(sym, context.enclosingDeclaration, SymbolFlags.All, context.trueErrorNode); + context.tracker?.trackSymbol?.(sym, context.enclosingDeclaration, SymbolFlags.All); includePrivateSymbol?.(sym); } if (isIdentifier(node)) { @@ -6184,8 +6183,8 @@ namespace ts { remappedSymbolNames: new Map(), tracker: { ...oldcontext.tracker, - trackSymbol: (sym, decl, meaning, trueErrorNode) => { - const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeAliases*/ false, trueErrorNode); + trackSymbol: (sym, decl, meaning) => { + const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeAliases*/ false); if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { // Lookup the root symbol of the chain of refs we'll use to access it and serialize it const chain = lookupSymbolChainWorker(sym, context, meaning); @@ -6194,7 +6193,7 @@ namespace ts { } } else if (oldcontext.tracker && oldcontext.tracker.trackSymbol) { - oldcontext.tracker.trackSymbol(sym, decl, meaning, trueErrorNode); + oldcontext.tracker.trackSymbol(sym, decl, meaning); } } } @@ -6507,7 +6506,7 @@ namespace ts { ), ModifierFlags.None ); - context.tracker.trackSymbol!(type.symbol, context.enclosingDeclaration, SymbolFlags.Value, context.trueErrorNode); + context.tracker.trackSymbol!(type.symbol, context.enclosingDeclaration, SymbolFlags.Value); } else { const statement = setTextRange(factory.createVariableStatement(/*modifiers*/ undefined, factory.createVariableDeclarationList([ @@ -6627,16 +6626,17 @@ namespace ts { function addResult(node: Statement, additionalModifierFlags: ModifierFlags) { if (canHaveModifiers(node)) { let newModifierFlags: ModifierFlags = ModifierFlags.None; + const enclosingDeclaration = context.enclosingDeclaration && + (isJSDocTypeAlias(context.enclosingDeclaration) ? getSourceFileOfNode(context.enclosingDeclaration) : context.enclosingDeclaration); if (additionalModifierFlags & ModifierFlags.Export && - context.enclosingDeclaration && - (isExportingScope(context.enclosingDeclaration) || isModuleDeclaration(context.enclosingDeclaration)) && + enclosingDeclaration && (isExportingScope(enclosingDeclaration) || isModuleDeclaration(enclosingDeclaration)) && canHaveExportModifier(node) ) { // Classes, namespaces, variables, functions, interfaces, and types should all be `export`ed in a module context if not private newModifierFlags |= ModifierFlags.Export; } if (addingDeclare && !(newModifierFlags & ModifierFlags.Export) && - (!context.enclosingDeclaration || !(context.enclosingDeclaration.flags & NodeFlags.Ambient)) && + (!enclosingDeclaration || !(enclosingDeclaration.flags & NodeFlags.Ambient)) && (isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || isModuleDeclaration(node))) { // Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope newModifierFlags |= ModifierFlags.Ambient; @@ -6659,9 +6659,9 @@ namespace ts { const commentText = jsdocAliasDecl ? jsdocAliasDecl.comment || jsdocAliasDecl.parent.comment : undefined; const oldFlags = context.flags; - const oldTrueErrorNode = context.trueErrorNode; - context.trueErrorNode = jsdocAliasDecl; context.flags |= NodeBuilderFlags.InTypeAlias; + const oldEnclosingDecl = context.enclosingDeclaration; + context.enclosingDeclaration = jsdocAliasDecl; const typeNode = jsdocAliasDecl && jsdocAliasDecl.typeExpression && isJSDocTypeExpression(jsdocAliasDecl.typeExpression) && serializeExistingTypeNode(context, jsdocAliasDecl.typeExpression.type, includePrivateSymbol, bundled) @@ -6671,7 +6671,7 @@ namespace ts { !commentText ? [] : [{ kind: SyntaxKind.MultiLineCommentTrivia, text: "*\n * " + commentText.replace(/\n/g, "\n * ") + "\n ", pos: -1, end: -1, hasTrailingNewLine: true }] ), modifierFlags); context.flags = oldFlags; - context.trueErrorNode = oldTrueErrorNode; + context.enclosingDeclaration = oldEnclosingDecl; } function serializeInterface(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) { @@ -7478,11 +7478,11 @@ namespace ts { // We don't use `isValueSymbolAccessible` below. since that considers alternative containers (like modules) // which we can't write out in a syntactically valid way as an expression - if ((t as TypeReference).target && isSymbolAccessibleByFlags((t as TypeReference).target.symbol, enclosingDeclaration, flags, context.trueErrorNode)) { + if ((t as TypeReference).target && isSymbolAccessibleByFlags((t as TypeReference).target.symbol, enclosingDeclaration, flags)) { typeArgs = map(getTypeArguments(t as TypeReference), t => typeToTypeNodeHelper(t, context)); reference = symbolToExpression((t as TypeReference).target.symbol, context, SymbolFlags.Type); } - else if (t.symbol && isSymbolAccessibleByFlags(t.symbol, enclosingDeclaration, flags, context.trueErrorNode)) { + else if (t.symbol && isSymbolAccessibleByFlags(t.symbol, enclosingDeclaration, flags)) { reference = symbolToExpression(t.symbol, context, SymbolFlags.Type); } if (reference) { @@ -7634,7 +7634,6 @@ namespace ts { inferTypeParameters: TypeParameter[] | undefined; approximateLength: number; truncating?: boolean; - trueErrorNode?: Node; typeParameterSymbolList?: Set; typeParameterNames?: ESMap; typeParameterNamesByText?: Set; diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index de3b307576af9..a6dab51d9c8ab 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -154,9 +154,9 @@ namespace ts { } } - function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags, trueErrorNode?: Node) { + function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { if (symbol.flags & SymbolFlags.TypeParameter) return; - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true, trueErrorNode)); + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true)); recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning)); } @@ -217,12 +217,12 @@ namespace ts { function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) { const oldDiag = getSymbolAccessibilityDiagnostic; - getSymbolAccessibilityDiagnostic = (s) => ({ + getSymbolAccessibilityDiagnostic = (s) => (s.errorNode && canProduceDiagnostics(s.errorNode) ? createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({ diagnosticMessage: s.errorModuleName ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, errorNode: s.errorNode || sourceFile - }); + })); const result = resolver.getDeclarationStatementsForSourceFile(sourceFile, declarationEmitNodeBuilderFlags, symbolTracker, bundled); getSymbolAccessibilityDiagnostic = oldDiag; return result; diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index ebb453ee83d9a..5f6f599c5cf79 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -27,7 +27,10 @@ namespace ts { | TypeAliasDeclaration | ConstructorDeclaration | IndexSignatureDeclaration - | PropertyAccessExpression; + | PropertyAccessExpression + | JSDocTypedefTag + | JSDocCallbackTag + | JSDocEnumTag; export function canProduceDiagnostics(node: Node): node is DeclarationDiagnosticProducing { return isVariableDeclaration(node) || @@ -48,7 +51,8 @@ namespace ts { isTypeAliasDeclaration(node) || isConstructorDeclaration(node) || isIndexSignatureDeclaration(node) || - isPropertyAccessExpression(node); + isPropertyAccessExpression(node) || + isJSDocTypeAlias(node); } export function createGetSymbolAccessibilityDiagnosticForNodeName(node: DeclarationDiagnosticProducing) { @@ -149,7 +153,7 @@ namespace ts { else if (isImportEqualsDeclaration(node)) { return getImportEntityNameVisibilityError; } - else if (isTypeAliasDeclaration(node)) { + else if (isTypeAliasDeclaration(node) || isJSDocTypeAlias(node)) { return getTypeAliasDeclarationVisibilityError; } else { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d83c72f78648e..4352e2f2171e3 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4171,7 +4171,7 @@ namespace ts { ): Signature; /* @internal */ createSymbol(flags: SymbolFlags, name: __String): TransientSymbol; /* @internal */ createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo; - /* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult; + /* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult; /* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined; /* @internal */ getSymbolWalker(accept?: (symbol: Symbol) => boolean): SymbolWalker; @@ -4598,7 +4598,7 @@ namespace ts { createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; createTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode | undefined; createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, tracker: SymbolTracker): Expression; - isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags | undefined, shouldComputeAliasToMarkVisible: boolean, trueErrorNode: Node | undefined): SymbolAccessibilityResult; + isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags | undefined, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult; isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult; // Returns the constant value this property access resolves to, or 'undefined' for a non-constant getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined; @@ -7966,7 +7966,7 @@ namespace ts { // Called when the symbol writer encounters a symbol to write. Currently only used by the // declaration emitter to help determine if it should patch up the final declaration file // with import statements it previously saw (but chose not to emit). - trackSymbol?(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, trueErrorNode: Node | undefined): void; + trackSymbol?(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags): void; reportInaccessibleThisError?(): void; reportPrivateInBaseOfClassExpression?(propertyName: string): void; reportInaccessibleUniqueSymbolError?(): void; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index ebbafbb72c15c..8344c3e60ff87 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2538,7 +2538,7 @@ namespace ts { const notAccessible = () => { typeIsAccessible = false; }; const res = checker.typeToTypeNode(type, enclosingScope, NodeBuilderFlags.NoTruncation, { trackSymbol: (symbol, declaration, meaning) => { - typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning, /*shouldComputeAliasToMarkVisible*/ false, /*trueErrorNode*/undefined).accessibility === SymbolAccessibility.Accessible; + typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning, /*shouldComputeAliasToMarkVisible*/ false).accessibility === SymbolAccessibility.Accessible; }, reportInaccessibleThisError: notAccessible, reportPrivateInBaseOfClassExpression: notAccessible, diff --git a/tests/baselines/reference/jsDeclarationsClassImplementsGenericsSerialization.js b/tests/baselines/reference/jsDeclarationsClassImplementsGenericsSerialization.js index 04fbe98c54625..285cdae7b42b8 100644 --- a/tests/baselines/reference/jsDeclarationsClassImplementsGenericsSerialization.js +++ b/tests/baselines/reference/jsDeclarationsClassImplementsGenericsSerialization.js @@ -68,4 +68,4 @@ export class Encoder implements IEncoder { */ encode(value: T): Uint8Array; } -export type IEncoder = import("./interface").Encoder; +export type IEncoder = import('./interface').Encoder; diff --git a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js index bc85ba95d0de5..cb8fe79110dfe 100644 --- a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js +++ b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespace.js @@ -60,7 +60,7 @@ export namespace myTypes { /** * - Prop 1. */ - prop1: typeA; + prop1: myTypes.typeA; /** * - Prop 2. */ diff --git a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js index f635869cea711..bd27e71768a9e 100644 --- a/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js +++ b/tests/baselines/reference/jsDeclarationsImportAliasExposedWithinNamespaceCjs.js @@ -68,7 +68,7 @@ export namespace myTypes { /** * - Prop 1. */ - prop1: typeA; + prop1: myTypes.typeA; /** * - Prop 2. */ diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt index 525c1997ffff0..3bb07e1f856b6 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS9006: Declaration emit for this file requires using private name 'Base' from module '"tests/cases/conformance/jsdoc/declarations/base"'. An explicit type annotation may unblock declaration emit. +tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. ==== tests/cases/conformance/jsdoc/declarations/base.js (0 errors) ==== @@ -17,7 +17,7 @@ tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS9006: Declarati ==== tests/cases/conformance/jsdoc/declarations/file.js (1 errors) ==== /** @typedef {import('./base')} BaseFactory */ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS9006: Declaration emit for this file requires using private name 'Base' from module '"tests/cases/conformance/jsdoc/declarations/base"'. An explicit type annotation may unblock declaration emit. +!!! error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. /** * From 8f60abb061412fe9b0cdeab46ce68878ea205a92 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 26 Jan 2021 16:48:13 -0800 Subject: [PATCH 4/5] add test of @callback and @enum --- ...ParameterTagReusesInputNodeInEmit1.errors.txt | 16 +++++++++++++++- ...arationsParameterTagReusesInputNodeInEmit1.js | 12 ++++++++++++ ...onsParameterTagReusesInputNodeInEmit1.symbols | 13 ++++++++++--- ...tionsParameterTagReusesInputNodeInEmit1.types | 8 ++++++++ ...arationsParameterTagReusesInputNodeInEmit1.ts | 6 ++++++ 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt index 3bb07e1f856b6..0efc3b8e61733 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt @@ -1,4 +1,6 @@ tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. +tests/cases/conformance/jsdoc/declarations/file.js(3,4): error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'. +tests/cases/conformance/jsdoc/declarations/file.js(6,5): error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'. ==== tests/cases/conformance/jsdoc/declarations/base.js (0 errors) ==== @@ -14,10 +16,22 @@ tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS4081: Exported module.exports = BaseFactory; -==== tests/cases/conformance/jsdoc/declarations/file.js (1 errors) ==== +==== tests/cases/conformance/jsdoc/declarations/file.js (3 errors) ==== /** @typedef {import('./base')} BaseFactory */ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. + /** + * @callback BaseFactoryFactory + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * @param {import('./base')} factory + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + ~ +!!! error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'. + /** @enum {import('./base')} BaseFactoryFactoryRegistry */ + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'. + const couldntThinkOfAny = {} /** * diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js index c4a5b8c5018a1..6cbee5975c193 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -15,6 +15,12 @@ module.exports = BaseFactory; //// [file.js] /** @typedef {import('./base')} BaseFactory */ +/** + * @callback BaseFactoryFactory + * @param {import('./base')} factory + */ +/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +const couldntThinkOfAny = {} /** * @@ -37,6 +43,12 @@ BaseFactory.Base = Base; module.exports = BaseFactory; //// [file.js] /** @typedef {import('./base')} BaseFactory */ +/** + * @callback BaseFactoryFactory + * @param {import('./base')} factory + */ +/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +const couldntThinkOfAny = {}; /** * * @param {InstanceType} base diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols index d927bfa797baf..c04f6aa725f5a 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols @@ -27,6 +27,13 @@ module.exports = BaseFactory; === tests/cases/conformance/jsdoc/declarations/file.js === /** @typedef {import('./base')} BaseFactory */ +/** + * @callback BaseFactoryFactory + * @param {import('./base')} factory + */ +/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +const couldntThinkOfAny = {} +>couldntThinkOfAny : Symbol(couldntThinkOfAny, Decl(file.js, 6, 5), Decl(file.js, 5, 4)) /** * @@ -34,11 +41,11 @@ module.exports = BaseFactory; * @returns {InstanceType} */ const test = (base) => { ->test : Symbol(test, Decl(file.js, 7, 5)) ->base : Symbol(base, Decl(file.js, 7, 14)) +>test : Symbol(test, Decl(file.js, 13, 5)) +>base : Symbol(base, Decl(file.js, 13, 14)) return base; ->base : Symbol(base, Decl(file.js, 7, 14)) +>base : Symbol(base, Decl(file.js, 13, 14)) }; diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types index 0c45177a183b3..cbce276b5a080 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types @@ -31,6 +31,14 @@ module.exports = BaseFactory; === tests/cases/conformance/jsdoc/declarations/file.js === /** @typedef {import('./base')} BaseFactory */ +/** + * @callback BaseFactoryFactory + * @param {import('./base')} factory + */ +/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +const couldntThinkOfAny = {} +>couldntThinkOfAny : {} +>{} : {} /** * diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts index 6fe01d7b515b3..4167ed36cb117 100644 --- a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts @@ -18,6 +18,12 @@ module.exports = BaseFactory; // @filename: file.js /** @typedef {import('./base')} BaseFactory */ +/** + * @callback BaseFactoryFactory + * @param {import('./base')} factory + */ +/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +const couldntThinkOfAny = {} /** * From a215bd2fac583edc57bb39fcc2b80863a6902b8a Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 27 Jan 2021 16:50:39 -0800 Subject: [PATCH 5/5] Better error + fix @enum error Since enums don't have a name property, you *have* to call `getNameOfDeclaration` to go looking through the AST for one. --- src/compiler/checker.ts | 1 - src/compiler/diagnosticMessages.json | 4 ++++ .../transformers/declarations/diagnostics.ts | 12 +++++++----- ...ParameterTagReusesInputNodeInEmit1.errors.txt | 16 ++++++++-------- ...arationsParameterTagReusesInputNodeInEmit1.js | 4 ++-- ...onsParameterTagReusesInputNodeInEmit1.symbols | 2 +- ...tionsParameterTagReusesInputNodeInEmit1.types | 2 +- ...arationsParameterTagReusesInputNodeInEmit1.ts | 2 +- 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e9a915a4cc111..13a97c9ef2702 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6656,7 +6656,6 @@ namespace ts { const typeParams = getSymbolLinks(symbol).typeParameters; const typeParamDecls = map(typeParams, p => typeParameterToDeclaration(p, context)); const jsdocAliasDecl = find(symbol.declarations, isJSDocTypeAlias); - const commentText = jsdocAliasDecl ? jsdocAliasDecl.comment || jsdocAliasDecl.parent.comment : undefined; const oldFlags = context.flags; context.flags |= NodeBuilderFlags.InTypeAlias; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 99cb2d5a6f238..6fa1d5fb476a8 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3537,6 +3537,10 @@ "category": "Error", "code": 4083 }, + "Exported type alias '{0}' has or is using private name '{1}' from module {2}.": { + "category": "Error", + "code": 4084 + }, "Conflicting definitions for '{0}' found at '{1}' and '{2}'. Consider installing a specific version of this library to resolve the conflict.": { "category": "Error", "code": 4090 diff --git a/src/compiler/transformers/declarations/diagnostics.ts b/src/compiler/transformers/declarations/diagnostics.ts index 5f6f599c5cf79..7be27b453a0d2 100644 --- a/src/compiler/transformers/declarations/diagnostics.ts +++ b/src/compiler/transformers/declarations/diagnostics.ts @@ -128,7 +128,7 @@ namespace ts { } } - export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationDiagnosticProducing): (symbolAccessibilityResult: SymbolAccessibilityResult) => SymbolAccessibilityDiagnostic | undefined { + export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationDiagnosticProducing): GetSymbolAccessibilityDiagnostic { if (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isPropertyAccessExpression(node) || isBindingElement(node) || isConstructorDeclaration(node)) { return getVariableDeclarationTypeVisibilityError; } @@ -478,11 +478,13 @@ namespace ts { }; } - function getTypeAliasDeclarationVisibilityError(): SymbolAccessibilityDiagnostic { + function getTypeAliasDeclarationVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { return { - diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, - errorNode: (node as TypeAliasDeclaration).type, - typeName: (node as TypeAliasDeclaration).name + diagnosticMessage: symbolAccessibilityResult.errorModuleName + ? Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1_from_module_2 + : Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, + errorNode: isJSDocTypeAlias(node) ? Debug.checkDefined(node.typeExpression) : (node as TypeAliasDeclaration).type, + typeName: isJSDocTypeAlias(node) ? getNameOfDeclaration(node) : (node as TypeAliasDeclaration).name, }; } } diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt index 0efc3b8e61733..882a221dfef9a 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. -tests/cases/conformance/jsdoc/declarations/file.js(3,4): error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'. -tests/cases/conformance/jsdoc/declarations/file.js(6,5): error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'. +tests/cases/conformance/jsdoc/declarations/file.js(1,5): error TS4084: Exported type alias 'BaseFactory' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base". +tests/cases/conformance/jsdoc/declarations/file.js(3,4): error TS4084: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base". +tests/cases/conformance/jsdoc/declarations/file.js(6,5): error TS4084: Exported type alias 'couldntThinkOfAny' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base". ==== tests/cases/conformance/jsdoc/declarations/base.js (0 errors) ==== @@ -19,7 +19,7 @@ tests/cases/conformance/jsdoc/declarations/file.js(6,5): error TS4081: Exported ==== tests/cases/conformance/jsdoc/declarations/file.js (3 errors) ==== /** @typedef {import('./base')} BaseFactory */ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4081: Exported type alias 'BaseFactory' has or is using private name 'Base'. +!!! error TS4084: Exported type alias 'BaseFactory' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base". /** * @callback BaseFactoryFactory ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -27,10 +27,10 @@ tests/cases/conformance/jsdoc/declarations/file.js(6,5): error TS4081: Exported ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ ~ -!!! error TS4081: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base'. - /** @enum {import('./base')} BaseFactoryFactoryRegistry */ - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4081: Exported type alias 'Base' has or is using private name '"tests/cases/conformance/jsdoc/declarations/base"'. +!!! error TS4084: Exported type alias 'BaseFactoryFactory' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base". + /** @enum {import('./base')} */ + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4084: Exported type alias 'couldntThinkOfAny' has or is using private name 'Base' from module "tests/cases/conformance/jsdoc/declarations/base". const couldntThinkOfAny = {} /** diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js index 6cbee5975c193..fb4abcb308f4b 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -19,7 +19,7 @@ module.exports = BaseFactory; * @callback BaseFactoryFactory * @param {import('./base')} factory */ -/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +/** @enum {import('./base')} */ const couldntThinkOfAny = {} /** @@ -47,7 +47,7 @@ module.exports = BaseFactory; * @callback BaseFactoryFactory * @param {import('./base')} factory */ -/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +/** @enum {import('./base')} */ const couldntThinkOfAny = {}; /** * diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols index c04f6aa725f5a..0d20e28fa52cc 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.symbols @@ -31,7 +31,7 @@ module.exports = BaseFactory; * @callback BaseFactoryFactory * @param {import('./base')} factory */ -/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +/** @enum {import('./base')} */ const couldntThinkOfAny = {} >couldntThinkOfAny : Symbol(couldntThinkOfAny, Decl(file.js, 6, 5), Decl(file.js, 5, 4)) diff --git a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types index cbce276b5a080..17f9522ca5cf3 100644 --- a/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types +++ b/tests/baselines/reference/jsDeclarationsParameterTagReusesInputNodeInEmit1.types @@ -35,7 +35,7 @@ module.exports = BaseFactory; * @callback BaseFactoryFactory * @param {import('./base')} factory */ -/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +/** @enum {import('./base')} */ const couldntThinkOfAny = {} >couldntThinkOfAny : {} >{} : {} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts index 4167ed36cb117..28a293ee63191 100644 --- a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsParameterTagReusesInputNodeInEmit1.ts @@ -22,7 +22,7 @@ module.exports = BaseFactory; * @callback BaseFactoryFactory * @param {import('./base')} factory */ -/** @enum {import('./base')} BaseFactoryFactoryRegistry */ +/** @enum {import('./base')} */ const couldntThinkOfAny = {} /**