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 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
53 changes: 36 additions & 17 deletions dev/util.js
Casheeew marked this conversation as resolved.
Show resolved Hide resolved
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
20 changes: 14 additions & 6 deletions ext/js/data/json-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -1343,12 +1343,20 @@ 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;
default:
Casheeew marked this conversation as resolved.
Show resolved Hide resolved
break;
}
return null;
}
}
23 changes: 15 additions & 8 deletions ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,22 @@ 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;
}
default:
Casheeew marked this conversation as resolved.
Show resolved Hide resolved
break;
}

return null;
Expand Down
58 changes: 35 additions & 23 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 @@ -253,24 +258,31 @@ export class ObjectPropertyAccessor {
throw new Error(`Unexpected character: ${c}`);
}
break;
case 'close-bracket': // Expecting closing bracket after quoted string
if (v === 0x5d) { // ']'
pathArray.push(value);
value = '';
state = 'next';
} else {
throw new Error(`Unexpected character: ${c}`);
case 'close-bracket': { // Expecting closing bracket after quoted string
switch (v) {
Casheeew marked this conversation as resolved.
Show resolved Hide resolved
case 0x5d: // ']'
pathArray.push(value);
value = '';
state = 'next';
break;
default:
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