perf(ivy): avoid extra parameter in query instructions (#31667)
Currently we always generate the `read` parameter for the view and content query instructions, however since most of the time the `read` parameter won't be set, we'll end up generating `null` which adds 5 bytes for each query when minified. These changes make it so that the `read` parameter only gets generated if it has a value. PR Close #31667
This commit is contained in:
@ -280,7 +280,7 @@ runInEachFileSystem(() => {
|
||||
expect(addDefinitionsSpy.calls.first().args[2])
|
||||
.toEqual(
|
||||
`UndecoratedBase.ngBaseDef = ɵngcc0.ɵɵdefineBase({ viewQuery: function (rf, ctx) { if (rf & 1) {
|
||||
ɵngcc0.ɵɵstaticViewQuery(_c0, true, null);
|
||||
ɵngcc0.ɵɵstaticViewQuery(_c0, true);
|
||||
} if (rf & 2) {
|
||||
var _t;
|
||||
ɵngcc0.ɵɵqueryRefresh(_t = ɵngcc0.ɵɵloadViewQuery()) && (ctx.test = _t.first);
|
||||
|
@ -1530,8 +1530,8 @@ describe('compiler compliance', () => {
|
||||
factory: function ViewQueryComponent_Factory(t) { return new (t || ViewQueryComponent)(); },
|
||||
viewQuery: function ViewQueryComponent_Query(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵviewQuery(SomeDirective, true, null);
|
||||
$r3$.ɵɵviewQuery(SomeDirective, true, null);
|
||||
$r3$.ɵɵviewQuery(SomeDirective, true);
|
||||
$r3$.ɵɵviewQuery(SomeDirective, true);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -1588,8 +1588,8 @@ describe('compiler compliance', () => {
|
||||
…
|
||||
viewQuery: function ViewQueryComponent_Query(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵviewQuery($e0_attrs$, true, null);
|
||||
$r3$.ɵɵviewQuery($e1_attrs$, true, null);
|
||||
$r3$.ɵɵviewQuery($e0_attrs$, true);
|
||||
$r3$.ɵɵviewQuery($e1_attrs$, true);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -1641,8 +1641,8 @@ describe('compiler compliance', () => {
|
||||
factory: function ViewQueryComponent_Factory(t) { return new (t || ViewQueryComponent)(); },
|
||||
viewQuery: function ViewQueryComponent_Query(rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵstaticViewQuery(SomeDirective, true, null);
|
||||
$r3$.ɵɵviewQuery($refs$, true, null);
|
||||
$r3$.ɵɵstaticViewQuery(SomeDirective, true);
|
||||
$r3$.ɵɵviewQuery($refs$, true);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -1770,8 +1770,8 @@ describe('compiler compliance', () => {
|
||||
},
|
||||
contentQueries: function ContentQueryComponent_ContentQueries(rf, ctx, dirIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵcontentQuery(dirIndex, SomeDirective, true, null);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, SomeDirective, false, null);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, SomeDirective, true);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, SomeDirective, false);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -1830,8 +1830,8 @@ describe('compiler compliance', () => {
|
||||
…
|
||||
contentQueries: function ContentQueryComponent_ContentQueries(rf, ctx, dirIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $e0_attrs$, true, null);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $e1_attrs$, false, null);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $e0_attrs$, true);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $e1_attrs$, false);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -1892,8 +1892,8 @@ describe('compiler compliance', () => {
|
||||
},
|
||||
contentQueries: function ContentQueryComponent_ContentQueries(rf, ctx, dirIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵstaticContentQuery(dirIndex, SomeDirective, true, null);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $ref0$, true, null);
|
||||
$r3$.ɵɵstaticContentQuery(dirIndex, SomeDirective, true);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $ref0$, true);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -3140,7 +3140,7 @@ describe('compiler compliance', () => {
|
||||
BaseClass.ngBaseDef = i0.ɵɵdefineBase({
|
||||
viewQuery: function (rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵviewQuery($e0_attrs$, true, null);
|
||||
$r3$.ɵɵviewQuery($e0_attrs$, true);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -3185,7 +3185,7 @@ describe('compiler compliance', () => {
|
||||
BaseClass.ngBaseDef = i0.ɵɵdefineBase({
|
||||
viewQuery: function (rf, ctx) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵviewQuery(SomeDirective, true, null);
|
||||
$r3$.ɵɵviewQuery(SomeDirective, true);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -3228,7 +3228,7 @@ describe('compiler compliance', () => {
|
||||
BaseClass.ngBaseDef = i0.ɵɵdefineBase({
|
||||
contentQueries: function (rf, ctx, dirIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $e0_attrs$, true, null);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, $e0_attrs$, true);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
@ -3273,7 +3273,7 @@ describe('compiler compliance', () => {
|
||||
BaseClass.ngBaseDef = i0.ɵɵdefineBase({
|
||||
contentQueries: function (rf, ctx, dirIndex) {
|
||||
if (rf & 1) {
|
||||
$r3$.ɵɵcontentQuery(dirIndex, SomeDirective, false, null);
|
||||
$r3$.ɵɵcontentQuery(dirIndex, SomeDirective, false);
|
||||
}
|
||||
if (rf & 2) {
|
||||
var $tmp$;
|
||||
|
@ -22,13 +22,13 @@ const trim = (input: string): string => input.replace(/\s+/g, ' ').trim();
|
||||
const varRegExp = (name: string): RegExp => new RegExp(`var \\w+ = \\[\"${name}\"\\];`);
|
||||
|
||||
const viewQueryRegExp = (descend: boolean, ref?: string): RegExp => {
|
||||
const maybeRef = ref ? `${ref}` : `null`;
|
||||
return new RegExp(`i0\\.ɵɵviewQuery\\(\\w+, ${descend}, ${maybeRef}\\)`);
|
||||
const maybeRef = ref ? `, ${ref}` : ``;
|
||||
return new RegExp(`i0\\.ɵɵviewQuery\\(\\w+, ${descend}${maybeRef}\\)`);
|
||||
};
|
||||
|
||||
const contentQueryRegExp = (predicate: string, descend: boolean, ref?: string): RegExp => {
|
||||
const maybeRef = ref ? `${ref}` : `null`;
|
||||
return new RegExp(`i0\\.ɵɵcontentQuery\\(dirIndex, ${predicate}, ${descend}, ${maybeRef}\\)`);
|
||||
const maybeRef = ref ? `, ${ref}` : ``;
|
||||
return new RegExp(`i0\\.ɵɵcontentQuery\\(dirIndex, ${predicate}, ${descend}${maybeRef}\\)`);
|
||||
};
|
||||
|
||||
const setClassMetadataRegExp = (expectedType: string): RegExp =>
|
||||
@ -1654,7 +1654,7 @@ runInEachFileSystem(os => {
|
||||
// match `i0.ɵɵcontentQuery(dirIndex, _c1, true, TemplateRef)`
|
||||
expect(jsContents).toMatch(contentQueryRegExp('\\w+', true, 'TemplateRef'));
|
||||
|
||||
// match `i0.ɵɵviewQuery(_c2, true, null)`
|
||||
// match `i0.ɵɵviewQuery(_c2, true)`
|
||||
// Note that while ViewQuery doesn't necessarily make sense on a directive, because it doesn't
|
||||
// have a view, we still need to handle it because a component could extend the directive.
|
||||
expect(jsContents).toMatch(viewQueryRegExp(true));
|
||||
|
Reference in New Issue
Block a user