|
|
@ -3,11 +3,12 @@ import Wrapper from './shared/Wrapper';
|
|
|
|
import Renderer from '../Renderer';
|
|
|
|
import Renderer from '../Renderer';
|
|
|
|
import Block from '../Block';
|
|
|
|
import Block from '../Block';
|
|
|
|
import Title from '../../nodes/Title';
|
|
|
|
import Title from '../../nodes/Title';
|
|
|
|
import { stringify } from '../../utils/stringify';
|
|
|
|
import { stringify, string_literal } from '../../utils/stringify';
|
|
|
|
import add_to_set from '../../utils/add_to_set';
|
|
|
|
import add_to_set from '../../utils/add_to_set';
|
|
|
|
import Text from '../../nodes/Text';
|
|
|
|
import Text from '../../nodes/Text';
|
|
|
|
import { Identifier } from 'estree';
|
|
|
|
import { Identifier } from 'estree';
|
|
|
|
import { changed } from './shared/changed';
|
|
|
|
import { changed } from './shared/changed';
|
|
|
|
|
|
|
|
import MustacheTag from '../../nodes/MustacheTag';
|
|
|
|
|
|
|
|
|
|
|
|
export default class TitleWrapper extends Wrapper {
|
|
|
|
export default class TitleWrapper extends Wrapper {
|
|
|
|
node: Title;
|
|
|
|
node: Title;
|
|
|
@ -41,25 +42,21 @@ export default class TitleWrapper extends Wrapper {
|
|
|
|
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 =
|
|
|
|
value = this.node.children
|
|
|
|
(this.node.children[0].type === 'Text' ? '' : `"" + `) +
|
|
|
|
.map(chunk => {
|
|
|
|
this.node.children
|
|
|
|
if (chunk.type === 'Text') return string_literal(chunk.data);
|
|
|
|
.map((chunk) => {
|
|
|
|
|
|
|
|
if (chunk.type === 'Text') {
|
|
|
|
(chunk as MustacheTag).expression.dependencies.forEach(d => {
|
|
|
|
return stringify(chunk.data);
|
|
|
|
all_dependencies.add(d);
|
|
|
|
} else {
|
|
|
|
});
|
|
|
|
// @ts-ignore todo: check this
|
|
|
|
|
|
|
|
const snippet = chunk.expression.manipulate(block);
|
|
|
|
return (chunk as MustacheTag).expression.manipulate(block);
|
|
|
|
// @ts-ignore todo: check this
|
|
|
|
})
|
|
|
|
chunk.expression.dependencies.forEach(d => {
|
|
|
|
.reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
|
|
|
|
all_dependencies.add(d);
|
|
|
|
|
|
|
|
});
|
|
|
|
if (this.node.children[0].type !== 'Text') {
|
|
|
|
|
|
|
|
value = x`"" + ${value}`;
|
|
|
|
// @ts-ignore todo: check this
|
|
|
|
}
|
|
|
|
return chunk.expression.get_precedence() <= 13 ? `(${snippet})` : snippet;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.join(' + ');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const last = this.node.should_cache && block.get_unique_name(
|
|
|
|
const last = this.node.should_cache && block.get_unique_name(
|
|
|
@ -68,7 +65,7 @@ export default class TitleWrapper extends Wrapper {
|
|
|
|
|
|
|
|
|
|
|
|
if (this.node.should_cache) block.add_variable(last);
|
|
|
|
if (this.node.should_cache) block.add_variable(last);
|
|
|
|
|
|
|
|
|
|
|
|
const init = this.node.should_cache ? `${last} = ${value}` : value;
|
|
|
|
const init = this.node.should_cache ? x`${last} = ${value}` : value;
|
|
|
|
|
|
|
|
|
|
|
|
block.chunks.init.push(
|
|
|
|
block.chunks.init.push(
|
|
|
|
b`@_document.title = ${init};`
|
|
|
|
b`@_document.title = ${init};`
|
|
|
|