Skip to content

Commit e9b444b

Browse files
authored
Short-circuit before parsing (#224)
In attempting to troubleshoot #219, I realized that disabling the plugin using overrides and `importOrder: []` does not prevent parsing errors. Moving this short-circuit check up before we attempt to parse will not only solve that problem but also improve performance a little by avoiding parsing files that we're just going to short-circuit anyway.
1 parent a2c6312 commit e9b444b

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/preprocessors/preprocessor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export function preprocessor(code: string, options: PrettierOptions): string {
1717
plugins,
1818
};
1919

20+
// short-circuit if importOrder is an empty array (can be used to disable plugin)
21+
if (!remainingOptions.importOrder.length) {
22+
return code;
23+
}
24+
2025
// Astro component scripts allow returning a response
2126
if (options.parentParser === 'astro') {
2227
parserOptions.allowReturnOutsideFunction = true;
@@ -53,11 +58,6 @@ export function preprocessor(code: string, options: PrettierOptions): string {
5358
return code;
5459
}
5560

56-
// short-circuit if importOrder is an empty array (can be used to disable plugin)
57-
if (!remainingOptions.importOrder.length) {
58-
return code;
59-
}
60-
6161
const nodesToOutput = getSortedNodes(
6262
allOriginalImportNodes,
6363
remainingOptions,

0 commit comments

Comments
 (0)