File tree 11 files changed +1032
-555
lines changed
11 files changed +1032
-555
lines changed Original file line number Diff line number Diff line change 1
- # IntelliJ project files
2
1
.idea
3
2
* .iml
4
3
out
5
4
gen
6
5
node_modules
6
+ * .log
7
+ test /dist /
Original file line number Diff line number Diff line change 1
- const acorn = require ( 'acorn' ) ;
2
- const escodegen = require ( 'escodegen' ) ;
3
-
4
- module . exports = function ( source ) {
5
- this . cacheable && this . cacheable ( ) ;
6
- const tree = acorn . parse ( source , { sourceType : 'module' } ) ;
7
- traverse ( tree ) ;
8
- return escodegen . generate ( tree ) ;
9
- } ;
10
-
11
- function isObject ( item ) {
1
+ "use strict" ;
2
+ var acorn = require ( "acorn" ) ;
3
+ var escodegen = require ( "escodegen" ) ;
4
+ var isObject = function ( item ) {
12
5
return Object . prototype . toString . call ( item ) === '[object Object]' ;
13
- }
14
-
6
+ } ;
7
+ var acornOptions = {
8
+ sourceType : 'module'
9
+ } ;
15
10
function traverse ( input ) {
16
11
if ( Array . isArray ( input ) ) {
17
- input . forEach ( item => traverse ( item ) ) ;
18
- }
12
+ input . forEach ( traverse ) ;
13
+ }
19
14
else if ( isObject ( input ) ) {
20
- for ( let key in input ) {
15
+ for ( var key in input ) {
21
16
if ( typeof input [ key ] === 'string' ) {
22
17
input [ key ] = input [ key ] . replace ( / ( \n \s + ) / g, '' ) ;
23
18
}
24
- traverse ( input [ key ] ) ;
19
+ else {
20
+ traverse ( input [ key ] ) ;
21
+ }
25
22
}
26
23
}
27
24
}
25
+ module . exports = function ( source ) {
26
+ this . cacheable && this . cacheable ( ) ;
27
+ var tree = acorn . parse ( source , acornOptions ) ;
28
+ traverse ( tree ) ;
29
+ return escodegen . generate ( tree ) ;
30
+ } ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " template-string-optimize-loader" ,
3
- "version" : " 2.2.1 " ,
3
+ "version" : " 2.2.2 " ,
4
4
"description" : " template string optimize loader module for webpack" ,
5
- "main" : " index.js" ,
5
+ "main" : " lib/ index.js" ,
6
6
"scripts" : {
7
- "test" : " webpack && webpack --config webpack.config.optimize.js" ,
8
- "release" : " npm publish"
7
+ "lib" : " tsc -p tsconfig.json" ,
8
+ "test" : " bash ./test/test.sh" ,
9
+ "release" : " npm run lib && npm publish"
9
10
},
10
11
"author" : " chenjiahan" ,
11
12
"license" : " ISC" ,
12
13
"devDependencies" : {
13
- "babel" : " ^6.3.26" ,
14
- "babel-loader" : " ^6.2.1" ,
15
- "babel-preset-es2015" : " ^6.3.13" ,
16
- "webpack" : " ^1.12.10"
14
+ "@types/acorn" : " ^4.0.2" ,
15
+ "@types/escodegen" : " ^0.0.6" ,
16
+ "babel" : " ^6.23.0" ,
17
+ "babel-core" : " ^6.24.1" ,
18
+ "babel-loader" : " ^6.4.1" ,
19
+ "babel-preset-es2015" : " ^6.24.1" ,
20
+ "typescript" : " ^2.2.2" ,
21
+ "webpack" : " ^2.4.1"
17
22
},
18
23
"bugs" : {
19
24
"url" : " https://github.com/chenjiahan/template-string-optimize-loader/issues"
20
25
},
21
26
"homepage" : " https://github.com/chenjiahan/template-string-optimize-loader#readme" ,
22
27
"dependencies" : {
23
- "acorn" : " ^4 .0.9 " ,
28
+ "acorn" : " ^5 .0.3 " ,
24
29
"escodegen" : " ^1.8.1"
25
30
}
26
31
}
Original file line number Diff line number Diff line change
1
+ import acorn = require( 'acorn' ) ;
2
+ import escodegen = require( 'escodegen' ) ;
3
+
4
+ const isObject = ( item : any ) : boolean =>
5
+ Object . prototype . toString . call ( item ) === '[object Object]' ;
6
+
7
+ const acornOptions = {
8
+ sourceType : 'module'
9
+ } as acorn . Options ;
10
+
11
+ export = function ( source : string ) : string {
12
+ this . cacheable && this . cacheable ( ) ;
13
+ const tree = acorn . parse ( source , acornOptions ) ;
14
+ traverse ( tree ) ;
15
+ return escodegen . generate ( tree ) ;
16
+ } ;
17
+
18
+ function traverse ( input : any ) : void {
19
+ if ( Array . isArray ( input ) ) {
20
+ input . forEach ( traverse ) ;
21
+ } else if ( isObject ( input ) ) {
22
+ for ( let key in input ) {
23
+ if ( typeof input [ key ] === 'string' ) {
24
+ input [ key ] = input [ key ] . replace ( / ( \n \s + ) / g, '' ) ;
25
+ } else {
26
+ traverse ( input [ key ] ) ;
27
+ }
28
+ }
29
+ }
30
+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ npm run lib
3
+
4
+ mkdir node_modules/template-string-optimize-loader
5
+ cp -r ./package.json ./node_modules/template-string-optimize-loader
6
+ cp -r ./lib ./node_modules/template-string-optimize-loader
7
+
8
+ webpack
9
+ webpack --config webpack.config.optimize.js
Original file line number Diff line number Diff line change
1
+ {
2
+ "compilerOptions" : {
3
+ "target" : " es5" ,
4
+ "module" : " commonjs" ,
5
+ "moduleResolution" : " node" ,
6
+ "outDir" : " lib" ,
7
+ "isolatedModules" : false ,
8
+ "experimentalDecorators" : true ,
9
+ "noImplicitAny" : true ,
10
+ "removeComments" : true ,
11
+ "suppressImplicitAnyIndexErrors" : true ,
12
+ "allowSyntheticDefaultImports" : true ,
13
+ "types" : [
14
+ " acorn" ,
15
+ " escodegen"
16
+ ],
17
+ "lib" : [
18
+ " es2015"
19
+ ]
20
+ },
21
+ "include" : [
22
+ " ./src/*.ts"
23
+ ],
24
+ "compileOnSave" : false
25
+ }
Original file line number Diff line number Diff line change
1
+ const path = require ( 'path' ) ;
2
+
1
3
module . exports = {
2
- entry : " ./test/src/test.js" ,
4
+ entry : ' ./test/src/test.js' ,
3
5
output : {
4
- path : " test/dist" ,
5
- filename : " test.js"
6
+ path : path . resolve ( __dirname , './ test/dist' ) ,
7
+ filename : ' test.js'
6
8
} ,
7
9
module : {
8
- loaders : [
10
+ rules : [
9
11
{
10
12
test : / \. j s $ / ,
11
- loader : "babel?presets[]=es2015"
13
+ use : {
14
+ loader : 'babel-loader' ,
15
+ options : {
16
+ presets : [ 'es2015' ]
17
+ }
18
+ }
12
19
}
13
20
]
14
21
}
Original file line number Diff line number Diff line change
1
+ const path = require ( 'path' ) ;
2
+
1
3
module . exports = {
2
- entry : " ./test/src/test.js" ,
4
+ entry : ' ./test/src/test.js' ,
3
5
output : {
4
- path : " test/dist" ,
5
- filename : " test.min .js"
6
+ path : path . resolve ( __dirname , './ test/dist' ) ,
7
+ filename : ' test.optimize .js'
6
8
} ,
7
9
module : {
8
- loaders : [
10
+ rules : [
9
11
{
10
12
test : / \. j s $ / ,
11
- loader : "template-string-optimize!babel?presets[]=es2015"
13
+ use : [
14
+ 'template-string-optimize-loader' ,
15
+ {
16
+ loader : 'babel-loader' ,
17
+ options : {
18
+ presets : [ 'es2015' ]
19
+ }
20
+ }
21
+ ]
12
22
}
13
23
]
14
24
}
You can’t perform that action at this time.
0 commit comments