Jshint: Add support for dynamic imports

Created on 30 Mar 2020  ·  5Comments  ·  Source: jshint/jshint

Using Visual Studio Code 1.43.2

Extension: "dbaeumer.jshint" using global installation of jshint from npm

JSHint Installed: 2.11.0@npm

Expected Behaviour: Recognize import() as a function.

Actual Behaviour

JSHint doesn't recognize

import("module/path.mjs") //Returns Promise of export object

as a function and throws E053 and E021.

This function is used in importing modules for scripts doesn't end with ".mjs".
More info about can be seen in this MDN page.

I don't know if this function is in proposals, it just works in major browsers (Firefox,Chrome, etc.) and node.js.


Config Values


Not using .jshintrc file, using a global extension setting.

{
"jshint.lintHTML": true,
    "jshint.options": {
        "esversion": 9,
        "varstmt": true,
        "unused": true,
        "undef": true,
        "singleGroups": true,
        "eqeqeq": true,
        "freeze": true,
        "lastsemic": true,
        "leanswitch": true,
        "latedef": true,
        "maxdepth": 4,
        "noreturnawait": true,
        "nonbsp": true,
        "noarg": true,
        "maxparams": 3,
        "maxerr": 10,
        "maxcomplexity": 15,
        "node": true
    }
}
Proposal

Most helpful comment

Thanks for the report! We haven't implemented support for dynamic imports, but we plan to (it definitely satisfies our policy on new language features). That makes this more of a feature request than a bug report, so I've modified the issue's title a bit--hope you don't mind.

If you (or anyone else) would like to try implementing this, then I'd gladly give guidance!

All 5 comments

Thanks for the report! We haven't implemented support for dynamic imports, but we plan to (it definitely satisfies our policy on new language features). That makes this more of a feature request than a bug report, so I've modified the issue's title a bit--hope you don't mind.

If you (or anyone else) would like to try implementing this, then I'd gladly give guidance!

@jugglinmike Considering this is an es2020 proposal, how would you envision somone be able to toggle this feature? I'm assuming there would be an esversion: 11 which I assume would require all of the other es2020 proposals (nullish coalescing, optional chaining, etc...) to be supported as well.

I may look into implementing support for this specific proposal as it would help up quite a bit.

esversion: 11 sounds about right to me, @almercier! Implementing all of the new language features is a big undertaking, and I wouldn't expect anyone to take all of that on by themselves. If you wanted to focus on the import expression, then we could tackle the other features in parallel (or publish a release with partial support for the new language edition).

I've updated our submodule for Test262 so that we have better coverage for the new language features. I've also created a tracking branch for a new minor release; that's where we should land new features.

JSHint version 2.13.0, released today, includes support for dynamic imports. Be sure to update your configuration to opt in to the new language feature via esversion: 11 or later.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jugglinmike picture jugglinmike  ·  6Comments

NemoStein picture NemoStein  ·  7Comments

timdown picture timdown  ·  7Comments

Daniel-Hug picture Daniel-Hug  ·  3Comments

damyanpetev picture damyanpetev  ·  4Comments