-
Notifications
You must be signed in to change notification settings - Fork 358
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
Concise methods node #5
Comments
But getters and setters are also represented with a FunctionExpression node. It is only appropriate to re-use it yet again for methods. |
Good point, and similar problem. Maybe a new property on |
Tell me about it. But that problem exists all over the SpiderMonkey AST. |
@michaelficarra |
@IMPinball We have the opportunity to change things like that with ESTree. |
@sebmck We should not change pre-ES6 types cardinally though, as I don't think we want to break all the existing tools. |
@RReverser Sure, I agree, I just don't think these types of things should be taken off the table for consideration. |
@sebmck: That's a slippery slope. If you're going to make pre-ES6 breaking changes, there's not much argument against just adopting Shift. We shouldn't be considering breaking changes like those in this repo. |
I like the original proposal in this bug, a new boolean @sebmck I was merely clarifying a couple specific points on why certain nodes were used, and I highly doubt any of that's going to change now (not to mention it is a little unintelligent to do so, since patching all the tools isn't exactly trivial for anything). I actually disagreed with one of them, and the other isn't something easily replaced. I do find |
Adding a new property to |
Additive changes to any of the data structures can not be considered breaking. @michaelficarra, we have already agreed on a few non-BC changes already, but for the sake of interop. If we all agree to add a prop to function expression, I don't see how that's a breaking change. I don't think any discussion should be off the table. We're here to make iterative improvements, and that doesn't mean we have to move to shift to merely discuss them. |
To be more concrete, here's my proposal: Add a property
|
Maybe the kinds should be |
It's easy to get dependent on the number of property types. And "init" is
|
@IMPinball What do you mean by "get dependent on the number of property types"? Can you elaborate more about it? |
Adding a new property will not break any existing tools, and that's quite straightforward since the tools typically ignore any unknown properties. Still, that does not mean we should not come up with a proper justification as to why it is needed. Duplicating CMIIW @dherman, the SpiderMonkey AST already sets the precedent that a node does not always know what "role" it plays (rightfully so, although @michaelficarra or @ikarienator can say more about how it is same/different in Shift AST). Consider the |
Agree with @ariya here. Making some node types contextual while entire AST by design is not, doesn't seem to be legit. |
@ikarienator Imagine this kind of check: function handleProperty(node) {
if (node.kind === 'get') handleGetter(node);
else if (node.kind = 'set') handleSetter(node);
else handleInit(node);
} You don't know if it's going to be an foo() {}
foo: function () {} I don't think the |
Well, by the looks of it, it may be best to add a |
@IMPinball I don't see how my comment proves that it's best to add extra boolean property on function itself; as I wrote earlier, I'm actually against it. |
@RReverser Okay. Then I take that back, since I really misinterpreted it. |
@ariya Identifier is a bad example because it always has the same syntactic form regardless of where it is used. So it really doesn't matter where I encounter an Identifier because I know it always looks the same. FunctionExpression doesn't always look the same and that's a problem for tools. I mean, I'm assuming that's why we have ArrowFunctionExpression instead of using FunctionExpression to represent arrow functions - the only difference there is syntax but it represents the same thing. And to be clear, I'm talking about more than traversal here. I'm also talking about consistently representing syntax. Methods/getters/setters are a different syntactic form but you can't tell that from the node. That seems broken. |
nit: Identifiers in SM API are used for both Identifier and That said I totally agree that it's wrong represent getters and setter
|
I don't see how changing the getter/setter representation can even be considered at this point, given it is an ES5 feature that all existing tools will rely upon. |
@michaelficarra no one is suggesting changing anything. I'm suggesting adding something. Back compat would not be affected. |
If we cannot be breaking BC, then it moots your argument of doing something new (methods) "consistently" with the old stuff (getters/setters). That is, I would agree that having one way to distinguish the role/kind would be nice, but since that ship already sailed when getters/setters were represented in a non-generically-extendable way, we already accepted the (future, aka now) cost of other kinds. I like having a meta flag to indicate this shorthand form. I'm not sure |
|
Can we get some consensus on this? |
I would still like there to be a consistent way that concise methods and concise properties are indicated as concise. My vote remains |
@getify Are you referring to object property shorthand? ie. |
I am referring to that, yes, and I'm saying that conceptually these two separate cases seem like the same, and are often documented the same... that is, "concise properties" and "concise methods". So I think it's at least reasonable to entertain the notion that they should be notated the same... ie, with the word "concise" rather than with "shorthand" for properties and "method" for methods. |
From the perspective of a style enforcer that must care about concrete form, having a new property (which doesn't break BC) on Function nodes would be hugely beneficial. @nzakas is correct in describing what a pain it is without this. Once must check to see if the parent is an ObjectExpression, then traverse all properties of that object to see which property is equivalent to that function expression, and then check the kind property of that property node. For those that implement visitor pattern (ESLint), this is unnecessarily convoluted. Seems as if the Esprima team is not all on the same page. We'll resolve that tomorrow at our team meeting and report back. |
@mikesherov I'm not against this but you're grossly overestimating how hard it is without. On visit of a parent.type === "Property" && parent.method && parent.value === node |
Right. Forgot prop was parent. In that case, seems duplicative. |
Once again I'll point out how silly it is to have to look at a node's parent to determine its syntactic form. This is the only place in ESTree where this happens. |
yeah, and how silly it is that concise props have the "shorthand" flag but concise methods would not. |
@getify: What? What would a |
I'm not sure how I can be any clearer about what I'm suggesting? It seems silly to me that the node for a "concise property" would have a "shorthand" moniker, but the node for a "concise method" wouldn't have a similar flag (if named differently). It also seems silly to me that the flag would be named differently in these two cases. |
The point @michaelficarra is making that a shorthand literal property doesn't have the In this same manner, the function expression that is the |
Not only that, I was pointing out that methods don't have a non-shorthand variant. |
OK, my attempts at brevity in this thread have apparently significantly misled on my point. Let me try to be more specific.
|
We're getting into way too many tangential topics here. @getify - I think everyone understands your point fine, it's just that we don't share your opinion. I think it's best that we focus on the original topic so we can finally close this discussion out. Can we just get a quick +1/-1 check for adding some indicator of concise syntax on a |
fine. if my opinion isn't shared (even though I thought I was backing you up, specifically), then it's also probably not important for a consensus vote check, but I'd be a -1 for adding something in an inconsistent fashion, which it sounds like you'd be headed towards. |
👎 to an additional property on |
@sebmck I'm curious, why would you consider this containing parent information? To me, the parent is just the property name whereas |
@nzakas Consider code generator that would rely on In that case, you can't just extract function expression from object's property into other place (i.e. |
@RReverser Interesting, this is where I thought having such a property would help. I see your point. Thanks for explaining. Okay, I'm convinced it's not useful and potentially hazardous to add a property such as this, so I'm withdrawing the proposal. Thanks for the consideration, all. |
Thanks for explaining more eloquently than I coul @RReverser. This principle of context free replacement has come up several times. Perhaps we can add this as a guiding principe? |
+1 |
Sounds good. However I'll spend next 18 hours in KBP ✈ SFO, so will do it after unless someone gets to this earlier. |
Esprima currently represents concise methods as
Property
whosevalue
is aFunctionExpression
. This is pretty confusing because ES5 style properties with function values are represented the same way. Even though themethod
flag istrue
, that still means theFunctionExpression
node represents different syntax in each situation, and that can cause errors such as eslint/eslint#1677The text was updated successfully, but these errors were encountered: