Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Pick PR #58872 (Fix declaration emit crash) into release-5.5 #58874

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ import {
isExternalModuleIndicator,
isExternalModuleNameRelative,
isExternalModuleReference,
isExternalModuleSymbol,
isExternalOrCommonJsModule,
isForInOrOfStatement,
isForInStatement,
Expand Down Expand Up @@ -8960,7 +8961,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const parentSymbol = nodeSymbol
&& isSymbolAccessible(nodeSymbol, context.enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible
&& lookupSymbolChain(nodeSymbol, context, meaning, /*yieldModuleSymbol*/ true)[0];
if (parentSymbol && parentSymbol.flags & SymbolFlags.Module) {
if (parentSymbol && isExternalModuleSymbol(parentSymbol)) {
name = getSpecifierForModuleSymbol(parentSymbol, context);
}
else {
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,15 @@ export function isTransientSymbol(symbol: Symbol): symbol is TransientSymbol {
return (symbol.flags & SymbolFlags.Transient) !== 0;
}

/**
* True if the symbol is for an external module, as opposed to a namespace.
*
* @internal
*/
export function isExternalModuleSymbol(moduleSymbol: Symbol): boolean {
return !!(moduleSymbol.flags & SymbolFlags.Module) && (moduleSymbol.escapedName as string).charCodeAt(0) === CharacterCodes.doubleQuote;
}

const stringWriter = createSingleLineStringWriter();

function createSingleLineStringWriter(): EmitTextWriter {
Expand Down
9 changes: 0 additions & 9 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2408,15 +2408,6 @@ export function isTypeKeywordTokenOrIdentifier(node: Node) {
return isTypeKeywordToken(node) || isIdentifier(node) && node.text === "type";
}

/**
* True if the symbol is for an external module, as opposed to a namespace.
*
* @internal
*/
export function isExternalModuleSymbol(moduleSymbol: Symbol): boolean {
return !!(moduleSymbol.flags & SymbolFlags.Module) && moduleSymbol.name.charCodeAt(0) === CharacterCodes.doubleQuote;
}

/**
* Returns `true` the first time it encounters a node and `false` afterwards.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/types.js(3,21): error TS2304: Cannot find name 'Keyword'.
/types.js(3,30): error TS2304: Cannot find name 'ParamValueTyped'.


==== /contractHelper.d.ts (0 errors) ====
export function handleParamGovernance(zcf: any): {
publicMixin: {
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
};
};

==== /exported.d.ts (0 errors) ====
type _ERef<T> = T | Promise<T>;
import { ParamStateRecord as _ParamStateRecord } from './types.js';
declare global {
// @ts-ignore TS2666
export {
_ERef as ERef,
_ParamStateRecord as ParamStateRecord,
};
}

==== /types.js (2 errors) ====
export {};
/**
* @typedef {Record<Keyword, ParamValueTyped>} ParamStateRecord a Record containing
~~~~~~~
!!! error TS2304: Cannot find name 'Keyword'.
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'ParamValueTyped'.
* keyword pairs with descriptions of parameters under governance.
*/

==== /index.js (0 errors) ====
import { handleParamGovernance } from './contractHelper.js';
export const blah = handleParamGovernance({});

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//// [tests/cases/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.ts] ////

//// [contractHelper.d.ts]
export function handleParamGovernance(zcf: any): {
publicMixin: {
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
};
};

//// [exported.d.ts]
type _ERef<T> = T | Promise<T>;
import { ParamStateRecord as _ParamStateRecord } from './types.js';
declare global {
// @ts-ignore TS2666
export {
_ERef as ERef,
_ParamStateRecord as ParamStateRecord,
};
}

//// [types.js]
export {};
/**
* @typedef {Record<Keyword, ParamValueTyped>} ParamStateRecord a Record containing
* keyword pairs with descriptions of parameters under governance.
*/

//// [index.js]
import { handleParamGovernance } from './contractHelper.js';
export const blah = handleParamGovernance({});




//// [types.d.ts]
/**
* a Record containing
* keyword pairs with descriptions of parameters under governance.
*/
export type ParamStateRecord = Record<Keyword, ParamValueTyped>;
//// [index.d.ts]
export const blah: {
publicMixin: {
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @checkJs: true
// @declaration: true
// @module: preserve
// @emitDeclarationOnly: true
// @noTypesAndSymbols: true

// @Filename: /contractHelper.d.ts
export function handleParamGovernance(zcf: any): {
publicMixin: {
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
};
};

// @Filename: /exported.d.ts
type _ERef<T> = T | Promise<T>;
import { ParamStateRecord as _ParamStateRecord } from './types.js';
declare global {
// @ts-ignore TS2666
export {
_ERef as ERef,
_ParamStateRecord as ParamStateRecord,
};
}

// @Filename: /types.js
export {};
/**
* @typedef {Record<Keyword, ParamValueTyped>} ParamStateRecord a Record containing
* keyword pairs with descriptions of parameters under governance.
*/

// @Filename: /index.js
import { handleParamGovernance } from './contractHelper.js';
export const blah = handleParamGovernance({});