Files
privacy.sexy/src/application/Parser/Script/Compiler/Function/SharedFunction.ts
undergroundwires a721e82a4f Bump TypeScript to 5.3 with verbatimModuleSyntax
This commit upgrades TypeScript to the latest version 5.3 and introduces
`verbatimModuleSyntax` in line with the official Vue guide
recommendatinos (vuejs/docs#2592).

By enforcing `import type` for type-only imports, this commit improves
code clarity and supports tooling optimization, ensuring imports are
only bundled when necessary for runtime.

Changes:

- Bump TypeScript to 5.3.3 across the project.
- Adjust import statements to utilize `import type` where applicable,
  promoting cleaner and more efficient code.
2024-02-27 04:20:22 +01:00

63 lines
1.9 KiB
TypeScript

import {
FunctionBodyType, type IFunctionCode, type ISharedFunction, type SharedFunctionBody,
} from './ISharedFunction';
import type { FunctionCall } from './Call/FunctionCall';
import type { IReadOnlyFunctionParameterCollection } from './Parameter/IFunctionParameterCollection';
export function createCallerFunction(
name: string,
parameters: IReadOnlyFunctionParameterCollection,
callSequence: readonly FunctionCall[],
): ISharedFunction {
if (!callSequence.length) {
throw new Error(`missing call sequence in function "${name}"`);
}
return new SharedFunction(name, parameters, callSequence, FunctionBodyType.Calls);
}
export function createFunctionWithInlineCode(
name: string,
parameters: IReadOnlyFunctionParameterCollection,
code: string,
revertCode?: string,
): ISharedFunction {
if (!code) {
throw new Error(`undefined code in function "${name}"`);
}
const content: IFunctionCode = {
execute: code,
revert: revertCode,
};
return new SharedFunction(name, parameters, content, FunctionBodyType.Code);
}
class SharedFunction implements ISharedFunction {
public readonly body: SharedFunctionBody;
constructor(
public readonly name: string,
public readonly parameters: IReadOnlyFunctionParameterCollection,
content: IFunctionCode | readonly FunctionCall[],
bodyType: FunctionBodyType,
) {
if (!name) { throw new Error('missing function name'); }
switch (bodyType) {
case FunctionBodyType.Code:
this.body = {
type: FunctionBodyType.Code,
code: content as IFunctionCode,
};
break;
case FunctionBodyType.Calls:
this.body = {
type: FunctionBodyType.Calls,
calls: content as readonly FunctionCall[],
};
break;
default:
throw new Error(`unknown body type: ${FunctionBodyType[bodyType]}`);
}
}
}