Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Babel 7 #50

Closed
wants to merge 1 commit into from
Closed

Babel 7 #50

wants to merge 1 commit into from

Conversation

sharmilajesupaul
Copy link
Contributor

@sharmilajesupaul sharmilajesupaul commented Oct 3, 2018

Bumps deps to Babel v7

babel-cli@^6.26.0 -> @babel/cli@^7.1.2
babel-core@^6.26.3 -> @babel/core@^7.1.2
babel-register@^6.26.0 -> @babel/register@^7.0.0
[email protected]  -> ^3.0.1

Also bumps tape: ^4.9.0 -> ^4.9.1

Also updated the npm test script to use @babel/register and updated the readme to require @babel/core.

Looks like some new lines were removed while transforming with Babel 7 🤔, so I omitted them in the expected fixtures (d8397fd).

Tested this by npm linking to the Babel 7 branch on babel-preset-airbnb (airbnb/babel-preset-airbnb#37), and running tests.

src/index.js Outdated
@@ -1,5 +1,5 @@
import template from 'babel-template';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a maintainer of this module, but FYI this whole module could be rewritten as

export default ({ template }) => {
  const buildImport = template(`
    (new Promise((resolve) => {
      require.ensure([], (require) => {
        resolve(require(SOURCE));
      });
    }))
  `);
  
  return {
    manipulateOptions(opts, parserOpts) {
      parserOpts.plugins.push("dynamicImport");
    },

    visitor: {
      Import(path) {
        const newImport = buildImport({
          SOURCE: path.parentPath.node.arguments,
        });
        path.parentPath.replaceWith(newImport);
      },
    },
  };
};

and work on both Babel 6 and 7, I'd expect. Generally we don't recommend importing babel-template or @babel/template directly. The expectations are less clear for @babel/plugin-syntax-dynamic-import, but there's nothing wrong with just setting the parser plugin directly if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL. This seems like a much better alternative to releasing a breaking change that only supports Babel v7. I'll update this PR. Thanks @loganfsmyth!

Updates dev deps to Babel v7, adds a peer dependency on @babel/core.
@sharmilajesupaul
Copy link
Contributor Author

closing this package is now compatible with babel v6 & v7

@ljharb ljharb deleted the shar--babel-7 branch February 17, 2020 19:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants