-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
920 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/node_modules/prettier-plugin-svelte/plugin.js b/node_modules/prettier-plugin-svelte/plugin.js | ||
index bcb248e..9d4ad94 100644 | ||
--- a/node_modules/prettier-plugin-svelte/plugin.js | ||
+++ b/node_modules/prettier-plugin-svelte/plugin.js | ||
@@ -2120,7 +2120,7 @@ const parsers = { | ||
hasPragma, | ||
parse: (text) => { | ||
try { | ||
- return Object.assign(Object.assign({}, require(`svelte/compiler`).parse(text)), { __isRoot: true }); | ||
+ return Object.assign(Object.assign({}, require(`svelte/compiler.cjs`).parse(text)), { __isRoot: true }); | ||
} | ||
catch (err) { | ||
if (err.start != null && err.end != null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { PrettierOptions } from '../types'; | ||
import { preprocessor } from './preprocessor'; | ||
|
||
const booleanGuard = <T>(value: T | undefined): value is T => Boolean(value); | ||
|
||
const sortImports = (code: string, options: PrettierOptions) => { | ||
const { parse } = require('svelte/compiler.cjs'); | ||
const { instance, module } = parse(code); | ||
const sources = [instance, module].filter(booleanGuard); | ||
if (!sources.length) return code; | ||
return sources.reduce((code, source) => { | ||
const snippet = code.slice(source.content.start, source.content.end); | ||
const preprocessed = preprocessor(snippet, options); | ||
const result = code.replace(snippet, `\n${preprocessed}\n`); | ||
return result; | ||
}, code); | ||
}; | ||
|
||
export function sveltePreprocessor(code: string, options: PrettierOptions) { | ||
const sorted = sortImports(code, options); | ||
|
||
const prettierPluginSvelte = require('prettier-plugin-svelte'); | ||
return prettierPluginSvelte.parsers.svelte.preprocess(sorted, options); | ||
} |
Oops, something went wrong.