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

Support ChainExpression AST node type for optional chaining #103

Closed
junoatwork opened this issue Oct 5, 2020 · 1 comment · Fixed by #102
Closed

Support ChainExpression AST node type for optional chaining #103

junoatwork opened this issue Oct 5, 2020 · 1 comment · Fixed by #102

Comments

@junoatwork
Copy link

Symptom:

Began seeing The prop value with an expression type of ChainExpression could not be resolved. Please file issue to get this fixed immediately. in eslint output after upgrading.

ECMAscript Optional Chaining shipped, resulting in various changes to parsers and javascript/typescript tools to support it. Initially there were different, non-standard names for the AST nodes to represent it. Over this year, consensus has settled out, including in the parser that eslint uses, estree (see estree/estree#204 ).

jsx-ast-utils should be updated to support the new AST nodes.

Versions:

eslint@7.10.0
jsx-ast-utils@2.4.1 (via eslint-plugin-react@7.21.3, eslint-plugin-jsx-a11y@6.3.1)

Minimal test case

Component.jsx

import React from 'react';

export function Component() {
  const x = {};
  return (
    <div role="button" key={x.y?.z}>
      hi
    </div>
  );
}

.eslintrc

module.exports = {
  extends: [
    'plugin:react/recommended',
    'plugin:jsx-a11y/recommended'
  ],
  plugins: ['react', 'jsx-a11y'],
}

run

eslint ./Component.jsx

Related:

Example AST (via console.log):

{
  type: 'JSXExpressionContainer',
  expression: {
    type: 'ChainExpression',
    expression: {
      type: 'MemberExpression',
      object: [Object],
      property: [Object],
      computed: false,
      optional: true,
      range: [Array],
      loc: [Object],
      parent: [Circular]
    },
    range: [ 6299, 6313 ],
    loc: { start: [Object], end: [Object] },
    parent: [Circular]
  },
  range: [ 6298, 6314 ],
  loc: { start: { line: 205, column: 29 }, end: { line: 205, column: 45 } },
  parent: {
    type: 'JSXAttribute',
    name: {
      type: 'JSXIdentifier',
      name: 'href',
      range: [Array],
      loc: [Object],
      parent: [Circular]
    },
    value: [Circular],
    range: [ 6293, 6314 ],
    loc: { start: [Object], end: [Object] },
    parent: {
      type: 'JSXOpeningElement',
      typeParameters: undefined,
      selfClosing: false,
      name: [Object],
      attributes: [Array],
      range: [Array],
      loc: [Object],
      parent: [Object]
    }
  }
}
@ljharb
Copy link
Member

ljharb commented Oct 5, 2020

See #102.

zburke added a commit to folio-org/ui-data-import that referenced this issue Oct 11, 2020
Due to a [bug in
jsx-exlint](jsx-eslint/jsx-ast-utils#103), the
changed line causes ESLint to die. The bug [has been fixed](jsx-eslint/jsx-ast-utils#102) but hasn't made it's way into a release yet, and it would be really nice to have lint working again!

Refs UIDATIMP-690
zburke added a commit to folio-org/ui-data-import that referenced this issue Oct 12, 2020
Due to a [bug in jsx-exlint](jsx-eslint/jsx-ast-utils#103), 
the changed line causes ESLint to die. The bug [has been fixed](jsx-eslint/jsx-ast-utils#102) 
but hasn't made its way into a release yet, and it would be really nice to
have lint working again!

Refs UIDATIMP-690
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants