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

deno compile keeps failing with export anonimous default functions #9346

Closed
oscarotero opened this issue Jan 31, 2021 · 2 comments
Closed

deno compile keeps failing with export anonimous default functions #9346

oscarotero opened this issue Jan 31, 2021 · 2 comments
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)

Comments

@oscarotero
Copy link
Contributor

The bug reported here #9250 is not fixed yet.

I have the following script:

import log from "./log.js";

cli();

export default async function cli() {
    log("It works!");
}

That imports the following code:

export default function (message) {
  console.log(message);
}

After compile and run it, I get this error:

error: ReferenceError: Cannot access '__default' before initialization
    at cli (file://$deno$/bundle.js:6:5)
    at file://$deno$/bundle.js:1:1

Checking with deno bundle the output code is the following:

cli();
const __default = function(message) {
    console.log(message);
};
async function cli() {
    __default("It works!");
}
export { cli as default };

As you can see, cli() is executed before define __default.

If I set a name to the function in log.js:

export default function log (message) {
  console.log(message);
}

The ouput code of deno bundle is a bit different:

function log(message) {
    console.log(message);
}
cli();
async function cli() {
    log("It works!");
}
export { cli as default };

As you can see, the function is defined before cli(), its name is log instead __default and it's declared instead assigned to a variable. As possible solution could be build a similar code, independently of whether the function has name or not:

function __default(message) {
    console.log(message);
};
cli();
async function cli() {
    __default("It works!");
}
export { cli as default };
kdy1 added a commit to kdy1/swc that referenced this issue Feb 1, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Feb 1, 2021
@kdy1
Copy link

kdy1 commented Feb 1, 2021

FIxed on upstream

@kitsonk kitsonk added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Feb 3, 2021
@bartlomieju
Copy link
Member

Done in #9374

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

No branches or pull requests

4 participants