Add basic CompletionMapping and runEngine code

This commit is contained in:
2020-09-07 16:48:04 +05:30
parent 479c4d0f2e
commit a1090de269
3 changed files with 121 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
import { Node } from "acorn";
import { inspect } from "../../engine262/dist/engine262";
import { CompletionRecord, CompletionTypes } from "../types/engine262-stubs";
export interface ICompletionDetail {
start: number;
end: number;
completionType: CompletionTypes;
completionValueString: string;
completionTargetString: string | undefined;
completionValue: any;
}
export const completionMapping: {
completionDetails: ICompletionDetail[];
addCompletion(_: { node: Node; result: CompletionRecord }): void;
reset(): void;
} = {
completionDetails: [],
addCompletion({ node, result }) {
const { start, end } = node;
const {
Type: completionType,
Value: completionValue,
Target: completionTarget,
} = result;
const completionValueString: string = inspect(completionValue);
const completionTargetString: string | undefined =
completionTarget !== undefined
? inspect(completionTarget)
: completionTarget;
const obj = {
start,
end,
completionType,
completionValueString,
completionTargetString,
completionValue,
};
this.completionDetails.push(obj);
},
reset() {
this.completionDetails = [];
},
};