From 2d1f50303d3fe8aa95d8d803e36b5ca00f4523a8 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 2 May 2019 17:55:59 +0900 Subject: Improve MisskeyPages --- src/misc/aiscript/evaluator.ts | 100 ++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'src/misc') 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) => ReturnType; }; -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[]; - public name: string; - - constructor(layerdStates: Scope['layerdStates'], name?: Scope['name']) { - this.layerdStates = layerdStates; - this.name = name || 'anonymous'; - } - - @autobind - public createChildScope(states: Record, 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[]; + public name: string; + + constructor(layerdStates: Scope['layerdStates'], name?: Scope['name']) { + this.layerdStates = layerdStates; + this.name = name || 'anonymous'; + } + + @autobind + public createChildScope(states: Record, 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 + }); + } +} -- cgit v1.2.3-freya