Skip to content

Commit 8a5fc47

Browse files
authored
Merge pull request #40 from angular-experts-io/feature/fieldsPublicExplicit
feat: 🎸 parse fields public explicit for directive & component
2 parents 3379c76 + efdc740 commit 8a5fc47

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

src/converters/component/component.converter.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('Component converter', () => {
1818
template: '',
1919
styles: '',
2020
methodsPublicExplicit: [],
21+
fieldsPublicExplicit: [],
2122
},
2223
{
2324
type: NgParselOutputType.COMPONENT,
@@ -33,6 +34,7 @@ describe('Component converter', () => {
3334
template: '',
3435
styles: '',
3536
methodsPublicExplicit: [],
37+
fieldsPublicExplicit: [],
3638
},
3739
{
3840
type: NgParselOutputType.COMPONENT,
@@ -48,6 +50,7 @@ describe('Component converter', () => {
4850
template: '',
4951
styles: '',
5052
methodsPublicExplicit: [],
53+
fieldsPublicExplicit: [],
5154
},
5255
];
5356

src/converters/directive/directive.converter.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('Directive converter', () => {
1414
outputs: [],
1515
implementation: '',
1616
methodsPublicExplicit: [],
17+
fieldsPublicExplicit: [],
1718
},
1819
{
1920
type: NgParselOutputType.DIRECTIVE,
@@ -25,6 +26,7 @@ describe('Directive converter', () => {
2526
outputs: [],
2627
implementation: '',
2728
methodsPublicExplicit: [],
29+
fieldsPublicExplicit: [],
2830
},
2931
{
3032
type: NgParselOutputType.DIRECTIVE,
@@ -36,6 +38,7 @@ describe('Directive converter', () => {
3638
outputs: [],
3739
implementation: '',
3840
methodsPublicExplicit: [],
41+
fieldsPublicExplicit: [],
3942
},
4043
];
4144

src/parser/component/component.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NgParselOutput } from '../shared/model/types.model.js';
22
import { NgParselFieldDecorator } from '../shared/model/decorator.model.js';
33
import { NgParselMethod } from '../shared/model/method.model.js';
4+
import { NgParselField } from '../shared/model/field.model.js';
45

56
export interface NgParselComponent extends NgParselOutput {
67
className: string;
@@ -14,5 +15,6 @@ export interface NgParselComponent extends NgParselOutput {
1415
template: string;
1516
styles: string | string[];
1617
methodsPublicExplicit: NgParselMethod[];
18+
fieldsPublicExplicit: NgParselField[];
1719
classJsDoc?: string | undefined;
1820
}

src/parser/component/component.parser.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ describe('ComponentParser', () => {
1717
@Input() foo: string;
1818
@Output() bar = new EventEmitter();
1919
20+
public value = signal<string>('');
21+
2022
public foo(bar: string): string {
2123
}
2224
@@ -69,6 +71,11 @@ describe('ComponentParser', () => {
6971
returnType: 'string',
7072
},
7173
],
74+
fieldsPublicExplicit: [{
75+
name: 'value',
76+
type: 'inferred',
77+
value: `signal<string>('')`,
78+
}],
7279
};
7380
jest.spyOn(fs, 'readFileSync').mockReturnValue(implementation);
7481

@@ -137,6 +144,7 @@ describe('ComponentParser', () => {
137144
returnType: 'string',
138145
},
139146
],
147+
fieldsPublicExplicit: [],
140148
};
141149
jest.spyOn(fs, 'readFileSync').mockReturnValue(implementation);
142150

src/parser/component/component.parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { parseClassName, parseClassJsDoc } from '../shared/parser/class.parser.j
1010

1111
import { NgParselComponent } from './component.model.js';
1212
import { getDecoratorProperties } from '../shared/parser/decorator.parser.js';
13+
import { parseExplicitPublicFields } from '../shared/parser/field.parser.js';
1314

1415
export function parseComponent(ast: ts.SourceFile, componentFilePath: string): NgParselComponent {
1516
const componentDecorators = getDecoratorProperties(ast);
@@ -39,6 +40,7 @@ export function parseComponent(ast: ts.SourceFile, componentFilePath: string): N
3940
inputs: inputsAndOutputs.inputs,
4041
outputs: inputsAndOutputs.outputs,
4142
methodsPublicExplicit: parseExplicitPublicMethods(ast),
43+
fieldsPublicExplicit: parseExplicitPublicFields(ast),
4244
classJsDoc: parseClassJsDoc(ast),
4345
};
4446
}

src/parser/directive/directive.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NgParselOutput } from '../shared/model/types.model.js';
22
import { NgParselFieldDecorator } from '../shared/model/decorator.model.js';
33
import { NgParselMethod } from '../shared/model/method.model.js';
4+
import { NgParselField } from '../shared/model/field.model.js';
45

56
export interface NgParselDirective extends NgParselOutput {
67
className: string;
@@ -10,5 +11,6 @@ export interface NgParselDirective extends NgParselOutput {
1011
inputs: NgParselFieldDecorator[];
1112
outputs: NgParselFieldDecorator[];
1213
methodsPublicExplicit: NgParselMethod[];
14+
fieldsPublicExplicit: NgParselField[];
1315
classJsDoc?: string | undefined;
1416
}

src/parser/directive/directive.parser.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ describe('DirectiveParser', () => {
1515
const implementation = `export class MyTestDirective {
1616
@Input() foo: string;
1717
@Output() bar = new EventEmitter();
18+
19+
public value = signal<string>('');
1820
}`;
1921

2022
const ast = tsquery.ast(`
@@ -49,6 +51,11 @@ describe('DirectiveParser', () => {
4951
],
5052
implementation,
5153
methodsPublicExplicit: [],
54+
fieldsPublicExplicit: [{
55+
name: 'value',
56+
type: 'inferred',
57+
value: `signal<string>('')`,
58+
}]
5259
};
5360
jest.spyOn(fs, 'readFileSync').mockReturnValue(implementation);
5461

@@ -95,6 +102,7 @@ describe('DirectiveParser', () => {
95102
],
96103
implementation,
97104
methodsPublicExplicit: [],
105+
fieldsPublicExplicit: [],
98106
};
99107
jest.spyOn(fs, 'readFileSync').mockReturnValue(implementation);
100108

src/parser/directive/directive.parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { parseInputsAndOutputs } from '../shared/parser/field-decorator.parser.j
88

99
import { NgParselDirective } from './directive.model.js';
1010
import { parseExplicitPublicMethods } from '../shared/parser/method.parser.js';
11+
import { parseExplicitPublicFields } from '../shared/parser/field.parser.js';
1112

1213
export function parseDirective(ast: ts.SourceFile, directiveFilePath: string): NgParselDirective {
1314
const directiveDecorators = getDecoratorProperties(ast);
@@ -26,6 +27,7 @@ export function parseDirective(ast: ts.SourceFile, directiveFilePath: string): N
2627
inputs: inputsAndOutputs.inputs,
2728
outputs: inputsAndOutputs.outputs,
2829
methodsPublicExplicit: parseExplicitPublicMethods(ast),
30+
fieldsPublicExplicit: parseExplicitPublicFields(ast),
2931
classJsDoc: parseClassJsDoc(ast),
3032
};
3133
}

0 commit comments

Comments
 (0)