File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
components/sandbox/CodeEditor Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -288,9 +288,9 @@ export default class CodeEditor extends React.PureComponent {
288288 const { id, title, preferences } = this . props ;
289289 const code = this . getCode ( ) ;
290290 const mode = await this . getMode ( title ) ;
291- if ( mode === 'jsx' ) {
291+ if ( mode === 'jsx' || mode === 'css' ) {
292292 try {
293- const newCode = await prettify ( code , preferences . lintEnabled ) ;
293+ const newCode = await prettify ( code , mode , preferences . lintEnabled ) ;
294294
295295 if ( newCode !== code ) {
296296 this . props . changeCode ( id , newCode ) ;
@@ -323,7 +323,7 @@ export default class CodeEditor extends React.PureComponent {
323323 addons : addon ,
324324 syntax : newMode ,
325325 } ) ;
326- }
326+ } ;
327327
328328 codemirror: typeof CodeMirror ;
329329 server: typeof CodeMirror . TernServer ;
Original file line number Diff line number Diff line change 1- export default ( async function prettify ( code , eslintEnabled ) {
1+ function getParser ( mode ) {
2+ if ( mode === 'jsx' ) return 'babylon' ;
3+ if ( mode === 'css' ) return 'postcss' ;
4+
5+ return 'babylon' ;
6+ }
7+
8+ export default ( async function prettify ( code , mode , eslintEnabled ) {
29 const prettier = await System . import ( 'prettier' ) ;
310 const prettifiedCode = prettier . format ( code , {
411 singleQuote : true ,
12+ parser : getParser ( mode ) ,
513 trailingComma : 'all' ,
614 } ) ;
715
8- if ( eslintEnabled ) {
16+ if ( eslintEnabled && mode === 'jsx' ) {
917 const { fix } = await System . import ( 'app/utils/codemirror/eslint-lint' ) ;
1018 try {
1119 const lintedCode = fix ( prettifiedCode ) . output ;
You can’t perform that action at this time.
0 commit comments