Skip to content

Commit f0acb6c

Browse files
committed
#69 Change issue args format again so that it's friendly to both indexed and by-name interpolation
1 parent 212b016 commit f0acb6c

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

src/parsing/tylasu-parser.ts

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

src/transformation/transformation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class ASTTransformer {
274274
origin?.position,
275275
origin instanceof Node ? origin : undefined,
276276
SOURCE_NODE_NOT_MAPPED,
277-
{ nodeType }
277+
[{ name: "nodeType", value: nodeType }]
278278
)
279279
);
280280
} else {

src/validation.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ export enum IssueType { LEXICAL, SYNTACTIC, SEMANTIC}
55

66
export enum IssueSeverity { ERROR, WARNING, INFO}
77

8+
export interface IssueArg {
9+
name: string;
10+
value: string;
11+
}
12+
813
export class Issue {
914

1015
constructor(
@@ -14,25 +19,25 @@ export class Issue {
1419
public readonly position?: Position,
1520
public readonly node?: Node,
1621
public readonly code?: string,
17-
public readonly args: { [key: string]: string } = {}
22+
public readonly args: IssueArg[] = []
1823
) {
1924
if (!position) {
2025
this.position = node?.position;
2126
}
2227
}
2328

2429
static lexical(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position,
25-
node?: Node, code?: string, args: { [key: string]: string } = {}): Issue {
30+
node?: Node, code?: string, args: IssueArg[] = []): Issue {
2631
return new Issue(IssueType.LEXICAL, message, severity, position, node, code, args);
2732
}
2833

2934
static syntactic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position,
30-
node?: Node, code?: string, args: { [key: string]: string } = {}): Issue {
35+
node?: Node, code?: string, args: IssueArg[] = []): Issue {
3136
return new Issue(IssueType.SYNTACTIC, message, severity, position, node, code, args);
3237
}
3338

3439
static semantic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position,
35-
node?: Node, code?: string, args: { [key: string]: string } = {}): Issue {
40+
node?: Node, code?: string, args: IssueArg[] = []): Issue {
3641
return new Issue(IssueType.SEMANTIC, message, severity, position, node, code, args);
3742
}
3843
}

tests/issues.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Issues', function() {
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!");
2929
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");
30+
SOURCE_NODE_NOT_MAPPED, [{ name: "nodeType", value: "SomeNode" }]);
31+
expect(i18next.t(issue.code!, { type: issue.args[0].value })).to.equal("Source node not mapped: SomeNode");
3232
});
3333
});

0 commit comments

Comments
 (0)