Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 9, 2025

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 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 Copilot AI requested a review from andrewbranch June 9, 2025 22:58
Copilot finished work on behalf of andrewbranch June 9, 2025 22:59
@jakebailey jakebailey deleted the copilot/fix-1119 branch June 24, 2025 23:56
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