binjs-ref icon indicating copy to clipboard operation
binjs-ref copied to clipboard

Implement a mechanism to cleanup foo["bar"] into foo.bar

Open Yoric opened this issue 6 years ago • 3 comments

Since we namespace strings and property keys separately, having both foo["bar"] and foo.bar in the same source hurts compression. We should have a mechanism to optionally clean this up.

I believe that the best place to do so is around the Shift parser.

Yoric avatar Feb 15 '19 10:02 Yoric

After discussing with @dominiccooney and @RReverser, we concluded that this PR should not be landed. Leaving it lying on a branch as it may be useful for performance testing.

Yoric avatar Feb 15 '19 16:02 Yoric

@dominiccooney @RReverser I feel that we should optimize our dictionary for a case in which foo["bar"] has been rewritten foo.bar, also

{
   "sna": "fu"
}

has been rewritten

{
   sna: "fu"
}

etc.

Do you have ideas on how to best do this?

One way to do this would, of course, be to perform such rewrites in binjs-ref. Alternatively, we could rely upon a well-configured external minifier to do so.

Yoric avatar Feb 17 '19 20:02 Yoric

As for the object literals - as far as I remember, Shift already converts both examples you provided to the same representation.

RReverser avatar Feb 17 '19 22:02 RReverser