Skip to content

fix(es/transforms/module/common_js): fix duplicate named exports iss… #1846

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

Merged
merged 11 commits into from
Jun 29, 2021
Merged

fix(es/transforms/module/common_js): fix duplicate named exports iss… #1846

merged 11 commits into from
Jun 29, 2021

Conversation

@CLAassistant
Copy link

CLAassistant commented Jun 24, 2021

CLA assistant check
All committers have signed the CLA.

@kdy1
Copy link
Member

kdy1 commented Jun 24, 2021

I'm sorry but it's already fixed by #1829
I was wrong.

But the issue is already closed.

@IronLu233
Copy link
Contributor Author

So should I need open a new issue for it?

@kdy1
Copy link
Member

kdy1 commented Jun 24, 2021

What do you are trying to fix?
If there are some unhandled edge cases left, I'll reopen the issue.

@IronLu233
Copy link
Contributor Author

IronLu233 commented Jun 24, 2021

Please reopen the issue.
I want add if (key in exports && exports[key] === _File2[key]) return; in each named reexport.
If we don't have this judge, when two module have same named-export, the code will emit a error:
image
source:

export const BIZ = 'biz';
export * from './File1';
export * from './File2';

compile result of swc:

"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
var _exportNames = {
    BIZ: true
};
exports.BIZ = void 0;
var _file1 = require("./File1");
var _file2 = require("./File2");
function _interopRequireWildcard(obj) {
    if (obj && obj.__esModule) {
        return obj;
    } else {
        var newObj = {
        };
        if (obj != null) {
            for(var key in obj){
                if (Object.prototype.hasOwnProperty.call(obj, key)) {
                    var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
                    };
                    if (desc.get || desc.set) {
                        Object.defineProperty(newObj, key, desc);
                    } else {
                        newObj[key] = obj[key];
                    }
                }
            }
        }
        newObj.default = obj;
        return newObj;
    }
}
var BIZ = 'biz';
exports.BIZ = BIZ;
Object.keys(_file1).forEach(function(key) {
    if (key === "default" || key === "__esModule") return;
    if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
    Object.defineProperty(exports, key, {
        enumerable: true,
        get: function() {
            return _file1[key];
        }
    });
});
Object.keys(_file2).forEach(function(key) {
    if (key === "default" || key === "__esModule") return;
    if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
    Object.defineProperty(exports, key, {
        enumerable: true,
        get: function() {
            return _file2[key];
        }
    });
});

compile result of babel:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var _exportNames = {
  BIZ: true
};
exports.BIZ = void 0;

var _File = require("./File1");

Object.keys(_File).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _File[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _File[key];
    }
  });
});

var _File2 = require("./File2");

Object.keys(_File2).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _File2[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _File2[key];
    }
  });
});
const BIZ = 'biz';
exports.BIZ = BIZ;

@kdy1 kdy1 modified the milestones: v1.2.62, v1.2.63 Jun 26, 2021
@IronLu233
Copy link
Contributor Author

Hi, @kdy1 , I updated the branch and confirmed all unit test passed. Please approve the workflow.

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@kdy1 kdy1 merged commit f8a3df8 into swc-project:master Jun 29, 2021
@swc-project swc-project locked as resolved and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

more than one export * from cause Cannot redefine property when re-imports have same name export
3 participants