marko 6.3.31 → 6.3.33

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 (67) hide show
  1. package/cheatsheet.md +39 -18
  2. package/dist/common/helpers.d.ts +2 -0
  3. package/dist/debug/dom/catch.feat.js +38 -0
  4. package/dist/debug/dom/catch.feat.mjs +37 -0
  5. package/dist/debug/dom/controllable-input.feat.js +7 -0
  6. package/dist/debug/dom/controllable-input.feat.mjs +6 -0
  7. package/dist/debug/dom/controllable-open.feat.js +5 -0
  8. package/dist/debug/dom/controllable-open.feat.mjs +4 -0
  9. package/dist/debug/dom/controllable-select.feat.js +5 -0
  10. package/dist/debug/dom/controllable-select.feat.mjs +4 -0
  11. package/dist/debug/dom/controllable-textarea.feat.js +5 -0
  12. package/dist/debug/dom/controllable-textarea.feat.mjs +4 -0
  13. package/dist/debug/dom/controllable.feat.js +11 -0
  14. package/dist/debug/dom/controllable.feat.mjs +10 -0
  15. package/dist/debug/dom-BJ93mcSe.mjs +2016 -0
  16. package/dist/debug/dom-CiFITSPN.js +2814 -0
  17. package/dist/debug/dom.js +156 -2250
  18. package/dist/debug/dom.mjs +6 -2094
  19. package/dist/debug/html.js +35 -7
  20. package/dist/debug/html.mjs +36 -5
  21. package/dist/dom/catch.feat.d.ts +1 -0
  22. package/dist/dom/catch.feat.js +25 -0
  23. package/dist/dom/catch.feat.mjs +26 -0
  24. package/dist/dom/control-flow.d.ts +3 -3
  25. package/dist/dom/controllable-input.feat.d.ts +1 -0
  26. package/dist/dom/controllable-input.feat.js +3 -0
  27. package/dist/dom/controllable-input.feat.mjs +3 -0
  28. package/dist/dom/controllable-open.feat.d.ts +1 -0
  29. package/dist/dom/controllable-open.feat.js +4 -0
  30. package/dist/dom/controllable-open.feat.mjs +4 -0
  31. package/dist/dom/controllable-select.feat.d.ts +1 -0
  32. package/dist/dom/controllable-select.feat.js +4 -0
  33. package/dist/dom/controllable-select.feat.mjs +4 -0
  34. package/dist/dom/controllable-textarea.feat.d.ts +1 -0
  35. package/dist/dom/controllable-textarea.feat.js +4 -0
  36. package/dist/dom/controllable-textarea.feat.mjs +4 -0
  37. package/dist/dom/controllable.d.ts +3 -8
  38. package/dist/dom/controllable.feat.d.ts +3 -0
  39. package/dist/dom/controllable.feat.js +3 -0
  40. package/dist/dom/controllable.feat.mjs +6 -0
  41. package/dist/dom/queue.d.ts +2 -2
  42. package/dist/dom/resume.d.ts +0 -1
  43. package/dist/dom-CI-06TZb.js +1721 -0
  44. package/dist/dom-Cj4HQ7T_.mjs +1137 -0
  45. package/dist/dom.d.ts +2 -2
  46. package/dist/dom.js +36 -1224
  47. package/dist/dom.mjs +4 -1191
  48. package/dist/html/compat.d.ts +3 -1
  49. package/dist/html/writer.d.ts +3 -0
  50. package/dist/html.d.ts +1 -1
  51. package/dist/html.js +31 -11
  52. package/dist/html.mjs +31 -11
  53. package/dist/translator/index.js +680 -583
  54. package/dist/translator/util/branch-tag.d.ts +5 -0
  55. package/dist/translator/util/constants/structure-kind.d.ts +7 -0
  56. package/dist/translator/util/get-tag-name.d.ts +2 -1
  57. package/dist/translator/util/import-reference.d.ts +3 -0
  58. package/dist/translator/util/runtime.d.ts +2 -0
  59. package/dist/translator/util/sections.d.ts +28 -1
  60. package/dist/translator/util/signals.d.ts +1 -3
  61. package/dist/translator/util/{walks.d.ts → structure.d.ts} +20 -9
  62. package/dist/translator/util/writer.d.ts +0 -8
  63. package/dist/translator/visitors/placeholder.d.ts +4 -3
  64. package/dist/translator/visitors/tag/native-tag.d.ts +9 -6
  65. package/dist/translator/visitors/text.d.ts +3 -7
  66. package/index.d.ts +19 -1
  67. package/package.json +4 -4
@@ -0,0 +1,5 @@
1
+ import { type Binding } from "./references";
2
+ import type { Section } from "./sections";
3
+ export declare function getBranchSectionAccessor(nodeBinding: Binding): NonNullable<Section["sectionAccessor"]>;
4
+ export declare function initBranchSection(bodySection: Section, upstreamExpression: Section["upstreamExpression"], sectionAccessor: Section["sectionAccessor"]): void;
5
+ export declare function resumeOwnerByMarkerWhenStatic(tagSection: Section, bodySection: Section, nodeBinding: Binding, statefulReasonKey: symbol): void;
@@ -0,0 +1,7 @@
1
+ export declare const Visit = "visit";
2
+ export declare const Child = "child";
3
+ export declare const SectionRef = "sectionRef";
4
+ export declare const ExportRef = "exportRef";
5
+ type Self = typeof import("./structure-kind");
6
+ export type Value = Self[keyof Self];
7
+ export {};
@@ -1,2 +1,3 @@
1
- import type { types as t } from "@marko/compiler";
1
+ import { types as t } from "@marko/compiler";
2
2
  export declare function getTagName<T extends t.MarkoTag>(tag: t.NodePath<T>): T["name"] extends t.StringLiteral ? string : string | undefined;
3
+ export declare function getStaticTagName(node: t.MarkoTag): string;
@@ -0,0 +1,3 @@
1
+ import { types as t } from "@marko/compiler";
2
+ export declare function importOrSelfReferenceName(file: t.BabelFile, request: string, name: string, nameHint?: string): t.Identifier;
3
+ export declare function isCircularRequest(file: t.BabelFile, request: string): boolean;
@@ -5,6 +5,8 @@ export type DOMRuntimeHelpers = keyof typeof import("../../dom");
5
5
  export type HTMLRuntimeHelpers = keyof typeof import("../../html");
6
6
  export declare function importRuntime(name: DOMRuntimeHelpers | HTMLRuntimeHelpers): t.Identifier;
7
7
  export declare function callRuntime(name: DOMRuntimeHelpers | HTMLRuntimeHelpers, ...args: Array<Parameters<typeof t.callExpression>[1][number] | Falsy>): t.CallExpression;
8
+ export type DOMRuntimeFeature = "catch" | "controllable" | "controllable-input" | "controllable-open" | "controllable-select" | "controllable-textarea";
9
+ export declare function importRuntimeFeature(feature: DOMRuntimeFeature): void;
8
10
  export declare function getHTMLRuntime(): {
9
11
  _escape: typeof _escape;
10
12
  _escape_comment: typeof _escape_comment;
@@ -1,6 +1,9 @@
1
1
  import { types as t } from "@marko/compiler";
2
2
  import type { AccessorPrefix } from "../../common/accessor.debug";
3
+ import type { WalkCode } from "../../common/types";
3
4
  import * as ContentType from "./constants/content-type";
5
+ import type * as Step from "./constants/step";
6
+ import * as StructureKind from "./constants/structure-kind";
4
7
  import { type Opt, Sorted } from "./optional";
5
8
  import { type Binding, type InputBinding, type ParamBinding, type ReferencedBindings, type Sources } from "./references";
6
9
  import { type SerializeReason } from "./serialize-reasons";
@@ -13,7 +16,30 @@ export type ParamSerializeReasonGroups = [
13
16
  ...ParamSerializeReasonGroup[]
14
17
  ];
15
18
  type ContentType = ContentType.Value;
16
- export { ContentType };
19
+ export { ContentType, StructureKind };
20
+ export type StructureRef = StructureSectionRef | StructureExportRef;
21
+ export interface StructureSectionRef {
22
+ kind: typeof StructureKind.SectionRef;
23
+ section: Section;
24
+ }
25
+ export interface StructureExportRef {
26
+ kind: typeof StructureKind.ExportRef;
27
+ program: t.ProgramExtra;
28
+ path: string;
29
+ hint: string;
30
+ }
31
+ export type StructureOp = string | Step.Value | StructureVisit | StructureChild;
32
+ export interface StructureVisit {
33
+ kind: typeof StructureKind.Visit;
34
+ code: typeof WalkCode.Get | typeof WalkCode.Replace | typeof WalkCode.DynamicTagWithVar;
35
+ claimed: boolean;
36
+ }
37
+ export interface StructureChild {
38
+ kind: typeof StructureKind.Child;
39
+ name: string;
40
+ hasVar: boolean;
41
+ renderer?: StructureRef;
42
+ }
17
43
  export interface Section {
18
44
  id: number;
19
45
  name: string;
@@ -53,6 +79,7 @@ export interface Section {
53
79
  endType: ContentType;
54
80
  singleChild: boolean;
55
81
  };
82
+ structure: StructureOp[] | null;
56
83
  }
57
84
  declare module "@marko/compiler/dist/types" {
58
85
  interface ProgramExtra {
@@ -15,9 +15,7 @@ export interface Signal {
15
15
  }>;
16
16
  intersection: Opt<Signal>;
17
17
  render: t.Statement[];
18
- renderReferencedBindings: ReferencedBindings;
19
18
  effect: t.Statement[];
20
- effectReferencedBindings: ReferencedBindings;
21
19
  hasHTMLEffect: boolean;
22
20
  hasSideEffect: boolean;
23
21
  forcePersist: boolean;
@@ -46,7 +44,7 @@ export declare function signalHasStatements(signal: Signal): boolean;
46
44
  export declare function getSignalFn(signal: Signal): t.Expression;
47
45
  export declare function getSignalValueIdentifier(signal: Signal): t.Identifier;
48
46
  export declare function replaceNullishAndEmptyFunctionsWith0(args: (t.Expression | undefined | false)[]): t.Expression[];
49
- export declare function addStatement(type: "render" | "effect", targetSection: Section, referencedBindings: ReferencedBindings, statement: t.Statement | t.Statement[], usedReferences?: ReferencedBindings[] | false, isPure?: boolean): void;
47
+ export declare function addStatement(type: "render" | "effect", targetSection: Section, referencedBindings: ReferencedBindings, statement: t.Statement | t.Statement[], isPure?: boolean): void;
50
48
  export declare function addValue(targetSection: Section, referencedBindings: ReferencedBindings, signal: Signal, value: t.Expression): void;
51
49
  export declare function getResumeRegisterId(section: Section, referencedBindings: string | ReferencedBindings, type?: string): string;
52
50
  export declare function writeSignals(section: Section): Set<Signal>;
@@ -1,17 +1,28 @@
1
1
  import { types as t } from "@marko/compiler";
2
- import { WalkCode } from "../../common/types";
3
- import { type Section } from "../util/sections";
4
2
  import * as Step from "./constants/step";
5
- type Walk = string | t.Expression | (() => undefined | string | t.Expression);
6
- type Step = Step.Value;
7
- export { Step };
8
- type VisitCodes = typeof WalkCode.Get | typeof WalkCode.Replace | typeof WalkCode.DynamicTagWithVar;
3
+ import { type Section, type StructureRef, type StructureVisit } from "./sections";
9
4
  export declare function enter(path: t.NodePath<any>): void;
10
5
  export declare function exit(path: t.NodePath<any>): void;
11
6
  export declare function enterShallow(path: t.NodePath<any>): void;
12
- export declare function injectWalks(tag: t.NodePath<t.MarkoTag>, name: string, expr?: Walk): void;
13
- export declare function visit(path: t.NodePath<t.MarkoTag | t.MarkoPlaceholder | t.Program>, code: VisitCodes): void;
7
+ export declare function child(tag: t.NodePath<t.MarkoTag>, name: string, renderer?: StructureRef): void;
8
+ export declare function writeTo(path: t.NodePath<any>): (strs: TemplateStringsArray, ...exprs: string[]) => void;
9
+ export declare function visit(path: t.NodePath<t.MarkoTag | t.MarkoPlaceholder | t.Program>, code: StructureVisit["code"], claimed?: boolean): StructureVisit | undefined;
10
+ type ResolvedPart = string | t.Expression;
11
+ interface ResolvedStructure {
12
+ writes: ResolvedPart[];
13
+ walks: ResolvedPart[];
14
+ walkComment: string[];
15
+ steps: Step.Value[];
16
+ }
17
+ export declare function resolveStructure(section: Section): ResolvedStructure;
18
+ interface SectionMeta {
19
+ walks: t.Expression | undefined;
20
+ writes: t.Expression | undefined;
21
+ decls: t.VariableDeclarator[] | undefined;
22
+ }
23
+ export declare const getSectionMeta: (section: Section) => SectionMeta;
24
+ export declare function getSectionMetaIdentifiers(section: Section): SectionMeta;
14
25
  /** `_content` strips trailing exit codes before it walks, so a renderer that
15
26
  * reaches the runtime through it never needs them on the wire. */
16
27
  export declare function trimTrailingExits(walks: t.Expression | undefined): t.ArrayExpression | t.ArrowFunctionExpression | t.AssignmentExpression | t.AwaitExpression | t.BigIntLiteral | t.BinaryExpression | t.BindExpression | t.BooleanLiteral | t.CallExpression | t.ClassExpression | t.ConditionalExpression | t.DecimalLiteral | t.DoExpression | t.FunctionExpression | t.Identifier | t.Import | t.ImportExpression | t.JSXElement | t.JSXFragment | t.LogicalExpression | t.MarkoParseError | t.MemberExpression | t.MetaProperty | t.ModuleExpression | t.NewExpression | t.NullLiteral | t.NumericLiteral | t.ObjectExpression | t.OptionalCallExpression | t.OptionalMemberExpression | t.ParenthesizedExpression | t.PipelineBareFunction | t.PipelinePrimaryTopicReference | t.PipelineTopicExpression | t.RecordExpression | t.RegExpLiteral | t.SequenceExpression | t.StringLiteral | t.Super | t.TSAsExpression | t.TSInstantiationExpression | t.TSNonNullExpression | t.TSSatisfiesExpression | t.TSTypeAssertion | t.TaggedTemplateExpression | t.TemplateLiteral | t.ThisExpression | t.TopicReference | t.TupleExpression | t.TypeCastExpression | t.UnaryExpression | t.UpdateExpression | t.YieldExpression | undefined;
17
- export declare function getWalkString(section: Section): t.Expression | undefined;
28
+ export {};
@@ -1,5 +1,4 @@
1
1
  import { types as t } from "@marko/compiler";
2
- import { type Section } from "../util/sections";
3
2
  import { type Binding } from "./references";
4
3
  import type { SerializeReason } from "./serialize-reasons";
5
4
  type Write = string | t.Expression | (() => undefined | string | t.Expression);
@@ -7,12 +6,5 @@ export declare function writeTo(path: t.NodePath<any>, trailer?: boolean): (strs
7
6
  export declare function consumeHTML(path: t.NodePath<any>): t.ExpressionStatement | undefined;
8
7
  export declare function flushBefore(path: t.NodePath<any>): void;
9
8
  export declare function flushInto(path: t.NodePath<t.MarkoTag> | t.NodePath<t.Program>): void;
10
- interface SectionMeta {
11
- walks: t.Expression | undefined;
12
- writes: t.Expression | undefined;
13
- decls: t.VariableDeclarator[] | undefined;
14
- }
15
- export declare const getSectionMeta: (section: Section) => SectionMeta;
16
- export declare function getSectionMetaIdentifiers(section: Section): SectionMeta;
17
9
  export declare function markNode(path: t.NodePath<t.MarkoTag | t.MarkoPlaceholder>, nodeBinding: Binding, reason: undefined | false | SerializeReason, deferred?: boolean): void;
18
10
  export {};
@@ -3,17 +3,18 @@ import { type Binding } from "../util/references";
3
3
  import * as SiblingText from "./constants/sibling-text";
4
4
  declare const kNodeBinding: unique symbol;
5
5
  declare const kSiblingText: unique symbol;
6
- declare const kSharedText: unique symbol;
7
6
  type SiblingText = SiblingText.Value;
8
7
  declare module "@marko/compiler/dist/types" {
9
8
  interface MarkoPlaceholderExtra {
10
9
  [kNodeBinding]?: Binding;
11
10
  [kSiblingText]?: SiblingText;
12
- [kSharedText]?: true;
13
11
  }
14
12
  }
15
13
  declare const _default: {
16
- analyze(this: unknown, placeholder: t.NodePath<t.MarkoPlaceholder>): void;
14
+ analyze: {
15
+ enter(this: unknown, placeholder: t.NodePath<t.MarkoPlaceholder>): void;
16
+ exit(this: unknown, placeholder: t.NodePath<t.MarkoPlaceholder>): void;
17
+ };
17
18
  translate: {
18
19
  exit(this: unknown, placeholder: t.NodePath<t.MarkoPlaceholder>): void;
19
20
  };
@@ -1,19 +1,23 @@
1
1
  import { types as t } from "@marko/compiler";
2
2
  import { type Binding } from "../../util/references";
3
- import { type DOMRuntimeHelpers } from "../../util/runtime";
3
+ import { type DOMRuntimeFeature } from "../../util/runtime";
4
+ import { type StructureVisit } from "../../util/sections";
4
5
  export declare const kNativeTagBinding: unique symbol;
5
6
  export declare const kSkipEndTag: unique symbol;
6
7
  declare const kTagContentAttr: unique symbol;
8
+ declare const kVisitOp: unique symbol;
7
9
  declare module "@marko/compiler/dist/types" {
8
10
  interface NodeExtra {
9
11
  [kNativeTagBinding]?: Binding;
10
12
  [kSkipEndTag]?: true;
11
13
  [kTagContentAttr]?: true;
14
+ [kVisitOp]?: StructureVisit;
12
15
  }
13
16
  }
14
17
  declare const _default: {
15
18
  analyze: {
16
19
  enter(this: unknown, tag: t.NodePath<t.MarkoTag>): void;
20
+ exit(this: unknown, tag: t.NodePath<t.MarkoTag>): void;
17
21
  };
18
22
  translate: {
19
23
  readonly enter: (path: t.NodePath<t.MarkoTag>) => void;
@@ -25,8 +29,7 @@ export default _default;
25
29
  * tags that control nothing, and nothing when a static attr owns the
26
30
  * controllable, since then the spread must leave the slots it wrote alone. */
27
31
  export declare function controllableClaimFor(tagName: string | undefined): "_controllable_input" | "_controllable_open" | "_controllable_select" | "_controllable_textarea" | undefined;
28
- /** The resume-pass latch for a tag: `_attrs_script` resolves the control kind
29
- * at run time, and a run-time tag name can be any of them. */
30
- export declare function controllableScriptLatchFor(tagName: string | undefined): "_enable_controllable" | "_enable_controllable_input" | "_enable_controllable_open" | "_enable_controllable_select" | "_enable_controllable_textarea" | undefined;
31
- /** Emits the latch once per program, like `_enable_catch`. */
32
- export declare function enableControllable(helper: DOMRuntimeHelpers | undefined): void;
32
+ /** The resume-pass feature for a tag: `_attrs_script` resolves the control
33
+ * kind at run time, and a run-time tag name can be any of them. */
34
+ export declare function controllableFeatureFor(tagName: string | undefined): "controllable" | "controllable-input" | "controllable-open" | "controllable-select" | "controllable-textarea" | undefined;
35
+ export declare function enableControllable(feature: DOMRuntimeFeature | undefined): void;
@@ -1,12 +1,8 @@
1
1
  import { types as t } from "@marko/compiler";
2
- declare const kSharedText: unique symbol;
3
- declare module "@marko/compiler/dist/types" {
4
- interface NodeExtra {
5
- [kSharedText]?: true;
6
- }
7
- }
8
2
  declare const _default: {
9
- analyze(this: unknown, text: t.NodePath<t.MarkoText>): void;
3
+ analyze: {
4
+ exit(this: unknown, text: t.NodePath<t.MarkoText>): void;
5
+ };
10
6
  translate: {
11
7
  exit(this: unknown, text: t.NodePath<t.MarkoText>): void;
12
8
  };
package/index.d.ts CHANGED
@@ -11,7 +11,25 @@ declare global {
11
11
  }
12
12
 
13
13
  namespace Marko {
14
- /** A mutable global object for the current render. */
14
+ /**
15
+ * A mutable global object for the current render.
16
+ *
17
+ * The open index signature means an unaugmented `$global` is unchecked. To
18
+ * type your own keys, merge into this interface:
19
+ *
20
+ * ```ts
21
+ * declare global {
22
+ * namespace Marko {
23
+ * interface Global {
24
+ * data?: MyRouteContext;
25
+ * }
26
+ * }
27
+ * }
28
+ * ```
29
+ *
30
+ * Declare merged members OPTIONAL — a required one makes every
31
+ * `render({ $global: {} })` call fail with TS2741.
32
+ */
15
33
  export interface Global {
16
34
  [x: PropertyKey]: unknown;
17
35
  /** An AbortSignal instance that, when aborted, stops further streamed content. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.3.31",
3
+ "version": "6.3.33",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -48,14 +48,14 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@marko/compiler": "^5.41.12",
51
+ "@marko/compiler": "^5.41.17",
52
52
  "csstype": "^3.2.3",
53
53
  "fastest-levenshtein": "^1.0.16",
54
54
  "magic-string": "^0.30.21"
55
55
  },
56
56
  "devDependencies": {
57
- "@marko/runtime-tags": "npm:marko@6.3.31",
58
- "marko": "5.39.30"
57
+ "@marko/runtime-tags": "npm:marko@6.3.33",
58
+ "marko": "5.39.31"
59
59
  },
60
60
  "engines": {
61
61
  "node": ">=22"