lexer: yield* is delegation - #309
Merged
Merged
Conversation
A `*` directly after `yield` on the same line scans as the FROM token
that `yield from` produces, so `yield* other()`, `yield *other()` and
`yield * other()` all delegate, which is how JavaScript reads the same
spelling. They used to compile to a bare yield multiplied by the
operand, which yielded undefined and never delegated.
`(yield) * 2` and `yield ** 2` keep their meaning, `*{` still opens a
Map literal ahead of this branch, `yield *= x` still rejects, and a `*`
opening the next line stays multiplication because the retag requires
the yield's own line.
No grammar change: the parser is byte-identical and the corpus is
unchanged. The editor grammars already color yield as a keyword and *
as an operator. The browser bundle is regenerated under the pinned Bun.
Battery: eight rows in async.rip pin the three spellings, the return
value, a generator method, the parenthesized multiply, exponentiation,
the Map literal, and the emitted code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
yield*now means delegation, the same thing asyield from. A*directly afteryieldon the same line scans as the delegation token, soyield* other(),yield *other()andyield * other()all emityield* other(). Until now they compiled to(yield) * other(): a bare yield multiplied by the operand, which yieldedundefinedand never delegated, with no error.Unchanged on purpose.
(yield) * 2andyield ** 2keep their meaning.yield *{a: 1}still yields a Map because*{is claimed first.yield *= xstill rejects. A*that opens the next line stays multiplication, since the retag requires the yield's own line.One meaning change.
yield * 3used to multiply the sent value by three and now delegates to3, which throws at runtime. JavaScript reads the spelling the same way.No grammar change.
src/parser.jsis byte-identical, the corpus is unchanged, and the three editor grammars already coloryieldas a keyword and*as an operator. Browser bundle regenerated under Bun 1.4.0.Test
Eight new rows in
async.rip. Language battery 3258 passing, toolchain gates 661 passing, fulltest:allsuite green across all 26 lanes.