File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -56,7 +56,13 @@ function getGlobalConcealingNames(glo_fn_path) {
56
56
const obj = { }
57
57
glo_fn_path . traverse ( {
58
58
SwitchCase ( path ) {
59
- const key = parseInt ( generator ( path . node . test ) . code )
59
+ const code = generator ( path . node . test ) . code
60
+ const key = parseInt ( code )
61
+ if ( Number . isNaN ( key ) ) {
62
+ console . error ( `[GlobalConcealing] concealed key: ${ code } ` )
63
+ obj [ 'invalid' ] = true
64
+ return
65
+ }
60
66
let consequent = path . node . consequent [ 0 ]
61
67
if ( t . isReturnStatement ( consequent ) ) {
62
68
obj [ key ] = consequent . argument . property . value
@@ -113,15 +119,20 @@ const deGlobalConcealing = {
113
119
const glo_vars = getGlobalConcealingNames ( obj . glo_fn_path )
114
120
console . log ( `[GlobalConcealing] globalFn: ${ obj . glo_fn_name } ` )
115
121
let binding = obj . glo_fn_path . parentPath . scope . getBinding ( obj . glo_fn_name )
122
+ let remain = false
116
123
for ( const ref of binding . referencePaths ) {
117
124
const repl_path = ref . parentPath
118
125
if ( ref . key !== 'callee' || ! repl_path . isCallExpression ( ) ) {
119
126
continue
120
127
}
121
128
const key = parseInt ( generator ( repl_path . node . arguments [ 0 ] ) . code )
122
- repl_path . replaceWith ( t . identifier ( glo_vars [ key ] ) )
129
+ if ( glo_vars [ key ] ) {
130
+ repl_path . replaceWith ( t . identifier ( glo_vars [ key ] ) )
131
+ } else {
132
+ remain = true
133
+ }
123
134
}
124
- if ( safeDeleteNode ( obj . glo_fn_name , obj . glo_fn_path ) ) {
135
+ if ( ! remain && safeDeleteNode ( obj . glo_fn_name , obj . glo_fn_path ) ) {
125
136
obj . tmp_path . remove ( )
126
137
}
127
138
} ,
Original file line number Diff line number Diff line change @@ -293,7 +293,7 @@ function processStackParam(path, len) {
293
293
while ( changed ) {
294
294
checkStackInvalid ( path , invalid )
295
295
if ( ! checkChangeValid ( invalid , used ) ) {
296
- path . replaceWith ( parse ( orig_code ) )
296
+ path . replaceWith ( parse ( orig_code ) . program . body [ 0 ] )
297
297
used = { }
298
298
}
299
299
changed = tryStackReplace ( path , len , invalid , used )
You can’t perform that action at this time.
0 commit comments