-
Notifications
You must be signed in to change notification settings - Fork 399
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
feat(babel-plugin-compiler): observe string, number, and identifier bracketed fields #4548
Conversation
packages/@lwc/integration-karma/test/component/observed-fields/index.spec.js
Outdated
Show resolved
Hide resolved
I removed the observing of template literal computed fields, so this could be ready to merge if everything else is right. |
One thing that might be missing here is booleans [true] [false]. No idea why anyone would do that, but it could be included for the sake of completion and consistency. |
Thanks a lot for this PR! A few quick comments:
@ekashida @jye-sf @wjhsf What do you think about supporting numbers? |
Any string, numeric, or symbol is a valid property key. If we support strings as property keys (computed and non-computed), then we should also support numeric literals. I don't think we need to support boolean (and regex and null) literals in computed properties until somebody complains that they actually want to do that. |
The argument against numbers from my POV is mostly just that it "feels" weird, since it's typically only used in collections (e.g. arrays/HTMLCollections), and I can't imagine why you'd want to use that in an LWC component. I could also potentially see some issues if we have a reactive property like
|
Do we currently have handling for duplicate string/identifiers? |
It looks like for I guess maybe this is fine because there's no difference in JavaScript between string keys and number keys in plain objects. I'm just wondering whether we really need to support this at the top-level in components. Even if you want your key to be |
I thought about this PR a bit more. It occurred to me that we still don't support decorators ( I feel like it might make more sense to just document this as a limitation of the framework, and then focus on fixing it once browsers have native support for decorators. At that point, it would be easy to support these decorators at the syntax level (since we wouldn't need our own Babel plugin), and we could potentially get rid of |
I'm closing this one for now then @nolanlawson . Feel free to reopen if things change. |
Details
Adds support for observing simple string and number bracketed fields (eg: ['with spaces'] and [1337]), as well as identifiers (eg: [symbol]). Support for non-computed numbers and strings is also included eg 1337 and 'with spaces'
String and number literals are very straightforward. Bracketed identifiers (to support symbol) deserve a deeper look.
Support for booleans [true] [false] is not included since it wasn't in the original issue, but it could be desirable for completeness and consistency, although it's hard for me to see why one would do that.
Closes #4547
Does this pull request introduce a breaking change?
It can be a breaking change if a bracketed identifier, string or number property is expected to not be observable, but I doubt anyone would be relying on this behavior, especially since most linters will warn/error about it.
Does this pull request introduce an observable change?
Simple bracketed identifier, strings and number properties will now be observed.
GUS work item