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

Loading…
Cancel
Save