mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:01:22 +08:00
FIX: Wrap theme javascript inside IIFE to prevent using global namespace
This commit is contained in:
@ -205,15 +205,17 @@ class ThemeJavascriptCompiler
|
||||
def transpile(es6_source, version)
|
||||
template = Tilt::ES6ModuleTranspilerTemplate.new {}
|
||||
wrapped = <<~PLUGIN_API_JS
|
||||
if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
|
||||
const settings = Discourse.__container__
|
||||
.lookup("service:theme-settings")
|
||||
.getObjectForTheme(#{@theme_id});
|
||||
const themePrefix = (key) => `theme_translations.#{@theme_id}.${key}`;
|
||||
Discourse._registerPluginCode('#{version}', api => {
|
||||
#{es6_source}
|
||||
});
|
||||
}
|
||||
(function() {
|
||||
if ('Discourse' in window && typeof Discourse._registerPluginCode === 'function') {
|
||||
const settings = Discourse.__container__
|
||||
.lookup("service:theme-settings")
|
||||
.getObjectForTheme(#{@theme_id});
|
||||
const themePrefix = (key) => `theme_translations.#{@theme_id}.${key}`;
|
||||
Discourse._registerPluginCode('#{version}', api => {
|
||||
#{es6_source}
|
||||
});
|
||||
}
|
||||
})();
|
||||
PLUGIN_API_JS
|
||||
|
||||
template.babel_transpile(wrapped)
|
||||
|
Reference in New Issue
Block a user