mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 17:05:58 -05:00
Fix a crash when transforming functions in modules. (#34513)
When transforming a module declaration and block, parse tree nodes contained in the module block have their parent pointers reset due to `shouldEmitModuleDeclaration` calling into `isInstantiatedModule`, which needs to set parent pointers to operate. That causes a crash when later transforming any nodes within the module, as retrieving their source file in `getSourceFileOfNode` (via `getOrCreateEmitNode`) fails, due to their new synthesized parent nodes not being in a source file. This change avoids the issue by using the parse tree node in `ts.ts` to decide whether a module declaration should be emitted (i.e. whether the module contains values). This means transformers cannot add values to modules that previously did not contain any. Fixes #34644.
This commit is contained in:
committed by
Andrew Branch
parent
cbbbcfa4c5
commit
ff590b622e
@@ -2452,7 +2452,12 @@ namespace ts {
|
||||
*
|
||||
* @param node The module declaration node.
|
||||
*/
|
||||
function shouldEmitModuleDeclaration(node: ModuleDeclaration) {
|
||||
function shouldEmitModuleDeclaration(nodeIn: ModuleDeclaration) {
|
||||
const node = getParseTreeNode(nodeIn, isModuleDeclaration);
|
||||
if (!node) {
|
||||
// If we can't find a parse tree node, assume the node is instantiated.
|
||||
return true;
|
||||
}
|
||||
return isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user