11"use strict" ;
22
3- let JavaScriptObfuscator = require ( 'javascript-obfuscator' ) ,
3+ let JavaScriptObfuscator : any = require ( 'javascript-obfuscator' ) ,
44 multimatch : any = require ( 'multimatch' ) ,
55 RawSource : any = require ( 'webpack-core/lib/RawSource' ) ,
66 SourceMapSource : any = require ( "webpack-core/lib/SourceMapSource" ) ,
@@ -17,7 +17,7 @@ class WebpackObfuscator {
1717 * @param excludes
1818 */
1919 constructor ( options : any , excludes : string | string [ ] ) {
20- this . options = options ;
20+ this . options = options || { } ;
2121 this . excludes = typeof excludes === 'string' ? [ excludes ] : excludes || [ ] ;
2222 }
2323
@@ -43,8 +43,10 @@ class WebpackObfuscator {
4343 if ( this . shouldExclude ( file , this . excludes ) ) {
4444 return ;
4545 }
46- let asset = compilation . assets [ file ] ;
47- let input , inputSourceMap ;
46+
47+ let asset = compilation . assets [ file ] ,
48+ input , inputSourceMap ;
49+
4850 if ( this . options . sourceMap !== false ) {
4951 if ( asset . sourceAndMap ) {
5052 let sourceAndMap = asset . sourceAndMap ( ) ;
@@ -54,24 +56,35 @@ class WebpackObfuscator {
5456 inputSourceMap = asset . map ( ) ;
5557 input = asset . source ( ) ;
5658 }
57- if ( inputSourceMap ) {
58- this . options . sourceMap = true ;
59- }
59+
60+ if ( inputSourceMap ) {
61+ this . options . sourceMap = true ;
62+ }
6063 } else {
6164 input = asset . source ( ) ;
6265 }
6366
6467 let obfuscationResult : any = JavaScriptObfuscator . obfuscate (
65- input ,
66- this . options
67- ) ;
68+ input ,
69+ this . options
70+ ) ;
71+
6872 if ( this . options . sourceMap ) {
69- let obfuscationSourceMap : any = obfuscationResult . getSourceMap ( ) ;
70- let transferedSourceMap : any = transferSourceMap ( { fromSourceMap : obfuscationSourceMap , toSourceMap : inputSourceMap } ) ;
71- compilation . assets [ file ] = new SourceMapSource ( obfuscationResult . toString ( ) , file , JSON . parse ( transferedSourceMap ) , asset . source ( ) , inputSourceMap ) ;
72- }
73- else {
74- compilation . assets [ file ] = new RawSource ( obfuscationResult . toString ( ) ) ;
73+ let obfuscationSourceMap : any = obfuscationResult . getSourceMap ( ) ,
74+ transferredSourceMap : any = transferSourceMap ( {
75+ fromSourceMap : obfuscationSourceMap ,
76+ toSourceMap : inputSourceMap
77+ } ) ;
78+
79+ compilation . assets [ file ] = new SourceMapSource (
80+ obfuscationResult . toString ( ) ,
81+ file ,
82+ JSON . parse ( transferredSourceMap ) ,
83+ asset . source ( ) ,
84+ inputSourceMap
85+ ) ;
86+ } else {
87+ compilation . assets [ file ] = new RawSource ( obfuscationResult . toString ( ) ) ;
7588 }
7689 } ) ;
7790
0 commit comments