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

Babel 7 version ignoring options? #62

Open
verydanny opened this issue Feb 8, 2019 · 1 comment
Open

Babel 7 version ignoring options? #62

verydanny opened this issue Feb 8, 2019 · 1 comment

Comments

@verydanny
Copy link

verydanny commented Feb 8, 2019

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

@rjgotten
Copy link

rjgotten commented Jul 17, 2019

@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.

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

No branches or pull requests

2 participants