File tree Expand file tree Collapse file tree 6 files changed +68
-4
lines changed
Expand file tree Collapse file tree 6 files changed +68
-4
lines changed Original file line number Diff line number Diff line change 1010 " babel-plugin-transform-object-rest-spread" ,
1111 " babel-plugin-transform-class-properties" ,
1212 " babel-plugin-transform-runtime" ,
13- " babel-plugin-lodash"
13+ " babel-plugin-lodash" ,
14+ " babel-plugin-system-import-transformer"
1415 ]
1516 }
1617 }
Original file line number Diff line number Diff line change 6767 },
6868 "dependencies" : {
6969 "axios" : " ^0.16.1" ,
70+ "babel-plugin-system-import" : " ^1.1.5" ,
71+ "babel-plugin-system-import-transformer" : " 3.1.0" ,
7072 "babel-plugin-transform-async-to-generator" : " ^6.24.1" ,
7173 "babel-plugin-transform-decorators-legacy" : " ^1.3.4" ,
7274 "babel-plugin-transform-remove-strict-mode" : " ^0.0.2" ,
Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+ exports [` prettify should prettify code 1` ] = `
4+ "const a = '32';
5+ "
6+ ` ;
7+
8+ exports [` prettify should prettify static class props 1` ] = `
9+ "class Ives extends React.Component {
10+ property = {};
11+ }
12+ "
13+ ` ;
14+
15+ exports [` prettify should prettify syntax errors 1` ] = `
16+ "apofdawoifefjaweoifj;
17+ "
18+ ` ;
Original file line number Diff line number Diff line change 11export default ( async function prettify ( code , eslintEnabled ) {
22 const prettier = await System . import ( 'prettier' ) ;
3- let newCode = prettier . format ( code , {
3+ const prettifiedCode = prettier . format ( code , {
44 singleQuote : true ,
55 trailingComma : 'all' ,
66 } ) ;
77
88 if ( eslintEnabled ) {
99 const { fix } = await System . import ( 'app/utils/codemirror/eslint-lint' ) ;
1010 try {
11- newCode = fix ( newCode ) . output ;
11+ const lintedCode = fix ( prettifiedCode ) . output ;
12+
13+ // If linter can't parse, it will return an empty string. Unwanted, so fall
14+ // back to prettified code
15+ if ( lintedCode ) return lintedCode ;
1216 } catch ( e ) {
1317 console . error ( e ) ;
1418 }
1519 }
16- return newCode ;
20+
21+ return prettifiedCode ;
1722} ) ;
Original file line number Diff line number Diff line change 1+ import prettify from './prettify' ;
2+
3+ const testCode = async ( code : string ) => {
4+ const prettified = await prettify ( code ) ;
5+ expect ( prettified ) . toMatchSnapshot ( ) ;
6+ } ;
7+
8+ describe ( 'prettify' , ( ) => {
9+ it ( 'should prettify code' , async ( ) => {
10+ await testCode ( `const a='32'` ) ;
11+ } ) ;
12+
13+ it ( 'should prettify static class props' , async ( ) => {
14+ await testCode (
15+ `
16+ class Ives extends React.Component {
17+ property = {
18+
19+ }
20+ }
21+ ` ,
22+ ) ;
23+ } ) ;
24+
25+ it ( 'should prettify syntax errors' , async ( ) => {
26+ await testCode ( `apofdawoifefjaweoifj` ) ;
27+ } ) ;
28+ } ) ;
Original file line number Diff line number Diff line change @@ -648,6 +648,16 @@ babel-plugin-syntax-trailing-function-commas@^6.22.0:
648648 version "6.22.0"
649649 resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3"
650650
651+ 652+ version "3.1.0"
653+ resolved "https://registry.yarnpkg.com/babel-plugin-system-import-transformer/-/babel-plugin-system-import-transformer-3.1.0.tgz#d37f0cae8e61ef39060208331d931b5e630d7c5f"
654+ dependencies :
655+ babel-plugin-syntax-dynamic-import "^6.18.0"
656+
657+ babel-plugin-system-import@^1.1.5 :
658+ version "1.1.5"
659+ resolved "https://registry.yarnpkg.com/babel-plugin-system-import/-/babel-plugin-system-import-1.1.5.tgz#d8910a7b98a289bfa92ad9c8b204ba5fe73358f0"
660+
651661babel-plugin-transform-async-generator-functions@^6.24.1 :
652662 version "6.24.1"
653663 resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-generator-functions/-/babel-plugin-transform-async-generator-functions-6.24.1.tgz#f058900145fd3e9907a6ddf28da59f215258a5db"
You can’t perform that action at this time.
0 commit comments