Skip to content

Commit

Permalink
Merge pull request #23 from angular-experts-io/feature/intersectionAn…
Browse files Browse the repository at this point in the history
…dUnionTypes

feat: 🎸 intersection and union types
  • Loading branch information
kreuzerk committed May 1, 2024
2 parents 8b29c35 + e2e79a8 commit d2a1b6c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/parser/shared/parser/field-decorator.parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,52 @@ describe('Field Decorator', function () {
});
});

it('should parse a signal input with a union type', () => {
const ast = tsquery.ast(`
export class MyTestClass {
test = input<myIcon | string>();
}
`);

const expectedInputs = [
{
decorator: 'input',
name: 'test',
initialValue: '',
type: 'myIcon | string',
required: false,
field: 'test = input<myIcon | string>();',
},
];
expect(parseInputsAndOutputs(ast)).toEqual({
inputs: expectedInputs,
outputs: [],
});
});

it('should parse a signal input with a intersection type', () => {
const ast = tsquery.ast(`
export class MyTestClass {
test = input<myIcon & string>();
}
`);

const expectedInputs = [
{
decorator: 'input',
name: 'test',
initialValue: '',
type: 'myIcon & string',
required: false,
field: 'test = input<myIcon & string>();',
},
];
expect(parseInputsAndOutputs(ast)).toEqual({
inputs: expectedInputs,
outputs: [],
});
});

it('should parse signal inputs with initial string value', () => {
const ast = tsquery.ast(`
export class MyTestClass {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/shared/parser/field-decorator.parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function parseSignalInputsAndModels(ast: ts.SourceFile): NgParselFieldDecorator[
[
...tsquery(
field,
'CallExpression > :matches(BooleanKeyword, AnyKeyword, TypeReference, StringKeyword, LiteralType, TypeLiteral, NullKeyword, UndefinedKeyword, Identifier[name=Array], ArrayType)'
'CallExpression > :matches(BooleanKeyword, AnyKeyword, TypeReference, StringKeyword, LiteralType, TypeLiteral, NullKeyword, UndefinedKeyword, Identifier[name=Array], ArrayType, UnionType, IntersectionType)'
),
][0]?.getText() || 'inferred';

Expand Down

0 comments on commit d2a1b6c

Please sign in to comment.