- Linting: Comment out unused var.

- Maintenance: Add `.editorconfig`
- npm: Update jml, core-js-bundle, devDeps
This commit is contained in:
Brett Zamir
2019-11-12 22:11:46 +08:00
parent c54444c08b
commit d808cc22de
8 changed files with 1189 additions and 926 deletions

View File

@@ -49,20 +49,35 @@ function _defineProperty(obj, key, value) {
return obj;
}
function _objectSpread(target) {
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === 'function') {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
if (i % 2) {
ownKeys(source, true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(source).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
ownKeys.forEach(function (key) {
_defineProperty(target, key, source[key]);
});
}
return target;
@@ -238,6 +253,10 @@ function _iterableToArray(iter) {
}
function _iterableToArrayLimit(arr, i) {
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
return;
}
var _arr = [];
var _n = true;
var _d = false;
@@ -430,7 +449,7 @@ function _appendNode(parent, child) {
* @static
* @param {Element} el DOM element to which to attach the event
* @param {string} type The DOM event (without 'on') to attach to the element
* @param {Function} handler The event handler to attach to the element
* @param {EventListener} handler The event handler to attach to the element
* @param {boolean} [capturing] Whether or not the event should be
* capturing (W3C-browsers only); default is false; NOT IN USE
* @returns {void}
@@ -472,7 +491,7 @@ function _upperCase(n0, n1) {
} // Todo: Make as public utility
/**
* @param {*} o
* @param {any} o
* @returns {boolean}
*/
@@ -484,7 +503,7 @@ function _isNullish(o) {
/**
* @private
* @static
* @param {string|object|Array|Element|DocumentFragment} item
* @param {string|JamilihAttributes|JamilihArray|Element|DocumentFragment} item
* @returns {"string"|"null"|"array"|"element"|"fragment"|"object"}
*/
@@ -580,7 +599,7 @@ function _jmlSingleArg(arg) {
return jml(arg);
}
/**
* @typedef {Array} AttributeArray
* @typedef {JamilihAttributes} AttributeArray
* @property {string} 0 The key
* @property {string} 1 The value
*/
@@ -668,10 +687,10 @@ function _appendJMLOrText(node) {
* @private
* @static
function _DOMfromJMLOrString (childNodeJML) {
if (typeof childNodeJML === 'string') {
return doc.createTextNode(childNodeJML);
}
return jml(...childNodeJML);
if (typeof childNodeJML === 'string') {
return doc.createTextNode(childNodeJML);
}
return jml(...childNodeJML);
}
*/
@@ -679,12 +698,16 @@ function _DOMfromJMLOrString (childNodeJML) {
* @typedef {Element|DocumentFragment} JamilihReturn
*/
/**
* @typedef {PlainObject} JamilihAttributes
*/
/**
* @typedef {GenericArray} JamilihArray
* @property {string} 0 The element to create (by lower-case name)
* @property {Object} [1] Attributes to add with the key as the attribute name
* and value as the attribute value; important for IE where the input
* element's type cannot be added later after already added to the page
* @property {JamilihAttributes} [1] Attributes to add with the key as the
* attribute name and value as the attribute value; important for IE where
* the input element's type cannot be added later after already added to the page
* @param {Element[]} [children] The optional children of this element
* (but raw DOM elements required to be specified within arrays since
* could not otherwise be distinguished from siblings being added)
@@ -746,9 +769,9 @@ var jml = function jml() {
0. {$xmlDocument: []} // doc.implementation.createDocument
0. Accept array for any attribute with first item as prefix and second as value?
0. {$: ['xhtml', 'div']} for prefixed elements
case '$': // Element with prefix?
nodes[nodes.length] = elem = doc.createElementNS(attVal[0], attVal[1]);
break;
case '$': // Element with prefix?
nodes[nodes.length] = elem = doc.createElementNS(attVal[0], attVal[1]);
break;
*/
case '#':
{
@@ -1034,7 +1057,7 @@ var jml = function jml() {
/*
// Todo:
if (attVal.internalSubset) {
node = {};
node = {};
}
else
*/
@@ -1067,13 +1090,13 @@ var jml = function jml() {
/*
// Todo: Should we auto-copy another node's properties/methods (like DocumentType) excluding or changing its non-entity node values?
const node = {
nodeName: attVal.name,
nodeValue: null,
publicId: attVal.publicId,
systemId: attVal.systemId,
notationName: attVal.notationName,
nodeType: 6,
childNodes: attVal.childNodes.map(_DOMfromJMLOrString)
nodeName: attVal.name,
nodeValue: null,
publicId: attVal.publicId,
systemId: attVal.systemId,
notationName: attVal.notationName,
nodeType: 6,
childNodes: attVal.childNodes.map(_DOMfromJMLOrString)
};
*/
break;
@@ -1219,9 +1242,9 @@ var jml = function jml() {
/*
// The following reorders which is troublesome for serialization, e.g., as used in our testing
if (elem.style.cssText !== undefined) {
elem.style.cssText += attVal;
elem.style.cssText += attVal;
} else { // Opera
elem.style += attVal;
elem.style += attVal;
}
*/
@@ -1316,8 +1339,6 @@ var jml = function jml() {
obj = dataVal[1] || defaultMap[1];
} // Map
/* eslint-disable-next-line unicorn/no-unsafe-regex */
} else if (/^\[object (?:Weak)?Map\]$/.test([].toString.call(dataVal))) {
map = dataVal;
obj = defaultMap[1]; // Non-map data object
@@ -1570,11 +1591,11 @@ var jml = function jml() {
/**
* Converts a DOM object or a string of HTML into a Jamilih object (or string).
* @param {string|HTMLElement} [dom=document.documentElement] Defaults to converting the current document.
* @param {object} [config={stringOutput:false}] Configuration object
* @param {PlainObject} [config] Configuration object
* @param {boolean} [config.stringOutput=false] Whether to output the Jamilih object as a string.
* @returns {Array|string} Array containing the elements which represent a Jamilih object, or,
if `stringOutput` is true, it will be the stringified version of
such an object
* @returns {JamilihArray|string} Array containing the elements which represent
* a Jamilih object, or, if `stringOutput` is true, it will be the stringified
* version of such an object
*/
@@ -1636,7 +1657,7 @@ jml.toJML = function (dom, config) {
}
/**
*
* @param {*} val
* @param {any} val
* @returns {void}
*/
@@ -1684,11 +1705,11 @@ jml.toJML = function (dom, config) {
/*
if ((node.prefix && node.prefix.includes(':')) || (node.localName && node.localName.includes(':'))) {
invalidStateError();
invalidStateError();
}
*/
var type = 'nodeType' in node ? node.nodeType : null;
namespaces = _objectSpread({}, namespaces);
namespaces = _objectSpread2({}, namespaces);
var xmlChars = /([\t\n\r -\uD7FF\uE000-\uFFFD]|(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF]))(?:(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))*$/; // eslint-disable-line no-control-regex
if ([2, 3, 4, 7, 8].includes(type) && !xmlChars.test(node.nodeValue)) {
@@ -1764,7 +1785,7 @@ jml.toJML = function (dom, config) {
break;
}
case undefined: // Treat as attribute node until this is fixed: https://github.com/tmpvar/jsdom/issues/1641 / https://github.com/tmpvar/jsdom/pull/1822
case undefined: // Treat as attribute node until this is fixed: https://github.com/jsdom/jsdom/issues/1641 / https://github.com/jsdom/jsdom/pull/1822
case 2:
// ATTRIBUTE (should only get here if passing in an attribute node)
@@ -2248,8 +2269,8 @@ jml.getXMLSerializer = function () {
};
/**
* Does not run Jamilih so can be further processed.
* @param {Array} jmlArray
* @param {string|Array|Element} glu
* @param {JamilihArray} jmlArray
* @param {string|JamilihArray|Element} glu
* @returns {Element}
*/