added 8 commits
March 15, 2017 21:43This commit fixes, in a fairly myopic way, the most obviously incorrect
issues with object slices. In particular:
* `o{k: expr}`, if `expr` is not a valid key, will now produce an error
instead of compiling to `{k: o[expr]}`. (This does not interfere with
the special property logic syntax `o{k: a ? b}`, which still becomes
`{k: o.a ? b}`.) Anyone who really wants the other interpretation can
explicitly write `o{k: (expr)}`.
* Speaking of property logic, attempting to use `xor` as a property
operator now also produces an error, as it was clearly excluded from
the special list of operators that the AST code knew to handle for
this feature despite being treated as such by the parser.
* `o{(a.b)}` now correctly accesses `o[a.b]` instead of `o.ref$` (yeah,
that was happening!)
This commit is a refactoring that doesn't touch the language grammar (it does touch the interface between the grammar and AST). It prepares for the grammar refactoring that comes next. No language semantics are changed. The big idea here is to have Objs hold only Props (well, and comments), and to pull out any and/or/? logic onto the Prop instead of having it wrap the Prop or the value inside the Prop. Splats in Objs are now Prop(Splat!, contents), and keyless properties are simply Props with a null key. The refactoring also pulls out slice expanding and property shorthand expanding as a distinct pass from the rest of the compilation; this makes them easier to reason about and cleans up the rest of the code a little.
This commit simplifies the parse grammar by permitting arbitrary
expressions to sit inside objects and letting the AST sort out the
shorthand. As a side effect, this makes `{a.b.c}` no longer a parse
error, and so all expressions of the form `{expr.k}` now legally
expand to `{k: expr.k}`
The destructuring label syntax `[]:k` only has an effect in a pattern position, like the LHS of an assignment. Previously, such labels were simply ignored outside of patterns; now, throw an explicit syntax error if a value with a label is compiled.
Change the semantics of splats in an object destructuring pattern to mean taking all the keys from the destructuree that have not yet been extracted into this object, instead of importing all subkeys from one specific key on the destructuree. Resolves gkz#941