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

Add @__NO_SIDE_EFFECTS__ or @__PURE__ annotations #1899

Open
tetsuharuohzeki opened this issue Jun 21, 2023 · 2 comments
Open

Add @__NO_SIDE_EFFECTS__ or @__PURE__ annotations #1899

tetsuharuohzeki opened this issue Jun 21, 2023 · 2 comments

Comments

@tetsuharuohzeki
Copy link
Contributor

tetsuharuohzeki commented Jun 21, 2023

Motivation

This helps to provide more information to a minifier for code reduction.

Implementation

  1. Add @__NO_SIDE_EFFECTS__ annotation for function definitions
  2. Add @__PURE__ annotation for callee site

Unresolved Questions

  1. We need to add them carefully.
    • If we supply them, a minifier trusts their information for code reduction. This means that this effort would lead a bug. It might be hard to reproduce or detect because an user would run minifier only in a production/release build.
  2. Testing.

See also

@tetsuharuohzeki
Copy link
Contributor Author

At least, we cannot mark map() method as @__NO_SIDE_EFFECTS__. We think and provide map() as that its transformer argument does not have any side effect ordinally. But an user probably pass any functions that do something having a side effect wildly and we don't have any way to detect and disallow them.

@tetsuharuohzeki
Copy link
Contributor Author

If there are some demands from user, we may have a benefit to do this.

But I suspect that we need to wait and see the progress about their annotations (e.g. specification, or inventing a lint rule and push into ESLint).

Furthermore, our implementation uses a function declaration syntax for all to define APIs. Of course, this does not help to provide a complete information for code reduction with less computation but their syntax is easier to reduce than function expression + variable declaratio like const bar = (val) => { ...} , I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant