Skip to content

Commit 813cbdd

Browse files
committed
add postFormat to parsers
1 parent 6d65af0 commit 813cbdd

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/livecodes/formatter/format.worker.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,16 @@ const format = async (
116116
singleQuote: formatterConfig.singleQuote ?? defaultConfig.singleQuote,
117117
trailingComma: formatterConfig.trailingComma === false ? 'none' : 'all',
118118
};
119-
return (
120-
(await (self as any).prettier.formatWithCursor(value, {
121-
parser: parser?.name,
122-
plugins: prettierPlugins,
123-
cursorOffset,
124-
...options,
125-
})) || unFormatted
126-
);
119+
let formatted = await (self as any).prettier.formatWithCursor(value, {
120+
parser: parser?.name,
121+
plugins: prettierPlugins,
122+
cursorOffset,
123+
...options,
124+
});
125+
if (typeof parser?.postFormat === 'function') {
126+
formatted = await parser.postFormat(formatted);
127+
}
128+
return formatted || unFormatted;
127129
}
128130
if (getFormatter(language) != null) {
129131
const formatFn = loadFormatter(language);

src/livecodes/languages/ripple/lang-ripple.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export const ripple: LanguageSpecs = {
99
parser: {
1010
name: 'ripple',
1111
pluginUrls: [parserPlugins.ripple],
12+
postFormat: async (parsed: { formatted: string; cursorOffset: number }) => ({
13+
formatted: parsed.formatted.replace(/,?\[object Object\],?/g, ''),
14+
cursorOffset: parsed.cursorOffset,
15+
}),
1216
},
1317
compiler: {
1418
factory: async () => {

src/livecodes/vendors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export const postcssImportUrlUrl = /* @__PURE__ */ getUrl(
344344
export const prettierBaseUrl = /* @__PURE__ */ getUrl('prettier@3.3.2/');
345345

346346
export const prettierRippleUrl = /* @__PURE__ */ getUrl(
347-
'@hatemhosny/prettier-plugin-ripple@0.0.6/build/parser-ripple.js',
347+
'@hatemhosny/prettier-plugin-ripple@0.0.5/build/parser-ripple.js',
348348
);
349349

350350
export const prettierPhpUrl = /* @__PURE__ */ getUrl('@prettier/plugin-php@0.22.2/standalone.js');

src/sdk/models.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,10 @@ export interface Parser {
12571257
name: ParserName;
12581258
plugins?: any[];
12591259
pluginUrls: string[];
1260+
postFormat?: (parsed: {
1261+
formatted: string;
1262+
cursorOffset: number;
1263+
}) => Promise<{ formatted: string; cursorOffset: number }>;
12601264
}
12611265
export type FormatFn = (
12621266
value: string,

0 commit comments

Comments
 (0)