@@ -46,59 +46,107 @@ describe('FunctionTransformer', () => {
46
46
} ) ;
47
47
48
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 } ) * \( \) ; / ;
49
+ describe ( 'Variant #1' , ( ) => {
50
+ const functionExpressionParamIdentifierRegExp : RegExp = / \( f u n c t i o n * \( ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) \) * \{ / ;
51
+ const functionParamIdentifierRegExp : RegExp = / f u n c t i o n * ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) * \( \) * \{ / ;
52
+ const functionObjectIdentifierRegExp : RegExp = / r e t u r n n e w ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) * \( \) ; / ;
52
53
53
- let obfuscatedCode : string ,
54
- functionExpressionParamIdentifierName : string ,
55
- functionParamIdentifierName : string ,
56
- functionObjectIdentifierName : string ;
54
+ let obfuscatedCode : string ,
55
+ functionExpressionParamIdentifierName : string ,
56
+ functionParamIdentifierName : string ,
57
+ functionObjectIdentifierName : string ;
57
58
58
- before ( ( ) => {
59
- const code : string = readFileAsString ( __dirname + '/fixtures/function-id-name.js' ) ;
59
+ before ( ( ) => {
60
+ const code : string = readFileAsString ( __dirname + '/fixtures/function-id-name-1 .js' ) ;
60
61
61
- obfuscatedCode = JavaScriptObfuscator . obfuscate (
62
- code ,
63
- {
64
- ...NO_ADDITIONAL_NODES_PRESET
65
- }
66
- ) . getObfuscatedCode ( ) ;
62
+ obfuscatedCode = JavaScriptObfuscator . obfuscate (
63
+ code ,
64
+ {
65
+ ...NO_ADDITIONAL_NODES_PRESET
66
+ }
67
+ ) . getObfuscatedCode ( ) ;
67
68
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 ) ;
69
+ const functionExpressionParamIdentifierMatch : RegExpMatchArray | null = obfuscatedCode
70
+ . match ( functionExpressionParamIdentifierRegExp ) ;
71
+ const functionParamIdentifierMatch : RegExpMatchArray | null = obfuscatedCode
72
+ . match ( functionParamIdentifierRegExp ) ;
73
+ const functionObjectIdentifierMatch : RegExpMatchArray | null = obfuscatedCode
74
+ . match ( functionObjectIdentifierRegExp ) ;
74
75
75
- functionParamIdentifierName = ( < RegExpMatchArray > functionParamIdentifierMatch ) [ 1 ] ;
76
- functionExpressionParamIdentifierName = ( < RegExpMatchArray > functionExpressionParamIdentifierMatch ) [ 1 ] ;
77
- functionObjectIdentifierName = ( < RegExpMatchArray > functionObjectIdentifierMatch ) [ 1 ] ;
78
- } ) ;
76
+ functionParamIdentifierName = ( < RegExpMatchArray > functionParamIdentifierMatch ) [ 1 ] ;
77
+ functionExpressionParamIdentifierName = ( < RegExpMatchArray > functionExpressionParamIdentifierMatch ) [ 1 ] ;
78
+ functionObjectIdentifierName = ( < RegExpMatchArray > functionObjectIdentifierMatch ) [ 1 ] ;
79
+ } ) ;
79
80
80
- it ( 'should correctly transform function expression parameter identifier' , ( ) => {
81
- assert . match ( obfuscatedCode , functionExpressionParamIdentifierRegExp ) ;
82
- } ) ;
81
+ it ( 'should correctly transform function expression parameter identifier' , ( ) => {
82
+ assert . match ( obfuscatedCode , functionExpressionParamIdentifierRegExp ) ;
83
+ } ) ;
83
84
84
- it ( 'should correctly transform function parameter identifier' , ( ) => {
85
- assert . match ( obfuscatedCode , functionParamIdentifierRegExp ) ;
86
- } ) ;
85
+ it ( 'should correctly transform function parameter identifier' , ( ) => {
86
+ assert . match ( obfuscatedCode , functionParamIdentifierRegExp ) ;
87
+ } ) ;
87
88
88
- it ( 'should correctly transform function object parameter identifier' , ( ) => {
89
- assert . match ( obfuscatedCode , functionObjectIdentifierRegExp ) ;
90
- } ) ;
89
+ it ( 'should correctly transform function object parameter identifier' , ( ) => {
90
+ assert . match ( obfuscatedCode , functionObjectIdentifierRegExp ) ;
91
+ } ) ;
91
92
92
- it ( 'should generate same names for function parameter and function object identifiers' , ( ) => {
93
- assert . equal ( functionParamIdentifierName , functionObjectIdentifierName ) ;
94
- } ) ;
93
+ it ( 'should generate same names for function parameter and function object identifiers' , ( ) => {
94
+ assert . equal ( functionParamIdentifierName , functionObjectIdentifierName ) ;
95
+ } ) ;
96
+
97
+ it ( 'should generate same names for function parameter identifiers' , ( ) => {
98
+ assert . equal ( functionExpressionParamIdentifierName , functionParamIdentifierName ) ;
99
+ } ) ;
95
100
96
- it ( 'should generate same names for function parameter identifiers' , ( ) => {
97
- assert . equal ( functionExpressionParamIdentifierName , functionParamIdentifierName ) ;
101
+ it ( 'should generate same names for function expression parameter and function object identifiers' , ( ) => {
102
+ assert . equal ( functionExpressionParamIdentifierName , functionObjectIdentifierName ) ;
103
+ } ) ;
98
104
} ) ;
99
105
100
- it ( 'should generate same names for function expression parameter and function object identifiers' , ( ) => {
101
- assert . equal ( functionExpressionParamIdentifierName , functionObjectIdentifierName ) ;
106
+ describe ( 'Variant #2' , ( ) => {
107
+ const functionIdentifiersRegExp : RegExp = / f u n c t i o n * ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) * \( ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) \) * \{ / ;
108
+ const functionObjectIdentifierRegExp : RegExp = / r e t u r n n e w ( _ 0 x [ a - f 0 - 9 ] { 4 , 6 } ) * \( \) ; / ;
109
+
110
+ let obfuscatedCode : string ,
111
+ functionIdentifierName : string ,
112
+ functionParamIdentifierName : string ,
113
+ functionObjectIdentifierName : string ;
114
+
115
+ before ( ( ) => {
116
+ const code : string = readFileAsString ( __dirname + '/fixtures/function-id-name-2.js' ) ;
117
+
118
+ obfuscatedCode = JavaScriptObfuscator . obfuscate (
119
+ code ,
120
+ {
121
+ ...NO_ADDITIONAL_NODES_PRESET
122
+ }
123
+ ) . getObfuscatedCode ( ) ;
124
+
125
+ const functionIdentifiersMatch : RegExpMatchArray | null = obfuscatedCode
126
+ . match ( functionIdentifiersRegExp ) ;
127
+ const functionObjectIdentifierMatch : RegExpMatchArray | null = obfuscatedCode
128
+ . match ( functionObjectIdentifierRegExp ) ;
129
+
130
+ functionIdentifierName = ( < RegExpMatchArray > functionIdentifiersMatch ) [ 1 ] ;
131
+ functionParamIdentifierName = ( < RegExpMatchArray > functionIdentifiersMatch ) [ 2 ] ;
132
+ functionObjectIdentifierName = ( < RegExpMatchArray > functionObjectIdentifierMatch ) [ 1 ] ;
133
+ } ) ;
134
+
135
+ it ( 'should correctly transform function identifiers' , ( ) => {
136
+ assert . match ( obfuscatedCode , functionIdentifiersRegExp ) ;
137
+ } ) ;
138
+
139
+ it ( 'should correctly transform function object parameter identifier' , ( ) => {
140
+ assert . match ( obfuscatedCode , functionObjectIdentifierRegExp ) ;
141
+ } ) ;
142
+
143
+ it ( 'should generate same names for function parameter and function object identifiers' , ( ) => {
144
+ assert . equal ( functionIdentifierName , functionObjectIdentifierName ) ;
145
+ } ) ;
146
+
147
+ it ( 'should generate same names for function id and parameter identifiers' , ( ) => {
148
+ assert . equal ( functionIdentifierName , functionParamIdentifierName ) ;
149
+ } ) ;
102
150
} ) ;
103
151
} ) ;
104
152
@@ -356,27 +404,27 @@ describe('FunctionTransformer', () => {
356
404
assert . match ( obfuscatedCode , functionBodyRegExp ) ;
357
405
} ) ;
358
406
359
- it ( 'equal #1: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
360
- assert . notEqual ( variableDeclarationIdentifierName , functionParameterIdentifierName ) ;
407
+ it ( 'equal #1: should keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
408
+ assert . equal ( variableDeclarationIdentifierName , functionParameterIdentifierName ) ;
361
409
} ) ;
362
410
363
411
it ( 'equal #2: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
364
412
assert . notEqual ( variableDeclarationIdentifierName , functionDefaultParameterIdentifierName1 ) ;
365
413
} ) ;
366
414
367
- it ( 'equal #3: shouldn\'t keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
368
- assert . notEqual ( variableDeclarationIdentifierName , functionDefaultParameterIdentifierName2 ) ;
415
+ it ( 'equal #3: should keep same names for variable declaration identifier and function parameters identifiers' , ( ) => {
416
+ assert . equal ( variableDeclarationIdentifierName , functionDefaultParameterIdentifierName2 ) ;
369
417
} ) ;
370
418
371
- it ( 'should keep same names for identifier in first function parameter and default value identifier of second function parameter' , ( ) => {
419
+ it ( 'equal #4: should keep same names for identifier in first function parameter and default value identifier of second function parameter' , ( ) => {
372
420
assert . equal ( functionParameterIdentifierName , functionDefaultParameterIdentifierName2 ) ;
373
421
} ) ;
374
422
375
- it ( 'equal #1 : should keep same names for identifiers in function params and function body' , ( ) => {
423
+ it ( 'equal #5 : should keep same names for identifiers in function params and function body' , ( ) => {
376
424
assert . equal ( functionParameterIdentifierName , functionBodyIdentifierName1 ) ;
377
425
} ) ;
378
426
379
- it ( 'equal #2 : should keep same names for identifiers in function params and function body' , ( ) => {
427
+ it ( 'equal #6 : should keep same names for identifiers in function params and function body' , ( ) => {
380
428
assert . equal ( functionDefaultParameterIdentifierName1 , functionBodyIdentifierName2 ) ;
381
429
} ) ;
382
430
} ) ;
0 commit comments