{"record":{"id":"52c6618896ca3e54","repo":"swc-project/swc","slug":"tried-to-parse-an-argument-of-yield","errorCode":null,"errorMessage":"Tried to parse an argument of yield","messagePattern":"Tried to parse an argument of yield","errorType":"validation","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_lexer/src/common/parser/expr.rs","lineNumber":122,"sourceCode":"\nfn parse_yield_expr<'a, P: Parser<'a>>(p: &mut P) -> PResult<Box<Expr>> {\n    let start = p.input().cur_pos();\n    p.assert_and_bump(&P::Token::YIELD);\n    debug_assert!(p.ctx().contains(Context::InGenerator));\n\n    // Spec says\n    // YieldExpression cannot be used within the FormalParameters of a generator\n    // function because any expressions that are part of FormalParameters are\n    // evaluated before the resulting generator object is in a resumable state.\n    if p.ctx().contains(Context::InParameters) && !p.ctx().contains(Context::InFunction) {\n        syntax_error!(p, p.input().prev_span(), SyntaxError::YieldParamInGen)\n    }\n\n    let parse_with_arg = |p: &mut P| {\n        let has_star = p.input_mut().eat(&P::Token::MUL);\n        let err_span = p.span(start);\n        let arg = parse_assignment_expr(p).map_err(|err| {\n            Error::new(\n                err.span(),\n                SyntaxError::WithLabel {\n                    inner: Box::new(err),\n                    span: err_span,\n                    note: \"Tried to parse an argument of yield\",\n                },\n            )\n        })?;\n        Ok(YieldExpr {\n            span: p.span(start),\n            arg: Some(arg),\n            delegate: has_star,\n        }\n        .into())\n    };\n\n    if p.is_general_semi() || {\n        let cur = p.input().cur();","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_lexer/src/common/parser/expr.rs#L104-L140","documentation":"Labeled syntax error from parse_yield_expr: a yield expression was found inside the FormalParameters of a generator function (Context::InParameters without InFunction). The spec forbids this because parameter expressions are evaluated before the generator object is resumable; the label clarifies the failing sub-parse of the yield argument.","triggerScenarios":"Thrown at crates/swc_ecma_lexer/src/common/parser/expr.rs:122 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the yield expression out of the generator's parameter list into the function body","Wrap the inner function (non-generator or arrow) so yield is legal in that scope"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}