Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@apexdevtools/apex-parser

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apexdevtools/apex-parser - npm Package Compare versions

Comparing version 3.0.0 to 3.1.0

CHANGELOG.md

125

lib/__tests__/ApexParserTest.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ApexLexer_1 = require("../ApexLexer");
const ApexParser_1 = require("../ApexParser");
const CaseInsensitiveInputStream_1 = require("../CaseInsensitiveInputStream");
const antlr4ts_1 = require("antlr4ts");
const ThrowingErrorListener_1 = require("../ThrowingErrorListener");
const SyntaxErrorCounter_1 = require("./SyntaxErrorCounter");
test('Boolean Literal', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("true")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("true");
const context = parser.literal();
expect(errorCounter.getNumErrors()).toEqual(0);
expect(context).toBeInstanceOf(ApexParser_1.LiteralContext);

@@ -18,6 +15,5 @@ expect(context.BooleanLiteral()).toBeTruthy();

test('Expression', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("a * 5")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("a * 5");
const context = parser.expression();
expect(errorCounter.getNumErrors()).toEqual(0);
expect(context).toBeInstanceOf(ApexParser_1.Arth1ExpressionContext);

@@ -28,17 +24,15 @@ const arthExpression = context;

test('Compilation Unit', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("public class Hello {}")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("public class Hello {}");
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (case insensitive)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("Public CLASS Hello {}")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("Public CLASS Hello {}");
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (bug test)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString(`public class Hello {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)(`public class Hello {
public testMethod void func() {

@@ -48,23 +42,19 @@ System.runAs(u) {

}
}`)));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
}`);
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (inline SOQL)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString(`public class Hello {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)(`public class Hello {
public void func() {
List<Account> accounts = [Select Id from Accounts];
}
}`)));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
}`);
const context = parser.compilationUnit();
expect(context.typeDeclaration).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.CompilationUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('Compilation Unit (throwing errors)', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("public class Hello {")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser] = (0, SyntaxErrorCounter_1.createParser)("public class Hello {");
parser.removeErrorListeners();

@@ -81,57 +71,36 @@ parser.addErrorListener(new ThrowingErrorListener_1.ThrowingErrorListener());

test('Trigger Unit', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("trigger test on Account (before update, after update) {}")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("trigger test on Account (before update, after update) {}");
const context = parser.triggerUnit();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.TriggerUnitContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('SOQL Query', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("Select Id from Account")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const context = parser.query();
expect(context).toBeTruthy();
test('testSemiAllowedAsWhileBody', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("while (x++ < 10 && !(y-- < 0));");
const context = parser.statement();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('SOQL Query Using Field function', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("Select Fields(All) from Account")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const context = parser.query();
expect(context).toBeTruthy();
test('testSemiAllowedAsForBody', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("for(x=0; x<10; x++);");
const context = parser.statement();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('SOSL Query', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("[Find {something} RETURNING Account]")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const context = parser.soslLiteral();
expect(context).toBeTruthy();
test('testSemiDisallowedAsGeneralStatement', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)("if (x == 3); else { ; }");
const context = parser.statement();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(1);
});
test('CurrencyLiteral', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("SELECT Id FROM Account WHERE Amount > USD100.01 AND Amount < USD200")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const context = parser.query();
expect(context).toBeTruthy();
});
test('IdentifiersThatCouldBeCurrencyLiterals', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("USD100.name = 'name';")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
test('testWhenLiteralParens', () => {
const [parser, errorCounter] = (0, SyntaxErrorCounter_1.createParser)(`
switch on (x) {
when 1 { return 1; }
when ((2)) { return 2; }
when (3), (4) { return 3; }
}`);
const context = parser.statement();
expect(context).toBeTruthy();
expect(context).toBeInstanceOf(ApexParser_1.StatementContext);
expect(errorCounter.getNumErrors()).toEqual(0);
});
test('DateTimeLiteral', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("SELECT Name, (SELECT Id FROM Account WHERE createdDate > 2020-01-01T12:00:00Z) FROM Opportunity")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const context = parser.query();
expect(context).toBeTruthy();
});
test('testNegativeNumericLiteral', () => {
const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString("SELECT Name FROM Opportunity WHERE Value = -100.123")));
const tokens = new antlr4ts_1.CommonTokenStream(lexer);
const parser = new ApexParser_1.ApexParser(tokens);
const context = parser.query();
expect(context).toBeTruthy();
});
//# sourceMappingURL=ApexParserTest.js.map

@@ -114,129 +114,137 @@ import { ATN } from "antlr4ts/atn/ATN";

static readonly STANDARD = 108;
static readonly CALENDAR_MONTH = 109;
static readonly CALENDAR_QUARTER = 110;
static readonly CALENDAR_YEAR = 111;
static readonly DAY_IN_MONTH = 112;
static readonly DAY_IN_WEEK = 113;
static readonly DAY_IN_YEAR = 114;
static readonly DAY_ONLY = 115;
static readonly FISCAL_MONTH = 116;
static readonly FISCAL_QUARTER = 117;
static readonly FISCAL_YEAR = 118;
static readonly HOUR_IN_DAY = 119;
static readonly WEEK_IN_MONTH = 120;
static readonly WEEK_IN_YEAR = 121;
static readonly CONVERT_TIMEZONE = 122;
static readonly YESTERDAY = 123;
static readonly TODAY = 124;
static readonly TOMORROW = 125;
static readonly LAST_WEEK = 126;
static readonly THIS_WEEK = 127;
static readonly NEXT_WEEK = 128;
static readonly LAST_MONTH = 129;
static readonly THIS_MONTH = 130;
static readonly NEXT_MONTH = 131;
static readonly LAST_90_DAYS = 132;
static readonly NEXT_90_DAYS = 133;
static readonly LAST_N_DAYS_N = 134;
static readonly NEXT_N_DAYS_N = 135;
static readonly NEXT_N_WEEKS_N = 136;
static readonly LAST_N_WEEKS_N = 137;
static readonly NEXT_N_MONTHS_N = 138;
static readonly LAST_N_MONTHS_N = 139;
static readonly THIS_QUARTER = 140;
static readonly LAST_QUARTER = 141;
static readonly NEXT_QUARTER = 142;
static readonly NEXT_N_QUARTERS_N = 143;
static readonly LAST_N_QUARTERS_N = 144;
static readonly THIS_YEAR = 145;
static readonly LAST_YEAR = 146;
static readonly NEXT_YEAR = 147;
static readonly NEXT_N_YEARS_N = 148;
static readonly LAST_N_YEARS_N = 149;
static readonly THIS_FISCAL_QUARTER = 150;
static readonly LAST_FISCAL_QUARTER = 151;
static readonly NEXT_FISCAL_QUARTER = 152;
static readonly NEXT_N_FISCAL_QUARTERS_N = 153;
static readonly LAST_N_FISCAL_QUARTERS_N = 154;
static readonly THIS_FISCAL_YEAR = 155;
static readonly LAST_FISCAL_YEAR = 156;
static readonly NEXT_FISCAL_YEAR = 157;
static readonly NEXT_N_FISCAL_YEARS_N = 158;
static readonly LAST_N_FISCAL_YEARS_N = 159;
static readonly DateLiteral = 160;
static readonly DateTimeLiteral = 161;
static readonly IntegralCurrencyLiteral = 162;
static readonly FIND = 163;
static readonly EMAIL = 164;
static readonly NAME = 165;
static readonly PHONE = 166;
static readonly SIDEBAR = 167;
static readonly FIELDS = 168;
static readonly METADATA = 169;
static readonly PRICEBOOKID = 170;
static readonly NETWORK = 171;
static readonly SNIPPET = 172;
static readonly TARGET_LENGTH = 173;
static readonly DIVISION = 174;
static readonly RETURNING = 175;
static readonly LISTVIEW = 176;
static readonly FindLiteral = 177;
static readonly IntegerLiteral = 178;
static readonly LongLiteral = 179;
static readonly NumberLiteral = 180;
static readonly BooleanLiteral = 181;
static readonly StringLiteral = 182;
static readonly NullLiteral = 183;
static readonly LPAREN = 184;
static readonly RPAREN = 185;
static readonly LBRACE = 186;
static readonly RBRACE = 187;
static readonly LBRACK = 188;
static readonly RBRACK = 189;
static readonly SEMI = 190;
static readonly COMMA = 191;
static readonly DOT = 192;
static readonly ASSIGN = 193;
static readonly GT = 194;
static readonly LT = 195;
static readonly BANG = 196;
static readonly TILDE = 197;
static readonly QUESTIONDOT = 198;
static readonly QUESTION = 199;
static readonly COLON = 200;
static readonly EQUAL = 201;
static readonly TRIPLEEQUAL = 202;
static readonly NOTEQUAL = 203;
static readonly LESSANDGREATER = 204;
static readonly TRIPLENOTEQUAL = 205;
static readonly AND = 206;
static readonly OR = 207;
static readonly INC = 208;
static readonly DEC = 209;
static readonly ADD = 210;
static readonly SUB = 211;
static readonly MUL = 212;
static readonly DIV = 213;
static readonly BITAND = 214;
static readonly BITOR = 215;
static readonly CARET = 216;
static readonly MOD = 217;
static readonly MAPTO = 218;
static readonly ADD_ASSIGN = 219;
static readonly SUB_ASSIGN = 220;
static readonly MUL_ASSIGN = 221;
static readonly DIV_ASSIGN = 222;
static readonly AND_ASSIGN = 223;
static readonly OR_ASSIGN = 224;
static readonly XOR_ASSIGN = 225;
static readonly MOD_ASSIGN = 226;
static readonly LSHIFT_ASSIGN = 227;
static readonly RSHIFT_ASSIGN = 228;
static readonly URSHIFT_ASSIGN = 229;
static readonly ATSIGN = 230;
static readonly Identifier = 231;
static readonly WS = 232;
static readonly DOC_COMMENT = 233;
static readonly COMMENT = 234;
static readonly LINE_COMMENT = 235;
static readonly DISTANCE = 109;
static readonly GEOLOCATION = 110;
static readonly CALENDAR_MONTH = 111;
static readonly CALENDAR_QUARTER = 112;
static readonly CALENDAR_YEAR = 113;
static readonly DAY_IN_MONTH = 114;
static readonly DAY_IN_WEEK = 115;
static readonly DAY_IN_YEAR = 116;
static readonly DAY_ONLY = 117;
static readonly FISCAL_MONTH = 118;
static readonly FISCAL_QUARTER = 119;
static readonly FISCAL_YEAR = 120;
static readonly HOUR_IN_DAY = 121;
static readonly WEEK_IN_MONTH = 122;
static readonly WEEK_IN_YEAR = 123;
static readonly CONVERT_TIMEZONE = 124;
static readonly YESTERDAY = 125;
static readonly TODAY = 126;
static readonly TOMORROW = 127;
static readonly LAST_WEEK = 128;
static readonly THIS_WEEK = 129;
static readonly NEXT_WEEK = 130;
static readonly LAST_MONTH = 131;
static readonly THIS_MONTH = 132;
static readonly NEXT_MONTH = 133;
static readonly LAST_90_DAYS = 134;
static readonly NEXT_90_DAYS = 135;
static readonly LAST_N_DAYS_N = 136;
static readonly NEXT_N_DAYS_N = 137;
static readonly N_DAYS_AGO_N = 138;
static readonly NEXT_N_WEEKS_N = 139;
static readonly LAST_N_WEEKS_N = 140;
static readonly N_WEEKS_AGO_N = 141;
static readonly NEXT_N_MONTHS_N = 142;
static readonly LAST_N_MONTHS_N = 143;
static readonly N_MONTHS_AGO_N = 144;
static readonly THIS_QUARTER = 145;
static readonly LAST_QUARTER = 146;
static readonly NEXT_QUARTER = 147;
static readonly NEXT_N_QUARTERS_N = 148;
static readonly LAST_N_QUARTERS_N = 149;
static readonly N_QUARTERS_AGO_N = 150;
static readonly THIS_YEAR = 151;
static readonly LAST_YEAR = 152;
static readonly NEXT_YEAR = 153;
static readonly NEXT_N_YEARS_N = 154;
static readonly LAST_N_YEARS_N = 155;
static readonly N_YEARS_AGO_N = 156;
static readonly THIS_FISCAL_QUARTER = 157;
static readonly LAST_FISCAL_QUARTER = 158;
static readonly NEXT_FISCAL_QUARTER = 159;
static readonly NEXT_N_FISCAL_QUARTERS_N = 160;
static readonly LAST_N_FISCAL_QUARTERS_N = 161;
static readonly N_FISCAL_QUARTERS_AGO_N = 162;
static readonly THIS_FISCAL_YEAR = 163;
static readonly LAST_FISCAL_YEAR = 164;
static readonly NEXT_FISCAL_YEAR = 165;
static readonly NEXT_N_FISCAL_YEARS_N = 166;
static readonly LAST_N_FISCAL_YEARS_N = 167;
static readonly N_FISCAL_YEARS_AGO_N = 168;
static readonly DateLiteral = 169;
static readonly DateTimeLiteral = 170;
static readonly IntegralCurrencyLiteral = 171;
static readonly FIND = 172;
static readonly EMAIL = 173;
static readonly NAME = 174;
static readonly PHONE = 175;
static readonly SIDEBAR = 176;
static readonly FIELDS = 177;
static readonly METADATA = 178;
static readonly PRICEBOOKID = 179;
static readonly NETWORK = 180;
static readonly SNIPPET = 181;
static readonly TARGET_LENGTH = 182;
static readonly DIVISION = 183;
static readonly RETURNING = 184;
static readonly LISTVIEW = 185;
static readonly FindLiteral = 186;
static readonly FindLiteralAlt = 187;
static readonly IntegerLiteral = 188;
static readonly LongLiteral = 189;
static readonly NumberLiteral = 190;
static readonly BooleanLiteral = 191;
static readonly StringLiteral = 192;
static readonly NullLiteral = 193;
static readonly LPAREN = 194;
static readonly RPAREN = 195;
static readonly LBRACE = 196;
static readonly RBRACE = 197;
static readonly LBRACK = 198;
static readonly RBRACK = 199;
static readonly SEMI = 200;
static readonly COMMA = 201;
static readonly DOT = 202;
static readonly ASSIGN = 203;
static readonly GT = 204;
static readonly LT = 205;
static readonly BANG = 206;
static readonly TILDE = 207;
static readonly QUESTIONDOT = 208;
static readonly QUESTION = 209;
static readonly COLON = 210;
static readonly EQUAL = 211;
static readonly TRIPLEEQUAL = 212;
static readonly NOTEQUAL = 213;
static readonly LESSANDGREATER = 214;
static readonly TRIPLENOTEQUAL = 215;
static readonly AND = 216;
static readonly OR = 217;
static readonly INC = 218;
static readonly DEC = 219;
static readonly ADD = 220;
static readonly SUB = 221;
static readonly MUL = 222;
static readonly DIV = 223;
static readonly BITAND = 224;
static readonly BITOR = 225;
static readonly CARET = 226;
static readonly MAPTO = 227;
static readonly ADD_ASSIGN = 228;
static readonly SUB_ASSIGN = 229;
static readonly MUL_ASSIGN = 230;
static readonly DIV_ASSIGN = 231;
static readonly AND_ASSIGN = 232;
static readonly OR_ASSIGN = 233;
static readonly XOR_ASSIGN = 234;
static readonly LSHIFT_ASSIGN = 235;
static readonly RSHIFT_ASSIGN = 236;
static readonly URSHIFT_ASSIGN = 237;
static readonly ATSIGN = 238;
static readonly Identifier = 239;
static readonly WS = 240;
static readonly DOC_COMMENT = 241;
static readonly COMMENT = 242;
static readonly LINE_COMMENT = 243;
static readonly WHITESPACE_CHANNEL = 2;

@@ -243,0 +251,0 @@ static readonly COMMENT_CHANNEL = 3;

@@ -6,2 +6,3 @@ import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor";

import { TypeRefPrimaryContext } from "./ApexParser";
import { VoidPrimaryContext } from "./ApexParser";
import { IdPrimaryContext } from "./ApexParser";

@@ -131,2 +132,4 @@ import { SoqlPrimaryContext } from "./ApexParser";

import { DateFieldNameContext } from "./ApexParser";
import { LocationValueContext } from "./ApexParser";
import { CoordinateValueContext } from "./ApexParser";
import { TypeOfContext } from "./ApexParser";

@@ -163,2 +166,3 @@ import { WhenClauseContext } from "./ApexParser";

import { SoslLiteralContext } from "./ApexParser";
import { SoslLiteralAltContext } from "./ApexParser";
import { SoslClausesContext } from "./ApexParser";

@@ -212,2 +216,9 @@ import { SearchGroupContext } from "./ApexParser";

/**
* Visit a parse tree produced by the `voidPrimary`
* labeled alternative in `ApexParser.primary`.
* @param ctx the parse tree
* @return the visitor result
*/
visitVoidPrimary?: (ctx: VoidPrimaryContext) => Result;
/**
* Visit a parse tree produced by the `idPrimary`

@@ -983,2 +994,14 @@ * labeled alternative in `ApexParser.primary`.

/**
* Visit a parse tree produced by `ApexParser.locationValue`.
* @param ctx the parse tree
* @return the visitor result
*/
visitLocationValue?: (ctx: LocationValueContext) => Result;
/**
* Visit a parse tree produced by `ApexParser.coordinateValue`.
* @param ctx the parse tree
* @return the visitor result
*/
visitCoordinateValue?: (ctx: CoordinateValueContext) => Result;
/**
* Visit a parse tree produced by `ApexParser.typeOf`.

@@ -1170,2 +1193,8 @@ * @param ctx the parse tree

/**
* Visit a parse tree produced by `ApexParser.soslLiteralAlt`.
* @param ctx the parse tree
* @return the visitor result
*/
visitSoslLiteralAlt?: (ctx: SoslLiteralAltContext) => Result;
/**
* Visit a parse tree produced by `ApexParser.soslClauses`.

@@ -1172,0 +1201,0 @@ * @param ctx the parse tree

@@ -1,9 +0,25 @@

export * from './ApexLexer';
export * from './ApexParser';
export * from './CaseInsensitiveInputStream';
export * from './ThrowingErrorListener';
export * from './ApexParserListener';
export * from './ApexParserVisitor';
export { CommonTokenStream } from 'antlr4ts';
export { ParseTreeWalker } from 'antlr4ts/tree/ParseTreeWalker';
export declare function check(): void;
export * from "./ApexLexer";
export * from "./ApexParser";
export * from "./CaseInsensitiveInputStream";
export * from "./ThrowingErrorListener";
export * from "./ApexParserListener";
export * from "./ApexParserVisitor";
export { CommonTokenStream } from "antlr4ts";
export { ParseTreeWalker } from "antlr4ts/tree/ParseTreeWalker";
interface ParseCheckError {
path: string;
error: string;
}
interface CheckResult {
status: number;
errors: ParseCheckError[];
}
interface ProjectCheckResult {
name: string;
path: string;
pkg?: string;
status: number;
errors: ParseCheckError[];
}
export declare function check(pathStr?: string): Promise<CheckResult>;
export declare function checkProject(pathStr?: string): Promise<ProjectCheckResult[]>;

@@ -43,4 +43,13 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.check = exports.ParseTreeWalker = exports.CommonTokenStream = void 0;
exports.checkProject = exports.check = exports.ParseTreeWalker = exports.CommonTokenStream = void 0;
const path_1 = require("path");

@@ -54,3 +63,2 @@ const dir = require("node-dir");

const fs_1 = require("fs");
const fs_2 = require("fs");
__exportStar(require("./ApexLexer"), exports);

@@ -66,10 +74,60 @@ __exportStar(require("./ApexParser"), exports);

Object.defineProperty(exports, "ParseTreeWalker", { enumerable: true, get: function () { return ParseTreeWalker_1.ParseTreeWalker; } });
function check() {
const path = (0, path_1.resolve)(process.argv[1] || process.cwd());
dir.files(path, function (err, files) {
if (err)
throw err;
function check(pathStr) {
return __awaiter(this, void 0, void 0, function* () {
const path = (0, path_1.resolve)(pathStr || process.argv[1] || process.cwd());
const result = {
status: 0,
errors: []
};
if (!(0, fs_1.existsSync)(path)) {
console.log(`Path does not exist, aborting: ${path}`);
result.status = 2;
}
else {
try {
yield parseFiles(path);
}
catch (err) {
console.log(`Error processing: ${path}`);
console.log(err);
result.status = 1;
}
}
process.exitCode = result.status;
return result;
});
}
exports.check = check;
function checkProject(pathStr) {
return __awaiter(this, void 0, void 0, function* () {
const path = (0, path_1.resolve)(pathStr || process.argv[1] || process.cwd());
const name = (0, path_1.basename)(path);
const project = findProjectFile(path, 1);
const packages = getProjectPackages(project);
if (packages.length == 0) {
console.log(`[${name}]: No valid SFDX project, checking all cls files`);
const result = yield check(path);
return [Object.assign({ name, path: "." }, result)];
}
const projectDir = (0, path_1.dirname)(project);
const projectResult = yield Promise.all(packages
.map((pkg) => __awaiter(this, void 0, void 0, function* () {
console.log(`[${name}]: Checking package "${pkg}"`);
const pkgPath = (0, path_1.resolve)(projectDir, pkg);
const result = yield check(pkgPath);
return Object.assign({ name,
pkg, path: (0, path_1.relative)(path, pkgPath) }, result);
})));
process.exitCode = Math.max(...projectResult.map(r => r.status));
return projectResult;
});
}
exports.checkProject = checkProject;
function parseFiles(path) {
return __awaiter(this, void 0, void 0, function* () {
const files = yield dir.promiseFiles(path);
let parsedCount = 0;
const errors = [];
files.filter(name => name.endsWith(".cls")).forEach(file => {
if ((0, fs_2.lstatSync)(file).isFile()) {
if ((0, fs_1.lstatSync)(file).isFile()) {
const content = (0, fs_1.readFileSync)(file);

@@ -85,4 +143,8 @@ const lexer = new ApexLexer_1.ApexLexer(new CaseInsensitiveInputStream_1.CaseInsensitiveInputStream(antlr4ts_1.CharStreams.fromString(content.toString())));

catch (err) {
console.log(`Error parsing ${file}`);
console.log(`Error parsing: ${file}`);
console.log(err);
errors.push({
path: (0, path_1.relative)(path, file),
error: JSON.stringify(err)
});
}

@@ -92,6 +154,32 @@ parsedCount += 1;

});
console.log(`Parsed ${parsedCount} files`);
console.log(`Parsed ${parsedCount} files in: ${path}`);
return errors;
});
}
exports.check = check;
function findProjectFile(wd, depth) {
const proj = "sfdx-project.json";
const files = (0, fs_1.readdirSync)(wd).filter(i => !(/(^|\/)\.[^\/\.]/g).test(i));
if (files.includes(proj)) {
return (0, path_1.resolve)(wd, proj);
}
if (depth) {
const dirs = files.map(f => (0, path_1.resolve)(wd, f)).filter(f => (0, fs_1.lstatSync)(f).isDirectory());
const newDepth = depth - 1;
for (const d of dirs) {
const p = findProjectFile(d, newDepth);
if (p) {
return p;
}
}
}
return undefined;
}
function getProjectPackages(projectFilePath) {
if (!projectFilePath) {
return [];
}
const config = JSON.parse((0, fs_1.readFileSync)(projectFilePath, { encoding: "utf8" }));
const packages = config.packageDirectories || [];
return packages.flatMap((p) => p.path ? p.path.replace(/\\/g, "/") : []);
}
//# sourceMappingURL=index.js.map
{
"name": "@apexdevtools/apex-parser",
"version": "3.0.0",
"version": "3.1.0",
"author": "Apex Dev Tools Team <apexdevtools@gmail.com> (https://github.com/apex-dev-tools)",

@@ -10,8 +10,11 @@ "bugs": "https://github.com/apex-dev-tools/apex-parser/issues",

"scripts": {
"build": "npm run antlr4ts && cp ../README.md . && tsc",
"test": "jest --config jestconfig.json lib",
"antlr4ts": "npm run antlr-build && npm run antlr-patch",
"antlr-build": "(cd antlr; antlr4ts -visitor -o ../src ApexLexer.g4 ApexParser.g4)",
"antlr-patch": "node patch",
"check": "node -e require(\"./lib/index.js\").check()'"
"build": "npm run clean && npm run antlr4ts && cp ../*.md . && tsc",
"check": "node -e 'require(\"./lib/index.js\").check()'",
"clean": "rm -rf lib",
"test": "jest --config jestconfig.json lib",
"test-samples": "jest --config sys.jestconfig.json lib",
"test-snapshot": "npm run test-samples -- --updateSnapshot"
},

@@ -18,0 +21,0 @@ "files": [

@@ -1,13 +0,13 @@

apex-parser
===========
# apex-parser
Parser for Salesforce Apex (including Triggers & inline SOQL/SOQL). This is based on an [ANTLR4](https://www.antlr.org/) grammar, see antlr/ApexParser.g4.
Parser for Salesforce Apex (including Triggers & inline SOQL/SOQL). This is based on an [ANTLR4](https://www.antlr.org/) grammar, see antlr/ApexParser.g4.
There are two builds of the parser available, a NPM module for use with Node and a Maven package for use on JVMs.
These builds just contain the Parser & Lexer and provides no further support for analysing the generated parse trees beyond what is provided by ANTLR4.
These builds just contain the Parser & Lexer and provides no further support for analysing the generated parse trees beyond what is provided by ANTLR4.
As Apex & SOQL/SOQL are case-insenstive languages you need to use the provided CaseInsensitiveInputStream for the parser to function correctly. When parsing Apex, inline SOQL/SOSL is automtaically parsed, but you can also parse SOQL/SOQL directly. You can find some minimal examples in the test classes.
As Apex & SOQL/SOQL are case-insenstive languages you need to use the provided CaseInsensitiveInputStream for the parser to function correctly. When parsing Apex, inline SOQL/SOSL is automtaically parsed, but you can also parse SOQL/SOQL directly. You can find some minimal examples in the test classes.
### Example
## Example
To parse a class file (NPM version):

@@ -23,9 +23,10 @@

### Unicode handling
Prior to 2.12.0 the use of ANTLRInputStream for reading data in CaseInsensitiveStream would result character positions being given for UTF-16. The switch to CharStream input in 2.12.0 for JVM and 2.14.0 for node results in character positions reflecting Unicode code points.
## Unicode handling
### antlr4ts versions
Prior to 2.12.0 the use of ANTLRInputStream for reading data in CaseInsensitiveStream would result character positions being given for UTF-16. The switch to CharStream input in 2.12.0 for JVM and 2.14.0 for node results in character positions reflecting Unicode code points.
## antlr4ts versions
The npm module uses antlr4ts 0.5.0-alpha.4, this was updated from 0.5.0-alpha.3 in the 2.9.1 version. You should make
sure that if you are using a matching versions of this dependency if you use it directly. To avoid issues you can
sure that if you are using a matching versions of this dependency if you use it directly. To avoid issues you can
import 'CommonTokenStream' & 'ParseTreeWalker' from 'apex-parser' instead of from antlr4ts.

@@ -36,4 +37,12 @@

### Packages
## SOSL FIND quoting
SOSL FIND uses ' as a quoting character when embedded in Apex, in the API braces are used:
Find {something} RETURNING Account
To parse the API format there is an alternative parser rule, soslLiteralAlt, that you can use instead of soslLiteral. See SOSLParserTest for some examples of how these differ.
## Packages
Maven

@@ -51,3 +60,4 @@

### Building
## Building
To build both distributions:

@@ -57,3 +67,16 @@

### History
## Testing
Unit tests are executed during the respective package builds. The system tests require both packages to be built, as the js test also spawns the jar version. They use a collection of sample projects located in the [apex-samples](https://github.com/apex-dev-tools/apex-samples) repository. Follow the README instructions in apex-samples to checkout the submodules or use `git clone --recurse-submodules <repo-url>`. To run the tests:
# Set SAMPLES env var to samples repo location
export SAMPLES=<abs path to apex-samples>
# Exec test script
npm run test-samples
System test failures relating to the snapshots may highlight regressions. Though if an error is expected or the samples have changed, instead use `npm run test-snapshot` to update the snapshots, then commit the changes.
## History
3.0.0 - Move to @apexdevtools/apex-parser

@@ -81,4 +104,4 @@ 2.14.0 - Change npm api to replace ANTLRInputStream with CharStream, for Unicode char positions

### Source & Licenses
## Source & Licenses
All the source code included uses a 3-clause BSD license. The only third-party component included is the Apex Antlr4 grammar originally from [Tooling-force.com](https://github.com/neowit/tooling-force.com), although this version used is now markedly different from the original.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc