MatAtBread/fast-async

Babel 7 version ignoring options?

verydanny opened this issue · 1 comments

Package.json

    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.2.2",
    "@babel/plugin-proposal-class-properties": "^7.3.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.3.2",
    "@babel/plugin-transform-modules-commonjs": "^7.2.0",
    "@babel/plugin-transform-runtime": "^7.2.0",
    "@babel/preset-env": "^7.3.1",
    "@babel/preset-react": "^7.0.0",
    "@babel/register": "^7.0.0",
    "fast-async": "^7",

My babel.config.js:

module.exports = api => {
  api.cache(true)

  const presets = [
    ['@babel/preset-env', {
      exclude: [
        'transform-async-to-generator',
        'transform-regenerator',
      ],
    }],
    '@babel/preset-react',
  ]

  const plugins = [
    ['module:fast-async', {
      compiler: {
        promises: false,
      },
    }],
    '@babel/plugin-transform-runtime',
    '@babel/plugin-proposal-class-properties',
    '@babel/plugin-proposal-object-rest-spread',
  ]

  const env = {
    commonjs: {
      plugins: [
        ['@babel/plugin-transform-modules-commonjs', { loose: true }],
      ],
    },
  }

  return {
    presets,
    plugins,
    env,
  }
}

Snippet of code:

export default async ({
  store,
  location,
  ...options
}) => {
  if (!store) {
    throw new Error('Expected to receive a redux store.')
  }
  return ({
    dispatch: store.dispatch,
    getState: store.getState,
    location: store.dispatch('hello').location,
    ...options,
  })
}

Out: { compiler: { promises: false }}

"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _default = function _default(_ref) {
  return new Promise(function ($return, $error) {
    var store = _ref.store,
        location = _ref.location,
        options = (0, _objectWithoutProperties2.default)(_ref, ["store", "location"]);

    if (!store) {
      return $error(new Error('Expected to receive a redux store.'));
    }

    return $return((0, _objectSpread2.default)({
      dispatch: store.dispatch,
      getState: store.getState,
      location: store.dispatch('hello').location
    }, options));
  });
};

exports.default = _default;

Out: { compiler: { promises: true }}
Same as above

Is fast-async only spec now? None of the setting seem to impact anything. Does the documentation need to be updated? Thanks

@verydanny

Looking at the source of fast-async 7.0.6 it seems that the options sub-object which used to be housed under the compilers option should now go under an as-of-yet not documented codeGenerationOptions option:

fast-async/plugin.js

Lines 44 to 51 in 52336c7

if (options.codeGenerationOptions) {
var keys = Object.keys(options.codeGenerationOptions);
for (var i = 0; i < keys.length; i++) {
if (keys[i] in opts) {
opts[keys[i]] = options.codeGenerationOptions[keys[i]];
}
}
}

Don't bother fixing up your configuration. It more than likely won't help getting your code to compile correctly. fast-async@7 seems broken and will generate code that uses generator functions, even if explicitly told not to. See #67

EDIT:
No wait; that's my bad.
Messed up Babel configuration was not tearing out the entire async-to-generator transformation.