goog.reflect.sinkValue and deadcode elimination #203
-
One of the tips for preventing code removal by the compiler is the use of reflect.sinkValue from closure-library. Is it possible to use this feature without resorting to creating native.js? lets say I have something like this:
And I want to call it like this:
What should I pass to sinkValue wrapper?
As I can see from the docs I should use something like |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
There are couple of issues here. The reason you are looking into sinkValue is because you are not directly accessing the property, but accessing it through a map which is a string access. Your code is effectively The second issues here is that the mangled names like You are trying work around dead code elimination but if you can describe what you would like to really achieve, perhaps there are better ways to do what you want. However for the sake of completeness and answering your question directly, following should work with sinkValue :
If you are doing this, then you can as well just
If you can modify Test class you can also do:
|
Beta Was this translation helpful? Give feedback.
-
@gkdn thank you, works great!
To generate a mangled name I reuse com.google.j2cl.transpiler.ast.MemberDescriptor, so I have to be in sync with j2cl version. |
Beta Was this translation helpful? Give feedback.
There are couple of issues here.
The reason you are looking into sinkValue is because you are not directly accessing the property, but accessing it through a map which is a string access. Your code is effectively
test["m_test___$p_org_treblereel_Test"]
which wouldn't be recognized as a property access by JsCompiler hence will be renamed, removed etc. If the access looked liketest.test
then you wouldn't need goog.reflect.objectProperty or sinkValue. [Details]The second issues here is that the mangled names like
m_test___$p_org_treblereel_Test
are not stable. We are not intending to preserve the mangling rules and we already have changed them in the past. So this may get broken any time. …