refactor(core): static-query migrations fails if options cannot be transformed (#30178)
Currently the `static-query` migrations fails at the final step of updating a query when the query already specifies options which cannot be transformed easily. e.g. the options are computed through a function call: `@ViewChild(..., getQueryOpts());` or `@ViewChild(..., myOptionsVar)`. In these cases we technically could add additionally logic to update the query options, but given that this is an edge-case and it's potentially over-engineering the migration schematic, we just always add a TODO for the timing and print out the determined query timing in the console. The developer in that case just needs to manually update the logic for the query options to contain the printed query timing. Potentially related to: https://github.com/angular/angular-cli/issues/14298 PR Close #30178
This commit is contained in:

committed by
Andrew Kushnir

parent
1353bf0277
commit
164d160b22
@ -492,6 +492,31 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toMatch(/^⮑ {3}index.ts@6:11: Content queries cannot be migrated automatically\./);
|
||||
});
|
||||
|
||||
it('should add a todo if query options cannot be migrated inline', async() => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
const myOptionsVar = {};
|
||||
|
||||
@Component({template: '<p #myRef></p>'})
|
||||
export class MyComp {
|
||||
@ViewChild('myRef', myOptionsVar) query: any;
|
||||
}
|
||||
|
||||
@NgModule({declarations: [MyComp]})
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('myRef', /* TODO: add static flag */ myOptionsVar) query: any;`);
|
||||
expect(warnOutput.length).toBe(1);
|
||||
expect(warnOutput[0])
|
||||
.toMatch(/^⮑ {3}index.ts@8:11: Cannot update query declaration to explicit timing./);
|
||||
expect(warnOutput[0]).toMatch(/Please manually set the query timing to.*static: true/);
|
||||
});
|
||||
|
||||
it('should not normalize stylesheets which are referenced in component', async() => {
|
||||
writeFile('sub_dir/index.ts', `
|
||||
import {Component, NgModule, ContentChild} from '@angular/core';
|
||||
|
Reference in New Issue
Block a user