<commit_before>import Node from './shared/Node';
import Tag from './shared/Tag';
import Block from '../dom/Block';
import Expression from './shared/Expression';
import deindent from '../../utils/deindent';
import addToSet from '../../utils/addToSet';

export default class DebugTag extends Node {
	expressions: Expression[];
	shouldSkip: boolean;

	constructor(compiler, parent, scope, info) {
		super(compiler, parent, scope, info);

		this.shouldSkip = !compiler.options.dev;

		this.expressions = info.identifiers.map(node => {
			return new Expression(compiler, parent, scope, node);
		});
	}

	build(
		block: Block,
		parentNode: string,
		parentNodes: string,
	) {
		if (this.shouldSkip) return;

		// Debug all
		if (this.expressions.length === 0) {
			block.builders.create.addLine('debugger;');
			block.builders.update.addLine('debugger;');
		} else {
			const dependencies = new Set();
			this.expressions.forEach(expression => {
				addToSet(dependencies, expression.dependencies);
			});

			const condition = [...dependencies].map(d => `changed.${d}`).join(' || ');

			const identifiers = this.expressions.map(e => e.node.name).join(', ');

			block.builders.update.addBlock(deindent`
				if (${condition}) {
					const { ${identifiers} } = ctx;
					console.log({ ${identifiers} });
					debugger;
				}
			`);

			block.builders.create.addBlock(deindent`
				const { ${identifiers} } = ctx;
				console.log({ ${identifiers} });
				debugger;
			`);
		}
	}
}<commit_msg>add sourcemaps to debug tags<commit_after>import Node from './shared/Node';
import Tag from './shared/Tag';
import Block from '../dom/Block';
import Expression from './shared/Expression';
import deindent from '../../utils/deindent';
import addToSet from '../../utils/addToSet';

export default class DebugTag extends Node {
	expressions: Expression[];

	constructor(compiler, parent, scope, info) {
		super(compiler, parent, scope, info);

		this.expressions = info.identifiers.map(node => {
			return new Expression(compiler, parent, scope, node);
		});
	}

	build(
		block: Block,
		parentNode: string,
		parentNodes: string,
	) {
		if (!this.compiler.options.dev) return;

		const { code } = this.compiler;

		// Debug all
		if (this.expressions.length === 0) {
			code.overwrite(this.start + 1, this.start + 7, 'debugger', {
				storeName: true
			});
			const statement = `[✂${this.start + 1}-${this.start + 7}✂];`;

			block.builders.create.addLine(statement);
			block.builders.update.addLine(statement);
		} else {
			const { code } = this.compiler;
			code.overwrite(this.start + 1, this.start + 7, 'log', {
				storeName: true
			});
			const log = `[✂${this.start + 1}-${this.start + 7}✂]`;

			const dependencies = new Set();
			this.expressions.forEach(expression => {
				addToSet(dependencies, expression.dependencies);
			});

			const condition = [...dependencies].map(d => `changed.${d}`).join(' || ');

			const identifiers = this.expressions.map(e => e.node.name).join(', ');

			block.builders.update.addBlock(deindent`
				if (${condition}) {
					const { ${identifiers} } = ctx;
					console.${log}({ ${identifiers} });
					debugger;
				}
			`);

			block.builders.create.addBlock(deindent`
				{
					const { ${identifiers} } = ctx;
					console.${log}({ ${identifiers} });
					debugger;
				}
			`);
		}
	}
}
{'fraction_non_alphanumeric': 0.1757448089076136, 'fraction_numerical': 0.003009328919650918, 'mean_word_length': 3.4202127659574466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7563195', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1065, 'n_words': 232}