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

improve merging of resolve and parsing options #9126

Merged
merged 1 commit into from May 13, 2019
Merged

Conversation

sokra
Copy link
Member

@sokra sokra commented May 13, 2019

improve merging of resolve and parsing options
by rules and via loader API

Objects are deeply merged
Arrays overwrite by default, but can reference old value with "..."

fixes #8968

What kind of change does this PR introduce?
feature, maybe bugfix

Did you add tests for your changes?
yes

Does this PR introduce a breaking change?
yes

What needs to be documented once your changes are merged?
Rule.resolve/Rule.parser objects are now deeply merged.
In array the special "..." item can now be used to reference to old value, while otherwise array values overwrite each other.
This also affects the getResolve(options) API in the loader API

by rules and via loader API

Objects are deeply merged
Arrays overwrite by default, but can reference old value with "..."

fixes #8968
@webpack-bot
Copy link
Contributor

webpack-bot commented May 13, 2019

For maintainers only:

  • This need to be documented (issue in webpack/webpack.js.org will be filed when merged)

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@webpack-bot
Copy link
Contributor

I've created an issue to document this in webpack/webpack.js.org.

newObject[key] = second[key];
continue;
}
const secondValue = second[key];
Copy link

Choose a reason for hiding this comment

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

This assignment should be before the if statement above. Then replace second[key] in the body of the if with secondValue.

Copy link
Member

Choose a reason for hiding this comment

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

Can you open issue and describe problem?

Copy link

@deAtog deAtog left a comment

Choose a reason for hiding this comment

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

This code is difficult to follow and somewhat inefficient. Please address the issues identified below.

}
const secondValue = second[key];
if (typeof secondValue !== "object" || secondValue === null) {
newObject[key] = secondValue;
Copy link

Choose a reason for hiding this comment

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

There should probably be continue here. If secondValue is not an object or null, then it will not be an Array and firstValue will equal secondValue in the else portion of the if below resulting in reassignment of newObject[key] to secondValue. The assignment of newObject[key] = secondValue currently occurs 4 times in this code. A cleaner approach might be to either introduce a variable called newValue which is initially set to secondValue, modified if needed, and then newObject[key] assigned to newValue at the end of the loop, OR negate the above if statement, wrap it around the one below, move this assignment to the end of the loop and add a continue after all other places where newObject[key] is set.

newObject[key] = secondValue;
}
if (Array.isArray(secondValue)) {
const firstValue = newObject[key];
Copy link

Choose a reason for hiding this comment

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

This line is duplicated in the else portion of this if statement. The firstValue variable should thus be declared before the if statement.

}
newObject[key] = newArray;
} else {
newObject[key] = secondValue;
Copy link

Choose a reason for hiding this comment

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

See above comment above.

) {
newObject[key] = cleverMerge(firstValue, secondValue);
} else {
newObject[key] = secondValue;
Copy link

Choose a reason for hiding this comment

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

See comment above.

@alexander-akait
Copy link
Member

@deAtog please don't write in merged PRs/closed issues, it is hard to track because we have many issues/PRs in many repos, so it can be wasted, better open issue and describe problem, thanks

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.

None yet

4 participants