Removed x not found, set to 0 info messages from parser
This commit is contained in:
@@ -3,7 +3,7 @@ import constant from './constant.js';
|
|||||||
import { toString } from '../resolve.js';
|
import { toString } from '../resolve.js';
|
||||||
|
|
||||||
const accessor = {
|
const accessor = {
|
||||||
create({name, path}) {
|
create({ name, path }) {
|
||||||
return {
|
return {
|
||||||
parseType: 'accessor',
|
parseType: 'accessor',
|
||||||
path,
|
path,
|
||||||
@@ -19,12 +19,12 @@ const accessor = {
|
|||||||
});
|
});
|
||||||
let valueType = Array.isArray(value) ? 'array' : typeof value;
|
let valueType = Array.isArray(value) ? 'array' : typeof value;
|
||||||
// If the accessor returns an objet, get the object's value instead
|
// If the accessor returns an objet, get the object's value instead
|
||||||
while (valueType === 'object'){
|
while (valueType === 'object') {
|
||||||
value = value.value;
|
value = value.value;
|
||||||
valueType = Array.isArray(value) ? 'array' : typeof value;
|
valueType = Array.isArray(value) ? 'array' : typeof value;
|
||||||
}
|
}
|
||||||
// Return a parse node based on the type returned
|
// Return a parse node based on the type returned
|
||||||
if (valueType === 'string' || valueType === 'number' || valueType === 'boolean'){
|
if (valueType === 'string' || valueType === 'number' || valueType === 'boolean') {
|
||||||
return {
|
return {
|
||||||
result: constant.create({
|
result: constant.create({
|
||||||
value,
|
value,
|
||||||
@@ -65,10 +65,9 @@ const accessor = {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
reduce(node, scope, context){
|
reduce(node, scope, context) {
|
||||||
let { result } = accessor.compile(node, scope, context);
|
let { result } = accessor.compile(node, scope, context);
|
||||||
if (result.parseType === 'accessor'){
|
if (result.parseType === 'accessor') {
|
||||||
context.error(`${toString(result)} not found, set to 0`);
|
|
||||||
return {
|
return {
|
||||||
result: constant.create({
|
result: constant.create({
|
||||||
value: 0,
|
value: 0,
|
||||||
@@ -76,10 +75,10 @@ const accessor = {
|
|||||||
context
|
context
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {result, context};
|
return { result, context };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toString(node){
|
toString(node) {
|
||||||
return `${node.name}.${node.path.join('.')}`;
|
return `${node.name}.${node.path.join('.')}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,58 +2,54 @@ import resolve, { toString } from '../resolve.js';
|
|||||||
import constant from './constant.js';
|
import constant from './constant.js';
|
||||||
|
|
||||||
const symbol = {
|
const symbol = {
|
||||||
create({name}){
|
create({ name }) {
|
||||||
return {
|
return {
|
||||||
parseType: 'symbol',
|
parseType: 'symbol',
|
||||||
name,
|
name,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
toString(node){
|
toString(node) {
|
||||||
return `${node.name}`
|
return `${node.name}`
|
||||||
},
|
},
|
||||||
compile(node, scope, context, calledFromReduce = false){
|
compile(node, scope, context, calledFromReduce = false) {
|
||||||
let value = scope && scope[node.name];
|
let value = scope && scope[node.name];
|
||||||
let type = typeof value;
|
let type = typeof value;
|
||||||
// For objects, default to their .value
|
// For objects, default to their .value
|
||||||
if (type === 'object'){
|
if (type === 'object') {
|
||||||
value = value.value;
|
value = value.value;
|
||||||
type = typeof value;
|
type = typeof value;
|
||||||
}
|
}
|
||||||
// For parse nodes, compile and return
|
// For parse nodes, compile and return
|
||||||
if (value?.parseType){
|
if (value?.parseType) {
|
||||||
if (calledFromReduce){
|
if (calledFromReduce) {
|
||||||
return resolve('reduce', value, scope, context);
|
return resolve('reduce', value, scope, context);
|
||||||
} else {
|
} else {
|
||||||
return resolve('compile', value, scope, context);
|
return resolve('compile', value, scope, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type === 'string' || type === 'number' || type === 'boolean'){
|
if (type === 'string' || type === 'number' || type === 'boolean') {
|
||||||
return {
|
return {
|
||||||
result: constant.create({value}),
|
result: constant.create({ value }),
|
||||||
context,
|
context,
|
||||||
};
|
};
|
||||||
} else if (type === 'undefined'){
|
} else if (type === 'undefined') {
|
||||||
return {
|
return {
|
||||||
result: symbol.create({name: node.name}),
|
result: symbol.create({ name: node.name }),
|
||||||
context,
|
context,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
throw new Meteor.Error(`Unexpected case: ${node.name} resolved to ${value}`);
|
throw new Meteor.Error(`Unexpected case: ${node.name} resolved to ${value}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
reduce(node, scope, context){
|
reduce(node, scope, context) {
|
||||||
let {result} = symbol.compile(node, scope, context, true);
|
let { result } = symbol.compile(node, scope, context, true);
|
||||||
if (result.parseType === 'symbol'){
|
if (result.parseType === 'symbol') {
|
||||||
context.error({
|
|
||||||
type: 'info',
|
|
||||||
message: `${toString(result)} not found, set to 0`
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
result: constant.create({value: 0}),
|
result: constant.create({ value: 0 }),
|
||||||
context,
|
context,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {result, context};
|
return { result, context };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user