@markuplint/svelte-parser 3.5.0 → 3.6.0

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.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { SvelteDirective } from './svelte-parser';
2
2
  import type { MLASTAttr } from '@markuplint/ml-ast';
3
- export declare function attr(attr: SvelteDirective, rawHTML: string): MLASTAttr | {
4
- __spreadAttr: true;
5
- };
3
+ export declare function attr(
4
+ attr: SvelteDirective,
5
+ rawHTML: string,
6
+ ):
7
+ | MLASTAttr
8
+ | {
9
+ __spreadAttr: true;
10
+ };
@@ -1,2 +1,8 @@
1
1
  import type { MLASTHTMLAttr } from '@markuplint/ml-ast';
2
- export default function directiveTokenizer(raw: string, rawValue: string, line: number, col: number, startOffset: number): MLASTHTMLAttr;
2
+ export default function directiveTokenizer(
3
+ raw: string,
4
+ rawValue: string,
5
+ line: number,
6
+ col: number,
7
+ startOffset: number,
8
+ ): MLASTHTMLAttr;
@@ -9,7 +9,7 @@ const reBeforeStructure = /^(\s*)([^\x00-\x1f\x7f-\x9f {>/=]+)(\s*)(=)(\s*){(\s*
9
9
  const reBeforeStructureWithoutName = /^{(\s*)$/;
10
10
  const reAfterStructure = /(\s*)}/;
11
11
  function directiveTokenizer(raw, rawValue, line, col, startOffset) {
12
- var _a, _b, _c, _d, _e;
12
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
13
13
  let spacesBeforeAttrString = '';
14
14
  let nameChars = '';
15
15
  let spacesBeforeEqualChars = '';
@@ -24,12 +24,12 @@ function directiveTokenizer(raw, rawValue, line, col, startOffset) {
24
24
  spacesBeforeAttrString = (_a = beforeMatchedMap[1]) !== null && _a !== void 0 ? _a : '';
25
25
  nameChars = (_b = beforeMatchedMap[2]) !== null && _b !== void 0 ? _b : '';
26
26
  spacesBeforeEqualChars = (_c = beforeMatchedMap[3]) !== null && _c !== void 0 ? _c : '';
27
- equalChars = beforeMatchedMap[4] || null;
28
- spacesAfterEqualChars = (_d = beforeMatchedMap[5]) !== null && _d !== void 0 ? _d : '';
29
- valueChars = ((_e = beforeMatchedMap[6]) !== null && _e !== void 0 ? _e : '') + rawValue + (afterMatchedMap[1] || '');
27
+ equalChars = (_d = beforeMatchedMap[4]) !== null && _d !== void 0 ? _d : null;
28
+ spacesAfterEqualChars = (_e = beforeMatchedMap[5]) !== null && _e !== void 0 ? _e : '';
29
+ valueChars = ((_f = beforeMatchedMap[6]) !== null && _f !== void 0 ? _f : '') + rawValue + ((_g = afterMatchedMap[1]) !== null && _g !== void 0 ? _g : '');
30
30
  }
31
31
  else if (beforeWithoutNameMatchedMap && afterMatchedMap) {
32
- valueChars = (beforeWithoutNameMatchedMap[1] || '') + rawValue + (afterMatchedMap[1] || '');
32
+ valueChars = ((_h = beforeWithoutNameMatchedMap[1]) !== null && _h !== void 0 ? _h : '') + rawValue + ((_j = afterMatchedMap[1]) !== null && _j !== void 0 ? _j : '');
33
33
  }
34
34
  else if (reNameOnly.test(raw)) {
35
35
  const token = (0, html_parser_1.attrTokenizer)(raw, line, col, startOffset);
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { parse } from './parse';
2
- export declare const endTag = "xml";
2
+ export declare const endTag = 'xml';
package/lib/nodeize.d.ts CHANGED
@@ -1,3 +1,9 @@
1
1
  import type { SvelteNode } from './svelte-parser';
2
2
  import type { MLASTNode, MLASTParentNode, ParserOptions } from '@markuplint/ml-ast';
3
- export declare function nodeize(originNode: SvelteNode, prevNode: MLASTNode | null, parentNode: MLASTParentNode | null, rawHtml: string, options?: ParserOptions): MLASTNode | MLASTNode[] | null;
3
+ export declare function nodeize(
4
+ originNode: SvelteNode,
5
+ prevNode: MLASTNode | null,
6
+ parentNode: MLASTParentNode | null,
7
+ rawHtml: string,
8
+ options?: ParserOptions,
9
+ ): MLASTNode | MLASTNode[] | null;
package/lib/nodeize.js CHANGED
@@ -13,7 +13,7 @@ originNode,
13
13
  prevNode,
14
14
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
15
15
  parentNode, rawHtml, options) {
16
- var _a, _b, _c, _d;
16
+ var _a, _b, _c, _d, _e, _f;
17
17
  const nextNode = null;
18
18
  const { startOffset, endOffset, startLine, endLine, startCol, endCol, raw } = (0, parser_utils_1.sliceFragment)(rawHtml, originNode.start, originNode.end);
19
19
  const parentNamespace = parentNode && 'namespace' in parentNode ? parentNode.namespace : 'http://www.w3.org/1999/xhtml';
@@ -58,11 +58,9 @@ parentNode, rawHtml, options) {
58
58
  };
59
59
  }
60
60
  case 'Element': {
61
- const children = originNode.children || [];
61
+ const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
62
62
  const reEndTag = new RegExp(`</${originNode.name}\\s*>$`, 'i');
63
- const startTagEndOffset = children.length
64
- ? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
65
- : raw.replace(reEndTag, '').length + startOffset;
63
+ const startTagEndOffset = children.length > 0 ? (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : 0 : raw.replace(reEndTag, '').length + startOffset;
66
64
  const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
67
65
  let endTag = null;
68
66
  if (reEndTag.test(raw)) {
@@ -98,7 +96,7 @@ parentNode, rawHtml, options) {
98
96
  tagCloseChar: '>',
99
97
  };
100
98
  }
101
- const directives = originNode.attributes.map(a => (0, attr_1.attr)(a, rawHtml)) || [];
99
+ const directives = (_d = originNode.attributes.map(a => (0, attr_1.attr)(a, rawHtml))) !== null && _d !== void 0 ? _d : [];
102
100
  const attributes = directives.filter((d) => !('__spreadAttr' in d));
103
101
  const hasSpreadAttr = directives.some(d => '__spreadAttr' in d);
104
102
  const tagTokens = (0, html_parser_1.parseRawTag)(startTagLocation.raw, startTagLocation.startLine, startTagLocation.startCol, startTagLocation.startOffset);
@@ -158,7 +156,7 @@ parentNode, rawHtml, options) {
158
156
  let then = null;
159
157
  if (originNode.then) {
160
158
  const thenNode = originNode.then;
161
- const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (_c = (thenNode.children && thenNode.children[0] && thenNode.children[0].start)) !== null && _c !== void 0 ? _c : thenNode.end);
159
+ const thenTag = (0, parser_utils_1.sliceFragment)(rawHtml, thenNode.start, (_e = (thenNode.children && thenNode.children[0] && thenNode.children[0].start)) !== null && _e !== void 0 ? _e : thenNode.end);
162
160
  then = {
163
161
  uuid: (0, parser_utils_1.uuid)(),
164
162
  ...thenTag,
@@ -177,7 +175,7 @@ parentNode, rawHtml, options) {
177
175
  let awaitCatch = null;
178
176
  if (originNode.catch) {
179
177
  const awaitCatchNode = originNode.catch;
180
- const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (_d = (awaitCatchNode.children && awaitCatchNode.children[0] && awaitCatchNode.children[0].start)) !== null && _d !== void 0 ? _d : awaitCatchNode.end);
178
+ const awaitCatchTag = (0, parser_utils_1.sliceFragment)(rawHtml, awaitCatchNode.start, (_f = (awaitCatchNode.children && awaitCatchNode.children[0] && awaitCatchNode.children[0].start)) !== null && _f !== void 0 ? _f : awaitCatchNode.end);
181
179
  awaitCatch = {
182
180
  uuid: (0, parser_utils_1.uuid)(),
183
181
  ...awaitCatchTag,
@@ -1,3 +1,13 @@
1
1
  import type { SvelteNode } from './svelte-parser';
2
2
  import type { MLASTNode, MLASTParentNode, MLASTPreprocessorSpecificBlock, ParserOptions } from '@markuplint/ml-ast';
3
- export declare function parseCtrlBlock(ctrlName: 'if' | 'each', originNode: SvelteNode, raw: string, rawHtml: string, startOffset: number, parentNode: MLASTParentNode | null, prevNode: MLASTNode | null, nextNode: MLASTNode | null, options?: ParserOptions): MLASTPreprocessorSpecificBlock[];
3
+ export declare function parseCtrlBlock(
4
+ ctrlName: 'if' | 'each',
5
+ originNode: SvelteNode,
6
+ raw: string,
7
+ rawHtml: string,
8
+ startOffset: number,
9
+ parentNode: MLASTParentNode | null,
10
+ prevNode: MLASTNode | null,
11
+ nextNode: MLASTNode | null,
12
+ options?: ParserOptions,
13
+ ): MLASTPreprocessorSpecificBlock[];
@@ -12,15 +12,13 @@ parentNode,
12
12
  prevNode,
13
13
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
14
14
  nextNode, options) {
15
- var _a, _b, _c, _d;
15
+ var _a, _b, _c, _d, _e;
16
16
  if (ctrlName === 'if') {
17
17
  return parseIfBlock(originNode, raw, rawHtml, startOffset, originNode.start, parentNode, prevNode, nextNode, options);
18
18
  }
19
- const children = originNode.children || [];
19
+ const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
20
20
  const reEndTag = new RegExp('{/each}$', 'i');
21
- const startTagEndOffset = children.length
22
- ? (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0
23
- : raw.replace(reEndTag, '').length + startOffset;
21
+ const startTagEndOffset = children.length > 0 ? (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : 0 : raw.replace(reEndTag, '').length + startOffset;
24
22
  const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, startOffset, startTagEndOffset);
25
23
  const tag = {
26
24
  uuid: (0, parser_utils_1.uuid)(),
@@ -39,9 +37,7 @@ nextNode, options) {
39
37
  let elseTag = null;
40
38
  if (originNode.else) {
41
39
  const elseNode = originNode.else;
42
- const elseTagStartOffset = children.length
43
- ? (_d = (_c = children[children.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0
44
- : startTagLocation.endOffset;
40
+ const elseTagStartOffset = children.length > 0 ? (_e = (_d = children[children.length - 1]) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : 0 : startTagLocation.endOffset;
45
41
  const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
46
42
  elseTag = {
47
43
  uuid: (0, parser_utils_1.uuid)(),
@@ -102,9 +98,9 @@ parentNode,
102
98
  prevNode,
103
99
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
104
100
  nextNode, options) {
105
- var _a, _b, _c, _d, _e, _f, _g, _h;
106
- const children = originNode.children || [];
107
- const startTagEndOffset = (_b = (_a = children[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : tokenStartOffset;
101
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
102
+ const children = (_a = originNode.children) !== null && _a !== void 0 ? _a : [];
103
+ const startTagEndOffset = (_c = (_b = children[0]) === null || _b === void 0 ? void 0 : _b.start) !== null && _c !== void 0 ? _c : tokenStartOffset;
108
104
  const startTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, tokenStartOffset, startTagEndOffset);
109
105
  const tag = {
110
106
  uuid: (0, parser_utils_1.uuid)(),
@@ -123,13 +119,11 @@ nextNode, options) {
123
119
  const elseOrElseIfTags = [];
124
120
  if (originNode.else) {
125
121
  const elseNode = originNode.else;
126
- const elseTagStartOffset = children.length
127
- ? (_d = (_c = children[children.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0
128
- : startTagLocation.endOffset;
122
+ const elseTagStartOffset = children.length > 0 ? (_e = (_d = children[children.length - 1]) === null || _d === void 0 ? void 0 : _d.end) !== null && _e !== void 0 ? _e : 0 : startTagLocation.endOffset;
129
123
  const elseTagLocation = (0, parser_utils_1.sliceFragment)(rawHtml, elseTagStartOffset, elseNode.start);
130
124
  if (elseNode.children) {
131
- if (elseNode.children.length === 1 && ((_e = elseNode.children[0]) === null || _e === void 0 ? void 0 : _e.type) === 'IfBlock') {
132
- const elseIfTags = parseIfBlock(elseNode.children[0], elseTagLocation.raw, rawHtml, statementStartOffset, (_h = (_g = (_f = originNode.children) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.end) !== null && _h !== void 0 ? _h : startTagLocation.endOffset, parentNode, null, null, options);
125
+ if (elseNode.children.length === 1 && ((_f = elseNode.children[0]) === null || _f === void 0 ? void 0 : _f.type) === 'IfBlock') {
126
+ const elseIfTags = parseIfBlock(elseNode.children[0], elseTagLocation.raw, rawHtml, statementStartOffset, (_j = (_h = (_g = originNode.children) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.end) !== null && _j !== void 0 ? _j : startTagLocation.endOffset, parentNode, null, null, options);
133
127
  elseOrElseIfTags.push(...elseIfTags);
134
128
  }
135
129
  else {
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const compiler_1 = require("svelte/compiler");
4
4
  function svelteParse(template) {
5
+ var _a;
5
6
  const ast = (0, compiler_1.parse)(template, { customElement: true });
6
7
  const start = ast.html.start;
7
- const children = ast.html.children || [];
8
+ const children = (_a = ast.html.children) !== null && _a !== void 0 ? _a : [];
8
9
  if (children[0] && children[0].end === start) {
9
10
  children.shift();
10
11
  }
package/lib/traverse.d.ts CHANGED
@@ -1,3 +1,8 @@
1
1
  import type { SvelteNode } from './svelte-parser';
2
2
  import type { MLASTNode, MLASTParentNode, ParserOptions } from '@markuplint/ml-ast';
3
- export declare function traverse(astNodes: readonly SvelteNode[], parentNode: MLASTParentNode | null | undefined, rawHtml: string, options?: ParserOptions): MLASTNode[];
3
+ export declare function traverse(
4
+ astNodes: readonly SvelteNode[],
5
+ parentNode: MLASTParentNode | null | undefined,
6
+ rawHtml: string,
7
+ options?: ParserOptions,
8
+ ): MLASTNode[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/svelte-parser",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "Svelte parser for markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -16,11 +16,11 @@
16
16
  "clean": "tsc --build --clean"
17
17
  },
18
18
  "dependencies": {
19
- "@markuplint/html-parser": "3.5.0",
19
+ "@markuplint/html-parser": "3.6.0",
20
20
  "@markuplint/ml-ast": "3.1.0",
21
- "@markuplint/parser-utils": "3.5.0",
21
+ "@markuplint/parser-utils": "3.6.0",
22
22
  "svelte": "^3.57.0",
23
23
  "tslib": "^2.4.1"
24
24
  },
25
- "gitHead": "0c47b2c2722f6823a17f36edbab98486275f8ab4"
25
+ "gitHead": "715dd53d3b1064a9bcf616c1533921cad9e3b187"
26
26
  }