Skip to content

CommentToken (EN)

bhsd edited this page Dec 9, 2023 · 12 revisions

Other Languages

Introduction

HTML comment.

✅ Available in the Mini and Browser versions.

Properties

closed

✅ Expand

type: boolean
Whether the comment is closed.

// closed
var {firstChild} = Parser.parse('<!--');
assert.equal(firstChild, '<!--');
assert(!firstChild.closed);
firstChild.closed = true;
assert.equal(firstChild, '<!---->');

hidden

Expand

type: true
CommentToken is invisible, read-only.

// hidden
var {firstChild} = Parser.parse('<!--a-->');
assert.equal(firstChild, '<!--a-->');
assert(firstChild.hidden);

innerText

Expand

type: string
The text content of the comment.

// innerText
var {firstChild} = Parser.parse('<!--a-->');
assert.equal(firstChild, '<!--a-->');
assert.strictEqual(firstChild.innerText, 'a');
firstChild.innerText = 'b';
assert.equal(firstChild, '<!--b-->');

Methods

lint

✅ Expand

returns LintError[]
Report potential grammar errors.

// lint
var {firstChild} = Parser.parse('<!--');
assert.equal(firstChild, '<!--');
assert.deepStrictEqual(firstChild.lint(), [
    {
        severity: 'error',
        message: 'unclosed HTML comment',
        startLine: 0,
        startCol: 0,
        startIndex: 0,
        endLine: 0,
        endCol: 4,
        endIndex: 4,
        excerpt: '<!--',
    },
]);

cloneNode

Expand

returns: this
Deep clone the node.

// cloneNode
var {firstChild, lastChild} = Parser.parse('<!--a--><!--b'),
    closed = firstChild.cloneNode(),
    open = lastChild.cloneNode();
assert.equal(firstChild, '<!--a-->');
assert.equal(closed, '<!--a-->');
assert.equal(lastChild, '<!--b');
assert.equal(open, '<!--b');
assert.deepStrictEqual(closed, firstChild);
assert.deepStrictEqual(open, lastChild);
Clone this wiki locally