Comments (4)
Yeah, it is by design.
escope makes writable-references for variable-initializers.
When it's used together with destructuring and default values, the variable has multiple writable-references for its initializer.
So the Reference
object has init
property in order to check whether or not the reference is the initializer. And the Reference
object has partial
property in order to check whether or not the reference writes a part of writeExpr
to the variable.
Please see also #65.
And eslint/eslint#2639 may help you.
from escope.
@mysticatea Thank you for responding, given your description of init and partial I would be able to implement the changes in behaviour.
Partial doesn't seem to be operating in the fashion you mention, here are the results for partial and init in two different circumstances;
const { x = 10 } = { y: 15 };
- partial=false init=true // given your definition I'd expect this to be true
- partial=true init=true // given your definition I'd expect this to be false
const { x = 10 } = { x: 15 };
- partial=false init=true // given your definition I'd expect this to be true
- partial=true init=true
from escope.
On const { x = 10 } = { y: 15 };
, x
has two initializers.
x = 10
is not partial.{x} = {y: 15}
is partial. This meansx = ({y: 15}).x
. A runtime optimizer may remove it. But we can assignment toObject.prototype.x
anywhere, so escope cannot decide whether it isundefined
.
On const { x = 10 } = { x: 15 };
, x
has two initializers as almost same as the above. x = 10
exists but it is unreachable. escope does not analyze execution paths.
from escope.
I may be wrong but I don't think this is incorrect according to the draft. My interpretation of the draft is that it creates a reference from the assignment expression, then declares the value with rhs destructuring if available and if not uses the default value on the assignment expression.
This makes sense because if it didn't you are declaring const
twice when destructuring their assignments. This is also the way that babel transforms the code.
// const { x = 10 } = { y: 15 };
"use strict";
var _x = { y: 15 };
var _x$x = _x.x;
var x = _x$x === undefined ? 10 : _x$x;
from escope.
Related Issues (20)
- Function Expression
- Error on ImportDeclaration HOT 1
- Update scope manager scopes once it was created HOT 2
- Add support for label scoping
- New escope-demo (not a bug)
- Add node.body check before attempting to vist children HOT 8
- Variables from global scope have empty references array
- Drop `es6-map`. HOT 1
- Function scope arguments variable HOT 1
- Drop using require'd assert in favour of just throwing an error
- Enter the version directly in index.js
- Problem with unused library functions
- let declaration treated as var declaration HOT 1
- Can't locate variable within named function's scope when function assigned to other variable HOT 4
- Function declarations attached to block scope? HOT 1
- Another version of escope HOT 1
- what does 'through' in escope mean? HOT 1
- Maybe i find a bug in escope ?
- Is ES6 parameter scope not supported? HOT 1
- JSDoc unavailable: 404 error
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 escope.