Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Transpilation Error with fuse-box 4.0.0 (or maybe I'm simply blind) #2024

Open
mqualizz opened this issue Oct 4, 2021 · 1 comment
Open

Comments

@mqualizz
Copy link

mqualizz commented Oct 4, 2021

I'm running into an issue where fuse-box isn't correctly transpiling statements like:
export const { A, B } = .... The exports are completely ignored.

If I do:

const { A, B } = ...
export { A, B };

then things seem fine.

Example:

fuse.ts

import {fusebox} from "fuse-box";

const fuse = fusebox({
    entry: "src/index.ts",
    target: "browser",
    devServer: {
        enabled: true,
        httpServer: {
            port: 8080
        },
        hmrServer: {
            port: 8081
        }
    },
    webIndex: true,

    // Enable hot module replace
    hmr: true,
});

fuse.runDev({
    bundles: {
        distRoot: "dist",
        app: "bundle.js"
    }
});

src/Test.ts

const Stuff = {
    A: 1,
    B: () => { console.log("B") },
    C: () => { console.log("C") }
}

export const { B, C } = Stuff;

export const Doit = () => { B() }

src/index.ts

import { Doit } from "./Test";

Doit();

Relevant snippets from generated bundle.js

__fuse.bundle({

// src/index.ts @1
1: function(__fusereq, exports, module){
exports.__esModule = true;
var Test_1 = __fusereq(4);
Test_1.Doit();

},

and

// src/Test.ts @4
4: function(__fusereq, exports, module){
exports.__esModule = true;
const Stuff = {
  A: 1,
  B: () => {
    console.log("B");
  },
  C: () => {
    console.log("C");
  }
};
exports.undefined = Stuff;
exports.Doit = () => {
  B();
};

},

Issues:

  1. exports.undefined = Stuff -- stuff wasn't exported in the original code
  2. missing exports and corrected references for export { B, C } = Stuff

Further, I get the following error when I try to open this in the browser:

index.ts:3 Uncaught TypeError: Test_1.Doit is not a function
    at 1 (index.ts:3)
    at Object.f.r (bundle.js:24)
    at Test.ts:9
    at Object.f.bundle (bundle.js:10)
    at bundle.js:28
@nchanged
Copy link
Contributor

nchanged commented Oct 9, 2021

It's definitely a bug, and it is supposed to look like this:

exports.B = Stuff.B, exports.C = Stuff.C;
const Doit = () => { (0, exports.B)(); };
exports.Doit = Doit;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants