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

Invalid JS: [a?.b…] compiles to invalid JavaScript #4260

Closed
maxnordlund opened this issue Apr 26, 2016 · 4 comments
Closed

Invalid JS: [a?.b…] compiles to invalid JavaScript #4260

maxnordlund opened this issue Apr 26, 2016 · 4 comments
Labels

Comments

@maxnordlund
Copy link

I found this today, below is the reduced code to reproduce this error on coffeescript.org.

handler = (error) =>
  if error instanceof Error
    arr.push(error)
  else
    arr.push(error.data?.errors...)
  @showErrors = !!foo.length
var handler;

handler = (function(_this) {
  return function(error) {
    var ref;
    if (error instanceof Error) {
      arr.push(error);
    } else {
      // The loose if-statement is the error
      arr.push.apply(_this,       if ((ref = error.data) != null) {
        ref.errors;
      });
    }
    return _this.showErrors = !!foo.length;
  };
})(this);
@vendethiel vendethiel added the bug label Apr 26, 2016
@vendethiel
Copy link
Collaborator

Whoops, good catch...

@lydell
Copy link
Collaborator

lydell commented Apr 26, 2016

Minimal case:

coffee -bpe '[a?.b...]'
var slice = [].slice;

slice.call(  if (typeof a !== "undefined" && a !== null) {
    a.b;
  });

@GeoffreyBooth GeoffreyBooth changed the title Syntax error in the compiled JavaScript [a?.b…] compiles to invalid JavaScript Apr 28, 2017
@GeoffreyBooth GeoffreyBooth changed the title [a?.b…] compiles to invalid JavaScript Invalid JS: [a?.b…] compiles to invalid JavaScript May 6, 2017
@GeoffreyBooth
Copy link
Collaborator

Either a duplicate or else very closely related to #1349.

GeoffreyBooth added a commit to GeoffreyBooth/coffeescript that referenced this issue Aug 23, 2017
zdenko pushed a commit to GeoffreyBooth/coffeescript that referenced this issue Aug 23, 2017
GeoffreyBooth pushed a commit that referenced this issue Aug 27, 2017
…sions (#4644)

* fix splat error with soak properties or expressions

* Add test based on #4260

* Add test based on #1349

* tests for the leading splat variant

* test for spaced prefix ...

* fixed 'if' statement in parens

* fixed replacing 'void 0' with '[]'

* remove 'void 0' replacement; add Splat::compileNode

* Use LEVEL_OP; follow style better
@GeoffreyBooth
Copy link
Collaborator

Fixed by #4644.

GeoffreyBooth pushed a commit that referenced this issue Aug 27, 2017
…sions (#4643)

* fix splat error with soak properties or expressions

* Add test based on #4260

* Add test based on #1349

* remove 'void 0' replacement; add Splat::compileNode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants