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

[feat] tree shake namespace XXX {} #3076

Closed
loynoir opened this issue Apr 21, 2023 · 1 comment
Closed

[feat] tree shake namespace XXX {} #3076

loynoir opened this issue Apr 21, 2023 · 1 comment

Comments

@loynoir
Copy link

loynoir commented Apr 21, 2023

Reproduce

$ npm exec -- esbuild --format=esm --bundle ./entry.mts
==> entry.mts <==
import { TypeRegistry } from './lib.mjs'

TypeRegistry.Clear()

==> lib.mts <==
export namespace TypeRegistry {
  const map = new Map<string, unknown>()
  export function Entries() {
    return new Map(map)
  }
  export function Clear() {
    return map.clear()
  }
}

Actual

// lib.mts
var TypeRegistry;
((TypeRegistry2) => {
  const map = /* @__PURE__ */ new Map();
  function Entries() {
    return new Map(map);
  }
  TypeRegistry2.Entries = Entries;
  function Clear() {
    return map.clear();
  }
  TypeRegistry2.Clear = Clear;
})(TypeRegistry || (TypeRegistry = {}));

// entry.mts
TypeRegistry.Clear();

Expected

// lib.mts
var TypeRegistry = / /* @__PURE__ */(()=>{
((TypeRegistry2) => {
  const map = /* @__PURE__ */ new Map();
  function Clear() {
    return map.clear();
  }
  TypeRegistry2.Clear = /* @__PURE__ */Clear;
})(TypeRegistry || (TypeRegistry = {}));
})()

// entry.mts
TypeRegistry.Clear();

Related

sinclairzx81/typebox#401

@loynoir
Copy link
Author

loynoir commented Apr 22, 2023

Close in favor of #3077

@loynoir loynoir closed this as completed Apr 22, 2023
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

1 participant