marko 6.0.0-next.3.56 → 6.0.0-next.3.58

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/debug/dom.js CHANGED
@@ -206,9 +206,14 @@ function handleDelegated(ev) {
206
206
  }
207
207
 
208
208
  // src/dom/resolve-cursor-position.ts
209
- function resolveCursorPosition(updatedValue, initialValue, initialPosition, inputType2) {
210
- if (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
211
- /kw/.test(inputType2)) {
209
+ function resolveCursorPosition(inputType2, initialPosition, initialValue, updatedValue) {
210
+ if (
211
+ // If initial position is null or false then
212
+ // either this node is not the active element
213
+ // or does not support selection ranges.
214
+ (initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
215
+ /kw/.test(inputType2))
216
+ ) {
212
217
  const before = initialValue.slice(0, initialPosition);
213
218
  const after = initialValue.slice(initialPosition);
214
219
  if (updatedValue.startsWith(before)) {
@@ -643,22 +648,15 @@ function controllable_detailsOrDialog_open_effect(scope, nodeAccessor) {
643
648
  }
644
649
  var inputType = "";
645
650
  function setValueAndUpdateSelection(el, value2) {
646
- const initialValue = el.value;
647
- if (initialValue !== value2) {
648
- if (el.getRootNode().activeElement === el) {
649
- const initialPosition = el.selectionStart;
650
- el.value = value2;
651
- const updatedPosition = resolveCursorPosition(
652
- el.value,
653
- initialValue,
654
- initialPosition,
655
- inputType
656
- );
657
- if (~updatedPosition) {
658
- el.setSelectionRange(updatedPosition, updatedPosition);
659
- }
660
- } else {
661
- el.value = value2;
651
+ if (el.value !== value2) {
652
+ const updatedPosition = resolveCursorPosition(
653
+ inputType,
654
+ el.getRootNode().activeElement === el && el.selectionStart,
655
+ el.value,
656
+ el.value = value2
657
+ );
658
+ if (~updatedPosition) {
659
+ el.selectionStart = updatedPosition;
662
660
  }
663
661
  }
664
662
  }
@@ -121,9 +121,14 @@ function handleDelegated(ev) {
121
121
  }
122
122
 
123
123
  // src/dom/resolve-cursor-position.ts
124
- function resolveCursorPosition(updatedValue, initialValue, initialPosition, inputType2) {
125
- if (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
126
- /kw/.test(inputType2)) {
124
+ function resolveCursorPosition(inputType2, initialPosition, initialValue, updatedValue) {
125
+ if (
126
+ // If initial position is null or false then
127
+ // either this node is not the active element
128
+ // or does not support selection ranges.
129
+ (initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
130
+ /kw/.test(inputType2))
131
+ ) {
127
132
  const before = initialValue.slice(0, initialPosition);
128
133
  const after = initialValue.slice(initialPosition);
129
134
  if (updatedValue.startsWith(before)) {
@@ -558,22 +563,15 @@ function controllable_detailsOrDialog_open_effect(scope, nodeAccessor) {
558
563
  }
559
564
  var inputType = "";
560
565
  function setValueAndUpdateSelection(el, value2) {
561
- const initialValue = el.value;
562
- if (initialValue !== value2) {
563
- if (el.getRootNode().activeElement === el) {
564
- const initialPosition = el.selectionStart;
565
- el.value = value2;
566
- const updatedPosition = resolveCursorPosition(
567
- el.value,
568
- initialValue,
569
- initialPosition,
570
- inputType
571
- );
572
- if (~updatedPosition) {
573
- el.setSelectionRange(updatedPosition, updatedPosition);
574
- }
575
- } else {
576
- el.value = value2;
566
+ if (el.value !== value2) {
567
+ const updatedPosition = resolveCursorPosition(
568
+ inputType,
569
+ el.getRootNode().activeElement === el && el.selectionStart,
570
+ el.value,
571
+ el.value = value2
572
+ );
573
+ if (~updatedPosition) {
574
+ el.selectionStart = updatedPosition;
577
575
  }
578
576
  }
579
577
  }
@@ -1 +1 @@
1
- export declare function resolveCursorPosition(updatedValue: string, initialValue: string, initialPosition: number, inputType: string): number;
1
+ export declare function resolveCursorPosition(inputType: string, initialPosition: number | null | false, initialValue: string, updatedValue: string): number;
package/dist/dom.js CHANGED
@@ -173,9 +173,14 @@ function handleDelegated(ev) {
173
173
  }
174
174
 
175
175
  // src/dom/resolve-cursor-position.ts
176
- function resolveCursorPosition(updatedValue, initialValue, initialPosition, inputType2) {
177
- if (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
178
- /kw/.test(inputType2)) {
176
+ function resolveCursorPosition(inputType2, initialPosition, initialValue, updatedValue) {
177
+ if (
178
+ // If initial position is null or false then
179
+ // either this node is not the active element
180
+ // or does not support selection ranges.
181
+ (initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
182
+ /kw/.test(inputType2))
183
+ ) {
179
184
  let before = initialValue.slice(0, initialPosition), after = initialValue.slice(initialPosition);
180
185
  if (updatedValue.startsWith(before))
181
186
  return initialPosition;
@@ -447,20 +452,15 @@ function controllable_detailsOrDialog_open_effect(scope, nodeAccessor) {
447
452
  }
448
453
  var inputType = "";
449
454
  function setValueAndUpdateSelection(el, value2) {
450
- let initialValue = el.value;
451
- if (initialValue !== value2)
452
- if (el.getRootNode().activeElement === el) {
453
- let initialPosition = el.selectionStart;
454
- el.value = value2;
455
- let updatedPosition = resolveCursorPosition(
456
- el.value,
457
- initialValue,
458
- initialPosition,
459
- inputType
460
- );
461
- ~updatedPosition && el.setSelectionRange(updatedPosition, updatedPosition);
462
- } else
463
- el.value = value2;
455
+ if (el.value !== value2) {
456
+ let updatedPosition = resolveCursorPosition(
457
+ inputType,
458
+ el.getRootNode().activeElement === el && el.selectionStart,
459
+ el.value,
460
+ el.value = value2
461
+ );
462
+ ~updatedPosition && (el.selectionStart = updatedPosition);
463
+ }
464
464
  }
465
465
  function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
466
466
  scope[nodeAccessor + ";" /* ControlledHandler */] = checkedChange, checkedChange ? (scope[nodeAccessor + "=" /* ControlledType */] = type, scope[nodeAccessor].checked = checked) : (scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, scope[nodeAccessor].defaultChecked = checked);
package/dist/dom.mjs CHANGED
@@ -91,9 +91,14 @@ function handleDelegated(ev) {
91
91
  }
92
92
 
93
93
  // src/dom/resolve-cursor-position.ts
94
- function resolveCursorPosition(updatedValue, initialValue, initialPosition, inputType2) {
95
- if (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
96
- /kw/.test(inputType2)) {
94
+ function resolveCursorPosition(inputType2, initialPosition, initialValue, updatedValue) {
95
+ if (
96
+ // If initial position is null or false then
97
+ // either this node is not the active element
98
+ // or does not support selection ranges.
99
+ (initialPosition || initialPosition === 0) && (initialPosition !== initialValue.length || // short regex to match input types that delete backwards
100
+ /kw/.test(inputType2))
101
+ ) {
97
102
  let before = initialValue.slice(0, initialPosition), after = initialValue.slice(initialPosition);
98
103
  if (updatedValue.startsWith(before))
99
104
  return initialPosition;
@@ -365,20 +370,15 @@ function controllable_detailsOrDialog_open_effect(scope, nodeAccessor) {
365
370
  }
366
371
  var inputType = "";
367
372
  function setValueAndUpdateSelection(el, value2) {
368
- let initialValue = el.value;
369
- if (initialValue !== value2)
370
- if (el.getRootNode().activeElement === el) {
371
- let initialPosition = el.selectionStart;
372
- el.value = value2;
373
- let updatedPosition = resolveCursorPosition(
374
- el.value,
375
- initialValue,
376
- initialPosition,
377
- inputType
378
- );
379
- ~updatedPosition && el.setSelectionRange(updatedPosition, updatedPosition);
380
- } else
381
- el.value = value2;
373
+ if (el.value !== value2) {
374
+ let updatedPosition = resolveCursorPosition(
375
+ inputType,
376
+ el.getRootNode().activeElement === el && el.selectionStart,
377
+ el.value,
378
+ el.value = value2
379
+ );
380
+ ~updatedPosition && (el.selectionStart = updatedPosition);
381
+ }
382
382
  }
383
383
  function setCheckboxValue(scope, nodeAccessor, type, checked, checkedChange) {
384
384
  scope[nodeAccessor + ";" /* ControlledHandler */] = checkedChange, checkedChange ? (scope[nodeAccessor + "=" /* ControlledType */] = type, scope[nodeAccessor].checked = checked) : (scope[nodeAccessor + "=" /* ControlledType */] = 5 /* None */, scope[nodeAccessor].defaultChecked = checked);
@@ -2688,27 +2688,12 @@ function writeHTMLResumeStatements(path5) {
2688
2688
  if (!section) return;
2689
2689
  const allSignals = Array.from(getSignals(section).values());
2690
2690
  const scopeIdIdentifier = getScopeIdIdentifier(section);
2691
- const serializeOwnersUntilBindingSection = (binding) => {
2692
- let currentSection = section;
2693
- while (currentSection !== binding.section) {
2694
- const currentSerialized = getSerializedScopeProperties(currentSection);
2695
- currentSection = currentSection.parent;
2696
- if (!currentSerialized.has("_")) {
2697
- currentSerialized.set(
2698
- "_",
2699
- callRuntime(
2700
- "ensureScopeWithId",
2701
- getScopeIdIdentifier(currentSection)
2702
- )
2703
- );
2704
- }
2705
- }
2706
- };
2707
- forEach(section.assignments, serializeOwnersUntilBindingSection);
2708
- forEach(section.referencedHoists, serializeOwnersUntilBindingSection);
2691
+ const serializeOwnersUntilBinding = (binding) => serializeOwners(section, binding.section);
2692
+ forEach(section.assignments, serializeOwnersUntilBinding);
2693
+ forEach(section.referencedHoists, serializeOwnersUntilBinding);
2709
2694
  forEach(section.referencedClosures, (closure) => {
2710
2695
  if (isStatefulReferences(closure)) {
2711
- serializeOwnersUntilBindingSection(closure);
2696
+ serializeOwnersUntilBinding(closure);
2712
2697
  setForceResumeScope(closure.section);
2713
2698
  if (isDynamicClosure(section, closure)) {
2714
2699
  const closureSignal = getSignal(closure.section, closure);
@@ -2910,6 +2895,21 @@ function writeHTMLResumeStatements(path5) {
2910
2895
  path5.pushContainer("body", import_compiler17.types.returnStatement(returnIdentifier));
2911
2896
  }
2912
2897
  }
2898
+ function serializeOwners(from, to) {
2899
+ let cur = from;
2900
+ while (cur !== to) {
2901
+ const parent = cur.parent;
2902
+ if (!parent) break;
2903
+ const serialized = getSerializedScopeProperties(cur);
2904
+ cur = parent;
2905
+ if (!serialized.has("_")) {
2906
+ serialized.set(
2907
+ "_",
2908
+ callRuntime("ensureScopeWithId", getScopeIdIdentifier(cur))
2909
+ );
2910
+ }
2911
+ }
2912
+ }
2913
2913
  function getSetup(section) {
2914
2914
  return getSignals(section).get(void 0)?.identifier;
2915
2915
  }
@@ -3863,7 +3863,7 @@ function trackReference(referencePath, binding) {
3863
3863
  propPath = reference.name;
3864
3864
  continue;
3865
3865
  }
3866
- if (root.parentPath.parentPath.isCallExpression() && !isEventOrChangeHandler(prop)) {
3866
+ if (isInvokedFunction(root.parentPath) && !isEventOrChangeHandler(prop)) {
3867
3867
  break;
3868
3868
  }
3869
3869
  root = root.parentPath;
@@ -4951,19 +4951,7 @@ var native_tag_default = {
4951
4951
  for (const reference of varBinding.referencePaths) {
4952
4952
  const referenceSection = getSection(reference);
4953
4953
  if (!reference.node.extra?.hoist) {
4954
- let currentSection = referenceSection;
4955
- while (currentSection !== section && currentSection.parent) {
4956
- setSerializedProperty(
4957
- currentSection,
4958
- "_",
4959
- callRuntime(
4960
- "ensureScopeWithId",
4961
- getScopeIdIdentifier(
4962
- currentSection = currentSection.parent
4963
- )
4964
- )
4965
- );
4966
- }
4954
+ serializeOwners(referenceSection, section);
4967
4955
  }
4968
4956
  }
4969
4957
  setForceResumeScope(section);
@@ -6336,7 +6324,7 @@ var html_comment_default = {
6336
6324
  }
6337
6325
  needsBinding = true;
6338
6326
  for (const ref of tag.scope.getBinding(tagVar.name).referencePaths) {
6339
- if (!ref.parentPath?.isCallExpression()) {
6327
+ if (!isInvokedFunction(ref)) {
6340
6328
  needsGetter = true;
6341
6329
  break;
6342
6330
  }
@@ -6407,7 +6395,7 @@ var html_comment_default = {
6407
6395
  }
6408
6396
  for (const reference of references) {
6409
6397
  const referenceSection = getSection(reference);
6410
- if (reference.parentPath?.isCallExpression()) {
6398
+ if (isInvokedFunction(reference)) {
6411
6399
  reference.parentPath.replaceWith(
6412
6400
  import_compiler35.types.expressionStatement(
6413
6401
  createScopeReadExpression(referenceSection, commentBinding)
@@ -6571,7 +6559,7 @@ var html_script_default = {
6571
6559
  );
6572
6560
  if (node.var) {
6573
6561
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
6574
- if (!ref.parentPath?.isCallExpression()) {
6562
+ if (!isInvokedFunction(ref)) {
6575
6563
  tagExtra[kGetterId3] = getRegisterUID(section, bindingName);
6576
6564
  break;
6577
6565
  }
@@ -6592,17 +6580,7 @@ var html_script_default = {
6592
6580
  const varName = tag.node.var.name;
6593
6581
  const references = tag.scope.getBinding(varName).referencePaths;
6594
6582
  for (const reference of references) {
6595
- let currentSection = getSection(reference);
6596
- while (currentSection !== section && currentSection.parent) {
6597
- setSerializedProperty(
6598
- currentSection,
6599
- "_",
6600
- callRuntime(
6601
- "ensureScopeWithId",
6602
- getScopeIdIdentifier(currentSection = currentSection.parent)
6603
- )
6604
- );
6605
- }
6583
+ serializeOwners(getSection(reference), section);
6606
6584
  }
6607
6585
  translateVar(
6608
6586
  tag,
@@ -6636,7 +6614,7 @@ var html_script_default = {
6636
6614
  }
6637
6615
  for (const reference of references) {
6638
6616
  const referenceSection = getSection(reference);
6639
- if (reference.parentPath?.isCallExpression()) {
6617
+ if (isInvokedFunction(reference)) {
6640
6618
  reference.parentPath.replaceWith(
6641
6619
  import_compiler36.types.expressionStatement(
6642
6620
  createScopeReadExpression(referenceSection, nodeRef2)
@@ -6967,7 +6945,7 @@ var html_style_default = {
6967
6945
  );
6968
6946
  if (node.var) {
6969
6947
  for (const ref of tag.scope.getBinding(node.var.name).referencePaths) {
6970
- if (!ref.parentPath?.isCallExpression()) {
6948
+ if (!isInvokedFunction(ref)) {
6971
6949
  tagExtra[kGetterId4] = getRegisterUID(section, bindingName);
6972
6950
  break;
6973
6951
  }
@@ -6988,17 +6966,7 @@ var html_style_default = {
6988
6966
  const varName = tag.node.var.name;
6989
6967
  const references = tag.scope.getBinding(varName).referencePaths;
6990
6968
  for (const reference of references) {
6991
- let currentSection = getSection(reference);
6992
- while (currentSection !== section && currentSection.parent) {
6993
- setSerializedProperty(
6994
- currentSection,
6995
- "_",
6996
- callRuntime(
6997
- "ensureScopeWithId",
6998
- getScopeIdIdentifier(currentSection = currentSection.parent)
6999
- )
7000
- );
7001
- }
6969
+ serializeOwners(getSection(reference), section);
7002
6970
  }
7003
6971
  translateVar(
7004
6972
  tag,
@@ -7032,7 +7000,7 @@ var html_style_default = {
7032
7000
  }
7033
7001
  for (const reference of references) {
7034
7002
  const referenceSection = getSection(reference);
7035
- if (reference.parentPath?.isCallExpression()) {
7003
+ if (isInvokedFunction(reference)) {
7036
7004
  reference.parentPath.replaceWith(
7037
7005
  import_compiler37.types.expressionStatement(
7038
7006
  createScopeReadExpression(referenceSection, nodeRef2)
@@ -8494,6 +8462,7 @@ var kBinding = Symbol("placeholder node binding");
8494
8462
  var kSiblingText = Symbol("placeholder has sibling text");
8495
8463
  var placeholder_default = {
8496
8464
  analyze(placeholder) {
8465
+ if (isNonHTMLPlaceholder(placeholder)) return;
8497
8466
  const { node } = placeholder;
8498
8467
  const { confident, computed } = evaluate(node.value);
8499
8468
  if (!(confident && (node.escape || isVoid2(computed)))) {
@@ -8610,6 +8579,18 @@ function analyzeSiblingText(placeholder) {
8610
8579
  }
8611
8580
  return placeholderExtra[kSiblingText] = 0 /* None */;
8612
8581
  }
8582
+ function isNonHTMLPlaceholder(placeholder) {
8583
+ const parentTag = placeholder.parentPath.isMarkoTagBody() && placeholder.parentPath.parentPath;
8584
+ if (parentTag && isCoreTag(parentTag)) {
8585
+ switch (parentTag.node.name.value) {
8586
+ case "html-comment":
8587
+ case "html-script":
8588
+ case "html-style":
8589
+ return true;
8590
+ }
8591
+ }
8592
+ return false;
8593
+ }
8613
8594
  function isVoid2(value) {
8614
8595
  return value == null || value === false;
8615
8596
  }
@@ -55,6 +55,7 @@ export declare function writeSignals(section: Section): void;
55
55
  export declare function writeRegisteredFns(): void;
56
56
  export declare function addHTMLEffectCall(section: Section, referencedBindings?: ReferencedBindings): void;
57
57
  export declare function writeHTMLResumeStatements(path: t.NodePath<t.MarkoTagBody | t.Program>): void;
58
+ export declare function serializeOwners(from: Section, to?: Section): void;
58
59
  export declare function getSetup(section: Section): t.Identifier | undefined;
59
60
  export declare function replaceRegisteredFunctionNode(node: t.Node): t.CallExpression | t.ClassPrivateProperty | t.ClassProperty | t.VariableDeclaration | t.Identifier | t.ObjectProperty | undefined;
60
61
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.0-next.3.56",
3
+ "version": "6.0.0-next.3.58",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",