-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Transform logic to extract signal debug names #57348
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 occasiona 8000 lly send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Transform logic to extract signal debug names #57348
Conversation
packages/compiler-cli/src/ngtsc/annotations/directive/src/input_output_parse_options.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/debug_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/debug_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/annotations/directive/src/input_output_parse_options.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/debug_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/debug_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/debug_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/debug_transform.ts
Outdated
Show resolved
Hide resolved
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.
LGTM
c3d0bf5
to
fbbc8c0
Compare
packages/compiler-cli/src/ngtsc/annotations/directive/src/input_output_parse_options.ts
Outdated
Show resolved
Hide resolved
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.
First round of comments!
Additionally, in the commit history, use refactor
commits for implementation details. A given feature (debug names for example) should have exactly 1 feat
commit, which is the commit which actually makes the feature available for end users to use.
packages/compiler-cli/src/ngtsc/annotations/directive/src/input_output_parse_options.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
]), | ||
undefined, | ||
ts.factory.createArrayLiteralExpression([ | ||
ts.factory.createObjectLiteralExpression(existingArgument.properties), |
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.
Same comment about ts.factory.update*
.
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.
This is still a bit sketchy to me. This creates a node without any context (e.g. sourcemaps).
Ideally, we wouldn't have to copy the user's code like this, but we should still use ts.update*
instead.
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.
We discussed this briefly in the DevTools sync today. We can definitely update this object literal to just be existingArgument
. How should this work for the duplicated node though?
We're effectively converting signal(0, { equals })
to signal(0, ...(ngDevMode ? [{ debugName: 'test', equals }] : [{ equals }]))
. That moves { equals }
to the false
case, but also duplicate its in the true
case. I presume we just need to ts.factory.create*(...)
for the true
case and can't update the existing one because we need it for the false
case?
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.
Tested over the weekend with ng new and the compiler cli code with the transform. Source maps are working as expected even with the transformation applied. I think this is working as expected now
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
252d2cd
to
5f59f91
Compare
43e0707
to
850cea2
Compare
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.
Thanks for working through all these changes, it's looking great!
No major concerns on my side, just a few minor suggestions and questions. I think a couple existing comments are still open too when you get a chance.
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
program: ts.Program, | ||
expression: ts.Expression, | ||
): boolean { | ||
const symbol = program.getTypeChecker().getSymbolAtLocation(expression); |
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.
Question: @alxhub, do we care that this is using the type checker to resolve to the imported symbol?
I know we're trying to avoid the type checker for single-file transpilations, so I'm wondering if there's a better way or if this is ok because we're keeping it within the source file.
} | ||
|
||
// climb up the tree from the import specifier to the import declaration | ||
const importSpecifier = declarations[0]; |
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.
Question: What exactly does it mean to have multiple declarations? Are these shadowed declarations like:
import { signal } from '@angular/core';
function foo() {
const signal = () => {};
console.log(signal); // Has two declarations?
}
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.
No, multiple declarations would be something like:
interface Foo {
bar: string;
}
interface Foo {
baz: number;
}
Multiple declarations really only applies to types. When looking for the declaration of a value, you can use symbol.valueDeclaration
instead, since a value can only ever be defined once.
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.
Is it safe to just look at the first declaration? I guess if it is a real signal
function then it will always have just one declaration from the import
?
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
F438
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Show resolved
Hide resolved
packages/compiler-cli/src/ngtsc/transform/src/implicit_signal_debug_name_transform.ts
Outdated
Show resolved
Hide resolved
850cea2
to
7c96e70
Compare
1f03d73
to
57ec5c4
Compare
af1f967
to
f05cdea
Compare
f05cdea
to
780dab1
Compare
780dab1
to
6c5f302
Compare
f034848
to
52c3eb0
Compare
52c3eb0
to
e8acd3f
Compare
ad1b0ad
to
57eaa4e
Compare
TGP still looking good: http://test/OCL:758440362:BASE:758744767:1747244383957:e4a093db |
57eaa4e
to
05a8db2
Compare
…om signal functions Implements a compiler transform that attempts to statically analyze variable names and apply them to usages of signal functions like signal, computed, effect, etc.
05a8db2
to
0a905d2
Compare
Implements a compiler transform that attempts to statically analyze variable names and apply them to usages of signal functions like signal, computed, effect, etc as debug names.
Related: #57074
Depends on: #57073