@swagger-api/apidom-parser-adapter-json 1.9.0 → 1.10.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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.10.0](https://github.com/swagger-api/apidom/compare/v1.9.0...v1.10.0) (2026-04-01)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **parser-adapter:** move tree lifecycle management to callers ([#5156](https://github.com/swagger-api/apidom/issues/5156)) ([30f173b](https://github.com/swagger-api/apidom/commit/30f173b6ac5a13c7f53e01440dde6ded222bd18a))
11
+
6
12
  # [1.9.0](https://github.com/swagger-api/apidom/compare/v1.8.0...v1.9.0) (2026-03-30)
7
13
 
8
14
  **Note:** Version bump only for package @swagger-api/apidom-parser-adapter-json
@@ -9005,7 +9005,8 @@
9005
9005
  };
9006
9006
  let parser = null;
9007
9007
  let parserInitLock = null;
9008
- let currentTree = null;
9008
+ const activeTrees = /* @__PURE__ */ new Set();
9009
+ const MAX_ACTIVE_TREES = 5;
9009
9010
  const analyze$2 = (source) => __async$1(null, null, function* () {
9010
9011
  if (parser === null && parserInitLock === null) {
9011
9012
  parserInitLock = Parser.init().then(() => Parser.Language.load(treeSitterJson)).then((jsonLanguage) => {
@@ -9023,9 +9024,22 @@
9023
9024
  "Error while initializing web-tree-sitter and loading tree-sitter-json grammar."
9024
9025
  );
9025
9026
  }
9026
- currentTree = parser.parse(source);
9027
+ if (activeTrees.size >= MAX_ACTIVE_TREES) {
9028
+ const treesToEvict = [...activeTrees];
9029
+ activeTrees.clear();
9030
+ for (const oldTree of treesToEvict) {
9031
+ oldTree.delete();
9032
+ }
9033
+ }
9034
+ const tree = parser.parse(source);
9035
+ activeTrees.add(tree);
9036
+ const originalDelete = tree.delete;
9037
+ tree.delete = function deleteAndUntrack() {
9038
+ activeTrees.delete(this);
9039
+ originalDelete.call(this);
9040
+ };
9027
9041
  parser.reset();
9028
- return currentTree;
9042
+ return tree;
9029
9043
  });
9030
9044
 
9031
9045
  /**
@@ -17396,25 +17410,32 @@
17396
17410
  if (!detectionRegExp.test(source)) {
17397
17411
  return false;
17398
17412
  }
17413
+ let cst = null;
17399
17414
  try {
17400
- const cst = yield analyze$2(source);
17415
+ cst = yield analyze$2(source);
17401
17416
  const isError = cst.rootNode.type !== "ERROR";
17402
- cst.delete();
17403
17417
  return isError;
17404
17418
  } catch (e) {
17405
17419
  return false;
17420
+ } finally {
17421
+ if (cst !== null) {
17422
+ cst.delete();
17423
+ }
17406
17424
  }
17407
17425
  });
17408
17426
  const parse = (_0, ..._1) => __async(null, [_0, ..._1], function* (source, { sourceMap = false, syntacticAnalysis = "direct" } = {}) {
17409
- const cst = yield analyze$2(source);
17410
- let apiDOM;
17411
- if (syntacticAnalysis === "indirect") {
17412
- apiDOM = analyze(cst, { sourceMap });
17413
- } else {
17414
- apiDOM = analyze$1(cst, { sourceMap });
17427
+ let cst = null;
17428
+ try {
17429
+ cst = yield analyze$2(source);
17430
+ if (syntacticAnalysis === "indirect") {
17431
+ return analyze(cst, { sourceMap });
17432
+ }
17433
+ return analyze$1(cst, { sourceMap });
17434
+ } finally {
17435
+ if (cst !== null) {
17436
+ cst.delete();
17437
+ }
17415
17438
  }
17416
- cst.delete();
17417
- return apiDOM;
17418
17439
  });
17419
17440
 
17420
17441
  exports.detect = detect;