Simplifies input source map tracker.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 13 Dec 2014 20:27:22 +0000 (20:27 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 13 Dec 2014 20:27:22 +0000 (20:27 +0000)
lib/clean.js
lib/utils/input-source-map-tracker.js

index d736e99..cdf7582 100644 (file)
@@ -92,7 +92,7 @@ function runMinifier(callback, context) {
 
   return function (data) {
     if (context.options.sourceMap) {
-      context.inputSourceMapTracker = new InputSourceMapTracker(context.options, context);
+      context.inputSourceMapTracker = new InputSourceMapTracker(context);
       return context.inputSourceMapTracker.track(data, function () { return whenSourceMapReady(data); });
     } else {
       return whenSourceMapReady(data);
index d6c1560..ff346f6 100644 (file)
@@ -6,31 +6,20 @@ var http = require('http');
 var https = require('https');
 var url = require('url');
 
-var MAP_MARKER = /\/\*# sourceMappingURL=(\S+) \*\//;
-
-var DEFAULT_TIMEOUT = 5000;
+var override = require('../utils/object.js').override;
 
+var MAP_MARKER = /\/\*# sourceMappingURL=(\S+) \*\//;
 
-function InputSourceMapStore(options, outerContext) {
-  this.options = options;
+function InputSourceMapStore(outerContext) {
+  this.options = outerContext.options;
   this.errors = outerContext.errors;
   this.sourceTracker = outerContext.sourceTracker;
-  this.timeout = (options.inliner && options.inliner.timeout) || DEFAULT_TIMEOUT;
-  this.requestOptions = (options.inliner && options.inliner.request) || {};
+  this.timeout = this.options.inliner.timeout;
+  this.requestOptions = this.options.inliner.request;
 
   this.maps = {};
 }
 
-function merge(source1, source2) {
-  var target = {};
-  for (var key1 in source1)
-    target[key1] = source1[key1];
-  for (var key2 in source2)
-    target[key2] = source2[key2];
-
-  return target;
-}
-
 function fromString(self, data, whenDone) {
   self.maps[undefined] = new SourceMapConsumer(self.options.sourceMap);
   return whenDone();
@@ -93,7 +82,7 @@ function fetchMapFile(self, mapSource, context, done) {
   }
 
   var method = mapSource.indexOf('https') === 0 ? https : http;
-  var requestOptions = merge(url.parse(mapSource), self.requestOptions);
+  var requestOptions = override(url.parse(mapSource), self.requestOptions);
 
   method
     .get(requestOptions, function (res) {