webfuscator 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analysis/constant.js +3 -3
- package/dist/analysis/constant.js.map +1 -1
- package/dist/analysis/inlineability.js +2 -2
- package/dist/analysis/inlineability.js.map +1 -1
- package/dist/analysis/purity.js +1 -1
- package/dist/analysis/purity.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/obfuscator.d.ts.map +1 -1
- package/dist/obfuscator.js.map +1 -1
- package/dist/options.d.ts.map +1 -1
- package/dist/preparation/expand-destructuring.js +4 -3
- package/dist/preparation/expand-destructuring.js.map +1 -1
- package/dist/preparation/expand-template-literals.js +3 -2
- package/dist/preparation/expand-template-literals.js.map +1 -1
- package/dist/preparation/split-sequence-expressions.js +1 -1
- package/dist/preparation/split-sequence-expressions.js.map +1 -1
- package/dist/preparation/split-variable-declarations.js +1 -1
- package/dist/preparation/split-variable-declarations.js.map +1 -1
- package/dist/preparation/stringify-object-keys.js +1 -1
- package/dist/preparation/stringify-object-keys.js.map +1 -1
- package/dist/preparation/wrap-single-statements.js +2 -2
- package/dist/preparation/wrap-single-statements.js.map +1 -1
- package/dist/transforms/arguments-to-parameters.js +1 -1
- package/dist/transforms/arguments-to-parameters.js.map +1 -1
- package/dist/transforms/arrow-to-function.js.map +1 -1
- package/dist/transforms/collapse-single-use-temps.js +7 -7
- package/dist/transforms/collapse-single-use-temps.js.map +1 -1
- package/dist/transforms/const-let-to-var.js +3 -3
- package/dist/transforms/const-let-to-var.js.map +1 -1
- package/dist/transforms/const-to-let.js.map +1 -1
- package/dist/transforms/do-while-to-while.js +3 -3
- package/dist/transforms/do-while-to-while.js.map +1 -1
- package/dist/transforms/drop-console.js +4 -3
- package/dist/transforms/drop-console.js.map +1 -1
- package/dist/transforms/drop-debugger.js.map +1 -1
- package/dist/transforms/expand-binary-assignment.js +5 -3
- package/dist/transforms/expand-binary-assignment.js.map +1 -1
- package/dist/transforms/expand-logical-assignment.js +5 -3
- package/dist/transforms/expand-logical-assignment.js.map +1 -1
- package/dist/transforms/extract-object-properties.js +7 -7
- package/dist/transforms/extract-object-properties.js.map +1 -1
- package/dist/transforms/fold-builtin-methods.js +16 -15
- package/dist/transforms/fold-builtin-methods.js.map +1 -1
- package/dist/transforms/fold-constants.js +2 -2
- package/dist/transforms/fold-constants.js.map +1 -1
- package/dist/transforms/for-to-while.js +5 -5
- package/dist/transforms/for-to-while.js.map +1 -1
- package/dist/transforms/function-declaration-to-expression.js +3 -3
- package/dist/transforms/function-declaration-to-expression.js.map +1 -1
- package/dist/transforms/inline-functions.js +7 -7
- package/dist/transforms/inline-functions.js.map +1 -1
- package/dist/transforms/logical-to-ternary.js +2 -2
- package/dist/transforms/logical-to-ternary.js.map +1 -1
- package/dist/transforms/mangle-properties.d.ts.map +1 -1
- package/dist/transforms/mangle-properties.js +35 -86
- package/dist/transforms/mangle-properties.js.map +1 -1
- package/dist/transforms/nullish-coalescing-to-ternary.js +2 -2
- package/dist/transforms/nullish-coalescing-to-ternary.js.map +1 -1
- package/dist/transforms/numbers-to-strings.js +2 -2
- package/dist/transforms/numbers-to-strings.js.map +1 -1
- package/dist/transforms/object-method-to-property.js +1 -1
- package/dist/transforms/object-method-to-property.js.map +1 -1
- package/dist/transforms/optional-chaining-to-ternary.js +2 -2
- package/dist/transforms/optional-chaining-to-ternary.js.map +1 -1
- package/dist/transforms/pack-declarations-into-parameters.js +2 -2
- package/dist/transforms/pack-declarations-into-parameters.js.map +1 -1
- package/dist/transforms/pack.d.ts.map +1 -1
- package/dist/transforms/pack.js +10 -11
- package/dist/transforms/pack.js.map +1 -1
- package/dist/transforms/remove-anonymous-function-names.js +3 -3
- package/dist/transforms/remove-anonymous-function-names.js.map +1 -1
- package/dist/transforms/remove-unreachable-code.js +1 -1
- package/dist/transforms/remove-unreachable-code.js.map +1 -1
- package/dist/transforms/remove-unused-code.js +4 -4
- package/dist/transforms/remove-unused-code.js.map +1 -1
- package/dist/transforms/rename-identifiers.d.ts.map +1 -1
- package/dist/transforms/rename-identifiers.js +4 -3
- package/dist/transforms/rename-identifiers.js.map +1 -1
- package/dist/transforms/specials-to-strings.d.ts.map +1 -1
- package/dist/transforms/specials-to-strings.js +2 -2
- package/dist/transforms/specials-to-strings.js.map +1 -1
- package/dist/transforms/switch-to-if.js +7 -7
- package/dist/transforms/switch-to-if.js.map +1 -1
- package/dist/transforms/ternary-to-if.js +7 -4
- package/dist/transforms/ternary-to-if.js.map +1 -1
- package/dist/transforms/update-to-assignment.js +4 -2
- package/dist/transforms/update-to-assignment.js.map +1 -1
- package/dist/transforms/yodify-conditions.js +3 -3
- package/dist/transforms/yodify-conditions.js.map +1 -1
- package/dist/utils/ast.d.ts.map +1 -1
- package/dist/utils/ast.js +2 -1
- package/dist/utils/ast.js.map +1 -1
- package/dist/utils/evaluation-order.js.map +1 -1
- package/dist/utils/logical-lowering.js +2 -2
- package/dist/utils/logical-lowering.js.map +1 -1
- package/dist/utils/loop-lowering.js +1 -1
- package/dist/utils/loop-lowering.js.map +1 -1
- package/dist/utils/string-generator.js +1 -1
- package/dist/utils/string-generator.js.map +1 -1
- package/package.json +11 -10
- package/src/analysis/constant.ts +4 -4
- package/src/analysis/inlineability.ts +4 -4
- package/src/analysis/purity.ts +3 -3
- package/src/index.ts +4 -2
- package/src/obfuscator.ts +42 -42
- package/src/options.ts +1 -1
- package/src/preparation/expand-destructuring.ts +5 -4
- package/src/preparation/expand-template-literals.ts +4 -3
- package/src/preparation/split-sequence-expressions.ts +2 -2
- package/src/preparation/split-variable-declarations.ts +1 -1
- package/src/preparation/stringify-object-keys.ts +2 -2
- package/src/preparation/wrap-single-statements.ts +2 -2
- package/src/transforms/arguments-to-parameters.ts +5 -5
- package/src/transforms/arrow-to-function.ts +3 -3
- package/src/transforms/collapse-single-use-temps.ts +14 -14
- package/src/transforms/const-let-to-var.ts +6 -6
- package/src/transforms/const-to-let.ts +4 -4
- package/src/transforms/do-while-to-while.ts +6 -6
- package/src/transforms/drop-console.ts +8 -7
- package/src/transforms/drop-debugger.ts +2 -2
- package/src/transforms/expand-binary-assignment.ts +8 -6
- package/src/transforms/expand-logical-assignment.ts +8 -6
- package/src/transforms/extract-object-properties.ts +12 -12
- package/src/transforms/fold-builtin-methods.ts +20 -19
- package/src/transforms/fold-constants.ts +8 -8
- package/src/transforms/for-to-while.ts +8 -8
- package/src/transforms/function-declaration-to-expression.ts +5 -5
- package/src/transforms/inline-functions.ts +14 -14
- package/src/transforms/logical-to-ternary.ts +7 -7
- package/src/transforms/mangle-properties.ts +43 -97
- package/src/transforms/nullish-coalescing-to-ternary.ts +6 -6
- package/src/transforms/numbers-to-strings.ts +4 -4
- package/src/transforms/object-method-to-property.ts +4 -4
- package/src/transforms/optional-chaining-to-ternary.ts +5 -5
- package/src/transforms/pack-declarations-into-parameters.ts +7 -7
- package/src/transforms/pack.ts +20 -16
- package/src/transforms/remove-anonymous-function-names.ts +5 -5
- package/src/transforms/remove-unreachable-code.ts +3 -3
- package/src/transforms/remove-unused-code.ts +8 -8
- package/src/transforms/rename-identifiers.ts +9 -8
- package/src/transforms/specials-to-strings.ts +7 -7
- package/src/transforms/switch-to-if.ts +12 -12
- package/src/transforms/ternary-to-if.ts +12 -9
- package/src/transforms/update-to-assignment.ts +7 -5
- package/src/transforms/yodify-conditions.ts +6 -6
- package/src/utils/ast.ts +2 -1
- package/src/utils/evaluation-order.ts +1 -1
- package/src/utils/logical-lowering.ts +3 -3
- package/src/utils/loop-lowering.ts +1 -1
- package/src/utils/string-generator.ts +1 -1
|
@@ -3,11 +3,11 @@ import type { Binding, Scope } from '@babel/traverse'
|
|
|
3
3
|
import * as t from '@babel/types'
|
|
4
4
|
import type { File } from '@babel/types'
|
|
5
5
|
|
|
6
|
-
import type { TransformContext } from '
|
|
7
|
-
import { isDirectEvalCall, isInsideWith } from '
|
|
8
|
-
import { hasAnnexBFunctionAlias, referencesOrWritesVariable } from '
|
|
9
|
-
import { mulberry32 } from '
|
|
10
|
-
import { StringGenerator } from '
|
|
6
|
+
import type { TransformContext } from '../options'
|
|
7
|
+
import { isDirectEvalCall, isInsideWith } from '../utils/ast'
|
|
8
|
+
import { hasAnnexBFunctionAlias, referencesOrWritesVariable } from '../utils/paths'
|
|
9
|
+
import { mulberry32 } from '../utils/random'
|
|
10
|
+
import { StringGenerator } from '../utils/string-generator'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Renames bindings and labels with a fresh `StringGenerator`. Each scope avoids
|
|
@@ -125,7 +125,7 @@ export function renameIdentifiers(ast: File, ctx: TransformContext): boolean {
|
|
|
125
125
|
|
|
126
126
|
traverse(ast, {
|
|
127
127
|
Scopable(path) {
|
|
128
|
-
const
|
|
128
|
+
const scope = path.scope
|
|
129
129
|
// Test global reservations during allocation to avoid copying them per scope.
|
|
130
130
|
const offLimits = new Set<string>()
|
|
131
131
|
const live = liveAncestors.get(scope)
|
|
@@ -174,7 +174,7 @@ export function renameIdentifiers(ast: File, ctx: TransformContext): boolean {
|
|
|
174
174
|
|
|
175
175
|
traverse(ast, {
|
|
176
176
|
Identifier(path) {
|
|
177
|
-
const
|
|
177
|
+
const node = path.node
|
|
178
178
|
const directName = idToName.get(node)
|
|
179
179
|
if (directName !== undefined) {
|
|
180
180
|
node.name = directName
|
|
@@ -200,7 +200,8 @@ export function renameIdentifiers(ast: File, ctx: TransformContext): boolean {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
function isNonBindingPosition(path: { node: t.Identifier; parent: t.Node }): boolean {
|
|
203
|
-
const
|
|
203
|
+
const node = path.node
|
|
204
|
+
const parent = path.parent
|
|
204
205
|
// A PrivateName id is not a variable and must match its class declaration.
|
|
205
206
|
if (t.isPrivateName(parent)) {
|
|
206
207
|
return true
|
|
@@ -3,11 +3,11 @@ import type { NodePath, Visitor } from '@babel/traverse'
|
|
|
3
3
|
import * as t from '@babel/types'
|
|
4
4
|
import type { File } from '@babel/types'
|
|
5
5
|
|
|
6
|
-
import type { TransformContext } from '
|
|
7
|
-
import { enclosingScopeHasDirectEval, isInsideWith } from '
|
|
8
|
-
import type { ChangeState } from '
|
|
9
|
-
import { mulberry32 } from '
|
|
10
|
-
import { StringGenerator } from '
|
|
6
|
+
import type { TransformContext } from '../options'
|
|
7
|
+
import { enclosingScopeHasDirectEval, isInsideWith } from '../utils/ast'
|
|
8
|
+
import type { ChangeState } from '../utils/change-tracking'
|
|
9
|
+
import { mulberry32 } from '../utils/random'
|
|
10
|
+
import { StringGenerator } from '../utils/string-generator'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Rewrites five constant-like values through strings for later string mangling:
|
|
@@ -59,7 +59,7 @@ const visitor: Visitor<State> = {
|
|
|
59
59
|
state.changed = true
|
|
60
60
|
},
|
|
61
61
|
Identifier(path, state) {
|
|
62
|
-
const
|
|
62
|
+
const name = path.node.name
|
|
63
63
|
if (!GLOBAL_SPECIALS.has(name)) {
|
|
64
64
|
return
|
|
65
65
|
}
|
|
@@ -93,7 +93,7 @@ function buildGlobalReplacement(name: string, str: t.StringLiteral): t.Expressio
|
|
|
93
93
|
// Babel calls update and iterator targets references, but replacements there
|
|
94
94
|
// would not be assignable. Delete also distinguishes references from values.
|
|
95
95
|
function isWriteTarget(path: NodePath<t.Identifier>): boolean {
|
|
96
|
-
const
|
|
96
|
+
const parentPath = path.parentPath
|
|
97
97
|
if (!parentPath) {
|
|
98
98
|
return false
|
|
99
99
|
}
|
|
@@ -2,11 +2,11 @@ import type { NodePath, Scope, Visitor } from '@babel/traverse'
|
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import type { File } from '@babel/types'
|
|
4
4
|
|
|
5
|
-
import { isPure } from '
|
|
6
|
-
import { traverseForChanges } from '
|
|
7
|
-
import type { ChangeState } from '
|
|
8
|
-
import { isPrimitiveLiteral } from '
|
|
9
|
-
import { generateLoopLabel } from '
|
|
5
|
+
import { isPure } from '../analysis/purity'
|
|
6
|
+
import { traverseForChanges } from '../utils/change-tracking'
|
|
7
|
+
import type { ChangeState } from '../utils/change-tracking'
|
|
8
|
+
import { isPrimitiveLiteral } from '../utils/literal'
|
|
9
|
+
import { generateLoopLabel } from '../utils/loop-lowering'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Lowers `switch` to an `if` chain or, when cases fall through, a labeled block
|
|
@@ -46,7 +46,7 @@ const visitor: Visitor<ChangeState> = {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function transformSwitch(path: NodePath<t.SwitchStatement>): boolean {
|
|
49
|
-
const
|
|
49
|
+
const node = path.node
|
|
50
50
|
// Separate `if` blocks cannot preserve cross-case lexical scope or Annex B
|
|
51
51
|
// function hoisting.
|
|
52
52
|
if (hasBlockScopedDeclaration(node)) {
|
|
@@ -114,7 +114,7 @@ function canLowerToIfElseChain(node: t.SwitchStatement): boolean {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
function caseEligibleForIfElseChain(caseClause: t.SwitchCase, isLast: boolean): boolean {
|
|
117
|
-
const
|
|
117
|
+
const consequent = caseClause.consequent
|
|
118
118
|
if (consequent.length === 0) {
|
|
119
119
|
return isLast
|
|
120
120
|
}
|
|
@@ -189,8 +189,8 @@ function buildBody(consequent: t.Statement[]): t.BlockStatement {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
function lowerToIfElseChain(path: NodePath<t.SwitchStatement>): void {
|
|
192
|
-
const
|
|
193
|
-
const
|
|
192
|
+
const node = path.node
|
|
193
|
+
const scope = path.scope
|
|
194
194
|
|
|
195
195
|
let discriminantExpr: t.Expression
|
|
196
196
|
const preStmts: t.Statement[] = []
|
|
@@ -244,8 +244,8 @@ function lowerToIfElseChain(path: NodePath<t.SwitchStatement>): void {
|
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
function lowerToLabeledBlock(path: NodePath<t.SwitchStatement>): void {
|
|
247
|
-
const
|
|
248
|
-
const
|
|
247
|
+
const node = path.node
|
|
248
|
+
const scope = path.scope
|
|
249
249
|
|
|
250
250
|
// `scope.generateUid` alone can collide with enclosing or nested labels.
|
|
251
251
|
const labelName = generateLoopLabel(path, 'switch')
|
|
@@ -314,7 +314,7 @@ function lowerToLabeledBlock(path: NodePath<t.SwitchStatement>): void {
|
|
|
314
314
|
|
|
315
315
|
const labeledBlock = t.labeledStatement(t.identifier(labelName), t.blockStatement(statements))
|
|
316
316
|
|
|
317
|
-
const
|
|
317
|
+
const labeledPath = path.replaceWith(labeledBlock)[0]
|
|
318
318
|
rewriteUnlabeledBreaks(labeledPath, labelName)
|
|
319
319
|
}
|
|
320
320
|
|
|
@@ -2,11 +2,11 @@ import type { NodePath, Visitor } from '@babel/traverse'
|
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import type { File } from '@babel/types'
|
|
4
4
|
|
|
5
|
-
import { isInsideWith } from '
|
|
6
|
-
import { traverseForChanges } from '
|
|
7
|
-
import type { ChangeState } from '
|
|
8
|
-
import { isConditionalGate, reorderableToStatement } from '
|
|
9
|
-
import { isStandaloneDeclaration } from '
|
|
5
|
+
import { isInsideWith } from '../utils/ast'
|
|
6
|
+
import { traverseForChanges } from '../utils/change-tracking'
|
|
7
|
+
import type { ChangeState } from '../utils/change-tracking'
|
|
8
|
+
import { isConditionalGate, reorderableToStatement } from '../utils/evaluation-order'
|
|
9
|
+
import { isStandaloneDeclaration } from '../utils/paths'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Lowers conditional expressions to `if` statements. Expression values use a
|
|
@@ -67,7 +67,9 @@ function lowerConditional(path: NodePath<t.ConditionalExpression>): boolean {
|
|
|
67
67
|
return false
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const
|
|
70
|
+
const test = path.node.test
|
|
71
|
+
const consequent = path.node.consequent
|
|
72
|
+
const alternate = path.node.alternate
|
|
71
73
|
|
|
72
74
|
if (parent.isExpressionStatement() && parent.node.expression === path.node) {
|
|
73
75
|
parent.replaceWith(
|
|
@@ -163,7 +165,7 @@ function lowerConditional(path: NodePath<t.ConditionalExpression>): boolean {
|
|
|
163
165
|
return false
|
|
164
166
|
}
|
|
165
167
|
|
|
166
|
-
const
|
|
168
|
+
const scope = path.scope
|
|
167
169
|
const tmpId = scope.generateUidIdentifier('ternaryResult')
|
|
168
170
|
scope.push({ id: t.cloneNode(tmpId) })
|
|
169
171
|
|
|
@@ -293,8 +295,9 @@ function lowerEnclosingLogical(path: NodePath, stmtPath: NodePath): boolean {
|
|
|
293
295
|
if (!logical || logical.removed || !logical.container) {
|
|
294
296
|
return false
|
|
295
297
|
}
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
+
const node = logical.node
|
|
299
|
+
const left = node.left
|
|
300
|
+
const right = node.right
|
|
298
301
|
let test: t.Expression
|
|
299
302
|
let valueRef: t.Expression
|
|
300
303
|
if (t.isIdentifier(left) && logical.scope.hasBinding(left.name)) {
|
|
@@ -2,9 +2,9 @@ import type { Binding, NodePath, Visitor } from '@babel/traverse'
|
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import type { File } from '@babel/types'
|
|
4
4
|
|
|
5
|
-
import { isDirectEvalCall, isInsideWith } from '
|
|
6
|
-
import { traverseForChanges } from '
|
|
7
|
-
import type { ChangeState } from '
|
|
5
|
+
import { isDirectEvalCall, isInsideWith } from '../utils/ast'
|
|
6
|
+
import { traverseForChanges } from '../utils/change-tracking'
|
|
7
|
+
import type { ChangeState } from '../utils/change-tracking'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Rewrites numeric updates as compound assignments for later expansion. Prefix
|
|
@@ -35,7 +35,9 @@ export function updateToAssignment(ast: File): boolean {
|
|
|
35
35
|
|
|
36
36
|
const visitor: Visitor<ChangeState> = {
|
|
37
37
|
UpdateExpression(path, state) {
|
|
38
|
-
const
|
|
38
|
+
const argument = path.node.argument
|
|
39
|
+
const prefix = path.node.prefix
|
|
40
|
+
const operator = path.node.operator
|
|
39
41
|
if (!t.isIdentifier(argument)) {
|
|
40
42
|
return
|
|
41
43
|
}
|
|
@@ -61,7 +63,7 @@ const visitor: Visitor<ChangeState> = {
|
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
function valueIsDiscarded(path: NodePath<t.UpdateExpression>): boolean {
|
|
64
|
-
const
|
|
66
|
+
const parentPath = path.parentPath
|
|
65
67
|
if (!parentPath) {
|
|
66
68
|
return false
|
|
67
69
|
}
|
|
@@ -2,9 +2,9 @@ import type { Visitor } from '@babel/traverse'
|
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import type { File } from '@babel/types'
|
|
4
4
|
|
|
5
|
-
import { traverseForChanges } from '
|
|
6
|
-
import type { ChangeState } from '
|
|
7
|
-
import { isLiteralShaped } from '
|
|
5
|
+
import { traverseForChanges } from '../utils/change-tracking'
|
|
6
|
+
import type { ChangeState } from '../utils/change-tracking'
|
|
7
|
+
import { isLiteralShaped } from '../utils/literal'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Moves a safe literal-shaped right operand to the left of a comparison.
|
|
@@ -31,7 +31,7 @@ export function yodifyConditions(ast: File): boolean {
|
|
|
31
31
|
|
|
32
32
|
const visitor: Visitor<ChangeState> = {
|
|
33
33
|
BinaryExpression(path, state) {
|
|
34
|
-
const
|
|
34
|
+
const node = path.node
|
|
35
35
|
const op = node.operator
|
|
36
36
|
if (!isComparisonOp(op)) {
|
|
37
37
|
return
|
|
@@ -51,8 +51,8 @@ const visitor: Visitor<ChangeState> = {
|
|
|
51
51
|
return
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const
|
|
55
|
-
const
|
|
54
|
+
const left = node.left
|
|
55
|
+
const right = node.right
|
|
56
56
|
node.left = right
|
|
57
57
|
node.right = left
|
|
58
58
|
const flipped = RELATIONAL_FLIP[op]
|
package/src/utils/ast.ts
CHANGED
|
@@ -13,7 +13,8 @@ export function isInDirectivePrologue(path: NodePath): boolean {
|
|
|
13
13
|
if (!inBody) {
|
|
14
14
|
return false
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const container = path.container
|
|
17
|
+
const index = path.key
|
|
17
18
|
if (!Array.isArray(container) || typeof index !== 'number') {
|
|
18
19
|
return false
|
|
19
20
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
|
|
4
|
-
import { isPure } from '
|
|
4
|
+
import { isPure } from '../analysis/purity'
|
|
5
5
|
|
|
6
6
|
// Moving a gated node can change whether it runs.
|
|
7
7
|
export function isConditionalGate(parent: NodePath, cur: NodePath): boolean {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
|
|
4
|
-
import { isSideEffectFree } from '
|
|
5
|
-
import { isStandaloneDeclaration } from '
|
|
4
|
+
import { isSideEffectFree } from '../analysis/purity'
|
|
5
|
+
import { isStandaloneDeclaration } from './paths'
|
|
6
6
|
|
|
7
7
|
// Lowers a short-circuit expression assigned to a bare identifier:
|
|
8
8
|
//
|
|
@@ -15,7 +15,7 @@ export function lowerLogicalWriteStatement(
|
|
|
15
15
|
path: NodePath<t.LogicalExpression>,
|
|
16
16
|
fallbackTest: (target: t.Identifier) => t.Expression,
|
|
17
17
|
): boolean {
|
|
18
|
-
const
|
|
18
|
+
const node = path.node
|
|
19
19
|
const parent = path.parentPath
|
|
20
20
|
if (!parent) {
|
|
21
21
|
return false
|
|
@@ -76,7 +76,7 @@ const redirectVisitor: Visitor<RedirectState> = {
|
|
|
76
76
|
path.skip()
|
|
77
77
|
},
|
|
78
78
|
ContinueStatement(path, state) {
|
|
79
|
-
const
|
|
79
|
+
const label = path.node.label
|
|
80
80
|
if (!label) {
|
|
81
81
|
if (!hasInterposedLoop(path, state.rootPath)) {
|
|
82
82
|
path.replaceWith(t.breakStatement(t.identifier(state.innerLabel)))
|