Skip to content

Port TypeScript PR #60262: Include non-enumerable keys in __importStar helper#1124

Closed
andrewbranch with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-1119
Closed

Port TypeScript PR #60262: Include non-enumerable keys in __importStar helper#1124
andrewbranch with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-1119

Conversation

Copilot AI commented Jun 9, 2025

Copy link
Copy Markdown
Contributor

This PR ports the changes from microsoft/TypeScript#60262 to include non-enumerable properties when importing modules with import * as syntax.

Problem

The previous __importStar helper only included enumerable properties when performing star imports, which could miss important non-enumerable properties that should be part of the imported namespace.

Solution

Updated the __importStar helper to use Object.getOwnPropertyNames() (with fallback) instead of a simple for...in loop. This ensures both enumerable and non-enumerable properties are included.

Before:

var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};

After:

var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();

Changes Made

  • Updated importStarHelper.Text in internal/printer/helpers.go
  • Updated test expectations in internal/transformers/commonjsmodule_test.go
  • Accepted baseline changes across all affected test files

Test Results

  • ✅ All tests pass
  • ✅ Many baseline diff files completely eliminated (28 files deleted)
  • ✅ Remaining diff files significantly reduced
  • ✅ Net result: 126 files changed, 1515 insertions, 2709 deletions

This change ensures the Go port maintains compatibility with the latest TypeScript behavior for star imports.

Fixes #1119.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…r helper

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Copilot AI changed the title [WIP] Port TypeScript PR #60262: Include non-enumerable keys in __importStar helper Port TypeScript PR #60262: Include non-enumerable keys in __importStar helper Jun 9, 2025
Copilot AI requested a review from andrewbranch June 9, 2025 22:58
@jakebailey
jakebailey deleted the copilot/fix-1119 branch June 24, 2025 23:56
Copilot AI added a commit that referenced this pull request Feb 5, 2026
For JavaScript CommonJS modules with `module.exports = { ... }`,
the binder creates an export= symbol with SymbolFlagsProperty, not
SymbolFlagsValueModule. This was causing TS2497 to be emitted even
when esModuleInterop was enabled.

The fix adds a check in resolveESModuleSymbol to skip the error for
JavaScript files when esModuleInterop is explicitly enabled.

Fixes #1124 and related issue #1054

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port TypeScript PR #60262: Include non-enumerable keys in __importStar helper

2 participants