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

refactor(compiler-cli): make the output AST translator generic #38775

Closed

Conversation

petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Sep 9, 2020

This commit refactors the ExpressionTranslatorVisitor so that it
is not tied directly to the TypeScript AST. Instead it uses generic
TExpression and TStatement types that are then converted
to concrete types by the TypeScriptAstFactory.

This paves the way for a BabelAstFactory that can be used to
generate Babel AST nodes instead of TypeScript, which will be
part of the new linker tool.

@petebacondarwin petebacondarwin added state: WIP area: compiler Issues related to `ngc`, Angular's template compiler target: minor This PR is targeted for the next minor release labels Sep 9, 2020
@ngbot ngbot bot modified the milestone: needsTriage Sep 9, 2020
@JoostK JoostK added this to In progress in ng-linker via automation Sep 10, 2020
@petebacondarwin petebacondarwin force-pushed the linker-translator branch 7 times, most recently from 7a1eadb to 5a0fa33 Compare September 15, 2020 20:02
@petebacondarwin petebacondarwin force-pushed the linker-translator branch 2 times, most recently from 227d5b2 to 8accc38 Compare September 15, 2020 21:16
@petebacondarwin petebacondarwin marked this pull request as ready for review September 16, 2020 09:44
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

I did a very quick initial pass over this, I plan to go over it again.

@JoostK JoostK moved this from In progress to Review in progress in ng-linker Sep 16, 2020
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

LGTM,

Reviewed-for: dev-infra

@AndrewKushnir
Copy link
Contributor

Presubmit #2.

@AndrewKushnir AndrewKushnir removed their request for review September 21, 2020 18:57
@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Sep 21, 2020
@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 21, 2020
@petebacondarwin petebacondarwin moved this from Review in progress to Reviewer approved in ng-linker Sep 21, 2020
The cast to `ts.Identifier` was a hack that "just happened to work".
The new approach is more robust and doesn't have to undermine
the type checker.
These imports are not used and so are just bloating the code unnecessarily
Using an interface makes the code cleaner and more readable.
This change also adds the `range` property to the type to be used
for source-mapping.
When the target of the compiler is ES2015 or newer then we should
be generating `let` and `const` variable declarations rather than `var`.
This file contains a number of classes making it long and hard to work with.
This commit splits the `ImportManager`, `Context` and `TypeTranslatorVisitor`
classes, along with associated functions and types into their own files.
…ator

Previously each identifier was being imported individually, which made for a
very long import statement, but also obscurred, in the code, which identifiers
came from the compiler.
This commit refactors the `ExpressionTranslatorVisitor` so that it
is not tied directly to the TypeScript AST. Instead it uses generic
`TExpression` and `TStatement` types that are then converted
to concrete types by the `TypeScriptAstFactory`.

This paves the way for a `BabelAstFactory` that can be used to
generate Babel AST nodes instead of TypeScript, which will be
part of the new linker tool.
@mhevery mhevery closed this in 856e74a Sep 21, 2020
mhevery pushed a commit that referenced this pull request Sep 21, 2020
These imports are not used and so are just bloating the code unnecessarily

PR Close #38775
ng-linker automation moved this from Reviewer approved to Done Sep 21, 2020
mhevery pushed a commit that referenced this pull request Sep 21, 2020
…38775)

Using an interface makes the code cleaner and more readable.
This change also adds the `range` property to the type to be used
for source-mapping.

PR Close #38775
mhevery pushed a commit that referenced this pull request Sep 21, 2020
When the target of the compiler is ES2015 or newer then we should
be generating `let` and `const` variable declarations rather than `var`.

PR Close #38775
mhevery pushed a commit that referenced this pull request Sep 21, 2020
This file contains a number of classes making it long and hard to work with.
This commit splits the `ImportManager`, `Context` and `TypeTranslatorVisitor`
classes, along with associated functions and types into their own files.

PR Close #38775
mhevery pushed a commit that referenced this pull request Sep 21, 2020
…ator (#38775)

Previously each identifier was being imported individually, which made for a
very long import statement, but also obscurred, in the code, which identifiers
came from the compiler.

PR Close #38775
mhevery pushed a commit that referenced this pull request Sep 21, 2020
This commit refactors the `ExpressionTranslatorVisitor` so that it
is not tied directly to the TypeScript AST. Instead it uses generic
`TExpression` and `TStatement` types that are then converted
to concrete types by the `TypeScriptAstFactory`.

This paves the way for a `BabelAstFactory` that can be used to
generate Babel AST nodes instead of TypeScript, which will be
part of the new linker tool.

PR Close #38775
@petebacondarwin petebacondarwin deleted the linker-translator branch September 21, 2020 19:29
@alfaproject
Copy link
Contributor

OOC, do we need to care about ES5 at all? I thought that we started delegating the responsibility of downleveling to the building tool, like Angular CLI or whatever else, right?

@JoostK
Copy link
Member

JoostK commented Sep 28, 2020

@alfaproject ngcc uses this machinery to emit code into ES5 bundles of libraries.

@petebacondarwin
Copy link
Member Author

In the long run we would not but for now there are plenty of libraries and project setups that rely upon ES5

@alfaproject
Copy link
Contributor

Got it. Thank you for explaining. (:

@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 Oct 29, 2020
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: compiler Issues related to `ngc`, Angular's template compiler cla: yes target: minor This PR is targeted for the next minor release
Projects
No open projects
ng-linker
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants