@markuplint/parser-utils 4.1.1 → 4.2.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/parser.js CHANGED
@@ -1082,6 +1082,7 @@ _Parser_booleanish = new WeakMap(), _Parser_defaultState = new WeakMap(), _Parse
1082
1082
  ? // TODO: Use sort instead of toSorted until we end support for Node 18
1083
1083
  [...nodes].sort(sortNodes)
1084
1084
  : nodes.toSorted(sortNodes);
1085
+ const nameToLastOpenTag = {};
1085
1086
  for (const node of oldNodes) {
1086
1087
  const id = `${node.startOffset}::${node.nodeName}`;
1087
1088
  if (stack.has(id)) {
@@ -1089,13 +1090,16 @@ _Parser_booleanish = new WeakMap(), _Parser_defaultState = new WeakMap(), _Parse
1089
1090
  }
1090
1091
  stack.add(id);
1091
1092
  if (node.type === 'endtag') {
1092
- const openTag = newNodes.findLast((n) => n.type === 'starttag' && n.nodeName === node.nodeName);
1093
+ const openTag = nameToLastOpenTag[node.nodeName];
1093
1094
  if (openTag && !openTag.pairNode) {
1094
1095
  __classPrivateFieldGet(this, _Parser_instances, "m", _Parser_pairing).call(this, openTag, node, false);
1095
1096
  newNodes.push(node);
1096
1097
  continue;
1097
1098
  }
1098
1099
  }
1100
+ else if (node.type === 'starttag') {
1101
+ nameToLastOpenTag[node.nodeName] = node;
1102
+ }
1099
1103
  newNodes.push(node);
1100
1104
  }
1101
1105
  return newNodes;
@@ -1,2 +1,2 @@
1
1
  import type { MLASTNodeTreeItem } from '@markuplint/ml-ast';
2
- export declare function sortNodes(a: MLASTNodeTreeItem, b: MLASTNodeTreeItem): 1 | -1 | 0;
2
+ export declare function sortNodes(a: MLASTNodeTreeItem, b: MLASTNodeTreeItem): number;
package/lib/sort-nodes.js CHANGED
@@ -1,18 +1,13 @@
1
1
  export function sortNodes(a, b) {
2
2
  if (a.startOffset === b.startOffset) {
3
- return sort(a, b, 'endOffset');
3
+ return sort(a.endOffset, b.endOffset);
4
4
  }
5
- return sort(a, b, 'startOffset');
5
+ return sort(a.startOffset, b.startOffset);
6
6
  }
7
- function sort(a, b, key) {
8
- if (Number.isNaN(a[key]) || Number.isNaN(b[key])) {
7
+ function sort(a, b) {
8
+ const diff = a - b;
9
+ if (Number.isNaN(diff)) {
9
10
  return 0;
10
11
  }
11
- if (a[key] < b[key]) {
12
- return -1;
13
- }
14
- if (a[key] > b[key]) {
15
- return 1;
16
- }
17
- return 0;
12
+ return diff;
18
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/parser-utils",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
4
4
  "description": "Utility module for markuplint parser plugin",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@markuplint/ml-ast": "4.0.1",
31
- "@markuplint/ml-spec": "4.0.2",
31
+ "@markuplint/ml-spec": "4.1.0",
32
32
  "@markuplint/types": "4.0.2",
33
33
  "@types/uuid": "^9.0.8",
34
34
  "debug": "^4.3.4",
@@ -36,5 +36,5 @@
36
36
  "type-fest": "^4.10.2",
37
37
  "uuid": "^9.0.1"
38
38
  },
39
- "gitHead": "10ce6c8374106f311eeaaffbae8f3fdcbb40f877"
39
+ "gitHead": "d5d99c5d84b676f8b2bb84684533ed74cf2f1da6"
40
40
  }