Template literal property names in object literals

Alex Kodat akodat at rocketsoftware.com
Thu Nov 7 20:14:12 UTC 2019


Jordan,

The sentiments in that link discuss the wisdom of having the StringLiteral definition include NoSubstitutionTemplate, a question about which I am agnostic, and wouldn't provide the full functionality I'm asking about, anyway.

And I also understand that the spec currently only allows computed property names in square brackets.

My suggestion was that ComputedPropertyName *could* be changed to include TemplateString (without square brackets). Whether this is worth doing or paints JS syntax into a corner is a fair question, but I don't see that adding TemplateString to ComputedPropertyName would create any syntactic ambiguities and wouldn't seem to present daunting implementation issues. But maybe this last assertion is incorrect and ambiguities would arise or implementation would be a nightmare?

Thanks

------
Alex Kodat
Senior Product Architect
Rocket Software
t: +1 781 684 2294 • m: +1 315 527 4764 • w: http://www.rocketsoftware.com/

From: Jordan Harband <ljharb at gmail.com>
Sent: Thursday, November 7, 2019 1:46 PM
To: Alex Kodat <akodat at rocketsoftware.com>
Cc: Gus Caplan <me at gus.host>; es-discuss at mozilla.org
Subject: Re: Template literal propery names in object literals

Anything dynamic - computed - should be in brackets, since that's what that indicates.

Thus, template literals with substitutions must require brackets.

Based on sentiments like https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftc39%2Fecma262%2Fissues%2F1399%23issuecomment-452910799&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527965990546&sdata=71bc85j8UPdAdkFjmprrximGsaySHt1o3r8zkV9ZYgQ%3D&reserved=0, either all template literals or none should be permitted in a given position.

Thus, no change is possible.

On Thu, Nov 7, 2019 at 10:00 AM Alex Kodat <mailto:akodat at rocketsoftware.com> wrote:
Thanks Gus,

Good stuff. Though I think I’d take a different tack on the discussion at that link, especially as I think the template literals should allow substitutions (why not?):

let obj = { `${Date()}`: 1};

I guess the tack I would take in the spec would be to add TemplateLiteral to ComputedPropertyName and not worry about whether or not it's a NoSubstitutionTemplate.

Thanks

------
Alex Kodat
Senior Product Architect
Rocket Software
t: +1 781 684 2294 • m: +1 315 527 4764 • w: https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com%2F&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527965990546&sdata=d62CHuayKkj8EhttWHK9kbMjnnkMGJgrrDbZRjtlul0%3D&reserved=0

From: Gus Caplan <mailto:me at gus.host>
Sent: Thursday, November 7, 2019 11:13 AM
To: Alex Kodat <mailto:akodat at rocketsoftware.com>
Cc: mailto:es-discuss at mozilla.org
Subject: Re: Template literal propery names in object literals

Related discussion https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftc39%2Fecma262%2Fissues%2F1399&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527965990546&sdata=8XRONc3vM6asxLzdeGYYKXaqkQ0ltiNzDgBD9en3X7s%3D&reserved=0

On Thu, Nov 7, 2019 at 8:46 AM Alex Kodat <mailto:mailto:akodat at rocketsoftware.com> wrote:
Just curious. Is there a reason template literals are not allowed as property names in object literals? I can do:

   let obj = {'foo bar': 1};

and

   let obj = {"foo bar": 1};

but not

   let obj = {`foo bar`: 1};

It doesn't seem that allowing the latter would present any syntactic problems and seems like almost an oversight that it's not allowed.

The main reason I ask is that we've gone completely over to using template literals for all our literals (why not?) and was surprised that we can't use a template literal as an object literal property name. Obviously, we can do:

   let obj = {[`foo bar`]: 1};

And given that square brackets allow arbitrary expressions for propery names, it wouldn't seem that supporting template literals for object literal property names would not present any daunting implementation issues.

I guess I'd argue that the Principle of Least Astonishment and/or completeness suggests that JS should support this.

Sorry if this has been asked before but couldn't find anything in the archive.

Thanks

------
Alex Kodat
Senior Product Architect
Rocket Software
t: +1 781 684 2294 • m: +1 315 527 4764 • w: https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966000541&sdata=ZKH85YD9HEKWNt0Gti1IYmywyMwa%2BbtGxSn41xKjt%2FE%3D&reserved=0

================================
Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA 02451 ■ Main Office Toll Free Number: +1 855.577.4323
Contact Customer Support: https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmy.rocketsoftware.com%2FRocketCommunity%2FRCEmailSupport&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966000541&sdata=o2jLB3Up2WN%2FLbYnNp5II%2BwR5MFBcm5%2Bl1ejZ%2Ft%2FJiI%3D&reserved=0
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com%2Fmanage-your-email-preferences&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966010535&sdata=SWWsXjtV0%2Fogzd9pHPHBLt57fuYbxdreIkYRFJ4Qgdc%3D&reserved=0
Privacy Policy - https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com%2Fcompany%2Flegal%2Fprivacy-policy&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966010535&sdata=GNQujvYIbGmSbJjpsalm9nb65wqEzHS2L4e2LZerQUc%3D&reserved=0
================================

This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you.
_______________________________________________
es-discuss mailing list
mailto:mailto:es-discuss at mozilla.org
https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966020527&sdata=T%2FFSvh2o9gGEbWVUZHtyX18izHUXatULcBiq%2FeP7m6c%3D&reserved=0
================================
Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA 02451 ■ Main Office Toll Free Number: +1 855.577.4323
Contact Customer Support: https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmy.rocketsoftware.com%2FRocketCommunity%2FRCEmailSupport&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966020527&sdata=r4sXoDpYXafc3E%2BCUQ2LPn6i4u9eNOBdrFROWg9%2FfJw%3D&reserved=0
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com%2Fmanage-your-email-preferences&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966030521&sdata=Sx4MoukMKC8LeIpmjZNe1dhdK0mGOtPtQJTEY99eMjY%3D&reserved=0
Privacy Policy - https://nam01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.rocketsoftware.com%2Fcompany%2Flegal%2Fprivacy-policy&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966030521&sdata=b4LeRM1oEW6gYOGbRK6IdZnZvXG95x9N26V5sLbjm1A%3D&reserved=0
================================

This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you.
_______________________________________________
es-discuss mailing list
mailto:es-discuss at mozilla.org
https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.mozilla.org%2Flistinfo%2Fes-discuss&data=02%7C01%7C%7Ca6f02ff84bd446c7593708d763bb3255%7C79544c1eed224879a082b67a9a672aae%7C0%7C0%7C637087527966040522&sdata=Q9GR4eG9CD8%2FTYAMEBctPZ37MXnsLPr0zYJgRFKqIO4%3D&reserved=0
================================
Rocket Software, Inc. and subsidiaries ■ 77 Fourth Avenue, Waltham MA 02451 ■ Main Office Toll Free Number: +1 855.577.4323
Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences
Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy
================================

This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you.


More information about the es-discuss mailing list