ast-types visit changes ast tree
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 194
- Avg merge
- 22h 43m
- Merged PRs (30d)
- 10
Description
I'm trying to use `ast-types` to do ast tree parsing in `eslint` rules. But it changes some ast tree nodes, thus not compatible with `eslint` rules
The code is
```javascript
var a = Array.from([1, 2, 3, -1, -2], function(x) { return x * x; });
a.uniq();
```
Errors are:
```javascript
AssertionError [ERR_ASSERTION]: Rule should not modify AST.
+ expected - actual
"start": 20
"type": "ArrayExpression"
}
{
+ "async": false
"body": {
"body": [
{
"argument": {
"line": 2
}
}
"name": "x"
+ "optional": false
"range": [
60
61
]
"start": 60
"type": "Identifier"
+ "typeAnnotation": [null]
}
"loc": {
"end": {
"column": 64
"line": 2
}
}
"name": "x"
+ "optional": false
"range": [
64
65
]
"start": 64
"type": "Identifier"
+ "typeAnnotation": [null]
}
"start": 60
"type": "BinaryExpression"
}
"start": 53
"type": "ReturnStatement"
}
]
+ "directives": []
"end": 68
"loc": {
"end": {
"column": 67
]
"start": 51
"type": "BlockStatement"
}
+ "defaults": []
"end": 68
"expression": false
"generator": false
"id": [null]
"line": 2
}
}
"name": "x"
+ "optional": false
"range": [
48
49
]
"start": 48
"type": "Identifier"
+ "typeAnnotation": [null]
}
]
"range": [
39
68
]
+ "rest": [null]
+ "returnType": [null]
"start": 39
"type": "FunctionExpression"
+ "typeParameters": [null]
}
]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the reported AST comparison with the provided JavaScript snippet, using ast-types in an ESLint rule, and inspect where traversal or parsing changes nodes. No files or tests are named; done means the resulting AST remains compatible with ESLint's rule validation without the added fields or other reported changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, javascript, typescript
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100