jsx-eslint/jsx-ast-utils

The prop value with an expression type of OptionalMemberExpression could not be resolved

HsuTing opened this issue · 8 comments

I use @babel/plugin-proposal-optional-chaining like this:

<div href={data?.href} />

I found only href will throw error. Other props will not throw error, like this:

<div test={data?.test} />
pdong commented

I am seeing this with .title as well

{data?.title} will error out with

The prop value with an expression type of OptionalMemberExpression could not be resolved.
  Please file issue to get this fixed immediately.
Error: The prop value with an expression type of OptionalMemberExpression could not be resolved.
  Please file issue to get this fixed immediately.
    at Object.extractLiteral [as JSXExpressionContainer] (/Users/pdong/node_modules/jsx-ast-utils/lib/values/expressions/index.js:202:11)
    at getLiteralValue (/Users/pdong/node_modules/jsx-ast-utils/lib/values/index.js:61:35)
    at extractValue (/Users/pdong/node_modules/jsx-ast-utils/lib/getPropValue.js:24:12)
    at getLiteralPropValue (/Users/pdong/node_modules/jsx-ast-utils/lib/getPropValue.js:56:10)
    at JSXAttribute (/Users/pdong/node_modules/eslint-plugin-jsx-a11y/lib/rules/aria-proptypes.js:88:58)
    at listeners.(anonymous function).forEach.listener (/Users/pdong/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/pdong/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (/Users/pdong/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/Users/pdong/node_modules/eslint/lib/util/node-event-generator.js:280:22)

but if I change it it works. 🤔

Wondering if this is broken for all valid html attrs maybe 🤷‍♂️

Working on it now. I need to update all the dev dependencies to get there :)

@HsuTing , Fixed in version v2.2.1. This will log an error in the console, but it will no longer throw.

@jessebeach OK, thank for your help.

Could we not get this error? The message comes from here, following the issue trail from eslint.

If there is an error/bug, it should get fixed, if it's a false report, I don't want to see it.

@MathiasKandelborg I understand the frustration here. I feel it, too. I hate seeing these bugs pop up. I'll look into it this weekend and put out a patch release.

note that v3.0 of jsx-ast-utils is out, and eslint-plugin-jsx-a11y has been updated with it, but not yet released - so a patch release here would still need a release in eslint-plugin-jsx-a11y.

It's also possible this is already fixed in v3.0.

Pretty sure this is fixed by #77. eslint-pliugin-react has already been updated with it, and eslint-plugin-jsx-a11y will get it on the next release.