diff --git a/.editorconfig b/.editorconfig index 874bf8b81..270106b1f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,2 +1,2 @@ [*] -end_of_line = lf \ No newline at end of file +end_of_line = lf diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index df267f4cb..37dde25cb 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -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 && \ diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index efb95fc43..435ae544d 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index 2a13962dd..7948922db 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,4 @@ test-report.html !.yarn/releases !.yarn/sdks !.yarn/versions -yarn-error.log \ No newline at end of file +yarn-error.log diff --git a/.prettierignore b/.prettierignore index cb1a50835..283029514 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,3 @@ /src/alt-langs/ /src/py-slang/ -/src/**/__tests__/**/__snapshots__ \ No newline at end of file +/src/**/__tests__/**/__snapshots__ diff --git a/package.json b/package.json index 313c3c6de..1fa198a5a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/src/alt-langs/scheme/scm-slang b/src/alt-langs/scheme/scm-slang index fdad3f85a..3cd7cbc5a 160000 --- a/src/alt-langs/scheme/scm-slang +++ b/src/alt-langs/scheme/scm-slang @@ -1 +1 @@ -Subproject commit fdad3f85a6e9fe8145a88b741f00db0019c29702 +Subproject commit 3cd7cbc5aef2a0b20ee77e2d1a41d1408758775e diff --git a/src/createContext.ts b/src/createContext.ts index 84e74c51c..27a2df966 100644 --- a/src/createContext.ts +++ b/src/createContext.ts @@ -1,16 +1,12 @@ // 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' @@ -18,6 +14,13 @@ 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' @@ -33,9 +36,6 @@ import { } 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 @@ -262,7 +262,7 @@ export const importExternalSymbols = (context: Context, externalSymbols: string[ ensureGlobalEnvironmentExist(context) externalSymbols.forEach(symbol => { - defineSymbol(context, symbol, GLOBAL[symbol]) + defineSymbol(context, symbol, GLOBAL[symbol as keyof typeof GLOBAL]) }) } @@ -324,7 +324,7 @@ export const importBuiltins = (context: Context, externalBuiltIns: CustomBuiltIn // 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 diff --git a/src/editors/ace/modes/source.ts b/src/editors/ace/modes/source.ts index 08ca784e9..a0778f685 100644 --- a/src/editors/ace/modes/source.ts +++ b/src/editors/ace/modes/source.ts @@ -37,7 +37,7 @@ export function HighlightRulesSelector( } )[] = [] ) { - // @ts-ignore + // @ts-expect-error implicit any function _SourceHighlightRules(acequire, exports, _module) { 'use strict' @@ -49,7 +49,8 @@ export function HighlightRulesSelector( 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) { diff --git a/src/infiniteLoops/instrument.ts b/src/infiniteLoops/instrument.ts index acd6c7354..d5e47e194 100644 --- a/src/infiniteLoops/instrument.ts +++ b/src/infiniteLoops/instrument.ts @@ -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 = { @@ -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() @@ -607,7 +608,7 @@ function instrument( builtins: Iterable ): string { const { builtinsId, functionsId, stateId } = globalIds - const predefined = {} + const predefined: Record = {} predefined[builtinsId] = builtinsId predefined[functionsId] = functionsId predefined[stateId] = stateId @@ -640,7 +641,7 @@ function instrument( } export { - instrument, FunctionNames as InfiniteLoopRuntimeFunctions, - globalIds as InfiniteLoopRuntimeObjectNames + globalIds as InfiniteLoopRuntimeObjectNames, + instrument } diff --git a/src/infiniteLoops/runtime.ts b/src/infiniteLoops/runtime.ts index d125ebb12..77511649a 100644 --- a/src/infiniteLoops/runtime.ts +++ b/src/infiniteLoops/runtime.ts @@ -251,7 +251,7 @@ function prepareBuiltins(oldBuiltins: Map) { const nonDetFunctions = ['get_time', 'math_random'] const newBuiltins = new Map() 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 { diff --git a/src/infiniteLoops/state.ts b/src/infiniteLoops/state.ts index a48c49cf4..64620638f 100644 --- a/src/infiniteLoops/state.ts +++ b/src/infiniteLoops/state.ts @@ -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? + const transition: any = transitions[i] if (transition[0] === name) { transition[1] = concrete transition[2] = id @@ -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] } } diff --git a/src/parser/__tests__/disallowed-syntax.ts b/src/parser/__tests__/disallowed-syntax.ts index 2f2c457f0..f429c2a0d 100644 --- a/src/parser/__tests__/disallowed-syntax.ts +++ b/src/parser/__tests__/disallowed-syntax.ts @@ -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"`) }) @@ -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). @@ -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"`) }) @@ -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). @@ -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" @@ -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). @@ -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 @@ -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). diff --git a/src/parser/source/typed/typeParser.ts b/src/parser/source/typed/typeParser.ts index ca6f9c570..a31c48d08 100644 --- a/src/parser/source/typed/typeParser.ts +++ b/src/parser/source/typed/typeParser.ts @@ -395,7 +395,7 @@ const tsPlugin = (BaseParser: any) => { let node switch (this.type) { case tokTypes.name: - switch (tsTypeOperator[this.value]) { + switch (tsTypeOperator[this.value as keyof typeof tsTypeOperator]) { case tsTypeOperator.infer: node = this.parseTSInferType() break @@ -431,7 +431,7 @@ const tsPlugin = (BaseParser: any) => { } _parseTSDeclaration(node: any, expr: { name: string | number }) { - const val = tsDeclaration[expr.name] + const val = tsDeclaration[expr.name as keyof typeof tsDeclaration] switch (val) { case tsDeclaration.interface: if (this.type === tokTypes.name) { @@ -467,7 +467,7 @@ const tsPlugin = (BaseParser: any) => { const node = this.startNode() const keyword = this.value this.next() - this.finishNode(node, tsPredefinedType[keyword]) + this.finishNode(node, tsPredefinedType[keyword as keyof typeof tsPredefinedType]) return node } @@ -1028,10 +1028,16 @@ const tsPlugin = (BaseParser: any) => { } _parseMaybeTSExpression(node: any) { - if (this.type === tokTypes.prefix && tsExprMarkup[this.value] === tsExprMarkup['!']) { + if ( + this.type === tokTypes.prefix && + tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup['!'] + ) { node = this.parseTSNonNullExpression(node) } - if (this.type === tokTypes.name && tsExprMarkup[this.value] === tsExprMarkup.as) { + if ( + this.type === tokTypes.name && + tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup.as + ) { node = this.parseTSAsExpression(node) } return node @@ -1039,7 +1045,10 @@ const tsPlugin = (BaseParser: any) => { parseTSAsExpression(expression: any) { let node = expression - while (this.type === tokTypes.name && tsExprMarkup[this.value] === tsExprMarkup.as) { + while ( + this.type === tokTypes.name && + tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup.as + ) { const _node = this.startNodeAtNode(node) this.next() _node.expression = node @@ -1051,7 +1060,10 @@ const tsPlugin = (BaseParser: any) => { parseTSNonNullExpression(expression: any) { let node = expression - while (this.type === tokTypes.prefix && tsExprMarkup[this.value] === tsExprMarkup['!']) { + while ( + this.type === tokTypes.prefix && + tsExprMarkup[this.value as keyof typeof tsExprMarkup] === tsExprMarkup['!'] + ) { const _node = this.startNodeAtNode(node) _node.expression = node this.next() diff --git a/src/repl/utils.ts b/src/repl/utils.ts index fa376999c..6f7c7ec99 100644 --- a/src/repl/utils.ts +++ b/src/repl/utils.ts @@ -1,11 +1,10 @@ import { Option } from '@commander-js/extra-typings' - +import { parseError, type Context } from '..' import { pyLanguages, scmLanguages, sourceLanguages } from '../constants' -import { Chapter, type Language, Variant, type Result, type LanguageOptions } from '../types' -import { stringify } from '../utils/stringify' import Closure from '../cse-machine/closure' -import { parseError, type Context } from '..' +import { Chapter, Variant, type Language, type LanguageOptions, type Result } from '../types' import { objectKeys } from '../utils/misc' +import { stringify } from '../utils/stringify' export function chapterParser(str: string): Chapter { let foundChapter: string | undefined @@ -23,7 +22,7 @@ export function chapterParser(str: string): Chapter { } if (foundChapter in Chapter) { - return Chapter[foundChapter] + return Chapter[foundChapter as keyof typeof Chapter] } throw new Error(`Invalid chapter value: ${str}`) } diff --git a/src/stdlib/pylib.ts b/src/stdlib/pylib.ts index a06814955..dff35b2f7 100644 --- a/src/stdlib/pylib.ts +++ b/src/stdlib/pylib.ts @@ -28,7 +28,8 @@ export function __py_adder(x: Value, y: Value) { return x + Number(y) } if (__is_numeric(x) && __is_numeric(y)) { - return x + y + // TODO: Shouldn't this be `Number(x) + Number(y)`? + return (x as any) + (y as any) } throw new Error(`Invalid types for addition operation: ${typeof x}, ${typeof y}`) } diff --git a/src/transpiler/transpiler.ts b/src/transpiler/transpiler.ts index 9fc545d7b..83ea89e9f 100644 --- a/src/transpiler/transpiler.ts +++ b/src/transpiler/transpiler.ts @@ -7,6 +7,7 @@ import { NATIVE_STORAGE_ID, UNKNOWN_LOCATION } from '../constants' import { Chapter, type Context, type NativeStorage, type Node, Variant } from '../types' import * as create from '../utils/ast/astCreator' import { filterImportDeclarations, getImportedName } from '../utils/ast/helpers' +import { isNamespaceSpecifier } from '../utils/ast/typeGuards' import { getFunctionDeclarationNamesInProgram, getIdentifiersInNativeStorage, @@ -17,7 +18,6 @@ import { } from '../utils/uniqueIds' import { simple } from '../utils/walkers' import { checkForUndefinedVariables } from '../validator/validator' -import { isNamespaceSpecifier } from '../utils/ast/typeGuards' /** * This whole transpiler includes many many many many hacks to get stuff working. @@ -260,8 +260,8 @@ function transformSomeExpressionsToCheckIfBoolean(program: es.Program, globalIds const { line, column } = (node.loc ?? UNKNOWN_LOCATION).start const source = node.loc?.source ?? null const test = node.type === 'LogicalExpression' ? 'left' : 'test' - node[test] = create.callExpression(globalIds.boolOrErr, [ - node[test], + ;(node as any)[test] = create.callExpression(globalIds.boolOrErr, [ + (node as any)[test], create.literal(line), create.literal(column), create.literal(source) diff --git a/src/utils/ast/astToString.ts b/src/utils/ast/astToString.ts index 3da4495eb..a5c432910 100644 --- a/src/utils/ast/astToString.ts +++ b/src/utils/ast/astToString.ts @@ -57,7 +57,7 @@ export const sourceGen = Object.assign({}, astring.GENERATOR, { formatComments(state, statement.comments, indent, lineEnd) } state.write(indent) - this[statement.type](statement, state) + this[statement.type as keyof typeof this](statement, state) state.write(lineEnd) } state.write(indent) diff --git a/src/utils/operators.ts b/src/utils/operators.ts index 2fc9d773c..f8331a55a 100644 --- a/src/utils/operators.ts +++ b/src/utils/operators.ts @@ -12,8 +12,8 @@ import { PotentialInfiniteRecursionError } from '../errors/timeoutErrors' import { Chapter, type NativeStorage } from '../types' -import { callExpression, locationDummyNode } from './ast/astCreator' import * as create from './ast/astCreator' +import { callExpression, locationDummyNode } from './ast/astCreator' import { makeWrapper } from './makeWrapper' import * as rttc from './rttc' @@ -249,7 +249,7 @@ export const wrap = ( const wrapped = (...args: any[]) => callIteratively(f, nativeStorage, ...args) makeWrapper(f, wrapped) wrapped.transformedFunction = f - wrapped[Symbol.toStringTag] = () => stringified + ;(wrapped as any)[Symbol.toStringTag] = () => stringified wrapped.toString = () => stringified return wrapped } diff --git a/src/utils/stringify.ts b/src/utils/stringify.ts index f5007c4b8..cd1101fe1 100644 --- a/src/utils/stringify.ts +++ b/src/utils/stringify.ts @@ -49,9 +49,9 @@ function niceTypeToString(type: Type, nameMap = { _next: 0 }): string { } if (!(type.name in nameMap)) { // type name is not in map, so add it - nameMap[type.name] = 'T' + nameMap._next++ + ;(nameMap as any)[type.name] = 'T' + nameMap._next++ } - return nameMap[type.name] + return (nameMap as any)[type.name] case 'list': return `List<${curriedTypeToString(type.elementType)}>` case 'array': diff --git a/src/utils/testing/sanitizer.ts b/src/utils/testing/sanitizer.ts index f699da888..edf00dbeb 100644 --- a/src/utils/testing/sanitizer.ts +++ b/src/utils/testing/sanitizer.ts @@ -21,7 +21,7 @@ const sanitizers = Object.entries(propertiesToDelete).reduce( ...res, [nodeType](node: es.Node) { for (const prop of props) { - delete node[prop] + delete node[prop as keyof typeof node] } } }), diff --git a/src/utils/uniqueIds.ts b/src/utils/uniqueIds.ts index 348dfa149..4239d2a3b 100644 --- a/src/utils/uniqueIds.ts +++ b/src/utils/uniqueIds.ts @@ -20,7 +20,7 @@ const globalIdNames = [ export type NativeIds = Record<(typeof globalIdNames)[number], es.Identifier> export function getNativeIds(program: es.Program, usedIdentifiers: Set): NativeIds { - const globalIds = {} + const globalIds: Partial = {} for (const identifier of globalIdNames) { globalIds[identifier] = create.identifier(getUniqueId(usedIdentifiers, identifier)) } diff --git a/src/vm/svml-assembler.ts b/src/vm/svml-assembler.ts index 9728f9d80..124781081 100644 --- a/src/vm/svml-assembler.ts +++ b/src/vm/svml-assembler.ts @@ -93,7 +93,7 @@ function serialiseFunction(f: SVMFunction): ImFunction { case OpCodes.NEWC: holes.push({ offset: b.cursor, - referent: ['function', instr[1]![0]] + referent: ['function', (instr[1]! as any)[0]] }) b.putU(32, 0) break diff --git a/src/vm/svml-compiler.ts b/src/vm/svml-compiler.ts index 0710ab4eb..fa0f059e2 100644 --- a/src/vm/svml-compiler.ts +++ b/src/vm/svml-compiler.ts @@ -485,7 +485,17 @@ function compileStatements( } // each compiler should return a maxStackSize -const compilers = { +const compilers: Partial< + Record< + Node['type'], + ( + node: Node, + indexTable: Map[], + insertFlag: boolean, + isTailCallPosition?: boolean + ) => ReturnType + > +> = { // wrapper Program(node: Node, indexTable: Map[], insertFlag: boolean) { node = node as es.Program diff --git a/src/vm/util.ts b/src/vm/util.ts index 7cf9e8d23..bbd3f2f38 100644 --- a/src/vm/util.ts +++ b/src/vm/util.ts @@ -29,8 +29,6 @@ const OPCODES_STR = { [OpCodes.DIVF]: 'DIVF ', [OpCodes.MODG]: 'MODG ', [OpCodes.MODF]: 'MODF ', - [OpCodes.NEGG]: 'NEGG ', - [OpCodes.NEGF]: 'NEGF ', [OpCodes.NOTG]: 'NOTG ', [OpCodes.NOTB]: 'NOTB ', [OpCodes.LTG]: 'LTG ', @@ -44,9 +42,6 @@ const OPCODES_STR = { [OpCodes.EQG]: 'EQG ', [OpCodes.EQF]: 'EQF ', [OpCodes.EQB]: 'EQB ', - [OpCodes.NEQG]: 'NEQG ', - [OpCodes.NEQF]: 'NEQF ', - [OpCodes.NEQB]: 'NEQB ', [OpCodes.NEWC]: 'NEWC ', [OpCodes.NEWA]: 'NEWA ', [OpCodes.LDLG]: 'LDLG ', @@ -156,7 +151,7 @@ const OPCODES_STR = { // get name of opcode for debugging export function getName(op: number) { - return OPCODES_STR[op] // need to add guard in case op does not exist + return OPCODES_STR[op as keyof typeof OPCODES_STR] // need to add guard in case op does not exist } // pretty-print the program diff --git a/tsconfig.json b/tsconfig.json index 0635b6340..65519ddab 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,12 +3,7 @@ "module": "commonjs", "declaration": true, "target": "es2020", - "lib": [ - "es2021.string", - "es2018", - "es2017.object", - "dom" - ], + "lib": ["es2021.string", "es2018", "es2017.object", "dom"], "sourceMap": true, "allowJs": false, "removeComments": false, @@ -21,20 +16,17 @@ "noImplicitThis": true, "noImplicitAny": true, "strictNullChecks": true, - "suppressImplicitAnyIndexErrors": true, "resolveJsonModule": true, "noUnusedLocals": true, "incremental": true, + "skipLibCheck": true }, "exclude": [ "src/stdlib/metacircular-interpreter", "src/stdlib/**/*.js", "node_modules", "dist", - "sicp_publish", + "sicp_publish" ], - "types": [ - "typePatches", - "jest" - ] + "types": ["typePatches", "jest"] } diff --git a/tsconfig.prod.json b/tsconfig.prod.json index 08e1b0b8a..1e47d3813 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -2,7 +2,8 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./dist", - "noEmit": false + "noEmit": false, + "skipLibCheck": true }, // Excludes are overwritten when using extends, so we // list all the excludes again diff --git a/yarn.lock b/yarn.lock index aaf749566..ee45994f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1238,6 +1238,13 @@ __metadata: languageName: node linkType: hard +"@babel/runtime@npm:^7.26.10": + version: 7.28.2 + resolution: "@babel/runtime@npm:7.28.2" + checksum: 10c0/c20afe253629d53a405a610b12a62ac74d341a2c1e0fb202bbef0c118f6b5c84f94bf16039f58fd0483dd256901259930a43976845bdeb180cab1f882c21b6e0 + languageName: node + linkType: hard + "@babel/template@npm:^7.27.1, @babel/template@npm:^7.27.2, @babel/template@npm:^7.3.3": version: 7.27.2 resolution: "@babel/template@npm:7.27.2" @@ -1992,6 +1999,15 @@ __metadata: languageName: node linkType: hard +"@types/mathjs@npm:^9.4.2": + version: 9.4.2 + resolution: "@types/mathjs@npm:9.4.2" + dependencies: + mathjs: "npm:*" + checksum: 10c0/bcbc5069e8f3f2cf3b46c224d613d86ab86ff05967451bc2b4a9e8801ee79ecf3f37850b453f7615ec89f2f3bf986c4351e254fef033805078bc2a533e46942b + languageName: node + linkType: hard + "@types/mdurl@npm:*": version: 1.0.2 resolution: "@types/mdurl@npm:1.0.2" @@ -2945,6 +2961,13 @@ __metadata: languageName: node linkType: hard +"complex.js@npm:^2.2.5": + version: 2.4.2 + resolution: "complex.js@npm:2.4.2" + checksum: 10c0/c78cca0a3c08fa48845e2703b9772bdd80d44e56728382d43879183cb23391da6e8b6326ceec23c685abfd529b61d34842ba1784d7fa3783b194fbc6d0850d7c + languageName: node + linkType: hard + "concat-map@npm:0.0.1": version: 0.0.1 resolution: "concat-map@npm:0.0.1" @@ -3129,6 +3152,13 @@ __metadata: languageName: node linkType: hard +"decimal.js@npm:^10.4.3": + version: 10.6.0 + resolution: "decimal.js@npm:10.6.0" + checksum: 10c0/07d69fbcc54167a340d2d97de95f546f9ff1f69d2b45a02fd7a5292412df3cd9eb7e23065e532a318f5474a2e1bccf8392fdf0443ef467f97f3bf8cb0477e5aa + languageName: node + linkType: hard + "dedent@npm:^1.0.0": version: 1.5.1 resolution: "dedent@npm:1.5.1" @@ -3442,6 +3472,13 @@ __metadata: languageName: node linkType: hard +"escape-latex@npm:^1.2.0": + version: 1.2.0 + resolution: "escape-latex@npm:1.2.0" + checksum: 10c0/b77ea1594a38625295793a61105222c283c1792d1b2511bbfd6338cf02cc427dcabce7e7c1e22ec2f5c40baf3eaf2eeaf229a62dbbb74c6e69bb4a4209f2544f + languageName: node + linkType: hard + "escape-string-regexp@npm:^2.0.0": version: 2.0.0 resolution: "escape-string-regexp@npm:2.0.0" @@ -3873,6 +3910,13 @@ __metadata: languageName: node linkType: hard +"fraction.js@npm:^5.2.1": + version: 5.2.2 + resolution: "fraction.js@npm:5.2.2" + checksum: 10c0/708f92c929c1147b91dac6820627cd84a89fcbf7a37f4c2cee6c1b6729d735ecd2ffc9aea343e404ac1e611d24387491b516a0a63ba61c158f424bfa9154883e + languageName: node + linkType: hard + "fs-minipass@npm:^3.0.0": version: 3.0.3 resolution: "fs-minipass@npm:3.0.3" @@ -4758,6 +4802,13 @@ __metadata: languageName: node linkType: hard +"javascript-natural-sort@npm:^0.7.1": + version: 0.7.1 + resolution: "javascript-natural-sort@npm:0.7.1" + checksum: 10c0/340f8ffc5d30fb516e06dc540e8fa9e0b93c865cf49d791fed3eac3bdc5fc71f0066fc81d44ec1433edc87caecaf9f13eec4a1fce8c5beafc709a71eaedae6fe + languageName: node + linkType: hard + "jest-changed-files@npm:^29.7.0": version: 29.7.0 resolution: "jest-changed-files@npm:29.7.0" @@ -5256,6 +5307,7 @@ __metadata: "@types/estree": "npm:^1.0.5" "@types/jest": "npm:^29.0.0" "@types/lodash": "npm:^4.14.202" + "@types/mathjs": "npm:^9.4.2" "@types/node": "npm:^20.0.0" "@types/offscreencanvas": "npm:^2019.7.0" ace-builds: "npm:~1.17.0" @@ -5281,7 +5333,7 @@ __metadata: prettier: "npm:^3.6.2" source-map: "npm:0.7.6" ts-jest: "npm:^29.0.0" - typescript: "npm:^4.0.3" + typescript: "npm:^5.9.2" typescript-eslint: "npm:^8.8.1" bin: js-slang: dist/repl/index.js @@ -5758,6 +5810,25 @@ __metadata: languageName: node linkType: hard +"mathjs@npm:*": + version: 14.6.0 + resolution: "mathjs@npm:14.6.0" + dependencies: + "@babel/runtime": "npm:^7.26.10" + complex.js: "npm:^2.2.5" + decimal.js: "npm:^10.4.3" + escape-latex: "npm:^1.2.0" + fraction.js: "npm:^5.2.1" + javascript-natural-sort: "npm:^0.7.1" + seedrandom: "npm:^3.0.5" + tiny-emitter: "npm:^2.1.0" + typed-function: "npm:^4.2.1" + bin: + mathjs: bin/cli.js + checksum: 10c0/1f1cadf7ce0241d916b1d6e0a3712d494c090f39cadf312c033ed24b61502312062f3c234e8efcd941a54c644621b9a0893b495083b2f2679ac07115e9a01e3f + languageName: node + linkType: hard + "mdurl@npm:^1.0.1": version: 1.0.1 resolution: "mdurl@npm:1.0.1" @@ -6721,6 +6792,13 @@ __metadata: languageName: node linkType: hard +"seedrandom@npm:^3.0.5": + version: 3.0.5 + resolution: "seedrandom@npm:3.0.5" + checksum: 10c0/929752ac098ff4990b3f8e0ac39136534916e72879d6eb625230141d20db26e2f44c4d03d153d457682e8cbaab0fb7d58a1e7267a157cf23fd8cf34e25044e88 + languageName: node + linkType: hard + "semver@npm:^6.3.0, semver@npm:^6.3.1": version: 6.3.1 resolution: "semver@npm:6.3.1" @@ -7163,6 +7241,13 @@ __metadata: languageName: node linkType: hard +"tiny-emitter@npm:^2.1.0": + version: 2.1.0 + resolution: "tiny-emitter@npm:2.1.0" + checksum: 10c0/459c0bd6e636e80909898220eb390e1cba2b15c430b7b06cec6ac29d87acd29ef618b9b32532283af749f5d37af3534d0e3bde29fdf6bcefbf122784333c953d + languageName: node + linkType: hard + "tmpl@npm:1.0.5": version: 1.0.5 resolution: "tmpl@npm:1.0.5" @@ -7370,6 +7455,13 @@ __metadata: languageName: node linkType: hard +"typed-function@npm:^4.2.1": + version: 4.2.1 + resolution: "typed-function@npm:4.2.1" + checksum: 10c0/0b4e9a359e456f7df50f3d7cc53e2408d23a516f27b50c2c0654f388110ecf407c0595b1bf2296d3d8667fae6aae311ec2af90c602385777d12fe724bae99156 + languageName: node + linkType: hard + "typescript-eslint@npm:^8.8.1": version: 8.35.1 resolution: "typescript-eslint@npm:8.35.1" @@ -7384,23 +7476,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^4.0.3": - version: 4.9.5 - resolution: "typescript@npm:4.9.5" +"typescript@npm:^5.9.2": + version: 5.9.2 + resolution: "typescript@npm:5.9.2" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/5f6cad2e728a8a063521328e612d7876e12f0d8a8390d3b3aaa452a6a65e24e9ac8ea22beb72a924fd96ea0a49ea63bb4e251fb922b12eedfb7f7a26475e5c56 + checksum: 10c0/cd635d50f02d6cf98ed42de2f76289701c1ec587a363369255f01ed15aaf22be0813226bff3c53e99d971f9b540e0b3cc7583dbe05faded49b1b0bed2f638a18 languageName: node linkType: hard -"typescript@patch:typescript@npm%3A^4.0.3#optional!builtin": - version: 4.9.5 - resolution: "typescript@patch:typescript@npm%3A4.9.5#optional!builtin::version=4.9.5&hash=289587" +"typescript@patch:typescript@npm%3A^5.9.2#optional!builtin": + version: 5.9.2 + resolution: "typescript@patch:typescript@npm%3A5.9.2#optional!builtin::version=5.9.2&hash=5786d5" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/e3333f887c6829dfe0ab6c1dbe0dd1e3e2aeb56c66460cb85c5440c566f900c833d370ca34eb47558c0c69e78ced4bfe09b8f4f98b6de7afed9b84b8d1dd06a1 + checksum: 10c0/34d2a8e23eb8e0d1875072064d5e1d9c102e0bdce56a10a25c0b917b8aa9001a9cf5c225df12497e99da107dc379360bc138163c66b55b95f5b105b50578067e languageName: node linkType: hard