Skip to content
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

Keywords in ReferenceIdentifier should be syntax error. #407

Closed
mysticatea opened this issue May 2, 2016 · 4 comments
Closed

Keywords in ReferenceIdentifier should be syntax error. #407

mysticatea opened this issue May 2, 2016 · 4 comments

Comments

@mysticatea
Copy link
Contributor

mysticatea commented May 2, 2016

From eslint/eslint#6013

On v3.1.0, Acorn succeeds to parse the following code.

let foo = {this};

But this should be syntax error: https://tc39.github.io/ecma262/2016/#prod-ObjectLiteral

PropertyDefinition → IdentifierReference → Identifier → IdentifierName but not ReserevedWord


"use strict";

const acorn = require("acorn");
const ast = acorn.parse(
    `
    let foo = {this};
    `,
    {
        ecmaVersion: 6
    }
);

console.log(`acorn v${acorn.version}`);
console.log(JSON.stringify(ast, null, 4));
> node test.js
acorn v3.1.0
{
    "type": "Program",
    "start": 0,
    "end": 27,
    "body": [
        {
            "type": "VariableDeclaration",
            "start": 5,
            "end": 22,
            "declarations": [
                {
                    "type": "VariableDeclarator",
                    "start": 9,
                    "end": 21,
                    "id": {
                        "type": "Identifier",
                        "start": 9,
                        "end": 12,
                        "name": "foo"
                    },
                    "init": {
                        "type": "ObjectExpression",
                        "start": 15,
                        "end": 21,
                        "properties": [
                            {
                                "type": "Property",
                                "start": 16,
                                "end": 20,
                                "method": false,
                                "shorthand": true,
                                "computed": false,
                                "key": {
                                    "type": "Identifier",
                                    "start": 16,
                                    "end": 20,
                                    "name": "this"
                                },
                                "kind": "init",
                                "value": {
                                    "type": "Identifier",
                                    "start": 16,
                                    "end": 20,
                                    "name": "this"
                                }
                            }
                        ]
                    }
                }
            ],
            "kind": "let"
        }
    ],
    "sourceType": "script"
}
@marijnh marijnh closed this as completed in 24623a2 May 2, 2016
@marijnh
Copy link
Member

marijnh commented May 2, 2016

Attached patch should help.

@mysticatea
Copy link
Contributor Author

mysticatea commented May 2, 2016

I checked this on the current master branch, but this is not fixed yet.
This is about object literals, not object patterns.

Please reopen?

marijnh added a commit that referenced this issue May 2, 2016
@marijnh
Copy link
Member

marijnh commented May 2, 2016

Ugh, I should not read bug reports before I'm properly awake. Try again with patch 7c4758c

@mysticatea
Copy link
Contributor Author

Thank you very much for the fast fix!
I confirmed this issue have been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants