feat(ivy): add an IVY local the compiler which avoids analyzeModule (#23441)
closes #23289 Based on a spike by @chukjaz PR Close #23441
This commit is contained in:
@ -22,6 +22,7 @@ import {BindingParser} from '../../src/template_parser/binding_parser';
|
||||
import {OutputContext, escapeRegExp} from '../../src/util';
|
||||
import {MockAotCompilerHost, MockCompilerHost, MockData, MockDirectory, arrayToMockDir, expectNoDiagnostics, settings, toMockFileArray} from '../aot/test_util';
|
||||
|
||||
|
||||
const IDENTIFIER = /[A-Za-z_$ɵ][A-Za-z0-9_$]*/;
|
||||
const OPERATOR =
|
||||
/!|%|\*|\/|\^|&&?|\|\|?|\(|\)|\{|\}|\[|\]|:|;|<=?|>=?|={1,3}|!==?|=>|\+\+?|--?|@|,|\.|\.\.\./;
|
||||
@ -235,7 +236,7 @@ function doCompile(
|
||||
const errors: ParseError[] = [];
|
||||
|
||||
const hostBindingParser = new BindingParser(
|
||||
expressionParser, DEFAULT_INTERPOLATION_CONFIG, elementSchemaRegistry, [], errors);
|
||||
expressionParser, DEFAULT_INTERPOLATION_CONFIG, elementSchemaRegistry, null, errors);
|
||||
|
||||
// Load all directives and pipes
|
||||
for (const pipeOrDirective of pipesOrDirectives) {
|
||||
@ -278,22 +279,45 @@ export function compile(
|
||||
continue;
|
||||
}
|
||||
if (resolver.isDirective(pipeOrDirective)) {
|
||||
const metadata = resolver.getDirectiveMetadata(pipeOrDirective);
|
||||
if (metadata.isComponent) {
|
||||
const directive = resolver.getDirectiveMetadata(pipeOrDirective);
|
||||
if (directive.isComponent) {
|
||||
const fakeUrl = 'ng://fake-template-url.html';
|
||||
const htmlAst = htmlParser.parse(metadata.template !.template !, fakeUrl);
|
||||
let htmlAst = htmlParser.parse(directive.template !.template !, fakeUrl);
|
||||
|
||||
// Map of StaticType by directive selectors
|
||||
const directiveTypeBySel = new Map<string, any>();
|
||||
|
||||
const directives = module.transitiveModule.directives.map(
|
||||
dir => resolver.getDirectiveSummary(dir.reference));
|
||||
|
||||
directives.forEach(directive => {
|
||||
if (directive.selector) {
|
||||
directiveTypeBySel.set(directive.selector, directive.type.reference);
|
||||
}
|
||||
});
|
||||
|
||||
// Map of StaticType by pipe names
|
||||
const pipeTypeByName = new Map<string, any>();
|
||||
|
||||
const pipes = module.transitiveModule.pipes.map(
|
||||
pipe => resolver.getPipeSummary(pipe.reference));
|
||||
const parsedTemplate = templateParser.parse(
|
||||
metadata, htmlAst, directives, pipes, module.schemas, fakeUrl, false);
|
||||
|
||||
pipes.forEach(pipe => { pipeTypeByName.set(pipe.name, pipe.type.reference); });
|
||||
|
||||
const preserveWhitespaces = directive.template !.preserveWhitespaces;
|
||||
if (!preserveWhitespaces) {
|
||||
htmlAst = removeWhitespaces(htmlAst);
|
||||
}
|
||||
const transform = new HtmlToTemplateTransform(hostBindingParser);
|
||||
const nodes = html.visitAll(transform, htmlAst.rootNodes, null);
|
||||
const hasNgContent = transform.hasNgContent;
|
||||
const ngContentSelectors = transform.ngContentSelectors;
|
||||
|
||||
compileComponent(
|
||||
outputCtx, metadata, pipes, parsedTemplate.template, reflector, hostBindingParser);
|
||||
outputCtx, directive, nodes, hasNgContent, ngContentSelectors, reflector,
|
||||
hostBindingParser, directiveTypeBySel, pipeTypeByName);
|
||||
} else {
|
||||
compileDirective(
|
||||
outputCtx, metadata, reflector, hostBindingParser);
|
||||
compileDirective(outputCtx, directive, reflector, hostBindingParser);
|
||||
}
|
||||
} else if (resolver.isPipe(pipeOrDirective)) {
|
||||
const metadata = resolver.getPipeMetadata(pipeOrDirective);
|
||||
|
@ -344,11 +344,11 @@ describe('compiler compliance', () => {
|
||||
template: function MyComponent_Template(rf: IDENT, ctx: IDENT) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'ul', null, $c1$);
|
||||
$r3$.ɵC(2, MyComponent_IfDirective_Template_2, null, $c2$);
|
||||
$r3$.ɵC(2, MyComponent_li_Template_2, null, $c2$);
|
||||
$r3$.ɵe();
|
||||
}
|
||||
const $foo$ = $r3$.ɵld(1);
|
||||
function MyComponent_IfDirective_Template_2(rf: IDENT, ctx0: IDENT) {
|
||||
function MyComponent_li_Template_2(rf: IDENT, ctx0: IDENT) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'li');
|
||||
$r3$.ɵT(1);
|
||||
@ -359,7 +359,7 @@ describe('compiler compliance', () => {
|
||||
}
|
||||
}
|
||||
},
|
||||
directives: [IfDirective]
|
||||
directives:[IfDirective]
|
||||
});`;
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
@ -420,7 +420,7 @@ describe('compiler compliance', () => {
|
||||
$r3$.ɵp(0, 'names', $r3$.ɵb($r3$.ɵf1($e0_ff$, ctx.customName)));
|
||||
}
|
||||
},
|
||||
directives: [MyComp]
|
||||
directives: [MyComp]
|
||||
});
|
||||
`;
|
||||
|
||||
@ -1147,7 +1147,7 @@ describe('compiler compliance', () => {
|
||||
`;
|
||||
|
||||
const MyComponentDefinition = `
|
||||
const $_c0$ = ['forOf',''];
|
||||
const $_c0$ = ['for','','forOf',''];
|
||||
…
|
||||
static ngComponentDef = $r3$.ɵdefineComponent({
|
||||
type: MyComponent,
|
||||
@ -1156,14 +1156,14 @@ describe('compiler compliance', () => {
|
||||
template: function MyComponent_Template(rf: IDENT, ctx: IDENT) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'ul');
|
||||
$r3$.ɵC(1, MyComponent_ForOfDirective_Template_1, null, $_c0$);
|
||||
$r3$.ɵC(1, MyComponent_li_Template_1, null, $_c0$);
|
||||
$r3$.ɵe();
|
||||
}
|
||||
if (rf & 2) {
|
||||
$r3$.ɵp(1, 'forOf', $r3$.ɵb(ctx.items));
|
||||
}
|
||||
|
||||
function MyComponent_ForOfDirective_Template_1(rf: IDENT, ctx0: IDENT) {
|
||||
function MyComponent_li_Template_1(rf: IDENT, ctx0: IDENT) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'li');
|
||||
$r3$.ɵT(1);
|
||||
@ -1225,7 +1225,7 @@ describe('compiler compliance', () => {
|
||||
};
|
||||
|
||||
const MyComponentDefinition = `
|
||||
const $c1$ = ['forOf', ''];
|
||||
const $c1$ = ['for', '', 'forOf', ''];
|
||||
…
|
||||
static ngComponentDef = $r3$.ɵdefineComponent({
|
||||
type: MyComponent,
|
||||
@ -1234,21 +1234,21 @@ describe('compiler compliance', () => {
|
||||
template: function MyComponent_Template(rf: IDENT, ctx: IDENT) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'ul');
|
||||
$r3$.ɵC(1, MyComponent_ForOfDirective_Template_1, null, $c1$);
|
||||
$r3$.ɵC(1, MyComponent_li_Template_1, null, $c1$);
|
||||
$r3$.ɵe();
|
||||
}
|
||||
if (rf & 2) {
|
||||
$r3$.ɵp(1, 'forOf', $r3$.ɵb(ctx.items));
|
||||
}
|
||||
|
||||
function MyComponent_ForOfDirective_Template_1(rf: IDENT, ctx0: IDENT) {
|
||||
function MyComponent_li_Template_1(rf: IDENT, ctx0: IDENT) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'li');
|
||||
$r3$.ɵE(1, 'div');
|
||||
$r3$.ɵT(2);
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵE(3, 'ul');
|
||||
$r3$.ɵC(4, MyComponent_ForOfDirective_ForOfDirective_Template_4, null, $c1$);
|
||||
$r3$.ɵC(4, MyComponent_li_li_Template_4, null, $c1$);
|
||||
$r3$.ɵe();
|
||||
$r3$.ɵe();
|
||||
}
|
||||
@ -1258,8 +1258,7 @@ describe('compiler compliance', () => {
|
||||
$r3$.ɵp(4, 'forOf', $r3$.ɵb(IDENT.infos));
|
||||
}
|
||||
|
||||
function MyComponent_ForOfDirective_ForOfDirective_Template_4(
|
||||
rf: IDENT, ctx1: IDENT) {
|
||||
function MyComponent_li_li_Template_4(rf: IDENT, ctx1: IDENT) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'li');
|
||||
$r3$.ɵT(1);
|
||||
|
@ -51,8 +51,7 @@ describe('compiler compliance: listen()', () => {
|
||||
}
|
||||
};
|
||||
|
||||
// The template should look like this (where IDENT is a wild card for an identifier):
|
||||
const template = `
|
||||
const componentDef = `
|
||||
static ngComponentDef = IDENT.ɵdefineComponent({
|
||||
…
|
||||
inputs:{
|
||||
@ -63,9 +62,10 @@ describe('compiler compliance: listen()', () => {
|
||||
componentOutput: 'componentOutput',
|
||||
originalComponentOutput: 'renamedComponentOutput'
|
||||
}
|
||||
});
|
||||
…
|
||||
static ngDirectiveDef = IDENT.ɵdefineDirective({
|
||||
});`;
|
||||
|
||||
const directiveDef = `
|
||||
static ngDirectiveDef = IDENT.ɵdefineDirective({
|
||||
…
|
||||
inputs:{
|
||||
directiveInput: 'directiveInput',
|
||||
@ -80,7 +80,8 @@ describe('compiler compliance: listen()', () => {
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
|
||||
expectEmit(result.source, template, 'Incorrect template');
|
||||
expectEmit(result.source, componentDef, 'Incorrect component definition');
|
||||
expectEmit(result.source, directiveDef, 'Incorrect directive definition');
|
||||
});
|
||||
|
||||
});
|
@ -44,7 +44,7 @@ describe('compiler compliance: listen()', () => {
|
||||
template: function MyComponent_Template(rf: $RenderFlags$, ctx: $MyComponent$) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵE(0, 'div');
|
||||
$r3$.ɵL('click', function MyComponent_Template_div_click_listener($event: $any$) {
|
||||
$r3$.ɵL('click', function MyComponent_Template_div_click_listener($event: $any$) {
|
||||
ctx.onClick($event);
|
||||
return (1 == 2);
|
||||
});
|
||||
@ -53,7 +53,6 @@ describe('compiler compliance: listen()', () => {
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
|
||||
expectEmit(result.source, template, 'Incorrect template');
|
||||
|
@ -28,7 +28,7 @@ describe('compiler compliance: template', () => {
|
||||
template: \`
|
||||
<ul *ngFor="let outer of items">
|
||||
<li *ngFor="let middle of outer.items">
|
||||
<div *ngFor="let inner of items"
|
||||
<div *ngFor="let inner of items"
|
||||
(click)="onClick(outer, middle, inner)"
|
||||
[title]="format(outer, middle, inner, component)"
|
||||
>
|
||||
@ -51,58 +51,59 @@ describe('compiler compliance: template', () => {
|
||||
|
||||
// The template should look like this (where IDENT is a wild card for an identifier):
|
||||
const template = `
|
||||
template:function MyComponent_Template(rf: IDENT, ctx: IDENT){
|
||||
if (rf & 1) {
|
||||
$i0$.ɵC(0, MyComponent_NgForOf_Template_0, null, _c0);
|
||||
const $c0$ = ['ngFor','','ngForOf',''];
|
||||
// ...
|
||||
template:function MyComponent_Template(rf: IDENT, $ctx$: IDENT){
|
||||
if (rf & 1) {
|
||||
$i0$.ɵC(0, MyComponent_ul_Template_0, null, _c0);
|
||||
}
|
||||
if (rf & 2) {
|
||||
$i0$.ɵp(0, 'ngForOf', $i0$.ɵb(ctx.items));
|
||||
$i0$.ɵp(0, 'ngForOf', $i0$.ɵb($ctx$.items));
|
||||
}
|
||||
|
||||
function MyComponent_NgForOf_Template_0(rf: IDENT, ctx0: IDENT) {
|
||||
|
||||
function MyComponent_ul_Template_0(rf: IDENT, $ctx0$: IDENT) {
|
||||
if (rf & 1) {
|
||||
$i0$.ɵE(0, 'ul');
|
||||
$i0$.ɵC(1, MyComponent_NgForOf_NgForOf_Template_1, null, _c0);
|
||||
$i0$.ɵC(1, MyComponent_ul_li_Template_1, null, _c0);
|
||||
$i0$.ɵe();
|
||||
}
|
||||
if (rf & 2) {
|
||||
const $outer$ = ctx0.$implicit;
|
||||
const $outer$ = $ctx0$.$implicit;
|
||||
$i0$.ɵp(1, 'ngForOf', $i0$.ɵb($outer$.items));
|
||||
}
|
||||
function MyComponent_NgForOf_NgForOf_Template_1(rf: IDENT, ctx1: IDENT) {
|
||||
function MyComponent_ul_li_Template_1(rf: IDENT, $ctx1$: IDENT) {
|
||||
if (rf & 1) {
|
||||
$i0$.ɵE(0, 'li');
|
||||
$i0$.ɵC(1, MyComponent_NgForOf_NgForOf_NgForOf_Template_1, null, _c0);
|
||||
$i0$.ɵC(1, MyComponent_ul_li_div_Template_1, null, _c0);
|
||||
$i0$.ɵe();
|
||||
}
|
||||
if (rf & 2) {
|
||||
$i0$.ɵp(1, 'ngForOf', $i0$.ɵb(ctx.items));
|
||||
$i0$.ɵp(1, 'ngForOf', $i0$.ɵb($ctx$.items));
|
||||
}
|
||||
function MyComponent_NgForOf_NgForOf_NgForOf_Template_1(rf: IDENT, ctx2: IDENT) {
|
||||
function MyComponent_ul_li_div_Template_1(rf: IDENT, $ctx2$: IDENT) {
|
||||
if (rf & 1) {
|
||||
$i0$.ɵE(0, 'div');
|
||||
$i0$.ɵL('click', function MyComponent_NgForOf_NgForOf_NgForOf_Template_1_div_click_listener($event:any){
|
||||
const $outer$ = ctx0.$implicit;
|
||||
const $middle$ = ctx1.$implicit;
|
||||
const $inner$ = ctx2.$implicit;
|
||||
$i0$.ɵL('click', function MyComponent_ul_li_div_Template_1_div_click_listener($event:any){
|
||||
const $outer$ = $ctx0$.$implicit;
|
||||
const $middle$ = $ctx1$.$implicit;
|
||||
const $inner$ = $ctx2$.$implicit;
|
||||
return ctx.onClick($outer$, $middle$, $inner$);
|
||||
});
|
||||
$i0$.ɵT(1);
|
||||
$i0$.ɵe();
|
||||
}
|
||||
if (rf & 2) {
|
||||
const $outer$ = ctx0.$implicit;
|
||||
const $middle$ = ctx1.$implicit;
|
||||
const $inner$ = ctx2.$implicit;
|
||||
$i0$.ɵp(0, 'title', $i0$.ɵb(ctx.format($outer$, $middle$, $inner$, ctx.component)));
|
||||
$i0$.ɵt(1, $i0$.ɵi1(' ', ctx.format($outer$, $middle$, $inner$, ctx.component), ' '));
|
||||
const $outer$ = $ctx0$.$implicit;
|
||||
const $middle$ = $ctx1$.$implicit;
|
||||
const $inner$ = $ctx2$.$implicit;
|
||||
$i0$.ɵp(0, 'title', $i0$.ɵb(ctx.format($outer$, $middle$, $inner$, $ctx$.component)));
|
||||
$i0$.ɵt(1, $i0$.ɵi1(' ', ctx.format($outer$, $middle$, $inner$, $ctx$.component), ' '));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
|
||||
const result = compile(files, angularFiles);
|
||||
|
||||
expectEmit(result.source, template, 'Incorrect template');
|
||||
|
Reference in New Issue
Block a user