diff --git a/index.js b/index.js index 92cafd4..feefefe 100644 --- a/index.js +++ b/index.js @@ -75,7 +75,15 @@ function loadTranslationsPath(id,path,reload){ } try { - translations = "(function(){return "+translations+";})();"; + // remove `"use strict";` at the beginning of the file (add generally by tanspiler like typescript) if present + if (/^\s*("use\sstrict");?/.test(translations)) { + translations = translations.replace(/^\s*"use\sstrict";?\s*/, ''); + } + if (translations.trim().endsWith(";")) { + translations = "(function(){return " + translations + "})();"; + } else { + translations = "(function(){return " + translations + ";})();"; + } if(!jshint(translations)){ var checkfail = jshint.data().errors; var jsHintError = new Error("Sheet sintax error"); @@ -189,4 +197,4 @@ function functionBody(func){ end = end.exec(source); if(end){end = end.index;} else {end = source.length;} return source.substring(ini,end); -} \ No newline at end of file +}