MCPcopy Create free account
hub / github.com/babel/babel / parseYield

Function parseYield

packages/babel-parser/src/parser/expression.ts:3038–3079  ·  view source on GitHub ↗
(this: Parser, startLoc: Position)

Source from the content-addressed store, hash-verified

3036 // Parses yield expression inside generator.
3037
3038 parseYield(this: Parser, startLoc: Position): N.YieldExpression {
3039 const node = this.startNodeAt<N.YieldExpression>(startLoc);
3040
3041 this.expressionScope.recordParameterInitializerError(
3042 Errors.YieldInParameter,
3043 startLoc.index,
3044 );
3045
3046 let delegating = false;
3047 let argument: N.Expression | null = null;
3048 if (!this.hasPrecedingLineBreak()) {
3049 delegating = this.eat(tt.star);
3050 switch (this.state.type) {
3051 case tt.semi:
3052 case tt.eof:
3053 case tt.braceR:
3054 case tt.parenR:
3055 case tt.bracketR:
3056 case tt.braceBarR:
3057 case tt.colon:
3058 case tt.comma:
3059 // The above is the complete set of tokens that can
3060 // follow an AssignmentExpression, and none of them
3061 // can start an AssignmentExpression
3062 if (!delegating) break;
3063 /* fallthrough */
3064 case tt._in:
3065 // `in` may follow an AssignmentExpression[~In] in an Annex B
3066 // for-in initializer: `for (var x = yield in z)`
3067 if (this.options.annexB && !delegating) break;
3068 /* fallthrough */
3069 default:
3070 argument = this.parseMaybeAssign();
3071 }
3072 }
3073 if (!argument) {
3074 this.state.regExpAllowedAt = this.state.lastTokEndLoc!.index;
3075 }
3076 node.delegate = delegating;
3077 node.argument = argument;
3078 return this.finishNode(node, "YieldExpression");
3079 }
3080
3081 // https://tc39.es/ecma262/#prod-ImportCall
3082 parseImportCall(

Callers

nothing calls this directly

Calls 3

finishNodeMethod · 0.80
parseMaybeAssignMethod · 0.45

Tested by

no test coverage detected