diff options
-rw-r--r-- | dev/util.js | 53 | ||||
-rw-r--r-- | ext/js/data/json-schema.js | 18 | ||||
-rw-r--r-- | ext/js/display/display-generator.js | 21 | ||||
-rw-r--r-- | ext/js/general/object-property-accessor.js | 41 |
4 files changed, 86 insertions, 47 deletions
diff --git a/dev/util.js b/dev/util.js index 542ad6a2..731b5456 100644 --- a/dev/util.js +++ b/dev/util.js @@ -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; } } diff --git a/ext/js/data/json-schema.js b/ext/js/data/json-schema.js index 08414164..ee58976e 100644 --- a/ext/js/data/json-schema.js +++ b/ext/js/data/json-schema.js @@ -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; } } diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index 920d2c94..b91d0ce9 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -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; } } diff --git a/ext/js/general/object-property-accessor.js b/ext/js/general/object-property-accessor.js index d818c9d1..b8d6ddc5 100644 --- a/ext/js/general/object-property-accessor.js +++ b/ext/js/general/object-property-accessor.js @@ -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 @@ -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) { |