volarjs / volar.js

💙🌊
https://volarjs.dev/
MIT License
970 stars 47 forks source link

`sfc.scriptSetup.ast` without `getStart` & `forEachChild` method when use vue-tsc to check type #165

Closed zhiyuanzmj closed 4 months ago

zhiyuanzmj commented 4 months ago

When I use vue-tsc to check type, The sfc.scriptSetup.ast has no getStart & forEachChild method. But it works fine in vue's vscode plugin.

const plugin = ({
  modules: { typescript: ts },
  vueCompilerOptions,
}) => {
  return {
    name: 'test-souce-file',
    version: 2,
    resolveEmbeddedCode(fileName, sfc, embeddedFile) {
      // Will be undefined when runing the "vue-tsc --noEmit" command
      console.log([
        sfc.scriptSetup?.ast.getStart,
        sfc.scriptSetup?.ast.getEnd,
        ts.createSourceFile('a.ts', 'var a = 1', 99).forEachChild
      ])
    },
  }
}
johnsoncodehk commented 4 months ago

In 2.0 you need to replace Node.getStart, Node.forEachChild with the following.

zhiyuanzmj commented 4 months ago

I found some another issues when I upgraded @vue-macros/volar to volar2.0.