refactor(ivy): move directive, component and pipe factories to ngFactoryFn (#31953)
Reworks the compiler to output the factories for directives, components and pipes under a new static field called `ngFactoryFn`, instead of the usual `factory` property in their respective defs. This should eventually allow us to inject any kind of decorated class (e.g. a pipe). **Note:** these changes are the first part of the refactor and they don't include injectables. I decided to leave injectables for a follow-up PR, because there's some more cases we need to handle when it comes to their factories. Furthermore, directives, components and pipes make up most of the compiler output tests that need to be refactored and it'll make follow-up PRs easier to review if the tests are cleaned up now. This is part of the larger refactor for FW-1468. PR Close #31953
This commit is contained in:

committed by
atscott

parent
14feb56139
commit
c885178d5f
@ -119,7 +119,7 @@ runInEachFileSystem(() => {
|
||||
const typingsFile = result.find(f => f.path === _('/typings/file.d.ts')) !;
|
||||
expect(typingsFile.contents)
|
||||
.toContain(
|
||||
'foo(x: number): number;\n static ngDirectiveDef: ɵngcc0.ɵɵDirectiveDefWithMeta');
|
||||
'foo(x: number): number;\n static ngFactoryDef: ɵngcc0.ɵɵFactoryDef<A>;\n static ngDirectiveDef: ɵngcc0.ɵɵDirectiveDefWithMeta');
|
||||
});
|
||||
|
||||
it('should render imports into typings files', () => {
|
||||
|
@ -188,8 +188,8 @@ runInEachFileSystem(() => {
|
||||
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses);
|
||||
const addDefinitionsSpy = testFormatter.addDefinitions as jasmine.Spy;
|
||||
expect(addDefinitionsSpy.calls.first().args[2])
|
||||
.toEqual(
|
||||
`A.ngComponentDef = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], factory: function A_Factory(t) { return new (t || A)(); }, consts: 1, vars: 1, template: function A_Template(rf, ctx) { if (rf & 1) {
|
||||
.toEqual(`A.ngFactoryDef = function A_Factory(t) { return new (t || A)(); };
|
||||
A.ngComponentDef = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], consts: 1, vars: 1, template: function A_Template(rf, ctx) { if (rf & 1) {
|
||||
ɵngcc0.ɵɵtext(0);
|
||||
} if (rf & 2) {
|
||||
ɵngcc0.ɵɵtextInterpolate(ctx.person.name);
|
||||
@ -227,9 +227,10 @@ runInEachFileSystem(() => {
|
||||
name: 'A',
|
||||
decorators: [jasmine.objectContaining({name: 'Directive'})]
|
||||
}));
|
||||
|
||||
expect(addDefinitionsSpy.calls.first().args[2])
|
||||
.toEqual(
|
||||
`A.ngDirectiveDef = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]], factory: function A_Factory(t) { return new (t || A)(); } });
|
||||
.toEqual(`A.ngFactoryDef = function A_Factory(t) { return new (t || A)(); };
|
||||
A.ngDirectiveDef = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]] });
|
||||
/*@__PURE__*/ ɵngcc0.ɵsetClassMetadata(A, [{
|
||||
type: Directive,
|
||||
args: [{ selector: '[a]' }]
|
||||
|
@ -26,6 +26,7 @@ import {tsSourceMapBug29300Fixed} from '../../util/src/ts_source_map_bug_29300';
|
||||
|
||||
import {ResourceLoader} from './api';
|
||||
import {extractDirectiveMetadata, parseFieldArrayValue} from './directive';
|
||||
import {compileNgFactoryDefField} from './factory';
|
||||
import {generateSetClassMetadataCall} from './metadata';
|
||||
import {findAngularDecorator, isAngularCoreReference, isExpressionForwardReference, readBaseClass, unwrapExpression} from './util';
|
||||
|
||||
@ -517,18 +518,21 @@ export class ComponentDecoratorHandler implements
|
||||
}
|
||||
|
||||
compile(node: ClassDeclaration, analysis: ComponentHandlerData, pool: ConstantPool):
|
||||
CompileResult {
|
||||
const res = compileComponentFromMetadata(analysis.meta, pool, makeBindingParser());
|
||||
|
||||
const statements = res.statements;
|
||||
CompileResult[] {
|
||||
const meta = analysis.meta;
|
||||
const res = compileComponentFromMetadata(meta, pool, makeBindingParser());
|
||||
const factoryRes = compileNgFactoryDefField(meta);
|
||||
if (analysis.metadataStmt !== null) {
|
||||
statements.push(analysis.metadataStmt);
|
||||
factoryRes.statements.push(analysis.metadataStmt);
|
||||
}
|
||||
return {
|
||||
name: 'ngComponentDef',
|
||||
initializer: res.expression, statements,
|
||||
type: res.type,
|
||||
};
|
||||
return [
|
||||
factoryRes, {
|
||||
name: 'ngComponentDef',
|
||||
initializer: res.expression,
|
||||
statements: [],
|
||||
type: res.type,
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
private _resolveLiteral(decorator: Decorator): ts.ObjectLiteralExpression {
|
||||
@ -822,4 +826,4 @@ export interface ParsedTemplate {
|
||||
|
||||
interface PreanalyzedTemplate extends ParsedTemplate {
|
||||
parseTemplate: (options?: ParseTemplateOptions) => ParsedTemplate;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import {DynamicValue, EnumValue, PartialEvaluator} from '../../partial_evaluator
|
||||
import {ClassDeclaration, ClassMember, ClassMemberKind, Decorator, ReflectionHost, filterToMembersWithDecorator, reflectObjectLiteral} from '../../reflection';
|
||||
import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../transform';
|
||||
|
||||
import {compileNgFactoryDefField} from './factory';
|
||||
import {generateSetClassMetadataCall} from './metadata';
|
||||
import {findAngularDecorator, getValidConstructorDependencies, readBaseClass, unwrapExpression, unwrapForwardRef} from './util';
|
||||
|
||||
@ -90,18 +91,21 @@ export class DirectiveDecoratorHandler implements
|
||||
}
|
||||
|
||||
compile(node: ClassDeclaration, analysis: DirectiveHandlerData, pool: ConstantPool):
|
||||
CompileResult {
|
||||
const res = compileDirectiveFromMetadata(analysis.meta, pool, makeBindingParser());
|
||||
const statements = res.statements;
|
||||
CompileResult[] {
|
||||
const meta = analysis.meta;
|
||||
const res = compileDirectiveFromMetadata(meta, pool, makeBindingParser());
|
||||
const factoryRes = compileNgFactoryDefField(meta);
|
||||
if (analysis.metadataStmt !== null) {
|
||||
statements.push(analysis.metadataStmt);
|
||||
factoryRes.statements.push(analysis.metadataStmt);
|
||||
}
|
||||
return {
|
||||
name: 'ngDirectiveDef',
|
||||
initializer: res.expression,
|
||||
statements: statements,
|
||||
type: res.type,
|
||||
};
|
||||
return [
|
||||
factoryRes, {
|
||||
name: 'ngDirectiveDef',
|
||||
initializer: res.expression,
|
||||
statements: [],
|
||||
type: res.type,
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
21
packages/compiler-cli/src/ngtsc/annotations/src/factory.ts
Normal file
21
packages/compiler-cli/src/ngtsc/annotations/src/factory.ts
Normal file
@ -0,0 +1,21 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {R3FactoryDefMetadata, compileFactoryFromMetadata} from '@angular/compiler';
|
||||
|
||||
import {CompileResult} from '../../transform';
|
||||
|
||||
export function compileNgFactoryDefField(metadata: R3FactoryDefMetadata): CompileResult {
|
||||
const res = compileFactoryFromMetadata(metadata);
|
||||
return {
|
||||
name: 'ngFactoryDef',
|
||||
initializer: res.factory,
|
||||
statements: res.statements,
|
||||
type: res.type
|
||||
};
|
||||
}
|
@ -16,6 +16,7 @@ import {PartialEvaluator} from '../../partial_evaluator';
|
||||
import {ClassDeclaration, Decorator, ReflectionHost, reflectObjectLiteral} from '../../reflection';
|
||||
import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence} from '../../transform';
|
||||
|
||||
import {compileNgFactoryDefField} from './factory';
|
||||
import {generateSetClassMetadataCall} from './metadata';
|
||||
import {findAngularDecorator, getValidConstructorDependencies, unwrapExpression} from './util';
|
||||
|
||||
@ -105,16 +106,20 @@ export class PipeDecoratorHandler implements DecoratorHandler<PipeHandlerData, D
|
||||
};
|
||||
}
|
||||
|
||||
compile(node: ClassDeclaration, analysis: PipeHandlerData): CompileResult {
|
||||
const res = compilePipeFromMetadata(analysis.meta);
|
||||
const statements = res.statements;
|
||||
compile(node: ClassDeclaration, analysis: PipeHandlerData): CompileResult[] {
|
||||
const meta = analysis.meta;
|
||||
const res = compilePipeFromMetadata(meta);
|
||||
const factoryRes = compileNgFactoryDefField({...meta, isPipe: true});
|
||||
if (analysis.metadataStmt !== null) {
|
||||
statements.push(analysis.metadataStmt);
|
||||
factoryRes.statements.push(analysis.metadataStmt);
|
||||
}
|
||||
return {
|
||||
name: 'ngPipeDef',
|
||||
initializer: res.expression, statements,
|
||||
type: res.type,
|
||||
};
|
||||
return [
|
||||
factoryRes, {
|
||||
name: 'ngPipeDef',
|
||||
initializer: res.expression,
|
||||
statements: [],
|
||||
type: res.type,
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ const R3_DEF_NAME_PATTERN = [
|
||||
'ngInjectorDef',
|
||||
'ngModuleDef',
|
||||
'ngPipeDef',
|
||||
'ngFactoryDef',
|
||||
].join('|');
|
||||
|
||||
// Pattern matching `Identifier.property` where property is a Render3 property.
|
||||
|
@ -44,7 +44,7 @@ describe('compiler compliance', () => {
|
||||
|
||||
// The factory should look like this:
|
||||
const factory =
|
||||
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
|
||||
// The template should look like this (where IDENT is a wild card for an identifier):
|
||||
const template = `
|
||||
@ -94,7 +94,7 @@ describe('compiler compliance', () => {
|
||||
|
||||
// The factory should look like this:
|
||||
const factory =
|
||||
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
|
||||
// The template should look like this (where IDENT is a wild card for an identifier):
|
||||
const template = `
|
||||
@ -142,7 +142,7 @@ describe('compiler compliance', () => {
|
||||
|
||||
// The factory should look like this:
|
||||
const factory =
|
||||
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
|
||||
// The template should look like this (where IDENT is a wild card for an identifier):
|
||||
const template = `
|
||||
@ -190,7 +190,7 @@ describe('compiler compliance', () => {
|
||||
|
||||
// The factory should look like this:
|
||||
const factory =
|
||||
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
|
||||
// The template should look like this (where IDENT is a wild card for an identifier):
|
||||
const template = `
|
||||
@ -306,7 +306,7 @@ describe('compiler compliance', () => {
|
||||
};
|
||||
|
||||
const factory =
|
||||
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
const template = `
|
||||
const $e0_attrs$ = [${AttributeMarker.Bindings}, "id"];
|
||||
…
|
||||
@ -361,7 +361,7 @@ describe('compiler compliance', () => {
|
||||
///////////////
|
||||
|
||||
const factory =
|
||||
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
const template = `
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
@ -476,12 +476,9 @@ describe('compiler compliance', () => {
|
||||
};
|
||||
|
||||
const factory =
|
||||
'factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
'MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); }';
|
||||
const template = `
|
||||
MyComponent.ngComponentDef = i0.ɵɵdefineComponent({type:MyComponent,selectors:[["my-component"]],
|
||||
factory: function MyComponent_Factory(t){
|
||||
return new (t || MyComponent)();
|
||||
},
|
||||
consts: 1,
|
||||
vars: 2,
|
||||
template: function MyComponent_Template(rf,ctx){
|
||||
@ -536,7 +533,6 @@ describe('compiler compliance', () => {
|
||||
ChildComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: ChildComponent,
|
||||
selectors: [["child"]],
|
||||
factory: function ChildComponent_Factory(t) { return new (t || ChildComponent)(); },
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function ChildComponent_Template(rf, ctx) {
|
||||
@ -547,15 +543,20 @@ describe('compiler compliance', () => {
|
||||
encapsulation: 2
|
||||
});`;
|
||||
|
||||
const ChildComponentFactory =
|
||||
`ChildComponent.ngFactoryDef = function ChildComponent_Factory(t) { return new (t || ChildComponent)(); };`;
|
||||
|
||||
// SomeDirective definition should be:
|
||||
const SomeDirectiveDefinition = `
|
||||
SomeDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: SomeDirective,
|
||||
selectors: [["", "some-directive", ""]],
|
||||
factory: function SomeDirective_Factory(t) {return new (t || SomeDirective)(); }
|
||||
selectors: [["", "some-directive", ""]]
|
||||
});
|
||||
`;
|
||||
|
||||
const SomeDirectiveFactory =
|
||||
`SomeDirective.ngFactoryDef = function SomeDirective_Factory(t) {return new (t || SomeDirective)(); };`;
|
||||
|
||||
// MyComponent definition should be:
|
||||
const MyComponentDefinition = `
|
||||
const $c1$ = ["some-directive", ""];
|
||||
@ -563,7 +564,6 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 2,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -577,13 +577,18 @@ describe('compiler compliance', () => {
|
||||
});
|
||||
`;
|
||||
|
||||
const MyComponentFactory =
|
||||
`MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); };`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, ChildComponentDefinition, 'Incorrect ChildComponent.ngComponentDef');
|
||||
expectEmit(source, ChildComponentFactory, 'Incorrect ChildComponent.ngFactoryDef');
|
||||
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ngDirectiveDef');
|
||||
expectEmit(source, SomeDirectiveFactory, 'Incorrect SomeDirective.ngFactoryDef');
|
||||
expectEmit(source, MyComponentDefinition, 'Incorrect MyComponentDefinition.ngComponentDef');
|
||||
expectEmit(source, MyComponentFactory, 'Incorrect MyComponentDefinition.ngFactoryDef');
|
||||
});
|
||||
|
||||
it('should support complex selectors', () => {
|
||||
@ -608,25 +613,31 @@ describe('compiler compliance', () => {
|
||||
const SomeDirectiveDefinition = `
|
||||
SomeDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: SomeDirective,
|
||||
selectors: [["div", "some-directive", "", 8, "foo", 3, "title", "", 9, "baz"]],
|
||||
factory: function SomeDirective_Factory(t) {return new (t || SomeDirective)(); }
|
||||
selectors: [["div", "some-directive", "", 8, "foo", 3, "title", "", 9, "baz"]]
|
||||
});
|
||||
`;
|
||||
|
||||
const SomeDirectiveFactory =
|
||||
`SomeDirective.ngFactoryDef = function SomeDirective_Factory(t) {return new (t || SomeDirective)(); };`;
|
||||
|
||||
// OtherDirective definition should be:
|
||||
const OtherDirectiveDefinition = `
|
||||
OtherDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: OtherDirective,
|
||||
selectors: [["", 5, "span", "title", "", 9, "baz"]],
|
||||
factory: function OtherDirective_Factory(t) {return new (t || OtherDirective)(); }
|
||||
selectors: [["", 5, "span", "title", "", 9, "baz"]]
|
||||
});
|
||||
`;
|
||||
|
||||
const OtherDirectiveFactory =
|
||||
`OtherDirective.ngFactoryDef = function OtherDirective_Factory(t) {return new (t || OtherDirective)(); };`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, SomeDirectiveDefinition, 'Incorrect SomeDirective.ngDirectiveDef');
|
||||
expectEmit(source, SomeDirectiveFactory, 'Incorrect SomeDirective.ngFactoryDef');
|
||||
expectEmit(source, OtherDirectiveDefinition, 'Incorrect OtherDirective.ngDirectiveDef');
|
||||
expectEmit(source, OtherDirectiveFactory, 'Incorrect OtherDirective.ngFactoryDef');
|
||||
});
|
||||
|
||||
it('should support components without selector', () => {
|
||||
@ -650,7 +661,6 @@ describe('compiler compliance', () => {
|
||||
EmptyOutletComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: EmptyOutletComponent,
|
||||
selectors: [["ng-component"]],
|
||||
factory: function EmptyOutletComponent_Factory(t) { return new (t || EmptyOutletComponent)(); },
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function EmptyOutletComponent_Template(rf, ctx) {
|
||||
@ -662,11 +672,16 @@ describe('compiler compliance', () => {
|
||||
});
|
||||
`;
|
||||
|
||||
const EmptyOutletComponentFactory =
|
||||
`EmptyOutletComponent.ngFactoryDef = function EmptyOutletComponent_Factory(t) { return new (t || EmptyOutletComponent)(); };`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(
|
||||
source, EmptyOutletComponentDefinition, 'Incorrect EmptyOutletComponent.ngComponentDef');
|
||||
expectEmit(
|
||||
source, EmptyOutletComponentFactory, 'Incorrect EmptyOutletComponent.ngFactoryDef');
|
||||
});
|
||||
|
||||
it('should not treat ElementRef, ViewContainerRef, or ChangeDetectorRef specially when injecting',
|
||||
@ -695,21 +710,23 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) {
|
||||
return new (t || MyComponent)(
|
||||
$r3$.ɵɵdirectiveInject($i$.ElementRef), $r3$.ɵɵdirectiveInject($i$.ViewContainerRef),
|
||||
$r3$.ɵɵdirectiveInject($i$.ChangeDetectorRef));
|
||||
},
|
||||
consts: 0,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, ctx) {},
|
||||
encapsulation: 2
|
||||
});`;
|
||||
|
||||
const MyComponentFactory = `MyComponent.ngFactoryDef = function MyComponent_Factory(t) {
|
||||
return new (t || MyComponent)(
|
||||
$r3$.ɵɵdirectiveInject($i$.ElementRef), $r3$.ɵɵdirectiveInject($i$.ViewContainerRef),
|
||||
$r3$.ɵɵdirectiveInject($i$.ChangeDetectorRef));
|
||||
};`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, MyComponentDefinition, 'Incorrect MyComponent.ngComponentDef');
|
||||
expectEmit(source, MyComponentFactory, 'Incorrect MyComponent.ngFactoryDef');
|
||||
});
|
||||
|
||||
it('should support structural directives', () => {
|
||||
@ -740,9 +757,11 @@ describe('compiler compliance', () => {
|
||||
const IfDirectiveDefinition = `
|
||||
IfDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: IfDirective,
|
||||
selectors: [["", "if", ""]],
|
||||
factory: function IfDirective_Factory(t) { return new (t || IfDirective)($r3$.ɵɵdirectiveInject($i$.TemplateRef)); }
|
||||
selectors: [["", "if", ""]]
|
||||
});`;
|
||||
const IfDirectiveFactory =
|
||||
`IfDirective.ngFactoryDef = function IfDirective_Factory(t) { return new (t || IfDirective)($r3$.ɵɵdirectiveInject($i$.TemplateRef)); };`;
|
||||
|
||||
const MyComponentDefinition = `
|
||||
const $c1$ = ["foo", ""];
|
||||
const $c2$ = [${AttributeMarker.Template}, "if"];
|
||||
@ -763,7 +782,6 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 3,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -777,11 +795,16 @@ describe('compiler compliance', () => {
|
||||
encapsulation: 2
|
||||
});`;
|
||||
|
||||
const MyComponentFactory =
|
||||
`MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); };`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, IfDirectiveDefinition, 'Incorrect IfDirective.ngDirectiveDef');
|
||||
expectEmit(source, IfDirectiveFactory, 'Incorrect IfDirective.ngFactoryDef');
|
||||
expectEmit(source, MyComponentDefinition, 'Incorrect MyComponent.ngComponentDef');
|
||||
expectEmit(source, MyComponentFactory, 'Incorrect MyComponent.ngFactoryDef');
|
||||
});
|
||||
|
||||
describe('value composition', () => {
|
||||
@ -826,7 +849,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
|
||||
consts: 1,
|
||||
vars: 3,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -908,7 +930,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
|
||||
consts: 1,
|
||||
vars: 11,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -971,7 +992,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
|
||||
consts: 1,
|
||||
vars: 3,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -1039,7 +1059,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
|
||||
consts: 1,
|
||||
vars: 8,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -1100,7 +1119,6 @@ describe('compiler compliance', () => {
|
||||
SimpleComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: SimpleComponent,
|
||||
selectors: [["simple"]],
|
||||
factory: function SimpleComponent_Factory(t) { return new (t || SimpleComponent)(); },
|
||||
ngContentSelectors: $c0$,
|
||||
consts: 2,
|
||||
vars: 0,
|
||||
@ -1123,7 +1141,6 @@ describe('compiler compliance', () => {
|
||||
ComplexComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: ComplexComponent,
|
||||
selectors: [["complex"]],
|
||||
factory: function ComplexComponent_Factory(t) { return new (t || ComplexComponent)(); },
|
||||
ngContentSelectors: _c4,
|
||||
consts: 4,
|
||||
vars: 0,
|
||||
@ -1179,7 +1196,6 @@ describe('compiler compliance', () => {
|
||||
Cmp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: Cmp,
|
||||
selectors: [["ng-component"]],
|
||||
factory: function Cmp_Factory(t) { return new (t || Cmp)(); },
|
||||
ngContentSelectors: $c1$,
|
||||
consts: 3,
|
||||
vars: 0,
|
||||
@ -1368,9 +1384,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) {
|
||||
return new(t || MyApp)();
|
||||
},
|
||||
consts: 2,
|
||||
vars: 0,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -1423,9 +1436,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) {
|
||||
return new(t || MyApp)();
|
||||
},
|
||||
consts: 2,
|
||||
vars: 0,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -1489,7 +1499,6 @@ describe('compiler compliance', () => {
|
||||
ViewQueryComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: ViewQueryComponent,
|
||||
selectors: [["view-query-component"]],
|
||||
factory: function ViewQueryComponent_Factory(t) { return new (t || ViewQueryComponent)(); },
|
||||
viewQuery: function ViewQueryComponent_Query(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵviewQuery(SomeDirective, true);
|
||||
@ -1600,7 +1609,6 @@ describe('compiler compliance', () => {
|
||||
ViewQueryComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: ViewQueryComponent,
|
||||
selectors: [["view-query-component"]],
|
||||
factory: function ViewQueryComponent_Factory(t) { return new (t || ViewQueryComponent)(); },
|
||||
viewQuery: function ViewQueryComponent_Query(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵstaticViewQuery(SomeDirective, true);
|
||||
@ -1727,9 +1735,6 @@ describe('compiler compliance', () => {
|
||||
ContentQueryComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: ContentQueryComponent,
|
||||
selectors: [["content-query-component"]],
|
||||
factory: function ContentQueryComponent_Factory(t) {
|
||||
return new (t || ContentQueryComponent)();
|
||||
},
|
||||
contentQueries: function ContentQueryComponent_ContentQueries(rf, ctx, dirIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵcontentQuery(dirIndex, SomeDirective, true);
|
||||
@ -1849,9 +1854,6 @@ describe('compiler compliance', () => {
|
||||
ContentQueryComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: ContentQueryComponent,
|
||||
selectors: [["content-query-component"]],
|
||||
factory: function ContentQueryComponent_Factory(t) {
|
||||
return new (t || ContentQueryComponent)();
|
||||
},
|
||||
contentQueries: function ContentQueryComponent_ContentQueries(rf, ctx, dirIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵstaticContentQuery(dirIndex, SomeDirective, true);
|
||||
@ -1988,19 +1990,25 @@ describe('compiler compliance', () => {
|
||||
MyPipe.ngPipeDef = $r3$.ɵɵdefinePipe({
|
||||
name: "myPipe",
|
||||
type: MyPipe,
|
||||
factory: function MyPipe_Factory(t) { return new (t || MyPipe)(); },
|
||||
pure: false
|
||||
});
|
||||
`;
|
||||
|
||||
const MyPipengFactoryDef = `
|
||||
MyPipe.ngFactoryDef = function MyPipe_Factory(t) { return new (t || MyPipe)(); };
|
||||
`;
|
||||
|
||||
const MyPurePipeDefinition = `
|
||||
MyPurePipe.ngPipeDef = $r3$.ɵɵdefinePipe({
|
||||
name: "myPurePipe",
|
||||
type: MyPurePipe,
|
||||
factory: function MyPurePipe_Factory(t) { return new (t || MyPurePipe)(); },
|
||||
pure: true
|
||||
});`;
|
||||
|
||||
const MyPurePipengFactoryDef = `
|
||||
MyPurePipe.ngFactoryDef = function MyPurePipe_Factory(t) { return new (t || MyPurePipe)(); };
|
||||
`;
|
||||
|
||||
const MyAppDefinition = `
|
||||
const $c0$ = function ($a0$) {
|
||||
return [$a0$, 1, 2, 3, 4, 5];
|
||||
@ -2009,7 +2017,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
|
||||
consts: 7,
|
||||
vars: 20,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -2037,7 +2044,9 @@ describe('compiler compliance', () => {
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, MyPipeDefinition, 'Invalid pipe definition');
|
||||
expectEmit(source, MyPipengFactoryDef, 'Invalid pipe factory function');
|
||||
expectEmit(source, MyPurePipeDefinition, 'Invalid pure pipe definition');
|
||||
expectEmit(source, MyPurePipengFactoryDef, 'Invalid pure pipe factory function');
|
||||
expectEmit(source, MyAppDefinition, 'Invalid MyApp definition');
|
||||
});
|
||||
|
||||
@ -2075,7 +2084,6 @@ describe('compiler compliance', () => {
|
||||
MyApp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyApp,
|
||||
selectors: [["my-app"]],
|
||||
factory: function MyApp_Factory(t) { return new (t || MyApp)(); },
|
||||
consts: 6,
|
||||
vars: 27,
|
||||
template: function MyApp_Template(rf, ctx) {
|
||||
@ -2148,24 +2156,32 @@ describe('compiler compliance', () => {
|
||||
MyPipe.ngPipeDef = $r3$.ɵɵdefinePipe({
|
||||
name: "myPipe",
|
||||
type: MyPipe,
|
||||
factory: function MyPipe_Factory(t) { return new (t || MyPipe)($r3$.ɵɵinjectPipeChangeDetectorRef()); },
|
||||
pure: true
|
||||
});
|
||||
`;
|
||||
|
||||
const MyPipeFactory = `
|
||||
MyPipe.ngFactoryDef = function MyPipe_Factory(t) { return new (t || MyPipe)($r3$.ɵɵinjectPipeChangeDetectorRef()); };
|
||||
`;
|
||||
|
||||
const MyOtherPipeDefinition = `
|
||||
MyOtherPipe.ngPipeDef = $r3$.ɵɵdefinePipe({
|
||||
name: "myOtherPipe",
|
||||
type: MyOtherPipe,
|
||||
factory: function MyOtherPipe_Factory(t) { return new (t || MyOtherPipe)($r3$.ɵɵinjectPipeChangeDetectorRef(8)); },
|
||||
pure: true
|
||||
});`;
|
||||
|
||||
const MyOtherPipeFactory = `
|
||||
MyOtherPipe.ngFactoryDef = function MyOtherPipe_Factory(t) { return new (t || MyOtherPipe)($r3$.ɵɵinjectPipeChangeDetectorRef(8)); };
|
||||
`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, MyPipeDefinition, 'Invalid pipe definition');
|
||||
expectEmit(source, MyPipeFactory, 'Invalid pipe factory function');
|
||||
expectEmit(source, MyOtherPipeDefinition, 'Invalid alternate pipe definition');
|
||||
expectEmit(source, MyOtherPipeFactory, 'Invalid alternate pipe factory function');
|
||||
});
|
||||
|
||||
});
|
||||
@ -2191,7 +2207,6 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 3,
|
||||
vars: 1,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -2288,7 +2303,6 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 6,
|
||||
vars: 1,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -2434,7 +2448,6 @@ describe('compiler compliance', () => {
|
||||
LifecycleComp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: LifecycleComp,
|
||||
selectors: [["lifecycle-comp"]],
|
||||
factory: function LifecycleComp_Factory(t) { return new (t || LifecycleComp)(); },
|
||||
inputs: {nameMin: ["name", "nameMin"]},
|
||||
features: [$r3$.ɵɵNgOnChangesFeature()],
|
||||
consts: 0,
|
||||
@ -2447,7 +2460,6 @@ describe('compiler compliance', () => {
|
||||
SimpleLayout.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: SimpleLayout,
|
||||
selectors: [["simple-layout"]],
|
||||
factory: function SimpleLayout_Factory(t) { return new (t || SimpleLayout)(); },
|
||||
consts: 2,
|
||||
vars: 2,
|
||||
template: function SimpleLayout_Template(rf, ctx) {
|
||||
@ -2556,14 +2568,16 @@ describe('compiler compliance', () => {
|
||||
ForOfDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: ForOfDirective,
|
||||
selectors: [["", "forOf", ""]],
|
||||
factory: function ForOfDirective_Factory(t) {
|
||||
return new (t || ForOfDirective)($r3$.ɵɵdirectiveInject(ViewContainerRef), $r3$.ɵɵdirectiveInject(TemplateRef));
|
||||
},
|
||||
features: [$r3$.ɵɵNgOnChangesFeature()],
|
||||
inputs: {forOf: "forOf"}
|
||||
});
|
||||
`;
|
||||
|
||||
const ForDirectiveFactory =
|
||||
`ForOfDirective.ngFactoryDef = function ForOfDirective_Factory(t) {
|
||||
return new (t || ForOfDirective)($r3$.ɵɵdirectiveInject(ViewContainerRef), $r3$.ɵɵdirectiveInject(TemplateRef));
|
||||
};`;
|
||||
|
||||
const MyComponentDefinition = `
|
||||
const $t1_attrs$ = [${AttributeMarker.Template}, "for", "forOf"];
|
||||
function MyComponent__svg_g_1_Template(rf, ctx) {
|
||||
@ -2578,7 +2592,6 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 2,
|
||||
vars: 1,
|
||||
template: function MyComponent_Template(rf, ctx){
|
||||
@ -2603,6 +2616,7 @@ describe('compiler compliance', () => {
|
||||
|
||||
// TODO(benlesh): Enforce this when the directives are specified
|
||||
// expectEmit(source, ForDirectiveDefinition, 'Invalid directive definition');
|
||||
// expectEmit(source, ForDirectiveFactory, 'Invalid directive factory');
|
||||
expectEmit(source, MyComponentDefinition, 'Invalid component definition');
|
||||
});
|
||||
|
||||
@ -2635,14 +2649,17 @@ describe('compiler compliance', () => {
|
||||
ForOfDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: ForOfDirective,
|
||||
selectors: [["", "forOf", ""]],
|
||||
factory: function ForOfDirective_Factory(t) {
|
||||
return new (t || ForOfDirective)($r3$.ɵɵdirectiveInject(ViewContainerRef), $r3$.ɵɵdirectiveInject(TemplateRef));
|
||||
},
|
||||
features: [$r3$.ɵɵNgOnChangesFeature()],
|
||||
inputs: {forOf: "forOf"}
|
||||
});
|
||||
`;
|
||||
|
||||
const ForDirectiveFactory = `
|
||||
ForOfDirective.ngFactoryDef = function ForOfDirective_Factory(t) {
|
||||
return new (t || ForOfDirective)($r3$.ɵɵdirectiveInject(ViewContainerRef), $r3$.ɵɵdirectiveInject(TemplateRef));
|
||||
};
|
||||
`;
|
||||
|
||||
const MyComponentDefinition = `
|
||||
const $t1_attrs$ = [${AttributeMarker.Template}, "for", "forOf"];
|
||||
function MyComponent_li_1_Template(rf, ctx) {
|
||||
@ -2661,7 +2678,6 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 2,
|
||||
vars: 1,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -2685,6 +2701,7 @@ describe('compiler compliance', () => {
|
||||
|
||||
// TODO(chuckj): Enforce this when the directives are specified
|
||||
// expectEmit(source, ForDirectiveDefinition, 'Invalid directive definition');
|
||||
// expectEmit(source, ForDirectiveFactory, 'Invalid directive factory');
|
||||
expectEmit(source, MyComponentDefinition, 'Invalid component definition');
|
||||
});
|
||||
|
||||
@ -2765,7 +2782,6 @@ describe('compiler compliance', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 2,
|
||||
vars: 1,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -2883,7 +2899,6 @@ describe('compiler compliance', () => {
|
||||
SomeDirective.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: SomeDirective,
|
||||
selectors: [["", "some-directive", ""]],
|
||||
factory: function SomeDirective_Factory(t) {return new (t || SomeDirective)(); },
|
||||
exportAs: ["someDir", "otherDir"]
|
||||
});
|
||||
`;
|
||||
|
@ -671,7 +671,6 @@ describe('compiler compliance: bindings', () => {
|
||||
HostBindingDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: HostBindingDir,
|
||||
selectors: [["", "hostBindingDir", ""]],
|
||||
factory: function HostBindingDir_Factory(t) { return new (t || HostBindingDir)(); },
|
||||
hostBindings: function HostBindingDir_HostBindings(rf, ctx, elIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵallocHostVars(1);
|
||||
@ -718,7 +717,6 @@ describe('compiler compliance: bindings', () => {
|
||||
HostBindingComp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: HostBindingComp,
|
||||
selectors: [["host-binding-comp"]],
|
||||
factory: function HostBindingComp_Factory(t) { return new (t || HostBindingComp)(); },
|
||||
hostBindings: function HostBindingComp_HostBindings(rf, ctx, elIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵallocHostVars(3);
|
||||
@ -766,7 +764,6 @@ describe('compiler compliance: bindings', () => {
|
||||
HostAttributeDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: HostAttributeDir,
|
||||
selectors: [["", "hostAttributeDir", ""]],
|
||||
factory: function HostAttributeDir_Factory(t) { return new (t || HostAttributeDir)(); },
|
||||
hostBindings: function HostAttributeDir_HostBindings(rf, ctx, elIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵallocHostVars(1);
|
||||
@ -811,7 +808,6 @@ describe('compiler compliance: bindings', () => {
|
||||
HostAttributeDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: HostAttributeDir,
|
||||
selectors: [["", "hostAttributeDir", ""]],
|
||||
factory: function HostAttributeDir_Factory(t) { return new (t || HostAttributeDir)(); },
|
||||
hostBindings: function HostAttributeDir_HostBindings(rf, ctx, elIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵelementHostAttrs($c0$);
|
||||
@ -869,7 +865,6 @@ describe('compiler compliance: bindings', () => {
|
||||
HostAttributeComp.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: HostAttributeComp,
|
||||
selectors: [["my-host-attribute-component"]],
|
||||
factory: function HostAttributeComp_Factory(t) { return new (t || HostAttributeComp)(); },
|
||||
hostBindings: function HostAttributeComp_HostBindings(rf, ctx, elIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵelementHostAttrs($c0$);
|
||||
@ -881,7 +876,6 @@ describe('compiler compliance: bindings', () => {
|
||||
HostAttributeDir.ngDirectiveDef = $r3$.ɵɵdefineDirective({
|
||||
type: HostAttributeDir,
|
||||
selectors: [["", "hostAttributeDir", ""]],
|
||||
factory: function HostAttributeDir_Factory(t) { return new (t || HostAttributeDir)(); },
|
||||
hostBindings: function HostAttributeDir_HostBindings(rf, ctx, elIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵallocHostVars(2);
|
||||
|
@ -48,7 +48,7 @@ describe('compiler compliance: dependency injection', () => {
|
||||
};
|
||||
|
||||
const factory = `
|
||||
factory: function MyComponent_Factory(t) {
|
||||
MyComponent.ngFactoryDef = function MyComponent_Factory(t) {
|
||||
return new (t || MyComponent)(
|
||||
$r3$.ɵɵinjectAttribute('name'),
|
||||
$r3$.ɵɵdirectiveInject(MyService),
|
||||
|
@ -41,7 +41,6 @@ describe('compiler compliance: directives', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -53,10 +52,15 @@ describe('compiler compliance: directives', () => {
|
||||
});
|
||||
`;
|
||||
|
||||
const MyComponentFactory = `
|
||||
MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); };
|
||||
`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ngComponentDef');
|
||||
expectEmit(source, MyComponentFactory, 'Incorrect ChildComponent.ngFactoryDef');
|
||||
});
|
||||
|
||||
it('should not match directives on i18n-prefixed attributes', () => {
|
||||
@ -87,7 +91,6 @@ describe('compiler compliance: directives', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -99,10 +102,15 @@ describe('compiler compliance: directives', () => {
|
||||
});
|
||||
`;
|
||||
|
||||
const MyComponentFactory = `
|
||||
MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); };
|
||||
`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, MyComponentDefinition, 'Incorrect ChildComponent.ngComponentDef');
|
||||
expectEmit(source, MyComponentFactory, 'Incorrect ChildComponent.ngFactoryDef');
|
||||
});
|
||||
|
||||
it('should match directives on element bindings', () => {
|
||||
|
@ -201,7 +201,6 @@ describe('compiler compliance: listen()', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 4,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -222,10 +221,15 @@ describe('compiler compliance: listen()', () => {
|
||||
});
|
||||
`;
|
||||
|
||||
const MyComponentFactory = `
|
||||
MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); };
|
||||
`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
const source = result.source;
|
||||
|
||||
expectEmit(source, MyComponentDefinition, 'Incorrect MyComponent.ngComponentDef');
|
||||
expectEmit(source, MyComponentFactory, 'Incorrect MyComponent.ngFactoryDef');
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -144,10 +144,10 @@ describe('compiler compliance: providers', () => {
|
||||
result.source, `
|
||||
export class MyComponent {
|
||||
}
|
||||
MyComponent.ngFactoryDef = function MyComponent_Factory(t) { return new (t || MyComponent)(); };
|
||||
MyComponent.ngComponentDef = i0.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) { return new (t || MyComponent)(); },
|
||||
consts: 1,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
|
@ -131,9 +131,6 @@ describe('compiler compliance: styling', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors:[["my-component"]],
|
||||
factory:function MyComponent_Factory(t){
|
||||
return new (t || MyComponent)();
|
||||
},
|
||||
consts: 0,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, $ctx$) {
|
||||
@ -173,9 +170,6 @@ describe('compiler compliance: styling', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors:[["my-component"]],
|
||||
factory:function MyComponent_Factory(t){
|
||||
return new (t || MyComponent)();
|
||||
},
|
||||
consts: 0,
|
||||
vars: 0,
|
||||
template: function MyComponent_Template(rf, $ctx$) {
|
||||
@ -524,9 +518,6 @@ describe('compiler compliance: styling', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors:[["my-component"]],
|
||||
factory:function MyComponent_Factory(t){
|
||||
return new (t || MyComponent)();
|
||||
},
|
||||
consts: 1,
|
||||
vars: 4,
|
||||
template: function MyComponent_Template(rf, $ctx$) {
|
||||
@ -577,9 +568,6 @@ describe('compiler compliance: styling', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors: [["my-component"]],
|
||||
factory: function MyComponent_Factory(t) {
|
||||
return new (t || MyComponent)();
|
||||
},
|
||||
consts: 1,
|
||||
vars: 1,
|
||||
template: function MyComponent_Template(rf, ctx) {
|
||||
@ -736,9 +724,6 @@ describe('compiler compliance: styling', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors:[["my-component"]],
|
||||
factory:function MyComponent_Factory(t){
|
||||
return new (t || MyComponent)();
|
||||
},
|
||||
consts: 1,
|
||||
vars: 4,
|
||||
template: function MyComponent_Template(rf, $ctx$) {
|
||||
@ -791,9 +776,6 @@ describe('compiler compliance: styling', () => {
|
||||
MyComponent.ngComponentDef = $r3$.ɵɵdefineComponent({
|
||||
type: MyComponent,
|
||||
selectors:[["my-component"]],
|
||||
factory:function MyComponent_Factory(t){
|
||||
return new (t || MyComponent)();
|
||||
},
|
||||
consts: 1,
|
||||
vars: 2,
|
||||
template: function MyComponent_Template(rf, $ctx$) {
|
||||
|
@ -197,12 +197,14 @@ runInEachFileSystem(os => {
|
||||
|
||||
const jsContents = env.getContents('test.js');
|
||||
expect(jsContents).toContain('TestCmp.ngComponentDef = i0.ɵɵdefineComponent');
|
||||
expect(jsContents).toContain('TestCmp.ngFactoryDef = function');
|
||||
expect(jsContents).not.toContain('__decorate');
|
||||
|
||||
const dtsContents = env.getContents('test.d.ts');
|
||||
expect(dtsContents)
|
||||
.toContain(
|
||||
'static ngComponentDef: i0.ɵɵComponentDefWithMeta<TestCmp, "test-cmp", never, {}, {}, never>');
|
||||
expect(dtsContents).toContain('static ngFactoryDef: i0.ɵɵFactoryDef<TestCmp>');
|
||||
});
|
||||
|
||||
it('should compile Components (dynamic inline template) without errors', () => {
|
||||
@ -220,12 +222,15 @@ runInEachFileSystem(os => {
|
||||
|
||||
const jsContents = env.getContents('test.js');
|
||||
expect(jsContents).toContain('TestCmp.ngComponentDef = i0.ɵɵdefineComponent');
|
||||
expect(jsContents).toContain('TestCmp.ngFactoryDef = function');
|
||||
expect(jsContents).not.toContain('__decorate');
|
||||
|
||||
const dtsContents = env.getContents('test.d.ts');
|
||||
|
||||
expect(dtsContents)
|
||||
.toContain(
|
||||
'static ngComponentDef: i0.ɵɵComponentDefWithMeta<TestCmp, "test-cmp", never, {}, {}, never>');
|
||||
expect(dtsContents).toContain('static ngFactoryDef: i0.ɵɵFactoryDef<TestCmp>');
|
||||
});
|
||||
|
||||
it('should compile Components (function call inline template) without errors', () => {
|
||||
@ -246,12 +251,14 @@ runInEachFileSystem(os => {
|
||||
|
||||
const jsContents = env.getContents('test.js');
|
||||
expect(jsContents).toContain('TestCmp.ngComponentDef = i0.ɵɵdefineComponent');
|
||||
expect(jsContents).toContain('TestCmp.ngFactoryDef = function');
|
||||
expect(jsContents).not.toContain('__decorate');
|
||||
|
||||
const dtsContents = env.getContents('test.d.ts');
|
||||
expect(dtsContents)
|
||||
.toContain(
|
||||
'static ngComponentDef: i0.ɵɵComponentDefWithMeta<TestCmp, "test-cmp", never, {}, {}, never>');
|
||||
expect(dtsContents).toContain('static ngFactoryDef: i0.ɵɵFactoryDef<TestCmp>');
|
||||
});
|
||||
|
||||
it('should compile Components (external template) without errors', () => {
|
||||
@ -880,10 +887,13 @@ runInEachFileSystem(os => {
|
||||
|
||||
expect(jsContents)
|
||||
.toContain(
|
||||
'TestPipe.ngPipeDef = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, ' +
|
||||
'factory: function TestPipe_Factory(t) { return new (t || TestPipe)(); }, pure: false })');
|
||||
'TestPipe.ngPipeDef = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, pure: false })');
|
||||
expect(jsContents)
|
||||
.toContain(
|
||||
'TestPipe.ngFactoryDef = function TestPipe_Factory(t) { return new (t || TestPipe)(); }');
|
||||
expect(dtsContents)
|
||||
.toContain('static ngPipeDef: i0.ɵɵPipeDefWithMeta<TestPipe, "test-pipe">;');
|
||||
expect(dtsContents).toContain('static ngFactoryDef: i0.ɵɵFactoryDef<TestPipe>;');
|
||||
});
|
||||
|
||||
it('should compile pure Pipes without errors', () => {
|
||||
@ -903,10 +913,13 @@ runInEachFileSystem(os => {
|
||||
|
||||
expect(jsContents)
|
||||
.toContain(
|
||||
'TestPipe.ngPipeDef = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, ' +
|
||||
'factory: function TestPipe_Factory(t) { return new (t || TestPipe)(); }, pure: true })');
|
||||
'TestPipe.ngPipeDef = i0.ɵɵdefinePipe({ name: "test-pipe", type: TestPipe, pure: true })');
|
||||
expect(jsContents)
|
||||
.toContain(
|
||||
'TestPipe.ngFactoryDef = function TestPipe_Factory(t) { return new (t || TestPipe)(); }');
|
||||
expect(dtsContents)
|
||||
.toContain('static ngPipeDef: i0.ɵɵPipeDefWithMeta<TestPipe, "test-pipe">;');
|
||||
expect(dtsContents).toContain('static ngFactoryDef: i0.ɵɵFactoryDef<TestPipe>;');
|
||||
});
|
||||
|
||||
it('should compile Pipes with dependencies', () => {
|
||||
@ -947,6 +960,7 @@ runInEachFileSystem(os => {
|
||||
const dtsContents = env.getContents('test.d.ts');
|
||||
expect(dtsContents)
|
||||
.toContain('static ngPipeDef: i0.ɵɵPipeDefWithMeta<TestPipe<any>, "test-pipe">;');
|
||||
expect(dtsContents).toContain('static ngFactoryDef: i0.ɵɵFactoryDef<TestPipe<any>>;');
|
||||
});
|
||||
|
||||
it('should include @Pipes in @NgModule scopes', () => {
|
||||
@ -1615,7 +1629,7 @@ runInEachFileSystem(os => {
|
||||
const jsContents = env.getContents('test.js');
|
||||
expect(jsContents)
|
||||
.toContain(
|
||||
`factory: function FooCmp_Factory(t) { return new (t || FooCmp)(i0.ɵɵinjectAttribute("test"), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.TemplateRef), i0.ɵɵdirectiveInject(i0.ViewContainerRef)); }`);
|
||||
`FooCmp.ngFactoryDef = function FooCmp_Factory(t) { return new (t || FooCmp)(i0.ɵɵinjectAttribute("test"), i0.ɵɵdirectiveInject(i0.ChangeDetectorRef), i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.Injector), i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i0.TemplateRef), i0.ɵɵdirectiveInject(i0.ViewContainerRef)); }`);
|
||||
});
|
||||
|
||||
it('should generate queries for components', () => {
|
||||
|
Reference in New Issue
Block a user