Skip to content

Commit

Permalink
fix(shaker): re-exports compiled by tsc not working (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabbeV committed Oct 17, 2022
1 parent 2906ec1 commit 3c1886a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/babel/src/module.ts
Expand Up @@ -223,11 +223,14 @@ class Module {

return true;
},
getOwnPropertyDescriptor() {
return {
enumerable: true,
configurable: true,
};
getOwnPropertyDescriptor: (target, key) => {
if (this.#lazyValues.has(key))
return {
enumerable: true,
configurable: true,
};

return undefined;
},
});

Expand Down
@@ -0,0 +1,5 @@
"use strict";
exports.__esModule = true;
exports.bar = exports.foo = void 0;
exports.foo = 'foo';
exports.bar = 'bar';
17 changes: 17 additions & 0 deletions packages/testkit/src/__fixtures__/ts-compiled-re-exports/index.js
@@ -0,0 +1,17 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
exports.__esModule = true;
__exportStar(require("./constants"), exports);
12 changes: 12 additions & 0 deletions packages/testkit/src/module.test.ts
Expand Up @@ -291,3 +291,15 @@ it('correctly processes export declarations in strict mode', () => {
expect(mod.id).toBe(filename);
expect(mod.filename).toBe(filename);
});

it('export * compiled by typescript to commonjs works', () => {
const mod = createModule(getFileName(), options);

mod.evaluate(dedent`
const { foo } = require('./ts-compiled-re-exports');
module.exports = foo;
`);

expect(mod.exports).toBe('foo');
});

0 comments on commit 3c1886a

Please sign in to comment.