@bamboocss/parser 1.54.1 → 1.55.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/dist/index.cjs CHANGED
@@ -983,6 +983,7 @@ var ParserResult = class {
983
983
  /** The call site of `result`, when the encoder is recording them. */
984
984
  originOf = (result) => {
985
985
  if (!this.origins || !this.encoder.recordOrigins) return void 0;
986
+ if (result.atomOrigin) return result.atomOrigin;
986
987
  const node = result.box?.getNode();
987
988
  const sourceFile = node?.getSourceFile();
988
989
  if (!node || !sourceFile) return void 0;
@@ -1749,6 +1750,8 @@ var Project = class {
1749
1750
  * files.
1750
1751
  */
1751
1752
  auxiliarySources = /* @__PURE__ */ new Set();
1753
+ /** Bytes explicitly supplied by a caller rather than read from disk. */
1754
+ overriddenSources = /* @__PURE__ */ new Map();
1752
1755
  /** File-tree changes invalidate even successful resolutions (extension precedence can move). */
1753
1756
  #fileTreeRevision = 0;
1754
1757
  resolutionWork = {
@@ -1768,6 +1771,7 @@ var Project = class {
1768
1771
  this.sourcePreparations = /* @__PURE__ */ new Map();
1769
1772
  this.removedSourcePaths = /* @__PURE__ */ new Set();
1770
1773
  this.auxiliarySources = /* @__PURE__ */ new Set();
1774
+ this.overriddenSources = /* @__PURE__ */ new Map();
1771
1775
  this.resolutionWork = {
1772
1776
  moduleResolutionsAttempted: 0,
1773
1777
  sourceFilesAdded: 0,
@@ -1796,6 +1800,22 @@ var Project = class {
1796
1800
  this.#assertNotLoading();
1797
1801
  return Object.freeze({ ...this.resolutionWork });
1798
1802
  };
1803
+ /** @internal Whether an operation has crossed into the TypeScript-backed API. */
1804
+ hasMaterializedCompiler = () => this.#sourceFiles.project !== void 0;
1805
+ /** Source bytes from overlays, virtual filesystems, or disk, without creating a compiler. */
1806
+ getSourceText = (filePath) => {
1807
+ const override = this.overriddenSources.get(this.normalizePath(filePath));
1808
+ if (override !== void 0) return override;
1809
+ try {
1810
+ return this.options.readFile(filePath);
1811
+ } catch {
1812
+ return;
1813
+ }
1814
+ };
1815
+ /** Whether that same compiler-free source view can read a path. */
1816
+ sourceExists = (filePath) => this.overriddenSources.has(this.normalizePath(filePath)) || (this.options.fileExists?.(filePath) ?? this.getSourceText(filePath) !== void 0);
1817
+ /** Whether a caller supplied bytes that can differ from the path on disk. */
1818
+ sourceIsOverridden = (filePath) => this.overriddenSources.has(this.normalizePath(filePath));
1799
1819
  getSourceFile = (filePath) => {
1800
1820
  this.#assertNotLoading();
1801
1821
  if (!this.project.has(filePath)) return void 0;
@@ -2527,6 +2547,7 @@ var Project = class {
2527
2547
  */
2528
2548
  if (existing && existing.getFullText() === content) {
2529
2549
  this.markAuxiliary((0, _bamboocss_ts_ast.pathOf)(existing), options.auxiliary);
2550
+ this.overriddenSources.set(this.normalizePath((0, _bamboocss_ts_ast.pathOf)(existing)), content);
2530
2551
  return existing;
2531
2552
  }
2532
2553
  this.invalidateSourcePreparation(filePath, existing);
@@ -2535,6 +2556,7 @@ var Project = class {
2535
2556
  const sourceFile = this.project.createSourceFile(filePath, content, { scriptKind: scriptKindFor(filePath) });
2536
2557
  if (!sourceFile) throw new Error(`bamboo: could not add ${filePath} to the project`);
2537
2558
  this.markAuxiliary((0, _bamboocss_ts_ast.pathOf)(sourceFile), options.auxiliary);
2559
+ this.overriddenSources.set(this.normalizePath((0, _bamboocss_ts_ast.pathOf)(sourceFile)), content);
2538
2560
  return sourceFile;
2539
2561
  };
2540
2562
  /** Claim or release compiler ownership of one source, in the ledger's own spelling. */
@@ -2553,8 +2575,10 @@ var Project = class {
2553
2575
  this.markTargetRemoved(this.normalizePath((0, _bamboocss_ts_ast.pathOf)(sourceFile)), sourceFile);
2554
2576
  this.options.parserOptions.encoder.releaseFile((0, _bamboocss_ts_ast.pathOf)(sourceFile));
2555
2577
  this.auxiliarySources.delete(this.normalizePath((0, _bamboocss_ts_ast.pathOf)(sourceFile)));
2578
+ this.overriddenSources.delete(this.normalizePath((0, _bamboocss_ts_ast.pathOf)(sourceFile)));
2556
2579
  return this.project.removeSourceFile((0, _bamboocss_ts_ast.pathOf)(sourceFile));
2557
2580
  }
2581
+ this.overriddenSources.delete(this.normalizePath(filePath));
2558
2582
  return false;
2559
2583
  };
2560
2584
  /**
@@ -2573,7 +2597,11 @@ var Project = class {
2573
2597
  this.#ensureSourceFiles();
2574
2598
  const sourceFile = this.getSourceFile(filePath);
2575
2599
  this.invalidate(false, (0, _bamboocss_ts_ast.pathOf)(sourceFile));
2576
- if (!sourceFile) return;
2600
+ if (!sourceFile) {
2601
+ this.overriddenSources.delete(this.normalizePath(filePath));
2602
+ return;
2603
+ }
2604
+ this.overriddenSources.delete(this.normalizePath((0, _bamboocss_ts_ast.pathOf)(sourceFile)));
2577
2605
  this.invalidateSourcePreparation(filePath, sourceFile);
2578
2606
  return this.project.reloadSourceFile(filePath);
2579
2607
  };
@@ -2583,6 +2611,7 @@ var Project = class {
2583
2611
  const files = this.getFiles();
2584
2612
  this.invalidate();
2585
2613
  for (const file of files) {
2614
+ this.overriddenSources.delete(this.normalizePath(file));
2586
2615
  const source = this.getSourceFile(file);
2587
2616
  if (source) {
2588
2617
  this.invalidateSourcePreparation(file, source);
package/dist/index.d.cts CHANGED
@@ -458,6 +458,7 @@ interface ProjectOptions extends ProjectOptions$1 {
458
458
  */
459
459
  deferInitialSourceFiles?: boolean;
460
460
  readFile: Runtime['fs']['readFileSync'];
461
+ fileExists?: Runtime['fs']['existsSync'];
461
462
  getFiles(): string[];
462
463
  hooks: Partial<BambooHooks>;
463
464
  parserOptions: ParserOptions;
@@ -586,6 +587,8 @@ declare class Project {
586
587
  * files.
587
588
  */
588
589
  private auxiliarySources;
590
+ /** Bytes explicitly supplied by a caller rather than read from disk. */
591
+ private overriddenSources;
589
592
  private resolutionWork;
590
593
  private resetResolutionState;
591
594
  /** Files whose imports may resolve differently after a local file appears. */
@@ -596,6 +599,14 @@ declare class Project {
596
599
  getResolvedSourceFiles: () => readonly string[];
597
600
  /** @internal Deterministic resolver/add/read work, for regression assertions. */
598
601
  getResolutionWork: () => ResolutionWork;
602
+ /** @internal Whether an operation has crossed into the TypeScript-backed API. */
603
+ hasMaterializedCompiler: () => boolean;
604
+ /** Source bytes from overlays, virtual filesystems, or disk, without creating a compiler. */
605
+ getSourceText: (filePath: string) => string | undefined;
606
+ /** Whether that same compiler-free source view can read a path. */
607
+ sourceExists: (filePath: string) => boolean;
608
+ /** Whether a caller supplied bytes that can differ from the path on disk. */
609
+ sourceIsOverridden: (filePath: string) => boolean;
599
610
  getSourceFile: (filePath: string) => SourceFile | undefined;
600
611
  /**
601
612
  * How many syntax errors this file's parse produced.
package/dist/index.d.mts CHANGED
@@ -458,6 +458,7 @@ interface ProjectOptions extends ProjectOptions$1 {
458
458
  */
459
459
  deferInitialSourceFiles?: boolean;
460
460
  readFile: Runtime['fs']['readFileSync'];
461
+ fileExists?: Runtime['fs']['existsSync'];
461
462
  getFiles(): string[];
462
463
  hooks: Partial<BambooHooks>;
463
464
  parserOptions: ParserOptions;
@@ -586,6 +587,8 @@ declare class Project {
586
587
  * files.
587
588
  */
588
589
  private auxiliarySources;
590
+ /** Bytes explicitly supplied by a caller rather than read from disk. */
591
+ private overriddenSources;
589
592
  private resolutionWork;
590
593
  private resetResolutionState;
591
594
  /** Files whose imports may resolve differently after a local file appears. */
@@ -596,6 +599,14 @@ declare class Project {
596
599
  getResolvedSourceFiles: () => readonly string[];
597
600
  /** @internal Deterministic resolver/add/read work, for regression assertions. */
598
601
  getResolutionWork: () => ResolutionWork;
602
+ /** @internal Whether an operation has crossed into the TypeScript-backed API. */
603
+ hasMaterializedCompiler: () => boolean;
604
+ /** Source bytes from overlays, virtual filesystems, or disk, without creating a compiler. */
605
+ getSourceText: (filePath: string) => string | undefined;
606
+ /** Whether that same compiler-free source view can read a path. */
607
+ sourceExists: (filePath: string) => boolean;
608
+ /** Whether a caller supplied bytes that can differ from the path on disk. */
609
+ sourceIsOverridden: (filePath: string) => boolean;
599
610
  getSourceFile: (filePath: string) => SourceFile | undefined;
600
611
  /**
601
612
  * How many syntax errors this file's parse produced.
package/dist/index.mjs CHANGED
@@ -982,6 +982,7 @@ var ParserResult = class {
982
982
  /** The call site of `result`, when the encoder is recording them. */
983
983
  originOf = (result) => {
984
984
  if (!this.origins || !this.encoder.recordOrigins) return void 0;
985
+ if (result.atomOrigin) return result.atomOrigin;
985
986
  const node = result.box?.getNode();
986
987
  const sourceFile = node?.getSourceFile();
987
988
  if (!node || !sourceFile) return void 0;
@@ -1748,6 +1749,8 @@ var Project = class {
1748
1749
  * files.
1749
1750
  */
1750
1751
  auxiliarySources = /* @__PURE__ */ new Set();
1752
+ /** Bytes explicitly supplied by a caller rather than read from disk. */
1753
+ overriddenSources = /* @__PURE__ */ new Map();
1751
1754
  /** File-tree changes invalidate even successful resolutions (extension precedence can move). */
1752
1755
  #fileTreeRevision = 0;
1753
1756
  resolutionWork = {
@@ -1767,6 +1770,7 @@ var Project = class {
1767
1770
  this.sourcePreparations = /* @__PURE__ */ new Map();
1768
1771
  this.removedSourcePaths = /* @__PURE__ */ new Set();
1769
1772
  this.auxiliarySources = /* @__PURE__ */ new Set();
1773
+ this.overriddenSources = /* @__PURE__ */ new Map();
1770
1774
  this.resolutionWork = {
1771
1775
  moduleResolutionsAttempted: 0,
1772
1776
  sourceFilesAdded: 0,
@@ -1795,6 +1799,22 @@ var Project = class {
1795
1799
  this.#assertNotLoading();
1796
1800
  return Object.freeze({ ...this.resolutionWork });
1797
1801
  };
1802
+ /** @internal Whether an operation has crossed into the TypeScript-backed API. */
1803
+ hasMaterializedCompiler = () => this.#sourceFiles.project !== void 0;
1804
+ /** Source bytes from overlays, virtual filesystems, or disk, without creating a compiler. */
1805
+ getSourceText = (filePath) => {
1806
+ const override = this.overriddenSources.get(this.normalizePath(filePath));
1807
+ if (override !== void 0) return override;
1808
+ try {
1809
+ return this.options.readFile(filePath);
1810
+ } catch {
1811
+ return;
1812
+ }
1813
+ };
1814
+ /** Whether that same compiler-free source view can read a path. */
1815
+ sourceExists = (filePath) => this.overriddenSources.has(this.normalizePath(filePath)) || (this.options.fileExists?.(filePath) ?? this.getSourceText(filePath) !== void 0);
1816
+ /** Whether a caller supplied bytes that can differ from the path on disk. */
1817
+ sourceIsOverridden = (filePath) => this.overriddenSources.has(this.normalizePath(filePath));
1798
1818
  getSourceFile = (filePath) => {
1799
1819
  this.#assertNotLoading();
1800
1820
  if (!this.project.has(filePath)) return void 0;
@@ -2526,6 +2546,7 @@ var Project = class {
2526
2546
  */
2527
2547
  if (existing && existing.getFullText() === content) {
2528
2548
  this.markAuxiliary(pathOf(existing), options.auxiliary);
2549
+ this.overriddenSources.set(this.normalizePath(pathOf(existing)), content);
2529
2550
  return existing;
2530
2551
  }
2531
2552
  this.invalidateSourcePreparation(filePath, existing);
@@ -2534,6 +2555,7 @@ var Project = class {
2534
2555
  const sourceFile = this.project.createSourceFile(filePath, content, { scriptKind: scriptKindFor(filePath) });
2535
2556
  if (!sourceFile) throw new Error(`bamboo: could not add ${filePath} to the project`);
2536
2557
  this.markAuxiliary(pathOf(sourceFile), options.auxiliary);
2558
+ this.overriddenSources.set(this.normalizePath(pathOf(sourceFile)), content);
2537
2559
  return sourceFile;
2538
2560
  };
2539
2561
  /** Claim or release compiler ownership of one source, in the ledger's own spelling. */
@@ -2552,8 +2574,10 @@ var Project = class {
2552
2574
  this.markTargetRemoved(this.normalizePath(pathOf(sourceFile)), sourceFile);
2553
2575
  this.options.parserOptions.encoder.releaseFile(pathOf(sourceFile));
2554
2576
  this.auxiliarySources.delete(this.normalizePath(pathOf(sourceFile)));
2577
+ this.overriddenSources.delete(this.normalizePath(pathOf(sourceFile)));
2555
2578
  return this.project.removeSourceFile(pathOf(sourceFile));
2556
2579
  }
2580
+ this.overriddenSources.delete(this.normalizePath(filePath));
2557
2581
  return false;
2558
2582
  };
2559
2583
  /**
@@ -2572,7 +2596,11 @@ var Project = class {
2572
2596
  this.#ensureSourceFiles();
2573
2597
  const sourceFile = this.getSourceFile(filePath);
2574
2598
  this.invalidate(false, pathOf(sourceFile));
2575
- if (!sourceFile) return;
2599
+ if (!sourceFile) {
2600
+ this.overriddenSources.delete(this.normalizePath(filePath));
2601
+ return;
2602
+ }
2603
+ this.overriddenSources.delete(this.normalizePath(pathOf(sourceFile)));
2576
2604
  this.invalidateSourcePreparation(filePath, sourceFile);
2577
2605
  return this.project.reloadSourceFile(filePath);
2578
2606
  };
@@ -2582,6 +2610,7 @@ var Project = class {
2582
2610
  const files = this.getFiles();
2583
2611
  this.invalidate();
2584
2612
  for (const file of files) {
2613
+ this.overriddenSources.delete(this.normalizePath(file));
2585
2614
  const source = this.getSourceFile(file);
2586
2615
  if (source) {
2587
2616
  this.invalidateSourcePreparation(file, source);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/parser",
3
- "version": "1.54.1",
3
+ "version": "1.55.0",
4
4
  "description": "The static parser for bamboo css",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -33,20 +33,20 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "ts-pattern": "5.9.0",
36
- "@bamboocss/config": "^1.54.1",
37
- "@bamboocss/core": "^1.54.1",
38
- "@bamboocss/extractor": "1.54.1",
39
- "@bamboocss/logger": "1.54.1",
40
- "@bamboocss/shared": "1.54.1",
41
- "@bamboocss/ts-ast": "1.54.1",
42
- "@bamboocss/types": "1.54.1"
36
+ "@bamboocss/config": "^1.55.0",
37
+ "@bamboocss/core": "^1.55.0",
38
+ "@bamboocss/extractor": "1.55.0",
39
+ "@bamboocss/logger": "1.55.0",
40
+ "@bamboocss/shared": "1.55.0",
41
+ "@bamboocss/ts-ast": "1.55.0",
42
+ "@bamboocss/types": "1.55.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@typescript/api": "npm:typescript@7.1.0-dev.20260826.1",
46
46
  "ts-morph": "28.0.0",
47
- "@bamboocss/generator": "1.54.1",
48
- "@bamboocss/plugin-svelte": "1.54.1",
49
- "@bamboocss/plugin-vue": "1.54.1"
47
+ "@bamboocss/generator": "1.55.0",
48
+ "@bamboocss/plugin-svelte": "1.55.0",
49
+ "@bamboocss/plugin-vue": "1.55.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsdown src/index.ts --format=esm,cjs --dts",