diff --git a/src/lib/_lexer.ts b/src/lib/_lexer.ts index 8445605..d6a4474 100644 --- a/src/lib/_lexer.ts +++ b/src/lib/_lexer.ts @@ -8,7 +8,7 @@ import { debug } from './logger'; // These are the regex patterns for parsing. They must not have any // capturing groups. They are used during lexing and will be // checked by name during parsing. -const PATTERNS = { +const PATTERNS: { [key: string]: string } = { COMMENT: '#.*$', STRING: '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"', ALIGNMENT: '~(?:[a-z].?)?[0-9]+(?:,[0-9]+)*', diff --git a/src/lib/model.ts b/src/lib/model.ts index 32dedf4..a02d903 100644 --- a/src/lib/model.ts +++ b/src/lib/model.ts @@ -81,10 +81,10 @@ export class Model { const deifs: Map> = new Map(); if (reifications) { for (const [role, concept, source, target] of reifications) { - if (reifs[role] === undefined) { - reifs[role] = []; + if (!reifs.has(role)) { + reifs.set(role, []); } - reifs[role].push([concept, source, target]); + reifs.get(role)!.push([concept, source, target]); if (!deifs.has(concept)) { deifs.set(concept, []); } @@ -258,7 +258,7 @@ export class Model { * Return `true` if `role` can be reified. */ isRoleReifiable(role: Role): boolean { - return role in this.reifications; + return this.reifications.has(role); } /** @@ -285,10 +285,10 @@ export class Model { reify(triple: Triple, options: ModelReifyOptions = {}): _Reification { const { variables } = options; const [source, role, target] = triple; - if (!(role in this.reifications)) { + if (!this.reifications.has(role)) { throw new ModelError(`'${role}' cannot be reified`); } - const [concept, sourceRole, targetRole] = this.reifications[role][0]; + const [concept, sourceRole, targetRole] = this.reifications.get(role)![0]; let variable = '_'; if (variables) { diff --git a/src/lib/transform.spec.ts b/src/lib/transform.spec.ts index be68497..766e4a9 100644 --- a/src/lib/transform.spec.ts +++ b/src/lib/transform.spec.ts @@ -61,7 +61,7 @@ test('canonicalize_roles_amr_codec', (t) => { test('reify_edges_default_codec', (t) => { const decode = defCodec.decode.bind(defCodec); const norm = makeNorm(reifyEdges, defModel); - const form = makeForm((g: Graph, { indent }: { indent?: number }) => + const form = makeForm((g: Graph, { indent }: { indent?: number | null }) => defCodec.encode(g, { indent }), ); @@ -75,7 +75,7 @@ test('reify_edges_default_codec', (t) => { test('reify_edges_amr_codec', (t) => { const decode = amrCodec.decode.bind(amrCodec); const norm = makeNorm(reifyEdges, amrModel); - const form = makeForm((g: Graph, { indent }: { indent?: number }) => + const form = makeForm((g: Graph, { indent }: { indent?: number | null }) => amrCodec.encode(g, { indent }), ); @@ -101,7 +101,7 @@ test('reify_edges_amr_codec', (t) => { test('dereify_edges_default_codec', (t) => { const decode = defCodec.decode.bind(defCodec); const norm = makeNorm(dereifyEdges, defModel); - const form = makeForm((g: Graph, { indent }: { indent?: number }) => + const form = makeForm((g: Graph, { indent }: { indent?: number | null }) => defCodec.encode(g, { indent }), ); @@ -125,7 +125,7 @@ test('dereify_edges_default_codec', (t) => { test('dereify_edges_amr_codec', (t) => { const decode = amrCodec.decode.bind(amrCodec); const norm = makeNorm(dereifyEdges, amrModel); - const form = makeForm((g: Graph, { indent }: { indent?: number }) => + const form = makeForm((g: Graph, { indent }: { indent?: number | null }) => amrCodec.encode(g, { indent }), ); @@ -148,7 +148,7 @@ test('dereify_edges_amr_codec', (t) => { test('reify_attributes', (t) => { const decode = defCodec.decode.bind(defCodec); const norm = reifyAttributes; - const form = makeForm((g: Graph, { indent }: { indent?: number }) => + const form = makeForm((g: Graph, { indent }: { indent?: number | null }) => defCodec.encode(g, { indent }), ); @@ -165,7 +165,7 @@ test('indicate_branches', (t) => { (x, { model }: { model: Model }) => indicateBranches(x, model), defModel, ); - const form = makeForm((g: Graph, { indent }: { indent?: number }) => + const form = makeForm((g: Graph, { indent }: { indent?: number | null }) => defCodec.encode(g, { indent }), ); diff --git a/src/lib/tree.spec.ts b/src/lib/tree.spec.ts index 9763119..3c55b52 100644 --- a/src/lib/tree.spec.ts +++ b/src/lib/tree.spec.ts @@ -214,7 +214,7 @@ test('walk', (t) => { // assert _vars(t) == ['a', 'b'] test('reset_variables', (t) => { - const _vars = (t) => t.nodes().map(([v]) => v); + const _vars = (t: Tree) => t.nodes().map(([v]) => v); const t1 = new Tree(one_arg_node()); t.deepEqual(_vars(t1), ['a', 'b']); diff --git a/src/lib/tree.ts b/src/lib/tree.ts index 8383c91..5086bc5 100644 --- a/src/lib/tree.ts +++ b/src/lib/tree.ts @@ -168,7 +168,7 @@ const _nodes = (node: Node): Node[] => { return ns; }; -function* _walk(node: Node, path: number[]) { +function* _walk(node: Node, path: number[]): Generator<_Step> { const branches = node[1] ?? []; for (const [i, branch] of branches.entries()) { const curpath = path.concat([i]); diff --git a/tsconfig.json b/tsconfig.json index 5d12667..a102e61 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,16 +10,7 @@ "inlineSourceMap": true, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "resolveJsonModule": true /* Include modules imported with .json extension. */, - - // "strict": true /* Enable all strict type-checking options. */, - - /* Strict Type-Checking Options */ - // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, - "strictNullChecks": true /* Enable strict null checks. */, - // "strictFunctionTypes": true /* Enable strict checking of function types. */, - // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, - // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, - // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + "strict": true /* Enable all strict type-checking options. */, /* Additional Checks */ "noUnusedLocals": true /* Report errors on unused locals. */,