Sha256: 8efd630910810d14c76750616d8dd11e3c1256b5420f62b4a4297753d32af93e

Contents?: true

Size: 1.48 KB

Versions: 52

Compression:

Stored size: 1.48 KB

Contents

/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/
var loaderUtils = require("loader-utils");
var SourceNode = require("source-map").SourceNode;
var SourceMapConsumer = require("source-map").SourceMapConsumer;
var HEADER = "/*** IMPORTS FROM imports-loader ***/\n";
module.exports = function(content, sourceMap) {
	if(this.cacheable) this.cacheable();
	var query = loaderUtils.parseQuery(this.query);
	var imports = [];
	var postfixes = [];
	Object.keys(query).forEach(function(name) {
		var value;
		if(typeof query[name] == "string" && query[name].substr(0, 1) == ">") {
			value = query[name].substr(1);
		} else {
			var mod = name;
			if(typeof query[name] === "string") {
				mod = query[name];
			}
			value = "require(" + JSON.stringify(mod) + ")";
		}
		if(name === "this") {
			imports.push("(function() {");
			postfixes.unshift("}.call(" + value + "));");
		} else {
			imports.push("var " + name + " = " + value + ";");
		}
	});
	var prefix = HEADER + imports.join("\n") + "\n\n";
	var postfix = postfixes.join("\n");
	if(sourceMap) {
		var currentRequest = loaderUtils.getCurrentRequest(this);
		var node = SourceNode.fromStringWithSourceMap(content, new SourceMapConsumer(sourceMap));
		node.prepend(prefix);
		node.add(postfix);
		var result = node.toStringWithSourceMap({
			file: currentRequest
		});
		this.callback(null, result.code, result.map.toJSON());
		return;
	}
	return prefix + content + postfix;
}

Version data entries

52 entries across 52 versions & 1 rubygems

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