File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export interface PluginConfig {
66 svelteBracketNewLine ?: boolean ;
77 svelteAllowShorthand ?: boolean ;
88 svelteIndentScriptAndStyle ?: boolean ;
9+ svelte5CompilerPath ?: string ;
910}
1011
1112export type PrettierConfig = PluginConfig & Config ;
Original file line number Diff line number Diff line change @@ -31,9 +31,12 @@ export const languages: Partial<SupportLanguage>[] = [
3131export const parsers : Record < string , Parser > = {
3232 svelte : {
3333 hasPragma,
34- parse : ( text ) => {
34+ parse : async ( text , options : ParserOptions ) => {
3535 try {
36- return < ASTNode > { ...parse ( text ) , __isRoot : true } ;
36+ const _parse = options . svelte5CompilerPath
37+ ? ( await import ( options . svelte5CompilerPath ) ) . parse
38+ : parse ;
39+ return < ASTNode > { ..._parse ( text ) , __isRoot : true } ;
3740 } catch ( err : any ) {
3841 if ( err . start != null && err . end != null ) {
3942 // Prettier expects error objects to have loc.start and loc.end fields.
@@ -57,8 +60,9 @@ export const parsers: Record<string, Parser> = {
5760 // Therefore we do it ourselves here.
5861 options . originalText = text ;
5962 // Only Svelte 5 can have TS in the template
60- options . _svelte_ts = isSvelte5Plus && result . isTypescript ;
61- options . _svelte_is5Plus = isSvelte5Plus ;
63+ const is = ! ! options . svelte5CompilerPath || isSvelte5Plus ;
64+ options . _svelte_ts = is && result . isTypescript ;
65+ options . _svelte_is5Plus = is ;
6266 return text ;
6367 } ,
6468 locStart,
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ function makeChoice(choice: string) {
1919}
2020
2121export const options : Record < keyof PluginConfig , SupportOption > = {
22+ svelte5CompilerPath : {
23+ category : 'Svelte' ,
24+ type : 'string' ,
25+ default : '' ,
26+ description : 'Only set this when using Svelte 5! Path to the Svelte 5 compiler' ,
27+ } ,
2228 svelteSortOrder : {
2329 category : 'Svelte' ,
2430 type : 'choice' ,
You can’t perform that action at this time.
0 commit comments