sweet-js / sweet-core

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

operator ++ throwing: Error: replacement values for syntax template must not be null or undefined #679

Closed NSilv closed 7 years ago

NSilv commented 7 years ago

the following code:

operator ++ left 1 = (left, right) => #`${left}.concat(${right})`

let a = [1,2,3] 
let b = [4,5,6]
let c = a ++ b;

throws the following error:

Error: replacement values for syntax template must not be null or undefined
    at sanitizeReplacementValues (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\sweet.js\dist\load-syntax.js:64:11)
    at C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:3018:46
    at List.__iterate (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:2208:13)
    at IndexedIterable.mappedSequence.__iterateUncached (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:3017:23)
    at seqIterate (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:606:16)
    at IndexedIterable.IndexedSeq.__iterate (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:322:14)
    at IndexedIterable.toArray (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:4260:23)
    at new List (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:2067:62)
    at reify (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:3572:37)
    at List.map (C:\Users\User\Desktop\Nodejs\sweet_stuff\node_modules\immutable\dist\immutable.js:4403:14)
gabejohnson commented 7 years ago

I think this is an issue w/ ++ filling the role of prefix and postfix operator already. @disnet, maybe an ordering issue in enforestExpressionLoop?

gabejohnson commented 7 years ago

Additionally, the >>= bind example doesn't work if the first operand is an array:

operator >>= left 1 = (left, right) => {
  return #`${left}.then(${right})`;
}

[1, 2, 3] >>= [4, 5, 6]; // compiles to nothing
3 >>= [4, 5, 6] // 3..then([4, 5, 6]);
disnet commented 7 years ago

@NSilv thanks for reporting! Got a fix coming in.

@gabejohnson hehe that's a tricky one, not actually a bug though. Just further proof that the no-semicolon style is objectively wrong :)

ASI converts it to:

operator >>= left 1 = (left, right) => {
  return #`${left}.then(${right})`;
}[1, 2, 3] >>= [4, 5, 6]