Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
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
11 changes: 11 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ const config = withTypescript({
test: path.resolve(__dirname, 'test'),
scripts: path.resolve(__dirname, 'scripts')
})

// TODO: Remove when https://github.com/webpack/webpack/pull/9349 is
// added on the webpack version I'm using
config.module.rules.push({
test: /\.json$/,
type: 'javascript/auto',
use: {
loader: path.resolve(__dirname, './optimizedJsonLoader.js')
}
})

return config
},
env: {
Expand Down
12 changes: 12 additions & 0 deletions optimizedJsonLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = function loadJsonModule(source) {
if (typeof source !== 'string') {
throw new Error('Unexpected source type: ' + typeof source)
}
const object = JSON.parse(source)
const jsonSource = JSON.stringify(object)

// cf. https://v8.dev/blog/cost-of-javascript-2019
// > As long as the JSON string is only evaluated once, the JSON.parse approach is
// > much faster compared to the JavaScript object literal, especially for cold loads.
return `module.exports = JSON.parse(${JSON.stringify(jsonSource)});`
}
21 changes: 17 additions & 4 deletions scripts/lib/buildExpressionFromParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
isVariableShorthandBinaryParams,
isVariableShorthandUnaryParams,
isVariableShorthandNumberParams,
isMagicalVariableParams
isMagicalVariableParams,
isConditionalParams
} from 'scripts/lib/expressionParamGuards'
import {
CallExpressionParams,
Expand All @@ -17,7 +18,8 @@ import {
VariableShorthandBinaryParams,
VariableShorthandNumberParams,
ConditionalExpressionParams,
MagicalVariableParams
MagicalVariableParams,
RepeatExpressionParams
} from 'src/types/ExpressionParamTypes'
import {
NonExecutableStepCall,
Expand All @@ -27,7 +29,8 @@ import {
StepVariableShorthandBinary,
StepVariableShorthandNumber,
StepConditional,
StepMagicalVariable
StepMagicalVariable,
RepeatExpression
} from 'src/types/ExpressionTypes'
import { VariableNames } from 'src/types/VariableNames'

Expand Down Expand Up @@ -93,6 +96,9 @@ export default function buildExpressionFromParams(
export default function buildExpressionFromParams(
expressionParams: ConditionalExpressionParams
): StepConditional
export default function buildExpressionFromParams(
expressionParams: RepeatExpressionParams
): RepeatExpression
export default function buildExpressionFromParams(
expressionParams: ExpressionParams
): StepChild
Expand Down Expand Up @@ -178,7 +184,7 @@ export default function buildExpressionFromParams(
),
magical: expressionParams.magical
}
} else {
} else if (isConditionalParams(expressionParams)) {
return {
type: 'conditional',
state: 'default',
Expand All @@ -188,5 +194,12 @@ export default function buildExpressionFromParams(
falseCase: buildExpressionFromParams(expressionParams.falseCase),
priority: 0
}
} else {
return {
type: 'repeat',
begin: expressionParams.begin,
end: expressionParams.end,
child: buildExpressionFromParams(expressionParams.child)
}
}
}
7 changes: 5 additions & 2 deletions scripts/lib/checkExecutableUnaryExists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
isFunction,
isVariable,
isCall,
isVariableShorthandUnaryNumber
isVariableShorthandUnaryNumber,
isConditional
} from 'src/lib/expressionTypeGuards'
import { Expression } from 'src/types/ExpressionTypes'

Expand All @@ -17,12 +18,14 @@ const checkExecutableUnaryExists = (e: Expression): boolean => {
return (
checkExecutableUnaryExists(e.arg) || checkExecutableUnaryExists(e.func)
)
} else {
} else if (isConditional(e)) {
return (
checkExecutableUnaryExists(e.condition) ||
checkExecutableUnaryExists(e.trueCase) ||
checkExecutableUnaryExists(e.falseCase)
)
} else {
throw new Error()
}
}

Expand Down
11 changes: 9 additions & 2 deletions scripts/lib/getConflictsToUnused.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import difference from 'lodash/difference'
import intersection from 'lodash/intersection'
import { ExecutableCallRegular } from 'src/types/ExpressionTypes'
import uniq from 'lodash/uniq'
import { isCall, isVariable, isFunction } from 'src/lib/expressionTypeGuards'
import {
isCall,
isVariable,
isFunction,
isConditional
} from 'src/lib/expressionTypeGuards'
import { Expression } from 'src/types/ExpressionTypes'
import { VariableNames } from 'src/types/VariableNames'
import alphaConvertTargetVariableNames from 'scripts/lib/alphaConvertTargetVariableNames'
Expand All @@ -29,10 +34,12 @@ function getAllVariableNamesWithDuplicates(
return getAllVariableNames(expression.arg, { filter }).concat(
getAllVariableNames(expression.body, { filter })
)
} else {
} else if (isConditional(expression)) {
return getAllVariableNames(expression.condition, { filter })
.concat(getAllVariableNames(expression.trueCase, { filter }))
.concat(getAllVariableNames(expression.falseCase, { filter }))
} else {
throw new Error()
}
}

Expand Down
11 changes: 9 additions & 2 deletions scripts/lib/hasUnboundVariables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isCall, isVariable, isFunction } from 'src/lib/expressionTypeGuards'
import {
isCall,
isVariable,
isFunction,
isConditional
} from 'src/lib/expressionTypeGuards'
import { Expression } from 'src/types/ExpressionTypes'

export default function hasUnboundVariables(expression: Expression): boolean {
Expand All @@ -14,11 +19,13 @@ export default function hasUnboundVariables(expression: Expression): boolean {
hasUnboundVariables(expression.arg) ||
hasUnboundVariables(expression.body)
)
} else {
} else if (isConditional(expression)) {
return (
hasUnboundVariables(expression.condition) ||
hasUnboundVariables(expression.trueCase) ||
hasUnboundVariables(expression.falseCase)
)
} else {
throw new Error()
}
}
16 changes: 16 additions & 0 deletions scripts/lib/initialExpressionContainers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1383,3 +1383,19 @@ export const gxqm = initializeExpressionContainer({
shorthandNumber: 28
}
})

export const gcie = initializeExpressionContainer([
{
begin: 2,
end: 5,
child: [
'blankNumber',
{
shorthandBinary: 'mult'
}
]
},
{
shorthandNumber: 1
}
])
11 changes: 9 additions & 2 deletions scripts/lib/maxNestedFunctionDepth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isCall, isVariable, isFunction } from 'src/lib/expressionTypeGuards'
import {
isCall,
isVariable,
isFunction,
isConditional
} from 'src/lib/expressionTypeGuards'
import { Expression } from 'src/types/ExpressionTypes'

export default function maxNestedFunctionDepth(expression: Expression): number {
Expand All @@ -11,11 +16,13 @@ export default function maxNestedFunctionDepth(expression: Expression): number {
)
} else if (isFunction(expression)) {
return 1 + maxNestedFunctionDepth(expression.body)
} else {
} else if (isConditional(expression)) {
return Math.max(
maxNestedFunctionDepth(expression.condition),
maxNestedFunctionDepth(expression.trueCase),
maxNestedFunctionDepth(expression.falseCase)
)
} else {
return 0
}
}
17 changes: 16 additions & 1 deletion scripts/lib/prioritizeExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
isCall,
isFunction,
isVariable,
isConditional
isConditional,
isRepeat
} from 'src/lib/expressionTypeGuards'
import {
CallExpression,
Expand Down Expand Up @@ -190,6 +191,11 @@ function prioritizeExpressionHelper<E extends Expression = Expression>(
priority: 1,
expression
}).expression
} else if (isRepeat(expression)) {
return {
...expression,
child: prioritizeExpressionHelper(expression.child)
}
} else {
throw new Error()
}
Expand Down Expand Up @@ -253,6 +259,15 @@ function populatePriorityAggs<E extends Expression>({
funcPriorityAgg: [expression.priority, ...funcPriorityAgg]
})
}
} else if (isRepeat(expression)) {
return {
...expression,
child: populatePriorityAggs({
expression: expression.child,
argPriorityAgg,
funcPriorityAgg
})
}
} else {
throw new Error()
}
Expand Down
11 changes: 9 additions & 2 deletions scripts/lib/replaceCallParentKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isCall, isVariable, isFunction } from 'src/lib/expressionTypeGuards'
import {
isCall,
isVariable,
isFunction,
isConditional
} from 'src/lib/expressionTypeGuards'
import {
CallExpression,
Expression,
Expand Down Expand Up @@ -69,7 +74,7 @@ export default function replaceCallParentKey(
...expression,
body: replaceCallParentKey(expression.body, target, key, replaceWith)
}
} else {
} else if (isConditional(expression)) {
return {
...expression,
condition: replaceCallParentKey(
Expand All @@ -91,5 +96,7 @@ export default function replaceCallParentKey(
replaceWith
)
}
} else {
throw new Error()
}
}
11 changes: 9 additions & 2 deletions scripts/lib/replaceConditionalParentKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isCall, isVariable, isFunction } from 'src/lib/expressionTypeGuards'
import {
isCall,
isVariable,
isFunction,
isConditional
} from 'src/lib/expressionTypeGuards'
import {
CallExpression,
Expression,
Expand Down Expand Up @@ -55,7 +60,7 @@ export default function replaceConditionalParentKey(
...expression,
body: replaceConditionalParentKey(expression.body, target, replaceWith)
}
} else {
} else if (isConditional(expression)) {
if (expression === target) {
return {
...expression,
Expand All @@ -81,5 +86,7 @@ export default function replaceConditionalParentKey(
)
}
}
} else {
throw new Error()
}
}
11 changes: 9 additions & 2 deletions scripts/lib/replaceFuncParentKey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isCall, isVariable, isFunction } from 'src/lib/expressionTypeGuards'
import {
isCall,
isVariable,
isFunction,
isConditional
} from 'src/lib/expressionTypeGuards'
import {
CallExpression,
Expression,
Expand Down Expand Up @@ -62,7 +67,7 @@ export default function replaceFuncParentKey(
body: replaceFuncParentKey(expression.body, target, replaceWith)
}
}
} else {
} else if (isConditional(expression)) {
return {
...expression,
condition: replaceFuncParentKey(
Expand All @@ -73,5 +78,7 @@ export default function replaceFuncParentKey(
trueCase: replaceFuncParentKey(expression.trueCase, target, replaceWith),
falseCase: replaceFuncParentKey(expression.falseCase, target, replaceWith)
}
} else {
throw new Error()
}
}
11 changes: 9 additions & 2 deletions scripts/lib/resetExpression.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { isCall, isVariable, isFunction } from 'src/lib/expressionTypeGuards'
import {
isCall,
isVariable,
isFunction,
isConditional
} from 'src/lib/expressionTypeGuards'
import {
CallExpression,
Expression,
Expand Down Expand Up @@ -57,7 +62,7 @@ export default function resetExpression(
arg: resetExpression(expression.arg),
body: resetExpression(expression.body)
}
} else {
} else if (isConditional(expression)) {
return {
...expression,
state: 'default',
Expand All @@ -66,5 +71,7 @@ export default function resetExpression(
trueCase: resetExpression(expression.trueCase),
falseCase: resetExpression(expression.falseCase)
}
} else {
throw new Error()
}
}
5 changes: 5 additions & 0 deletions scripts/lib/runnerConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2715,3 +2715,8 @@ export const zqum: ExpressionRunnerShorthandConfig = {
runner: 'playButtonOnly',
initialExpressionContainer: initialExpressionContainers.qolg
}

export const oklg: ExpressionRunnerShorthandConfig = {
runner: 'simple',
initialExpressionContainer: initialExpressionContainers.gcie
}
Loading