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

Preprocessors must be ran before svelte2tsx #2447

Closed
ottomated opened this issue Jul 26, 2024 · 1 comment
Closed

Preprocessors must be ran before svelte2tsx #2447

ottomated opened this issue Jul 26, 2024 · 1 comment
Labels
bug Something isn't working limitation Constraints of the existing architecture make this hard to fix

Comments

@ottomated
Copy link

Describe the bug

If a svelte preprocessor edits the code to, for example, change the value of a $props() rune, the language server will not reflect that change. I believe this is because svelte2tsx is receiving the original unprocessed code.

Reproduction

// preprocess.js

export default function preprocess() {
  return {
    script: ({ content }) => {
      return {
        code: 'const { test }: { test: string } = $props();\n' + content
      }
    }
  };
}
// svelte.config.js
import adapter from '@sveltejs/adapter-auto';
import preprocess from './preprocess.js';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: [preprocess(), vitePreprocess()],
  kit: { adapter: adapter() },
};

export default config;
<!-- +page.svelte -->
<script>
  import Foo from './Foo.svelte';
</script>

<Foo test="foo" />
<!-- ^~~~ Type 'string' is not assignable to type 'never'. ts(2322) -->
<!-- Foo.svelte -->
<script>
</script>

{test}

Expected behaviour

Since the above example compiles and runs, the language server output should match it.

System Info

  • OS: Linux
  • IDE: VSCode

Which package is the issue about?

svelte-language-server, svelte2tsx

Additional Information, eg. Screenshots

No response

@ottomated ottomated added the bug Something isn't working label Jul 26, 2024
@jasonlyu123
Copy link
Member

Duplicate of #1567, #339. Preprocess API is asynchronous but TypeScript API requires it to be synchronous. There is also no way to tell if the preprocess is intended to transpile typescript into javascript or add stuff to typescript code.

@jasonlyu123 jasonlyu123 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2024
@jasonlyu123 jasonlyu123 added the limitation Constraints of the existing architecture make this hard to fix label Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working limitation Constraints of the existing architecture make this hard to fix
Projects
None yet
Development

No branches or pull requests

2 participants