diff --git a/src/printer.ts b/src/printer.ts
index b51501e7..758b334f 100644
--- a/src/printer.ts
+++ b/src/printer.ts
@@ -160,20 +160,23 @@ interface FormatDelegatePrettierOptions {
/**
* Supported parsers for the `formatDelegatePrettier` function.
*/
-type FormatDelegatePrettierSupportedParser = keyof Pick<
- typeof AngularParsers &
- typeof BabelParsers &
- typeof HtmlParsers &
- typeof PostCssParsers,
- | 'css'
- | 'vue'
- | '__vue_event_binding'
- | '__vue_expression'
- | '__js_expression'
- | '__ng_binding'
- | '__ng_action'
- | '__ng_directive'
->;
+type FormatDelegatePrettierSupportedParser =
+ | keyof Pick<
+ typeof AngularParsers &
+ typeof BabelParsers &
+ typeof HtmlParsers &
+ typeof PostCssParsers,
+ | 'css'
+ | 'vue'
+ | '__vue_event_binding'
+ | '__vue_expression'
+ | '__js_expression'
+ | '__ng_binding'
+ | '__ng_action'
+ | '__ng_directive'
+ >
+ | '__vue_ts_event_binding'
+ | '__vue_ts_expression';
/**
* The printer class.
@@ -672,13 +675,31 @@ export class PugPrinter {
}
private formatVueEventBinding(val: string): string {
- return this.formatDelegatePrettier(val, '__vue_event_binding', {
+ try {
+ return this.formatDelegatePrettier(val, '__vue_event_binding', {
+ trimTrailingSemicolon: true,
+ });
+ } catch {
+ return this.formatVueTsEventBinding(val);
+ }
+ }
+
+ private formatVueTsEventBinding(val: string): string {
+ return this.formatDelegatePrettier(val, '__vue_ts_event_binding', {
trimTrailingSemicolon: true,
});
}
private formatVueExpression(val: string): string {
- return this.formatDelegatePrettier(val, '__vue_expression');
+ try {
+ return this.formatDelegatePrettier(val, '__vue_expression');
+ } catch {
+ return this.formatVueTsExpression(val);
+ }
+ }
+
+ private formatVueTsExpression(val: string): string {
+ return this.formatDelegatePrettier(val, '__vue_ts_expression');
}
private formatAngularBinding(val: string): string {
diff --git a/tests/issues/issue-365/formatted.vue b/tests/issues/issue-365/formatted.vue
new file mode 100644
index 00000000..aefe5a4d
--- /dev/null
+++ b/tests/issues/issue-365/formatted.vue
@@ -0,0 +1,8 @@
+
+
+
+n-input(:ref="(el: any) => (pinRefs[index] = el)", @change="(val: string) => val")
+
diff --git a/tests/issues/issue-365/issue-365.test.ts b/tests/issues/issue-365/issue-365.test.ts
new file mode 100644
index 00000000..1a363393
--- /dev/null
+++ b/tests/issues/issue-365/issue-365.test.ts
@@ -0,0 +1,15 @@
+import { compareFiles } from 'tests/common';
+import { describe, expect, it } from 'vitest';
+
+describe('Issues', () => {
+ it('should handle TS in Vue files', () => {
+ const { actual, expected } = compareFiles(__dirname, {
+ source: 'unformatted.vue',
+ target: 'formatted.vue',
+ formatOptions: {
+ pugFramework: 'vue',
+ },
+ });
+ expect(actual).toBe(expected);
+ });
+});
diff --git a/tests/issues/issue-365/unformatted.vue b/tests/issues/issue-365/unformatted.vue
new file mode 100644
index 00000000..bb31aafb
--- /dev/null
+++ b/tests/issues/issue-365/unformatted.vue
@@ -0,0 +1,8 @@
+
+
+
+n-input(:ref="(el:any)=>pinRefs[index]=el", @change="(val:string)=>val")
+