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

Helper functions from previous API call outputs in next call too #323

Open
lydell opened this issue Aug 1, 2014 · 8 comments
Open

Helper functions from previous API call outputs in next call too #323

lydell opened this issue Aug 1, 2014 · 8 comments

Comments

@lydell
Copy link
Collaborator

lydell commented Aug 1, 2014

$ node -pe "var cs = require('./lib/module'); cs.cs2js('a=c in d') + '\n--------------\n' + cs.cs2js('a=1')"
// Generated by CoffeeScript 2.0.0-beta9-dev
void function () {
  var a;
  a = in$(c, d);
  function in$(member, list) {
    for (var i = 0, length = list.length; i < length; ++i)
      if (i in list && list[i] === member)
        return true;
    return false;
  }
}.call(this);
--------------
// Generated by CoffeeScript 2.0.0-beta9-dev
void function () {
  var a;
  a = 1;
  function in$(member, list) {
    for (var i = 0, length = list.length; i < length; ++i)
      if (i in list && list[i] === member)
        return true;
    return false;
  }
}.call(this);

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@lydell
Copy link
Collaborator Author

lydell commented Aug 1, 2014

I think this happen because enableHelpers is a module-global variable. It should be created on each invocation.

@lydell
Copy link
Collaborator Author

lydell commented Aug 1, 2014

Are there any API tests? In case I end up making a PR…

lydell added a commit to lydell/CoffeeScriptRedux that referenced this issue Aug 1, 2014
- Self-hosted coffee compilation instead of dependency on (old version
  of) jashkenas/coffee-script.
- No more `@variable`s for global variables and helper functions, which
  involves having to use `=>` instead of `->` sometimes. Now, just use
  `variable` like in plain JavaScript.
- It is now possible to do `a:Foo? { a ?= []; rp a}` as expected.
- Better error messages. Partly because CSR has better error messages
  than jashkenas/coffee-script@1.6.3, partly because you also get to
  know in which rule the code resides. The error messages will get line
  and column numbers in the .pegcoffee file as soon as
  lydell/pegjs-each-code#1 is resolved.
- No more weird hacks in the initializer.
- Note: lib/parser.js gets pretty bloated because of michaelficarra#323.
lydell added a commit to lydell/CoffeeScriptRedux that referenced this issue Aug 20, 2014
- Self-hosted coffee compilation instead of dependency on (old version
  of) jashkenas/coffee-script.
- No more `@variable`s for global variables and helper functions, which
  involves having to use `=>` instead of `->` sometimes. Now, just use
  `variable` like in plain JavaScript.
- It is now possible to do `a:Foo? { a ?= []; rp a}` as expected.
- Better error messages. Partly because CSR has better error messages
  than jashkenas/coffee-script@1.6.3, partly because you also get to
  know in which rule the code resides. The error messages will get line
  and column numbers in the .pegcoffee file as soon as
  lydell/pegjs-each-code#1 is resolved.
- No more weird hacks in the initializer.
- Note: lib/parser.js gets pretty bloated because of michaelficarra#323.
@lydell
Copy link
Collaborator Author

lydell commented Aug 20, 2014

Does it make sense to pass helpers to each rule, just like inScope, ancestry etc.?

@michaelficarra
Copy link
Owner

I don't think so. helpers is something that needs to be mutated (or threaded through return values monadically), right? inScope and ancestry are entirely informational. They are built up in the traversal. Rules do not mutate them or pass out new values for them.

@lydell
Copy link
Collaborator Author

lydell commented Aug 21, 2014

Then I don't know how to fix this issue :(

@michaelficarra
Copy link
Owner

Yeah, it's a shitty one. You can keep the state in the Compiler instance and mutate it there instead of threading it through the compilation rules. It's cleaner. Unfortunately, JavaScript/CoffeeScript do not allow for very powerful abstraction.

@lydell
Copy link
Collaborator Author

lydell commented Aug 21, 2014

I thought about keeping the state on the Compiler instance as well, but the rules don't seem to have access to it?

@lydell
Copy link
Collaborator Author

lydell commented Aug 23, 2014

Just found efaa09b:

next up, remove {h,enabledH}elpers statefulness

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

No branches or pull requests

2 participants