jetstreamapp / soql-parser-js

Javascript SOQL parser
https://jetstreamapp.github.io/soql-parser-js/
MIT License
79 stars 20 forks source link

parseQuery not working with FunctionExpressions #130

Closed gla5001 closed 3 years ago

gla5001 commented 3 years ago

Description

Not necessarily a bug (i might be doing something wrong), but I recently upgraded to version 3.0.0 and now parseQuery does not work with any FieldFunctionExpression. Locally, if I try and example from the demo site, like

import { parseQuery } from 'soql-parser-js';
const parsedQuery = parseQuery('SELECT CampaignId, AVG(Amount) avg FROM Opportunity GROUP BY CampaignId HAVING COUNT(Id, Name) > 1');

it throws an error

TypeError: ctx.functionExpression.map(...).flat is not a function
ABenassi87 commented 3 years ago

@paustint I can take a look if you want it

paustint commented 3 years ago

@gla5001 - This query is parsed correctly on the example website (https://paustint.github.io/soql-parser-js/), so it should work fine locally on the latest version.

I hadn't intentionally done this, but just realized that this library requires node version 11.0 or higher or a polyfill, but all browsers aside from IE should work because of the use of array.flat(). https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat

What environment are you working in and what version?

Codebase line: https://github.com/paustint/soql-parser-js/blob/5d8a4565a0493eef42161e8d65ff95abb4e464c5/src/parser/visitor.ts#L529

gla5001 commented 3 years ago

ah. I bet thats it. My project is running node 10.14 (which i need to upgrade as well), so that sounds like it could be this issue. I'll try upgrading and trying again. Thanks for the info @paustint.

gla5001 commented 3 years ago

Yup. That did the trick. Its working now.