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

Smart constant rewriting #156

Open
kangax opened this issue Sep 12, 2016 · 0 comments
Open

Smart constant rewriting #156

kangax opened this issue Sep 12, 2016 · 0 comments

Comments

@kangax
Copy link
Member

kangax commented Sep 12, 2016

(as suggested by @sebmarkbage)

The minifier already has simple constant folding and/or dead-code elimination of primitives:

if (__DEV__) {
}

It would be great if it could also do that for frozen objects and non-writable/non-configurable properties.

If I declare an object like:

var obj = {};
Object.defineProperty(obj, 'foo', { configurable: false, writable: false, value: false });

Then this expression should also evaluate to false and be dead-code eliminated:

if (obj.foo) {
}

If the primitive value is a number or boolean it would rewrite it:

var x = obj.foo;

could be rewritten to:

var x = 123;

However, the most important one for potential further optimization would be rewriting bindings for non-primitives;

A binding like:

obj.foo();

would be rewritten to:

foo();

and the minifier would somehow communicate back that the obj binding is now replaced with the foo binding which should have the value of obj.foo.

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