Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zhiyuanzmj opened this issue Apr 26, 2024 · 2 comments
Labels
question Further information is requested

Comments

@zhiyuanzmj
Copy link

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
Copy link
Member

johnsoncodehk commented Apr 30, 2024

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

  • node.forEachChild(cb) -> ts.forEachChild(node, cb)

  • node.getStart(sourceFile) -> (ts as any).getTokenPosOfNode(node, sourceFile)
    Or -> require('@vue/language-core').getStartEnd(ts, node, sourceFile).start

@johnsoncodehk johnsoncodehk added the question Further information is requested label Apr 30, 2024
@zhiyuanzmj
Copy link
Author

zhiyuanzmj commented May 1, 2024

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

  • ts.isJsxExpression -> node.kind === 294
  • node.expression.text -> node.expression.escapedText
  • node.getText(sourceFile) ->
sfc.scriptSetup.content.slice(
  (ts as any).getTokenPosOfNode(node, sfc.scriptSetup.ast),
  node.end
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants