{"record":{"id":"10e886357c21c7c9","repo":"karatelabs/karate","slug":"invalid-sitename-nodetype-is-not-a-valid-assignment-target","errorCode":null,"errorMessage":"invalid ${siteName}: ${nodeType} is not a valid assignment target","messagePattern":"invalid (.+?): (.+?) is not a valid assignment target","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1746,"sourceCode":"                // Plain member access; a `?.` would have been caught earlier by\n                // the optional-chain branch above with a more specific message.\n                // `import.meta` is a meta-property whose AssignmentTargetType is\n                // invalid; `import` is not a reserved word in our lexer so it\n                // parses as a normal REF_DOT_EXPR — flag the literal shape here.\n                if (n.type == NodeType.REF_DOT_EXPR && isImportMeta(n)) {\n                    throw new ParserException(\"invalid \" + siteName + \": import.meta\");\n                }\n            }\n            case FN_CALL_EXPR -> {\n                // Web-compat carve-out (Annex B B.3.5): allow `f() = 1` in non-strict mode.\n                // Logical-assignment operators (||=, &&=, ??=) are ES2021 and the carve-out\n                // does NOT apply to them; the caller passes noCallCarveOut=true in that case.\n                if (noCallCarveOut) {\n                    throw new ParserException(\"invalid \" + siteName + \": call expression\");\n                }\n            }\n            default ->\n                    throw new ParserException(\"invalid \" + siteName + \": \"\n                            + n.type.name() + \" is not a valid assignment target\");\n        }\n    }\n\n    /**\n     * Strip thin {@code EXPR} / {@code EXPR_LIST} single-child wrappers introduced\n     * by the parser so that callers can inspect the underlying expression shape.\n     * Returns the node unchanged once the wrappers run out or the node has more\n     * than one child.\n     */\n    private static Node stripExprWrappers(Node n) {\n        while (n != null && n.size() == 1\n                && (n.type == NodeType.EXPR || n.type == NodeType.EXPR_LIST)) {\n            n = n.get(0);\n        }\n        return n;\n    }\n","sourceCodeStart":1728,"sourceCodeEnd":1764,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1728-L1764","documentation":"Catch-all rejection in assignment-target validation: when a node of an unhandled type appears in an assignment/binding target position, the parser reports that the node type is not a valid assignment target, naming the concrete NodeType.","triggerScenarios":"Any syntactic form that is not an identifier, member access, or destructuring pattern placed on the left of `=`, in a destructuring pattern, or in `++`/`--`/compound-assignment positions — e.g. literals (`1 = x`), binary expressions (`a + b = c`), or template literals as targets.","commonSituations":"Typos like `if x = 1` intent written elsewhere, `a + b = c`, or LHS literals produced by code-generation mistakes.","solutions":["Make the left side an identifier, property access, or destructuring pattern","Compute the right-hand expression first and assign the result to a variable","Check for swapped operands: often the expression belongs on the right of `=`"],"exampleFix":"// before\na + b = total;\n// after\nconst total = a + b;","handlingStrategy":"validation","validationCode":"const VALID = ['Identifier','MemberExpression','ObjectPattern','ArrayPattern'];\nif (expr.left && !VALID.includes(expr.left.type)) {\n  throw new Error('invalid assignment target: ' + expr.left.type);\n}","typeGuard":"function isValidTarget(node) {\n  return ['Identifier','MemberExpression','ObjectPattern','ArrayPattern'].includes(node?.type);\n}","tryCatchPattern":"try {\n  karate.eval(code);\n} catch (e) {\n  if (String(e.message).includes('is not a valid assignment target')) { /* inspect LHS */ }\n  throw e;\n}","preventionTips":["Keep LHS of assignments to identifiers/properties/patterns","Check for swapped operands when expressions appear left of `=`","Lint generated code for literal/binary targets"],"tags":["javascript","parser","assignment-target","syntax-error"],"backgroundTag":"invalid-argument-value","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"}