Socket
Socket
Sign inDemoInstall

happy-dom

Package Overview
Dependencies
Maintainers
1
Versions
576
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

happy-dom - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

16

lib/html-parser/HTMLParser.js

@@ -63,18 +63,2 @@ "use strict";

};
// /**
// * Prepends text and comment nodes.
// *
// * @param {Document} document Document.
// * @param {Node} node Node.
// * @param {string} text Text to search in.
// */
// private static prependTextAndCommentNodes(document: Document, node: Node, text: string): void {
// for (const innerNode of this.getTextAndCommentNodes(document, text)) {
// if (node.firstChild) {
// node.insertBefore(innerNode, node.firstChild);
// } else {
// node.appendChild(innerNode);
// }
// }
// }
/**

@@ -81,0 +65,0 @@ * Appends text and comment nodes.

3

lib/mutation-observer/MutationObserver.js

@@ -30,2 +30,5 @@ "use strict";

MutationObserver.prototype.observe = function (target, options) {
options = Object.assign({}, options, {
attributeFilter: options.attributeFilter ? options.attributeFilter.map(function (name) { return name.toLowerCase(); }) : null
});
this.target = target;

@@ -32,0 +35,0 @@ this.listener = new MutationListener_1.default();

@@ -175,3 +175,3 @@ "use strict";

}
return node.cloneNode();
return node.cloneNode(true);
};

@@ -178,0 +178,0 @@ /**

@@ -242,4 +242,5 @@ "use strict";

Element.prototype.setAttribute = function (name, value) {
var oldValue = this.attributesMap[name] !== undefined ? this.attributesMap[name] : null;
this.attributesMap[name] = value;
var lowerName = name.toLowerCase();
var oldValue = this.attributesMap[lowerName] !== undefined ? this.attributesMap[lowerName] : null;
this.attributesMap[lowerName] = String(value);
if (this.attributeChangedCallback) {

@@ -253,6 +254,6 @@ this.attributeChangedCallback(name, oldValue, value);

if (observer.options.attributes &&
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(name))) {
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(lowerName))) {
var record = new MutationRecord_1.default();
record.type = MutationType_1.default.attributes;
record.attributeName = name;
record.attributeName = lowerName;
record.oldValue = observer.options.attributeOldValue ? oldValue : null;

@@ -270,3 +271,4 @@ observer.callback([record]);

Element.prototype.getAttribute = function (name) {
return this.attributesMap[name] !== undefined ? this.attributesMap[name] : null;
var lowerName = name.toLowerCase();
return this.attributesMap[lowerName] !== undefined ? this.attributesMap[lowerName] : null;
};

@@ -279,4 +281,5 @@ /**

Element.prototype.removeAttribute = function (name) {
var oldValue = this.attributesMap[name] !== undefined ? this.attributesMap[name] : null;
delete this.attributesMap[name];
var lowerName = name.toLowerCase();
var oldValue = this.attributesMap[lowerName] !== undefined ? this.attributesMap[lowerName] : null;
delete this.attributesMap[lowerName];
// MutationObserver

@@ -287,6 +290,6 @@ if (this.observers.length > 0) {

if (observer.options.attributes &&
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(name))) {
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(lowerName))) {
var record = new MutationRecord_1.default();
record.type = MutationType_1.default.attributes;
record.attributeName = name;
record.attributeName = lowerName;
record.oldValue = observer.options.attributeOldValue ? oldValue : null;

@@ -308,3 +311,3 @@ observer.callback([record]);

while ((match = attributeRegexp.exec(rawAttributes))) {
var name_1 = match[1];
var name_1 = match[1].toLowerCase();
var value = he_1.decode(match[2] || match[3] || match[4] || '');

@@ -311,0 +314,0 @@ this.attributesMap[name_1] = value;

@@ -90,5 +90,6 @@ import NodeType from './NodeType';

*
* @param {boolean} [deep=true] "false" to not clone deep.
* @return {Node} Cloned node.
*/
cloneNode(): Node;
cloneNode(deep?: boolean): Node;
/**

@@ -95,0 +96,0 @@ * Append a child node to childNodes.

@@ -199,5 +199,7 @@ "use strict";

*
* @param {boolean} [deep=true] "false" to not clone deep.
* @return {Node} Cloned node.
*/
Node.prototype.cloneNode = function () {
Node.prototype.cloneNode = function (deep) {
if (deep === void 0) { deep = true; }
var clone = new this.constructor();

@@ -207,12 +209,16 @@ for (var _i = 0, _a = Object.keys(this); _i < _a.length; _i++) {

if (key === 'childNodes') {
for (var _b = 0, _c = this[key]; _b < _c.length; _b++) {
var childNode = _c[_b];
var childClone = childNode.cloneNode();
childClone.parentNode = clone;
clone.childNodes.push(childClone);
if (deep) {
for (var _b = 0, _c = this[key]; _b < _c.length; _b++) {
var childNode = _c[_b];
var childClone = childNode.cloneNode();
childClone.parentNode = clone;
clone.childNodes.push(childClone);
}
}
}
else if (key !== 'parentNode' && key !== 'ownerDocument' && this[key] instanceof Node) {
clone[key] = this[key].cloneNode();
clone[key].parentNode = clone;
if (deep) {
clone[key] = this[key].cloneNode();
clone[key].parentNode = clone;
}
}

@@ -219,0 +225,0 @@ else if (key === 'classList') {

@@ -24,3 +24,3 @@ "use strict";

ShadowRootRenderer.getInnerHTML = function (element, cssCache) {
var clone = element.cloneNode();
var clone = element.cloneNode(true);
this.scopeElement(clone, cssCache);

@@ -27,0 +27,0 @@ return clone.shadowRoot.innerHTML;

@@ -40,3 +40,3 @@ "use strict";

TreeWalker.prototype.parentNode = function () {
if (this.currentNode !== this.root && this.currentNode.parentNode) {
if (this.currentNode !== this.root && this.currentNode && this.currentNode.parentNode) {
this.currentNode = this.currentNode.parentNode;

@@ -53,3 +53,3 @@ return this.currentNode;

TreeWalker.prototype.firstChild = function () {
var childNodes = this.currentNode.childNodes;
var childNodes = this.currentNode ? this.currentNode.childNodes : [];
if (childNodes.length > 0) {

@@ -67,3 +67,3 @@ this.currentNode = childNodes[0];

TreeWalker.prototype.lastChild = function () {
var childNodes = this.currentNode.childNodes;
var childNodes = this.currentNode ? this.currentNode.childNodes : [];
if (childNodes.length > 0) {

@@ -81,3 +81,3 @@ this.currentNode = childNodes[childNodes.length - 1];

TreeWalker.prototype.previousSibling = function () {
if (this.currentNode !== this.root) {
if (this.currentNode !== this.root && this.currentNode) {
var siblings = this.currentNode.parentNode.childNodes;

@@ -98,3 +98,3 @@ var index = siblings.indexOf(this.currentNode);

TreeWalker.prototype.nextSibling = function () {
if (this.currentNode !== this.root) {
if (this.currentNode !== this.root && this.currentNode) {
var siblings = this.currentNode.parentNode.childNodes;

@@ -117,3 +117,3 @@ var index = siblings.indexOf(this.currentNode);

while (!this.nextSibling() && this.parentNode()) { }
this.currentNode = this.currentNode === this.root ? null : this.currentNode;
this.currentNode = this.currentNode === this.root ? null : (this.currentNode || null);
}

@@ -129,3 +129,3 @@ return this.currentNode;

while (!this.previousSibling() && this.parentNode()) { }
this.currentNode = this.currentNode === this.root ? null : this.currentNode;
this.currentNode = this.currentNode === this.root ? null : (this.currentNode || null);
return this.currentNode;

@@ -132,0 +132,0 @@ };

{
"name": "happy-dom",
"version": "0.0.1",
"version": "0.0.2",
"license": "MIT",

@@ -44,2 +44,2 @@ "homepage": "https://github.com/capricorn86/happy-dom#readme",

}
}
}

@@ -71,19 +71,2 @@ import Node from '../nodes/Node';

// /**
// * Prepends text and comment nodes.
// *
// * @param {Document} document Document.
// * @param {Node} node Node.
// * @param {string} text Text to search in.
// */
// private static prependTextAndCommentNodes(document: Document, node: Node, text: string): void {
// for (const innerNode of this.getTextAndCommentNodes(document, text)) {
// if (node.firstChild) {
// node.insertBefore(innerNode, node.firstChild);
// } else {
// node.appendChild(innerNode);
// }
// }
// }
/**

@@ -90,0 +73,0 @@ * Appends text and comment nodes.

@@ -32,2 +32,5 @@ import Node from '../nodes/Node';

public observe(target: Node, options: IMutationObserverInit): void {
options = Object.assign({}, options, {
attributeFilter: options.attributeFilter ? options.attributeFilter.map(name => name.toLowerCase()) : null
});
this.target = target;

@@ -34,0 +37,0 @@ this.listener = new MutationObserverListener();

@@ -170,3 +170,3 @@ import Element from './Element';

}
return node.cloneNode();
return node.cloneNode(true);
}

@@ -173,0 +173,0 @@

@@ -200,4 +200,5 @@ import Node from './Node';

public setAttribute(name: string, value: string): void {
const oldValue = this.attributesMap[name] !== undefined ? this.attributesMap[name] : null;
this.attributesMap[name] = value;
const lowerName = name.toLowerCase();
const oldValue = this.attributesMap[lowerName] !== undefined ? this.attributesMap[lowerName] : null;
this.attributesMap[lowerName] = String(value);

@@ -213,7 +214,7 @@ if (this.attributeChangedCallback) {

observer.options.attributes &&
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(name))
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(lowerName))
) {
const record = new MutationRecord();
record.type = MutationTypeConstant.attributes;
record.attributeName = name;
record.attributeName = lowerName;
record.oldValue = observer.options.attributeOldValue ? oldValue : null;

@@ -232,3 +233,4 @@ observer.callback([record]);

public getAttribute(name: string): string {
return this.attributesMap[name] !== undefined ? this.attributesMap[name] : null;
const lowerName = name.toLowerCase();
return this.attributesMap[lowerName] !== undefined ? this.attributesMap[lowerName] : null;
}

@@ -242,4 +244,5 @@

public removeAttribute(name: string): void {
const oldValue = this.attributesMap[name] !== undefined ? this.attributesMap[name] : null;
delete this.attributesMap[name];
const lowerName = name.toLowerCase();
const oldValue = this.attributesMap[lowerName] !== undefined ? this.attributesMap[lowerName] : null;
delete this.attributesMap[lowerName];

@@ -251,7 +254,7 @@ // MutationObserver

observer.options.attributes &&
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(name))
(!observer.options.attributeFilter || observer.options.attributeFilter.includes(lowerName))
) {
const record = new MutationRecord();
record.type = MutationTypeConstant.attributes;
record.attributeName = name;
record.attributeName = lowerName;
record.oldValue = observer.options.attributeOldValue ? oldValue : null;

@@ -274,3 +277,3 @@ observer.callback([record]);

while ((match = attributeRegexp.exec(rawAttributes))) {
const name = match[1];
const name = match[1].toLowerCase();
const value = decode(match[2] || match[3] || match[4] || '');

@@ -277,0 +280,0 @@ this.attributesMap[name] = value;

@@ -181,16 +181,21 @@ import NodeType from './NodeType';

*
* @param {boolean} [deep=true] "false" to not clone deep.
* @return {Node} Cloned node.
*/
public cloneNode(): Node {
public cloneNode(deep = true): Node {
const clone = new (<typeof Node>this.constructor)();
for (const key of Object.keys(this)) {
if (key === 'childNodes') {
for (const childNode of this[key]) {
const childClone = childNode.cloneNode();
childClone.parentNode = clone;
clone.childNodes.push(childClone);
if (deep) {
for (const childNode of this[key]) {
const childClone = childNode.cloneNode();
childClone.parentNode = clone;
clone.childNodes.push(childClone);
}
}
} else if (key !== 'parentNode' && key !== 'ownerDocument' && this[key] instanceof Node) {
clone[key] = this[key].cloneNode();
clone[key].parentNode = clone;
if (deep) {
clone[key] = this[key].cloneNode();
clone[key].parentNode = clone;
}
} else if (key === 'classList') {

@@ -197,0 +202,0 @@ // eslint-disable-next-line

@@ -20,3 +20,3 @@ import ScopedCSSCache from './css/ScopedCSSCache';

public static getInnerHTML(element: Element | DocumentFragment, cssCache: ScopedCSSCache): string {
const clone = <Element>element.cloneNode();
const clone = <Element>element.cloneNode(true);
this.scopeElement(clone, cssCache);

@@ -23,0 +23,0 @@ return clone.shadowRoot.innerHTML;

@@ -37,3 +37,3 @@ import Node from '../nodes/Node';

public parentNode(): Node {
if (this.currentNode !== this.root && this.currentNode.parentNode) {
if (this.currentNode !== this.root && this.currentNode && this.currentNode.parentNode) {
this.currentNode = this.currentNode.parentNode;

@@ -51,3 +51,3 @@ return this.currentNode;

public firstChild(): Node {
const childNodes = this.currentNode.childNodes;
const childNodes = this.currentNode ? this.currentNode.childNodes : [];

@@ -68,3 +68,3 @@ if (childNodes.length > 0) {

public lastChild(): Node {
const childNodes = this.currentNode.childNodes;
const childNodes = this.currentNode ? this.currentNode.childNodes : [];

@@ -85,3 +85,3 @@ if (childNodes.length > 0) {

public previousSibling(): Node {
if (this.currentNode !== this.root) {
if (this.currentNode !== this.root && this.currentNode) {
const siblings = this.currentNode.parentNode.childNodes;

@@ -105,3 +105,3 @@ const index = siblings.indexOf(this.currentNode);

public nextSibling(): Node {
if (this.currentNode !== this.root) {
if (this.currentNode !== this.root && this.currentNode) {
const siblings = this.currentNode.parentNode.childNodes;

@@ -127,3 +127,3 @@ const index = siblings.indexOf(this.currentNode);

while (!this.nextSibling() && this.parentNode()) {}
this.currentNode = this.currentNode === this.root ? null : this.currentNode;
this.currentNode = this.currentNode === this.root ? null : (this.currentNode || null);
}

@@ -140,3 +140,3 @@ return this.currentNode;

while (!this.previousSibling() && this.parentNode()) {}
this.currentNode = this.currentNode === this.root ? null : this.currentNode;
this.currentNode = this.currentNode === this.root ? null : (this.currentNode || null);
return this.currentNode;

@@ -143,0 +143,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc