webpack-core
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -49,6 +49,6 @@ /* | ||
} | ||
SourceMapNodeSource.call(this, node); | ||
SourceMapNodeSource.call(this, node, name); | ||
this._value = value; | ||
this._name = name; | ||
} | ||
module.exports = OriginalSource; | ||
@@ -55,0 +55,0 @@ |
@@ -5,8 +5,8 @@ /* | ||
*/ | ||
var Source = require("./Source"); | ||
var SourceMapNodeSource = require("./SourceMapNodeSource"); | ||
var SourceNode = require("source-map").SourceNode; | ||
var SourceMapConsumer = require("source-map").SourceMapConsumer; | ||
function ReplaceSource(source) { | ||
Source.call(this); | ||
function ReplaceSource(source, name) { | ||
SourceMapNodeSource.call(this, null, name); | ||
this._source = source; | ||
@@ -17,3 +17,3 @@ this.replacements = []; | ||
ReplaceSource.prototype = Object.create(Source.prototype); | ||
ReplaceSource.prototype = Object.create(SourceMapNodeSource.prototype); | ||
@@ -53,11 +53,3 @@ ReplaceSource.prototype.replace = function(start, end, newValue) { | ||
result = result.reverse(); | ||
var node = new SourceNode(null, null, null, result); | ||
var nodeResult = node.toStringWithSourceMap({ | ||
file: "?" | ||
}); | ||
return { | ||
source: nodeResult.code, | ||
map: nodeResult.map.toJSON(), | ||
node: node | ||
} | ||
return new SourceNode(null, null, null, result); | ||
}; | ||
@@ -64,0 +56,0 @@ |
@@ -16,13 +16,56 @@ /* | ||
SourceMapNodeSource.prototype._bake = function() { | ||
var result = this._node.toStringWithSourceMap({ | ||
file: this._name | ||
}); | ||
return { | ||
source: result.code, | ||
map: result.map.toJSON(), | ||
node: this._node | ||
}; | ||
throw new Error("Overwrite or pass valid SourceNode to constructor"); | ||
}; | ||
SourceMapNodeSource.prototype.source = function() { | ||
if(!this._node) this._node = this._bake(); | ||
if(!this._sourceResult) { | ||
this._sourceResult = this._node.toString(); | ||
} | ||
return this._sourceResult; | ||
}; | ||
SourceMapNodeSource.prototype.map = function() { | ||
if(!this._node) this._node = this._bake(); | ||
if(!this._mapResult) { | ||
this._mapResult = this._node.toStringWithSourceMap({ | ||
file: this._name | ||
}).map.toJSON(); | ||
} | ||
return this._mapResult; | ||
}; | ||
SourceMapNodeSource.prototype.size = function() { | ||
if(!this._node) this._node = this._bake(); | ||
if(!this._sizeResult) { | ||
this._sizeResult = sizeOfNode(this._node); | ||
} | ||
return this._sizeResult; | ||
}; | ||
SourceMapNodeSource.prototype.node = function() { | ||
if(!this._node) this._node = this._bake(); | ||
return this._node; | ||
} | ||
}; | ||
Source.prototype.updateHash = function(hash) { | ||
if(!this._node) this._node = this._bake(); | ||
updateHashForNode(this._node, hash); | ||
}; | ||
function updateHashForNode(node, hash) { | ||
hash.update(node.source + ""); | ||
hash.update(node.line + ""); | ||
hash.update(node.column + ""); | ||
hash.update(node.name + ""); | ||
var c = node.children; | ||
for(var i = 0; i < c.length; i++) { | ||
var x = c[i]; | ||
if(typeof x === "string") hash.update(x); | ||
else updateHashForNode(x, hash); | ||
} | ||
} | ||
function sizeOfNode(node) { | ||
var c = node.children; | ||
var s = 0; | ||
for(var i = 0; i < c.length; i++) { | ||
var x = c[i]; | ||
if(typeof x === "string") s += x.length; | ||
else s += sizeOfNode(x); | ||
} | ||
return s; | ||
} |
{ | ||
"name": "webpack-core", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -5,0 +5,0 @@ "description": "The core of webpack and enhanced-require.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26525
788