{"record":{"id":"f7b89496d691417f","repo":"karatelabs/karate","slug":"invalid-sitename-arrow-function","errorCode":null,"errorMessage":"invalid ${siteName}: arrow function","messagePattern":"invalid (.+?): arrow function","errorType":"exception","errorClass":"ParserException","httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/parser/JsParser.java","lineNumber":1717,"sourceCode":"            Node inner = stripExprWrappers(body);\n            if (inner == null) {\n                throw new ParserException(\"invalid \" + siteName);\n            }\n            if (inner.type == NodeType.LIT_EXPR && inner.size() >= 1) {\n                NodeType lit = inner.getFirst().type;\n                if (lit == NodeType.LIT_ARRAY || lit == NodeType.LIT_OBJECT) {\n                    throw new ParserException(\"invalid \" + siteName + \": parenthesized destructuring pattern\");\n                }\n            }\n            n = inner;\n        }\n        switch (n.type) {\n            case REF_EXPR -> {\n                // REF_EXPR is single-arg arrow `x => ...` when its first child is an\n                // FN_ARROW_EXPR rather than the IDENT token; that form is invalid.\n                if (n.size() >= 1 && !n.getFirst().isToken()\n                        && n.getFirst().type == NodeType.FN_ARROW_EXPR) {\n                    throw new ParserException(\"invalid \" + siteName + \": arrow function\");\n                }\n                // `this` lexes as IDENT (see JsLexer.keywordOrIdent) but per spec\n                // the ThisExpression has AssignmentTargetType=invalid.\n                if (n.size() >= 1 && n.getFirst().isToken()\n                        && n.getFirst().token.type == IDENT\n                        && \"this\".equals(n.getFirst().getText())) {\n                    throw new ParserException(\"invalid \" + siteName + \": this\");\n                }\n            }\n            case REF_DOT_EXPR, REF_BRACKET_EXPR -> {\n                // 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                }","sourceCodeStart":1699,"sourceCodeEnd":1735,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/parser/JsParser.java#L1699-L1735","documentation":"Karate's JS engine validates that the left-hand side of an assignment (or other assignment-target position) is a valid Reference. A single-argument arrow function like `x => ...` appearing in that position has no AssignmentTargetType, so the parser rejects it with this message naming the syntax site.","triggerScenarios":"Parsing code where an assignment/destructuring target position contains a REF_EXPR whose first child is an FN_ARROW_EXPR, e.g. `(x => x) = 1` or `(a, b = () => c) = [1, 2]`.","commonSituations":"Typos such as using `=>` instead of `=` in an assignment; accidentally swapping the sides of an arrow function and an assignment; generated or transpiled code with malformed output.","solutions":["Fix the source so the left side of `=` is an identifier, member access, or destructuring pattern","Replace `=>` with `=` if an assignment was intended","Wrap the arrow function in a call or store it in a variable before using its result"],"exampleFix":"// before\nx => 42 = y;\n// after\nlet f = x => 42;\ny = f(0);","handlingStrategy":"validation","validationCode":"// validate before evaluating assignment\nconst lhs = expr.left;\nif (lhs && lhs.type === 'ArrowFunctionExpression') {\n  throw new Error('LHS of assignment cannot be an arrow function');\n}","typeGuard":"function isArrowLhs(node) {\n  return node != null && node.type === 'ArrowFunctionExpression';\n}","tryCatchPattern":"try {\n  karate.eval(code);\n} catch (e) {\n  if (String(e.message).includes('arrow function')) { /* fix syntax */ }\n  throw e;\n}","preventionTips":["Never place `=>` expressions on the left of `=`","Lint JS snippets before eval with a parser that flags invalid assignment targets","When generating code, verify LHS is an Identifier/MemberExpression/Pattern"],"tags":["javascript","parser","syntax-error","assignment-target"],"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"}