js-slang
Version:
Javascript-based implementations of Source, written in Typescript
34 lines (33 loc) • 1.55 kB
TypeScript
import type es from 'estree';
import type { Context, IOptions } from '../..';
import { RecursivePartial } from '../../types';
import type { FileGetter } from '../moduleTypes';
import { type Bundler } from './bundler';
export type PreprocessResult = {
ok: true;
program: es.Program;
files: Record<string, string>;
verboseErrors: boolean;
} | {
ok: false;
verboseErrors: boolean;
};
/**
* Preprocesses file imports and returns a transformed Abstract Syntax Tree (AST).
* If an error is encountered at any point, returns `undefined` to signify that an
* error occurred. Details of the error can be found inside `context.errors`.
*
* The preprocessing works by transforming each imported file into a function whose
* parameters are other files (results of transformed functions) and return value
* is a pair where the head is the default export or null, and the tail is a list
* of pairs that map from exported names to identifiers.
*
* See https://github.com/source-academy/js-slang/wiki/Local-Module-Import-&-Export
* for more information.
*
* @param files An object mapping absolute file paths to file content.
* @param entrypointFilePath The absolute path of the entrypoint file.
* @param context The information associated with the program evaluation.
*/
declare const preprocessFileImports: (files: FileGetter, entrypointFilePath: string, context: Context, options?: RecursivePartial<IOptions>, bundler?: Bundler) => Promise<PreprocessResult>;
export default preprocessFileImports;