-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Correctly handle commas in CP property keys #13231
Conversation
current[index] = part; | ||
all.push(current); | ||
}); | ||
parts.forEach((part) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map? Or should this be unrolled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it should be a straight for loop here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point about the map, @stefanpenner.
Since there's an overall desire to reduce function calls, I'll rewrite this as a straight for loop.
I was under the impression that we did not intend to support nested brace expansion, so I'm not sure if we should add that. @stefanpenner/@krisselden - Thoughts? I'm also somewhat curious to see if we have made this better or worse performance wise, would it be possible to make a small benchmark before and after? |
@rwjblue I did not remember if we talked about the nesting in person or, if we did, what the conclusion was, and I didn't get a response about it over on #13217. It's possible to remove the second commit, which is the one that introduces nested handling, without affecting comma handling. I'll put together a benchmark to compare before/comma/nested. |
Awesome, that would be great, thank you. |
@nickiaconis - Any updates here? |
Here are the results of the benchmarking. The code used to run the benchmark is also included in the gist. Since the "comma" and "nested" versions were so much slower than the "before" version, I wrote a few other implementations. The "iteration" version is a little slower than the "before" version, but I think it's close enough to be acceptable. |
Thanks for putting in the time on that benchmark! The iteration version looks good to me (implementation and perf wise). @krisselden - What do you think? |
On April 12, @krisselden mentioned he was reviewing my benchmarks by trying them in a browser:
I wonder at what conclusion he arrived. |
☔ The latest upstream changes (presumably #13658) made this pull request unmergeable. Please resolve the merge conflicts. |
I am nervous about supporting this feature at all, Is it really common for people to valid properties with |
@stefanpenner I don't know if it's common, but it can definitely happen, especially when the property names are generated dynamically. For example, the place where I bumped into this was Erik's app-cache-demo from EmberConf 2016. The (static) data is set in the application route, and it has a model whose ID contains a comma. Later, that ID is used to create a computed property. Of course, this doesn't work because of the bug this PR aims to fix, hence the need to remove all commas from IDs in the component. |
The perf improvement in the iteration fix variant is very nice. I appreciate the due diligence here. We (the ember core team) needs to decide if this is something we intend to support or not. As demonstrated it doesn't appear to make the status quo worse. The only technical concern I can think of is, can we make the status quo better, and would enabling this feature prevent that? @tomdale would love your guidance here. |
let part = parts[i]; | ||
if (part.indexOf(',') >= 0) { | ||
properties = duplicateAndReplace(properties, part.split(','), i); | ||
// Iterating backward over the pattern makes dealing with indeces easier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: s/indeces/indices/
This seems like a great improvement to me. While it's easy to consider the previous My only comment is that I wouldn't mind having a few more tests to verify correct behavior in other, weird cases like nested (And let me just say, @nickiaconis, I am very impressed that you implemented a stateful mini-parser here instead of trying to gin up an overly complicated regular expression, which seems like what most people try to do in these scenarios.) |
Thanks for the review, @tomdale! Upstream changes have added tests for nested Speaking of upstream changes, an assertion to catch unbalanced and nested braces was added, which involves iterating over The performance of P.S. What's the rational behind the no-const-outside-module-scope ESLint rule? |
See "liberal let" in http://madhatted.com/2016/1/25/let-it-be. |
Thanks for the info @rwjblue! I'm of the "constantly const" opinion as articulated in https://ponyfoo.com/articles/var-let-const, but it's good to read a differing opinion. |
☔ The latest upstream changes (presumably #14830) made this pull request unmergeable. Please resolve the merge conflicts. |
Roll unbalanced and nested brace assertion into mini-parser iteration
f55afed
to
14edb5c
Compare
@rwjblue I've rebased and resolved merge conflicts, so this is ready for review and/or merge. |
LETS DO IT! |
There was a bug in the brace expansion implementation before 2.13 that admitted expressions like `a.{b,c` and `a.b,c` in property expansion without failing. On February 2017, emberjs#13231 was merged improving the implementation of `expandProperties` and fixing the previous issue. Sadly, people upgrading from 2.12 are having problems with this. We have two options here: - Backporting emberjs#13231 fixes it and can be done, as of today, without any problem just by cherry-picking its two commits. Sadly, this would break people apps in a patch version, and this bug does not seem like a critical bugfix. - Adding a warning if a user is using invalid properties. I went with this option since it looks like the less intrusive one while letting the users know that their apps will break in the next update.
There was a bug in the brace expansion implementation before 2.13 that admitted expressions like `a.{b,c` and `a.b,c` in property expansion without failing. On February 2017, emberjs#13231 was merged improving the implementation of `expandProperties` and fixing the previous issue. Sadly, people upgrading from 2.12 are having problems with this. We have two options here: - Backporting emberjs#13231 fixes it and can be done, as of today, without any problem just by cherry-picking its two commits. Sadly, this would break people apps in a patch version, and this bug does not seem like a critical bugfix. - Adding a warning if a user is using invalid properties. I went with this option since it looks like the less intrusive one while letting the users know that their apps will break in the next update.
This addresses the issue of splitting on all commas in dependency key names, which prompted the opening of #13217.
Currently:
With this PR applied:
Edited to remove reference of nested brace expansion, since we don't intend to support it.