@apexdevtools/apex-parser 5.0.0-beta.5 → 5.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/README.md +55 -4
- package/dist/browser/apex-parser.mjs +64579 -0
- package/dist/browser/apex-parser.mjs.map +1 -0
- package/dist/browser/apex-parser.umd.js +64784 -0
- package/dist/browser/apex-parser.umd.js.map +1 -0
- package/dist/cjs/ApexErrorListener.cjs +31 -0
- package/dist/cjs/ApexErrorListener.cjs.map +1 -0
- package/dist/cjs/ApexParserFactory.cjs +83 -0
- package/dist/cjs/ApexParserFactory.cjs.map +1 -0
- package/dist/cjs/CaseInsensitiveInputStream.cjs +30 -0
- package/dist/cjs/CaseInsensitiveInputStream.cjs.map +1 -0
- package/dist/cjs/Check.cjs +172 -0
- package/dist/cjs/Check.cjs.map +1 -0
- package/dist/cjs/antlr/ApexLexer.cjs +23244 -0
- package/dist/cjs/antlr/ApexLexer.cjs.map +1 -0
- package/dist/cjs/antlr/ApexParser.cjs +38369 -0
- package/dist/cjs/antlr/ApexParser.cjs.map +1 -0
- package/dist/cjs/antlr/ApexParserListener.cjs +1915 -0
- package/dist/cjs/antlr/ApexParserListener.cjs.map +1 -0
- package/dist/cjs/antlr/ApexParserVisitor.cjs +1147 -0
- package/dist/cjs/antlr/ApexParserVisitor.cjs.map +1 -0
- package/dist/cjs/index.cjs +214 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/ApexErrorListener.js +27 -0
- package/dist/esm/ApexErrorListener.js.map +1 -0
- package/dist/esm/ApexParserFactory.js +78 -0
- package/dist/esm/ApexParserFactory.js.map +1 -0
- package/dist/esm/CaseInsensitiveInputStream.js +28 -0
- package/dist/esm/CaseInsensitiveInputStream.js.map +1 -0
- package/dist/esm/Check.js +169 -0
- package/dist/esm/Check.js.map +1 -0
- package/dist/esm/antlr/ApexLexer.js +23240 -0
- package/dist/esm/antlr/ApexLexer.js.map +1 -0
- package/dist/esm/antlr/ApexParser.js +38179 -0
- package/dist/esm/antlr/ApexParser.js.map +1 -0
- package/dist/esm/antlr/ApexParserListener.js +1911 -0
- package/dist/esm/antlr/ApexParserListener.js.map +1 -0
- package/dist/esm/antlr/ApexParserVisitor.js +1143 -0
- package/dist/esm/antlr/ApexParserVisitor.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/ApexErrorListener.d.cts +26 -0
- package/dist/{src → types}/ApexErrorListener.d.ts +4 -3
- package/dist/types/ApexParserFactory.d.cts +81 -0
- package/dist/{src → types}/ApexParserFactory.d.ts +12 -0
- package/dist/types/CaseInsensitiveInputStream.d.ts +14 -0
- package/dist/types/Check.d.ts +36 -0
- package/dist/types/antlr/ApexLexer.d.cts +275 -0
- package/dist/{src → types}/antlr/ApexLexer.d.ts +54 -53
- package/dist/types/antlr/ApexParser.d.cts +3126 -0
- package/dist/{src → types}/antlr/ApexParser.d.ts +113 -85
- package/dist/{src/antlr/ApexParserListener.js → types/antlr/ApexParserListener.d.cts} +568 -366
- package/dist/{src → types}/antlr/ApexParserListener.d.ts +22 -0
- package/dist/{src/antlr/ApexParserVisitor.js → types/antlr/ApexParserVisitor.d.cts} +379 -185
- package/dist/{src → types}/antlr/ApexParserVisitor.d.ts +14 -0
- package/dist/types/index.browser.d.cts +8 -0
- package/dist/types/index.browser.d.ts +8 -0
- package/dist/types/index.d.ts +9 -0
- package/package.json +89 -21
- package/dist/src/ApexErrorListener.js +0 -61
- package/dist/src/ApexErrorListener.js.map +0 -1
- package/dist/src/ApexParserFactory.js +0 -116
- package/dist/src/ApexParserFactory.js.map +0 -1
- package/dist/src/CaseInsensitiveInputStream.js +0 -64
- package/dist/src/CaseInsensitiveInputStream.js.map +0 -1
- package/dist/src/Check.js +0 -205
- package/dist/src/Check.js.map +0 -1
- package/dist/src/antlr/ApexLexer.js +0 -1573
- package/dist/src/antlr/ApexLexer.js.map +0 -1
- package/dist/src/antlr/ApexParser.js +0 -20786
- package/dist/src/antlr/ApexParser.js.map +0 -1
- package/dist/src/antlr/ApexParserListener.js.map +0 -1
- package/dist/src/antlr/ApexParserVisitor.js.map +0 -1
- package/dist/src/index.js +0 -37
- package/dist/src/index.js.map +0 -1
- /package/dist/{src/CaseInsensitiveInputStream.d.ts → types/CaseInsensitiveInputStream.d.cts} +0 -0
- /package/dist/{src/Check.d.ts → types/Check.d.cts} +0 -0
- /package/dist/{src/index.d.ts → types/index.d.cts} +0 -0
|
@@ -156,6 +156,8 @@ import { DataCategorySelectionContext } from "./ApexParser.js";
|
|
|
156
156
|
import { DataCategoryNameContext } from "./ApexParser.js";
|
|
157
157
|
import { FilteringSelectorContext } from "./ApexParser.js";
|
|
158
158
|
import { GroupByClauseContext } from "./ApexParser.js";
|
|
159
|
+
import { FieldGroupByListContext } from "./ApexParser.js";
|
|
160
|
+
import { FieldGroupByContext } from "./ApexParser.js";
|
|
159
161
|
import { OrderByClauseContext } from "./ApexParser.js";
|
|
160
162
|
import { FieldOrderListContext } from "./ApexParser.js";
|
|
161
163
|
import { FieldOrderContext } from "./ApexParser.js";
|
|
@@ -1163,6 +1165,18 @@ export default class ApexParserVisitor<Result> extends ParseTreeVisitor<Result>
|
|
|
1163
1165
|
* @return the visitor result
|
|
1164
1166
|
*/
|
|
1165
1167
|
visitGroupByClause?: (ctx: GroupByClauseContext) => Result;
|
|
1168
|
+
/**
|
|
1169
|
+
* Visit a parse tree produced by `ApexParser.fieldGroupByList`.
|
|
1170
|
+
* @param ctx the parse tree
|
|
1171
|
+
* @return the visitor result
|
|
1172
|
+
*/
|
|
1173
|
+
visitFieldGroupByList?: (ctx: FieldGroupByListContext) => Result;
|
|
1174
|
+
/**
|
|
1175
|
+
* Visit a parse tree produced by `ApexParser.fieldGroupBy`.
|
|
1176
|
+
* @param ctx the parse tree
|
|
1177
|
+
* @return the visitor result
|
|
1178
|
+
*/
|
|
1179
|
+
visitFieldGroupBy?: (ctx: FieldGroupByContext) => Result;
|
|
1166
1180
|
/**
|
|
1167
1181
|
* Visit a parse tree produced by `ApexParser.orderByClause`.
|
|
1168
1182
|
* @param ctx the parse tree
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./ApexErrorListener.js";
|
|
2
|
+
export * from "./ApexParserFactory.js";
|
|
3
|
+
export * from "./CaseInsensitiveInputStream.js";
|
|
4
|
+
export * from "./antlr/ApexParser.js";
|
|
5
|
+
export { default as ApexLexer } from "./antlr/ApexLexer.js";
|
|
6
|
+
export { default as ApexParser } from "./antlr/ApexParser.js";
|
|
7
|
+
export { default as ApexParserListener } from "./antlr/ApexParserListener.js";
|
|
8
|
+
export { default as ApexParserVisitor } from "./antlr/ApexParserVisitor.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./ApexErrorListener.js";
|
|
2
|
+
export * from "./ApexParserFactory.js";
|
|
3
|
+
export * from "./CaseInsensitiveInputStream.js";
|
|
4
|
+
export * from "./antlr/ApexParser.js";
|
|
5
|
+
export { default as ApexLexer } from "./antlr/ApexLexer.js";
|
|
6
|
+
export { default as ApexParser } from "./antlr/ApexParser.js";
|
|
7
|
+
export { default as ApexParserListener } from "./antlr/ApexParserListener.js";
|
|
8
|
+
export { default as ApexParserVisitor } from "./antlr/ApexParserVisitor.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./ApexErrorListener.js";
|
|
2
|
+
export * from "./ApexParserFactory.js";
|
|
3
|
+
export * from "./CaseInsensitiveInputStream.js";
|
|
4
|
+
export * from "./Check.js";
|
|
5
|
+
export * from "./antlr/ApexParser.js";
|
|
6
|
+
export { default as ApexLexer } from "./antlr/ApexLexer.js";
|
|
7
|
+
export { default as ApexParser } from "./antlr/ApexParser.js";
|
|
8
|
+
export { default as ApexParserListener } from "./antlr/ApexParserListener.js";
|
|
9
|
+
export { default as ApexParserVisitor } from "./antlr/ApexParserVisitor.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apexdevtools/apex-parser",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0-beta.1",
|
|
4
4
|
"description": "Javascript parser for Salesforce Apex Language",
|
|
5
5
|
"author": "Apex Dev Tools Team <apexdevtools@gmail.com> (https://github.com/apex-dev-tools)",
|
|
6
6
|
"bugs": "https://github.com/apex-dev-tools/apex-parser/issues",
|
|
@@ -10,14 +10,18 @@
|
|
|
10
10
|
"url": "git+https://github.com/apex-dev-tools/apex-parser.git"
|
|
11
11
|
},
|
|
12
12
|
"license": "BSD-3-Clause",
|
|
13
|
-
"main": "dist/
|
|
14
|
-
"
|
|
13
|
+
"main": "./dist/cjs/index.cjs",
|
|
14
|
+
"module": "./dist/esm/index.js",
|
|
15
|
+
"types": "./dist/types/index.d.ts",
|
|
16
|
+
"browser": "./dist/browser/apex-parser.mjs",
|
|
15
17
|
"type": "module",
|
|
16
18
|
"scripts": {
|
|
17
19
|
"antlr": "mvn exec:exec",
|
|
18
|
-
"build": "npm run clean && npm run antlr &&
|
|
19
|
-
"build:
|
|
20
|
-
"
|
|
20
|
+
"build": "npm run clean && npm run antlr && npm run build:bundle && npm run build:types",
|
|
21
|
+
"build:bundle": "rollup -c",
|
|
22
|
+
"build:types": "tsc -p tsconfig.declarations.json && node scripts/copy-dcts.mjs",
|
|
23
|
+
"build:test": "npm run build && tsc -p tsconfig.test.json && npm test",
|
|
24
|
+
"check": "node -e 'import(\"./dist/esm/index.js\").then(m => m.check())'",
|
|
21
25
|
"clean": "rm -rf dist",
|
|
22
26
|
"init": "npm ci && npm run antlr",
|
|
23
27
|
"lint": "eslint --cache --cache-location .eslintcache ./src --fix",
|
|
@@ -28,7 +32,10 @@
|
|
|
28
32
|
"test:snapshot": "npm run test:samples -- --updateSnapshot"
|
|
29
33
|
},
|
|
30
34
|
"files": [
|
|
31
|
-
"dist/
|
|
35
|
+
"dist/esm",
|
|
36
|
+
"dist/cjs",
|
|
37
|
+
"dist/browser",
|
|
38
|
+
"dist/types",
|
|
32
39
|
"patches",
|
|
33
40
|
"CHANGELOG.md"
|
|
34
41
|
],
|
|
@@ -39,24 +46,85 @@
|
|
|
39
46
|
"antlr4": "4.13.2"
|
|
40
47
|
},
|
|
41
48
|
"devDependencies": {
|
|
42
|
-
"@eslint/js": "^
|
|
49
|
+
"@eslint/js": "^10.0.1",
|
|
50
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
43
51
|
"@types/jest": "^30.0.0",
|
|
44
|
-
"@types/node": "^22.17
|
|
45
|
-
"eslint": "^
|
|
46
|
-
"jest": "^30.0
|
|
47
|
-
"patch-package": "^8.0.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
52
|
+
"@types/node": "^22.19.17",
|
|
53
|
+
"eslint": "^10.2.1",
|
|
54
|
+
"jest": "^30.3.0",
|
|
55
|
+
"patch-package": "^8.0.1",
|
|
56
|
+
"rollup": "^4.60.3",
|
|
57
|
+
"rollup-plugin-esbuild": "^6.2.1",
|
|
58
|
+
"typescript": "^6.0.3",
|
|
59
|
+
"typescript-eslint": "^8.59.0"
|
|
50
60
|
},
|
|
51
61
|
"engines": {
|
|
52
|
-
"node": "
|
|
62
|
+
"node": "^20.19.0 || ^22.13.0 || >=24"
|
|
53
63
|
},
|
|
54
64
|
"exports": {
|
|
55
|
-
".":
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
".": {
|
|
66
|
+
"browser": {
|
|
67
|
+
"types": "./dist/types/index.browser.d.ts",
|
|
68
|
+
"default": "./dist/browser/apex-parser.mjs"
|
|
69
|
+
},
|
|
70
|
+
"import": {
|
|
71
|
+
"types": "./dist/types/index.d.ts",
|
|
72
|
+
"default": "./dist/esm/index.js"
|
|
73
|
+
},
|
|
74
|
+
"require": {
|
|
75
|
+
"types": "./dist/types/index.d.cts",
|
|
76
|
+
"default": "./dist/cjs/index.cjs"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"./antlr/*": {
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/types/antlr/*.d.ts",
|
|
82
|
+
"default": "./dist/esm/antlr/*.js"
|
|
83
|
+
},
|
|
84
|
+
"require": {
|
|
85
|
+
"types": "./dist/types/antlr/*.d.cts",
|
|
86
|
+
"default": "./dist/cjs/antlr/*.cjs"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"./ApexErrorListener": {
|
|
90
|
+
"import": {
|
|
91
|
+
"types": "./dist/types/ApexErrorListener.d.ts",
|
|
92
|
+
"default": "./dist/esm/ApexErrorListener.js"
|
|
93
|
+
},
|
|
94
|
+
"require": {
|
|
95
|
+
"types": "./dist/types/ApexErrorListener.d.cts",
|
|
96
|
+
"default": "./dist/cjs/ApexErrorListener.cjs"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"./ApexParserFactory": {
|
|
100
|
+
"import": {
|
|
101
|
+
"types": "./dist/types/ApexParserFactory.d.ts",
|
|
102
|
+
"default": "./dist/esm/ApexParserFactory.js"
|
|
103
|
+
},
|
|
104
|
+
"require": {
|
|
105
|
+
"types": "./dist/types/ApexParserFactory.d.cts",
|
|
106
|
+
"default": "./dist/cjs/ApexParserFactory.cjs"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"./CaseInsensitiveInputStream": {
|
|
110
|
+
"import": {
|
|
111
|
+
"types": "./dist/types/CaseInsensitiveInputStream.d.ts",
|
|
112
|
+
"default": "./dist/esm/CaseInsensitiveInputStream.js"
|
|
113
|
+
},
|
|
114
|
+
"require": {
|
|
115
|
+
"types": "./dist/types/CaseInsensitiveInputStream.d.cts",
|
|
116
|
+
"default": "./dist/cjs/CaseInsensitiveInputStream.cjs"
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"./Check": {
|
|
120
|
+
"import": {
|
|
121
|
+
"types": "./dist/types/Check.d.ts",
|
|
122
|
+
"default": "./dist/esm/Check.js"
|
|
123
|
+
},
|
|
124
|
+
"require": {
|
|
125
|
+
"types": "./dist/types/Check.d.cts",
|
|
126
|
+
"default": "./dist/cjs/Check.cjs"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
61
129
|
}
|
|
62
130
|
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
[The "BSD licence"]
|
|
3
|
-
Copyright (c) 2025 Kevin Jones, Certinia Inc.
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions
|
|
8
|
-
are met:
|
|
9
|
-
1. Redistributions of source code must retain the above copyright
|
|
10
|
-
notice, this list of conditions and the following disclaimer.
|
|
11
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer in the
|
|
13
|
-
documentation and/or other materials provided with the distribution.
|
|
14
|
-
3. The name of the author may not be used to endorse or promote products
|
|
15
|
-
derived from this software without specific prior written permission.
|
|
16
|
-
|
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
18
|
-
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
19
|
-
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20
|
-
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
22
|
-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
import { ErrorListener, } from "antlr4";
|
|
29
|
-
/**
|
|
30
|
-
* Base `ErrorListener` for Apex parsers.
|
|
31
|
-
*
|
|
32
|
-
* Implement `apexSyntaxError()` to set behaviour.
|
|
33
|
-
*/
|
|
34
|
-
export class ApexErrorListener extends ErrorListener {
|
|
35
|
-
syntaxError(recognizer, offendingSymbol, line, column, msg, e) {
|
|
36
|
-
this.apexSyntaxError(line, column, msg);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export class ApexSyntaxError extends Error {
|
|
40
|
-
line;
|
|
41
|
-
column;
|
|
42
|
-
message;
|
|
43
|
-
constructor(line, column, message) {
|
|
44
|
-
super(message);
|
|
45
|
-
this.line = line;
|
|
46
|
-
this.column = column;
|
|
47
|
-
this.name = this.constructor.name;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* `ApexErrorListener` that throws an `ApexSyntaxError` on first reported error.
|
|
52
|
-
*
|
|
53
|
-
* Use ThrowingErrorListener.INSTANCE to share across parsers.
|
|
54
|
-
*/
|
|
55
|
-
export class ThrowingErrorListener extends ApexErrorListener {
|
|
56
|
-
static INSTANCE = new ThrowingErrorListener();
|
|
57
|
-
apexSyntaxError(line, column, msg) {
|
|
58
|
-
throw new ApexSyntaxError(line, column, msg);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=ApexErrorListener.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApexErrorListener.js","sourceRoot":"","sources":["../../src/ApexErrorListener.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE;AACF,OAAO,EACL,aAAa,GAId,MAAM,QAAQ,CAAC;AAEhB;;;;GAIG;AACH,MAAM,OAAgB,iBAAkB,SAAQ,aAAoB;IAGlE,WAAW,CACT,UAA6B,EAC7B,eAAsB,EACtB,IAAY,EACZ,MAAc,EACd,GAAW,EACX,CAAmC;QAEnC,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,IAAI,CAAS;IACb,MAAM,CAAS;IACf,OAAO,CAAU;IAEjB,YAAY,IAAY,EAAE,MAAc,EAAE,OAAe;QACvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,iBAAiB;IAC1D,MAAM,CAAU,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAC;IAEvD,eAAe,CAAC,IAAY,EAAE,MAAc,EAAE,GAAW;QACvD,MAAM,IAAI,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
[The "BSD licence"]
|
|
3
|
-
Copyright (c) 2025 Kevin Jones, Certinia Inc.
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions
|
|
8
|
-
are met:
|
|
9
|
-
1. Redistributions of source code must retain the above copyright
|
|
10
|
-
notice, this list of conditions and the following disclaimer.
|
|
11
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer in the
|
|
13
|
-
documentation and/or other materials provided with the distribution.
|
|
14
|
-
3. The name of the author may not be used to endorse or promote products
|
|
15
|
-
derived from this software without specific prior written permission.
|
|
16
|
-
|
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
18
|
-
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
19
|
-
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20
|
-
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
22
|
-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
import { CharStreams, CommonTokenStream, ParseTreeListener, ParseTreeVisitor, ParseTreeWalker, } from "antlr4";
|
|
29
|
-
import ApexLexer from "./antlr/ApexLexer.js";
|
|
30
|
-
import ApexParser from "./antlr/ApexParser.js";
|
|
31
|
-
import { ThrowingErrorListener } from "./ApexErrorListener.js";
|
|
32
|
-
/**
|
|
33
|
-
* A factory for `ApexParser` and its components. Abstracts interaction
|
|
34
|
-
* with core ANTLR types like `CommonTokenStream`.
|
|
35
|
-
*/
|
|
36
|
-
export class ApexParserFactory {
|
|
37
|
-
constructor() { }
|
|
38
|
-
static createParser(source, throwOnFirstError = false) {
|
|
39
|
-
const parser = new ApexParser(typeof source === "string"
|
|
40
|
-
? new CommonTokenStream(this.createLexer(source))
|
|
41
|
-
: source);
|
|
42
|
-
// always remove default console listener
|
|
43
|
-
parser.removeErrorListeners();
|
|
44
|
-
if (throwOnFirstError) {
|
|
45
|
-
parser.addErrorListener(ThrowingErrorListener.INSTANCE);
|
|
46
|
-
}
|
|
47
|
-
return parser;
|
|
48
|
-
}
|
|
49
|
-
static createTokenStream(source) {
|
|
50
|
-
return new CommonTokenStream(typeof source === "string" ? this.createLexer(source) : source);
|
|
51
|
-
}
|
|
52
|
-
static createLexer(source) {
|
|
53
|
-
const lexer = new ApexLexer(CharStreams.fromString(source));
|
|
54
|
-
// always remove default console listener
|
|
55
|
-
lexer.removeErrorListeners();
|
|
56
|
-
return lexer;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* A base visitor for an Apex parse tree produced by `ApexParser`. Extend this
|
|
61
|
-
* class to define a subset of visitor operations.
|
|
62
|
-
*
|
|
63
|
-
* @see ApexParserVisitor for tree context visit operations.
|
|
64
|
-
* @param Result The return type of the visit operation. Use `void` for
|
|
65
|
-
* operations with no return type.
|
|
66
|
-
* @example
|
|
67
|
-
* // Implementations can be property or method styles.
|
|
68
|
-
* visitCompilationUnit = (ctx: CompilationUnitContext) => { return result; }
|
|
69
|
-
* visitCompilationUnit(ctx: CompilationUnitContext) { return result; }
|
|
70
|
-
*/
|
|
71
|
-
export class ApexParserBaseVisitor extends ParseTreeVisitor {
|
|
72
|
-
visit(tree) {
|
|
73
|
-
return super.visit(tree);
|
|
74
|
-
}
|
|
75
|
-
visitChildren(node) {
|
|
76
|
-
return super.visitChildren(node);
|
|
77
|
-
}
|
|
78
|
-
visitTerminal(node) {
|
|
79
|
-
return super.visitTerminal(node);
|
|
80
|
-
}
|
|
81
|
-
visitErrorNode(node) {
|
|
82
|
-
return super.visitErrorNode(node);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* A base listener for an Apex parse tree produced by `ApexParser`. Extend this
|
|
87
|
-
* class to define a subset of listener operations.
|
|
88
|
-
*
|
|
89
|
-
* @see ApexParserListener for tree context listen operations.
|
|
90
|
-
* @example
|
|
91
|
-
* // Implementations can be property or method styles.
|
|
92
|
-
* enterCompilationUnit = (ctx: CompilationUnitContext) => {}
|
|
93
|
-
* enterCompilationUnit(ctx: CompilationUnitContext) {}
|
|
94
|
-
*/
|
|
95
|
-
export class ApexParserBaseListener extends ParseTreeListener {
|
|
96
|
-
visitTerminal(node) { }
|
|
97
|
-
visitErrorNode(node) { }
|
|
98
|
-
enterEveryRule(ctx) { }
|
|
99
|
-
exitEveryRule(ctx) { }
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Walker for a parse tree starting at the root and going down recursively
|
|
103
|
-
* with depth-first search.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* const parser = ApexParserFactory.createParser("public class Foo {}");
|
|
107
|
-
* const listener = new MyListener(); // extends ApexParseTreeListener
|
|
108
|
-
* ApexParseTreeWalker.DEFAULT.walk(listener, parser.compilationUnit());
|
|
109
|
-
*/
|
|
110
|
-
export class ApexParseTreeWalker extends ParseTreeWalker {
|
|
111
|
-
static DEFAULT = super.DEFAULT;
|
|
112
|
-
walk(listener, t) {
|
|
113
|
-
super.walk(listener, t);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=ApexParserFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApexParserFactory.js","sourceRoot":"","sources":["../../src/ApexParserFactory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE;AAEF,OAAO,EACL,WAAW,EACX,iBAAiB,EAIjB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,GAIhB,MAAM,QAAQ,CAAC;AAGhB,OAAO,SAAS,MAAM,sBAAsB,CAAC;AAC7C,OAAO,UAAU,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAU/D;;;GAGG;AACH,MAAM,OAAO,iBAAiB;IAC5B,gBAAuB,CAAC;IAExB,MAAM,CAAC,YAAY,CACjB,MAAgC,EAChC,oBAA6B,KAAK;QAElC,MAAM,MAAM,GAAG,IAAI,UAAU,CAC3B,OAAO,MAAM,KAAK,QAAQ;YACxB,CAAC,CAAC,IAAI,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACjD,CAAC,CAAC,MAAM,CACX,CAAC;QAEF,yCAAyC;QACzC,MAAM,CAAC,oBAAoB,EAAE,CAAC;QAC9B,IAAI,iBAAiB,EAAE,CAAC;YACtB,MAAM,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,MAA0B;QACjD,OAAO,IAAI,iBAAiB,CAC1B,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAC/D,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAc;QAC/B,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;QAE5D,yCAAyC;QACzC,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,qBACX,SAAQ,gBAAwB;IAGhC,KAAK,CAAC,IAAmB;QACvB,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,aAAa,CAAC,IAAkB;QAC9B,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,aAAa,CAAC,IAAsB;QAClC,OAAO,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,cAAc,CAAC,IAAmB;QAChC,OAAO,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,sBACX,SAAQ,iBAAiB;IAGzB,aAAa,CAAC,IAAsB,IAAS,CAAC;IAC9C,cAAc,CAAC,IAAmB,IAAS,CAAC;IAC5C,cAAc,CAAC,GAA0B,IAAS,CAAC;IACnD,aAAa,CAAC,GAA0B,IAAS,CAAC;CACnD;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,mBAAoB,SAAQ,eAAe;IACtD,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,OAA8B,CAAC;IAEtD,IAAI,CAA+B,QAAW,EAAE,CAAgB;QAC9D,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC1B,CAAC"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
[The "BSD licence"]
|
|
3
|
-
Copyright (c) 2019 Kevin Jones
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions
|
|
8
|
-
are met:
|
|
9
|
-
1. Redistributions of source code must retain the above copyright
|
|
10
|
-
notice, this list of conditions and the following disclaimer.
|
|
11
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer in the
|
|
13
|
-
documentation and/or other materials provided with the distribution.
|
|
14
|
-
3. The name of the author may not be used to endorse or promote products
|
|
15
|
-
derived from this software without specific prior written permission.
|
|
16
|
-
|
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
18
|
-
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
19
|
-
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20
|
-
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
22
|
-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
import { CharStream } from "antlr4";
|
|
29
|
-
/**
|
|
30
|
-
* Converts char stream to lower case for case insensitive usage.
|
|
31
|
-
*
|
|
32
|
-
* @deprecated since 5.0.0. ApexLexer is generated with ANTLR 4.10
|
|
33
|
-
* `caseInsensitive` option enabled.
|
|
34
|
-
*/
|
|
35
|
-
export class CaseInsensitiveInputStream extends CharStream {
|
|
36
|
-
constructor(data, decodeToUnicodeCodePoints = true) {
|
|
37
|
-
// Default to unicode code points
|
|
38
|
-
// CharStreams.fromString is always `new CharStream(data, true)`
|
|
39
|
-
// but `new CharStream(data)` defaults to false / UTF-16 code units
|
|
40
|
-
if (typeof data === "string") {
|
|
41
|
-
super(data, decodeToUnicodeCodePoints);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
super(data.toString(), decodeToUnicodeCodePoints);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
LA(i) {
|
|
48
|
-
return this.toLower(super.LA(i));
|
|
49
|
-
}
|
|
50
|
-
LT(offset) {
|
|
51
|
-
// same behaviour as CharStream
|
|
52
|
-
return this.LA(offset);
|
|
53
|
-
}
|
|
54
|
-
// We only need basic upper to lower conversions
|
|
55
|
-
toLower(c) {
|
|
56
|
-
if (c >= 65 && c <= 90) {
|
|
57
|
-
return c + 32;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
return c;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
//# sourceMappingURL=CaseInsensitiveInputStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CaseInsensitiveInputStream.js","sourceRoot":"","sources":["../../src/CaseInsensitiveInputStream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BE;AAEF,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,OAAO,0BAA2B,SAAQ,UAAU;IAGxD,YACE,IAAyB,EACzB,4BAAqC,IAAI;QAEzC,iCAAiC;QACjC,gEAAgE;QAChE,mEAAmE;QACnE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,KAAK,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,yBAAyB,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,EAAE,CAAC,CAAS;QACV,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IAED,EAAE,CAAC,MAAc;QACf,+BAA+B;QAC/B,OAAO,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;IAED,gDAAgD;IACxC,OAAO,CAAC,CAAS;QACvB,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/Check.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
[The "BSD licence"]
|
|
3
|
-
Copyright (c) 2020 Kevin Jones
|
|
4
|
-
All rights reserved.
|
|
5
|
-
|
|
6
|
-
Redistribution and use in source and binary forms, with or without
|
|
7
|
-
modification, are permitted provided that the following conditions
|
|
8
|
-
are met:
|
|
9
|
-
1. Redistributions of source code must retain the above copyright
|
|
10
|
-
notice, this list of conditions and the following disclaimer.
|
|
11
|
-
2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
-
notice, this list of conditions and the following disclaimer in the
|
|
13
|
-
documentation and/or other materials provided with the distribution.
|
|
14
|
-
3. The name of the author may not be used to endorse or promote products
|
|
15
|
-
derived from this software without specific prior written permission.
|
|
16
|
-
|
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
18
|
-
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
19
|
-
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
20
|
-
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
21
|
-
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
22
|
-
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
23
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
24
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
25
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
26
|
-
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
|
-
*/
|
|
28
|
-
import { readdir } from "node:fs/promises";
|
|
29
|
-
import { readdirSync, readFileSync, lstatSync, existsSync } from "node:fs";
|
|
30
|
-
import { basename, dirname, extname, resolve, relative, join } from "node:path";
|
|
31
|
-
import { ApexErrorListener } from "./ApexErrorListener.js";
|
|
32
|
-
import { ApexParserFactory } from "./ApexParserFactory.js";
|
|
33
|
-
/**
|
|
34
|
-
* Check Apex files in a path for syntax errors.
|
|
35
|
-
*
|
|
36
|
-
* @param pathStr Path to check. If not provided, uses process.argv or
|
|
37
|
-
* process.cwd().
|
|
38
|
-
* @param fileExt CSV list of file extensions to check
|
|
39
|
-
* (default: `.cls,.trigger,.apex`).
|
|
40
|
-
* @returns Result with status (0 ok, 1 error, 2 missing path) and syntax
|
|
41
|
-
* errors.
|
|
42
|
-
*/
|
|
43
|
-
export async function check(pathStr, fileExt) {
|
|
44
|
-
const path = resolve(pathStr || process.argv[1] || process.cwd());
|
|
45
|
-
const ext = fileExt || process.argv[2];
|
|
46
|
-
const extensions = ext ? ext.split(",") : [".cls", ".trigger", ".apex"];
|
|
47
|
-
const result = {
|
|
48
|
-
status: 0,
|
|
49
|
-
extensions,
|
|
50
|
-
errors: [],
|
|
51
|
-
};
|
|
52
|
-
if (!existsSync(path)) {
|
|
53
|
-
console.error(`Path does not exist, aborting: ${path}`);
|
|
54
|
-
result.status = 2;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
try {
|
|
58
|
-
result.errors = await parseFiles(path, extensions);
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
console.error(`Error processing: ${path}`);
|
|
62
|
-
console.error(err);
|
|
63
|
-
result.status = 1;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
process.exitCode = result.status;
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Check an Apex sfdx-project for syntax errors.
|
|
71
|
-
*
|
|
72
|
-
* @param pathStr Path to directory containing an sfdx-project.json at most 1
|
|
73
|
-
* level deep. If not found, reverts to `check()` behaviour.
|
|
74
|
-
* @returns Result for each package with status (0 ok, 1 error, 2 missing path)
|
|
75
|
-
* and syntax errors.
|
|
76
|
-
*/
|
|
77
|
-
export async function checkProject(pathStr) {
|
|
78
|
-
const path = resolve(pathStr || process.argv[1] || process.cwd());
|
|
79
|
-
const ext = ".cls,.trigger";
|
|
80
|
-
const name = basename(path);
|
|
81
|
-
const project = findProjectFile(path, 1);
|
|
82
|
-
if (!project) {
|
|
83
|
-
console.error(`[${name}]: No valid SFDX project, checking all cls & trigger files`);
|
|
84
|
-
const result = await check(path, ext);
|
|
85
|
-
return [
|
|
86
|
-
{
|
|
87
|
-
name,
|
|
88
|
-
path: ".",
|
|
89
|
-
...result,
|
|
90
|
-
},
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
const packages = getProjectPackages(project);
|
|
94
|
-
const projectDir = dirname(project);
|
|
95
|
-
const projectResult = await Promise.all(packages.map(async (pkg) => {
|
|
96
|
-
console.log(`[${name}]: Checking package "${pkg}"`);
|
|
97
|
-
const pkgPath = resolve(projectDir, pkg);
|
|
98
|
-
const result = await check(pkgPath, ext);
|
|
99
|
-
return {
|
|
100
|
-
name,
|
|
101
|
-
pkg,
|
|
102
|
-
path: relative(path, pkgPath),
|
|
103
|
-
...result,
|
|
104
|
-
};
|
|
105
|
-
}));
|
|
106
|
-
process.exitCode = Math.max(...projectResult.map(r => r.status));
|
|
107
|
-
return projectResult;
|
|
108
|
-
}
|
|
109
|
-
class CheckApexErrorListener extends ApexErrorListener {
|
|
110
|
-
path;
|
|
111
|
-
errors = [];
|
|
112
|
-
constructor(relativePath) {
|
|
113
|
-
super();
|
|
114
|
-
this.path = relativePath;
|
|
115
|
-
}
|
|
116
|
-
apexSyntaxError(line, column, message) {
|
|
117
|
-
const error = {
|
|
118
|
-
column,
|
|
119
|
-
line,
|
|
120
|
-
message,
|
|
121
|
-
path: this.path,
|
|
122
|
-
};
|
|
123
|
-
console.log(JSON.stringify(error));
|
|
124
|
-
this.errors.push(error);
|
|
125
|
-
}
|
|
126
|
-
getErrors() {
|
|
127
|
-
return this.errors;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async function parseFiles(path, extensions) {
|
|
131
|
-
const parsers = {
|
|
132
|
-
".cls": parser => parser.compilationUnit(),
|
|
133
|
-
".trigger": parser => parser.triggerUnit(),
|
|
134
|
-
".apex": parser => parser.anonymousUnit(),
|
|
135
|
-
};
|
|
136
|
-
const ext = Object.keys(parsers);
|
|
137
|
-
extensions.forEach(e => {
|
|
138
|
-
if (!ext.includes(e)) {
|
|
139
|
-
throw new Error(`Unknown extension '${e}' - one or more of [${ext.join(",")}] required.`);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
const files = await getPathsInDir(path, extensions);
|
|
143
|
-
return extensions.flatMap(ext => parseByType(path, files, ext, parsers[ext]));
|
|
144
|
-
}
|
|
145
|
-
async function getPathsInDir(path, ext) {
|
|
146
|
-
const dirent = await readdir(path, {
|
|
147
|
-
withFileTypes: true,
|
|
148
|
-
recursive: true,
|
|
149
|
-
});
|
|
150
|
-
return dirent.reduce((files, ent) => {
|
|
151
|
-
if (ent.isFile() && ext.includes(extname(ent.name))) {
|
|
152
|
-
files.push(join(ent.parentPath, ent.name));
|
|
153
|
-
}
|
|
154
|
-
return files;
|
|
155
|
-
}, []);
|
|
156
|
-
}
|
|
157
|
-
function parseByType(rootPath, files, endsWith, operation) {
|
|
158
|
-
let parsedCount = 0;
|
|
159
|
-
const errors = [];
|
|
160
|
-
files
|
|
161
|
-
.filter(name => name.endsWith(endsWith))
|
|
162
|
-
.forEach(file => {
|
|
163
|
-
if (lstatSync(file).isFile()) {
|
|
164
|
-
const parser = ApexParserFactory.createParser(readFileSync(file).toString());
|
|
165
|
-
const relativePath = relative(rootPath, file);
|
|
166
|
-
const listener = new CheckApexErrorListener(relativePath);
|
|
167
|
-
parser.addErrorListener(listener);
|
|
168
|
-
operation(parser);
|
|
169
|
-
const fileErrors = listener.getErrors();
|
|
170
|
-
if (fileErrors.length) {
|
|
171
|
-
console.log(`Found ${fileErrors.length} syntax errors in: ${relativePath}`);
|
|
172
|
-
errors.push(...fileErrors);
|
|
173
|
-
}
|
|
174
|
-
parsedCount += 1;
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
console.log(`Parsed ${parsedCount} '${endsWith}' files in: ${rootPath}`);
|
|
178
|
-
return errors;
|
|
179
|
-
}
|
|
180
|
-
function findProjectFile(wd, depth) {
|
|
181
|
-
const proj = "sfdx-project.json";
|
|
182
|
-
const files = readdirSync(wd).filter(i => !/(^|\/)\.[^/.]/g.test(i));
|
|
183
|
-
if (files.includes(proj)) {
|
|
184
|
-
return resolve(wd, proj);
|
|
185
|
-
}
|
|
186
|
-
if (depth) {
|
|
187
|
-
const dirs = files
|
|
188
|
-
.map(f => resolve(wd, f))
|
|
189
|
-
.filter(f => lstatSync(f).isDirectory());
|
|
190
|
-
const newDepth = depth - 1;
|
|
191
|
-
for (const d of dirs) {
|
|
192
|
-
const p = findProjectFile(d, newDepth);
|
|
193
|
-
if (p) {
|
|
194
|
-
return p;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
|
-
function getProjectPackages(projectFilePath) {
|
|
201
|
-
const config = JSON.parse(readFileSync(projectFilePath, { encoding: "utf8" }));
|
|
202
|
-
const packages = config.packageDirectories || [];
|
|
203
|
-
return packages.flatMap(p => (p.path ? p.path.replace(/\\/g, "/") : []));
|
|
204
|
-
}
|
|
205
|
-
//# sourceMappingURL=Check.js.map
|