Tools: Linter warns on the dynamic import operator

Created on 27 Jun 2017  ·  5Comments  ·  Source: Polymer/tools

We have a setup where we pull our project though Babel's stage 2 preset, which amongst other things allows for dynamically loading html via JS (see screenshot). However, at the moment this causes polymer lint to error with error [parse-error] - 'import' and 'export' may only appear at the top level. Since it's a parse error, we can't disable this rule in our polymer.json file. Would it be possible to allow for this syntax or disable this error?

image

linter High Available Bug wontfix

Most helpful comment

This is a polymer-analyzer issue. The problem is that Espree, the JavaScript parser polymer-analyzer uses, doesn't support dynamic imports and has no plans to support them until they're part of the ECMAScript standard. (From the Espree README: “In general, we do not support experimental JavaScript features. We may make exceptions from time to time depending on the maturity of the features.”)

As far as I can tell the only solution would be for polymer-analyzer to switch to a different parser like Acorn (which has a plugin for dynamic imports) or Esprima. I don't know how likely that is to happen, but you should definitely file a polymer-analyzer issue so they know there's demand for it.

All 5 comments

You can use System.import to get around it - if that helps.

This is a polymer-analyzer issue. The problem is that Espree, the JavaScript parser polymer-analyzer uses, doesn't support dynamic imports and has no plans to support them until they're part of the ECMAScript standard. (From the Espree README: “In general, we do not support experimental JavaScript features. We may make exceptions from time to time depending on the maturity of the features.”)

As far as I can tell the only solution would be for polymer-analyzer to switch to a different parser like Acorn (which has a plugin for dynamic imports) or Esprima. I don't know how likely that is to happen, but you should definitely file a polymer-analyzer issue so they know there's demand for it.

We have added support for this in the upcoming polymer-analyzer 3.0.0 branch. Coming soon.

This is a case where our existing behavior is in error. I'd call that a bug.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings