astro-eslint-parser 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -32,10 +32,62 @@ const errors_1 = require("../../errors");
|
|
|
32
32
|
*/
|
|
33
33
|
function parse(code, ctx) {
|
|
34
34
|
const ast = service.parse(code, { position: true }).ast;
|
|
35
|
+
const htmlElement = ast.children.find((n) => n.type === "element" && n.name === "html");
|
|
36
|
+
if (htmlElement) {
|
|
37
|
+
adjustHTML(ast, htmlElement, ctx);
|
|
38
|
+
}
|
|
35
39
|
fixLocations(ast, ctx);
|
|
36
40
|
return { ast };
|
|
37
41
|
}
|
|
38
42
|
exports.parse = parse;
|
|
43
|
+
/**
|
|
44
|
+
* Adjust <html> element node
|
|
45
|
+
*/
|
|
46
|
+
function adjustHTML(ast, htmlElement, ctx) {
|
|
47
|
+
var _a;
|
|
48
|
+
const htmlEnd = ctx.code.indexOf("</html");
|
|
49
|
+
if (htmlEnd == null) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const children = [...htmlElement.children];
|
|
53
|
+
for (const child of children) {
|
|
54
|
+
const offset = (_a = child.position) === null || _a === void 0 ? void 0 : _a.start.offset;
|
|
55
|
+
if (offset != null) {
|
|
56
|
+
if (htmlEnd <= offset) {
|
|
57
|
+
htmlElement.children.splice(htmlElement.children.indexOf(child), 1);
|
|
58
|
+
ast.children.push(child);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (child.type === "element" && child.name === "body") {
|
|
62
|
+
adjustHTMLBody(ast, htmlElement, htmlEnd, child, ctx);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Adjust <body> element node
|
|
68
|
+
*/
|
|
69
|
+
function adjustHTMLBody(ast, htmlElement, htmlEnd, bodyElement, ctx) {
|
|
70
|
+
var _a;
|
|
71
|
+
const bodyEnd = ctx.code.indexOf("</body");
|
|
72
|
+
if (bodyEnd == null) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const children = [...bodyElement.children];
|
|
76
|
+
for (const child of children) {
|
|
77
|
+
const offset = (_a = child.position) === null || _a === void 0 ? void 0 : _a.start.offset;
|
|
78
|
+
if (offset != null) {
|
|
79
|
+
if (bodyEnd <= offset) {
|
|
80
|
+
bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
|
|
81
|
+
if (htmlEnd <= offset) {
|
|
82
|
+
ast.children.push(child);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
htmlElement.children.push(child);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
39
91
|
/**
|
|
40
92
|
* Fix locations
|
|
41
93
|
*/
|