From 3a18bce7e6890d009592b887530e45e2a91cade4 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Sun, 1 May 2022 22:54:30 +0200 Subject: [PATCH] Added error message for unsupported accessors --- app/imports/parser/parseTree/accessor.js | 26 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/imports/parser/parseTree/accessor.js b/app/imports/parser/parseTree/accessor.js index 64ef1ba9..920e1e6b 100644 --- a/app/imports/parser/parseTree/accessor.js +++ b/app/imports/parser/parseTree/accessor.js @@ -1,4 +1,5 @@ import constant from './constant.js'; +// import array from './array.js'; import { toString } from '../resolve.js'; const accessor = { @@ -9,18 +10,18 @@ const accessor = { name, }; }, - compile(node, scope, context){ + compile(node, scope, context) { let value = scope && scope[node.name]; // For objects, get their value node.path.forEach(name => { if (value === undefined) return; value = value[name]; }); - let valueType = typeof value; + let valueType = Array.isArray(value) ? 'array' : typeof value; // If the accessor returns an objet, get the object's value instead while (valueType === 'object'){ value = value.value; - valueType = typeof value; + valueType = Array.isArray(value) ? 'array' : typeof value; } // Return a parse node based on the type returned if (valueType === 'string' || valueType === 'number' || valueType === 'boolean'){ @@ -31,7 +32,21 @@ const accessor = { }), context, }; - } else if (valueType === 'undefined'){ + } + /* Can't access #object.tags until this is fixed + * If we activate this, the array node expects values to be an array of + * parse nodes, so it will break unless the values are coerced here or at + * in the array node's code to be parse nodes, not raw js + else if (valueType === 'array') { + return { + result: array.create({ + values: value, + }), + context, + }; + } + */ + else if (valueType === 'undefined') { return { result: accessor.create({ name: node.name, @@ -40,8 +55,7 @@ const accessor = { context, }; } else { - context.error(`${node.name} returned an unexpected type`); - context.error(JSON.stringify(value, null, 2)); + context.error(`Accessing ${accessor.toString(node)} is not supported yet`); return { result: accessor.create({ name: node.name,