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

fix(typescript-estree): options range loc being always true #704

Merged
merged 7 commits into from Nov 12, 2019

Conversation

Mark1626
Copy link
Contributor

Fix #694

@bradzacher

Originally planned on removing range and loc inside here

private createNode<T extends TSESTree.BaseNode = TSESTree.BaseNode>(
node: ts.Node,
data: TSESTree.OptionalRangeAndLoc<T>,
): T {

but saw that some Nodes(StringLiteral, BigIntLiteral) depended on range after createNode.

Left the responsibility of removing it to

private converter(
node?: ts.Node,
parent?: ts.Node,
inTypeMode?: boolean,
allowPattern?: boolean,
): any {

which covered all Nodes except ClassDeclaration, InterfaceDeclaration, ShorthandPropertyAssignment on which I had to remove the field if necessary

Let me know if I need to change anything

@bradzacher bradzacher added the bug Something isn't working label Jul 18, 2019
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a problem with the idea behind your logic, but I think that it'll be a bit hard on the maintenance side.

We will have to ensure that we remember to catch every single place that creates a child node outside of the normal converter flow, and call applyExtraOptions to it.

This is very manual and will be error prone. For example in this diff, it looks like you missed the usages in convertJSXTagName.

I think a better option would be to do this after the AST has been created in its entirety.

Within the parser package, we have a list of visitor keys. Additionally, we have a utility class, SimpleTraverser, which you can use to traverse the AST.

These two could be moved into typescript-estree, and used to traverse the tree after the fact, and scrub the range/loc if requested:

function parse(file, options) {
  const ast = convert();
  if (options.range === false || options.loc === false) {
    const traverser = new SimpleTraverser({
      enter() => // scrub range and/or loc
    })
    traverser.traverse(ast);
  }
}

WDYT?

@Mark1626
Copy link
Contributor Author

Sure I think it's better to do this after the AST has been created. I'll make the changes

@codecov
Copy link

codecov bot commented Nov 12, 2019

Codecov Report

Merging #704 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #704      +/-   ##
==========================================
+ Coverage   93.98%   93.98%   +<.01%     
==========================================
  Files         121      121              
  Lines        5217     5224       +7     
  Branches     1444     1447       +3     
==========================================
+ Hits         4903     4910       +7     
  Misses        179      179              
  Partials      135      135
Impacted Files Coverage Δ
packages/parser/src/parser.ts 100% <ø> (ø) ⬆️
packages/typescript-estree/src/visitor-keys.ts 100% <ø> (ø)
packages/typescript-estree/src/simple-traverse.ts 95% <ø> (ø)
packages/typescript-estree/src/ast-converter.ts 100% <100%> (ø) ⬆️
packages/parser/src/analyze-scope.ts 95.5% <100%> (ø) ⬆️
packages/typescript-estree/src/parser.ts 94.06% <100%> (+0.1%) ⬆️

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for doing this

@bradzacher bradzacher merged commit db1aa18 into typescript-eslint:master Nov 12, 2019
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

range and loc options are always true
2 participants