test(compiler): update examples and compiler tests (#30626)
PR Close #30626
This commit is contained in:
parent
dcdecfa9a8
commit
214ae0ea4c
|
@ -1714,7 +1714,7 @@ describe('compiler compliance', () => {
|
||||||
\`
|
\`
|
||||||
})
|
})
|
||||||
export class ContentQueryComponent {
|
export class ContentQueryComponent {
|
||||||
@ContentChild(SomeDirective) someDir: SomeDirective;
|
@ContentChild(SomeDirective, {static: false}) someDir: SomeDirective;
|
||||||
@ContentChildren(SomeDirective) someDirList !: QueryList<SomeDirective>;
|
@ContentChildren(SomeDirective) someDirList !: QueryList<SomeDirective>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1786,7 +1786,7 @@ describe('compiler compliance', () => {
|
||||||
\`
|
\`
|
||||||
})
|
})
|
||||||
export class ContentQueryComponent {
|
export class ContentQueryComponent {
|
||||||
@ContentChild('myRef') myRef: any;
|
@ContentChild('myRef', {static: false}) myRef: any;
|
||||||
@ContentChildren('myRef1, myRef2, myRef3') myRefs: QueryList<any>;
|
@ContentChildren('myRef1, myRef2, myRef3') myRefs: QueryList<any>;
|
||||||
}
|
}
|
||||||
@NgModule({declarations: [ContentQueryComponent]})
|
@NgModule({declarations: [ContentQueryComponent]})
|
||||||
|
@ -1911,9 +1911,9 @@ describe('compiler compliance', () => {
|
||||||
\`
|
\`
|
||||||
})
|
})
|
||||||
export class ContentQueryComponent {
|
export class ContentQueryComponent {
|
||||||
@ContentChild('myRef', {read: TemplateRef}) myRef: TemplateRef;
|
@ContentChild('myRef', {read: TemplateRef, static: false}) myRef: TemplateRef;
|
||||||
@ContentChildren('myRef1, myRef2, myRef3', {read: ElementRef}) myRefs: QueryList<ElementRef>;
|
@ContentChildren('myRef1, myRef2, myRef3', {read: ElementRef}) myRefs: QueryList<ElementRef>;
|
||||||
@ContentChild(SomeDirective, {read: ElementRef}) someDir: ElementRef;
|
@ContentChild(SomeDirective, {read: ElementRef, static: false}) someDir: ElementRef;
|
||||||
@ContentChildren(SomeDirective, {read: TemplateRef}) someDirs: QueryList<TemplateRef>;
|
@ContentChildren(SomeDirective, {read: TemplateRef}) someDirs: QueryList<TemplateRef>;
|
||||||
}
|
}
|
||||||
@NgModule({declarations: [ContentQueryComponent]})
|
@NgModule({declarations: [ContentQueryComponent]})
|
||||||
|
@ -1966,7 +1966,7 @@ describe('compiler compliance', () => {
|
||||||
\`
|
\`
|
||||||
})
|
})
|
||||||
export class ContentQueryComponent {
|
export class ContentQueryComponent {
|
||||||
@Input() @ContentChild('foo') foo: any;
|
@Input() @ContentChild('foo', {static: false}) foo: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -3139,7 +3139,7 @@ describe('compiler compliance', () => {
|
||||||
'spec.ts': `
|
'spec.ts': `
|
||||||
import {Component, NgModule, ContentChild} from '@angular/core';
|
import {Component, NgModule, ContentChild} from '@angular/core';
|
||||||
export class BaseClass {
|
export class BaseClass {
|
||||||
@ContentChild('something') something: any;
|
@ContentChild('something', {static: false}) something: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -1536,10 +1536,10 @@ describe('ngtsc behavioral tests', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
class FooCmp {
|
class FooCmp {
|
||||||
@ContentChild('bar', {read: TemplateRef}) child: any;
|
@ContentChild('bar', {read: TemplateRef, static: false}) child: any;
|
||||||
@ContentChildren(TemplateRef) children: any;
|
@ContentChildren(TemplateRef) children: any;
|
||||||
get aview(): any { return null; }
|
get aview(): any { return null; }
|
||||||
@ViewChild('accessor') set aview(value: any) {}
|
@ViewChild('accessor', {static: false}) set aview(value: any) {}
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -1568,7 +1568,7 @@ describe('ngtsc behavioral tests', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
class FooCmp {
|
class FooCmp {
|
||||||
@ContentChild('bar', {read: TemplateRef}) child: any;
|
@ContentChild('bar', {read: TemplateRef, static: false}) child: any;
|
||||||
@ContentChildren(TemplateRef) children: any;
|
@ContentChildren(TemplateRef) children: any;
|
||||||
get aview(): any { return null; }
|
get aview(): any { return null; }
|
||||||
@ViewChild('accessor') set aview(value: any) {}
|
@ViewChild('accessor') set aview(value: any) {}
|
||||||
|
@ -1600,11 +1600,11 @@ describe('ngtsc behavioral tests', () => {
|
||||||
template: '<div #foo></div>',
|
template: '<div #foo></div>',
|
||||||
})
|
})
|
||||||
class FooCmp {
|
class FooCmp {
|
||||||
@ContentChild(forwardRef(() => TemplateRef)) child: any;
|
@ContentChild(forwardRef(() => TemplateRef), {static: false}) child: any;
|
||||||
|
|
||||||
@ContentChild(forwardRef(function() { return ViewContainerRef; })) child2: any;
|
@ContentChild(forwardRef(function() { return ViewContainerRef; }), {static: false}) child2: any;
|
||||||
|
|
||||||
@ContentChild((forwardRef((function() { return 'parens'; }) as any))) childInParens: any;
|
@ContentChild((forwardRef((function() { return 'parens'; }) as any)), {static: false}) childInParens: any;
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,11 @@ import * as core from '@angular/core';
|
||||||
typeExtends<compilerCore.Query, core.Query>();
|
typeExtends<compilerCore.Query, core.Query>();
|
||||||
typeExtends<core.Query, compilerCore.Query>();
|
typeExtends<core.Query, compilerCore.Query>();
|
||||||
compareRuntimeShape(
|
compareRuntimeShape(
|
||||||
new core.ContentChild('someSelector'), compilerCore.createContentChild('someSelector'));
|
new core.ContentChild('someSelector', {static: false}),
|
||||||
|
compilerCore.createContentChild('someSelector', {static: false}));
|
||||||
compareRuntimeShape(
|
compareRuntimeShape(
|
||||||
new core.ContentChild('someSelector', {read: 'someRead'}),
|
new core.ContentChild('someSelector', {read: 'someRead', static: false}),
|
||||||
compilerCore.createContentChild('someSelector', {read: 'someRead'}));
|
compilerCore.createContentChild('someSelector', {read: 'someRead', static: false}));
|
||||||
compareRuntimeShape(
|
compareRuntimeShape(
|
||||||
new core.ContentChildren('someSelector'),
|
new core.ContentChildren('someSelector'),
|
||||||
compilerCore.createContentChildren('someSelector'));
|
compilerCore.createContentChildren('someSelector'));
|
||||||
|
@ -39,10 +40,11 @@ import * as core from '@angular/core';
|
||||||
compilerCore.createContentChildren(
|
compilerCore.createContentChildren(
|
||||||
'someSelector', {read: 'someRead', descendants: false}));
|
'someSelector', {read: 'someRead', descendants: false}));
|
||||||
compareRuntimeShape(
|
compareRuntimeShape(
|
||||||
new core.ViewChild('someSelector'), compilerCore.createViewChild('someSelector'));
|
new core.ViewChild('someSelector', {static: false}),
|
||||||
|
compilerCore.createViewChild('someSelector', {static: false}));
|
||||||
compareRuntimeShape(
|
compareRuntimeShape(
|
||||||
new core.ViewChild('someSelector', {read: 'someRead'}),
|
new core.ViewChild('someSelector', {read: 'someRead', static: false}),
|
||||||
compilerCore.createViewChild('someSelector', {read: 'someRead'}));
|
compilerCore.createViewChild('someSelector', {read: 'someRead', static: false}));
|
||||||
compareRuntimeShape(
|
compareRuntimeShape(
|
||||||
new core.ViewChildren('someSelector'), compilerCore.createViewChildren('someSelector'));
|
new core.ViewChildren('someSelector'), compilerCore.createViewChildren('someSelector'));
|
||||||
compareRuntimeShape(
|
compareRuntimeShape(
|
||||||
|
|
|
@ -68,15 +68,15 @@ class SomeDirectiveWithViewChildren {
|
||||||
c: any;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c')}})
|
@Directive({selector: 'someDirective', queries: {'c': new ContentChild('c', {static: false})}})
|
||||||
class SomeDirectiveWithContentChild {
|
class SomeDirectiveWithContentChild {
|
||||||
@ContentChild('a') a: any;
|
@ContentChild('a', {static: false}) a: any;
|
||||||
c: any;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c')}})
|
@Directive({selector: 'someDirective', queries: {'c': new ViewChild('c', {static: false})}})
|
||||||
class SomeDirectiveWithViewChild {
|
class SomeDirectiveWithViewChild {
|
||||||
@ViewChild('a') a: any;
|
@ViewChild('a', {static: false}) a: any;
|
||||||
c: any;
|
c: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,37 +408,41 @@ class SomeDirectiveWithoutMetadata {}
|
||||||
|
|
||||||
it('should append ContentChild', () => {
|
it('should append ContentChild', () => {
|
||||||
const directiveMetadata = resolver.resolve(SomeDirectiveWithContentChild);
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithContentChild);
|
||||||
expect(directiveMetadata.queries)
|
expect(directiveMetadata.queries).toEqual({
|
||||||
.toEqual({'c': new ContentChild('c'), 'a': new ContentChild('a')});
|
'c': new ContentChild('c', {static: false}),
|
||||||
|
'a': new ContentChild('a', {static: false})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should append ViewChild', () => {
|
it('should append ViewChild', () => {
|
||||||
const directiveMetadata = resolver.resolve(SomeDirectiveWithViewChild);
|
const directiveMetadata = resolver.resolve(SomeDirectiveWithViewChild);
|
||||||
expect(directiveMetadata.queries)
|
expect(directiveMetadata.queries).toEqual({
|
||||||
.toEqual({'c': new ViewChild('c'), 'a': new ViewChild('a')});
|
'c': new ViewChild('c', {static: false}),
|
||||||
|
'a': new ViewChild('a', {static: false})
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support inheriting queries', () => {
|
it('should support inheriting queries', () => {
|
||||||
@Directive({selector: 'p'})
|
@Directive({selector: 'p'})
|
||||||
class Parent {
|
class Parent {
|
||||||
@ContentChild('p1')
|
@ContentChild('p1', {static: false})
|
||||||
p1: any;
|
p1: any;
|
||||||
@ContentChild('p21')
|
@ContentChild('p21', {static: false})
|
||||||
p2: any;
|
p2: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Child extends Parent {
|
class Child extends Parent {
|
||||||
@ContentChild('p22')
|
@ContentChild('p22', {static: false})
|
||||||
p2: any;
|
p2: any;
|
||||||
@ContentChild('p3')
|
@ContentChild('p3', {static: false})
|
||||||
p3: any;
|
p3: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const directiveMetadata = resolver.resolve(Child);
|
const directiveMetadata = resolver.resolve(Child);
|
||||||
expect(directiveMetadata.queries).toEqual({
|
expect(directiveMetadata.queries).toEqual({
|
||||||
'p1': new ContentChild('p1'),
|
'p1': new ContentChild('p1', {static: false}),
|
||||||
'p2': new ContentChild('p22'),
|
'p2': new ContentChild('p22', {static: false}),
|
||||||
'p3': new ContentChild('p3')
|
'p3': new ContentChild('p3', {static: false})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -295,7 +295,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||||
it('should compile ContentChild query with string predicate on a directive', () => {
|
it('should compile ContentChild query with string predicate on a directive', () => {
|
||||||
@Directive({selector: '[test]'})
|
@Directive({selector: '[test]'})
|
||||||
class TestDirective {
|
class TestDirective {
|
||||||
@ContentChild('foo') foo: ElementRef|undefined;
|
@ContentChild('foo', {static: false}) foo: ElementRef|undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
|
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
|
||||||
|
@ -317,7 +317,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||||
|
|
||||||
@Directive({selector: '[test]'})
|
@Directive({selector: '[test]'})
|
||||||
class TestDirective {
|
class TestDirective {
|
||||||
@ContentChild(SomeDir) dir: SomeDir|undefined;
|
@ContentChild(SomeDir, {static: false}) dir: SomeDir|undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
|
expect((TestDirective as any).ngDirectiveDef.contentQueries).not.toBeNull();
|
||||||
|
@ -326,7 +326,7 @@ ivyEnabled && describe('render3 jit', () => {
|
||||||
it('should compile ViewChild query on a component', () => {
|
it('should compile ViewChild query on a component', () => {
|
||||||
@Component({selector: 'test', template: ''})
|
@Component({selector: 'test', template: ''})
|
||||||
class TestComponent {
|
class TestComponent {
|
||||||
@ViewChild('foo') foo: ElementRef|undefined;
|
@ViewChild('foo', {static: false}) foo: ElementRef|undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
expect((TestComponent as any).ngComponentDef.foo).not.toBeNull();
|
expect((TestComponent as any).ngComponentDef.foo).not.toBeNull();
|
||||||
|
|
|
@ -62,7 +62,7 @@ export class NgIfThenElse implements OnInit {
|
||||||
|
|
||||||
@ViewChild('primaryBlock', {static: true})
|
@ViewChild('primaryBlock', {static: true})
|
||||||
primaryBlock: TemplateRef<any>|null = null;
|
primaryBlock: TemplateRef<any>|null = null;
|
||||||
@ViewChild('secondaryBlock')
|
@ViewChild('secondaryBlock', {static: true})
|
||||||
secondaryBlock: TemplateRef<any>|null = null;
|
secondaryBlock: TemplateRef<any>|null = null;
|
||||||
|
|
||||||
switchPrimary() {
|
switchPrimary() {
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class Pane {
|
||||||
})
|
})
|
||||||
export class Tab {
|
export class Tab {
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
@ContentChild(Pane) pane !: Pane;
|
@ContentChild(Pane, {static: false}) pane !: Pane;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
|
@ -15,7 +15,7 @@ class ChildDirective {
|
||||||
|
|
||||||
@Directive({selector: 'someDir'})
|
@Directive({selector: 'someDir'})
|
||||||
class SomeDir implements AfterContentInit {
|
class SomeDir implements AfterContentInit {
|
||||||
@ContentChild(ChildDirective) contentChild !: ChildDirective;
|
@ContentChild(ChildDirective, {static: false}) contentChild !: ChildDirective;
|
||||||
|
|
||||||
ngAfterContentInit() {
|
ngAfterContentInit() {
|
||||||
// contentChild is set
|
// contentChild is set
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class Pane {
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
export class ViewChildComp {
|
export class ViewChildComp {
|
||||||
@ViewChild(Pane)
|
@ViewChild(Pane, {static: false})
|
||||||
set pane(v: Pane) {
|
set pane(v: Pane) {
|
||||||
setTimeout(() => { this.selectedPane = v.id; }, 0);
|
setTimeout(() => { this.selectedPane = v.id; }, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ChildDirective {
|
||||||
@Component({selector: 'someCmp', templateUrl: 'someCmp.html'})
|
@Component({selector: 'someCmp', templateUrl: 'someCmp.html'})
|
||||||
class SomeCmp implements AfterViewInit {
|
class SomeCmp implements AfterViewInit {
|
||||||
// TODO(issue/24571): remove '!'.
|
// TODO(issue/24571): remove '!'.
|
||||||
@ViewChild(ChildDirective) child !: ChildDirective;
|
@ViewChild(ChildDirective, {static: false}) child !: ChildDirective;
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
// child is set
|
// child is set
|
||||||
|
|
Loading…
Reference in New Issue