Coder Social home page Coder Social logo

Comments (16)

bakkot avatar bakkot commented on June 20, 2024 2

That was not why we relaxed that restriction. It was explicitly because the restriction caused difficulty for implementations and did not obviously benefit anyone. The same is true here.

Also, that is definitely not a reasonable thing to want to do, at least not with the semantics it has. (The var e declares a variable in the outer function scope, but the loop assigns to the e created by the catch binding.)

from proposal-logical-assignment.

jridgewell avatar jridgewell commented on June 20, 2024 1

can someone confirm if var a = 1; (a) &&= 4; a; is also valid?

It is, and this is covered by the AssignmentTargetType static error in https://tc39.es/proposal-logical-assignment/#sec-assignment-operators-static-semantics-early-errors. The AssignmentTargetType of the (a) in (a) &&= 4 is simple, due to:

If so, it seems like perhaps we don't want to add more parenthesized LHS's to the language?

It'd actually take considerably more work to change this behavior, we'd have to plumb an entirely new AssignmentTargetType through the spec.


could we call this out in a Section 1 note, so it's understood that we don't mean to merge it that way?

Sure.

from proposal-logical-assignment.

ljharb avatar ljharb commented on June 20, 2024

var a = 1; (a) += 4; a; is valid; can someone confirm if var a = 1; (a) &&= 4; a; is also valid? If so, it seems like perhaps we don't want to add more parenthesized LHS's to the language?

from proposal-logical-assignment.

rkirsling avatar rkirsling commented on June 20, 2024

You explained in #15 (comment) that LogicalAssignmentPunctuator is just for viewability within the proposal, but could we call this out in a Section 1 note, so it's understood that we don't mean to merge it that way?

(Otherwise LGTM from the sidelines. 😄)

from proposal-logical-assignment.

bakkot avatar bakkot commented on June 20, 2024

It'd actually take considerably more work to change this behavior, we'd have to plumb an entirely new AssignmentTargetType through the spec.

Without offering an opinion on whether this change should be made, I don't think this is true: you could just have an Early Error to the effect of

AssignmentExpression : LeftHandSideExpression LogicalAssignmentOperator AssignmentExpression

It is a Syntax Error if LeftHandSideExpression is PrimaryExpression : CoverParenthesizedExpressionAndArrowParameterList.

(Similar wording is used in the Early Errors for delete.)

Of course, it might be better to have a new AssignmentTargetType instead of this.

from proposal-logical-assignment.

bakkot avatar bakkot commented on June 20, 2024

On reflection, I think it'd be best to allow these parenthesized LHSes (i.e., keep the current spec). Banning weird syntax whenever there is any new syntax involved, even though that syntax is very similar to existing syntax, causes trouble for implementations and does not obviously benefit anyone.

For example, we recently removed the restriction that you could not have try {} catch (e) { for (var e of foo); } (note the duplicate e), which strikes me as a pretty similar situation.

from proposal-logical-assignment.

ljharb avatar ljharb commented on June 20, 2024

In that case, that's because that's a reasonable thing to want to do :-) when would you actually want to put parens around the LHS?

from proposal-logical-assignment.

DanielRosenwasser avatar DanielRosenwasser commented on June 20, 2024

Review approval pending #20

from proposal-logical-assignment.

ljharb avatar ljharb commented on June 20, 2024

LGTM

from proposal-logical-assignment.

syg avatar syg commented on June 20, 2024

I agree that we should allow parenthesized LHSes.

LGTM editorially. Only suggestion is when preparing the PR for merge, please make sure the strict mode note isn't duplicated for every single production.

from proposal-logical-assignment.

michaelficarra avatar michaelficarra commented on June 20, 2024

LGTM. I think we could've described the error behaviour inline in the algorithm steps instead of in a big note that references step numbers (gross), but I see that it's just consistent with what's already there, so it's fine for now.

from proposal-logical-assignment.

rkirsling avatar rkirsling commented on June 20, 2024

One more point I almost forgot: in the same way as tc39/proposal-nullish-coalescing#50, it would be good to rename LogicalAssignmentOperator to ShortCircuitAssignmentOperator before this reaches Stage 4.

(I know the name of the proposal is a foregone thing but we can still editorialize the spec text. 😂)

from proposal-logical-assignment.

ljharb avatar ljharb commented on June 20, 2024

My understanding is that "LogicalAssignmentOperator" won't actually be in the spec PR; it was just a device to show the diff in this repo?

from proposal-logical-assignment.

rkirsling avatar rkirsling commented on June 20, 2024

@ljharb That's LogicalAssignmentPunctuator, but the similarity is in fact why I forgot to mention this earlier. 😅

from proposal-logical-assignment.

ljharb avatar ljharb commented on June 20, 2024

whoops, good call then :-)

from proposal-logical-assignment.

jridgewell avatar jridgewell commented on June 20, 2024

Update: I've opened #23 to discuss adding a NamedEvaluation to anonymous functions that are the RHS.

from proposal-logical-assignment.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.