Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Both modes use the existing lexer and assume valid JavaScript input.
They do not execute the source or validate the complete JavaScript grammar.

Extended mode detects literal names in `Object.defineProperty` calls regardless of the descriptor expression or getter body.
This includes TypeScript default reexports whose getters call `__importDefault`.
It also detects names in object literals passed to `Object.defineProperties(exports, ...)` or assigned to `module.exports`.
Object values can contain arbitrary expressions.
Methods, accessors, and computed string literal keys contribute their names.
Expand Down
25 changes: 25 additions & 0 deletions test/extended.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,31 @@ suite('Extended parsing', () => {
'fixture.cjs', options), { exports: ['name'], reexports: [] });
});

for (const helper of ['__importDefault', 'tslib_1.__importDefault']) {
for (const predeclare of [false, true]) {
test(`TypeScript default reexports with ${helper} and predeclaration ${predeclare}`, () => {
const source = `
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
${helper === '__importDefault' ? '' : 'var tslib_1 = require("tslib");'}
Object.defineProperty(exports, "__esModule", { value: true });
${predeclare ? 'exports.bar = void 0;' : ''}
var bar_1 = require("./bar");
Object.defineProperty(exports, "bar", {
enumerable: true, get: function () { return ${helper}(bar_1).default; }
});
`;
assert.deepEqual(parse(source, 'typescript.cjs'), { exports: ['__esModule'], reexports: [] });
assert.deepEqual(parse(source, 'typescript.cjs', options),
{ exports: ['__esModule', 'bar'], reexports: [] });
assert.deepEqual(parse(source, 'typescript.cjs', { mode: 'default' }),
{ exports: ['__esModule'], reexports: [] });
});
}
}

test('webpack parenthesized descriptors', () => {
assert.deepEqual(parse(`Object.defineProperty(exports, 'BaseWatchPlugin', ({
enumerable: true, get: function () { return _BaseWatchPlugin.default; }
Expand Down
Loading