Skip to content

Avoid trying to emit anonymous classish/expando functions as assignments - #55472

Merged
Wesley Wigham (weswigham) merged 3 commits into
microsoft:mainfrom
weswigham:js-declarations-global-file
Aug 28, 2023
Merged

Avoid trying to emit anonymous classish/expando functions as assignments#55472
Wesley Wigham (weswigham) merged 3 commits into
microsoft:mainfrom
weswigham:js-declarations-global-file

Conversation

@weswigham

Copy link
Copy Markdown
Member

Fixes #55172

Comment thread src/compiler/checker.ts Outdated
if (!context.remappedSymbolRefernces) {
context.remappedSymbolRefernces = new Map();
}
context.remappedSymbolRefernces.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle the not-anonymous-but-still-an-expression case where you could use that local name to refer to the type of the expando-thing as a whole. Because it'd be odd if just adding a name to the function expression made this transform stop working.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is for cases like

const f = function g() { }
f.p = 1

Does remappedSymbolReferences record g? When would g show up in the declaration emit?

Edit: Looking at the test cases, it's actually g -> f so that when a constructor function g returns g, it serialises as f.

Comment thread src/compiler/checker.ts Outdated
Comment thread src/compiler/checker.ts Outdated
Comment thread src/compiler/checker.ts Outdated
Comment thread src/compiler/checker.ts Outdated
if (!context.remappedSymbolRefernces) {
context.remappedSymbolRefernces = new Map();
}
context.remappedSymbolRefernces.set(getSymbolId(type.symbol), symbol); // save name remapping as local name for target symbol

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is for cases like

const f = function g() { }
f.p = 1

Does remappedSymbolReferences record g? When would g show up in the declaration emit?

Edit: Looking at the test cases, it's actually g -> f so that when a constructor function g returns g, it serialises as f.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsc with allowJs reports TS9005 error for anonymous constructor functions

3 participants