Repository navigation
Conversation
ecb2c80 to
8d6ed43
Compare
kyliau
left a comment
There was a problem hiding this comment.
LGTM for language service
|
One open question is whether the absolute span should apply to an AST's entire logical span or just the AST name. For example, the AST span of a safe property read currently covers the object being read from as well: obj?.prop
^^^^^^^^^ SafePropertyRead span
^^^^ potential alternate spanWhat is an example of a |
Yes, this is an interesting question. The TypeScript AST prevents this problem by having
I didn't know this one, but it seems like a hook to allow external languages to be used inside Angular templates, like so:
I don't know if this has ever been used as such, |
petebacondarwin
left a comment
There was a problem hiding this comment.
Generally approve - nice work @ayazhafiz!
I have a couple of nits and questions that I would like to see dealt with.
Regarding the PropertyRead span... what is the downside of leaving it as the full expression (i.e. abc.foo)? If there is no obvious use case for distinguishing them, then I would leave it as it is.
There was a problem hiding this comment.
Is there much point in this ASTWithSource type now, given that AST nodes will include the sourceSpan already?
There was a problem hiding this comment.
Probably not, but many consumers still rely on it. We can look into removing it in a future PR.
There was a problem hiding this comment.
I would love to get rid of this as well, but agree it should be part of followup work 👍
There was a problem hiding this comment.
This function is called a lot of times with the same start number (and possibly when there is the same this.inputIndex value. If that is the case then we are creating unnecessary duplicate AbsoluteSourceSpan objects. Can we check all the calls to sourceSpan() to make sure that they are actually needed and can't be cached in variables - which they already are occasionally.
There was a problem hiding this comment.
Done. Using an object instead of a map for performance; let me know if you'd prefer more idiomatic usage.
I'll perform a follow up PR and clean up assignments of both span and sourceSpan after this is merged.
Sorry for being vague in my comment; what I mean to say is that this new One other issue I've noticed is that nested expressions with trailing whitespace will be given a span that includes the trailing whitespace: {{ bool ? 1 : 0 }}
^^^^^ span of `bool`We may want to make absolute spans ignore this too to remove ambiguity.
There isn't a downside, but the benefits are what I mentioned in the paragraph above. I think it'll work fine either way though.
👍 thanks, this is what I was looking for! |
JoostK
left a comment
There was a problem hiding this comment.
Is there a plan for getting rid of ParseSpan on AST nodes? With the introduction of sourceSpan I don't see why they should stay around.
There was a problem hiding this comment.
I would love to get rid of this as well, but agree it should be part of followup work 👍
Good idea. We will have to think about this because there are many consumers of |
Currently, the spans of expressions are recorded only relative to the template node that they reside in, not their source file. Introduce a `sourceSpan` property on expression ASTs that records the location of an expression relative to the entire source code file that it is in. This may allow for reducing duplication of effort in ngtsc/typecheck/src/diagnostics later on as well. Child of angular#31898
9dc11ae to
ecdedb2
Compare
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Currently, the spans of expressions are recorded only relative to the
template node that they reside in, not their source file.
Introduce a
sourceSpanproperty on expression ASTs that records thelocation of an expression relative to the entire source code file that
it is in. This may allow for reducing duplication of effort in
ngtsc/typecheck/src/diagnostics later on as well.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #31898
What is the new behavior?
Does this PR introduce a breaking change?
Other information