sweet-js / sweet-core

Sweeten your JavaScript.
https://www.sweetjs.org
BSD 2-Clause "Simplified" License
4.58k stars 208 forks source link

Cannot use rest/spread operator in syntax template for all valid expressions #717

Open gabejohnson opened 7 years ago

gabejohnson commented 7 years ago

As noted #715

import { fromPunctuator } from 'sweet.js/helpers' for syntax;

syntax $$ = (ctx) => {
  var dummy = #`dummy`.get(0);
  return #`${fromPunctuator(dummy, '...')}${ctx}`;
};

function foo(args){}
foo( $$ [0] );

fails with Error: expecting a , punctuator [ 0 ], but

function foo(args){}
foo( ... [0] );

is fine.

Same with

let [$$ x] = [1]; // Error: unexpected token __x__

but this is fine

let x = [$$ [0]];

This may be related to #716. Hopefully it'll come out in the wash.