Repository navigation
match JSX attributes whose value is an expression in hasAttributes - #755
Open
aashish254 wants to merge 2 commits into
Open
aashish254 wants to merge 2 commits into
aashish254 wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: ad3f3a4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@aashish254 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hasAttributescould not match any attribute written as an expression. Given:every one of these filters returns an empty collection:
Measured on
mainwith the default (babel) parser, and again withflow,tsxandbabylon: all four return 0 for all four filters. The same probe on this branch returns 1 for all sixteen of them.Why. The filter unwrapped a literal only when the value node itself was a literal (
attr="foo"). Forattr={...}the value is aJSXExpressionContainer, soactualbecame the expression node and the comparisonString(expected) === actualcompared a string to an object. It could therefore never be true, and callback filters were handed an AST node where the docstring for the value-less case (baz: v => v === null, added in #277) says they receive a value.What changed
getAttributeValue()unwraps a literal that sits inside aJSXExpressionContainer, using the sameLiteral.checkthe filter already used.attr={true}now yieldstrue,attr={'x'}yields'x',attr="x"is unchanged, a value-lessattris stillnull, and a computedattr={foo()}still yields the expression node.{b: 1}matchesb={1}the way{name: 'foo'}has always matchedname="foo". Attributes that carry no comparable value (null, or a non-literal expression) still never match, exactly as before — theswitchontypeof actualmakes that explicit instead of relying on a string never equaling an object.hasAttributesnow states what the filter accepts. There is nohasAttributespage in the website docs to update.Verification
src/collections/__tests__/JSXElement-test.js, in a describe block with its own fixture so no existing counts move. 4 of them fail onmain(boolean/number values, string in a container, string comparison, callback receives the value); the other 2 are regression guards that pass on both, for the value-less and computed cases and for plainattr="foo".matches boolean and number values,compares the filter to the value as strings).yarn --frozen-lockfile && yarn test— the exact CI commands: 19 suites, 227 passed, 1 pre-existing skip, 11 snapshots pass.yarn.lockuntouched..eslintrcrules (quotes: single,eslint:recommended) reports nothing on both files. It needsrequireConfigFile: falseto run at all — as shipped,eslintfails to parse every file insrc/on a clean checkout, mine included, so it isn't a signal I introduced.