Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6e13803

Browse files
authored
Merge pull request#1538 from vietdanh1899/fix-autoformat-codeeditor
Fix code editor auto format
2 parentsc42c0e0 +109bb8f commit6e13803

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

‎client/packages/lowcoder/src/base/codeEditor/autoFormat.tsx‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@ import type { CodeType } from "lowcoder-core";
22
import{relaxedJSONToJSON}from"lowcoder-core";
33
import{getDynamicStringSegments,isDynamicSegment}from"lowcoder-core";
44
import{formatasformatSQL}from"sql-formatter";
5+
importestreefrom"prettier/plugins/estree";
56
importtype{Language}from"./codeEditorTypes";
67

78
exportasyncfunctioncssFormatter(text:string){
8-
constprettier=awaitrequire("prettier/standalone");
9-
constparserPlugin=awaitrequire("prettier/parser-postcss");
9+
constprettier=awaitimport("prettier/standalone");
10+
constparserPlugin=awaitimport("prettier/plugins/postcss");
1011
return(awaitprettier.format(text,{parser:"css",plugins:[parserPlugin],semi:false})).trim();
1112
}
1213

1314
exportasyncfunctionhtmlFormatter(text:string){
14-
constprettier=awaitrequire("prettier/standalone");
15-
constparserPlugin=awaitrequire("prettier/parser-html");
15+
constprettier=awaitimport("prettier/standalone");
16+
constparserPlugin=awaitimport("prettier/plugins/html");
1617
return(awaitprettier.format(text,{parser:"html",plugins:[parserPlugin],semi:false})).trim();
1718
}
1819

1920
asyncfunctiongetJavascriptFormatter(){
20-
constprettier=awaitrequire("prettier/standalone");
21-
constparserBabel=awaitrequire("prettier/parser-babel");
21+
constprettier=awaitimport("prettier/standalone");
22+
constparserBabel=awaitimport("prettier/plugins/babel");
2223
returnasync(text:string)=>
23-
(awaitprettier.format(text,{parser:"babel",plugins:[parserBabel],semi:false})).trim();
24+
(awaitprettier.format(text,{parser:"babel",plugins:[parserBabel,estree],semi:false})).trim();
2425
}
2526

2627
exportasyncfunctiongetJsonFormatter(){
27-
constprettier=awaitrequire("prettier/standalone");
28-
constparserBabel=awaitrequire("prettier/parser-babel");
28+
constprettier=awaitimport("prettier/standalone");
29+
constparserBabel=awaitimport("prettier/plugins/babel");
2930
returnasync(text:string)=>(awaitprettier.format(text,{parser:"json",plugins:[parserBabel]})).trim();
3031
}
3132

@@ -46,15 +47,16 @@ async function formatJsSegment(formatter: (text: string) => Promise<string>, scr
4647
asyncfunctiongetJsSegmentFormatter(){
4748
constformatter=awaitgetJavascriptFormatter();
4849
returnasync(segment:string)=>{
49-
return"{{"+formatJsSegment(formatter,segment.slice(2,-2))+"}}";
50+
return"{{"+awaitformatJsSegment(formatter,segment.slice(2,-2))+"}}";
5051
};
5152
}
5253

5354
exportasyncfunctionformatStringWithJsSnippets(text:string):Promise<string>{
5455
constjsSegmentFormatter=awaitgetJsSegmentFormatter();
55-
returngetDynamicStringSegments(text)
56-
.map((s)=>(isDynamicSegment(s) ?jsSegmentFormatter(s) :s))
57-
.join("");
56+
constformatedSegments=awaitPromise.all(
57+
getDynamicStringSegments(text).map((s)=>(isDynamicSegment(s) ?jsSegmentFormatter(s) :s))
58+
);
59+
returnformatedSegments.join("");
5860
}
5961

6062
exportasyncfunctionformatSqlWithJsSnippets(text:string){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp