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

pull/8569/head
Simon Holthausen 3 years ago
parent c4bbf44aa0
commit 711dfa073b

@ -5,7 +5,6 @@ import add_to_set from '../../utils/add_to_set.js';
/** @extends Wrapper */ /** @extends Wrapper */
export default class TitleWrapper extends Wrapper { export default class TitleWrapper extends Wrapper {
/** @type {import('../../nodes/Title.js').default} */ /** @type {import('../../nodes/Title.js').default} */
node; node;
@ -41,17 +40,19 @@ export default class TitleWrapper extends Wrapper {
const { expression } = this.node.children[0]; const { expression } = this.node.children[0];
value = expression.manipulate(block); value = expression.manipulate(block);
add_to_set(all_dependencies, expression.dependencies); add_to_set(all_dependencies, expression.dependencies);
} } else {
else {
// '{foo} {bar}' — treat as string concatenation // '{foo} {bar}' — treat as string concatenation
value = this.node.children value = this.node.children
.map((chunk) => { .map((chunk) => {
if (chunk.type === 'Text') if (chunk.type === 'Text') return string_literal(chunk.data);
return string_literal(chunk.data); /** @type {import('../../nodes/MustacheTag.js').default} */ (
( /** @type {import('../../nodes/MustacheTag.js').default} */(chunk)).expression.dependencies.forEach((d) => { chunk
).expression.dependencies.forEach((d) => {
all_dependencies.add(d); all_dependencies.add(d);
}); });
return ( /** @type {import('../../nodes/MustacheTag.js').default} */(chunk)).expression.manipulate(block); return /** @type {import('../../nodes/MustacheTag.js').default} */ (
chunk
).expression.manipulate(block);
}) })
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`); .reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
if (this.node.children[0].type !== 'Text') { if (this.node.children[0].type !== 'Text') {
@ -59,8 +60,7 @@ export default class TitleWrapper extends Wrapper {
} }
} }
const last = this.node.should_cache && block.get_unique_name('title_value'); const last = this.node.should_cache && block.get_unique_name('title_value');
if (this.node.should_cache) if (this.node.should_cache) block.add_variable(last);
block.add_variable(last);
const init = this.node.should_cache ? x`${last} = ${value}` : value; const init = this.node.should_cache ? x`${last} = ${value}` : value;
block.chunks.init.push(b`@_document.title = ${init};`); block.chunks.init.push(b`@_document.title = ${init};`);
const updater = b`@_document.title = ${this.node.should_cache ? last : value};`; const updater = b`@_document.title = ${this.node.should_cache ? last : value};`;
@ -78,16 +78,14 @@ export default class TitleWrapper extends Wrapper {
${updater} ${updater}
}`); }`);
} }
} } else {
else { const value =
const value = this.node.children.length > 0 this.node.children.length > 0
? string_literal(( /** @type {import('../../nodes/Text.js').default} */(this.node.children[0])).data) ? string_literal(
/** @type {import('../../nodes/Text.js').default} */ (this.node.children[0]).data
)
: x`""`; : x`""`;
block.chunks.hydrate.push(b`@_document.title = ${value};`); block.chunks.hydrate.push(b`@_document.title = ${value};`);
} }
} }
} }

Loading…
Cancel
Save