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 for optional class property #34

Closed bpstrngr closed 1 year ago

bpstrngr commented 1 year ago

Another error coming from parsing Rollup's src/Graph.ts:

export default class Graph {
        readonly acornParser: typeof acorn.Parser;
        readonly cachedModules = new Map<string, ModuleJSON>();
        readonly deoptimizationTracker = new PathTracker();
        entryModules: Module[] = [];
        readonly fileOperationQueue: Queue;
        readonly moduleLoader: ModuleLoader;
        readonly modulesById = new Map<string, Module | ExternalModule>();
        needsTreeshakingPass = false;
        phase: BuildPhase = BuildPhase.LOAD_AND_PARSE;
        readonly pluginDriver: PluginDriver;
        readonly pureFunctions: PureFunctions;
        readonly scope = new GlobalScope();
        readonly watchFiles: Record<string, true> = Object.create(null);
        watchMode = false;

        private readonly externalModules: ExternalModule[] = [];
        private implicitEntryModules: Module[] = [];
        private modules: Module[] = [];
        private declare pluginCache?: Record<string, SerializablePluginCache>;
}
                                   ^

throwing:

SyntaxError: Unexpected token (72: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 pp.semicolon (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/parseutil.js:88:59)
    at pp.parseClassField (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/haverbeke_2012_acorn/0/acorn/src/statement.js:747:8)
    at TypeScriptParser.parseClassField (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:3730:30)
    at callParseClassMemberWithIsStatic (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:3904:34)
    at TypeScriptParser.tsInAmbientContext (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:2995:28)
    at TypeScriptParser.parseClassElement (file:///mnt/chromeos/GoogleDrive/MyDrive/blik/tyrealhu_2023_acorn_typescript.js:3910:26) {
  pos: 2348,
  loc: Position { line: 72, column: 28 },
  raisedAt: 2349
}
bpstrngr commented 1 year ago

another example (src/Module.ts):

export default class Module {
        readonly alternativeReexportModules = new Map<Variable, Module>();
        readonly chunkFileNames = new Set<string>();
        declare namespace: NamespaceVariable;
        needsExportShim = false;
        declare originalCode: string;
        declare originalSourcemap: ExistingDecodedSourceMap | null;
        preserveSignature: PreserveEntrySignaturesOption;
        readonly sourcesWithAssertions = new Map<string, Record<string, string>>();
        declare transformFiles?: EmittedFile[];
}
                              ^
TyrealHu commented 1 year ago

Had been fixed in version 1.4.3