astro-eslint-parser 0.2.1 → 0.2.2

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.
@@ -52,38 +52,44 @@ function adjustHTML(ast, htmlElement, ctx) {
52
52
  if (htmlEnd == null) {
53
53
  return;
54
54
  }
55
+ const hasTokenAfter = Boolean(ctx.code.slice(htmlEnd + 7).trim());
55
56
  const children = [...htmlElement.children];
56
57
  for (const child of children) {
57
58
  const offset = child.position?.start.offset;
58
- if (offset != null) {
59
+ if (hasTokenAfter && offset != null) {
59
60
  if (htmlEnd <= offset) {
60
61
  htmlElement.children.splice(htmlElement.children.indexOf(child), 1);
61
62
  ast.children.push(child);
62
63
  }
63
64
  }
64
65
  if (child.type === "element" && child.name === "body") {
65
- adjustHTMLBody(ast, htmlElement, htmlEnd, child, ctx);
66
+ adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfter, child, ctx);
66
67
  }
67
68
  }
68
69
  }
69
70
  /**
70
71
  * Adjust <body> element node
71
72
  */
72
- function adjustHTMLBody(ast, htmlElement, htmlEnd, bodyElement, ctx) {
73
+ function adjustHTMLBody(ast, htmlElement, htmlEnd, hasTokenAfterHtmlEnd, bodyElement, ctx) {
73
74
  const bodyEnd = ctx.code.indexOf("</body");
74
75
  if (bodyEnd == null) {
75
76
  return;
76
77
  }
78
+ const hasTokenAfter = Boolean(ctx.code.slice(bodyEnd + 7, htmlEnd).trim());
79
+ if (!hasTokenAfter && !hasTokenAfterHtmlEnd) {
80
+ return;
81
+ }
77
82
  const children = [...bodyElement.children];
78
83
  for (const child of children) {
79
84
  const offset = child.position?.start.offset;
80
85
  if (offset != null) {
81
86
  if (bodyEnd <= offset) {
82
- bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
83
- if (htmlEnd <= offset) {
87
+ if (hasTokenAfterHtmlEnd && htmlEnd <= offset) {
88
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
84
89
  ast.children.push(child);
85
90
  }
86
- else {
91
+ else if (hasTokenAfter) {
92
+ bodyElement.children.splice(bodyElement.children.indexOf(child), 1);
87
93
  htmlElement.children.push(child);
88
94
  }
89
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Astro component parser for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "homepage": "https://github.com/ota-meshi/astro-eslint-parser#readme",
44
44
  "dependencies": {
45
- "@astrojs/compiler": "^0.15.0",
45
+ "@astrojs/compiler": "^0.15.2",
46
46
  "@typescript-eslint/types": "^5.25.0",
47
47
  "debug": "^4.3.4",
48
48
  "eslint-visitor-keys": "^3.0.0",
@@ -70,7 +70,7 @@
70
70
  "eslint": "^8.15.0",
71
71
  "eslint-config-prettier": "^8.3.0",
72
72
  "eslint-formatter-codeframe": "^7.32.1",
73
- "eslint-plugin-astro": "^0.4.0",
73
+ "eslint-plugin-astro": "^0.8.0",
74
74
  "eslint-plugin-eslint-comments": "^3.2.0",
75
75
  "eslint-plugin-json-schema-validator": "^3.0.0",
76
76
  "eslint-plugin-jsonc": "^2.0.0",