Skip to content

Object literals, yield, and try/catch generate invalid js #301

@NickHeiner

Description

@NickHeiner

Given the following es6:

function* foo() {
    try {
        yield someValue;
    }
    catch (err) {
        var obj = {err: err};
    }
}

6to5@1.3.11 produces the following es5:

"use strict";

var foo = regeneratorRuntime.mark(function foo() {
  var obj;
  return regeneratorRuntime.wrap(function foo$(_context) {
    while (true) switch (_context.prev = _context.next) {
      case 0: _context.prev = 0;
        _context.next = 3;
        return someValue;
      case 3: _context.next = 8;
        break;
      case 5: _context.prev = 5;
        _context.t0 = _context["catch"](0);
        obj = { _context.t0: _context.t0 };
      case 8:
      case "end": return _context.stop();
    }
  }, foo, this, [[0, 5]]);
});

The part of the output is problematic:

        obj = { _context.t0: _context.t0 };

which comes from this line of es6:

        var obj = {err: err};

The correct output would be:

        obj = { err: _context.t0 };

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    outdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions