zyzz 0.0.28 → 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.
- package/binding/wasi/wasi-worker.mjs +186 -0
- package/binding/wasi/zyzz.wasi.cjs +2302 -0
- package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
- package/binding/zyzz.linux-x64-gnu.node +0 -0
- package/dist/babel/index.d.ts.map +1 -1
- package/dist/babel/index.js +2 -4
- package/dist/babel/index.js.map +1 -1
- package/dist/babel/internal/Compilation.d.ts +0 -1
- package/dist/babel/internal/Compilation.d.ts.map +1 -1
- package/dist/compiler/Graph.d.ts +14 -11
- package/dist/compiler/Graph.d.ts.map +1 -1
- package/dist/compiler/Graph.js +57 -1442
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Native.d.ts +7 -9
- package/dist/compiler/Native.d.ts.map +1 -1
- package/dist/compiler/Native.js +12 -716
- package/dist/compiler/Native.js.map +1 -1
- package/dist/compiler/Source.d.ts +122 -24
- package/dist/compiler/Source.d.ts.map +1 -1
- package/dist/compiler/Source.js +10 -1267
- package/dist/compiler/Source.js.map +1 -1
- package/dist/compiler/Transform.d.ts +4 -3
- package/dist/compiler/Transform.d.ts.map +1 -1
- package/dist/compiler/Transform.js +13 -961
- package/dist/compiler/Transform.js.map +1 -1
- package/dist/compiler/internal/AtRules.d.ts +5 -1
- package/dist/compiler/internal/AtRules.d.ts.map +1 -1
- package/dist/compiler/internal/AtRules.js +12 -106
- package/dist/compiler/internal/AtRules.js.map +1 -1
- package/dist/compiler/internal/Context.d.ts +11 -0
- package/dist/compiler/internal/Context.d.ts.map +1 -0
- package/dist/compiler/internal/Context.js +11 -0
- package/dist/compiler/internal/Context.js.map +1 -0
- package/dist/compiler/internal/Results.d.ts +148 -0
- package/dist/compiler/internal/Results.d.ts.map +1 -0
- package/dist/compiler/internal/Results.js +259 -0
- package/dist/compiler/internal/Results.js.map +1 -0
- package/dist/compiler/internal/Syntax.d.ts +0 -2
- package/dist/compiler/internal/Syntax.d.ts.map +1 -1
- package/dist/compiler/internal/Syntax.js +0 -2
- package/dist/compiler/internal/Syntax.js.map +1 -1
- package/dist/compiler/internal/Wire.d.ts +17 -0
- package/dist/compiler/internal/Wire.d.ts.map +1 -0
- package/dist/compiler/internal/Wire.js +795 -0
- package/dist/compiler/internal/Wire.js.map +1 -0
- package/dist/internal/Addon.d.ts +28 -0
- package/dist/internal/Addon.d.ts.map +1 -0
- package/dist/internal/Addon.js +87 -0
- package/dist/internal/Addon.js.map +1 -0
- package/dist/internal/Literal.d.ts +4 -1
- package/dist/internal/Literal.d.ts.map +1 -1
- package/dist/internal/Literal.js +4 -2
- package/dist/internal/Literal.js.map +1 -1
- package/dist/internal/Token.d.ts +2 -1
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js +2 -2
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Vlq.d.ts +14 -0
- package/dist/internal/Vlq.d.ts.map +1 -0
- package/dist/internal/Vlq.js +47 -0
- package/dist/internal/Vlq.js.map +1 -0
- package/dist/internal/Wasm.d.ts +22 -0
- package/dist/internal/Wasm.d.ts.map +1 -0
- package/dist/internal/Wasm.js +83 -0
- package/dist/internal/Wasm.js.map +1 -0
- package/dist/metro/Graph.d.ts +0 -1
- package/dist/metro/Graph.d.ts.map +1 -1
- package/dist/metro/transformer.d.ts.map +1 -1
- package/dist/metro/transformer.js +0 -1
- package/dist/metro/transformer.js.map +1 -1
- package/dist/next/internal/Project.d.ts.map +1 -1
- package/dist/next/internal/Project.js +2 -5
- package/dist/next/internal/Project.js.map +1 -1
- package/dist/node/Host.d.ts.map +1 -1
- package/dist/node/Host.js +0 -2
- package/dist/node/Host.js.map +1 -1
- package/dist/node/internal/Contracts.d.ts.map +1 -1
- package/dist/node/internal/Contracts.js +3 -7
- package/dist/node/internal/Contracts.js.map +1 -1
- package/dist/node/internal/Snapshot.d.ts +0 -1
- package/dist/node/internal/Snapshot.d.ts.map +1 -1
- package/dist/node/internal/Snapshot.js +0 -6
- package/dist/node/internal/Snapshot.js.map +1 -1
- package/dist/runtime/Composition.d.ts +2 -3
- package/dist/runtime/Composition.d.ts.map +1 -1
- package/dist/runtime/Composition.js +51 -30
- package/dist/runtime/Composition.js.map +1 -1
- package/dist/runtime/Recipe.d.ts.map +1 -1
- package/dist/runtime/Recipe.js +16 -12
- package/dist/runtime/Recipe.js.map +1 -1
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +3 -6
- package/dist/unplugin/index.js.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +696 -201
- package/dist/vite/index.js.map +1 -1
- package/dist/web/Css.d.ts +8 -3
- package/dist/web/Css.d.ts.map +1 -1
- package/dist/web/Css.js +5 -721
- package/dist/web/Css.js.map +1 -1
- package/dist/web/internal/Block.d.ts +0 -2
- package/dist/web/internal/Block.d.ts.map +1 -1
- package/dist/web/internal/Block.js +1 -12
- package/dist/web/internal/Block.js.map +1 -1
- package/dist/web/internal/ClassName.d.ts +23 -18
- package/dist/web/internal/ClassName.d.ts.map +1 -1
- package/dist/web/internal/ClassName.js +26 -55
- package/dist/web/internal/ClassName.js.map +1 -1
- package/dist/web/internal/Contributions.d.ts +3 -5
- package/dist/web/internal/Contributions.d.ts.map +1 -1
- package/dist/web/internal/Contributions.js +0 -45
- package/dist/web/internal/Contributions.js.map +1 -1
- package/dist/web/internal/Engine.browser.d.ts +8 -0
- package/dist/web/internal/Engine.browser.d.ts.map +1 -0
- package/dist/web/internal/Engine.browser.js +42 -0
- package/dist/web/internal/Engine.browser.js.map +1 -0
- package/dist/web/internal/Engine.d.ts +9 -0
- package/dist/web/internal/Engine.d.ts.map +1 -0
- package/dist/web/internal/Engine.js +14 -0
- package/dist/web/internal/Engine.js.map +1 -0
- package/dist/web/internal/Themes.d.ts +1 -9
- package/dist/web/internal/Themes.d.ts.map +1 -1
- package/dist/web/internal/Themes.js +3 -221
- package/dist/web/internal/Themes.js.map +1 -1
- package/dist/web/internal/Wasm.generated.d.ts +4 -0
- package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
- package/dist/web/internal/Wasm.generated.js +4 -0
- package/dist/web/internal/Wasm.generated.js.map +1 -0
- package/dist/web/internal/Wire.d.ts +19 -0
- package/dist/web/internal/Wire.d.ts.map +1 -0
- package/dist/web/internal/Wire.js +387 -0
- package/dist/web/internal/Wire.js.map +1 -0
- package/package.json +20 -1
- package/src/babel/index.ts +2 -5
- package/src/babel/internal/Compilation.ts +0 -1
- package/src/compiler/Graph.ts +89 -1930
- package/src/compiler/Native.ts +18 -871
- package/src/compiler/Source.ts +144 -1803
- package/src/compiler/Transform.ts +16 -1315
- package/src/compiler/internal/AtRules.ts +27 -115
- package/src/compiler/internal/Context.ts +11 -0
- package/src/compiler/internal/Results.ts +406 -0
- package/src/compiler/internal/Syntax.ts +0 -3
- package/src/compiler/internal/Wire.ts +1045 -0
- package/src/internal/Addon.ts +118 -0
- package/src/internal/Literal.ts +4 -2
- package/src/internal/Token.ts +2 -2
- package/src/internal/Vlq.ts +59 -0
- package/src/internal/Wasm.ts +111 -0
- package/src/metro/transformer.ts +0 -1
- package/src/next/internal/Project.ts +2 -9
- package/src/node/Host.ts +0 -2
- package/src/node/internal/Contracts.ts +3 -7
- package/src/node/internal/Snapshot.ts +0 -8
- package/src/runtime/Composition.ts +48 -25
- package/src/runtime/Recipe.ts +21 -14
- package/src/unplugin/index.ts +6 -6
- package/src/vite/index.ts +922 -221
- package/src/web/Css.ts +12 -908
- package/src/web/internal/Block.ts +0 -14
- package/src/web/internal/ClassName.ts +52 -85
- package/src/web/internal/Contributions.ts +3 -59
- package/src/web/internal/Engine.browser.ts +51 -0
- package/src/web/internal/Engine.ts +17 -0
- package/src/web/internal/Themes.ts +3 -279
- package/src/web/internal/Wasm.generated.ts +3 -0
- package/src/web/internal/Wire.ts +466 -0
- package/src/web/internal/wasm.d.ts +9 -0
- package/dist/compiler/internal/Applications.d.ts +0 -55
- package/dist/compiler/internal/Applications.d.ts.map +0 -1
- package/dist/compiler/internal/Applications.js +0 -393
- package/dist/compiler/internal/Applications.js.map +0 -1
- package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
- package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
- package/dist/compiler/internal/ColorProfiles.js +0 -84
- package/dist/compiler/internal/ColorProfiles.js.map +0 -1
- package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
- package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
- package/dist/compiler/internal/CompositionBindings.js +0 -89
- package/dist/compiler/internal/CompositionBindings.js.map +0 -1
- package/dist/compiler/internal/Compositions.d.ts +0 -37
- package/dist/compiler/internal/Compositions.d.ts.map +0 -1
- package/dist/compiler/internal/Compositions.js +0 -494
- package/dist/compiler/internal/Compositions.js.map +0 -1
- package/dist/compiler/internal/Configurations.d.ts +0 -26
- package/dist/compiler/internal/Configurations.d.ts.map +0 -1
- package/dist/compiler/internal/Configurations.js +0 -259
- package/dist/compiler/internal/Configurations.js.map +0 -1
- package/dist/compiler/internal/Contract.d.ts +0 -30
- package/dist/compiler/internal/Contract.d.ts.map +0 -1
- package/dist/compiler/internal/Contract.js +0 -753
- package/dist/compiler/internal/Contract.js.map +0 -1
- package/dist/compiler/internal/Contributions.d.ts +0 -54
- package/dist/compiler/internal/Contributions.d.ts.map +0 -1
- package/dist/compiler/internal/Contributions.js +0 -1151
- package/dist/compiler/internal/Contributions.js.map +0 -1
- package/dist/compiler/internal/Descriptors.d.ts +0 -15
- package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
- package/dist/compiler/internal/Descriptors.js +0 -192
- package/dist/compiler/internal/Descriptors.js.map +0 -1
- package/dist/compiler/internal/Dynamic.d.ts +0 -14
- package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
- package/dist/compiler/internal/Dynamic.js +0 -175
- package/dist/compiler/internal/Dynamic.js.map +0 -1
- package/dist/compiler/internal/Expression.d.ts +0 -19
- package/dist/compiler/internal/Expression.d.ts.map +0 -1
- package/dist/compiler/internal/Expression.js +0 -164
- package/dist/compiler/internal/Expression.js.map +0 -1
- package/dist/compiler/internal/Functions.d.ts +0 -5
- package/dist/compiler/internal/Functions.d.ts.map +0 -1
- package/dist/compiler/internal/Functions.js +0 -191
- package/dist/compiler/internal/Functions.js.map +0 -1
- package/dist/compiler/internal/Keyframes.d.ts +0 -5
- package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
- package/dist/compiler/internal/Keyframes.js +0 -51
- package/dist/compiler/internal/Keyframes.js.map +0 -1
- package/dist/compiler/internal/Names.d.ts +0 -5
- package/dist/compiler/internal/Names.d.ts.map +0 -1
- package/dist/compiler/internal/Names.js +0 -37
- package/dist/compiler/internal/Names.js.map +0 -1
- package/dist/compiler/internal/NativeBindings.d.ts +0 -72
- package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
- package/dist/compiler/internal/NativeBindings.js +0 -171
- package/dist/compiler/internal/NativeBindings.js.map +0 -1
- package/dist/compiler/internal/NativeMedia.d.ts +0 -14
- package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
- package/dist/compiler/internal/NativeMedia.js +0 -287
- package/dist/compiler/internal/NativeMedia.js.map +0 -1
- package/dist/compiler/internal/NativeVars.d.ts +0 -28
- package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
- package/dist/compiler/internal/NativeVars.js +0 -160
- package/dist/compiler/internal/NativeVars.js.map +0 -1
- package/dist/compiler/internal/PackedStyles.d.ts +0 -37
- package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
- package/dist/compiler/internal/PackedStyles.js +0 -344
- package/dist/compiler/internal/PackedStyles.js.map +0 -1
- package/dist/compiler/internal/Properties.d.ts +0 -5
- package/dist/compiler/internal/Properties.d.ts.map +0 -1
- package/dist/compiler/internal/Properties.js +0 -82
- package/dist/compiler/internal/Properties.js.map +0 -1
- package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
- package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
- package/dist/compiler/internal/RecipeConditions.js +0 -82
- package/dist/compiler/internal/RecipeConditions.js.map +0 -1
- package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
- package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
- package/dist/compiler/internal/RecipePayloads.js +0 -99
- package/dist/compiler/internal/RecipePayloads.js.map +0 -1
- package/dist/compiler/internal/Recipes.d.ts +0 -32
- package/dist/compiler/internal/Recipes.d.ts.map +0 -1
- package/dist/compiler/internal/Recipes.js +0 -339
- package/dist/compiler/internal/Recipes.js.map +0 -1
- package/dist/compiler/internal/Selectors.d.ts +0 -13
- package/dist/compiler/internal/Selectors.d.ts.map +0 -1
- package/dist/compiler/internal/Selectors.js +0 -280
- package/dist/compiler/internal/Selectors.js.map +0 -1
- package/dist/compiler/internal/Static.d.ts +0 -39
- package/dist/compiler/internal/Static.d.ts.map +0 -1
- package/dist/compiler/internal/Static.js +0 -534
- package/dist/compiler/internal/Static.js.map +0 -1
- package/dist/compiler/internal/Themes.d.ts +0 -190
- package/dist/compiler/internal/Themes.d.ts.map +0 -1
- package/dist/compiler/internal/Themes.js +0 -1577
- package/dist/compiler/internal/Themes.js.map +0 -1
- package/dist/compiler/internal/Vars.d.ts +0 -33
- package/dist/compiler/internal/Vars.d.ts.map +0 -1
- package/dist/compiler/internal/Vars.js +0 -387
- package/dist/compiler/internal/Vars.js.map +0 -1
- package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
- package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
- package/dist/compiler/internal/ViewTransitions.js +0 -68
- package/dist/compiler/internal/ViewTransitions.js.map +0 -1
- package/dist/internal/Cascade.d.ts +0 -74
- package/dist/internal/Cascade.d.ts.map +0 -1
- package/dist/internal/Cascade.js +0 -210
- package/dist/internal/Cascade.js.map +0 -1
- package/src/compiler/internal/Applications.ts +0 -610
- package/src/compiler/internal/ColorProfiles.ts +0 -93
- package/src/compiler/internal/CompositionBindings.ts +0 -120
- package/src/compiler/internal/Compositions.ts +0 -678
- package/src/compiler/internal/Configurations.ts +0 -349
- package/src/compiler/internal/Contract.ts +0 -1028
- package/src/compiler/internal/Contributions.ts +0 -1561
- package/src/compiler/internal/Descriptors.ts +0 -242
- package/src/compiler/internal/Dynamic.ts +0 -275
- package/src/compiler/internal/Expression.ts +0 -218
- package/src/compiler/internal/Functions.ts +0 -206
- package/src/compiler/internal/Keyframes.ts +0 -62
- package/src/compiler/internal/Names.ts +0 -48
- package/src/compiler/internal/NativeBindings.ts +0 -235
- package/src/compiler/internal/NativeMedia.ts +0 -342
- package/src/compiler/internal/NativeVars.ts +0 -231
- package/src/compiler/internal/PackedStyles.ts +0 -473
- package/src/compiler/internal/Properties.ts +0 -121
- package/src/compiler/internal/RecipeConditions.ts +0 -139
- package/src/compiler/internal/RecipePayloads.ts +0 -132
- package/src/compiler/internal/Recipes.ts +0 -531
- package/src/compiler/internal/Selectors.ts +0 -353
- package/src/compiler/internal/Static.ts +0 -784
- package/src/compiler/internal/Themes.ts +0 -2398
- package/src/compiler/internal/Vars.ts +0 -516
- package/src/compiler/internal/ViewTransitions.ts +0 -82
|
@@ -1,516 +0,0 @@
|
|
|
1
|
-
/** Resolves individual CSS variables across lexical scopes and packed libraries. @module */
|
|
2
|
-
import type * as Ast from '@oxc-project/types'
|
|
3
|
-
import * as Walker from 'oxc-walker'
|
|
4
|
-
import type * as Binding from '../../internal/Binding.js'
|
|
5
|
-
import * as Theme from '../../internal/Theme.js'
|
|
6
|
-
import type * as Css from '../../web/Css.js'
|
|
7
|
-
import * as Identity from '../../internal/Identity.js'
|
|
8
|
-
import * as Expression from './Expression.js'
|
|
9
|
-
import * as Names from './Names.js'
|
|
10
|
-
import type * as Scope from './Scope.js'
|
|
11
|
-
import type * as Themes from './Themes.js'
|
|
12
|
-
import { InvalidError } from './Themes.js'
|
|
13
|
-
|
|
14
|
-
/** One authoring call replaced with immutable compiler-assigned slot data. */
|
|
15
|
-
export type Call = {
|
|
16
|
-
/** Exclusive source offset. */
|
|
17
|
-
readonly end: number
|
|
18
|
-
/** Whether the consumer supplied a portable variable identity. */
|
|
19
|
-
readonly explicit?: boolean | undefined
|
|
20
|
-
/** Fixed scalar reference retained in portable metadata. */
|
|
21
|
-
readonly slots: Readonly<Record<string, Binding.Reference>>
|
|
22
|
-
/** Inclusive source offset. */
|
|
23
|
-
readonly start: number
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Collects module-owned declarations without executing application code. */
|
|
27
|
-
export function collect(
|
|
28
|
-
program: Ast.Program,
|
|
29
|
-
namespace: string,
|
|
30
|
-
scope: Scope.Tracker,
|
|
31
|
-
links: Readonly<Record<string, Themes.Link>> = {},
|
|
32
|
-
moduleId = namespace,
|
|
33
|
-
) {
|
|
34
|
-
const authoredNames = Names.collect(program)
|
|
35
|
-
const imports = new Set<number>()
|
|
36
|
-
const external = new Map<number, Themes.Link>()
|
|
37
|
-
for (const statement of program.body) {
|
|
38
|
-
if (
|
|
39
|
-
statement.type !== 'ImportDeclaration' ||
|
|
40
|
-
statement.importKind === 'type'
|
|
41
|
-
)
|
|
42
|
-
continue
|
|
43
|
-
for (const specifier of statement.specifiers) {
|
|
44
|
-
if (
|
|
45
|
-
specifier.type === 'ImportSpecifier' &&
|
|
46
|
-
specifier.importKind === 'type'
|
|
47
|
-
)
|
|
48
|
-
continue
|
|
49
|
-
if (links[specifier.local.name]?.kind === 'variables')
|
|
50
|
-
external.set(specifier.start, links[specifier.local.name]!)
|
|
51
|
-
if (
|
|
52
|
-
statement.source.value === 'zyzz' &&
|
|
53
|
-
specifier.type === 'ImportSpecifier' &&
|
|
54
|
-
(specifier.imported.type === 'Identifier'
|
|
55
|
-
? specifier.imported.name
|
|
56
|
-
: specifier.imported.value) === 'variable'
|
|
57
|
-
)
|
|
58
|
-
imports.add(specifier.start)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!imports.size && !external.size)
|
|
63
|
-
return {
|
|
64
|
-
calls: [] as Call[],
|
|
65
|
-
exports: {} as Record<string, Themes.Link>,
|
|
66
|
-
reference: () => false,
|
|
67
|
-
references: new Map<
|
|
68
|
-
number,
|
|
69
|
-
{ end: number; reference: Binding.Reference }
|
|
70
|
-
>(),
|
|
71
|
-
registrations: [] as Css.Contribution[],
|
|
72
|
-
registrationStarts: [] as number[],
|
|
73
|
-
registrationLocations: [] as Ast.Node[],
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const declarations = new Map<number, number>()
|
|
77
|
-
const bindings = new Map<number, Ast.Expression>()
|
|
78
|
-
const namespaces = new Map<number, Map<string, Ast.Expression>>()
|
|
79
|
-
const factories: Ast.CallExpression[] = []
|
|
80
|
-
const undefinedValues = new Set<number>()
|
|
81
|
-
const ancestors: Ast.Node[] = []
|
|
82
|
-
|
|
83
|
-
function members(node: Ast.TSModuleDeclaration | Ast.TSGlobalDeclaration) {
|
|
84
|
-
const result = new Map<string, Ast.Expression>()
|
|
85
|
-
if (node.body?.type !== 'TSModuleBlock') return result
|
|
86
|
-
for (const statement of node.body.body) {
|
|
87
|
-
if (
|
|
88
|
-
statement.type !== 'ExportNamedDeclaration' ||
|
|
89
|
-
statement.declaration?.type !== 'VariableDeclaration' ||
|
|
90
|
-
statement.declaration.kind !== 'const'
|
|
91
|
-
)
|
|
92
|
-
continue
|
|
93
|
-
for (const declaration of statement.declaration.declarations)
|
|
94
|
-
if (declaration.id.type === 'Identifier' && declaration.init)
|
|
95
|
-
result.set(declaration.id.name, declaration.init)
|
|
96
|
-
}
|
|
97
|
-
return result
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
Walker.walk(program, {
|
|
101
|
-
scopeTracker: scope,
|
|
102
|
-
enter(node, parent) {
|
|
103
|
-
if (node.type === 'Identifier') {
|
|
104
|
-
const declaration = scope.getDeclaration(node.name)
|
|
105
|
-
if (declaration) declarations.set(node.start, declaration.node.start)
|
|
106
|
-
else if (node.name === 'undefined') undefinedValues.add(node.start)
|
|
107
|
-
if (
|
|
108
|
-
declaration?.type === 'Import' &&
|
|
109
|
-
imports.has(declaration.node.start) &&
|
|
110
|
-
Walker.isReferenceIdentifier(node, parent!)
|
|
111
|
-
) {
|
|
112
|
-
if (
|
|
113
|
-
parent?.type !== 'CallExpression' ||
|
|
114
|
-
parent.callee !== node ||
|
|
115
|
-
parent.optional
|
|
116
|
-
)
|
|
117
|
-
throw new InvalidError(
|
|
118
|
-
'variable must be called directly in a module-level constant.',
|
|
119
|
-
node,
|
|
120
|
-
)
|
|
121
|
-
if (
|
|
122
|
-
!ancestors.some(
|
|
123
|
-
(entry) =>
|
|
124
|
-
entry.type === 'VariableDeclaration' && entry.kind === 'const',
|
|
125
|
-
) ||
|
|
126
|
-
ancestors.some((entry) =>
|
|
127
|
-
[
|
|
128
|
-
'ArrowFunctionExpression',
|
|
129
|
-
'FunctionExpression',
|
|
130
|
-
'FunctionDeclaration',
|
|
131
|
-
'BlockStatement',
|
|
132
|
-
].includes(entry.type),
|
|
133
|
-
)
|
|
134
|
-
)
|
|
135
|
-
throw new InvalidError(
|
|
136
|
-
'variable requires a module-level constant.',
|
|
137
|
-
parent,
|
|
138
|
-
)
|
|
139
|
-
|
|
140
|
-
let initializer: Ast.Node = parent
|
|
141
|
-
for (let index = ancestors.length - 2; index >= 0; index--) {
|
|
142
|
-
const ancestor = ancestors[index]!
|
|
143
|
-
if (ancestor.type === 'VariableDeclarator') {
|
|
144
|
-
if (
|
|
145
|
-
ancestor.id.type === 'Identifier' &&
|
|
146
|
-
ancestor.init === initializer
|
|
147
|
-
)
|
|
148
|
-
break
|
|
149
|
-
} else if (
|
|
150
|
-
Expression.unwrap(ancestor) === Expression.unwrap(initializer)
|
|
151
|
-
) {
|
|
152
|
-
initializer = ancestor
|
|
153
|
-
continue
|
|
154
|
-
} else if (
|
|
155
|
-
ancestor.type === 'Property' &&
|
|
156
|
-
!ancestor.computed &&
|
|
157
|
-
ancestor.kind === 'init' &&
|
|
158
|
-
!ancestor.method &&
|
|
159
|
-
ancestor.value === initializer
|
|
160
|
-
) {
|
|
161
|
-
initializer = ancestor
|
|
162
|
-
continue
|
|
163
|
-
} else if (
|
|
164
|
-
ancestor.type === 'ObjectExpression' &&
|
|
165
|
-
ancestor.properties.some((property) => property === initializer)
|
|
166
|
-
) {
|
|
167
|
-
initializer = ancestor
|
|
168
|
-
continue
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
throw new InvalidError(
|
|
172
|
-
'variable requires a direct constant or object-group initializer.',
|
|
173
|
-
parent,
|
|
174
|
-
)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
factories.push(parent)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (node.type === 'VariableDeclaration' && node.kind === 'const')
|
|
181
|
-
for (const declaration of node.declarations)
|
|
182
|
-
if (declaration.id.type === 'Identifier' && declaration.init)
|
|
183
|
-
bindings.set(declaration.start, declaration.init)
|
|
184
|
-
if (node.type === 'TSModuleDeclaration' && node.id.type === 'Identifier')
|
|
185
|
-
namespaces.set(node.id.start, members(node))
|
|
186
|
-
ancestors.push(node)
|
|
187
|
-
},
|
|
188
|
-
leave() {
|
|
189
|
-
ancestors.pop()
|
|
190
|
-
},
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
const calls: Call[] = []
|
|
194
|
-
const explicit = new Set<number>()
|
|
195
|
-
const definitions = new Map<number, Themes.Link>()
|
|
196
|
-
const registrations: Css.Contribution[] = []
|
|
197
|
-
const registrationStarts: number[] = []
|
|
198
|
-
const registrationLocations: Ast.Node[] = []
|
|
199
|
-
for (const call of factories) {
|
|
200
|
-
const domain = call.arguments[0] && Expression.unwrap(call.arguments[0])
|
|
201
|
-
const value =
|
|
202
|
-
domain?.type === 'ObjectExpression'
|
|
203
|
-
? domain
|
|
204
|
-
: call.arguments[1] && Expression.unwrap(call.arguments[1])
|
|
205
|
-
const kind = (() => {
|
|
206
|
-
if (call.arguments.length === 0 || domain?.type === 'ObjectExpression')
|
|
207
|
-
return '*'
|
|
208
|
-
if (domain?.type === 'Literal') return domain.value
|
|
209
|
-
return undefined
|
|
210
|
-
})()
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
(kind !== '*' &&
|
|
214
|
-
![
|
|
215
|
-
'color',
|
|
216
|
-
'length',
|
|
217
|
-
'number',
|
|
218
|
-
'percentage',
|
|
219
|
-
'signedLength',
|
|
220
|
-
'signedPercentage',
|
|
221
|
-
].includes(String(kind))) ||
|
|
222
|
-
call.arguments.length > 2 ||
|
|
223
|
-
(value && value.type !== 'ObjectExpression')
|
|
224
|
-
)
|
|
225
|
-
throw new InvalidError(
|
|
226
|
-
'variable requires a scalar domain and optional literal registration options.',
|
|
227
|
-
call,
|
|
228
|
-
)
|
|
229
|
-
const descriptor: Record<string, string | number | boolean> =
|
|
230
|
-
Object.create(null)
|
|
231
|
-
|
|
232
|
-
if (value?.type === 'ObjectExpression')
|
|
233
|
-
for (const entry of value.properties) {
|
|
234
|
-
if (
|
|
235
|
-
entry.type !== 'Property' ||
|
|
236
|
-
entry.computed ||
|
|
237
|
-
entry.method ||
|
|
238
|
-
entry.kind !== 'init'
|
|
239
|
-
)
|
|
240
|
-
throw new InvalidError(
|
|
241
|
-
'Variable registrations require literal descriptors.',
|
|
242
|
-
value,
|
|
243
|
-
)
|
|
244
|
-
|
|
245
|
-
const key =
|
|
246
|
-
entry.key.type === 'Identifier'
|
|
247
|
-
? entry.key.name
|
|
248
|
-
: entry.key.type === 'Literal'
|
|
249
|
-
? String(entry.key.value)
|
|
250
|
-
: ''
|
|
251
|
-
|
|
252
|
-
const input = Expression.unwrap(entry.value)
|
|
253
|
-
if (
|
|
254
|
-
key === 'syntax' &&
|
|
255
|
-
input.type === 'Identifier' &&
|
|
256
|
-
input.name === 'undefined' &&
|
|
257
|
-
undefinedValues.has(input.start)
|
|
258
|
-
)
|
|
259
|
-
continue
|
|
260
|
-
|
|
261
|
-
const literal =
|
|
262
|
-
input.type === 'Literal'
|
|
263
|
-
? input.value
|
|
264
|
-
: input.type === 'UnaryExpression' &&
|
|
265
|
-
['+', '-'].includes(input.operator) &&
|
|
266
|
-
input.argument.type === 'Literal' &&
|
|
267
|
-
typeof input.argument.value === 'number'
|
|
268
|
-
? (input.operator === '-' ? -1 : 1) * input.argument.value
|
|
269
|
-
: undefined
|
|
270
|
-
if (
|
|
271
|
-
!['id', 'syntax', 'inherits', 'initialValue'].includes(key) ||
|
|
272
|
-
Object.hasOwn(descriptor, key) ||
|
|
273
|
-
!['string', 'number', 'boolean'].includes(typeof literal)
|
|
274
|
-
)
|
|
275
|
-
throw new InvalidError(
|
|
276
|
-
'Invalid variable registration descriptor.',
|
|
277
|
-
entry,
|
|
278
|
-
)
|
|
279
|
-
|
|
280
|
-
descriptor[key] = literal as string | number | boolean
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (descriptor.id !== undefined) explicit.add(call.start)
|
|
284
|
-
|
|
285
|
-
const name =
|
|
286
|
-
`--z-${descriptor.id === undefined ? authoredNames.get(call.start)! : Identity.requireId(typeof descriptor.id === 'string' ? descriptor.id : undefined, 'variable').slice(3)}` as const
|
|
287
|
-
if (value && Object.keys(descriptor).some((key) => key !== 'id')) {
|
|
288
|
-
const syntax =
|
|
289
|
-
kind === 'signedLength'
|
|
290
|
-
? '<length>'
|
|
291
|
-
: kind === 'signedPercentage'
|
|
292
|
-
? '<percentage>'
|
|
293
|
-
: `<${kind}>`
|
|
294
|
-
if (
|
|
295
|
-
typeof descriptor.inherits !== 'boolean' ||
|
|
296
|
-
!['string', 'number'].includes(typeof descriptor.initialValue) ||
|
|
297
|
-
(descriptor.syntax !== undefined && descriptor.syntax !== syntax)
|
|
298
|
-
)
|
|
299
|
-
throw new InvalidError(
|
|
300
|
-
'Registration requires matching syntax, inherits, and an independent initialValue.',
|
|
301
|
-
value,
|
|
302
|
-
)
|
|
303
|
-
|
|
304
|
-
if (kind === 'length' || kind === 'percentage') {
|
|
305
|
-
const initialValue = String(descriptor.initialValue)
|
|
306
|
-
const literal =
|
|
307
|
-
kind === 'length'
|
|
308
|
-
? /^(?:0|\+?(?:\d*\.\d+|\d+)(?:[eE][+-]?\d+)?(?:px|in|cm|mm|q|pt|pc))$/
|
|
309
|
-
: /^\+?(?:\d*\.\d+|\d+)(?:[eE][+-]?\d+)?%$/
|
|
310
|
-
|
|
311
|
-
if (!literal.test(initialValue))
|
|
312
|
-
throw new InvalidError(
|
|
313
|
-
'Unsigned variable registrations require a nonnegative literal initialValue.',
|
|
314
|
-
value,
|
|
315
|
-
)
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
registrationStarts.push(call.start)
|
|
319
|
-
registrationLocations.push(call)
|
|
320
|
-
registrations.push({
|
|
321
|
-
kind: 'property',
|
|
322
|
-
name,
|
|
323
|
-
syntax,
|
|
324
|
-
inherits: descriptor.inherits,
|
|
325
|
-
initialValue: descriptor.initialValue as string | number,
|
|
326
|
-
})
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const slot = Object.freeze({
|
|
330
|
-
name,
|
|
331
|
-
type: kind as Binding.Domain,
|
|
332
|
-
variable: true as const,
|
|
333
|
-
})
|
|
334
|
-
const entry = Object.freeze({
|
|
335
|
-
explicit: explicit.has(call.start),
|
|
336
|
-
start: call.start,
|
|
337
|
-
end: call.end,
|
|
338
|
-
slots: Object.freeze({ value: slot }),
|
|
339
|
-
})
|
|
340
|
-
calls.push(entry)
|
|
341
|
-
definitions.set(call.start, {
|
|
342
|
-
binding: name,
|
|
343
|
-
kind: 'variables',
|
|
344
|
-
definition: Theme.define({}),
|
|
345
|
-
call: {
|
|
346
|
-
start: call.start,
|
|
347
|
-
end: call.end,
|
|
348
|
-
name,
|
|
349
|
-
tokenType: '{}',
|
|
350
|
-
variables: entry.slots,
|
|
351
|
-
variableOwner: moduleId.replace(/\.[cm]?[jt]sx?$/, ''),
|
|
352
|
-
},
|
|
353
|
-
})
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function group(
|
|
357
|
-
values: Map<string, Ast.Expression>,
|
|
358
|
-
start: number,
|
|
359
|
-
seen: Set<Ast.Node>,
|
|
360
|
-
): Themes.Link | undefined {
|
|
361
|
-
const members: Record<string, Themes.Link> = Object.create(null)
|
|
362
|
-
for (const [name, value] of values) {
|
|
363
|
-
const member = resolve(value, new Set(seen))
|
|
364
|
-
if (member) members[name] = member
|
|
365
|
-
}
|
|
366
|
-
if (!Object.keys(members).length) return undefined
|
|
367
|
-
return {
|
|
368
|
-
binding: `z-v${namespace}-${start}`,
|
|
369
|
-
kind: 'variables',
|
|
370
|
-
definition: Theme.define({}),
|
|
371
|
-
call: { start: -1, end: -1, name: '', tokenType: '{}', variables: {} },
|
|
372
|
-
members,
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
function resolve(
|
|
377
|
-
input: Ast.Node,
|
|
378
|
-
seen = new Set<Ast.Node>(),
|
|
379
|
-
): Themes.Link | undefined {
|
|
380
|
-
const node = Expression.unwrap(input)
|
|
381
|
-
if (seen.has(node)) return undefined
|
|
382
|
-
seen.add(node)
|
|
383
|
-
if (node.type === 'CallExpression') return definitions.get(node.start)
|
|
384
|
-
if (node.type === 'Identifier') {
|
|
385
|
-
const declaration = declarations.get(node.start)
|
|
386
|
-
if (declaration === undefined) return undefined
|
|
387
|
-
const imported = external.get(declaration)
|
|
388
|
-
if (imported) return imported
|
|
389
|
-
const values = namespaces.get(declaration)
|
|
390
|
-
if (values) return group(values, declaration, seen)
|
|
391
|
-
const value = bindings.get(declaration)
|
|
392
|
-
return value ? resolve(value, seen) : undefined
|
|
393
|
-
}
|
|
394
|
-
if (node.type === 'MemberExpression' && !node.optional) {
|
|
395
|
-
const key =
|
|
396
|
-
!node.computed && node.property.type === 'Identifier'
|
|
397
|
-
? node.property.name
|
|
398
|
-
: node.property.type === 'Literal'
|
|
399
|
-
? String(node.property.value)
|
|
400
|
-
: undefined
|
|
401
|
-
if (key === undefined) return undefined
|
|
402
|
-
return resolve(node.object, seen)?.members?.[key]
|
|
403
|
-
}
|
|
404
|
-
if (node.type === 'ObjectExpression') {
|
|
405
|
-
const values = new Map<string, Ast.Expression>()
|
|
406
|
-
for (const property of node.properties) {
|
|
407
|
-
if (
|
|
408
|
-
property.type !== 'Property' ||
|
|
409
|
-
property.method ||
|
|
410
|
-
property.kind !== 'init' ||
|
|
411
|
-
property.computed
|
|
412
|
-
)
|
|
413
|
-
return undefined
|
|
414
|
-
const key =
|
|
415
|
-
property.key.type === 'Identifier'
|
|
416
|
-
? property.key.name
|
|
417
|
-
: property.key.type === 'Literal'
|
|
418
|
-
? String(property.key.value)
|
|
419
|
-
: undefined
|
|
420
|
-
if (key !== undefined) values.set(key, property.value)
|
|
421
|
-
}
|
|
422
|
-
return group(values, node.start, seen)
|
|
423
|
-
}
|
|
424
|
-
return undefined
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
const references = new Map<
|
|
428
|
-
number,
|
|
429
|
-
{ end: number; reference: Binding.Reference }
|
|
430
|
-
>()
|
|
431
|
-
Walker.walk(program, {
|
|
432
|
-
enter(node) {
|
|
433
|
-
if (node.type !== 'Identifier' && node.type !== 'MemberExpression') return
|
|
434
|
-
const resolved = resolve(node)
|
|
435
|
-
const reference = resolved?.call.variables?.value
|
|
436
|
-
if (reference) references.set(node.start, { end: node.end, reference })
|
|
437
|
-
},
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
const exports: Record<string, Themes.Link> = Object.create(null)
|
|
441
|
-
for (const statement of program.body) {
|
|
442
|
-
if (statement.type === 'ExportDefaultDeclaration') {
|
|
443
|
-
const link = resolve(statement.declaration)
|
|
444
|
-
if (link) exports.default = link
|
|
445
|
-
}
|
|
446
|
-
if (
|
|
447
|
-
statement.type !== 'ExportNamedDeclaration' ||
|
|
448
|
-
statement.exportKind === 'type'
|
|
449
|
-
)
|
|
450
|
-
continue
|
|
451
|
-
const declaration = statement.declaration
|
|
452
|
-
if (declaration?.type === 'VariableDeclaration')
|
|
453
|
-
for (const variable of declaration.declarations) {
|
|
454
|
-
if (variable.id.type !== 'Identifier' || !variable.init) continue
|
|
455
|
-
const link = resolve(variable.init)
|
|
456
|
-
if (link) exports[variable.id.name] = link
|
|
457
|
-
}
|
|
458
|
-
if (
|
|
459
|
-
declaration?.type === 'TSModuleDeclaration' &&
|
|
460
|
-
declaration.id.type === 'Identifier'
|
|
461
|
-
) {
|
|
462
|
-
const link = group(members(declaration), declaration.start, new Set())
|
|
463
|
-
if (link) exports[declaration.id.name] = link
|
|
464
|
-
}
|
|
465
|
-
for (const specifier of statement.specifiers) {
|
|
466
|
-
if (specifier.exportKind === 'type') continue
|
|
467
|
-
const link = resolve(specifier.local)
|
|
468
|
-
if (link)
|
|
469
|
-
exports[
|
|
470
|
-
specifier.exported.type === 'Identifier'
|
|
471
|
-
? specifier.exported.name
|
|
472
|
-
: specifier.exported.value
|
|
473
|
-
] = link
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function reference(
|
|
478
|
-
node: Extract<Ast.Node, { type: 'Identifier' | 'JSXIdentifier' }>,
|
|
479
|
-
parent: Ast.Node,
|
|
480
|
-
ancestors: readonly Ast.Node[],
|
|
481
|
-
binding: Walker.ScopeTrackerNode | null,
|
|
482
|
-
) {
|
|
483
|
-
if (binding?.type === 'Import' && imports.has(binding.node.start))
|
|
484
|
-
return true
|
|
485
|
-
const link =
|
|
486
|
-
resolve(
|
|
487
|
-
parent.type === 'MemberExpression' && parent.object === node
|
|
488
|
-
? parent
|
|
489
|
-
: node,
|
|
490
|
-
) ?? resolve(node)
|
|
491
|
-
if (!link) return false
|
|
492
|
-
// Reads inside functions wait for a call, so only module-scope reads must follow the declaration.
|
|
493
|
-
if (
|
|
494
|
-
link.call.start >= 0 &&
|
|
495
|
-
node.start < link.call.end &&
|
|
496
|
-
!ancestors.some(
|
|
497
|
-
(ancestor) =>
|
|
498
|
-
ancestor.type === 'ArrowFunctionExpression' ||
|
|
499
|
-
ancestor.type === 'FunctionDeclaration' ||
|
|
500
|
-
ancestor.type === 'FunctionExpression',
|
|
501
|
-
)
|
|
502
|
-
)
|
|
503
|
-
throw new InvalidError('Vars must be declared before use.', node)
|
|
504
|
-
return true
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
return {
|
|
508
|
-
calls,
|
|
509
|
-
exports,
|
|
510
|
-
reference,
|
|
511
|
-
references,
|
|
512
|
-
registrations,
|
|
513
|
-
registrationStarts,
|
|
514
|
-
registrationLocations,
|
|
515
|
-
}
|
|
516
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/** Validates view-transition descriptors before a parser can discard invalid values. @module */
|
|
2
|
-
import * as Lightning from 'lightningcss'
|
|
3
|
-
|
|
4
|
-
/** Checks a token-preserving spelling of view-transition rules from source or packed CSS. */
|
|
5
|
-
export function validate(source: string, marker: string): void {
|
|
6
|
-
Lightning.transform({
|
|
7
|
-
filename: 'view-transitions.css',
|
|
8
|
-
code: new TextEncoder().encode(source),
|
|
9
|
-
visitor: {
|
|
10
|
-
Rule(rule) {
|
|
11
|
-
if (rule.type !== 'unknown' || rule.value.name !== marker) return
|
|
12
|
-
if (rule.value.prelude.length || !rule.value.block)
|
|
13
|
-
throw new Error(
|
|
14
|
-
'View-transition rules require a descriptor block and no prelude.',
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
let declaration: Lightning.TokenOrValue[] = []
|
|
18
|
-
const flush = () => {
|
|
19
|
-
if (!declaration.length) return
|
|
20
|
-
const [name, colon, ...values] = declaration
|
|
21
|
-
if (
|
|
22
|
-
name?.type !== 'token' ||
|
|
23
|
-
name.value.type !== 'ident' ||
|
|
24
|
-
colon?.type !== 'token' ||
|
|
25
|
-
colon.value.type !== 'colon' ||
|
|
26
|
-
!values.length ||
|
|
27
|
-
values.some(
|
|
28
|
-
(value) =>
|
|
29
|
-
value.type !== 'dashed-ident' &&
|
|
30
|
-
(value.type !== 'token' || value.value.type !== 'ident'),
|
|
31
|
-
)
|
|
32
|
-
)
|
|
33
|
-
throw new Error('Invalid view-transition descriptor.')
|
|
34
|
-
|
|
35
|
-
const names = values.map((value) =>
|
|
36
|
-
value.type === 'dashed-ident'
|
|
37
|
-
? value.value
|
|
38
|
-
: value.type === 'token' && value.value.type === 'ident'
|
|
39
|
-
? value.value.value
|
|
40
|
-
: '',
|
|
41
|
-
)
|
|
42
|
-
const key = name.value.value.toLowerCase()
|
|
43
|
-
if (key === 'navigation') {
|
|
44
|
-
if (
|
|
45
|
-
names.length !== 1 ||
|
|
46
|
-
!['auto', 'none'].includes(names[0]!.toLowerCase())
|
|
47
|
-
)
|
|
48
|
-
throw new Error('Invalid view-transition navigation.')
|
|
49
|
-
} else if (key === 'types') {
|
|
50
|
-
if (
|
|
51
|
-
names.some(
|
|
52
|
-
(name) =>
|
|
53
|
-
[
|
|
54
|
-
'default',
|
|
55
|
-
'inherit',
|
|
56
|
-
'initial',
|
|
57
|
-
'revert',
|
|
58
|
-
'revert-layer',
|
|
59
|
-
'unset',
|
|
60
|
-
].includes(name.toLowerCase()) ||
|
|
61
|
-
(name.toLowerCase() === 'none' && names.length !== 1),
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
|
-
throw new Error('Invalid view-transition types.')
|
|
65
|
-
} else throw new Error('Unknown view-transition descriptor.')
|
|
66
|
-
declaration = []
|
|
67
|
-
}
|
|
68
|
-
for (const token of rule.value.block) {
|
|
69
|
-
if (
|
|
70
|
-
token.type === 'token' &&
|
|
71
|
-
['white-space', 'comment'].includes(token.value.type)
|
|
72
|
-
)
|
|
73
|
-
continue
|
|
74
|
-
if (token.type === 'token' && token.value.type === 'semicolon')
|
|
75
|
-
flush()
|
|
76
|
-
else declaration.push(token)
|
|
77
|
-
}
|
|
78
|
-
flush()
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
}
|