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

Svelte and TypeScript and Bun issues #555

Open
dhbaird opened this issue Nov 6, 2022 · 2 comments
Open

Svelte and TypeScript and Bun issues #555

dhbaird opened this issue Nov 6, 2022 · 2 comments

Comments

@dhbaird
Copy link

dhbaird commented Nov 6, 2022

The svelte-preprocessor seems to have two issues when used with Bun. This might also be a Bun or other issue; I'm not sure yet :)

  1. The module doesn't import the same way in node vs bun:
// node
const sveltePreprocess = await import('svelte-preprocess');
sveltePreprocess.default({});

// bun
const sveltePreprocess = await import('svelte-preprocess');
sveltePreprocess.default()({});
  1. When used to preprocess some text, the bun version ends up escaping the escapes (UPDATE: this was a Bun issue, fixed in Bun upstream, see comments below in this issue):
// a.js
const { preprocess } = await import("svelte/compiler");
const sveltePreprocess = await import('svelte-preprocess');
(async ({ source }) => {
    const x = await preprocess(
        source,
        [sveltePreprocess.default({})],
        { filename: "<inline>", });
    console.log("x.code =", JSON.stringify(x.code));
})({source: `
<script lang="ts">
let x : int = 1;
</script>
`});

// b.js
const { preprocess } = await import("svelte/compiler");
const sveltePreprocess = await import('svelte-preprocess');
(async ({ source }) => {
    const x = await preprocess(
        source,
        [sveltePreprocess.default()({})],
        { filename: "<inline>", });
    console.log("x.code =", JSON.stringify(x.code));
})({source: `
<script lang="ts">
let x : int = 1;
</script>
`});
node a.js ; bun b.js
// >>>
// x.code = "\n<script lang=\"ts\">let x = 1;\n</script>\n"  <-- expected this
// x.code = "\n<script lang=\"ts\">let x = 1;\\n</script>\n"  <-- but got extra "\"

Versions:

  • node 16.17.0
  • bun 0.2.2
  • svelte-preprocess 4.10.7
  • svelte 3.52.0
  • typescript 4.8.2

EDIT: added: typescript 4.8.2

@dhbaird
Copy link
Author

dhbaird commented Nov 7, 2022

The extra slash gets inserted in the call to typescript transpileModule().

@dhbaird
Copy link
Author

dhbaird commented Nov 8, 2022

os.EOL yields different values in node vs bun and seems to be the source of the newline problem:

  • "\n" in node
  • "\\n" in bun

Quick reproducer:

echo 'console.log(JSON.stringify(require("os").EOL));' > oseol.cjs ; node oseol.cjs ; bun oseol.cjs
# >>>
# "\n"
# "\\n"

Quick workaround, set this:
tsconfig.json --> { "compilerOptions": { "newLine": "lf" } }

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

No branches or pull requests

1 participant