Repository navigation
Conversation
bae3c1b to
0a8cedd
Compare
I am pretty confident that for ngcc, all of these wrapped nodes will have come from JS files, so it seems likely that they are already JS. Right? |
|
Generally looks like a good idea! |
8c97aa2 to
8cc985f
Compare
There was a problem hiding this comment.
How do we know what name is defined? Should we not check name for the whole function body?
There was a problem hiding this comment.
Was the previous printer producing a fat arrow here or something?
There was a problem hiding this comment.
Nope, it was only the non-null assertion in the template (person!.name) that tripped stuff up. It's actually surprising that the TypeScript printer has worked so well until that tiny syntactical difference.
95abaaf to
78e3da4
Compare
|
@petebacondarwin @alxhub After a rebase this is now green again, should be good to go. Let me know if we do want to elide the |
8b2fc25 to
518b043
Compare
petebacondarwin
left a comment
There was a problem hiding this comment.
This fix looks good to me. It needs to have an ngtsc test too IMO. I am going to add one.
Then leave it to @alxhub to do final approval.
I realised that ngtsc outputs its AST through a JS renderer so that the non-JS AST nodes are removed, which makes a test inside ngtsc_spec.ts not possible.
There was a problem hiding this comment.
LGTM! @alxhub over to you. I have rebased on master, just to be sure!
518b043 to
e02c917
Compare
518b043 to
aebacd3
Compare
If a template contains specific TypeScript syntax, such as a non-null assertion, the code that is emitted from ngcc into a JavaScript bundle should not retain such syntax as it is invalid in JS. A full-blown TypeScript emit of a complete ts.SourceFile would be required to be able to emit JS and possibly downlevel into a lower language target, which is not an option for ngcc as it currently operates on partial ASTs, not full source files. Instead, ngtsc no longer produces TypeScript specific syntax in the first place, such that TypeScript print logic will only generate JS code.
aebacd3 to
b087d68
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. |
Previously, ngcc used ngtsc's logic to transform the Angular AST
to a TypeScript AST and then leverages TypeScript's node printer to
obtain the source text to insert. This turns out to be a problem when
specific TypeScript syntax is represented in the AST; the printer cannot
be configured to output only JavaScript syntax.
A full-blown TypeScript emit of a complete
ts.SourceFilewould berequired to be able to emit JS and possibly downlevel into a lower
language target, which is not an option for ngcc as it currently
operates on partial ASTs, not full source files.
Instead, the Angular AST itself is used to emit source files, using the
emitter logic that is also used in JIT compilations. As the Angular AST
produced by ngtsc may contain literal TypeScript nodes inside of
WrappedNodeExpr, a TypeScript printer is still used to obtain sourcetext for such nodes (assuming no TypeScript specific syntax is present
within that node's subtree).
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?
ngcc may output TypeScript specific syntax into JavaScript bundles, which fail to be parsed.
What is the new behavior?
ngcc uses existing emitter logic that operates on Angular AST to produce JavaScript code instead of TypeScript.
Does this PR introduce a breaking change?
Other information
@alxhub Can you comment on my assumption that we can safely print
WrappedNodeExprusing TypeScript's printing logic, as doing so still has a risk of producing TS specific syntax.