From 699e835204360d9ae82b2fc06d1a0e360548327e Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Sun, 2 Apr 2017 15:08:41 +0530 Subject: [PATCH] fix loop protection for ts and es6 code --- src/script.js | 4 ++-- src/utils.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/script.js b/src/script.js index acf71fb..88107e2 100644 --- a/src/script.js +++ b/src/script.js @@ -626,7 +626,7 @@ onboardDontShowInTabOptionBtn, TextareaAutoComplete, savedItemCountEl, indentati showErrors('js', [ { lineNumber: e.location.first_line, message: e.message } ]); } finally { if (shouldPreventInfiniteLoops !== false) { - code = utils.addInfiniteLoopProtection(code); + code = utils.addInfiniteLoopProtection(coffeeCode); } d.resolve(code); } @@ -674,7 +674,7 @@ onboardDontShowInTabOptionBtn, TextareaAutoComplete, savedItemCountEl, indentati throw ({ description: code.diagnostics[0].messageText, lineNumber: ts.getLineOfLocalPosition(code.diagnostics[0].file,code.diagnostics[0].start) }); } if (shouldPreventInfiniteLoops !== false) { - code = utils.addInfiniteLoopProtection(ast); + code = utils.addInfiniteLoopProtection(code.outputText); } d.resolve(code); } catch (e) { diff --git a/src/utils.js b/src/utils.js index 073417a..625d1ac 100644 --- a/src/utils.js +++ b/src/utils.js @@ -54,7 +54,7 @@ var varStr = 'var %d = Date.now();\n' var checkStr = '\nif (Date.now() - %d > 1000) { window.top.previewException(new Error("Infinite loop")); break;}\n' - esprima.parse(code, { tolerant: true, range: true }, function (node) { + esprima.parse(code, { tolerant: true, range: true, jsx: true }, function (node) { switch (node.type) { case 'DoWhileStatement': case 'ForStatement':