@markuplint/svelte-parser 4.0.0-alpha.3 → 4.0.0-dev.28

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.
package/lib/attr.js CHANGED
@@ -4,7 +4,7 @@ const mustacheTag = {
4
4
  start: '{',
5
5
  end: '}',
6
6
  };
7
- const specificBindDirective = ['bind:group', 'bind:this'];
7
+ const specificBindDirective = new Set(['bind:group', 'bind:this']);
8
8
  export function attr(
9
9
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
10
10
  attr, rawHTML) {
@@ -33,7 +33,7 @@ attr, rawHTML) {
33
33
  : '';
34
34
  token = directiveTokenizer(raw, valueToken, startLine, startCol, startOffset);
35
35
  }
36
- if (!specificBindDirective.includes(token.name.raw) && /^bind:/i.test(token.name.raw)) {
36
+ if (!specificBindDirective.has(token.name.raw) && /^bind:/i.test(token.name.raw)) {
37
37
  // Remove "bind:"
38
38
  token.potentialName = token.name.raw.slice(5);
39
39
  token.isDirective = undefined;
@@ -1,9 +1,9 @@
1
1
  import { attrTokenizer } from '@markuplint/html-parser';
2
2
  import { tokenizer, uuid } from '@markuplint/parser-utils';
3
3
  // eslint-disable-next-line no-control-regex
4
- const reNameOnly = /^[^\x00-\x1f\x7f-\x9f {>/=]+/;
4
+ const reNameOnly = /^[^\u0000-\u001F /=>{\u007F-\u009F]+/;
5
5
  // eslint-disable-next-line no-control-regex
6
- const reBeforeStructure = /^(\s*)([^\x00-\x1f\x7f-\x9f {>/=]+)(\s*)(=)(\s*){(\s*)$/;
6
+ const reBeforeStructure = /^(\s*)([^\u0000-\u001F /=>{\u007F-\u009F]+)(\s*)(=)(\s*){(\s*)$/;
7
7
  const reBeforeStructureWithoutName = /^{(\s*)$/;
8
8
  const reAfterStructure = /(\s*)}/;
9
9
  export default function directiveTokenizer(raw, rawValue, line, col, startOffset) {
package/lib/nodeize.js CHANGED
@@ -258,7 +258,7 @@ parentNode, rawHtml, options) {
258
258
  startTag.endCol = firstChild.startCol;
259
259
  startTag.raw = rawHtml.slice(startTag.startOffset, startTag.endOffset);
260
260
  }
261
- const lastChild = startTag.childNodes[startTag.childNodes.length - 1];
261
+ const lastChild = startTag.childNodes.at(-1);
262
262
  if (lastChild && lastChild.endOffset > startTag.endOffset) {
263
263
  const startOffset = lastChild.endOffset;
264
264
  const startLine = lastChild.endLine;
@@ -283,7 +283,7 @@ parentNode, rawHtml, options) {
283
283
  };
284
284
  }
285
285
  }
286
- return endTag != null ? [startTag, endTag] : startTag;
286
+ return endTag == null ? startTag : [startTag, endTag];
287
287
  }
288
288
  }
289
289
  }
@@ -33,7 +33,7 @@ nextNode, options) {
33
33
  let elseTag = null;
34
34
  if (originNode.else) {
35
35
  const elseNode = originNode.else;
36
- const elseTagStartOffset = children.length > 0 ? children[children.length - 1]?.end ?? 0 : startTagLocation.endOffset;
36
+ const elseTagStartOffset = children.length > 0 ? children.at(-1)?.end ?? 0 : startTagLocation.endOffset;
37
37
  const elseTagLocation = sliceFragment(rawHtml, elseTagStartOffset, elseNode.start);
38
38
  elseTag = {
39
39
  uuid: uuid(),
@@ -113,7 +113,7 @@ nextNode, options) {
113
113
  const elseOrElseIfTags = [];
114
114
  if (originNode.else) {
115
115
  const elseNode = originNode.else;
116
- const elseTagStartOffset = children.length > 0 ? children[children.length - 1]?.end ?? 0 : startTagLocation.endOffset;
116
+ const elseTagStartOffset = children.length > 0 ? children.at(-1)?.end ?? 0 : startTagLocation.endOffset;
117
117
  const elseTagLocation = sliceFragment(rawHtml, elseTagStartOffset, elseNode.start);
118
118
  if (elseNode.children) {
119
119
  if (elseNode.children.length === 1 && elseNode.children[0]?.type === 'IfBlock') {
package/lib/parse.js CHANGED
@@ -18,24 +18,24 @@ export const parse = (rawCode, options) => {
18
18
  try {
19
19
  ast = svelteParse(blocks.replaced);
20
20
  }
21
- catch (err) {
22
- if (err instanceof Error && 'start' in err && 'end' in err && 'frame' in err) {
21
+ catch (error) {
22
+ if (error instanceof Error && 'start' in error && 'end' in error && 'frame' in error) {
23
23
  // @ts-ignore
24
- const raw = rawCode.slice(err.start.character, err.end.character);
24
+ const raw = rawCode.slice(error.start.character, error.end.character);
25
25
  throw new ParserError(
26
26
  // @ts-ignore
27
- err.message + '\n' + err.frame, {
27
+ error.message + '\n' + error.frame, {
28
28
  // @ts-ignore
29
- line: err.start.line,
29
+ line: error.start.line,
30
30
  // @ts-ignore
31
- col: err.start.column,
31
+ col: error.start.column,
32
32
  raw,
33
33
  });
34
34
  }
35
35
  return {
36
36
  nodeList: [],
37
37
  isFragment: true,
38
- parseError: err instanceof Error ? err.message : new Error(`${err}`).message,
38
+ parseError: error instanceof Error ? error.message : new Error(`${error}`).message,
39
39
  };
40
40
  }
41
41
  const nodes = traverse(ast, null, blocks.replaced, options);
package/lib/traverse.js CHANGED
@@ -11,7 +11,7 @@ astNodes, parentNode = null, rawHtml, options) {
11
11
  }
12
12
  let node;
13
13
  if (Array.isArray(nodes)) {
14
- const lastNode = nodes[nodes.length - 1];
14
+ const lastNode = nodes.at(-1);
15
15
  if (!lastNode) {
16
16
  continue;
17
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/svelte-parser",
3
- "version": "4.0.0-alpha.3",
3
+ "version": "4.0.0-dev.28+0131de5e",
4
4
  "description": "Svelte parser for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -21,11 +21,10 @@
21
21
  "clean": "tsc --build --clean"
22
22
  },
23
23
  "dependencies": {
24
- "@markuplint/html-parser": "4.0.0-alpha.3",
25
- "@markuplint/ml-ast": "4.0.0-alpha.3",
26
- "@markuplint/parser-utils": "4.0.0-alpha.3",
27
- "svelte": "^4.2.1",
28
- "tslib": "^2.6.2"
24
+ "@markuplint/html-parser": "4.0.0-dev.28+0131de5e",
25
+ "@markuplint/ml-ast": "4.0.0-dev.28+0131de5e",
26
+ "@markuplint/parser-utils": "4.0.0-dev.28+0131de5e",
27
+ "svelte": "^4.2.2"
29
28
  },
30
- "gitHead": "380836f7adc1ff7e8eaf9d869e68d29eee8f3b7e"
29
+ "gitHead": "0131de5ea9dd6d3fd5472d7b414b66644c758881"
31
30
  }