Files
privacy.sexy/tests/unit/shared/Stubs/ScriptCompilerStub.ts
undergroundwires c138f74460 Refactor to unify scripts/categories as Executable
This commit consolidates scripts and categories under a unified
'Executable' concept. This simplifies the architecture and improves code
readability.

- Introduce subfolders within `src/domain` to segregate domain elements.
- Update class and interface names by removing the 'I' prefix in
  alignment with new coding standards.
- Replace 'Node' with 'Executable' to clarify usage; reserve 'Node'
  exclusively for the UI's tree component.
2024-06-12 12:36:40 +02:00

29 lines
991 B
TypeScript

import type { ScriptData } from '@/application/collections/';
import type { IScriptCompiler } from '@/application/Parser/Executable/Script/Compiler/IScriptCompiler';
import type { ScriptCode } from '@/domain/Executables/Script/Code/ScriptCode';
import { ScriptCodeStub } from './ScriptCodeStub';
export class ScriptCompilerStub implements IScriptCompiler {
public compilableScripts = new Map<ScriptData, ScriptCode>();
public canCompile(script: ScriptData): boolean {
return this.compilableScripts.has(script);
}
public compile(script: ScriptData): ScriptCode {
const foundCode = this.compilableScripts.get(script);
if (foundCode) {
return foundCode;
}
return new ScriptCodeStub();
}
public withCompileAbility(script: ScriptData, result?: ScriptCode): this {
this.compilableScripts.set(
script,
result ?? { execute: `compiled code of ${script.name}`, revert: `compiled revert code of ${script.name}` },
);
return this;
}
}