|
|
|
@ -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,53 +40,52 @@ 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') {
|
|
|
|
value = x `"" + ${value}`;
|
|
|
|
value = x`"" + ${value}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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};`;
|
|
|
|
|
|
|
|
if (all_dependencies.size) {
|
|
|
|
if (all_dependencies.size) {
|
|
|
|
const dependencies = Array.from(all_dependencies);
|
|
|
|
const dependencies = Array.from(all_dependencies);
|
|
|
|
let condition = block.renderer.dirty(dependencies);
|
|
|
|
let condition = block.renderer.dirty(dependencies);
|
|
|
|
if (block.has_outros) {
|
|
|
|
if (block.has_outros) {
|
|
|
|
condition = x `!#current || ${condition}`;
|
|
|
|
condition = x`!#current || ${condition}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.node.should_cache) {
|
|
|
|
if (this.node.should_cache) {
|
|
|
|
condition = x `${condition} && (${last} !== (${last} = ${value}))`;
|
|
|
|
condition = x`${condition} && (${last} !== (${last} = ${value}))`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
block.chunks.update.push(b `
|
|
|
|
block.chunks.update.push(b`
|
|
|
|
if (${condition}) {
|
|
|
|
if (${condition}) {
|
|
|
|
${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(
|
|
|
|
: x `""`;
|
|
|
|
/** @type {import('../../nodes/Text.js').default} */ (this.node.children[0]).data
|
|
|
|
block.chunks.hydrate.push(b `@_document.title = ${value};`);
|
|
|
|
)
|
|
|
|
|
|
|
|
: x`""`;
|
|
|
|
|
|
|
|
block.chunks.hydrate.push(b`@_document.title = ${value};`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|