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
fix(compiler-cli): generate proper exports.* identifiers in cjs output #22564
Conversation
prefixIdent ? ts.createPropertyAccess(prefixIdent, name !) : ts.createIdentifier(name !); | ||
return result; | ||
if (prefixIdent) { | ||
return ts.createPropertyAccess(prefixIdent, name !); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove !
as we discussed.
@@ -166,6 +173,19 @@ class _NodeEmitterVisitor implements StatementVisitor, ExpressionVisitor { | |||
private _importsWithPrefixes = new Map<string, string>(); | |||
private _reexports = new Map<string, {name: string, as: string}[]>(); | |||
private _templateSources = new Map<ParseSourceFile, ts.SourceMapSource>(); | |||
private _exportedVariableIdentifiers = new Map<string, ts.Identifier>(); | |||
|
|||
loadExportedVariableIdentifiers(sourceFile: ts.SourceFile): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment explaining why we only collect variable references and not classes.
You can preview ca6faa7 at https://pr22564-ca6faa7.ngbuilds.io/. |
ca6faa7
to
226b872
Compare
You can preview 226b872 at https://pr22564-226b872.ngbuilds.io/. |
When the compiler generates a reference to an exported variable in the same file, it inserts a synthetic ts.Identifier node. In CommonJS output, this synthetic node would not be properly rewritten with an `exports.` prefix. This change sets the TS original node property on the synthetic node we generate, which ensures TS knows to rewrite it in CommonJS output.
226b872
to
c04e89b
Compare
You can preview c04e89b at https://pr22564-c04e89b.ngbuilds.io/. |
angular#22564) When the compiler generates a reference to an exported variable in the same file, it inserts a synthetic ts.Identifier node. In CommonJS output, this synthetic node would not be properly rewritten with an `exports.` prefix. This change sets the TS original node property on the synthetic node we generate, which ensures TS knows to rewrite it in CommonJS output. PR Close angular#22564
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
When the compiler generates a reference to an exported variable in the
same file, it inserts a synthetic ts.Identifier node. In CommonJS
output, this synthetic node would not be properly rewritten with an
exports.
prefix.This change sets the TS original node property on the synthetic node
we generate, which ensures TS knows to rewrite it in CommonJS output.