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

jco exports uses invalid alias based on WIT world package name #292

Closed
DougAnderson444 opened this issue Dec 6, 2023 · 7 comments
Closed

Comments

@DougAnderson444
Copy link
Contributor

Hi, it's me again

Given the following WIT that exports an interface named reactivity:

package wurbo:vowels;

interface reactivity {
  render: func(name: string) -> string;
  listen: func();
}

world example {
    import imports;
    export reactivity;
}

the resulting ES module code is invalid because the world package name is also used:

// ... 

await $init;
const reactivity = {
  listen: listen,
  render: render,
  
};

export { reactivity, reactivity as wurbo:vowels/reactivity };
//                                  ^^^^^^^^^^^^^^^^^^^______invalid javascript

The : is invalid JS syntax unfortunately

@DougAnderson444
Copy link
Contributor Author

The workaround is to not use export interfaces, but it's probably better to just remove the invalid alias?

@guybedford
Copy link
Collaborator

export { reactivity, reactivity as "wurbo:vowels/reactivity" }; is very much valid JavaScript, I'm pretty sure you'll find it's quoted.

The problem is that TypeScript doesn't support the above. We have a flag for supporting this via --no-namespaced-exports, at least until TypeScript adds support in microsoft/TypeScript#40594.

@DougAnderson444
Copy link
Contributor Author

No Typescript was involved at all in this process. The export was definitely not in "quotes" in my code, I wonder if Rollup removed it during the bundling process? I will try the flag and see what happens, thank you

@DougAnderson444
Copy link
Contributor Author

Tried the flag and it works nicely thank you Guy.

You were right, jco outputs the export in quotes and Rollup is removing them when bundling the files together. Looks like this is an issue with Rollup not jco! Yeah!

I'll close and shift this to Rollup

@guybedford
Copy link
Collaborator

Thanks for following up on the Rollup issue here!

@DougAnderson444
Copy link
Contributor Author

This issue has been resolved via rollup/rollup#5298 as part of rollup@4.9.0.

@James-Mart
Copy link

The problem is that TypeScript doesn't support the above. We have a flag for supporting this via --no-namespaced-exports, at least until TypeScript adds support in microsoft/TypeScript#40594.

FYI microsoft/TypeScript#58640
CC @guybedford

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

3 participants