fix(ssr): `this` in exported function should be `undefined`
Description
this in exported function should be undefined but it was not.
reproduction in Node: https://stackblitz.com/edit/node-7bhlmx?file=index.js (make sure you run it locally, it works differently in stackblitz https://github.com/stackblitz/webcontainer-core/issues/1532)
I used an identity function to avoid the this binding. (0, foo.bar) can be used as well, but I thought it will be difficult for the same reason with https://github.com/vitejs/vite/pull/3682.
Run & review this pull request in StackBlitz Codeflow.
/ecosystem-ci run
📝 Ran ecosystem CI on 8549d55: Open
| suite | result | latest scheduled |
|---|---|---|
| redwoodjs | :x: failure | :white_check_mark: success |
| remix | :x: failure | :x: failure |
| sveltekit | :x: failure | :x: failure |
| vike | :x: failure | :x: failure |
| vite-environment-examples | :x: failure | :white_check_mark: success |
| vitest | :x: failure | :white_check_mark: success |
:white_check_mark: analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, storybook, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress
/ecosystem-ci run
vite-environment-examples and vitest are failing with snapshot diff caused by stacktrace change (Module.foo is now foo) or the output change which is expected.
redwoodjs fail should be fixed by the last commit.
📝 Ran ecosystem CI on 17be758: Open
| suite | result | latest scheduled |
|---|---|---|
| remix | :x: failure | :x: failure |
| sveltekit | :x: failure | :x: failure |
| vike | :x: failure | :x: failure |
| vite-environment-examples | :x: failure | :white_check_mark: success |
| vitest | :x: failure | :white_check_mark: success |
:white_check_mark: analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, redwoodjs, storybook, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress
This change makes sense, but it might be affecting Vitest coverage a bit. Other than stacktrace, I found one coverage test is failing when testing with a local build. It's only one test case with Vue (specifically this one pnpm -C test/coverage-test test /vue.test -- --project v8), so it might be an issue in different parts though. I'll check with the team.
@AriPerkkio What do you mean by left on source map? Is it the mapping from __vite_ssr_identity__( to the space on the original source in this example with sourcemap visualizer? If so, it is not intentional. That said, I don't know how to do that in a performant way, I think we need to improve magic-string to achieve that.