codesandbox / codesandbox/codesandbox-client
Default exported function not being hoisted
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 13.6k
- Forks
- 2.4k
- Avg merge
- 6d 19h
- Merged PRs (30d)
- 2
Description
🐛 bug report
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project
adheres to. - I have searched the issue tracker for an issue that matches the one I want
to file, without success.
Description of the problem
Default function exports are not hoisted; in contrast named function exports are correctly hoisted.
How has this issue affected you? What are you trying to accomplish?
Circular import involving default exported function will break.
As default exported functions are not hoisted, one of the ES module will get undefined when accessing default export from another ES module.
To Reproduce
export default function test() {}
Produces:
Object.defineProperty(exports, "__esModule", {
value: true
});
function test() {}
exports.default = test;
Expected result:
exports.default = void 0;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = test;
function test() {}
Appearently, the positionToInsert logic found for named function exports in convert-esmodule.ts#L297 is missing for default function exports convert-esmodule.ts#L420
Link to sandbox: link (optional)
Your Environment
| Software | Name/Version |
|---|---|
| Сodesandbox | |
| Browser | |
| Operating System |
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.
Research direction
Start in packages/app/src/sandbox/eval/transpilers/babel/ast/convert-esmodule.ts, comparing the positionToInsert handling near line 297 for named exports with the default-export path near line 420. Confirm that a default function export is initialized before the function declaration in the generated output, matching the expected ordering shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100