royale-compiler: trace no longer stripped out
Here is a very simple app which uses trace.
<?xml version="1.0" encoding="utf-8"?>
<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:js="library://ns.apache.org/royale/basic"
applicationComplete="onComplete()">
<fx:Script>
<![CDATA[
private function onComplete():void{
trace("foo");
}
]]>
</fx:Script>
<js:valuesImpl>
<js:SimpleCSSValuesImpl />
</js:valuesImpl>
<js:initialView>
<js:View>
<js:Label text="ID" id="id1" localId="id1" />
</js:View>
</js:initialView>
</js:Application>
Language.trace has a “debug comment” of @royaledebug This is suposed to cause if(!goog.DEBUG)return; to be inserted at the top of the function. That line allows the Google Complier to strip out the entire function and any references to it in the app using dead code removal.
It’s not actually being removed. Currently, Language.trace is output like this:
/**
* @royaledebug
* @nocollapse
* @param {...} rest
*/
org.apache.royale.utils.Language.trace = function(rest) {
rest = rest;if(!goog.DEBUG)return;
rest = Array.prototype.slice.call(arguments, 0);
var /** @type {*} */ theConsole;
theConsole = goog.global.console;
if (theConsole === undefined) {
if (typeof(window) !== "undefined") {
theConsole = window.console;
} else if (typeof(console) !== "undefined") {
theConsole = console;
}
}
try {
if (theConsole && theConsole.log) {
theConsole.log.apply(theConsole, rest);
}
} catch (e) {
}
};
Notice that if(!goog.DEBUG)return; is being inserted, but it’s after rest = rest; I don’t know if that’s the reason it’s not being stripped or there’s some other reason.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (18 by maintainers)
@joshtynjala I made it so that @royalesuppressexport also avoids emitting @nocollapse which does address the issue raised by @Harbs here for trace. It was keeping hold of an empty function with the @nocollapse. I’ll leave it up to you to consider whether or not you think there is more to do and if not, please feel free to close this issue (I don’t know if there is more use of @nocollapse than is needed by default, I am pretty sure you know more about this stuff than the rest of us because you ‘had your head in it’ for some time).