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.
57 lines
2.6 KiB
TypeScript
57 lines
2.6 KiB
TypeScript
import { FunctionParameterCollection } from '@/application/Parser/Script/Compiler/Function/Parameter/FunctionParameterCollection';
|
|
import { FunctionCallArgumentCollection } from '../../Function/Call/Argument/FunctionCallArgumentCollection';
|
|
import { ExpressionEvaluationContext, type IExpressionEvaluationContext } from './ExpressionEvaluationContext';
|
|
import { ExpressionPosition } from './ExpressionPosition';
|
|
import type { IReadOnlyFunctionCallArgumentCollection } from '../../Function/Call/Argument/IFunctionCallArgumentCollection';
|
|
import type { IReadOnlyFunctionParameterCollection } from '../../Function/Parameter/IFunctionParameterCollection';
|
|
import type { IExpression } from './IExpression';
|
|
|
|
export type ExpressionEvaluator = (context: IExpressionEvaluationContext) => string;
|
|
export class Expression implements IExpression {
|
|
public readonly parameters: IReadOnlyFunctionParameterCollection;
|
|
|
|
constructor(
|
|
public readonly position: ExpressionPosition,
|
|
public readonly evaluator: ExpressionEvaluator,
|
|
parameters?: IReadOnlyFunctionParameterCollection,
|
|
) {
|
|
this.parameters = parameters ?? new FunctionParameterCollection();
|
|
}
|
|
|
|
public evaluate(context: IExpressionEvaluationContext): string {
|
|
validateThatAllRequiredParametersAreSatisfied(this.parameters, context.args);
|
|
const args = filterUnusedArguments(this.parameters, context.args);
|
|
const filteredContext = new ExpressionEvaluationContext(args, context.pipelineCompiler);
|
|
return this.evaluator(filteredContext);
|
|
}
|
|
}
|
|
|
|
function validateThatAllRequiredParametersAreSatisfied(
|
|
parameters: IReadOnlyFunctionParameterCollection,
|
|
args: IReadOnlyFunctionCallArgumentCollection,
|
|
) {
|
|
const requiredParameterNames = parameters
|
|
.all
|
|
.filter((parameter) => !parameter.isOptional)
|
|
.map((parameter) => parameter.name);
|
|
const missingParameterNames = requiredParameterNames
|
|
.filter((parameterName) => !args.hasArgument(parameterName));
|
|
if (missingParameterNames.length) {
|
|
throw new Error(
|
|
`argument values are provided for required parameters: "${missingParameterNames.join('", "')}"`,
|
|
);
|
|
}
|
|
}
|
|
|
|
function filterUnusedArguments(
|
|
parameters: IReadOnlyFunctionParameterCollection,
|
|
allFunctionArgs: IReadOnlyFunctionCallArgumentCollection,
|
|
): IReadOnlyFunctionCallArgumentCollection {
|
|
const specificCallArgs = new FunctionCallArgumentCollection();
|
|
parameters.all
|
|
.filter((parameter) => allFunctionArgs.hasArgument(parameter.name))
|
|
.map((parameter) => allFunctionArgs.getArgument(parameter.name))
|
|
.forEach((argument) => specificCallArgs.addArgument(argument));
|
|
return specificCallArgs;
|
|
}
|