Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweet.js conflicts with ES6 spreads #715

Open
ghost opened this issue Jun 2, 2017 · 7 comments
Open

Sweet.js conflicts with ES6 spreads #715

ghost opened this issue Jun 2, 2017 · 7 comments

Comments

@ghost
Copy link

ghost commented Jun 2, 2017

You can try with online editor. I cannot using spreads with Sweet.

  Error: expecting a , punctuator
pointer

This code:

operator $ postfix 1 = (right) => {
  return #`${right}[0][${right}[1]]`;
};

operator $$ prefix 1 = (left) => {
  return #`...${left}`;
};

operator $p left 19 = (object, accessor) => {
  return #`[${object}, ${accessor}]`;
};

let array = [0, 1, 2];
let pointer = array $p 0;
pointer $ = 2;

let v = pointer $;

function acceptPair(array, index){
  
}

acceptPair( $$ pointer );
@gabejohnson
Copy link
Member

I think you have a bug in your definition of $$. It should be

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

@ghost
Copy link
Author

ghost commented Jun 2, 2017

operator $ prefix 1 = (_, right) => {
  return #`${right}[0][${right}[1]]`;
};

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

operator $p left 19 = (object, accessor) => {
  return #`[${object}, ${accessor}]`;
};

let array = [0, 1, 2];
let pointer = array $p 0;
$ pointer = 2;

let v = $ pointer;

function acceptPair(array, index){
  
}

acceptPair( $$ pointer );

Anyways

  Error: replacement values for syntax template must not be null or undefined

@gabejohnson
Copy link
Member

@capitalknew Sorry, I haven't had coffee yet. Your definition of $$ was correct. I'll take a look in the editor.

@ghost
Copy link
Author

ghost commented Jun 2, 2017

This is not coffee script. This is SweetJS and ES6 (spreads usage) example.

@gabejohnson
Copy link
Member

This is not coffee script

I know. I was talking about the drink 😄

I think this issue is related to on #650 (comment). It's good to have an issue specifically for it though. Thank you.

@gabejohnson
Copy link
Member

operator $ prefix 1 = (right) => {
  return #`${right}[0][${right}[1]]`;
};

is broken for a different reason. right is a MacroContext object an can't be interpolated the way you're attempting to. Try

operator $ prefix 1 = (right) => {
  var ptr = right.next().value;
  return #`${ptr}[0][${ptr}[1]]`;
};

@ghost
Copy link
Author

ghost commented Jun 2, 2017

Also, try fix "..." operator, it really needs for ES6 today.
Error: expecting a , punctuator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant