astro-eslint-parser 0.0.10 → 0.0.11

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.
@@ -50,7 +50,7 @@ function parseByService(code) {
50
50
  return { ast };
51
51
  }
52
52
  catch (_a) {
53
- // Adjust because you may get the wrong escape as JSON.
53
+ // Adjust because may get the wrong escape as JSON.
54
54
  const ast = JSON.parse(jsonAst.replace(/\\./gu, (m) => {
55
55
  try {
56
56
  JSON.parse(`"${m}"`);
@@ -117,7 +117,9 @@ function adjustHTMLBody(ast, htmlElement, htmlEnd, bodyElement, ctx) {
117
117
  function fixLocations(node, ctx) {
118
118
  // FIXME: Adjust because the parser does not return the correct location.
119
119
  let start = 0;
120
- (0, astro_1.walk)(node, ctx.code, (node) => {
120
+ (0, astro_1.walk)(node, ctx.code,
121
+ // eslint-disable-next-line complexity -- X(
122
+ (node, parent) => {
121
123
  if (node.type === "frontmatter") {
122
124
  start = node.position.start.offset = tokenIndex(ctx, "---", start);
123
125
  start = node.position.end.offset =
@@ -146,8 +148,20 @@ function fixLocations(node, ctx) {
146
148
  start = (0, astro_1.getCommentEndOffset)(node, ctx);
147
149
  }
148
150
  else if (node.type === "text") {
149
- start = node.position.start.offset = tokenIndex(ctx, node.value, start);
150
- start += node.value.length;
151
+ if (parent.type === "element" &&
152
+ (parent.name === "script" || parent.name === "style")) {
153
+ node.position.start.offset = start;
154
+ start = ctx.code.indexOf(`</${parent.name}`, start);
155
+ if (start < 0) {
156
+ start = ctx.code.length;
157
+ }
158
+ // Workaround for escape bugs
159
+ node.value = ctx.code.slice(node.position.start.offset, start);
160
+ }
161
+ else {
162
+ start = node.position.start.offset = tokenIndex(ctx, node.value, start);
163
+ start += node.value.length;
164
+ }
151
165
  }
152
166
  else if (node.type === "expression") {
153
167
  start = node.position.start.offset = tokenIndex(ctx, "{", start);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-eslint-parser",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "Astro parser for ESLint",
5
5
  "main": "lib/index.js",
6
6
  "files": [