(dest: Ast.Expression, scope: Scope, callStack: readonly CallInfo[])
| 1773 | |
| 1774 | @autobind |
| 1775 | private getReferenceSync(dest: Ast.Expression, scope: Scope, callStack: readonly CallInfo[]): Reference | Control { |
| 1776 | switch (dest.type) { |
| 1777 | case 'identifier': { |
| 1778 | return Reference.variable(dest.name, scope); |
| 1779 | } |
| 1780 | case 'index': { |
| 1781 | const assignee = this._evalSync(dest.target, scope, callStack); |
| 1782 | if (isControl(assignee)) { |
| 1783 | return assignee; |
| 1784 | } |
| 1785 | const i = this._evalSync(dest.index, scope, callStack); |
| 1786 | if (isControl(i)) { |
| 1787 | return i; |
| 1788 | } |
| 1789 | if (isArray(assignee)) { |
| 1790 | assertNumber(i); |
| 1791 | return Reference.index(assignee, i.value); |
| 1792 | } else if (isObject(assignee)) { |
| 1793 | assertString(i); |
| 1794 | return Reference.prop(assignee, i.value); |
| 1795 | } else { |
| 1796 | throw new AiScriptRuntimeError(`Cannot read prop (${reprValue(i)}) of ${assignee.type}.`); |
| 1797 | } |
| 1798 | } |
| 1799 | case 'prop': { |
| 1800 | const assignee = this._evalSync(dest.target, scope, callStack); |
| 1801 | if (isControl(assignee)) { |
| 1802 | return assignee; |
| 1803 | } |
| 1804 | assertObject(assignee); |
| 1805 | |
| 1806 | return Reference.prop(assignee, dest.name); |
| 1807 | } |
| 1808 | case 'arr': { |
| 1809 | const items: Reference[] = []; |
| 1810 | for (const item of dest.value) { |
| 1811 | const ref = this.getReferenceSync(item, scope, callStack); |
| 1812 | if (isControl(ref)) { |
| 1813 | return ref; |
| 1814 | } |
| 1815 | items.push(ref); |
| 1816 | } |
| 1817 | return Reference.arr(items); |
| 1818 | } |
| 1819 | case 'obj': { |
| 1820 | const entries = new Map<string, Reference>(); |
| 1821 | for (const [key, item] of dest.value.entries()) { |
| 1822 | const ref = this.getReferenceSync(item, scope, callStack); |
| 1823 | if (isControl(ref)) { |
| 1824 | return ref; |
| 1825 | } |
| 1826 | entries.set(key, ref); |
| 1827 | } |
| 1828 | return Reference.obj(entries); |
| 1829 | } |
| 1830 | default: { |
| 1831 | throw new AiScriptRuntimeError('The left-hand side of an assignment expression must be a variable or a property/index access.'); |
| 1832 | } |
no test coverage detected