{"record":{"id":"3f8420f028cba9cf","repo":"karatelabs/karate","slug":"cannot-apply-logical-assignment-to-node","errorCode":null,"errorMessage":"cannot apply logical-assignment to: ${node}","messagePattern":"cannot apply logical-assignment to: (.+?)","errorType":"exception","errorClass":"JsErrorException (typeError)","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/PropertyAccess.java","lineNumber":453,"sourceCode":"                    PrivateAccess.set(site.target, site.privateName, newValue, context);\n                    yield newValue;\n                }\n                if (site.receiver != null) {\n                    // super reference — the fused by-index/by-name workers\n                    // below have no receiver seam; run the generic sequence.\n                    Object oldValue = siteRead(site, context);\n                    if (context.isStopped()) yield null;\n                    if (!shouldLogicalAssign(operator, oldValue)) yield oldValue;\n                    Object newValue = Interpreter.eval(rhsNode, context);\n                    if (context.isStopped()) yield null;\n                    siteWrite(site, newValue, context, trackingNode);\n                    yield newValue;\n                }\n                yield site.isIndex\n                        ? logicalCompoundByIndex(site.target, site.key, operator, rhsNode, context, trackingNode)\n                        : logicalCompoundByName(site.target, (String) site.key, operator, rhsNode, context, trackingNode);\n            }\n            default -> throw JsErrorException.typeError(\"cannot apply logical-assignment to: \" + node);\n        };\n    }\n\n    // Name-keyed REF_EXPR tails, outlined from their switch cases to keep the\n    // slot fast paths small enough to inline reliably.\n\n    private static Object compoundRefByName(Node node, CoreContext context, TokenType operator, Node rhsNode, Node trackingNode) {\n        String name = node.getText();\n        Object oldValue = context.get(name);\n        if (context.isStopped()) return Terms.UNDEFINED;\n        Object operand = Interpreter.eval(rhsNode, context);\n        if (context.isStopped()) return Terms.UNDEFINED;\n        Object newValue = applyOperator(oldValue, operator, operand, context);\n        context.update(name, newValue, trackingNode);\n        return newValue;\n    }\n\n    private static Object logicalCompoundRefByName(Node node, CoreContext context, TokenType operator, Node rhsNode, Node trackingNode) {","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/PropertyAccess.java#L435-L471","documentation":"A TypeError thrown when a logical assignment operator (`||=`, `&&=`, `??=`) is applied to a parse-tree node type that is neither a variable reference nor a member access. It is the default arm of the switch in PropertyAccess.logicalCompound, so it indicates an LHS shape the evaluator cannot treat as an assignment reference.","triggerScenarios":"Executing a script whose logical-assignment LHS parses as something other than REF_EXPR / REF_DOT_EXPR / REF_BRACKET_EXPR — e.g. `(a + b) ||= 1`, assignment to a call result, or a malformed/generated AST.","commonSituations":"Hand-edited JS with an expression on the left of `||=`; code generators emitting invalid assignment targets; engine/parser version mismatch.","solutions":["Rewrite the statement so the LHS is a variable or property access","Compute the expression into a variable, then apply the logical assignment to that variable","If the LHS appears valid, check for a parser regression and upgrade the engine"],"exampleFix":"// before\nfoo().bar ??= 1;\n// after\nlet f = foo();\nf.bar ??= 1;","handlingStrategy":"validation","validationCode":"// Reject logical-assignment statements whose LHS is not an identifier/member\nif (/[^=!<>]=(&&|\\|\\||\\?\\?)?\\s*(?![\\w$.[])/.test(code)) { /* lint target */ }\n// preferred: parse and check node type before eval\n// valid = ['Identifier','MemberExpression'].includes(lhs.type)","typeGuard":"function isLogicalAssignTarget(lhsNode) {\n  return lhsNode && ['Identifier','MemberExpression'].includes(lhsNode.type);\n}","tryCatchPattern":null,"preventionTips":["Only use ||=, &&=, ??= on identifiers or property accesses","Lint generated code for invalid assignment targets","Avoid hand-editing minified/generated JS"],"tags":["javascript","ast","unsupported-lhs"],"backgroundTag":"unsupported-operation","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}