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

[Feature request] ability to declare a static block as pure #1523

Open
bigopon opened this issue Apr 26, 2024 · 3 comments
Open

[Feature request] ability to declare a static block as pure #1523

bigopon opened this issue Apr 26, 2024 · 3 comments

Comments

@bigopon
Copy link

bigopon commented Apr 26, 2024

Version

Current latest

Complete CLI command or minify() options used

N/A

terser input

class Abc {
  /*@__PURE__*/static { doThis() }
}

console.log('hi abc');

terser output or error

class Abc {
  static { doThis() }
}

console.log('hi abc');

Expected result

console.log('hi abc');

Visual:
image

Context

Sometimes there' some groups of classes that share a common setup on their prototypes, so it's more reasonable to use some mixins to apply those methods. Prior to static block, the application of those mixins would have been in separate statements after the classes. But regardless where it is, those calls would mark the class as sideeffectful.
I was hoping with static block enabled this would allow us to treat static block as something "internal" to a class and won't affect the sideeffect analysis of it.

class O1 {
  static {
    mixinA(O1)
    mixinB(O1)
  }
}
@bigopon
Copy link
Author

bigopon commented Jun 5, 2024

@fabiosantoscode just nudging since Im not sure what I did so wrong that this didnt get any attention 😬

@fabiosantoscode
Copy link
Collaborator

Usually /*@__PURE__*/ is a source of a lot of conversation, since it's very subtle, and read by many other tools.

I see the point of marking the whole static as pure, but why not something like (/*@__PURE__*/() => { <pure code here> })()? It's a bit more clunky, but especially compilers can output stuff like it easily.

@bigopon
Copy link
Author

bigopon commented Jun 5, 2024

You meant

class Abc {}
(/*@__PURE__*/(klass) => {...})(Abc)

Or

class Abc {
 static {
    (/*@__PURE__*/(klass) => {...})()
  }

I can try this, but Im not sure itll work for a library code.

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