From fb28f086308f7df8ab7b8f84f2289f67de5720e0 Mon Sep 17 00:00:00 2001 From: ASSIONGBON Modeste Date: Wed, 3 Oct 2018 23:23:17 +0000 Subject: [PATCH 1/2] Fix error that occurred when the language file content ends with a semicolon --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 92cafd4..6eb80e5 100644 --- a/index.js +++ b/index.js @@ -75,7 +75,11 @@ function loadTranslationsPath(id,path,reload){ } try { - translations = "(function(){return "+translations+";})();"; + 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 +193,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 +} From aed6471f03552b0b55e48af34f8a7f41ba3ee6e8 Mon Sep 17 00:00:00 2001 From: ASSIONGBON Modeste Date: Mon, 8 Oct 2018 09:23:16 +0000 Subject: [PATCH 2/2] Fix error that occurred when the language file content ends with a `"use strict";`. --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 6eb80e5..feefefe 100644 --- a/index.js +++ b/index.js @@ -75,7 +75,11 @@ function loadTranslationsPath(id,path,reload){ } try { - if (translations.trim().endsWith(";")) { + // 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 + ";})();";