summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-05-02 17:55:59 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-05-02 17:55:59 +0900
commit2d1f50303d3fe8aa95d8d803e36b5ca00f4523a8 (patch)
tree154e74549d18fad8ad1390edc052f94cfc684e9d /src/misc
parent11.8.1 (diff)
downloadsharkey-2d1f50303d3fe8aa95d8d803e36b5ca00f4523a8.tar.gz
sharkey-2d1f50303d3fe8aa95d8d803e36b5ca00f4523a8.tar.bz2
sharkey-2d1f50303d3fe8aa95d8d803e36b5ca00f4523a8.zip
Improve MisskeyPages
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/aiscript/evaluator.ts100
1 files changed, 50 insertions, 50 deletions
diff --git a/src/misc/aiscript/evaluator.ts b/src/misc/aiscript/evaluator.ts
index fef2d4f3a5..2bc866dc43 100644
--- a/src/misc/aiscript/evaluator.ts
+++ b/src/misc/aiscript/evaluator.ts
@@ -7,56 +7,6 @@ type Fn = {
exec: (args: Record<string, any>) => ReturnType<ASEvaluator['evaluate']>;
};
-class AiScriptError extends Error {
- public info?: any;
-
- constructor(message: string, info?: any) {
- super(message);
-
- this.info = info;
-
- // Maintains proper stack trace for where our error was thrown (only available on V8)
- if (Error.captureStackTrace) {
- Error.captureStackTrace(this, AiScriptError);
- }
- }
-}
-
-class Scope {
- private layerdStates: Record<string, any>[];
- public name: string;
-
- constructor(layerdStates: Scope['layerdStates'], name?: Scope['name']) {
- this.layerdStates = layerdStates;
- this.name = name || 'anonymous';
- }
-
- @autobind
- public createChildScope(states: Record<string, any>, name?: Scope['name']): Scope {
- const layer = [states, ...this.layerdStates];
- return new Scope(layer, name);
- }
-
- /**
- * 指定した名前の変数の値を取得します
- * @param name 変数名
- */
- @autobind
- public getState(name: string): any {
- for (const later of this.layerdStates) {
- const state = later[name];
- if (state !== undefined) {
- return state;
- }
- }
-
- throw new AiScriptError(
- `No such variable '${name}' in scope '${this.name}'`, {
- scope: this.layerdStates
- });
- }
-}
-
/**
* AiScript evaluator
*/
@@ -238,3 +188,53 @@ export class ASEvaluator {
}
}
}
+
+class AiScriptError extends Error {
+ public info?: any;
+
+ constructor(message: string, info?: any) {
+ super(message);
+
+ this.info = info;
+
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
+ if (Error.captureStackTrace) {
+ Error.captureStackTrace(this, AiScriptError);
+ }
+ }
+}
+
+class Scope {
+ private layerdStates: Record<string, any>[];
+ public name: string;
+
+ constructor(layerdStates: Scope['layerdStates'], name?: Scope['name']) {
+ this.layerdStates = layerdStates;
+ this.name = name || 'anonymous';
+ }
+
+ @autobind
+ public createChildScope(states: Record<string, any>, name?: Scope['name']): Scope {
+ const layer = [states, ...this.layerdStates];
+ return new Scope(layer, name);
+ }
+
+ /**
+ * 指定した名前の変数の値を取得します
+ * @param name 変数名
+ */
+ @autobind
+ public getState(name: string): any {
+ for (const later of this.layerdStates) {
+ const state = later[name];
+ if (state !== undefined) {
+ return state;
+ }
+ }
+
+ throw new AiScriptError(
+ `No such variable '${name}' in scope '${this.name}'`, {
+ scope: this.layerdStates
+ });
+ }
+}