Skip to content

Commit 89c83f7

Browse files
committed
Fix error when used without options
Also, don't default to source map generation.
1 parent a5bfdb9 commit 89c83f7

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

index.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,29 @@ var async = require('async');
99
var ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');
1010

1111
function ClosureCompilerPlugin(options) {
12-
this.options = options;
12+
if (typeof options === "object") {
13+
this.options = options;
14+
} else {
15+
this.options = {};
16+
}
17+
if (typeof this.options['compiler'] === "object") {
18+
this.compilerOptions = this.options['compiler'];
19+
} else {
20+
this.compilerOptions = {};
21+
}
1322
}
1423

1524
ClosureCompilerPlugin.prototype.apply = function(compiler) {
1625

1726
var options = this.options;
27+
var compilerOptions = this.compilerOptions;
1828
var queue = async.queue(function(task, callback) {
1929

2030
var input;
2131
var inputSourceMap;
2232
var outputSourceMapFile;
2333

24-
if (options['compiler']['create_source_map'] !== false) {
34+
if (compilerOptions['create_source_map']) {
2535
if (task.asset.sourceAndMap) {
2636
var sourceAndMap = task.asset.sourceAndMap();
2737
inputSourceMap = sourceAndMap.map;
@@ -31,16 +41,16 @@ ClosureCompilerPlugin.prototype.apply = function(compiler) {
3141
input = task.asset.source();
3242
}
3343
outputSourceMapFile = temp.openSync('ccwp-dump-', 'w+');
34-
options['compiler']['create_source_map'] = outputSourceMapFile.path;
44+
compilerOptions['create_source_map'] = outputSourceMapFile.path;
3545
} else {
3646
input = task.asset.source();
3747
}
3848

39-
gcc.compile(input, options['compiler'], function (err, stdout, stderr) {
49+
gcc.compile(input, compilerOptions, function (err, stdout, stderr) {
4050
if (err) {
4151
task.error(new Error(task.file + ' from Closure Compiler\n' + err.message));
4252
} else {
43-
if (options['compiler']['create_source_map']) {
53+
if (compilerOptions['create_source_map']) {
4454
var outputSourceMap = JSON.parse(fs.readFileSync(outputSourceMapFile.path));
4555
fs.unlinkSync(outputSourceMapFile.path);
4656
outputSourceMap.sources = [];

0 commit comments

Comments
 (0)