-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathTitle.ts
37 lines (32 loc) · 983 Bytes
/
Title.ts
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';
import map_children, { Children } from './shared/map_children';
import Component from '../Component';
export default class Title extends Node {
type: 'Title';
children: Children;
should_cache: boolean;
constructor(component: 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], {
code: `illegal-attribute`,
message: `<title> cannot have attributes`
});
}
info.children.forEach(child => {
if (child.type !== 'Text' && child.type !== 'MustacheTag') {
component.error(child, {
code: 'illegal-structure',
message: `<title> can only contain text and {tags}`
});
}
});
this.should_cache = info.children.length === 1
? (
info.children[0].type !== 'Identifier' ||
scope.names.has(info.children[0].name)
)
: true;
}
}