marko 6.0.0-next.3.27 → 6.0.0-next.3.29

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.
@@ -542,6 +542,10 @@ var KNOWN_OBJECTS = /* @__PURE__ */ new Map([
542
542
  [Math, "Math"],
543
543
  [Reflect, "Reflect"]
544
544
  ]);
545
+ function toAccess(accessor) {
546
+ const start = accessor[0];
547
+ return start === '"' || start >= "0" && start <= "9" ? "[" + accessor + "]" : "." + accessor;
548
+ }
545
549
 
546
550
  // src/html/writer.ts
547
551
  var K_SCOPE_ID = Symbol("Scope ID");
@@ -596,6 +600,7 @@ function escapeAttrValue(str) {
596
600
  var prefix = false ? "$compat_" : "$C_";
597
601
  var RENDERER_REGISTER_ID = prefix + (false ? "renderer" : "r");
598
602
  var SET_SCOPE_REGISTER_ID = prefix + (false ? "setScope" : "s");
603
+ var RENDER_BODY_ID = prefix + (false ? "renderBody" : "b");
599
604
 
600
605
  // src/html/compat.ts
601
606
  var K_TAGS_API_STATE = Symbol();
@@ -1091,6 +1096,7 @@ function startSection(path5) {
1091
1096
  section = extra.section = {
1092
1097
  id: sections.length,
1093
1098
  name: sectionName,
1099
+ loc: sectionNamePath?.node.loc || void 0,
1094
1100
  depth: parentSection ? parentSection.depth + 1 : 0,
1095
1101
  parent: parentSection,
1096
1102
  params: void 0,
@@ -2581,16 +2587,48 @@ function writeHTMLResumeStatements(path5, tagVarIdentifier) {
2581
2587
  }
2582
2588
  }
2583
2589
  if (serializedProperties.length || forceResumeScope(section)) {
2584
- path5.pushContainer(
2585
- "body",
2586
- import_compiler17.types.expressionStatement(
2587
- callRuntime(
2588
- "writeScope",
2589
- scopeIdIdentifier,
2590
- import_compiler17.types.objectExpression(serializedProperties)
2591
- )
2592
- )
2590
+ let writeScope2 = callRuntime(
2591
+ "writeScope",
2592
+ scopeIdIdentifier,
2593
+ import_compiler17.types.objectExpression(serializedProperties)
2593
2594
  );
2595
+ if (!isOptimize()) {
2596
+ let debugVars;
2597
+ forEach(section.bindings, (binding) => {
2598
+ let root = binding;
2599
+ let access = "";
2600
+ while (!root.loc && root.upstreamAlias) {
2601
+ if (root.property !== void 0) {
2602
+ access = toAccess(root.property) + access;
2603
+ }
2604
+ root = root.upstreamAlias;
2605
+ }
2606
+ if (root.loc) {
2607
+ const locStr = import_compiler17.types.stringLiteral(
2608
+ `${root.loc.start.line}:${root.loc.start.column + 1}`
2609
+ );
2610
+ (debugVars ||= []).push(
2611
+ import_compiler17.types.objectProperty(
2612
+ getScopeAccessorLiteral(binding),
2613
+ root !== binding ? import_compiler17.types.arrayExpression([
2614
+ import_compiler17.types.stringLiteral(root.name + access),
2615
+ locStr
2616
+ ]) : locStr
2617
+ )
2618
+ );
2619
+ }
2620
+ });
2621
+ writeScope2 = callRuntime(
2622
+ "debug",
2623
+ writeScope2,
2624
+ import_compiler17.types.stringLiteral(path5.hub.file.opts.filenameRelative),
2625
+ section.loc && section.loc.start.line != null ? import_compiler17.types.stringLiteral(
2626
+ `${section.loc.start.line}:${section.loc.start.column + 1}`
2627
+ ) : import_compiler17.types.numericLiteral(0),
2628
+ debugVars && import_compiler17.types.objectExpression(debugVars)
2629
+ );
2630
+ }
2631
+ path5.pushContainer("body", import_compiler17.types.expressionStatement(writeScope2));
2594
2632
  }
2595
2633
  const resumeClosestBranch2 = !section.isBranch && (section.hasAbortSignal || !!section.closures || !!find(section.bindings, (binding) => binding.type === 1 /* let */));
2596
2634
  if (resumeClosestBranch2) {
@@ -3204,12 +3242,13 @@ function withPreviousLocation(newNode, originalNode) {
3204
3242
  // src/translator/util/references.ts
3205
3243
  var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
3206
3244
  var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
3207
- function createBinding(name2, type, section, upstreamAlias, upstreamExpression, property, declared = false) {
3245
+ function createBinding(name2, type, section, upstreamAlias, upstreamExpression, property, loc = null, declared = false) {
3208
3246
  const id = getNextBindingId();
3209
3247
  const binding = {
3210
3248
  id,
3211
3249
  name: name2,
3212
3250
  type,
3251
+ loc,
3213
3252
  section,
3214
3253
  property,
3215
3254
  declared,
@@ -3333,6 +3372,7 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
3333
3372
  upstreamAlias,
3334
3373
  upstreamExpression,
3335
3374
  property,
3375
+ lVal.loc,
3336
3376
  true
3337
3377
  );
3338
3378
  trackReferencesForBinding(scope.getBinding(lVal.name));
@@ -3344,7 +3384,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
3344
3384
  section,
3345
3385
  upstreamAlias,
3346
3386
  void 0,
3347
- property
3387
+ property,
3388
+ lVal.loc
3348
3389
  ));
3349
3390
  for (const prop of lVal.properties) {
3350
3391
  if (prop.type === "RestElement") {
@@ -3386,7 +3427,8 @@ function createBindingsAndTrackReferences(lVal, type, scope, section, upstreamAl
3386
3427
  section,
3387
3428
  upstreamAlias,
3388
3429
  void 0,
3389
- property
3430
+ property,
3431
+ lVal.loc
3390
3432
  ));
3391
3433
  let i = -1;
3392
3434
  for (const element of lVal.elements) {
@@ -7930,7 +7972,7 @@ var function_default = {
7930
7972
  const extra = node.extra ??= {};
7931
7973
  const name2 = extra.name = fn.node.id?.name || (isMarkoAttribute(markoRoot) ? markoRoot.node.default ? import_compiler47.types.toIdentifier(
7932
7974
  markoRoot.parentPath.has("var") ? markoRoot.parentPath.get("var") : markoRoot.parentPath.get("name")
7933
- ) : markoRoot.node.name : import_compiler47.types.isVariableDeclarator(fn.parent) && import_compiler47.types.isIdentifier(fn.parent.id) ? fn.parent.id.name : "anonymous");
7975
+ ) : markoRoot.node.name : import_compiler47.types.isVariableDeclarator(fn.parent) && import_compiler47.types.isIdentifier(fn.parent.id) ? fn.parent.id.name : import_compiler47.types.isObjectMethod(node) && import_compiler47.types.isIdentifier(node.key) ? node.key.name : "anonymous");
7934
7976
  if (isMarkoAttribute(markoRoot) && ((0, import_babel_utils37.isNativeTag)(markoRoot.parentPath) && /^on[A-Z-]/.test(markoRoot.node.name) || isCoreTagName(markoRoot.parentPath, "script") || isCoreTagName(markoRoot.parentPath, "lifecycle") || isCoreTagName(markoRoot.parentPath, "for"))) {
7935
7977
  return;
7936
7978
  }
@@ -7965,6 +8007,7 @@ function isFunction(fn, isStatic2) {
7965
8007
  return isStatic2 && !fn.node.declare;
7966
8008
  case "FunctionExpression":
7967
8009
  case "ArrowFunctionExpression":
8010
+ case "ObjectMethod":
7968
8011
  return true;
7969
8012
  default:
7970
8013
  return false;
@@ -15,6 +15,7 @@ export type Binding = {
15
15
  id: number;
16
16
  name: string;
17
17
  type: BindingType;
18
+ loc: t.SourceLocation | null;
18
19
  section: Section;
19
20
  serialize: boolean | Set<Binding>;
20
21
  aliases: Set<Binding>;
@@ -53,7 +54,7 @@ declare module "@marko/compiler/dist/types" {
53
54
  interface FunctionExpressionExtra extends FunctionExtra {
54
55
  }
55
56
  }
56
- export declare function createBinding(name: string, type: Binding["type"], section: Section, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"], property?: string, declared?: boolean): Binding;
57
+ export declare function createBinding(name: string, type: Binding["type"], section: Section, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"], property?: string, loc?: t.SourceLocation | null, declared?: boolean): Binding;
57
58
  export declare function trackVarReferences(tag: t.NodePath<t.MarkoTag>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"]): void;
58
59
  export declare function trackParamsReferences(body: t.NodePath<t.MarkoTagBody | t.Program>, type: BindingType, upstreamAlias?: Binding["upstreamAlias"], upstreamExpression?: Binding["upstreamExpression"]): void;
59
60
  export declare function setReferencesScope(path: t.NodePath<any>): void;
@@ -10,6 +10,7 @@ export declare enum ContentType {
10
10
  export interface Section {
11
11
  id: number;
12
12
  name: string;
13
+ loc: t.SourceLocation | undefined;
13
14
  depth: number;
14
15
  parent: Section | undefined;
15
16
  params: undefined | Binding;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.0-next.3.27",
3
+ "version": "6.0.0-next.3.29",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -48,7 +48,7 @@
48
48
  "build": "node -r ~ts ./scripts/bundle.ts"
49
49
  },
50
50
  "dependencies": {
51
- "@marko/compiler": "^5.39.11",
51
+ "@marko/compiler": "^5.39.12",
52
52
  "csstype": "^3.1.3",
53
53
  "magic-string": "^0.30.17"
54
54
  },