@@ -45,6 +45,63 @@ describe('FunctionTransformer', () => {
45
45
} ) ;
46
46
} ) ;
47
47
48
+ describe ( 'function id name obfuscation' , ( ) => {
49
+ const functionExpressionParamIdentifierRegExp : RegExp = / \( f u n c t i o n * \( ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) \) * \{ / ;
50
+ const functionParamIdentifierRegExp : RegExp = / f u n c t i o n * ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) * \( \) * \{ / ;
51
+ const functionObjectIdentifierRegExp : RegExp = / r e t u r n n e w ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) * \( \) ; / ;
52
+
53
+ let obfuscatedCode : string ,
54
+ functionExpressionParamIdentifierName : string ,
55
+ functionParamIdentifierName : string ,
56
+ functionObjectIdentifierName : string ;
57
+
58
+ before ( ( ) => {
59
+ const code : string = readFileAsString ( __dirname + '/fixtures/function-id-name.js' ) ;
60
+
61
+ obfuscatedCode = JavaScriptObfuscator . obfuscate (
62
+ code ,
63
+ {
64
+ ...NO_ADDITIONAL_NODES_PRESET
65
+ }
66
+ ) . getObfuscatedCode ( ) ;
67
+
68
+ const functionExpressionParamIdentifierMatch : RegExpMatchArray | null = obfuscatedCode
69
+ . match ( functionExpressionParamIdentifierRegExp ) ;
70
+ const functionParamIdentifierMatch : RegExpMatchArray | null = obfuscatedCode
71
+ . match ( functionParamIdentifierRegExp ) ;
72
+ const functionObjectIdentifierMatch : RegExpMatchArray | null = obfuscatedCode
73
+ . match ( functionObjectIdentifierRegExp ) ;
74
+
75
+ functionParamIdentifierName = ( < RegExpMatchArray > functionParamIdentifierMatch ) [ 1 ] ;
76
+ functionExpressionParamIdentifierName = ( < RegExpMatchArray > functionExpressionParamIdentifierMatch ) [ 1 ] ;
77
+ functionObjectIdentifierName = ( < RegExpMatchArray > functionObjectIdentifierMatch ) [ 1 ] ;
78
+ } ) ;
79
+
80
+ it ( 'should correctly transform function expression parameter identifier' , ( ) => {
81
+ assert . match ( obfuscatedCode , functionExpressionParamIdentifierRegExp ) ;
82
+ } ) ;
83
+
84
+ it ( 'should correctly transform function parameter identifier' , ( ) => {
85
+ assert . match ( obfuscatedCode , functionParamIdentifierRegExp ) ;
86
+ } ) ;
87
+
88
+ it ( 'should correctly transform function object parameter identifier' , ( ) => {
89
+ assert . match ( obfuscatedCode , functionObjectIdentifierRegExp ) ;
90
+ } ) ;
91
+
92
+ it ( 'should generate same names for function parameter and function object identifiers' , ( ) => {
93
+ assert . equal ( functionParamIdentifierName , functionObjectIdentifierName ) ;
94
+ } ) ;
95
+
96
+ it ( 'should generate same names for function parameter identifiers' , ( ) => {
97
+ assert . equal ( functionExpressionParamIdentifierName , functionParamIdentifierName ) ;
98
+ } ) ;
99
+
100
+ it ( 'should generate same names for function expression parameter and function object identifiers' , ( ) => {
101
+ assert . equal ( functionExpressionParamIdentifierName , functionObjectIdentifierName ) ;
102
+ } ) ;
103
+ } ) ;
104
+
48
105
describe ( 'object pattern as parameter' , ( ) => {
49
106
describe ( 'Variant #1: simple' , ( ) => {
50
107
const functionParameterRegExp : RegExp = / f u n c t i o n * \( \{ * b a r * \} \) * \{ / ;
@@ -299,15 +356,15 @@ describe('FunctionTransformer', () => {
299
356
assert . match ( obfuscatedCode , functionBodyRegExp ) ;
300
357
} ) ;
301
358
302
- it ( 'equal #1: shouldn\'t keep same names variable declaration identifier and function parameters identifiers' , ( ) => {
359
+ it ( 'equal #1: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
303
360
assert . notEqual ( variableDeclarationIdentifierName , functionParameterIdentifierName ) ;
304
361
} ) ;
305
362
306
- it ( 'equal #2: shouldn\'t keep same names variable declaration identifier and function parameters identifiers' , ( ) => {
363
+ it ( 'equal #2: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
307
364
assert . notEqual ( variableDeclarationIdentifierName , functionDefaultParameterIdentifierName1 ) ;
308
365
} ) ;
309
366
310
- it ( 'equal #3: shouldn\'t keep same names variable declaration identifier and function parameters identifiers' , ( ) => {
367
+ it ( 'equal #3: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
311
368
assert . notEqual ( variableDeclarationIdentifierName , functionDefaultParameterIdentifierName2 ) ;
312
369
} ) ;
313
370
0 commit comments