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

range and loc options are always true #694

Closed
ehmicky opened this issue Jul 11, 2019 · 2 comments · Fixed by #704
Closed

range and loc options are always true #694

ehmicky opened this issue Jul 11, 2019 · 2 comments · Fixed by #704
Labels
bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@ehmicky
Copy link

ehmicky commented Jul 11, 2019

What code were you trying to parse?

typescriptEstree.parse('true', {range: false, loc: false})

What did you expect to happen?

The returned node should not include the range or loc properties.

What actually happened?

{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "Literal",
        "value": true,
        "raw": "true",
        "range": [
          0,
          4
        ],
        "loc": {
          "start": {
            "line": 1,
            "column": 0
          },
          "end": {
            "line": 1,
            "column": 4
          }
        }
      },
      "range": [
        0,
        4
      ],
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 4
        }
      }
    }
  ],
  "sourceType": "script",
  "range": [
    0,
    4
  ],
  "loc": {
    "start": {
      "line": 1,
      "column": 0
    },
    "end": {
      "line": 1,
      "column": 4
    }
  }
}

Versions

package version
@typescript-eslint/typescript-estree 1.11.0
TypeScript 3.5.3
node 12.6.0
npm 6.10.0
@ehmicky ehmicky added package: typescript-estree Issues related to @typescript-eslint/typescript-estree triage Waiting for maintainers to take a look labels Jul 11, 2019
@ehmicky ehmicky changed the title range and loc options are always true [typescript-estree] range and loc options are always true Jul 11, 2019
@ehmicky ehmicky changed the title [typescript-estree] range and loc options are always true range and loc options are always true Jul 11, 2019
@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for maintainers to take a look labels Jul 11, 2019
@Mark1626
Copy link
Contributor

Hi @bradzacher,
Can I pick this up? Had a look into the code, I thought of this approach can you comment on it.

I'll update the ConverterOptions to include the range and loc options.

interface ConverterOptions {
errorOnUnknownASTType: boolean;
useJSXTextNode: boolean;
shouldPreserveNodeMaps: boolean;
}

Will then pass the options to convertor instance here

const instance = new Converter(ast, {
errorOnUnknownASTType: extra.errorOnUnknownASTType || false,
useJSXTextNode: extra.useJSXTextNode || false,
shouldPreserveNodeMaps,
});

Then using the options I exclude range and loc from getting added when converting nodes in convert.ts

@ehmicky
Copy link
Author

ehmicky commented Nov 12, 2019

Thanks for working on this! :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants