Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e36d95

Browse files
committed
feat(app): outputs signal supports
fix #1443 fix #1439
1 parent 0d366b0 commit 2e36d95

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

src/app/compiler/angular-dependencies.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,20 @@ export class AngularDependencies extends FrameworkDependencies {
248248
if (IO.constructor && !Configuration.mainData.disableConstructors) {
249249
deps.constructorObj = IO.constructor;
250250
}
251-
if (IO.inputs) {
251+
if (IO.inputs) {
252252
deps.inputsClass = IO.inputs;
253253
}
254+
if (IO.outputs) {
255+
deps.outputsClass = IO.outputs;
256+
}
254257
if (IO.properties) {
255258
deps.properties = IO.properties;
256-
deps.inputsClass = deps.inputsClass ? deps.inputsClass.concat(this.componentHelper.getInputSignals(IO.properties)) : this.componentHelper.getInputSignals(IO.properties);
259+
deps.inputsClass = deps.inputsClass
260+
? deps.inputsClass.concat(this.componentHelper.getInputSignals(IO.properties))
261+
: this.componentHelper.getInputSignals(IO.properties);
262+
deps.outputsClass = deps.outputsClass
263+
? deps.outputsClass.concat(this.componentHelper.getOutputSignals(IO.properties))
264+
: this.componentHelper.getOutputSignals(IO.properties);
257265
}
258266
if (IO.description) {
259267
deps.description = IO.description;
@@ -276,9 +284,7 @@ export class AngularDependencies extends FrameworkDependencies {
276284
if (IO.accessors) {
277285
deps.accessors = IO.accessors;
278286
}
279-
if (IO.outputs) {
280-
deps.outputsClass = IO.outputs;
281-
}
287+
282288
if (IO.hostBindings) {
283289
deps.hostBindings = IO.hostBindings;
284290
}

src/app/compiler/angular/deps/component-dep.factory.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ export class ComponentDepFactory {
8989
componentDep.accessors = IO.accessors;
9090
}
9191
if (IO.properties) {
92-
componentDep.inputsClass = componentDep.inputsClass.concat(this.helper.getInputSignals(IO.properties));
92+
componentDep.inputsClass = componentDep.inputsClass.concat(
93+
this.helper.getInputSignals(IO.properties)
94+
);
95+
componentDep.outputsClass = componentDep.outputsClass.concat(
96+
this.helper.getOutputSignals(IO.properties)
97+
);
9398
}
9499

95100
return componentDep;

src/app/compiler/angular/deps/directive-dep.factory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class DirectiveDepFactory {
2727
standalone: this.helper.getComponentStandalone(props, srcFile) ? true : false,
2828

2929
inputsClass: this.helper.getInputSignals(IO.properties).concat(IO.inputs),
30-
outputsClass: IO.outputs,
30+
outputsClass: this.helper.getInputSignals(IO.properties).concat(IO.outputs),
3131

3232
deprecated: IO.deprecated,
3333
deprecationMessage: IO.deprecationMessage,

src/app/compiler/angular/deps/helpers/component-helper.ts

+15
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,21 @@ export class ComponentHelper {
150150
return inputSignals;
151151
}
152152

153+
public getOutputSignals(props) {
154+
let outputSignals = [];
155+
props?.forEach((prop, i) => {
156+
const regexp = /output(?:\.(required))?(?:<([\w-]+)>)?\(([\w-]+)?\)/;
157+
const res = regexp.exec(prop.defaultValue);
158+
if (res) {
159+
const newOutput = prop;
160+
newOutput.defaultValue = res[res.length - 1];
161+
newOutput.required = res[0]?.includes('.required') ?? false;
162+
outputSignals.push(newOutput);
163+
}
164+
});
165+
return outputSignals;
166+
}
167+
153168
public getComponentStandalone(
154169
props: ReadonlyArray<ts.ObjectLiteralElementLike>,
155170
srcFile: ts.SourceFile

test/fixtures/todomvc-ng2/src/app/shared/components/dumb-parent-component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
import { Input, Output, HostBinding, HostListener } from '@angular/core';
1+
import { Input, Output, output, input } from '@angular/core';
22

33
/**
44
* Empty parent component for inheritance demo
55
*/
66
export class DumbParentComponent {
77
@Input() public parentInput: string;
88

9+
label = input.required<string>();
10+
911
@Output() public parentoutput;
1012

13+
currentChange = output<number>();
14+
1115
public parentProperty;
1216

1317
/**

test/src/cli/cli-generation-big-app.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -973,4 +973,10 @@ describe('CLI simple generation - big app', () => {
973973
);
974974
expect(file).to.contain('<div><i>&nbsp;Inputs</i> : color&nbsp;</div>');
975975
});
976+
977+
it('should support inputs and outputs signals', () => {
978+
const file = read(distFolder + '/classes/DumbParentComponent.html');
979+
expect(file).to.contain('<a href="#label" >label</a>');
980+
expect(file).to.contain('<a href="#currentChange" >currentChange</a>');
981+
});
976982
});

0 commit comments

Comments
 (0)