Should create new Identifer Node when node.shorthand = true #1755

Open
fishbar opened this Issue Feb 14, 2017 · 0 comments

Projects

None yet

1 participant

@fishbar
Contributor
fishbar commented Feb 14, 2017

TestCase:

case 1:

let name = 'test';
let email = ''
let user = {name, email}

case 2:

let user = {name: 'test', email: 'abc@xxx.com'}
let {name, email} = user;

esprima parse code into ast as following:

{
    "type": "ObjectExpression",
    "properties": [
        {
            "type": "Property",
            "key": {
                "type": "Identifier",
                "name": "name"
            },
            "computed": false,
            "value": {
                "type": "Identifier",
                "name": "name"
            },
            "kind": "init",
            "method": false,
            "shorthand": true
        },
        {
            "type": "Property",
            "key": { 
                "type": "Identifier",
                "name": "email"
            },
            "computed": false,
            "value": {
                "type": "Identifier",
                "name": "email"
            },
            "kind": "init",
            "method": false,
            "shorthand": true
        }
    ]
}

see the above AST tree, each property, the Node(key) === the Node(value) , so when eshortten change the Identifier name into shortten chars, bug cames

Actual output:

let {a, b} = user;

Expected

let {name:b,email:c}=a;

so esprima should clone the value Node from the key Node, instead of refer value Node to key Node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment