Skip to content

Commit

Permalink
Avoid source-map import under AMD
Browse files Browse the repository at this point in the history
Fixes #989
  • Loading branch information
kpdecker committed Apr 8, 2015
1 parent e15af4c commit 81a4d50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 12 additions & 2 deletions lib/handlebars/compiler/code-gen.js
Original file line number Diff line number Diff line change
@@ -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 = '';
Expand Down
6 changes: 4 additions & 2 deletions spec/source-map.js
Original file line number Diff line number Diff line change
@@ -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 */
}
Expand Down

0 comments on commit 81a4d50

Please sign in to comment.