nodejs / nodejs/cjs-module-lexer
Not work well with TypeScript export default as output
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 262
- Forks
- 31
- Avg merge
- 9d 2h
- Merged PRs (30d)
- 5
Description
Hi,
TypeScript export default as syntax seems not working with this module. Considering the following TS code:
export { default as fs } from 'fs';
Test its output with cjs-module-lexer:
const { parse } = require('cjs-module-lexer');
const result = parse(`
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fs = void 0;
var fs_1 = require("fs");
Object.defineProperty(exports, "fs", { enumerable: true, get: function () { return __importDefault(fs_1).default; } });
`);
console.log(result);
It prints:
{ exports: [ '__esModule' ], reexports: [] }
fs do not be considered as exports in the above case.
And I also figure out that changing the place of the __importDefault call
var fs_1 = require("fs");
Object.defineProperty(exports, "fs", { enumerable: true, get: function () { return __importDefault(fs_1).default; } });
to something like this one (what babel does):
var fs_1 = __importDefault(require("fs"));
Object.defineProperty(exports, "fs", { enumerable: true, get: function () { return fs_1.default; } });
The result will become:
{ exports: [ '__esModule', 'fs'], reexports: [] }
Is this an expected behavior?
Ref:
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 by running the shown cjs-module-lexer parse example and compare its result for the TypeScript-generated and Babel-generated output forms. Trace how the parser handles the Object.defineProperty getter, then establish the expected export result and cover that behavior with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100