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