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

@cucumber/gherkin

Package Overview
Dependencies
Maintainers
2
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cucumber/gherkin - npm Package Compare versions

Comparing version 9.1.0 to 9.2.0

.eslintignore

25

dist/package.json
{
"name": "@cucumber/gherkin",
"version": "9.1.0",
"version": "9.2.0",
"description": "Gherkin parser",

@@ -12,4 +12,4 @@ "main": "dist/src/index.js",

"test": "mocha",
"lint": "tslint src/**/*.ts test/**/*.ts",
"lint-fix": "tslint --fix src/**/*.ts test/**/*.ts",
"lint": "eslint --ext ts --max-warnings 0 src test",
"lint-fix": "eslint --ext ts --max-warnings 0 --fix src test",
"coverage": "nyc --reporter=html --reporter=text mocha",

@@ -35,14 +35,19 @@ "build": "tsc",

"@types/mocha": "^5.2.7",
"@types/node": "^13.1.6",
"@types/node": "^13.1.8",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.0",
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"ts-node": "^8.6.0",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.1.0",
"typescript": "^3.7.4"
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
},
"dependencies": {
"@cucumber/messages": "9.0.3",
"@cucumber/messages": "^9.0.3",
"@teppeis/multimaps": "^1.1.0",
"commander": "^4.1.0",

@@ -49,0 +54,0 @@ "source-map-support": "^0.5.16"

4

dist/src/AstBuilder.d.ts

@@ -12,3 +12,3 @@ import AstNode from './AstNode';

startRule(ruleType: RuleType): void;
endRule(ruleType: RuleType): void;
endRule(): void;
build(token: Token): void;

@@ -23,4 +23,4 @@ getResult(): any;

getTableRows(node: AstNode): messages.GherkinDocument.Feature.TableRow[];
ensureCellCount(rows: any[]): void;
ensureCellCount(rows: messages.GherkinDocument.Feature.TableRow[]): void;
transformNode(node: AstNode): string | AstNode | messages.GherkinDocument | messages.GherkinDocument.Feature | messages.GherkinDocument.Feature.Step | messages.GherkinDocument.Feature.Step.DocString | messages.GherkinDocument.Feature.Step.DataTable | messages.GherkinDocument.Feature.TableRow[] | messages.GherkinDocument.Feature.Background | messages.GherkinDocument.Feature.Scenario | messages.GherkinDocument.Feature.Scenario.Examples | messages.GherkinDocument.Feature.FeatureChild.Rule;
}

@@ -37,3 +37,3 @@ "use strict";

};
AstBuilder.prototype.endRule = function (ruleType) {
AstBuilder.prototype.endRule = function () {
var node = this.stack.pop();

@@ -40,0 +40,0 @@ var transformedNode = this.transformNode(node);

@@ -6,4 +6,6 @@ "use strict";

this.ruleType = ruleType;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.subItems = new Map();
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
AstNode.prototype.add = function (type, obj) {

@@ -10,0 +12,0 @@ var items = this.subItems.get(type);

@@ -15,6 +15,6 @@ import { messages } from '@cucumber/messages';

export declare class UnexpectedTokenException extends GherkinException {
static create(token: Token, expectedTokenTypes: string[], stateComment: string): GherkinException;
static create(token: Token, expectedTokenTypes: string[]): GherkinException;
}
export declare class UnexpectedEOFException extends GherkinException {
static create(token: Token, expectedTokenTypes: string[], stateComment: string): GherkinException;
static create(token: Token, expectedTokenTypes: string[]): GherkinException;
}

@@ -21,0 +21,0 @@ export declare class AstBuilderException extends GherkinException {

@@ -72,3 +72,3 @@ "use strict";

}
UnexpectedTokenException.create = function (token, expectedTokenTypes, stateComment) {
UnexpectedTokenException.create = function (token, expectedTokenTypes) {
var message = "expected: " + expectedTokenTypes.join(', ') + ", got '" + token.getTokenValue().trim() + "'";

@@ -86,3 +86,3 @@ var location = tokenLocation(token);

}
UnexpectedEOFException.create = function (token, expectedTokenTypes, stateComment) {
UnexpectedEOFException.create = function (token, expectedTokenTypes) {
var message = "unexpected end of file, expected: " + expectedTokenTypes.join(', ');

@@ -89,0 +89,0 @@ var location = tokenLocation(token);

import { messages } from '@cucumber/messages';
export default class GherkinQuery {
private readonly gherkinDocuments;
private readonly locationByAstNodeId;
private readonly gherkinStepById;
private readonly pickleIdsMapByUri;
private readonly pickleStepIdsMapByUri;
/**

@@ -11,7 +13,16 @@ * Gets the location (line and column) of an AST node.

getLocation(astNodeId: string): messages.ILocation;
getPickleIds(uri: string, lineNumber: number): string[];
getGherkinDocuments(): messages.IGherkinDocument[];
/**
* Gets all the pickle IDs
* @param uri - the URI of the document
* @param lineNumber - optionally restrict results to a particular line number
*/
getPickleIds(uri: string, lineNumber?: number): string[];
getPickleStepIds(uri: string, lineNumber: number): string[];
update(message: messages.IEnvelope): GherkinQuery;
private updateBackground;
private updateScenario;
private updateStep;
private updateGherkinBackground;
private updateGherkinScenario;
private updateGherkinStep;
private updatePickle;
private updatePickleSteps;
}

@@ -13,8 +13,15 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var StrictMap_1 = __importDefault(require("./StrictMap"));
var StrictArrayMultimap_1 = __importDefault(require("./StrictArrayMultimap"));
var GherkinQuery = /** @class */ (function () {
function GherkinQuery() {
this.locationByAstNodeId = new Map();
this.gherkinStepById = new Map();
this.pickleIdsMapByUri = new Map();
this.gherkinDocuments = [];
this.locationByAstNodeId = new StrictMap_1.default();
this.gherkinStepById = new StrictMap_1.default();
this.pickleIdsMapByUri = new StrictMap_1.default();
this.pickleStepIdsMapByUri = new StrictMap_1.default();
}

@@ -26,116 +33,85 @@ /**

GherkinQuery.prototype.getLocation = function (astNodeId) {
var location = this.locationByAstNodeId.get(astNodeId);
if (location === undefined) {
throw new Error("No location found for " + astNodeId + ". Known: " + Array.from(this.locationByAstNodeId.keys()));
}
return location;
return this.locationByAstNodeId.get(astNodeId);
};
GherkinQuery.prototype.getGherkinDocuments = function () {
return this.gherkinDocuments;
};
/**
* Gets all the pickle IDs
* @param uri - the URI of the document
* @param lineNumber - optionally restrict results to a particular line number
*/
GherkinQuery.prototype.getPickleIds = function (uri, lineNumber) {
var pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri);
if (pickleIdsByLineNumber === undefined) {
throw new Error("No document found for uri " + uri + ". Known: " + Array.from(this.pickleIdsMapByUri.keys()));
}
return pickleIdsByLineNumber.get(lineNumber);
return lineNumber === undefined
? Array.from(new Set(pickleIdsByLineNumber.values()))
: pickleIdsByLineNumber.get(lineNumber);
};
GherkinQuery.prototype.getPickleStepIds = function (uri, lineNumber) {
var pickleStepIdsByLineNumber = this.pickleStepIdsMapByUri.get(uri);
return pickleStepIdsByLineNumber.get(lineNumber);
};
GherkinQuery.prototype.update = function (message) {
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
var _this = this;
if (message.gherkinDocument && message.gherkinDocument.feature) {
this.pickleIdsMapByUri.set(message.gherkinDocument.uri, new Map());
try {
for (var _f = __values(message.gherkinDocument.feature.children), _g = _f.next(); !_g.done; _g = _f.next()) {
var featureChild = _g.value;
if (featureChild.background) {
this.updateBackground(featureChild.background, message.gherkinDocument.uri);
}
if (featureChild.scenario) {
this.updateScenario(featureChild.scenario, message.gherkinDocument.uri);
}
if (featureChild.rule) {
var ruleChildren = featureChild.rule.children;
try {
for (var ruleChildren_1 = (e_2 = void 0, __values(ruleChildren)), ruleChildren_1_1 = ruleChildren_1.next(); !ruleChildren_1_1.done; ruleChildren_1_1 = ruleChildren_1.next()) {
var ruleChild = ruleChildren_1_1.value;
if (ruleChild.background) {
this.updateBackground(ruleChild.background, message.gherkinDocument.uri);
var e_1, _a, e_2, _b;
if (message.gherkinDocument) {
this.gherkinDocuments.push(message.gherkinDocument);
if (message.gherkinDocument.feature) {
this.pickleIdsMapByUri.set(message.gherkinDocument.uri, new StrictArrayMultimap_1.default());
this.pickleStepIdsMapByUri.set(message.gherkinDocument.uri, new StrictArrayMultimap_1.default());
try {
for (var _c = __values(message.gherkinDocument.feature.children), _d = _c.next(); !_d.done; _d = _c.next()) {
var featureChild = _d.value;
if (featureChild.background) {
this.updateGherkinBackground(featureChild.background);
}
if (featureChild.scenario) {
this.updateGherkinScenario(featureChild.scenario);
}
if (featureChild.rule) {
var ruleChildren = featureChild.rule.children;
try {
for (var ruleChildren_1 = (e_2 = void 0, __values(ruleChildren)), ruleChildren_1_1 = ruleChildren_1.next(); !ruleChildren_1_1.done; ruleChildren_1_1 = ruleChildren_1.next()) {
var ruleChild = ruleChildren_1_1.value;
if (ruleChild.background) {
this.updateGherkinBackground(ruleChild.background);
}
if (ruleChild.scenario) {
this.updateGherkinScenario(ruleChild.scenario);
}
}
if (ruleChild.scenario) {
this.updateScenario(ruleChild.scenario, message.gherkinDocument.uri);
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (ruleChildren_1_1 && !ruleChildren_1_1.done && (_b = ruleChildren_1.return)) _b.call(ruleChildren_1);
}
finally { if (e_2) throw e_2.error; }
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (ruleChildren_1_1 && !ruleChildren_1_1.done && (_b = ruleChildren_1.return)) _b.call(ruleChildren_1);
}
finally { if (e_2) throw e_2.error; }
}
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
}
finally { if (e_1) throw e_1.error; }
}
}
if (message.pickle) {
var pickleIdsByLineNumber = this.pickleIdsMapByUri.get(message.pickle.uri);
var pickleLineNumbers = message.pickle.astNodeIds.map(function (astNodeId) { return _this.locationByAstNodeId.get(astNodeId).line; });
try {
for (var pickleLineNumbers_1 = __values(pickleLineNumbers), pickleLineNumbers_1_1 = pickleLineNumbers_1.next(); !pickleLineNumbers_1_1.done; pickleLineNumbers_1_1 = pickleLineNumbers_1.next()) {
var pickleLineNumber = pickleLineNumbers_1_1.value;
pickleIdsByLineNumber.get(pickleLineNumber).push(message.pickle.id);
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (pickleLineNumbers_1_1 && !pickleLineNumbers_1_1.done && (_c = pickleLineNumbers_1.return)) _c.call(pickleLineNumbers_1);
}
finally { if (e_3) throw e_3.error; }
}
try {
for (var _h = __values(message.pickle.steps), _j = _h.next(); !_j.done; _j = _h.next()) {
var pickleStep = _j.value;
var stepLineNumbers = pickleStep.astNodeIds.map(function (astNodeId) { return _this.locationByAstNodeId.get(astNodeId).line; });
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
for (var stepLineNumbers_1 = (e_5 = void 0, __values(stepLineNumbers)), stepLineNumbers_1_1 = stepLineNumbers_1.next(); !stepLineNumbers_1_1.done; stepLineNumbers_1_1 = stepLineNumbers_1.next()) {
var stepLineNumber = stepLineNumbers_1_1.value;
pickleIdsByLineNumber.get(stepLineNumber).push(pickleStep.id);
}
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
}
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {
try {
if (stepLineNumbers_1_1 && !stepLineNumbers_1_1.done && (_e = stepLineNumbers_1.return)) _e.call(stepLineNumbers_1);
}
finally { if (e_5) throw e_5.error; }
}
finally { if (e_1) throw e_1.error; }
}
}
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {
try {
if (_j && !_j.done && (_d = _h.return)) _d.call(_h);
}
finally { if (e_4) throw e_4.error; }
}
}
if (message.pickle) {
var pickle = message.pickle;
this.updatePickle(pickle);
}
return this;
};
GherkinQuery.prototype.updateBackground = function (background, uri) {
var e_6, _a;
var pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri);
pickleIdsByLineNumber.set(background.location.line, []);
GherkinQuery.prototype.updateGherkinBackground = function (background) {
var e_3, _a;
try {
for (var _b = __values(background.steps), _c = _b.next(); !_c.done; _c = _b.next()) {
var step = _c.value;
this.updateStep(step, uri);
this.updateGherkinStep(step);
}
}
catch (e_6_1) { e_6 = { error: e_6_1 }; }
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {

@@ -145,17 +121,15 @@ try {

}
finally { if (e_6) throw e_6.error; }
finally { if (e_3) throw e_3.error; }
}
};
GherkinQuery.prototype.updateScenario = function (scenario, uri) {
var e_7, _a, e_8, _b, e_9, _c;
GherkinQuery.prototype.updateGherkinScenario = function (scenario) {
var e_4, _a, e_5, _b, e_6, _c;
this.locationByAstNodeId.set(scenario.id, scenario.location);
var pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri);
pickleIdsByLineNumber.set(scenario.location.line, []);
try {
for (var _d = __values(scenario.steps), _e = _d.next(); !_e.done; _e = _d.next()) {
var step = _e.value;
this.updateStep(step, uri);
this.updateGherkinStep(step);
}
}
catch (e_7_1) { e_7 = { error: e_7_1 }; }
catch (e_4_1) { e_4 = { error: e_4_1 }; }
finally {

@@ -165,3 +139,3 @@ try {

}
finally { if (e_7) throw e_7.error; }
finally { if (e_4) throw e_4.error; }
}

@@ -172,9 +146,8 @@ try {

try {
for (var _h = (e_9 = void 0, __values(examples.tableBody)), _j = _h.next(); !_j.done; _j = _h.next()) {
for (var _h = (e_6 = void 0, __values(examples.tableBody)), _j = _h.next(); !_j.done; _j = _h.next()) {
var tableRow = _j.value;
this.locationByAstNodeId.set(tableRow.id, tableRow.location);
pickleIdsByLineNumber.set(tableRow.location.line, []);
}
}
catch (e_9_1) { e_9 = { error: e_9_1 }; }
catch (e_6_1) { e_6 = { error: e_6_1 }; }
finally {

@@ -184,7 +157,7 @@ try {

}
finally { if (e_9) throw e_9.error; }
finally { if (e_6) throw e_6.error; }
}
}
}
catch (e_8_1) { e_8 = { error: e_8_1 }; }
catch (e_5_1) { e_5 = { error: e_5_1 }; }
finally {

@@ -194,11 +167,63 @@ try {

}
finally { if (e_8) throw e_8.error; }
finally { if (e_5) throw e_5.error; }
}
};
GherkinQuery.prototype.updateStep = function (step, uri) {
GherkinQuery.prototype.updateGherkinStep = function (step) {
this.locationByAstNodeId.set(step.id, step.location);
this.gherkinStepById.set(step.id, step);
var pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri);
pickleIdsByLineNumber.set(step.location.line, []);
};
GherkinQuery.prototype.updatePickle = function (pickle) {
var e_7, _a;
var _this = this;
var pickleIdsByLineNumber = this.pickleIdsMapByUri.get(pickle.uri);
var pickleLineNumbers = pickle.astNodeIds.map(function (astNodeId) { return _this.locationByAstNodeId.get(astNodeId).line; });
try {
for (var pickleLineNumbers_1 = __values(pickleLineNumbers), pickleLineNumbers_1_1 = pickleLineNumbers_1.next(); !pickleLineNumbers_1_1.done; pickleLineNumbers_1_1 = pickleLineNumbers_1.next()) {
var pickleLineNumber = pickleLineNumbers_1_1.value;
// if (!pickleIdsByLineNumber.has(pickleLineNumber)) {
pickleIdsByLineNumber.put(pickleLineNumber, pickle.id);
// }
}
}
catch (e_7_1) { e_7 = { error: e_7_1 }; }
finally {
try {
if (pickleLineNumbers_1_1 && !pickleLineNumbers_1_1.done && (_a = pickleLineNumbers_1.return)) _a.call(pickleLineNumbers_1);
}
finally { if (e_7) throw e_7.error; }
}
this.updatePickleSteps(pickle);
};
GherkinQuery.prototype.updatePickleSteps = function (pickle) {
var e_8, _a, e_9, _b;
var _this = this;
var pickleStepIdsByLineNumber = this.pickleStepIdsMapByUri.get(pickle.uri);
var pickleSteps = pickle.steps;
try {
for (var pickleSteps_1 = __values(pickleSteps), pickleSteps_1_1 = pickleSteps_1.next(); !pickleSteps_1_1.done; pickleSteps_1_1 = pickleSteps_1.next()) {
var pickleStep = pickleSteps_1_1.value;
var stepLineNumbers = pickleStep.astNodeIds.map(function (astNodeId) { return _this.locationByAstNodeId.get(astNodeId).line; });
try {
for (var stepLineNumbers_1 = (e_9 = void 0, __values(stepLineNumbers)), stepLineNumbers_1_1 = stepLineNumbers_1.next(); !stepLineNumbers_1_1.done; stepLineNumbers_1_1 = stepLineNumbers_1.next()) {
var stepLineNumber = stepLineNumbers_1_1.value;
pickleStepIdsByLineNumber.put(stepLineNumber, pickleStep.id);
}
}
catch (e_9_1) { e_9 = { error: e_9_1 }; }
finally {
try {
if (stepLineNumbers_1_1 && !stepLineNumbers_1_1.done && (_b = stepLineNumbers_1.return)) _b.call(stepLineNumbers_1);
}
finally { if (e_9) throw e_9.error; }
}
}
}
catch (e_8_1) { e_8 = { error: e_8_1 }; }
finally {
try {
if (pickleSteps_1_1 && !pickleSteps_1_1.done && (_a = pickleSteps_1.return)) _a.call(pickleSteps_1);
}
finally { if (e_8) throw e_8.error; }
}
};
return GherkinQuery;

@@ -205,0 +230,0 @@ }());

import Gherkin from './Gherkin';
import IGherkinOptions from './IGherkinOptions';
import GherkinQuery from './GherkinQuery';
import StrictArrayMultimap from './StrictArrayMultimap';
import StrictMap from './StrictMap';
export default Gherkin;
export { IGherkinOptions, GherkinQuery };
export { IGherkinOptions, GherkinQuery, StrictArrayMultimap, StrictMap };

@@ -9,3 +9,7 @@ "use strict";

exports.GherkinQuery = GherkinQuery_1.default;
var StrictArrayMultimap_1 = __importDefault(require("./StrictArrayMultimap"));
exports.StrictArrayMultimap = StrictArrayMultimap_1.default;
var StrictMap_1 = __importDefault(require("./StrictMap"));
exports.StrictMap = StrictMap_1.default;
exports.default = Gherkin_1.default;
//# sourceMappingURL=index.js.map

@@ -133,5 +133,2 @@ "use strict";

}
function pickleSteps(scenario, variableCells, valuesRow, newId) {
return scenario.steps.map(function (s) { return pickleStep(s, variableCells, valuesRow, newId); });
}
function pickleStep(step, variableCells, valuesRow, newId) {

@@ -138,0 +135,0 @@ var astNodeIds = [step.id];

{
"name": "@cucumber/gherkin",
"version": "9.1.0",
"version": "9.2.0",
"description": "Gherkin parser",

@@ -12,4 +12,4 @@ "main": "dist/src/index.js",

"test": "mocha",
"lint": "tslint src/**/*.ts test/**/*.ts",
"lint-fix": "tslint --fix src/**/*.ts test/**/*.ts",
"lint": "eslint --ext ts --max-warnings 0 src test",
"lint-fix": "eslint --ext ts --max-warnings 0 --fix src test",
"coverage": "nyc --reporter=html --reporter=text mocha",

@@ -35,14 +35,19 @@ "build": "tsc",

"@types/mocha": "^5.2.7",
"@types/node": "^13.1.6",
"@types/node": "^13.1.8",
"@typescript-eslint/eslint-plugin": "^2.17.0",
"@typescript-eslint/parser": "^2.17.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.0",
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"prettier": "^1.19.1",
"ts-node": "^8.6.0",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.1.0",
"typescript": "^3.7.4"
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
},
"dependencies": {
"@cucumber/messages": "9.0.3",
"@cucumber/messages": "^9.0.3",
"@teppeis/multimaps": "^1.1.0",
"commander": "^4.1.0",

@@ -49,0 +54,0 @@ "source-map-support": "^0.5.16"

@@ -30,3 +30,3 @@ import AstNode from './AstNode'

public endRule(ruleType: RuleType) {
public endRule() {
const node = this.stack.pop()

@@ -114,3 +114,3 @@ const transformedNode = this.transformNode(node)

public ensureCellCount(rows: any[]) {
public ensureCellCount(rows: messages.GherkinDocument.Feature.TableRow[]) {
if (rows.length === 0) {

@@ -117,0 +117,0 @@ return

@@ -5,2 +5,3 @@ import { RuleType, TokenType } from './Parser'

export default class AstNode {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private readonly subItems = new Map<any, any[]>()

@@ -10,2 +11,3 @@

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public add(type: any, obj: any) {

@@ -12,0 +14,0 @@ let items = this.subItems.get(type)

@@ -44,7 +44,3 @@ import { messages } from '@cucumber/messages'

export class UnexpectedTokenException extends GherkinException {
public static create(
token: Token,
expectedTokenTypes: string[],
stateComment: string
) {
public static create(token: Token, expectedTokenTypes: string[]) {
const message = `expected: ${expectedTokenTypes.join(

@@ -61,7 +57,3 @@ ', '

export class UnexpectedEOFException extends GherkinException {
public static create(
token: Token,
expectedTokenTypes: string[],
stateComment: string
) {
public static create(token: Token, expectedTokenTypes: string[]) {
const message = `unexpected end of file, expected: ${expectedTokenTypes.join(

@@ -68,0 +60,0 @@ ', '

import { messages } from '@cucumber/messages'
import StrictMap from './StrictMap'
import StrictArrayMultimap from './StrictArrayMultimap'
export default class GherkinQuery {
private readonly locationByAstNodeId = new Map<string, messages.ILocation>()
private readonly gherkinStepById = new Map<
private readonly gherkinDocuments: messages.IGherkinDocument[] = []
private readonly locationByAstNodeId = new StrictMap<
string,
messages.ILocation
>()
private readonly gherkinStepById = new StrictMap<
string,
messages.GherkinDocument.Feature.IStep
>()
private readonly pickleIdsMapByUri = new Map<string, Map<number, string[]>>()
private readonly pickleIdsMapByUri = new StrictMap<
string,
StrictArrayMultimap<number, string>
>()
private readonly pickleStepIdsMapByUri = new StrictMap<
string,
StrictArrayMultimap<number, string>
>()

@@ -16,62 +29,58 @@ /**

public getLocation(astNodeId: string): messages.ILocation {
const location = this.locationByAstNodeId.get(astNodeId)
if (location === undefined) {
throw new Error(
`No location found for ${astNodeId}. Known: ${Array.from(
this.locationByAstNodeId.keys()
)}`
)
}
return location
return this.locationByAstNodeId.get(astNodeId)
}
public getPickleIds(uri: string, lineNumber: number): string[] {
public getGherkinDocuments(): messages.IGherkinDocument[] {
return this.gherkinDocuments
}
/**
* Gets all the pickle IDs
* @param uri - the URI of the document
* @param lineNumber - optionally restrict results to a particular line number
*/
public getPickleIds(uri: string, lineNumber?: number): string[] {
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri)
if (pickleIdsByLineNumber === undefined) {
throw new Error(
`No document found for uri ${uri}. Known: ${Array.from(
this.pickleIdsMapByUri.keys()
)}`
)
}
return pickleIdsByLineNumber.get(lineNumber)
return lineNumber === undefined
? Array.from(new Set(pickleIdsByLineNumber.values()))
: pickleIdsByLineNumber.get(lineNumber)
}
public getPickleStepIds(uri: string, lineNumber: number): string[] {
const pickleStepIdsByLineNumber = this.pickleStepIdsMapByUri.get(uri)
return pickleStepIdsByLineNumber.get(lineNumber)
}
public update(message: messages.IEnvelope): GherkinQuery {
if (message.gherkinDocument && message.gherkinDocument.feature) {
this.pickleIdsMapByUri.set(
message.gherkinDocument.uri,
new Map<number, string[]>()
)
if (message.gherkinDocument) {
this.gherkinDocuments.push(message.gherkinDocument)
if (message.gherkinDocument.feature) {
this.pickleIdsMapByUri.set(
message.gherkinDocument.uri,
new StrictArrayMultimap<number, string>()
)
this.pickleStepIdsMapByUri.set(
message.gherkinDocument.uri,
new StrictArrayMultimap<number, string>()
)
for (const featureChild of message.gherkinDocument.feature.children) {
if (featureChild.background) {
this.updateBackground(
featureChild.background,
message.gherkinDocument.uri
)
}
for (const featureChild of message.gherkinDocument.feature.children) {
if (featureChild.background) {
this.updateGherkinBackground(featureChild.background)
}
if (featureChild.scenario) {
this.updateScenario(
featureChild.scenario,
message.gherkinDocument.uri
)
}
if (featureChild.scenario) {
this.updateGherkinScenario(featureChild.scenario)
}
if (featureChild.rule) {
const ruleChildren = featureChild.rule.children
for (const ruleChild of ruleChildren) {
if (ruleChild.background) {
this.updateBackground(
ruleChild.background,
message.gherkinDocument.uri
)
}
if (featureChild.rule) {
const ruleChildren = featureChild.rule.children
for (const ruleChild of ruleChildren) {
if (ruleChild.background) {
this.updateGherkinBackground(ruleChild.background)
}
if (ruleChild.scenario) {
this.updateScenario(
ruleChild.scenario,
message.gherkinDocument.uri
)
if (ruleChild.scenario) {
this.updateGherkinScenario(ruleChild.scenario)
}
}

@@ -84,20 +93,4 @@ }

if (message.pickle) {
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(
message.pickle.uri
)
const pickleLineNumbers = message.pickle.astNodeIds.map(
astNodeId => this.locationByAstNodeId.get(astNodeId).line
)
for (const pickleLineNumber of pickleLineNumbers) {
pickleIdsByLineNumber.get(pickleLineNumber).push(message.pickle.id)
}
for (const pickleStep of message.pickle.steps) {
const stepLineNumbers = pickleStep.astNodeIds.map(
astNodeId => this.locationByAstNodeId.get(astNodeId).line
)
for (const stepLineNumber of stepLineNumbers) {
pickleIdsByLineNumber.get(stepLineNumber).push(pickleStep.id)
}
}
const pickle = message.pickle
this.updatePickle(pickle)
}

@@ -108,24 +101,16 @@

private updateBackground(
background: messages.GherkinDocument.Feature.IBackground,
uri: string
private updateGherkinBackground(
background: messages.GherkinDocument.Feature.IBackground
) {
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri)
pickleIdsByLineNumber.set(background.location.line, [])
for (const step of background.steps) {
this.updateStep(step, uri)
this.updateGherkinStep(step)
}
}
private updateScenario(
scenario: messages.GherkinDocument.Feature.IScenario,
uri: string
private updateGherkinScenario(
scenario: messages.GherkinDocument.Feature.IScenario
) {
this.locationByAstNodeId.set(scenario.id, scenario.location)
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri)
pickleIdsByLineNumber.set(scenario.location.line, [])
for (const step of scenario.steps) {
this.updateStep(step, uri)
this.updateGherkinStep(step)
}

@@ -136,3 +121,2 @@

this.locationByAstNodeId.set(tableRow.id, tableRow.location)
pickleIdsByLineNumber.set(tableRow.location.line, [])
}

@@ -142,12 +126,32 @@ }

private updateStep(
step: messages.GherkinDocument.Feature.IStep,
uri: string
) {
private updateGherkinStep(step: messages.GherkinDocument.Feature.IStep) {
this.locationByAstNodeId.set(step.id, step.location)
this.gherkinStepById.set(step.id, step)
}
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(uri)
pickleIdsByLineNumber.set(step.location.line, [])
private updatePickle(pickle: messages.IPickle) {
const pickleIdsByLineNumber = this.pickleIdsMapByUri.get(pickle.uri)
const pickleLineNumbers = pickle.astNodeIds.map(
astNodeId => this.locationByAstNodeId.get(astNodeId).line
)
for (const pickleLineNumber of pickleLineNumbers) {
// if (!pickleIdsByLineNumber.has(pickleLineNumber)) {
pickleIdsByLineNumber.put(pickleLineNumber, pickle.id)
// }
}
this.updatePickleSteps(pickle)
}
private updatePickleSteps(pickle: messages.IPickle) {
const pickleStepIdsByLineNumber = this.pickleStepIdsMapByUri.get(pickle.uri)
const pickleSteps = pickle.steps
for (const pickleStep of pickleSteps) {
const stepLineNumbers = pickleStep.astNodeIds.map(
astNodeId => this.locationByAstNodeId.get(astNodeId).line
)
for (const stepLineNumber of stepLineNumbers) {
pickleStepIdsByLineNumber.put(stepLineNumber, pickleStep.id)
}
}
}
}
import Gherkin from './Gherkin'
import IGherkinOptions from './IGherkinOptions'
import GherkinQuery from './GherkinQuery'
import StrictArrayMultimap from './StrictArrayMultimap'
import StrictMap from './StrictMap'
export default Gherkin
export { IGherkinOptions, GherkinQuery }
export { IGherkinOptions, GherkinQuery, StrictArrayMultimap, StrictMap }

@@ -232,11 +232,2 @@ import { messages, IdGenerator } from '@cucumber/messages'

function pickleSteps(
scenario: messages.GherkinDocument.Feature.IScenario,
variableCells: messages.GherkinDocument.Feature.TableRow.ITableCell[],
valuesRow: messages.GherkinDocument.Feature.ITableRow,
newId: IdGenerator.NewId
) {
return scenario.steps.map(s => pickleStep(s, variableCells, valuesRow, newId))
}
function pickleStep(

@@ -243,0 +234,0 @@ step: messages.GherkinDocument.Feature.IStep,

import Token from './Token'
import GherkinLine from './GherkinLine'
import { messages } from '@cucumber/messages'
import createLocation from './cli/createLocation'

@@ -5,0 +4,0 @@

@@ -27,4 +27,5 @@ {

"src/**/*",
"test/**/*"
"test/**/*",
"features/**/*"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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 not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

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