Repository: paustint/soql-parser-js (ts)

Issue:
The field Format fails if it is in a query
<!--
  Please include the following classification.
  If your classification is not added, you can modify the list below
-->
- [ ] Feature
- [x] Bug Request

<!--If this is a bug, please include the steps to reproduce the bug-->
## Description
For AuraDefinitionBundle, there is a field named FORMAT which is incorrectly.

Example:
```sql
SELECT Id, CreatedById, CreatedDate, DefType, IsDeleted, Format,
	LastModifiedById, LastModifiedDate, AuraDefinitionBundleId, ManageableState,
	Source, SystemModstamp
FROM AuraDefinition
```

The field `Format` in the query causes it to fail because this is also a reserved keyword.

![image](https://user-images.githubusercontent.com/5461649/58042241-60bcaf80-7af7-11e9-9704-fde352072ad1.png)


Pull request description:
The field Format fails if it is in a query #59
Fixed queries where FORMAT was included in the query when it was not a function keyword

resolves #59

Patch:
diff --git a/lib/SoqlListener.ts b/lib/SoqlListener.ts
index 4eeb67d..c5b1a20 100644
--- a/lib/SoqlListener.ts
+++ b/lib/SoqlListener.ts
@@ -464,7 +464,7 @@ export class Listener implements SOQLListener {
     if (this.config.logging) {
       console.log('enterFunction_name:', ctx.text);
     }
-    if (this.context.currentItem === 'field') {
+    if (this.context.currentItem === 'field' && this.context.currentFieldFn) {
       if (!this.context.currentFieldFn.fn) {
         this.context.currentFieldFn.fn = ctx.text;
       }


Test patch:
diff --git a/debug/test.js b/debug/test.js
index 6f0a4e1..71040bd 100644
--- a/debug/test.js
+++ b/debug/test.js
@@ -1,6 +1,6 @@
 var soqlParserJs = require('./lib');
 
-const query = `@`;
+const query = `SELECT Id, Format, Foo FROM Account`;
 // const query = `
 // SELECT Id, Name, FORMAT(Amount),
 //   (SELECT Quantity, ListPrice, PricebookEntry.UnitPrice, PricebookEntry.Name FROM OpportunityLineItems)
diff --git a/test/TestCases.ts b/test/TestCases.ts
index bd73587..b22a8d8 100644
--- a/test/TestCases.ts
+++ b/test/TestCases.ts
@@ -1675,5 +1675,63 @@ export const testCases: TestCase[] = [
       },
     },
   },
+  {
+    testCase: 55,
+    soql:
+      'SELECT Id, CreatedById, CreatedDate, DefType, IsDeleted, Format, LastModifiedById, LastModifiedDate, AuraDefinitionBundleId, ManageableState, Source, SystemModstamp FROM AuraDefinition',
+    output: {
+      fields: [
+        {
+          type: 'Field',
+          field: 'Id',
+        },
+        {
+          type: 'Field',
+          field: 'CreatedById',
+        },
+        {
+          type: 'Field',
+          field: 'CreatedDate',
+        },
+        {
+          type: 'Field',
+          field: 'DefType',
+        },
+        {
+          type: 'Field',
+          field: 'IsDeleted',
+        },
+        {
+          type: 'Field',
+          field: 'Format',
+        },
+        {
+          type: 'Field',
+          field: 'LastModifiedById',
+        },
+        {
+          type: 'Field',
+          field: 'LastModifiedDate',
+        },
+        {
+          type: 'Field',
+          field: 'AuraDefinitionBundleId',
+        },
+        {
+          type: 'Field',
+          field: 'ManageableState',
+        },
+        {
+          type: 'Field',
+          field: 'Source',
+        },
+        {
+          type: 'Field',
+          field: 'SystemModstamp',
+        },
+      ],
+      sObject: 'AuraDefinition',
+    },
+  },
 ];
 export default testCases;
diff --git a/test/TestCasesForIsValid.ts b/test/TestCasesForIsValid.ts
index 11679aa..54c049c 100644
--- a/test/TestCasesForIsValid.ts
+++ b/test/TestCasesForIsValid.ts
@@ -150,5 +150,10 @@ export const testCases: TestCaseForFormat[] = [
     soql: 'select some fake text',
     isValid: false,
   },
+  {
+    testCase: 30,
+    soql: 'SELECT Id, Format FROM Account',
+    isValid: true,
+  },
 ];
 export default testCases;