Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Mar 2, 2018

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.

@alxhub alxhub added action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Mar 2, 2018
prefixIdent ? ts.createPropertyAccess(prefixIdent, name !) : ts.createIdentifier(name !);
return result;
if (prefixIdent) {
return ts.createPropertyAccess(prefixIdent, name !);
Copy link
Contributor

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 {
Copy link
Contributor

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.

@mary-poppins
Copy link

You can preview ca6faa7 at https://pr22564-ca6faa7.ngbuilds.io/.

@alxhub alxhub force-pushed the injectable-def-inject-import branch from ca6faa7 to 226b872 Compare March 2, 2018 23:24
@mary-poppins
Copy link

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.
@alxhub alxhub force-pushed the injectable-def-inject-import branch from 226b872 to c04e89b Compare March 5, 2018 16:18
@mary-poppins
Copy link

You can preview c04e89b at https://pr22564-c04e89b.ngbuilds.io/.

@kara kara closed this in 0d8deb0 Mar 9, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants