{"record":{"id":"8f837d424713b74d","repo":"karatelabs/karate","slug":"invalid-assignment-to-name-in-strict-mode","errorCode":null,"errorMessage":"invalid assignment to '${name}' in strict mode","messagePattern":"invalid assignment to '(.+?)' in strict mode","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1473,"sourceCode":"            if (!seen.add(name)) {\n                return name;\n            }\n        }\n        return null;\n    }\n\n    /** A strict assignment / update may not target {@code eval} / {@code arguments}.\n     *  Only a bare identifier reference is an early error; member targets\n     *  ({@code arguments[0] = …}) are fine. */\n    private void checkAssignTargetBinding(Node lhs) {\n        if (lhs == null) {\n            return;\n        }\n        Node n = stripExprWrappers(lhs);\n        if (n != null && n.type == NodeType.REF_EXPR && n.size() == 1\n                && n.getFirst().isToken() && n.getFirst().token.type == IDENT\n                && isEvalOrArguments(n.getFirst().getText())) {\n            throw new ParserException(\n                    \"invalid assignment to '\" + n.getFirst().getText() + \"' in strict mode\");\n        }\n    }\n\n    /** Strict-mode early error for a legacy octal ({@code 0755}) or NonOctalDecimal\n     *  ({@code 08} / {@code 09}) integer literal — any NUMBER whose text starts with\n     *  {@code 0} immediately followed by a decimal digit. {@code 0x…} / {@code 0b…} /\n     *  {@code 0o…} / {@code 0.…} / {@code 0e…} have a non-digit second char and a plain\n     *  {@code 0} is length 1, so all are correctly excluded. */\n    private static void checkLegacyOctalLiteral(Node litExpr) {\n        if (litExpr.size() != 1) {\n            return;\n        }\n        Node tok = litExpr.getFirst();\n        if (!tok.isToken() || tok.token.type != NUMBER) {\n            return;\n        }\n        String text = tok.getText();","sourceCodeStart":1455,"sourceCodeEnd":1491,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1455-L1491","documentation":"Strict-mode early error: an assignment targets `eval` or `arguments` as a simple identifier, which the ECMAScript spec forbids in strict mode (and Karate's parser enforces). These names lose their special meaning in strict mode and may not be assigned, declared, or used as parameter names. Parsing fails before the script runs.","triggerScenarios":"Parsing code like `eval = 5;` or `arguments = something;` in strict mode — checkStrictInvalidAssignment detects an IDENT reference that isEvalOrArguments matches on the left-hand side of an assignment.","commonSituations":"Porting old sloppy-mode scripts that used `eval` or `arguments` as ordinary variable names; shadowing bugs where a helper was named `eval`; minified/generated code assigning to these reserved names.","solutions":["Rename the variable (e.g. `evalFn`, `args`) — `eval`/`arguments` are reserved as assignment targets in strict mode","Remove the assignment if it was unintentional (e.g. trying to overwrite built-in eval)","If assignment is truly needed, restructure to return a value instead of mutating `eval`/`arguments`"],"exampleFix":"// before\neval = myCode; // strict-mode violation\n// after\nvar evalFn = myCode;\nresult = evalFn();","handlingStrategy":"validation","validationCode":"// reject assignments to eval/arguments before parsing\nif (/\\b(?:eval|arguments)\\s*=[^=]/.test(src)) {\n  throw new Error('script assigns to eval/arguments: not allowed in strict mode');\n}","typeGuard":null,"tryCatchPattern":"try {\n  karate.runJs(src);\n} catch (e) {\n  if (String(e).includes(\"invalid assignment to\")) {\n    // rename eval/arguments variable in the script\n  }\n  throw e;\n}","preventionTips":["Never name variables `eval` or `arguments`","Enable ESLint no-shadow-restricted-names in the project","Review ported legacy scripts for reserved-name usage"],"tags":["javascript","parser","strict-mode","reserved-words"],"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-16T19:17:19.609Z"}