Skip to content
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

transformSync of export { a, b } from 'foo' to cjs produces invalid JavaScript #393

Closed
dmichon-msft opened this issue Sep 17, 2020 · 2 comments

Comments

@dmichon-msft
Copy link

Repro:

const { transformSync } = require('esbuild');

console.log(transformSync(`export { a, b } from './foo';`, {
  target: 'es2018',
  format: 'cjs',
  minify: false
}).js);

Output:

var __defineProperty = Object.defineProperty;
var __hasOwnProperty = Object.prototype.hasOwnProperty;
var __markAsModule = (target) => {
  return __defineProperty(target, "__esModule", {value: true});
};
var __export = (target, all) => {
  __markAsModule(target);
  for (var name in all)
    __defineProperty(target, name, {get: all[name], enumerable: true});
};
var __exportStar = (target, module2) => {
  __markAsModule(target);
  if (typeof module2 === "object" || typeof module2 === "function") {
    for (let key in module2)
      if (!__hasOwnProperty.call(target, key) && key !== "default")
        __defineProperty(target, key, {get: () => module2[key], enumerable: true});
  }
  return target;
};
var __toModule = (module2) => {
  if (module2 && module2.__esModule)
    return module2;
  return __exportStar(__defineProperty({}, "default", {value: module2, enumerable: true}), module2);
};
__export(exports, {
  a: () => a,
  b: () => b
});
const foo = __toModule(require("./foo"));

The code to extract a and b from foo is missing from the output.

esbuild version: 0.7.1

@evanw
Copy link
Owner

evanw commented Sep 19, 2020

Thank you very much for reporting this issue. This should be fixed in version 0.7.2.

@evanw evanw closed this as completed Sep 19, 2020
@aleclarson
Copy link

I was just about to report this one. :)

Great work, @evanw! 🚀

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

No branches or pull requests

3 participants