Skip to content

Commit

Permalink
switch updates (#459)
Browse files Browse the repository at this point in the history
* switch updates

* revert to if-else

* revert to if-else

* remove empty default
  • Loading branch information
Casheeew authored Dec 27, 2023
1 parent 0094ff7 commit 860374f
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 47 deletions.
53 changes: 36 additions & 17 deletions dev/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,44 @@ export function getArgs(args, argMap) {
}

const target = argMap.get(key);
if (typeof target === 'boolean') {
argMap.set(key, true);
key = null;
} else if (typeof target === 'number') {
argMap.set(key, target + 1);
key = null;
} else if (target === null || typeof target === 'string') {
if (!onKey) {
argMap.set(key, arg);

switch (typeof target) {
case 'boolean':
argMap.set(key, true);
key = null;
}
} else if (Array.isArray(target)) {
if (!onKey) {
target.push(arg);
break;
case 'number':
argMap.set(key, target + 1);
key = null;
}
} else {
console.error(`Unknown argument: ${arg}`);
key = null;
break;
case 'string':
if (!onKey) {
argMap.set(key, arg);
key = null;
}
break;
case 'object':
if (target === null) {
if (!onKey) {
argMap.set(key, arg);
key = null;
}
return argMap;
} else if (Array.isArray(target)) {
if (!onKey) {
target.push(arg);
key = null;
}
return argMap;
} else {
console.error(`Unknown argument: ${arg}`);
key = null;
}
break;
default:
console.error(`Unknown argument: ${arg}`);
key = null;
break;
}
}

Expand Down
18 changes: 12 additions & 6 deletions ext/js/data/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1343,12 +1343,18 @@ class JsonSchemaProxyHandler {
* @returns {?number}
*/
_getArrayIndex(property) {
if (typeof property === 'string' && this._numberPattern.test(property)) {
return Number.parseInt(property, 10);
} else if (typeof property === 'number' && Math.floor(property) === property && property >= 0) {
return property;
} else {
return null;
switch (typeof property) {
case 'string':
if (this._numberPattern.test(property)) {
return Number.parseInt(property, 10);
}
break;
case 'number':
if (Math.floor(property) === property && property >= 0) {
return property;
}
break;
}
return null;
}
}
21 changes: 13 additions & 8 deletions ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,19 @@ export class DisplayGenerator {
* @returns {?HTMLElement}
*/
_createTermDefinitionEntry(entry, dictionary) {
if (typeof entry === 'string') {
return this._createTermDefinitionEntryText(entry);
} else if (typeof entry === 'object' && entry !== null) {
switch (entry.type) {
case 'image':
return this._createTermDefinitionEntryImage(entry, dictionary);
case 'structured-content':
return this._createTermDefinitionEntryStructuredContent(entry.content, dictionary);
switch (typeof entry) {
case 'string':
return this._createTermDefinitionEntryText(entry);
case 'object': {
switch (entry.type) {
case 'image':
return this._createTermDefinitionEntryImage(entry, dictionary);
case 'structured-content':
return this._createTermDefinitionEntryStructuredContent(entry.content, dictionary);
case 'text':
break;
}
break;
}
}

Expand Down
41 changes: 25 additions & 16 deletions ext/js/general/object-property-accessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,21 @@ export class ObjectPropertyAccessor {
v === 0x5f // '_'
) {
value += c;
} else if (v === 0x5b) { // '['
pathArray.push(value);
value = '';
state = 'open-bracket';
} else if (v === 0x2e) { // '.'
pathArray.push(value);
value = '';
state = 'id-start';
} else {
throw new Error(`Unexpected character: ${c}`);
switch (v) {
case 0x5b: // '['
pathArray.push(value);
value = '';
state = 'open-bracket';
break;
case 0x2e: // '.'
pathArray.push(value);
value = '';
state = 'id-start';
break;
default:
throw new Error(`Unexpected character: ${c}`);
}
}
break;
case 'open-bracket': // Open bracket
Expand Down Expand Up @@ -262,15 +267,19 @@ export class ObjectPropertyAccessor {
throw new Error(`Unexpected character: ${c}`);
}
break;
case 'next': // Expecting . or [
if (v === 0x5b) { // '['
state = 'open-bracket';
} else if (v === 0x2e) { // '.'
state = 'id-start';
} else {
throw new Error(`Unexpected character: ${c}`);
case 'next': { // Expecting . or [
switch (v) {
case 0x5b: // '['
state = 'open-bracket';
break;
case 0x2e: // '.'
state = 'id-start';
break;
default:
throw new Error(`Unexpected character: ${c}`);
}
break;
}
}
}
switch (state) {
Expand Down

0 comments on commit 860374f

Please sign in to comment.