-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathtext.js
More file actions
26 lines (22 loc) · 835 Bytes
/
text.js
File metadata and controls
26 lines (22 loc) · 835 Bytes
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
import { TEXT_NODE } from 'domconstants/constants';
import { TEXT_ELEMENTS } from 'domconstants/re';
import { escape } from 'html-escaper';
import CharacterData from './character-data.js';
import { parentNode, localName, ownerDocument, value, __chunks__ } from './symbols.js';
export default class Text extends CharacterData {
constructor(data = '', owner = null) {
super(TEXT_NODE, '#text', data, owner);
}
cloneNode() {
return new Text(this[value], this[ownerDocument]);
}
toString() {
const { [parentNode]: parent, [value]: data } = this;
return parent && TEXT_ELEMENTS.test(parent[localName]) ?
data :
(this[ownerDocument]?.[__chunks__] && this.previousSibling?.nodeType === TEXT_NODE ?
`<!--#-->${escape(data)}` :
escape(data)
);
}
}