summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-04-07 22:35:14 -0500
committerkpdecker <kpdecker@gmail.com>2015-04-07 22:35:14 -0500
commit81a4d50955b13e7d5e5052d904bb3e8c993ebb88 (patch)
tree0cc6e3fcf64a45c515a4b33ed6a670f02bb3fd2e
parente15af4c84993ef730e1c07168f7cc97bc027f304 (diff)
downloadhandlebars.js-81a4d50955b13e7d5e5052d904bb3e8c993ebb88.zip
handlebars.js-81a4d50955b13e7d5e5052d904bb3e8c993ebb88.tar.gz
handlebars.js-81a4d50955b13e7d5e5052d904bb3e8c993ebb88.tar.bz2
Avoid source-map import under AMD
Fixes #989
-rw-r--r--lib/handlebars/compiler/code-gen.js14
-rw-r--r--spec/source-map.js6
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/handlebars/compiler/code-gen.js b/lib/handlebars/compiler/code-gen.js
index 0fddb7c..e998095 100644
--- a/lib/handlebars/compiler/code-gen.js
+++ b/lib/handlebars/compiler/code-gen.js
@@ -1,9 +1,19 @@
import {isArray} from "../utils";
+var SourceNode;
+
try {
- var SourceMap = require('source-map'),
- SourceNode = SourceMap.SourceNode;
+ if (typeof define !== 'function' || !define.amd) {
+ // We don't support this in AMD environments. For these environments, we asusme that
+ // they are running on the browser and thus have no need for the source-map library.
+ var SourceMap = require('source-map');
+ SourceNode = SourceMap.SourceNode;
+ }
} catch (err) {
+ /* NOP */
+}
+
+if (!SourceNode) {
/* istanbul ignore next: tested but not covered in istanbul due to dist build */
SourceNode = function(line, column, srcFile, chunks) {
this.src = '';
diff --git a/spec/source-map.js b/spec/source-map.js
index 6eced9c..8037b88 100644
--- a/spec/source-map.js
+++ b/spec/source-map.js
@@ -1,7 +1,9 @@
/*global CompilerContext, Handlebars */
try {
- var SourceMap = require('source-map'),
- SourceMapConsumer = SourceMap.SourceMapConsumer;
+ if (typeof define !== 'function' || !define.amd) {
+ var SourceMap = require('source-map'),
+ SourceMapConsumer = SourceMap.SourceMapConsumer;
+ }
} catch (err) {
/* NOP for in browser */
}