-
-
Notifications
You must be signed in to change notification settings - Fork 75
sourceCode.getTokenAfter works incorrectly on our AST #122
Comments
more info: for this specific rule, those visitors get called: ClassBody(node) {
checkForPartOfClassBody(sourceCode.getFirstToken(node, 1)); // 0 is `{`.
},
MethodDefinition(node) {
checkForPartOfClassBody(sourceCode.getTokenAfter(node));
}, at one point, this happens
apparently, there should always be a token after a |
OK, this code tells me what we need to know: const tsp = require('typescript-eslint-parser')
const esp = require('espree')
const { SourceCode, linter } = require('eslint')
const code = `
export default class Reader {
render() {
return (
<div className="flex-transparent">
<nav></nav>
</div>
)
}
}
`
const configs = [
[esp, { ecmaFeatures: { jsx: true }, tokens: true, comment: true, loc: true, range: true, ecmaVersion: 6, sourceType: 'module' }],
[tsp, { ecmaFeatures: { jsx: 'react' }, tokens: true, comment: true }],
]
for (const [parser, options] of configs) {
const ast = parser.parse(code, options)
const sc = new SourceCode(code, ast)
const method = sc.ast.body[0].declaration.body.body[0]
console.log(sc.getTokenAfter(method))
const messages = linter.verify(sc, {
rules: {
'no-extra-semi': 2,
},
}, { filename: 'Reader.tsx' })
console.log(messages)
} the output is: for espree: Token {
type: 'Punctuator',
value: '}',
start: 125,
end: 126,
loc:
SourceLocation {
start: Position { line: 10, column: 0 },
end: Position { line: 10, column: 1 } },
range: [ 125, 126 ] }
[] for this parser:
i.e. somehow the AST this parser creates doesn’t allow eslint’s |
This is another duplicate of #70. The problem is with the whitespace between the JSX nodes, amending it to the following causes the source to be parsed without error:
(I do realise that totally sucks 😄 I will try and get a fix merged into the TypeScript compiler as soon as possible) |
aww, i invested so much detective work into the code, and then it turned out a tiny bit more in the issue tracker would have been sufficient 😢 thanks 😆 |
It happens! 😄 Thank you for your digging regardless @flying-sheep - it is so helpful when users are able to provide detailed context, and simple examples. |
Test:
error:
The text was updated successfully, but these errors were encountered: