@emmetio/abbreviation
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -85,8 +85,15 @@ 'use strict'; | ||
/** @type Node */ | ||
this.children = []; | ||
/** @type {Node} Pointer to parent node */ | ||
this.parent = null; | ||
this.children = []; | ||
/** @type {Node} Pointer to next sibling */ | ||
this.next = null; | ||
/** @type {Node} Pointer to previous sibling */ | ||
this.previous = null; | ||
this._attributes = []; | ||
this._attributes = []; | ||
@@ -143,2 +150,34 @@ if (Array.isArray(attributes)) { | ||
/** | ||
* Returns last child of current node | ||
* @return {Node} | ||
*/ | ||
get lastChild() { | ||
return last(this.children); | ||
} | ||
/** | ||
* Return index of current node in its parent child list | ||
* @return {Number} Returns -1 if current node is a root one | ||
*/ | ||
get childIndex() { | ||
return this.parent ? this.parent.children.indexOf(this) : -1; | ||
} | ||
/** | ||
* Returns next sibling of current node | ||
* @return {Node} | ||
*/ | ||
get nextSibling() { | ||
return this.next; | ||
} | ||
/** | ||
* Returns previous sibling of current node | ||
* @return {Node} | ||
*/ | ||
get previousSibling() { | ||
return this.previous; | ||
} | ||
/** | ||
* Returns array of unique class names in current node | ||
@@ -145,0 +184,0 @@ * @return {String[]} |
@@ -83,8 +83,15 @@ /** | ||
/** @type Node */ | ||
this.children = []; | ||
/** @type {Node} Pointer to parent node */ | ||
this.parent = null; | ||
this.children = []; | ||
/** @type {Node} Pointer to next sibling */ | ||
this.next = null; | ||
/** @type {Node} Pointer to previous sibling */ | ||
this.previous = null; | ||
this._attributes = []; | ||
this._attributes = []; | ||
@@ -141,2 +148,34 @@ if (Array.isArray(attributes)) { | ||
/** | ||
* Returns last child of current node | ||
* @return {Node} | ||
*/ | ||
get lastChild() { | ||
return last(this.children); | ||
} | ||
/** | ||
* Return index of current node in its parent child list | ||
* @return {Number} Returns -1 if current node is a root one | ||
*/ | ||
get childIndex() { | ||
return this.parent ? this.parent.children.indexOf(this) : -1; | ||
} | ||
/** | ||
* Returns next sibling of current node | ||
* @return {Node} | ||
*/ | ||
get nextSibling() { | ||
return this.next; | ||
} | ||
/** | ||
* Returns previous sibling of current node | ||
* @return {Node} | ||
*/ | ||
get previousSibling() { | ||
return this.previous; | ||
} | ||
/** | ||
* Returns array of unique class names in current node | ||
@@ -143,0 +182,0 @@ * @return {String[]} |
@@ -22,8 +22,15 @@ 'use strict'; | ||
/** @type Node */ | ||
this.children = []; | ||
/** @type {Node} Pointer to parent node */ | ||
this.parent = null; | ||
this.children = []; | ||
/** @type {Node} Pointer to next sibling */ | ||
this.next = null; | ||
/** @type {Node} Pointer to previous sibling */ | ||
this.previous = null; | ||
this._attributes = []; | ||
this._attributes = []; | ||
@@ -80,2 +87,34 @@ if (Array.isArray(attributes)) { | ||
/** | ||
* Returns last child of current node | ||
* @return {Node} | ||
*/ | ||
get lastChild() { | ||
return last(this.children); | ||
} | ||
/** | ||
* Return index of current node in its parent child list | ||
* @return {Number} Returns -1 if current node is a root one | ||
*/ | ||
get childIndex() { | ||
return this.parent ? this.parent.children.indexOf(this) : -1; | ||
} | ||
/** | ||
* Returns next sibling of current node | ||
* @return {Node} | ||
*/ | ||
get nextSibling() { | ||
return this.next; | ||
} | ||
/** | ||
* Returns previous sibling of current node | ||
* @return {Node} | ||
*/ | ||
get previousSibling() { | ||
return this.previous; | ||
} | ||
/** | ||
* Returns array of unique class names in current node | ||
@@ -82,0 +121,0 @@ * @return {String[]} |
{ | ||
"name": "@emmetio/abbreviation", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "Emmet standalone abbreviation parser", | ||
@@ -5,0 +5,0 @@ "main": "dist/abbreviation.cjs.js", |
@@ -22,2 +22,3 @@ 'use strict'; | ||
assert.equal(root.firstChild, a); | ||
assert.equal(root.lastChild, a); | ||
assert.equal(a.parent, root); | ||
@@ -27,2 +28,6 @@ assert.equal(a.previous, null); | ||
assert.equal(a.childIndex, 0); | ||
assert.equal(b.childIndex, -1); | ||
assert.equal(c.childIndex, -1); | ||
// ensure children are making up a linked list | ||
@@ -32,2 +37,3 @@ root.appendChild(b); | ||
assert.equal(root.firstChild, a); | ||
assert.equal(root.lastChild, b); | ||
assert.equal(a.previous, null); | ||
@@ -38,5 +44,10 @@ assert.equal(a.next, b); | ||
assert.equal(a.childIndex, 0); | ||
assert.equal(b.childIndex, 1); | ||
assert.equal(c.childIndex, -1); | ||
root.appendChild(c); | ||
assert.equal(root.children.length, 3); | ||
assert.equal(root.firstChild, a); | ||
assert.equal(root.lastChild, c); | ||
assert.equal(a.previous, null); | ||
@@ -49,2 +60,6 @@ assert.equal(a.next, b); | ||
assert.equal(a.childIndex, 0); | ||
assert.equal(b.childIndex, 1); | ||
assert.equal(c.childIndex, 2); | ||
// re-append existing child to change children order | ||
@@ -54,2 +69,3 @@ root.appendChild(a); | ||
assert.equal(root.firstChild, b); | ||
assert.equal(root.lastChild, a); | ||
assert.equal(b.previous, null); | ||
@@ -62,2 +78,6 @@ assert.equal(b.next, c); | ||
assert.equal(a.childIndex, 2); | ||
assert.equal(b.childIndex, 0); | ||
assert.equal(c.childIndex, 1); | ||
// remove node and maintain a linked list | ||
@@ -67,2 +87,3 @@ c.remove(); | ||
assert.equal(root.firstChild, b); | ||
assert.equal(root.lastChild, a); | ||
assert.equal(b.previous, null); | ||
@@ -76,2 +97,6 @@ assert.equal(b.next, a); | ||
assert.equal(a.childIndex, 1); | ||
assert.equal(b.childIndex, 0); | ||
assert.equal(c.childIndex, -1); | ||
// remove detached node: do not throw error | ||
@@ -91,2 +116,6 @@ c.remove(); | ||
assert.equal(c.parent, root); | ||
assert.equal(a.childIndex, 2); | ||
assert.equal(b.childIndex, 0); | ||
assert.equal(c.childIndex, 1); | ||
}); | ||
@@ -93,0 +122,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89544
3001