Comments (16)
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.
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:
- https://tc39.es/ecma262/#sec-grouping-operator-static-semantics-assignmenttargettype
- https://tc39.es/ecma262/#sec-identifiers-static-semantics-assignmenttargettype
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.
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.
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.
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.
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.
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.
Review approval pending #20
from proposal-logical-assignment.
LGTM
from proposal-logical-assignment.
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.
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.
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.
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.
@ljharb That's LogicalAssignmentPunctuator, but the similarity is in fact why I forgot to mention this earlier.
from proposal-logical-assignment.
whoops, good call then :-)
from proposal-logical-assignment.
Update: I've opened #23 to discuss adding a NamedEvaluation to anonymous functions that are the RHS.
from proposal-logical-assignment.
Related Issues (16)
- introduce only ??= HOT 3
- Editorial nit: notes are incorrect HOT 2
- Confusing behavior relative to existing assigment operators HOT 2
- Stage 3 review HOT 1
- Is this worth the syntax complexity? HOT 5
- Better examples? HOT 3
- Giving name to anonymous functions HOT 8
- Implementation status tracking HOT 9
- Duplication of Note in Evaluation
- Is assigned expression always evaluated even if not needed? HOT 3
- Destructing HOT 1
- Short-circuiting concerns HOT 26
- Optional assignment HOT 2
- Property assignment operator HOT 4
- Use in destructuring default assignments HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-logical-assignment.