diff --git a/etc/aiscript.api.md b/etc/aiscript.api.md index a24367a7..6ca83a88 100644 --- a/etc/aiscript.api.md +++ b/etc/aiscript.api.md @@ -671,7 +671,7 @@ type Return = NodeBase & { // @public (undocumented) export class Scope { - constructor(layerdStates?: Scope['layerdStates'], parent?: Scope, name?: Scope['name'], nsName?: string); + constructor(layeredStates?: Scope['layeredStates'], parent?: Scope, name?: Scope['name'], nsName?: string); add(name: string, variable: Variable): void; assign(name: string, val: Value): void; // (undocumented) diff --git a/src/interpreter/scope.ts b/src/interpreter/scope.ts index a9c37dc8..c6640c49 100644 --- a/src/interpreter/scope.ts +++ b/src/interpreter/scope.ts @@ -4,11 +4,11 @@ import type { Value } from './value.js'; import type { Variable } from './variable.js'; import type { LogObject } from './index.js'; -export type LayerdStates = [Map, ...Map[]] +export type LayeredStates = [Map, ...Map[]] export class Scope { private parent?: Scope; - private layerdStates: LayerdStates; + private layeredStates: LayeredStates; public name: string; public opts: { log?(type: string, params: LogObject): void; @@ -16,10 +16,10 @@ export class Scope { } = {}; public nsName?: string; - constructor(layerdStates: Scope['layerdStates'] = [new Map()], parent?: Scope, name?: Scope['name'], nsName?: string) { - this.layerdStates = layerdStates; + constructor(layeredStates: Scope['layeredStates'] = [new Map()], parent?: Scope, name?: Scope['name'], nsName?: string) { + this.layeredStates = layeredStates; this.parent = parent; - this.name = name || (layerdStates.length === 1 ? '' : ''); + this.name = name || (layeredStates.length === 1 ? '' : ''); this.nsName = nsName; } @@ -43,13 +43,13 @@ export class Scope { @autobind public createChildScope(states: Map = new Map(), name?: Scope['name']): Scope { - const layer: LayerdStates = [states, ...this.layerdStates]; + const layer: LayeredStates = [states, ...this.layeredStates]; return new Scope(layer, this, name); } @autobind public createChildNamespaceScope(nsName: string, states: Map = new Map(), name?: Scope['name']): Scope { - const layer: LayerdStates = [states, ...this.layerdStates]; + const layer: LayeredStates = [states, ...this.layeredStates]; return new Scope(layer, this, name, nsName); } @@ -59,7 +59,7 @@ export class Scope { */ @autobind public get(name: string): Value { - for (const layer of this.layerdStates) { + for (const layer of this.layeredStates) { const value = layer.get(name); if (value) { const state = value.value; @@ -70,7 +70,7 @@ export class Scope { throw new AiScriptRuntimeError( `No such variable '${name}' in scope '${this.name}'`, - { scope: this.layerdStates }); + { scope: this.layeredStates }); } /** @@ -88,7 +88,7 @@ export class Scope { */ @autobind public exists(name: string): boolean { - for (const layer of this.layerdStates) { + for (const layer of this.layeredStates) { if (layer.has(name)) { this.log('exists', { var: name }); return true; @@ -104,7 +104,7 @@ export class Scope { */ @autobind public getAll(): Map { - const vars = this.layerdStates.reduce((arr, layer) => { + const vars = this.layeredStates.reduce((arr, layer) => { return [...arr, ...layer]; }, [] satisfies [string, Variable][]); return new Map(vars); @@ -118,11 +118,11 @@ export class Scope { @autobind public add(name: string, variable: Variable): void { this.log('add', { var: name, val: variable }); - const states = this.layerdStates[0]; + const states = this.layeredStates[0]; if (states.has(name)) { throw new AiScriptRuntimeError( `Variable '${name}' already exists in scope '${this.name}'`, - { scope: this.layerdStates }); + { scope: this.layeredStates }); } states.set(name, variable); if (this.parent == null) this.onUpdated(name, variable.value); @@ -137,7 +137,7 @@ export class Scope { @autobind public assign(name: string, val: Value): void { let i = 1; - for (const layer of this.layerdStates) { + for (const layer of this.layeredStates) { const variable = layer.get(name); if (variable != null) { if (!variable.isMutable) { @@ -147,7 +147,7 @@ export class Scope { variable.value = val; this.log('assign', { var: name, val: val }); - if (i === this.layerdStates.length) this.onUpdated(name, val); + if (i === this.layeredStates.length) this.onUpdated(name, val); return; } i++; @@ -155,6 +155,6 @@ export class Scope { throw new AiScriptRuntimeError( `No such variable '${name}' in scope '${this.name}'`, - { scope: this.layerdStates }); + { scope: this.layeredStates }); } }