File size: 1,211 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Node from './shared/Node.js';
import map_children from './shared/map_children.js';
import compiler_errors from '../compiler_errors.js';

/** @extends Node<'Title'> */
export default class Title extends Node {
	/** @type {import('./shared/map_children.js').Children} */
	children;

	/** @type {boolean} */
	should_cache;

	/**
	 * @param {import('../Component.js').default} component
	 * @param {import('./shared/Node.js').default} parent
	 * @param {import('./shared/TemplateScope.js').default} scope
	 * @param {import('../../interfaces.js').TemplateNode} info
	 */
	constructor(component, parent, scope, info) {
		super(component, parent, scope, info);
		this.children = map_children(component, parent, scope, info.children);
		if (info.attributes.length > 0) {
			component.error(info.attributes[0], compiler_errors.illegal_attribute_title);
			return;
		}
		info.children.forEach((child) => {
			if (child.type !== 'Text' && child.type !== 'MustacheTag') {
				return component.error(child, compiler_errors.illegal_structure_title);
			}
		});
		this.should_cache =
			info.children.length === 1
				? info.children[0].type !== 'Identifier' || scope.names.has(info.children[0].name)
				: true;
	}
}