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

Named default import symbols get incorrectly renamed #9868

Closed
seivan opened this issue Mar 23, 2021 · 6 comments
Closed

Named default import symbols get incorrectly renamed #9868

seivan opened this issue Mar 23, 2021 · 6 comments
Labels
bug Something isn't working swc related to swc (bundling/transpiling)

Comments

@seivan
Copy link

seivan commented Mar 23, 2021

There seems to be a distinction between the names of an exported value between deno run and deno compile when importing an object and using it as a key in a new object

In 'https://deno.land/x/yargs_parser@v20.2.4-deno/deno.ts'

export default yargsParser

In 'https://deno.land/x/yargs/deno.ts'

import Parser from 'https://deno.land/x/yargs_parser@v20.2.4-deno/deno.ts';

const newObject = {
 Parser
}

This will create {yargParser: Parser} in deno compile which is unexpected.

Expected value would be {Parser: Parser} which is the result you get with deno run

Related: yargs/yargs#1891

@kitsonk kitsonk added the needs info needs further information to be properly triaged label Mar 23, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Mar 23, 2021

What problem is this causing?

When you bundle ESM modules, some renaming has to take place. Modules are bundled before they can be used in deno compile.

@seivan
Copy link
Author

seivan commented Mar 23, 2021

@kitsonk Sorry for being unclear, I rephrased the issue.
The expectation is that this should work

const someObj = {
 Parser
 }
 
 assert(someObj.Parser)

both in deno run and deno compile

@kitsonk kitsonk added bug Something isn't working swc related to swc (bundling/transpiling) and removed needs info needs further information to be properly triaged labels Mar 23, 2021
@kitsonk kitsonk changed the title Difference between compile and run when inferring name of imported objects Named default import symbols get incorrectly renamed Mar 23, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Mar 23, 2021

cc/ @kdy1

Looks like some default import symbols get renamed, which then causes unexpected/breaking changes in the downstream code.

@nayeemrmn
Copy link
Collaborator

Occurs with any aliased imports:

import { foo } from './temp2.ts';

console.log({
  foo
});
// temp2.ts
const bar = 1;
export { bar as foo };

Bundle output:

console.log({
    bar: 1
});

Expected:

console.log({
    foo: 1
});

SWC should ensure { foo } is treated the same as { foo: foo }.

kdy1 added a commit to kdy1/swc that referenced this issue Mar 26, 2021
kdy1 added a commit to swc-project/swc that referenced this issue Mar 26, 2021
@kdy1
Copy link

kdy1 commented Mar 26, 2021

Fixed on upstream. (Published a new version)

kdy1 added a commit to kdy1/swc that referenced this issue Mar 31, 2021
@bartlomieju
Copy link
Member

Fixed in 1.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working swc related to swc (bundling/transpiling)
Projects
None yet
Development

No branches or pull requests

5 participants