refactor(core): static-query template strategy should not parse stylesheets (#29876)
Currently the `template-strategy` for the static query migration uses the Angular compiler in order to determine the query timing. This is problematic as the AngularCompilerProgram also collects metadata for referenced component stylesheets which aren't necessarily present. e.g. in a CLI project the component can reference a Sass file. It's not guaranteed that the standalone Angular compiler plugin supports Sass without custom logic that is brought in by the Angular CLI webpack plugin. In order to avoid any failures for invalid stylesheets, we just disable normalizing of all referenced stylesheets. PR Close #29876
This commit is contained in:

committed by
Ben Lesh

parent
ca591641c7
commit
c1d5fbd0ad
@ -488,5 +488,32 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(warnOutput[0])
|
||||
.toMatch(/^⮑ {3}index.ts@6:11: Content queries cannot be migrated automatically\./);
|
||||
});
|
||||
|
||||
it('should not normalize stylesheets which are referenced in component', async() => {
|
||||
writeFile('sub_dir/index.ts', `
|
||||
import {Component, NgModule, ContentChild} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
template: '<p #myRef></p>',
|
||||
styleUrls: ['./my-comp.scss']
|
||||
})
|
||||
export class MyComp {}
|
||||
|
||||
@NgModule({declarations: [MyComp]})
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
// In order to check that the stylesheet is not normalized, we add an "@import" statement
|
||||
// that would be extracted by the "DirectiveNormalizer" and fail because the URL resolver
|
||||
// is not able to resolve the "../shared" relative import to the SCSS file extension.
|
||||
writeFile('/sub_dir/my-comp.scss', `@import '../shared'`);
|
||||
writeFile('/shared.scss', `shared {}`);
|
||||
|
||||
spyOn(console, 'error').and.callThrough();
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(console.error).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user