Closed skoshx closed 1 year ago
I was unable to reproduce this. I ran this code from a file at the root of the recast repo:
const { parse } = require('./lib/parser');
const babelTsParser = require('./parsers/babel-ts');
const code = `
'use client';
function foo() {}
`
const ast2 = parse(code, { parser: babelTsParser })
console.log("Substring: ")
console.log(JSON.stringify(code.substring(0, ast2.program.directives[0].end)))
I got this output:
Substring:
"\n'use client';"
The version of @babel/parser
shown by npm ls
is @babel/parser@7.20.5
, which is the one pinned in package.json
. If you think this is still a problem, can you provide more details about how you reproduced it? Perhaps you could reproduce it in astexplorer.net?
The
end
index value of parsed program directives is wrong, when using the babel TS parser. I tried the same with latest@babel/parser
and it seems to work fine, so just bumping@babel/parser
to latest should fix this issue.Minimal reproduction:
Notice the leading
f
... In some cases it also becomesfunc
etc.