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

[fix] update preprocessor types #6904

Merged
merged 2 commits into from
Nov 9, 2021
Merged

[fix] update preprocessor types #6904

merged 2 commits into from
Nov 9, 2021

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Nov 4, 2021

Fix preprocessor types:

  • Allow Preprocessor to return void
  • Make MarkupPreprocessor filename arg optional (always has been optional)

Refactor src/compiler/preprocess/index.ts too ensuring filename is nullable.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with [feat], [fix], [chore], or [docs].
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@dummdidumm
Copy link
Member

Why the void return type? Was that ever allowed, or when is this useful? The other things look fine 👍

@bluwy
Copy link
Member Author

bluwy commented Nov 4, 2021

Yeah returning nothing for preprocessors were allowed for a long time. From the code, when we run preprocess, it would check whether we return something, otherwise bail out:

if (processed) {

if (!processed) return no_change();

Returning nothing is often used to early out on preprocessing due to certain fast checks, plus it would give a small perf boost too internally.

Another example in vite-plugin-svelte, we had to use ts-expect-error to be able to suppress typescript returning void: code

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks!

@Conduitry Conduitry merged commit bc34862 into master Nov 9, 2021
@dummdidumm dummdidumm deleted the fix-preprocess-types branch November 9, 2021 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants