angular / ts-minify

A tool to aid minification of Typescript code, using Typescript's type information.
Apache License 2.0
121 stars 7 forks source link

shorthand assignment desugaring #47

Open dariajung opened 9 years ago

dariajung commented 9 years ago

A shorthand assignment is when an object literal is created without explicitly writing the property name using the name: expression syntax.

An example:

var title = "hello world";
var author = "Foo Bar";
var obj = { title, author }; 

is the same as writing

var obj = {title: title, author: author};

We would like to desugar this ourselves when we are in the visit step. If we see a node with SyntaxKind.ShorthandPropertyAssignment, rewrite the identifier like so, and check if the name of the property can be renamed.

property_name_identifier: expression_being_assigned

Difficulty: Between easy and medium