Skip to content

Commit 646e8ba

Browse files
committed
refactor: make error codes an enum
1 parent 88c77cc commit 646e8ba

File tree

29 files changed

+117
-69
lines changed

29 files changed

+117
-69
lines changed

src/__tests__/fixtures/argument-attr-multiple/__snapshots__/argument-attr-multiple.expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
1╭─ <div for(var i = 0; i < 10; i++) (nonsense!)></div>
2-
│ │ │ ││ ╰─ error(ILLEGAL_ATTRIBUTE_ARGUMENT:An attribute can only have one set of arguments) "nonsense!"
2+
│ │ │ ││ ╰─ error(INVALID_ATTRIBUTE_ARGUMENT:An attribute can only have one set of arguments) "nonsense!"
33
│ │ │ │╰─ attrArgs.value "var i = 0; i < 10; i++"
44
│ │ │ ╰─ attrArgs "(var i = 0; i < 10; i++)"
55
│ │ ╰─ attrName "for"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
1╭─ <for(var i = 0; i < 10; i++) (nonsense!)></for>
2-
│ │ ││ ╰─ error(ILLEGAL_TAG_ARGUMENT:A tag can only have one argument)
2+
│ │ ││ ╰─ error(INVALID_TAG_ARGUMENT:A tag can only have one argument)
33
│ │ │╰─ tagArgs.value "var i = 0; i < 10; i++"
44
│ │ ╰─ tagArgs "(var i = 0; i < 10; i++)"
55
╰─ ╰─ tagName "for"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
1╭─ tagname <span>hello frank</span>
2-
│ │ ╰─ error(ILLEGAL_ATTRIBUTE_NAME:Invalid attribute name. Attribute name cannot begin with the "<" character.)
2+
│ │ ╰─ error(INVALID_ATTRIBUTE_NAME:Invalid attribute name. Attribute name cannot begin with the "<" character.)
33
╰─ ╰─ tagName "tagname"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
1╭─ var colors=['red', 'green', 'blue']
2-
╰─ ╰─ error(BAD_INDENTATION:Line has extra indentation at the beginning)
2+
╰─ ╰─ error(INVALID_INDENTATION:Line has extra indentation at the beginning)

src/__tests__/fixtures/mixed-bad-indentation/__snapshots__/mixed-bad-indentation.expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
│ │ ╰─ tagName
99
╰─ ╰─ openTagEnd
1010
3╭─ BAD
11-
╰─ ╰─ error(BAD_INDENTATION:Line indentation does match indentation of previous line)
11+
╰─ ╰─ error(INVALID_INDENTATION:Line indentation does match indentation of previous line)

src/__tests__/fixtures/open-tag-only-with-body-concise/__snapshots__/open-tag-only-with-body-concise.expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
│ │ ╰─ attrName "src"
55
╰─ ╰─ tagName "img"
66
2╭─ This is not allowed!
7-
│ │ ╰─ error(BAD_INDENTATION:Line has extra indentation at the beginning)
7+
│ │ ╰─ error(INVALID_INDENTATION:Line has extra indentation at the beginning)
88
╰─ ╰─ openTagEnd
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
1╭─ <${}/>
2-
╰─ ╰─ error(PLACEHOLDER_EXPRESSION_REQUIRED:Invalid placeholder, the expression cannot be missing)
2+
╰─ ╰─ error(MALFORMED_PLACEHOLDER:Invalid placeholder, the expression cannot be missing)
33
2╰─
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
1╭─ script
22
╰─ ╰─ tagName "script"
33
2╭─ p - This is not allowed
4-
│ │ ╰─ error(ILLEGAL_LINE_START:A line within a tag that only allows text content must begin with a "-" character)
4+
│ │ ╰─ error(INVALID_LINE_START:A line within a tag that only allows text content must begin with a "-" character)
55
╰─ ╰─ openTagEnd
66
3╰─ div

src/__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import path from "path";
33
import snap from "mocha-snap";
4-
import { getLines, TagType } from "../internal";
4+
import { ErrorCode, getLines, TagType } from "../internal";
55
import { createParser, Position, Ranges, Range } from "..";
66

77
const FIXTURES = path.join(__dirname, "fixtures");
@@ -61,7 +61,7 @@ for (const entry of fs.readdirSync(FIXTURES)) {
6161
const tagStack: Ranges.TagName[] = [];
6262
const parser = createParser({
6363
onError(range) {
64-
addRange(`error(${range.code}:${range.message})`, range);
64+
addRange(`error(${ErrorCode[range.code]}:${range.message})`, range);
6565
},
6666
onText(range) {
6767
addRange("text", range);

src/core/Parser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
getLines,
99
getLoc,
1010
getPos,
11+
ErrorCode,
1112
} from "../internal";
1213

1314
export interface Meta extends Range {
@@ -169,7 +170,7 @@ export class Parser {
169170
content.indent = this.indent;
170171
}
171172

172-
emitError(range: number | Range, code: string, message: string) {
173+
emitError(range: number | Range, code: ErrorCode, message: string) {
173174
let start, end;
174175

175176
if (typeof range === "number") {

0 commit comments

Comments
 (0)