[LIQ] group by: Convert plain JS objects to LuaTable in results
Items from `index.tag` are stored as plain JS objects when no metatable is defined. The `group by` clause wraps rows in `LuaTable` (`key`, `group`) but leaves the individual `group` items as plain JS objects. This causes `t.keys is not a function` errors when passing `row.group` to APIs like `template.each` that expect `LuaTable` instances. Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
This commit is contained in:
@@ -12,6 +12,7 @@ import type {
|
||||
} from "./ast.ts";
|
||||
|
||||
import {
|
||||
jsToLuaValue,
|
||||
luaCall,
|
||||
LuaEnv,
|
||||
LuaFunction,
|
||||
@@ -730,7 +731,14 @@ export async function applyQuery(
|
||||
for (const { key, items } of groups.values()) {
|
||||
const groupTable = new LuaTable();
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
groupTable.rawSetArrayIndex(i + 1, items[i]);
|
||||
const item = items[i];
|
||||
groupTable.rawSetArrayIndex(
|
||||
i + 1,
|
||||
(item instanceof LuaTable || typeof item !== "object" ||
|
||||
item === null)
|
||||
? item
|
||||
: jsToLuaValue(item),
|
||||
);
|
||||
}
|
||||
const row = new LuaTable();
|
||||
row.rawSet("key", key);
|
||||
|
||||
Reference in New Issue
Block a user