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

switch updates #459

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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