zyzz 0.0.27 → 0.0.29

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 (320) hide show
  1. package/binding/wasi/wasi-worker.mjs +186 -0
  2. package/binding/wasi/zyzz.wasi.cjs +2302 -0
  3. package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
  4. package/binding/zyzz.linux-x64-gnu.node +0 -0
  5. package/dist/babel/index.d.ts.map +1 -1
  6. package/dist/babel/index.js +2 -4
  7. package/dist/babel/index.js.map +1 -1
  8. package/dist/babel/internal/Compilation.d.ts +0 -1
  9. package/dist/babel/internal/Compilation.d.ts.map +1 -1
  10. package/dist/compiler/Graph.d.ts +14 -11
  11. package/dist/compiler/Graph.d.ts.map +1 -1
  12. package/dist/compiler/Graph.js +57 -1442
  13. package/dist/compiler/Graph.js.map +1 -1
  14. package/dist/compiler/Native.d.ts +7 -9
  15. package/dist/compiler/Native.d.ts.map +1 -1
  16. package/dist/compiler/Native.js +12 -716
  17. package/dist/compiler/Native.js.map +1 -1
  18. package/dist/compiler/Source.d.ts +122 -24
  19. package/dist/compiler/Source.d.ts.map +1 -1
  20. package/dist/compiler/Source.js +10 -1113
  21. package/dist/compiler/Source.js.map +1 -1
  22. package/dist/compiler/Transform.d.ts +4 -3
  23. package/dist/compiler/Transform.d.ts.map +1 -1
  24. package/dist/compiler/Transform.js +13 -958
  25. package/dist/compiler/Transform.js.map +1 -1
  26. package/dist/compiler/internal/AtRules.d.ts +5 -1
  27. package/dist/compiler/internal/AtRules.d.ts.map +1 -1
  28. package/dist/compiler/internal/AtRules.js +12 -106
  29. package/dist/compiler/internal/AtRules.js.map +1 -1
  30. package/dist/compiler/internal/Context.d.ts +11 -0
  31. package/dist/compiler/internal/Context.d.ts.map +1 -0
  32. package/dist/compiler/internal/Context.js +11 -0
  33. package/dist/compiler/internal/Context.js.map +1 -0
  34. package/dist/compiler/internal/Results.d.ts +148 -0
  35. package/dist/compiler/internal/Results.d.ts.map +1 -0
  36. package/dist/compiler/internal/Results.js +259 -0
  37. package/dist/compiler/internal/Results.js.map +1 -0
  38. package/dist/compiler/internal/Syntax.d.ts +0 -2
  39. package/dist/compiler/internal/Syntax.d.ts.map +1 -1
  40. package/dist/compiler/internal/Syntax.js +0 -2
  41. package/dist/compiler/internal/Syntax.js.map +1 -1
  42. package/dist/compiler/internal/Wire.d.ts +17 -0
  43. package/dist/compiler/internal/Wire.d.ts.map +1 -0
  44. package/dist/compiler/internal/Wire.js +795 -0
  45. package/dist/compiler/internal/Wire.js.map +1 -0
  46. package/dist/internal/Addon.d.ts +28 -0
  47. package/dist/internal/Addon.d.ts.map +1 -0
  48. package/dist/internal/Addon.js +87 -0
  49. package/dist/internal/Addon.js.map +1 -0
  50. package/dist/internal/Authoring.d.ts.map +1 -1
  51. package/dist/internal/Authoring.js +37 -7
  52. package/dist/internal/Authoring.js.map +1 -1
  53. package/dist/internal/Configuration.d.ts +6 -1
  54. package/dist/internal/Configuration.d.ts.map +1 -1
  55. package/dist/internal/Configuration.js.map +1 -1
  56. package/dist/internal/Literal.d.ts +5 -2
  57. package/dist/internal/Literal.d.ts.map +1 -1
  58. package/dist/internal/Literal.js +7 -2
  59. package/dist/internal/Literal.js.map +1 -1
  60. package/dist/internal/Theme.d.ts +4 -0
  61. package/dist/internal/Theme.d.ts.map +1 -1
  62. package/dist/internal/Theme.js.map +1 -1
  63. package/dist/internal/Token.d.ts +2 -1
  64. package/dist/internal/Token.d.ts.map +1 -1
  65. package/dist/internal/Token.js +2 -2
  66. package/dist/internal/Token.js.map +1 -1
  67. package/dist/internal/Vlq.d.ts +14 -0
  68. package/dist/internal/Vlq.d.ts.map +1 -0
  69. package/dist/internal/Vlq.js +47 -0
  70. package/dist/internal/Vlq.js.map +1 -0
  71. package/dist/internal/Wasm.d.ts +22 -0
  72. package/dist/internal/Wasm.d.ts.map +1 -0
  73. package/dist/internal/Wasm.js +83 -0
  74. package/dist/internal/Wasm.js.map +1 -0
  75. package/dist/metro/Graph.d.ts +0 -1
  76. package/dist/metro/Graph.d.ts.map +1 -1
  77. package/dist/metro/transformer.d.ts.map +1 -1
  78. package/dist/metro/transformer.js +0 -1
  79. package/dist/metro/transformer.js.map +1 -1
  80. package/dist/next/internal/Project.d.ts.map +1 -1
  81. package/dist/next/internal/Project.js +2 -5
  82. package/dist/next/internal/Project.js.map +1 -1
  83. package/dist/node/Host.d.ts.map +1 -1
  84. package/dist/node/Host.js +0 -2
  85. package/dist/node/Host.js.map +1 -1
  86. package/dist/node/internal/Contracts.d.ts.map +1 -1
  87. package/dist/node/internal/Contracts.js +3 -7
  88. package/dist/node/internal/Contracts.js.map +1 -1
  89. package/dist/node/internal/Snapshot.d.ts +0 -1
  90. package/dist/node/internal/Snapshot.d.ts.map +1 -1
  91. package/dist/node/internal/Snapshot.js +0 -6
  92. package/dist/node/internal/Snapshot.js.map +1 -1
  93. package/dist/runtime/Composition.d.ts +2 -3
  94. package/dist/runtime/Composition.d.ts.map +1 -1
  95. package/dist/runtime/Composition.js +51 -30
  96. package/dist/runtime/Composition.js.map +1 -1
  97. package/dist/runtime/Recipe.d.ts.map +1 -1
  98. package/dist/runtime/Recipe.js +16 -12
  99. package/dist/runtime/Recipe.js.map +1 -1
  100. package/dist/styleFunction.d.ts +11 -2
  101. package/dist/styleFunction.d.ts.map +1 -1
  102. package/dist/styleFunction.js +3 -1
  103. package/dist/styleFunction.js.map +1 -1
  104. package/dist/unplugin/index.d.ts.map +1 -1
  105. package/dist/unplugin/index.js +3 -6
  106. package/dist/unplugin/index.js.map +1 -1
  107. package/dist/vite/index.d.ts +7 -0
  108. package/dist/vite/index.d.ts.map +1 -1
  109. package/dist/vite/index.js +862 -216
  110. package/dist/vite/index.js.map +1 -1
  111. package/dist/web/Css.d.ts +8 -3
  112. package/dist/web/Css.d.ts.map +1 -1
  113. package/dist/web/Css.js +5 -721
  114. package/dist/web/Css.js.map +1 -1
  115. package/dist/web/internal/Block.d.ts +0 -2
  116. package/dist/web/internal/Block.d.ts.map +1 -1
  117. package/dist/web/internal/Block.js +1 -12
  118. package/dist/web/internal/Block.js.map +1 -1
  119. package/dist/web/internal/ClassName.d.ts +23 -18
  120. package/dist/web/internal/ClassName.d.ts.map +1 -1
  121. package/dist/web/internal/ClassName.js +26 -55
  122. package/dist/web/internal/ClassName.js.map +1 -1
  123. package/dist/web/internal/Contributions.d.ts +3 -5
  124. package/dist/web/internal/Contributions.d.ts.map +1 -1
  125. package/dist/web/internal/Contributions.js +0 -45
  126. package/dist/web/internal/Contributions.js.map +1 -1
  127. package/dist/web/internal/Engine.browser.d.ts +8 -0
  128. package/dist/web/internal/Engine.browser.d.ts.map +1 -0
  129. package/dist/web/internal/Engine.browser.js +42 -0
  130. package/dist/web/internal/Engine.browser.js.map +1 -0
  131. package/dist/web/internal/Engine.d.ts +9 -0
  132. package/dist/web/internal/Engine.d.ts.map +1 -0
  133. package/dist/web/internal/Engine.js +14 -0
  134. package/dist/web/internal/Engine.js.map +1 -0
  135. package/dist/web/internal/Themes.d.ts +1 -9
  136. package/dist/web/internal/Themes.d.ts.map +1 -1
  137. package/dist/web/internal/Themes.js +3 -221
  138. package/dist/web/internal/Themes.js.map +1 -1
  139. package/dist/web/internal/Wasm.generated.d.ts +4 -0
  140. package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
  141. package/dist/web/internal/Wasm.generated.js +4 -0
  142. package/dist/web/internal/Wasm.generated.js.map +1 -0
  143. package/dist/web/internal/Wire.d.ts +19 -0
  144. package/dist/web/internal/Wire.d.ts.map +1 -0
  145. package/dist/web/internal/Wire.js +387 -0
  146. package/dist/web/internal/Wire.js.map +1 -0
  147. package/package.json +20 -1
  148. package/src/babel/index.ts +2 -5
  149. package/src/babel/internal/Compilation.ts +0 -1
  150. package/src/compiler/Graph.ts +89 -1930
  151. package/src/compiler/Native.ts +18 -871
  152. package/src/compiler/Source.ts +144 -1579
  153. package/src/compiler/Transform.ts +16 -1312
  154. package/src/compiler/internal/AtRules.ts +27 -115
  155. package/src/compiler/internal/Context.ts +11 -0
  156. package/src/compiler/internal/Results.ts +406 -0
  157. package/src/compiler/internal/Syntax.ts +0 -3
  158. package/src/compiler/internal/Wire.ts +1045 -0
  159. package/src/internal/Addon.ts +118 -0
  160. package/src/internal/Authoring.ts +53 -18
  161. package/src/internal/Configuration.ts +38 -1
  162. package/src/internal/Literal.ts +7 -2
  163. package/src/internal/Theme.ts +15 -0
  164. package/src/internal/Token.ts +2 -2
  165. package/src/internal/Vlq.ts +59 -0
  166. package/src/internal/Wasm.ts +111 -0
  167. package/src/metro/transformer.ts +0 -1
  168. package/src/next/internal/Project.ts +2 -9
  169. package/src/node/Host.ts +0 -2
  170. package/src/node/internal/Contracts.ts +3 -7
  171. package/src/node/internal/Snapshot.ts +0 -8
  172. package/src/runtime/Composition.ts +48 -25
  173. package/src/runtime/Recipe.ts +21 -14
  174. package/src/styleFunction.ts +31 -2
  175. package/src/unplugin/index.ts +6 -6
  176. package/src/vite/index.ts +1157 -241
  177. package/src/web/Css.ts +12 -908
  178. package/src/web/internal/Block.ts +0 -14
  179. package/src/web/internal/ClassName.ts +52 -85
  180. package/src/web/internal/Contributions.ts +3 -59
  181. package/src/web/internal/Engine.browser.ts +51 -0
  182. package/src/web/internal/Engine.ts +17 -0
  183. package/src/web/internal/Themes.ts +3 -279
  184. package/src/web/internal/Wasm.generated.ts +3 -0
  185. package/src/web/internal/Wire.ts +466 -0
  186. package/src/web/internal/wasm.d.ts +9 -0
  187. package/dist/compiler/internal/Applications.d.ts +0 -55
  188. package/dist/compiler/internal/Applications.d.ts.map +0 -1
  189. package/dist/compiler/internal/Applications.js +0 -352
  190. package/dist/compiler/internal/Applications.js.map +0 -1
  191. package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
  192. package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
  193. package/dist/compiler/internal/ColorProfiles.js +0 -84
  194. package/dist/compiler/internal/ColorProfiles.js.map +0 -1
  195. package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
  196. package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
  197. package/dist/compiler/internal/CompositionBindings.js +0 -89
  198. package/dist/compiler/internal/CompositionBindings.js.map +0 -1
  199. package/dist/compiler/internal/Compositions.d.ts +0 -37
  200. package/dist/compiler/internal/Compositions.d.ts.map +0 -1
  201. package/dist/compiler/internal/Compositions.js +0 -494
  202. package/dist/compiler/internal/Compositions.js.map +0 -1
  203. package/dist/compiler/internal/Configurations.d.ts +0 -26
  204. package/dist/compiler/internal/Configurations.d.ts.map +0 -1
  205. package/dist/compiler/internal/Configurations.js +0 -259
  206. package/dist/compiler/internal/Configurations.js.map +0 -1
  207. package/dist/compiler/internal/Contract.d.ts +0 -30
  208. package/dist/compiler/internal/Contract.d.ts.map +0 -1
  209. package/dist/compiler/internal/Contract.js +0 -753
  210. package/dist/compiler/internal/Contract.js.map +0 -1
  211. package/dist/compiler/internal/Contributions.d.ts +0 -54
  212. package/dist/compiler/internal/Contributions.d.ts.map +0 -1
  213. package/dist/compiler/internal/Contributions.js +0 -1151
  214. package/dist/compiler/internal/Contributions.js.map +0 -1
  215. package/dist/compiler/internal/Descriptors.d.ts +0 -15
  216. package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
  217. package/dist/compiler/internal/Descriptors.js +0 -192
  218. package/dist/compiler/internal/Descriptors.js.map +0 -1
  219. package/dist/compiler/internal/Dynamic.d.ts +0 -14
  220. package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
  221. package/dist/compiler/internal/Dynamic.js +0 -175
  222. package/dist/compiler/internal/Dynamic.js.map +0 -1
  223. package/dist/compiler/internal/Expression.d.ts +0 -19
  224. package/dist/compiler/internal/Expression.d.ts.map +0 -1
  225. package/dist/compiler/internal/Expression.js +0 -164
  226. package/dist/compiler/internal/Expression.js.map +0 -1
  227. package/dist/compiler/internal/Functions.d.ts +0 -5
  228. package/dist/compiler/internal/Functions.d.ts.map +0 -1
  229. package/dist/compiler/internal/Functions.js +0 -191
  230. package/dist/compiler/internal/Functions.js.map +0 -1
  231. package/dist/compiler/internal/Keyframes.d.ts +0 -5
  232. package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
  233. package/dist/compiler/internal/Keyframes.js +0 -51
  234. package/dist/compiler/internal/Keyframes.js.map +0 -1
  235. package/dist/compiler/internal/Names.d.ts +0 -5
  236. package/dist/compiler/internal/Names.d.ts.map +0 -1
  237. package/dist/compiler/internal/Names.js +0 -37
  238. package/dist/compiler/internal/Names.js.map +0 -1
  239. package/dist/compiler/internal/NativeBindings.d.ts +0 -72
  240. package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
  241. package/dist/compiler/internal/NativeBindings.js +0 -171
  242. package/dist/compiler/internal/NativeBindings.js.map +0 -1
  243. package/dist/compiler/internal/NativeMedia.d.ts +0 -14
  244. package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
  245. package/dist/compiler/internal/NativeMedia.js +0 -287
  246. package/dist/compiler/internal/NativeMedia.js.map +0 -1
  247. package/dist/compiler/internal/NativeVars.d.ts +0 -28
  248. package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
  249. package/dist/compiler/internal/NativeVars.js +0 -160
  250. package/dist/compiler/internal/NativeVars.js.map +0 -1
  251. package/dist/compiler/internal/PackedStyles.d.ts +0 -37
  252. package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
  253. package/dist/compiler/internal/PackedStyles.js +0 -344
  254. package/dist/compiler/internal/PackedStyles.js.map +0 -1
  255. package/dist/compiler/internal/Properties.d.ts +0 -5
  256. package/dist/compiler/internal/Properties.d.ts.map +0 -1
  257. package/dist/compiler/internal/Properties.js +0 -82
  258. package/dist/compiler/internal/Properties.js.map +0 -1
  259. package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
  260. package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
  261. package/dist/compiler/internal/RecipeConditions.js +0 -82
  262. package/dist/compiler/internal/RecipeConditions.js.map +0 -1
  263. package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
  264. package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
  265. package/dist/compiler/internal/RecipePayloads.js +0 -99
  266. package/dist/compiler/internal/RecipePayloads.js.map +0 -1
  267. package/dist/compiler/internal/Recipes.d.ts +0 -32
  268. package/dist/compiler/internal/Recipes.d.ts.map +0 -1
  269. package/dist/compiler/internal/Recipes.js +0 -339
  270. package/dist/compiler/internal/Recipes.js.map +0 -1
  271. package/dist/compiler/internal/Selectors.d.ts +0 -12
  272. package/dist/compiler/internal/Selectors.d.ts.map +0 -1
  273. package/dist/compiler/internal/Selectors.js +0 -268
  274. package/dist/compiler/internal/Selectors.js.map +0 -1
  275. package/dist/compiler/internal/Static.d.ts +0 -39
  276. package/dist/compiler/internal/Static.d.ts.map +0 -1
  277. package/dist/compiler/internal/Static.js +0 -534
  278. package/dist/compiler/internal/Static.js.map +0 -1
  279. package/dist/compiler/internal/Themes.d.ts +0 -190
  280. package/dist/compiler/internal/Themes.d.ts.map +0 -1
  281. package/dist/compiler/internal/Themes.js +0 -1577
  282. package/dist/compiler/internal/Themes.js.map +0 -1
  283. package/dist/compiler/internal/Vars.d.ts +0 -33
  284. package/dist/compiler/internal/Vars.d.ts.map +0 -1
  285. package/dist/compiler/internal/Vars.js +0 -387
  286. package/dist/compiler/internal/Vars.js.map +0 -1
  287. package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
  288. package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
  289. package/dist/compiler/internal/ViewTransitions.js +0 -68
  290. package/dist/compiler/internal/ViewTransitions.js.map +0 -1
  291. package/dist/internal/Cascade.d.ts +0 -74
  292. package/dist/internal/Cascade.d.ts.map +0 -1
  293. package/dist/internal/Cascade.js +0 -210
  294. package/dist/internal/Cascade.js.map +0 -1
  295. package/src/compiler/internal/Applications.ts +0 -554
  296. package/src/compiler/internal/ColorProfiles.ts +0 -93
  297. package/src/compiler/internal/CompositionBindings.ts +0 -120
  298. package/src/compiler/internal/Compositions.ts +0 -678
  299. package/src/compiler/internal/Configurations.ts +0 -349
  300. package/src/compiler/internal/Contract.ts +0 -1028
  301. package/src/compiler/internal/Contributions.ts +0 -1561
  302. package/src/compiler/internal/Descriptors.ts +0 -242
  303. package/src/compiler/internal/Dynamic.ts +0 -275
  304. package/src/compiler/internal/Expression.ts +0 -218
  305. package/src/compiler/internal/Functions.ts +0 -206
  306. package/src/compiler/internal/Keyframes.ts +0 -62
  307. package/src/compiler/internal/Names.ts +0 -48
  308. package/src/compiler/internal/NativeBindings.ts +0 -235
  309. package/src/compiler/internal/NativeMedia.ts +0 -342
  310. package/src/compiler/internal/NativeVars.ts +0 -231
  311. package/src/compiler/internal/PackedStyles.ts +0 -473
  312. package/src/compiler/internal/Properties.ts +0 -121
  313. package/src/compiler/internal/RecipeConditions.ts +0 -139
  314. package/src/compiler/internal/RecipePayloads.ts +0 -132
  315. package/src/compiler/internal/Recipes.ts +0 -531
  316. package/src/compiler/internal/Selectors.ts +0 -339
  317. package/src/compiler/internal/Static.ts +0 -784
  318. package/src/compiler/internal/Themes.ts +0 -2398
  319. package/src/compiler/internal/Vars.ts +0 -516
  320. package/src/compiler/internal/ViewTransitions.ts +0 -82
@@ -1,554 +0,0 @@
1
- /** Finds nonescaping local static callables whose applications can become props. @module */
2
- import type * as Ast from '@oxc-project/types'
3
- import * as Walker from 'oxc-walker'
4
- import * as Scope from './Scope.js'
5
- import type * as Source from '../Source.js'
6
-
7
- /** Conservatively proves direct applications without changing binding reads. */
8
- export function create(
9
- program: Ast.Program,
10
- calls: readonly Source.Call[],
11
- options: create.Options = {},
12
- ): Collector | undefined {
13
- const definitions = new Map(calls.map((call) => [call.start, call]))
14
- const memberBindings = new Map<number, string>()
15
- const referencedDefinitions = new Set<string>()
16
- const namespaceCounts = new Map<string, number>()
17
-
18
- for (const statement of program.body) {
19
- const node =
20
- statement.type === 'ExportNamedDeclaration'
21
- ? statement.declaration
22
- : statement
23
-
24
- if (node?.type === 'TSModuleDeclaration' && node.id.type === 'Identifier')
25
- namespaceCounts.set(
26
- node.id.name,
27
- (namespaceCounts.get(node.id.name) ?? 0) + 1,
28
- )
29
- }
30
-
31
- const candidates: {
32
- declaration: {
33
- id: Extract<Ast.Node, { type: 'Identifier' }>
34
- }
35
- direct: Source.Call | undefined
36
- members: Map<string, Source.Call>
37
- /** Namespace statement start and member identifier ends by extracted name. */
38
- namespace?: Namespace | undefined
39
- /** Offset after which top-level reads observe an initialized binding. */
40
- ready: number
41
- }[] = []
42
-
43
- for (const statement of program.body) {
44
- if (
45
- statement.type === 'TSModuleDeclaration' &&
46
- statement.id.type === 'Identifier' &&
47
- statement.body?.type === 'TSModuleBlock'
48
- ) {
49
- const members = new Map<string, Source.Call>()
50
- const ends = new Map<string, number>()
51
- let valid = true
52
-
53
- for (const member of statement.body.body) {
54
- const node =
55
- member.type === 'ExportNamedDeclaration'
56
- ? member.declaration
57
- : undefined
58
-
59
- if (node?.type !== 'VariableDeclaration' || node.kind !== 'const') {
60
- valid = false
61
- break
62
- }
63
-
64
- for (const declaration of node.declarations) {
65
- const call =
66
- declaration.init && definitions.get(declaration.init.start)
67
-
68
- if (
69
- declaration.id.type !== 'Identifier' ||
70
- declaration.init?.type !== 'CallExpression' ||
71
- declaration.init.end !== call?.end ||
72
- members.has(declaration.id.name)
73
- ) {
74
- valid = false
75
- break
76
- }
77
-
78
- members.set(declaration.id.name, call)
79
- ends.set(call.name, declaration.id.end)
80
- memberBindings.set(declaration.id.start, call.name)
81
- }
82
- }
83
-
84
- if (valid && members.size)
85
- candidates.push({
86
- declaration: { id: statement.id },
87
- direct: undefined,
88
- members,
89
- namespace: { ends, start: statement.start },
90
- ready: statement.end,
91
- })
92
-
93
- continue
94
- }
95
-
96
- // Exported values can escape and object members can subsequently be replaced.
97
- if (statement.type !== 'VariableDeclaration' || statement.kind !== 'const')
98
- continue
99
-
100
- for (const declaration of statement.declarations) {
101
- if (declaration.id.type !== 'Identifier' || !declaration.init) continue
102
-
103
- const members = new Map<string, Source.Call>()
104
- const candidate = definitions.get(declaration.init.start)
105
-
106
- const direct =
107
- declaration.init.type === 'CallExpression' &&
108
- declaration.init.end === candidate?.end
109
- ? candidate
110
- : undefined
111
-
112
- if (!direct) {
113
- if (declaration.init.type !== 'ObjectExpression') continue
114
-
115
- let valid = true
116
-
117
- for (const property of declaration.init.properties) {
118
- if (
119
- property.type !== 'Property' ||
120
- property.computed ||
121
- property.method ||
122
- property.kind !== 'init'
123
- ) {
124
- valid = false
125
- break
126
- }
127
-
128
- const key =
129
- property.key.type === 'Identifier' ? property.key.name : undefined
130
- const candidate = definitions.get(property.value.start)
131
-
132
- const call =
133
- property.value.type === 'CallExpression' &&
134
- property.value.end === candidate?.end
135
- ? candidate
136
- : undefined
137
-
138
- if (!key || key === '__proto__' || !call || members.has(key)) {
139
- valid = false
140
- break
141
- }
142
-
143
- members.set(key, call)
144
- }
145
-
146
- if (!valid || !members.size) continue
147
- }
148
-
149
- candidates.push({
150
- declaration: { ...declaration, id: declaration.id },
151
- direct,
152
- members,
153
- ready: declaration.end,
154
- })
155
- }
156
- }
157
-
158
- if (!candidates.length) return undefined
159
-
160
- const lexical = new Set<Ast.Node>()
161
- // Reads inside functions, classes, or namespaces may run before initialization.
162
- const deferred = new Set<Ast.Node>()
163
- const terminals = new Set<Ast.Node>()
164
- const scope = new Scope.Tracker({ preserveExitedScopes: true })
165
- Walker.walk(program, { scopeTracker: scope })
166
- scope.freeze()
167
- const ancestors: Ast.Node[] = []
168
- Walker.walk(program, {
169
- scopeTracker: scope,
170
- enter(node, parent) {
171
- ancestors.push(node)
172
- if (
173
- node.type !== 'Identifier' ||
174
- !parent ||
175
- !Walker.isReferenceIdentifier(node, parent)
176
- )
177
- return
178
- if (
179
- ancestors.some((node) =>
180
- [
181
- 'TSTypeQuery',
182
- 'TSTypeAnnotation',
183
- 'TSTypeAliasDeclaration',
184
- 'TSInterfaceDeclaration',
185
- 'TSTypeParameterInstantiation',
186
- 'TSTypeParameterDeclaration',
187
- ].includes(node.type),
188
- )
189
- )
190
- return
191
- const binding = scope.getDeclaration(node.name, { mode: 'value' })
192
- const id = binding?.node
193
- const member = id && memberBindings.get(id.start)
194
- if (member) referencedDefinitions.add(member)
195
- if (
196
- id &&
197
- candidates.some(
198
- (candidate) => candidate.declaration.id.start === id.start,
199
- )
200
- ) {
201
- lexical.add(node)
202
- if (terminal(ancestors)) terminals.add(node)
203
- if (
204
- ancestors.some((node) =>
205
- [
206
- 'ArrowFunctionExpression',
207
- 'ClassDeclaration',
208
- 'ClassExpression',
209
- 'FunctionDeclaration',
210
- 'FunctionExpression',
211
- 'TSModuleDeclaration',
212
- ].includes(node.type),
213
- )
214
- )
215
- deferred.add(node)
216
- }
217
- },
218
- leave() {
219
- ancestors.pop()
220
- },
221
- })
222
-
223
- const parents = new Map<Ast.Node, Ast.Node>()
224
- const references = new Map<
225
- string,
226
- Extract<Ast.Node, { type: 'Identifier' }>[]
227
- >(candidates.map(({ declaration }) => [declaration.id.name, []]))
228
- let evaluation = false
229
-
230
- // Returns undefined when any read escapes. Recipes, dynamic styles, and
231
- // applications with overrides keep their runtime calls.
232
- function collect(candidate: (typeof candidates)[number]):
233
- | {
234
- readonly applications: readonly Application[]
235
- readonly called: ReadonlySet<string>
236
- }
237
- | undefined {
238
- const { declaration, direct, members } = candidate
239
- const applications: Application[] = []
240
- const called = new Set<string>()
241
-
242
- for (const reference of references.get(declaration.id.name) ?? []) {
243
- if (reference === declaration.id) continue
244
-
245
- let callee: Ast.Node = reference
246
- let call = direct
247
-
248
- if (!direct) {
249
- const member = parents.get(reference)
250
-
251
- if (
252
- member?.type !== 'MemberExpression' ||
253
- member.object !== reference ||
254
- member.computed ||
255
- member.optional ||
256
- member.property.type !== 'Identifier'
257
- )
258
- return undefined
259
-
260
- call = members.get(member.property.name)
261
- callee = member
262
- }
263
-
264
- if (
265
- call?.composition ||
266
- call?.runtimeComposition ||
267
- (!options.dynamic && (call?.slots || call?.recipe))
268
- )
269
- continue
270
-
271
- const application = parents.get(callee)
272
-
273
- if (
274
- !call ||
275
- application?.type !== 'CallExpression' ||
276
- application.callee !== callee ||
277
- application.optional
278
- )
279
- return undefined
280
-
281
- // An override needs the runtime callable, but exposes no other definition.
282
- if (!options.dynamic && application.arguments.length) {
283
- called.add(call.name)
284
- continue
285
- }
286
-
287
- applications.push({
288
- calleeEnd: callee.end,
289
- end: application.end,
290
- initialized:
291
- !deferred.has(reference) &&
292
- reference.start >= candidate.ready &&
293
- (!candidate.namespace ||
294
- namespaceCounts.get(declaration.id.name) === 1),
295
- name: call.name,
296
- start: application.start,
297
- terminal: terminals.has(reference),
298
- })
299
- }
300
-
301
- return { applications, called }
302
- }
303
-
304
- return {
305
- dead() {
306
- if (evaluation) return new Set<string>()
307
-
308
- const result = new Set<string>()
309
- const counts = new Map<string, number>()
310
-
311
- for (const { declaration } of candidates)
312
- counts.set(
313
- declaration.id.name,
314
- (counts.get(declaration.id.name) ?? 0) + 1,
315
- )
316
-
317
- for (const { declaration, direct, members } of candidates) {
318
- if (
319
- counts.get(declaration.id.name)! > 1 ||
320
- (namespaceCounts.get(declaration.id.name) ?? 0) > 1
321
- )
322
- continue
323
-
324
- const reads = references.get(declaration.id.name) ?? []
325
-
326
- if (direct) {
327
- if (!reads.length) result.add(direct.name)
328
- continue
329
- }
330
-
331
- const used = new Set<string>()
332
- let escapes = false
333
-
334
- for (const reference of reads) {
335
- const member = parents.get(reference)
336
-
337
- if (
338
- member?.type !== 'MemberExpression' ||
339
- member.object !== reference ||
340
- member.computed ||
341
- member.optional ||
342
- member.property.type !== 'Identifier'
343
- ) {
344
- escapes = true
345
- break
346
- }
347
-
348
- used.add(member.property.name)
349
- }
350
-
351
- if (!escapes)
352
- for (const [name, call] of members)
353
- if (!used.has(name) && !referencedDefinitions.has(call.name))
354
- result.add(call.name)
355
- }
356
-
357
- return result
358
- },
359
- definitions() {
360
- const namespaces: Namespace[] = []
361
- const values = new Map<string, boolean>()
362
-
363
- if (evaluation) return { namespaces, values }
364
-
365
- const counts = new Map<string, number>()
366
-
367
- for (const { declaration } of candidates)
368
- counts.set(
369
- declaration.id.name,
370
- (counts.get(declaration.id.name) ?? 0) + 1,
371
- )
372
-
373
- for (const candidate of candidates) {
374
- const name = candidate.declaration.id.name
375
- if (counts.get(name)! > 1 || (namespaceCounts.get(name) ?? 0) > 1)
376
- continue
377
-
378
- const result = collect(candidate)
379
- if (!result) continue
380
-
381
- let erased = !!candidate.namespace
382
-
383
- for (const call of candidate.direct
384
- ? [candidate.direct]
385
- : candidate.members.values()) {
386
- if (
387
- call.composition ||
388
- call.runtimeComposition ||
389
- call.slots ||
390
- call.recipe ||
391
- result.called.has(call.name)
392
- ) {
393
- erased = false
394
- continue
395
- }
396
-
397
- const initialized = result.applications.every(
398
- (application) =>
399
- application.name !== call.name || application.initialized,
400
- )
401
-
402
- values.set(call.name, initialized)
403
- erased &&= initialized
404
- }
405
-
406
- if (erased) namespaces.push(candidate.namespace!)
407
- }
408
-
409
- return { namespaces, values }
410
- },
411
- enter(node, parent) {
412
- if (
413
- node.type === 'MemberExpression' &&
414
- node.object.type === 'Identifier' &&
415
- references.has(node.object.name) &&
416
- parent
417
- )
418
- parents.set(node, parent)
419
-
420
- if (node.type !== 'Identifier') return
421
-
422
- if (node.name === 'eval') evaluation = true
423
-
424
- if (!lexical.has(node)) return
425
-
426
- const nodes = references.get(node.name)
427
- if (!nodes) return
428
-
429
- nodes.push(node)
430
-
431
- if (parent) parents.set(node, parent)
432
- },
433
- find() {
434
- if (evaluation) return []
435
-
436
- return candidates.flatMap(
437
- (candidate) => collect(candidate)?.applications ?? [],
438
- )
439
- },
440
- }
441
- }
442
-
443
- /** Proven call site and its compiled definition. */
444
- type Application = {
445
- /** End of the original binding or property read. */
446
- readonly calleeEnd: number
447
- /** End of the application. */
448
- readonly end: number
449
- /** Whether the read runs at top level after its definition initializes. */
450
- readonly initialized: boolean
451
- /** Extracted class identity. */
452
- readonly name: string
453
- /** Start of the application. */
454
- readonly start: number
455
- /** Whether a DOM element receives the props alone, so its classes meet no other style's. */
456
- readonly terminal: boolean
457
- }
458
-
459
- /** A top-level namespace whose members are all static definitions. */
460
- type Namespace = {
461
- /** Member identifier ends keyed by extracted name. */
462
- readonly ends: ReadonlyMap<string, number>
463
- /** Start of the namespace statement. */
464
- readonly start: number
465
- }
466
-
467
- /** Binding references gathered during the transform's existing walk. */
468
- type Collector = {
469
- /** Definitions with no observable value reads, retaining escaped containers. */
470
- dead: () => ReadonlySet<string>
471
- /**
472
- * Static definitions whose every read is a found application, keyed by
473
- * extracted name with whether every read is initialized. Namespaces list
474
- * those whose definitions all qualify with initialized reads.
475
- */
476
- definitions: () => {
477
- readonly namespaces: readonly Namespace[]
478
- readonly values: ReadonlyMap<string, boolean>
479
- }
480
- /** Records relevant reads and their immediate parents. */
481
- enter: (node: Ast.Node, parent: Ast.Node | null | undefined) => void
482
- /** Resolves applications after traversal completes. */
483
- find: () => readonly Application[]
484
- }
485
-
486
- /** Local application collection modes. */
487
- export declare namespace create {
488
- /** Controls whether arguments are retained for fixed runtime compositions. */
489
- type Options = {
490
- /** Includes recipe/value applications while preserving their runtime calls. */
491
- readonly dynamic?: boolean | undefined
492
- }
493
- }
494
-
495
- // Matches a no-argument application spread onto, or read as the class of, a DOM element.
496
- function terminal(path: readonly Ast.Node[]): boolean {
497
- let index = path.length - 1
498
- let node = path[index]
499
- const member = path[index - 1]
500
- if (member?.type === 'MemberExpression' && member.object === node)
501
- node = path[--index]
502
-
503
- const call = path[--index]
504
- if (
505
- call?.type !== 'CallExpression' ||
506
- call.callee !== node ||
507
- call.arguments.length
508
- )
509
- return false
510
-
511
- const parent = path[--index]
512
- if (parent?.type === 'JSXSpreadAttribute')
513
- return parent.argument === call && alone(path[index - 1], parent)
514
-
515
- if (
516
- parent?.type !== 'MemberExpression' ||
517
- parent.object !== call ||
518
- parent.computed ||
519
- parent.property.type !== 'Identifier' ||
520
- !/^class(?:Name)?$/.test(parent.property.name)
521
- )
522
- return false
523
-
524
- const container = path[--index]
525
- const attribute = path[--index]
526
- return (
527
- container?.type === 'JSXExpressionContainer' &&
528
- container.expression === parent &&
529
- attribute?.type === 'JSXAttribute' &&
530
- attribute.value === container &&
531
- attribute.name.type === 'JSXIdentifier' &&
532
- /^class(?:Name)?$/.test(attribute.name.name) &&
533
- alone(path[index - 1], attribute)
534
- )
535
- }
536
-
537
- // Other spreads or class attributes could add another style's classes.
538
- function alone(element: Ast.Node | undefined, own: Ast.Node): boolean {
539
- return (
540
- element?.type === 'JSXOpeningElement' &&
541
- element.name.type === 'JSXIdentifier' &&
542
- /^[a-z]/.test(element.name.name) &&
543
- element.attributes.every(
544
- (attribute) =>
545
- attribute === own ||
546
- (attribute.type === 'JSXAttribute' &&
547
- !(
548
- attribute.name.type === 'JSXIdentifier'
549
- ? attribute.name.name
550
- : attribute.name.namespace.name
551
- ).startsWith('class')),
552
- )
553
- )
554
- }
@@ -1,93 +0,0 @@
1
- /** Checks custom color-profile descriptors before source or packed publication. @module */
2
- import * as Lightning from 'lightningcss'
3
-
4
- /** Validates complete profile blocks, including decoded component and intent tokens. */
5
- export function validate(source: string): void {
6
- Lightning.transform({
7
- filename: 'color-profiles.css',
8
- code: new TextEncoder().encode(source),
9
- visitor: {
10
- Rule(rule) {
11
- if (rule.type !== 'unknown' || rule.value.name !== 'color-profile')
12
- return
13
- const name = rule.value.prelude[0]
14
- if (
15
- rule.value.prelude.length !== 1 ||
16
- !rule.value.block ||
17
- !(
18
- name?.type === 'dashed-ident' ||
19
- (name?.type === 'token' &&
20
- name.value.type === 'ident' &&
21
- name.value.value.toLowerCase() === 'device-cmyk')
22
- )
23
- )
24
- throw new Error('Expected a color-profile name and descriptor block.')
25
-
26
- let declaration: Lightning.TokenOrValue[] = []
27
- let src = false
28
- const flush = () => {
29
- if (!declaration.length) return
30
- const [name, colon, ...values] = declaration
31
- if (
32
- name?.type !== 'token' ||
33
- name.value.type !== 'ident' ||
34
- colon?.type !== 'token' ||
35
- colon.value.type !== 'colon'
36
- )
37
- throw new Error('Invalid color-profile descriptor.')
38
- const key = name.value.value.toLowerCase()
39
- if (key === 'src') {
40
- if (values.length !== 1 || values[0]?.type !== 'url')
41
- throw new Error('Color-profile src requires one URL.')
42
- src = true
43
- } else if (key === 'rendering-intent') {
44
- const token = values[0]
45
- if (
46
- values.length !== 1 ||
47
- token?.type !== 'token' ||
48
- token.value.type !== 'ident' ||
49
- ![
50
- 'absolute-colorimetric',
51
- 'relative-colorimetric',
52
- 'perceptual',
53
- 'saturation',
54
- ].includes(token.value.value.toLowerCase())
55
- )
56
- throw new Error('Invalid color-profile rendering intent.')
57
- } else if (key === 'components') {
58
- if (
59
- values.length % 2 !== 1 ||
60
- values.some((token, index) => {
61
- if (index % 2)
62
- return token.type !== 'token' || token.value.type !== 'comma'
63
- const name =
64
- token.type === 'dashed-ident'
65
- ? token.value
66
- : token.type === 'token' && token.value.type === 'ident'
67
- ? token.value.value
68
- : undefined
69
- return name === undefined || name.toLowerCase() === 'none'
70
- })
71
- )
72
- throw new Error(
73
- 'Color-profile components require comma-separated identifiers other than none.',
74
- )
75
- } else throw new Error('Unknown color-profile descriptor.')
76
- declaration = []
77
- }
78
- for (const token of rule.value.block) {
79
- if (
80
- token.type === 'token' &&
81
- ['white-space', 'comment'].includes(token.value.type)
82
- )
83
- continue
84
- if (token.type === 'token' && token.value.type === 'semicolon')
85
- flush()
86
- else declaration.push(token)
87
- }
88
- flush()
89
- if (!src) throw new Error('Color-profile requires a src descriptor.')
90
- },
91
- },
92
- })
93
- }