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
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@emotion/styled": "^10.0.14",
"@material-ui/core": "^4.2.1",
"color": "^3.1.2",
"luxon": "^1.17.1",
"luxon": "^1.17.2",
"next": "9.0.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
Expand Down Expand Up @@ -47,23 +47,23 @@
"@types/material-ui": "^0.21.6",
"@types/node": "^12.6.8",
"@types/nprogress": "^0.2.0",
"@types/prettier": "^1.16.4",
"@types/prettier": "^1.18.0",
"@types/react": "^16.8.23",
"@types/react-dom": "^16.8.4",
"@types/react-dom": "^16.8.5",
"@types/smoothscroll-polyfill": "^0.3.1",
"@typescript-eslint/eslint-plugin": "^1.12.0",
"@typescript-eslint/parser": "^1.12.0",
"@typescript-eslint/eslint-plugin": "^1.13.0",
"@typescript-eslint/parser": "^1.13.0",
"babel-eslint": "^10.0.1",
"babel-plugin-emotion": "^10.0.14",
"concurrently": "^4.1.1",
"eslint": "^5.16.0",
"eslint-config-prettier": "^6.0.0",
"eslint-config-react-app": "^4.0.1",
"eslint-plugin-flowtype": "^2.x",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.14.2",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.6.1",
"fs-extra": "^8.1.0",
"glob": "^7.1.4",
Expand Down
37 changes: 34 additions & 3 deletions scripts/lib/stepExpressionContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
isCall,
isExecutableCallRegular,
isVariableShorthandUnaryNumber,
isExecutableCallMagical
isExecutableCallMagical,
isExecutableCallBinary
} from 'src/lib/expressionTypeGuards'
import replaceFuncParentKey from 'scripts/lib/replaceFuncParentKey'
import {
Expand All @@ -31,6 +32,7 @@ import {
stepToCaseProcessed,
stepToCaseOnly,
stepToMagicalExpanded,
stepToShorthandComputed,
stepToDefault,
stepToShowExecutableUnary,
stepToUnaryProcessed,
Expand All @@ -46,7 +48,8 @@ import {
ExecutableConditionalStatesDistributed,
ExecutableCall,
ExecutableCallMagical,
ExecutableCallBinary
ExecutableCallBinary,
ExecutableCallShorthand
} from 'src/types/ExpressionTypes'
import prioritizeExpression from 'scripts/lib/prioritizeExpression'

Expand Down Expand Up @@ -178,6 +181,32 @@ const stepMagical = (
}
}

const stepShorthand = (
e: ExecutableCallShorthand
): {
nextExpression: ExecutableCall | StepChild<'default'>
matchExists?: boolean
previouslyChangedExpressionState: ExpressionContainer['previouslyChangedExpressionState']
} => {
switch (e.state) {
case 'default': {
return {
nextExpression: stepToActive(e),
previouslyChangedExpressionState: 'active'
}
}
case 'active': {
return {
nextExpression: stepToShorthandComputed(e),
previouslyChangedExpressionState: 'default'
}
}
default: {
throw new Error()
}
}
}

const stepRegular = (
e: ExecutableCallRegular,
{ showAllShowSteps, skipAlphaConvert }: StepOptions,
Expand Down Expand Up @@ -369,7 +398,9 @@ const runStep = (
? stepRegular(expression, stepOptions, e.matchExists)
: isExecutableCallMagical(expression)
? stepMagical(expression)
: stepBinary(expression)
: isExecutableCallBinary(expression)
? stepBinary(expression)
: stepShorthand(expression)
: stepConditional(expression)

if (!callParent && !callParentKey && !funcParent && !conditionalParent) {
Expand Down
3 changes: 3 additions & 0 deletions scripts/lib/steps/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ export {
export {
default as stepToBinaryComputed
} from 'scripts/lib/steps/stepToBinaryComputed'
export {
default as stepToShorthandComputed
} from 'scripts/lib/steps/stepToShorthandComputed'
41 changes: 37 additions & 4 deletions scripts/lib/steps/stepToActive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
isExecutableCallRegular,
isCall,
isExecutableCallBinary,
isConditional
isConditional,
isExecutableCallShorthand
} from 'src/lib/expressionTypeGuards'
import {
CallExpression,
Expand All @@ -27,13 +28,18 @@ import {
MagicalVariable,
StepMagicalVariable,
ExecutableStepCallMagical,
ExecutableStepCallBinary
ExecutableStepCallBinary,
ExecutableCallShorthand,
ExecutableStepCallShorthand,
VariableShorthandFunc,
StepVariableShorthandFunc
} from 'src/types/ExpressionTypes'

function toActive(
e: VariableShorthandBinary
): StepVariableShorthandBinary<'active'>
function toActive(e: MagicalVariable): StepMagicalVariable<'active'>
function toActive(e: VariableShorthandFunc): StepVariableShorthandFunc<'active'>
function toActive(e: VariableExpression): StepVariable<'active'>
function toActive(e: FunctionExpression): StepFunction<'active'>
function toActive(e: ConditionalExpression): StepConditional<'active'>
Expand Down Expand Up @@ -129,11 +135,19 @@ export default function stepToActive(
e: ExecutableCallBinary
): ExecutableStepCallBinary<'active'>
export default function stepToActive(
e: ExecutableCallRegular | ExecutableCallMagical | ExecutableCallBinary
e: ExecutableCallShorthand
): ExecutableStepCallShorthand<'active'>
export default function stepToActive(
e:
| ExecutableCallRegular
| ExecutableCallMagical
| ExecutableCallBinary
| ExecutableCallShorthand
):
| ExecutableStepCallRegular<'active'>
| ExecutableStepCallMagical<'active'>
| ExecutableStepCallBinary<'active'> {
| ExecutableStepCallBinary<'active'>
| ExecutableStepCallShorthand<'active'> {
if (isExecutableCallBinary(e)) {
return {
...e,
Expand Down Expand Up @@ -162,6 +176,25 @@ export default function stepToActive(
emphasizePriority: true
}
}
} else if (isExecutableCallShorthand(e)) {
return {
...e,
state: 'active',
arg: {
...e.arg,
topLeftBadgeType: 'none',
bottomRightBadgeType: 'none',
highlightType: 'active',
emphasizePriority: true
},
func: {
...e.func,
topLeftBadgeType: 'none',
bottomRightBadgeType: 'none',
highlightType: 'active',
emphasizePriority: true
}
}
} else {
const arg = isFunction(e.arg)
? toExecutableActiveFunction(e.arg)
Expand Down
17 changes: 17 additions & 0 deletions scripts/lib/steps/stepToShorthandComputed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
ExecutableCallShorthand,
VariableShorthandNumber,
StepVariableShorthandNumber
} from 'src/types/ExpressionTypes'
import toDefault from 'scripts/lib/toDefault'

export default function stepToShorthandComputed(
e: ExecutableCallShorthand
): StepVariableShorthandNumber<'default'> {
const result: VariableShorthandNumber = {
...e.arg,
shorthandNumber:
e.arg.shorthandNumber + (e.func.shorthandFunc === 'add' ? 1 : -1)
}
return toDefault(result)
}
7 changes: 6 additions & 1 deletion scripts/lib/toDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import {
StepChild,
StepFunction,
StepVariable,
VariableExpression
VariableExpression,
VariableShorthandNumber,
StepVariableShorthandNumber
} from 'src/types/ExpressionTypes'

export default function toDefault(
e: VariableShorthandNumber
): StepVariableShorthandNumber<'default'>
export default function toDefault(
e: VariableExpression
): StepVariable<'default'>
Expand Down
11 changes: 11 additions & 0 deletions src/components/MinusOne.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import MinusOneSvg from 'src/components/MinusOneSvg'
import Emoji, { EmojiProps } from 'src/components/Emoji'

const MinusOne = (emojiProps: EmojiProps) => (
<Emoji {...emojiProps} customSvg={<MinusOneSvg />} />
)

MinusOne.defaultProps = Emoji.defaultProps

export default MinusOne
27 changes: 27 additions & 0 deletions src/components/MinusOneSvg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react'

const MinusOneSvg = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 36 36" {...props}>
<g stroke="none" strokeWidth={1} fill="none" fillRule="evenodd">
<g fillRule="nonzero">
<path
d="M36,32 C36,34.209 34.209,36 32,36 L4,36 C1.791,36 0,34.209 0,32 L0,4 C0,1.791 1.791,0 4,0 L32,0 C34.209,0 36,1.791 36,4 L36,32 Z"
fill="#BE1931"
/>
<path
d="M25.462,11.175 L23.633,11.175 C22.145,11.175 21.525,10.09 21.525,9.036 C21.525,7.951 22.3,6.896 23.633,6.896 L28.035,6.896 C29.369,6.896 30.113,7.857 30.113,9.097 L30.113,26.74 C30.113,28.291 29.121,29.158 27.787,29.158 C26.454,29.158 25.462,28.291 25.462,26.74 L25.462,11.175 Z"
fill="#FFFFFF"
/>
</g>
<g
transform="translate(4.000000, 16.000000)"
fill="#FFFFFF"
fillRule="nonzero"
>
<path d="M16,1.75 C16,2.71658333 15.3285,3.5 14.5,3.5 L1.5,3.5 C0.6715,3.5 0,2.71658333 0,1.75 C0,0.783416667 0.6715,0 1.5,0 L14.5,0 C15.3285,0 16,0.783416667 16,1.75 Z" />
</g>
</g>
</svg>
)

export default MinusOneSvg
11 changes: 11 additions & 0 deletions src/components/PlusOne.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import PlusOneSvg from 'src/components/PlusOneSvg'
import Emoji, { EmojiProps } from 'src/components/Emoji'

const PlusOne = (emojiProps: EmojiProps) => (
<Emoji {...emojiProps} customSvg={<PlusOneSvg />} />
)

PlusOne.defaultProps = Emoji.defaultProps

export default PlusOne
23 changes: 23 additions & 0 deletions src/components/PlusOneSvg.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react'

const PlusOneSvg = (props: React.SVGProps<SVGSVGElement>) => (
<svg viewBox="0 0 36 36" {...props}>
<g stroke="none" strokeWidth={1} fill="none" fillRule="evenodd">
<g fillRule="nonzero">
<path
d="M36,32 C36,34.209 34.209,36 32,36 L4,36 C1.791,36 0,34.209 0,32 L0,4 C0,1.791 1.791,0 4,0 L32,0 C34.209,0 36,1.791 36,4 L36,32 Z"
fill="#31373D"
/>
<path
d="M25.462,11.175 L23.633,11.175 C22.145,11.175 21.525,10.09 21.525,9.036 C21.525,7.951 22.3,6.896 23.633,6.896 L28.035,6.896 C29.369,6.896 30.113,7.857 30.113,9.097 L30.113,26.74 C30.113,28.291 29.121,29.158 27.787,29.158 C26.454,29.158 25.462,28.291 25.462,26.74 L25.462,11.175 Z"
fill="#FFFFFF"
/>
<g transform="translate(4.000000, 10.000000)" fill="#FFFFFF">
<path d="M14.5,6.5 L9.5,6.5 L9.5,1.5 C9.5,0.6715 8.8285,0 8,0 C7.1715,0 6.5,0.6715 6.5,1.5 L6.5,6.5 L1.5,6.5 C0.6715,6.5 0,7.1715 0,8 C0,8.8285 0.6715,9.5 1.5,9.5 L6.5,9.5 L6.5,14.5 C6.5,15.3285 7.1715,16 8,16 C8.8285,16 9.5,15.3285 9.5,14.5 L9.5,9.5 L14.5,9.5 C15.3285,9.5 16,8.8285 16,8 C16,7.1715 15.3285,6.5 14.5,6.5 Z" />
</g>
</g>
</g>
</svg>
)

export default PlusOneSvg
14 changes: 14 additions & 0 deletions src/components/VariableExpressionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { VariableExpression } from 'src/types/ExpressionTypes'
import H from 'src/components/H'
import { ExpressionRunnerContextProps } from 'src/types/ExpressionRunnerTypes'
import BlankNumber from 'src/components/BlankNumber'
import PlusOne from 'src/components/PlusOne'
import MinusOne from 'src/components/MinusOne'

interface VariableExpressionBoxProps {
expression: VariableExpression
Expand Down Expand Up @@ -175,6 +177,18 @@ const VariableEmoji = ({ expression }: VariableExpressionBoxProps) => {
</span>
</div>
)
} else if (expression.shorthandFunc === 'add') {
return (
<div>
<PlusOne size="sm" />
</div>
)
} else if (expression.shorthandFunc === 'pred') {
return (
<div>
<MinusOne size="sm" />
</div>
)
} else {
return (
<span
Expand Down
19 changes: 18 additions & 1 deletion src/lib/expressionTypeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
VariableShorthandUnaryNumber,
ExecutableCallMagical,
MagicalVariable,
RepeatExpression
RepeatExpression,
ExecutableCallShorthand,
VariableShorthandFunc
} from 'src/types/ExpressionTypes'

export function isVariable<V extends VariableExpression = VariableExpression>(
Expand Down Expand Up @@ -59,6 +61,12 @@ export function isVariableShorthandBinary<
return isVariable(expression) && expression.shorthandBinary !== undefined
}

export function isVariableShorthandFunc<
V extends VariableShorthandFunc = VariableShorthandFunc
>(expression: Expression): expression is V {
return isVariable(expression) && expression.shorthandFunc !== undefined
}

export function isVariableShorthandUnaryNumber<
V extends VariableShorthandUnaryNumber = VariableShorthandUnaryNumber
>(expression: Expression): expression is V {
Expand Down Expand Up @@ -97,6 +105,15 @@ export function isExecutableCallBinary<E extends ExecutableCallBinary>(
)
}

export function isExecutableCallShorthand<E extends ExecutableCallShorthand>(
expression: CallExpression
): expression is E {
return (
isVariableShorthandFunc(expression.func) &&
isVariableShorthandNumber(expression.arg)
)
}

export function isExecutableCall<E extends ExecutableCall>(
expression: CallExpression
): expression is E {
Expand Down
Loading