From d54c5e80e7d6477c802dcdfcc08f632df0f0c588 Mon Sep 17 00:00:00 2001 From: Sheyne Anderson Date: Sun, 26 Feb 2017 00:37:14 -0700 Subject: [PATCH] Enable tslint --- .travis.yml | 4 +- interpreters/dfa/dfa.ts | 18 +-- interpreters/nfa/nfa.ts | 16 +-- package.json | 8 +- sinap-includes/plugin-stub.ts | 4 +- src/element.ts | 16 +-- src/files.ts | 4 +- src/plugin-loader.ts | 20 +-- src/plugin.ts | 8 +- src/program.ts | 2 +- src/types.ts | 10 +- test/definitions.ts | 22 +-- test/dfa-definitions.ts | 8 +- test/files-mock.ts | 8 +- .../ideal-dfa-interpreter-v2/plugin.ts | 12 +- test/interpreters/serial/first/definitions.ts | 22 +-- .../serial/second/definitions-for-serial.ts | 16 +-- .../stub/stub-test-definitions.ts | 6 +- test/interpreters/validation/definitions.ts | 36 +++++ test/interpreters/validation/package.json | 15 ++ test/test-ideal-dfa-interpreter-v2.ts | 24 ++-- test/test-ideal-dfa-interpreter.ts | 4 +- test/test-interpreters.ts | 128 +++++++++--------- test/test-plugin.ts | 26 ++-- test/test-serialization.ts | 12 +- test/test-stub.ts | 8 +- test/test-validation.ts | 5 +- 27 files changed, 259 insertions(+), 203 deletions(-) create mode 100644 test/interpreters/validation/definitions.ts create mode 100644 test/interpreters/validation/package.json diff --git a/.travis.yml b/.travis.yml index 38bf27e..9aa3574 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,9 @@ before_script: - npm prune script: - npm run typings -- npm run format -- npm test +- npm run lint - git diff --exit-code HEAD +- npm test after_success: - npm run semantic-release branches: diff --git a/interpreters/dfa/dfa.ts b/interpreters/dfa/dfa.ts index 27846f8..0ec6cf9 100644 --- a/interpreters/dfa/dfa.ts +++ b/interpreters/dfa/dfa.ts @@ -17,9 +17,9 @@ export class DFAGraph { // startState: DFANode; } -export type Nodes = DFANode -export type Edges = DFAEdge -export type Graph = DFAGraph +export type Nodes = DFANode; +export type Edges = DFAEdge; +export type Graph = DFAGraph; export class State { constructor(public active: DFANode, @@ -30,8 +30,8 @@ export class State { } function isEmpty(label?: string) { - if (label != undefined) { - if (label != "") { + if (label !== undefined) { + if (label !== "") { return false; } } @@ -76,7 +76,7 @@ export function start(input: DFAGraph, data: string): State | boolean { if (!start) { throw new Error("Must have one start state"); } - if (accepts.size == 0) { + if (accepts.size === 0) { throw new Error("Must have at least one accept state"); } @@ -85,16 +85,16 @@ export function start(input: DFAGraph, data: string): State | boolean { export function step(current: State): State | boolean { if (current.inputLeft.length === 0) { - return current.active.isAcceptState == true; + return current.active.isAcceptState === true; } const destinations = current.active.children .filter(edge => edge.label === current.inputLeft[0]) .map(edge => edge.destination); - if (destinations.length == 1) { + if (destinations.length === 1) { return new State(destinations[0], current.inputLeft.substr(1), `transitioning from ${current.active.label} to ${destinations[0].label}`); - } else if (destinations.length == 0) { + } else if (destinations.length === 0) { return false; } else { throw "This is a DFA!"; diff --git a/interpreters/nfa/nfa.ts b/interpreters/nfa/nfa.ts index 6d22c1a..d1dccb7 100644 --- a/interpreters/nfa/nfa.ts +++ b/interpreters/nfa/nfa.ts @@ -17,9 +17,9 @@ export class NFAGraph { // startState: NFANode; } -export type Nodes = NFANode -export type Edges = NFAEdge -export type Graph = NFAGraph +export type Nodes = NFANode; +export type Edges = NFAEdge; +export type Graph = NFAGraph; export class State { constructor(public active: NFANode[], @@ -29,8 +29,8 @@ export class State { } function isEmpty(label?: string) { - if (label != undefined) { - if (label != "") { + if (label !== undefined) { + if (label !== "") { return false; } } @@ -69,7 +69,7 @@ export function start(input: NFAGraph, data: string): State | boolean { if (!start) { throw new Error("Must have one start state"); } - if (accepts.size == 0) { + if (accepts.size === 0) { throw new Error("Must have at least one accept state"); } @@ -78,13 +78,13 @@ export function start(input: NFAGraph, data: string): State | boolean { export function step(current: State): State | boolean { if (current.inputLeft.length === 0) { - return current.active.reduce((a, b) => b.isAcceptState == true || a, false); + return current.active.reduce((a, b) => b.isAcceptState === true || a, false); } const destinations = current.active.reduce((dests, a) => dests.concat(a.children), [] as NFAEdge[]) .filter(edge => edge.label === current.inputLeft[0]) .map(edge => edge.destination); - if (destinations.length == 0) { + if (destinations.length === 0) { return false; } else { return new State(destinations, current.inputLeft.substr(1)); diff --git a/package.json b/package.json index a367761..7f01298 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,10 @@ } }, "scripts": { - "format": "tsfmt -r --baseDir ./src/ && tsfmt -r --baseDir ./tests/", + "formater": "tsfmt -r ./src/*.ts && tsfmt -r ./test/*.ts && tsfmt -r ./sinap-includes/*.ts", + "formater:verify": "tsfmt --verify ./src/*.ts && tsfmt --verify ./test/*.ts && tsfmt --verify ./sinap-includes/*.ts", + "format": "npm run formater && tslint --project . --fix", + "lint": "npm run formater:verify && tslint --project .", "clean": "rm -r ./lib/ ./test/build/ ./node_modules/ ./typings/", "build": "webpack", "typings": "typings install", @@ -43,7 +46,8 @@ "raw-loader": "0.5.1", "semantic-release": "^6.3.2", "ts-loader": "2.0.0", - "typescript-formatter": "latest", + "tslint": "^4.4.2", + "typescript-formatter": "^4.1.2", "typings": "^2.1.0", "webpack": "2.2.1", "webpack-merge": "2.6.1", diff --git a/sinap-includes/plugin-stub.ts b/sinap-includes/plugin-stub.ts index 9388293..11ceaef 100644 --- a/sinap-includes/plugin-stub.ts +++ b/sinap-includes/plugin-stub.ts @@ -56,7 +56,7 @@ export function deserialize(pojo: SerialJSO): Graph { traverse(el); } } - } + }; traverse(elements); @@ -119,7 +119,7 @@ export class Program implements PluginProgram { } catch (e) { return { error: e - } + }; } } } diff --git a/src/element.ts b/src/element.ts index 4db5aea..cff9de7 100644 --- a/src/element.ts +++ b/src/element.ts @@ -33,10 +33,10 @@ export class CoreModel { /** * Create a new CoreModel. If `pojo` is provided, build the model from the - * serial represnetation. - * + * serial represnetation. + * * Note that this modifies the pojo object given and once it is passed to this - * constructor, it should not be reused. + * constructor, it should not be reused. */ constructor(private plugin: Plugin, pojo?: SerialJSO) { if (pojo === undefined) { @@ -47,12 +47,12 @@ export class CoreModel { assert.deepEqual(plugin.pluginKind, pojo.kind); if (pojo.format !== "sinap-file-format" || pojo.version !== "0.0.7") { - throw Error("not a CoreModel");; + throw Error("not a CoreModel"); } this.elements = pojo.elements.map((e) => this.plugin.makeElement(CoreElementKind[e.kind as any] as any, e.type)); - // TODO: typecheck all values against plugin-declared. + // TODO: typecheck all values against plugin-declared. const traverse = (a: any) => { if (typeof (a) !== "object") { return; @@ -65,7 +65,7 @@ export class CoreModel { traverse(el); } } - } + }; traverse(pojo.elements); @@ -87,13 +87,13 @@ export class CoreModel { removeElement(element: CoreElement) { const idx = this.elements.indexOf(element); if (idx === -1) { - throw Error("element doesn't exist");; + throw Error("element doesn't exist"); } this.elements.splice(idx, 1); } /** - * Generate an acyclic JS object which can be used to reconstruct this + * Generate an acyclic JS object which can be used to reconstruct this * model. */ serialize(): SerialJSO { diff --git a/src/files.ts b/src/files.ts index fa515ef..99461df 100644 --- a/src/files.ts +++ b/src/files.ts @@ -44,6 +44,6 @@ export interface FileService { } export interface AppLocations { - currentDirectory: Directory, - pluginDirectory: Directory + currentDirectory: Directory; + pluginDirectory: Directory; } diff --git a/src/plugin-loader.ts b/src/plugin-loader.ts index 0962af4..b92db40 100644 --- a/src/plugin-loader.ts +++ b/src/plugin-loader.ts @@ -1,8 +1,8 @@ import * as ts from "typescript"; import { File, FileService, readAsJson, Directory, Plugin, CompilationResult } from "."; -const pluginFileKey = 'plugin-file'; -const pluginKindKey = 'kind' +const pluginFileKey = "plugin-file"; +const pluginKindKey = "kind"; const options: ts.CompilerOptions = { noEmitOnError: false, @@ -32,9 +32,9 @@ function getInterpreterInfo(directory: Directory): Promise { const fileArr: [string, File][] = pluginFiles.map((file): [string, File] => [file.name, file]); const fileMap = new Map(fileArr); // TODO run npm install. - return nullPromise(fileMap.get('package.json'), `package.json for plugin ${directory.fullName}`) + return nullPromise(fileMap.get("package.json"), `package.json for plugin ${directory.fullName}`) .then((npmFile: File): Promise => { - return readAsJson(npmFile).then((pluginJson): Promise => nullPromise(pluginJson.sinap, 'sinap')) + return readAsJson(npmFile).then((pluginJson): Promise => nullPromise(pluginJson.sinap, "sinap")) .then((sinapJson) => { const filePromise = nullPromise(sinapJson[pluginFileKey], `sinap.${pluginFileKey}`); const pluginKind = nullPromise(sinapJson[pluginKindKey], `sinap.${pluginKindKey}`); @@ -49,7 +49,7 @@ function getInterpreterInfo(directory: Directory): Promise { } /** - * An abstract representation of a plugin + * An abstract representation of a plugin */ function loadPlugin(pluginInfo: InterpreterInfo, fileService: FileService): Promise { const pluginLocation = pluginInfo.interp; @@ -76,7 +76,7 @@ function loadPlugin(pluginInfo: InterpreterInfo, fileService: FileService): Prom }; program.emit(); if (script === undefined) { - throw Error("failed to emit");; + throw Error("failed to emit"); } const compInfo = new CompilationResult(script, results); return new Plugin(program, compInfo, pluginInfo.pluginKind); @@ -85,7 +85,7 @@ function loadPlugin(pluginInfo: InterpreterInfo, fileService: FileService): Prom export function printDiagnostics(diagnostics: ts.Diagnostic[]) { for (const result of diagnostics) { - console.log() + console.log(); if (result.file) { const { line, character } = result.file.getLineAndCharacterOfPosition(result.start); const starts = result.file.getLineStarts(); @@ -110,9 +110,9 @@ function createCompilerHost(files: Map, options: ts.CompilerOpti getSourceFile: (fileName): ts.SourceFile => { let source = files.get(fileName); if (!source) { - // if we didn't bundle the source file, maybe it's a lib? + // if we didn't bundle the source file, maybe it's a lib? if (fileName.indexOf("/") !== -1) { - throw Error("no relative/absolute paths here");; + throw Error("no relative/absolute paths here"); } source = fileService.getModuleFile(fileService.joinPath("typescript", "lib", fileName)); } @@ -133,7 +133,7 @@ function createCompilerHost(files: Map, options: ts.CompilerOpti getCurrentDirectory: () => "", getNewLine: () => "\n", fileExists: (fileName): boolean => { - return files.has(fileName) + return files.has(fileName); }, readFile: () => "", directoryExists: () => true, diff --git a/src/plugin.ts b/src/plugin.ts index 00590f7..ed9e208 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -7,7 +7,7 @@ function unionToList(type: Type): [string, ObjectType][] { } else if (type instanceof ObjectType) { return [[type.name, type]]; } - throw `type must be a union type or an object type.` + throw `type must be a union type or an object type.`; } @@ -74,7 +74,7 @@ export class PluginTypeEnvironment extends TypeEnvironment { elementTypes(kind: CoreElementKind) { const type = this.pluginTypes.get(kindToKey(kind)); if (type === undefined) { - throw Error("kind not found");; + throw Error("kind not found"); } return type.keys(); } @@ -82,11 +82,11 @@ export class PluginTypeEnvironment extends TypeEnvironment { getElementType(kind: CoreElementKind, type: string): ObjectType { const t = this.pluginTypes.get(kindToKey(kind)); if (t === undefined) { - throw Error("kind not found");; + throw Error("kind not found"); } const ty = t.get(type); if (ty === undefined) { - throw Error("type not found");; + throw Error("type not found"); } return ty; } diff --git a/src/program.ts b/src/program.ts index 92d7902..1681b41 100644 --- a/src/program.ts +++ b/src/program.ts @@ -2,7 +2,7 @@ import { PluginProgram, isError } from "../sinap-includes/plugin-program"; import { CoreValue, Plugin, IType, Type, UnionType, FakeUnionType } from "."; function signatureAssignable(t1: IType[], t2: IType[]) { - return t1.reduce((a, v, i) => a && v.isAssignableTo(t2[i]), true) + return t1.reduce((a, v, i) => a && v.isAssignableTo(t2[i]), true); } function pickReturnType(argTypes: IType[], signatures: [Type[], Type][], stateType: Type): IType { diff --git a/src/types.ts b/src/types.ts index be79af8..5c759cd 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,9 +13,9 @@ function hasAssignableFrom(t: Type | AssignableFrom): t is AssignableFrom { /** * Store a mapping of typescript types to our wrappers. - * + * * In order to avoid infinite loops, we need to cache the ones - * that we find. + * that we find. */ export class TypeEnvironment { private types = new Map(); @@ -64,7 +64,7 @@ export class Type implements interfaces.Type { } // TODO: protect the arguments /** - * Never call this manually, use getType on the appropriate + * Never call this manually, use getType on the appropriate * TypeEnvironment */ constructor(public env: TypeEnvironment, public type: ts.Type) { @@ -102,7 +102,7 @@ export class FakeUnionType implements interfaces.Type { * Return if this type is assignable to that type */ public isAssignableTo(that: Type, cond = (that: UnionType) => (acc: boolean, t: Type, i: number) => acc && t.isAssignableTo(that.types[i])) { - if ((that.type as any).intrinsicName === 'any') { + if ((that.type as any).intrinsicName === "any") { return true; } if (that instanceof UnionType) { @@ -136,7 +136,7 @@ export class ObjectType extends Type implements interfaces.ObjectType { constructor(env: TypeEnvironment, type: ts.ObjectType) { super(env, type); if (this.type.symbol === undefined || this.type.symbol.members === undefined) { - //throw Error("not an object type");; + // throw Error("not an object type"); // TODO: address this return; } diff --git a/test/definitions.ts b/test/definitions.ts index b868634..252986a 100644 --- a/test/definitions.ts +++ b/test/definitions.ts @@ -1,35 +1,35 @@ class Character { } class Node1 { - a: boolean + a: boolean; } class Node2 { - parents: Edge1[] - b: boolean + parents: Edge1[]; + b: boolean; } class Node3 { - c: boolean + c: boolean; } class Edge1 { /** Symbol */ - label: Character - destination: Node1 | Node2 + label: Character; + destination: Node1 | Node2; } class Edge2 { - source: Node1 | Node2 + source: Node1 | Node2; } class Graph1 { - startState: Node1 + startState: Node1; } -type Nodes = Node1 | Node2 | Node3 -type Edges = Edge1 | Edge2 -type Graph = Graph1 +type Nodes = Node1 | Node2 | Node3; +type Edges = Edge1 | Edge2; +type Graph = Graph1; export function start() { diff --git a/test/dfa-definitions.ts b/test/dfa-definitions.ts index 4bb765e..b5b433a 100644 --- a/test/dfa-definitions.ts +++ b/test/dfa-definitions.ts @@ -14,9 +14,9 @@ export class DFAGraph { startState: DFANode; } -export type Nodes = DFANode -export type Edges = DFAEdge -export type Graph = DFAGraph +export type Nodes = DFANode; +export type Edges = DFAEdge; +export type Graph = DFAGraph; export function interpret(graph: DFAGraph, input: string) { let current = graph.startState; @@ -35,7 +35,7 @@ export function interpret(graph: DFAGraph, input: string) { current = possibleStates[0]; } else { // more than one means that this is an NFA - throw Error("Not a DFA");; + throw Error("Not a DFA"); } } // check if we ended up in an accept state diff --git a/test/files-mock.ts b/test/files-mock.ts index a95a0d5..9123292 100644 --- a/test/files-mock.ts +++ b/test/files-mock.ts @@ -22,7 +22,7 @@ class LocalFile implements File { readData(): Promise { return new Promise((resolve, reject) => { // data is a string but something weird is going on. - fs.readFile(this.fullName, 'utf8', (err: any, data: any) => { + fs.readFile(this.fullName, "utf8", (err: any, data: any) => { if (err) { reject(err); } else { @@ -111,9 +111,9 @@ class LocalDirectory implements Directory { export class LocalFileService implements FileService { getAppLocations(): Promise { - const pluginPath = path.join('.', 'plugins'); + const pluginPath = path.join(".", "plugins"); const result: AppLocations = { - currentDirectory: new LocalDirectory('.'), + currentDirectory: new LocalDirectory("."), pluginDirectory: new LocalDirectory(pluginPath) }; @@ -141,6 +141,6 @@ export class LocalFileService implements FileService { } getModuleFile(file: string): string { - return fs.readFileSync(path.join('node_modules', file), 'utf8') as any; + return fs.readFileSync(path.join("node_modules", file), "utf8") as any; } } \ No newline at end of file diff --git a/test/interpreters/ideal-dfa-interpreter-v2/plugin.ts b/test/interpreters/ideal-dfa-interpreter-v2/plugin.ts index 34714b8..2f411ff 100644 --- a/test/interpreters/ideal-dfa-interpreter-v2/plugin.ts +++ b/test/interpreters/ideal-dfa-interpreter-v2/plugin.ts @@ -15,9 +15,9 @@ export class DFAGraph { startState: DFANode; } -export type Nodes = DFANode -export type Edges = DFAEdge -export type Graph = DFAGraph +export type Nodes = DFANode; +export type Edges = DFAEdge; +export type Graph = DFAGraph; export class State { constructor(public active: DFANode, @@ -39,12 +39,12 @@ export function step(current: State): State | boolean { .filter(edge => edge.label === current.inputLeft[0]) .map(edge => edge.destination); - if (destinations.length == 1) { + if (destinations.length === 1) { return new State(destinations[0], current.inputLeft.substr(1), `transitioning from ${current.active.label} to ${destinations[0].label}`); - } else if (destinations.length == 0) { + } else if (destinations.length === 0) { return false; } else { - throw Error("This is a DFA!");; + throw Error("This is a DFA!"); } } \ No newline at end of file diff --git a/test/interpreters/serial/first/definitions.ts b/test/interpreters/serial/first/definitions.ts index fcacd05..8d90673 100644 --- a/test/interpreters/serial/first/definitions.ts +++ b/test/interpreters/serial/first/definitions.ts @@ -1,34 +1,34 @@ class Character { } class Node1 { - a: boolean + a: boolean; } class Node2 { - parents: Edge1[] - b: boolean + parents: Edge1[]; + b: boolean; } class Node3 { - c: boolean + c: boolean; } class Edge1 { /** Symbol */ - label: Character - destination: Node1 | Node2 + label: Character; + destination: Node1 | Node2; } class Edge2 { - source: Node1 | Node2 + source: Node1 | Node2; } class Graph1 { - startState: Node1 + startState: Node1; } -type Nodes = Node1 | Node2 | Node3 -type Edges = Edge1 | Edge2 -type Graph = Graph1 +type Nodes = Node1 | Node2 | Node3; +type Edges = Edge1 | Edge2; +type Graph = Graph1; export function start() { } \ No newline at end of file diff --git a/test/interpreters/serial/second/definitions-for-serial.ts b/test/interpreters/serial/second/definitions-for-serial.ts index 0aea933..c18c1b7 100644 --- a/test/interpreters/serial/second/definitions-for-serial.ts +++ b/test/interpreters/serial/second/definitions-for-serial.ts @@ -1,25 +1,25 @@ class Node1 { - a: boolean + a: boolean; } class Node2 { b: { n: Node1 - } + }; } class Edge1 { - label: string - destination: Node1 | Node2 + label: string; + destination: Node1 | Node2; } class Graph1 { - startState: Node1 | Node2 + startState: Node1 | Node2; } -type Nodes = Node1 | Node2 -type Edges = Edge1 -type Graph = Graph1 +type Nodes = Node1 | Node2; +type Edges = Edge1; +type Graph = Graph1; export function start() { diff --git a/test/interpreters/stub/stub-test-definitions.ts b/test/interpreters/stub/stub-test-definitions.ts index b48a215..9d5d895 100644 --- a/test/interpreters/stub/stub-test-definitions.ts +++ b/test/interpreters/stub/stub-test-definitions.ts @@ -11,9 +11,9 @@ export class GraphC { nodes: Node[]; } -export type Nodes = Node -export type Edges = Edge -export type Graph = GraphC +export type Nodes = Node; +export type Edges = Edge; +export type Graph = GraphC; export function doIt() { return "Did it"; diff --git a/test/interpreters/validation/definitions.ts b/test/interpreters/validation/definitions.ts new file mode 100644 index 0000000..252986a --- /dev/null +++ b/test/interpreters/validation/definitions.ts @@ -0,0 +1,36 @@ +class Character { } + +class Node1 { + a: boolean; +} + +class Node2 { + parents: Edge1[]; + b: boolean; +} + +class Node3 { + c: boolean; +} + +class Edge1 { + /** Symbol */ + label: Character; + destination: Node1 | Node2; +} + +class Edge2 { + source: Node1 | Node2; +} + +class Graph1 { + startState: Node1; +} + +type Nodes = Node1 | Node2 | Node3; +type Edges = Edge1 | Edge2; +type Graph = Graph1; + +export function start() { + +} \ No newline at end of file diff --git a/test/interpreters/validation/package.json b/test/interpreters/validation/package.json new file mode 100644 index 0000000..a821e53 --- /dev/null +++ b/test/interpreters/validation/package.json @@ -0,0 +1,15 @@ +{ + "name": "stub", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "2graphic", + "license": "MIT", + "sinap": { + "kind": ["test"], + "plugin-file": "definitions.ts" + } +} diff --git a/test/test-ideal-dfa-interpreter-v2.ts b/test/test-ideal-dfa-interpreter-v2.ts index 0a0ca7b..404f032 100644 --- a/test/test-ideal-dfa-interpreter-v2.ts +++ b/test/test-ideal-dfa-interpreter-v2.ts @@ -9,7 +9,7 @@ describe("test ideal v2", () => { before(function(done) { const fileService = new LocalFileService(); - fileService.directoryByName('test/interpreters/ideal-dfa-interpreter-v2').then((directory) => { + fileService.directoryByName("test/interpreters/ideal-dfa-interpreter-v2").then((directory) => { return loadPluginDir(directory, fileService); }) .then((locPlug) => { @@ -133,35 +133,35 @@ describe("test ideal v2", () => { }); const [context, serialGraph] = setupTest(model); - const plugProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const plugProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(plugProg, plugin); const stringType = plugin.typeEnvironment.getStringType(); let results; - results = prog.run([new CoreValue(stringType, '11')]); + results = prog.run([new CoreValue(stringType, "11")]); assert.equal(3, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '')]); + results = prog.run([new CoreValue(stringType, "")]); assert.equal(1, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '101')]) + results = prog.run([new CoreValue(stringType, "101")]); assert.equal(4, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '1000')]) + results = prog.run([new CoreValue(stringType, "1000")]); assert.equal(5, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '1001')]) + results = prog.run([new CoreValue(stringType, "1001")]); assert.equal(5, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '01')]) + results = prog.run([new CoreValue(stringType, "01")]); assert.equal(3, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '011')]) + results = prog.run([new CoreValue(stringType, "011")]); assert.equal(4, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); for (let x = 0; x < 10000; x++) { - assert.equal(x % 3 == 0, prog.run([new CoreValue(stringType, x.toString(2))]).result.data); + assert.equal(x % 3 === 0, prog.run([new CoreValue(stringType, x.toString(2))]).result.data); } }); @@ -263,9 +263,9 @@ describe("test ideal v2", () => { const [context, serialGraph] = setupTest(model); for (let x = 0; x < 1000; x++) { - const plugProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const plugProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(plugProg, plugin); - assert.equal(x % 3 == 0, prog.run([new CoreValue(plugin.typeEnvironment.getStringType(), x.toString(2))]).result.data); + assert.equal(x % 3 === 0, prog.run([new CoreValue(plugin.typeEnvironment.getStringType(), x.toString(2))]).result.data); } }); diff --git a/test/test-ideal-dfa-interpreter.ts b/test/test-ideal-dfa-interpreter.ts index fe023fd..b4aeb91 100644 --- a/test/test-ideal-dfa-interpreter.ts +++ b/test/test-ideal-dfa-interpreter.ts @@ -17,7 +17,7 @@ describe("run the ideal interpreter v1", () => { ], isAcceptState: false, } - } + }; it("1", () => { assert.equal(true, interpret(g, "1")); }); @@ -48,7 +48,7 @@ describe("run the ideal interpreter v1", () => { ], isAcceptState: false, } - } + }; g.startState.children[0].destination.children.push({ label: "0", destination: g.startState, diff --git a/test/test-interpreters.ts b/test/test-interpreters.ts index 978b80f..2f8c888 100644 --- a/test/test-interpreters.ts +++ b/test/test-interpreters.ts @@ -18,14 +18,14 @@ describe("various interpreters", () => { const fs = new LocalFileService(); function loadTestPlugin(name: string): Promise { - return fs.directoryByName(fs.joinPath('interpreters', name)) + return fs.directoryByName(fs.joinPath("interpreters", name)) .then((directory) => loadPluginDir(directory, fs)); } describe("dfa", () => { let dfa: Plugin; before((done) => { - loadTestPlugin('dfa').then((dfaPlugin) => { + loadTestPlugin("dfa").then((dfaPlugin) => { dfa = dfaPlugin; done(); }); @@ -33,8 +33,8 @@ describe("various interpreters", () => { it("computes divisibility", () => { const model = new CoreModel(dfa, { format: "sinap-file-format", - kind: ["Formal Languages", "DFA"], - version: "0.0.7", + kind: ["Formal Languages", "DFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -127,43 +127,43 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(dfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, dfa); const stringType = dfa.typeEnvironment.getStringType(); let results; - results = prog.run([new CoreValue(stringType, '11')]); + results = prog.run([new CoreValue(stringType, "11")]); assert.equal(3, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '')]); + results = prog.run([new CoreValue(stringType, "")]); assert.equal(1, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '101')]); + results = prog.run([new CoreValue(stringType, "101")]); assert.equal(4, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '1000')]); + results = prog.run([new CoreValue(stringType, "1000")]); assert.equal(5, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '1001')]); + results = prog.run([new CoreValue(stringType, "1001")]); assert.equal(5, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '01')]); + results = prog.run([new CoreValue(stringType, "01")]); assert.equal(3, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '011')]); + results = prog.run([new CoreValue(stringType, "011")]); assert.equal(4, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); for (let x = 0; x < 10000; x++) { - assert.equal(x % 3 == 0, prog.run([new CoreValue(stringType, x.toString(2))]).result.data); + assert.equal(x % 3 === 0, prog.run([new CoreValue(stringType, x.toString(2))]).result.data); } }); it("checks for 1 start states", () => { const model = new CoreModel(dfa, { format: "sinap-file-format", - kind: ["Formal Languages", "DFA"], - version: "0.0.7", + kind: ["Formal Languages", "DFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -256,17 +256,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(dfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, dfa); const stringType = dfa.typeEnvironment.getStringType(); - assert.throws(() => prog.run([new CoreValue(stringType, '11')]), "allows multiple start states"); + assert.throws(() => prog.run([new CoreValue(stringType, "11")]), "allows multiple start states"); }); it("checks for 0 start states", () => { const model = new CoreModel(dfa, { format: "sinap-file-format", - kind: ["Formal Languages", "DFA"], - version: "0.0.7", + kind: ["Formal Languages", "DFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -359,17 +359,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(dfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, dfa); const stringType = dfa.typeEnvironment.getStringType(); - assert.throws(() => prog.run([new CoreValue(stringType, '11')]), "allows zero start states"); + assert.throws(() => prog.run([new CoreValue(stringType, "11")]), "allows zero start states"); }); it("checks for empty transitions", () => { const model = new CoreModel(dfa, { format: "sinap-file-format", - kind: ["Formal Languages", "DFA"], - version: "0.0.7", + kind: ["Formal Languages", "DFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -462,17 +462,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(dfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, dfa); const stringType = dfa.typeEnvironment.getStringType(); - assert.throws(() => prog.run([new CoreValue(stringType, '11')]), "allows empty transitions"); + assert.throws(() => prog.run([new CoreValue(stringType, "11")]), "allows empty transitions"); }); it("checks for two character transitions", () => { const model = new CoreModel(dfa, { format: "sinap-file-format", - kind: ["Formal Languages", "DFA"], - version: "0.0.7", + kind: ["Formal Languages", "DFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -565,17 +565,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(dfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, dfa); const stringType = dfa.typeEnvironment.getStringType(); - assert.throws(() => prog.run([new CoreValue(stringType, '11')]), "allows two character transitions"); + assert.throws(() => prog.run([new CoreValue(stringType, "11")]), "allows two character transitions"); }); }); describe("nfa", () => { let nfa: Plugin; before((done) => { - loadTestPlugin('nfa').then((nfaPlugin) => { + loadTestPlugin("nfa").then((nfaPlugin) => { nfa = nfaPlugin; done(); }); @@ -583,8 +583,8 @@ describe("various interpreters", () => { it("computes divisibility", () => { const model = new CoreModel(nfa, { format: "sinap-file-format", - kind: ["Formal Languages", "NFA"], - version: "0.0.7", + kind: ["Formal Languages", "NFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -677,43 +677,43 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(nfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, nfa); const stringType = nfa.typeEnvironment.getStringType(); let results; - results = prog.run([new CoreValue(stringType, '11')]); + results = prog.run([new CoreValue(stringType, "11")]); assert.equal(3, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '')]); + results = prog.run([new CoreValue(stringType, "")]); assert.equal(1, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '101')]); + results = prog.run([new CoreValue(stringType, "101")]); assert.equal(4, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '1000')]); + results = prog.run([new CoreValue(stringType, "1000")]); assert.equal(5, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '1001')]); + results = prog.run([new CoreValue(stringType, "1001")]); assert.equal(5, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '01')]); + results = prog.run([new CoreValue(stringType, "01")]); assert.equal(3, results.states.length, "correct number of states"); assert.equal(false, results.result.data, "correct value"); - results = prog.run([new CoreValue(stringType, '011')]); + results = prog.run([new CoreValue(stringType, "011")]); assert.equal(4, results.states.length, "correct number of states"); assert.equal(true, results.result.data, "correct value"); for (let x = 0; x < 10000; x++) { - assert.equal(x % 3 == 0, prog.run([new CoreValue(stringType, x.toString(2))]).result.data); + assert.equal(x % 3 === 0, prog.run([new CoreValue(stringType, x.toString(2))]).result.data); } }); it("checks for 1 start states", () => { const model = new CoreModel(nfa, { format: "sinap-file-format", - kind: ["Formal Languages", "NFA"], - version: "0.0.7", + kind: ["Formal Languages", "NFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -806,17 +806,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(nfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, nfa); const stringType = nfa.typeEnvironment.getStringType(); - assert.throws(() => prog.run([new CoreValue(stringType, '11')]), "allows multiple start states"); + assert.throws(() => prog.run([new CoreValue(stringType, "11")]), "allows multiple start states"); }); it("checks for 0 start states", () => { const model = new CoreModel(nfa, { format: "sinap-file-format", - kind: ["Formal Languages", "NFA"], - version: "0.0.7", + kind: ["Formal Languages", "NFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -909,17 +909,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(nfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, nfa); const stringType = nfa.typeEnvironment.getStringType(); - assert.throws(() => prog.run([new CoreValue(stringType, '11')]), "allows zero start states"); + assert.throws(() => prog.run([new CoreValue(stringType, "11")]), "allows zero start states"); }); it("allows empty transitions", () => { const model = new CoreModel(nfa, { format: "sinap-file-format", - kind: ["Formal Languages", "NFA"], - version: "0.0.7", + kind: ["Formal Languages", "NFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -1012,17 +1012,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(nfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, nfa); const stringType = nfa.typeEnvironment.getStringType(); - prog.run([new CoreValue(stringType, '11')]); + prog.run([new CoreValue(stringType, "11")]); }); it("checks for two character transitions", () => { const model = new CoreModel(nfa, { format: "sinap-file-format", - kind: ["Formal Languages", "NFA"], - version: "0.0.7", + kind: ["Formal Languages", "NFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -1115,17 +1115,17 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(nfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, nfa); const stringType = nfa.typeEnvironment.getStringType(); - assert.throws(() => prog.run([new CoreValue(stringType, '11')]), "allows two character transitions"); + assert.throws(() => prog.run([new CoreValue(stringType, "11")]), "allows two character transitions"); }); it("supports non-determinism", () => { const model = new CoreModel(nfa, { format: "sinap-file-format", - kind: ["Formal Languages", "NFA"], - version: "0.0.7", + kind: ["Formal Languages", "NFA"], + version: "0.0.7", elements: [ { kind: "Graph", @@ -1182,14 +1182,14 @@ describe("various interpreters", () => { }); const [context, serialGraph] = setupTest(nfa, model); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, nfa); const stringType = nfa.typeEnvironment.getStringType(); - assert.equal(true, prog.run([new CoreValue(stringType, '11')]).result.data); - assert.equal(true, prog.run([new CoreValue(stringType, '10001')]).result.data); - assert.equal(true, prog.run([new CoreValue(stringType, '0001')]).result.data); - assert.equal(false, prog.run([new CoreValue(stringType, '1100')]).result.data); + assert.equal(true, prog.run([new CoreValue(stringType, "11")]).result.data); + assert.equal(true, prog.run([new CoreValue(stringType, "10001")]).result.data); + assert.equal(true, prog.run([new CoreValue(stringType, "0001")]).result.data); + assert.equal(false, prog.run([new CoreValue(stringType, "1100")]).result.data); }); }); }); \ No newline at end of file diff --git a/test/test-plugin.ts b/test/test-plugin.ts index 31938df..999c540 100644 --- a/test/test-plugin.ts +++ b/test/test-plugin.ts @@ -6,7 +6,7 @@ import * as vm from "vm"; describe("plugin", () => { const fs = new LocalFileService(); - function loadTestPlugin(name: string, dirs = ['interpreters']): Promise { + function loadTestPlugin(name: string, dirs = ["interpreters"]): Promise { return fs.directoryByName(fs.joinPath(...dirs.concat([name]))) .then((directory) => loadPluginDir(directory, fs)); } @@ -18,19 +18,19 @@ describe("plugin", () => { it("provides start type info", () => { return loadTestPlugin("dfa").then(plugin => { const ts = plugin.typeEnvironment.startTypes.map(m => [m[0].map(n => n.name), m[1].name]); - assert.deepEqual([[['DFAGraph', 'string'], 'boolean | State']], ts); + assert.deepEqual([[["DFAGraph", "string"], "boolean | State"]], ts); }); }); it("handles overloads", () => { - return loadTestPlugin("start-functions", ['test', 'interpreters']).then(plugin => { + return loadTestPlugin("start-functions", ["test", "interpreters"]).then(plugin => { const ts = plugin.typeEnvironment.startTypes.map(m => [m[0].map(n => n.name), m[1].name]); assert.deepEqual([ - [['Graph', 'any', 'any'], 'any'], - [['Graph', 'number', 'number'], 'number'], - [['Graph', 'number', 'string'], 'number'], - [['Graph', 'string', 'string'], 'string'], - [['Graph', 'string', 'string'], 'string | number'], + [["Graph", "any", "any"], "any"], + [["Graph", "number", "number"], "number"], + [["Graph", "number", "string"], "number"], + [["Graph", "string", "string"], "string"], + [["Graph", "string", "string"], "string | number"], ], ts); }); }); @@ -40,14 +40,14 @@ describe("plugin", () => { let stringType: Type; let numberType: Type; before(() => { - return loadTestPlugin("start-functions", ['test', 'interpreters']).then(plugin => { + return loadTestPlugin("start-functions", ["test", "interpreters"]).then(plugin => { const script = new vm.Script(plugin.results.js as string); const sandbox: any = { console: console, global: {} }; const context: any = vm.createContext(sandbox); script.runInContext(context); - const pluginProgram = new context.global['plugin-stub'].Program({ elements: [] }); + const pluginProgram = new context.global["plugin-stub"].Program({ elements: [] }); program = new Program(pluginProgram, plugin); // const anyType = plugin.typeEnvironment.getType(plugin.typeEnvironment.checker.getAnyType()); @@ -55,7 +55,7 @@ describe("plugin", () => { numberType = plugin.typeEnvironment.getType(plugin.typeEnvironment.checker.getNumberType()); }); }); - // TODO: make the commented out cases pass (non-urgent, this only applies if several types are given for the + // TODO: make the commented out cases pass (non-urgent, this only applies if several types are given for the // start function) // it("handles any case", () => { @@ -80,14 +80,14 @@ describe("plugin", () => { let stringType: Type; let numberType: Type; before(() => { - return loadTestPlugin("start-functions-2", ['test', 'interpreters']).then(plugin => { + return loadTestPlugin("start-functions-2", ["test", "interpreters"]).then(plugin => { const script = new vm.Script(plugin.results.js as string); const sandbox: any = { console: console, global: {} }; const context: any = vm.createContext(sandbox); script.runInContext(context); - const pluginProgram = new context.global['plugin-stub'].Program({ elements: [] }); + const pluginProgram = new context.global["plugin-stub"].Program({ elements: [] }); program = new Program(pluginProgram, plugin); // const anyType = plugin.typeEnvironment.getType(plugin.typeEnvironment.checker.getAnyType()); diff --git a/test/test-serialization.ts b/test/test-serialization.ts index 987e298..1d736dc 100644 --- a/test/test-serialization.ts +++ b/test/test-serialization.ts @@ -21,12 +21,12 @@ describe("Serialization", () => { const fs = new LocalFileService(); function loadSerPlugin(name: string): Promise { - return fs.directoryByName(fs.joinPath('test', 'interpreters', 'serial', name)) + return fs.directoryByName(fs.joinPath("test", "interpreters", "serial", name)) .then((directory) => loadPluginDir(directory, fs)); } before(() => { - return Promise.all([loadSerPlugin('first'), loadSerPlugin('second')]) + return Promise.all([loadSerPlugin("first"), loadSerPlugin("second")]) .then(([first, second]) => { firstPlugin = first; secondPlugin = second; @@ -36,7 +36,7 @@ describe("Serialization", () => { it("one", () => { const test = roundTripJSO(firstPlugin, { format: "sinap-file-format", - kind: ['test'], + kind: ["test"], version: "0.0.7", elements: [ { @@ -56,13 +56,13 @@ describe("Serialization", () => { ] }); - assert.equal(true, test.elements[0].data['startState'].data.a); + assert.equal(true, test.elements[0].data["startState"].data.a); }); it("two", () => { const test = roundTripJSO(secondPlugin, { format: "sinap-file-format", - kind: ['test'], + kind: ["test"], version: "0.0.7", elements: [ { @@ -91,6 +91,6 @@ describe("Serialization", () => { ] }); - assert.equal(true, test.elements[0].data['startState'].data.b.n.data.a); + assert.equal(true, test.elements[0].data["startState"].data.b.n.data.a); }); }); \ No newline at end of file diff --git a/test/test-stub.ts b/test/test-stub.ts index 648d8ba..dac0f30 100644 --- a/test/test-stub.ts +++ b/test/test-stub.ts @@ -8,7 +8,7 @@ describe("plugin stub", () => { let plugin: Plugin; before((done) => { const fs = new LocalFileService(); - fs.directoryByName(fs.joinPath('test', 'interpreters', 'stub')) + fs.directoryByName(fs.joinPath("test", "interpreters", "stub")) .then((directory) => loadPluginDir(directory, fs)) .then((newPlugin) => { plugin = newPlugin; @@ -181,7 +181,7 @@ describe("plugin stub", () => { const [context, serialGraph] = setupTest(model, { global: { "plugin-stub": { "Program": null } } }); - const pluginProg = new context.global['plugin-stub'].Program(JSON.parse(serialGraph)); + const pluginProg = new context.global["plugin-stub"].Program(JSON.parse(serialGraph)); const prog = new Program(pluginProg, plugin); const numberType = plugin.typeEnvironment.getNumberType(); @@ -193,7 +193,7 @@ describe("plugin stub", () => { const script = new vm.Script(plugin.results.js as string); const context = vm.createContext({ global: { "plugin-stub": { "Program": null } } }); script.runInContext(context); - const pluginProg = new (context as any).global['plugin-stub'].Program({ elements: [] }); + const pluginProg = new (context as any).global["plugin-stub"].Program({ elements: [] }); const prog = new Program(pluginProg, plugin); const numberType = plugin.typeEnvironment.getStringType(); @@ -206,5 +206,5 @@ describe("plugin stub", () => { const borderColor = drawableNode.members.get("borderColor")!; assert.equal(true, borderColor.isAssignableTo(color)); - }) + }); }); \ No newline at end of file diff --git a/test/test-validation.ts b/test/test-validation.ts index 91dd151..8d0b123 100644 --- a/test/test-validation.ts +++ b/test/test-validation.ts @@ -2,7 +2,7 @@ import * as assert from "assert"; import * as ts from "typescript"; -import { TypeEnvironment, UnionType, validateEdge, ObjectType, Type } from "../src/" +import { TypeEnvironment, UnionType, validateEdge, ObjectType, Type } from "../src/"; describe("isValidEdge", () => { const program = ts.createProgram(["test/definitions.ts"], { @@ -13,7 +13,8 @@ describe("isValidEdge", () => { const typeMap = new Map(["Nodes", "Edges", - "Graph",].map(k => [k, env.getType(env.checker.lookupTypeAt(k, program.getSourceFile("test/definitions.ts")))] as [string, Type])); + "Graph", + ].map(k => [k, env.getType(env.checker.lookupTypeAt(k, program.getSourceFile("test/definitions.ts")))] as [string, Type])); const nodes = typeMap.get("Nodes") as UnionType; const node1 = nodes.types[0] as ObjectType;