@cdk8s/awscdk-resolver 0.0.609 → 0.0.611

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.
Files changed (145) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +3 -3
  4. package/node_modules/@aws-sdk/core/package.json +2 -2
  5. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  6. package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
  7. package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
  8. package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
  9. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  10. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  11. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  12. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  13. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  14. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  15. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  16. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  17. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  18. package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
  19. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  20. package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-parser.browser.js +1 -1
  21. package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-parser.js +233 -43
  22. package/node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.browser.js +1 -1
  23. package/node_modules/@aws-sdk/xml-builder/dist-es/xml-parser.js +233 -43
  24. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/xml-parser.d.ts +1 -1
  25. package/node_modules/@aws-sdk/xml-builder/dist-types/xml-parser.d.ts +2 -1
  26. package/node_modules/@aws-sdk/xml-builder/package.json +4 -4
  27. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +518 -371
  28. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +1 -1
  29. package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-decode.js +326 -269
  30. package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-encode.js +192 -103
  31. package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor.js +4 -2
  32. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/get-value-from-text-node.js +1 -1
  33. package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor-decode.d.ts +4 -0
  34. package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor-encode.d.ts +8 -4
  35. package/node_modules/@smithy/core/package.json +1 -1
  36. package/node_modules/@smithy/credential-provider-imds/package.json +2 -2
  37. package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
  38. package/node_modules/@smithy/node-http-handler/package.json +2 -2
  39. package/node_modules/@smithy/signature-v4/package.json +2 -2
  40. package/package.json +9 -9
  41. package/node_modules/@aws-sdk/xml-builder/dist-cjs/xml-external/nodable_entities.js +0 -333
  42. package/node_modules/@aws-sdk/xml-builder/dist-es/xml-external/nodable_entities.js +0 -332
  43. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/xml-external/nodable_entities.d.ts +0 -66
  44. package/node_modules/@aws-sdk/xml-builder/dist-types/xml-external/nodable_entities.d.ts +0 -65
  45. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/CHANGELOG.md +0 -827
  46. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/LICENSE +0 -21
  47. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/README.md +0 -202
  48. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxbuilder.min.js +0 -2
  49. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxbuilder.min.js.map +0 -1
  50. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.cjs +0 -1
  51. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.d.cts +0 -770
  52. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.min.js +0 -2
  53. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxp.min.js.map +0 -1
  54. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxparser.min.js +0 -2
  55. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxparser.min.js.map +0 -1
  56. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxvalidator.min.js +0 -2
  57. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/lib/fxvalidator.min.js.map +0 -1
  58. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/package.json +0 -93
  59. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/cli/cli.js +0 -97
  60. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/cli/man.js +0 -17
  61. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/cli/read.js +0 -43
  62. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/fxp.d.ts +0 -739
  63. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/fxp.js +0 -14
  64. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/ignoreAttributes.js +0 -18
  65. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/util.js +0 -61
  66. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/CharsSymbol.js +0 -16
  67. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/EntitiesParser.js +0 -106
  68. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OptionsBuilder.js +0 -61
  69. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/BaseOutputBuilder.js +0 -69
  70. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsArrBuilder.js +0 -103
  71. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsMinArrBuilder.js +0 -100
  72. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/JsObjBuilder.js +0 -154
  73. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/OutputBuilders/ParserOptionsBuilder.js +0 -94
  74. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/Report.js +0 -0
  75. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/TagPath.js +0 -81
  76. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/TagPathMatcher.js +0 -13
  77. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/XMLParser.js +0 -83
  78. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/Xml2JsParser.js +0 -235
  79. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/XmlPartReader.js +0 -210
  80. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/XmlSpecialTagsReader.js +0 -111
  81. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/inputSource/BufferSource.js +0 -116
  82. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/inputSource/StringSource.js +0 -121
  83. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/EntitiesParser.js +0 -105
  84. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParser.js +0 -22
  85. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/booleanParserExt.js +0 -19
  86. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/currency.js +0 -38
  87. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/join.js +0 -13
  88. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/number.js +0 -14
  89. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/v6/valueParsers/trim.js +0 -6
  90. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/validator.js +0 -425
  91. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlbuilder/json2xml.js +0 -6
  92. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +0 -407
  93. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/OptionsBuilder.js +0 -163
  94. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js +0 -840
  95. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/XMLParser.js +0 -71
  96. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/node2json.js +0 -177
  97. package/node_modules/@aws-sdk/xml-builder/node_modules/fast-xml-parser/src/xmlparser/xmlNode.js +0 -40
  98. package/node_modules/@nodable/entities/README.md +0 -41
  99. package/node_modules/@nodable/entities/package.json +0 -57
  100. package/node_modules/@nodable/entities/src/EntityDecoder.js +0 -644
  101. package/node_modules/@nodable/entities/src/EntityEncoder.js +0 -194
  102. package/node_modules/@nodable/entities/src/entities.js +0 -1159
  103. package/node_modules/@nodable/entities/src/entityTries.js +0 -49
  104. package/node_modules/@nodable/entities/src/index.d.ts +0 -341
  105. package/node_modules/@nodable/entities/src/index.js +0 -29
  106. package/node_modules/anynum/LICENSE +0 -21
  107. package/node_modules/anynum/README.md +0 -142
  108. package/node_modules/anynum/anynum.js +0 -135
  109. package/node_modules/anynum/digitTable.js +0 -116
  110. package/node_modules/anynum/package.json +0 -42
  111. package/node_modules/fast-xml-builder/CHANGELOG.md +0 -40
  112. package/node_modules/fast-xml-builder/LICENSE +0 -21
  113. package/node_modules/fast-xml-builder/README.md +0 -74
  114. package/node_modules/fast-xml-builder/lib/fxb.cjs +0 -1
  115. package/node_modules/fast-xml-builder/lib/fxb.d.cts +0 -270
  116. package/node_modules/fast-xml-builder/lib/fxb.min.js +0 -2
  117. package/node_modules/fast-xml-builder/lib/fxb.min.js.map +0 -1
  118. package/node_modules/fast-xml-builder/package.json +0 -81
  119. package/node_modules/fast-xml-builder/src/fxb.d.ts +0 -270
  120. package/node_modules/fast-xml-builder/src/fxb.js +0 -599
  121. package/node_modules/fast-xml-builder/src/ignoreAttributes.js +0 -18
  122. package/node_modules/fast-xml-builder/src/orderedJs2Xml.js +0 -359
  123. package/node_modules/fast-xml-builder/src/prettifyJs2Xml.js +0 -0
  124. package/node_modules/fast-xml-builder/src/util.js +0 -16
  125. package/node_modules/path-expression-matcher/LICENSE +0 -21
  126. package/node_modules/path-expression-matcher/README.md +0 -947
  127. package/node_modules/path-expression-matcher/lib/pem.cjs +0 -1
  128. package/node_modules/path-expression-matcher/lib/pem.d.cts +0 -715
  129. package/node_modules/path-expression-matcher/lib/pem.min.js +0 -2
  130. package/node_modules/path-expression-matcher/lib/pem.min.js.map +0 -1
  131. package/node_modules/path-expression-matcher/package.json +0 -79
  132. package/node_modules/path-expression-matcher/src/Expression.js +0 -232
  133. package/node_modules/path-expression-matcher/src/ExpressionSet.js +0 -225
  134. package/node_modules/path-expression-matcher/src/Matcher.js +0 -660
  135. package/node_modules/path-expression-matcher/src/index.d.ts +0 -589
  136. package/node_modules/path-expression-matcher/src/index.js +0 -29
  137. package/node_modules/strnum/CHANGELOG.md +0 -51
  138. package/node_modules/strnum/LICENSE +0 -21
  139. package/node_modules/strnum/README.md +0 -113
  140. package/node_modules/strnum/package.json +0 -36
  141. package/node_modules/strnum/strnum.js +0 -171
  142. package/node_modules/xml-naming/README.md +0 -189
  143. package/node_modules/xml-naming/package.json +0 -54
  144. package/node_modules/xml-naming/src/index.d.ts +0 -74
  145. package/node_modules/xml-naming/src/index.js +0 -270
@@ -1,660 +0,0 @@
1
- import ExpressionSet from "./ExpressionSet.js";
2
-
3
- /**
4
- * MatcherView - A lightweight read-only view over a Matcher's internal state.
5
- *
6
- * Created once by Matcher and reused across all callbacks. Holds a direct
7
- * reference to the parent Matcher so it always reflects current parser state
8
- * with zero copying or freezing overhead.
9
- *
10
- * Users receive this via {@link Matcher#readOnly} or directly from parser
11
- * callbacks. It exposes all query and matching methods but has no mutation
12
- * methods — misuse is caught at the TypeScript level rather than at runtime.
13
- *
14
- * @example
15
- * const matcher = new Matcher();
16
- * const view = matcher.readOnly();
17
- *
18
- * matcher.push("root", {});
19
- * view.getCurrentTag(); // "root"
20
- * view.getDepth(); // 1
21
- */
22
- export class MatcherView {
23
- /**
24
- * @param {Matcher} matcher - The parent Matcher instance to read from.
25
- */
26
- constructor(matcher) {
27
- this._matcher = matcher;
28
- }
29
-
30
- /**
31
- * Get the path separator used by the parent matcher.
32
- * @returns {string}
33
- */
34
- get separator() {
35
- return this._matcher.separator;
36
- }
37
-
38
- /**
39
- * Get current tag name.
40
- * @returns {string|undefined}
41
- */
42
- getCurrentTag() {
43
- const path = this._matcher.path;
44
- return path.length > 0 ? path[path.length - 1].tag : undefined;
45
- }
46
-
47
- /**
48
- * Get current namespace.
49
- * @returns {string|undefined}
50
- */
51
- getCurrentNamespace() {
52
- const path = this._matcher.path;
53
- return path.length > 0 ? path[path.length - 1].namespace : undefined;
54
- }
55
-
56
- /**
57
- * Get current node's attribute value.
58
- * @param {string} attrName
59
- * @returns {*}
60
- */
61
- getAttrValue(attrName) {
62
- const path = this._matcher.path;
63
- if (path.length === 0) return undefined;
64
- return path[path.length - 1].values?.[attrName];
65
- }
66
-
67
- /**
68
- * Check if current node has an attribute.
69
- * @param {string} attrName
70
- * @returns {boolean}
71
- */
72
- hasAttr(attrName) {
73
- const path = this._matcher.path;
74
- if (path.length === 0) return false;
75
- const current = path[path.length - 1];
76
- return current.values !== undefined && attrName in current.values;
77
- }
78
-
79
- /**
80
- * Get the value of a "kept" attribute from the nearest ancestor (or
81
- * current node) that declared it via `push(tag, attrs, ns, { keep: [...] })`.
82
- * @param {string} attrName
83
- * @returns {*}
84
- */
85
- getAnyParentAttr(attrName) {
86
- return this._matcher.getAnyParentAttr(attrName);
87
- }
88
-
89
- /**
90
- * Check whether any ancestor (or the current node) kept the given
91
- * attribute via `push(tag, attrs, ns, { keep: [...] })`.
92
- * @param {string} attrName
93
- * @returns {boolean}
94
- */
95
- hasAnyParentAttr(attrName) {
96
- return this._matcher.hasAnyParentAttr(attrName);
97
- }
98
-
99
- /**
100
- * Get current node's sibling position (child index in parent).
101
- * @returns {number}
102
- */
103
- getPosition() {
104
- const path = this._matcher.path;
105
- if (path.length === 0) return -1;
106
- return path[path.length - 1].position ?? 0;
107
- }
108
-
109
- /**
110
- * Get current node's repeat counter (occurrence count of this tag name).
111
- * @returns {number}
112
- */
113
- getCounter() {
114
- const path = this._matcher.path;
115
- if (path.length === 0) return -1;
116
- return path[path.length - 1].counter ?? 0;
117
- }
118
-
119
- /**
120
- * Get current node's sibling index (alias for getPosition).
121
- * @returns {number}
122
- * @deprecated Use getPosition() or getCounter() instead
123
- */
124
- getIndex() {
125
- return this.getPosition();
126
- }
127
-
128
- /**
129
- * Get current path depth.
130
- * @returns {number}
131
- */
132
- getDepth() {
133
- return this._matcher.path.length;
134
- }
135
-
136
- /**
137
- * Get path as string.
138
- * @param {string} [separator] - Optional separator (uses default if not provided)
139
- * @param {boolean} [includeNamespace=true]
140
- * @returns {string}
141
- */
142
- toString(separator, includeNamespace = true) {
143
- return this._matcher.toString(separator, includeNamespace);
144
- }
145
-
146
- /**
147
- * Get path as array of tag names.
148
- * @returns {string[]}
149
- */
150
- toArray() {
151
- return this._matcher.path.map(n => n.tag);
152
- }
153
-
154
- /**
155
- * Match current path against an Expression.
156
- * @param {Expression} expression
157
- * @returns {boolean}
158
- */
159
- matches(expression) {
160
- return this._matcher.matches(expression);
161
- }
162
-
163
- /**
164
- * Match any expression in the given set against the current path.
165
- * @param {ExpressionSet} exprSet
166
- * @returns {boolean}
167
- */
168
- matchesAny(exprSet) {
169
- return exprSet.matchesAny(this._matcher);
170
- }
171
- }
172
-
173
- /**
174
- * Matcher - Tracks current path in XML/JSON tree and matches against Expressions.
175
- *
176
- * The matcher maintains a stack of nodes representing the current path from root to
177
- * current tag. It only stores attribute values for the current (top) node to minimize
178
- * memory usage. Sibling tracking is used to auto-calculate position and counter.
179
- *
180
- * Use {@link Matcher#readOnly} to obtain a {@link MatcherView} safe to pass to
181
- * user callbacks — it always reflects current state with no Proxy overhead.
182
- *
183
- * @example
184
- * const matcher = new Matcher();
185
- * matcher.push("root", {});
186
- * matcher.push("users", {});
187
- * matcher.push("user", { id: "123", type: "admin" });
188
- *
189
- * const expr = new Expression("root.users.user");
190
- * matcher.matches(expr); // true
191
- */
192
- export default class Matcher {
193
- /**
194
- * Create a new Matcher.
195
- * @param {Object} [options={}]
196
- * @param {string} [options.separator='.'] - Default path separator
197
- */
198
- constructor(options = {}) {
199
- this.separator = options.separator || '.';
200
- this.path = [];
201
- this.siblingStacks = [];
202
- // Each path node: { tag, values, position, counter, namespace? }
203
- // values only present for current (last) node
204
- // Each siblingStacks entry: Map<tagName, count> tracking occurrences at each level
205
- this._pathStringCache = null;
206
- this._view = new MatcherView(this);
207
-
208
- // Kept-attribute stack: only populated when push() is called with options.keep.
209
- this._keptAttrs = [];
210
- }
211
-
212
- /**
213
- * Push a new tag onto the path.
214
- * @param {string} tagName
215
- * @param {Object|null} [attrValues=null]
216
- * @param {string|null} [namespace=null]
217
- * @param {Object|null} [options=null]
218
- * @param {string[]} [options.keep] - Names of attributes (from attrValues)
219
- */
220
- push(tagName, attrValues = null, namespace = null, options = null) {
221
- this._pathStringCache = null;
222
-
223
- // Remove values from previous current node (now becoming ancestor)
224
- if (this.path.length > 0) {
225
- this.path[this.path.length - 1].values = undefined;
226
- }
227
-
228
- // Get or create sibling tracking for current level
229
- const currentLevel = this.path.length;
230
- if (!this.siblingStacks[currentLevel]) {
231
- this.siblingStacks[currentLevel] = new Map();
232
- }
233
-
234
- const siblings = this.siblingStacks[currentLevel];
235
-
236
- // Create a unique key for sibling tracking that includes namespace
237
- const siblingKey = namespace ? `${namespace}:${tagName}` : tagName;
238
-
239
- // Calculate counter (how many times this tag appeared at this level)
240
- const counter = siblings.get(siblingKey) || 0;
241
-
242
- // Calculate position (total children at this level so far)
243
- let position = 0;
244
- for (const count of siblings.values()) {
245
- position += count;
246
- }
247
-
248
- // Update sibling count for this tag
249
- siblings.set(siblingKey, counter + 1);
250
-
251
- // Create new node
252
- const node = {
253
- tag: tagName,
254
- position: position,
255
- counter: counter
256
- };
257
-
258
- if (namespace !== null && namespace !== undefined) {
259
- node.namespace = namespace;
260
- }
261
-
262
- if (attrValues !== null && attrValues !== undefined) {
263
- node.values = attrValues;
264
- }
265
-
266
- this.path.push(node);
267
-
268
- // Depth of the node we just pushed (1-based, matches this.path.length)
269
- const depth = this.path.length;
270
-
271
- // Copy only the requested attributes into the kept-attrs stack. This is
272
- // the one part of push() whose cost scales with input (O(keep.length))
273
- // rather than being O(1) — by design, since the caller is explicitly
274
- // opting in for specific attribute names. No options/keep => zero added
275
- // cost beyond the two property reads below.
276
- const keep = options !== null ? options.keep : null;
277
- if (keep !== null && keep !== undefined && keep.length > 0 && attrValues) {
278
- for (let i = 0; i < keep.length; i++) {
279
- const name = keep[i];
280
- if (attrValues[name] !== undefined) {
281
- this._keptAttrs.push({ depth, name, value: attrValues[name] });
282
- }
283
- }
284
- }
285
- }
286
-
287
- /**
288
- * Pop the last tag from the path.
289
- * @returns {Object|undefined} The popped node
290
- */
291
- pop() {
292
- if (this.path.length === 0) return undefined;
293
- this._pathStringCache = null;
294
-
295
- const node = this.path.pop();
296
-
297
- if (this.siblingStacks.length > this.path.length + 1) {
298
- this.siblingStacks.length = this.path.length + 1;
299
- }
300
-
301
- // Drop any kept attributes that belonged to the popped node (or deeper).
302
- // _keptAttrs is depth-ordered (push only ever appends increasing depths),
303
- // so this is a backward scan that stops at the first surviving entry —
304
- // typically O(1) since kept attrs are rare by design.
305
- const poppedDepth = this.path.length + 1;
306
- while (
307
- this._keptAttrs.length > 0 &&
308
- this._keptAttrs[this._keptAttrs.length - 1].depth >= poppedDepth
309
- ) {
310
- this._keptAttrs.pop();
311
- }
312
-
313
- return node;
314
- }
315
-
316
- /**
317
- * Update current node's attribute values.
318
- * Useful when attributes are parsed after push.
319
- * @param {Object} attrValues
320
- */
321
- updateCurrent(attrValues) {
322
- if (this.path.length > 0) {
323
- const current = this.path[this.path.length - 1];
324
- if (attrValues !== null && attrValues !== undefined) {
325
- current.values = attrValues;
326
- }
327
- }
328
- }
329
-
330
- /**
331
- * Get current tag name.
332
- * @returns {string|undefined}
333
- */
334
- getCurrentTag() {
335
- return this.path.length > 0 ? this.path[this.path.length - 1].tag : undefined;
336
- }
337
-
338
- /**
339
- * Get current namespace.
340
- * @returns {string|undefined}
341
- */
342
- getCurrentNamespace() {
343
- return this.path.length > 0 ? this.path[this.path.length - 1].namespace : undefined;
344
- }
345
-
346
- /**
347
- * Get current node's attribute value.
348
- * @param {string} attrName
349
- * @returns {*}
350
- */
351
- getAttrValue(attrName) {
352
- if (this.path.length === 0) return undefined;
353
- return this.path[this.path.length - 1].values?.[attrName];
354
- }
355
-
356
- /**
357
- * Check if current node has an attribute.
358
- * @param {string} attrName
359
- * @returns {boolean}
360
- */
361
- hasAttr(attrName) {
362
- if (this.path.length === 0) return false;
363
- const current = this.path[this.path.length - 1];
364
- return current.values !== undefined && attrName in current.values;
365
- }
366
-
367
- /**
368
- * Get the value of a "kept" attribute from the nearest ancestor (or
369
- * current node) that declared it via `push(tag, attrs, ns, { keep: [...] })`.
370
- * Unlike getAttrValue(), this works regardless of how deep the path has
371
- * gone since the attribute was pushed — but only for attribute names that
372
- * were explicitly marked with `keep` at push time. Cost is proportional to
373
- * the number of currently-kept attributes (typically 0-3), not path depth.
374
- * @param {string} attrName
375
- * @returns {*} the value, or undefined if no ancestor kept this attribute
376
- */
377
- getAnyParentAttr(attrName) {
378
- const kept = this._keptAttrs;
379
- for (let i = kept.length - 1; i >= 0; i--) {
380
- if (kept[i].name === attrName) return kept[i].value;
381
- }
382
- return undefined;
383
- }
384
-
385
- /**
386
- * Check whether any ancestor (or the current node) kept the given
387
- * attribute via `push(tag, attrs, ns, { keep: [...] })`.
388
- * @param {string} attrName
389
- * @returns {boolean}
390
- */
391
- hasAnyParentAttr(attrName) {
392
- const kept = this._keptAttrs;
393
- for (let i = kept.length - 1; i >= 0; i--) {
394
- if (kept[i].name === attrName) return true;
395
- }
396
- return false;
397
- }
398
-
399
- /**
400
- * Get current node's sibling position (child index in parent).
401
- * @returns {number}
402
- */
403
- getPosition() {
404
- if (this.path.length === 0) return -1;
405
- return this.path[this.path.length - 1].position ?? 0;
406
- }
407
-
408
- /**
409
- * Get current node's repeat counter (occurrence count of this tag name).
410
- * @returns {number}
411
- */
412
- getCounter() {
413
- if (this.path.length === 0) return -1;
414
- return this.path[this.path.length - 1].counter ?? 0;
415
- }
416
-
417
- /**
418
- * Get current node's sibling index (alias for getPosition).
419
- * @returns {number}
420
- * @deprecated Use getPosition() or getCounter() instead
421
- */
422
- getIndex() {
423
- return this.getPosition();
424
- }
425
-
426
- /**
427
- * Get current path depth.
428
- * @returns {number}
429
- */
430
- getDepth() {
431
- return this.path.length;
432
- }
433
-
434
- /**
435
- * Get path as string.
436
- * @param {string} [separator] - Optional separator (uses default if not provided)
437
- * @param {boolean} [includeNamespace=true]
438
- * @returns {string}
439
- */
440
- toString(separator, includeNamespace = true) {
441
- const sep = separator || this.separator;
442
- const isDefault = (sep === this.separator && includeNamespace === true);
443
-
444
- if (isDefault) {
445
- if (this._pathStringCache !== null) {
446
- return this._pathStringCache;
447
- }
448
- const result = this.path.map(n =>
449
- (n.namespace) ? `${n.namespace}:${n.tag}` : n.tag
450
- ).join(sep);
451
- this._pathStringCache = result;
452
- return result;
453
- }
454
-
455
- return this.path.map(n =>
456
- (includeNamespace && n.namespace) ? `${n.namespace}:${n.tag}` : n.tag
457
- ).join(sep);
458
- }
459
-
460
- /**
461
- * Get path as array of tag names.
462
- * @returns {string[]}
463
- */
464
- toArray() {
465
- return this.path.map(n => n.tag);
466
- }
467
-
468
- /**
469
- * Reset the path to empty.
470
- */
471
- reset() {
472
- this._pathStringCache = null;
473
- this.path = [];
474
- this.siblingStacks = [];
475
- this._keptAttrs = [];
476
- }
477
-
478
- /**
479
- * Match current path against an Expression.
480
- * @param {Expression} expression
481
- * @returns {boolean}
482
- */
483
- matches(expression) {
484
- const segments = expression.segments;
485
-
486
- if (segments.length === 0) {
487
- return false;
488
- }
489
-
490
- if (expression.hasDeepWildcard()) {
491
- return this._matchWithDeepWildcard(segments);
492
- }
493
-
494
- return this._matchSimple(segments);
495
- }
496
-
497
- /**
498
- * @private
499
- */
500
- _matchSimple(segments) {
501
- if (this.path.length !== segments.length) {
502
- return false;
503
- }
504
-
505
- for (let i = 0; i < segments.length; i++) {
506
- if (!this._matchSegment(segments[i], this.path[i], i === this.path.length - 1)) {
507
- return false;
508
- }
509
- }
510
-
511
- return true;
512
- }
513
-
514
- /**
515
- * @private
516
- */
517
- _matchWithDeepWildcard(segments) {
518
- let pathIdx = this.path.length - 1;
519
- let segIdx = segments.length - 1;
520
-
521
- while (segIdx >= 0 && pathIdx >= 0) {
522
- const segment = segments[segIdx];
523
-
524
- if (segment.type === 'deep-wildcard') {
525
- segIdx--;
526
-
527
- if (segIdx < 0) {
528
- return true;
529
- }
530
-
531
- const nextSeg = segments[segIdx];
532
- let found = false;
533
-
534
- for (let i = pathIdx; i >= 0; i--) {
535
- if (this._matchSegment(nextSeg, this.path[i], i === this.path.length - 1)) {
536
- pathIdx = i - 1;
537
- segIdx--;
538
- found = true;
539
- break;
540
- }
541
- }
542
-
543
- if (!found) {
544
- return false;
545
- }
546
- } else {
547
- if (!this._matchSegment(segment, this.path[pathIdx], pathIdx === this.path.length - 1)) {
548
- return false;
549
- }
550
- pathIdx--;
551
- segIdx--;
552
- }
553
- }
554
-
555
- return segIdx < 0;
556
- }
557
-
558
- /**
559
- * @private
560
- */
561
- _matchSegment(segment, node, isCurrentNode) {
562
- if (segment.tag !== '*' && segment.tag !== node.tag) {
563
- return false;
564
- }
565
-
566
- if (segment.namespace !== undefined) {
567
- if (segment.namespace !== '*' && segment.namespace !== node.namespace) {
568
- return false;
569
- }
570
- }
571
-
572
- if (segment.attrName !== undefined) {
573
- if (!isCurrentNode) {
574
- return false;
575
- }
576
-
577
- if (!node.values || !(segment.attrName in node.values)) {
578
- return false;
579
- }
580
-
581
- if (segment.attrValue !== undefined) {
582
- if (String(node.values[segment.attrName]) !== String(segment.attrValue)) {
583
- return false;
584
- }
585
- }
586
- }
587
-
588
- if (segment.position !== undefined) {
589
- if (!isCurrentNode) {
590
- return false;
591
- }
592
-
593
- const counter = node.counter ?? 0;
594
-
595
- if (segment.position === 'first' && counter !== 0) {
596
- return false;
597
- } else if (segment.position === 'odd' && counter % 2 !== 1) {
598
- return false;
599
- } else if (segment.position === 'even' && counter % 2 !== 0) {
600
- return false;
601
- } else if (segment.position === 'nth' && counter !== segment.positionValue) {
602
- return false;
603
- }
604
- }
605
-
606
- return true;
607
- }
608
-
609
- /**
610
- * Match any expression in the given set against the current path.
611
- * @param {ExpressionSet} exprSet
612
- * @returns {boolean}
613
- */
614
- matchesAny(exprSet) {
615
- return exprSet.matchesAny(this);
616
- }
617
-
618
- /**
619
- * Create a snapshot of current state.
620
- * @returns {Object}
621
- */
622
- snapshot() {
623
- return {
624
- path: this.path.map(node => ({ ...node })),
625
- siblingStacks: this.siblingStacks.map(map => new Map(map)),
626
- keptAttrs: this._keptAttrs.map(entry => ({ ...entry }))
627
- };
628
- }
629
-
630
- /**
631
- * Restore state from snapshot.
632
- * @param {Object} snapshot
633
- */
634
- restore(snapshot) {
635
- this._pathStringCache = null;
636
- this.path = snapshot.path.map(node => ({ ...node }));
637
- this.siblingStacks = snapshot.siblingStacks.map(map => new Map(map));
638
- this._keptAttrs = (snapshot.keptAttrs || []).map(entry => ({ ...entry }));
639
- }
640
-
641
- /**
642
- * Return the read-only {@link MatcherView} for this matcher.
643
- *
644
- * The same instance is returned on every call — no allocation occurs.
645
- * It always reflects the current parser state and is safe to pass to
646
- * user callbacks without risk of accidental mutation.
647
- *
648
- * @returns {MatcherView}
649
- *
650
- * @example
651
- * const view = matcher.readOnly();
652
- * // pass view to callbacks — it stays in sync automatically
653
- * view.matches(expr); // ✓
654
- * view.getCurrentTag(); // ✓
655
- * // view.push(...) // ✗ method does not exist — caught by TypeScript
656
- */
657
- readOnly() {
658
- return this._view;
659
- }
660
- }