MCPcopy Create free account
hub / github.com/aiscript-dev/aiscript / define

Method define

src/interpreter/index.ts:1686–1710  ·  view source on GitHub ↗
(scope: Scope, dest: Ast.Expression, value: Value, isMutable: boolean)

Source from the content-addressed store, hash-verified

1684
1685 @autobind
1686 private define(scope: Scope, dest: Ast.Expression, value: Value, isMutable: boolean): void {
1687 switch (dest.type) {
1688 case 'identifier': {
1689 scope.add(dest.name, { isMutable, value });
1690 break;
1691 }
1692 case 'arr': {
1693 assertArray(value);
1694 dest.value.map(
1695 (item, index) => this.define(scope, item, value.value[index] ?? NULL, isMutable),
1696 );
1697 break;
1698 }
1699 case 'obj': {
1700 assertObject(value);
1701 [...dest.value].map(
1702 ([key, item]) => this.define(scope, item, value.value.get(key) ?? NULL, isMutable),
1703 );
1704 break;
1705 }
1706 default: {
1707 throw new AiScriptRuntimeError('The left-hand side of an definition expression must be a variable.');
1708 }
1709 }
1710 }
1711
1712 @autobind
1713 private async getReference(dest: Ast.Expression, scope: Scope, callStack: readonly CallInfo[]): Promise<Reference | Control> {

Callers 6

collectNsMemberMethod · 0.95
collectNsMemberSyncMethod · 0.95
_fnMethod · 0.95
_fnSyncMethod · 0.95
__evalMethod · 0.95
__evalSyncMethod · 0.95

Calls 4

assertArrayFunction · 0.85
assertObjectFunction · 0.85
addMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected