TyrealHu / acorn-typescript

Alternative, TypeScript parser
https://www.npmjs.com/package/acorn-typescript?activeTab=readme
MIT License
145 stars 18 forks source link

SyntaxError: Unexpected token in arrow function's (nested) generic type #36

Closed bpstrngr closed 1 year ago

bpstrngr commented 1 year ago

Thrown in Rollup's src/utils/options/normalizeInputOptions.ts:

const getIdMatcher = <T extends Array<any>>(
                                     ^
        option:
                | undefined
                | boolean
                | string
                | RegExp
                | (string | RegExp)[]
                | ((id: string, ...parameters: T) => boolean | null | void)
): ((id: string, ...parameters: T) => boolean) => {
        if (option === true) {
                return () => true;
        }
        if (typeof option === 'function') {
                return (id, ...parameters) => (!id.startsWith('\0') && option(id, ...parameters)) || false;
        }
        if (option) {
                const ids = new Set<string>();
                const matchers: RegExp[] = [];
                for (const value of ensureArray(option)) {
                        if (value instanceof RegExp) {
                                matchers.push(value);
                        } else {
                                ids.add(value);
                        }
                }
                return (id: string, ..._arguments) => ids.has(id) || matchers.some(matcher => matcher.test(id));
        }
        return () => false;
};
SyntaxError: Unexpected token (116:37)
    at pp.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/location.js:15:13)
    at TypeScriptParser.raiseCommonCheck (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4975:44)
    at TypeScriptParser.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4981:29)
    at pp.unexpected (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/parseutil.js:111:8)
    at TypeScriptParser.jsx_parseIdentifier (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:773:22)
    at TypeScriptParser.jsx_parseNamespacedName (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:780:29)
    at TypeScriptParser.jsx_parseAttribute (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:847:30)
    at TypeScriptParser.jsx_parseOpeningElementAt (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:5017:47)
    at TypeScriptParser.jsx_parseElementAt (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:878:39)
    at TypeScriptParser.jsx_parseElement (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:926:25) {
  pos: 3725,
  loc: Position { line: 116, column: 37 },
  raisedAt: 3726
}

looks like jsx is getting involved, this might be a tough one... I was surprised actually that the acorn Parser's class name became "JSXParser" by the way after extending with this plugin, is there an option to not enable JSX parsing along with typescript?

bpstrngr commented 1 year ago

probably same issue in neighboring file src/utils/options/normalizeOutputOptions.ts:

const getAddon = <T extends 'banner' | 'footer' | 'intro' | 'outro'>(
                              ^
        config: OutputOptions,
        name: T
): NormalizedOutputOptions[T] => {
        const configAddon = config[name];
        if (typeof configAddon === 'function') {
                return configAddon as NormalizedOutputOptions[T];
        }
        return () => configAddon || '';
};
SyntaxError: Unexpected token (283:28)
    at pp.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/location.js:15:13)
    at TypeScriptParser.raiseCommonCheck (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4975:44)
    at TypeScriptParser.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:4981:29)
    at pp.unexpected (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/parseutil.js:111:8)
    at TypeScriptParser.jsx_parseIdentifier (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:773:22)
    at TypeScriptParser.jsx_parseNamespacedName (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:780:29)
    at TypeScriptParser.jsx_parseAttribute (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:847:30)
    at TypeScriptParser.jsx_parseOpeningElementAt (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:5017:47)
    at TypeScriptParser.jsx_parseElementAt (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:878:39)
    at TypeScriptParser.jsx_parseElement (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:926:25) {
  pos: 8472,
  loc: Position { line: 283, column: 28 },
  raisedAt: 8480
}
TyrealHu commented 1 year ago

Had been fixed in version 1.4.3