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

TypeError when parsing template literal in dynamic import #12750

Closed
mikecbrant opened this issue Jan 6, 2020 · 2 comments
Closed

TypeError when parsing template literal in dynamic import #12750

mikecbrant opened this issue Jan 6, 2020 · 2 comments
Labels
3rd party plugin This is an issue related to a 3rd party plugin, config, or parser archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue

Comments

@mikecbrant
Copy link

Tell us about your environment

  • ESLint Version: 6.8.0
  • Node Version: 13.3.0
  • npm Version: 6.13.4

What parser (default, Babel-ESLint, etc.) are you using?

babel-eslint

Please show your full configuration:

.eslintrc.yml:

env:
  es2020: true
  browser: true
extends:
  - eslint:recommended
  - plugin:import/errors
  - plugin:import/warnings
  - plugin:security/recommended
  - plugin:react/recommended
parser: babel-eslint
parserOptions:
  ecmaVersion: 2020
  sourceType: module
  ecmaFeatures:
    impliedStrict: true
    jsx: true
plugins:
  - import
  - react
  - security
rules:
  indent:
    - error
    - 2
    - SwitchCase: 1
  linebreak-style:
    - error
    - unix
  quotes:
    - error
    - single
    - avoidEscape: true
  semi:
    - error
    - always
  # this rule is currently causing some false positives https://github.com/eslint/eslint/issues/11899
  # so we want to downgrade to warn so developer can take a look and fix if needed
  # if issue is fixed, we can remove this config
  require-atomic-updates: warn
  security/detect-eval-with-expression: error
  # this rule can flag cases where bracket notation access of objects is totally fine (i.e. no user input)
  # so we are downgrading this to a warn
  security/detect-object-injection: warn
settings:
  react:
    version: latest

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

It seems that use of a template literal within a dynamic import is causing a TypeError to be thrown at parse time.

   // ... pertinent section of code below
    
    const promises = [
      import('intl-pluralrules'),
      import('@formatjs/intl-relativetimeformat/polyfill')
    ];
    supportedLocales.forEach(locale => {
      // the following line is causing parsing failure
      promises.push(import(`@formatjs/intl-relativetimeformat/dist/locale-data/${locale}`));
    });

    await Promise.all(promises);

It is run via a gulp-like task scheduler using gulp-eslint, so usage is in module context.

What did you expect to happen?

The template should parse correctly.

What actually happened? Please include the actual, raw output from ESLint.

TypeError is thrown when parsing module containing code sample above. Details shown below.

C:\...\node_modules\eslint\lib\rules\indent.js:340
        return this.setDesiredOffsets(token.range, fromToken, offset);
                                            ^
TypeError: Cannot read property 'range' of null
Occurred while linting C:\...\src\<omitted>.mjs:1
    at OffsetStorage.setDesiredOffset (C:\...\node_modules\eslint\lib\rules\indent.js:340:45)
    at C:\...\node_modules\eslint\lib\rules\indent.js:1358:29
    at Array.forEach (<anonymous>)
    at Object.TemplateLiteral [as listener] (C:\...\node_modules\eslint\lib\rules\indent.js:1350:34)
    at C:\.\node_modules\eslint\lib\rules\indent.js:1596:55
    at Array.forEach (<anonymous>)
    at Program:exit (C:\...\eslint\lib\rules\indent.js:1596:26)
    at C:\...\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (C:\...\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
npm ERR! Test failed.  See above for more details.

Are you willing to submit a pull request to fix this bug?

Potentially, if this issue ever becomes urgent for some reason. Workaround is simple enough, simply fall back to more traditional string concatenation. :)

@mikecbrant mikecbrant added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jan 6, 2020
@kaicataldo
Copy link
Member

I believe this is an issue in babel-eslint (which should eventually be fixed by babel/babel#10828). The default parser works fine with the indent rule (see demo here).

@kaicataldo kaicataldo added 3rd party plugin This is an issue related to a 3rd party plugin, config, or parser and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jan 6, 2020
@eslint-deprecated eslint-deprecated bot added the auto closed The bot closed this issue label Feb 6, 2020
@eslint-deprecated
Copy link

Unfortunately, it looks like there wasn't enough interest from the team
or community to implement this change. While we wish we'd be able to
accommodate everyone's requests, we do need to prioritize. We've found
that issues failing to reach accepted status after 21 days tend to
never be accepted, and as such, we close those issues.
This doesn't mean the idea isn't interesting or useful, just that it's
not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 6, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Aug 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3rd party plugin This is an issue related to a 3rd party plugin, config, or parser archived due to age This issue has been archived; please open a new issue for any further discussion auto closed The bot closed this issue
Projects
None yet
Development

No branches or pull requests

2 participants