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

remove Namespacee for tree shaking #1069

Closed
ryoppippi opened this issue Jun 4, 2024 · 5 comments
Closed

remove Namespacee for tree shaking #1069

ryoppippi opened this issue Jun 4, 2024 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ryoppippi
Copy link
Contributor

ryoppippi commented Jun 4, 2024

Feature Request

Related to #1063

Typescript's namespace is great, but this is not good for tree shaking.

Examples

with namespace

When you use vite for bundler, this code

namespace calc {
  export function add(a: number, b: number): number {
    return a + b;
  }

  export function sub(a: number, b: number): number {
    return a - b;
  }
}

console.log(add(1,2))

bundled like this

var calc;
((calc2) => {
  function add(a, b) {
    return a + b;
  }
  calc2.add = add;
  function sub(a, b) {
    return a - b;
  }
  calc2.sub = sub;
})(calc || (calc = {}));
console.log(calc.add(1, 2));

without namespace

However, if you do not use namespace

  export function add(a: number, b: number): number {
    return a + b;
  }

  export function sub(a: number, b: number): number {
    return a - b;
  }

console.log(add(1,2))

the bundle is like this↓

function add(a, b) {
  return a + b;
}

console.log(add(1, 2));

Or you can split the codebase and use Namespace Import:

calc.ts

export function add(a: number, b: number): number {
  return a + b;
}

export function sub(a: number, b: number): number {
  return a - b;
}

index.ts

import * as calc from "./calc.js";

console.log(calc.add(1, 2));

the bundle result here↓

import { add } from './calc.js';

console.log(add(1, 2));
@samchon samchon added the good first issue Good for newcomers label Jun 4, 2024
@samchon
Copy link
Owner

samchon commented Jun 4, 2024

I'm developing it on v7 update advised by #752

Wait for next 3 to 4 months please.

@samchon samchon added the enhancement New feature or request label Jun 4, 2024
@ryoppippi
Copy link
Contributor Author

ryoppippi commented Jun 4, 2024

If you need it, I'll help you!
Currently I have time to work on it

@samchon
Copy link
Owner

samchon commented Jun 4, 2024

Thanks for helping me, but this issue needs my working, due to it needs entire compiler API level refactoring.

@ryoppippi
Copy link
Contributor Author

OK! Thanks.
So, I wait for that! Thanks

@ryoppippi
Copy link
Contributor Author

ryoppippi commented Jul 3, 2024

The namespace has almost disappeared at the implementation level, so this issue is good to close
Also, tree-skaing of named import/export works well with this #1133

However, random function is not optimized yet.

Other things are fine.

So I'll create a new issue for this specific topic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants