Skip to content

Commit

Permalink
fix(compiler): output input flags as a literal (#55215)
Browse files Browse the repository at this point in the history
Previously the input flags were being generated as a reference to an enum member for better readability and under the assumption that minifiers would inline the values. That doesn't appear to be the case so these changes switch to using the literal values instead.

PR Close #55215
  • Loading branch information
crisbeto authored and thePunderWoman committed Apr 4, 2024
1 parent 493c192 commit 39624c6
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 148 deletions.
@@ -1,10 +1,10 @@
TestDir.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs: {
counter: [$r3$.ɵɵInputFlags.SignalBased, "counter"],
modelWithAlias: [$r3$.ɵɵInputFlags.SignalBased, "alias", "modelWithAlias"],
counter: [1, "counter"],
modelWithAlias: [1, "alias", "modelWithAlias"],
decoratorInput: "decoratorInput",
decoratorInputWithAlias: [$r3$.ɵɵInputFlags.None, "publicNameDecorator", "decoratorInputWithAlias"],
decoratorInputWithAlias: [0, "publicNameDecorator", "decoratorInputWithAlias"],
decoratorInputTwoWay: "decoratorInputTwoWay"
},
outputs: {
Expand Down
@@ -1,8 +1,8 @@
TestComp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
inputs: {
counter: [$r3$.ɵɵInputFlags.SignalBased, "counter"],
name: [$r3$.ɵɵInputFlags.SignalBased, "name"]
counter: [1, "counter"],
name: [1, "name"]
},
outputs: {
counter: "counterChange",
Expand Down
@@ -1,8 +1,8 @@
TestDir.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs: {
counter: [$r3$.ɵɵInputFlags.SignalBased, "counter"],
name: [$r3$.ɵɵInputFlags.SignalBased, "name"]
counter: [1, "counter"],
name: [1, "name"]
},
outputs: {
counter: "counterChange",
Expand Down
@@ -1,7 +1,7 @@
LifecycleComp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
type: LifecycleComp,
selectors: [["lifecycle-comp"]],
inputs: {nameMin: [$r3$.ɵɵInputFlags.None, "name", "nameMin"]},
inputs: {nameMin: [0, "name", "nameMin"]},
features: [$r3$.ɵɵNgOnChangesFeature],
decls: 0,
vars: 0,
Expand Down
Expand Up @@ -2,7 +2,7 @@ MyComponent.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
inputs:{
componentInput: "componentInput",
originalComponentInput: [$r3$.ɵɵInputFlags.None, "renamedComponentInput", "originalComponentInput"]
originalComponentInput: [0, "renamedComponentInput", "originalComponentInput"]
},
outputs: {
componentOutput: "componentOutput",
Expand Down
Expand Up @@ -2,7 +2,7 @@ MyDirective.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs:{
directiveInput: "directiveInput",
originalDirectiveInput: [$r3$.ɵɵInputFlags.None, "renamedDirectiveInput", "originalDirectiveInput"]
originalDirectiveInput: [0, "renamedDirectiveInput", "originalDirectiveInput"]
},
outputs: {
directiveOutput: "directiveOutput",
Expand Down
@@ -1,8 +1,8 @@
MyDirective.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs: {
functionDeclarationInput: [$r3$.ɵɵInputFlags.HasDecoratorInputTransform, "functionDeclarationInput", "functionDeclarationInput", toNumber],
inlineFunctionInput: [$r3$.ɵɵInputFlags.HasDecoratorInputTransform, "inlineFunctionInput", "inlineFunctionInput", (value, _) => value ? 1 : 0]
functionDeclarationInput: [2, "functionDeclarationInput", "functionDeclarationInput", toNumber],
inlineFunctionInput: [2, "inlineFunctionInput", "inlineFunctionInput", (value, _) => value ? 1 : 0]
},
features: [$r3$.ɵɵInputTransformsFeature]
});
@@ -1,10 +1,10 @@
TestDir.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs: {
name: [$r3$.ɵɵInputFlags.SignalBased, "name"],
name2: [$r3$.ɵɵInputFlags.SignalBased, "name2"],
genericTransform: [$r3$.ɵɵInputFlags.SignalBased, "genericTransform"],
genericTransform2: [$r3$.ɵɵInputFlags.SignalBased, "genericTransform2"]
name: [1, "name"],
name2: [1, "name2"],
genericTransform: [1, "genericTransform"],
genericTransform2: [1, "genericTransform2"]
},
});
Expand Down
@@ -1,8 +1,8 @@
TestComp.ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({
inputs: {
counter: [$r3$.ɵɵInputFlags.SignalBased, "counter"],
name: [$r3$.ɵɵInputFlags.SignalBased, "name"]
counter: [1, "counter"],
name: [1, "name"]
},
});
Expand Down
@@ -1,8 +1,8 @@
TestDir.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs: {
counter: [$r3$.ɵɵInputFlags.SignalBased, "counter"],
name: [$r3$.ɵɵInputFlags.SignalBased, "name"]
counter: [1, "counter"],
name: [1, "name"]
},
});
Expand Down
@@ -1,12 +1,12 @@
TestDir.ɵdir = /* @__PURE__ */ $r3$.ɵɵdefineDirective({
inputs: {
counter: [$r3$.ɵɵInputFlags.SignalBased, "counter"],
signalWithTransform: [$r3$.ɵɵInputFlags.SignalBased, "signalWithTransform"],
signalWithTransformAndAlias: [$r3$.ɵɵInputFlags.SignalBased, "publicNameSignal", "signalWithTransformAndAlias"],
counter: [1, "counter"],
signalWithTransform: [1, "signalWithTransform"],
signalWithTransformAndAlias: [1, "publicNameSignal", "signalWithTransformAndAlias"],
decoratorInput: "decoratorInput",
decoratorInputWithAlias: [$r3$.ɵɵInputFlags.None, "publicNameDecorator", "decoratorInputWithAlias"],
decoratorInputWithTransformAndAlias: [$r3$.ɵɵInputFlags.HasDecoratorInputTransform, "publicNameDecorator2", "decoratorInputWithTransformAndAlias", convertToBoolean]
decoratorInputWithAlias: [0, "publicNameDecorator", "decoratorInputWithAlias"],
decoratorInputWithTransformAndAlias: [2, "publicNameDecorator2", "decoratorInputWithTransformAndAlias", convertToBoolean]
},
});
@@ -1,7 +1,7 @@
TestDir.ɵdir = /*@__PURE__*/ $r3$.ɵɵdefineDirective({
inputs: {
name: [$r3$.ɵɵInputFlags.SignalBased, "name"]
name: [1, "name"]
},
});
Expand Down
10 changes: 4 additions & 6 deletions packages/compiler-cli/test/ngtsc/authoring_inputs_spec.ts
Expand Up @@ -35,7 +35,7 @@ runInEachFileSystem(() => {
`);
env.driveMain();
const js = env.getContents('test.js');
expect(js).toContain('inputs: { data: [i0.ɵɵInputFlags.SignalBased, "data"] }');
expect(js).toContain('inputs: { data: [1, "data"] }');
});

it('should fail if @Input is applied on signal input member', () => {
Expand Down Expand Up @@ -144,7 +144,7 @@ runInEachFileSystem(() => {
`);
env.driveMain();
const js = env.getContents('test.js');
expect(js).toContain('inputs: { data: [i0.ɵɵInputFlags.SignalBased, "publicName", "data"] }');
expect(js).toContain('inputs: { data: [1, "publicName", "data"] }');
});

it('should error if a required input declares an initial value', () => {
Expand Down Expand Up @@ -177,8 +177,7 @@ runInEachFileSystem(() => {
}
`);
env.driveMain();
expect(env.getContents('test.js'))
.toContain(`inputs: { data: [i0.ɵɵInputFlags.SignalBased, "data"] }`);
expect(env.getContents('test.js')).toContain(`inputs: { data: [1, "data"] }`);
expect(env.getContents('test.d.ts')).toContain('"required": true; "isSignal": true;');
expect(env.getContents('test.d.ts'))
.withContext(
Expand All @@ -197,8 +196,7 @@ runInEachFileSystem(() => {
}
`);
env.driveMain();
expect(env.getContents('test.js'))
.toContain(`inputs: { data: [i0.ɵɵInputFlags.SignalBased, "data"] }`);
expect(env.getContents('test.js')).toContain(`inputs: { data: [1, "data"] }`);
});

it('should report mixed two-way binding with a signal input', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-cli/test/ngtsc/authoring_models_spec.ts
Expand Up @@ -38,7 +38,7 @@ runInEachFileSystem(() => {
const js = env.getContents('test.js');
const dts = env.getContents('test.d.ts');

expect(js).toContain('inputs: { value: [i0.ɵɵInputFlags.SignalBased, "value"] }');
expect(js).toContain('inputs: { value: [1, "value"] }');
expect(js).toContain('outputs: { value: "valueChange" }');
expect(dts).toContain(
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, ' +
Expand All @@ -60,7 +60,7 @@ runInEachFileSystem(() => {
const js = env.getContents('test.js');
const dts = env.getContents('test.d.ts');

expect(js).toContain('inputs: { value: [i0.ɵɵInputFlags.SignalBased, "alias", "value"] }');
expect(js).toContain('inputs: { value: [1, "alias", "value"] }');
expect(js).toContain('outputs: { value: "aliasChange" }');
expect(dts).toContain(
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, ' +
Expand All @@ -82,7 +82,7 @@ runInEachFileSystem(() => {
const js = env.getContents('test.js');
const dts = env.getContents('test.d.ts');

expect(js).toContain('inputs: { value: [i0.ɵɵInputFlags.SignalBased, "value"] }');
expect(js).toContain('inputs: { value: [1, "value"] }');
expect(js).toContain('outputs: { value: "valueChange" }');
expect(dts).toContain(
'static ɵdir: i0.ɵɵDirectiveDeclaration<TestDir, never, never, ' +
Expand Down
49 changes: 20 additions & 29 deletions packages/compiler-cli/test/ngtsc/local_compilation_spec.ts
Expand Up @@ -1505,7 +1505,7 @@ runInEachFileSystem(() => {
@Directive({standalone: true})
export class LocalDirective {
}
@Component({
selector: 'my-comp',
template: '',
Expand All @@ -1527,7 +1527,7 @@ runInEachFileSystem(() => {
env.write('test.ts', `
import {Directive, Component} from '@angular/core';
import {HostDir} from 'some_where';
@Component({
selector: 'my-comp',
template: '',
Expand All @@ -1554,7 +1554,7 @@ runInEachFileSystem(() => {
() => {
env.write('test.ts', `
import {Directive, Component} from '@angular/core';
@Directive({standalone: true})
export class LocalDirective {
}
Expand Down Expand Up @@ -1585,14 +1585,14 @@ runInEachFileSystem(() => {
env.write('test.ts', `
import {Directive, Component} from '@angular/core';
import {ExternalDirective} from 'some_where';
@Directive({
standalone: true,
hostDirectives: [ExternalDirective],
})
export class LocalDirective {
}
@Directive({
standalone: true,
hostDirectives: [LocalDirective],
Expand All @@ -1617,22 +1617,22 @@ runInEachFileSystem(() => {
it('should generate hostDirectives definition with forward references of local directives', () => {
env.write('test.ts', `
import {Component, Directive, forwardRef, Input} from '@angular/core';
@Component({
selector: 'my-component',
template: '',
hostDirectives: [forwardRef(() => DirectiveB)]
})
export class MyComponent {
}
@Directive({
standalone: true,
hostDirectives: [{directive: forwardRef(() => DirectiveA), inputs: ['value']}],
})
export class DirectiveB {
}
@Directive({standalone: true})
export class DirectiveA {
@Input() value: any;
Expand All @@ -1655,7 +1655,7 @@ runInEachFileSystem(() => {
env.write('test.ts', `
import {Component, Directive, forwardRef} from '@angular/core';
import {ExternalDirective} from 'some_where';
@Component({
selector: 'my-component',
template: '',
Expand Down Expand Up @@ -1695,13 +1695,12 @@ runInEachFileSystem(() => {
env.driveMain();
const jsContents = env.getContents('test.js');

expect(jsContents)
.toContain(
'inputs: { x: [i0.ɵɵInputFlags.HasDecoratorInputTransform, "x", "x", externalFunc] }');
expect(jsContents).toContain('inputs: { x: [2, "x", "x", externalFunc] }');
});

it('should generate input info for transform function imported externally using namespace', () => {
env.write('test.ts', `
it('should generate input info for transform function imported externally using namespace',
() => {
env.write('test.ts', `
import {Component, NgModule, Input} from '@angular/core';
import * as n from './some_where';
Expand All @@ -1714,13 +1713,11 @@ runInEachFileSystem(() => {
}
`);

env.driveMain();
const jsContents = env.getContents('test.js');
env.driveMain();
const jsContents = env.getContents('test.js');

expect(jsContents)
.toContain(
'inputs: { x: [i0.ɵɵInputFlags.HasDecoratorInputTransform, "x", "x", n.externalFunc] }');
});
expect(jsContents).toContain('inputs: { x: [2, "x", "x", n.externalFunc] }');
});

it('should generate input info for transform function defined locally', () => {
env.write('test.ts', `
Expand All @@ -1742,9 +1739,7 @@ runInEachFileSystem(() => {
env.driveMain();
const jsContents = env.getContents('test.js');

expect(jsContents)
.toContain(
'inputs: { x: [i0.ɵɵInputFlags.HasDecoratorInputTransform, "x", "x", localFunc] }');
expect(jsContents).toContain('inputs: { x: [2, "x", "x", localFunc] }');
});

it('should generate input info for inline transform function', () => {
Expand All @@ -1763,9 +1758,7 @@ runInEachFileSystem(() => {
env.driveMain();
const jsContents = env.getContents('test.js');

expect(jsContents)
.toContain(
'inputs: { x: [i0.ɵɵInputFlags.HasDecoratorInputTransform, "x", "x", (v) => v + \'TRANSFORMED!\'] }');
expect(jsContents).toContain('inputs: { x: [2, "x", "x", (v) => v + \'TRANSFORMED!\'] }');
});

it('should not check inline function param type', () => {
Expand All @@ -1784,9 +1777,7 @@ runInEachFileSystem(() => {
env.driveMain();
const jsContents = env.getContents('test.js');

expect(jsContents)
.toContain(
'inputs: { x: [i0.ɵɵInputFlags.HasDecoratorInputTransform, "x", "x", v => v + \'TRANSFORMED!\'] }');
expect(jsContents).toContain('inputs: { x: [2, "x", "x", v => v + \'TRANSFORMED!\'] }');
});
});

Expand Down

0 comments on commit 39624c6

Please sign in to comment.