Skip to content

Commit 4da4b62

Browse files
committed
sojsonv7: Fix string-array decoding
Chained variables can be defined in the init part of a for statement. Signed-off-by: echo094 <20028238+echo094@users.noreply.github.com>
1 parent c899865 commit 4da4b62

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/plugin/sojsonv7.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ function decodeGlobal(ast) {
283283
if (item.path.isFunctionDeclaration()) {
284284
scope = item.path.parentPath.scope
285285
}
286-
const refs = scope.bindings[cur_val].referencePaths
286+
// var is function scoped and let is block scoped
287+
// Hence, var may not be in the current scope, e.g., in a for-loop
288+
const binding = scope.getBinding(cur_val)
289+
scope = binding.scope
290+
const refs = binding.referencePaths
287291
const refs_next = []
288292
for (let ref of refs) {
289293
const parent = ref.parentPath
@@ -294,12 +298,21 @@ function decodeGlobal(ast) {
294298
path: parent,
295299
code: 'var ' + parent,
296300
})
301+
} else if (ref.key === 'right') {
302+
// AssignmentExpression
303+
refs_next.push({
304+
name: parent.node.left.name,
305+
path: parent,
306+
code: 'var ' + parent,
307+
})
297308
} else if (ref.key === 'object') {
298309
// MemberExpression
299310
memToStr(parent)
300311
} else if (ref.key === 'callee') {
301312
// CallExpression
302313
funToStr(parent)
314+
} else {
315+
console.error('Unexpected reference')
303316
}
304317
}
305318
for (let ref of refs_next) {

0 commit comments

Comments
 (0)