Skip to content

Commit

Permalink
fix(angular): generate event type with inline types (#412)
Browse files Browse the repository at this point in the history
* fix(angular): generate event type with inline types
  • Loading branch information
sean-perkins authored Jan 25, 2024
1 parent a18afc8 commit 5704cca
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,42 @@ export declare interface MyComponent extends Components.MyComponent {
},
internal: false,
},
{
name: 'mySwipe',
method: 'mySwipe',
bubbles: true,
cancelable: true,
composed: true,
docs: {
tags: [],
text: '',
},
complexType: {
original: '{ side: Side }',
resolved: '{ side: Side; }',
references: {
Side: {
location: 'import',
path: '../../interfaces',
},
},
},
internal: false,
},
],
'@ionic/core'
);

expect(definition).toEqual(
`import type { MyEvent as IMyComponentMyEvent } from '@ionic/core';
import type { Currency as IMyComponentCurrency } from '@ionic/core';
import type { Side as IMyComponentSide } from '@ionic/core';
export declare interface MyComponent extends Components.MyComponent {
myChange: EventEmitter<CustomEvent<IMyComponentMyEvent<IMyComponentCurrency>>>;
mySwipe: EventEmitter<CustomEvent<{ side: IMyComponentSide }>>;
}`
);
});
Expand Down
17 changes: 16 additions & 1 deletion packages/angular-output-target/src/generate-angular-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,23 @@ const formatOutputType = (componentClassName: string, event: ComponentCompilerEv
(type, [src, dst]) => {
let renamedType = type;
if (!type.startsWith(prefix)) {
renamedType = `I${componentClassName}${type}`;
if (type.startsWith('{') && type.endsWith('}')) {
/**
* If the type starts with { and ends with }, it is an inline type.
* For example, `{ a: string }`.
* We don't need to rename these types, so we return the original type.
*/
renamedType = type;
} else {
/**
* If the type does not start with { and end with }, it is a reference type.
* For example, `MyType`.
* We need to rename these types, so we prepend the prefix.
*/
renamedType = `I${componentClassName}${type}`;
}
}

return (
renamedType
.replace(new RegExp(`^${src}$`, 'g'), `${dst}`)
Expand Down

0 comments on commit 5704cca

Please sign in to comment.