File tree Expand file tree Collapse file tree 3 files changed +1941
-3
lines changed Expand file tree Collapse file tree 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+
14module . 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 11{
22 "name" : " template-string-optimize-loader" ,
3- "version" : " 1 .0.2 " ,
3+ "version" : " 2 .0.0 " ,
44 "description" : " template string optimize loader module for webpack" ,
55 "main" : " index.js" ,
66 "scripts" : {
99 "author" : " chenjiahan" ,
1010 "license" : " ISC" ,
1111 "devDependencies" : {
12+ "acorn" : " ^4.0.4" ,
1213 "babel" : " ^6.3.26" ,
1314 "babel-loader" : " ^6.2.1" ,
1415 "babel-preset-es2015" : " ^6.3.13" ,
16+ "escodegen" : " ^1.8.1" ,
1517 "webpack" : " ^1.12.10"
1618 },
1719 "bugs" : {
You can’t perform that action at this time.
0 commit comments