TyrealHu / acorn-typescript

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

compatibility with `acorn.walk` (visitor types) #57

Open thescientist13 opened 5 months ago

thescientist13 commented 5 months ago

With the following bit of code, I ran into this issue when trying to walk this with acorn.walk

interface User {
  name: string;
}

export default class Greeting extends HTMLElement {
  connectedCallback() {
    const user: User = {
      name: this.getAttribute('name') || 'World'
    };

    this.innerHTML = `
      <h3>Hello ${user.name}!</h3>
    `;
  }
}
file:///Users/owenbuckley/Workspace/github/acorn-ts-example/node_modules/acorn-walk/dist/walk.mjs:23
    baseVisitor[type](node, st, c);
                     ^

TypeError: baseVisitor[type] is not a function
    at c (file:///Users/owenbuckley/Workspace/github/acorn-ts-example/node_modules/acorn-walk/dist/walk.mjs:23:22)
    at Module.simple (file:///Users/owenbuckley/Workspace/github/acorn-ts-example/node_modules/acorn-walk/dist/walk.mjs:25:5)
    at file:///Users/owenbuckley/Workspace/github/acorn-ts-example/acorn-ts.js:18:6
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12)

Unless acorn.walk is initialized with this option to explicitly support the usage of interface, which is similar to an observation I saw when using acorn-jsx plugin

walk.simple(node, {}, {
  ...walk.base,
  TSInterfaceDeclaration: () => { }
});

Is this expected? Is there some list of these visitor types available somewhere I should be using?

Here's a basic repro repo you can check out https://github.com/thescientist13/acorn-ts-example

Thanks!