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

hasAttributes filter method supports attributes with omitted boolean values #277

Merged
merged 1 commit into from
Dec 3, 2018
Merged

hasAttributes filter method supports attributes with omitted boolean values #277

merged 1 commit into from
Dec 3, 2018

Conversation

artemruts
Copy link
Contributor

@artemruts artemruts commented Oct 10, 2018

This solves an issue when JSXElement's hasAttribute filter method can't find attributes where boolean value (true) was omitted.

E.g., given this jsx:

<FooBar baz />

If I try to do something like this:

const jsx = Collection.fromNodes(/* jsx nodes */)
  .findJSXElements()
  .filter(
    JSXElementCollection.filters.hasAttributes({
      baz: v => v === null
    })
  );

JSXElement will throw an error TypeError: Cannot read property 'expression' of null since there is no value.

const actual = Literal.check(value) ? value.value : value.expression;

balylon7 AST for above jsx code looks like this:

{
  "type": "JSXAttribute",
  "start": 8,
  "end": 11,
  "loc": {
   /* ... */
  },
  "name": {
    "type": "JSXIdentifier",
     /* ... */
    },
    "name": "baz"
  },
  "value": null
}

I also ran npm run docs since I modified a few files, this produced lots of doc updates 😨
Main changes are in JSXElement.js and JSXElement-test.js files.

@artemruts
Copy link
Contributor Author

@fkling Felix, I know you're busy but can I please get any feedback on this or is there someone who can review this PR?

Thanks.

@fkling fkling merged commit 1fc7a7a into facebook:master Dec 3, 2018
@artemruts artemruts deleted the jsx-support-omitted-boolean-attributes branch December 5, 2018 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants