Giter Club home page Giter Club logo

Comments (4)

mysticatea avatar mysticatea commented on August 26, 2024

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.

jbrumwell avatar jbrumwell commented on August 26, 2024

@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 };

  1. partial=false init=true // given your definition I'd expect this to be true
  2. partial=true init=true // given your definition I'd expect this to be false

const { x = 10 } = { x: 15 };

  1. partial=false init=true // given your definition I'd expect this to be true
  2. partial=true init=true

from escope.

mysticatea avatar mysticatea commented on August 26, 2024

On const { x = 10 } = { y: 15 };, x has two initializers.

  1. x = 10 is not partial.
  2. {x} = {y: 15} is partial. This means x = ({y: 15}).x. A runtime optimizer may remove it. But we can assignment to Object.prototype.x anywhere, so escope cannot decide whether it is undefined.

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.

jbrumwell avatar jbrumwell commented on August 26, 2024

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)

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.