Skip to content

Commit 9dfb3d5

Browse files
committed
feat: 🎸 (parser) correctly parse aliased signal inputs
1 parent cf02a60 commit 9dfb3d5

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/parser/shared/parser/field-decorator.parser.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,29 @@ describe('Field Decorator', function () {
405405
outputs: [],
406406
});
407407
});
408+
409+
it('should use the alias as name', () => {
410+
const ast = tsquery.ast(`
411+
export class MyTestClass {
412+
test = input<myIcon>("el-icon", {alias: "foo"});
413+
}
414+
`);
415+
416+
const expectedInputs = [
417+
{
418+
decorator: 'input',
419+
name: 'foo',
420+
initialValue: '"el-icon"',
421+
type: 'myIcon',
422+
required: false,
423+
field: 'test = input<myIcon>("el-icon", {alias: "foo"});',
424+
},
425+
];
426+
expect(parseInputsAndOutputs(ast)).toEqual({
427+
inputs: expectedInputs,
428+
outputs: [],
429+
});
430+
});
408431
});
409432

410433
describe('model inputs', () => {
@@ -660,6 +683,29 @@ describe('Field Decorator', function () {
660683
outputs: [],
661684
});
662685
});
686+
687+
it('should parse signal model with aliases and use the alias as name', () => {
688+
const ast = tsquery.ast(`
689+
export class MyTestClass {
690+
test = model("myValue", {alias: "foo"});
691+
}
692+
`);
693+
694+
const expectedInputs = [
695+
{
696+
decorator: 'model',
697+
name: 'foo',
698+
type: 'inferred',
699+
required: false,
700+
initialValue: '"myValue"',
701+
field: 'test = model("myValue", {alias: "foo"});',
702+
},
703+
];
704+
expect(parseInputsAndOutputs(ast)).toEqual({
705+
inputs: expectedInputs,
706+
outputs: [],
707+
});
708+
});
663709
});
664710

665711
describe('output', () => {

src/parser/shared/parser/field-decorator.parser.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ function parseSignalInputsAndModels(ast: ts.SourceFile): NgParselFieldDecorator[
9999
const required = isRequiredSingalInput(field);
100100

101101
const name = [...tsquery(field, 'BinaryExpression > Identifier')][0]?.getText() || '';
102+
const alias = [
103+
...tsquery(field, 'CallExpression ObjectLiteralExpression PropertyAssignment[name.name="alias"] StringLiteral'),
104+
][0]
105+
?.getText()
106+
.replace(/"/g, '');
107+
102108
const decorator =
103109
[
104110
...tsquery(
@@ -126,7 +132,7 @@ function parseSignalInputsAndModels(ast: ts.SourceFile): NgParselFieldDecorator[
126132
signalInputs.push({
127133
decorator,
128134
required,
129-
name,
135+
name: alias || name,
130136
type,
131137
field,
132138
});
@@ -135,7 +141,7 @@ function parseSignalInputsAndModels(ast: ts.SourceFile): NgParselFieldDecorator[
135141
decorator,
136142
required,
137143
initialValue,
138-
name,
144+
name: alias || name,
139145
type,
140146
field,
141147
});

0 commit comments

Comments
 (0)