https://bugzilla.wikimedia.org/show_bug.cgi?id=69924
--- Comment #14 from Krinkle <[email protected]> --- Hm.. so yeah, that's annoying. The condition-wrap is supposed to hide an issue in old browsers, not introduce issues in modern browsers. So far I've only seen two possible solutions: 1) Wrap in $.globalEval, passing the function body as a string. Something like: if (window.mw) { $.globalEval('foo(); function foo() { return 1; }'); } Produced by $content = 'if (window.mw) { $.globalEval(' . FormatJson::encode( $content ) . ' ); }';'; Or: $content = 'if (window.mw) { ' . Xml::encodeJsCall( '$.globalEval', array( $content ) ) . '}';'; Though this is relatively cheap and doesn't bloat the output much in terms of size, it does make it impossible to minify after the fact, so we should probably run the js-filter on it first. 2) Parse the javascript and transform local var statements and function declarations to explicit instead of implicit global properties so that scope doesn't matter. This can be done with something like emscripten, and then use the AST to replace var statements and function declarations with window[key] assignments (and manually hoist function declarations I guess). Then it's safe to use a closure (or even a plain wrap, like now). This requires getting a JS parser in PHP though, or shelling out to nodejs. -- You are receiving this mail because: You are the assignee for the bug. You are on the CC list for the bug. _______________________________________________ Wikibugs-l mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/wikibugs-l
