Skip to content

refactor(compiler): combine call ASTs#42882

Closed
crisbeto wants to merge 3 commits intoangular:masterfrom
crisbeto:ast-call-cleanup
Closed

refactor(compiler): combine call ASTs#42882
crisbeto wants to merge 3 commits intoangular:masterfrom
crisbeto:ast-call-cleanup

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Jul 17, 2021

Currently the compiler has three different classes to represent a "call to something":

  1. MethodCall - foo.bar()
  2. SafeMethodCall - foo?.bar().
  3. FunctionCall - Any calls that don't fit into the first two classes. E.g. foo.bar()().

There are a few problems with this approach:

  1. It is inconsistent with the TypeScript AST which only has one node: CallExpression.
  2. It means that we have to maintain more code, because the various parts of the compiler need to know about three node types.
  3. It doesn't allow us to easily implement some new JS features like safe calls (e.g. foo.bar?.())).

These changes rework the compiler so that it produces only one node: Call. The new node behaves similarly to the TypeScript CallExpression whose receiver can be any expression.

There was a similar situation in the output AST where we had an InvokeMethodExpression and InvokeFunctionExpression. I've combined both of them into InvokeFunctionExpression.

@google-cla google-cla bot added the cla: yes label Jul 17, 2021
@crisbeto crisbeto force-pushed the ast-call-cleanup branch 2 times, most recently from 0120220 to 9968b3b Compare July 18, 2021 16:04
@alxhub alxhub added the area: compiler Issues related to `ngc`, Angular's template compiler label Jul 21, 2021
@ngbot ngbot bot added this to the Backlog milestone Jul 21, 2021
@crisbeto crisbeto force-pushed the ast-call-cleanup branch 3 times, most recently from 79b1771 to 37db16e Compare August 1, 2021 10:37
@crisbeto crisbeto marked this pull request as ready for review August 1, 2021 10:56
@pullapprove pullapprove bot requested review from alxhub and zarend August 1, 2021 10:56
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer refactoring Issue that involves refactoring or code-cleanup target: major This PR is targeted for the next major release labels Aug 1, 2021
@crisbeto crisbeto force-pushed the ast-call-cleanup branch 4 times, most recently from 6b9f01c to c850981 Compare August 3, 2021 15:01
@alxhub
Copy link
Member

alxhub commented Aug 4, 2021

TGP

@crisbeto crisbeto force-pushed the ast-call-cleanup branch 2 times, most recently from 6e5449b to 8921861 Compare August 19, 2021 18:24
Copy link
Contributor

@zarend zarend left a comment

Choose a reason for hiding this comment

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

LGTM

Currently the compiler has three different classes to represent a "call to something":
1. `MethodCall` - `foo.bar()`
2. `SafeMethodCall` - `foo?.bar()`.
3. `FunctionCall` - Any calls that don't fit into the first two classes. E.g. `foo.bar()()`.

There are a few problems with this approach:
1. It is inconistent with the TypeScript AST which only has one node: `CallExpression`.
2. It means that we have to maintain more code, because the various parts of the compiler need to know about three node types.
3. It doesn't allow us to easily implement some new JS features like safe calls (e.g. `foo.bar?.())`).

These changes rework the compiler so that it produces only one node: `Call`. The new node behaves  similarly to the TypeScript `CallExpression` whose `receiver` can be any expression.

There was a similar situation in the output AST where we had an `InvokeMethodExpression` and `InvokeFunctionExpression`. I've combined both of them into `InvokeFunctionExpression`.
@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Sep 16, 2021
@crisbeto crisbeto 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, 2021
@jessicajaniuk jessicajaniuk removed the action: presubmit The PR is in need of a google3 presubmit label Sep 21, 2021
@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 22, 2021
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 refactoring Issue that involves refactoring or code-cleanup target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants