Skip to content

Commit b074aeb

Browse files
committed
small refactorings
1 parent 73656c8 commit b074aeb

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/analyser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ export const analyse = (text: string): Diagnostic[] => {
2929

3030
// HTML parser
3131
const document = parse(text);
32-
ELEMENT_DEFINITIONS.forEach(([tagName, attNames]) => {
32+
ELEMENT_DEFINITIONS.forEach(({tagName, attributes}) => {
3333
const els = document.querySelectorAll(tagName);
3434
els.forEach((el) => {
35-
attNames.forEach((att) => {
35+
attributes.forEach((attribute) => {
3636
let iStart = el.range[0];
3737
let iEnd = el.range[1];
38-
if (el.hasAttribute(att.name)) {
38+
if (el.hasAttribute(attribute.name)) {
3939
// Try to parse it
40-
const value = el.getAttribute(att.name);
40+
const value = el.getAttribute(attribute.name);
4141
if (value !== undefined) {
42-
switch(att.format) {
42+
switch(attribute.format) {
4343
case("json"):
4444
try {
4545
JSON.parse(value)
@@ -56,7 +56,7 @@ export const analyse = (text: string): Diagnostic[] => {
5656
character: characterNumber[iEnd],
5757
},
5858
},
59-
message: `Could not parse: '${att.name}' into ${att.format}.`,
59+
message: `Could not parse: '${attribute.name}' into ${attribute.format}.`,
6060
});
6161
}
6262
break;
@@ -74,7 +74,7 @@ export const analyse = (text: string): Diagnostic[] => {
7474
character: characterNumber[iEnd],
7575
},
7676
},
77-
message: `Could not parse: '${att.name}' into ${att.format}.`,
77+
message: `Could not parse: '${attribute.name}' into ${attribute.format}.`,
7878
});
7979
}
8080
break;
@@ -93,7 +93,7 @@ export const analyse = (text: string): Diagnostic[] => {
9393
},
9494
end: { line: lineNumber[iEnd], character: characterNumber[iEnd] },
9595
},
96-
message: `Missing '${att.name}' HTML attribute.`,
96+
message: `Missing '${attribute.name}' HTML attribute.`,
9797
});
9898
}
9999
});

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ const codeActions = (params: CodeActionParams): CodeActionResult => {
337337
const dom = parse(text);
338338

339339
// TODO: drive this with diagnostic data
340-
ELEMENT_DEFINITIONS.forEach(([tagName, attributes]) => {
340+
ELEMENT_DEFINITIONS.forEach(({tagName, attributes}) => {
341341
const els = dom.getElementsByTagName(tagName);
342342
els.forEach((el) => {
343343
attributes.forEach((attribute) => {

src/schema.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ interface TypedAttribute {
55
default: string;
66
}
77

8-
type Definition = [string, TypedAttribute[]];
8+
type Definition = { tagName: string; attributes: TypedAttribute[] };
99

1010
export const ELEMENT_DEFINITIONS: Definition[] = [
11-
[
12-
"l-map",
13-
[
11+
{
12+
tagName: "l-map",
13+
attributes: [
1414
{ name: "center", format: "json", default: "[0, 0]" },
1515
{ name: "zoom", format: "number", default: "0" },
1616
],
17-
],
18-
["l-tile-layer", [{ name: "url-template", format: "string", default: "" }]],
19-
["l-circle", [{ name: "lat-lng", format: "json", default: "[0, 0]" }]],
17+
},
18+
{
19+
tagName: "l-tile-layer",
20+
attributes: [{ name: "url-template", format: "string", default: "" }],
21+
},
22+
{
23+
tagName: "l-circle",
24+
attributes: [{ name: "lat-lng", format: "json", default: "[0, 0]" }],
25+
},
2026
];

0 commit comments

Comments
 (0)