Skip to content

Commit

Permalink
style: run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Aug 4, 2023
1 parent 129ff0d commit e7aac22
Show file tree
Hide file tree
Showing 46 changed files with 89 additions and 94 deletions.
14 changes: 7 additions & 7 deletions src/interpreter/environment/create-sanitized-environment.ts
Expand Up @@ -14,7 +14,7 @@ import {ProcessError} from "../error/policy-error/process-error/process-error.js
import {isProcessSpawnChildOperation} from "../policy/process/is-process-spawn-child-operation.js";
import type {ICreateSanitizedEnvironmentOptions} from "./i-create-sanitized-environment-options.js";
import {isConsoleOperation} from "../policy/console/is-console-operation.js";
import { EvaluationErrorIntent } from "../error/evaluation-error/evaluation-error-intent.js";
import {EvaluationErrorIntent} from "../error/evaluation-error/evaluation-error-intent.js";

/**
* Creates an environment that provide hooks into policy checks
Expand All @@ -27,27 +27,27 @@ export function createSanitizedEnvironment({policy, env}: ICreateSanitizedEnviro
}

if (!policy.io.read && isIoRead(item)) {
return new EvaluationErrorIntent((node, options) => new IoError({...options, node, kind: "read"}));
return new EvaluationErrorIntent((node, options) => new IoError({...options, node, kind: "read"}));
}

if (!policy.io.write && isIoWrite(item)) {
return new EvaluationErrorIntent((node, options) => new IoError({...options, node, kind: "write"}));
return new EvaluationErrorIntent((node, options) => new IoError({...options, node, kind: "write"}));
}

if (!policy.process.exit && isProcessExitOperation(item)) {
return new EvaluationErrorIntent((node, options) => new ProcessError({...options, node, kind: "exit"}));
return new EvaluationErrorIntent((node, options) => new ProcessError({...options, node, kind: "exit"}));
}

if (!policy.process.exit && isProcessSpawnChildOperation(item)) {
return new EvaluationErrorIntent((node, options) => new ProcessError({...options, node, kind: "spawnChild"}));
return new EvaluationErrorIntent((node, options) => new ProcessError({...options, node, kind: "spawnChild"}));
}

if (!policy.network && isNetworkOperation(item)) {
return new EvaluationErrorIntent((node, options) => new NetworkError({...options, node, operation: stringifyPolicyTrapKindOnPath(item.kind, item.path)}));
return new EvaluationErrorIntent((node, options) => new NetworkError({...options, node, operation: stringifyPolicyTrapKindOnPath(item.kind, item.path)}));
}

if (policy.deterministic && isNonDeterministic(item)) {
return new EvaluationErrorIntent((node, options) => new NonDeterministicError({...options, node, operation: stringifyPolicyTrapKindOnPath(item.kind, item.path)}));
return new EvaluationErrorIntent((node, options) => new NonDeterministicError({...options, node, operation: stringifyPolicyTrapKindOnPath(item.kind, item.path)}));
}

return true;
Expand Down
6 changes: 3 additions & 3 deletions src/interpreter/error/evaluation-error/evaluation-error.ts
@@ -1,6 +1,6 @@
import type {IEvaluationErrorOptions} from "./i-evaluation-error-options.js";
import type {TS} from "../../../type/ts.js";
import type { LexicalEnvironment } from "../../lexical-environment/lexical-environment.js";
import type {LexicalEnvironment} from "../../lexical-environment/lexical-environment.js";

export type ThrowError = (error: EvaluationError) => EvaluationError;

Expand All @@ -22,6 +22,6 @@ export class EvaluationError extends Error {
}
}

export function isEvaluationError (item: unknown): item is EvaluationError {
export function isEvaluationError(item: unknown): item is EvaluationError {
return typeof item === "object" && item != null && item instanceof EvaluationError;
}
}
@@ -1,5 +1,5 @@
import type {TS} from "../../../type/ts.js";
import type { LexicalEnvironment } from "../../lexical-environment/lexical-environment.js";
import type {LexicalEnvironment} from "../../lexical-environment/lexical-environment.js";

export interface IEvaluationErrorOptions {
node: TS.Node;
Expand Down
@@ -1,7 +1,7 @@
import {EvaluationError} from "../evaluation-error/evaluation-error.js";
import type {INotCallableErrorOptions} from "./i-not-callable-error-options.js";
import type {Literal} from "../../literal/literal.js";
import { stringifyLiteral} from "../../literal/literal.js";
import {stringifyLiteral} from "../../literal/literal.js";

/**
* An Error that can be thrown when a value is attempted to be called, but isn't callable
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/evaluate.ts
Expand Up @@ -10,7 +10,7 @@ import {createStatementTraversalStack} from "./stack/traversal-stack/statement-t
import {isExpression} from "./util/expression/is-expression.js";
import type {Literal} from "./literal/literal.js";
import {isStatement} from "./util/statement/is-statement.js";
import type { Stack} from "./stack/stack.js";
import type {Stack} from "./stack/stack.js";
import {createStack} from "./stack/stack.js";
import {isDeclaration} from "./util/declaration/is-declaration.js";
import {UnexpectedNodeError} from "./error/unexpected-node-error/unexpected-node-error.js";
Expand All @@ -19,7 +19,7 @@ import {reportError} from "./util/reporting/report-error.js";
import {createReportedErrorSet} from "./reporting/reported-error-set.js";
import type {ReportingOptionsSanitized} from "./reporting/i-reporting-options.js";
import type {EvaluationError, ThrowError} from "./error/evaluation-error/evaluation-error.js";
import type { ICreateNodeEvaluatorOptions } from "./evaluator/node-evaluator/i-create-node-evaluator-options.js";
import type {ICreateNodeEvaluatorOptions} from "./evaluator/node-evaluator/i-create-node-evaluator-options.js";
/**
* Will get a literal value for the given Expression, ExpressionStatement, or Declaration.
*/
Expand Down
@@ -1,5 +1,5 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type { LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {getFromLexicalEnvironment, pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import type {Literal} from "../literal/literal.js";
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/evaluator/evaluate-block.ts
@@ -1,6 +1,6 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import { pathInLexicalEnvironmentEquals} from "../lexical-environment/lexical-environment.js";
import {pathInLexicalEnvironmentEquals} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import {BREAK_SYMBOL} from "../util/break/break-symbol.js";
import {CONTINUE_SYMBOL} from "../util/continue/continue-symbol.js";
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/evaluator/evaluate-call-expression.ts
@@ -1,5 +1,5 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type { Literal} from "../literal/literal.js";
import type {Literal} from "../literal/literal.js";
import {isLazyCall} from "../literal/literal.js";
import {NotCallableError} from "../error/not-callable-error/not-callable-error.js";
import {getFromLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
Expand Down
@@ -1,6 +1,6 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import { pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import type {IndexLiteral, Literal} from "../literal/literal.js";
import {evaluateParameterDeclarations} from "./evaluate-parameter-declarations.js";
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/evaluator/evaluate-decorator.ts
@@ -1,6 +1,6 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {IndexLiteral} from "../literal/literal.js";
import { stringifyLiteral} from "../literal/literal.js";
import {stringifyLiteral} from "../literal/literal.js";
import {NotCallableError} from "../error/not-callable-error/not-callable-error.js";
import type {TS} from "../../type/ts.js";
import {__decorate, __param} from "../util/tslib/tslib-util.js";
Expand Down
@@ -1,6 +1,6 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {IndexLiteral, IndexLiteralKey, LazyCall, Literal} from "../literal/literal.js";
import { LAZY_CALL_FLAG, LiteralFlagKind} from "../literal/literal.js";
import {LAZY_CALL_FLAG, LiteralFlagKind} from "../literal/literal.js";
import {isBindCallApply} from "../util/function/is-bind-call-apply.js";
import type {TS} from "../../type/ts.js";
import {maybeThrow} from "../error/evaluation-error/evaluation-error-intent.js";
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/evaluator/evaluate-function-declaration.ts
@@ -1,5 +1,5 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type { LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {getFromLexicalEnvironment, pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import type {Literal} from "../literal/literal.js";
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/evaluator/evaluate-function-expression.ts
@@ -1,5 +1,5 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type { LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {getFromLexicalEnvironment, pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import type {Literal} from "../literal/literal.js";
Expand Down
@@ -1,6 +1,6 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import { pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import type {IndexLiteral, IndexLiteralKey, Literal} from "../literal/literal.js";
import {THIS_SYMBOL} from "../util/this/this-symbol.js";
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/evaluator/evaluate-method-declaration.ts
@@ -1,5 +1,5 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type { LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {getFromLexicalEnvironment, pathInLexicalEnvironmentEquals, setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import type {IndexLiteral, IndexLiteralKey, Literal} from "../literal/literal.js";
Expand Down
@@ -1,6 +1,6 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {IndexLiteral, LazyCall, Literal} from "../literal/literal.js";
import { LAZY_CALL_FLAG, LiteralFlagKind} from "../literal/literal.js";
import {LAZY_CALL_FLAG, LiteralFlagKind} from "../literal/literal.js";
import {isBindCallApply} from "../util/function/is-bind-call-apply.js";
import type {TS} from "../../type/ts.js";
import {maybeThrow} from "../error/evaluation-error/evaluation-error-intent.js";
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/evaluator/evaluate-property-declaration.ts
Expand Up @@ -2,7 +2,7 @@ import type {EvaluatorOptions} from "./evaluator-options.js";
import type {IndexLiteral, IndexLiteralKey} from "../literal/literal.js";
import {inStaticContext} from "../util/static/in-static-context.js";
import type {TS} from "../../type/ts.js";
import { canHaveDecorators, getDecorators } from "../util/node/modifier-util.js";
import {canHaveDecorators, getDecorators} from "../util/node/modifier-util.js";

/**
* Evaluates, or attempts to evaluate, a PropertyDeclaration, before applying it on the given parent
Expand Down
@@ -1,6 +1,6 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {LexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import { setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {setInLexicalEnvironment} from "../lexical-environment/lexical-environment.js";
import {cloneLexicalEnvironment} from "../lexical-environment/clone-lexical-environment.js";
import type {IndexLiteral, IndexLiteralKey, Literal} from "../literal/literal.js";
import {THIS_SYMBOL} from "../util/this/this-symbol.js";
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/evaluator/evaluate-spread-assignment.ts
Expand Up @@ -7,10 +7,10 @@ import type {TS} from "../../type/ts.js";
*/
export function evaluateSpreadAssignment({node, evaluate, ...options}: EvaluatorOptions<TS.SpreadAssignment>, parent: IndexLiteral): void {
const entries = evaluate.expression(node.expression, options) as IndexLiteral;

if (options.getCurrentError() != null) {
return;
}

Object.assign(parent, entries);
}
6 changes: 3 additions & 3 deletions src/interpreter/evaluator/evaluate-throw-statement.ts
@@ -1,14 +1,14 @@
import type {EvaluatorOptions} from "./evaluator-options.js";
import type {TS} from "../../type/ts.js";
import type { EvaluationError } from "../error/evaluation-error/evaluation-error.js";
import type {EvaluationError} from "../error/evaluation-error/evaluation-error.js";

/**
* Evaluates, or attempts to evaluate, a ThrowStatement
*/
export function evaluateThrowStatement({node, evaluate, ...options}: EvaluatorOptions<TS.ThrowStatement>): void|EvaluationError {
export function evaluateThrowStatement({node, evaluate, ...options}: EvaluatorOptions<TS.ThrowStatement>): void | EvaluationError {
const {getCurrentError, throwError} = options;
const result = evaluate.expression(node.expression, options) as EvaluationError;

if (getCurrentError() != null) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/evaluator/evaluate-variable-declaration.ts
Expand Up @@ -27,10 +27,10 @@ export function evaluateVariableDeclaration(options: EvaluatorOptions<TS.Variabl

// Evaluate the binding name
evaluate.nodeWithArgument(node.name, initializerResult, options);

if (getCurrentError() != null) {
return;
}

stack.push(initializerResult);
}
3 changes: 1 addition & 2 deletions src/interpreter/evaluator/evaluator-options.ts
Expand Up @@ -12,9 +12,8 @@ export interface NextEvaluatorOptions {
environment: LexicalEnvironment;
moduleOverrides?: Record<string, unknown>;
throwError: ThrowError;
getCurrentError (): EvaluationError|undefined;
getCurrentError(): EvaluationError | undefined;
statementTraversalStack: StatementTraversalStack;

}

export interface EvaluatorOptions<T extends TS.Node | TS.NodeArray<TS.Node>> extends NextEvaluatorOptions {
Expand Down
Expand Up @@ -10,8 +10,8 @@ import {evaluateNodeWithValue} from "../evaluate-node-with-value.js";
import {createStatementTraversalStack} from "../../stack/traversal-stack/statement-traversal-stack.js";
import type {TS} from "../../../type/ts.js";
import type {EvaluationError} from "../../error/evaluation-error/evaluation-error.js";
import { isEvaluationError} from "../../error/evaluation-error/evaluation-error.js";
import type { Literal } from "../../literal/literal.js";
import {isEvaluationError} from "../../error/evaluation-error/evaluation-error.js";
import type {Literal} from "../../literal/literal.js";

/**
* Creates a Node Evaluator
Expand Down Expand Up @@ -50,7 +50,6 @@ export function createNodeEvaluator(options: ICreateNodeEvaluatorOptions): NodeE
};

const evaluate: NodeEvaluator = {

statement: (node, nextOptions): void => {
const combinedNextOptions = {...nextOptions, statementTraversalStack: createStatementTraversalStack()};
const prequalifyResult = prequalifyNextNode(node, combinedNextOptions);
Expand All @@ -73,14 +72,14 @@ export function createNodeEvaluator(options: ICreateNodeEvaluatorOptions): NodeE
}
return evaluateNodeWithArgument(getEvaluatorOptions(node, nextOptions), arg);
},
expression: (node, nextOptions): Literal|EvaluationError => {
expression: (node, nextOptions): Literal | EvaluationError => {
const prequalifyResult = prequalifyNextNode(node, nextOptions);
if (isEvaluationError(prequalifyResult)) {
return prequalifyResult;
}
return evaluateExpression(getEvaluatorOptions(node, nextOptions));
},
nodeWithValue: (node, nextOptions): Literal|EvaluationError => {
nodeWithValue: (node, nextOptions): Literal | EvaluationError => {
const prequalifyResult = prequalifyNextNode(node, nextOptions);
if (isEvaluationError(prequalifyResult)) {
return prequalifyResult;
Expand Down
Expand Up @@ -3,9 +3,9 @@ import type {Stack} from "../../stack/stack.js";
import type {EvaluatePolicySanitized} from "../../policy/evaluate-policy.js";
import type {ReportingOptionsSanitized} from "../../reporting/i-reporting-options.js";
import type {TS} from "../../../type/ts.js";
import type { EvaluationError, ThrowError } from "../../error/evaluation-error/evaluation-error.js";
import type { LexicalEnvironment } from "../../lexical-environment/lexical-environment.js";
import type { StatementTraversalStack } from "../../stack/traversal-stack/statement-traversal-stack.js";
import type {EvaluationError, ThrowError} from "../../error/evaluation-error/evaluation-error.js";
import type {LexicalEnvironment} from "../../lexical-environment/lexical-environment.js";
import type {StatementTraversalStack} from "../../stack/traversal-stack/statement-traversal-stack.js";

export interface ICreateNodeEvaluatorOptions {
typeChecker?: TS.TypeChecker;
Expand All @@ -18,5 +18,5 @@ export interface ICreateNodeEvaluatorOptions {
statementTraversalStack: StatementTraversalStack;
environment: LexicalEnvironment;
throwError: ThrowError;
getCurrentError (): EvaluationError|undefined;
getCurrentError(): EvaluationError | undefined;
}
8 changes: 4 additions & 4 deletions src/interpreter/evaluator/node-evaluator/node-evaluator.ts
@@ -1,15 +1,15 @@
import type {Literal} from "../../literal/literal.js";
import type {TS} from "../../../type/ts.js";
import type { NextEvaluatorOptions } from "../evaluator-options.js";
import type { EvaluationError } from "../../error/evaluation-error/evaluation-error.js";
import type {NextEvaluatorOptions} from "../evaluator-options.js";
import type {EvaluationError} from "../../error/evaluation-error/evaluation-error.js";

export type NodeWithValue = TS.PropertyName;

export type StatementEvaluator = (node: TS.Statement, nextOptions: NextEvaluatorOptions) => void;
export type DeclarationEvaluator = (node: TS.Declaration, nextOptions: NextEvaluatorOptions) => void;
export type NodeEvaluatorWithArgument = (node: TS.Node, arg: Literal, nextOptions: NextEvaluatorOptions) => void;
export type ExpressionEvaluator = (node: TS.Expression | TS.PrivateIdentifier, nextOptions: NextEvaluatorOptions) => Literal|EvaluationError;
export type NodeWithValueEvaluator = (node: NodeWithValue, nextOptions: NextEvaluatorOptions) => Literal|EvaluationError;
export type ExpressionEvaluator = (node: TS.Expression | TS.PrivateIdentifier, nextOptions: NextEvaluatorOptions) => Literal | EvaluationError;
export type NodeWithValueEvaluator = (node: NodeWithValue, nextOptions: NextEvaluatorOptions) => Literal | EvaluationError;

export interface NodeEvaluator {
statement: StatementEvaluator;
Expand Down
@@ -1,4 +1,4 @@
import type { TS } from "../../type/ts.js";
import type {TS} from "../../type/ts.js";
import type {LexicalEnvironment} from "./lexical-environment.js";

/**
Expand All @@ -7,7 +7,7 @@ import type {LexicalEnvironment} from "./lexical-environment.js";
export function cloneLexicalEnvironment(environment: LexicalEnvironment, startingNode: TS.Node): LexicalEnvironment {
return {
parentEnv: environment,
startingNode,
startingNode,
env: {}
};
}
@@ -1,6 +1,6 @@
import type {IEnvironment} from "../environment/i-environment.js";
import type {EvaluatePolicySanitized} from "../policy/evaluate-policy.js";
import type { TS } from "../../type/ts.js";
import type {TS} from "../../type/ts.js";

export interface ICreateLexicalEnvironmentOptions {
startingNode: TS.Node;
Expand Down

0 comments on commit e7aac22

Please sign in to comment.