diff --git a/src/__tests__/block-scoping.test.ts b/src/__tests__/block-scoping.test.ts index aeaba2b62..1a6928da5 100644 --- a/src/__tests__/block-scoping.test.ts +++ b/src/__tests__/block-scoping.test.ts @@ -1,7 +1,7 @@ import { test } from 'vitest' import { Chapter } from '../langs' import { stripIndent } from '../utils/formatters' -import { expectParsedError, expectFinishedResult } from '../utils/testing' +import { expectFinishedResult, expectParsedError } from '../utils/testing' // This is bad practice. Don't do this! test('standalone block statements', () => { @@ -145,7 +145,6 @@ test('Error when accessing temporal dead zone', () => { `).toEqual("Line 3: ReferenceError: Cannot access 'a' before initialization") }, 30000) -// tslint:disable-next-line:max-line-length test('In a block, every going-to-be-defined variable in the block cannot be accessed until it has been defined in the block.', () => { return expectParsedError(stripIndent` const a = 1; diff --git a/src/__tests__/draw_data.test.ts b/src/__tests__/draw_data.test.ts index 2f8297edd..16829f096 100644 --- a/src/__tests__/draw_data.test.ts +++ b/src/__tests__/draw_data.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' import { Chapter } from '../langs' -import { expectParsedError, expectFinishedResult } from '../utils/testing' +import { expectFinishedResult, expectParsedError } from '../utils/testing' test('draw_data returns first argument if more than one argument', () => { return expectFinishedResult(`draw_data(1, 2);`, Chapter.SOURCE_3).toEqual(1) diff --git a/src/__tests__/environmentTree.test.ts b/src/__tests__/environmentTree.test.ts index beffbc62d..a06a7818e 100644 --- a/src/__tests__/environmentTree.test.ts +++ b/src/__tests__/environmentTree.test.ts @@ -1,8 +1,8 @@ import { expect, test } from 'vitest' import { createGlobalEnvironment, EnvTree, EnvTreeNode } from '../createContext' import { pushEnvironment } from '../cse-machine/utils' -import { mockContext, mockEnvironment } from '../utils/testing/mocks' import { Chapter } from '../langs' +import { mockContext, mockEnvironment } from '../utils/testing/mocks' test('EnvTree root should be null upon instantiation', () => { const envTree = new EnvTree() diff --git a/src/__tests__/index.test.ts b/src/__tests__/index.test.ts index 59e78978c..72a7a7585 100644 --- a/src/__tests__/index.test.ts +++ b/src/__tests__/index.test.ts @@ -1,23 +1,23 @@ -import { describe, expect, test } from 'vitest' import type { Position } from 'acorn/dist/acorn' import type { SourceLocation } from 'estree' +import { describe, expect, test } from 'vitest' import { findDeclaration, getScope, runInContext } from '../index' -import { Value } from '../types' import { Chapter } from '../langs' +import { Value } from '../types' import { stripIndent } from '../utils/formatters' import { createTestContext, - expectParsedError, expectFinishedResult, + expectParsedError, testSuccess } from '../utils/testing' -import type { TestOptions } from '../utils/testing/types' import { - evalWithBuiltins, assertFinishedResultValue, + evalWithBuiltins, processTestOptions } from '../utils/testing/misc' +import type { TestOptions } from '../utils/testing/types' const toString = (x: Value) => '' + x diff --git a/src/__tests__/mode.test.ts b/src/__tests__/mode.test.ts index 1e25805b9..3fd4a5549 100644 --- a/src/__tests__/mode.test.ts +++ b/src/__tests__/mode.test.ts @@ -1,6 +1,6 @@ -import { expect, test, vi } from 'vitest' import * as ace from 'ace-builds' import { Mode as DefaultMode } from 'ace-builds/src-noconflict/mode-javascript' +import { expect, test, vi } from 'vitest' import { HighlightRulesSelector, ModeSelector } from '../editors/ace/modes/source' import { Chapter, Variant } from '../langs' diff --git a/src/__tests__/return-regressions.test.ts b/src/__tests__/return-regressions.test.ts index 40e62b7ee..1d44aff50 100644 --- a/src/__tests__/return-regressions.test.ts +++ b/src/__tests__/return-regressions.test.ts @@ -5,7 +5,7 @@ import { test } from 'vitest' import { Chapter } from '../langs' -import { expectParsedError, expectFinishedResult } from '../utils/testing' +import { expectFinishedResult, expectParsedError } from '../utils/testing' // This is bad practice. Don't do this! test('Calling unreachable results in error', () => { diff --git a/src/__tests__/scope-refactoring.test.ts b/src/__tests__/scope-refactoring.test.ts index 3f474226d..7eda5b057 100644 --- a/src/__tests__/scope-refactoring.test.ts +++ b/src/__tests__/scope-refactoring.test.ts @@ -2,6 +2,7 @@ import { expect, test } from 'vitest' import { default as createContext } from '../createContext' import { getAllOccurrencesInScope } from '../index' +import { Chapter } from '../langs' import { looseParse } from '../parser/utils' import { getAllIdentifiers, @@ -12,7 +13,6 @@ import { scopeVariables } from '../scope-refactoring' import type { BlockFrame } from '../types' -import { Chapter } from '../langs' class Target { public name: string diff --git a/src/__tests__/sicp/.gitignore b/src/__tests__/sicp/.gitignore index 8fa9d6f15..d4aa116a2 100644 --- a/src/__tests__/sicp/.gitignore +++ b/src/__tests__/sicp/.gitignore @@ -1 +1 @@ -!*.js \ No newline at end of file +!*.js diff --git a/src/__tests__/stdlib.test.ts b/src/__tests__/stdlib.test.ts index 60798a75d..6b1aa3ba1 100644 --- a/src/__tests__/stdlib.test.ts +++ b/src/__tests__/stdlib.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' -import { Value } from '../types' import { Chapter } from '../langs' +import { Value } from '../types' import { stripIndent } from '../utils/formatters' import { expectFinishedResult, snapshotFailure } from '../utils/testing' diff --git a/src/__tests__/stringify.benchmark.ts b/src/__tests__/stringify.benchmark.ts index 0243601c1..0eb0c4e9f 100644 --- a/src/__tests__/stringify.benchmark.ts +++ b/src/__tests__/stringify.benchmark.ts @@ -1,7 +1,7 @@ // TODO: Convert to actual benchmark import { test } from 'vitest' -import * as list from '../stdlib/list' import { Chapter } from '../langs' +import * as list from '../stdlib/list' import { stripIndent } from '../utils/formatters' import { stringify } from '../utils/stringify' import { expectFinishedResult } from '../utils/testing' diff --git a/src/__tests__/stringify.test.ts b/src/__tests__/stringify.test.ts index 7e318d6af..f25ede8b0 100644 --- a/src/__tests__/stringify.test.ts +++ b/src/__tests__/stringify.test.ts @@ -97,7 +97,6 @@ test('Correctly handles circular structures with multiple entry points', async ( }) // The interpreter runs into a MaximumStackLimitExceeded error on 1000, so reduced it to 100. -// tslint:disable:max-line-length test('String representation of huge lists are nice', async () => { const { result: { value } @@ -194,7 +193,6 @@ test('String representation of huge lists are nice', async () => { [89, [90, [91, [92, [93, [94, [95, [96, [97, [98, [99, [100, null]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" `) }) -// tslint:enable:max-line-length test('String representation of huge arrays are nice', async () => { const { @@ -432,7 +430,6 @@ test('String representation of undefined is nice', () => { return expectFinishedResult(`stringify(undefined);`).toEqual('undefined') }) -// tslint:disable:max-line-length test('String representation with no indent', async () => { const { result: { value } diff --git a/src/__tests__/tailcall-return.test.ts b/src/__tests__/tailcall-return.test.ts index e8aa5f296..f0d11aaf8 100644 --- a/src/__tests__/tailcall-return.test.ts +++ b/src/__tests__/tailcall-return.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' import { stripIndent } from '../utils/formatters' -import { expectParsedError, expectFinishedResult } from '../utils/testing' +import { expectFinishedResult, expectParsedError } from '../utils/testing' test('Check that stack is at most 10k in size', { timeout: 10000 }, () => { return expectParsedError(stripIndent` diff --git a/src/alt-langs/__tests__/mapper.test.ts b/src/alt-langs/__tests__/mapper.test.ts index f8277d21a..12555e7c7 100644 --- a/src/alt-langs/__tests__/mapper.test.ts +++ b/src/alt-langs/__tests__/mapper.test.ts @@ -1,7 +1,7 @@ -import { expect, test } from 'vitest' -import { mockContext } from "../../utils/testing/mocks"; -import { type Finished } from "../../types"; +import { expect, test } from 'vitest'; import { Chapter } from "../../langs"; +import { type Finished } from "../../types"; +import { mockContext } from "../../utils/testing/mocks"; import { mapResult } from "../mapper"; test("given source, mapper should do nothing (no mapping needed)", () => { @@ -31,4 +31,4 @@ test("given scheme, mapper should map result to scheme representation", () => { representation: "#(1 2 3 4 5)", }, }); -}) \ No newline at end of file +}) diff --git a/src/alt-langs/mapper.ts b/src/alt-langs/mapper.ts index d04f92ea4..8a6186d47 100644 --- a/src/alt-langs/mapper.ts +++ b/src/alt-langs/mapper.ts @@ -47,4 +47,4 @@ export const isSchemeLanguage = (context: Context) => context.chapter === Chapter.SCHEME_2 || context.chapter === Chapter.SCHEME_3 || context.chapter === Chapter.SCHEME_4 || - context.chapter === Chapter.FULL_SCHEME \ No newline at end of file + context.chapter === Chapter.FULL_SCHEME diff --git a/src/alt-langs/scheme/__tests__/scheme-encode-decode.test.ts b/src/alt-langs/scheme/__tests__/scheme-encode-decode.test.ts index 245f77d6b..493c0f891 100644 --- a/src/alt-langs/scheme/__tests__/scheme-encode-decode.test.ts +++ b/src/alt-langs/scheme/__tests__/scheme-encode-decode.test.ts @@ -1,11 +1,11 @@ -import { describe, expect, it, test } from 'vitest' import type { Node } from 'estree' +import { describe, expect, it, test } from 'vitest' import { UnassignedVariable } from '../../../errors/errors' +import { dummyExpression } from '../../../utils/ast/dummyAstCreator' +import { decodeValue, mapErrorToScheme } from '../scheme-mapper' import { decode, encode } from '../scm-slang/src' import { cons, set$45$cdr$33$ } from '../scm-slang/src/stdlib/base' -import { dummyExpression } from '../../../utils/ast/dummyAstCreator' -import { mapErrorToScheme, decodeValue } from '../scheme-mapper' describe('Scheme encoder and decoder', () => { describe('encoder and decoder are proper inverses of one another', () => { diff --git a/src/alt-langs/scheme/__tests__/scheme-mapper.test.ts b/src/alt-langs/scheme/__tests__/scheme-mapper.test.ts index aebda2c27..ec5f5f976 100644 --- a/src/alt-langs/scheme/__tests__/scheme-mapper.test.ts +++ b/src/alt-langs/scheme/__tests__/scheme-mapper.test.ts @@ -1,7 +1,7 @@ import { expect, test } from 'vitest' import { schemeVisualise } from "../scheme-mapper" -import { make_number } from "../scm-slang/src/stdlib/core-math" import { circular$45$list, cons, cons$42$, list } from "../scm-slang/src/stdlib/base" +import { make_number } from "../scm-slang/src/stdlib/core-math" test("schemeVisualise: should visualise null properly", () => { expect(schemeVisualise(null).toString()).toEqual("()") diff --git a/src/alt-langs/scheme/scheme-mapper.ts b/src/alt-langs/scheme/scheme-mapper.ts index 510dbcbc1..4a5569f9d 100644 --- a/src/alt-langs/scheme/scheme-mapper.ts +++ b/src/alt-langs/scheme/scheme-mapper.ts @@ -1,11 +1,11 @@ import { ArrowFunctionExpression, Identifier, RestElement } from "estree" import Closure from "../../cse-machine/closure" -import { decode, estreeDecode } from "./scm-slang/src" -import { boolean$63$, car, cdr, circular$45$list$63$, cons, dotted$45$list$63$, last$45$pair, list$45$tail, null$63$, number$63$, pair$63$, proper$45$list$63$, set$45$cdr$33$, vector$63$ } from "./scm-slang/src/stdlib/source-scheme-library" import { ErrorType, type SourceError } from "../../errors/base" import { List, Pair } from "../../stdlib/list" -import { Representation } from "../mapper" import type { Result } from "../../types" +import { Representation } from "../mapper" +import { decode, estreeDecode } from "./scm-slang/src" +import { boolean$63$, car, cdr, circular$45$list$63$, cons, dotted$45$list$63$, last$45$pair, list$45$tail, null$63$, number$63$, pair$63$, proper$45$list$63$, set$45$cdr$33$, vector$63$ } from "./scm-slang/src/stdlib/source-scheme-library" export function mapResultToScheme(res: Result): Result { if (res.status === "finished") { diff --git a/src/createContext.ts b/src/createContext.ts index 15e0cce98..e903a4ff8 100644 --- a/src/createContext.ts +++ b/src/createContext.ts @@ -7,6 +7,7 @@ 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 { Chapter, Variant, type LanguageOptions } from './langs' import * as list from './stdlib/list' import { list_to_vector } from './stdlib/list' import { listPrelude } from './stdlib/list.prelude' @@ -25,7 +26,6 @@ import * as stream from './stdlib/stream' import { streamPrelude } from './stdlib/stream.prelude' import { createTypeEnvironment, tForAll, tVar } from './typeChecker/utils' import type { Context, CustomBuiltIns, Environment, NativeStorage, Value } from './types' -import { Chapter, Variant, type LanguageOptions } from './langs' import * as operators from './utils/operators' import { stringify } from './utils/stringify' @@ -366,7 +366,6 @@ export const importBuiltins = (context: Context, externalBuiltIns: CustomBuiltIn defineBuiltin( context, 'apply_in_underlying_javascript(fun, args)', - // tslint:disable-next-line:ban-types (fun: Function, args: Value) => fun.apply(fun, list_to_vector(args)) ) @@ -389,7 +388,6 @@ export const importBuiltins = (context: Context, externalBuiltIns: CustomBuiltIn defineBuiltin(context, 'is_NaN(val)', misc.is_NaN) defineBuiltin(context, 'has_own_property(obj, prop)', misc.has_own_property) defineBuiltin(context, 'alert(val)', alert) - // tslint:disable-next-line:ban-types defineBuiltin(context, 'timed(fun)', (f: Function) => misc.timed(context, f, context.externalContext, externalBuiltIns.rawDisplay) ) diff --git a/src/cse-machine/__tests__/cse-machine-callcc-js.test.ts b/src/cse-machine/__tests__/cse-machine-callcc-js.test.ts index ba3b2fe9d..156b1de77 100644 --- a/src/cse-machine/__tests__/cse-machine-callcc-js.test.ts +++ b/src/cse-machine/__tests__/cse-machine-callcc-js.test.ts @@ -1,7 +1,7 @@ import { test } from 'vitest' import { Chapter, Variant } from '../../langs' -import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing' import { stripIndent } from '../../utils/formatters' +import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing' // Continuation tests for Source const optionEC4 = { chapter: Chapter.SOURCE_4, variant: Variant.EXPLICIT_CONTROL } diff --git a/src/cse-machine/__tests__/cse-machine-callcc.test.ts b/src/cse-machine/__tests__/cse-machine-callcc.test.ts index 88687556e..09da7ce0c 100644 --- a/src/cse-machine/__tests__/cse-machine-callcc.test.ts +++ b/src/cse-machine/__tests__/cse-machine-callcc.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' import { Chapter, Variant } from '../../langs' -import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing' +import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing' // Continuation tests for Scheme const optionECScm = { chapter: Chapter.SCHEME_4, variant: Variant.EXPLICIT_CONTROL } diff --git a/src/cse-machine/__tests__/cse-machine-heap.test.ts b/src/cse-machine/__tests__/cse-machine-heap.test.ts index 29d300a1b..ad35dae94 100644 --- a/src/cse-machine/__tests__/cse-machine-heap.test.ts +++ b/src/cse-machine/__tests__/cse-machine-heap.test.ts @@ -1,8 +1,8 @@ import { expect, test } from 'vitest' -import { mockClosure, mockContext } from '../../utils/testing/mocks' -import { runCodeInSource } from '../../runner' import { Chapter } from '../../langs' +import { runCodeInSource } from '../../runner' import { stripIndent } from '../../utils/formatters' +import { mockClosure, mockContext } from '../../utils/testing/mocks' import Heap from '../heap' import type { EnvArray } from '../types' diff --git a/src/cse-machine/__tests__/cse-machine-return-regressions.test.ts b/src/cse-machine/__tests__/cse-machine-return-regressions.test.ts index d2cfdcbac..932d79f89 100644 --- a/src/cse-machine/__tests__/cse-machine-return-regressions.test.ts +++ b/src/cse-machine/__tests__/cse-machine-return-regressions.test.ts @@ -5,7 +5,7 @@ import { test } from 'vitest' import { Chapter, Variant } from '../../langs' -import { expectParsedError, expectFinishedResult } from '../../utils/testing' +import { expectFinishedResult, expectParsedError } from '../../utils/testing' const optionEC = { variant: Variant.EXPLICIT_CONTROL } const optionEC3 = { chapter: Chapter.SOURCE_3, variant: Variant.EXPLICIT_CONTROL } diff --git a/src/cse-machine/__tests__/cse-machine-runtime-context.test.ts b/src/cse-machine/__tests__/cse-machine-runtime-context.test.ts index 5d25d8ce2..4f37a90da 100644 --- a/src/cse-machine/__tests__/cse-machine-runtime-context.test.ts +++ b/src/cse-machine/__tests__/cse-machine-runtime-context.test.ts @@ -1,13 +1,13 @@ import type es from 'estree' import { expect, test } from 'vitest' import type { IOptions } from '../..' -import { mockContext } from '../../utils/testing/mocks' +import { Chapter } from '../../langs' import { parse } from '../../parser/parser' import { runCodeInSource } from '../../runner' import type { RecursivePartial } from '../../types' -import { Chapter } from '../../langs' import { stripIndent } from '../../utils/formatters' -import { Control, Transformers, Stash, generateCSEMachineStateStream } from '../interpreter' +import { mockContext } from '../../utils/testing/mocks' +import { Control, Stash, Transformers, generateCSEMachineStateStream } from '../interpreter' const getContextFrom = async (code: string, steps?: number) => { const context = mockContext(Chapter.SOURCE_4) diff --git a/src/cse-machine/__tests__/cse-machine-stdlib.test.ts b/src/cse-machine/__tests__/cse-machine-stdlib.test.ts index 562653817..c07484d47 100644 --- a/src/cse-machine/__tests__/cse-machine-stdlib.test.ts +++ b/src/cse-machine/__tests__/cse-machine-stdlib.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' -import type { Value } from '../../types' import { Chapter, Variant } from '../../langs' +import type { Value } from '../../types' import { stripIndent } from '../../utils/formatters' import { expectFinishedResult, snapshotFailure } from '../../utils/testing' diff --git a/src/cse-machine/__tests__/cset-machine-apply.test.ts b/src/cse-machine/__tests__/cset-machine-apply.test.ts index 6d9b3985f..4247d7129 100644 --- a/src/cse-machine/__tests__/cset-machine-apply.test.ts +++ b/src/cse-machine/__tests__/cset-machine-apply.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' import { Chapter, Variant } from '../../langs' -import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing' +import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing' // apply tests for Scheme const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL } diff --git a/src/cse-machine/__tests__/cset-machine-eval.test.ts b/src/cse-machine/__tests__/cset-machine-eval.test.ts index 3d81ed180..e34919b78 100644 --- a/src/cse-machine/__tests__/cset-machine-eval.test.ts +++ b/src/cse-machine/__tests__/cset-machine-eval.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' import { Chapter, Variant } from '../../langs' -import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing' +import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing' // CSET tests for Scheme const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL } diff --git a/src/cse-machine/__tests__/cset-machine-macros.test.ts b/src/cse-machine/__tests__/cset-machine-macros.test.ts index 21e1cbfc7..4c860ec34 100644 --- a/src/cse-machine/__tests__/cset-machine-macros.test.ts +++ b/src/cse-machine/__tests__/cset-machine-macros.test.ts @@ -1,6 +1,6 @@ import { test } from 'vitest' import { Chapter, Variant } from '../../langs' -import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing' +import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing' // CSET tests for Scheme Macros const optionECScm = { chapter: Chapter.FULL_SCHEME, variant: Variant.EXPLICIT_CONTROL } diff --git a/src/cse-machine/__tests__/patterns.test.ts b/src/cse-machine/__tests__/patterns.test.ts index b3be961d7..c96fc64da 100644 --- a/src/cse-machine/__tests__/patterns.test.ts +++ b/src/cse-machine/__tests__/patterns.test.ts @@ -1,6 +1,6 @@ import { expect, test } from 'vitest' -import { match } from '../patterns' import { _Symbol } from '../../alt-langs/scheme/scm-slang/src/stdlib/base' +import { match } from '../patterns' function makeList(...args: any[]) { return args.reduceRight((acc, x) => { diff --git a/src/cse-machine/closure.ts b/src/cse-machine/closure.ts index 749b8b26d..a52781b3c 100644 --- a/src/cse-machine/closure.ts +++ b/src/cse-machine/closure.ts @@ -11,8 +11,8 @@ import { } from '../cse-machine/utils' import type { Context, Environment, StatementSequence, Value } from '../types' import * as ast from '../utils/ast/astCreator' -import { Control, Transformers, Stash, generateCSEMachineStateStream } from './interpreter' import { envInstr } from './instrCreator' +import { Control, Stash, Transformers, generateCSEMachineStateStream } from './interpreter' const closureToJS = (value: Closure, context: Context) => { function DummyClass(this: Closure) { diff --git a/src/cse-machine/instrCreator.ts b/src/cse-machine/instrCreator.ts index 280669269..720eba078 100644 --- a/src/cse-machine/instrCreator.ts +++ b/src/cse-machine/instrCreator.ts @@ -5,22 +5,22 @@ import type es from 'estree' import type { Environment, Node } from '../types' +import { Transformers } from './interpreter' import { type AppInstr, type ArrLitInstr, type AssmtInstr, type BinOpInstr, type BranchInstr, + type DeclAssmtInstr, type EnvInstr, type ForInstr, type Instr, InstrType, + type RegularAssmtInstr, type UnOpInstr, - type WhileInstr, - type DeclAssmtInstr, - type RegularAssmtInstr + type WhileInstr } from './types' -import { Transformers } from './interpreter' export const resetInstr = (srcNode: Node): Instr => ({ instrType: InstrType.RESET, diff --git a/src/cse-machine/interpreter.ts b/src/cse-machine/interpreter.ts index 5408e6eb7..938ba921d 100644 --- a/src/cse-machine/interpreter.ts +++ b/src/cse-machine/interpreter.ts @@ -5,11 +5,11 @@ * and the legacy interpreter */ -/* tslint:disable:max-classes-per-file */ import type es from 'estree' import { isArray } from 'lodash' import type { IOptions } from '..' +import { isSchemeLanguage } from '../alt-langs/mapper' import { UNKNOWN_LOCATION } from '../constants' import * as errors from '../errors/errors' import { RuntimeSourceError } from '../errors/runtimeSourceError' @@ -17,11 +17,11 @@ import { checkEditorBreakpoints } from '../stdlib/inspector' import type { Context, ContiguousArrayElements, + Node, + NodeTypeToNode, Result, - Value, StatementSequence, - Node, - NodeTypeToNode + Value } from '../types' import * as ast from '../utils/ast/astCreator' import { @@ -34,7 +34,6 @@ import { evaluateBinaryExpression, evaluateUnaryExpression } from '../utils/oper import * as rttc from '../utils/rttc' import * as seq from '../utils/statementSeqTransform' import { checkProgramForUndefinedVariables } from '../validator/validator' -import { isSchemeLanguage } from '../alt-langs/mapper' import Closure from './closure' import { Continuation, @@ -42,6 +41,9 @@ import { makeDummyContCallExpression } from './continuations' import * as instr from './instrCreator' +import { flattenList, isList } from './macro-utils' +import { Transformer } from './patterns' +import { isApply, isEval, schemeEval } from './scheme-macros' import { Stack } from './stack' import { type AppInstr, @@ -83,9 +85,6 @@ import { setVariable, valueProducing } from './utils' -import { isApply, isEval, schemeEval } from './scheme-macros' -import { Transformer } from './patterns' -import { flattenList, isList } from './macro-utils' /** * The control is a list of commands that still needs to be executed by the machine. diff --git a/src/cse-machine/patterns.ts b/src/cse-machine/patterns.ts index 9c432fbde..357370b5a 100644 --- a/src/cse-machine/patterns.ts +++ b/src/cse-machine/patterns.ts @@ -3,17 +3,17 @@ // it consists of a set of literals used as additional syntax, // a pattern (for a list to match against) // and a final template (for the list to be transformed into). -import type { List, Pair } from '../stdlib/list' import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base' import { atomic_equals, is_number } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math' +import type { List, Pair } from '../stdlib/list' import { arrayToImproperList, arrayToList, flattenList, improperListLength, isImproperList, - isPair, - isList + isList, + isPair } from './macro-utils' // a single pattern stored within the patterns component diff --git a/src/cse-machine/scheme-macros.ts b/src/cse-machine/scheme-macros.ts index b3b539fa4..8adf42e6a 100644 --- a/src/cse-machine/scheme-macros.ts +++ b/src/cse-machine/scheme-macros.ts @@ -1,23 +1,23 @@ import type es from 'estree' -import * as errors from '../errors/errors' -import type { List } from '../stdlib/list' +import { encode } from '../alt-langs/scheme/scm-slang/src' import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base' import { is_number, SchemeNumber } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math' +import * as errors from '../errors/errors' +import type { List } from '../stdlib/list' import type { Context } from '../types' -import { encode } from '../alt-langs/scheme/scm-slang/src' +import { popInstr } from './instrCreator' import type { Control, Stash } from './interpreter' -import { currentTransformers, getVariable, handleRuntimeError } from './utils' -import { Transformer, macro_transform, match } from './patterns' import { arrayToImproperList, arrayToList, flattenImproperList, - isImproperList, flattenList, + isImproperList, isList } from './macro-utils' +import { macro_transform, match, Transformer } from './patterns' import type { ControlItem } from './types' -import { popInstr } from './instrCreator' +import { currentTransformers, getVariable, handleRuntimeError } from './utils' // this needs to be better but for now it's fine export type SchemeControlItems = List | _Symbol | SchemeNumber | boolean | string diff --git a/src/cse-machine/types.ts b/src/cse-machine/types.ts index c035b4259..ad4c048f6 100644 --- a/src/cse-machine/types.ts +++ b/src/cse-machine/types.ts @@ -2,8 +2,8 @@ import type es from 'estree' import type { Environment, Node } from '../types' import type Closure from './closure' -import type { SchemeControlItems } from './scheme-macros' import type { Transformers } from './interpreter' +import type { SchemeControlItems } from './scheme-macros' export enum InstrType { RESET = 'Reset', diff --git a/src/cse-machine/utils.ts b/src/cse-machine/utils.ts index a978df8a0..dffd4b273 100644 --- a/src/cse-machine/utils.ts +++ b/src/cse-machine/utils.ts @@ -1,28 +1,28 @@ import type es from 'estree' import { isFunction } from 'lodash' +import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base' +import { is_number } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math' import * as errors from '../errors/errors' import { RuntimeSourceError } from '../errors/runtimeSourceError' -import type { Context, Environment, Node, NodeTypeToNode, StatementSequence, Value } from '../types' import { Chapter } from '../langs' +import type { Context, Environment, Node, NodeTypeToNode, StatementSequence, Value } from '../types' import * as ast from '../utils/ast/astCreator' -import { _Symbol } from '../alt-langs/scheme/scm-slang/src/stdlib/base' -import { is_number } from '../alt-langs/scheme/scm-slang/src/stdlib/core-math' import { isIdentifier, isImportDeclaration } from '../utils/ast/typeGuards' +import Closure from './closure' +import { Continuation, isCallWithCurrentContinuation } from './continuations' import Heap from './heap' import * as instr from './instrCreator' import { type Control, Transformers } from './interpreter' +import { isApply, isEval } from './scheme-macros' import { type AppInstr, - type EnvArray, type ControlItem, + type EnvArray, type Instr, InstrType, type InstrTypeToInstr } from './types' -import Closure from './closure' -import { Continuation, isCallWithCurrentContinuation } from './continuations' -import { isApply, isEval } from './scheme-macros' /** * Typeguard for commands to check if they are scheme values. diff --git a/src/editors/ace/docTooltip/index.ts b/src/editors/ace/docTooltip/index.ts index a22685f62..0e502cff0 100644 --- a/src/editors/ace/docTooltip/index.ts +++ b/src/editors/ace/docTooltip/index.ts @@ -6,8 +6,8 @@ import * as source_2_typed from './source_2_typed.json' import * as source_3 from './source_3.json' import * as source_3_typed from './source_3_typed.json' import * as source_4 from './source_4.json' -import * as source_4_typed from './source_4_typed.json' import * as source_4_explicit_control from './source_4_explicit-control.json' +import * as source_4_typed from './source_4_typed.json' // (18 March 2022) // Problem to be fixed in the future: diff --git a/src/editors/ace/modes/source.ts b/src/editors/ace/modes/source.ts index 38a872dbe..4f8c9ebcd 100644 --- a/src/editors/ace/modes/source.ts +++ b/src/editors/ace/modes/source.ts @@ -1,8 +1,6 @@ import { Variant } from '../../../langs' import { SourceDocumentation } from '../docTooltip' -/* tslint:disable */ - /** * Source Mode for Ace Editor * (Modified from javascript mode in default brace package) @@ -10,7 +8,7 @@ import { SourceDocumentation } from '../docTooltip' * https://github.com/ajaxorg/ace-builds/blob/master/src/mode-javascript.js * * Changes includes: - * 1) change code styles so that it passes tslint test + * 1) change code styles * 2) refactor some code to ES2015 class syntax * 3) Encapsulate the orginal mode and higlightrules in two selectors so as to change according to source chapter * 4) changed regex to mark certain operators in pink diff --git a/src/errors/errors.ts b/src/errors/errors.ts index b193ae86a..41637ae33 100644 --- a/src/errors/errors.ts +++ b/src/errors/errors.ts @@ -1,12 +1,10 @@ -/* tslint:disable: max-classes-per-file */ -/* tslint:disable:max-line-length */ import { baseGenerator, generate } from 'astring' import type es from 'estree' import { UNKNOWN_LOCATION } from '../constants' import type { Node, Value } from '../types' import { stringify } from '../utils/stringify' -import { ErrorType, ErrorSeverity, type SourceError } from './base' +import { ErrorSeverity, ErrorType, type SourceError } from './base' import { RuntimeSourceError } from './runtimeSourceError' //Wrap build-in function error in SourceError diff --git a/src/errors/runtimeSourceError.ts b/src/errors/runtimeSourceError.ts index 9536f533c..d9c9b3917 100644 --- a/src/errors/runtimeSourceError.ts +++ b/src/errors/runtimeSourceError.ts @@ -2,7 +2,7 @@ import type es from 'estree' import type { Node } from '../types' import { UNKNOWN_LOCATION } from '../constants' -import { ErrorType, ErrorSeverity, type SourceError } from './base' +import { ErrorSeverity, ErrorType, type SourceError } from './base' export class RuntimeSourceError implements SourceError { public type = ErrorType.RUNTIME diff --git a/src/errors/timeoutErrors.ts b/src/errors/timeoutErrors.ts index 717f85403..d2a5aaf90 100644 --- a/src/errors/timeoutErrors.ts +++ b/src/errors/timeoutErrors.ts @@ -1,4 +1,3 @@ -/* tslint:disable:max-classes-per-file */ import { JSSLANG_PROPERTIES } from '../constants' import type { Node } from '../types' import { stripIndent } from '../utils/formatters' diff --git a/src/errors/typeErrors.ts b/src/errors/typeErrors.ts index 4e3f3bfda..05069f321 100644 --- a/src/errors/typeErrors.ts +++ b/src/errors/typeErrors.ts @@ -1,15 +1,12 @@ import { generate } from 'astring' import type es from 'estree' - import { UNKNOWN_LOCATION } from '../constants' import type * as tsEs from '../typeChecker/tsESTree' import type { Node, NodeWithInferredType, SArray, Type } from '../types' +import { getSourceVariableDeclaration } from '../utils/ast/helpers' import { simplify, stripIndent } from '../utils/formatters' import { typeToString } from '../utils/stringify' -import { getSourceVariableDeclaration } from '../utils/ast/helpers' -import { ErrorType, ErrorSeverity, type SourceError } from './base' - -// tslint:disable:max-classes-per-file +import { ErrorSeverity, ErrorType, type SourceError } from './base' export class InvalidArrayIndexType implements SourceError { public type = ErrorType.TYPE diff --git a/src/index.ts b/src/index.ts index f9a72de14..8d970f2fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,31 +4,31 @@ import { SourceMapConsumer } from 'source-map' import createContext from './createContext' import { InterruptedError } from './errors/errors' import { findDeclarationNode, findIdentifierNode } from './finder' +import { Chapter, type Variant } from './langs' import { looseParse, parseWithComments } from './parser/utils' import { getAllOccurrencesInScopeHelper, getScopeHelper } from './scope-refactoring' import { setBreakpointAtLine } from './stdlib/inspector' import type { Context, - Error as ResultError, ExecutionMethod, Finished, ModuleContext, RecursivePartial, Result, + Error as ResultError, SVMProgram } from './types' -import { Chapter, type Variant } from './langs' import { assemble } from './vm/svml-assembler' import { compileToIns } from './vm/svml-compiler' import { CSEResultPromise, resumeEvaluate } from './cse-machine/interpreter' +import type { SourceError } from './errors/base' import { ModuleNotFoundError } from './modules/errors' import type { ImportOptions } from './modules/moduleTypes' import preprocessFileImports from './modules/preprocessor' import { validateFilePath } from './modules/preprocessor/filePaths' import { getKeywords, getProgramNames, type NameDeclaration } from './name-extractor' import { htmlRunner, sourceFilesRunner } from './runner' -import type { SourceError } from './errors/base' export { SourceDocumentation } from './editors/ace/docTooltip' @@ -309,4 +309,4 @@ export async function compileFiles( } } -export { createContext, Context, ModuleContext, Result, setBreakpointAtLine, assemble } +export { assemble, Context, createContext, ModuleContext, Result, setBreakpointAtLine } diff --git a/src/modules/loader/__tests__/loader.test.ts b/src/modules/loader/__tests__/loader.test.ts index 2446ec3b3..b402c90ec 100644 --- a/src/modules/loader/__tests__/loader.test.ts +++ b/src/modules/loader/__tests__/loader.test.ts @@ -1,7 +1,8 @@ import { beforeEach, describe, expect, test, vi } from 'vitest' -import { mockContext } from '../../../utils/testing/mocks' import { Chapter, Variant } from '../../../langs' +import { mockContext } from '../../../utils/testing/mocks' import { ModuleConnectionError, ModuleNotFoundError } from '../../errors' +import type { ModuleDocumentation, ModuleManifest } from '../../moduleTypes' import * as importers from '../importers' import { loadModuleBundleAsync, @@ -9,7 +10,6 @@ import { memoizedGetModuleDocsAsync, memoizedGetModuleManifestAsync } from '../loaders' -import type { ModuleDocumentation, ModuleManifest } from '../../moduleTypes' const moduleMocker = vi.fn() diff --git a/src/modules/loader/__tests__/requireProvider.test.ts b/src/modules/loader/__tests__/requireProvider.test.ts index 60c2ed4e3..a802e0a0a 100644 --- a/src/modules/loader/__tests__/requireProvider.test.ts +++ b/src/modules/loader/__tests__/requireProvider.test.ts @@ -1,6 +1,6 @@ import { expect, test, vi } from 'vitest' -import { mockContext } from '../../../utils/testing/mocks' import { Chapter } from '../../../langs' +import { mockContext } from '../../../utils/testing/mocks' import { getRequireProvider } from '../requireProvider' vi.mock( diff --git a/src/modules/loader/index.ts b/src/modules/loader/index.ts index a1c96c070..01dd87b70 100644 --- a/src/modules/loader/index.ts +++ b/src/modules/loader/index.ts @@ -56,7 +56,7 @@ export async function loadSourceModuleTypes(sourceModulesToImport: Set, export { MODULES_STATIC_URL } from './importers' export { - setModulesStaticURL, memoizedGetModuleDocsAsync, - memoizedGetModuleManifestAsync + memoizedGetModuleManifestAsync, + setModulesStaticURL } from './loaders' diff --git a/src/modules/loader/loaders.ts b/src/modules/loader/loaders.ts index 323d7a4bd..58fcf7a48 100644 --- a/src/modules/loader/loaders.ts +++ b/src/modules/loader/loaders.ts @@ -4,8 +4,8 @@ import type { ModuleDocumentation, ModuleFunctions, ModuleManifest } from '../mo import { bundleAndTabImporter, docsImporter, - MODULES_STATIC_URL, - setModulesStaticURL as internalUrlSetter + setModulesStaticURL as internalUrlSetter, + MODULES_STATIC_URL } from './importers' import { getRequireProvider } from './requireProvider' diff --git a/src/modules/preprocessor/__tests__/analyzer.test.ts b/src/modules/preprocessor/__tests__/analyzer.test.ts index 4a5d0eec1..724b1e789 100644 --- a/src/modules/preprocessor/__tests__/analyzer.test.ts +++ b/src/modules/preprocessor/__tests__/analyzer.test.ts @@ -1,20 +1,20 @@ -import { beforeEach, describe, expect, test, vi } from 'vitest' import type { Program } from 'estree' +import { beforeEach, describe, expect, test, vi } from 'vitest' +import { Chapter } from '../../../langs' +import { parse } from '../../../parser/parser' +import { stripIndent } from '../../../utils/formatters' +import { objectKeys } from '../../../utils/misc' +import { mockContext } from '../../../utils/testing/mocks' import { DuplicateImportNameError, UndefinedDefaultImportError, UndefinedImportError, UndefinedNamespaceImportError } from '../../errors' -import { Chapter } from '../../../langs' -import { stripIndent } from '../../../utils/formatters' -import parseProgramsAndConstructImportGraph from '../linker' -import analyzeImportsAndExports from '../analyzer' -import { parse } from '../../../parser/parser' -import { mockContext } from '../../../utils/testing/mocks' import loadSourceModules from '../../loader' import type { SourceFiles as Files } from '../../moduleTypes' -import { objectKeys } from '../../../utils/misc' +import analyzeImportsAndExports from '../analyzer' +import parseProgramsAndConstructImportGraph from '../linker' vi.mock(import('../../loader/loaders')) diff --git a/src/modules/preprocessor/__tests__/linker.test.ts b/src/modules/preprocessor/__tests__/linker.test.ts index 5b30bd78e..372aeb90d 100644 --- a/src/modules/preprocessor/__tests__/linker.test.ts +++ b/src/modules/preprocessor/__tests__/linker.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, test, vi } from 'vitest' -import { mockContext } from '../../../utils/testing/mocks' +import { Chapter } from '../../../langs' import { MissingSemicolonError } from '../../../parser/errors' import type { Context } from '../../../types' -import { Chapter } from '../../../langs' +import { mockContext } from '../../../utils/testing/mocks' import { CircularImportError, ModuleNotFoundError } from '../../errors' import type { SourceFiles } from '../../moduleTypes' import parseProgramsAndConstructImportGraph from '../linker' diff --git a/src/modules/preprocessor/__tests__/preprocessor.test.ts b/src/modules/preprocessor/__tests__/preprocessor.test.ts index b31df7e9a..1d366bc32 100644 --- a/src/modules/preprocessor/__tests__/preprocessor.test.ts +++ b/src/modules/preprocessor/__tests__/preprocessor.test.ts @@ -1,20 +1,20 @@ -import { beforeEach, describe, expect, it, vi } from 'vitest' import type { Program } from 'estree' +import { beforeEach, describe, expect, it, vi } from 'vitest' +import preprocessFileImports from '..' import { parseError, type IOptions } from '../../..' -import { mockContext } from '../../../utils/testing/mocks' -import type { RecursivePartial } from '../../../types' import { Chapter } from '../../../langs' -import { memoizedGetModuleDocsAsync } from '../../loader/loaders' -import preprocessFileImports from '..' -import { sanitizeAST } from '../../../utils/testing/sanitizer' import { parse } from '../../../parser/parser' import { accessExportFunctionName, defaultExportLookupName } from '../../../stdlib/localImport.prelude' -import type { SourceFiles } from '../../moduleTypes' +import type { RecursivePartial } from '../../../types' +import { mockContext } from '../../../utils/testing/mocks' +import { sanitizeAST } from '../../../utils/testing/sanitizer' import { UndefinedImportError } from '../../errors' +import { memoizedGetModuleDocsAsync } from '../../loader/loaders' +import type { SourceFiles } from '../../moduleTypes' vi.mock(import('../../loader/loaders')) diff --git a/src/modules/preprocessor/__tests__/transformers/hoistAndMergeImports.test.ts b/src/modules/preprocessor/__tests__/transformers/hoistAndMergeImports.test.ts index 278308f03..6c851aa3a 100644 --- a/src/modules/preprocessor/__tests__/transformers/hoistAndMergeImports.test.ts +++ b/src/modules/preprocessor/__tests__/transformers/hoistAndMergeImports.test.ts @@ -1,9 +1,9 @@ import { describe, expect, test } from 'vitest' -import { mockContext } from '../../../../utils/testing/mocks' -import { parse } from '../../../../parser/parser' import { Chapter } from '../../../../langs' -import hoistAndMergeImports from '../../transformers/hoistAndMergeImports' +import { parse } from '../../../../parser/parser' +import { mockContext } from '../../../../utils/testing/mocks' import { sanitizeAST } from '../../../../utils/testing/sanitizer' +import hoistAndMergeImports from '../../transformers/hoistAndMergeImports' describe(hoistAndMergeImports, () => { const assertASTsAreEqual = (actualCode: string, expectedCode: string) => { diff --git a/src/modules/preprocessor/__tests__/transformers/removeExports.test.ts b/src/modules/preprocessor/__tests__/transformers/removeExports.test.ts index 26e25edf5..7fe0b89c0 100644 --- a/src/modules/preprocessor/__tests__/transformers/removeExports.test.ts +++ b/src/modules/preprocessor/__tests__/transformers/removeExports.test.ts @@ -1,10 +1,10 @@ import { describe, expect, test } from 'vitest' -import { mockContext } from '../../../../utils/testing/mocks' +import { Chapter } from '../../../../langs' import { parse } from '../../../../parser/parser' import type { Context } from '../../../../types' -import { Chapter } from '../../../../langs' -import removeExports from '../../transformers/removeExports' +import { mockContext } from '../../../../utils/testing/mocks' import { sanitizeAST } from '../../../../utils/testing/sanitizer' +import removeExports from '../../transformers/removeExports' type TestCase = [description: string, inputCode: string, expectedCode: string] diff --git a/src/modules/preprocessor/__tests__/transformers/transformProgramToFunctionDeclaration.test.ts b/src/modules/preprocessor/__tests__/transformers/transformProgramToFunctionDeclaration.test.ts index 1a734db1c..8a786e29a 100644 --- a/src/modules/preprocessor/__tests__/transformers/transformProgramToFunctionDeclaration.test.ts +++ b/src/modules/preprocessor/__tests__/transformers/transformProgramToFunctionDeclaration.test.ts @@ -1,10 +1,10 @@ import { beforeEach, describe, expect, it } from 'vitest' -import { mockContext } from '../../../../utils/testing/mocks' +import { Chapter } from '../../../../langs' import { parse } from '../../../../parser/parser' import { defaultExportLookupName } from '../../../../stdlib/localImport.prelude' -import { Chapter } from '../../../../langs' -import { transformProgramToFunctionDeclaration } from '../../transformers/transformProgramToFunctionDeclaration' +import { mockContext } from '../../../../utils/testing/mocks' import { sanitizeAST } from '../../../../utils/testing/sanitizer' +import { transformProgramToFunctionDeclaration } from '../../transformers/transformProgramToFunctionDeclaration' describe('transformImportedFile', () => { const currentFileName = '/dir/a.js' diff --git a/src/modules/preprocessor/analyzer.ts b/src/modules/preprocessor/analyzer.ts index d066a50dc..99c87a218 100644 --- a/src/modules/preprocessor/analyzer.ts +++ b/src/modules/preprocessor/analyzer.ts @@ -1,6 +1,7 @@ import type es from 'estree' import { partition } from 'lodash' +import type { Context } from '../../types' import assert from '../../utils/assert' import { getIdsFromDeclaration, @@ -16,7 +17,6 @@ import { UndefinedNamespaceImportError } from '../errors' import { isSourceModule } from '../utils' -import type { Context } from '../../types' export const defaultAnalysisOptions: ImportAnalysisOptions = { allowUndefinedImports: false, diff --git a/src/modules/preprocessor/bundler.ts b/src/modules/preprocessor/bundler.ts index 8138ba30e..81d1afc42 100644 --- a/src/modules/preprocessor/bundler.ts +++ b/src/modules/preprocessor/bundler.ts @@ -1,22 +1,22 @@ import { posix as posixPath } from 'path' import type es from 'estree' -import { isIdentifier, isImportDeclaration, isModuleDeclaration } from '../../utils/ast/typeGuards' +import type { Context } from '../..' import assert from '../../utils/assert' import { getModuleDeclarationSource } from '../../utils/ast/helpers' +import { isIdentifier, isImportDeclaration, isModuleDeclaration } from '../../utils/ast/typeGuards' import { isSourceModule } from '../utils' -import type { Context } from '../..' -import { - createAccessImportStatements, - getInvokedFunctionResultVariableNameToImportSpecifiersMap, - transformProgramToFunctionDeclaration -} from './transformers/transformProgramToFunctionDeclaration' +import { createInvokedFunctionResultVariableDeclaration } from './constructors/contextSpecificConstructors' import { transformFilePathToValidFunctionName, transformFunctionNameToInvokedFunctionResultVariableName } from './filePaths' -import { createInvokedFunctionResultVariableDeclaration } from './constructors/contextSpecificConstructors' import hoistAndMergeImports from './transformers/hoistAndMergeImports' import removeExports from './transformers/removeExports' +import { + createAccessImportStatements, + getInvokedFunctionResultVariableNameToImportSpecifiersMap, + transformProgramToFunctionDeclaration +} from './transformers/transformProgramToFunctionDeclaration' /** * A function that converts multiple programs into a single program diff --git a/src/modules/preprocessor/index.ts b/src/modules/preprocessor/index.ts index 9c24d57c5..8bc4f754f 100644 --- a/src/modules/preprocessor/index.ts +++ b/src/modules/preprocessor/index.ts @@ -2,13 +2,13 @@ import type es from 'estree' // import * as TypedES from '../../typeChecker/tsESTree' import type { Context, IOptions } from '../..' +import { Variant } from '../../langs' import { RecursivePartial } from '../../types' import loadSourceModules, { loadSourceModuleTypes } from '../loader' import type { FileGetter } from '../moduleTypes' -import { Variant } from '../../langs' import analyzeImportsAndExports from './analyzer' -import parseProgramsAndConstructImportGraph from './linker' import defaultBundler, { type Bundler } from './bundler' +import parseProgramsAndConstructImportGraph from './linker' export type PreprocessResult = | { diff --git a/src/modules/preprocessor/linker.ts b/src/modules/preprocessor/linker.ts index c7a71c796..58b38e27e 100644 --- a/src/modules/preprocessor/linker.ts +++ b/src/modules/preprocessor/linker.ts @@ -2,13 +2,13 @@ import type es from 'estree' import type { Context } from '../..' import { parse } from '../../parser/parser' +import { parseAt } from '../../parser/utils' import type { RecursivePartial } from '../../types' -import { CircularImportError, ModuleNotFoundError } from '../errors' import { getModuleDeclarationSource } from '../../utils/ast/helpers' -import type { FileGetter } from '../moduleTypes' -import { mapAndFilter } from '../../utils/misc' -import { parseAt } from '../../parser/utils' import { isDirective } from '../../utils/ast/typeGuards' +import { mapAndFilter } from '../../utils/misc' +import { CircularImportError, ModuleNotFoundError } from '../errors' +import type { FileGetter } from '../moduleTypes' import { DirectedGraph } from './directedGraph' import resolveFile, { defaultResolutionOptions, type ImportResolutionOptions } from './resolver' diff --git a/src/modules/preprocessor/resolver.ts b/src/modules/preprocessor/resolver.ts index 04342b4bc..d028b3546 100644 --- a/src/modules/preprocessor/resolver.ts +++ b/src/modules/preprocessor/resolver.ts @@ -1,7 +1,7 @@ import { posix as posixPath } from 'path' import { memoizedGetModuleManifestAsync } from '../loader' -import { isSourceModule } from '../utils' import type { FileGetter } from '../moduleTypes' +import { isSourceModule } from '../utils' /** * Options for resolving modules given a path diff --git a/src/name-extractor/__tests__/autocomplete.test.ts b/src/name-extractor/__tests__/autocomplete.test.ts index 46939434a..c8e8e5b1a 100644 --- a/src/name-extractor/__tests__/autocomplete.test.ts +++ b/src/name-extractor/__tests__/autocomplete.test.ts @@ -1,5 +1,5 @@ -import { expect, test, vi } from 'vitest' import { pick } from 'lodash' +import { expect, test, vi } from 'vitest' import { createContext } from '../..' import { getNames } from '../../index' import { Chapter } from '../../langs' diff --git a/src/name-extractor/__tests__/modules.test.ts b/src/name-extractor/__tests__/modules.test.ts index d9917b291..2efe3b2da 100644 --- a/src/name-extractor/__tests__/modules.test.ts +++ b/src/name-extractor/__tests__/modules.test.ts @@ -1,14 +1,14 @@ import { beforeEach, describe, expect, test, vi } from 'vitest' import { DeclarationKind } from '..' import { getNames } from '../..' -import { mockContext } from '../../utils/testing/mocks' import { Chapter } from '../../langs' +import { mockContext } from '../../utils/testing/mocks' +import { ModuleConnectionError } from '../../modules/errors' import { memoizedGetModuleDocsAsync, memoizedGetModuleManifestAsync } from '../../modules/loader/loaders' -import { ModuleConnectionError } from '../../modules/errors' vi.mock(import('../../modules/loader/loaders')) diff --git a/src/name-extractor/index.ts b/src/name-extractor/index.ts index 0272ebbb8..1afe89427 100644 --- a/src/name-extractor/index.ts +++ b/src/name-extractor/index.ts @@ -8,9 +8,9 @@ import { memoizedGetModuleDocsAsync, memoizedGetModuleManifestAsync } from '../m import type { ModuleDocsEntry } from '../modules/moduleTypes' import { isSourceModule } from '../modules/utils' import syntaxBlacklist from '../parser/source/syntax' +import type { Context, Node } from '../types' import { getImportedName, getModuleDeclarationSource } from '../utils/ast/helpers' import { isDeclaration, isImportDeclaration, isNamespaceSpecifier } from '../utils/ast/typeGuards' -import type { Context, Node } from '../types' export enum DeclarationKind { KIND_IMPORT = 'import', @@ -173,7 +173,6 @@ export async function getProgramNames( while (queue.length > 0) { // Workaround due to minification problem - // tslint:disable-next-line const node = queue.shift()! if (isFunction(node)) { // This is the only time we want raw identifiers diff --git a/src/parser/__tests__/fullTS.test.ts b/src/parser/__tests__/fullTS.test.ts index 4a7dbec01..6d0167b98 100644 --- a/src/parser/__tests__/fullTS.test.ts +++ b/src/parser/__tests__/fullTS.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it } from 'vitest' import { parseError } from '../..' -import { mockContext } from '../../utils/testing/mocks' import { Chapter } from '../../langs' +import { mockContext } from '../../utils/testing/mocks' import { FullTSParser } from '../fullTS' const parser = new FullTSParser() diff --git a/src/parser/__tests__/python.test.ts b/src/parser/__tests__/python.test.ts index ad91176f4..40a3aa9d7 100644 --- a/src/parser/__tests__/python.test.ts +++ b/src/parser/__tests__/python.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it } from 'vitest' import { parseError } from '../..' -import { mockContext } from '../../utils/testing/mocks' import { Chapter } from '../../langs' +import { mockContext } from '../../utils/testing/mocks' import { FatalSyntaxError } from '../errors' import { parse } from '../parser' import { PythonParser } from '../python' diff --git a/src/parser/errors.ts b/src/parser/errors.ts index 8e41d3664..78c9e5344 100644 --- a/src/parser/errors.ts +++ b/src/parser/errors.ts @@ -1,8 +1,8 @@ import type { SourceLocation } from 'estree' import { UNKNOWN_LOCATION } from '../constants' +import { ErrorSeverity, ErrorType, type SourceError } from '../errors/base' import type { Node } from '../types' -import { ErrorType, ErrorSeverity, type SourceError } from '../errors/base' import { stripIndent } from '../utils/formatters' export class MissingSemicolonError implements SourceError { diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 48990b1f7..2be829752 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -1,7 +1,7 @@ import type { Program } from 'estree' -import type { Context } from '../types' import { Chapter, Variant } from '../langs' +import type { Context } from '../types' import { FullJSParser } from './fullJS' import { FullTSParser } from './fullTS' import { PythonParser } from './python' diff --git a/src/parser/python/index.ts b/src/parser/python/index.ts index d6a41dfa6..d76bfa82e 100644 --- a/src/parser/python/index.ts +++ b/src/parser/python/index.ts @@ -1,8 +1,8 @@ import type { Program } from 'estree' +import { Chapter } from '../../langs' import { parsePythonToEstreeAst } from '../../py-slang/src' import type { Context } from '../../types' -import { Chapter } from '../../langs' import { FatalSyntaxError } from '../errors' import type { AcornOptions, Parser } from '../types' import { positionToSourceLocation } from '../utils' diff --git a/src/parser/scheme/index.ts b/src/parser/scheme/index.ts index e198d05ed..4d752cbca 100644 --- a/src/parser/scheme/index.ts +++ b/src/parser/scheme/index.ts @@ -1,7 +1,7 @@ import type { Program } from 'estree' import { schemeParse } from '../../alt-langs/scheme/scm-slang/src' -import type { Context } from '../../types' import { Chapter } from '../../langs' +import type { Context } from '../../types' import { FatalSyntaxError } from '../errors' import type { AcornOptions, Parser } from '../types' import { positionToSourceLocation } from '../utils' diff --git a/src/parser/source/index.ts b/src/parser/source/index.ts index 93b18e468..12cacfe62 100644 --- a/src/parser/source/index.ts +++ b/src/parser/source/index.ts @@ -2,11 +2,11 @@ import { parse as acornParse, type Token, tokenizer } from 'acorn' import type es from 'estree' import { DEFAULT_ECMA_VERSION } from '../../constants' -import type { Context, Node } from '../../types' import type { Chapter, Variant } from '../../langs' +import type { Context, Node } from '../../types' import { ancestor, AncestorWalkerFn } from '../../utils/ast/walkers' import { DisallowedConstructError, FatalSyntaxError } from '../errors' -import type { AcornOptions, Rule, Parser } from '../types' +import type { AcornOptions, Parser, Rule } from '../types' import { createAcornParserOptions, positionToSourceLocation } from '../utils' import defaultRules from './rules' import syntaxBlacklist from './syntax' diff --git a/src/parser/source/rules/bracesAroundFor.ts b/src/parser/source/rules/bracesAroundFor.ts index a3c0fc1bf..eb337d7e0 100644 --- a/src/parser/source/rules/bracesAroundFor.ts +++ b/src/parser/source/rules/bracesAroundFor.ts @@ -1,7 +1,7 @@ import { generate } from 'astring' import type { ForStatement } from 'estree' -import type { Rule } from '../../types' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class BracesAroundForError extends RuleError { public explain() { diff --git a/src/parser/source/rules/bracesAroundIfElse.ts b/src/parser/source/rules/bracesAroundIfElse.ts index 28309a359..6d6f62913 100644 --- a/src/parser/source/rules/bracesAroundIfElse.ts +++ b/src/parser/source/rules/bracesAroundIfElse.ts @@ -1,8 +1,8 @@ import { generate } from 'astring' import type { IfStatement } from 'estree' -import type { Rule } from '../../types' import { stripIndent } from '../../../utils/formatters' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class BracesAroundIfElseError extends RuleError { constructor( diff --git a/src/parser/source/rules/bracesAroundWhile.ts b/src/parser/source/rules/bracesAroundWhile.ts index fcee41164..7dcbff36e 100644 --- a/src/parser/source/rules/bracesAroundWhile.ts +++ b/src/parser/source/rules/bracesAroundWhile.ts @@ -1,7 +1,7 @@ import { generate } from 'astring' import type { WhileStatement } from 'estree' -import type { Rule } from '../../types' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class BracesAroundWhileError extends RuleError { public explain() { diff --git a/src/parser/source/rules/forStatementMustHaveAllParts.ts b/src/parser/source/rules/forStatementMustHaveAllParts.ts index 9a6ff921e..d47f613f9 100644 --- a/src/parser/source/rules/forStatementMustHaveAllParts.ts +++ b/src/parser/source/rules/forStatementMustHaveAllParts.ts @@ -1,7 +1,7 @@ import type { ForStatement } from 'estree' -import type { Rule } from '../../types' import { stripIndent } from '../../../utils/formatters' import { RuleError } from '../../errors' +import type { Rule } from '../../types' type ForStatementParts = keyof ForStatement const forStatementParts: ForStatementParts[] = ['init', 'test', 'update'] diff --git a/src/parser/source/rules/noConstDeclarationInForLoopInit.ts b/src/parser/source/rules/noConstDeclarationInForLoopInit.ts index a9ad878f1..b31a83f6d 100644 --- a/src/parser/source/rules/noConstDeclarationInForLoopInit.ts +++ b/src/parser/source/rules/noConstDeclarationInForLoopInit.ts @@ -1,7 +1,7 @@ import type { ForStatement } from 'estree' -import type { Rule } from '../../types' import { stripIndent } from '../../../utils/formatters' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoConstDeclarationInForLoopInit extends RuleError { public explain(): string { diff --git a/src/parser/source/rules/noDeclareMutable.ts b/src/parser/source/rules/noDeclareMutable.ts index f38b04165..9cff6182a 100644 --- a/src/parser/source/rules/noDeclareMutable.ts +++ b/src/parser/source/rules/noDeclareMutable.ts @@ -1,9 +1,9 @@ import { generate } from 'astring' import type { VariableDeclaration } from 'estree' -import type { Rule } from '../../types' -import { RuleError } from '../../errors' import { Chapter } from '../../../langs' import { getSourceVariableDeclaration } from '../../../utils/ast/helpers' +import { RuleError } from '../../errors' +import type { Rule } from '../../types' const mutableDeclarators: VariableDeclaration['kind'][] = ['let', 'var'] diff --git a/src/parser/source/rules/noDotAbbreviation.ts b/src/parser/source/rules/noDotAbbreviation.ts index 1f65b8bc5..1987e6e02 100644 --- a/src/parser/source/rules/noDotAbbreviation.ts +++ b/src/parser/source/rules/noDotAbbreviation.ts @@ -1,7 +1,7 @@ import type { MemberExpression } from 'estree' -import type { Rule } from '../../types' -import { RuleError } from '../../errors' import { Chapter } from '../../../langs' +import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoDotAbbreviationError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noExportNamedDeclarationWithDefault.ts b/src/parser/source/rules/noExportNamedDeclarationWithDefault.ts index d1003ec0d..2c6a6ef17 100644 --- a/src/parser/source/rules/noExportNamedDeclarationWithDefault.ts +++ b/src/parser/source/rules/noExportNamedDeclarationWithDefault.ts @@ -1,9 +1,9 @@ import type { ExportNamedDeclaration } from 'estree' import { defaultExportLookupName } from '../../../stdlib/localImport.prelude' +import { mapAndFilter } from '../../../utils/misc' +import { RuleError } from '../../errors' import type { Rule } from '../../types' import syntaxBlacklist from '../syntax' -import { RuleError } from '../../errors' -import { mapAndFilter } from '../../../utils/misc' export class NoExportNamedDeclarationWithDefaultError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noExportNamedDeclarationWithSource.ts b/src/parser/source/rules/noExportNamedDeclarationWithSource.ts index 05a0f8140..9ac25b6c6 100644 --- a/src/parser/source/rules/noExportNamedDeclarationWithSource.ts +++ b/src/parser/source/rules/noExportNamedDeclarationWithSource.ts @@ -1,7 +1,7 @@ import type { ExportNamedDeclaration } from 'estree' -import type { Rule } from '../../types' -import { RuleError } from '../../errors' import { speciferToString } from '../../../utils/ast/helpers' +import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoExportNamedDeclarationWithSourceError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noFunctionDeclarationWithoutIdentifier.ts b/src/parser/source/rules/noFunctionDeclarationWithoutIdentifier.ts index 7a55795ca..5063b24f6 100644 --- a/src/parser/source/rules/noFunctionDeclarationWithoutIdentifier.ts +++ b/src/parser/source/rules/noFunctionDeclarationWithoutIdentifier.ts @@ -1,6 +1,6 @@ import type { FunctionDeclaration } from 'estree' -import type { Rule } from '../../types' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoFunctionDeclarationWithoutIdentifierError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noHolesInArrays.ts b/src/parser/source/rules/noHolesInArrays.ts index 94a4d7d16..77d24c73e 100644 --- a/src/parser/source/rules/noHolesInArrays.ts +++ b/src/parser/source/rules/noHolesInArrays.ts @@ -1,7 +1,7 @@ import type { ArrayExpression } from 'estree' -import type { Rule } from '../../types' import { stripIndent } from '../../../utils/formatters' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoHolesInArrays extends RuleError { public explain() { diff --git a/src/parser/source/rules/noIfWithoutElse.ts b/src/parser/source/rules/noIfWithoutElse.ts index 8398facd9..4e68b1c8f 100644 --- a/src/parser/source/rules/noIfWithoutElse.ts +++ b/src/parser/source/rules/noIfWithoutElse.ts @@ -1,9 +1,9 @@ import { generate } from 'astring' import type { IfStatement } from 'estree' -import type { Rule } from '../../types' +import { Chapter } from '../../../langs' import { stripIndent } from '../../../utils/formatters' import { RuleError } from '../../errors' -import { Chapter } from '../../../langs' +import type { Rule } from '../../types' export class NoIfWithoutElseError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noImplicitDeclareUndefined.ts b/src/parser/source/rules/noImplicitDeclareUndefined.ts index 57d277d31..fcb840be3 100644 --- a/src/parser/source/rules/noImplicitDeclareUndefined.ts +++ b/src/parser/source/rules/noImplicitDeclareUndefined.ts @@ -1,8 +1,8 @@ import type { Identifier, VariableDeclaration } from 'estree' -import type { Rule } from '../../types' import { stripIndent } from '../../../utils/formatters' -import { RuleError } from '../../errors' import { mapAndFilter } from '../../../utils/misc' +import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoImplicitDeclareUndefinedError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noImplicitReturnUndefined.ts b/src/parser/source/rules/noImplicitReturnUndefined.ts index bb78a0f69..7a717a4fb 100644 --- a/src/parser/source/rules/noImplicitReturnUndefined.ts +++ b/src/parser/source/rules/noImplicitReturnUndefined.ts @@ -1,7 +1,7 @@ import type { ReturnStatement } from 'estree' -import type { Rule } from '../../types' import { stripIndent } from '../../../utils/formatters' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoImplicitReturnUndefinedError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noImportSpecifierWithDefault.ts b/src/parser/source/rules/noImportSpecifierWithDefault.ts index 8612c44b8..0c5075636 100644 --- a/src/parser/source/rules/noImportSpecifierWithDefault.ts +++ b/src/parser/source/rules/noImportSpecifierWithDefault.ts @@ -1,8 +1,8 @@ import type { ImportSpecifier } from 'estree' import { defaultExportLookupName } from '../../../stdlib/localImport.prelude' +import { RuleError } from '../../errors' import type { Rule } from '../../types' import syntaxBlacklist from '../syntax' -import { RuleError } from '../../errors' export class NoImportSpecifierWithDefaultError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noNull.ts b/src/parser/source/rules/noNull.ts index 1ee89c194..aeeb2ce05 100644 --- a/src/parser/source/rules/noNull.ts +++ b/src/parser/source/rules/noNull.ts @@ -1,7 +1,7 @@ import type { Literal } from 'estree' +import { Chapter } from '../../../langs' import { RuleError } from '../../errors' import type { Rule } from '../../types' -import { Chapter } from '../../../langs' export class NoNullError extends RuleError { public explain() { diff --git a/src/parser/source/rules/noUnspecifiedOperator.ts b/src/parser/source/rules/noUnspecifiedOperator.ts index 00433c427..0b9c5b401 100644 --- a/src/parser/source/rules/noUnspecifiedOperator.ts +++ b/src/parser/source/rules/noUnspecifiedOperator.ts @@ -1,6 +1,6 @@ import type { AssignmentExpression, BinaryExpression, UnaryExpression } from 'estree' -import type { Rule } from '../../types' import { RuleError } from '../../errors' +import type { Rule } from '../../types' type ExpressionNodeType = AssignmentExpression | BinaryExpression | UnaryExpression diff --git a/src/parser/source/rules/noVar.ts b/src/parser/source/rules/noVar.ts index 18b05f94f..b9f210e37 100644 --- a/src/parser/source/rules/noVar.ts +++ b/src/parser/source/rules/noVar.ts @@ -1,8 +1,8 @@ -import type { VariableDeclaration } from 'estree' import { generate } from 'astring' -import type { Rule } from '../../types' -import { RuleError } from '../../errors' +import type { VariableDeclaration } from 'estree' import { getSourceVariableDeclaration } from '../../../utils/ast/helpers' +import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class NoVarError extends RuleError { public explain() { diff --git a/src/parser/source/rules/singleVariableDeclaration.ts b/src/parser/source/rules/singleVariableDeclaration.ts index 3ac411c76..f5f6f5ae7 100644 --- a/src/parser/source/rules/singleVariableDeclaration.ts +++ b/src/parser/source/rules/singleVariableDeclaration.ts @@ -1,7 +1,7 @@ import { generate } from 'astring' import type { VariableDeclaration } from 'estree' -import type { Rule } from '../../types' import { RuleError } from '../../errors' +import type { Rule } from '../../types' export class MultipleDeclarationsError extends RuleError { private readonly fixs: VariableDeclaration[] diff --git a/src/parser/types.ts b/src/parser/types.ts index 976aa70fb..7282d536b 100644 --- a/src/parser/types.ts +++ b/src/parser/types.ts @@ -1,11 +1,11 @@ import type { Program } from 'estree' -import type { Context, Node } from '../types' -import { Chapter, Variant } from '../langs' import type { SourceError } from '../errors/base' +import { Chapter, Variant } from '../langs' +import type { Context, Node } from '../types' -export type { Options as AcornOptions } from 'acorn' export type { ParserOptions as BabelOptions } from '@babel/parser' +export type { Options as AcornOptions } from 'acorn' export interface Parser { parse( diff --git a/src/parser/utils.ts b/src/parser/utils.ts index 75b115251..3cf357d44 100644 --- a/src/parser/utils.ts +++ b/src/parser/utils.ts @@ -1,9 +1,9 @@ import { + parse as acornParse, + parseExpressionAt as acornParseAt, type Comment, ecmaVersion, type Node, - parse as acornParse, - parseExpressionAt as acornParseAt, type Position } from 'acorn' import { parse as acornLooseParse } from 'acorn-loose' diff --git a/src/repl/__tests__/main.test.ts b/src/repl/__tests__/main.test.ts index 0b829df38..cb909c3d9 100644 --- a/src/repl/__tests__/main.test.ts +++ b/src/repl/__tests__/main.test.ts @@ -1,7 +1,7 @@ // @vitest-environment node -import { describe, test, expect, vi } from 'vitest' import type { Command } from '@commander-js/extra-typings' +import { describe, expect, test, vi } from 'vitest' import { getMainCommand } from '../main' vi.spyOn(process, 'exit').mockImplementation(code => { diff --git a/src/repl/__tests__/repl.test.ts b/src/repl/__tests__/repl.test.ts index 59e3fcfe3..db90405bd 100644 --- a/src/repl/__tests__/repl.test.ts +++ b/src/repl/__tests__/repl.test.ts @@ -3,8 +3,8 @@ import fs from 'fs/promises' import repl from 'repl' import { beforeEach, describe, expect, test, vi } from 'vitest' -import type { SourceFiles } from '../../modules/moduleTypes' import { Chapter } from '../../langs' +import type { SourceFiles } from '../../modules/moduleTypes' import { getReplCommand } from '../repl' import { chapterParser } from '../utils' diff --git a/src/repl/__tests__/svmc.test.ts b/src/repl/__tests__/svmc.test.ts index 88d3a1131..519b13245 100644 --- a/src/repl/__tests__/svmc.test.ts +++ b/src/repl/__tests__/svmc.test.ts @@ -2,8 +2,8 @@ import fs from 'fs/promises' import { beforeEach, describe, expect, it, test, vi } from 'vitest' -import { compileToChoices, getSVMCCommand } from '../svmc' import * as vm from '../../vm/svml-compiler' +import { compileToChoices, getSVMCCommand } from '../svmc' import { expectWritten, getCommandRunner } from './utils' const mockedReadFile = vi.spyOn(fs, 'readFile') diff --git a/src/repl/__tests__/utils.ts b/src/repl/__tests__/utils.ts index de4c715c0..e646664bd 100644 --- a/src/repl/__tests__/utils.ts +++ b/src/repl/__tests__/utils.ts @@ -1,5 +1,5 @@ -import { expect, vi } from 'vitest' import type { Command } from '@commander-js/extra-typings' +import { expect, vi } from 'vitest' /** * Set up the environment for testing the given command. Returns diff --git a/src/repl/main.ts b/src/repl/main.ts index 6ca6834ae..bf21bcb5d 100644 --- a/src/repl/main.ts +++ b/src/repl/main.ts @@ -1,7 +1,7 @@ import { Command } from '@commander-js/extra-typings' -import { getSVMCCommand } from './svmc' import { getReplCommand } from './repl' +import { getSVMCCommand } from './svmc' import { getTranspilerCommand } from './transpiler' export const getMainCommand = () => diff --git a/src/repl/repl.ts b/src/repl/repl.ts index 83f901310..7f113e54d 100644 --- a/src/repl/repl.ts +++ b/src/repl/repl.ts @@ -4,11 +4,11 @@ import replLib from 'repl' import { Command } from '@commander-js/extra-typings' import { createContext, type IOptions } from '..' -import { setModulesStaticURL } from '../modules/loader' -import type { RecursivePartial } from '../types' import { Chapter, isSupportedLanguageCombo, Variant } from '../langs' -import { runCodeInSource, sourceFilesRunner } from '../runner' +import { setModulesStaticURL } from '../modules/loader' import type { FileGetter } from '../modules/moduleTypes' +import { runCodeInSource, sourceFilesRunner } from '../runner' +import type { RecursivePartial } from '../types' import { chapterParser, getChapterOption, diff --git a/src/repl/svmc.ts b/src/repl/svmc.ts index f6e9ca19d..8b75ba62b 100644 --- a/src/repl/svmc.ts +++ b/src/repl/svmc.ts @@ -1,12 +1,12 @@ -import { basename, extname } from 'path' import fs from 'fs/promises' +import { basename, extname } from 'path' import { Command, InvalidArgumentError, Option } from '@commander-js/extra-typings' +import { parseError } from '..' import { createEmptyContext } from '../createContext' -import { parse } from '../parser/parser' import { Chapter, Variant } from '../langs' +import { parse } from '../parser/parser' import { stripIndent } from '../utils/formatters' -import { parseError } from '..' import { assemble } from '../vm/svml-assembler' import { compileToIns } from '../vm/svml-compiler' import { stringifyProgram } from '../vm/util' diff --git a/src/repl/transpiler.ts b/src/repl/transpiler.ts index 68f1c77af..3f4fd6546 100644 --- a/src/repl/transpiler.ts +++ b/src/repl/transpiler.ts @@ -5,10 +5,10 @@ import { Command } from '@commander-js/extra-typings' import { generate } from 'astring' import { createContext, parseError } from '../index' +import { Chapter, isSourceLanguage, Variant } from '../langs' import defaultBundler from '../modules/preprocessor/bundler' import parseProgramsAndConstructImportGraph from '../modules/preprocessor/linker' import { transpile } from '../transpiler/transpiler' -import { Chapter, isSourceLanguage, Variant } from '../langs' import { chapterParser, getChapterOption, getLanguageOption, getVariantOption } from './utils' export const getTranspilerCommand = () => diff --git a/src/repl/utils.ts b/src/repl/utils.ts index 89e45f61d..6da020944 100644 --- a/src/repl/utils.ts +++ b/src/repl/utils.ts @@ -1,11 +1,11 @@ import { Option } from '@commander-js/extra-typings' -import { stringify } from '../utils/stringify' -import Closure from '../cse-machine/closure' import { parseError } from '..' +import Closure from '../cse-machine/closure' +import { Chapter, LanguageOptions, Variant } from '../langs' import type { Context, Result } from '../types' import { objectKeys } from '../utils/misc' -import { Chapter, LanguageOptions, Variant } from '../langs' +import { stringify } from '../utils/stringify' export function chapterParser(str: string): Chapter { let foundChapter: string | undefined diff --git a/src/runner/__tests__/files.test.ts b/src/runner/__tests__/files.test.ts index ffbb95ff9..157250f5e 100644 --- a/src/runner/__tests__/files.test.ts +++ b/src/runner/__tests__/files.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it } from 'vitest' import { compileFiles, parseError, runFilesInContext } from '../../index' -import { mockContext } from '../../utils/testing/mocks' import { Chapter } from '../../langs' +import { mockContext } from '../../utils/testing/mocks' describe(runFilesInContext, () => { let context = mockContext(Chapter.SOURCE_4) diff --git a/src/runner/__tests__/runners.test.ts b/src/runner/__tests__/runners.test.ts index 42a8765a8..4b3f442c2 100644 --- a/src/runner/__tests__/runners.test.ts +++ b/src/runner/__tests__/runners.test.ts @@ -1,19 +1,19 @@ import { describe, expect, it, test } from 'vitest' import { parseError, runInContext } from '../..' -import { UndefinedVariable } from '../../errors/errors' -import { mockContext } from '../../utils/testing/mocks' -import { FatalSyntaxError } from '../../parser/errors' import type { SourceError } from '../../errors/base' +import { UndefinedVariable } from '../../errors/errors' import { Chapter, Variant } from '../../langs' +import { FatalSyntaxError } from '../../parser/errors' import { locationDummyNode } from '../../utils/ast/astCreator' -import { htmlErrorHandlingScript } from '../htmlRunner' import { - expectParsedError, expectFinishedResult, + expectParsedError, testFailure, testSuccess } from '../../utils/testing' import { assertFinishedResultValue, testWithChapters } from '../../utils/testing/misc' +import { mockContext } from '../../utils/testing/mocks' +import { htmlErrorHandlingScript } from '../htmlRunner' interface CodeSnippetTestCase { name: string diff --git a/src/runner/errors.ts b/src/runner/errors.ts index 87e16cbe3..8fdbacca5 100644 --- a/src/runner/errors.ts +++ b/src/runner/errors.ts @@ -1,8 +1,8 @@ import { type NullableMappedPosition, type RawSourceMap, SourceMapConsumer } from 'source-map' import { UNKNOWN_LOCATION } from '../constants' -import { ConstAssignment, ExceptionError, UndefinedVariable } from '../errors/errors' import type { SourceError } from '../errors/base' +import { ConstAssignment, ExceptionError, UndefinedVariable } from '../errors/errors' import { locationDummyNode } from '../utils/ast/astCreator' enum BrowserType { diff --git a/src/runner/index.ts b/src/runner/index.ts index ee142f77c..afeefe226 100644 --- a/src/runner/index.ts +++ b/src/runner/index.ts @@ -1,18 +1,18 @@ -import * as _ from 'lodash' import type { Program } from 'estree' +import * as _ from 'lodash' import type { Context, IOptions, Result } from '..' import { mapResult } from '../alt-langs/mapper' +import { Chapter, Variant } from '../langs' import type { FileGetter } from '../modules/moduleTypes' import preprocessFileImports from '../modules/preprocessor' -import type { RecursivePartial } from '../types' -import { Chapter, Variant } from '../langs' -import { validateAndAnnotate } from '../validator/validator' -import { parse } from '../parser/parser' -import assert from '../utils/assert' import { defaultAnalysisOptions } from '../modules/preprocessor/analyzer' import { defaultLinkerOptions } from '../modules/preprocessor/linker' -import { determineExecutionMethod, determineVariant } from './utils' +import { parse } from '../parser/parser' +import type { RecursivePartial } from '../types' +import assert from '../utils/assert' +import { validateAndAnnotate } from '../validator/validator' import runners from './sourceRunner' +import { determineExecutionMethod, determineVariant } from './utils' let previousCode: { files: Partial> diff --git a/src/runner/sourceRunner.ts b/src/runner/sourceRunner.ts index fd2de61bc..5f2636fe8 100644 --- a/src/runner/sourceRunner.ts +++ b/src/runner/sourceRunner.ts @@ -6,12 +6,12 @@ import { CSEResultPromise, evaluate as CSEvaluate } from '../cse-machine/interpr import { ExceptionError } from '../errors/errors' import { RuntimeSourceError } from '../errors/runtimeSourceError' import { TimeoutError } from '../errors/timeoutErrors' +import { getSteps } from '../tracer/steppers' import { sandboxedEval } from '../transpiler/evalContainer' import { transpile } from '../transpiler/transpiler' -import { getSteps } from '../tracer/steppers' import { toSourceError } from './errors' -import type { Runner } from './types' import fullJSRunner from './fullJSRunner' +import type { Runner } from './types' let isPreviousCodeTimeoutError = false const runners = { diff --git a/src/stdlib/__tests__/list.test.ts b/src/stdlib/__tests__/list.test.ts index 2b7a530e0..0b1ab76de 100644 --- a/src/stdlib/__tests__/list.test.ts +++ b/src/stdlib/__tests__/list.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it, test } from 'vitest' import { Chapter } from '../../langs' import { stripIndent } from '../../utils/formatters' -import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing' +import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing' import * as list from '../list' test('list creates list', async () => { diff --git a/src/stdlib/__tests__/misc.test.ts b/src/stdlib/__tests__/misc.test.ts index 686ccadb7..324b37704 100644 --- a/src/stdlib/__tests__/misc.test.ts +++ b/src/stdlib/__tests__/misc.test.ts @@ -1,7 +1,7 @@ import { test } from 'vitest' import { Chapter } from '../../langs' import { stripIndent } from '../../utils/formatters' -import { expectParsedError, expectFinishedResult } from '../../utils/testing' +import { expectFinishedResult, expectParsedError } from '../../utils/testing' test('parse_int with valid args is ok, radix 2', () => { return expectFinishedResult(`parse_int('1100101010101', 2);`, Chapter.SOURCE_1).toBe( diff --git a/src/stdlib/__tests__/stream.test.ts b/src/stdlib/__tests__/stream.test.ts index 028906b75..5d7a2eb43 100644 --- a/src/stdlib/__tests__/stream.test.ts +++ b/src/stdlib/__tests__/stream.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from 'vitest' import { Chapter } from '../../langs' import { stripIndent } from '../../utils/formatters' -import { expectParsedError, expectFinishedResult, testSuccess } from '../../utils/testing' +import { expectFinishedResult, expectParsedError, testSuccess } from '../../utils/testing' describe('primitive stream functions', () => { test('empty stream is null', () => { diff --git a/src/stdlib/index.ts b/src/stdlib/index.ts index 6a186f040..329c3b59f 100644 --- a/src/stdlib/index.ts +++ b/src/stdlib/index.ts @@ -1,6 +1,6 @@ import createContext from '../createContext' -import type { Value } from '../types' import { Chapter } from '../langs' +import type { Value } from '../types' import * as list from './list' import * as misc from './misc' import * as parser from './parser' @@ -50,7 +50,6 @@ export const chapter_4 = { ...chapter_3, parse: (str: string, chapter: Chapter) => parser.parse(str, createContext(chapter)), tokenize: (str: string, chapter: Chapter) => parser.tokenize(str, createContext(chapter)), - // tslint:disable-next-line:ban-types apply_in_underlying_javascript: (fun: Function, args: Value) => fun.apply(fun, list.list_to_vector(args)) } @@ -61,7 +60,6 @@ export const chapter_library_parser = { is_NaN: misc.is_NaN, has_own_property: misc.has_own_property // defineBuiltin(context, 'alert(val)', alert) - // tslint:disable-next-line:ban-types // timed: (f: Function: context: Context) => misc.timed(context, f, context.externalContext, externalBuiltIns.rawDisplay), } diff --git a/src/stdlib/misc.ts b/src/stdlib/misc.ts index 327aa6194..3f0ff0f3f 100644 --- a/src/stdlib/misc.ts +++ b/src/stdlib/misc.ts @@ -10,7 +10,6 @@ import { stringify } from '../utils/stringify' * any information required for external use (optional). */ export function rawDisplay(value: Value, str: string, _externalContext: any) { - // tslint:disable-next-line:no-console console.log((str === undefined ? '' : str + ' ') + value.toString()) return value } @@ -22,7 +21,6 @@ export function error_message(value: Value, ...strs: string[]) { export function timed( context: Context, - // tslint:disable-next-line:ban-types f: Function, externalContext: any, displayBuiltin: (value: Value, str: string, externalContext: any) => Value diff --git a/src/stdlib/parser.ts b/src/stdlib/parser.ts index 4596e67ae..e43f2343d 100644 --- a/src/stdlib/parser.ts +++ b/src/stdlib/parser.ts @@ -4,9 +4,9 @@ import { parse as sourceParse } from '../parser/parser' import { SourceParser } from '../parser/source' import { libraryParserLanguage } from '../parser/source/syntax' import type { Context, ContiguousArrayElements, Node, NodeTypeToNode, Value } from '../types' -import { oneLine } from '../utils/formatters' import { getSourceVariableDeclaration } from '../utils/ast/helpers' import { isDeclaration } from '../utils/ast/typeGuards' +import { oneLine } from '../utils/formatters' import { vector_to_list, type List } from './list' class ParseError extends Error { @@ -17,7 +17,6 @@ class ParseError extends Error { } function unreachable() { - // tslint:disable-next-line:no-console console.error(oneLine` UNREACHABLE CODE REACHED! Please file an issue at diff --git a/src/tracer/README.md b/src/tracer/README.md index d9b75ba44..19e94b829 100644 --- a/src/tracer/README.md +++ b/src/tracer/README.md @@ -1,4 +1,4 @@ -# Stepper Documentation +# Stepper Documentation @@ -20,23 +20,29 @@ - ## Quickstart + First of all, make sure that you have already installed `js-slang` using `yarn`. There are many possible ways that you can work and test the code. One of my personal solution is using `yarn test`. During the development, you can edit the file from `../__test__/tracer_debug.ts` and run it with the following command: + ```bash yarn test -- tracer_debug.ts > testOutput.log ``` + Note that the flag `--silence=false` is set in order to see the output from `console.log`. In order to fully test the stepper, you can execute the following command. + ```bash yarn test -- tracer_full.ts ``` + ## High-level implementation details + Our stepper is a program that reduces a piece of code to its simplest form until it can no longer be reduced. While the idea sounds abstract, the step-by-step reduction of code allows us to add explanations, further aiding student learning when they want to scrutinize how the code is evaluated. The method is formally defined as beta reduction. ### Expression stepper -In order to implement the program with such functionalities, we have to first parse the program string into certain structure that we can approach to, so-called Abstract Syntax Tree (AST). For instance, string `2 * 3` can be converted to AST as `BinExp[* Lit[2] Lit[3]]`, where `BinExp` is a binary expression node consisting of two literals `2` and `3` combined with operator `*`. Note that our programming language consists of various node types, it's difficult to implement a parser from scratch to cover all cases. Luckily, the library `acorn` helps us generate the AST from a piece of string which is very convenient. -Here comes the fun part. How are we supposed to evaluate `BinExp[* Lit[2] Lit[3]]`? Since we cannot do anything further, we just simply **contract** them to `Lit[6]` and we are done. However, consider the AST `BinExp[* Lit[2] BinExp[+ Lit[3] Lit[4]]]` generated from `2 * (3 + 4)`, if we contract this expression directly, we will get `2 * {OBJECT}` which is not computable since one of the operands is not a number. Hence, we have to contract `BinExp[+ Lit[3] Lit[4]]]` first before contracting the outer `BinExp`. Note that our stepper only contracts one node for each step. This is our main constraint that we use during the implementation. +In order to implement the program with such functionalities, we have to first parse the program string into certain structure that we can approach to, so-called Abstract Syntax Tree (AST). For instance, string `2 * 3` can be converted to AST as `BinExp[* Lit[2] Lit[3]]`, where `BinExp` is a binary expression node consisting of two literals `2` and `3` combined with operator `*`. Note that our programming language consists of various node types, it's difficult to implement a parser from scratch to cover all cases. Luckily, the library `acorn` helps us generate the AST from a piece of string which is very convenient. + +Here comes the fun part. How are we supposed to evaluate `BinExp[* Lit[2] Lit[3]]`? Since we cannot do anything further, we just simply **contract** them to `Lit[6]` and we are done. However, consider the AST `BinExp[* Lit[2] BinExp[+ Lit[3] Lit[4]]]` generated from `2 * (3 + 4)`, if we contract this expression directly, we will get `2 * {OBJECT}` which is not computable since one of the operands is not a number. Hence, we have to contract `BinExp[+ Lit[3] Lit[4]]]` first before contracting the outer `BinExp`. Note that our stepper only contracts one node for each step. This is our main constraint that we use during the implementation. ![alt text](images/tracer-1.png) @@ -50,13 +56,17 @@ To implement this, we should have two methods `oneStep` and `contract` to perfor These methods can be applied for all types of AST nodes, such as expressions, statements, and program. The details about `StepperBaseNode` are discussed in [this](#augmenting-functionalities) section. ### Statements + Each program consists of one or more statements. Consider the simplest case where every statement is an expression statement. + ```ts 1 + 1; 2 + 3; 4 + 5; ``` -Initially, our stepper must reduce the first two statements while keeping the second statement. For each expression statement, the simplest form where the statement contains literal value is called _value statement_ (e.g. `2;`). + +Initially, our stepper must reduce the first two statements while keeping the second statement. For each expression statement, the simplest form where the statement contains literal value is called _value statement_ (e.g. `2;`). + ```ts 1 + 1; 2 + 3; 4 + 5; 2; 2 + 3; 4 + 5; @@ -65,7 +75,9 @@ Initially, our stepper must reduce the first two statements while keeping the se 5; 9; // Now, the first two statements are value statements 9; // second statement is kept ``` + Not all statements, however, are value-inducing. For instance, constant declaration statement `const x = 1;` and function declarations do not produce value. Here, we assume that non-value inducing statements will be reduced to `undefined;` (an expression statement containing literal value `undefinedNode`). The fix is really simple; we just ignore it during the search for the first two statements. + ```ts const x = 1; 1 + 1; const y = 3; 1 + 5; 1 + 1; const y = 3; 1 + 5; @@ -74,18 +86,22 @@ const x = 1; 1 + 1; const y = 3; 1 + 5; 2; 6; 6; // second value statement is kept. ``` + If there is no value inducing statement, we simply output `undefined';` + ```ts const x = 1; undefined; // after substituting x ``` -Note that the `oneStep` method determines which child nodes will be contracted. You can check the implementation of `oneStep` in `nodes/Program.ts` for more details. +Note that the `oneStep` method determines which child nodes will be contracted. You can check the implementation of `oneStep` in `nodes/Program.ts` for more details. ### Constant declaration + To be updated To make sure that the substituted variable has not been declared in the scope, we can simply check whether the variable name is in the list generated by `scanAllDeclarationNames()`. + ```ts scanAllDeclarationNames(): string[] { return this.body @@ -100,11 +116,17 @@ scanAllDeclarationNames(): string[] { }) } ``` -### Functions + +### Functions + To be updated + ### Alpha renaming + To be updated + ## Augmenting functionalities + Since our stepper takes AST (of any types) as an input and recursively navigate along the tree to find the next node to contract. There are many functionalities that we have to perform on each AST (such as contracting the AST as discussed in the previous section). Intuitively, we should add these functionalities as methods for each of the AST classes. Since the AST obtaining from the library is an `ESTree` interface, we have to implement our own concrete classes inherited from the ESTree AST Nodes. We also have to create our own convertor to convert the former ESTree into our own Stepper AST: ```typescript @@ -121,6 +143,7 @@ export interface StepperBaseNode { rename(before: string, after: string): StepperBaseNode } ``` + Conversion from `es.BaseNode` (AST interface from `ESTree`) to `StepperBaseNode` is handled by function `convert` in `generator.ts`. ```typescript @@ -140,6 +163,7 @@ export function convert(node: es.BaseNode): StepperBaseNode { ``` ### Entry point + The starting point of our stepper is at `steppers.ts` with the function `getSteps`. This function is responsible for triggering reduction until it cannot be proceed. The result from our evaluation is then stored in array `steps`. Here is the shorten version of `getSteps`. ```typescript @@ -174,13 +198,20 @@ redex.preRedex = [node] const ret = someSortOfReduction(node) redex.postRedex = [ret] ``` + ### Generating explanations -Explanations are generated based on `preRedex`. We use the same approach with the convert function. We have several dispatchers corresponding to each of the AST types. The implementation of `explainer` is in `generator.ts`. + +Explanations are generated based on `preRedex`. We use the same approach with the convert function. We have several dispatchers corresponding to each of the AST types. The implementation of `explainer` is in `generator.ts`. + ### Some important decisions + There are some design decisions that diverge from the original Source 1 and 2. Here are some changes we have made. + #### Builtin math functions + Calling math function with non number arguments is prohibited in stepper. + ```ts // Test Incorrect type of argument for math function math_sin(true); // error! -``` \ No newline at end of file +``` diff --git a/src/tracer/__tests__/tracer_debug.test.ts b/src/tracer/__tests__/tracer_debug.test.ts index 3e86ba2f1..e03503b20 100644 --- a/src/tracer/__tests__/tracer_debug.test.ts +++ b/src/tracer/__tests__/tracer_debug.test.ts @@ -1,12 +1,12 @@ -import { test } from 'vitest' import { parse } from 'acorn' import * as astring from 'astring' -import { getSteps } from '../steppers' -import { convert } from '../generator' -import type { Context } from '../../types' -import type { StepperBaseNode } from '../interface' +import { test } from 'vitest' import type { IStepperPropContents } from '..' import createContext from '../../createContext' +import type { Context } from '../../types' +import { convert } from '../generator' +import type { StepperBaseNode } from '../interface' +import { getSteps } from '../steppers' const stringify = (ast: StepperBaseNode) => { if (ast === undefined || ast.type === undefined) { diff --git a/src/tracer/__tests__/tracer_full.test.ts b/src/tracer/__tests__/tracer_full.test.ts index 8c8f383dc..0e5efb5e6 100644 --- a/src/tracer/__tests__/tracer_full.test.ts +++ b/src/tracer/__tests__/tracer_full.test.ts @@ -1,15 +1,15 @@ -import { describe, expect, test } from 'vitest' import * as acorn from 'acorn' import * as astring from 'astring' -import { getSteps } from '../steppers' +import { describe, expect, test } from 'vitest' +import createContext from '../../createContext' +import { mockContext } from '../../utils/testing/mocks' import { convert } from '../generator' import type { StepperBaseNode } from '../interface' +import { StepperArrowFunctionExpression } from '../nodes/Expression/ArrowFunctionExpression' import { StepperProgram } from '../nodes/Program' import { StepperExpressionStatement } from '../nodes/Statement/ExpressionStatement' -import { StepperArrowFunctionExpression } from '../nodes/Expression/ArrowFunctionExpression' import { StepperVariableDeclaration } from '../nodes/Statement/VariableDeclaration' -import createContext from '../../createContext' -import { mockContext } from '../../utils/testing/mocks' +import { getSteps } from '../steppers' function codify(node: StepperBaseNode) { const steps = getSteps(convert(node), createContext(2), { stepLimit: 1000 }) diff --git a/src/tracer/builtins/index.ts b/src/tracer/builtins/index.ts index d4c1c7f77..8bcd8f59d 100644 --- a/src/tracer/builtins/index.ts +++ b/src/tracer/builtins/index.ts @@ -1,11 +1,11 @@ import * as es from 'estree' +import { convert } from '../generator' import { StepperExpression } from '../nodes' import { StepperIdentifier } from '../nodes/Expression/Identifier' import { StepperLiteral } from '../nodes/Expression/Literal' -import { convert } from '../generator' +import { auxiliaryBuiltinFunctions } from './auxiliary' import { listBuiltinFunctions } from './lists' import { miscBuiltinFunctions } from './misc' -import { auxiliaryBuiltinFunctions } from './auxiliary' const builtinFunctions = { ...listBuiltinFunctions, diff --git a/src/tracer/builtins/lists.ts b/src/tracer/builtins/lists.ts index be4eecd1e..75f040f94 100644 --- a/src/tracer/builtins/lists.ts +++ b/src/tracer/builtins/lists.ts @@ -3,10 +3,10 @@ import type { ArrowFunctionExpression, ExpressionStatement } from 'estree' import type { StepperExpression } from '../nodes' import { StepperArrayExpression } from '../nodes/Expression/ArrayExpression' import { StepperArrowFunctionExpression } from '../nodes/Expression/ArrowFunctionExpression' +import { StepperBinaryExpression } from '../nodes/Expression/BinaryExpression' import { StepperFunctionApplication } from '../nodes/Expression/FunctionApplication' import { StepperIdentifier } from '../nodes/Expression/Identifier' import { StepperLiteral } from '../nodes/Expression/Literal' -import { StepperBinaryExpression } from '../nodes/Expression/BinaryExpression' export const listBuiltinFunctions = { pair: { diff --git a/src/tracer/generator.ts b/src/tracer/generator.ts index 917e1862d..81c6124c9 100644 --- a/src/tracer/generator.ts +++ b/src/tracer/generator.ts @@ -7,30 +7,30 @@ Every class should have the following properties - static create: factory method to parse estree to StepperAST */ -import type es from 'estree' import { generate } from 'astring' +import type es from 'estree' +import { isBuiltinFunction } from './builtins' +import { StepperBaseNode } from './interface' +import { StepperArrayExpression } from './nodes/Expression/ArrayExpression' +import { StepperArrowFunctionExpression } from './nodes/Expression/ArrowFunctionExpression' import { StepperBinaryExpression } from './nodes/Expression/BinaryExpression' -import { StepperUnaryExpression } from './nodes/Expression/UnaryExpression' +import { StepperBlockExpression } from './nodes/Expression/BlockExpression' +import { StepperConditionalExpression } from './nodes/Expression/ConditionalExpression' +import { StepperFunctionApplication } from './nodes/Expression/FunctionApplication' +import { StepperIdentifier } from './nodes/Expression/Identifier' import { StepperLiteral } from './nodes/Expression/Literal' -import { StepperBaseNode } from './interface' -import { StepperExpressionStatement } from './nodes/Statement/ExpressionStatement' +import { StepperLogicalExpression } from './nodes/Expression/LogicalExpression' +import { StepperUnaryExpression } from './nodes/Expression/UnaryExpression' import { StepperProgram } from './nodes/Program' +import { StepperBlockStatement } from './nodes/Statement/BlockStatement' +import { StepperExpressionStatement } from './nodes/Statement/ExpressionStatement' +import { StepperFunctionDeclaration } from './nodes/Statement/FunctionDeclaration' +import { StepperIfStatement } from './nodes/Statement/IfStatement' +import { StepperReturnStatement } from './nodes/Statement/ReturnStatement' import { StepperVariableDeclaration, StepperVariableDeclarator } from './nodes/Statement/VariableDeclaration' -import { StepperIdentifier } from './nodes/Expression/Identifier' -import { StepperBlockStatement } from './nodes/Statement/BlockStatement' -import { StepperIfStatement } from './nodes/Statement/IfStatement' -import { StepperConditionalExpression } from './nodes/Expression/ConditionalExpression' -import { StepperArrowFunctionExpression } from './nodes/Expression/ArrowFunctionExpression' -import { StepperFunctionApplication } from './nodes/Expression/FunctionApplication' -import { StepperReturnStatement } from './nodes/Statement/ReturnStatement' -import { StepperFunctionDeclaration } from './nodes/Statement/FunctionDeclaration' -import { StepperArrayExpression } from './nodes/Expression/ArrayExpression' -import { StepperLogicalExpression } from './nodes/Expression/LogicalExpression' -import { StepperBlockExpression } from './nodes/Expression/BlockExpression' -import { isBuiltinFunction } from './builtins' const undefinedNode = new StepperLiteral('undefined') diff --git a/src/tracer/nodes/Expression/ArrayExpression.ts b/src/tracer/nodes/Expression/ArrayExpression.ts index 490130d20..a60d60587 100644 --- a/src/tracer/nodes/Expression/ArrayExpression.ts +++ b/src/tracer/nodes/Expression/ArrayExpression.ts @@ -1,8 +1,8 @@ import type { ArrayExpression, Comment, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { redex } from '../..' import type { StepperExpression, StepperPattern } from '..' +import { redex } from '../..' import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' export class StepperArrayExpression implements ArrayExpression, StepperBaseNode { type: 'ArrayExpression' diff --git a/src/tracer/nodes/Expression/ArrowFunctionExpression.ts b/src/tracer/nodes/Expression/ArrowFunctionExpression.ts index 4a40c2264..7f80e311a 100644 --- a/src/tracer/nodes/Expression/ArrowFunctionExpression.ts +++ b/src/tracer/nodes/Expression/ArrowFunctionExpression.ts @@ -1,7 +1,7 @@ import type { ArrowFunctionExpression, Comment, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' import type { StepperExpression, StepperPattern } from '..' import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { getFreshName } from '../../utils' import { StepperBlockStatement } from '../Statement/BlockStatement' diff --git a/src/tracer/nodes/Expression/BinaryExpression.ts b/src/tracer/nodes/Expression/BinaryExpression.ts index 54944ac12..6060f8067 100644 --- a/src/tracer/nodes/Expression/BinaryExpression.ts +++ b/src/tracer/nodes/Expression/BinaryExpression.ts @@ -1,8 +1,8 @@ import type { BinaryExpression, BinaryOperator, Comment, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { redex } from '../..' import type { StepperExpression, StepperPattern } from '..' +import { redex } from '../..' import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { StepperLiteral } from './Literal' export class StepperBinaryExpression implements BinaryExpression, StepperBaseNode { diff --git a/src/tracer/nodes/Expression/BlockExpression.ts b/src/tracer/nodes/Expression/BlockExpression.ts index 92ac6bc37..6f1aff5a1 100644 --- a/src/tracer/nodes/Expression/BlockExpression.ts +++ b/src/tracer/nodes/Expression/BlockExpression.ts @@ -1,12 +1,12 @@ import type { BlockStatement, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' import { type StepperExpression, type StepperPattern, undefinedNode } from '..' -import { convert } from '../../generator' import { redex } from '../..' -import { StepperVariableDeclaration } from '../Statement/VariableDeclaration' +import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { assignMuTerms, getFreshName } from '../../utils' import type { StepperStatement } from '../Statement' import { StepperFunctionDeclaration } from '../Statement/FunctionDeclaration' +import { StepperVariableDeclaration } from '../Statement/VariableDeclaration' // TODO: add docs, because this is a block expression, not a block statement, and this does not follow official estree spec export class StepperBlockExpression implements StepperBaseNode { diff --git a/src/tracer/nodes/Expression/ConditionalExpression.ts b/src/tracer/nodes/Expression/ConditionalExpression.ts index af4d40207..4b074ffe3 100644 --- a/src/tracer/nodes/Expression/ConditionalExpression.ts +++ b/src/tracer/nodes/Expression/ConditionalExpression.ts @@ -1,8 +1,8 @@ -import type { ConditionalExpression, Comment, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { redex } from '../..' +import type { Comment, ConditionalExpression, SourceLocation } from 'estree' import type { StepperExpression, StepperPattern } from '..' +import { redex } from '../..' import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' export class StepperConditionalExpression implements ConditionalExpression, StepperBaseNode { type: 'ConditionalExpression' diff --git a/src/tracer/nodes/Expression/FunctionApplication.ts b/src/tracer/nodes/Expression/FunctionApplication.ts index 12d4ce289..957be4a64 100644 --- a/src/tracer/nodes/Expression/FunctionApplication.ts +++ b/src/tracer/nodes/Expression/FunctionApplication.ts @@ -1,11 +1,11 @@ -import type { SimpleCallExpression, Comment, SourceLocation } from 'estree' import * as astring from 'astring' -import type { StepperBaseNode } from '../../interface' -import { redex } from '../..' +import type { Comment, SimpleCallExpression, SourceLocation } from 'estree' import type { StepperExpression, StepperPattern } from '..' +import { redex } from '../..' +import { getBuiltinFunction, isBuiltinFunction } from '../../builtins' import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { StepperBlockStatement } from '../Statement/BlockStatement' -import { getBuiltinFunction, isBuiltinFunction } from '../../builtins' import { StepperBlockExpression } from './BlockExpression' export class StepperFunctionApplication implements SimpleCallExpression, StepperBaseNode { diff --git a/src/tracer/nodes/Expression/Identifier.ts b/src/tracer/nodes/Expression/Identifier.ts index 6819e8932..94d79631e 100644 --- a/src/tracer/nodes/Expression/Identifier.ts +++ b/src/tracer/nodes/Expression/Identifier.ts @@ -1,8 +1,8 @@ -import type { Identifier, Comment, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' +import type { Comment, Identifier, SourceLocation } from 'estree' import type { StepperExpression, StepperPattern } from '..' import { redex } from '../..' import { isBuiltinFunction } from '../../builtins' +import type { StepperBaseNode } from '../../interface' export class StepperIdentifier implements Identifier, StepperBaseNode { type: 'Identifier' diff --git a/src/tracer/nodes/Expression/Literal.ts b/src/tracer/nodes/Expression/Literal.ts index 4c2126154..6678447e8 100644 --- a/src/tracer/nodes/Expression/Literal.ts +++ b/src/tracer/nodes/Expression/Literal.ts @@ -1,6 +1,6 @@ import type { Comment, SimpleLiteral, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' import type { StepperExpression, StepperPattern } from '..' +import type { StepperBaseNode } from '../../interface' /** * This class represents a literal node in the stepper's AST (Abstract Syntax Tree). diff --git a/src/tracer/nodes/Expression/LogicalExpression.ts b/src/tracer/nodes/Expression/LogicalExpression.ts index 6e258c531..324906623 100644 --- a/src/tracer/nodes/Expression/LogicalExpression.ts +++ b/src/tracer/nodes/Expression/LogicalExpression.ts @@ -1,8 +1,8 @@ -import type { LogicalExpression, LogicalOperator, Comment, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { redex } from '../..' +import type { Comment, LogicalExpression, LogicalOperator, SourceLocation } from 'estree' import type { StepperExpression, StepperPattern } from '..' +import { redex } from '../..' import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { StepperLiteral } from './Literal' export class StepperLogicalExpression implements LogicalExpression, StepperBaseNode { diff --git a/src/tracer/nodes/Expression/UnaryExpression.ts b/src/tracer/nodes/Expression/UnaryExpression.ts index c0a468884..5e4f3d97c 100644 --- a/src/tracer/nodes/Expression/UnaryExpression.ts +++ b/src/tracer/nodes/Expression/UnaryExpression.ts @@ -1,8 +1,8 @@ import type { Comment, Literal, SourceLocation, UnaryExpression, UnaryOperator } from 'estree' -import type { StepperBaseNode } from '../../interface' +import type { StepperExpression, StepperPattern } from '..' import { redex } from '../..' import { convert } from '../../generator' -import type { StepperExpression, StepperPattern } from '..' +import type { StepperBaseNode } from '../../interface' import { StepperLiteral } from './Literal' export class StepperUnaryExpression implements UnaryExpression, StepperBaseNode { diff --git a/src/tracer/nodes/Program.ts b/src/tracer/nodes/Program.ts index b16fb9f1f..3fd576fa0 100644 --- a/src/tracer/nodes/Program.ts +++ b/src/tracer/nodes/Program.ts @@ -1,12 +1,12 @@ import type { Comment, Program, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../interface' import { convert } from '../generator' +import type { StepperBaseNode } from '../interface' import { redex } from '..' import { assignMuTerms } from '../utils' -import type { StepperVariableDeclaration } from './Statement/VariableDeclaration' import { StepperStatement } from './Statement' import type { StepperFunctionDeclaration } from './Statement/FunctionDeclaration' +import type { StepperVariableDeclaration } from './Statement/VariableDeclaration' import { type StepperExpression, type StepperPattern, undefinedNode } from '.' export class StepperProgram implements Program, StepperBaseNode { diff --git a/src/tracer/nodes/Statement/BlockStatement.ts b/src/tracer/nodes/Statement/BlockStatement.ts index a33a147b9..cae596aea 100644 --- a/src/tracer/nodes/Statement/BlockStatement.ts +++ b/src/tracer/nodes/Statement/BlockStatement.ts @@ -1,11 +1,11 @@ import type { BlockStatement, Comment, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' import { type StepperExpression, type StepperPattern, undefinedNode } from '..' -import { convert } from '../../generator' import { redex } from '../..' +import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { assignMuTerms, getFreshName } from '../../utils' -import { StepperVariableDeclaration } from './VariableDeclaration' import { StepperFunctionDeclaration } from './FunctionDeclaration' +import { StepperVariableDeclaration } from './VariableDeclaration' import { StepperStatement } from '.' export class StepperBlockStatement implements BlockStatement, StepperBaseNode { diff --git a/src/tracer/nodes/Statement/ExpressionStatement.ts b/src/tracer/nodes/Statement/ExpressionStatement.ts index 39ed7fb09..becaa5132 100644 --- a/src/tracer/nodes/Statement/ExpressionStatement.ts +++ b/src/tracer/nodes/Statement/ExpressionStatement.ts @@ -1,8 +1,8 @@ -import type { Comment, SourceLocation, ExpressionStatement } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { convert } from '../../generator' +import type { Comment, ExpressionStatement, SourceLocation } from 'estree' import type { StepperExpression, StepperPattern } from '..' import { redex } from '../..' +import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' export class StepperExpressionStatement implements ExpressionStatement, StepperBaseNode { type: 'ExpressionStatement' diff --git a/src/tracer/nodes/Statement/FunctionDeclaration.ts b/src/tracer/nodes/Statement/FunctionDeclaration.ts index f22e32d6a..994a3fb91 100644 --- a/src/tracer/nodes/Statement/FunctionDeclaration.ts +++ b/src/tracer/nodes/Statement/FunctionDeclaration.ts @@ -1,11 +1,11 @@ import type { Comment, FunctionDeclaration, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { StepperIdentifier } from '../Expression/Identifier' import { type StepperExpression, type StepperPattern, undefinedNode } from '..' -import { convert } from '../../generator' import { redex } from '../..' -import { StepperArrowFunctionExpression } from '../Expression/ArrowFunctionExpression' +import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { getFreshName } from '../../utils' +import { StepperArrowFunctionExpression } from '../Expression/ArrowFunctionExpression' +import { StepperIdentifier } from '../Expression/Identifier' import { StepperBlockStatement } from './BlockStatement' import { StepperVariableDeclaration } from './VariableDeclaration' diff --git a/src/tracer/nodes/Statement/IfStatement.ts b/src/tracer/nodes/Statement/IfStatement.ts index c751104b5..02324d87e 100644 --- a/src/tracer/nodes/Statement/IfStatement.ts +++ b/src/tracer/nodes/Statement/IfStatement.ts @@ -1,8 +1,8 @@ import type { Comment, IfStatement, SourceLocation } from 'estree' -import type { StepperBaseNode } from '../../interface' import { type StepperExpression, type StepperPattern, undefinedNode } from '..' -import { convert } from '../../generator' import { redex } from '../..' +import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' import { StepperLiteral } from '../Expression/Literal' import { StepperBlockStatement } from './BlockStatement' import { StepperExpressionStatement } from './ExpressionStatement' diff --git a/src/tracer/nodes/Statement/ReturnStatement.ts b/src/tracer/nodes/Statement/ReturnStatement.ts index a6dcd1ed9..0d43ce5ac 100644 --- a/src/tracer/nodes/Statement/ReturnStatement.ts +++ b/src/tracer/nodes/Statement/ReturnStatement.ts @@ -1,8 +1,8 @@ -import type { Comment, SourceLocation, ReturnStatement } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { convert } from '../../generator' +import type { Comment, ReturnStatement, SourceLocation } from 'estree' import type { StepperExpression, StepperPattern } from '..' import { redex } from '../..' +import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' export class StepperReturnStatement implements ReturnStatement, StepperBaseNode { type: 'ReturnStatement' diff --git a/src/tracer/nodes/Statement/VariableDeclaration.ts b/src/tracer/nodes/Statement/VariableDeclaration.ts index c8cc4e0e6..7ee366475 100644 --- a/src/tracer/nodes/Statement/VariableDeclaration.ts +++ b/src/tracer/nodes/Statement/VariableDeclaration.ts @@ -1,8 +1,8 @@ import type { Comment, SourceLocation, VariableDeclaration, VariableDeclarator } from 'estree' -import type { StepperBaseNode } from '../../interface' -import { convert } from '../../generator' import { type StepperExpression, type StepperPattern, undefinedNode } from '..' import { redex } from '../..' +import { convert } from '../../generator' +import type { StepperBaseNode } from '../../interface' export class StepperVariableDeclarator implements VariableDeclarator, StepperBaseNode { type: 'VariableDeclarator' diff --git a/src/tracer/steppers.ts b/src/tracer/steppers.ts index 53ef8f1bf..02b13b662 100644 --- a/src/tracer/steppers.ts +++ b/src/tracer/steppers.ts @@ -1,13 +1,13 @@ import type es from 'estree' import type { Context, IOptions } from '..' -import { checkProgramForUndefinedVariables } from '../validator/validator' import { UndefinedVariable } from '../errors/errors' -import type { StepperBaseNode } from './interface' +import { checkProgramForUndefinedVariables } from '../validator/validator' +import { prelude } from './builtins' import { explain } from './generator' -import type { StepperProgram } from './nodes/Program' +import type { StepperBaseNode } from './interface' import { undefinedNode } from './nodes' +import type { StepperProgram } from './nodes/Program' import { StepperExpressionStatement } from './nodes/Statement/ExpressionStatement' -import { prelude } from './builtins' import { type IStepperPropContents, type Marker, redex } from '.' export function getSteps( diff --git a/src/transpiler/__tests__/native.test.ts b/src/transpiler/__tests__/native.test.ts index 13f01149f..d11d1be78 100644 --- a/src/transpiler/__tests__/native.test.ts +++ b/src/transpiler/__tests__/native.test.ts @@ -1,10 +1,10 @@ import { expect, test } from 'vitest' import { runInContext } from '../../index' -import { mockContext } from '../../utils/testing/mocks' import { Chapter } from '../../langs' import { stripIndent } from '../../utils/formatters' import { expectNativeToTimeoutAndError } from '../../utils/testing' import { assertFinishedResultValue } from '../../utils/testing/misc' +import { mockContext } from '../../utils/testing/mocks' test('Proper stringify-ing of arguments during potentially infinite iterative function calls', async () => { const code = stripIndent` diff --git a/src/transpiler/__tests__/transpiled-code.test.ts b/src/transpiler/__tests__/transpiled-code.test.ts index 86526dfb7..19aef1c06 100644 --- a/src/transpiler/__tests__/transpiled-code.test.ts +++ b/src/transpiler/__tests__/transpiled-code.test.ts @@ -1,10 +1,10 @@ import { describe, expect, test } from 'vitest' -import { mockContext } from '../../utils/testing/mocks' -import { parse } from '../../parser/parser' import { Chapter } from '../../langs' +import { parse } from '../../parser/parser' import * as ast from '../../utils/ast/astCreator' -import { sanitizeAST } from '../../utils/testing/sanitizer' import { stripIndent } from '../../utils/formatters' +import { mockContext } from '../../utils/testing/mocks' +import { sanitizeAST } from '../../utils/testing/sanitizer' import { transformImportDeclarations, transpile } from '../transpiler' /* DO NOT HAVE 'native[]' AS A SUBSTRING IN CODE STRINGS ANYWHERE IN THIS FILE! diff --git a/src/transpiler/transpiler.ts b/src/transpiler/transpiler.ts index 34a2dbe1f..f85b41b5c 100644 --- a/src/transpiler/transpiler.ts +++ b/src/transpiler/transpiler.ts @@ -3,8 +3,8 @@ import type es from 'estree' import { type RawSourceMap, SourceMapGenerator } from 'source-map' import { NATIVE_STORAGE_ID, UNKNOWN_LOCATION } from '../constants' -import type { Context, NativeStorage, Node } from '../types' import { Chapter, Variant } from '../langs' +import type { Context, NativeStorage, Node } from '../types' import * as create from '../utils/ast/astCreator' import { filterImportDeclarations, @@ -12,6 +12,7 @@ import { getSourceVariableDeclaration } from '../utils/ast/helpers' import { isNamespaceSpecifier, isVariableDeclaration } from '../utils/ast/typeGuards' +import { simple } from '../utils/ast/walkers' import { getFunctionDeclarationNamesInProgram, getIdentifiersInNativeStorage, @@ -20,7 +21,6 @@ import { getUniqueId, type NativeIds } from '../utils/uniqueIds' -import { simple } from '../utils/ast/walkers' import { checkForUndefinedVariables } from '../validator/validator' /** diff --git a/src/typeChecker/__tests__/source1Typed.test.ts b/src/typeChecker/__tests__/source1Typed.test.ts index 17ce53337..965a1fd62 100644 --- a/src/typeChecker/__tests__/source1Typed.test.ts +++ b/src/typeChecker/__tests__/source1Typed.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, it } from 'vitest' import { parseError } from '../..' -import { mockContext } from '../../utils/testing/mocks' -import { parse } from '../../parser/parser' import { Chapter, Variant } from '../../langs' +import { parse } from '../../parser/parser' +import { mockContext } from '../../utils/testing/mocks' let context = mockContext(Chapter.SOURCE_1, Variant.TYPED) diff --git a/src/typeChecker/__tests__/source2Typed.test.ts b/src/typeChecker/__tests__/source2Typed.test.ts index 9e1deaf75..28c4a70b6 100644 --- a/src/typeChecker/__tests__/source2Typed.test.ts +++ b/src/typeChecker/__tests__/source2Typed.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, it } from 'vitest' import { parseError } from '../..' -import { mockContext } from '../../utils/testing/mocks' -import { parse } from '../../parser/parser' import { Chapter, Variant } from '../../langs' +import { parse } from '../../parser/parser' +import { mockContext } from '../../utils/testing/mocks' let context = mockContext(Chapter.SOURCE_2, Variant.TYPED) diff --git a/src/typeChecker/__tests__/source3Typed.test.ts b/src/typeChecker/__tests__/source3Typed.test.ts index afd319988..234fed438 100644 --- a/src/typeChecker/__tests__/source3Typed.test.ts +++ b/src/typeChecker/__tests__/source3Typed.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, it } from 'vitest' import { parseError } from '../..' -import { mockContext } from '../../utils/testing/mocks' -import { parse } from '../../parser/parser' import { Chapter, Variant } from '../../langs' +import { parse } from '../../parser/parser' +import { mockContext } from '../../utils/testing/mocks' let context = mockContext(Chapter.SOURCE_3, Variant.TYPED) diff --git a/src/typeChecker/__tests__/source4Typed.test.ts b/src/typeChecker/__tests__/source4Typed.test.ts index fa91c6d75..b677af865 100644 --- a/src/typeChecker/__tests__/source4Typed.test.ts +++ b/src/typeChecker/__tests__/source4Typed.test.ts @@ -1,8 +1,8 @@ import { beforeEach, describe, expect, it } from 'vitest' import { parseError } from '../..' -import { mockContext } from '../../utils/testing/mocks' -import { parse } from '../../parser/parser' import { Chapter, Variant } from '../../langs' +import { parse } from '../../parser/parser' +import { mockContext } from '../../utils/testing/mocks' let context = mockContext(Chapter.SOURCE_4, Variant.TYPED) diff --git a/src/typeChecker/__tests__/source4TypedModules.test.ts b/src/typeChecker/__tests__/source4TypedModules.test.ts index 7724ed9f2..39c319167 100644 --- a/src/typeChecker/__tests__/source4TypedModules.test.ts +++ b/src/typeChecker/__tests__/source4TypedModules.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest' import { parseError } from '../../index' -import { parse } from '../../parser/parser' import { Chapter, Variant } from '../../langs' +import { parse } from '../../parser/parser' import { mockContext } from '../../utils/testing/mocks' function getContext() { diff --git a/src/typeChecker/internalTypeErrors.ts b/src/typeChecker/internalTypeErrors.ts index 116b222d8..0608665ba 100644 --- a/src/typeChecker/internalTypeErrors.ts +++ b/src/typeChecker/internalTypeErrors.ts @@ -4,7 +4,6 @@ import type { Node, NodeWithInferredType, Type } from '../types' import { typeToString } from '../utils/stringify' import type * as tsEs from './tsESTree' -// tslint:disable:max-classes-per-file export class TypeError implements SourceError { public type = ErrorType.TYPE public severity = ErrorSeverity.WARNING diff --git a/src/typeChecker/typeErrorChecker.ts b/src/typeChecker/typeErrorChecker.ts index 02ea66712..3e346b8f7 100644 --- a/src/typeChecker/typeErrorChecker.ts +++ b/src/typeChecker/typeErrorChecker.ts @@ -20,6 +20,7 @@ import { TypeParameterNameNotAllowedError, UndefinedVariableTypeError } from '../errors/typeErrors' +import { Chapter } from '../langs' import { type BindableType, type Context, @@ -34,7 +35,6 @@ import { type TypeEnvironment, type Variable } from '../types' -import { Chapter } from '../langs' import { TypecheckError } from './internalTypeErrors' import { parseTreeTypesPrelude } from './parseTreeTypes.prelude' import type * as tsEs from './tsESTree' diff --git a/src/typeChecker/utils.ts b/src/typeChecker/utils.ts index 27e0acb3a..818eacc26 100644 --- a/src/typeChecker/utils.ts +++ b/src/typeChecker/utils.ts @@ -2,6 +2,7 @@ // Helper functions/constants for type checker and type error checker // ======================================= +import { Chapter } from '../langs' import type { AllowedDeclarations, BindableType, @@ -19,7 +20,6 @@ import type { UnionType, Variable } from '../types' -import { Chapter } from '../langs' import * as tsEs from './tsESTree' // Name of Unary negative builtin operator diff --git a/src/types.ts b/src/types.ts index 3f3415323..056fb92e0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,16 +2,14 @@ This file contains definitions of some interfaces and classes that are used in Source (such as error-related classes). */ - import type es from 'estree' - +import type { Representation } from './alt-langs/mapper' import type { EnvTree } from './createContext' import type Heap from './cse-machine/heap' import type { Control, Stash, Transformers } from './cse-machine/interpreter' -import type { ModuleFunctions } from './modules/moduleTypes' -import type { Representation } from './alt-langs/mapper' -import type { Chapter, LanguageOptions, Variant } from './langs' import type { SourceError } from './errors/base' +import type { Chapter, LanguageOptions, Variant } from './langs' +import type { ModuleFunctions } from './modules/moduleTypes' /** * Defines functions that act as built-ins, but might rely on @@ -156,12 +154,10 @@ export interface DefinitionNode { loc?: es.SourceLocation | null } -// tslint:disable:no-any export interface Frame { [name: string]: any } export type Value = any -// tslint:enable:no-any export type AllowedDeclarations = 'const' | 'let' @@ -242,12 +238,12 @@ export interface Directive extends es.ExpressionStatement { } export type { - Instruction as SVMInstruction, - Program as SVMProgram, Address as SVMAddress, Argument as SVMArgument, + SVMFunction, + Instruction as SVMInstruction, Offset as SVMOffset, - SVMFunction + Program as SVMProgram } from './vm/svml-compiler' export type ContiguousArrayElementExpression = Exclude diff --git a/src/utils/__tests__/rttc.test.ts b/src/utils/__tests__/rttc.test.ts index 15d728d62..935de15b2 100644 --- a/src/utils/__tests__/rttc.test.ts +++ b/src/utils/__tests__/rttc.test.ts @@ -1,10 +1,10 @@ -import { describe, expect, test } from 'vitest' import type { BinaryOperator, UnaryOperator } from 'estree' +import { describe, expect, test } from 'vitest' -import { mockClosure, mockRuntimeContext } from '../testing/mocks' -import type { Value } from '../../types' import { Chapter } from '../../langs' +import type { Value } from '../../types' import * as rttc from '../rttc' +import { mockClosure, mockRuntimeContext } from '../testing/mocks' const num = 0 const bool = true diff --git a/src/utils/ast/helpers.ts b/src/utils/ast/helpers.ts index b4ffc8636..fd0704a5a 100644 --- a/src/utils/ast/helpers.ts +++ b/src/utils/ast/helpers.ts @@ -2,13 +2,13 @@ import type es from 'estree' import assert from '../assert' import { ArrayMap } from '../dict' -import { simple } from './walkers' import { isDeclaration, isIdentifier, isImportDeclaration, isVariableDeclaration } from './typeGuards' +import { simple } from './walkers' export function getModuleDeclarationSource( node: Exclude diff --git a/src/utils/makeWrapper.ts b/src/utils/makeWrapper.ts index aca6e5d09..b62bc5d06 100644 --- a/src/utils/makeWrapper.ts +++ b/src/utils/makeWrapper.ts @@ -1,4 +1,3 @@ -// tslint:disable-next-line:ban-types export function makeWrapper(originalFunc: Function, wrappedFunc: Function) { for (const prop in originalFunc) { if (originalFunc.hasOwnProperty(prop)) { diff --git a/src/utils/rttc.ts b/src/utils/rttc.ts index 89d15c67b..9bd7f94fd 100644 --- a/src/utils/rttc.ts +++ b/src/utils/rttc.ts @@ -1,9 +1,8 @@ import type es from 'estree' - +import { ErrorSeverity, ErrorType } from '../errors/base' import { RuntimeSourceError } from '../errors/runtimeSourceError' -import type { Node, Value } from '../types' import { Chapter } from '../langs' -import { ErrorSeverity, ErrorType } from '../errors/base' +import type { Node, Value } from '../types' const LHS = ' on left hand side of operation' const RHS = ' on right hand side of operation' @@ -48,7 +47,6 @@ const typeOf = (v: Value) => { const isNumber = (v: Value) => typeOf(v) === 'number' // See section 4 of https://2ality.com/2012/12/arrays.html // v >>> 0 === v checks that v is a valid unsigned 32-bit int -// tslint:disable-next-line:no-bitwise const isArrayIndex = (v: Value) => isNumber(v) && v >>> 0 === v && v < 2 ** 32 - 1 const isString = (v: Value) => typeOf(v) === 'string' const isBool = (v: Value) => typeOf(v) === 'boolean' diff --git a/src/utils/testing/__tests__/testing.test.ts b/src/utils/testing/__tests__/testing.test.ts index 6620483ff..755e81c0e 100644 --- a/src/utils/testing/__tests__/testing.test.ts +++ b/src/utils/testing/__tests__/testing.test.ts @@ -6,10 +6,10 @@ import { testFailure, testSuccess } from '..' +import * as main from '../../..' import { Chapter, Variant } from '../../../langs' import { processTestOptions } from '../misc' import type { TestOptions } from '../types' -import * as main from '../../..' const mockedRunInContext = vi.spyOn(main, 'runInContext') diff --git a/src/utils/testing/index.ts b/src/utils/testing/index.ts index 8b2399033..d2ac90f47 100644 --- a/src/utils/testing/index.ts +++ b/src/utils/testing/index.ts @@ -1,8 +1,8 @@ import { expect } from 'vitest' -import type { CustomBuiltIns } from '../../types' -import { Chapter } from '../../langs' import { parseError, runInContext } from '../..' import createContext, { defineBuiltin } from '../../createContext' +import { Chapter } from '../../langs' +import type { CustomBuiltIns } from '../../types' import { assertIsFinished, processTestOptions } from './misc' import { mockContext } from './mocks' import type { TestContext, TestOptions, TestResults } from './types' diff --git a/src/utils/testing/misc.ts b/src/utils/testing/misc.ts index 97386b3ab..28ccfbc02 100644 --- a/src/utils/testing/misc.ts +++ b/src/utils/testing/misc.ts @@ -1,7 +1,7 @@ import { describe, expect, test, type TestContext as VitestTestContext } from 'vitest' import type { Result } from '../..' -import type { Finished, Value, Node, NodeTypeToNode } from '../../types' import { Chapter } from '../../langs' +import type { Finished, Node, NodeTypeToNode, Value } from '../../types' import { getChapterName } from '../misc' import type { TestBuiltins, TestOptions } from './types' @@ -166,6 +166,5 @@ export function evalWithBuiltins(code: string, testBuiltins: TestBuiltins = {}) const builtins = Object.keys(testBuiltins).map(key => `const ${key} = testBuiltins.${key};`) const evalstring = builtins.join('\n') + code - // tslint:disable-next-line:no-eval return eval(evalstring + code) } diff --git a/src/utils/testing/mocks.ts b/src/utils/testing/mocks.ts index baf488ad0..4b061aa97 100644 --- a/src/utils/testing/mocks.ts +++ b/src/utils/testing/mocks.ts @@ -2,9 +2,9 @@ import type es from 'estree' import createContext, { EnvTree } from '../../createContext' import Closure from '../../cse-machine/closure' -import { Chapter, type LanguageOptions, Variant } from '../../langs' import { Transformers } from '../../cse-machine/interpreter' import { createBlockEnvironment } from '../../cse-machine/utils' +import { Chapter, type LanguageOptions, Variant } from '../../langs' import type { Context, Environment } from '../../types' export function mockContext( diff --git a/src/validator/__tests__/validator.test.ts b/src/validator/__tests__/validator.test.ts index a65d76c25..f7c917eba 100644 --- a/src/validator/__tests__/validator.test.ts +++ b/src/validator/__tests__/validator.test.ts @@ -1,15 +1,15 @@ -import { expect, test } from 'vitest' import type es from 'estree' +import { expect, test } from 'vitest' -import { mockContext } from '../../utils/testing/mocks' +import { Chapter } from '../../langs' import { parse } from '../../parser/parser' import type { NodeWithInferredType } from '../../types' -import { Chapter } from '../../langs' +import { getSourceVariableDeclaration } from '../../utils/ast/helpers' +import { simple } from '../../utils/ast/walkers' import { stripIndent } from '../../utils/formatters' import { expectParsedError } from '../../utils/testing' -import { simple } from '../../utils/ast/walkers' +import { mockContext } from '../../utils/testing/mocks' import { validateAndAnnotate } from '../validator' -import { getSourceVariableDeclaration } from '../../utils/ast/helpers' function toValidatedAst(code: string) { const context = mockContext(Chapter.SOURCE_1) diff --git a/src/validator/validator.ts b/src/validator/validator.ts index 80690aed0..3613ee28a 100644 --- a/src/validator/validator.ts +++ b/src/validator/validator.ts @@ -4,6 +4,8 @@ import { ConstAssignment, UndefinedVariable } from '../errors/errors' import { NoAssignmentToForVariable } from '../errors/validityErrors' import { parse } from '../parser/parser' import type { Context, Node, NodeWithInferredType } from '../types' +import { getSourceVariableDeclaration } from '../utils/ast/helpers' +import { ancestor, base, type FullWalkerCallback } from '../utils/ast/walkers' import { getFunctionDeclarationNamesInProgram, getIdentifiersInNativeStorage, @@ -11,8 +13,6 @@ import { getNativeIds, type NativeIds } from '../utils/uniqueIds' -import { ancestor, base, type FullWalkerCallback } from '../utils/ast/walkers' -import { getSourceVariableDeclaration } from '../utils/ast/helpers' class Declaration { public accessedBeforeDeclaration: boolean = false diff --git a/src/vm/svml-compiler.ts b/src/vm/svml-compiler.ts index e3df1df1b..1fbcbcfe1 100644 --- a/src/vm/svml-compiler.ts +++ b/src/vm/svml-compiler.ts @@ -12,8 +12,8 @@ import { } from '../stdlib/vm.prelude' import type { Context, ContiguousArrayElements, Node, NodeTypeToNode } from '../types' import * as create from '../utils/ast/astCreator' -import { recursive, simple } from '../utils/ast/walkers' import { getSourceVariableDeclaration } from '../utils/ast/helpers' +import { recursive, simple } from '../utils/ast/walkers' import OpCodes from './opcodes' const VALID_UNARY_OPERATORS: { [op in UnaryExpression['operator']]?: OpCodes } = {