@markuplint/astro-parser 3.6.1 → 3.6.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.
@@ -1,3 +1,11 @@
1
1
  import type { RootNode } from '@astrojs/compiler/shared/ast';
2
- export type { RootNode, ElementNode, CustomElementNode, ComponentNode, FragmentNode, AttributeNode, Node, } from '@astrojs/compiler/shared/ast';
2
+ export type {
3
+ RootNode,
4
+ ElementNode,
5
+ CustomElementNode,
6
+ ComponentNode,
7
+ FragmentNode,
8
+ AttributeNode,
9
+ Node,
10
+ } from '@astrojs/compiler/shared/ast';
3
11
  export declare function astroParse(code: string): RootNode;
@@ -1,3 +1,9 @@
1
1
  import type { AttributeNode } from './astro-parser';
2
2
  import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
3
- export declare function attrTokenizer(attr: AttributeNode, nextAttr: AttributeNode | null, rawHtml: string, startTag: string, startTagEndOffset: number): MLASTHTMLAttr;
3
+ export declare function attrTokenizer(
4
+ attr: AttributeNode,
5
+ nextAttr: AttributeNode | null,
6
+ rawHtml: string,
7
+ startTag: string,
8
+ startTagEndOffset: number,
9
+ ): MLASTHTMLAttr;
package/lib/parse.js CHANGED
@@ -233,25 +233,42 @@ nextNode, offset, options) {
233
233
  if (!originNode.position) {
234
234
  throw new TypeError("Node doesn't have position");
235
235
  }
236
+ let startTagRaw;
236
237
  let childrenStart;
237
238
  let childrenEnd;
238
239
  if (originNode.children[0]) {
239
240
  childrenStart = ((_c = (_b = (_a = originNode.children[0].position) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.offset) !== null && _c !== void 0 ? _c : 0) + offset;
240
241
  childrenEnd = ((_g = (_f = (_e = (_d = originNode.children[originNode.children.length - 1]) === null || _d === void 0 ? void 0 : _d.position) === null || _e === void 0 ? void 0 : _e.end) === null || _f === void 0 ? void 0 : _f.offset) !== null && _g !== void 0 ? _g : 0) + offset;
242
+ const startTagStartOffset = originNode.position.start.offset + offset;
243
+ const startTagEndOffset = childrenStart;
244
+ startTagRaw = rawHtml.slice(startTagStartOffset, startTagEndOffset);
241
245
  }
242
246
  else {
243
247
  childrenStart = offset + ((_k = (_j = (_h = originNode.position.end) === null || _h === void 0 ? void 0 : _h.offset) !== null && _j !== void 0 ? _j : nextNode === null || nextNode === void 0 ? void 0 : nextNode.endOffset) !== null && _k !== void 0 ? _k : rawHtml.length - offset);
244
248
  childrenEnd = childrenStart;
245
249
  const startTagStartOffset = originNode.position.start.offset + offset;
246
- const startTagEndOffset = childrenStart;
247
- const tag = rawHtml.slice(startTagStartOffset, startTagEndOffset);
250
+ let startTagEndOffset = childrenStart;
251
+ startTagRaw = rawHtml.slice(startTagStartOffset, startTagEndOffset);
248
252
  const expectedCloseTag = `</${originNode.name}>`;
249
- if (tag.includes(expectedCloseTag)) {
253
+ if (startTagRaw.includes(expectedCloseTag)) {
250
254
  childrenStart -= expectedCloseTag.length;
251
255
  childrenEnd = childrenStart;
256
+ startTagRaw = startTagRaw.replace(expectedCloseTag, '');
257
+ }
258
+ else {
259
+ let startTagRawMasked = startTagRaw;
260
+ for (const attr of originNode.attributes) {
261
+ startTagRawMasked = startTagRawMasked.replace(attr.value, ' '.repeat(attr.value.length));
262
+ }
263
+ const closeChars = '>';
264
+ const closeOffset = startTagRawMasked.indexOf(closeChars) + closeChars.length;
265
+ startTagEndOffset = startTagStartOffset + closeOffset;
266
+ startTagRaw = rawHtml.slice(startTagStartOffset, startTagEndOffset);
252
267
  }
253
268
  // console.log({
254
- // tag,
269
+ // originNode,
270
+ // attrs: originNode.attributes,
271
+ // startTagRaw,
255
272
  // startTagStartOffset,
256
273
  // startTagEndOffset,
257
274
  // expectedCloseTag,
@@ -259,9 +276,6 @@ nextNode, offset, options) {
259
276
  // childrenEnd,
260
277
  // });
261
278
  }
262
- const startTagStartOffset = originNode.position.start.offset + offset;
263
- const startTagEndOffset = childrenStart;
264
- const startTagRaw = rawHtml.slice(startTagStartOffset, startTagEndOffset);
265
279
  const tagTokens = (0, html_parser_1.parseRawTag)(startTagRaw, startLine, startCol, startOffset);
266
280
  const tagName = tagTokens.tagName;
267
281
  let endTag = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/astro-parser",
3
- "version": "3.6.1",
3
+ "version": "3.6.2",
4
4
  "description": "astro parser for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -26,5 +26,5 @@
26
26
  "astro-eslint-parser": "^0.13.2",
27
27
  "tslib": "^2.4.1"
28
28
  },
29
- "gitHead": "3cdf5a088b2da03773d5d4461d0e65ec32290a00"
29
+ "gitHead": "884e8dbf60ec2a350761d5cda3cdc0725881b9dc"
30
30
  }