Sha256: 1caf251e773ff39d8f5b20ef631df0226d1bab3a5b89992d751d4f2d49e25e51

Contents?: true

Size: 1.86 KB

Versions: 62

Compression:

Stored size: 1.86 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
var Source = require("./Source");

function SourceMapNodeSource(node, name) {
	Source.call(this);
	this._node = node;
	this._name = name;
}
module.exports = SourceMapNodeSource;

SourceMapNodeSource.prototype = Object.create(Source.prototype);
SourceMapNodeSource.prototype._bake = function() {
	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;
};
SourceMapNodeSource.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;
}

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
smock-0.1.268 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.267 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.266 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.265 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.264 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.263 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.262 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.261 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.260 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.259 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.258 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.256 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.255 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.254 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.253 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.252 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.251 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.250 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.249 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js
smock-0.1.247 node_modules/webpack/node_modules/webpack-core/lib/SourceMapNodeSource.js