Closed gtm-nayan closed 1 year ago
Could u show me the case which fails to parse something like 1 as number
// index.js
import * as acorn from 'acorn';
import { tsPlugin } from 'acorn-typescript';
const source = `1 as number`;
const node = acorn.Parser.extend(tsPlugin()).parse(source, {
sourceType: 'module',
ecmaVersion: 'latest',
locations: true
});
console.log(node);
package.json
{"type": "module"}
will fail with SyntaxError: Unexpected token (1:5)
I narrowed it down to this line, https://github.com/TyrealHu/acorn-typescript/blob/b01075d466889e6cdbf6d7ee39d20fba12f121f0/src/index.ts#L1904
it returns true when I'm running the tests inside this repo but it's false in my actual project.
Thanks for the quick fix.
It fails to parse something like
1 as number
because the plugin does reference equality checks on token types.But if using it from an ESM file, the users will load acorn/index.mjs, whereas this plugin will load the tokenTypes from acorn/index.js, which means the token types will be different objects even if they are the same token type and the reference equality will return false.
Possible solutions:
index.esm.js
file toindex.mjs
and let users import from it manually