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

smarter function eval/inline #15

Open
IWANABETHATGUY opened this issue Oct 10, 2024 · 3 comments
Open

smarter function eval/inline #15

IWANABETHATGUY opened this issue Oct 10, 2024 · 3 comments

Comments

@IWANABETHATGUY IWANABETHATGUY changed the title smarter function eval smarter function eval/inline Oct 10, 2024
@IWANABETHATGUY
Copy link
Author

Interesting thing, terser has same strategy as tree-shaker, they always inline function for this case.

for swc, it only inlines the function result when the function is called only once.

@KermanX
Copy link
Owner

KermanX commented Oct 10, 2024

Currently, there is a max_simple_string_length config, strings longer than this value won't be inlined.

I can also think of some other strategies:

  • Option 1: Compare the literal's length to the span width of the node to be replaced
  • Option 2: If a string is going to be inlined multiple times, then append var unique_name="ABCDE" at the end of the program and use unique_name instead.

And there is also a problem of

export function f() {
  effect()
}
export const x = f()

being tree-shaked into

export function f() {
	effect();
}
export const x = (f(), undefined);

This is not hard to solve but will lead to more lines of code - every transform function should return whether the value is still reserved. Not sure if there is a better strategy.

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

2 participants