This commit improves the validation logic in parser, corrects Windows collection files to adhere to expected structure. This validation helps catch errors that previously led to incomplete generated code in scripts for disabling VSCEIP and location settings. Changes: - Add type validation for function call structures in the parser/compiler. This helps prevent runtime errors by ensuring that only correctly structured data is processed. - Fix scripts in the Windows collection that previoulsy had incomplete `code` or `revertCode` values. These corrections ensure that the scripts function as intended. - Refactor related logic within the compiler/parser to improve testability and maintainability.
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import type { FunctionData } from '@/application/collections/';
|
|
import { sequenceEqual } from '@/application/Common/Array';
|
|
import type { ISharedFunctionCollection } from '@/application/Parser/Executable/Script/Compiler/Function/ISharedFunctionCollection';
|
|
import type { SharedFunctionsParser } from '@/application/Parser/Executable/Script/Compiler/Function/SharedFunctionsParser';
|
|
import type { ILanguageSyntax } from '@/application/Parser/Executable/Script/Validation/Syntax/ILanguageSyntax';
|
|
import { SharedFunctionCollectionStub } from './SharedFunctionCollectionStub';
|
|
|
|
export function createSharedFunctionsParserStub() {
|
|
const callHistory = new Array<{
|
|
readonly functions: readonly FunctionData[],
|
|
readonly syntax: ILanguageSyntax,
|
|
}>();
|
|
|
|
const setupResults = new Array<{
|
|
readonly functions: readonly FunctionData[],
|
|
readonly result: ISharedFunctionCollection,
|
|
}>();
|
|
|
|
const findResult = (
|
|
functions: readonly FunctionData[],
|
|
): ISharedFunctionCollection | undefined => {
|
|
return setupResults
|
|
.find((result) => sequenceEqual(result.functions, functions))
|
|
?.result;
|
|
};
|
|
|
|
const parser: SharedFunctionsParser = (
|
|
functions: readonly FunctionData[],
|
|
syntax: ILanguageSyntax,
|
|
) => {
|
|
callHistory.push({
|
|
functions: Array.from(functions),
|
|
syntax,
|
|
});
|
|
const result = findResult(functions);
|
|
return result || new SharedFunctionCollectionStub();
|
|
};
|
|
|
|
const setup = (
|
|
functions: readonly FunctionData[],
|
|
result: ISharedFunctionCollection,
|
|
) => {
|
|
setupResults.push({ functions, result });
|
|
};
|
|
|
|
return {
|
|
parser,
|
|
setup,
|
|
callHistory,
|
|
};
|
|
}
|