Skip to content

Commit

Permalink
🤖 Pick PR #58872 (Fix declaration emit crash) into release-5.5 (#58874)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Branch <[email protected]>
  • Loading branch information
TypeScript Bot and andrewbranch committed Jun 17, 2024
1 parent 17933ee commit 45b1e3c
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 10 deletions.
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 @@ -8975,7 +8976,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({});

0 comments on commit 45b1e3c

Please sign in to comment.