astro-eslint-parser 0.0.9 → 0.0.10
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type { ParseOptions
|
|
1
|
+
import type { ParseOptions } from "@astrojs/compiler";
|
|
2
2
|
/**
|
|
3
3
|
* Parse code by `@astrojs/compiler`
|
|
4
4
|
*/
|
|
5
|
-
export declare function parse(code: string, options: ParseOptions):
|
|
5
|
+
export declare function parse(code: string, options: ParseOptions): {
|
|
6
|
+
ast: string;
|
|
7
|
+
};
|
|
@@ -16,7 +16,6 @@ const service = globalThis["@astrojs/compiler"];
|
|
|
16
16
|
* Parse code by `@astrojs/compiler`
|
|
17
17
|
*/
|
|
18
18
|
function parse(code, options) {
|
|
19
|
-
|
|
20
|
-
return { ast };
|
|
19
|
+
return service.parse(code, options);
|
|
21
20
|
}
|
|
22
21
|
exports.parse = parse;
|
|
@@ -31,7 +31,7 @@ const errors_1 = require("../../errors");
|
|
|
31
31
|
* Parse code by `@astrojs/compiler`
|
|
32
32
|
*/
|
|
33
33
|
function parse(code, ctx) {
|
|
34
|
-
const ast =
|
|
34
|
+
const ast = parseByService(code).ast;
|
|
35
35
|
const htmlElement = ast.children.find((n) => n.type === "element" && n.name === "html");
|
|
36
36
|
if (htmlElement) {
|
|
37
37
|
adjustHTML(ast, htmlElement, ctx);
|
|
@@ -40,6 +40,29 @@ function parse(code, ctx) {
|
|
|
40
40
|
return { ast };
|
|
41
41
|
}
|
|
42
42
|
exports.parse = parse;
|
|
43
|
+
/**
|
|
44
|
+
* Parse code by `@astrojs/compiler`
|
|
45
|
+
*/
|
|
46
|
+
function parseByService(code) {
|
|
47
|
+
const jsonAst = service.parse(code, { position: true }).ast;
|
|
48
|
+
try {
|
|
49
|
+
const ast = JSON.parse(jsonAst);
|
|
50
|
+
return { ast };
|
|
51
|
+
}
|
|
52
|
+
catch (_a) {
|
|
53
|
+
// Adjust because you may get the wrong escape as JSON.
|
|
54
|
+
const ast = JSON.parse(jsonAst.replace(/\\./gu, (m) => {
|
|
55
|
+
try {
|
|
56
|
+
JSON.parse(`"${m}"`);
|
|
57
|
+
return m;
|
|
58
|
+
}
|
|
59
|
+
catch (_a) {
|
|
60
|
+
return `\\${m}`;
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
return { ast };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
43
66
|
/**
|
|
44
67
|
* Adjust <html> element node
|
|
45
68
|
*/
|