@fluentic/style 0.1.0-beta.15 → 0.1.0-beta.17

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 (124) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/compiler/compiler/compiler.ts +7 -0
  3. package/compiler/transform/evaluator/lazy_bindings.ts +63 -0
  4. package/compiler/transform/evaluator/tracer.ts +45 -38
  5. package/compiler/transform/extract/plugin.ts +19 -11
  6. package/compiler/transform/extract/utils/state.ts +3 -2
  7. package/dist/compiler/index.mjs +1 -1
  8. package/dist/{compiler-AOb_VaKQ.mjs → compiler-Cat8TmMk.mjs} +110 -44
  9. package/dist/compiler-Cat8TmMk.mjs.map +1 -0
  10. package/dist/config/index.js +2 -2
  11. package/dist/{config-B_OQYZSm.js → config-BK7oK4Hx.js} +3 -3
  12. package/dist/{config-B_OQYZSm.js.map → config-BK7oK4Hx.js.map} +1 -1
  13. package/dist/{config-BF-mxuPk.js → config-DFxeuT46.js} +4 -4
  14. package/dist/{config-BF-mxuPk.js.map → config-DFxeuT46.js.map} +1 -1
  15. package/dist/{css-RohOR3Vq.js → css-BkNqUfLD.js} +12 -12
  16. package/dist/{css-RohOR3Vq.js.map → css-BkNqUfLD.js.map} +1 -1
  17. package/dist/css.js +1 -1
  18. package/dist/{css_extra-CuzJtAR_.js → css_extra-qzi_eFFf.js} +2 -2
  19. package/dist/{css_extra-CuzJtAR_.js.map → css_extra-qzi_eFFf.js.map} +1 -1
  20. package/dist/{data-Bw3Xod5J.js → data-MrBhvIQZ.js} +7 -7
  21. package/dist/{data-Bw3Xod5J.js.map → data-MrBhvIQZ.js.map} +1 -1
  22. package/dist/{debug-CVO3xx4C.js → debug-Bo43rBKc.js} +2 -2
  23. package/dist/{debug-CVO3xx4C.js.map → debug-Bo43rBKc.js.map} +1 -1
  24. package/dist/dev/rsc.js +9 -9
  25. package/dist/{dev-BnQXPLQB.js → dev-BoEgFs_x.js} +6 -6
  26. package/dist/{dev-BnQXPLQB.js.map → dev-BoEgFs_x.js.map} +1 -1
  27. package/dist/dev.js +1 -1
  28. package/dist/dialect/extracted/index.js +1 -1
  29. package/dist/dialect/index.js +1 -1
  30. package/dist/{elementMarker-BrHXg161.js → elementMarker-nYeJnJPQ.js} +5 -5
  31. package/dist/{elementMarker-BrHXg161.js.map → elementMarker-nYeJnJPQ.js.map} +1 -1
  32. package/dist/entry/dev/adapter/preact.js +1 -1
  33. package/dist/entry/dev/adapter/react.js +1 -1
  34. package/dist/entry/dev/adapter/solid.js +1 -1
  35. package/dist/entry/dev/css.js +2 -2
  36. package/dist/entry/dev/jsx-dev-runtime.js +2 -2
  37. package/dist/entry/dev/jsx-runtime.js +2 -2
  38. package/dist/entry/dev.js +11 -11
  39. package/dist/{env-D6daex-9.js → env-BcNl1tsJ.js} +9 -16
  40. package/dist/{env-D6daex-9.js.map → env-BcNl1tsJ.js.map} +1 -1
  41. package/dist/{getClassName-m5DOkMFQ.js → getClassName-CkTq92nR.js} +4 -4
  42. package/dist/{getClassName-m5DOkMFQ.js.map → getClassName-CkTq92nR.js.map} +1 -1
  43. package/dist/{global-DeIYtcdl.js → global-DGcWZODV.js} +2 -8
  44. package/dist/{global-DeIYtcdl.js.map → global-DGcWZODV.js.map} +1 -1
  45. package/dist/{hash-DCJkLls_.js → hash-CjTP-uES.js} +3 -3
  46. package/dist/{hash-DCJkLls_.js.map → hash-CjTP-uES.js.map} +1 -1
  47. package/dist/index.js +9 -9
  48. package/dist/jsx/jsx-dev-runtime.js +1 -1
  49. package/dist/jsx/jsx-runtime.js +1 -1
  50. package/dist/{jsx-CvloSSpb.js → jsx-DA1LD8nU.js} +4 -4
  51. package/dist/{jsx-CvloSSpb.js.map → jsx-DA1LD8nU.js.map} +1 -1
  52. package/dist/{loader-fAuIjIik.mjs → loader-Cvz2pKYV.mjs} +3 -3
  53. package/dist/{loader-fAuIjIik.mjs.map → loader-Cvz2pKYV.mjs.map} +1 -1
  54. package/dist/{misc-CyZgGtc9.mjs → misc-BKaSZF14.mjs} +30 -4
  55. package/dist/misc-BKaSZF14.mjs.map +1 -0
  56. package/dist/{namedTokens-DwgmUMBM.js → namedTokens-paLD-Pdk.js} +2 -2
  57. package/dist/{namedTokens-DwgmUMBM.js.map → namedTokens-paLD-Pdk.js.map} +1 -1
  58. package/dist/plugin/farm/index.mjs +3 -3
  59. package/dist/plugin/nextjs/index.mjs +5 -5
  60. package/dist/plugin/nextjs/index.mjs.map +1 -1
  61. package/dist/plugin/nextjs/loader.mjs +4 -4
  62. package/dist/plugin/parcel/index.cjs +1 -1
  63. package/dist/plugin/parcel/index.mjs +2 -2
  64. package/dist/plugin/parcel/optimizer.cjs +1 -1
  65. package/dist/plugin/parcel/optimizer.mjs +2 -2
  66. package/dist/plugin/parcel/resolver.cjs +1 -1
  67. package/dist/plugin/parcel/resolver.mjs +2 -2
  68. package/dist/plugin/parcel/runtime.cjs +1 -1
  69. package/dist/plugin/parcel/runtime.mjs +1 -1
  70. package/dist/plugin/parcel/transformer.cjs +1 -1
  71. package/dist/plugin/parcel/transformer.mjs +2 -2
  72. package/dist/plugin/rspack/index.mjs +2 -2
  73. package/dist/plugin/vite/index.mjs +20 -17
  74. package/dist/plugin/vite/index.mjs.map +1 -1
  75. package/dist/plugin/webpack/index.mjs +2 -2
  76. package/dist/plugin/webpack/loader.mjs +2 -2
  77. package/dist/presets/tailwind/index.js +3 -3
  78. package/dist/{registry-BMijh1CM.mjs → registry-Bbxm5X90.mjs} +2 -2
  79. package/dist/{registry-BMijh1CM.mjs.map → registry-Bbxm5X90.mjs.map} +1 -1
  80. package/dist/server.js +14 -14
  81. package/dist/{shared-BfASWZo1.mjs → shared-BVciI9ew.mjs} +4 -4
  82. package/dist/{shared-BfASWZo1.mjs.map → shared-BVciI9ew.mjs.map} +1 -1
  83. package/dist/{shared-DY0kuBcN.cjs → shared-L-63tURh.cjs} +125 -45
  84. package/dist/shared-L-63tURh.cjs.map +1 -0
  85. package/dist/sheet-Biw_rI4_.js +1 -0
  86. package/dist/sheet-D_grHnaJ.js +7 -0
  87. package/dist/sheet-D_grHnaJ.js.map +1 -0
  88. package/dist/{sidecar-cCzTDkzg.mjs → sidecar-B7Q2P71F.mjs} +3 -3
  89. package/dist/{sidecar-cCzTDkzg.mjs.map → sidecar-B7Q2P71F.mjs.map} +1 -1
  90. package/dist/{style-a6ccye6R.js → style-CRs-vfY1.js} +10 -10
  91. package/dist/{style-a6ccye6R.js.map → style-CRs-vfY1.js.map} +1 -1
  92. package/dist/{styleStore-Ceoaqa5U.js → styleStore-HI4V2puu.js} +6 -6
  93. package/dist/{styleStore-Ceoaqa5U.js.map → styleStore-HI4V2puu.js.map} +1 -1
  94. package/dist/{token-Ci73NE6h.js → token-BX5jRxMb.js} +2 -2
  95. package/dist/{token-Ci73NE6h.js.map → token-BX5jRxMb.js.map} +1 -1
  96. package/dist/{trace-DDsvwdF0.js → trace-DdFJPELS.js} +3 -3
  97. package/dist/{trace-DDsvwdF0.js.map → trace-DdFJPELS.js.map} +1 -1
  98. package/dist/{transform-BkxIouPX.js → transform-BZ4jPwy3.js} +2 -2
  99. package/dist/{transform-BkxIouPX.js.map → transform-BZ4jPwy3.js.map} +1 -1
  100. package/dist/types/compiler/transform/evaluator/lazy_bindings.d.ts +22 -0
  101. package/dist/types/compiler/transform/evaluator/tracer.d.ts +1 -0
  102. package/dist/types/compiler/transform/extract/utils/state.d.ts +3 -2
  103. package/dist/types/plugin/utils/filter.d.ts +11 -0
  104. package/dist/{utils-BO6Ix8t5.mjs → utils-D2QdzQkX.mjs} +4 -4
  105. package/dist/{utils-BO6Ix8t5.mjs.map → utils-D2QdzQkX.mjs.map} +1 -1
  106. package/dist/{utils-EG9gh2g3.mjs → utils-D3KR1ht8.mjs} +3 -3
  107. package/dist/{utils-EG9gh2g3.mjs.map → utils-D3KR1ht8.mjs.map} +1 -1
  108. package/dist/utils.js +3 -3
  109. package/dist/{value-B-ThmbY-.js → value-BhyWGLkf.js} +5 -5
  110. package/dist/{value-B-ThmbY-.js.map → value-BhyWGLkf.js.map} +1 -1
  111. package/dist/{webpack-WXAJ3IYn.mjs → webpack-DRegoWgj.mjs} +6 -6
  112. package/dist/{webpack-WXAJ3IYn.mjs.map → webpack-DRegoWgj.mjs.map} +1 -1
  113. package/entry/dev/sheet.ts +4 -5
  114. package/package.json +16 -1
  115. package/plugin/bundler/vite/plugin.ts +20 -17
  116. package/plugin/bundler/webpack/plugin.ts +1 -1
  117. package/plugin/nextjs/plugin.ts +1 -1
  118. package/plugin/utils/filter.ts +65 -1
  119. package/dist/compiler-AOb_VaKQ.mjs.map +0 -1
  120. package/dist/misc-CyZgGtc9.mjs.map +0 -1
  121. package/dist/shared-DY0kuBcN.cjs.map +0 -1
  122. package/dist/sheet-B-5idGtZ.js +0 -9
  123. package/dist/sheet-B-5idGtZ.js.map +0 -1
  124. package/dist/sheet-D4f9KYPf.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @fluentic/style
2
2
 
3
+ ## 0.1.0-beta.17
4
+
5
+ ### Patch Changes
6
+
7
+ - Reduce build-time work by evaluating local bindings and imported exports only when style compilation needs them. Preserve declaration environments, cycle handling, and transitive dependency invalidation, reuse dependency hashes within a compilation, and skip runtime-import rewriting when it is unnecessary.
8
+
9
+ Add includePackages and excludePackages options for exact npm package names. Package exclusions take precedence over package inclusions, matching inclusions override file patterns for JavaScript and TypeScript files, and unmatched files retain existing filter behavior. Adapt package rules and defaults to Vite's native transform-hook filters while retaining the shared compatibility check.
10
+
11
+ ## 0.1.0-beta.16
12
+
13
+ ### Patch Changes
14
+
15
+ - Export the JSX import-source base paths so automatic JSX compilation can fall back to Fluentic's wrapped createElement when a key follows spread props. Preserve CSS prop handling and route the plugin fallback to development, production, and React Server Component runtimes, with generated TypeScript declarations.
16
+
3
17
  ## 0.1.0-beta.15
4
18
 
5
19
  ### Patch Changes
@@ -45,6 +45,7 @@ export function createCompiler(args: CompilerArgs, options: CompilerOptions) {
45
45
  const collector = createCssCollector();
46
46
 
47
47
  const compileDebug = (args: TransformDebugArgs): TransformDebugResult | null => {
48
+ tracer.beginCompilation();
48
49
  return rewriteTransformResult(
49
50
  transformDebug(internal, args, { tracer }),
50
51
  internal.runtimeMode,
@@ -53,6 +54,7 @@ export function createCompiler(args: CompilerArgs, options: CompilerOptions) {
53
54
  };
54
55
 
55
56
  const compileDebugRSC = (args: TransformDebugArgs): TransformDebugRscResult | null => {
57
+ tracer.beginCompilation();
56
58
  const debugResult = rewriteTransformResult(
57
59
  transformDebug(internal, args, { tracer }),
58
60
  internal.runtimeMode,
@@ -89,6 +91,7 @@ export function createCompiler(args: CompilerArgs, options: CompilerOptions) {
89
91
  };
90
92
 
91
93
  const compileExtract = (args: TransformExtractArgs): TransformExtractResult | null => {
94
+ tracer.beginCompilation();
92
95
  const startIndex = collector.getItems().length;
93
96
 
94
97
  const result = transformExtract(internal, args, {
@@ -161,6 +164,10 @@ function rewriteCompilerRuntimeImports(
161
164
  runtimeMode: CompilerRuntimeMode,
162
165
  sourceCode: string,
163
166
  ) {
167
+ // All rewritable entry points share this prefix. Escaped specifiers still
168
+ // need parsing, so only take the fast path when no escapes are present.
169
+ if (!code.includes(STYLE_IMPORT_PATH) && !code.includes('\\')) return code;
170
+
164
171
  const importRuntimeMode = getImportRuntimeMode(runtimeMode, sourceCode);
165
172
 
166
173
  return rewriteImportSources(
@@ -0,0 +1,63 @@
1
+ import { evalFail } from './evaluator';
2
+ import type { EvalResult } from './types';
3
+
4
+ /** Map-compatible bindings whose initializers run only when their values are read. */
5
+ export class LazyBindings extends Map<string, EvalResult> {
6
+ private initializers = new Map<string, () => EvalResult>();
7
+
8
+ setLazy(name: string, initializer: () => EvalResult) {
9
+ this.initializers.set(name, initializer);
10
+ super.set(name, evalFail(`Circular binding: ${name}`));
11
+ }
12
+
13
+ /** Capture a declaration environment without forcing pending initializers. */
14
+ fork() {
15
+ const bindings = new LazyBindings();
16
+ for (const [name, value] of super.entries()) bindings.set(name, value);
17
+ for (const [name, initializer] of this.initializers) bindings.setLazy(name, initializer);
18
+ return bindings;
19
+ }
20
+
21
+ override set(name: string, value: EvalResult) {
22
+ this.initializers.delete(name);
23
+ return super.set(name, value);
24
+ }
25
+
26
+ override delete(name: string) {
27
+ this.initializers.delete(name);
28
+ return super.delete(name);
29
+ }
30
+
31
+ override clear() {
32
+ this.initializers.clear();
33
+ super.clear();
34
+ }
35
+
36
+ override get(name: string): EvalResult | undefined {
37
+ const initializer = this.initializers.get(name);
38
+ if (initializer) {
39
+ this.initializers.delete(name);
40
+ super.set(name, initializer());
41
+ }
42
+ return super.get(name);
43
+ }
44
+
45
+ override forEach(
46
+ callback: (value: EvalResult, key: string, map: Map<string, EvalResult>) => void,
47
+ thisArg?: unknown,
48
+ ) {
49
+ for (const key of this.keys()) callback.call(thisArg, this.get(key)!, key, this);
50
+ }
51
+
52
+ override *entries(): MapIterator<[string, EvalResult]> {
53
+ for (const key of this.keys()) yield [key, this.get(key)!];
54
+ }
55
+
56
+ override *values(): MapIterator<EvalResult> {
57
+ for (const key of this.keys()) yield this.get(key)!;
58
+ }
59
+
60
+ override [Symbol.iterator]() {
61
+ return this.entries();
62
+ }
63
+ }
@@ -22,16 +22,17 @@ import { babelTransformOptions } from '../utils/babel';
22
22
  import { getProjectFileId } from '../utils/path';
23
23
  import type { CompiledStyleObject, CompiledStyleObjectLocations, EvalScope } from './evaluator';
24
24
  import { COMPILED_STYLE_OBJECT_LOCATIONS, evalFail, evalOk, evaluateEnumDeclaration, evaluateNode } from './evaluator';
25
+ import { LazyBindings } from './lazy_bindings';
25
26
  import type { EvalModuleBindings, EvalResult, EvalSlotRef, ImportMap, ResolveImportFn } from './types';
26
27
 
27
28
  export type Tracer = ReturnType<typeof createTracer>;
28
29
 
29
30
  type TraceCacheContent = {
30
- bindings: Array<[string, EvalResult]>;
31
+ bindings: EvalModuleBindings;
31
32
  dependencies?: TraceDependency[];
32
33
  };
33
34
 
34
- const CACHE_TYPE = 'transform-trace';
35
+ const CACHE_TYPE = 'transform-trace-lazy-v1';
35
36
 
36
37
  type TraceDependency = {
37
38
  filePath: string;
@@ -45,6 +46,11 @@ type TraceResult = TraceDependency & {
45
46
 
46
47
  export function createTracer(internal: CompilerInternal) {
47
48
  const active = new Set<string>();
49
+ const dependencyHashes = new Map<string, string | null>();
50
+ const getDependencyHash = (filePath: string) => {
51
+ if (!dependencyHashes.has(filePath)) dependencyHashes.set(filePath, hashFileContent(filePath));
52
+ return dependencyHashes.get(filePath) ?? null;
53
+ };
48
54
 
49
55
  const resolveImport = (
50
56
  babel: typeof BabelCore,
@@ -70,11 +76,11 @@ export function createTracer(internal: CompilerInternal) {
70
76
  cacheType: CACHE_TYPE,
71
77
  });
72
78
 
73
- if (cached && areDependenciesFresh(cached.dependencies ?? [])) {
79
+ if (cached?.bindings instanceof Map && areDependenciesFresh(cached.dependencies ?? [], getDependencyHash)) {
74
80
  return {
75
81
  filePath: resolved.filePath,
76
82
  contentHash,
77
- bindings: new Map(cached.bindings),
83
+ bindings: cached.bindings,
78
84
  dependencies: cached.dependencies ?? [],
79
85
  };
80
86
  }
@@ -84,11 +90,14 @@ export function createTracer(internal: CompilerInternal) {
84
90
 
85
91
  try {
86
92
  const dependencies = new Map<string, TraceDependency>();
93
+ const dependencyList: TraceDependency[] = [];
87
94
  const resolveDependency: ResolveImportFn = (source, fromFile) => {
88
95
  const traced = traceModuleResult(babel, source, fromFile);
89
96
  if (!traced) return null;
90
97
 
91
- return createTrackedBindings(traced, dependencies);
98
+ return createTrackedBindings(traced, dependencies, () => {
99
+ dependencyList.splice(0, dependencyList.length, ...dependencies.values());
100
+ });
92
101
  };
93
102
 
94
103
  const bindings = parseAndExtractModule(
@@ -101,15 +110,13 @@ export function createTracer(internal: CompilerInternal) {
101
110
  );
102
111
  if (!bindings) return null;
103
112
 
104
- const dependencyList = [...dependencies.values()];
105
-
106
113
  internal.cache.setItem<TraceCacheContent>({
107
114
  filePath: resolved.filePath,
108
115
  contentHash,
109
116
  cacheType: CACHE_TYPE,
110
117
  persistent: false,
111
118
  cacheContent: {
112
- bindings: [...bindings.entries()],
119
+ bindings,
113
120
  dependencies: dependencyList,
114
121
  },
115
122
  });
@@ -136,6 +143,9 @@ export function createTracer(internal: CompilerInternal) {
136
143
  return {
137
144
  resolveImport,
138
145
  traceModule,
146
+ beginCompilation() {
147
+ dependencyHashes.clear();
148
+ },
139
149
  };
140
150
  }
141
151
 
@@ -163,7 +173,7 @@ function parseAndExtractModule(
163
173
 
164
174
  const imports: ImportMap = new Map();
165
175
  const rawBindings: Map<string, BabelTypes.Node> = new Map();
166
- const bindings: EvalModuleBindings = new Map();
176
+ const bindings = new LazyBindings();
167
177
  const styleNames = new Set<string>();
168
178
  const styleMetas = new Map();
169
179
  const fileId = getProjectFileId(projectDir, filePath);
@@ -261,9 +271,9 @@ function parseAndExtractModule(
261
271
  if (stmt.type === 'ExportAllDeclaration') {
262
272
  const exported = resolveImport(stmt.source.value, filePath);
263
273
  if (exported) {
264
- exported.forEach((value, key) => {
265
- if (key !== 'default') bindings.set(key, value);
266
- });
274
+ for (const key of exported.keys()) {
275
+ if (key !== 'default') bindings.setLazy(key, () => exported.get(key)!);
276
+ }
267
277
  }
268
278
  }
269
279
 
@@ -285,7 +295,14 @@ function parseAndExtractModule(
285
295
  };
286
296
 
287
297
  rawBindings.forEach((node, name) => {
288
- bindings.set(name, evaluateResolvedNode(node, scope, styleNames, fileId, options));
298
+ bindings.setLazy(name, () => {
299
+ const imported = imports.get(name);
300
+ if (imported && node.type === 'Identifier' && node.name === name) {
301
+ return resolveImport(imported.source, filePath)?.get(imported.name) ??
302
+ evalFail(`Cannot resolve export: ${name}`);
303
+ }
304
+ return evaluateResolvedNode(node, scope, styleNames, fileId, options);
305
+ });
289
306
  });
290
307
 
291
308
  return bindings;
@@ -595,44 +612,34 @@ function addTraceDependency(
595
612
  function createTrackedBindings(
596
613
  traced: TraceResult,
597
614
  dependencies: Map<string, TraceDependency>,
615
+ onTrack: () => void,
598
616
  ): EvalModuleBindings {
599
617
  const track = () => {
600
618
  addTraceDependency(dependencies, traced);
601
619
  traced.dependencies.forEach((dependency) => addTraceDependency(dependencies, dependency));
620
+ onTrack();
602
621
  };
603
622
 
604
- return new class extends Map<string, EvalResult> {
605
- constructor() {
606
- super(traced.bindings);
607
- }
608
-
609
- override get(key: string): EvalResult | undefined {
610
- const value = super.get(key);
611
- if (value !== undefined || super.has(key)) track();
612
- return value;
613
- }
614
-
615
- override has(key: string): boolean {
616
- const result = super.has(key);
617
- if (result) track();
618
- return result;
619
- }
620
-
621
- override forEach(
622
- callbackfn: (value: EvalResult, key: string, map: Map<string, EvalResult>) => void,
623
- thisArg?: unknown,
624
- ): void {
623
+ const bindings = new LazyBindings();
624
+ for (const key of traced.bindings.keys()) {
625
+ bindings.setLazy(key, () => {
626
+ const value = traced.bindings.get(key)!;
625
627
  track();
626
- super.forEach(callbackfn, thisArg);
627
- }
628
- }();
628
+ return value;
629
+ });
630
+ }
631
+ // Record the module itself even when a requested export is missing. Values
632
+ // add their transitive dependencies after lazy resolution has completed.
633
+ track();
634
+ return bindings;
629
635
  }
630
636
 
631
637
  function areDependenciesFresh(
632
638
  dependencies: TraceDependency[],
639
+ getHash: (filePath: string) => string | null,
633
640
  ): boolean {
634
641
  for (const dependency of dependencies) {
635
- const currentHash = hashFileContent(dependency.filePath);
642
+ const currentHash = getHash(dependency.filePath);
636
643
  if (currentHash !== dependency.contentHash) return false;
637
644
  }
638
645
 
@@ -22,6 +22,7 @@ import {
22
22
  evaluateEnumDeclaration,
23
23
  evaluateNode,
24
24
  } from '../evaluator/evaluator';
25
+ import { LazyBindings } from '../evaluator/lazy_bindings';
25
26
  import { getImportedName } from '../syntax';
26
27
  import { annotateAtRuleDeclaration } from '../syntax/static_ids';
27
28
  import { BabelCore } from '../utils/babel';
@@ -69,7 +70,7 @@ export function createExtractPlugin(args: PluginArgs) {
69
70
  this.styleNames = new Set();
70
71
  this.sheetNames = new Set();
71
72
  this.styleMetas = new Map();
72
- this.bindings = new Map();
73
+ this.bindings = new LazyBindings();
73
74
  this.bindingNodes = new Map();
74
75
  this.imports = new Map();
75
76
  this.needsExtractImport = false;
@@ -137,11 +138,7 @@ export function createExtractPlugin(args: PluginArgs) {
137
138
  annotateAtRuleDeclaration(decl, state, t);
138
139
 
139
140
  const name = decl.id.name;
140
- const scope = getEvalScope(state);
141
- const result = evaluateNode(decl.init, scope);
142
-
143
- state.bindings.set(name, result);
144
- state.bindingNodes.set(name, decl.init);
141
+ recordLazyBinding(state, name, t.cloneNode(decl.init, true));
145
142
  });
146
143
  },
147
144
 
@@ -156,11 +153,7 @@ export function createExtractPlugin(args: PluginArgs) {
156
153
  annotateAtRuleDeclaration(decl, state, t);
157
154
 
158
155
  const name = decl.id.name;
159
- const scope = getEvalScope(state);
160
- const result = evaluateNode(decl.init, scope);
161
-
162
- state.bindings.set(name, result);
163
- state.bindingNodes.set(name, decl.init);
156
+ recordLazyBinding(state, name, t.cloneNode(decl.init, true));
164
157
  });
165
158
  },
166
159
 
@@ -328,6 +321,21 @@ export function createExtractPlugin(args: PluginArgs) {
328
321
  });
329
322
  }
330
323
 
324
+ function recordLazyBinding(state: ExtractPluginState, name: string, initializer: BabelTypes.Node) {
325
+ // Capture the declaration environment without evaluating it. Later shadowed
326
+ // declarations must not change the meaning of a pending initializer.
327
+ const bindings = state.bindings.fork();
328
+ const scope = {
329
+ ...getEvalScope(state),
330
+ bindings,
331
+ bindingNodes: new Map(state.bindingNodes),
332
+ imports: new Map(state.imports),
333
+ };
334
+ bindings.setLazy(name, () => evaluateNode(initializer, scope));
335
+ state.bindings.setLazy(name, () => bindings.get(name)!);
336
+ state.bindingNodes.set(name, initializer);
337
+ }
338
+
331
339
  function checkCompiledImportantUsage(
332
340
  result: NonNullable<ReturnType<typeof compileChain>>,
333
341
  options: CheckImportantOptions | undefined,
@@ -4,7 +4,8 @@ import type { CompilerOptions } from '../../../compiler/types';
4
4
  import type { CompilerCssCollector } from '../../../extract';
5
5
  import type { ImportSourceMatcher } from '../../../utils/import_source';
6
6
  import type { EvalScope } from '../../evaluator/evaluator';
7
- import type { EvalModuleBindings, ImportMap, ResolveImportFn } from '../../evaluator/types';
7
+ import type { LazyBindings } from '../../evaluator/lazy_bindings';
8
+ import type { ImportMap, ResolveImportFn } from '../../evaluator/types';
8
9
  import type { BabelTypes } from '../../utils/babel';
9
10
 
10
11
  export type HoistedDeclaration = {
@@ -21,7 +22,7 @@ export type ExtractPluginState = {
21
22
  styleNames: Set<string>;
22
23
  sheetNames: Set<string>;
23
24
  styleMetas: Map<string, StyleFnMeta>;
24
- bindings: EvalModuleBindings;
25
+ bindings: LazyBindings;
25
26
  bindingNodes: Map<string, BabelTypes.Node>;
26
27
  imports: ImportMap;
27
28
  needsExtractImport: boolean;
@@ -1,2 +1,2 @@
1
- import { a as getDefaultSourcemapUrl, g as createCompilerCache, i as CompilerRuntimeMode, n as createCompiler, o as normalizeSourcemapSourcePath, t as CssPropPresets } from "../compiler-AOb_VaKQ.mjs";
1
+ import { a as getDefaultSourcemapUrl, g as createCompilerCache, i as CompilerRuntimeMode, n as createCompiler, o as normalizeSourcemapSourcePath, t as CssPropPresets } from "../compiler-Cat8TmMk.mjs";
2
2
  export { CompilerRuntimeMode, CssPropPresets, createCompiler, createCompilerCache, getDefaultSourcemapUrl, normalizeSourcemapSourcePath };
@@ -7523,10 +7523,67 @@ function hasGlobalRuntimeValue(value, seen = /* @__PURE__ */ new Set()) {
7523
7523
  return Object.values(value).some((item) => hasGlobalRuntimeValue(item, seen));
7524
7524
  }
7525
7525
  //#endregion
7526
+ //#region compiler/transform/evaluator/lazy_bindings.ts
7527
+ /** Map-compatible bindings whose initializers run only when their values are read. */
7528
+ var LazyBindings = class LazyBindings extends Map {
7529
+ constructor(..._args) {
7530
+ super(..._args);
7531
+ this.initializers = /* @__PURE__ */ new Map();
7532
+ }
7533
+ setLazy(name, initializer) {
7534
+ this.initializers.set(name, initializer);
7535
+ super.set(name, evalFail(`Circular binding: ${name}`));
7536
+ }
7537
+ /** Capture a declaration environment without forcing pending initializers. */
7538
+ fork() {
7539
+ const bindings = new LazyBindings();
7540
+ for (const [name, value] of super.entries()) bindings.set(name, value);
7541
+ for (const [name, initializer] of this.initializers) bindings.setLazy(name, initializer);
7542
+ return bindings;
7543
+ }
7544
+ set(name, value) {
7545
+ this.initializers.delete(name);
7546
+ return super.set(name, value);
7547
+ }
7548
+ delete(name) {
7549
+ this.initializers.delete(name);
7550
+ return super.delete(name);
7551
+ }
7552
+ clear() {
7553
+ this.initializers.clear();
7554
+ super.clear();
7555
+ }
7556
+ get(name) {
7557
+ const initializer = this.initializers.get(name);
7558
+ if (initializer) {
7559
+ this.initializers.delete(name);
7560
+ super.set(name, initializer());
7561
+ }
7562
+ return super.get(name);
7563
+ }
7564
+ forEach(callback, thisArg) {
7565
+ for (const key of this.keys()) callback.call(thisArg, this.get(key), key, this);
7566
+ }
7567
+ *entries() {
7568
+ for (const key of this.keys()) yield [key, this.get(key)];
7569
+ }
7570
+ *values() {
7571
+ for (const key of this.keys()) yield this.get(key);
7572
+ }
7573
+ [Symbol.iterator]() {
7574
+ return this.entries();
7575
+ }
7576
+ };
7577
+ //#endregion
7526
7578
  //#region compiler/transform/evaluator/tracer.ts
7527
- const CACHE_TYPE = "transform-trace";
7579
+ const CACHE_TYPE = "transform-trace-lazy-v1";
7528
7580
  function createTracer(internal) {
7529
7581
  const active = /* @__PURE__ */ new Set();
7582
+ const dependencyHashes = /* @__PURE__ */ new Map();
7583
+ const getDependencyHash = (filePath) => {
7584
+ if (!dependencyHashes.has(filePath)) dependencyHashes.set(filePath, hashFileContent(filePath));
7585
+ return dependencyHashes.get(filePath) ?? null;
7586
+ };
7530
7587
  const resolveImport = (babel, source, fromFile) => {
7531
7588
  return traceModuleResult(babel, source, fromFile)?.bindings ?? null;
7532
7589
  };
@@ -7539,31 +7596,33 @@ function createTracer(internal) {
7539
7596
  contentHash,
7540
7597
  cacheType: CACHE_TYPE
7541
7598
  });
7542
- if (cached && areDependenciesFresh(cached.dependencies ?? [])) return {
7599
+ if (cached?.bindings instanceof Map && areDependenciesFresh(cached.dependencies ?? [], getDependencyHash)) return {
7543
7600
  filePath: resolved.filePath,
7544
7601
  contentHash,
7545
- bindings: new Map(cached.bindings),
7602
+ bindings: cached.bindings,
7546
7603
  dependencies: cached.dependencies ?? []
7547
7604
  };
7548
7605
  if (active.has(resolved.filePath)) return null;
7549
7606
  active.add(resolved.filePath);
7550
7607
  try {
7551
7608
  const dependencies = /* @__PURE__ */ new Map();
7609
+ const dependencyList = [];
7552
7610
  const resolveDependency = (source, fromFile) => {
7553
7611
  const traced = traceModuleResult(babel, source, fromFile);
7554
7612
  if (!traced) return null;
7555
- return createTrackedBindings(traced, dependencies);
7613
+ return createTrackedBindings(traced, dependencies, () => {
7614
+ dependencyList.splice(0, dependencyList.length, ...dependencies.values());
7615
+ });
7556
7616
  };
7557
7617
  const bindings = parseAndExtractModule(internal.projectDir, resolved.filePath, resolved.content, babel, resolveDependency, internal.options);
7558
7618
  if (!bindings) return null;
7559
- const dependencyList = [...dependencies.values()];
7560
7619
  internal.cache.setItem({
7561
7620
  filePath: resolved.filePath,
7562
7621
  contentHash,
7563
7622
  cacheType: CACHE_TYPE,
7564
7623
  persistent: false,
7565
7624
  cacheContent: {
7566
- bindings: [...bindings.entries()],
7625
+ bindings,
7567
7626
  dependencies: dependencyList
7568
7627
  }
7569
7628
  });
@@ -7582,7 +7641,10 @@ function createTracer(internal) {
7582
7641
  };
7583
7642
  return {
7584
7643
  resolveImport,
7585
- traceModule
7644
+ traceModule,
7645
+ beginCompilation() {
7646
+ dependencyHashes.clear();
7647
+ }
7586
7648
  };
7587
7649
  }
7588
7650
  function parseAndExtractModule(projectDir, filePath, content, babel, resolveImport, options) {
@@ -7598,7 +7660,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
7598
7660
  if (!ast) return null;
7599
7661
  const imports = /* @__PURE__ */ new Map();
7600
7662
  const rawBindings = /* @__PURE__ */ new Map();
7601
- const bindings = /* @__PURE__ */ new Map();
7663
+ const bindings = new LazyBindings();
7602
7664
  const styleNames = /* @__PURE__ */ new Set();
7603
7665
  const styleMetas = /* @__PURE__ */ new Map();
7604
7666
  const fileId = getProjectFileId$1(projectDir, filePath);
@@ -7679,9 +7741,9 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
7679
7741
  }
7680
7742
  if (stmt.type === "ExportAllDeclaration") {
7681
7743
  const exported = resolveImport(stmt.source.value, filePath);
7682
- if (exported) exported.forEach((value, key) => {
7683
- if (key !== "default") bindings.set(key, value);
7684
- });
7744
+ if (exported) {
7745
+ for (const key of exported.keys()) if (key !== "default") bindings.setLazy(key, () => exported.get(key));
7746
+ }
7685
7747
  }
7686
7748
  if (stmt.type === "ExportDefaultDeclaration") rawBindings.set("default", stmt.declaration);
7687
7749
  }
@@ -7697,7 +7759,11 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
7697
7759
  bindingNodes: rawBindings
7698
7760
  };
7699
7761
  rawBindings.forEach((node, name) => {
7700
- bindings.set(name, evaluateResolvedNode(node, scope, styleNames, fileId, options));
7762
+ bindings.setLazy(name, () => {
7763
+ const imported = imports.get(name);
7764
+ if (imported && node.type === "Identifier" && node.name === name) return resolveImport(imported.source, filePath)?.get(imported.name) ?? evalFail(`Cannot resolve export: ${name}`);
7765
+ return evaluateResolvedNode(node, scope, styleNames, fileId, options);
7766
+ });
7701
7767
  });
7702
7768
  return bindings;
7703
7769
  }
@@ -7865,33 +7931,23 @@ function hashContent(content) {
7865
7931
  function addTraceDependency(dependencies, dependency) {
7866
7932
  dependencies.set(dependency.filePath, dependency);
7867
7933
  }
7868
- function createTrackedBindings(traced, dependencies) {
7934
+ function createTrackedBindings(traced, dependencies, onTrack) {
7869
7935
  const track = () => {
7870
7936
  addTraceDependency(dependencies, traced);
7871
7937
  traced.dependencies.forEach((dependency) => addTraceDependency(dependencies, dependency));
7938
+ onTrack();
7872
7939
  };
7873
- return new class extends Map {
7874
- constructor() {
7875
- super(traced.bindings);
7876
- }
7877
- get(key) {
7878
- const value = super.get(key);
7879
- if (value !== void 0 || super.has(key)) track();
7880
- return value;
7881
- }
7882
- has(key) {
7883
- const result = super.has(key);
7884
- if (result) track();
7885
- return result;
7886
- }
7887
- forEach(callbackfn, thisArg) {
7888
- track();
7889
- super.forEach(callbackfn, thisArg);
7890
- }
7891
- }();
7940
+ const bindings = new LazyBindings();
7941
+ for (const key of traced.bindings.keys()) bindings.setLazy(key, () => {
7942
+ const value = traced.bindings.get(key);
7943
+ track();
7944
+ return value;
7945
+ });
7946
+ track();
7947
+ return bindings;
7892
7948
  }
7893
- function areDependenciesFresh(dependencies) {
7894
- for (const dependency of dependencies) if (hashFileContent(dependency.filePath) !== dependency.contentHash) return false;
7949
+ function areDependenciesFresh(dependencies, getHash) {
7950
+ for (const dependency of dependencies) if (getHash(dependency.filePath) !== dependency.contentHash) return false;
7895
7951
  return true;
7896
7952
  }
7897
7953
  function hashFileContent(filePath) {
@@ -8418,7 +8474,7 @@ function createExtractPlugin(args) {
8418
8474
  this.styleNames = /* @__PURE__ */ new Set();
8419
8475
  this.sheetNames = /* @__PURE__ */ new Set();
8420
8476
  this.styleMetas = /* @__PURE__ */ new Map();
8421
- this.bindings = /* @__PURE__ */ new Map();
8477
+ this.bindings = new LazyBindings();
8422
8478
  this.bindingNodes = /* @__PURE__ */ new Map();
8423
8479
  this.imports = /* @__PURE__ */ new Map();
8424
8480
  this.needsExtractImport = false;
@@ -8473,10 +8529,7 @@ function createExtractPlugin(args) {
8473
8529
  annotateTokenDeclaration(decl, state, t);
8474
8530
  annotateAtRuleDeclaration(decl, state, t);
8475
8531
  const name = decl.id.name;
8476
- const scope = getEvalScope(state);
8477
- const result = evaluateNode(decl.init, scope);
8478
- state.bindings.set(name, result);
8479
- state.bindingNodes.set(name, decl.init);
8532
+ recordLazyBinding(state, name, t.cloneNode(decl.init, true));
8480
8533
  });
8481
8534
  },
8482
8535
  ExportNamedDeclaration(path, state) {
@@ -8487,10 +8540,7 @@ function createExtractPlugin(args) {
8487
8540
  annotateTokenDeclaration(decl, state, t);
8488
8541
  annotateAtRuleDeclaration(decl, state, t);
8489
8542
  const name = decl.id.name;
8490
- const scope = getEvalScope(state);
8491
- const result = evaluateNode(decl.init, scope);
8492
- state.bindings.set(name, result);
8493
- state.bindingNodes.set(name, decl.init);
8543
+ recordLazyBinding(state, name, t.cloneNode(decl.init, true));
8494
8544
  });
8495
8545
  },
8496
8546
  TSEnumDeclaration(path, state) {
@@ -8589,6 +8639,18 @@ function createExtractPlugin(args) {
8589
8639
  };
8590
8640
  });
8591
8641
  }
8642
+ function recordLazyBinding(state, name, initializer) {
8643
+ const bindings = state.bindings.fork();
8644
+ const scope = {
8645
+ ...getEvalScope(state),
8646
+ bindings,
8647
+ bindingNodes: new Map(state.bindingNodes),
8648
+ imports: new Map(state.imports)
8649
+ };
8650
+ bindings.setLazy(name, () => evaluateNode(initializer, scope));
8651
+ state.bindings.setLazy(name, () => bindings.get(name));
8652
+ state.bindingNodes.set(name, initializer);
8653
+ }
8592
8654
  function checkCompiledImportantUsage(result, options, report) {
8593
8655
  if (!options) return;
8594
8656
  let hasRawValue = false;
@@ -8871,9 +8933,11 @@ function createCompiler(args, options) {
8871
8933
  const tracer = createTracer(internal);
8872
8934
  const collector = createCssCollector();
8873
8935
  const compileDebug = (args) => {
8936
+ tracer.beginCompilation();
8874
8937
  return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
8875
8938
  };
8876
8939
  const compileDebugRSC = (args) => {
8940
+ tracer.beginCompilation();
8877
8941
  const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
8878
8942
  if (!debugResult) return null;
8879
8943
  const rscCollector = createCssCollector();
@@ -8894,6 +8958,7 @@ function createCompiler(args, options) {
8894
8958
  };
8895
8959
  };
8896
8960
  const compileExtract = (args) => {
8961
+ tracer.beginCompilation();
8897
8962
  const startIndex = collector.getItems().length;
8898
8963
  const result = transformExtract(internal, args, {
8899
8964
  collector,
@@ -8941,6 +9006,7 @@ function rewriteTransformResult(result, runtimeMode, sourceCode) {
8941
9006
  };
8942
9007
  }
8943
9008
  function rewriteCompilerRuntimeImports(code, runtimeMode, sourceCode) {
9009
+ if (!code.includes("@fluentic/style") && !code.includes("\\")) return code;
8944
9010
  const importRuntimeMode = getImportRuntimeMode(runtimeMode, sourceCode);
8945
9011
  return rewriteImportSources(code, (source) => getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode));
8946
9012
  }
@@ -9003,4 +9069,4 @@ const CssPropPresets = {
9003
9069
  //#endregion
9004
9070
  export { getDefaultSourcemapUrl as a, getStyleFnMeta as c, babelTransform as d, extractCss as f, createCompilerCache as g, globalData as h, CompilerRuntimeMode as i, isPromiseLike as l, SIDECAR_URL_GLOBAL_SYMBOL as m, createCompiler as n, normalizeSourcemapSourcePath as o, compareLayerPriority as p, getStyleRuntimeImportPath as r, normalizePath as s, CssPropPresets as t, babelPlugin as u };
9005
9071
 
9006
- //# sourceMappingURL=compiler-AOb_VaKQ.mjs.map
9072
+ //# sourceMappingURL=compiler-Cat8TmMk.mjs.map