Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[*]
end_of_line = lf
end_of_line = lf
4 changes: 3 additions & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@v5
with:
submodules: recursive
- name: Install dependencies (apt)
run: |
sudo apt-get update && \
Expand Down
76 changes: 38 additions & 38 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,41 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Check for package-lock.json
run: |
if [ -e package-lock.json ]; then
echo "package-lock.json found; please do not use NPM! This project uses Yarn!"
exit 1
fi
exit 0
- name: Install dependencies (apt)
run: |
sudo apt-get update && \
sudo apt-get install -y --no-install-recommends \
texlive texlive-fonts-extra texlive-lang-cjk latexmk latex-cjk-all
# Has to be run before actions/setup-node.
# See: https://github.com/actions/setup-node/issues/480
- name: Enable corepack for Yarn
run: corepack enable
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- run: yarn install --immutable
- run: yarn build
- run: yarn format:ci
- run: yarn eslint
- run: yarn test-coverage
env:
CI: true
- name: Check that docs build
run: yarn jsdoc prepare
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v5
with:
submodules: recursive
- name: Check for package-lock.json
run: |
if [ -e package-lock.json ]; then
echo "package-lock.json found; please do not use NPM! This project uses Yarn!"
exit 1
fi
exit 0
- name: Install dependencies (apt)
run: |
sudo apt-get update && \
sudo apt-get install -y --no-install-recommends \
texlive texlive-fonts-extra texlive-lang-cjk latexmk latex-cjk-all
# Has to be run before actions/setup-node.
# See: https://github.com/actions/setup-node/issues/480
- name: Enable corepack for Yarn
run: corepack enable
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- run: yarn install --immutable
- run: yarn build
- run: yarn format:ci
- run: yarn eslint
- run: yarn test-coverage
env:
CI: true
- name: Check that docs build
run: yarn jsdoc prepare
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ test-report.html
!.yarn/releases
!.yarn/sdks
!.yarn/versions
yarn-error.log
yarn-error.log
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/src/alt-langs/
/src/py-slang/
/src/**/__tests__/**/__snapshots__
/src/**/__tests__/**/__snapshots__
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@types/babel__core": "^7",
"@types/jest": "^29.0.0",
"@types/lodash": "^4.14.202",
"@types/mathjs": "^9.4.2",
"@types/node": "^20.0.0",
"@types/offscreencanvas": "^2019.7.0",
"ace-builds": "~1.17.0",
Expand All @@ -82,7 +83,7 @@
"jsdom": "^19.0.0",
"prettier": "^3.6.2",
"ts-jest": "^29.0.0",
"typescript": "^4.0.3",
"typescript": "^5.9.2",
"typescript-eslint": "^8.8.1"
},
"devEngines": {
Expand Down
2 changes: 1 addition & 1 deletion src/alt-langs/scheme/scm-slang
Submodule scm-slang updated 2 files
+9 −9 package.json
+2,692 −1,462 yarn.lock
24 changes: 12 additions & 12 deletions src/createContext.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// Variable determining chapter of Source is contained in this file.

import { schemeVisualise } from './alt-langs/scheme/scheme-mapper'
import * as scheme_libs from './alt-langs/scheme/scm-slang/src/stdlib/source-scheme-library'
import {
scheme1Prelude,
scheme2Prelude,
scheme3Prelude,
scheme4Prelude,
schemeFullPrelude
} from './stdlib/scheme.prelude'
import { GLOBAL, JSSLANG_PROPERTIES } from './constants'
import { call_with_current_continuation } from './cse-machine/continuations'
import Heap from './cse-machine/heap'
import { Transformers } from './cse-machine/interpreter'
import { cset_apply, cset_eval } from './cse-machine/scheme-macros'
import * as list from './stdlib/list'
import { list_to_vector } from './stdlib/list'
import { listPrelude } from './stdlib/list.prelude'
import { localImportPrelude } from './stdlib/localImport.prelude'
import * as misc from './stdlib/misc'
import * as parser from './stdlib/parser'
import * as pylib from './stdlib/pylib'
import {
scheme1Prelude,
scheme2Prelude,
scheme3Prelude,
scheme4Prelude,
schemeFullPrelude
} from './stdlib/scheme.prelude'
import * as stream from './stdlib/stream'
import { streamPrelude } from './stdlib/stream.prelude'
import { createTypeEnvironment, tForAll, tVar } from './typeChecker/utils'
Expand All @@ -33,9 +36,6 @@
} from './types'
import * as operators from './utils/operators'
import { stringify } from './utils/stringify'
import { schemeVisualise } from './alt-langs/scheme/scheme-mapper'
import { cset_apply, cset_eval } from './cse-machine/scheme-macros'
import { Transformers } from './cse-machine/interpreter'

export class EnvTree {
private _root: EnvTreeNode | null = null
Expand Down Expand Up @@ -262,7 +262,7 @@
ensureGlobalEnvironmentExist(context)

externalSymbols.forEach(symbol => {
defineSymbol(context, symbol, GLOBAL[symbol])
defineSymbol(context, symbol, GLOBAL[symbol as keyof typeof GLOBAL])
})
}

Expand Down Expand Up @@ -324,7 +324,7 @@
// Short param names for stringified version of math functions
const parameterNames = [...'abcdefghijklmnopqrstuvwxyz']
for (const name of mathLibraryNames) {
const value = Math[name]
const value = Math[name as keyof typeof Math]
if (typeof value === 'function') {
let paramString: string
let minArgsNeeded = undefined
Expand Down Expand Up @@ -385,7 +385,7 @@
'call_cc(f)',
context.variant === Variant.EXPLICIT_CONTROL
? call_with_current_continuation
: (f: any) => {

Check warning on line 388 in src/createContext.ts

View workflow job for this annotation

GitHub Actions / build

'f' is defined but never used. Allowed unused args must match /^_/u
throw new Error('call_cc is only available in Explicit-Control variant')
}
)
Expand Down
5 changes: 3 additions & 2 deletions src/editors/ace/modes/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}
)[] = []
) {
// @ts-ignore
// @ts-expect-error implicit any
function _SourceHighlightRules(acequire, exports, _module) {
'use strict'

Expand All @@ -49,7 +49,8 @@
const identifierRegex = '[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*'

const chapter = variant === Variant.DEFAULT ? id.toString() : id.toString() + '_' + variant
const builtin_lib = SourceDocumentation.builtins[chapter]
const builtin_lib =
SourceDocumentation.builtins[chapter as keyof typeof SourceDocumentation.builtins]

function addFromBuiltinLibrary(meta: string) {
if (builtin_lib === null) {
Expand Down Expand Up @@ -120,9 +121,9 @@

// Documentation for token types:
// https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode#common-tokens
// @ts-ignore

Check warning on line 124 in src/editors/ace/modes/source.ts

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const SourceHighlightRules = function (options) {
// @ts-ignore

Check warning on line 126 in src/editors/ace/modes/source.ts

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
const keywordMapper = this.createKeywordMapper(
{
builtinconsts: getAllNames('const'),
Expand Down Expand Up @@ -159,7 +160,7 @@
'[4-7][0-7]?|' + //oct
'.)'

// @ts-ignore

Check warning on line 163 in src/editors/ace/modes/source.ts

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
this.$rules = {
no_regex: [
DocCommentHighlightRules.getStartRule('doc-start'),
Expand Down Expand Up @@ -522,11 +523,11 @@
}

if (!options || !options.noES6) {
// @ts-ignore

Check warning on line 526 in src/editors/ace/modes/source.ts

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
this.$rules.no_regex.unshift(
{
regex: '[{}]',
// @ts-ignore

Check warning on line 530 in src/editors/ace/modes/source.ts

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
onMatch: function (val, state, stack) {
this.next = val == '{' ? this.nextState : ''
if (val == '{' && stack.length) {
Expand Down Expand Up @@ -567,13 +568,13 @@
)

if (!options || options.jsx != false)
// @ts-ignore

Check warning on line 571 in src/editors/ace/modes/source.ts

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
JSX.call(this)

// Adding of highlight rules for Source Typed
// Code referenced from https://github.com/ajaxorg/ace-builds/blob/master/src/mode-typescript.js
if (variant === Variant.TYPED) {
// @ts-ignore

Check warning on line 577 in src/editors/ace/modes/source.ts

View workflow job for this annotation

GitHub Actions / build

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
this.$rules.no_regex.unshift(
{
token: ['storage.type', 'text', 'entity.name.function.ts'],
Expand Down
13 changes: 7 additions & 6 deletions src/infiniteLoops/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import type es from 'estree'
import { transformImportDeclarations } from '../transpiler/transpiler'
import type { Node } from '../types'
import * as create from '../utils/ast/astCreator'
import { recursive, simple, WalkerCallback } from '../utils/walkers'
import { getIdsFromDeclaration } from '../utils/ast/helpers'
import { objectValues } from '../utils/misc'
import { recursive, simple, WalkerCallback } from '../utils/walkers'
// transforms AST of program

const globalIds = {
Expand Down Expand Up @@ -40,8 +41,8 @@ enum FunctionNames {
* E.g. "function f(f)..." -> "function f_0(f_1)..."
* @param predefined A table of [key: string, value:string], where variables named 'key' will be renamed to 'value'
*/
function unshadowVariables(program: Node, predefined = {}) {
for (const name of Object.values(globalIds)) {
function unshadowVariables(program: Node, predefined: { [key: string]: string } = {}) {
for (const name of objectValues(globalIds)) {
predefined[name] = name
}
const seenIds = new Set()
Expand Down Expand Up @@ -607,7 +608,7 @@ function instrument(
builtins: Iterable<string>
): string {
const { builtinsId, functionsId, stateId } = globalIds
const predefined = {}
const predefined: Record<string, string> = {}
predefined[builtinsId] = builtinsId
predefined[functionsId] = functionsId
predefined[stateId] = stateId
Expand Down Expand Up @@ -640,7 +641,7 @@ function instrument(
}

export {
instrument,
FunctionNames as InfiniteLoopRuntimeFunctions,
globalIds as InfiniteLoopRuntimeObjectNames
globalIds as InfiniteLoopRuntimeObjectNames,
instrument
}
2 changes: 1 addition & 1 deletion src/infiniteLoops/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function prepareBuiltins(oldBuiltins: Map<string, any>) {
const nonDetFunctions = ['get_time', 'math_random']
const newBuiltins = new Map<string, any>()
for (const [name, fun] of oldBuiltins) {
const specialCase = builtinSpecialCases[name]
const specialCase = builtinSpecialCases[name as keyof typeof builtinSpecialCases]
if (specialCase !== undefined) {
newBuiltins.set(name, specialCase)
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/infiniteLoops/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export class State {
}
const transitions = this.mixedStack[this.stackPointer].transitions
for (let i = 0; i < transitions.length; i++) {
const transition = transitions[i]
// TODO: Something seems to be very wrong with the type definitions here
// Shall we just remove the infinite loop detector as per #1516?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we reraise this as an issue? I know that in #1516 it was agreed that the component was useful, but with the problems we are having with it (increased complexity, here we see strange issues with types) we may want to reimplement it (probably only viable as a student project if it's breaking?) or reevaluate it again

Copy link
Member Author

@RichDom2185 RichDom2185 Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, I try to fix type issues as I go (even if it means weird typecasts etc.) but this is beyond me; either it's some super old TS logic that predates my knowledge of the "modern" 4.x and 5.x versions or it's just (ab)use of TS that was somehow never caught.

Without looking at the code and figuring out how this all works I had to resort to just putting an any there.

I suspect the original type definitions may have not been entirely correct, but since TS used to implicitly give an any for these kinds of invalid accesses (and they are accessed in a way consistent and expected of the actual contract/behaviour) then it all just magically seems to work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with removing the feature for now. Re-implementing it will lead to a cleaner implementation.

The project is well-documented in a report and can be revived from there.

I don't think the system will be missed very much. It carries a bit of infrastructure with a server side, sentry support etc that was needed for carrying out the project.

So yea, please go ahead and remove it.

const transition: any = transitions[i]
if (transition[0] === name) {
transition[1] = concrete
transition[2] = id
Expand Down Expand Up @@ -234,6 +236,6 @@ export class State {
* @returns the name of the last function in the stack.
*/
public getLastFunctionName() {
return this.functionStack[this.functionStack.length - 1][0]
return (this.functionStack[this.functionStack.length - 1] as any)[0]
}
}
16 changes: 8 additions & 8 deletions src/parser/__tests__/disallowed-syntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ test('Cannot use function expressions', () => {
stripIndent`
(function fib(x) { return x <= 1 ? x : fib(x-1) + fib(x-2); })(4);
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`"Line 1: Function expressions are not allowed"`)
})

Expand All @@ -456,7 +456,7 @@ test('Cannot use function expressions - verbose', () => {
"enable verbose";
(function fib(x) { return x <= 1 ? x : fib(x-1) + fib(x-2); })(4);
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`
"Line 2, Column 1: Function expressions are not allowed
You are trying to use Function expressions, which is not allowed (yet).
Expand All @@ -469,7 +469,7 @@ test('Cannot use function expressions', () => {
stripIndent`
(function(x) { return x + 1; })(4);
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`"Line 1: Function expressions are not allowed"`)
})

Expand All @@ -479,7 +479,7 @@ test('Cannot use function expressions - verbose', () => {
"enable verbose";
(function(x) { return x + 1; })(4);
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`
"Line 2, Column 1: Function expressions are not allowed
You are trying to use Function expressions, which is not allowed (yet).
Expand Down Expand Up @@ -852,7 +852,7 @@ test('No classes', () => {
class Box {
}
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`
"Line 1: Class bodys are not allowed
Line 1: Class declarations are not allowed"
Expand All @@ -866,7 +866,7 @@ test('No classes - verbose', () => {
class Box {
}
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`
"Line 2, Column 10: Class bodys are not allowed
You are trying to use Class bodys, which is not allowed (yet).
Expand All @@ -886,7 +886,7 @@ test('No super', () => {
}
}
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`
"Line 3: Supers are not allowed
Line 2: Function expressions are not allowed
Expand All @@ -906,7 +906,7 @@ test('No super - verbose', () => {
}
}
`,
{ chapter: 5 }
{ chapter: 5 as Chapter }
).toMatchInlineSnapshot(`
"Line 4, Column 4: Supers are not allowed
You are trying to use Supers, which is not allowed (yet).
Expand Down
Loading
Loading