MatAtBread / fast-async

605 stars 21 forks source link

Does not transpile defaults in object destructuring #39

Closed reconbot closed 6 years ago

reconbot commented 6 years ago

config

{
    "presets": [
      [
        "env",
        {
          "targets": {
            "node": "6.10"
          },
          "exclude": [
            "transform-regenerator",
            "transform-async-to-generator"
          ]
        }
      ]
    ],
    "plugins": [
      "syntax-async-functions",
      [
        "fast-async",
        {
          "useRuntimeModule":true
        }
      ],
      "add-module-exports",
      [
        "transform-object-rest-spread",
        {
          "useBuiltIns": true
        }
      ]
    ]
}

Input:

const {
  bar = async bar => bar
} = {}

async function test ({
  foo = async foo => foo
}, cb = async foo => foo) {
  console.log(foo, cb)
}

output

"use strict";

var _nodentRuntime = require("nodent-runtime");

var _nodentRuntime2 = _interopRequireDefault(_nodentRuntime);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const {
  bar = async bar => bar
} = {};

function test({
  foo = async foo => foo
}, cb = foo => new Promise(function ($return, $error) {
  return $return(foo);
}.$asyncbind(this))) {
  return new Promise(function ($return, $error) {
    console.log(foo, cb);
    return $return();
  }.$asyncbind(this));
}

Thanks!

matAtWork commented 6 years ago

Yep, it's a bug. I'll take a look at fixing it ASAP. The actual issue is in https://github.com/MatAtBread/nodent-compiler, and I've replicated the core case in https://github.com/MatAtBread/nodent/issues/97 (which you might want to listen to).

reconbot commented 6 years ago

Thanks! I got a fairly large codebase I'm trying to port over from bluebird coroutines, so far this is the only obvious issue. πŸ‘Œ

matAtWork commented 6 years ago

Hopefully this is fixed by https://github.com/MatAtBread/nodent/releases/tag/3.1.2 (on npmjs).

If you have any further issues, please create a new issue in https://github.com/MatAtBread/nodent/issues

Thanks for the report!

reconbot commented 6 years ago

nodent@3.1.2 isn't on npm yet, and is there a release of fast-async that uses the updated runtime?

matAtWork commented 6 years ago

Says it is for me: https://www.npmjs.com/package/nodent

matatbread matatbread published 17 hours ago
3.1.2 is the latest of 180 releases

I didn't update fast-async as I didn't change anything in it, and it should simply import nodent>=3.1.0. The "easy" way to make sure you have the right version is to npm update nodent-compiler, or just uninstall then reinstall fast-async

reconbot commented 6 years ago

Ohh my mistake, I was trying to install nodent-runtime@3.1.2 which doesn't exist.

So I've removed fast-async and added it again with no luck.

// from npm ls
β”œβ”€β”¬ fast-async@6.3.0
β”‚ β”œβ”€β”¬ nodent-compiler@3.1.2
β”‚ β”‚ β”œβ”€β”€ acorn@5.1.1 deduped
β”‚ β”‚ β”œβ”€β”€ acorn-es7-plugin@1.1.7
β”‚ β”‚ └── source-map@0.5.6 deduped
β”‚ └── nodent-runtime@3.0.4

It took a yarn upgrade

β”œβ”€β”¬ fast-async@6.3.0
β”‚ β”œβ”€β”¬ nodent-compiler@3.1.2
β”‚ β”‚ β”œβ”€β”€ acorn@5.1.1 deduped
β”‚ β”‚ β”œβ”€β”€ acorn-es7-plugin@1.1.7
β”‚ β”‚ └── source-map@0.5.7 deduped
β”‚ └── nodent-runtime@3.0.4

Which worked! I'm not sure if source-map is a red hearing but, whatever. I'm happy and it worked! I leave these notes for future people in with similar problems.

Thank you so much!