diff options
author | kpdecker <kpdecker@gmail.com> | 2014-12-27 13:01:13 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-12-27 13:01:13 -0600 |
commit | 9c9a972a0c5d00db3a896cdadcdde6f2c453f66f (patch) | |
tree | ed79f44fa3fa63d920ef9abcf2b3e35754a60f10 | |
parent | b474630c7dc96f7a4e56c3530a89920e13bf26d4 (diff) | |
download | handlebars.js-9c9a972a0c5d00db3a896cdadcdde6f2c453f66f.zip handlebars.js-9c9a972a0c5d00db3a896cdadcdde6f2c453f66f.tar.gz handlebars.js-9c9a972a0c5d00db3a896cdadcdde6f2c453f66f.tar.bz2 |
Safely handle source map in browser tests
-rw-r--r-- | spec/source-map.js | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/spec/source-map.js b/spec/source-map.js index 4d3fa3e..a9e8ba3 100644 --- a/spec/source-map.js +++ b/spec/source-map.js @@ -1,9 +1,13 @@ /*global CompilerContext, Handlebars */ -var SourceMap = require('source-map'), - SourceMapConsumer = SourceMap.SourceMapConsumer; +try { + var SourceMap = require('source-map'), + SourceMapConsumer = SourceMap.SourceMapConsumer; +} catch (err) { + /* NOP for in browser */ +} describe('source-map', function() { - if (!Handlebars.precompile) { + if (!Handlebars.precompile || !SourceMap) { return; } @@ -14,8 +18,8 @@ describe('source-map', function() { equal(!!template.map, !CompilerContext.browser); }); it('should map source properly', function() { - var source = ' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}', - template = Handlebars.precompile(source, {destName: 'dest.js', srcName: 'src.hbs'}); + var template = ' b{{hello}} \n {{bar}}a {{#block arg hash=(subex 1 subval)}}{{/block}}'; + template = Handlebars.precompile(template, {destName: 'dest.js', srcName: 'src.hbs'}); if (template.map) { var consumer = new SourceMapConsumer(template.map), |