From a900a7a35b4caa886850c9ab414a70a7decfd2f7 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Sun, 1 Jun 2025 17:11:19 +0200 Subject: [PATCH] chore: use erasableSyntaxOnly --- src/api.ts | 11 ++++++----- src/compiler/header-builder.ts | 2 +- src/compiler/index.ts | 12 ++++++++---- src/implementation/c/code/base.ts | 4 +++- src/implementation/c/compilation.ts | 14 +++++++++++--- src/implementation/c/helpers/match-sequence.ts | 5 ++++- src/implementation/c/index.ts | 5 ++++- src/implementation/c/node/base.ts | 4 +++- src/implementation/c/transform/base.ts | 5 ++++- tsconfig.json | 3 ++- 10 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/api.ts b/src/api.ts index a34f5bc..9875ef7 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,6 +1,4 @@ -import * as frontend from 'llparse-frontend'; - -import source = frontend.source; +import { source } from 'llparse-frontend'; import { Compiler, ICompilerOptions, ICompilerResult } from './compiler'; @@ -12,6 +10,8 @@ export { source, ICompilerOptions, ICompilerResult }; * LLParse graph builder and compiler. */ export class LLParse extends source.Builder { + private readonly prefix: string; + /** * The prefix controls the names of methods and state struct in generated * public C headers: @@ -28,10 +28,11 @@ export class LLParse extends source.Builder { * * @param prefix Prefix to be used when generating public API. */ - constructor(private readonly prefix: string = 'llparse') { + constructor(prefix: string = 'llparse') { super(); + this.prefix = prefix; } - + /** * Compile LLParse graph to the C code and C headers * diff --git a/src/compiler/header-builder.ts b/src/compiler/header-builder.ts index 3de9c12..b7ddb83 100644 --- a/src/compiler/header-builder.ts +++ b/src/compiler/header-builder.ts @@ -1,5 +1,5 @@ import * as frontend from 'llparse-frontend'; -import source = frontend.source; +import { source } from 'llparse-frontend'; export interface IHeaderBuilderOptions { readonly prefix: string; diff --git a/src/compiler/index.ts b/src/compiler/index.ts index 80eb584..7bbadb4 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -1,7 +1,6 @@ import * as debugAPI from 'debug'; import * as frontend from 'llparse-frontend'; - -import source = frontend.source; +import { source } from 'llparse-frontend'; import * as cImpl from '../implementation/c'; import { HeaderBuilder } from './header-builder'; @@ -50,8 +49,13 @@ export interface ICompilerResult { } export class Compiler { - constructor(public readonly prefix: string, - public readonly options: ICompilerOptions) { + public readonly prefix: string; + public readonly options: ICompilerOptions; + + constructor(prefix: string, + options: ICompilerOptions) { + this.prefix = prefix; + this.options = options; } public compile(root: source.node.Node, diff --git a/src/implementation/c/code/base.ts b/src/implementation/c/code/base.ts index 888330d..c7554b6 100644 --- a/src/implementation/c/code/base.ts +++ b/src/implementation/c/code/base.ts @@ -4,8 +4,10 @@ import { Compilation } from '../compilation'; export abstract class Code { protected cachedDecl: string | undefined; + public readonly ref: T; - constructor(public readonly ref: T) { + constructor(ref: T) { + this.ref = ref; } public abstract build(ctx: Compilation, out: string[]): void; diff --git a/src/implementation/c/compilation.ts b/src/implementation/c/compilation.ts index 4cb017a..c958f42 100644 --- a/src/implementation/c/compilation.ts +++ b/src/implementation/c/compilation.ts @@ -42,10 +42,18 @@ export class Compilation { Map = new Map(); private readonly resumptionTargets: Set = new Set(); - constructor(public readonly prefix: string, - private readonly properties: ReadonlyArray, + public readonly prefix: string; + private readonly properties: ReadonlyArray; + private readonly options: ICompilationOptions; + + constructor(prefix: string, + properties: ReadonlyArray, resumptionTargets: ReadonlySet, - private readonly options: ICompilationOptions) { + options: ICompilationOptions) { + this.prefix = prefix; + this.properties = properties; + this.options = options; + for (const node of resumptionTargets) { this.resumptionTargets.add(STATE_PREFIX + node.ref.id.name); } diff --git a/src/implementation/c/helpers/match-sequence.ts b/src/implementation/c/helpers/match-sequence.ts index 0b04176..33eed27 100644 --- a/src/implementation/c/helpers/match-sequence.ts +++ b/src/implementation/c/helpers/match-sequence.ts @@ -9,7 +9,10 @@ import { Compilation } from '../compilation'; type TransformWrap = Transform; export class MatchSequence { - constructor(private readonly transform: TransformWrap) { + private readonly transform: TransformWrap; + + constructor(transform: TransformWrap) { + this.transform = transform; } public static buildGlobals(out: string[]): void { diff --git a/src/implementation/c/index.ts b/src/implementation/c/index.ts index 575e94a..1773ebe 100644 --- a/src/implementation/c/index.ts +++ b/src/implementation/c/index.ts @@ -21,8 +21,11 @@ export interface ICPublicOptions { } export class CCompiler { + public readonly options: ICCompilerOptions; + constructor(container: frontend.Container, - public readonly options: ICCompilerOptions) { + options: ICCompilerOptions) { + this.options = options; container.add(CONTAINER_KEY, { code, node, transform }); } diff --git a/src/implementation/c/node/base.ts b/src/implementation/c/node/base.ts index 51f90bb..d7c85ec 100644 --- a/src/implementation/c/node/base.ts +++ b/src/implementation/c/node/base.ts @@ -15,8 +15,10 @@ export interface INodeEdge { export abstract class Node { protected cachedDecl: string | undefined; protected privCompilation: Compilation | undefined; + public readonly ref: T; - constructor(public readonly ref: T) { + constructor(ref: T) { + this.ref = ref; } public build(compilation: Compilation): string { diff --git a/src/implementation/c/transform/base.ts b/src/implementation/c/transform/base.ts index 82028d5..5a911e6 100644 --- a/src/implementation/c/transform/base.ts +++ b/src/implementation/c/transform/base.ts @@ -3,7 +3,10 @@ import * as frontend from 'llparse-frontend'; import { Compilation } from '../compilation'; export abstract class Transform { - constructor(public readonly ref: T) { + public readonly ref: T; + + constructor(ref: T) { + this.ref = ref; } public abstract build(ctx: Compilation, value: string): string; diff --git a/tsconfig.json b/tsconfig.json index 4fa0169..f5c5826 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,8 @@ "pretty": true, "sourceMap": true, "noUncheckedIndexedAccess": true, - "noUnusedLocals": true + "noUnusedLocals": true, + "erasableSyntaxOnly": true }, "include": [ "src/**/*.ts"