Skip to content

Closes #9 #10

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

Closed
wants to merge 7 commits into from
Closed

Closes #9 #10

wants to merge 7 commits into from

Conversation

peterbabic
Copy link
Contributor

This PR fixes #9

It is not a bug fix, but rather a code quality improvement. It's purpose is to stop JS bundler complaining about the detected circular dependency.

It does not include any new tests, because it would require testing for circular dependency, not sure what the right approach would be right now. The issue thread shows dependency graphs and a clear resolve of the cyclic dependency that existed before PR.

Note that possible state (context) pollution introduced by passing any down the road from the index.js

@peterbabic peterbabic marked this pull request as ready for review December 14, 2020 20:24
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

thanks for taking a stab at this!

peterbabic and others added 2 commits December 14, 2020 21:35
Co-authored-by: Titus <tituswormer@gmail.com>
Co-authored-by: Titus <tituswormer@gmail.com>
@peterbabic peterbabic requested a review from wooorm December 14, 2020 20:45
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

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

The recursiveness seems to only be needed in matches (x:matches(:link)) and hasSelector (x:has(:link)). I’m assuming those two aren’t tested with pseudos in the select or selectAll cases


var is = convert()

match.needsIndex = [
Copy link
Member

Choose a reason for hiding this comment

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

this change can be reverted

@@ -75,7 +88,7 @@ function configure(query, state) {
var index = -1

while (++index < pseudos.length) {
if (pseudo.needsIndex.indexOf(pseudos[index].name) > -1) {
if (needsIndex.indexOf(pseudos[index].name) > -1) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (needsIndex.indexOf(pseudos[index].name) > -1) {
if (pseudo.needsIndex.indexOf(pseudos[index].name) > -1) {

this change can be reverted

var zwitch = require('zwitch')
var pseudo = require('./pseudo')
Copy link
Member

Choose a reason for hiding this comment

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

this change can be reverted

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 am getting quite lost here :sad:

What could be reverted, please?

Copy link
Member

Choose a reason for hiding this comment

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

We were discussing two approaches.

  1. place needsIndex in any, remove it from pseudo, which doesn’t work.
  2. Pass any down

As 1 didn’t work, it can be reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pardon me, but I am not seeing why it doesn't work. Could you please point me to the right direction?

Copy link
Member

Choose a reason for hiding this comment

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

You said here in the issue that changing needsIndex had no effect

Copy link
Contributor Author

@peterbabic peterbabic Dec 15, 2020

Choose a reason for hiding this comment

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

I have made another commit 89f8735 which I believe places needsIndex into even better place, by still not tripping any tests and with the circular dependency resolved.

If there is need to revert something, it has to be by your reasoning as a reviewer, otherwise I suspect I wasn't clear somewhere in the issue and your interpretation of what I have stated is different from what I have meant.

Please, provide way of moving this PR further, discarding the "this change could be reverted" suggestions in the process, if possible.

Copy link
Contributor Author

@peterbabic peterbabic Dec 15, 2020

Choose a reason for hiding this comment

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

Also, I might start getting what do you mean. To make things clear further, BOTH "approaches" need to be applied, not just the second one (with reverting the first one) to remove the cyclic dependency.

It is true that I said the first one does not work, meaning it reduced the dependency from direct (A -> B -> A) to indirect (A -> B -> C -> A, indirect cyclic dependencies tend to be easier to resolve) which was then resolved by the approach 2.

lib/any.js Outdated
Comment on lines 5 to 17
var needsIndex = [
'first-child',
'first-of-type',
'last-child',
'last-of-type',
'nth-child',
'nth-last-child',
'nth-of-type',
'nth-last-of-type',
'only-child',
'only-of-type'
]

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var needsIndex = [
'first-child',
'first-of-type',
'last-child',
'last-of-type',
'nth-child',
'nth-last-child',
'nth-of-type',
'nth-last-of-type',
'only-child',
'only-of-type'
]

this change can be reverted

Configure function is the sole consumer of the needsIndex array, it
shoould then be in it's local scope. This change further improves code
quiality.
@wooorm
Copy link
Member

wooorm commented Dec 15, 2020

I don’t see why the changes previously applied for approach 1 are needed. Moving any to something that is passed around removes the recursive dep.

Could you make the changes in this PR as small as possible? Only the change that any is passed around, not the needsIndex changes.

And could you pass any: any in index.js to the two other functions too?

@peterbabic
Copy link
Contributor Author

Or in even different words, there are TWO cyclic dependencies to begin with, the first approach removes the direct one (yellow), the second approach removes the indirect one (red)

2020-12-15_11-50

@wooorm
Copy link
Member

wooorm commented Dec 15, 2020

By passing any down to all files, that is removed though?

@wooorm
Copy link
Member

wooorm commented Dec 15, 2020

Hold on, let me try and do it myself. I’m sorry that I can’t seem to make my suggestion clear.

@peterbabic
Copy link
Contributor Author

I am sorry, you are right. Just by applying the approach 2 the cyclic dependency is resolved.

However by passing any: any into contextx into select and selectAll does not seem to affect anything

@wooorm
Copy link
Member

wooorm commented Dec 15, 2020

I described select and selectAll here: #10 (comment)

@peterbabic
Copy link
Contributor Author

Well, to my best efforts:

  • Approach 2, minimal code needed for tests passing and cyclic dependency removed
    peterbabic@375cdfe

  • Approach 2 + passing any also into select and selectAll, not just into matches
    peterbabic@e455227

These two could be squashed if needed, but TBH I am not quite there yet about the #10 (comment)

@wooorm
Copy link
Member

wooorm commented Dec 15, 2020

I’m already working on that approach, thanks, will push soon (but install graphviz for marge broke my computer 🥺)

@wooorm wooorm closed this in 5da284c Dec 15, 2020
@wooorm wooorm added ⛵️ status/released 🏡 area/internal This affects the hidden internals 👶 semver/patch This is a backwards-compatible fix 🦋 type/enhancement This is great to have labels Dec 15, 2020
@wooorm wooorm added the 💪 phase/solved Post is done label Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏡 area/internal This affects the hidden internals 💪 phase/solved Post is done 👶 semver/patch This is a backwards-compatible fix 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

Circular dependency any.js -> pseudo.js -> any.js using rollup
2 participants