Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

WIP: No children prop #387

Merged
merged 9 commits into from
May 5, 2020
Merged

WIP: No children prop #387

merged 9 commits into from
May 5, 2020

Conversation

macovedj
Copy link
Contributor

@macovedj macovedj commented May 3, 2020

@macovedj macovedj force-pushed the no-children-prop branch from b68da4e to e5157cc Compare May 3, 2020 22:30
if (
(
node.type === 'JSXElement' &&
node.attributes.find(attribute => (attribute as JSXAttribute).name.name === 'children')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you hoist the closure to the top level?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also don't use as. We're losing type precision here for no reason and I suspect this will fail accessing an unknown property on JSXSpreadAttribute.

node.callee.property.value.type === 'Identifier' &&
node.callee.property.value.name === 'createElement' &&
node.arguments[1].type === 'ObjectExpression' &&
node.arguments[1].properties.find(property => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also hoist this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that you meant by these that you'd like me to define the functions at the top level, which I've done. Let me know if you meant something else?

))
)
) {
path.context.addNodeDiagnostic(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this fixable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you thinking we would just get rid of the children prop? We could do that. I worry a little bit that people would maybe prefer to just be told though, so that they don't have to add it again with a name other than "children". But if you still think it would be better to delete it, or had something else in mind, then I could do that.

@macovedj
Copy link
Contributor Author

macovedj commented May 4, 2020

When running tests, I'm being prompted to run scripts/dev-rome test packages/@romejs/js-parser/index.test.ts --update-snapshots which then updates two lines (column and index fields of an object) across 969 markdown files, and I already tried catching up with master to be rid of it. Should I just bring these updates in, or am I doing something wrong?

@macovedj macovedj requested a review from sebmck May 4, 2020 23:39
@Kelbie
Copy link
Contributor

Kelbie commented May 5, 2020

@macovedj I also got those when I created my PR but I just ommited them

@macovedj
Copy link
Contributor Author

macovedj commented May 5, 2020

@macovedj I also got those when I created my PR but I just ommited them

Neato. New problem though. When I try to update snapshots for the tests that I wrote, I get this error which I'm having difficulty parsing.

`✖ unimplemented

10 │ export default function JSXReferenceIdentifier(): Token {

11 │ throw new Error('unimplemented');
│ ^
12 │ }

  1. (packages/@romejs/js-compiler/lint/rules/react/noChildrenProp.test.ts:14:10)
  2. ___R$project$rome$$romejs$js$compiler$lint$rules$testHelpers_ts$testLintMultiple (
    packages/@romejs/js-compiler/lint/rules/testHelpers.ts:29:10)
  3. ___R$project$rome$$romejs$js$compiler$lint$rules$testHelpers_ts$testLint (
    packages/@romejs/js-compiler/lint/rules/testHelpers.ts:71:20)
  4. ___R$project$rome$$romejs$js$compiler$lint$index_ts$default (
    packages/@romejs/js-compiler/lint/index.ts:50:24)
  5. ___R$project$rome$$romejs$js$formatter$index_ts$formatJS (
    packages/@romejs/js-formatter/index.ts:41:24)
  6. ___R$project$rome$$romejs$js$formatter$Builder_ts$default.tokenize (
    packages/@romejs/js-formatter/Builder.ts:68:22)
  7. ___R$project$rome$$romejs$js$formatter$builders$core$Program_ts$default (
    packages/@romejs/js-formatter/builders/core/Program.ts:23:12)
  8. ___R$project$rome$$romejs$js$formatter$Builder_ts$default.tokenizeStatementList (
    packages/@romejs/js-formatter/Builder.ts:136:25)
  9. ___R$project$rome$$romejs$js$formatter$Builder_ts$default.tokenize (
    packages/@romejs/js-formatter/Builder.ts:68:22)
  10. ___R$project$rome$$romejs$js$formatter$builders$statements$ExpressionStatement_ts$default
    (packages/@romejs/js-formatter/builders/statements/ExpressionStatement.ts:16:25)
  11. ___R$project$rome$$romejs$js$formatter$Builder_ts$default.tokenize (
    packages/@romejs/js-formatter/Builder.ts:68:22)
  12. ___R$project$rome$$romejs$js$formatter$builders$jsx$JSXElement_ts$default (
    packages/@romejs/js-formatter/builders/jsx/JSXElement.ts:23:12)
  13. ___R$project$rome$$romejs$js$formatter$Builder_ts$default.tokenize (
    packages/@romejs/js-formatter/Builder.ts:68:22)
  14. ___R$project$rome$$romejs$js$formatter$builders$jsx$JSXReferenceIdentifier_ts$default (
    packages/@romejs/js-formatter/builders/jsx/JSXReferenceIdentifier.ts:11:8)

ℹ Lint options

Object {
  category: 'lint/noChildrenProp'
  sourceType: 'module'
  syntax: Array []
}

ℹ Input

<MyComponent children={'foo'}></MyComponent>

`

@sebmck
Copy link
Contributor

sebmck commented May 5, 2020

It means JSXReferenceIdentifier is missing a function to handle formatting, which is true. All that needs to be done is update packages/@romejs/js-formatter/builders/jsx/JSXReferenceIdentifier.ts#L11 to:

export default function JSXReferenceIdentifier(
  builder: Builder,
  node: JSXReferenceIdentifier,
): Token {
  return node.name;
}

Feel free to do that in this PR.

@sebmck
Copy link
Contributor

sebmck commented May 5, 2020

When running tests, I'm being prompted to run scripts/dev-rome test packages/@romejs/js-parser/index.test.ts --update-snapshots which then updates two lines (column and index fields of an object) across 969 markdown files, and I already tried catching up with master to be rid of it. Should I just bring these updates in, or am I doing something wrong?

I believe there's a bug in snapshots that's not causing failures to be emitted correctly. There was a PR that must have been merged that incorrectly allowed them. I pushed the updated snapshots to master earlier.

@macovedj macovedj force-pushed the no-children-prop branch from def6357 to 68639f5 Compare May 5, 2020 02:29
@sebmck sebmck merged commit bfeaaa2 into rome:master May 5, 2020
@sebmck
Copy link
Contributor

sebmck commented May 5, 2020

Looks good, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants