File tree 3 files changed +1941
-3
lines changed
3 files changed +1941
-3
lines changed Original file line number Diff line number Diff line change
1
+ const acorn = require ( 'acorn' ) ;
2
+ const escodegen = require ( 'escodegen' ) ;
3
+
1
4
module . exports = function ( source ) {
2
- return source . replace ( / ( \\ n \s * ) / g, '' ) ;
3
- } ;
5
+ const tree = acorn . parse ( source , { sourceType : 'module' } ) ;
6
+ traverse ( tree ) ;
7
+ return escodegen . generate ( tree ) ;
8
+ } ;
9
+
10
+ function isObject ( item ) {
11
+ return Object . prototype . toString . call ( item ) === '[object Object]' ;
12
+ }
13
+
14
+ function traverse ( input ) {
15
+ if ( Array . isArray ( input ) ) {
16
+ input . forEach ( item => traverse ( item ) ) ;
17
+ }
18
+ else if ( isObject ( input ) ) {
19
+ for ( let key in input ) {
20
+ if ( typeof input [ key ] === 'string' ) {
21
+ input [ key ] = input [ key ] . replace ( / ( \n \s * ) / g, '' ) ;
22
+ }
23
+ traverse ( input [ key ] ) ;
24
+ }
25
+ }
26
+ }
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " template-string-optimize-loader" ,
3
- "version" : " 1 .0.2 " ,
3
+ "version" : " 2 .0.0 " ,
4
4
"description" : " template string optimize loader module for webpack" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
9
9
"author" : " chenjiahan" ,
10
10
"license" : " ISC" ,
11
11
"devDependencies" : {
12
+ "acorn" : " ^4.0.4" ,
12
13
"babel" : " ^6.3.26" ,
13
14
"babel-loader" : " ^6.2.1" ,
14
15
"babel-preset-es2015" : " ^6.3.13" ,
16
+ "escodegen" : " ^1.8.1" ,
15
17
"webpack" : " ^1.12.10"
16
18
},
17
19
"bugs" : {
You can’t perform that action at this time.
0 commit comments