Skip to content

Commit 212b016

Browse files
committed
#69 Store parameters as object rather than array.
1 parent 72c2594 commit 212b016

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/parsing/tylasu-parser.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ export abstract class TylasuParser<
197197
issues.push(Issue.syntactic(message, IssueSeverity.ERROR, Position.ofParseTree(it),
198198
undefined,
199199
ERROR_NODE_FOUND,
200-
[it.symbol?.type?.toString() || "", it.symbol?.text || ""]));
200+
{
201+
type: it.symbol?.type?.toString() || "",
202+
text: it.symbol?.text || ""
203+
}));
201204
});
202205
}
203206

src/transformation/transformation.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ export class ASTTransformer {
266266
if (this.allowGenericNode) {
267267
const origin : Origin | undefined = this.asOrigin(source);
268268
nodes = [new GenericNode(parent).withOrigin(origin)];
269-
const nodeName = getNodeDefinition(source)?.name || source?.constructor.name || "–";
269+
const nodeType = getNodeDefinition(source)?.name || source?.constructor.name || "–";
270270
this.issues.push(
271271
Issue.semantic(
272-
`Source node not mapped: ${nodeName}`,
272+
`Source node not mapped: ${nodeType}`,
273273
IssueSeverity.INFO,
274274
origin?.position,
275275
origin instanceof Node ? origin : undefined,
276276
SOURCE_NODE_NOT_MAPPED,
277-
[nodeName]
277+
{ nodeType }
278278
)
279279
);
280280
} else {

src/validation.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ export class Issue {
1414
public readonly position?: Position,
1515
public readonly node?: Node,
1616
public readonly code?: string,
17-
public readonly args: string[] = []
17+
public readonly args: { [key: string]: string } = {}
1818
) {
1919
if (!position) {
2020
this.position = node?.position;
2121
}
2222
}
2323

2424
static lexical(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position,
25-
node?: Node, code?: string, args: string[] = []): Issue {
25+
node?: Node, code?: string, args: { [key: string]: string } = {}): Issue {
2626
return new Issue(IssueType.LEXICAL, message, severity, position, node, code, args);
2727
}
2828

2929
static syntactic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position,
30-
node?: Node, code?: string, args: string[] = []): Issue {
30+
node?: Node, code?: string, args: { [key: string]: string } = {}): Issue {
3131
return new Issue(IssueType.SYNTACTIC, message, severity, position, node, code, args);
3232
}
3333

3434
static semantic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position,
35-
node?: Node, code?: string, args: string[] = []): Issue {
35+
node?: Node, code?: string, args: { [key: string]: string } = {}): Issue {
3636
return new Issue(IssueType.SEMANTIC, message, severity, position, node, code, args);
3737
}
3838
}

tests/issues.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('Issues', function() {
2626
});
2727
let issue = Issue.syntactic("Unexpected token: foo", IssueSeverity.ERROR, undefined, undefined, SYNTAX_ERROR);
2828
expect(i18next.t(issue.code!)).to.equal("A syntax error occurred!");
29-
issue = Issue.syntactic("Unexpected token: foo", IssueSeverity.ERROR, undefined, undefined, SOURCE_NODE_NOT_MAPPED, ["SomeNode"]);
30-
expect(i18next.t(issue.code!, { type: issue.args[0] })).to.equal("Source node not mapped: SomeNode");
29+
issue = Issue.semantic("Node not mapped: SomeNode", IssueSeverity.ERROR, undefined, undefined,
30+
SOURCE_NODE_NOT_MAPPED, { nodeType: "SomeNode" });
31+
expect(i18next.t(issue.code!, { type: issue.args.nodeType })).to.equal("Source node not mapped: SomeNode");
3132
});
3233
});

0 commit comments

Comments
 (0)