Skip to content

Commit f218052

Browse files
Allow to have boolean values in set-property and set-attribute commands
1 parent ad898bc commit f218052

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/commands/dom_modifiers.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function innerParseCssAttribute(
2929
jsonValidator.valueTypes.ident = {
3030
allowed: ['null'],
3131
};
32+
jsonValidator.valueTypes.boolean = {};
3233
}
3334
const ret = validator(parser,
3435
{
@@ -55,7 +56,7 @@ function innerParseCssAttribute(
5556
}
5657
const code = [];
5758
for (const [key, value] of attributes) {
58-
code.push(callback(key, value, value.kind === 'ident'));
59+
code.push(callback(key, value, value.kind));
5960
}
6061
const func = allowObjectPath ? `
6162
function setObjValue(object, path, value) {
@@ -92,8 +93,8 @@ ${indentString(code.join('\n'), 1)}
9293
// * ("selector", JSON dict)
9394
function parseSetAttribute(parser) {
9495
return innerParseCssAttribute(parser, 'attribute', 'parseSetAttributeElem', true,
95-
(key, value, isIdent) => {
96-
if (!isIdent) {
96+
(key, value, kind) => {
97+
if (kind !== 'ident' && kind !== 'boolean') {
9798
return `e.setAttribute("${key}","${value.value}");`;
9899
}
99100
return `e.removeAttribute("${key}");`;
@@ -106,9 +107,11 @@ function parseSetAttribute(parser) {
106107
// * ("selector", JSON dict)
107108
function parseSetProperty(parser) {
108109
return innerParseCssAttribute(parser, 'property', 'parseSetPropertyElem', true,
109-
(key, value, isIdent) => {
110+
(key, value, kind) => {
110111
const k_s = value.key.kind === 'object-path' ? key : `["${key}"]`;
111-
const arg = isIdent ? 'undefined' : `"${value.value}"`;
112+
const arg = kind === 'ident' ? 'undefined' :
113+
// eslint-disable-next-line no-extra-parens
114+
(kind === 'boolean' ? `${value.value}` : `"${value.value}"`);
112115
return `setObjValue(e, ${k_s}, ${arg});`;
113116
}, true);
114117
}
@@ -119,7 +122,7 @@ function parseSetProperty(parser) {
119122
// * ("selector", JSON dict)
120123
function parseSetCss(parser) {
121124
return innerParseCssAttribute(parser, 'CSS property', 'parseSetCssElem', false,
122-
(key, value, _isIdent) => `e.style["${key}"] = "${value.value}";`, false);
125+
(key, value, _kind) => `e.style["${key}"] = "${value.value}";`, false);
123126
}
124127

125128
// Possible inputs:

src/commands/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ ${varValue} + '\` (for NEAR check)');
126126
}`;
127127
}
128128
}
129-
// eslint-disable-next-line no-extra-parens
130129
const hasSpecialChecks = checks.length !== 0;
131130
if (checks.length === 0) {
132131
if (assertFalse) {

0 commit comments

Comments
 (0)