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

Location columns should be started from 1 instead of 0 #1951

Closed
KvanTTT opened this issue Sep 20, 2018 · 1 comment
Closed

Location columns should be started from 1 instead of 0 #1951

KvanTTT opened this issue Sep 20, 2018 · 1 comment

Comments

@KvanTTT
Copy link

KvanTTT commented Sep 20, 2018

Steps to reproduce

Consider the parsing of the following simple code on esprima demo page with checked Line and column-based option.

a

Expected output

{
    "type": "Program",
    "body": [
        {
            "type": "ExpressionStatement",
            "expression": {
                "type": "Identifier",
                "name": "a",
                "loc": {
                    "start": {
                        "line": 1,
                        "column": 1
                    },
                    "end": {
                        "line": 1,
                        "column": 2
                    }
                }
            },
            "loc": {
                "start": {
                    "line": 1,
                    "column": 1
                },
                "end": {
                    "line": 1,
                    "column": 2
                }
            }
        }
    ],
    "sourceType": "script",
    "loc": {
        "start": {
            "line": 1,
            "column": 1
        },
        "end": {
            "line": 1,
            "column": 2
        }
    }
}

Actual output

{
    "type": "Program",
    "body": [
        {
            "type": "ExpressionStatement",
            "expression": {
                "type": "Identifier",
                "name": "a",
                "loc": {
                    "start": {
                        "line": 1,
                        "column": 0
                    },
                    "end": {
                        "line": 1,
                        "column": 1
                    }
                }
            },
            "loc": {
                "start": {
                    "line": 1,
                    "column": 0
                },
                "end": {
                    "line": 1,
                    "column": 1
                }
            }
        }
    ],
    "sourceType": "script",
    "loc": {
        "start": {
            "line": 1,
            "column": 0
        },
        "end": {
            "line": 1,
            "column": 1
        }
    }
}

It unifies location between esprima library and common code editors (VS Code, Notepad++).

@ariya
Copy link
Contributor

ariya commented Sep 22, 2018

Thanks for the report! Unfortunately, it is designed like that for historical reason (the AST is originated from SpiderMonkey AST format) and now the cost is too high to break the downstream tools relying on the behavior. See estree/estree#65 for some more details.

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

No branches or pull requests

2 participants