Lint and format src/compiler/compile/render_dom/wrappers/DebugTag.js

pull/8569/head
Simon Holthausen 3 years ago
parent 01e3d502b8
commit 67ff828bc1

@ -4,87 +4,81 @@ import { b, p } from 'code-red';
/** @extends Wrapper */ /** @extends Wrapper */
export default class DebugTagWrapper extends Wrapper { export default class DebugTagWrapper extends Wrapper {
/** @type {import('../../nodes/DebugTag.js').default} */
node;
/** @type {import('../../nodes/DebugTag.js').default} */ /**
node; * @param {import('../Renderer.js').default} renderer
* @param {import('../Block.js').default} block
* @param {import('./shared/Wrapper.js').default} parent
* @param {import('../../nodes/DebugTag.js').default} node
* @param {boolean} _strip_whitespace
* @param {import('./shared/Wrapper.js').default} _next_sibling
*/
constructor(renderer, block, parent, node, _strip_whitespace, _next_sibling) {
super(renderer, block, parent, node);
}
/** /**
* @param {import('../Renderer.js').default} renderer * @param {import('../Block.js').default} block
* @param {import('../Block.js').default} block * @param {import('estree').Identifier} _parent_node
* @param {import('./shared/Wrapper.js').default} parent * @param {import('estree').Identifier} _parent_nodes
* @param {import('../../nodes/DebugTag.js').default} node */
* @param {boolean} _strip_whitespace render(block, _parent_node, _parent_nodes) {
* @param {import('./shared/Wrapper.js').default} _next_sibling const { renderer } = this;
*/ const { component } = renderer;
constructor(renderer, block, parent, node, _strip_whitespace, _next_sibling) { if (!renderer.options.dev) return;
super(renderer, block, parent, node); const { var_lookup } = component;
} const start = component.locate(this.node.start + 1);
const end = { line: start.line, column: start.column + 6 };
const loc = { start, end };
/** /** @type {import('estree').DebuggerStatement} */
* @param {import('../Block.js').default} block const debug = {
* @param {import('estree').Identifier} _parent_node type: 'DebuggerStatement',
* @param {import('estree').Identifier} _parent_nodes loc
*/ };
render(block, _parent_node, _parent_nodes) { if (this.node.expressions.length === 0) {
const { renderer } = this; // Debug all
const { component } = renderer; block.chunks.create.push(debug);
if (!renderer.options.dev) block.chunks.update.push(debug);
return; } else {
const { var_lookup } = component; /** @type {import('estree').Identifier} */
const start = component.locate(this.node.start + 1); const log = {
const end = { line: start.line, column: start.column + 6 }; type: 'Identifier',
const loc = { start, end }; name: 'log',
loc
};
/** @type {import('estree').DebuggerStatement} */ /** @type {Set<string>} */
const debug = { const dependencies = new Set();
type: 'DebuggerStatement', this.node.expressions.forEach((expression) => {
loc add_to_set(dependencies, expression.dependencies);
}; });
if (this.node.expressions.length === 0) { const contextual_identifiers = this.node.expressions
// Debug all .filter((e) => {
block.chunks.create.push(debug); const variable = var_lookup.get(/** @type {import('estree').Identifier} */ (e.node).name);
block.chunks.update.push(debug); return !(variable && variable.hoistable);
} })
else { .map((e) => /** @type {import('estree').Identifier} */ (e.node).name);
const logged_identifiers = this.node.expressions.map(
/** @type {import('estree').Identifier} */ (e) => p`${/** @type {import('estree').Identifier} */ (e.node).name}`
const log = { );
type: 'Identifier', const debug_statements = b`
name: 'log', ${contextual_identifiers.map((name) => b`const ${name} = ${renderer.reference(name)};`)}
loc
};
/** @type {Set<string>} */
const dependencies = new Set();
this.node.expressions.forEach((expression) => {
add_to_set(dependencies, expression.dependencies);
});
const contextual_identifiers = this.node.expressions
.filter((e) => {
const variable = var_lookup.get(( /** @type {import('estree').Identifier} */(e.node)).name);
return !(variable && variable.hoistable);
})
.map((e) => ( /** @type {import('estree').Identifier} */(e.node)).name);
const logged_identifiers = this.node.expressions.map((e) => p `${( /** @type {import('estree').Identifier} */(e.node)).name}`);
const debug_statements = b `
${contextual_identifiers.map((name) => b `const ${name} = ${renderer.reference(name)};`)}
@_console.${log}({ ${logged_identifiers} }); @_console.${log}({ ${logged_identifiers} });
debugger;`; debugger;`;
if (dependencies.size) { if (dependencies.size) {
const condition = renderer.dirty(Array.from(dependencies)); const condition = renderer.dirty(Array.from(dependencies));
block.chunks.update.push(b ` block.chunks.update.push(b`
if (${condition}) { if (${condition}) {
${debug_statements} ${debug_statements}
} }
`); `);
} }
block.chunks.create.push(b `{ block.chunks.create.push(b`{
${debug_statements} ${debug_statements}
}`); }`);
} }
} }
} }

Loading…
Cancel
Save