Comments (13)
This is intentional. What behaviour are you proposing?
from babylon.
The one which does not repeat Identifier
twice and does not require changing it in two places when modifying AST I guess :)
from babylon.
That's not very helpful, what node structure are you proposing?
from babylon.
First thing comes to my mind.
ObjectPattern {
properties: [ AssignmentPatternProperty | Property ]
}
PropertyAssignmentPattern <: Node {
key: Identifier
pattern: Pattern
}
from babylon.
To be even more precise, Property
does not really match ObjectPattern
well since it had a lot of fields that are not relevant to ObjectPattern
. I predict ObjectPatternProperty
in some bright future.
from babylon.
It's going to be a breaking change, while we do have that luxury since we forked the AST from ESTree it's still tricky because we have existing transforms and Babel rarely has a major.
The existing node definition is good for transformations as it doesn't require every single transform that targets object patterns to know how and when to perform explosion of shorthands. The idea of making shorthands distinct is obviously appealing to the idea of a CST but I'm unconvinced that it's an appropriate modification to an AST that's (currently) targeted so generally at transforms.
I understand it's annoying but IMO the pros far outweigh the cons as it leads to more reliable and solid transforms. I'm not convinced that the extra code needed to handle it is burdensome, for reference here is the code in babel-generator
that handles it.
from babylon.
@markelog Can you elaborate on the complexity around traversal that you mentioned in the issue body?
from babylon.
You will get two and same Identifiers
while traversing when it seems there should be only one and also see https://github.com/cst/cst/blob/996ce8451d1bdf14e06439533499d2e320cb3342/src/elementTree.js#L105-L119
from babylon.
And there is an example of code generation issue - cst/cst#127, since there is two identifiers they are duplicated
from babylon.
Those issues just seem to be consequent of the fact that it uses the AST in conjunction with tokens rather than relying entirely on the AST.
from babylon.
Those issues just seem to be consequent of the fact that it uses the AST in conjunction with tokens rather than relying entirely on the AST.
Yes, that's part of the issue, same kind thing could be viewed with any traversal though, like:
let i = 0;
let ast = require("babylon").parse("({ test = 1 } = {})", {});
let result = require('estraverse').traverse( ast.program, {
keys: require("babel-types").VISITOR_KEYS,
enter: function (node) {
if (node.type === 'Identifier') {
i++;
}
}
});
console.log(i); // 2
Or if you found a token and you want to understand for which node this token belongs to, you can find it by comparing position of the node and token since it has belong to the only one node right? That would be the assumption i guess, but in this case it wouldn't be true.
I understand you don't want to change that because you don't need this and we are only one consumer of this AST who is mentioned it, so there is could be any justification for denial really :).
from babylon.
so there is could be any justification for denial really :).
By that, i mean if you don't want to change then no big deal, we would be just force to add couple hacks, in any case it seems you made your mind already
from babylon.
Since it looks like we need an AST change that we'd not like to do with other changes in bulk, closing
from babylon.
Related Issues (20)
- Can't use object-rest-spread in a function HOT 6
- Should we allow Flowtype `import type` statements when `sourceType:script`? HOT 2
- How to get the "root" path HOT 5
- ES2016 bind syntax does not work with functions HOT 5
- Flow interfaces & `declare class` do not adhere to ASI HOT 2
- Warning if tests fail that if you need to generate fixtures. HOT 2
- React 16 SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag HOT 7
- Set id to null for ArrowFunctionExpressions? HOT 3
- babylon super.xxx will cause performance is very slow HOT 1
- Add sourceType 'function' HOT 12
- Typescript: ExportNamedDeclaration raises SyntaxError when exportExtensions plugin enabled HOT 1
- Unable to parse a class get method with a decorator HOT 2
- static field initializer as an arrow function containing new.target is not allowed
- Unexpected AST for pipeline operator with arrow function HOT 2
- Flow comment parsing HOT 8
- typescript: Support binding pattern in signature HOT 2
- Existential return type annot in arrow function confused with `*=` operator HOT 5
- Error w/ generics in return type annots inside JSXExpressionContainers HOT 3
- [Presets: React + Typescript] Complex method with generic type fails during transpilation HOT 2
- PSA: this repo has been moved to the main babel repo
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 babylon.