TyrealHu / acorn-typescript

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

Feature-Request: support import-assertions #41

Closed bpstrngr closed 1 year ago

bpstrngr commented 1 year ago

While parsing Rollup's src/ast/nodes/shared/FunctionBase.ts:

export default abstract class FunctionBase extends NodeBase {
                        ^
        declare async: boolean;
        // ...
}

SyntaxError: Unexpected token (36:24)
    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:5008:44)
    at TypeScriptParser.raise (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:5014:29)
    at pp.unexpected (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/parseutil.js:111:8)
    at pp.semicolon (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/parseutil.js:88:59)
    at TypeScriptParser.parseExport (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/xtuc_2020_acorn_importassertions/0/src/index.js:96:16)
    at TypeScriptParser.parseExport (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:3392:34)
    at pp.parseStatement (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/statement.js:137:69)
    at TypeScriptParser.parseStatement (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:3582:30)
    at pp.parseTopLevel (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/statement.js:22:21) {
  pos: 1277,
  loc: Position { line: 36, column: 24 },
  raisedAt: 1282
}

acorn expects a semicolon after the "abstract" keyword.

TyrealHu commented 1 year ago

I parse the same code, but it didnt throw an error. this is my case

bpstrngr commented 1 year ago

okay interesting, i looked around, i'm using one additional plugin, https://github.com/xtuc/acorn-import-attributes, and taking that out fixes this. It actually has a newer version than the one i'm using (an upgrade to import attributes instead of import assertions), besides an open issue regarding an export declaration, so i'll take a test with it. really hope it won't interfere cuz these compositions of overriding get nasty to track for me.

bpstrngr commented 1 year ago

well, the mentioned plugin's new version causes other interferences when turned on... extending acorn with it before acorn-typescript causes .d.ts files to fail ("SyntaxError: Missing initializer in const declaration: export const VERSION;"), while after it's line break between regular importnamedspecifiers that become "unexpected token".

Since now thinking about it it's not that surprising that importassertions interfere with typescript, i suppose either some typescript-ready variant of acorn-import-attributes, or some detection of its presence here would be required...

I think i could drop support for import-assertions in typescript though for now anyway..

TyrealHu commented 1 year ago

All right, maybe we can support import-assertions in acorn-typescript in the future

TyrealHu commented 1 year ago

I think this issue could be a feature request

TyrealHu commented 1 year ago

support in version acorn-typescript@1.4.6