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

Fibers bug with IIFE in parentheses #185

Closed
aseemk opened this issue Dec 16, 2013 · 0 comments
Closed

Fibers bug with IIFE in parentheses #185

aseemk opened this issue Dec 16, 2013 · 0 comments

Comments

@aseemk
Copy link
Contributor

aseemk commented Dec 16, 2013

This source JS compiles fine:

(function() {
    async(_);
})();

But if you wrap it in parentheses, it doesn't under fibers mode (streamline 0.10.2):

((function() {
    async(_);
})());

The error and stack trace:

Error: Function contains async calls but does not have _ parameter on line 2
    <<< async stack >>>
    at Node.Walker.call (/path/to/streamline/lib/fibers/transform.js:356:36)
    at walk (/path/to/streamline/lib/fibers/walker.js:222:21)
    at Node.Walker.semicolon (/path/to/streamline/lib/fibers/transform.js:525:18)
    at walk (/path/to/streamline/lib/fibers/walker.js:169:21)
    at Array.map (native)
    at Node.Walker.function (/path/to/streamline/lib/fibers/transform.js:330:9)
    at walk (/path/to/streamline/lib/fibers/walker.js:30:21)
    at Node.Walker.call (/path/to/streamline/lib/fibers/transform.js:441:5)
    at walk (/path/to/streamline/lib/fibers/walker.js:222:21)
    at Node.Walker.semicolon (/path/to/streamline/lib/fibers/transform.js:525:18)
    at exports_loadFile__2 (/path/to/streamline/lib/callbacks/compile.js:190:9)
    at _compile (/path/to/streamline/lib/callbacks/compile.js:273:4)
    at __1 (/path/to/streamline/lib/callbacks/compile.js:306:2)
    at value__1 (/path/to/streamline/lib/callbacks/builtins.js:131:28)
    at exports_compile__3 (/path/to/streamline/lib/callbacks/compile.js:305:1)
    <<< raw stack >>>
    at Node.Walker.call (/path/to/streamline/lib/fibers/transform.js:356:36)
    at walk (/path/to/streamline/lib/fibers/walker.js:222:21)
    at Node.Walker.semicolon (/path/to/streamline/lib/fibers/transform.js:525:18)
    at walk (/path/to/streamline/lib/fibers/walker.js:169:21)
    at Array.map (native)
    at Node.Walker.function (/path/to/streamline/lib/fibers/transform.js:330:9)
    at walk (/path/to/streamline/lib/fibers/walker.js:30:21)
    at Node.Walker.call (/path/to/streamline/lib/fibers/transform.js:441:5)
    at walk (/path/to/streamline/lib/fibers/walker.js:222:21)
    at Node.Walker.semicolon (/path/to/streamline/lib/fibers/transform.js:525:18)

It compiles fine in callbacks mode.

That's the tiniest repro I could arrive at; my actual use case is something like this CoffeeScript:

# get the first URL from a list of URLs (fetched async'ly)
# that matches a given regex:
[url] = (url for url in getURLs _ when url.match regex)

Compiled JS:

// Generated by CoffeeScript 1.6.3
var url;

url = ((function() {
  var _i, _len, _ref, _results;
  _ref = getURLs(_);
  _results = [];
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
    url = _ref[_i];
    if (url.match(regex)) {
      _results.push(url);
    }
  }
  return _results;
})())[0];

Notice the parentheses around the IIFE.

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

No branches or pull requests

1 participant