obscura-js 2.0.1 → 2.0.2
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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequenceExpression.d.ts","sourceRoot":"","sources":["../../../src/obfuscation/sequenceExpression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,UAAU,EACf,OAAO,GAAE,yBAA8B,GACtC,IAAI,
|
|
1
|
+
{"version":3,"file":"sequenceExpression.d.ts","sourceRoot":"","sources":["../../../src/obfuscation/sequenceExpression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,UAAU,EACf,OAAO,GAAE,yBAA8B,GACtC,IAAI,CA6EN"}
|
|
@@ -34,22 +34,50 @@ function applySequenceExpression(ast, options = {}) {
|
|
|
34
34
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
35
|
const toSeq = (block) => {
|
|
36
36
|
const exprs = block.stmts.map((s) => s.expression); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
37
|
+
// Always wrap in ParenthesisExpression so the comma-operator sequence
|
|
38
|
+
// and single assignment expressions are always syntactically valid
|
|
39
|
+
// regardless of the enclosing context (ternary branch or && right-hand
|
|
40
|
+
// side). Without parens, `cond && x = v` is parsed as `(cond && x) = v`
|
|
41
|
+
// which is a SyntaxError because the LHS is not assignable.
|
|
37
42
|
if (exprs.length === 1)
|
|
38
|
-
return exprs[0];
|
|
39
|
-
// Wrap in ParenthesisExpression so the comma-operator sequence is
|
|
40
|
-
// always syntactically valid regardless of the enclosing context
|
|
41
|
-
// (ternary branch or && right-hand side).
|
|
43
|
+
return swc_utils_1.t.parenthesisExpression(exprs[0]);
|
|
42
44
|
return swc_utils_1.t.parenthesisExpression(swc_utils_1.t.sequenceExpression(exprs));
|
|
43
45
|
};
|
|
46
|
+
// SWC's printer does NOT automatically parenthesise lower-precedence
|
|
47
|
+
// operators on the left-hand side of && or as the condition of ?:.
|
|
48
|
+
// We must do it explicitly when the test node has lower precedence
|
|
49
|
+
// than the operator we are generating.
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
const wrapTest = (node, context) => {
|
|
52
|
+
const type = node?.type;
|
|
53
|
+
const op = node?.operator;
|
|
54
|
+
if (context === "&&") {
|
|
55
|
+
// Lower precedence than &&: || ?? ?: = , (sequence)
|
|
56
|
+
if ((type === "BinaryExpression" && (op === "||" || op === "??")) ||
|
|
57
|
+
type === "ConditionalExpression" ||
|
|
58
|
+
type === "AssignmentExpression" ||
|
|
59
|
+
type === "SequenceExpression") {
|
|
60
|
+
return swc_utils_1.t.parenthesisExpression(node);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Lower precedence than ?:: = , (sequence)
|
|
65
|
+
// (|| / ?? / && all bind tighter than ?: so they never need wrapping here)
|
|
66
|
+
if (type === "AssignmentExpression" || type === "SequenceExpression") {
|
|
67
|
+
return swc_utils_1.t.parenthesisExpression(node);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return node;
|
|
71
|
+
};
|
|
44
72
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
73
|
let replacement;
|
|
46
74
|
if (alternate === null || alternate === undefined) {
|
|
47
75
|
// if (cond) { ... } → cond && (...)
|
|
48
|
-
replacement = swc_utils_1.t.logicalExpression("&&", test, toSeq(consequent));
|
|
76
|
+
replacement = swc_utils_1.t.logicalExpression("&&", wrapTest(test, "&&"), toSeq(consequent));
|
|
49
77
|
}
|
|
50
78
|
else {
|
|
51
79
|
// if (cond) { ... } else { ... } → cond ? (...) : (...)
|
|
52
|
-
replacement = swc_utils_1.t.conditionalExpression(test, toSeq(consequent), toSeq(alternate));
|
|
80
|
+
replacement = swc_utils_1.t.conditionalExpression(wrapTest(test, "?:"), toSeq(consequent), toSeq(alternate));
|
|
53
81
|
}
|
|
54
82
|
path.replaceWith(swc_utils_1.t.expressionStatement(replacement));
|
|
55
83
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sequenceExpression.js","sourceRoot":"","sources":["../../../src/obfuscation/sequenceExpression.ts"],"names":[],"mappings":";;AAgBA,
|
|
1
|
+
{"version":3,"file":"sequenceExpression.js","sourceRoot":"","sources":["../../../src/obfuscation/sequenceExpression.ts"],"names":[],"mappings":";;AAgBA,0DAgFC;AAhGD,4CAA2C;AAI3C;;;;;;;;;;;GAWG;AACH,SAAgB,uBAAuB,CACrC,GAAe,EACf,UAAqC,EAAE;IAEvC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC;IAE/C,IAAA,oBAAQ,EAAC,GAAG,EAAE;QACZ,WAAW,CAAC,IAAI;YACd,IAAI,IAAI,CAAC,MAAM,EAAE,GAAG,WAAW;gBAAE,OAAO;YAExC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;YAElD,8DAA8D;YAC9D,iDAAiD;YACjD,8DAA8D;YAC9D,MAAM,UAAU,GAAG,CAAC,IAAS,EAAW,EAAE,CACxC,aAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC;gBACxB,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;gBACrB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,aAAC,CAAC,qBAAqB,CAAC,CAAC,CAA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