Object destructuring inside namespaces causes other exports to disappear
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- typescript, vite
- Domain
- build-system
Research direction
Reproduce the namespace and object-destructuring example in both a .ts build and a .tsx build using vite-plugin-solid, then compare the generated output. Trace why the transformed .tsx namespace omits A.a, and consider the issue resolved when all declared exports remain available at runtime.
Written by the indexing model from the issue text.
Description
I have a file containing the following code:
namespace B {
export function c() { }
}
export namespace A {
export const { c } = B;
export function a() { }
export function b() { }
}
console.log(A);
When building it with vite it gets turned to this:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.alfa = {}));
})(this, (function (exports) { 'use strict';
var B;
((B2) => {
function c() {
}
B2.c = c;
})(B || (B = {}));
exports.A = void 0;
((A2) => {
({ c: A2.c } = B);
function a() {
}
A2.a = a;
function b() {
}
A2.b = b;
})(exports.A || (exports.A = {}));
console.log(exports.A);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
}));
And if I run it, it logs { c: [Function: c], a: [Function: a], b: [Function: b] }.
If I use vite-plugin-solid AND the file is a .tsx, the build result is the following:
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.alfa = {}));
})(this, (function (exports) { 'use strict';
let B;
(function (_B) {
function c() {}
_B.c = c;
})(B || (B = {}));
exports.A = void 0;
(function (_A) {
const {
c
} = B;
_A.c = c;
function b() {}
_A.b = b;
})(exports.A || (exports.A = {}));
console.log(exports.A);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
}));
And it outputs { c: [Function: c], b: [Function: b] } when ran.
Why does "A.a" gets removed from the namespace?
Moreover, why does changing the code like this works?
namespace B {
export function c() { }
}
export namespace A {
export function a() { }
export function b() { }
export const { c } = B; // ← Moved on the bottom of the namespace
}
console.log(A);
- Dominant language
- TypeScript
- Stars
- 520
- Forks
- 70
- Avg merge
- 23h 35m
- Merged PRs (30d)
- 39
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from solidjs/solid-vite-plugin
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
solidjs/solid-vite-plugin#205 · 1 comment · 2 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
solidjs/solid-vite-plugin#369 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
solidjs/solid-vite-plugin#328 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
solidjs/solid-vite-plugin#308 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
solidjs/solid-vite-plugin#262 · 2 comments ·
All issues in solidjs/solid-vite-plugin
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·