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

Compiler: sveltePath option is broken #6834

Closed
ebrehault opened this issue Oct 11, 2021 · 2 comments · Fixed by #6842
Closed

Compiler: sveltePath option is broken #6834

ebrehault opened this issue Oct 11, 2021 · 2 comments · Fixed by #6842
Labels
bug compiler Changes relating to the compiler

Comments

@ebrehault
Copy link

Describe the bug

When using the compile function from svelte/compiler with the sveltePath option, the generated JS source does not apply the provided path to all the Svelte imports.
For example, the following Svelte source:

<script>
    import { onDestroy } from 'svelte';
</script>

will result in:

/* generated by Svelte v3.43.1 */
import { SvelteComponent, init, safe_not_equal } from "/my/path/svelte/internal";

import { onDestroy } from 'svelte';

class Component extends SvelteComponent {
        constructor(options) {
                super();
                init(this, options, null, null, safe_not_equal, {});
        }
}

export default Component;

As we can see, onDestroy is imported from svelte and not from /my/path/svelte.

After digging a bit, it seems the bug appears with svelte@3.39 (3.38.3 was fine), and I suspect it is caused by this commit c550f60#diff-d45b1ba306d2b3502800078a886e7ad894d1828144409e58bf035bee8767b387 but I haven't ben able to identify the exact problem.

Reproduction

Create test.js like this:

const svelte = require('svelte/compiler');
const { js } = svelte.compile(
    `<script>
import { onDestroy } from 'svelte';
</script>`,
    {
        sveltePath: '/my/path/svelte',
    },
);
console.log(js.code);

and run node test.js

Logs

No response

System Info

System:
    OS: macOS 11.6
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 137.51 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.0 - ~/.nvm/versions/node/v14.17.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.17.0/bin/yarn
    npm: 6.14.13 - ~/.nvm/versions/node/v14.17.0/bin/npm
  Browsers:
    Chrome: 94.0.4606.81
    Firefox: 92.0.1
    Safari: 15.0

Severity

blocking an upgrade

@Conduitry Conduitry added bug compiler Changes relating to the compiler labels Oct 11, 2021
@RaiVaibhav
Copy link
Contributor

RaiVaibhav commented Oct 12, 2021

Problem is that print take the raw value if exists to output the generated code, changing code to

	imports.forEach(node => {
		node.source.value = edit_source(node.source.value, sveltePath);
		node.source.raw = JSON.stringify(node.source.value);
	});

solves the issue.

RaiVaibhav added a commit to RaiVaibhav/svelte that referenced this issue Oct 12, 2021
@Conduitry
Copy link
Member

This should be fixed in 3.43.2 - thanks for the report @ebrehault and thanks for the fix @RaiVaibhav!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug compiler Changes relating to the compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants