@kayjs/kay 1.109.0 → 1.111.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint.js +488 -75
- package/editors/zed/extension.toml +2 -2
- package/llms/actions-from-islands.md +1 -1
- package/llms/build-and-start.md +1 -1
- package/llms/checks.md +1 -0
- package/llms/component-libraries.md +1 -1
- package/llms/components.md +1 -1
- package/llms/deprecated-lints.md +1 -1
- package/llms/dev-tool.md +1 -1
- package/llms/effects.md +1 -0
- package/llms/head.md +1 -1
- package/llms/images.md +2 -0
- package/llms/island-and-form-lints.md +2 -1
- package/llms/islands-lazy-components.md +23 -0
- package/llms/islands.md +4 -14
- package/llms/lints.md +1 -1
- package/llms/live-values.md +1 -1
- package/llms/navigation-from-code.md +1 -1
- package/llms/navigation.md +5 -3
- package/llms/performance-lints.md +1 -0
- package/llms/prerendering.md +1 -1
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +1 -1
- package/llms/templates-elements-slots-snippets.md +4 -4
- package/llms/upgrading-archive.md +121 -42
- package/llms/upgrading.md +17 -133
- package/llms/whats-new-archive.md +31 -31
- package/llms/whats-new.md +45 -30
- package/llms.txt +3 -2
- package/package.json +11 -11
- package/src/build/client.ts +10 -8
- package/src/build/island-images.ts +277 -0
- package/src/build/pipeline.ts +10 -4
- package/src/build/static.ts +99 -24
- package/src/build/variants.ts +132 -18
- package/src/check/env-types.ts +1 -1
- package/src/check/project.ts +4 -0
- package/src/check/schema-builders.ts +230 -26
- package/src/check/shadow-types.ts +3 -3
- package/src/commands/upgrade.ts +2 -1
- package/src/compiler/allow-comments.ts +38 -2
- package/src/compiler/ast.ts +4 -4
- package/src/compiler/codegen.ts +4 -4
- package/src/compiler/deprecated-lints-1-106.ts +2 -2
- package/src/compiler/dom.ts +4 -3
- package/src/compiler/hand-parts.ts +36 -8
- package/src/compiler/handed-data.ts +15 -0
- package/src/compiler/helper-imports.ts +2 -2
- package/src/compiler/html.ts +3 -7
- package/src/compiler/index.ts +7 -4
- package/src/compiler/island-arguments.ts +9 -0
- package/src/compiler/island-lints.ts +7 -0
- package/src/compiler/items.ts +174 -0
- package/src/compiler/jsx.ts +10 -11
- package/src/compiler/kay-exports.ts +1 -0
- package/src/compiler/lints.ts +6 -7
- package/src/compiler/markup.ts +26 -24
- package/src/compiler/names.ts +1 -1
- package/src/compiler/removed-lints.ts +90 -0
- package/src/compiler/rewrite-types.ts +2 -0
- package/src/compiler/rewrite.ts +4 -2
- package/src/compiler/route-lints.ts +8 -0
- package/src/compiler/signal-from-prop.ts +141 -0
- package/src/compiler/template-reads.ts +16 -0
- package/src/compiler/template-walk.ts +2 -1
- package/src/config-shape.ts +4 -1
- package/src/config.ts +2 -2
- package/src/new.ts +16 -4
- package/src/project.ts +3 -3
- package/src/runtime/await.server.ts +4 -2
- package/src/runtime/checks.ts +14 -2
- package/src/runtime/client.ts +5 -9
- package/src/runtime/dev-tab-env.ts +28 -3
- package/src/runtime/dom-loop.ts +2 -4
- package/src/runtime/dom.ts +2 -2
- package/src/runtime/html.ts +53 -7
- package/src/runtime/image.ts +24 -23
- package/src/runtime/index.ts +2 -2
- package/src/runtime/island.server.ts +41 -11
- package/src/runtime/navigate.ts +14 -0
- package/src/runtime/navigation.ts +9 -1
- package/src/runtime/page-swap.ts +6 -3
- package/src/runtime/reactive.ts +72 -0
- package/src/runtime/row-key.ts +4 -0
- package/src/runtime/swap-flight.ts +10 -10
- package/src/runtime/swap-focus.ts +56 -9
- package/src/runtime/swap-kept.ts +97 -29
- package/src/runtime/swap-morph.ts +49 -9
- package/src/runtime/text-hash.ts +17 -0
- package/src/runtime/uid.server.ts +6 -4
- package/src/runtime/values.ts +12 -0
- package/src/server/client.ts +3 -0
- package/src/server/dev.ts +2 -0
- package/src/server/image.ts +1 -1
- package/src/server/kept-exports.ts +1 -0
- package/src/server/render-document.ts +11 -8
- package/src/server/render.ts +3 -3
- package/types/build/client.d.ts +6 -0
- package/types/build/client.d.ts.map +1 -1
- package/types/build/island-images.d.ts +45 -0
- package/types/build/island-images.d.ts.map +1 -0
- package/types/build/pipeline.d.ts.map +1 -1
- package/types/build/static.d.ts.map +1 -1
- package/types/build/variants.d.ts +9 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/project.d.ts.map +1 -1
- package/types/check/schema-builders.d.ts.map +1 -1
- package/types/commands/upgrade.d.ts.map +1 -1
- package/types/compiler/allow-comments.d.ts +2 -0
- package/types/compiler/allow-comments.d.ts.map +1 -1
- package/types/compiler/ast.d.ts +1 -1
- package/types/compiler/ast.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-106.d.ts +2 -2
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
- package/types/compiler/deprecated-lints.d.ts +2 -2
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/hand-parts.d.ts +6 -3
- package/types/compiler/hand-parts.d.ts.map +1 -1
- package/types/compiler/handed-data.d.ts +5 -0
- package/types/compiler/handed-data.d.ts.map +1 -0
- package/types/compiler/html.d.ts.map +1 -1
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-arguments.d.ts +5 -0
- package/types/compiler/island-arguments.d.ts.map +1 -1
- package/types/compiler/island-lints.d.ts +7 -0
- package/types/compiler/island-lints.d.ts.map +1 -1
- package/types/compiler/items.d.ts +14 -0
- package/types/compiler/items.d.ts.map +1 -1
- package/types/compiler/jsx.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +20 -5
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/markup.d.ts +3 -1
- package/types/compiler/markup.d.ts.map +1 -1
- package/types/compiler/names.d.ts.map +1 -1
- package/types/compiler/removed-lints.d.ts +3 -0
- package/types/compiler/removed-lints.d.ts.map +1 -0
- package/types/compiler/rewrite-types.d.ts +1 -0
- package/types/compiler/rewrite-types.d.ts.map +1 -1
- package/types/compiler/route-lints.d.ts +8 -0
- package/types/compiler/route-lints.d.ts.map +1 -1
- package/types/compiler/signal-from-prop.d.ts +4 -0
- package/types/compiler/signal-from-prop.d.ts.map +1 -0
- package/types/compiler/template-reads.d.ts +1 -0
- package/types/compiler/template-reads.d.ts.map +1 -1
- package/types/compiler/template-walk.d.ts.map +1 -1
- package/types/config-shape.d.ts.map +1 -1
- package/types/config.d.ts +3 -1
- package/types/config.d.ts.map +1 -1
- package/types/new.d.ts.map +1 -1
- package/types/project.d.ts +2 -2
- package/types/project.d.ts.map +1 -1
- package/types/runtime/await.server.d.ts.map +1 -1
- package/types/runtime/checks.d.ts +8 -2
- package/types/runtime/checks.d.ts.map +1 -1
- package/types/runtime/client.d.ts.map +1 -1
- package/types/runtime/dev-tab-env.d.ts.map +1 -1
- package/types/runtime/dom-loop.d.ts +2 -1
- package/types/runtime/dom-loop.d.ts.map +1 -1
- package/types/runtime/dom.d.ts +2 -2
- package/types/runtime/dom.d.ts.map +1 -1
- package/types/runtime/html.d.ts +6 -3
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/image.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -2
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +1 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/navigate.d.ts.map +1 -1
- package/types/runtime/navigation.d.ts +4 -0
- package/types/runtime/navigation.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +5 -0
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/row-key.d.ts +2 -0
- package/types/runtime/row-key.d.ts.map +1 -0
- package/types/runtime/swap-flight.d.ts +1 -1
- package/types/runtime/swap-flight.d.ts.map +1 -1
- package/types/runtime/swap-focus.d.ts +2 -0
- package/types/runtime/swap-focus.d.ts.map +1 -1
- package/types/runtime/swap-kept.d.ts.map +1 -1
- package/types/runtime/swap-morph.d.ts.map +1 -1
- package/types/runtime/text-hash.d.ts +2 -0
- package/types/runtime/text-hash.d.ts.map +1 -0
- package/types/runtime/uid.server.d.ts.map +1 -1
- package/types/runtime/values.d.ts +4 -0
- package/types/runtime/values.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +3 -1
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +3 -1
- package/types/server/app.d.ts.map +1 -1
- package/types/server/client.d.ts +2 -0
- package/types/server/client.d.ts.map +1 -1
- package/types/server/dev.d.ts +1 -0
- package/types/server/dev.d.ts.map +1 -1
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/render-document.d.ts +1 -1
- package/types/server/render-document.d.ts.map +1 -1
- package/types/server/render.d.ts +2 -2
- package/types/server/render.d.ts.map +1 -1
|
@@ -31,6 +31,39 @@ const OLD_SIZE = /^\d+(?:\.\d+)?[kmg]$/i
|
|
|
31
31
|
const KAY = /^kay(?:\/|$)/
|
|
32
32
|
const NEEDLE = /\.(?:String|Secret|Number|Numeric|Integer|Boolean|BooleanString|Date|File|Files|Literal|Union|Array|Object|UnionEnum|UnionKeys|Public|Optional)\(|\.(?:file|files)\(/
|
|
33
33
|
|
|
34
|
+
interface Mapped {
|
|
35
|
+
record: Node
|
|
36
|
+
literal: Node
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// `Object.keys(R).map(key => s.Literal(key))`, a cast on the key allowed: the record whose keys are the literals.
|
|
40
|
+
function mappedKeys(node: Node, receivers: Set<string>): Mapped | undefined {
|
|
41
|
+
if (node.type !== 'CallExpression' || node.callee.type !== 'MemberExpression' || node.callee.computed || node.callee.property.type !== 'Identifier' || node.callee.property.name !== 'map' || node.arguments.length !== 1)
|
|
42
|
+
return undefined
|
|
43
|
+
|
|
44
|
+
const keys = node.callee.object
|
|
45
|
+
const [callback] = node.arguments
|
|
46
|
+
|
|
47
|
+
if (keys.type !== 'CallExpression' || keys.arguments.length !== 1 || keys.callee.type !== 'MemberExpression' || keys.callee.computed || keys.callee.object.type !== 'Identifier' || keys.callee.object.name !== 'Object' || keys.callee.property.type !== 'Identifier' || keys.callee.property.name !== 'keys')
|
|
48
|
+
return undefined
|
|
49
|
+
|
|
50
|
+
const [param] = callback?.type === 'ArrowFunctionExpression' ? callback.params : []
|
|
51
|
+
|
|
52
|
+
if (callback?.type !== 'ArrowFunctionExpression' || callback.params.length !== 1 || param?.type !== 'Identifier')
|
|
53
|
+
return undefined
|
|
54
|
+
|
|
55
|
+
const literal = builderCall(callback.body, receivers)
|
|
56
|
+
let inner = literal?.node.arguments[0]
|
|
57
|
+
|
|
58
|
+
while (inner && (inner.type === 'TSAsExpression' || inner.type === 'TSNonNullExpression'))
|
|
59
|
+
inner = inner.expression
|
|
60
|
+
|
|
61
|
+
if (literal?.name !== 'Literal' || literal.node.arguments.length !== 1 || inner?.type !== 'Identifier' || inner.name !== param.name)
|
|
62
|
+
return undefined
|
|
63
|
+
|
|
64
|
+
return { record: keys.arguments[0]!, literal: callback.body }
|
|
65
|
+
}
|
|
66
|
+
|
|
34
67
|
interface Call {
|
|
35
68
|
node: Node & { type: 'CallExpression' }
|
|
36
69
|
name: string
|
|
@@ -79,10 +112,148 @@ function renames(call: Call, base: number): Edit[] {
|
|
|
79
112
|
return edits
|
|
80
113
|
}
|
|
81
114
|
|
|
82
|
-
//
|
|
83
|
-
function
|
|
115
|
+
// The options the lowercase builder needs to read as the PascalCase one did: a string takes `max` where it had none, as the lowercase one stops at 10,000 characters, unless it is in an action's input or an API body, which capped it there already; a list takes `max` where it had none (the lowercase one stops at 1,000 items, except a list of files), and an object `extra: 'strip'` (the lowercase one refuses a key its shape lacks). Undefined when the options are not an object literal of known keys, which the fix cannot add to.
|
|
116
|
+
function keptOptions(call: Call, bounded: boolean): string[] | undefined {
|
|
117
|
+
const index = BUILDERS[call.name]!.options
|
|
118
|
+
const options = call.node.arguments[index]
|
|
119
|
+
const keys = new Set<string>()
|
|
120
|
+
// The builders whose old behaviour the fix must write an option for; a string only outside the contexts that capped it already.
|
|
121
|
+
const writes = call.name === 'Array' || call.name === 'Object' || (call.name === 'String' && !bounded)
|
|
122
|
+
|
|
123
|
+
if (options !== undefined && options.type !== 'ObjectExpression')
|
|
124
|
+
return writes ? undefined : []
|
|
125
|
+
|
|
126
|
+
for (const entry of options?.properties ?? []) {
|
|
127
|
+
const name = keyName(entry)
|
|
128
|
+
|
|
129
|
+
if (name === undefined)
|
|
130
|
+
return writes ? undefined : []
|
|
131
|
+
|
|
132
|
+
keys.add(name)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (call.name === 'String')
|
|
136
|
+
return bounded || keys.has('max') || keys.has('maxLength') ? [] : ['max: Number.MAX_SAFE_INTEGER']
|
|
137
|
+
|
|
138
|
+
if (call.name === 'Object')
|
|
139
|
+
return keys.has('extra') ? [] : ['extra: \'strip\'']
|
|
140
|
+
|
|
141
|
+
if (call.name !== 'Array')
|
|
142
|
+
return []
|
|
143
|
+
|
|
144
|
+
const [item] = call.node.arguments
|
|
145
|
+
|
|
146
|
+
return keys.has('max') || keys.has('maxItems') || (item && FILES.has(builderCallName(item))) ? [] : ['max: Number.MAX_SAFE_INTEGER']
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const BODY_METHODS = new Set(['get', 'post', 'put', 'patch', 'delete'])
|
|
150
|
+
|
|
151
|
+
// The schemas that are the `const` of a file at its top level, by name, and the names the file exports, whose uses beyond it are unknown.
|
|
152
|
+
function topLevelSchemas(ast: Program): { bound: Map<string, Node>, exported: Set<string> } {
|
|
153
|
+
const bound = new Map<string, Node>()
|
|
154
|
+
const exported = new Set<string>()
|
|
155
|
+
|
|
156
|
+
for (const statement of ast.body) {
|
|
157
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement
|
|
158
|
+
|
|
159
|
+
if (statement.type === 'ExportNamedDeclaration') {
|
|
160
|
+
for (const specifier of statement.specifiers)
|
|
161
|
+
exported.add((specifier.local as { name?: string }).name ?? '')
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'const')
|
|
165
|
+
continue
|
|
166
|
+
|
|
167
|
+
for (const entry of declaration.declarations) {
|
|
168
|
+
if (entry.id.type !== 'Identifier' || !entry.init)
|
|
169
|
+
continue
|
|
170
|
+
|
|
171
|
+
bound.set(entry.id.name, entry.init)
|
|
172
|
+
|
|
173
|
+
if (statement.type === 'ExportNamedDeclaration')
|
|
174
|
+
exported.add(entry.id.name)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return { bound, exported }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// The nodes of the schemas kay caps an unbounded string in at 10,000 characters already: an action's input, and the `body` of an API route (a call of a method taking a path literal first, which leaves out `client.post(url, { body })`). A schema held in a top-level `const` is capped when every use of the name is one of those and the file does not export it. What it cannot tell is left out, so the fix writes the bound that keeps the old behaviour there.
|
|
182
|
+
function cappedByKay(ast: Program, actions: Set<string>): Set<Node> {
|
|
183
|
+
const capped = new Set<Node>()
|
|
184
|
+
const uses = new Set<Node>()
|
|
185
|
+
const take = (schema: Node) => {
|
|
186
|
+
if (schema.type === 'Identifier')
|
|
187
|
+
uses.add(schema)
|
|
188
|
+
else
|
|
189
|
+
walk(schema, node => capped.add(node))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
walk(ast, (node) => {
|
|
193
|
+
if (node.type !== 'CallExpression')
|
|
194
|
+
return
|
|
195
|
+
|
|
196
|
+
const [first, ...rest] = node.arguments
|
|
197
|
+
|
|
198
|
+
if (node.callee.type === 'Identifier' && actions.has(node.callee.name) && first)
|
|
199
|
+
take(first)
|
|
200
|
+
|
|
201
|
+
if (node.callee.type !== 'MemberExpression' || node.callee.computed || node.callee.property.type !== 'Identifier' || !BODY_METHODS.has(node.callee.property.name))
|
|
202
|
+
return
|
|
203
|
+
|
|
204
|
+
if (first?.type !== 'Literal' || typeof first.value !== 'string' || !first.value.startsWith('/'))
|
|
205
|
+
return
|
|
206
|
+
|
|
207
|
+
for (const argument of rest) {
|
|
208
|
+
if (argument.type !== 'ObjectExpression')
|
|
209
|
+
continue
|
|
210
|
+
|
|
211
|
+
for (const entry of argument.properties) {
|
|
212
|
+
if (entry.type === 'Property' && keyName(entry) === 'body')
|
|
213
|
+
take(entry.value)
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
const { bound, exported } = topLevelSchemas(ast)
|
|
219
|
+
const declared = new Set<Node>()
|
|
220
|
+
|
|
221
|
+
for (const statement of ast.body) {
|
|
222
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement
|
|
223
|
+
|
|
224
|
+
if (declaration?.type === 'VariableDeclaration') {
|
|
225
|
+
for (const entry of declaration.declarations)
|
|
226
|
+
declared.add(entry.id)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const references = new Map<string, number>()
|
|
231
|
+
|
|
232
|
+
walk(ast, (node) => {
|
|
233
|
+
if (node.type === 'Identifier' && bound.has(node.name) && !declared.has(node))
|
|
234
|
+
references.set(node.name, (references.get(node.name) ?? 0) + 1)
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
for (const [name, init] of bound) {
|
|
238
|
+
const total = references.get(name) ?? 0
|
|
239
|
+
const cappedUses = [...uses].filter(use => use.type === 'Identifier' && use.name === name).length
|
|
240
|
+
|
|
241
|
+
if (total > 0 && total === cappedUses && !exported.has(name))
|
|
242
|
+
walk(init, node => capped.add(node))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return capped
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function builderCallName(node: Node): string {
|
|
249
|
+
return node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' ? node.callee.property.name : ''
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Where options go in a builder's call: into its options object, or after its last argument. Undefined for options that are not an object literal, which the fix leaves to the app.
|
|
253
|
+
function addOptions(call: Call, base: number, added: string[]): Edit | undefined {
|
|
84
254
|
const index = BUILDERS[call.name]!.options
|
|
85
255
|
const options = call.node.arguments[index]
|
|
256
|
+
const text = added.join(', ')
|
|
86
257
|
|
|
87
258
|
if (options === undefined) {
|
|
88
259
|
if (call.node.arguments.length < index)
|
|
@@ -90,7 +261,7 @@ function optionalEdit(call: Call, base: number): Edit | undefined {
|
|
|
90
261
|
|
|
91
262
|
const close = base + call.node.end - 1
|
|
92
263
|
|
|
93
|
-
return { start: close, end: close, text: call.node.arguments.length === 0 ?
|
|
264
|
+
return { start: close, end: close, text: call.node.arguments.length === 0 ? `{ ${text} }` : `, { ${text} }` }
|
|
94
265
|
}
|
|
95
266
|
|
|
96
267
|
if (options.type !== 'ObjectExpression')
|
|
@@ -98,7 +269,7 @@ function optionalEdit(call: Call, base: number): Edit | undefined {
|
|
|
98
269
|
|
|
99
270
|
const open = base + options.start
|
|
100
271
|
|
|
101
|
-
return { start: open, end: open + 1, text: options.properties.length === 0 ?
|
|
272
|
+
return { start: open, end: open + 1, text: options.properties.length === 0 ? `{ ${text} ` : `{ ${text},` }
|
|
102
273
|
}
|
|
103
274
|
|
|
104
275
|
type Program = Parameters<typeof importsOf>[0]
|
|
@@ -146,8 +317,26 @@ function dropUnreadImport(ast: Program, receivers: Set<string>, dropped: number,
|
|
|
146
317
|
}
|
|
147
318
|
}
|
|
148
319
|
|
|
320
|
+
// `defineEnv(s.Object({ ... }))`: an env reads only the names its schema declares, so the record changes nothing. True when it reported one.
|
|
321
|
+
function envRecord(node: Node, records: Set<string>, receivers: Set<string>, base: number, taken: Set<Node>, report: Report): boolean {
|
|
322
|
+
if (node.type !== 'CallExpression' || node.callee.type !== 'Identifier' || !records.has(node.callee.name))
|
|
323
|
+
return false
|
|
324
|
+
|
|
325
|
+
const [schema] = node.arguments
|
|
326
|
+
const inner = schema === undefined ? undefined : builderCall(schema, receivers)
|
|
327
|
+
const shape = inner?.node.arguments[0]
|
|
328
|
+
|
|
329
|
+
if (!schema || inner?.name !== 'Object' || inner.node.arguments.length !== 1 || shape?.type !== 'ObjectExpression')
|
|
330
|
+
return false
|
|
331
|
+
|
|
332
|
+
taken.add(schema)
|
|
333
|
+
report(base + schema.start, base + schema.end, 'a plain record of fields is the schema of a defineEnv since 1.106, `s.Object` being the PascalCase builder it replaces; the old form works until 2.0', 'write the record of fields', [{ start: base + schema.start, end: base + shape.start, text: '' }, { start: base + shape.end, end: base + schema.end, text: '' }])
|
|
334
|
+
|
|
335
|
+
return true
|
|
336
|
+
}
|
|
337
|
+
|
|
149
338
|
// The PascalCase builders of `s`, which kay 1.106 replaces with its own lowercase ones, and the `'2m'` sizes of a file field, which are `'2mb'` as every size is.
|
|
150
|
-
// Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. `s.Optional(x)` of one of these builders is `optional: true` in its options; an `s.
|
|
339
|
+
// Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. `s.Optional(x)` of one of these builders is `optional: true` in its options; an `s.Array`, and an `s.String` with no bound outside an action's input and an API body, takes `max: Number.MAX_SAFE_INTEGER`, and an `s.Object` `extra: 'strip'`, which keeps what they did.
|
|
151
340
|
export async function schemaBuilders(root: string, options: CheckOptions): Promise<CheckDiagnostic[]> {
|
|
152
341
|
if (lintLevel('deprecated-schema-builders', options.lints) === 'allow')
|
|
153
342
|
return []
|
|
@@ -155,33 +344,23 @@ export async function schemaBuilders(root: string, options: CheckOptions): Promi
|
|
|
155
344
|
return scan(root, options, 'deprecated-schema-builders', NEEDLE, ({ parsed, report }) => {
|
|
156
345
|
for (const { ast, base, text } of parsed) {
|
|
157
346
|
const receivers = importsOf(ast, source => KAY.test(source), 's').locals
|
|
158
|
-
const records =
|
|
347
|
+
const records = importsOf(ast, source => KAY.test(source), 'defineEnv').locals
|
|
348
|
+
const capped = cappedByKay(ast, importsOf(ast, source => KAY.test(source), 'action').locals)
|
|
159
349
|
|
|
160
350
|
if (receivers.size === 0)
|
|
161
351
|
continue
|
|
162
352
|
|
|
163
|
-
// What an `s.Optional(...)`
|
|
353
|
+
// What an `s.Optional(...)` has taken over, so the call inside is not reported on its own.
|
|
164
354
|
const taken = new Set<Node>()
|
|
165
|
-
// The uses of `s` a fix takes away: an `s.
|
|
355
|
+
// The uses of `s` a fix takes away: an `s.Object(` of an env record.
|
|
166
356
|
let dropped = 0
|
|
167
357
|
|
|
168
358
|
walk(ast, (node) => {
|
|
169
359
|
const call = builderCall(node, receivers)
|
|
170
360
|
|
|
171
361
|
if (call === undefined) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const [schema] = node.arguments
|
|
175
|
-
const inner = schema === undefined ? undefined : builderCall(schema, receivers)
|
|
176
|
-
|
|
177
|
-
if (schema && inner?.name === 'Object' && inner.node.arguments.length === 1 && inner.node.arguments[0]!.type === 'ObjectExpression') {
|
|
178
|
-
const shape = inner.node.arguments[0]
|
|
179
|
-
|
|
180
|
-
taken.add(schema)
|
|
181
|
-
dropped++
|
|
182
|
-
report(base + schema.start, base + schema.end, 'a plain record of fields is the object schema of an action or a defineEnv since 1.106, `s.Object` being the PascalCase builder it replaces; the old form works until 2.0', 'write the record of fields', [{ start: base + schema.start, end: base + shape.start, text: '' }, { start: base + shape.end, end: base + schema.end, text: '' }])
|
|
183
|
-
}
|
|
184
|
-
}
|
|
362
|
+
if (envRecord(node, records, receivers, base, taken, report))
|
|
363
|
+
dropped++
|
|
185
364
|
|
|
186
365
|
return
|
|
187
366
|
}
|
|
@@ -190,7 +369,8 @@ export async function schemaBuilders(root: string, options: CheckOptions): Promi
|
|
|
190
369
|
const [inner, ...others] = call.node.arguments
|
|
191
370
|
const wrapped = inner === undefined ? undefined : builderCall(inner, receivers)
|
|
192
371
|
const known = wrapped && wrapped.name !== 'Public' && BUILDERS[wrapped.name] && !taken.has(inner!)
|
|
193
|
-
const
|
|
372
|
+
const kept = known ? keptOptions(wrapped, capped.has(wrapped.node)) : undefined
|
|
373
|
+
const edit = known && kept ? addOptions(wrapped, base, ['optional: true', ...kept]) : undefined
|
|
194
374
|
|
|
195
375
|
// Anything but a builder of `s`, such as the `imageField()` of kay/content, has no `optional` option to write yet.
|
|
196
376
|
if (!known)
|
|
@@ -203,7 +383,6 @@ export async function schemaBuilders(root: string, options: CheckOptions): Promi
|
|
|
203
383
|
}
|
|
204
384
|
|
|
205
385
|
taken.add(inner!)
|
|
206
|
-
dropped++
|
|
207
386
|
report(base + node.start, base + node.end, '`s.Optional(field)` is `optional: true` in the options of the field since 1.106, the same option on every builder; the old form works until 2.0', 'write `optional: true` in the field\'s options', [
|
|
208
387
|
{ start: base + node.start, end: base + inner!.start, text: '' },
|
|
209
388
|
...renames(wrapped, base),
|
|
@@ -216,13 +395,38 @@ export async function schemaBuilders(root: string, options: CheckOptions): Promi
|
|
|
216
395
|
|
|
217
396
|
const builder = BUILDERS[call.name]
|
|
218
397
|
|
|
398
|
+
// A mapped array is no tuple, so `s.union(...)` of one is a type error: `s.enum(record)` when it is the keys of a record, else the app writes it.
|
|
399
|
+
if (call.name === 'Union' && !taken.has(node) && call.node.arguments[0]?.type !== 'ArrayExpression') {
|
|
400
|
+
const mapped = call.node.arguments.length === 1 ? mappedKeys(call.node.arguments[0]!, receivers) : undefined
|
|
401
|
+
const message = '`s.Union` is `s.union` since 1.106, and `s.union` takes its schemas written out as a list, so an array built at run time is a type error'
|
|
402
|
+
const receiver = (call.node.callee as { object: { name: string } }).object.name
|
|
403
|
+
|
|
404
|
+
if (mapped) {
|
|
405
|
+
taken.add(mapped.literal)
|
|
406
|
+
report(base + node.start, base + node.end, `${message}; \`s.enum(record)\` takes the keys of a record`, 'write `s.enum` with the record', [
|
|
407
|
+
{ start: base + node.start, end: base + mapped.record.start, text: `${receiver}.enum(` },
|
|
408
|
+
{ start: base + mapped.record.end, end: base + node.end, text: ')' },
|
|
409
|
+
])
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
report(base + node.start, base + node.end, `${message}; write the schemas out as a list, or \`s.enum\` for the keys of a record`, 'write the schemas as a list, or `s.enum`', null)
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return
|
|
416
|
+
}
|
|
417
|
+
|
|
219
418
|
if (builder && !taken.has(node)) {
|
|
220
|
-
const
|
|
419
|
+
const kept = keptOptions(call, capped.has(node))
|
|
420
|
+
const edit = kept && kept.length > 0 ? addOptions(call, base, kept) : undefined
|
|
421
|
+
const object = call.name === 'Object' ? 'unknown keys are refused by `s.object` where kay reads the schema itself, where `s.Object` let them by, so the fix writes `extra: \'strip\'` to keep the old way' : ''
|
|
221
422
|
const message = call.name === 'UnionKeys' || call.name === 'UnionEnum'
|
|
222
423
|
? '`s.enum()` takes the values, or a record whose keys are the values, since 1.106, in place of `s.UnionEnum` and `s.UnionKeys`; the old forms work until 2.0'
|
|
223
|
-
: `\`s.${call.name}\` is \`s.${builder.name}\` since 1.106, kay's own lowercase builders with short options (\`min\`, \`max\`, \`optional\`) replacing the PascalCase ones of TypeBox${object ? `; ${object}` : ''}; the old form works until 2.0`
|
|
424
|
+
: `\`s.${call.name}\` is \`s.${builder.name}\` since 1.106, kay's own lowercase builders with short options (\`min\`, \`max\`, \`optional\`) replacing the PascalCase ones of TypeBox${object ? `; ${object}` : ''}; the old form works until 2.0${call.name === 'Array' ? '; `s.list` is at most 1,000 items where `s.Array` had no limit, so the fix writes `max: Number.MAX_SAFE_INTEGER`' : ''}${call.name === 'String' ? '; `s.string` is at most 10,000 characters where `s.String` had no limit, which an action\'s input and an API body already had, so the fix writes `max: Number.MAX_SAFE_INTEGER` anywhere else' : ''}`
|
|
425
|
+
|
|
426
|
+
// Without the option that keeps the old behaviour the rename would change it, so the fix is left to the app.
|
|
427
|
+
const keeps = kept !== undefined && (kept.length === 0 || edit !== undefined)
|
|
224
428
|
|
|
225
|
-
report(base + node.start, base + node.end, message, `write \`s.${builder.name}\``, renames(call, base))
|
|
429
|
+
report(base + node.start, base + node.end, message, `write \`s.${builder.name}\``, keeps ? [...renames(call, base), ...edit ? [edit] : []] : null)
|
|
226
430
|
}
|
|
227
431
|
})
|
|
228
432
|
|
|
@@ -323,11 +323,11 @@ async function libraryShadows(root: string, options: CheckOptions, own: string[]
|
|
|
323
323
|
})])
|
|
324
324
|
const unreached = new Set<string>()
|
|
325
325
|
|
|
326
|
-
await Promise.all(followed.
|
|
326
|
+
await Promise.all(followed.map(async (library) => {
|
|
327
327
|
const own = programs.some(program => program.library === library)
|
|
328
328
|
|
|
329
329
|
// A link left from a run in which the package was a program of its own would take what is written under `node_modules` to that program's folder.
|
|
330
|
-
if (!own)
|
|
330
|
+
if (!own && library.extension)
|
|
331
331
|
await dropLink(dirname(shadowPath(root, join(library.dir, 'x'))))
|
|
332
332
|
|
|
333
333
|
await linkDependencies(root, library, own, tree)
|
|
@@ -423,7 +423,7 @@ async function dropLink(path: string) {
|
|
|
423
423
|
catch {}
|
|
424
424
|
}
|
|
425
425
|
|
|
426
|
-
// A bare import climbs from the shadow, not from the package, so the dependencies the package installs are linked beside its shadows: its own `node_modules`, and the ones above it that the app's ancestors do not include.
|
|
426
|
+
// A bare import climbs from the shadow, not from the package, so the dependencies the package installs are linked beside its shadows, under bun's isolated install, where they sit beside the package's real path in `node_modules/.bun` and not in the app's `node_modules`, so an app need not list them: its own `node_modules`, and the ones above it that the app's ancestors do not include.
|
|
427
427
|
async function linkDependencies(root: string, { dir, realDir }: KayLibrary, own: boolean, tree: ShadowTree) {
|
|
428
428
|
const types = projectPaths(root).types
|
|
429
429
|
// The package of a program is shadowed beside its real path.
|
package/src/commands/upgrade.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { dirname, join } from 'node:path'
|
|
|
6
6
|
import process from 'node:process'
|
|
7
7
|
import { engines } from '../../package.json'
|
|
8
8
|
import { renameProjectFiles } from '../check/renamed-packages'
|
|
9
|
-
import { DEPRECATION_MINORS,
|
|
9
|
+
import { DEPRECATION_MINORS, UPGRADE_FROM } from '../compiler/lints'
|
|
10
|
+
import { minorAfter, minorOf } from '../compiler/minor'
|
|
10
11
|
import { isKayPackage, RENAMED_IN, renamePackages } from '../package-names'
|
|
11
12
|
import { done, formatOption, printDocument, printFailure, projectRoot } from './command'
|
|
12
13
|
import { majorWarning } from './upgrade-majors'
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Diagnostic } from './ast'
|
|
2
2
|
import { positionAt } from './mapping'
|
|
3
|
+
import { REMOVED_LINTS } from './removed-lints'
|
|
3
4
|
|
|
4
5
|
// What `lints.comments` in kay.config.ts asks of a `// kay-allow` comment: a comment that fails one of these allows nothing and is reported.
|
|
5
6
|
export interface AllowRules {
|
|
@@ -14,6 +15,7 @@ export interface AllowRules {
|
|
|
14
15
|
// A lint's name starts with a letter, so the `--` of a reason is never read as one: `// kay-allow a, b -- why`.
|
|
15
16
|
const ALLOW_COMMENT = /\/\/[ \t]*(kay-allow(?:-file)?)[ \t]+(\w[\w-]*(?:[ \t]*,[ \t]*\w[\w-]*)*)([^\n]*)/g
|
|
16
17
|
const LINT_NAME = /[\w-]+/g
|
|
18
|
+
const BLANK_END = /[ \t]*$/
|
|
17
19
|
const REASON = /^[ \t]*--[ \t]*\S/
|
|
18
20
|
|
|
19
21
|
export interface AllowComment {
|
|
@@ -22,8 +24,9 @@ export interface AllowComment {
|
|
|
22
24
|
file: boolean
|
|
23
25
|
// The line it allows: its own when it ends a line of code, the next when it is alone on its line; unused for a file comment.
|
|
24
26
|
line: number
|
|
25
|
-
// The offset of the comment's
|
|
27
|
+
// The offset of the comment's `//`, and of the end of what it holds.
|
|
26
28
|
start: number
|
|
29
|
+
end: number
|
|
27
30
|
// Whether a reason follows the names.
|
|
28
31
|
reasoned: boolean
|
|
29
32
|
}
|
|
@@ -35,7 +38,40 @@ export function allowComments(source: string): AllowComment[] {
|
|
|
35
38
|
const names = Array.from(comment[2]!.matchAll(LINT_NAME), name => ({ name: name[0], start: listStart + name.index }))
|
|
36
39
|
|
|
37
40
|
// A comment alone on its line allows the next one; one ending a line of code allows that line.
|
|
38
|
-
return { names, file: comment[1] === 'kay-allow-file', line: source.slice(comment.index - column + 1, comment.index).trim() === '' ? line + 1 : line, start: comment.index, reasoned: REASON.test(comment[3]!) }
|
|
41
|
+
return { names, file: comment[1] === 'kay-allow-file', line: source.slice(comment.index - column + 1, comment.index).trim() === '' ? line + 1 : line, start: comment.index, end: comment.index + comment[0].length, reasoned: REASON.test(comment[3]!) }
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// The names a comment holds that `known` does not know: a lint kay removed is a warning with a fix that drops the name, or the comment (its line when it stands alone) when it was the only one left, and any other name is the error `unknown-lint`.
|
|
46
|
+
export function unknownNames(comment: AllowComment, source: string, known: (name: string) => boolean, help: string): Diagnostic[] {
|
|
47
|
+
const unknown = comment.names.filter(({ name }) => !known(name))
|
|
48
|
+
const removed = new Set<string>(REMOVED_LINTS)
|
|
49
|
+
const lastKept = comment.names.findLastIndex(({ name }) => !removed.has(name))
|
|
50
|
+
const lineStart = source.lastIndexOf('\n', comment.start - 1) + 1
|
|
51
|
+
const whole = source.slice(lineStart, comment.start).trim() === ''
|
|
52
|
+
const after = comment.end + (source.startsWith('\r\n', comment.end) ? 2 : Number(source[comment.end] === '\n'))
|
|
53
|
+
const before = comment.start - (BLANK_END.exec(source.slice(lineStart, comment.start))?.[0].length ?? 0)
|
|
54
|
+
const last = comment.names.at(-1)!
|
|
55
|
+
|
|
56
|
+
return unknown.map(({ name, start }): Diagnostic => {
|
|
57
|
+
const end = start + name.length
|
|
58
|
+
|
|
59
|
+
if (!removed.has(name))
|
|
60
|
+
return { start, end, code: 'unknown-lint', message: `Unknown lint \`${name}\``, help, checkOnly: true }
|
|
61
|
+
|
|
62
|
+
const position = comment.names.findIndex(other => other.start === start)
|
|
63
|
+
const diagnostic: Diagnostic = { start, end, code: 'unknown-lint', severity: 'warning', message: `\`${name}\` is a lint kay has removed`, help: 'remove it from the comment: it allows nothing', checkOnly: true }
|
|
64
|
+
|
|
65
|
+
// The removed names after the last live one go in one edit, on the first of them, so no two edits overlap; the comment itself goes when no name is live.
|
|
66
|
+
if (position > lastKept && position !== lastKept + 1)
|
|
67
|
+
return diagnostic
|
|
68
|
+
|
|
69
|
+
const kept = comment.names[lastKept]
|
|
70
|
+
const dropped = whole ? { start: lineStart, end: after } : { start: before, end: comment.end }
|
|
71
|
+
const tail = kept ? { start: kept.start + kept.name.length, end: last.start + last.name.length } : dropped
|
|
72
|
+
const edit = position > lastKept ? tail : { start, end: comment.names[position + 1]!.start }
|
|
73
|
+
|
|
74
|
+
return { ...diagnostic, fixes: [{ title: kept || position < lastKept ? `remove \`${name}\`` : 'remove the comment', safe: true, edits: [{ ...edit, text: '' }] }] }
|
|
39
75
|
})
|
|
40
76
|
}
|
|
41
77
|
|
package/src/compiler/ast.ts
CHANGED
|
@@ -489,7 +489,7 @@ export function isChildrenSlot(node: Node): boolean {
|
|
|
489
489
|
return isSlot(node) && (node as ElementNode).outlet === undefined
|
|
490
490
|
}
|
|
491
491
|
|
|
492
|
-
export type TemplateHelper = 'For' | 'componentClass' | 'handParts' | 'partClass' | 'partHanded' | '
|
|
492
|
+
export type TemplateHelper = 'For' | 'componentClass' | 'handParts' | 'partClass' | 'partHanded' | 'partProps'
|
|
493
493
|
|
|
494
494
|
// Whether an entry of `src/ui.ts` has variants, which read the component's props: without them its parts are static classes, written into the template as they are.
|
|
495
495
|
export function uiHasVariants(entry: UiEntry): boolean {
|
|
@@ -701,7 +701,7 @@ function addRecipe(facts: TemplateFacts, file: KayFile, recipe: string): void {
|
|
|
701
701
|
facts.helpers.add('partClass')
|
|
702
702
|
|
|
703
703
|
if (facts.parts.implicit?.component) {
|
|
704
|
-
facts.helpers.add('
|
|
704
|
+
facts.helpers.add('partProps')
|
|
705
705
|
facts.helpers.add('handParts')
|
|
706
706
|
}
|
|
707
707
|
}
|
|
@@ -747,7 +747,7 @@ function factsOf(file: KayFile): TemplateFacts {
|
|
|
747
747
|
facts.helpers.add('partClass')
|
|
748
748
|
|
|
749
749
|
if (node.component) {
|
|
750
|
-
facts.helpers.add('
|
|
750
|
+
facts.helpers.add('partProps')
|
|
751
751
|
facts.helpers.add('handParts')
|
|
752
752
|
}
|
|
753
753
|
|
|
@@ -785,7 +785,7 @@ function factsOf(file: KayFile): TemplateFacts {
|
|
|
785
785
|
markRoot(facts.parts, file.template)
|
|
786
786
|
|
|
787
787
|
if (facts.parts.implicit?.component) {
|
|
788
|
-
facts.helpers.add('
|
|
788
|
+
facts.helpers.add('partProps')
|
|
789
789
|
facts.helpers.add('handParts')
|
|
790
790
|
}
|
|
791
791
|
}
|
package/src/compiler/codegen.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { emitHeadTag, emitHeadText } from './head-tags'
|
|
|
18
18
|
import { awaitAlertTail, htmlHelperImport, HtmlTemplate } from './html'
|
|
19
19
|
import { withoutComma } from './import-edits'
|
|
20
20
|
import { sourceLocator } from './inspect'
|
|
21
|
-
import { islandMessages, withAlertKeys } from './island-arguments'
|
|
21
|
+
import { islandExport, islandMessages, withAlertKeys } from './island-arguments'
|
|
22
22
|
import { ambientHelpers, constDeclaration } from './items'
|
|
23
23
|
import { JsxTemplate } from './jsx'
|
|
24
24
|
import { lazyDomImport, lazyEdits, lazyNoteImport } from './lazy-imports'
|
|
@@ -187,7 +187,7 @@ export function generate(file: KayFile, script: ScriptAnalysis, server: ServerAn
|
|
|
187
187
|
// The module around a template, alike for every output mode: its imports, the server fence's `load`, the component's signature, props and script, and its export; the template renders through the writer of the mode.
|
|
188
188
|
class ModuleShell {
|
|
189
189
|
private readonly b: CodeBuilder
|
|
190
|
-
private readonly sites: Sites = { rows: new Set(), consts: new Map(), loopItems: new Set(), snippets: new Set(), props: new Map() }
|
|
190
|
+
private readonly sites: Sites = { rows: new Set(), blocks: new Set(), consts: new Map(), loopItems: new Set(), snippets: new Set(), props: new Map() }
|
|
191
191
|
private readonly src: string
|
|
192
192
|
private readonly mode: OutputMode
|
|
193
193
|
private readonly kind: IslandKind
|
|
@@ -617,11 +617,11 @@ class ModuleShell {
|
|
|
617
617
|
if (this.kind === 'twin')
|
|
618
618
|
b.add(`\nexport default ${this.mode === 'html' && this.options.failedCode !== undefined ? `Object.assign((props: never) => KayInsideIsland() ? KayHydrated(props) : ${name}(props), { kayFailed: KayFailed })` : `((props: never) => KayInsideIsland() ? KayHydrated(props) : ${name}(props))`} as typeof ${name}${widened ? this.widenedCall(`typeof ${name}`) : ''}\n`)
|
|
619
619
|
else if (this.kind === 'island' && widened && !this.genericComponent)
|
|
620
|
-
b.add(
|
|
620
|
+
b.add(islandExport(`KayIsland(${JSON.stringify(this.options.island)}, ${name}${this.islandTail(src)}) as unknown as ReturnType<typeof KayIsland<Parameters<typeof ${name}>[0]>>${this.widenedCall(`ReturnType<typeof KayIsland<Parameters<typeof ${name}>[0]>>`)}`, this.script.island, this.options))
|
|
621
621
|
else if (widened && this.kind !== 'island')
|
|
622
622
|
b.add(`\nexport default ${name} as typeof ${name}${this.widenedCall(`typeof ${name}`)}\n`)
|
|
623
623
|
else if (this.kind === 'island')
|
|
624
|
-
b.add(
|
|
624
|
+
b.add(islandExport(`KayIsland(${JSON.stringify(this.options.island)}, ${name}${this.genericComponent ? ' as never' : ''}${this.islandTail(src)})${this.genericIslandType()}${widened ? this.widenedCall(`typeof ${name}`) : ''}`, this.script.island, this.options))
|
|
625
625
|
}
|
|
626
626
|
|
|
627
627
|
// The arguments after the component that `island()` takes: its message keys, the live values and cause of a server render, and what its `island()` call asks, the hydrate and persist the component asks for wherever it is used.
|
|
@@ -7,8 +7,8 @@ export const SCHEMA_BUILDERS = {
|
|
|
7
7
|
group: 'deprecated',
|
|
8
8
|
since: '1.106',
|
|
9
9
|
site: true,
|
|
10
|
-
summary: 'The PascalCase builders of `s` before 1.106, which kay\'s own lowercase builders replace, each taking the same field options (`optional`, `default`, `error`, `label`, `description`, `example`) and short names for the rest: `s.String` is `s.string` (`min`, `max`), `s.Integer` `s.int`, `s.Number` and `s.Numeric` `s.number`, `s.Boolean` and `s.BooleanString` `s.boolean`, `s.Array` `s.list`, `s.UnionEnum` and `s.UnionKeys` `s.enum`, and `s.Date`, `s.Literal`, `s.Union`, `s.Object`, `s.File`, `s.Files`, `s.Secret` and `s.Public` their lowercase names; `s.Optional(field)` is `optional: true` in the options of the field; an `s.Object({ ... })` that is the schema of
|
|
10
|
+
summary: 'The PascalCase builders of `s` before 1.106, which kay\'s own lowercase builders replace, each taking the same field options (`optional`, `default`, `error`, `label`, `description`, `example`) and short names for the rest: `s.String` is `s.string` (`min`, `max`), `s.Integer` `s.int`, `s.Number` and `s.Numeric` `s.number`, `s.Boolean` and `s.BooleanString` `s.boolean`, `s.Array` `s.list`, `s.UnionEnum` and `s.UnionKeys` `s.enum`, and `s.Date`, `s.Literal`, `s.Union`, `s.Object`, `s.File`, `s.Files`, `s.Secret` and `s.Public` their lowercase names; `s.Optional(field)` is `optional: true` in the options of the field; an `s.Object({ ... })` that is the schema of a `defineEnv` is the record of fields alone, as an env reads only the names it declares; and a file size written `\'2m\'` is `\'2mb\'`. The old names work until 2.0. Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. The fix renames the builder and the options that changed, and keeps what each did: an `s.Array` takes `max: Number.MAX_SAFE_INTEGER` (the lowercase list stops at 1,000 items) and an `s.Object` `extra: \'strip\'`, a rewrite whose options are not an object literal being reported without a fix; an `s.Union` of `Object.keys(R).map(key => s.Literal(key))` is `s.enum(R)`, and any other `s.Union` of a mapped array is reported without a fix; an `s.Optional` around anything but one of these builders, such as a helper of `kay/content`, is left as it is. A lowercase `s.object` refuses a key its shape lacks where kay reads the schema itself (an action\'s input, an API route\'s body, `defineEnv`, collection frontmatter), where `s.Object` let it by, so the fix writes `{ extra: \'strip\' }`. A query, the headers and the cookies of a request carry keys no schema names, so their unknown keys are dropped whatever the schema says.',
|
|
11
11
|
wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.Object({ title: s.String({ maxLength: 200 }), note: s.Optional(s.String()) }), ({ title }) => title)\n---\np x',
|
|
12
|
-
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ title: s.string({ max: 200 }), note: s.string({ optional: true }) }, ({ title }) => title)\n---\np x',
|
|
12
|
+
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.object({ title: s.string({ max: 200 }), note: s.string({ optional: true }) }, { extra: \'strip\' }), ({ title }) => title)\n---\np x',
|
|
13
13
|
},
|
|
14
14
|
} as const satisfies Record<string, Lint>
|
package/src/compiler/dom.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { FormHere } from './dom-here'
|
|
|
11
11
|
import { propertyBindings } from './dom-property'
|
|
12
12
|
import { addHandler, listenerOptions } from './event-modifiers'
|
|
13
13
|
import { decodeEntities, isFunctionAt } from './expression'
|
|
14
|
-
import { addKeyParameters, addRowItem, childItems, constDeclaration, contentOf, errorParagraphArguments, isDeclaration, rowKeying, slotValue, soleDynamic } from './items'
|
|
14
|
+
import { addKeyParameters, addRowItem, addSlotCall, childItems, constDeclaration, contentOf, errorParagraphArguments, isDeclaration, rowKeying, slotValue, soleDynamic } from './items'
|
|
15
15
|
import { addBindWrite, bindRead, END_MARKER, escapeStaticAttribute, escapeText, helperName, RAW_ELEMENTS, START_MARKER, TemplateWriter, VOID_ELEMENTS } from './markup'
|
|
16
16
|
import { SUBJECT } from './names'
|
|
17
17
|
import { addGroupChecked, checksMarkup, groupValue, staticAttributeText } from './plan'
|
|
@@ -157,7 +157,8 @@ export class DomTemplate extends TemplateWriter {
|
|
|
157
157
|
b.add(`${helperName(this.scoping)}((`).addSource(form).add('), () => ')
|
|
158
158
|
|
|
159
159
|
if (item.node.outlet) {
|
|
160
|
-
|
|
160
|
+
if (!addSlotCall(b, this.src, item.node, helperName('slotCall')))
|
|
161
|
+
slotValue(b, item.node)
|
|
161
162
|
}
|
|
162
163
|
else {
|
|
163
164
|
b.add('{ const KayC = ')
|
|
@@ -167,7 +168,7 @@ export class DomTemplate extends TemplateWriter {
|
|
|
167
168
|
|
|
168
169
|
b.add(')')
|
|
169
170
|
}
|
|
170
|
-
else {
|
|
171
|
+
else if (!addSlotCall(b, this.src, item.node, helperName('slotCall'))) {
|
|
171
172
|
slotValue(b, item.node)
|
|
172
173
|
}
|
|
173
174
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { Attribute, ElementNode, NamedAttribute } from './ast'
|
|
1
|
+
import type { Attribute, ElementNode, NamedAttribute, PartFacts } from './ast'
|
|
2
|
+
import type { ClassItem } from './class-items'
|
|
2
3
|
import type { CodeBuilder } from './mapping'
|
|
4
|
+
import { handedParts, partsOf } from './ast'
|
|
3
5
|
import { helperName } from './markup'
|
|
6
|
+
import { PROPS } from './names'
|
|
4
7
|
|
|
5
8
|
type ExpressionAttribute = Extract<NamedAttribute, { kind: 'expression' }>
|
|
6
9
|
|
|
@@ -11,16 +14,41 @@ export function writtenParts(element: ElementNode, source: string): Attribute[]
|
|
|
11
14
|
return [...element.attributes.filter(one => one.kind === 'spread'), hand].filter(attribute => attribute !== undefined)
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
//
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
+
// Whether a component call hands a part of this component on without being handed parts itself: it writes its `class` and `parts` as one source, `partProps`.
|
|
18
|
+
export function writesTogether(element: ElementNode, source: string, facts: PartFacts | undefined): boolean {
|
|
19
|
+
return element.component && partsOf(element, source, facts).length > 0 && handedParts(element, source, facts).length === 0
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// What a part handed on to a component adds to the class list: its recipe's classes and the caller's entry for it, which `partHanded` makes the part's value.
|
|
23
|
+
export function handedItem(b: CodeBuilder, part: string, recipe: readonly (() => void)[]): ClassItem {
|
|
24
|
+
return {
|
|
25
|
+
emit: () => {
|
|
26
|
+
b.add(`${helperName('partHanded')}(${JSON.stringify(part)}, [`)
|
|
27
|
+
|
|
28
|
+
for (const emit of recipe) {
|
|
29
|
+
emit()
|
|
30
|
+
b.add(', ')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
b.add(`${helperName('partClass')}(${PROPS}, ${JSON.stringify(part)})])`)
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// What opens the list of classes of an element: an array, or on a component call the helper merging it, which is `handParts` for the `parts` of a call handing parts on and `partProps` for the `class` and `parts` of a call written as one source.
|
|
39
|
+
export function openClassList(b: CodeBuilder, component: boolean, handing: readonly Attribute[] | undefined, together: boolean): void {
|
|
40
|
+
if (together) {
|
|
41
|
+
b.add(`${helperName('partProps')}(() => [[`)
|
|
42
|
+
|
|
43
|
+
return
|
|
44
|
+
}
|
|
17
45
|
|
|
18
|
-
b.add(component ? `${helperName(
|
|
46
|
+
b.add(component ? `${helperName(handing ? 'handParts' : 'componentClass')}([` : '[')
|
|
19
47
|
}
|
|
20
48
|
|
|
21
49
|
// What closes the `handParts` of a call: the `parts` it writes, the spreads' under them.
|
|
22
|
-
export function closeHandParts(b: CodeBuilder, component: boolean, written: readonly Attribute[] | undefined): void {
|
|
23
|
-
b.add(component && !written ? '])' : ']')
|
|
50
|
+
export function closeHandParts(b: CodeBuilder, component: boolean, written: readonly Attribute[] | undefined, together: boolean): void {
|
|
51
|
+
b.add(component && !written && !together ? '])' : ']')
|
|
24
52
|
|
|
25
53
|
const given = written?.filter(attribute => attribute.kind === 'expression' || attribute.kind === 'spread') ?? []
|
|
26
54
|
const emit = (attribute: (typeof given)[number]) => {
|
|
@@ -46,7 +74,7 @@ export function closeHandParts(b: CodeBuilder, component: boolean, written: read
|
|
|
46
74
|
}
|
|
47
75
|
|
|
48
76
|
if (written)
|
|
49
|
-
b.add(')')
|
|
77
|
+
b.add(together ? '])' : ')')
|
|
50
78
|
}
|
|
51
79
|
|
|
52
80
|
// Whether an attribute of a call handing parts on is one it writes itself, as `parts`: the `parts` and the spreads.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { KayFile } from './ast'
|
|
2
|
+
import type { ScriptAnalysis } from './script'
|
|
3
|
+
import type { ServerAnalysis } from './script-server'
|
|
4
|
+
import { templateWords } from './template-reads'
|
|
5
|
+
|
|
6
|
+
// The fence of a page that is an island with only the server values its script or template read, for the HTML output that builds the island's props: a value only the fence reads stays on the server.
|
|
7
|
+
// The analysis pass tells the reads from scopes, so a dynamic access cannot hide one; it leaves out the template's handlers, refs, transitions and loop keys, so any name a template expression writes stays too, and a fence that did not parse hands every one over.
|
|
8
|
+
export function handedServer(island: boolean, output: string | undefined, file: KayFile, script: ScriptAnalysis, server: ServerAnalysis | undefined, unread: ReadonlySet<number>): ServerAnalysis | undefined {
|
|
9
|
+
if (!island || output !== 'html' || !server || script.unparsed !== undefined || server.unparsed !== undefined)
|
|
10
|
+
return server
|
|
11
|
+
|
|
12
|
+
const words = new Set(templateWords(file))
|
|
13
|
+
|
|
14
|
+
return { ...server, data: server.data.filter(data => !unread.has(data.local.start) || words.has(data.name)) }
|
|
15
|
+
}
|