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

Missing type in Svelte compiler AST #14246

Open
Ice-mourne opened this issue Nov 10, 2024 · 4 comments
Open

Missing type in Svelte compiler AST #14246

Ice-mourne opened this issue Nov 10, 2024 · 4 comments

Comments

@Ice-mourne
Copy link

Describe the bug

The script part of AST specifically imports are missing importKind type

Reproduction

import { parse } from 'svelte/compiler';

const ast = parse(`
<script lang="ts">
  import type { Snippet } from 'svelte'
  import { mount } from 'svelte'
</script>
`, { modern: true })

// narrow down type to import declarations
if (ast.instance?.content.body[0].type === 'ImportDeclaration') {
  // this gives error // Property 'importKind' does not exist on type 'ImportDeclaration'.
  ast.instance?.content.body[0].importKind
  
  // But if we log it we can see it dose have them
  console.log(ast.instance?.content.body[0].importKind) // type
  console.log(ast.instance?.content.body[1].importKind) // value
}

Logs

No response

System Info

Not important

Severity

annoyance

@dummdidumm
Copy link
Member

This part is somewhat private API/ part of the acorn TS plugin, which may change . I'm not sure there are typings for it, and I'm not sure if we want to expose them

@Ice-mourne
Copy link
Author

Ice-mourne commented Nov 10, 2024

It's not something I'm importing from somewhere I shouldn't it's part or parse function and it even has documentation https://svelte.dev/docs/svelte/svelte-compiler#parse

I feel like something like that should have proper types I have seen svelte already adding extra types but was not able to figure out how I can do that too

@xeho91
Copy link
Contributor

xeho91 commented Nov 11, 2024

As a temporary workaround, you could use types from @typescript-eslint/typescript-estree.

Credits goes to @manuel3108 via his work on the Rich-Harris/esrap#13

@manuel3108
Copy link
Member

manuel3108 commented Nov 11, 2024

As a temporary workaround, you could use types from @typescript-eslint/typescript-estree.

Although, this shouldn't go without saying that these types are not fully compatible. Those are just the closest types we have available right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants