I have tried the code below but it seems to result in an error.
import * as acorn from "acorn";
import { tsPlugin } from "acorn-typescript";
const acornTs = acorn.Parser.extend(tsPlugin());
// OK
let node = acorn.Parser.parseExpressionAt("<tag prop={foo}/>", 11, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
});
console.log(node);
// Error
node = acornTs.parseExpressionAt("<tag prop={foo as number}/>", 11, {
sourceType: "module",
ecmaVersion: "latest",
locations: true,
});
console.log(node);
console:
TypeError: i.parseExpressionAt is not a function
at e.parseExpressionAt (/xxxxxxxxx/node_modules/.pnpm/acorn-typescript@1.2.4_acorn@8.8.2/node_modules/acorn-typescript/lib/index.js:1:100013)
I have tried the code below but it seems to result in an error.
console:
I think we probably need to call
parser.parseExpression()
instead ofparser.parseExpressionAt()
. https://github.com/TyrealHu/acorn-typescript/blob/48e555ddf43b212b069b156888c8560fedb85c23/src/index.ts#L5172