Fix newline handling after yield

YieldExpressions can only be defined as:
 * `yield`
 * `yield` [no nlb] AssignmentExpression
 * `yield` [no nlb] `*` AssignmentExpression
This commit is contained in:
Anthony Van de Gejuchte
2016-06-11 21:41:16 +02:00
parent fa29344781
commit b0555a123a
2 changed files with 29 additions and 11 deletions

View File

@@ -1174,17 +1174,23 @@ function parse($TEXT, options) {
var has_expression = true;
var tmp;
// Get expression behind yield, default to value `undefined` stored as `null` in ast
// Expression must start on same line, yield* has a mandatory expression
if (is("operator", "*")) {
star = true;
next();
if (S.token.nlb) {
unexpected(S.prev);
}
} else if (can_insert_semicolon() ||
// Attempt to get expression or star (and then the mandatory expression)
// behind yield on the same line.
//
// If nothing follows on the same line of the yieldExpression,
// it should default to the value `undefined` for yield to return.
// In that case, the `undefined` stored as `null` in ast.
//
// Note 1: It isn't allowed for yield* to close without an expression
// Note 2: If there is a nlb between yield and star, it is interpret as
// yield <explicit undefined> <inserted automatic semicolon> *
if (can_insert_semicolon() ||
(is("punc") && PUNC_AFTER_EXPRESSION(S.token.value))) {
has_expression = false;
} else if (is("operator", "*")) {
star = true;
next();
}
return new AST_Yield({