@cucumber/gherkin
Advanced tools
Comparing version 17.0.2 to 18.0.0
{ | ||
"require": ["ts-node/register", "source-map-support/register"], | ||
"require": ["tsconfig-paths/register", "ts-node/register", "source-map-support/register"], | ||
"extension": ["ts", "tsx"], | ||
"recursive": true, | ||
"timeout": 10000 | ||
"timeout": 10000 | ||
} |
{ | ||
"name": "@cucumber/gherkin", | ||
"version": "17.0.2", | ||
"version": "18.0.0", | ||
"description": "Gherkin parser", | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"bin": { | ||
"gherkin-javascript": "bin/gherkin" | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"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", | ||
"build": "tsc", | ||
"prepublishOnly": "npm run build" | ||
"prepublishOnly": "tsc --build tsconfig.build.json" | ||
}, | ||
@@ -33,23 +26,12 @@ "repository": { | ||
"devDependencies": { | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.28", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"core-js": "^3.8.3", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"eslint-plugin-react": "^7.22.0", | ||
"mocha": "^8.3.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.2.1", | ||
"@types/mocha": "^8.2.2", | ||
"@types/node": "^14.14.35", | ||
"core-js": "^3.9.1", | ||
"mocha": "^8.3.2", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.5" | ||
"typescript": "^4.2.3" | ||
}, | ||
"dependencies": { | ||
"@cucumber/messages": "^14.0.1", | ||
"commander": "^7.1.0", | ||
"source-map-support": "^0.5.19" | ||
"@cucumber/messages": "^15.0.0", | ||
"@cucumber/message-streams": "^1.0.0" | ||
}, | ||
@@ -56,0 +38,0 @@ "directories": { |
@@ -26,1 +26,2 @@ import AstNode from './AstNode'; | ||
} | ||
//# sourceMappingURL=AstBuilder.d.ts.map |
"use strict"; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -17,9 +6,9 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var AstNode_1 = __importDefault(require("./AstNode")); | ||
var messages_1 = require("@cucumber/messages"); | ||
var Parser_1 = require("./Parser"); | ||
var Errors_1 = require("./Errors"); | ||
var createLocation_1 = __importDefault(require("./cli/createLocation")); | ||
var AstBuilder = /** @class */ (function () { | ||
function AstBuilder(newId) { | ||
const AstNode_1 = __importDefault(require("./AstNode")); | ||
const messages_1 = require("@cucumber/messages"); | ||
const Parser_1 = require("./Parser"); | ||
const Errors_1 = require("./Errors"); | ||
const createLocation_1 = __importDefault(require("./createLocation")); | ||
class AstBuilder { | ||
constructor(newId) { | ||
this.newId = newId; | ||
@@ -31,15 +20,15 @@ if (!newId) { | ||
} | ||
AstBuilder.prototype.reset = function () { | ||
reset() { | ||
this.stack = [new AstNode_1.default(Parser_1.RuleType.None)]; | ||
this.comments = []; | ||
}; | ||
AstBuilder.prototype.startRule = function (ruleType) { | ||
} | ||
startRule(ruleType) { | ||
this.stack.push(new AstNode_1.default(ruleType)); | ||
}; | ||
AstBuilder.prototype.endRule = function () { | ||
var node = this.stack.pop(); | ||
var transformedNode = this.transformNode(node); | ||
} | ||
endRule() { | ||
const node = this.stack.pop(); | ||
const transformedNode = this.transformNode(node); | ||
this.currentNode().add(node.ruleType, transformedNode); | ||
}; | ||
AstBuilder.prototype.build = function (token) { | ||
} | ||
build(token) { | ||
if (token.matchedType === Parser_1.TokenType.Comment) { | ||
@@ -54,86 +43,57 @@ this.comments.push(messages_1.messages.GherkinDocument.Comment.create({ | ||
} | ||
}; | ||
AstBuilder.prototype.getResult = function () { | ||
} | ||
getResult() { | ||
return this.currentNode().getSingle(Parser_1.RuleType.GherkinDocument); | ||
}; | ||
AstBuilder.prototype.currentNode = function () { | ||
} | ||
currentNode() { | ||
return this.stack[this.stack.length - 1]; | ||
}; | ||
AstBuilder.prototype.getLocation = function (token, column) { | ||
return !column | ||
? token.location | ||
: createLocation_1.default({ line: token.location.line, column: column }); | ||
}; | ||
AstBuilder.prototype.getTags = function (node) { | ||
var e_1, _a, e_2, _b; | ||
var tags = []; | ||
var tagsNode = node.getSingle(Parser_1.RuleType.Tags); | ||
} | ||
getLocation(token, column) { | ||
return !column ? token.location : createLocation_1.default({ line: token.location.line, column }); | ||
} | ||
getTags(node) { | ||
const tags = []; | ||
const tagsNode = node.getSingle(Parser_1.RuleType.Tags); | ||
if (!tagsNode) { | ||
return tags; | ||
} | ||
var tokens = tagsNode.getTokens(Parser_1.TokenType.TagLine); | ||
try { | ||
for (var tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) { | ||
var token = tokens_1_1.value; | ||
try { | ||
for (var _c = (e_2 = void 0, __values(token.matchedItems)), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
var tagItem = _d.value; | ||
tags.push(messages_1.messages.GherkinDocument.Feature.Tag.create({ | ||
location: this.getLocation(token, tagItem.column), | ||
name: tagItem.text, | ||
id: this.newId(), | ||
})); | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_d && !_d.done && (_b = _c.return)) _b.call(_c); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
const tokens = tagsNode.getTokens(Parser_1.TokenType.TagLine); | ||
for (const token of tokens) { | ||
for (const tagItem of token.matchedItems) { | ||
tags.push(messages_1.messages.GherkinDocument.Feature.Tag.create({ | ||
location: this.getLocation(token, tagItem.column), | ||
name: tagItem.text, | ||
id: this.newId(), | ||
})); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return tags; | ||
}; | ||
AstBuilder.prototype.getCells = function (tableRowToken) { | ||
var _this = this; | ||
return tableRowToken.matchedItems.map(function (cellItem) { | ||
return messages_1.messages.GherkinDocument.Feature.TableRow.TableCell.create({ | ||
location: _this.getLocation(tableRowToken, cellItem.column), | ||
value: cellItem.text, | ||
}); | ||
}); | ||
}; | ||
AstBuilder.prototype.getDescription = function (node) { | ||
} | ||
getCells(tableRowToken) { | ||
return tableRowToken.matchedItems.map((cellItem) => messages_1.messages.GherkinDocument.Feature.TableRow.TableCell.create({ | ||
location: this.getLocation(tableRowToken, cellItem.column), | ||
value: cellItem.text, | ||
})); | ||
} | ||
getDescription(node) { | ||
return node.getSingle(Parser_1.RuleType.Description); | ||
}; | ||
AstBuilder.prototype.getSteps = function (node) { | ||
} | ||
getSteps(node) { | ||
return node.getItems(Parser_1.RuleType.Step); | ||
}; | ||
AstBuilder.prototype.getTableRows = function (node) { | ||
var _this = this; | ||
var rows = node.getTokens(Parser_1.TokenType.TableRow).map(function (token) { | ||
return messages_1.messages.GherkinDocument.Feature.TableRow.create({ | ||
id: _this.newId(), | ||
location: _this.getLocation(token), | ||
cells: _this.getCells(token), | ||
}); | ||
}); | ||
} | ||
getTableRows(node) { | ||
const rows = node.getTokens(Parser_1.TokenType.TableRow).map((token) => messages_1.messages.GherkinDocument.Feature.TableRow.create({ | ||
id: this.newId(), | ||
location: this.getLocation(token), | ||
cells: this.getCells(token), | ||
})); | ||
this.ensureCellCount(rows); | ||
return rows; | ||
}; | ||
AstBuilder.prototype.ensureCellCount = function (rows) { | ||
} | ||
ensureCellCount(rows) { | ||
if (rows.length === 0) { | ||
return; | ||
} | ||
var cellCount = rows[0].cells.length; | ||
rows.forEach(function (row) { | ||
const cellCount = rows[0].cells.length; | ||
rows.forEach((row) => { | ||
if (row.cells.length !== cellCount) { | ||
@@ -143,10 +103,9 @@ throw Errors_1.AstBuilderException.create('inconsistent cell count within the table', row.location); | ||
}); | ||
}; | ||
AstBuilder.prototype.transformNode = function (node) { | ||
var e_3, _a, e_4, _b, e_5, _c; | ||
} | ||
transformNode(node) { | ||
switch (node.ruleType) { | ||
case Parser_1.RuleType.Step: { | ||
var stepLine = node.getToken(Parser_1.TokenType.StepLine); | ||
var dataTable = node.getSingle(Parser_1.RuleType.DataTable); | ||
var docString = node.getSingle(Parser_1.RuleType.DocString); | ||
const stepLine = node.getToken(Parser_1.TokenType.StepLine); | ||
const dataTable = node.getSingle(Parser_1.RuleType.DataTable); | ||
const docString = node.getSingle(Parser_1.RuleType.DocString); | ||
return messages_1.messages.GherkinDocument.Feature.Step.create({ | ||
@@ -157,16 +116,14 @@ id: this.newId(), | ||
text: stepLine.matchedText, | ||
dataTable: dataTable, | ||
docString: docString, | ||
dataTable, | ||
docString, | ||
}); | ||
} | ||
case Parser_1.RuleType.DocString: { | ||
var separatorToken = node.getTokens(Parser_1.TokenType.DocStringSeparator)[0]; | ||
var mediaType = separatorToken.matchedText.length > 0 | ||
? separatorToken.matchedText | ||
: undefined; | ||
var lineTokens = node.getTokens(Parser_1.TokenType.Other); | ||
var content = lineTokens.map(function (t) { return t.matchedText; }).join('\n'); | ||
var result = messages_1.messages.GherkinDocument.Feature.Step.DocString.create({ | ||
const separatorToken = node.getTokens(Parser_1.TokenType.DocStringSeparator)[0]; | ||
const mediaType = separatorToken.matchedText.length > 0 ? separatorToken.matchedText : undefined; | ||
const lineTokens = node.getTokens(Parser_1.TokenType.Other); | ||
const content = lineTokens.map((t) => t.matchedText).join('\n'); | ||
const result = messages_1.messages.GherkinDocument.Feature.Step.DocString.create({ | ||
location: this.getLocation(separatorToken), | ||
content: content, | ||
content, | ||
delimiter: separatorToken.line.trimmedLineText.substring(0, 3), | ||
@@ -181,12 +138,12 @@ }); | ||
case Parser_1.RuleType.DataTable: { | ||
var rows = this.getTableRows(node); | ||
const rows = this.getTableRows(node); | ||
return messages_1.messages.GherkinDocument.Feature.Step.DataTable.create({ | ||
location: rows[0].location, | ||
rows: rows, | ||
rows, | ||
}); | ||
} | ||
case Parser_1.RuleType.Background: { | ||
var backgroundLine = node.getToken(Parser_1.TokenType.BackgroundLine); | ||
var description = this.getDescription(node); | ||
var steps = this.getSteps(node); | ||
const backgroundLine = node.getToken(Parser_1.TokenType.BackgroundLine); | ||
const description = this.getDescription(node); | ||
const steps = this.getSteps(node); | ||
return messages_1.messages.GherkinDocument.Feature.Background.create({ | ||
@@ -197,37 +154,37 @@ id: this.newId(), | ||
name: backgroundLine.matchedText, | ||
description: description, | ||
steps: steps, | ||
description, | ||
steps, | ||
}); | ||
} | ||
case Parser_1.RuleType.ScenarioDefinition: { | ||
var tags = this.getTags(node); | ||
var scenarioNode = node.getSingle(Parser_1.RuleType.Scenario); | ||
var scenarioLine = scenarioNode.getToken(Parser_1.TokenType.ScenarioLine); | ||
var description = this.getDescription(scenarioNode); | ||
var steps = this.getSteps(scenarioNode); | ||
var examples = scenarioNode.getItems(Parser_1.RuleType.ExamplesDefinition); | ||
const tags = this.getTags(node); | ||
const scenarioNode = node.getSingle(Parser_1.RuleType.Scenario); | ||
const scenarioLine = scenarioNode.getToken(Parser_1.TokenType.ScenarioLine); | ||
const description = this.getDescription(scenarioNode); | ||
const steps = this.getSteps(scenarioNode); | ||
const examples = scenarioNode.getItems(Parser_1.RuleType.ExamplesDefinition); | ||
return messages_1.messages.GherkinDocument.Feature.Scenario.create({ | ||
id: this.newId(), | ||
tags: tags, | ||
tags, | ||
location: this.getLocation(scenarioLine), | ||
keyword: scenarioLine.matchedKeyword, | ||
name: scenarioLine.matchedText, | ||
description: description, | ||
steps: steps, | ||
examples: examples, | ||
description, | ||
steps, | ||
examples, | ||
}); | ||
} | ||
case Parser_1.RuleType.ExamplesDefinition: { | ||
var tags = this.getTags(node); | ||
var examplesNode = node.getSingle(Parser_1.RuleType.Examples); | ||
var examplesLine = examplesNode.getToken(Parser_1.TokenType.ExamplesLine); | ||
var description = this.getDescription(examplesNode); | ||
var exampleTable = examplesNode.getSingle(Parser_1.RuleType.ExamplesTable); | ||
const tags = this.getTags(node); | ||
const examplesNode = node.getSingle(Parser_1.RuleType.Examples); | ||
const examplesLine = examplesNode.getToken(Parser_1.TokenType.ExamplesLine); | ||
const description = this.getDescription(examplesNode); | ||
const exampleTable = examplesNode.getSingle(Parser_1.RuleType.ExamplesTable); | ||
return messages_1.messages.GherkinDocument.Feature.Scenario.Examples.create({ | ||
id: this.newId(), | ||
tags: tags, | ||
tags, | ||
location: this.getLocation(examplesLine), | ||
keyword: examplesLine.matchedKeyword, | ||
name: examplesLine.matchedText, | ||
description: description, | ||
description, | ||
tableHeader: exampleTable !== undefined ? exampleTable[0] : undefined, | ||
@@ -241,5 +198,5 @@ tableBody: exampleTable !== undefined ? exampleTable.slice(1) : undefined, | ||
case Parser_1.RuleType.Description: { | ||
var lineTokens = node.getTokens(Parser_1.TokenType.Other); | ||
let lineTokens = node.getTokens(Parser_1.TokenType.Other); | ||
// Trim trailing empty lines | ||
var end = lineTokens.length; | ||
let end = lineTokens.length; | ||
while (end > 0 && lineTokens[end - 1].line.trimmedLineText === '') { | ||
@@ -249,95 +206,66 @@ end--; | ||
lineTokens = lineTokens.slice(0, end); | ||
return lineTokens.map(function (token) { return token.matchedText; }).join('\n'); | ||
return lineTokens.map((token) => token.matchedText).join('\n'); | ||
} | ||
case Parser_1.RuleType.Feature: { | ||
var header = node.getSingle(Parser_1.RuleType.FeatureHeader); | ||
const header = node.getSingle(Parser_1.RuleType.FeatureHeader); | ||
if (!header) { | ||
return null; | ||
} | ||
var tags = this.getTags(header); | ||
var featureLine = header.getToken(Parser_1.TokenType.FeatureLine); | ||
const tags = this.getTags(header); | ||
const featureLine = header.getToken(Parser_1.TokenType.FeatureLine); | ||
if (!featureLine) { | ||
return null; | ||
} | ||
var children = []; | ||
var background = node.getSingle(Parser_1.RuleType.Background); | ||
const children = []; | ||
const background = node.getSingle(Parser_1.RuleType.Background); | ||
if (background) { | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
background: background, | ||
background, | ||
})); | ||
} | ||
try { | ||
for (var _d = __values(node.getItems(Parser_1.RuleType.ScenarioDefinition)), _e = _d.next(); !_e.done; _e = _d.next()) { | ||
var scenario = _e.value; | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
scenario: scenario, | ||
})); | ||
} | ||
for (const scenario of node.getItems(Parser_1.RuleType.ScenarioDefinition)) { | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
scenario, | ||
})); | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_e && !_e.done && (_a = _d.return)) _a.call(_d); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
for (const rule of node.getItems(Parser_1.RuleType.Rule)) { | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
rule, | ||
})); | ||
} | ||
try { | ||
for (var _f = __values(node.getItems(Parser_1.RuleType.Rule)), _g = _f.next(); !_g.done; _g = _f.next()) { | ||
var rule = _g.value; | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
rule: rule, | ||
})); | ||
} | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (_g && !_g.done && (_b = _f.return)) _b.call(_f); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
var description = this.getDescription(header); | ||
var language = featureLine.matchedGherkinDialect; | ||
const description = this.getDescription(header); | ||
const language = featureLine.matchedGherkinDialect; | ||
return messages_1.messages.GherkinDocument.Feature.create({ | ||
tags: tags, | ||
tags, | ||
location: this.getLocation(featureLine), | ||
language: language, | ||
language, | ||
keyword: featureLine.matchedKeyword, | ||
name: featureLine.matchedText, | ||
description: description, | ||
children: children, | ||
description, | ||
children, | ||
}); | ||
} | ||
case Parser_1.RuleType.Rule: { | ||
var header = node.getSingle(Parser_1.RuleType.RuleHeader); | ||
const header = node.getSingle(Parser_1.RuleType.RuleHeader); | ||
if (!header) { | ||
return null; | ||
} | ||
var ruleLine = header.getToken(Parser_1.TokenType.RuleLine); | ||
const ruleLine = header.getToken(Parser_1.TokenType.RuleLine); | ||
if (!ruleLine) { | ||
return null; | ||
} | ||
var children = []; | ||
var background = node.getSingle(Parser_1.RuleType.Background); | ||
const tags = this.getTags(header); | ||
const children = []; | ||
const background = node.getSingle(Parser_1.RuleType.Background); | ||
if (background) { | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
background: background, | ||
background, | ||
})); | ||
} | ||
try { | ||
for (var _h = __values(node.getItems(Parser_1.RuleType.ScenarioDefinition)), _j = _h.next(); !_j.done; _j = _h.next()) { | ||
var scenario = _j.value; | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
scenario: scenario, | ||
})); | ||
} | ||
for (const scenario of node.getItems(Parser_1.RuleType.ScenarioDefinition)) { | ||
children.push(messages_1.messages.GherkinDocument.Feature.FeatureChild.create({ | ||
scenario, | ||
})); | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
finally { | ||
try { | ||
if (_j && !_j.done && (_c = _h.return)) _c.call(_h); | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
} | ||
var description = this.getDescription(header); | ||
const description = this.getDescription(header); | ||
return messages_1.messages.GherkinDocument.Feature.FeatureChild.Rule.create({ | ||
@@ -348,10 +276,11 @@ id: this.newId(), | ||
name: ruleLine.matchedText, | ||
description: description, | ||
children: children, | ||
description, | ||
children, | ||
tags, | ||
}); | ||
} | ||
case Parser_1.RuleType.GherkinDocument: { | ||
var feature = node.getSingle(Parser_1.RuleType.Feature); | ||
const feature = node.getSingle(Parser_1.RuleType.Feature); | ||
return messages_1.messages.GherkinDocument.create({ | ||
feature: feature, | ||
feature, | ||
comments: this.comments, | ||
@@ -363,6 +292,5 @@ }); | ||
} | ||
}; | ||
return AstBuilder; | ||
}()); | ||
} | ||
} | ||
exports.default = AstBuilder; | ||
//# sourceMappingURL=AstBuilder.js.map |
@@ -13,1 +13,2 @@ import { RuleType, TokenType } from './Parser'; | ||
} | ||
//# sourceMappingURL=AstNode.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var AstNode = /** @class */ (function () { | ||
function AstNode(ruleType) { | ||
class AstNode { | ||
constructor(ruleType) { | ||
this.ruleType = ruleType; | ||
@@ -10,4 +10,4 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
AstNode.prototype.add = function (type, obj) { | ||
var items = this.subItems.get(type); | ||
add(type, obj) { | ||
let items = this.subItems.get(type); | ||
if (items === undefined) { | ||
@@ -18,18 +18,17 @@ items = []; | ||
items.push(obj); | ||
}; | ||
AstNode.prototype.getSingle = function (ruleType) { | ||
} | ||
getSingle(ruleType) { | ||
return (this.subItems.get(ruleType) || [])[0]; | ||
}; | ||
AstNode.prototype.getItems = function (ruleType) { | ||
} | ||
getItems(ruleType) { | ||
return this.subItems.get(ruleType) || []; | ||
}; | ||
AstNode.prototype.getToken = function (tokenType) { | ||
} | ||
getToken(tokenType) { | ||
return (this.subItems.get(tokenType) || [])[0]; | ||
}; | ||
AstNode.prototype.getTokens = function (tokenType) { | ||
} | ||
getTokens(tokenType) { | ||
return this.subItems.get(tokenType) || []; | ||
}; | ||
return AstNode; | ||
}()); | ||
} | ||
} | ||
exports.default = AstNode; | ||
//# sourceMappingURL=AstNode.js.map |
export default function countSymbols(s: string): number; | ||
//# sourceMappingURL=countSymbols.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// https://mathiasbynens.be/notes/javascript-unicode | ||
var regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; | ||
const regexAstralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g; | ||
function countSymbols(s) { | ||
@@ -6,0 +6,0 @@ return s.replace(regexAstralSymbols, '_').length; |
@@ -16,1 +16,2 @@ export default interface Dialect { | ||
} | ||
//# sourceMappingURL=Dialect.d.ts.map |
@@ -20,1 +20,2 @@ import { messages } from '@cucumber/messages'; | ||
} | ||
//# sourceMappingURL=Errors.d.ts.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -20,80 +7,56 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.NoSuchLanguageException = exports.AstBuilderException = exports.CompositeParserException = exports.ParserException = exports.GherkinException = void 0; | ||
var createLocation_1 = __importDefault(require("./cli/createLocation")); | ||
var GherkinException = /** @class */ (function (_super) { | ||
__extends(GherkinException, _super); | ||
function GherkinException(message) { | ||
var _newTarget = this.constructor; | ||
var _this = _super.call(this, message) || this; | ||
var actualProto = _newTarget.prototype; | ||
const createLocation_1 = __importDefault(require("./createLocation")); | ||
class GherkinException extends Error { | ||
constructor(message) { | ||
super(message); | ||
const actualProto = new.target.prototype; | ||
// https://stackoverflow.com/questions/41102060/typescript-extending-error-class | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(_this, actualProto); | ||
Object.setPrototypeOf(this, actualProto); | ||
} | ||
else { | ||
// @ts-ignore | ||
_this.__proto__ = actualProto; | ||
this.__proto__ = actualProto; | ||
} | ||
return _this; | ||
} | ||
GherkinException._create = function (message, location) { | ||
var column = location != null ? location.column || 0 : -1; | ||
var line = location != null ? location.line || 0 : -1; | ||
var m = "(" + line + ":" + column + "): " + message; | ||
var err = new this(m); | ||
static _create(message, location) { | ||
const column = location != null ? location.column || 0 : -1; | ||
const line = location != null ? location.line || 0 : -1; | ||
const m = `(${line}:${column}): ${message}`; | ||
const err = new this(m); | ||
err.location = location; | ||
return err; | ||
}; | ||
return GherkinException; | ||
}(Error)); | ||
} | ||
} | ||
exports.GherkinException = GherkinException; | ||
var ParserException = /** @class */ (function (_super) { | ||
__extends(ParserException, _super); | ||
function ParserException() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
class ParserException extends GherkinException { | ||
static create(message, line, column) { | ||
const err = new this(`(${line}:${column}): ${message}`); | ||
err.location = createLocation_1.default({ line, column }); | ||
return err; | ||
} | ||
ParserException.create = function (message, line, column) { | ||
var err = new this("(" + line + ":" + column + "): " + message); | ||
err.location = createLocation_1.default({ line: line, column: column }); | ||
return err; | ||
}; | ||
return ParserException; | ||
}(GherkinException)); | ||
} | ||
exports.ParserException = ParserException; | ||
var CompositeParserException = /** @class */ (function (_super) { | ||
__extends(CompositeParserException, _super); | ||
function CompositeParserException() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
CompositeParserException.create = function (errors) { | ||
var message = 'Parser errors:\n' + errors.map(function (e) { return e.message; }).join('\n'); | ||
var err = new this(message); | ||
class CompositeParserException extends GherkinException { | ||
static create(errors) { | ||
const message = 'Parser errors:\n' + errors.map((e) => e.message).join('\n'); | ||
const err = new this(message); | ||
err.errors = errors; | ||
return err; | ||
}; | ||
return CompositeParserException; | ||
}(GherkinException)); | ||
} | ||
} | ||
exports.CompositeParserException = CompositeParserException; | ||
var AstBuilderException = /** @class */ (function (_super) { | ||
__extends(AstBuilderException, _super); | ||
function AstBuilderException() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
class AstBuilderException extends GherkinException { | ||
static create(message, location) { | ||
return this._create(message, location); | ||
} | ||
AstBuilderException.create = function (message, location) { | ||
} | ||
exports.AstBuilderException = AstBuilderException; | ||
class NoSuchLanguageException extends GherkinException { | ||
static create(language, location) { | ||
const message = 'Language not supported: ' + language; | ||
return this._create(message, location); | ||
}; | ||
return AstBuilderException; | ||
}(GherkinException)); | ||
exports.AstBuilderException = AstBuilderException; | ||
var NoSuchLanguageException = /** @class */ (function (_super) { | ||
__extends(NoSuchLanguageException, _super); | ||
function NoSuchLanguageException() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
NoSuchLanguageException.create = function (language, location) { | ||
var message = 'Language not supported: ' + language; | ||
return this._create(message, location); | ||
}; | ||
return NoSuchLanguageException; | ||
}(GherkinException)); | ||
} | ||
exports.NoSuchLanguageException = NoSuchLanguageException; | ||
//# sourceMappingURL=Errors.js.map |
import { messages } from '@cucumber/messages'; | ||
import IGherkinOptions from './IGherkinOptions'; | ||
export default function generateMessages(data: string, uri: string, options: IGherkinOptions): readonly messages.IEnvelope[]; | ||
//# sourceMappingURL=generateMessages.d.ts.map |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -28,11 +6,10 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Parser_1 = __importDefault(require("./Parser")); | ||
var TokenMatcher_1 = __importDefault(require("./TokenMatcher")); | ||
var messages_1 = require("@cucumber/messages"); | ||
var compile_1 = __importDefault(require("./pickles/compile")); | ||
var AstBuilder_1 = __importDefault(require("./AstBuilder")); | ||
var makeSourceEnvelope_1 = __importDefault(require("./makeSourceEnvelope")); | ||
const Parser_1 = __importDefault(require("./Parser")); | ||
const TokenMatcher_1 = __importDefault(require("./TokenMatcher")); | ||
const messages_1 = require("@cucumber/messages"); | ||
const compile_1 = __importDefault(require("./pickles/compile")); | ||
const AstBuilder_1 = __importDefault(require("./AstBuilder")); | ||
const makeSourceEnvelope_1 = __importDefault(require("./makeSourceEnvelope")); | ||
function generateMessages(data, uri, options) { | ||
var e_1, _a, e_2, _b; | ||
var result = []; | ||
const result = []; | ||
try { | ||
@@ -45,59 +22,39 @@ if (options.includeSource) { | ||
} | ||
var parser = new Parser_1.default(new AstBuilder_1.default(options.newId)); | ||
const parser = new Parser_1.default(new AstBuilder_1.default(options.newId), new TokenMatcher_1.default(options.defaultDialect)); | ||
parser.stopAtFirstError = false; | ||
var gherkinDocument = parser.parse(data, new TokenMatcher_1.default(options.defaultDialect)); | ||
const gherkinDocument = parser.parse(data); | ||
if (options.includeGherkinDocument) { | ||
result.push(messages_1.messages.Envelope.create({ | ||
gherkinDocument: __assign(__assign({}, gherkinDocument), { uri: uri }), | ||
gherkinDocument: Object.assign(Object.assign({}, gherkinDocument), { uri }), | ||
})); | ||
} | ||
if (options.includePickles) { | ||
var pickles = compile_1.default(gherkinDocument, uri, options.newId); | ||
try { | ||
for (var pickles_1 = __values(pickles), pickles_1_1 = pickles_1.next(); !pickles_1_1.done; pickles_1_1 = pickles_1.next()) { | ||
var pickle = pickles_1_1.value; | ||
result.push(messages_1.messages.Envelope.create({ | ||
pickle: pickle, | ||
})); | ||
} | ||
const pickles = compile_1.default(gherkinDocument, uri, options.newId); | ||
for (const pickle of pickles) { | ||
result.push(messages_1.messages.Envelope.create({ | ||
pickle, | ||
})); | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (pickles_1_1 && !pickles_1_1.done && (_a = pickles_1.return)) _a.call(pickles_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
} | ||
catch (err) { | ||
var errors = err.errors || [err]; | ||
try { | ||
for (var errors_1 = __values(errors), errors_1_1 = errors_1.next(); !errors_1_1.done; errors_1_1 = errors_1.next()) { | ||
var error = errors_1_1.value; | ||
if (!error.location) { | ||
// It wasn't a parser error - throw it (this is unexpected) | ||
throw error; | ||
} | ||
result.push(messages_1.messages.Envelope.create({ | ||
parseError: { | ||
source: { | ||
uri: uri, | ||
location: { | ||
line: error.location.line, | ||
column: error.location.column, | ||
}, | ||
const errors = err.errors || [err]; | ||
for (const error of errors) { | ||
if (!error.location) { | ||
// It wasn't a parser error - throw it (this is unexpected) | ||
throw error; | ||
} | ||
result.push(messages_1.messages.Envelope.create({ | ||
parseError: { | ||
source: { | ||
uri, | ||
location: { | ||
line: error.location.line, | ||
column: error.location.column, | ||
}, | ||
message: error.message, | ||
}, | ||
})); | ||
} | ||
message: error.message, | ||
}, | ||
})); | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (errors_1_1 && !errors_1_1.done && (_b = errors_1.return)) _b.call(errors_1); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
} | ||
@@ -104,0 +61,0 @@ return result; |
@@ -20,1 +20,2 @@ export default class GherkinLine { | ||
} | ||
//# sourceMappingURL=GherkinLine.d.ts.map |
@@ -6,6 +6,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var countSymbols_1 = __importDefault(require("./countSymbols")); | ||
var Errors_1 = require("./Errors"); | ||
var GherkinLine = /** @class */ (function () { | ||
function GherkinLine(lineText, lineNumber) { | ||
const countSymbols_1 = __importDefault(require("./countSymbols")); | ||
const Errors_1 = require("./Errors"); | ||
class GherkinLine { | ||
constructor(lineText, lineNumber) { | ||
this.lineText = lineText; | ||
@@ -17,9 +17,9 @@ this.lineNumber = lineNumber; | ||
} | ||
GherkinLine.prototype.startsWith = function (prefix) { | ||
startsWith(prefix) { | ||
return this.trimmedLineText.indexOf(prefix) === 0; | ||
}; | ||
GherkinLine.prototype.startsWithTitleKeyword = function (keyword) { | ||
} | ||
startsWithTitleKeyword(keyword) { | ||
return this.startsWith(keyword + ':'); // The C# impl is more complicated. Find out why. | ||
}; | ||
GherkinLine.prototype.getLineText = function (indentToRemove) { | ||
} | ||
getLineText(indentToRemove) { | ||
if (indentToRemove < 0 || indentToRemove > this.indent) { | ||
@@ -31,14 +31,14 @@ return this.trimmedLineText; | ||
} | ||
}; | ||
GherkinLine.prototype.getRestTrimmed = function (length) { | ||
} | ||
getRestTrimmed(length) { | ||
return this.trimmedLineText.substring(length).trim(); | ||
}; | ||
GherkinLine.prototype.getTableCells = function () { | ||
var cells = []; | ||
var col = 0; | ||
var startCol = col + 1; | ||
var cell = ''; | ||
var firstCell = true; | ||
} | ||
getTableCells() { | ||
const cells = []; | ||
let col = 0; | ||
let startCol = col + 1; | ||
let cell = ''; | ||
let firstCell = true; | ||
while (col < this.trimmedLineText.length) { | ||
var chr = this.trimmedLineText[col]; | ||
let chr = this.trimmedLineText[col]; | ||
col++; | ||
@@ -52,6 +52,6 @@ if (chr === '|') { | ||
// Keeps newlines | ||
var trimmedLeft = cell.replace(/^[ \t\v\f\r\u0085\u00A0]*/g, ''); | ||
var trimmed = trimmedLeft.replace(/[ \t\v\f\r\u0085\u00A0]*$/g, ''); | ||
var cellIndent = cell.length - trimmedLeft.length; | ||
var span = { | ||
const trimmedLeft = cell.replace(/^[ \t\v\f\r\u0085\u00A0]*/g, ''); | ||
const trimmed = trimmedLeft.replace(/[ \t\v\f\r\u0085\u00A0]*$/g, ''); | ||
const cellIndent = cell.length - trimmedLeft.length; | ||
const span = { | ||
column: this.indent + startCol + cellIndent, | ||
@@ -83,10 +83,10 @@ text: trimmed, | ||
return cells; | ||
}; | ||
GherkinLine.prototype.getTags = function () { | ||
var uncommentedLine = this.trimmedLineText.split(/\s#/g, 2)[0]; | ||
var column = this.indent + 1; | ||
var items = uncommentedLine.split('@'); | ||
var tags = []; | ||
for (var i = 0; i < items.length; i++) { | ||
var item = items[i].trimRight(); | ||
} | ||
getTags() { | ||
const uncommentedLine = this.trimmedLineText.split(/\s#/g, 2)[0]; | ||
let column = this.indent + 1; | ||
const items = uncommentedLine.split('@'); | ||
const tags = []; | ||
for (let i = 0; i < items.length; i++) { | ||
const item = items[i].trimRight(); | ||
if (item.length == 0) { | ||
@@ -98,3 +98,3 @@ continue; | ||
} | ||
var span = { column: column, text: '@' + item }; | ||
const span = { column, text: '@' + item }; | ||
tags.push(span); | ||
@@ -104,7 +104,6 @@ column += countSymbols_1.default(items[i]) + 1; | ||
return tags; | ||
}; | ||
return GherkinLine; | ||
}()); | ||
} | ||
} | ||
exports.default = GherkinLine; | ||
module.exports = GherkinLine; | ||
//# sourceMappingURL=GherkinLine.js.map |
@@ -22,1 +22,2 @@ import { IdGenerator, messages } from '@cucumber/messages'; | ||
} | ||
//# sourceMappingURL=IAstBuilder.d.ts.map |
@@ -9,1 +9,2 @@ import { IdGenerator } from '@cucumber/messages'; | ||
} | ||
//# sourceMappingURL=IGherkinOptions.d.ts.map |
@@ -9,5 +9,7 @@ import generateMessages from './generateMessages'; | ||
import compile from './pickles/compile'; | ||
import TokenMatcher from './TokenMatcher'; | ||
declare const dialects: Readonly<{ | ||
[key: string]: Dialect; | ||
}>; | ||
export { generateMessages, makeSourceEnvelope, IGherkinOptions, dialects, Dialect, Parser, AstBuilder, TokenScanner, compile, }; | ||
export { generateMessages, makeSourceEnvelope, IGherkinOptions, dialects, Dialect, Parser, AstBuilder, TokenScanner, TokenMatcher, compile, }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -6,18 +6,20 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.compile = exports.TokenScanner = exports.AstBuilder = exports.Parser = exports.dialects = exports.makeSourceEnvelope = exports.generateMessages = void 0; | ||
var generateMessages_1 = __importDefault(require("./generateMessages")); | ||
exports.compile = exports.TokenMatcher = exports.TokenScanner = exports.AstBuilder = exports.Parser = exports.dialects = exports.makeSourceEnvelope = exports.generateMessages = void 0; | ||
const generateMessages_1 = __importDefault(require("./generateMessages")); | ||
exports.generateMessages = generateMessages_1.default; | ||
var makeSourceEnvelope_1 = __importDefault(require("./makeSourceEnvelope")); | ||
const makeSourceEnvelope_1 = __importDefault(require("./makeSourceEnvelope")); | ||
exports.makeSourceEnvelope = makeSourceEnvelope_1.default; | ||
var Parser_1 = __importDefault(require("./Parser")); | ||
const Parser_1 = __importDefault(require("./Parser")); | ||
exports.Parser = Parser_1.default; | ||
var AstBuilder_1 = __importDefault(require("./AstBuilder")); | ||
const AstBuilder_1 = __importDefault(require("./AstBuilder")); | ||
exports.AstBuilder = AstBuilder_1.default; | ||
var TokenScanner_1 = __importDefault(require("./TokenScanner")); | ||
const TokenScanner_1 = __importDefault(require("./TokenScanner")); | ||
exports.TokenScanner = TokenScanner_1.default; | ||
var compile_1 = __importDefault(require("./pickles/compile")); | ||
const compile_1 = __importDefault(require("./pickles/compile")); | ||
exports.compile = compile_1.default; | ||
var gherkin_languages_json_1 = __importDefault(require("./gherkin-languages.json")); | ||
var dialects = gherkin_languages_json_1.default; | ||
const gherkin_languages_json_1 = __importDefault(require("./gherkin-languages.json")); | ||
const TokenMatcher_1 = __importDefault(require("./TokenMatcher")); | ||
exports.TokenMatcher = TokenMatcher_1.default; | ||
const dialects = gherkin_languages_json_1.default; | ||
exports.dialects = dialects; | ||
//# sourceMappingURL=index.js.map |
@@ -16,1 +16,2 @@ import { messages } from '@cucumber/messages'; | ||
} | ||
//# sourceMappingURL=IToken.d.ts.map |
import { messages } from '@cucumber/messages'; | ||
export default function makeSourceEnvelope(data: string, uri: string): messages.IEnvelope; | ||
//# sourceMappingURL=makeSourceEnvelope.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var messages_1 = require("@cucumber/messages"); | ||
const messages_1 = require("@cucumber/messages"); | ||
function makeSourceEnvelope(data, uri) { | ||
return new messages_1.messages.Envelope({ | ||
source: new messages_1.messages.Source({ | ||
data: data, | ||
uri: uri, | ||
data, | ||
uri, | ||
mediaType: 'text/x.cucumber.gherkin+plain', | ||
@@ -10,0 +10,0 @@ }), |
import { messages } from '@cucumber/messages'; | ||
import TokenMatcher from './TokenMatcher'; | ||
import GherkinLine from './GherkinLine'; | ||
import IToken from './IToken'; | ||
import { IAstBuilder } from './IAstBuilder'; | ||
import ITokenMatcher from './ITokenMatcher'; | ||
export declare class Token implements IToken<TokenType> { | ||
@@ -74,6 +74,7 @@ readonly line: GherkinLine; | ||
private readonly builder; | ||
private readonly tokenMatcher; | ||
stopAtFirstError: boolean; | ||
private context; | ||
constructor(builder: IAstBuilder<AstNode, TokenType, RuleType>); | ||
parse(gherkinSource: string, tokenMatcher?: TokenMatcher): messages.IGherkinDocument; | ||
constructor(builder: IAstBuilder<AstNode, TokenType, RuleType>, tokenMatcher: ITokenMatcher<TokenType>); | ||
parse(gherkinSource: string): messages.IGherkinDocument; | ||
private addError; | ||
@@ -129,3 +130,3 @@ private startRule; | ||
private matchTokenAt_40; | ||
private matchTokenAt_42; | ||
private matchTokenAt_41; | ||
private matchTokenAt_43; | ||
@@ -138,2 +139,3 @@ private matchTokenAt_44; | ||
private matchTokenAt_49; | ||
private matchTokenAt_50; | ||
private match_EOF; | ||
@@ -154,2 +156,4 @@ private match_Empty; | ||
private lookahead_0; | ||
private lookahead_1; | ||
} | ||
//# sourceMappingURL=Parser.d.ts.map |
import { messages, IdGenerator } from '@cucumber/messages'; | ||
import IGherkinDocument = messages.IGherkinDocument; | ||
export default function compile(gherkinDocument: IGherkinDocument, uri: string, newId: IdGenerator.NewId): ReadonlyArray<messages.IPickle>; | ||
//# sourceMappingURL=compile.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var messages_1 = require("@cucumber/messages"); | ||
const messages_1 = require("@cucumber/messages"); | ||
function compile(gherkinDocument, uri, newId) { | ||
var pickles = []; | ||
const pickles = []; | ||
if (gherkinDocument.feature == null) { | ||
return pickles; | ||
} | ||
var feature = gherkinDocument.feature; | ||
var language = feature.language; | ||
var featureTags = feature.tags; | ||
var featureBackgroundSteps = []; | ||
feature.children.forEach(function (stepsContainer) { | ||
const feature = gherkinDocument.feature; | ||
const language = feature.language; | ||
const featureTags = feature.tags; | ||
let featureBackgroundSteps = []; | ||
feature.children.forEach((stepsContainer) => { | ||
if (stepsContainer.background) { | ||
@@ -31,4 +31,5 @@ featureBackgroundSteps = [].concat(stepsContainer.background.steps); | ||
function compileRule(featureTags, featureBackgroundSteps, rule, language, pickles, uri, newId) { | ||
var ruleBackgroundSteps = [].concat(featureBackgroundSteps); | ||
rule.children.forEach(function (stepsContainer) { | ||
let ruleBackgroundSteps = [].concat(featureBackgroundSteps); | ||
const tags = [].concat(featureTags).concat(rule.tags); | ||
rule.children.forEach((stepsContainer) => { | ||
if (stepsContainer.background) { | ||
@@ -38,3 +39,3 @@ ruleBackgroundSteps = ruleBackgroundSteps.concat(stepsContainer.background.steps); | ||
else if (stepsContainer.scenario.examples.length === 0) { | ||
compileScenario(featureTags, ruleBackgroundSteps, stepsContainer.scenario, language, pickles, uri, newId); | ||
compileScenario(tags, ruleBackgroundSteps, stepsContainer.scenario, language, pickles, uri, newId); | ||
} | ||
@@ -46,36 +47,31 @@ else { | ||
} | ||
function compileScenario(featureTags, backgroundSteps, scenario, language, pickles, uri, newId) { | ||
var steps = scenario.steps.length === 0 | ||
function compileScenario(inheritedTags, backgroundSteps, scenario, language, pickles, uri, newId) { | ||
const steps = scenario.steps.length === 0 | ||
? [] | ||
: backgroundSteps.map(function (step) { return pickleStep(step, [], null, newId); }); | ||
var tags = [].concat(featureTags).concat(scenario.tags); | ||
scenario.steps.forEach(function (step) { | ||
return steps.push(pickleStep(step, [], null, newId)); | ||
}); | ||
var pickle = messages_1.messages.Pickle.create({ | ||
: backgroundSteps.map((step) => pickleStep(step, [], null, newId)); | ||
const tags = [].concat(inheritedTags).concat(scenario.tags); | ||
scenario.steps.forEach((step) => steps.push(pickleStep(step, [], null, newId))); | ||
const pickle = messages_1.messages.Pickle.create({ | ||
id: newId(), | ||
uri: uri, | ||
uri, | ||
astNodeIds: [scenario.id], | ||
tags: pickleTags(tags), | ||
name: scenario.name, | ||
language: language, | ||
steps: steps, | ||
language, | ||
steps, | ||
}); | ||
pickles.push(pickle); | ||
} | ||
function compileScenarioOutline(featureTags, backgroundSteps, scenario, language, pickles, uri, newId) { | ||
function compileScenarioOutline(inheritedTags, backgroundSteps, scenario, language, pickles, uri, newId) { | ||
scenario.examples | ||
.filter(function (e) { return e.tableHeader !== null; }) | ||
.forEach(function (examples) { | ||
var variableCells = examples.tableHeader.cells; | ||
examples.tableBody.forEach(function (valuesRow) { | ||
var steps = scenario.steps.length === 0 | ||
.filter((e) => e.tableHeader !== null) | ||
.forEach((examples) => { | ||
const variableCells = examples.tableHeader.cells; | ||
examples.tableBody.forEach((valuesRow) => { | ||
const steps = scenario.steps.length === 0 | ||
? [] | ||
: backgroundSteps.map(function (step) { return pickleStep(step, [], null, newId); }); | ||
var tags = [] | ||
.concat(featureTags) | ||
.concat(scenario.tags) | ||
.concat(examples.tags); | ||
scenario.steps.forEach(function (scenarioOutlineStep) { | ||
var step = pickleStep(scenarioOutlineStep, variableCells, valuesRow, newId); | ||
: backgroundSteps.map((step) => pickleStep(step, [], null, newId)); | ||
const tags = [].concat(inheritedTags).concat(scenario.tags).concat(examples.tags); | ||
scenario.steps.forEach((scenarioOutlineStep) => { | ||
const step = pickleStep(scenarioOutlineStep, variableCells, valuesRow, newId); | ||
steps.push(step); | ||
@@ -85,7 +81,7 @@ }); | ||
id: newId(), | ||
uri: uri, | ||
uri, | ||
astNodeIds: [scenario.id, valuesRow.id], | ||
name: interpolate(scenario.name, variableCells, valuesRow.cells), | ||
language: language, | ||
steps: steps, | ||
language, | ||
steps, | ||
tags: pickleTags(tags), | ||
@@ -98,7 +94,7 @@ })); | ||
if (step.dataTable) { | ||
var argument = step.dataTable; | ||
var table = { | ||
rows: argument.rows.map(function (row) { | ||
const argument = step.dataTable; | ||
const table = { | ||
rows: argument.rows.map((row) => { | ||
return { | ||
cells: row.cells.map(function (cell) { | ||
cells: row.cells.map((cell) => { | ||
return { | ||
@@ -117,4 +113,4 @@ location: cell.location, | ||
else if (step.docString) { | ||
var argument = step.docString; | ||
var docString = messages_1.messages.PickleStepArgument.PickleDocString.create({ | ||
const argument = step.docString; | ||
const docString = messages_1.messages.PickleStepArgument.PickleDocString.create({ | ||
content: interpolate(argument.content, variableCells, valueCells), | ||
@@ -126,3 +122,3 @@ }); | ||
return { | ||
docString: docString, | ||
docString, | ||
}; | ||
@@ -132,10 +128,10 @@ } | ||
function interpolate(name, variableCells, valueCells) { | ||
variableCells.forEach(function (variableCell, n) { | ||
var valueCell = valueCells[n]; | ||
var valuePattern = '<' + variableCell.value + '>'; | ||
var escapedPattern = valuePattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); | ||
var regexp = new RegExp(escapedPattern, 'g'); | ||
variableCells.forEach((variableCell, n) => { | ||
const valueCell = valueCells[n]; | ||
const valuePattern = '<' + variableCell.value + '>'; | ||
const escapedPattern = valuePattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); | ||
const regexp = new RegExp(escapedPattern, 'g'); | ||
// JS Specific - dollar sign needs to be escaped with another dollar sign | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter | ||
var replacement = valueCell.value.replace(new RegExp('\\$', 'g'), '$$$$'); | ||
const replacement = valueCell.value.replace(new RegExp('\\$', 'g'), '$$$$'); | ||
name = name.replace(regexp, replacement); | ||
@@ -146,7 +142,7 @@ }); | ||
function pickleStep(step, variableCells, valuesRow, newId) { | ||
var astNodeIds = [step.id]; | ||
const astNodeIds = [step.id]; | ||
if (valuesRow) { | ||
astNodeIds.push(valuesRow.id); | ||
} | ||
var valueCells = valuesRow ? valuesRow.cells : []; | ||
const valueCells = valuesRow ? valuesRow.cells : []; | ||
return messages_1.messages.Pickle.PickleStep.create({ | ||
@@ -156,3 +152,3 @@ id: newId(), | ||
argument: createPickleArguments(step, variableCells, valueCells), | ||
astNodeIds: astNodeIds, | ||
astNodeIds, | ||
}); | ||
@@ -159,0 +155,0 @@ } |
@@ -9,1 +9,2 @@ import IToken from './IToken'; | ||
} | ||
//# sourceMappingURL=TokenExceptions.d.ts.map |
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -20,35 +7,22 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.UnexpectedEOFException = exports.UnexpectedTokenException = void 0; | ||
var createLocation_1 = __importDefault(require("./cli/createLocation")); | ||
var Errors_1 = require("./Errors"); | ||
var UnexpectedTokenException = /** @class */ (function (_super) { | ||
__extends(UnexpectedTokenException, _super); | ||
function UnexpectedTokenException() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
const createLocation_1 = __importDefault(require("./createLocation")); | ||
const Errors_1 = require("./Errors"); | ||
class UnexpectedTokenException extends Errors_1.GherkinException { | ||
static create(token, expectedTokenTypes) { | ||
const message = `expected: ${expectedTokenTypes.join(', ')}, got '${token.getTokenValue().trim()}'`; | ||
const location = tokenLocation(token); | ||
return this._create(message, location); | ||
} | ||
UnexpectedTokenException.create = function (token, expectedTokenTypes) { | ||
var message = "expected: " + expectedTokenTypes.join(', ') + ", got '" + token.getTokenValue().trim() + "'"; | ||
var location = tokenLocation(token); | ||
} | ||
exports.UnexpectedTokenException = UnexpectedTokenException; | ||
class UnexpectedEOFException extends Errors_1.GherkinException { | ||
static create(token, expectedTokenTypes) { | ||
const message = `unexpected end of file, expected: ${expectedTokenTypes.join(', ')}`; | ||
const location = tokenLocation(token); | ||
return this._create(message, location); | ||
}; | ||
return UnexpectedTokenException; | ||
}(Errors_1.GherkinException)); | ||
exports.UnexpectedTokenException = UnexpectedTokenException; | ||
var UnexpectedEOFException = /** @class */ (function (_super) { | ||
__extends(UnexpectedEOFException, _super); | ||
function UnexpectedEOFException() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
UnexpectedEOFException.create = function (token, expectedTokenTypes) { | ||
var message = "unexpected end of file, expected: " + expectedTokenTypes.join(', '); | ||
var location = tokenLocation(token); | ||
return this._create(message, location); | ||
}; | ||
return UnexpectedEOFException; | ||
}(Errors_1.GherkinException)); | ||
} | ||
exports.UnexpectedEOFException = UnexpectedEOFException; | ||
function tokenLocation(token) { | ||
return token.location && | ||
token.location.line && | ||
token.line && | ||
token.line.indent !== undefined | ||
return token.location && token.location.line && token.line && token.line.indent !== undefined | ||
? createLocation_1.default({ | ||
@@ -55,0 +29,0 @@ line: token.location.line, |
import { messages } from '@cucumber/messages'; | ||
import IToken from './IToken'; | ||
import { TokenType } from './Parser'; | ||
export default class TokenMatcher { | ||
import ITokenMatcher from './ITokenMatcher'; | ||
export default class TokenMatcher implements ITokenMatcher<TokenType> { | ||
private readonly defaultDialectName; | ||
@@ -28,5 +29,6 @@ private dialect; | ||
match_Other(token: IToken<TokenType>): boolean; | ||
private matchTitleLine; | ||
matchTitleLine(token: IToken<TokenType>, tokenType: TokenType, keywords: readonly string[]): boolean; | ||
private setTokenMatched; | ||
private unescapeDocString; | ||
} | ||
//# sourceMappingURL=TokenMatcher.d.ts.map |
"use strict"; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -17,15 +6,14 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var gherkin_languages_json_1 = __importDefault(require("./gherkin-languages.json")); | ||
var Errors_1 = require("./Errors"); | ||
var Parser_1 = require("./Parser"); | ||
var DIALECT_DICT = gherkin_languages_json_1.default; | ||
var LANGUAGE_PATTERN = /^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$/; | ||
var TokenMatcher = /** @class */ (function () { | ||
function TokenMatcher(defaultDialectName) { | ||
if (defaultDialectName === void 0) { defaultDialectName = 'en'; } | ||
const gherkin_languages_json_1 = __importDefault(require("./gherkin-languages.json")); | ||
const Errors_1 = require("./Errors"); | ||
const Parser_1 = require("./Parser"); | ||
const DIALECT_DICT = gherkin_languages_json_1.default; | ||
const LANGUAGE_PATTERN = /^\s*#\s*language\s*:\s*([a-zA-Z\-_]+)\s*$/; | ||
class TokenMatcher { | ||
constructor(defaultDialectName = 'en') { | ||
this.defaultDialectName = defaultDialectName; | ||
this.reset(); | ||
} | ||
TokenMatcher.prototype.changeDialect = function (newDialectName, location) { | ||
var newDialect = DIALECT_DICT[newDialectName]; | ||
changeDialect(newDialectName, location) { | ||
const newDialect = DIALECT_DICT[newDialectName]; | ||
if (!newDialect) { | ||
@@ -36,4 +24,4 @@ throw Errors_1.NoSuchLanguageException.create(newDialectName, location); | ||
this.dialect = newDialect; | ||
}; | ||
TokenMatcher.prototype.reset = function () { | ||
} | ||
reset() { | ||
if (this.dialectName !== this.defaultDialectName) { | ||
@@ -44,4 +32,4 @@ this.changeDialect(this.defaultDialectName); | ||
this.indentToRemove = 0; | ||
}; | ||
TokenMatcher.prototype.match_TagLine = function (token) { | ||
} | ||
match_TagLine(token) { | ||
if (token.line.startsWith('@')) { | ||
@@ -52,20 +40,20 @@ this.setTokenMatched(token, Parser_1.TokenType.TagLine, null, null, null, token.line.getTags()); | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_FeatureLine = function (token) { | ||
} | ||
match_FeatureLine(token) { | ||
return this.matchTitleLine(token, Parser_1.TokenType.FeatureLine, this.dialect.feature); | ||
}; | ||
TokenMatcher.prototype.match_ScenarioLine = function (token) { | ||
} | ||
match_ScenarioLine(token) { | ||
return (this.matchTitleLine(token, Parser_1.TokenType.ScenarioLine, this.dialect.scenario) || | ||
this.matchTitleLine(token, Parser_1.TokenType.ScenarioLine, this.dialect.scenarioOutline)); | ||
}; | ||
TokenMatcher.prototype.match_BackgroundLine = function (token) { | ||
} | ||
match_BackgroundLine(token) { | ||
return this.matchTitleLine(token, Parser_1.TokenType.BackgroundLine, this.dialect.background); | ||
}; | ||
TokenMatcher.prototype.match_ExamplesLine = function (token) { | ||
} | ||
match_ExamplesLine(token) { | ||
return this.matchTitleLine(token, Parser_1.TokenType.ExamplesLine, this.dialect.examples); | ||
}; | ||
TokenMatcher.prototype.match_RuleLine = function (token) { | ||
} | ||
match_RuleLine(token) { | ||
return this.matchTitleLine(token, Parser_1.TokenType.RuleLine, this.dialect.rule); | ||
}; | ||
TokenMatcher.prototype.match_TableRow = function (token) { | ||
} | ||
match_TableRow(token) { | ||
if (token.line.startsWith('|')) { | ||
@@ -77,4 +65,4 @@ // TODO: indent | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_Empty = function (token) { | ||
} | ||
match_Empty(token) { | ||
if (token.line.isEmpty) { | ||
@@ -85,6 +73,6 @@ this.setTokenMatched(token, Parser_1.TokenType.Empty, null, null, 0); | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_Comment = function (token) { | ||
} | ||
match_Comment(token) { | ||
if (token.line.startsWith('#')) { | ||
var text = token.line.getLineText(0); // take the entire line, including leading space | ||
const text = token.line.getLineText(0); // take the entire line, including leading space | ||
this.setTokenMatched(token, Parser_1.TokenType.Comment, text, null, 0); | ||
@@ -94,7 +82,7 @@ return true; | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_Language = function (token) { | ||
var match = token.line.trimmedLineText.match(LANGUAGE_PATTERN); | ||
} | ||
match_Language(token) { | ||
const match = token.line.trimmedLineText.match(LANGUAGE_PATTERN); | ||
if (match) { | ||
var newDialectName = match[1]; | ||
const newDialectName = match[1]; | ||
this.setTokenMatched(token, Parser_1.TokenType.Language, newDialectName); | ||
@@ -105,4 +93,4 @@ this.changeDialect(newDialectName, token.location); | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_DocStringSeparator = function (token) { | ||
} | ||
match_DocStringSeparator(token) { | ||
return this.activeDocStringSeparator == null | ||
@@ -114,6 +102,6 @@ ? // open | ||
this._match_DocStringSeparator(token, this.activeDocStringSeparator, false); | ||
}; | ||
TokenMatcher.prototype._match_DocStringSeparator = function (token, separator, isOpen) { | ||
} | ||
_match_DocStringSeparator(token, separator, isOpen) { | ||
if (token.line.startsWith(separator)) { | ||
var mediaType = null; | ||
let mediaType = null; | ||
if (isOpen) { | ||
@@ -133,4 +121,4 @@ mediaType = token.line.getRestTrimmed(separator.length); | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_EOF = function (token) { | ||
} | ||
match_EOF(token) { | ||
if (token.isEof) { | ||
@@ -141,6 +129,5 @@ this.setTokenMatched(token, Parser_1.TokenType.EOF); | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_StepLine = function (token) { | ||
var e_1, _a; | ||
var keywords = [] | ||
} | ||
match_StepLine(token) { | ||
const keywords = [] | ||
.concat(this.dialect.given) | ||
@@ -151,48 +138,27 @@ .concat(this.dialect.when) | ||
.concat(this.dialect.but); | ||
try { | ||
for (var keywords_1 = __values(keywords), keywords_1_1 = keywords_1.next(); !keywords_1_1.done; keywords_1_1 = keywords_1.next()) { | ||
var keyword = keywords_1_1.value; | ||
if (token.line.startsWith(keyword)) { | ||
var title = token.line.getRestTrimmed(keyword.length); | ||
this.setTokenMatched(token, Parser_1.TokenType.StepLine, title, keyword); | ||
return true; | ||
} | ||
for (const keyword of keywords) { | ||
if (token.line.startsWith(keyword)) { | ||
const title = token.line.getRestTrimmed(keyword.length); | ||
this.setTokenMatched(token, Parser_1.TokenType.StepLine, title, keyword); | ||
return true; | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (keywords_1_1 && !keywords_1_1.done && (_a = keywords_1.return)) _a.call(keywords_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return false; | ||
}; | ||
TokenMatcher.prototype.match_Other = function (token) { | ||
var text = token.line.getLineText(this.indentToRemove); // take the entire line, except removing DocString indents | ||
} | ||
match_Other(token) { | ||
const text = token.line.getLineText(this.indentToRemove); // take the entire line, except removing DocString indents | ||
this.setTokenMatched(token, Parser_1.TokenType.Other, this.unescapeDocString(text), null, 0); | ||
return true; | ||
}; | ||
TokenMatcher.prototype.matchTitleLine = function (token, tokenType, keywords) { | ||
var e_2, _a; | ||
try { | ||
for (var keywords_2 = __values(keywords), keywords_2_1 = keywords_2.next(); !keywords_2_1.done; keywords_2_1 = keywords_2.next()) { | ||
var keyword = keywords_2_1.value; | ||
if (token.line.startsWithTitleKeyword(keyword)) { | ||
var title = token.line.getRestTrimmed(keyword.length + ':'.length); | ||
this.setTokenMatched(token, tokenType, title, keyword); | ||
return true; | ||
} | ||
} | ||
matchTitleLine(token, tokenType, keywords) { | ||
for (const keyword of keywords) { | ||
if (token.line.startsWithTitleKeyword(keyword)) { | ||
const title = token.line.getRestTrimmed(keyword.length + ':'.length); | ||
this.setTokenMatched(token, tokenType, title, keyword); | ||
return true; | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (keywords_2_1 && !keywords_2_1.done && (_a = keywords_2.return)) _a.call(keywords_2); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
return false; | ||
}; | ||
TokenMatcher.prototype.setTokenMatched = function (token, matchedType, text, keyword, indent, items) { | ||
} | ||
setTokenMatched(token, matchedType, text, keyword, indent, items) { | ||
token.matchedType = matchedType; | ||
@@ -202,23 +168,18 @@ token.matchedText = text; | ||
token.matchedIndent = | ||
typeof indent === 'number' | ||
? indent | ||
: token.line == null | ||
? 0 | ||
: token.line.indent; | ||
typeof indent === 'number' ? indent : token.line == null ? 0 : token.line.indent; | ||
token.matchedItems = items || []; | ||
token.location.column = token.matchedIndent + 1; | ||
token.matchedGherkinDialect = this.dialectName; | ||
}; | ||
TokenMatcher.prototype.unescapeDocString = function (text) { | ||
if (this.activeDocStringSeparator === "\"\"\"") { | ||
} | ||
unescapeDocString(text) { | ||
if (this.activeDocStringSeparator === '"""') { | ||
return text.replace('\\"\\"\\"', '"""'); | ||
} | ||
if (this.activeDocStringSeparator === "```") { | ||
if (this.activeDocStringSeparator === '```') { | ||
return text.replace('\\`\\`\\`', '```'); | ||
} | ||
return text; | ||
}; | ||
return TokenMatcher; | ||
}()); | ||
} | ||
} | ||
exports.default = TokenMatcher; | ||
//# sourceMappingURL=TokenMatcher.js.map |
@@ -17,1 +17,2 @@ import IToken from './IToken'; | ||
} | ||
//# sourceMappingURL=TokenScanner.d.ts.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var createLocation_1 = __importDefault(require("./cli/createLocation")); | ||
const createLocation_1 = __importDefault(require("./createLocation")); | ||
/** | ||
@@ -15,15 +15,14 @@ * The scanner reads a gherkin doc (typically read from a .feature file) and creates a token for each line. | ||
*/ | ||
var TokenScanner = /** @class */ (function () { | ||
function TokenScanner(source, makeToken) { | ||
class TokenScanner { | ||
constructor(source, makeToken) { | ||
this.makeToken = makeToken; | ||
this.lineNumber = 0; | ||
this.lines = source.split(/\r?\n/); | ||
if (this.lines.length > 0 && | ||
this.lines[this.lines.length - 1].trim() === '') { | ||
if (this.lines.length > 0 && this.lines[this.lines.length - 1].trim() === '') { | ||
this.lines.pop(); | ||
} | ||
} | ||
TokenScanner.prototype.read = function () { | ||
var line = this.lines[this.lineNumber++]; | ||
var location = createLocation_1.default({ | ||
read() { | ||
const line = this.lines[this.lineNumber++]; | ||
const location = createLocation_1.default({ | ||
line: this.lineNumber, | ||
@@ -33,6 +32,5 @@ }); | ||
return this.makeToken(line, location); | ||
}; | ||
return TokenScanner; | ||
}()); | ||
} | ||
} | ||
exports.default = TokenScanner; | ||
//# sourceMappingURL=TokenScanner.js.map |
{ | ||
"name": "@cucumber/gherkin", | ||
"version": "17.0.2", | ||
"version": "18.0.0", | ||
"description": "Gherkin parser", | ||
"main": "dist/src/index.js", | ||
"types": "dist/src/index.d.ts", | ||
"bin": { | ||
"gherkin-javascript": "bin/gherkin" | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"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", | ||
"build": "tsc", | ||
"prepublishOnly": "npm run build" | ||
"prepublishOnly": "tsc --build tsconfig.build.json" | ||
}, | ||
@@ -33,23 +26,12 @@ "repository": { | ||
"devDependencies": { | ||
"@types/mocha": "^8.2.0", | ||
"@types/node": "^14.14.28", | ||
"@typescript-eslint/eslint-plugin": "^4.15.1", | ||
"@typescript-eslint/parser": "^4.15.1", | ||
"core-js": "^3.8.3", | ||
"eslint": "^7.20.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"eslint-plugin-react": "^7.22.0", | ||
"mocha": "^8.3.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.2.1", | ||
"@types/mocha": "^8.2.2", | ||
"@types/node": "^14.14.35", | ||
"core-js": "^3.9.1", | ||
"mocha": "^8.3.2", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.5" | ||
"typescript": "^4.2.3" | ||
}, | ||
"dependencies": { | ||
"@cucumber/messages": "^14.0.1", | ||
"commander": "^7.1.0", | ||
"source-map-support": "^0.5.19" | ||
"@cucumber/messages": "^15.0.0", | ||
"@cucumber/message-streams": "^1.0.0" | ||
}, | ||
@@ -56,0 +38,0 @@ "directories": { |
@@ -5,8 +5,7 @@ import AstNode from './AstNode' | ||
import { AstBuilderException } from './Errors' | ||
import createLocation from './cli/createLocation' | ||
import createLocation from './createLocation' | ||
import IToken from './IToken' | ||
import { IAstBuilder } from './IAstBuilder' | ||
export default class AstBuilder | ||
implements IAstBuilder<AstNode, TokenType, RuleType> { | ||
export default class AstBuilder implements IAstBuilder<AstNode, TokenType, RuleType> { | ||
stack: AstNode[] | ||
@@ -61,5 +60,3 @@ comments: messages.GherkinDocument.IComment[] | ||
getLocation(token: IToken<TokenType>, column?: number): messages.ILocation { | ||
return !column | ||
? token.location | ||
: createLocation({ line: token.location.line, column }) | ||
return !column ? token.location : createLocation({ line: token.location.line, column }) | ||
} | ||
@@ -125,6 +122,3 @@ | ||
if (row.cells.length !== cellCount) { | ||
throw AstBuilderException.create( | ||
'inconsistent cell count within the table', | ||
row.location | ||
) | ||
throw AstBuilderException.create('inconsistent cell count within the table', row.location) | ||
} | ||
@@ -153,5 +147,3 @@ }) | ||
const mediaType = | ||
separatorToken.matchedText.length > 0 | ||
? separatorToken.matchedText | ||
: undefined | ||
separatorToken.matchedText.length > 0 ? separatorToken.matchedText : undefined | ||
const lineTokens = node.getTokens(TokenType.Other) | ||
@@ -227,4 +219,3 @@ const content = lineTokens.map((t) => t.matchedText).join('\n') | ||
tableHeader: exampleTable !== undefined ? exampleTable[0] : undefined, | ||
tableBody: | ||
exampleTable !== undefined ? exampleTable.slice(1) : undefined, | ||
tableBody: exampleTable !== undefined ? exampleTable.slice(1) : undefined, | ||
}) | ||
@@ -304,2 +295,3 @@ } | ||
} | ||
const tags = this.getTags(header) | ||
const children = [] | ||
@@ -330,2 +322,3 @@ const background = node.getSingle(RuleType.Background) | ||
children, | ||
tags, | ||
}) | ||
@@ -332,0 +325,0 @@ } |
import { messages } from '@cucumber/messages' | ||
import createLocation from './cli/createLocation' | ||
import createLocation from './createLocation' | ||
@@ -4,0 +4,0 @@ export class GherkinException extends Error { |
@@ -25,8 +25,8 @@ import Parser from './Parser' | ||
const parser = new Parser(new AstBuilder(options.newId)) | ||
parser.stopAtFirstError = false | ||
const gherkinDocument = parser.parse( | ||
data, | ||
const parser = new Parser( | ||
new AstBuilder(options.newId), | ||
new TokenMatcher(options.defaultDialect) | ||
) | ||
parser.stopAtFirstError = false | ||
const gherkinDocument = parser.parse(data) | ||
@@ -33,0 +33,0 @@ if (options.includeGherkinDocument) { |
@@ -1081,3 +1081,5 @@ { | ||
"feature": [ | ||
"Característica" | ||
"Característica", | ||
"Necesidad del negocio", | ||
"Requisito" | ||
], | ||
@@ -1094,3 +1096,4 @@ "given": [ | ||
"rule": [ | ||
"Regla" | ||
"Regla", | ||
"Regla de negocio" | ||
], | ||
@@ -1097,0 +1100,0 @@ "scenario": [ |
@@ -11,6 +11,3 @@ import countSymbols from './countSymbols' | ||
constructor( | ||
private readonly lineText: string, | ||
private readonly lineNumber: number | ||
) { | ||
constructor(private readonly lineText: string, private readonly lineNumber: number) { | ||
this.trimmedLineText = lineText.replace(/^\s+/g, '') // ltrim | ||
@@ -98,7 +95,3 @@ this.isEmpty = this.trimmedLineText.length === 0 | ||
if (!item.match(/^\S+$/)) { | ||
throw ParserException.create( | ||
'A tag may not contain whitespace', | ||
this.lineNumber, | ||
column | ||
) | ||
throw ParserException.create('A tag may not contain whitespace', this.lineNumber, column) | ||
} | ||
@@ -105,0 +98,0 @@ const span = { column, text: '@' + item } |
@@ -33,11 +33,7 @@ import { IdGenerator, messages } from '@cucumber/messages' | ||
getTableRows( | ||
node: AstNode | ||
): readonly messages.GherkinDocument.Feature.ITableRow[] | ||
getTableRows(node: AstNode): readonly messages.GherkinDocument.Feature.ITableRow[] | ||
ensureCellCount( | ||
rows: readonly messages.GherkinDocument.Feature.ITableRow[] | ||
): void | ||
ensureCellCount(rows: readonly messages.GherkinDocument.Feature.ITableRow[]): void | ||
transformNode(node: AstNode): any | ||
} |
@@ -10,2 +10,3 @@ import generateMessages from './generateMessages' | ||
import DIALECTS from './gherkin-languages.json' | ||
import TokenMatcher from './TokenMatcher' | ||
@@ -23,3 +24,4 @@ const dialects = DIALECTS as Readonly<{ [key: string]: Dialect }> | ||
TokenScanner, | ||
TokenMatcher, | ||
compile, | ||
} |
import { messages } from '@cucumber/messages' | ||
export default function makeSourceEnvelope( | ||
data: string, | ||
uri: string | ||
): messages.IEnvelope { | ||
export default function makeSourceEnvelope(data: string, uri: string): messages.IEnvelope { | ||
return new messages.Envelope({ | ||
@@ -8,0 +5,0 @@ source: new messages.Source({ |
@@ -69,10 +69,10 @@ import { messages, IdGenerator } from '@cucumber/messages' | ||
const tags = [].concat(featureTags).concat(rule.tags) | ||
rule.children.forEach((stepsContainer) => { | ||
if (stepsContainer.background) { | ||
ruleBackgroundSteps = ruleBackgroundSteps.concat( | ||
stepsContainer.background.steps | ||
) | ||
ruleBackgroundSteps = ruleBackgroundSteps.concat(stepsContainer.background.steps) | ||
} else if (stepsContainer.scenario.examples.length === 0) { | ||
compileScenario( | ||
featureTags, | ||
tags, | ||
ruleBackgroundSteps, | ||
@@ -100,3 +100,3 @@ stepsContainer.scenario, | ||
function compileScenario( | ||
featureTags: messages.GherkinDocument.Feature.ITag[], | ||
inheritedTags: messages.GherkinDocument.Feature.ITag[], | ||
backgroundSteps: messages.GherkinDocument.Feature.IStep[], | ||
@@ -114,7 +114,5 @@ scenario: messages.GherkinDocument.Feature.IScenario, | ||
const tags = [].concat(featureTags).concat(scenario.tags) | ||
const tags = [].concat(inheritedTags).concat(scenario.tags) | ||
scenario.steps.forEach((step) => | ||
steps.push(pickleStep(step, [], null, newId)) | ||
) | ||
scenario.steps.forEach((step) => steps.push(pickleStep(step, [], null, newId))) | ||
@@ -134,3 +132,3 @@ const pickle = messages.Pickle.create({ | ||
function compileScenarioOutline( | ||
featureTags: messages.GherkinDocument.Feature.ITag[], | ||
inheritedTags: messages.GherkinDocument.Feature.ITag[], | ||
backgroundSteps: messages.GherkinDocument.Feature.IStep[], | ||
@@ -152,14 +150,6 @@ scenario: messages.GherkinDocument.Feature.IScenario, | ||
: backgroundSteps.map((step) => pickleStep(step, [], null, newId)) | ||
const tags = [] | ||
.concat(featureTags) | ||
.concat(scenario.tags) | ||
.concat(examples.tags) | ||
const tags = [].concat(inheritedTags).concat(scenario.tags).concat(examples.tags) | ||
scenario.steps.forEach((scenarioOutlineStep) => { | ||
const step = pickleStep( | ||
scenarioOutlineStep, | ||
variableCells, | ||
valuesRow, | ||
newId | ||
) | ||
const step = pickleStep(scenarioOutlineStep, variableCells, valuesRow, newId) | ||
steps.push(step) | ||
@@ -211,7 +201,3 @@ }) | ||
if (argument.mediaType) { | ||
docString.mediaType = interpolate( | ||
argument.mediaType, | ||
variableCells, | ||
valueCells | ||
) | ||
docString.mediaType = interpolate(argument.mediaType, variableCells, valueCells) | ||
} | ||
@@ -218,0 +204,0 @@ return { |
import IToken from './IToken' | ||
import createLocation from './cli/createLocation' | ||
import createLocation from './createLocation' | ||
import { GherkinException } from './Errors' | ||
export class UnexpectedTokenException extends GherkinException { | ||
public static create<TokenType>( | ||
token: IToken<TokenType>, | ||
expectedTokenTypes: string[] | ||
) { | ||
public static create<TokenType>(token: IToken<TokenType>, expectedTokenTypes: string[]) { | ||
const message = `expected: ${expectedTokenTypes.join( | ||
@@ -21,9 +18,4 @@ ', ' | ||
export class UnexpectedEOFException extends GherkinException { | ||
public static create<TokenType>( | ||
token: IToken<TokenType>, | ||
expectedTokenTypes: string[] | ||
) { | ||
const message = `unexpected end of file, expected: ${expectedTokenTypes.join( | ||
', ' | ||
)}` | ||
public static create<TokenType>(token: IToken<TokenType>, expectedTokenTypes: string[]) { | ||
const message = `unexpected end of file, expected: ${expectedTokenTypes.join(', ')}` | ||
const location = tokenLocation(token) | ||
@@ -36,6 +28,3 @@ | ||
function tokenLocation<TokenType>(token: IToken<TokenType>) { | ||
return token.location && | ||
token.location.line && | ||
token.line && | ||
token.line.indent !== undefined | ||
return token.location && token.location.line && token.line && token.line.indent !== undefined | ||
? createLocation({ | ||
@@ -42,0 +31,0 @@ line: token.location.line, |
import DIALECTS from './gherkin-languages.json' | ||
import Dialect from './Dialect' | ||
import {NoSuchLanguageException} from './Errors' | ||
import {messages} from '@cucumber/messages' | ||
import { NoSuchLanguageException } from './Errors' | ||
import { messages } from '@cucumber/messages' | ||
import IToken from './IToken' | ||
import {TokenType} from './Parser' | ||
import { TokenType } from './Parser' | ||
import ITokenMatcher from './ITokenMatcher' | ||
@@ -11,3 +12,3 @@ const DIALECT_DICT: { [key: string]: Dialect } = DIALECTS | ||
export default class TokenMatcher { | ||
export default class TokenMatcher implements ITokenMatcher<TokenType> { | ||
private dialect: Dialect | ||
@@ -22,3 +23,3 @@ private dialectName: string | ||
public changeDialect(newDialectName: string, location?: messages.ILocation) { | ||
changeDialect(newDialectName: string, location?: messages.ILocation) { | ||
const newDialect = DIALECT_DICT[newDialectName] | ||
@@ -33,3 +34,3 @@ if (!newDialect) { | ||
public reset() { | ||
reset() { | ||
if (this.dialectName !== this.defaultDialectName) { | ||
@@ -42,12 +43,5 @@ this.changeDialect(this.defaultDialectName) | ||
public match_TagLine(token: IToken<TokenType>) { | ||
match_TagLine(token: IToken<TokenType>) { | ||
if (token.line.startsWith('@')) { | ||
this.setTokenMatched( | ||
token, | ||
TokenType.TagLine, | ||
null, | ||
null, | ||
null, | ||
token.line.getTags() | ||
) | ||
this.setTokenMatched(token, TokenType.TagLine, null, null, null, token.line.getTags()) | ||
return true | ||
@@ -58,56 +52,29 @@ } | ||
public match_FeatureLine(token: IToken<TokenType>) { | ||
return this.matchTitleLine( | ||
token, | ||
TokenType.FeatureLine, | ||
this.dialect.feature | ||
) | ||
match_FeatureLine(token: IToken<TokenType>) { | ||
return this.matchTitleLine(token, TokenType.FeatureLine, this.dialect.feature) | ||
} | ||
public match_ScenarioLine(token: IToken<TokenType>) { | ||
match_ScenarioLine(token: IToken<TokenType>) { | ||
return ( | ||
this.matchTitleLine( | ||
token, | ||
TokenType.ScenarioLine, | ||
this.dialect.scenario | ||
) || | ||
this.matchTitleLine( | ||
token, | ||
TokenType.ScenarioLine, | ||
this.dialect.scenarioOutline | ||
) | ||
this.matchTitleLine(token, TokenType.ScenarioLine, this.dialect.scenario) || | ||
this.matchTitleLine(token, TokenType.ScenarioLine, this.dialect.scenarioOutline) | ||
) | ||
} | ||
public match_BackgroundLine(token: IToken<TokenType>) { | ||
return this.matchTitleLine( | ||
token, | ||
TokenType.BackgroundLine, | ||
this.dialect.background | ||
) | ||
match_BackgroundLine(token: IToken<TokenType>) { | ||
return this.matchTitleLine(token, TokenType.BackgroundLine, this.dialect.background) | ||
} | ||
public match_ExamplesLine(token: IToken<TokenType>) { | ||
return this.matchTitleLine( | ||
token, | ||
TokenType.ExamplesLine, | ||
this.dialect.examples | ||
) | ||
match_ExamplesLine(token: IToken<TokenType>) { | ||
return this.matchTitleLine(token, TokenType.ExamplesLine, this.dialect.examples) | ||
} | ||
public match_RuleLine(token: IToken<TokenType>) { | ||
match_RuleLine(token: IToken<TokenType>) { | ||
return this.matchTitleLine(token, TokenType.RuleLine, this.dialect.rule) | ||
} | ||
public match_TableRow(token: IToken<TokenType>) { | ||
match_TableRow(token: IToken<TokenType>) { | ||
if (token.line.startsWith('|')) { | ||
// TODO: indent | ||
this.setTokenMatched( | ||
token, | ||
TokenType.TableRow, | ||
null, | ||
null, | ||
null, | ||
token.line.getTableCells() | ||
) | ||
this.setTokenMatched(token, TokenType.TableRow, null, null, null, token.line.getTableCells()) | ||
return true | ||
@@ -118,3 +85,3 @@ } | ||
public match_Empty(token: IToken<TokenType>) { | ||
match_Empty(token: IToken<TokenType>) { | ||
if (token.line.isEmpty) { | ||
@@ -127,3 +94,3 @@ this.setTokenMatched(token, TokenType.Empty, null, null, 0) | ||
public match_Comment(token: IToken<TokenType>) { | ||
match_Comment(token: IToken<TokenType>) { | ||
if (token.line.startsWith('#')) { | ||
@@ -137,3 +104,3 @@ const text = token.line.getLineText(0) // take the entire line, including leading space | ||
public match_Language(token: IToken<TokenType>) { | ||
match_Language(token: IToken<TokenType>) { | ||
const match = token.line.trimmedLineText.match(LANGUAGE_PATTERN) | ||
@@ -150,20 +117,12 @@ if (match) { | ||
public match_DocStringSeparator(token: IToken<TokenType>) { | ||
match_DocStringSeparator(token: IToken<TokenType>) { | ||
return this.activeDocStringSeparator == null | ||
? // open | ||
this._match_DocStringSeparator(token, '"""', true) || | ||
this._match_DocStringSeparator(token, '```', true) | ||
this._match_DocStringSeparator(token, '"""', true) || | ||
this._match_DocStringSeparator(token, '```', true) | ||
: // close | ||
this._match_DocStringSeparator( | ||
token, | ||
this.activeDocStringSeparator, | ||
false | ||
) | ||
this._match_DocStringSeparator(token, this.activeDocStringSeparator, false) | ||
} | ||
public _match_DocStringSeparator( | ||
token: IToken<TokenType>, | ||
separator: string, | ||
isOpen: boolean | ||
) { | ||
public _match_DocStringSeparator(token: IToken<TokenType>, separator: string, isOpen: boolean) { | ||
if (token.line.startsWith(separator)) { | ||
@@ -187,3 +146,3 @@ let mediaType = null | ||
public match_EOF(token: IToken<TokenType>) { | ||
match_EOF(token: IToken<TokenType>) { | ||
if (token.isEof) { | ||
@@ -196,3 +155,3 @@ this.setTokenMatched(token, TokenType.EOF) | ||
public match_StepLine(token: IToken<TokenType>) { | ||
match_StepLine(token: IToken<TokenType>) { | ||
const keywords = [] | ||
@@ -214,19 +173,9 @@ .concat(this.dialect.given) | ||
public match_Other(token: IToken<TokenType>) { | ||
match_Other(token: IToken<TokenType>) { | ||
const text = token.line.getLineText(this.indentToRemove) // take the entire line, except removing DocString indents | ||
this.setTokenMatched( | ||
token, | ||
TokenType.Other, | ||
this.unescapeDocString(text), | ||
null, | ||
0 | ||
) | ||
this.setTokenMatched(token, TokenType.Other, this.unescapeDocString(text), null, 0) | ||
return true | ||
} | ||
private matchTitleLine( | ||
token: IToken<TokenType>, | ||
tokenType: TokenType, | ||
keywords: readonly string[] | ||
) { | ||
matchTitleLine(token: IToken<TokenType>, tokenType: TokenType, keywords: readonly string[]) { | ||
for (const keyword of keywords) { | ||
@@ -254,7 +203,3 @@ if (token.line.startsWithTitleKeyword(keyword)) { | ||
token.matchedIndent = | ||
typeof indent === 'number' | ||
? indent | ||
: token.line == null | ||
? 0 | ||
: token.line.indent | ||
typeof indent === 'number' ? indent : token.line == null ? 0 : token.line.indent | ||
token.matchedItems = items || [] | ||
@@ -267,6 +212,6 @@ | ||
private unescapeDocString(text: string) { | ||
if (this.activeDocStringSeparator === "\"\"\"") { | ||
if (this.activeDocStringSeparator === '"""') { | ||
return text.replace('\\"\\"\\"', '"""') | ||
} | ||
if (this.activeDocStringSeparator === "```") { | ||
if (this.activeDocStringSeparator === '```') { | ||
return text.replace('\\`\\`\\`', '```') | ||
@@ -273,0 +218,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import createLocation from './cli/createLocation' | ||
import createLocation from './createLocation' | ||
import IToken from './IToken' | ||
@@ -18,12 +18,6 @@ import { messages } from '@cucumber/messages' | ||
source: string, | ||
private readonly makeToken: ( | ||
line: string, | ||
location: messages.ILocation | ||
) => IToken<TokenType> | ||
private readonly makeToken: (line: string, location: messages.ILocation) => IToken<TokenType> | ||
) { | ||
this.lines = source.split(/\r?\n/) | ||
if ( | ||
this.lines.length > 0 && | ||
this.lines[this.lines.length - 1].trim() === '' | ||
) { | ||
if (this.lines.length > 0 && this.lines[this.lines.length - 1].trim() === '') { | ||
this.lines.pop() | ||
@@ -30,0 +24,0 @@ } |
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"target": "es5", | ||
"lib": [ | ||
"es2019", | ||
"dom" | ||
], | ||
"sourceMap": true, | ||
"allowJs": false, | ||
"jsx": "react", | ||
"resolveJsonModule": true, | ||
"module": "commonjs", | ||
"esModuleInterop": true, | ||
"noImplicitAny": true, | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"downlevelIteration": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"src/**/*", | ||
"test/**/*", | ||
"features/**/*" | ||
] | ||
"extends": "../../tsconfig.json" | ||
} |
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 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 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
844496
2
6
17629
0
117
+ Added@cucumber/message-streams@1.0.0(transitive)
+ Added@cucumber/messages@15.0.0(transitive)
- Removedcommander@^7.1.0
- Removedsource-map-support@^0.5.19
- Removed@cucumber/messages@14.1.2(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedcommander@7.2.0(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsource-map-support@0.5.21(transitive)
Updated@cucumber/messages@^15.0.0