fix(queries): compile decorator queries: and match ngtsc's query options - #495
Open
ashley-hunter wants to merge 1 commit into
Open
ashley-hunter wants to merge 1 commit into
ashley-hunter wants to merge 1 commit into
Conversation
…tions
`@Directive({ queries: { el: new ViewChild('el') } })` (and `@Component`) was
ignored, so those queries never ran. It's now parsed like ngtsc's
`extractQueriesFromDecorator`: `new ViewChild/ViewChildren/ContentChild/
ContentChildren(...)` imported from `@angular/core` (directly or through a
namespace import), appended after the member queries, with ngtsc's diagnostics
word for word (not an object literal, not a query type, missing/extra
arguments, non-object options, non-boolean `descendants`/`static`/
`emitDistinctChangesOnly`, uninterpretable predicates, and a signal query
declared for the same property).
Member query decorators now match ngtsc too:
- `descendants` and `emitDistinctChangesOnly` are honoured on `@ViewChild`/
`@ViewChildren` (they were hard-coded), which changes the emitted flags
- a predicate referencing a same-file string const (`@ViewChild(SELECTOR)`)
compiles to that selector rather than to a type predicate
- `forwardRef(function () { return X; })`, and `forwardRef` behind parentheses
or `as`, is unwrapped like the arrow form
`extract_class_queries` returns a class's queries as they're compiled; the
compiler and the NAPI `extractComponentMetadataSync` both use it, so the
metadata API reports the same queries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack (3/4): #493 inputs/outputs → #494 transform validation → #495
queries:→ #496.d.tstransform types. This is #495.Compiles
queries:declared in@Directive/@Componentmetadata, and matches ngtsc on a few member-query options.The bug
compiled with no view query, so
elwas never set. Thequerieskey was ignored likeinputs:was.The fix
queries:is parsed like ngtsc'sextractQueriesFromDecorator:new ViewChild/ViewChildren/ContentChild/ContentChildren(...)imported from@angular/core(directly or through a namespace import), appended after the member queries. It raises ngtsc's diagnostics word for word:descendants,staticoremitDistinctChangesOnlyMember query decorators now also match ngtsc:
@ViewChild/@ViewChildrenhonourdescendantsandemitDistinctChangesOnly. They were hard-coded before, so this changes the emitted query flags for code that sets them.@ViewChild(SELECTOR)) compiles to that selector instead of a type predicate.forwardRef(function () { return X; }), andforwardRefbehind parentheses oras, is unwrapped like the arrow form.extract_class_queriesreturns a class's queries as they're compiled. The compiler and the NAPIextractComponentMetadataSyncboth use it, so the metadata API now reports the same queries.Tests
Added to the ngtsc snapshot: Angular's
queriesspecs (ngtsc_spec's decorator-queries errors and "should generate queries for components/directives",forwardRef, and theauthoring_queries_speccollisions), plus probes of every error, the flags and the ordering. A new NAPI test coversextractComponentMetadataSync, and it failed before the fix.