mirror of
https://github.com/bendtherules/completion-viz.git
synced 2026-08-19 00:31:34 +00:00
Add basic CompletionMapping and runEngine code
This commit is contained in:
@@ -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 = [];
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user