question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose Acorn allowImportExportEverywhere option

See original GitHub issue

Meteor version 1.3.3.1, just released, allows imports to be made from within conditionals and nested scopes. This was a welcome change.

Regrettably, it causes an actual parsing error in ESLint.

 272:7  error  Parsing error: 'import' and 'export' may only appear at the top level

I dissected enough of your code to find that Acorn has an option that adds the support we in the Meteor community need - the allowImportExportEverywhere option. I added code in my local copy of Espree to accept allowImportExportEverywhere as an ecmaFeature and pass it through to Acorn. It took all of three lines and accomplished exactly what I’d hoped.

In espree.js:

        // apply parsing flags after sourceType to allow overriding
        if (options.ecmaFeatures && typeof options.ecmaFeatures === "object") {
            extra.ecmaFeatures = options.ecmaFeatures;
            impliedStrict = extra.ecmaFeatures.impliedStrict;
            extra.ecmaFeatures.impliedStrict = typeof impliedStrict === "boolean" && impliedStrict;
            if (options.ecmaFeatures.globalReturn) {
                acornOptions.allowReturnOutsideFunction = true;
            }
// begin new code
            if (options.ecmaFeatures.allowImportExportEverywhere) {
                acornOptions.allowImportExportEverywhere = true;
            }
// end new code
        }

In addition, it looks as though changing the current “meteor” environment implementation as follows makes it default that way for Meteor users.

In environments.js:

    meteor: {
        globals: globals.meteor,
        parserOptions: {
          ecmaFeatures: {
            allowImportExportEverywhere: true
          }
        }
    },

I’ve read the notes at the bottom of your READMEs in both ESLint and Espree discouraging “experimental features”. This one isn’t experimental within the Meteor community now, it’s production. And it promises to lead to exciting new capabilities in the future such as automatic code splitting. Furthermore, the NPM “reify” module that implements it is available to the whole NPM community, and Meteor itself will soon be moving to NPM. So it will spread beyond the Meteor community.

Please consider the above changes.

Also, I’d be happy to create PRs though I believe the above is basically it.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:5
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rhettlivingstoncommented, Jun 20, 2016

I might be wrong (@hzoo can correct me), but isn’t it possible to create a Babel plugin to support your extra syntax? If so, I’d think that babel-eslint could work with it.

Thank you very much for this suggestion. I will dig into babel-eslint again and see if such a thing is possible. I know that Ben Newman plans a Babel plugin that includes his “reify” package that transpiles nested imports and exports. But for this purpose, I don’t need the actual implementation that transpiles it all, I just need the parser to accept it. So, if a babel plugin can be specified without forking things and can turn on the flag for parsing, that would be a start.

Acorn only added the flag because Babel used to allow it.

Purely in the interest of history (which I find fun), the issue records in Acorn indicate that they added the flag when they “corrected” their parser to not support it on December 8, 2014. Babylon, the parser used by babel-eslint, states in their credits “Heavily based on acorn and acorn-jsx, thanks to the awesome work of @RReverser and @marijnh.” I went back to the Babylon repository view of December 7, 2014 and found that their README at that time was still titled “Acorn” in blazing letters at the top and their main parser was in “acorn.js”. So Babylon, which began its life based on acorn before that date in history, inherited its “problem” with nested imports from acorn and “fixed” them after Acorn did by adopting Acorn’s fix.

0reactions
nzakascommented, Jun 29, 2016

Now supported via babel-eslint (thanks @hzoo!), so closing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

azu on Twitter: "見てる: "Expose Acorn ...
見てる: "Expose Acorn allowImportExportEverywhere option · Issue #‌6472 · eslint/eslint" ...
Read more >
acorn - npm
allowImportExportEverywhere : By default, import and export declarations can only appear at a program's top level. Setting this option to ...
Read more >
acorn - UNPKG
98 ; 99, - **allowImportExportEverywhere**: By default, `import` and `export` ; 100, declarations can only appear at a program's top level. Setting this...
Read more >
ACORN Investigation - James O'Keefe, Hannah Giles
Youtube description: "Undercover investigation featuring prostitution, sex trafficking, tax evasion, and money laundering. II-"ACORN Exposed" - Project Veritas ...
Read more >
acorn | Yarn - Package Manager
Setting this option to true allows them anywhere where a statement is allowed, and also allows import.meta expressions to appear in scripts (when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found