<commit_before>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
var ConstDependency = require("./dependencies/ConstDependency");
var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");

var NullFactory = require("./NullFactory");

function DefinePlugin(definitions) {
	this.definitions = definitions;
}
module.exports = DefinePlugin;
DefinePlugin.prototype.apply = function(compiler) {
	compiler.plugin("compilation", function(compilation, params) {
		compilation.dependencyFactories.set(ConstDependency, new NullFactory());
		compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
	});
	(function walkDefinitions(definitions, prefix) {
		Object.keys(definitions).forEach(function(key) {
			var code = definitions[key];
			if(typeof code === "object" && !(code instanceof RegExp)) {
				walkDefinitions(code, prefix + key + ".");
				applyObjectDefine(prefix + key, code);
				return;
			}
			applyDefine(prefix + key, code);
		});
	}(this.definitions, ""));
	function stringifyObj(obj) {
		return "{" + Object.keys(obj).map(function(key) {
			var code = obj[key];
			return JSON.stringify(key) + ":" + toCode(code);
		}).join(",") + "}";
	}
	function toCode(code) {
		if(code === null) return "null";
		else if(code === undefined) return "undefined";
		else if(code instanceof RegExp && code.toString) return code.toString();
		else if(typeof code === "function" && code.toString) return code.toString();
		else if(typeof code === "object") return stringifyObj(code);
		else return code + "";
	}
	function applyDefine(key, code) {
		var isTypeof = /^typeof\s+/.test(key);
		if(isTypeof) key = key.replace(/^typeof\s+/, "");
		var recurse = false;
		var recurseTypeof = false;
		code = toCode(code);
		if(!isTypeof) {
			compiler.parser.plugin("can-rename " + key, function(expr) {
				return true;
			});<commit_msg>support `null` in DefinePlugin<commit_after>/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author <NAME> @sokra
*/
var ConstDependency = require("./dependencies/ConstDependency");
var BasicEvaluatedExpression = require("./BasicEvaluatedExpression");

var NullFactory = require("./NullFactory");

function DefinePlugin(definitions) {
	this.definitions = definitions;
}
module.exports = DefinePlugin;
DefinePlugin.prototype.apply = function(compiler) {
	compiler.plugin("compilation", function(compilation, params) {
		compilation.dependencyFactories.set(ConstDependency, new NullFactory());
		compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
	});
	(function walkDefinitions(definitions, prefix) {
		Object.keys(definitions).forEach(function(key) {
			var code = definitions[key];
			if(code && typeof code === "object" && !(code instanceof RegExp)) {
				walkDefinitions(code, prefix + key + ".");
				applyObjectDefine(prefix + key, code);
				return;
			}
			applyDefine(prefix + key, code);
		});
	}(this.definitions, ""));
	function stringifyObj(obj) {
		return "{" + Object.keys(obj).map(function(key) {
			var code = obj[key];
			return JSON.stringify(key) + ":" + toCode(code);
		}).join(",") + "}";
	}
	function toCode(code) {
		if(code === null) return "null";
		else if(code === undefined) return "undefined";
		else if(code instanceof RegExp && code.toString) return code.toString();
		else if(typeof code === "function" && code.toString) return code.toString();
		else if(typeof code === "object") return stringifyObj(code);
		else return code + "";
	}
	function applyDefine(key, code) {
		var isTypeof = /^typeof\s+/.test(key);
		if(isTypeof) key = key.replace(/^typeof\s+/, "");
		var recurse = false;
		var recurseTypeof = false;
		code = toCode(code);
		if(!isTypeof) {
			compiler.parser.plugin("can-rename " + key, function(expr) {
				return true;
			});
{'fraction_non_alphanumeric': 0.1621903520208605, 'fraction_numerical': 0.0, 'mean_word_length': 4.883435582822086, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4359140', 'n_tokens_mistral': 1275, 'n_tokens_neox': 1172, 'n_words': 254}