From 4babdcaf20fcc03e01f083e0a80996a21883c814 Mon Sep 17 00:00:00 2001 From: Yasar icli Date: Mon, 20 Mar 2017 15:01:58 +0300 Subject: [PATCH] Spacebars-compiler npm ReferenceError error has been fixed in the _beautify function. #244 --- packages/spacebars-compiler/compiler.js | 40 ++++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/packages/spacebars-compiler/compiler.js b/packages/spacebars-compiler/compiler.js index 009571fe2..2a46f1488 100644 --- a/packages/spacebars-compiler/compiler.js +++ b/packages/spacebars-compiler/compiler.js @@ -1,5 +1,3 @@ -var UglifyJSMinify = Npm.require('uglify-js').minify; - SpacebarsCompiler.parse = function (input) { var tree = HTMLTools.parseFragment( @@ -96,20 +94,26 @@ SpacebarsCompiler.codeGen = function (parseTree, options) { }; SpacebarsCompiler._beautify = function (code) { - var result = UglifyJSMinify(code, { - fromString: true, - mangle: false, - compress: false, - output: { - beautify: true, - indent_level: 2, - width: 80 - } - }); - - var output = result.code; - // Uglify interprets our expression as a statement and may add a semicolon. - // Strip trailing semicolon. - output = output.replace(/;$/, ''); - return output; + try { + var UglifyJSMinify = Npm.require('uglify-js').minify; + var result = UglifyJSMinify(code, { + fromString: true, + mangle: false, + compress: false, + output: { + beautify: true, + indent_level: 2, + width: 80 + } + }); + + var output = result.code; + // Uglify interprets our expression as a statement and may add a semicolon. + // Strip trailing semicolon. + output = output.replace(/;$/, ''); + return output; + + } catch (e) { + return code; + } };