Skip to content

Commit 45b1e3c

Browse files
TypeScript Botandrewbranch
TypeScript Bot
andauthored
🤖 Pick PR #58872 (Fix declaration emit crash) into release-5.5 (#58874)
Co-authored-by: Andrew Branch <[email protected]>
1 parent 17933ee commit 45b1e3c

6 files changed

+128
-10
lines changed

Diff for: src/compiler/checker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ import {
541541
isExternalModuleIndicator,
542542
isExternalModuleNameRelative,
543543
isExternalModuleReference,
544+
isExternalModuleSymbol,
544545
isExternalOrCommonJsModule,
545546
isForInOrOfStatement,
546547
isForInStatement,
@@ -8975,7 +8976,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
89758976
const parentSymbol = nodeSymbol
89768977
&& isSymbolAccessible(nodeSymbol, context.enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible
89778978
&& lookupSymbolChain(nodeSymbol, context, meaning, /*yieldModuleSymbol*/ true)[0];
8978-
if (parentSymbol && parentSymbol.flags & SymbolFlags.Module) {
8979+
if (parentSymbol && isExternalModuleSymbol(parentSymbol)) {
89798980
name = getSpecifierForModuleSymbol(parentSymbol, context);
89808981
}
89818982
else {

Diff for: src/compiler/utilities.ts

+9
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,15 @@ export function isTransientSymbol(symbol: Symbol): symbol is TransientSymbol {
632632
return (symbol.flags & SymbolFlags.Transient) !== 0;
633633
}
634634

635+
/**
636+
* True if the symbol is for an external module, as opposed to a namespace.
637+
*
638+
* @internal
639+
*/
640+
export function isExternalModuleSymbol(moduleSymbol: Symbol): boolean {
641+
return !!(moduleSymbol.flags & SymbolFlags.Module) && (moduleSymbol.escapedName as string).charCodeAt(0) === CharacterCodes.doubleQuote;
642+
}
643+
635644
const stringWriter = createSingleLineStringWriter();
636645

637646
function createSingleLineStringWriter(): EmitTextWriter {

Diff for: src/services/utilities.ts

-9
Original file line numberDiff line numberDiff line change
@@ -2408,15 +2408,6 @@ export function isTypeKeywordTokenOrIdentifier(node: Node) {
24082408
return isTypeKeywordToken(node) || isIdentifier(node) && node.text === "type";
24092409
}
24102410

2411-
/**
2412-
* True if the symbol is for an external module, as opposed to a namespace.
2413-
*
2414-
* @internal
2415-
*/
2416-
export function isExternalModuleSymbol(moduleSymbol: Symbol): boolean {
2417-
return !!(moduleSymbol.flags & SymbolFlags.Module) && moduleSymbol.name.charCodeAt(0) === CharacterCodes.doubleQuote;
2418-
}
2419-
24202411
/**
24212412
* Returns `true` the first time it encounters a node and `false` afterwards.
24222413
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/types.js(3,21): error TS2304: Cannot find name 'Keyword'.
2+
/types.js(3,30): error TS2304: Cannot find name 'ParamValueTyped'.
3+
4+
5+
==== /contractHelper.d.ts (0 errors) ====
6+
export function handleParamGovernance(zcf: any): {
7+
publicMixin: {
8+
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
9+
};
10+
};
11+
12+
==== /exported.d.ts (0 errors) ====
13+
type _ERef<T> = T | Promise<T>;
14+
import { ParamStateRecord as _ParamStateRecord } from './types.js';
15+
declare global {
16+
// @ts-ignore TS2666
17+
export {
18+
_ERef as ERef,
19+
_ParamStateRecord as ParamStateRecord,
20+
};
21+
}
22+
23+
==== /types.js (2 errors) ====
24+
export {};
25+
/**
26+
* @typedef {Record<Keyword, ParamValueTyped>} ParamStateRecord a Record containing
27+
~~~~~~~
28+
!!! error TS2304: Cannot find name 'Keyword'.
29+
~~~~~~~~~~~~~~~
30+
!!! error TS2304: Cannot find name 'ParamValueTyped'.
31+
* keyword pairs with descriptions of parameters under governance.
32+
*/
33+
34+
==== /index.js (0 errors) ====
35+
import { handleParamGovernance } from './contractHelper.js';
36+
export const blah = handleParamGovernance({});
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//// [tests/cases/compiler/reuseTypeAnnotationImportTypeInGlobalThisTypeArgument.ts] ////
2+
3+
//// [contractHelper.d.ts]
4+
export function handleParamGovernance(zcf: any): {
5+
publicMixin: {
6+
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
7+
};
8+
};
9+
10+
//// [exported.d.ts]
11+
type _ERef<T> = T | Promise<T>;
12+
import { ParamStateRecord as _ParamStateRecord } from './types.js';
13+
declare global {
14+
// @ts-ignore TS2666
15+
export {
16+
_ERef as ERef,
17+
_ParamStateRecord as ParamStateRecord,
18+
};
19+
}
20+
21+
//// [types.js]
22+
export {};
23+
/**
24+
* @typedef {Record<Keyword, ParamValueTyped>} ParamStateRecord a Record containing
25+
* keyword pairs with descriptions of parameters under governance.
26+
*/
27+
28+
//// [index.js]
29+
import { handleParamGovernance } from './contractHelper.js';
30+
export const blah = handleParamGovernance({});
31+
32+
33+
34+
35+
//// [types.d.ts]
36+
/**
37+
* a Record containing
38+
* keyword pairs with descriptions of parameters under governance.
39+
*/
40+
export type ParamStateRecord = Record<Keyword, ParamValueTyped>;
41+
//// [index.d.ts]
42+
export const blah: {
43+
publicMixin: {
44+
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
45+
};
46+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @checkJs: true
2+
// @declaration: true
3+
// @module: preserve
4+
// @emitDeclarationOnly: true
5+
// @noTypesAndSymbols: true
6+
7+
// @Filename: /contractHelper.d.ts
8+
export function handleParamGovernance(zcf: any): {
9+
publicMixin: {
10+
getGovernedParams: () => globalThis.ERef<import("./types.js").ParamStateRecord>;
11+
};
12+
};
13+
14+
// @Filename: /exported.d.ts
15+
type _ERef<T> = T | Promise<T>;
16+
import { ParamStateRecord as _ParamStateRecord } from './types.js';
17+
declare global {
18+
// @ts-ignore TS2666
19+
export {
20+
_ERef as ERef,
21+
_ParamStateRecord as ParamStateRecord,
22+
};
23+
}
24+
25+
// @Filename: /types.js
26+
export {};
27+
/**
28+
* @typedef {Record<Keyword, ParamValueTyped>} ParamStateRecord a Record containing
29+
* keyword pairs with descriptions of parameters under governance.
30+
*/
31+
32+
// @Filename: /index.js
33+
import { handleParamGovernance } from './contractHelper.js';
34+
export const blah = handleParamGovernance({});

0 commit comments

Comments
 (0)