@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
|
@@ -2,10 +2,10 @@ import type { AwaitAlert } from './names'
|
|
|
2
2
|
import { helperName } from './markup'
|
|
3
3
|
|
|
4
4
|
// The `kay/html` helpers static server output calls, each imported under a `Kay` name.
|
|
5
|
-
const HTML_HELPERS = ['attempt', 'attribute', 'checkedMarkup', 'child', 'className', 'component', 'componentClass', 'currentPage', 'dynamic', 'element', 'errorParagraph', 'fieldDescribed', 'formConstraints', 'formKey', 'formOptions', 'formType', 'handParts', 'head', 'html', 'imageAttributes', 'innerMarkup', 'leadingNewline', 'linkHref', 'localHref', 'loop', 'memo', 'merge', 'nonEmptyAttribute', 'omit', 'outsideLink', 'partClass', 'partHanded', '
|
|
5
|
+
const HTML_HELPERS = ['attempt', 'attribute', 'checkedMarkup', 'child', 'className', 'component', 'componentClass', 'currentPage', 'dynamic', 'element', 'errorParagraph', 'fieldDescribed', 'formConstraints', 'formKey', 'formOptions', 'formType', 'handParts', 'head', 'html', 'imageAttributes', 'innerMarkup', 'leadingNewline', 'linkHref', 'localHref', 'loop', 'memo', 'merge', 'nonEmptyAttribute', 'omit', 'outsideLink', 'param', 'partClass', 'partHanded', 'partProps', 'raw', 'rawData', 'rawTyped', 'refillOptions', 'rowKey', 'schemaFill', 'selectOptions', 'serverIsland', 'show', 'spreadAttributes', 'spreadWith', 'style', 'untrack']
|
|
6
6
|
|
|
7
7
|
// The `kay/dom` helpers browser output calls, each imported under a `Kay` name.
|
|
8
|
-
const DOM_HELPERS = ['append', 'attribute', 'branches', 'checkedMarkup', 'choose', 'close', 'component', 'componentClass', 'effect', 'errorParagraph', 'fragment', 'handParts', 'holdSubmits', 'insert', 'listen', 'listenSubmit', 'listenSubmitWith', 'listenWith', 'markers', 'memo', 'merge', 'omit', 'outside', 'part', 'partClass', 'partHanded', '
|
|
8
|
+
const DOM_HELPERS = ['append', 'attribute', 'branches', 'checkedMarkup', 'choose', 'close', 'component', 'componentClass', 'effect', 'errorParagraph', 'fragment', 'handParts', 'holdSubmits', 'insert', 'listen', 'listenSubmit', 'listenSubmitWith', 'listenWith', 'markers', 'memo', 'merge', 'omit', 'outside', 'param', 'part', 'partClass', 'partHanded', 'partProps', 'property', 'ref', 'setClass', 'setStyle', 'slotCall', 'spreadAttributes', 'spreadWith', 'template', 'text', 'transition', 'untrack']
|
|
9
9
|
// The helpers in modules of their own, as their runtimes weigh on a page whose islands use none of them: the module of each is only loaded by a page with an island that compiles to it.
|
|
10
10
|
const APART = [['kay/dom-loop', ['loop', 'rowKey']], ['kay/dom-await', ['awaited']], ['kay/dom-try', ['attempt']], ['kay/dom-spread', ['dynamic', 'spread']], ['kay/dom-image', ['image']], ['kay/pending', ['pendingCall']]] as const
|
|
11
11
|
|
package/src/compiler/html.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { valuesOf } from './form-info'
|
|
|
12
12
|
import { addClassAttribute, addFieldFill, addSchemaOptions, listsFromSchema, schemaTypeCall } from './html-fields'
|
|
13
13
|
import { addInitial } from './html-initial'
|
|
14
14
|
import { Markup } from './html-parts'
|
|
15
|
-
import { addRowItem, childItems, constDeclaration, contentOf, errorParagraphArguments, fixedSource, isDeclaration,
|
|
15
|
+
import { addLoopTail, addRowItem, childItems, constDeclaration, contentOf, errorParagraphArguments, fixedSource, isDeclaration, slotValue, soleDynamic } from './items'
|
|
16
16
|
import { END_MARKER, escapeStaticAttribute, escapeText, fromRoot, helperName, RAW_ELEMENTS, START_MARKER, TemplateWriter, VOID_ELEMENTS } from './markup'
|
|
17
17
|
import { LOAD_KEY, PROPS, SUBJECT } from './names'
|
|
18
18
|
import { addGroupChecked, BEHAVIOUR, checkedContent, describedValue, fieldAriaOf, groupValue } from './plan'
|
|
@@ -74,6 +74,7 @@ export class HtmlTemplate extends TemplateWriter {
|
|
|
74
74
|
|
|
75
75
|
constructor(b: CodeBuilder, src: string, facts: TemplateFacts, ownMarkup: (name: string, at: number) => boolean, private readonly options: HtmlOptions = {}) {
|
|
76
76
|
super(b, src, facts, ownMarkup)
|
|
77
|
+
this.accessorBlocks = options.accessorLoops === true
|
|
77
78
|
this.mergesAtRuntime = options.classMerge === true
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -336,13 +337,8 @@ export class HtmlTemplate extends TemplateWriter {
|
|
|
336
337
|
b.add(', () => ')
|
|
337
338
|
this.markup(node.fallback)
|
|
338
339
|
}
|
|
339
|
-
else if (this.options.accessorLoops) {
|
|
340
|
-
b.add(', undefined')
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
if (this.options.accessorLoops)
|
|
344
|
-
b.add(rowKeying(node, this.src).kind === 'positional' ? ', "positional"' : ', "keyed"')
|
|
345
340
|
|
|
341
|
+
addLoopTail(b, node, this.src, this.options.accessorLoops === true, helperName('rowKey'))
|
|
346
342
|
b.add(')')
|
|
347
343
|
})
|
|
348
344
|
}
|
package/src/compiler/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { wrapActionButtons } from './button-forms'
|
|
|
17
17
|
import { generate, isInteractive, islandCause, lineOf } from './codegen'
|
|
18
18
|
import { asyncReplies, cssImportsWithoutText, missingCaptchas, onceReadProps, separatePageSettings, serverOnlyImports, unboundedFields } from './fence-checks'
|
|
19
19
|
import { openRedirects } from './fence-redirects'
|
|
20
|
+
import { handedServer } from './handed-data'
|
|
20
21
|
import { cwd, scopeStorage } from './host'
|
|
21
22
|
import { ignoredIslandExport, islandMessages, withAlertKeys } from './island-arguments'
|
|
22
23
|
import { describeCause } from './island-cause'
|
|
@@ -34,8 +35,9 @@ import { scopeAttribute } from './scoped-style'
|
|
|
34
35
|
import { analyzeScript, analyzeServer } from './script'
|
|
35
36
|
import { serialAwaits } from './serial-awaits'
|
|
36
37
|
import { serverImportReads } from './server-imports'
|
|
38
|
+
import { signalFromProps } from './signal-from-prop'
|
|
37
39
|
import { STATUS_PAGE_FILES } from './status-pages'
|
|
38
|
-
import { outerReads, templateWords } from './template-reads'
|
|
40
|
+
import { outerReads, templateWords, templateWrites } from './template-reads'
|
|
39
41
|
import { ISLAND_TWIN } from './twin'
|
|
40
42
|
import { unownedEffects } from './unowned-effects'
|
|
41
43
|
import { validate } from './validate'
|
|
@@ -287,7 +289,7 @@ export function onceReadChecks(original: string): Diagnostic[] {
|
|
|
287
289
|
const server = analyzeServer(source, file.server)
|
|
288
290
|
const script = analyzeScript(source, file.script, serverNames(server), file.module)
|
|
289
291
|
|
|
290
|
-
return script.fence ? onceReadProps(script.fence, script.props, templateWords(file)) : []
|
|
292
|
+
return script.fence ? [...onceReadProps(script.fence, script.props, templateWords(file)), ...signalFromProps(script.fence, script.props, templateWrites(file))] : []
|
|
291
293
|
}
|
|
292
294
|
|
|
293
295
|
const FAILED_FUNCTION = /^function KayFailed\(/m
|
|
@@ -341,7 +343,7 @@ export function compileKay(original: string, filename: string, options: CompileO
|
|
|
341
343
|
const found = findRewrites({ code: analysis.builder.code, map: analysis.builder.map(), sites: analysis.sites, values, dom: options.output === 'dom', source, templateStart: file.templateStart, imported, component: componentName(filename), check: options.check, fixedPage: routeFile })
|
|
342
344
|
const fences = [file.script, file.server, file.module].map(span => span ? source.slice(span.start, span.end) : '').join('\n')
|
|
343
345
|
const name = freeName(componentName(filename), fences, found.findings.globalReads)
|
|
344
|
-
const final = generate(file, script, server, { ...generateOptions, name, rewrites: found.plan.rewrites, writes: found.plan.writes, values: found.plan.values })
|
|
346
|
+
const final = generate(file, script, handedServer(island !== undefined, options.output, file, script, server, found.findings.unread), { ...generateOptions, name, rewrites: found.plan.rewrites, writes: found.plan.writes, values: found.plan.values })
|
|
345
347
|
// A fence that did not parse at all reaches the code unanalysed, so what the rewrites say of its names is only noise beside its syntax error.
|
|
346
348
|
const unparsed = script.unparsed !== undefined || server?.unparsed !== undefined
|
|
347
349
|
const diagnostics = [
|
|
@@ -383,7 +385,7 @@ export function compileKay(original: string, filename: string, options: CompileO
|
|
|
383
385
|
const browserScript = (island !== undefined || options.insideIsland === true) && !routeFile ? scriptFences(script) : []
|
|
384
386
|
const unusedLints = broken ? [] : [...unreadNames(source, file.template, script, server, found.findings), ...constantSignals(source, [file.script, file.module], found.findings)]
|
|
385
387
|
|
|
386
|
-
diagnostics.push(...unboundedFields(server), ...fenceLints, ...serialAwaits(server), ...browserScript.flatMap(fence => serverOnlyImports(fence)), ...browserScript.includes(script.fence!) ? onceReadProps(script.fence!, script.props, templateWords(file)) : [], ...unusedLints, ...templateLints(file), ...linkFlags(file))
|
|
388
|
+
diagnostics.push(...unboundedFields(server), ...fenceLints, ...serialAwaits(server), ...browserScript.flatMap(fence => serverOnlyImports(fence)), ...browserScript.includes(script.fence!) ? [...onceReadProps(script.fence!, script.props, templateWords(file)), ...signalFromProps(script.fence!, script.props, templateWrites(file))] : [], ...unusedLints, ...templateLints(file), ...linkFlags(file))
|
|
387
389
|
}
|
|
388
390
|
|
|
389
391
|
if (checked && pin !== undefined)
|
|
@@ -468,6 +470,7 @@ function takeBlock(file: KayFile, filename: string, options: CompileOptions, scr
|
|
|
468
470
|
return undefined
|
|
469
471
|
|
|
470
472
|
file.template.splice(index, 1)
|
|
473
|
+
file.facts = undefined
|
|
471
474
|
|
|
472
475
|
let lineStart = block.start
|
|
473
476
|
const written = file.source.slice(block.start, block.end).split('\n').map((text) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Diagnostic } from './ast'
|
|
2
|
+
import type { IslandDeclaration } from './island-declaration'
|
|
2
3
|
import type { AwaitAlert } from './names'
|
|
3
4
|
import type { ScriptAnalysis } from './script'
|
|
4
5
|
import { AWAIT_FAILED_KEY } from '../runtime/await-failed'
|
|
@@ -56,3 +57,11 @@ export function islandMessages(source: string, client = false, lives: string[] =
|
|
|
56
57
|
|
|
57
58
|
return keys.length > 0 ? `, ${JSON.stringify(keys)}` : ''
|
|
58
59
|
}
|
|
60
|
+
|
|
61
|
+
// The export of an island that lists `interactive` props, its type keeping the list, so a use turning none of them on, which renders as markup, can be handed a function; unchanged for a component that is an island in every use.
|
|
62
|
+
export function islandExport(expression: string, island: IslandDeclaration | undefined, options: { client?: boolean | undefined, lives?: string[] | undefined }): string {
|
|
63
|
+
if (island?.interactive === undefined || options.client || (options.lives?.length ?? 0) > 0 || island.hydrate !== undefined || island.persist !== undefined)
|
|
64
|
+
return `\nexport default ${expression}\n`
|
|
65
|
+
|
|
66
|
+
return `\nimport type { IslandAsked as KayIslandAsked } from 'kay'\nconst KayIslandExport = ${expression}\nexport default KayIslandExport as typeof KayIslandExport & KayIslandAsked<${JSON.stringify(island.interactive)}>\n`
|
|
67
|
+
}
|
|
@@ -9,4 +9,11 @@ export const ISLAND_LINTS = {
|
|
|
9
9
|
wrong: '---\nimport { signal } from \'kay\'\n\nconst count = signal(0)\n---\nbutton(onClick={() => count.set(count() + 1)}) {count()}',
|
|
10
10
|
right: '---\nimport Counter from \'../components/counter.kay\'\n---\nCounter',
|
|
11
11
|
},
|
|
12
|
+
'signal-from-prop': {
|
|
13
|
+
level: 'warn',
|
|
14
|
+
group: 'islands',
|
|
15
|
+
summary: 'A `signal` seeded from a destructured prop at the top of an island\'s script, `signal(light)` or `signal(todo.title)`, that the island never writes: an island stays when the page gives it new props, as after an action or a refresh, so the signal keeps the first value. `linked(() => light)` follows the prop; `kay check --fix` writes it. A signal the island writes, as a counter starting from a prop, is its own state and is left alone, as is a prop named `initial...` or `default...` or a comment `// kay-allow signal-from-prop`.',
|
|
16
|
+
wrong: '---\nimport { signal } from \'kay\'\n\nconst { light } = props<{ light: string }>()\nconst picked = signal(light)\n---\np {picked()}',
|
|
17
|
+
right: '---\nimport { linked } from \'kay\'\n\nconst { light } = props<{ light: string }>()\nconst picked = linked(() => light)\n---\np {picked()}',
|
|
18
|
+
},
|
|
12
19
|
} as const satisfies Record<string, Lint>
|
package/src/compiler/items.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AwaitNode, ConstNode, ElementNode, ErrorNode, ForNode, IfNode, MatchNode, Node, PendingNode, SnippetNode, Span, TextExpression, TryNode } from './ast'
|
|
2
2
|
import type { CodeBuilder } from './mapping'
|
|
3
|
+
import type { Sites } from './rewrite-types'
|
|
3
4
|
import { isHead, isSlot, keyedByPosition } from './ast'
|
|
4
5
|
import { PROPS } from './names'
|
|
5
6
|
import { parsedBindingNames } from './pattern-names'
|
|
@@ -170,6 +171,140 @@ export function parameterNames(pattern: string): string[] {
|
|
|
170
171
|
return parsedBindingNames(pattern) ?? []
|
|
171
172
|
}
|
|
172
173
|
|
|
174
|
+
const PLAIN_PARAMETER = /^([\p{ID_Start}$_][\p{ID_Continue}$]*)(?:\s*\?)?\s*(?::|$)/u
|
|
175
|
+
const OPENING = '([{<'
|
|
176
|
+
const CLOSING = ')]}>'
|
|
177
|
+
const QUOTES = '"\'`'
|
|
178
|
+
|
|
179
|
+
function skipString(text: string, from: number): number {
|
|
180
|
+
const quote = text[from]!
|
|
181
|
+
let index = from + 1
|
|
182
|
+
|
|
183
|
+
while (index < text.length && text[index] !== quote)
|
|
184
|
+
index += text[index] === '\\' ? 2 : 1
|
|
185
|
+
|
|
186
|
+
return index
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// The parameters of a block or a snippet that are plain names, typed or not, with their place in the list, which one of a component that renders again reads through an accessor, so a caller handing it what a `followed` draw follows gets the current value read each time. A pattern, a rest or a default stays as written. None when the list has no such name.
|
|
190
|
+
export function accessorParameters(params: string): { name: string, position: number }[] | undefined {
|
|
191
|
+
const names: { name: string, position: number }[] = []
|
|
192
|
+
let depth = 0
|
|
193
|
+
let from = 0
|
|
194
|
+
let defaulted = false
|
|
195
|
+
let position = 0
|
|
196
|
+
|
|
197
|
+
const close = (to: number) => {
|
|
198
|
+
const name = defaulted ? undefined : PLAIN_PARAMETER.exec(params.slice(from, to).trim())?.[1]
|
|
199
|
+
|
|
200
|
+
if (name !== undefined)
|
|
201
|
+
names.push({ name, position })
|
|
202
|
+
|
|
203
|
+
position++
|
|
204
|
+
|
|
205
|
+
from = to + 1
|
|
206
|
+
defaulted = false
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
for (let index = 0; index < params.length; index++) {
|
|
210
|
+
const char = params[index]!
|
|
211
|
+
|
|
212
|
+
if (char === '=' && params[index + 1] === '>') {
|
|
213
|
+
index++
|
|
214
|
+
}
|
|
215
|
+
else if (QUOTES.includes(char)) {
|
|
216
|
+
// A string in a type or a default, whose commas and brackets are no part of the list.
|
|
217
|
+
index = skipString(params, index)
|
|
218
|
+
}
|
|
219
|
+
else if (OPENING.includes(char)) {
|
|
220
|
+
depth++
|
|
221
|
+
}
|
|
222
|
+
else if (CLOSING.includes(char)) {
|
|
223
|
+
depth--
|
|
224
|
+
}
|
|
225
|
+
else if (char === ',' && depth === 0) {
|
|
226
|
+
close(index)
|
|
227
|
+
}
|
|
228
|
+
else if (char === '=' && depth === 0) {
|
|
229
|
+
defaulted = true
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
close(params.length)
|
|
234
|
+
|
|
235
|
+
return depth === 0 && names.length > 0 ? names : undefined
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const CHAIN = String.raw`[\p{ID_Start}$_][\p{ID_Continue}$]*(?:\.[\p{ID_Start}$_][\p{ID_Continue}$]*)*`
|
|
239
|
+
const CHAINS = new RegExp(String.raw`^\s*${CHAIN}(?:\s*,\s*${CHAIN})*\s*$`, 'u')
|
|
240
|
+
const COMMA = /,/g
|
|
241
|
+
|
|
242
|
+
// The spans of the arguments of a `slot` call when each is a name or a path of names, which the runtime reads one by one: the first as the item the block follows, the others where they change. None for any other argument.
|
|
243
|
+
function simpleArguments(src: string, args: Span): Span[] | undefined {
|
|
244
|
+
const text = src.slice(args.start, args.end)
|
|
245
|
+
|
|
246
|
+
if (!CHAINS.test(text))
|
|
247
|
+
return undefined
|
|
248
|
+
|
|
249
|
+
const spans: Span[] = []
|
|
250
|
+
let from = 0
|
|
251
|
+
|
|
252
|
+
for (const cut of [...[...text.matchAll(COMMA)].map(match => match.index), text.length]) {
|
|
253
|
+
const piece = text.slice(from, cut)
|
|
254
|
+
const lead = piece.length - piece.trimStart().length
|
|
255
|
+
|
|
256
|
+
spans.push({ start: args.start + from + lead, end: args.start + from + piece.trimEnd().length })
|
|
257
|
+
from = cut + 1
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return spans
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// A `slot` called with names or paths, which draws its block once for the item under its key, so a replacement leaves its nodes and their focus. False, and nothing written, for any other call.
|
|
264
|
+
export function addSlotCall(b: CodeBuilder, src: string, slot: ElementNode, helper: string): boolean {
|
|
265
|
+
const spans = slot.outlet?.args && simpleArguments(src, slot.outlet.args)
|
|
266
|
+
|
|
267
|
+
if (!slot.outlet || !spans)
|
|
268
|
+
return false
|
|
269
|
+
|
|
270
|
+
b.add(`${helper}(${PROPS}.`).addSource(slot.outlet.name)
|
|
271
|
+
|
|
272
|
+
for (const span of spans)
|
|
273
|
+
b.add(', () => ').addSource(span)
|
|
274
|
+
|
|
275
|
+
b.add(')')
|
|
276
|
+
|
|
277
|
+
return true
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// The parameters of a block or a snippet about to be written, which the rewrite reads through accessors where a component renders again.
|
|
281
|
+
export function markBlock(sites: Sites, b: CodeBuilder, src: string, params: Span, staticLoops?: boolean): void {
|
|
282
|
+
if (!staticLoops && accessorParameters(src.slice(params.start, params.end)))
|
|
283
|
+
sites.blocks.add(b.code.length)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const BARE_PARAMETER = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u
|
|
287
|
+
|
|
288
|
+
// A block's parameters and its arrow: one plain name is written bare, so a rule about the parentheses around it, which kay would otherwise be the one to write, has none to report.
|
|
289
|
+
export function addBlockParameters(sites: Sites, b: CodeBuilder, src: string, params: Span, staticLoops?: boolean): void {
|
|
290
|
+
const bare = BARE_PARAMETER.test(src.slice(params.start, params.end))
|
|
291
|
+
|
|
292
|
+
b.add(bare ? '' : '(')
|
|
293
|
+
markBlock(sites, b, src, params, staticLoops)
|
|
294
|
+
b.addSource(params).add(bare ? ' => ' : ') => ')
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// What a block or a snippet renders, its plain parameters read where they are used (`param` is the helper), so one a `followed` draw follows gives the current item.
|
|
298
|
+
export function addParameterReads(b: CodeBuilder, names: { name: string, position: number }[] | undefined, param: string, render: () => void): void {
|
|
299
|
+
if (names)
|
|
300
|
+
b.add(`(${names.map(({ name, position }) => `${name} = ${param}(${name}${position === 0 ? '' : `, ${position}`}), `).join('')}`)
|
|
301
|
+
|
|
302
|
+
render()
|
|
303
|
+
|
|
304
|
+
if (names)
|
|
305
|
+
b.add(')')
|
|
306
|
+
}
|
|
307
|
+
|
|
173
308
|
// What a `slot` renders: the component's children, or the block prop it names, called with its arguments when it has some.
|
|
174
309
|
export function slotValue(b: CodeBuilder, slot: ElementNode): void {
|
|
175
310
|
if (!slot.outlet) {
|
|
@@ -224,6 +359,33 @@ export function addKeyParameters(b: CodeBuilder, node: ForNode, src: string): vo
|
|
|
224
359
|
b.add(')')
|
|
225
360
|
}
|
|
226
361
|
|
|
362
|
+
// What follows the fallback in the server's `loop` call: how an island's rows read their item, or, in a page or a static component, the key of a keyed loop (`rowKey` when it names none), which an island in a row with no `key` or `id` of its own takes its identity from.
|
|
363
|
+
export function addLoopTail(b: CodeBuilder, node: ForNode, src: string, accessorLoops: boolean, rowKey: string): void {
|
|
364
|
+
const keying = rowKeying(node, src)
|
|
365
|
+
const keyed = !accessorLoops && keying.kind !== 'positional'
|
|
366
|
+
|
|
367
|
+
if (!node.fallback && (accessorLoops || keyed))
|
|
368
|
+
b.add(', undefined')
|
|
369
|
+
|
|
370
|
+
if (accessorLoops)
|
|
371
|
+
b.add(keying.kind === 'positional' ? ', "positional"' : ', "keyed"')
|
|
372
|
+
else if (keyed)
|
|
373
|
+
b.add(', undefined')
|
|
374
|
+
|
|
375
|
+
if (!keyed)
|
|
376
|
+
return
|
|
377
|
+
|
|
378
|
+
b.add(', ')
|
|
379
|
+
|
|
380
|
+
if (keying.kind === 'expression') {
|
|
381
|
+
addKeyParameters(b, node, src)
|
|
382
|
+
b.add(' => (').addSource(keying.key).add(')')
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
b.add(rowKey)
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
227
389
|
// Whether an expression names `name` as a variable: not as a property after a dot, nor inside a longer name.
|
|
228
390
|
function readsName(expression: string, name: string): boolean {
|
|
229
391
|
return new RegExp(`(?<![\\w$.])${name.replaceAll('$', '\\$')}(?![\\w$])`).test(expression)
|
|
@@ -248,3 +410,15 @@ export function fixedSource(element: ElementNode): string {
|
|
|
248
410
|
export function ambientHelpers(facts: { ambientForm: boolean, snippet: boolean, forms: ReadonlyMap<unknown, unknown> }, mode: string): ('formHere' | 'formError' | 'issueScope')[] {
|
|
249
411
|
return [...facts.ambientForm ? ['formHere' as const, 'formError' as const] : [], ...mode === 'dom' && facts.snippet && facts.forms.size > 0 ? ['issueScope' as const] : []]
|
|
250
412
|
}
|
|
413
|
+
|
|
414
|
+
const BOUND = /^bind:/
|
|
415
|
+
|
|
416
|
+
// The props a use writes, as the object type `KayFunctionProp` takes after the component; none for a use with a spread, which may carry any.
|
|
417
|
+
export function usedProps(element: ElementNode, text: (span: Span) => string): string {
|
|
418
|
+
if (element.attributes.some(attribute => attribute.kind === 'spread'))
|
|
419
|
+
return ''
|
|
420
|
+
|
|
421
|
+
const names = [...element.attributes.flatMap(attribute => attribute.kind === 'spread' ? [] : [attribute.name]), ...element.children.flatMap(child => child.kind === 'slot' ? [child.name] : [])]
|
|
422
|
+
|
|
423
|
+
return `, { ${names.map(name => `${JSON.stringify(text(name).replace(BOUND, ''))}: 0`).join(', ')} }`
|
|
424
|
+
}
|
package/src/compiler/jsx.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ElementShape } from './plan'
|
|
|
4
4
|
import type { Sites } from './rewrite-types'
|
|
5
5
|
import { bindsOwnProp, failedBlockOf, handedParts, isSlot, partAttribute, serverIslandOf } from './ast'
|
|
6
6
|
import { isFunctionAt, sentParts } from './expression'
|
|
7
|
-
import { addConstValue, addKeyParameters, addRowItem, contentOf, rowKeying, slotValue } from './items'
|
|
7
|
+
import { addBlockParameters, addConstValue, addKeyParameters, addRowItem, contentOf, markBlock, rowKeying, slotValue, usedProps } from './items'
|
|
8
8
|
import { addMergedClass, addShorthandClass, quoteAttribute } from './jsx-class'
|
|
9
9
|
import { addFieldName, addInheritedName, addWrittenField } from './jsx-field'
|
|
10
10
|
import { DYNAMIC_TAG } from './mapping'
|
|
@@ -40,7 +40,6 @@ const JSX_TEXT_ESCAPES = /[{}<>]|[ \t]{2,}/g
|
|
|
40
40
|
// Attributes rendered as markup rather than text.
|
|
41
41
|
const MARKUP_ATTRIBUTES = new Set(['innerHTML', 'srcdoc'])
|
|
42
42
|
const EVENT_HANDLER = /^on[A-Z]/
|
|
43
|
-
const PLAIN_PARAMETER = /^[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*$/u
|
|
44
43
|
|
|
45
44
|
// A template as JSX: what the analysis pass reads for scope, and `kay check` type-checks.
|
|
46
45
|
export class JsxTemplate {
|
|
@@ -179,7 +178,9 @@ export class JsxTemplate {
|
|
|
179
178
|
b.wrap(node, () => {
|
|
180
179
|
b.add('const ')
|
|
181
180
|
this.sites.snippets.add(b.code.length)
|
|
182
|
-
b.addSource(node.name).add(' = (')
|
|
181
|
+
b.addSource(node.name).add(' = (')
|
|
182
|
+
markBlock(this.sites, b, this.src, node.params, this.options.staticLoops)
|
|
183
|
+
b.addSource(node.params).add('): KayJSX.Element => (')
|
|
183
184
|
this.emitRoot(node.children)
|
|
184
185
|
b.add(');')
|
|
185
186
|
})
|
|
@@ -630,11 +631,8 @@ export class JsxTemplate {
|
|
|
630
631
|
|
|
631
632
|
b.add(' ').addSource(slot.name).add('={')
|
|
632
633
|
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
b.addSource(slot.params).add(' => ')
|
|
636
|
-
else if (slot.params)
|
|
637
|
-
b.add('(').addSource(slot.params).add(') => ')
|
|
634
|
+
if (slot.params)
|
|
635
|
+
addBlockParameters(this.sites, b, this.src, slot.params, this.options.staticLoops)
|
|
638
636
|
|
|
639
637
|
this.emitRoot(slot.children)
|
|
640
638
|
b.add('}')
|
|
@@ -879,7 +877,7 @@ export class JsxTemplate {
|
|
|
879
877
|
let at = start
|
|
880
878
|
|
|
881
879
|
if (sent.functions) {
|
|
882
|
-
this.emitFunctionPropCheck(element, attribute.name)
|
|
880
|
+
this.emitFunctionPropCheck(element, attribute.name, false)
|
|
883
881
|
b.add(' ')
|
|
884
882
|
}
|
|
885
883
|
|
|
@@ -904,8 +902,9 @@ export class JsxTemplate {
|
|
|
904
902
|
}
|
|
905
903
|
|
|
906
904
|
// Reports a function passed to an island, `0` standing for the prop.
|
|
907
|
-
|
|
908
|
-
|
|
905
|
+
// The props the use writes go along, as an object type, so an island that lists its interactive props takes a function from a use turning none of them on; a spread may carry any, so it sends none, and a function inside a literal value sends none either, as it is never sent.
|
|
906
|
+
private emitFunctionPropCheck(element: ElementNode, name: Span, whole = true) {
|
|
907
|
+
this.b.add('{...KayFunctionProp(').addSource(element.tag).add(whole ? usedProps(element, span => this.text(span)) : '').add(')(').wrap(name, () => this.b.add('0')).add(')}')
|
|
909
908
|
}
|
|
910
909
|
|
|
911
910
|
// `bind:value={name}` reads the signal and writes it back from the matching input event.
|
package/src/compiler/lints.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AllowRules } from './allow-comments'
|
|
2
2
|
import type { Diagnostic, ElementNode, ForNode, KayFile, TextChunk } from './ast'
|
|
3
|
+
import type { RemovedLintName } from './removed-lints'
|
|
3
4
|
import type { Scope } from './template-scopes'
|
|
4
5
|
import { accessibilityLints, MARKUP_LINTS } from './a11y'
|
|
5
|
-
import { allowComments, honoured, refusedComments } from './allow-comments'
|
|
6
|
+
import { allowComments, honoured, refusedComments, unknownNames } from './allow-comments'
|
|
6
7
|
import { keyedByPosition, walkNodes } from './ast'
|
|
7
8
|
import { DEPRECATED_LINTS } from './deprecated-lints'
|
|
8
9
|
import { I18N_LINTS } from './i18n-lints'
|
|
@@ -475,7 +476,7 @@ export const LINTS = {
|
|
|
475
476
|
site: true,
|
|
476
477
|
summary: 'A root Dockerfile whose `FROM oven/bun:<version>` is older than the Bun kay needs (`engines.bun`), so the image fails to build once kay moves up, as `kay upgrade` does. `--fix` moves the tag to the oldest Bun kay runs on, dropping a digest pin that would keep the old image; a tag that is no full version, as `1` or `latest`, is left alone.',
|
|
477
478
|
wrong: 'FROM oven/bun:1.0.0 AS build',
|
|
478
|
-
right: 'FROM oven/bun:1.4.
|
|
479
|
+
right: 'FROM oven/bun:1.4.5 AS build',
|
|
479
480
|
},
|
|
480
481
|
'untyped-socket': {
|
|
481
482
|
level: 'warn',
|
|
@@ -686,8 +687,8 @@ export const LINTS = {
|
|
|
686
687
|
export type LintName = keyof typeof LINTS
|
|
687
688
|
|
|
688
689
|
// `satisfied` is set by kay from the extensions' `satisfies`, never written in `kay.config.ts`: the lints an extension answers for a place it fills in by itself.
|
|
689
|
-
// `comments` is no lint's level: it sets what a `// kay-allow` comment must hold to count.
|
|
690
|
-
export type LintLevels = Partial<Record<LintName | LintGroup, LintLevel>> & { satisfied?: LintName[] | undefined, comments?: AllowRules | undefined }
|
|
690
|
+
// `comments` is no lint's level: it sets what a `// kay-allow` comment must hold to count. A removed lint is still accepted, warned about by `kay check`.
|
|
691
|
+
export type LintLevels = Partial<Record<LintName | LintGroup | RemovedLintName, LintLevel>> & { satisfied?: LintName[] | undefined, comments?: AllowRules | undefined }
|
|
691
692
|
|
|
692
693
|
export const LEVELS: ReadonlySet<string> = new Set<LintLevel>(['allow', 'warn', 'deny'])
|
|
693
694
|
|
|
@@ -717,8 +718,6 @@ export const UPGRADE_FROM = 'KAY_UPGRADE_FROM'
|
|
|
717
718
|
|
|
718
719
|
export { DEPRECATION_MINORS } from './deprecated-lints'
|
|
719
720
|
|
|
720
|
-
export { minorAfter, minorOf } from './minor'
|
|
721
|
-
|
|
722
721
|
export function isLintGroup(name: string | undefined): name is LintGroup {
|
|
723
722
|
return name !== undefined && Object.hasOwn(LINT_GROUPS, name)
|
|
724
723
|
}
|
|
@@ -776,7 +775,7 @@ export function applyLints(diagnostics: Diagnostic[], source: string, levels: Li
|
|
|
776
775
|
}
|
|
777
776
|
|
|
778
777
|
function unknownLints(source: string): Diagnostic[] {
|
|
779
|
-
return allowComments(source).flatMap(comment => comment
|
|
778
|
+
return allowComments(source).flatMap(comment => unknownNames(comment, source, isLint, `the lints are ${Object.keys(LINTS).map(lint => `\`${lint}\``).join(', ')}`))
|
|
780
779
|
}
|
|
781
780
|
|
|
782
781
|
// The template's own lints: what it can say from the markup alone.
|
package/src/compiler/markup.ts
CHANGED
|
@@ -13,9 +13,9 @@ import { addBoundWrites, calledByBinds, changeOf } from './bound-props'
|
|
|
13
13
|
import { joinTexts } from './class-items'
|
|
14
14
|
import { addHandler } from './event-modifiers'
|
|
15
15
|
import { decodeEntities, isFunctionAt } from './expression'
|
|
16
|
-
import { closeHandParts, handsEntry, openClassList, writtenParts } from './hand-parts'
|
|
16
|
+
import { closeHandParts, handedItem, handsEntry, openClassList, writesTogether, writtenParts } from './hand-parts'
|
|
17
17
|
import { IMAGE_OPTIONS, imageDefaults as imageDefaultsOf, imageOptions, placeholderOff, writeImageArguments } from './image-attributes'
|
|
18
|
-
import { contentOf } from './items'
|
|
18
|
+
import { accessorParameters, addParameterReads, contentOf } from './items'
|
|
19
19
|
import { controlId, fieldAttribute, inheritedAttributes, inheritedField } from './markup-fields'
|
|
20
20
|
import { PROPS } from './names'
|
|
21
21
|
import { addGroupChecked, bindingOf, classMergeOf, formDefaultsOf, groupValue, shapeOf, shorthandClass, staticAttributeText, valueBoundBy, writesAttribute } from './plan'
|
|
@@ -160,6 +160,9 @@ export abstract class TemplateWriter {
|
|
|
160
160
|
// The server hands over the markup itself, which an island reads its static slots off, and so draws a slot's ids once per read where the browser draws them once per insert; the browser sets the ids it binds, so they agree.
|
|
161
161
|
protected readonly lazySlots: boolean = false
|
|
162
162
|
|
|
163
|
+
// Whether a block's plain parameters are accessors: where the analysis read them as a loop's row is read, which a component that renders again does and a static one does not.
|
|
164
|
+
protected accessorBlocks = true
|
|
165
|
+
|
|
163
166
|
// The helper scoping a form's content: the server's also lets the fields in it refill, the browser's only gives them the form's messages.
|
|
164
167
|
protected readonly scoping: 'formScope' | 'issueScope' = 'formScope'
|
|
165
168
|
|
|
@@ -353,16 +356,20 @@ export abstract class TemplateWriter {
|
|
|
353
356
|
|
|
354
357
|
b.wrap(node, () => {
|
|
355
358
|
b.add('const ').addSource(node.name).add(' = (').addSource(node.params).add(') => ')
|
|
356
|
-
this.childrenValue(node.children)
|
|
359
|
+
this.readingParameters(node.params, () => this.childrenValue(node.children))
|
|
357
360
|
b.add('; ')
|
|
358
361
|
})
|
|
359
362
|
}
|
|
360
363
|
|
|
364
|
+
private readingParameters(params: Span, render: () => void): void {
|
|
365
|
+
addParameterReads(this.b, this.accessorBlocks ? accessorParameters(this.source(params)) : undefined, helperName('param'), render)
|
|
366
|
+
}
|
|
367
|
+
|
|
361
368
|
// A component's props: its attributes, then its slots and children, each read through a getter or a function so it renders where the component puts it.
|
|
362
369
|
// `except` is a slot that is no prop, as a server island's `@failed`.
|
|
363
370
|
protected componentProps(element: ElementNode, getters: boolean, except?: SlotNode): void {
|
|
364
371
|
const { b } = this
|
|
365
|
-
const spreads = element.attributes.some(attribute => attribute.kind === 'spread')
|
|
372
|
+
const spreads = element.attributes.some(attribute => attribute.kind === 'spread') || writesTogether(element, this.src, this.facts.parts)
|
|
366
373
|
|
|
367
374
|
if (spreads)
|
|
368
375
|
b.add(`${helperName('merge')}(`)
|
|
@@ -376,7 +383,7 @@ export abstract class TemplateWriter {
|
|
|
376
383
|
|
|
377
384
|
if (slot.params) {
|
|
378
385
|
b.add(`${JSON.stringify(this.source(slot.name))}: (`).addSource(slot.params).add(') => ')
|
|
379
|
-
this.childrenValue(slot.children)
|
|
386
|
+
this.readingParameters(slot.params, () => this.childrenValue(slot.children))
|
|
380
387
|
}
|
|
381
388
|
else {
|
|
382
389
|
b.add(`get ${JSON.stringify(this.source(slot.name))}() { return `)
|
|
@@ -557,11 +564,18 @@ export abstract class TemplateWriter {
|
|
|
557
564
|
|
|
558
565
|
// A call that hands a part on always holds parts in its list, which carry the classes as their root: its `class` is the one a spread would bring, left off.
|
|
559
566
|
const hands = element.component && handedParts(element, this.src, this.facts.parts).length > 0
|
|
567
|
+
const together = writesTogether(element, this.src, this.facts.parts)
|
|
560
568
|
|
|
561
|
-
if (
|
|
569
|
+
if (together) {
|
|
570
|
+
closeObject()
|
|
571
|
+
b.add(objects++ > 0 ? ', ' : '')
|
|
572
|
+
this.mergedClass(element, classAttribute, spreads, writtenParts(element, this.src), true)
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (!together && (hands ? spreads : mergedClass))
|
|
562
576
|
entry('class', () => hands ? b.add('undefined') : this.mergedClass(element, classAttribute, spreads), !hands)
|
|
563
577
|
|
|
564
|
-
if (element.component && parts.length > 0)
|
|
578
|
+
if (!together && element.component && parts.length > 0)
|
|
565
579
|
entry('parts', () => this.mergedClass(element, classAttribute, spreads, writtenParts(element, this.src)), true)
|
|
566
580
|
|
|
567
581
|
if (!keepOpen)
|
|
@@ -697,7 +711,7 @@ export abstract class TemplateWriter {
|
|
|
697
711
|
}
|
|
698
712
|
|
|
699
713
|
// `class` as written: the shorthand alone or merged with a static attribute is a string; with an expression or spreads, an array of every source, which a component gets merged into one string, as its `class?: string` prop takes it. With `handing`, the `parts` a component call that hands parts on gets in its place, laid over the `parts` it writes.
|
|
700
|
-
protected mergedClass(element: ElementNode, classAttribute: NamedAttribute | undefined, spreads: boolean, handing?: readonly Attribute[]): void {
|
|
714
|
+
protected mergedClass(element: ElementNode, classAttribute: NamedAttribute | undefined, spreads: boolean, handing?: readonly Attribute[], together = false): void {
|
|
701
715
|
const { b } = this
|
|
702
716
|
const shorthand = element.classes.length > 0 ? this.shorthand(element) : undefined
|
|
703
717
|
const parts = partsOf(element, this.src, this.facts.parts)
|
|
@@ -726,27 +740,15 @@ export abstract class TemplateWriter {
|
|
|
726
740
|
}
|
|
727
741
|
|
|
728
742
|
// The parts handed on come before the call's own, so the entry the caller gives the called component's root is the last word.
|
|
729
|
-
for (const part of handed)
|
|
730
|
-
items.push(
|
|
731
|
-
emit: () => {
|
|
732
|
-
b.add(`${helperName('partHanded')}(${JSON.stringify(part)}, [`)
|
|
733
|
-
|
|
734
|
-
for (const emit of this.recipeItem(part)) {
|
|
735
|
-
emit()
|
|
736
|
-
b.add(', ')
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
b.add(`${helperName('partClass')}(${PROPS}, ${JSON.stringify(part)})])`)
|
|
740
|
-
},
|
|
741
|
-
})
|
|
742
|
-
}
|
|
743
|
+
for (const part of handed)
|
|
744
|
+
items.push(handedItem(b, part, this.recipeItem(part)))
|
|
743
745
|
|
|
744
746
|
for (const part of parts)
|
|
745
747
|
items.push(...this.recipeItem(part).map(emit => ({ emit })), { emit: () => b.add(`${helperName('partClass')}(${PROPS}, ${JSON.stringify(part)})`) })
|
|
746
748
|
|
|
747
749
|
const written = this.classTable === undefined ? items : joinTexts(items, texts => this.joinLiterals(texts))
|
|
748
750
|
|
|
749
|
-
openClassList(b, element.component,
|
|
751
|
+
openClassList(b, element.component, handing, together)
|
|
750
752
|
for (const [index, item] of written.entries()) {
|
|
751
753
|
if (index > 0)
|
|
752
754
|
b.add(', ')
|
|
@@ -756,7 +758,7 @@ export abstract class TemplateWriter {
|
|
|
756
758
|
else
|
|
757
759
|
item.emit()
|
|
758
760
|
}
|
|
759
|
-
closeHandParts(b, element.component, handing)
|
|
761
|
+
closeHandParts(b, element.component, handing, together)
|
|
760
762
|
}
|
|
761
763
|
|
|
762
764
|
// What a component receives as `children` or a slot: a lone line of text as its string or values, as JSX passes it, anything else rendered.
|
package/src/compiler/names.ts
CHANGED
|
@@ -36,7 +36,7 @@ export function defaultName(index: number): string {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// What the editor leaves out of completions: the names above a completion can reach, and what the generated code imports or declares.
|
|
39
|
-
export const GENERATED_NAME = new RegExp(`^(?:${[PROPS, VALUES, CURRENT, 'kayEvent', 'kayMatched', 'kayAwaited', 'kayEach'].join('|')}|${DEFAULT_PREFIX}\\d+|Kay(?:Default|LoopFor|StaticFor|Show|Omit|ComponentClass|PartClass|PartsClass|HandParts|PartOf|HandedPart|Dynamic|TemplateHelpers|Island|IslandBrand|HydrateWhen|Href|Html|ComputedHtml|Field|FormValues|FormError|Prop|PlainProp|FunctionProp|PromotedProp|PromotedFunctionProp|HandsPart|Children|Row|List|Truthy|Unmatched|Keyed|Radio|Writable|WriteTo|UpdateTo|WriteBack|UpdateBack|Bound|Bindable|Handed|PageContext|PrerenderedContext|PageSettings|QueryOf|PageData|JSX|FormAction|RegisterActions|ActionStub|ReviveActions|UseHead|Await|Awaited|Try))$`)
|
|
39
|
+
export const GENERATED_NAME = new RegExp(`^(?:${[PROPS, VALUES, CURRENT, 'kayEvent', 'kayMatched', 'kayAwaited', 'kayEach'].join('|')}|${DEFAULT_PREFIX}\\d+|Kay(?:Default|LoopFor|StaticFor|Show|Omit|ComponentClass|PartClass|PartsClass|PartProps|HandParts|PartOf|HandedPart|Dynamic|TemplateHelpers|Island|IslandBrand|IslandAsked|IslandExport|HydrateWhen|Href|Html|ComputedHtml|Field|FormValues|FormError|Prop|PlainProp|FunctionProp|PromotedProp|PromotedFunctionProp|HandsPart|Children|Row|List|Truthy|Unmatched|Keyed|Radio|Writable|WriteTo|UpdateTo|WriteBack|UpdateBack|Bound|Bindable|Handed|PageContext|PrerenderedContext|PageSettings|QueryOf|PageData|JSX|FormAction|RegisterActions|ActionStub|ReviveActions|UseHead|Await|Awaited|Try))$`)
|
|
40
40
|
|
|
41
41
|
// The app's `src/await-failed.kay`, and the message keys it words.
|
|
42
42
|
export interface AwaitAlert {
|