@kayjs/kay 1.109.0 → 1.110.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.
Files changed (115) hide show
  1. package/dist/eslint.js +332 -52
  2. package/editors/zed/extension.toml +2 -2
  3. package/llms/actions-from-islands.md +1 -1
  4. package/llms/components.md +1 -1
  5. package/llms/deprecated-lints.md +1 -1
  6. package/llms/island-and-form-lints.md +2 -1
  7. package/llms/islands.md +4 -2
  8. package/llms/live-values.md +1 -1
  9. package/llms/navigation-from-code.md +1 -1
  10. package/llms/navigation.md +4 -2
  11. package/llms/templates-elements-slots-snippets.md +2 -2
  12. package/llms/upgrading-archive.md +31 -1
  13. package/llms/upgrading.md +26 -32
  14. package/llms/whats-new.md +15 -0
  15. package/llms.txt +1 -1
  16. package/package.json +6 -6
  17. package/src/build/variants.ts +132 -18
  18. package/src/check/env-types.ts +1 -1
  19. package/src/check/project.ts +4 -0
  20. package/src/check/schema-builders.ts +125 -26
  21. package/src/commands/upgrade.ts +2 -1
  22. package/src/compiler/allow-comments.ts +38 -2
  23. package/src/compiler/ast.ts +4 -4
  24. package/src/compiler/codegen.ts +3 -3
  25. package/src/compiler/deprecated-lints-1-106.ts +2 -2
  26. package/src/compiler/hand-parts.ts +36 -8
  27. package/src/compiler/helper-imports.ts +2 -2
  28. package/src/compiler/index.ts +4 -3
  29. package/src/compiler/island-arguments.ts +9 -0
  30. package/src/compiler/island-lints.ts +7 -0
  31. package/src/compiler/items.ts +12 -0
  32. package/src/compiler/jsx.ts +5 -4
  33. package/src/compiler/lints.ts +5 -6
  34. package/src/compiler/markup.ts +16 -21
  35. package/src/compiler/names.ts +1 -1
  36. package/src/compiler/removed-lints.ts +90 -0
  37. package/src/compiler/signal-from-prop.ts +141 -0
  38. package/src/compiler/template-reads.ts +16 -0
  39. package/src/runtime/checks.ts +14 -2
  40. package/src/runtime/client.ts +5 -9
  41. package/src/runtime/dom.ts +1 -1
  42. package/src/runtime/html.ts +1 -1
  43. package/src/runtime/image.ts +2 -19
  44. package/src/runtime/index.ts +1 -1
  45. package/src/runtime/island.server.ts +40 -10
  46. package/src/runtime/navigate.ts +9 -0
  47. package/src/runtime/navigation.ts +5 -1
  48. package/src/runtime/page-swap.ts +2 -2
  49. package/src/runtime/swap-flight.ts +10 -10
  50. package/src/runtime/swap-kept.ts +69 -29
  51. package/src/runtime/swap-morph.ts +49 -9
  52. package/src/runtime/text-hash.ts +17 -0
  53. package/src/runtime/uid.server.ts +6 -4
  54. package/src/runtime/values.ts +12 -0
  55. package/src/server/render-document.ts +8 -6
  56. package/src/server/render.ts +1 -1
  57. package/types/build/variants.d.ts +9 -1
  58. package/types/build/variants.d.ts.map +1 -1
  59. package/types/check/project.d.ts.map +1 -1
  60. package/types/check/schema-builders.d.ts.map +1 -1
  61. package/types/commands/upgrade.d.ts.map +1 -1
  62. package/types/compiler/allow-comments.d.ts +2 -0
  63. package/types/compiler/allow-comments.d.ts.map +1 -1
  64. package/types/compiler/ast.d.ts +1 -1
  65. package/types/compiler/ast.d.ts.map +1 -1
  66. package/types/compiler/deprecated-lints-1-106.d.ts +2 -2
  67. package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
  68. package/types/compiler/deprecated-lints.d.ts +2 -2
  69. package/types/compiler/hand-parts.d.ts +6 -3
  70. package/types/compiler/hand-parts.d.ts.map +1 -1
  71. package/types/compiler/index.d.ts.map +1 -1
  72. package/types/compiler/island-arguments.d.ts +5 -0
  73. package/types/compiler/island-arguments.d.ts.map +1 -1
  74. package/types/compiler/island-lints.d.ts +7 -0
  75. package/types/compiler/island-lints.d.ts.map +1 -1
  76. package/types/compiler/items.d.ts +1 -0
  77. package/types/compiler/items.d.ts.map +1 -1
  78. package/types/compiler/jsx.d.ts.map +1 -1
  79. package/types/compiler/lints.d.ts +11 -4
  80. package/types/compiler/lints.d.ts.map +1 -1
  81. package/types/compiler/markup.d.ts +1 -1
  82. package/types/compiler/markup.d.ts.map +1 -1
  83. package/types/compiler/names.d.ts.map +1 -1
  84. package/types/compiler/removed-lints.d.ts +3 -0
  85. package/types/compiler/removed-lints.d.ts.map +1 -0
  86. package/types/compiler/signal-from-prop.d.ts +4 -0
  87. package/types/compiler/signal-from-prop.d.ts.map +1 -0
  88. package/types/compiler/template-reads.d.ts +1 -0
  89. package/types/compiler/template-reads.d.ts.map +1 -1
  90. package/types/runtime/checks.d.ts +8 -2
  91. package/types/runtime/checks.d.ts.map +1 -1
  92. package/types/runtime/client.d.ts.map +1 -1
  93. package/types/runtime/dom.d.ts +1 -1
  94. package/types/runtime/dom.d.ts.map +1 -1
  95. package/types/runtime/html.d.ts +1 -1
  96. package/types/runtime/html.d.ts.map +1 -1
  97. package/types/runtime/image.d.ts.map +1 -1
  98. package/types/runtime/index.d.ts +1 -1
  99. package/types/runtime/index.d.ts.map +1 -1
  100. package/types/runtime/island.server.d.ts +1 -0
  101. package/types/runtime/island.server.d.ts.map +1 -1
  102. package/types/runtime/navigate.d.ts.map +1 -1
  103. package/types/runtime/navigation.d.ts +2 -0
  104. package/types/runtime/navigation.d.ts.map +1 -1
  105. package/types/runtime/swap-flight.d.ts +1 -1
  106. package/types/runtime/swap-flight.d.ts.map +1 -1
  107. package/types/runtime/swap-kept.d.ts.map +1 -1
  108. package/types/runtime/swap-morph.d.ts.map +1 -1
  109. package/types/runtime/text-hash.d.ts +2 -0
  110. package/types/runtime/text-hash.d.ts.map +1 -0
  111. package/types/runtime/uid.server.d.ts.map +1 -1
  112. package/types/runtime/values.d.ts +4 -0
  113. package/types/runtime/values.d.ts.map +1 -1
  114. package/types/server/render-document.d.ts +1 -1
  115. package/types/server/render-document.d.ts.map +1 -1
@@ -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' | 'partsClass'
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('partsClass')
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('partsClass')
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('partsClass')
788
+ facts.helpers.add('partProps')
789
789
  facts.helpers.add('handParts')
790
790
  }
791
791
  }
@@ -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'
@@ -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(`\nexport default 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]>>`)}\n`)
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(`\nexport default KayIsland(${JSON.stringify(this.options.island)}, ${name}${this.genericComponent ? ' as never' : ''}${this.islandTail(src)})${this.genericIslandType()}${widened ? this.widenedCall(`typeof ${name}`) : ''}\n`)
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 an `action` or a `defineEnv` is the record of fields alone; 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; 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: write `{ extra: \'strip\' }` where the old way is wanted. 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.',
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>
@@ -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
- // 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.
15
- export function openClassList(b: CodeBuilder, component: boolean, parts: boolean, handing: readonly Attribute[] | undefined): void {
16
- const helper = handing ? 'handParts' : 'partsClass'
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(parts ? helper : 'componentClass')}([` : '[')
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.
@@ -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', 'partsClass', 'raw', 'rawData', 'rawTyped', 'refillOptions', 'schemaFill', 'selectOptions', 'serverIsland', 'show', 'spreadAttributes', 'spreadWith', 'style', 'untrack']
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', 'partProps', 'raw', 'rawData', 'rawTyped', 'refillOptions', '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', 'partsClass', 'property', 'ref', 'setClass', 'setStyle', 'spreadAttributes', 'spreadWith', 'template', 'text', 'transition', 'untrack']
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', 'partProps', 'property', 'ref', 'setClass', 'setStyle', '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
 
@@ -34,8 +34,9 @@ import { scopeAttribute } from './scoped-style'
34
34
  import { analyzeScript, analyzeServer } from './script'
35
35
  import { serialAwaits } from './serial-awaits'
36
36
  import { serverImportReads } from './server-imports'
37
+ import { signalFromProps } from './signal-from-prop'
37
38
  import { STATUS_PAGE_FILES } from './status-pages'
38
- import { outerReads, templateWords } from './template-reads'
39
+ import { outerReads, templateWords, templateWrites } from './template-reads'
39
40
  import { ISLAND_TWIN } from './twin'
40
41
  import { unownedEffects } from './unowned-effects'
41
42
  import { validate } from './validate'
@@ -287,7 +288,7 @@ export function onceReadChecks(original: string): Diagnostic[] {
287
288
  const server = analyzeServer(source, file.server)
288
289
  const script = analyzeScript(source, file.script, serverNames(server), file.module)
289
290
 
290
- return script.fence ? onceReadProps(script.fence, script.props, templateWords(file)) : []
291
+ return script.fence ? [...onceReadProps(script.fence, script.props, templateWords(file)), ...signalFromProps(script.fence, script.props, templateWrites(file))] : []
291
292
  }
292
293
 
293
294
  const FAILED_FUNCTION = /^function KayFailed\(/m
@@ -383,7 +384,7 @@ export function compileKay(original: string, filename: string, options: CompileO
383
384
  const browserScript = (island !== undefined || options.insideIsland === true) && !routeFile ? scriptFences(script) : []
384
385
  const unusedLints = broken ? [] : [...unreadNames(source, file.template, script, server, found.findings), ...constantSignals(source, [file.script, file.module], found.findings)]
385
386
 
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))
387
+ 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
388
  }
388
389
 
389
390
  if (checked && pin !== undefined)
@@ -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>
@@ -248,3 +248,15 @@ export function fixedSource(element: ElementNode): string {
248
248
  export function ambientHelpers(facts: { ambientForm: boolean, snippet: boolean, forms: ReadonlyMap<unknown, unknown> }, mode: string): ('formHere' | 'formError' | 'issueScope')[] {
249
249
  return [...facts.ambientForm ? ['formHere' as const, 'formError' as const] : [], ...mode === 'dom' && facts.snippet && facts.forms.size > 0 ? ['issueScope' as const] : []]
250
250
  }
251
+
252
+ const BOUND = /^bind:/
253
+
254
+ // 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.
255
+ export function usedProps(element: ElementNode, text: (span: Span) => string): string {
256
+ if (element.attributes.some(attribute => attribute.kind === 'spread'))
257
+ return ''
258
+
259
+ const names = [...element.attributes.flatMap(attribute => attribute.kind === 'spread' ? [] : [attribute.name]), ...element.children.flatMap(child => child.kind === 'slot' ? [child.name] : [])]
260
+
261
+ return `, { ${names.map(name => `${JSON.stringify(text(name).replace(BOUND, ''))}: 0`).join(', ')} }`
262
+ }
@@ -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 { addConstValue, addKeyParameters, addRowItem, contentOf, 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'
@@ -879,7 +879,7 @@ export class JsxTemplate {
879
879
  let at = start
880
880
 
881
881
  if (sent.functions) {
882
- this.emitFunctionPropCheck(element, attribute.name)
882
+ this.emitFunctionPropCheck(element, attribute.name, false)
883
883
  b.add(' ')
884
884
  }
885
885
 
@@ -904,8 +904,9 @@ export class JsxTemplate {
904
904
  }
905
905
 
906
906
  // Reports a function passed to an island, `0` standing for the prop.
907
- private emitFunctionPropCheck(element: ElementNode, name: Span) {
908
- this.b.add('{...KayFunctionProp(').addSource(element.tag).add(')(').wrap(name, () => this.b.add('0')).add(')}')
907
+ // 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.
908
+ private emitFunctionPropCheck(element: ElementNode, name: Span, whole = true) {
909
+ this.b.add('{...KayFunctionProp(').addSource(element.tag).add(whole ? usedProps(element, span => this.text(span)) : '').add(')(').wrap(name, () => this.b.add('0')).add(')}')
909
910
  }
910
911
 
911
912
  // `bind:value={name}` reads the signal and writes it back from the matching input event.
@@ -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'
@@ -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.names.filter(({ name }) => !isLint(name)).map(({ name, start }): Diagnostic => ({ start, end: start + name.length, code: 'unknown-lint', message: `Unknown lint \`${name}\``, help: `the lints are ${Object.keys(LINTS).map(lint => `\`${lint}\``).join(', ')}`, checkOnly: true })))
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.
@@ -13,7 +13,7 @@ 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
18
  import { contentOf } from './items'
19
19
  import { controlId, fieldAttribute, inheritedAttributes, inheritedField } from './markup-fields'
@@ -362,7 +362,7 @@ export abstract class TemplateWriter {
362
362
  // `except` is a slot that is no prop, as a server island's `@failed`.
363
363
  protected componentProps(element: ElementNode, getters: boolean, except?: SlotNode): void {
364
364
  const { b } = this
365
- const spreads = element.attributes.some(attribute => attribute.kind === 'spread')
365
+ const spreads = element.attributes.some(attribute => attribute.kind === 'spread') || writesTogether(element, this.src, this.facts.parts)
366
366
 
367
367
  if (spreads)
368
368
  b.add(`${helperName('merge')}(`)
@@ -557,11 +557,18 @@ export abstract class TemplateWriter {
557
557
 
558
558
  // 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
559
  const hands = element.component && handedParts(element, this.src, this.facts.parts).length > 0
560
+ const together = writesTogether(element, this.src, this.facts.parts)
560
561
 
561
- if (hands ? spreads : mergedClass)
562
+ if (together) {
563
+ closeObject()
564
+ b.add(objects++ > 0 ? ', ' : '')
565
+ this.mergedClass(element, classAttribute, spreads, writtenParts(element, this.src), true)
566
+ }
567
+
568
+ if (!together && (hands ? spreads : mergedClass))
562
569
  entry('class', () => hands ? b.add('undefined') : this.mergedClass(element, classAttribute, spreads), !hands)
563
570
 
564
- if (element.component && parts.length > 0)
571
+ if (!together && element.component && parts.length > 0)
565
572
  entry('parts', () => this.mergedClass(element, classAttribute, spreads, writtenParts(element, this.src)), true)
566
573
 
567
574
  if (!keepOpen)
@@ -697,7 +704,7 @@ export abstract class TemplateWriter {
697
704
  }
698
705
 
699
706
  // `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 {
707
+ protected mergedClass(element: ElementNode, classAttribute: NamedAttribute | undefined, spreads: boolean, handing?: readonly Attribute[], together = false): void {
701
708
  const { b } = this
702
709
  const shorthand = element.classes.length > 0 ? this.shorthand(element) : undefined
703
710
  const parts = partsOf(element, this.src, this.facts.parts)
@@ -726,27 +733,15 @@ export abstract class TemplateWriter {
726
733
  }
727
734
 
728
735
  // 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
- }
736
+ for (const part of handed)
737
+ items.push(handedItem(b, part, this.recipeItem(part)))
743
738
 
744
739
  for (const part of parts)
745
740
  items.push(...this.recipeItem(part).map(emit => ({ emit })), { emit: () => b.add(`${helperName('partClass')}(${PROPS}, ${JSON.stringify(part)})`) })
746
741
 
747
742
  const written = this.classTable === undefined ? items : joinTexts(items, texts => this.joinLiterals(texts))
748
743
 
749
- openClassList(b, element.component, parts.length > 0, handing)
744
+ openClassList(b, element.component, handing, together)
750
745
  for (const [index, item] of written.entries()) {
751
746
  if (index > 0)
752
747
  b.add(', ')
@@ -756,7 +751,7 @@ export abstract class TemplateWriter {
756
751
  else
757
752
  item.emit()
758
753
  }
759
- closeHandParts(b, element.component, handing)
754
+ closeHandParts(b, element.component, handing, together)
760
755
  }
761
756
 
762
757
  // 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.
@@ -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 {
@@ -0,0 +1,90 @@
1
+ // The lints kay has removed, each with the form it reported gone: a `lints` entry naming one still loads, `kay check` says to remove it, and it changes nothing.
2
+ export const REMOVED_LINTS = [
3
+ 'deprecated-action-readers',
4
+ 'deprecated-action-type',
5
+ 'deprecated-ai-labels',
6
+ 'deprecated-ai-language',
7
+ 'deprecated-ai-links',
8
+ 'deprecated-ai-options',
9
+ 'deprecated-ai-props',
10
+ 'deprecated-analytics-options',
11
+ 'deprecated-app-hooks',
12
+ 'deprecated-auth-methods',
13
+ 'deprecated-auth-rate-limits',
14
+ 'deprecated-auth-signed',
15
+ 'deprecated-await-consent',
16
+ 'deprecated-call-result',
17
+ 'deprecated-callback-handler',
18
+ 'deprecated-children-prop',
19
+ 'deprecated-client-keys',
20
+ 'deprecated-cms-options',
21
+ 'deprecated-cms-test-helpers',
22
+ 'deprecated-config-groups',
23
+ 'deprecated-config-keys',
24
+ 'deprecated-config-switch',
25
+ 'deprecated-context-import',
26
+ 'deprecated-ctx-fail',
27
+ 'deprecated-deny-call',
28
+ 'deprecated-disk-files',
29
+ 'deprecated-env-files',
30
+ 'deprecated-event-names',
31
+ 'deprecated-filter-options',
32
+ 'deprecated-format-duration',
33
+ 'deprecated-guard-option',
34
+ 'deprecated-hook-context',
35
+ 'deprecated-hook-names',
36
+ 'deprecated-i18n-keys',
37
+ 'deprecated-if-alias',
38
+ 'deprecated-image-options',
39
+ 'deprecated-images-keys',
40
+ 'deprecated-import-path',
41
+ 'deprecated-infinite-list-options',
42
+ 'deprecated-island-attributes',
43
+ 'deprecated-island-events',
44
+ 'deprecated-island-fence',
45
+ 'deprecated-job-handler',
46
+ 'deprecated-job-options',
47
+ 'deprecated-link-flags',
48
+ 'deprecated-listen-target',
49
+ 'deprecated-live-api',
50
+ 'deprecated-local-state',
51
+ 'deprecated-mail-form',
52
+ 'deprecated-mail-send',
53
+ 'deprecated-navigate-query',
54
+ 'deprecated-navigation-hooks',
55
+ 'deprecated-package-names',
56
+ 'deprecated-page-cache',
57
+ 'deprecated-page-island',
58
+ 'deprecated-page-seo',
59
+ 'deprecated-pages-options',
60
+ 'deprecated-parts-class',
61
+ 'deprecated-persisted-call',
62
+ 'deprecated-persisted-query',
63
+ 'deprecated-persisted-storage',
64
+ 'deprecated-rate-enforce',
65
+ 'deprecated-redirect-permanent',
66
+ 'deprecated-refuse-call',
67
+ 'deprecated-route-keys',
68
+ 'deprecated-schedule-call',
69
+ 'deprecated-schedule-tz',
70
+ 'deprecated-schema-type',
71
+ 'deprecated-script-fence',
72
+ 'deprecated-secret-keys',
73
+ 'deprecated-socket-frames',
74
+ 'deprecated-source-readers',
75
+ 'deprecated-store-ms',
76
+ 'deprecated-store-names',
77
+ 'deprecated-test-helpers',
78
+ 'deprecated-ttl-names',
79
+ 'deprecated-ui-callbacks',
80
+ 'deprecated-ui-hotkey',
81
+ 'deprecated-ui-input',
82
+ 'deprecated-ui-item-keys',
83
+ 'deprecated-ui-items',
84
+ 'deprecated-uncaught-await',
85
+ 'deprecated-workflow-start-id',
86
+ 'uncaught-await',
87
+ 'unreturned-fail',
88
+ ] as const
89
+
90
+ export type RemovedLintName = typeof REMOVED_LINTS[number]