Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type error by xmldom #437

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/defaults-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import { DOMParser, XMLSerializer } from '@xmldom/xmldom';
import { DOMParser, Element, XMLSerializer } from '@xmldom/xmldom';

Check warning on line 2 in lib/defaults-utils.js

View workflow job for this annotation

GitHub Actions / test (18)

'Element' is defined but never used

Check warning on line 2 in lib/defaults-utils.js

View workflow job for this annotation

GitHub Actions / test (20)

'Element' is defined but never used

Check warning on line 2 in lib/defaults-utils.js

View workflow job for this annotation

GitHub Actions / test (22)

'Element' is defined but never used

Check warning on line 2 in lib/defaults-utils.js

View workflow job for this annotation

GitHub Actions / test (18)

'Element' is defined but never used

Check warning on line 2 in lib/defaults-utils.js

View workflow job for this annotation

GitHub Actions / test (20)

'Element' is defined but never used

Check warning on line 2 in lib/defaults-utils.js

View workflow job for this annotation

GitHub Actions / test (22)

'Element' is defined but never used
import { exec } from 'teen_process';
import B from 'bluebird';
import log from './logger';
Expand All @@ -12,7 +12,7 @@
* @param {any} value The value to be serialized
* @param {boolean} serialize [true] Whether to serialize the resulting
* XML to string or to return raw HTMLElement instance
* @returns {Node|string} Either string or raw node representation of
* @returns {Element|string} Either string or raw node representation of
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
* the given value
* @throws {TypeError} If it is not known how to serialize the given value
*/
Expand All @@ -25,17 +25,17 @@
const keyEl = xmlDoc.createElement('key');
const keyTextEl = xmlDoc.createTextNode(subKey);
keyEl.appendChild(keyTextEl);
xmlDoc.documentElement.appendChild(keyEl);
xmlDoc.documentElement?.appendChild(keyEl);
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
// @ts-ignore The typecast here is fine
const subValueEl = xmlDoc.importNode(toXmlArg(subValue, false), true);
xmlDoc.documentElement.appendChild(subValueEl);
xmlDoc.documentElement?.appendChild(subValueEl);
}
} else if (_.isArray(value)) {
xmlDoc = new DOMParser().parseFromString('<array></array>', 'text/xml');
for (const subValue of value) {
// @ts-ignore The typecast here is fine
const subValueEl = xmlDoc.importNode(toXmlArg(subValue, false), true);
xmlDoc.documentElement.appendChild(subValueEl);
xmlDoc.documentElement?.appendChild(subValueEl);
}
} else if (_.isBoolean(value)) {
xmlDoc = new DOMParser().parseFromString(value ? '<true/>' : '<false/>', 'text/xml');
Expand All @@ -46,15 +46,15 @@
} else if (_.isString(value)) {
xmlDoc = new DOMParser().parseFromString(`<string></string>`, 'text/xml');
const valueTextEl = xmlDoc.createTextNode(value);
xmlDoc.documentElement.appendChild(valueTextEl);
xmlDoc.documentElement?.appendChild(valueTextEl);
}

if (!xmlDoc) {
if (!xmlDoc || !xmlDoc.documentElement) {
throw new TypeError(`The defaults value ${JSON.stringify(value)} cannot be written, ` +
`because it is not known how to handle its type`);
}

return serialize
return serialize && xmlDoc.documentElement
mykola-mokhnach marked this conversation as resolved.
Show resolved Hide resolved
? new XMLSerializer().serializeToString(xmlDoc.documentElement)
: xmlDoc.documentElement;
}
Expand Down
Loading