Constants and value inlining

23 views
Skip to first unread message

João Fernandes

unread,
Feb 4, 2015, 11:28:13 AM2/4/15
to traceur-comp...@googlegroups.com
Hi, I usually use pseudo-constants to store specific values and use that reference in my code, eg: SomeFunction(someDefinition.SOME_CONST,...) instead of SomeFunction("someConstantvalue"). I know that that value could change at runtime due to javascript nature but I like to use this approach because in case of a refactoring it's less prone to break. My question is, will traceur in it's future support value inlining using some specific metadata?  What I mean is, some kind of way of defining a "constant" which traceur would replace with it's value during transpilation.

Something like

export Class AClass
{
@Inline
const someValue:string="SOME_VALUE"
constructor(){}
}

and using someFunction(AClass.someValue) would be transpiled to someFunction("SOME_VALUE"). 

I hope my questions aren't way too off of what traceur's focus is.

Erik Arvidsson

unread,
Feb 4, 2015, 12:53:49 PM2/4/15
to traceur-comp...@googlegroups.com
The way I see it is that inlining like this is better handled with a
dedicated tool like UglifyJS or Closure Compiler. That way your code
size can shrink significantly.
> --
> You received this message because you are subscribed to the Google Groups
> "traceur-compiler-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to traceur-compiler-d...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
erik

João Fernandes

unread,
Feb 4, 2015, 2:49:40 PM2/4/15
to traceur-comp...@googlegroups.com
Thanks Erik,

My question is, so if I want to use traceur non uglified output, I need to preserve the import statement from my external resource so the code doesn't fail on the assigment. My question now is, if I keep my import, I wonder if the close compiler or UglifyJS is smart enough to remove my dependency all together due the inlining of that reference.

Small example
Import {ExternalReference} from './SomeReference.js';
Class A
{
    doSomething()
    {
         DoSomeStuff(ExternalReference.SomeConstant);
    }
}

the current traceur output works perfecly because it uses the Import to download the external dependency before running the code and the ExternalReference is a real object.

By running under UglifyJS or Google Closure Compiler, I'm not sure if it will remove that external dependency all together.

If I use the annotation @const for my SomeConstant and remove the import statement, yes, the closure compiler will inline the value and optimize it, but I won't be able to run traceur raw output anymore for debugging purpose.

Am I missing something?



--
You received this message because you are subscribed to a topic in the Google Groups "traceur-compiler-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/traceur-compiler-discuss/eJaPhauq-7o/unsubscribe.
To unsubscribe from this group and all its topics, send an email to traceur-compiler-d...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

João Fernandes
Reply all
Reply to author
Forward
0 new messages