Sitelet https://github.com/angular/angular/pull/38775
Skip to content

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

Closed
petebacondarwin wants to merge 8 commits into
angular:masterfrom
petebacondarwin:linker-translator
Closed

petebacondarwin wants to merge 8 commits into
angular:masterfrom
petebacondarwin:linker-translator

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Sep 9, 2020 •

Copy link
Copy Markdown
Contributor

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
@petebacondarwin
petebacondarwin force-pushed the linker-translator branch 8 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

@JoostK JoostK left a comment

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.

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

Comment thread packages/compiler-cli/ngcc/src/rendering/esm_rendering_formatter.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/transform/src/transform.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/import_generator.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/import_generator.ts Outdated

@josephperrott josephperrott left a comment

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.

LGTM,

Reviewed-for: dev-infra

Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/import_manager.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/typecheck/src/environment.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/typescript_ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
Comment thread packages/compiler-cli/src/ngtsc/translator/src/api/ast_factory.ts Outdated
@AndrewKushnir

Copy link
Copy Markdown
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
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
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
Copy Markdown
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

JoostK commented Sep 28, 2020

Copy link
Copy Markdown
Member

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

@petebacondarwin

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

Got it. Thank you for explaining. (:

@angular-automatic-lock-bot

Copy link
Copy Markdown

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

None yet

Development

Successfully merging this pull request may close these issues.

8 participants