marko 6.0.120 → 6.0.121

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.
@@ -4863,30 +4863,25 @@ function withPreviousLocation(newNode, originalNode) {
4863
4863
  var TAG_NAME_IDENTIFIER_REG = /^[A-Z][a-zA-Z0-9_$]*$/;
4864
4864
  var BINDING_CHANGE_HANDLER = /* @__PURE__ */ new WeakMap();
4865
4865
  function preAnalyze2(program) {
4866
- const state = { crawl: false };
4867
- normalizeBody(state, program.get("body"));
4868
- if (state.crawl) {
4869
- program.scope.crawl();
4870
- }
4866
+ normalizeBody(program.get("body"));
4871
4867
  }
4872
- function normalizeBody(state, body) {
4868
+ function normalizeBody(body) {
4873
4869
  if (body?.length) {
4874
4870
  for (const child of body) {
4875
4871
  if (child.isMarkoTag()) {
4876
- normalizeTag(state, child);
4872
+ normalizeTag(child);
4877
4873
  }
4878
4874
  }
4879
4875
  }
4880
4876
  }
4881
- function normalizeTag(state, tag) {
4877
+ function normalizeTag(tag) {
4882
4878
  const { node } = tag;
4883
4879
  const { name: name2, attributes } = node;
4884
- normalizeBody(state, tag.get("body").get("body"));
4885
- normalizeBody(state, tag.get("attributeTags"));
4880
+ normalizeBody(tag.get("body").get("body"));
4881
+ normalizeBody(tag.get("attributeTags"));
4886
4882
  if (node.var) {
4887
4883
  const insertions = getAssignmentInsertions(node.var);
4888
4884
  if (insertions) {
4889
- state.crawl = true;
4890
4885
  tag.insertAfter(insertions);
4891
4886
  }
4892
4887
  }
@@ -4896,14 +4891,12 @@ function normalizeTag(state, tag) {
4896
4891
  insertions = getAssignmentInsertions(param, insertions);
4897
4892
  }
4898
4893
  if (insertions) {
4899
- state.crawl = true;
4900
4894
  node.body.body = [...insertions, ...node.body.body];
4901
4895
  }
4902
4896
  }
4903
4897
  if (name2.type === "StringLiteral") {
4904
4898
  const tagName = name2.value;
4905
4899
  if (tag.scope.getBinding(tagName) && TAG_NAME_IDENTIFIER_REG.test(tagName)) {
4906
- state.crawl = true;
4907
4900
  node.name = withPreviousLocation(import_compiler26.types.identifier(tagName), name2);
4908
4901
  } else {
4909
4902
  switch (tagName) {
@@ -4916,7 +4909,6 @@ function normalizeTag(state, tag) {
4916
4909
  for (let i = 0; i < attributes.length; i++) {
4917
4910
  const attr = attributes[i];
4918
4911
  if (import_compiler26.types.isMarkoAttribute(attr) && attr.bound) {
4919
- state.crawl = true;
4920
4912
  attr.bound = false;
4921
4913
  attributes.splice(++i, 0, getChangeHandler(tag, attr));
4922
4914
  }
@@ -4978,7 +4970,6 @@ function getChangeHandler(tag, attr) {
4978
4970
  } else {
4979
4971
  markoRoot.unshiftContainer("body", changeHandlerConst);
4980
4972
  }
4981
- markoRoot.scope.crawl();
4982
4973
  return import_compiler26.types.markoAttribute(
4983
4974
  changeAttrName,
4984
4975
  withPreviousLocation(import_compiler26.types.identifier(changeHandlerId), attr.value)
@@ -11653,6 +11644,7 @@ var referenced_identifier_default = {
11653
11644
  };
11654
11645
 
11655
11646
  // src/translator/visitors/scriptlet.ts
11647
+ var import_compiler59 = require("@marko/compiler");
11656
11648
  var import_babel_utils47 = require("@marko/compiler/babel-utils");
11657
11649
  var scriptlet_default = {
11658
11650
  analyze(scriptlet) {
@@ -11675,7 +11667,21 @@ var scriptlet_default = {
11675
11667
  const { node } = scriptlet;
11676
11668
  const isHTML = isOutputHTML();
11677
11669
  if (node.target && node.target !== (isHTML ? "server" : "client")) {
11678
- scriptlet.remove();
11670
+ const ids = Object.keys(scriptlet.getOuterBindingIdentifiers());
11671
+ const decl = ids.length && import_compiler59.types.variableDeclaration(
11672
+ "var",
11673
+ ids.map((key) => import_compiler59.types.variableDeclarator(import_compiler59.types.identifier(key)))
11674
+ );
11675
+ if (decl) {
11676
+ if (isHTML) {
11677
+ scriptlet.node.target = null;
11678
+ scriptlet.node.body = [decl];
11679
+ } else {
11680
+ scriptlet.replaceWith(decl);
11681
+ }
11682
+ } else {
11683
+ scriptlet.remove();
11684
+ }
11679
11685
  return;
11680
11686
  }
11681
11687
  if (isHTML) {
@@ -11688,11 +11694,11 @@ var scriptlet_default = {
11688
11694
  };
11689
11695
 
11690
11696
  // src/translator/visitors/tag/index.ts
11691
- var import_compiler62 = require("@marko/compiler");
11697
+ var import_compiler63 = require("@marko/compiler");
11692
11698
  var import_babel_utils51 = require("@marko/compiler/babel-utils");
11693
11699
 
11694
11700
  // src/translator/visitors/tag/attribute-tag.ts
11695
- var import_compiler59 = require("@marko/compiler");
11701
+ var import_compiler60 = require("@marko/compiler");
11696
11702
  var import_babel_utils48 = require("@marko/compiler/babel-utils");
11697
11703
  var attribute_tag_default = {
11698
11704
  analyze: {
@@ -11725,7 +11731,7 @@ var attribute_tag_default = {
11725
11731
  };
11726
11732
 
11727
11733
  // src/translator/visitors/tag/custom-tag.ts
11728
- var import_compiler60 = require("@marko/compiler");
11734
+ var import_compiler61 = require("@marko/compiler");
11729
11735
  var import_babel_utils49 = require("@marko/compiler/babel-utils");
11730
11736
  var import_path4 = __toESM(require("path"));
11731
11737
  var custom_tag_default = {
@@ -11779,9 +11785,9 @@ function translateHTML(tag) {
11779
11785
  const childProgram = (0, import_babel_utils49.loadFileForTag)(tag).ast.program;
11780
11786
  const childExtra = childProgram.extra;
11781
11787
  let tagIdentifier;
11782
- if (import_compiler60.types.isStringLiteral(node.name)) {
11788
+ if (import_compiler61.types.isStringLiteral(node.name)) {
11783
11789
  const relativePath = getTagRelativePath(tag);
11784
- tagIdentifier = isCircularRequest(tag.hub.file, relativePath) ? import_compiler60.types.identifier(getTemplateContentName()) : (0, import_babel_utils49.importDefault)(tag.hub.file, relativePath, getTagName(tag));
11790
+ tagIdentifier = isCircularRequest(tag.hub.file, relativePath) ? import_compiler61.types.identifier(getTemplateContentName()) : (0, import_babel_utils49.importDefault)(tag.hub.file, relativePath, getTagName(tag));
11785
11791
  } else {
11786
11792
  tagIdentifier = node.name;
11787
11793
  }
@@ -11802,7 +11808,7 @@ function translateDOM(tag) {
11802
11808
  const childExtra = childFile.ast.program.extra;
11803
11809
  const childExports = childExtra.domExports;
11804
11810
  const childSection = childExtra.section;
11805
- const tagName = import_compiler60.types.isIdentifier(node.name) ? node.name.name : import_compiler60.types.isStringLiteral(node.name) ? node.name.value : "tag";
11811
+ const tagName = import_compiler61.types.isIdentifier(node.name) ? node.name.name : import_compiler61.types.isStringLiteral(node.name) ? node.name.value : "tag";
11806
11812
  if (programSection === childSection) {
11807
11813
  knownTagTranslateDOM(
11808
11814
  tag,
@@ -11813,16 +11819,16 @@ function translateDOM(tag) {
11813
11819
  "render",
11814
11820
  section,
11815
11821
  void 0,
11816
- import_compiler60.types.expressionStatement(
11817
- import_compiler60.types.callExpression(import_compiler60.types.identifier(childExports.setup), [
11822
+ import_compiler61.types.expressionStatement(
11823
+ import_compiler61.types.callExpression(import_compiler61.types.identifier(childExports.setup), [
11818
11824
  createScopeReadExpression(childBinding, section)
11819
11825
  ])
11820
11826
  )
11821
11827
  );
11822
11828
  }
11823
11829
  );
11824
- write`${import_compiler60.types.identifier(childExports.template)}`;
11825
- injectWalks(tag, tagName, import_compiler60.types.identifier(childExports.walks));
11830
+ write`${import_compiler61.types.identifier(childExports.template)}`;
11831
+ injectWalks(tag, tagName, import_compiler61.types.identifier(childExports.walks));
11826
11832
  } else {
11827
11833
  knownTagTranslateDOM(
11828
11834
  tag,
@@ -11838,8 +11844,8 @@ function translateDOM(tag) {
11838
11844
  "render",
11839
11845
  section,
11840
11846
  void 0,
11841
- import_compiler60.types.expressionStatement(
11842
- import_compiler60.types.callExpression(
11847
+ import_compiler61.types.expressionStatement(
11848
+ import_compiler61.types.callExpression(
11843
11849
  importOrSelfReferenceName(
11844
11850
  file,
11845
11851
  relativePath,
@@ -11867,7 +11873,7 @@ function getTagRelativePath(tag) {
11867
11873
  hub: { file }
11868
11874
  } = tag;
11869
11875
  let relativePath;
11870
- if (import_compiler60.types.isStringLiteral(node.name)) {
11876
+ if (import_compiler61.types.isStringLiteral(node.name)) {
11871
11877
  const template = (0, import_babel_utils49.getTagTemplate)(tag);
11872
11878
  relativePath = template && (0, import_babel_utils49.resolveRelativePath)(file, template);
11873
11879
  } else if (node.extra?.tagNameImported) {
@@ -11888,7 +11894,7 @@ function getTagRelativePath(tag) {
11888
11894
  }
11889
11895
  function importOrSelfReferenceName(file, request, name2, nameHint) {
11890
11896
  if (isCircularRequest(file, request)) {
11891
- return import_compiler60.types.identifier(name2);
11897
+ return import_compiler61.types.identifier(name2);
11892
11898
  }
11893
11899
  return (0, import_babel_utils49.importNamed)(file, request, name2, nameHint);
11894
11900
  }
@@ -11898,7 +11904,7 @@ function isCircularRequest(file, request) {
11898
11904
  }
11899
11905
 
11900
11906
  // src/translator/visitors/tag/dynamic-tag.ts
11901
- var import_compiler61 = require("@marko/compiler");
11907
+ var import_compiler62 = require("@marko/compiler");
11902
11908
  var import_babel_utils50 = require("@marko/compiler/babel-utils");
11903
11909
  var kDOMBinding3 = Symbol("dynamic tag dom binding");
11904
11910
  var kChildOffsetScopeBinding2 = Symbol("custom tag scope offset");
@@ -11931,7 +11937,7 @@ var dynamic_tag_default = {
11931
11937
  tagSection
11932
11938
  );
11933
11939
  if (hasVar || tag.node.attributes.some(
11934
- (attr) => import_compiler61.types.isMarkoSpreadAttribute(attr) || isEventOrChangeHandler(attr.name)
11940
+ (attr) => import_compiler62.types.isMarkoSpreadAttribute(attr) || isEventOrChangeHandler(attr.name)
11935
11941
  )) {
11936
11942
  (0, import_babel_utils50.getProgram)().node.extra.isInteractive = true;
11937
11943
  }
@@ -11971,7 +11977,7 @@ var dynamic_tag_default = {
11971
11977
  if (isOutputHTML()) {
11972
11978
  knownTagTranslateHTML(
11973
11979
  tag,
11974
- import_compiler61.types.memberExpression(tag.node.name, import_compiler61.types.identifier("content")),
11980
+ import_compiler62.types.memberExpression(tag.node.name, import_compiler62.types.identifier("content")),
11975
11981
  definedBodySection,
11976
11982
  propTree
11977
11983
  );
@@ -11988,9 +11994,9 @@ var dynamic_tag_default = {
11988
11994
  "render",
11989
11995
  section,
11990
11996
  void 0,
11991
- import_compiler61.types.expressionStatement(
11992
- import_compiler61.types.callExpression(
11993
- import_compiler61.types.memberExpression(signal.identifier, import_compiler61.types.identifier("_")),
11997
+ import_compiler62.types.expressionStatement(
11998
+ import_compiler62.types.callExpression(
11999
+ import_compiler62.types.memberExpression(signal.identifier, import_compiler62.types.identifier("_")),
11994
12000
  [
11995
12001
  createScopeReadExpression(childBinding, section),
11996
12002
  getScopeExpression(section, definedBodySection.parent)
@@ -12015,7 +12021,7 @@ var dynamic_tag_default = {
12015
12021
  const nodeBinding = tagExtra[kDOMBinding3];
12016
12022
  const isClassAPI = tagExtra.featureType === "class";
12017
12023
  let tagExpression = node.name;
12018
- if (import_compiler61.types.isStringLiteral(tagExpression)) {
12024
+ if (import_compiler62.types.isStringLiteral(tagExpression)) {
12019
12025
  tagExpression = (0, import_babel_utils50.importDefault)(
12020
12026
  tag.hub.file,
12021
12027
  getTagRelativePath(tag),
@@ -12025,14 +12031,14 @@ var dynamic_tag_default = {
12025
12031
  if (isClassAPI) {
12026
12032
  if (isOutputHTML()) {
12027
12033
  (0, import_babel_utils50.getProgram)().node.body.push(
12028
- import_compiler61.types.markoScriptlet(
12034
+ import_compiler62.types.markoScriptlet(
12029
12035
  [
12030
- import_compiler61.types.expressionStatement(
12031
- import_compiler61.types.callExpression(
12036
+ import_compiler62.types.expressionStatement(
12037
+ import_compiler62.types.callExpression(
12032
12038
  (0, import_babel_utils50.importNamed)(tag.hub.file, getCompatRuntimeFile(), "s"),
12033
12039
  [
12034
- import_compiler61.types.identifier(tagExpression.name),
12035
- import_compiler61.types.stringLiteral((0, import_babel_utils50.loadFileForTag)(tag).metadata.marko.id)
12040
+ import_compiler62.types.identifier(tagExpression.name),
12041
+ import_compiler62.types.stringLiteral((0, import_babel_utils50.loadFileForTag)(tag).metadata.marko.id)
12036
12042
  ]
12037
12043
  )
12038
12044
  )
@@ -12042,11 +12048,11 @@ var dynamic_tag_default = {
12042
12048
  );
12043
12049
  } else {
12044
12050
  (0, import_babel_utils50.getProgram)().node.body.push(
12045
- import_compiler61.types.expressionStatement(
12051
+ import_compiler62.types.expressionStatement(
12046
12052
  callRuntime(
12047
12053
  "_resume",
12048
- import_compiler61.types.stringLiteral((0, import_babel_utils50.loadFileForTag)(tag).metadata.marko.id),
12049
- import_compiler61.types.identifier(tagExpression.name)
12054
+ import_compiler62.types.stringLiteral((0, import_babel_utils50.loadFileForTag)(tag).metadata.marko.id),
12055
+ import_compiler62.types.identifier(tagExpression.name)
12050
12056
  )
12051
12057
  )
12052
12058
  );
@@ -12089,9 +12095,9 @@ var dynamic_tag_default = {
12089
12095
  getScopeIdIdentifier(tagSection),
12090
12096
  getScopeAccessorLiteral(nodeBinding),
12091
12097
  tagExpression,
12092
- import_compiler61.types.arrayExpression(args),
12093
- import_compiler61.types.numericLiteral(0),
12094
- import_compiler61.types.numericLiteral(1),
12098
+ import_compiler62.types.arrayExpression(args),
12099
+ import_compiler62.types.numericLiteral(0),
12100
+ import_compiler62.types.numericLiteral(1),
12095
12101
  serializeArg
12096
12102
  ) : callRuntime(
12097
12103
  "_dynamic_tag",
@@ -12099,8 +12105,8 @@ var dynamic_tag_default = {
12099
12105
  getScopeAccessorLiteral(nodeBinding),
12100
12106
  tagExpression,
12101
12107
  args[0],
12102
- args[1] || (serializeArg ? import_compiler61.types.numericLiteral(0) : void 0),
12103
- serializeArg ? import_compiler61.types.numericLiteral(0) : void 0,
12108
+ args[1] || (serializeArg ? import_compiler62.types.numericLiteral(0) : void 0),
12109
+ serializeArg ? import_compiler62.types.numericLiteral(0) : void 0,
12104
12110
  serializeArg
12105
12111
  );
12106
12112
  if (node.var) {
@@ -12108,18 +12114,18 @@ var dynamic_tag_default = {
12108
12114
  tag.get("name").toString() + "_scope"
12109
12115
  );
12110
12116
  statements.push(
12111
- import_compiler61.types.variableDeclaration("const", [
12112
- import_compiler61.types.variableDeclarator(
12117
+ import_compiler62.types.variableDeclaration("const", [
12118
+ import_compiler62.types.variableDeclarator(
12113
12119
  dynamicScopeIdentifier,
12114
12120
  callRuntime("_peek_scope_id")
12115
12121
  )
12116
12122
  ])
12117
12123
  );
12118
12124
  statements.push(
12119
- import_compiler61.types.variableDeclaration("let", [
12120
- import_compiler61.types.variableDeclarator(node.var, dynamicTagExpr)
12125
+ import_compiler62.types.variableDeclaration("let", [
12126
+ import_compiler62.types.variableDeclarator(node.var, dynamicTagExpr)
12121
12127
  ]),
12122
- import_compiler61.types.expressionStatement(
12128
+ import_compiler62.types.expressionStatement(
12123
12129
  callRuntime(
12124
12130
  "_var",
12125
12131
  getScopeIdIdentifier(tagSection),
@@ -12127,7 +12133,7 @@ var dynamic_tag_default = {
12127
12133
  tag.node.extra[kChildOffsetScopeBinding2]
12128
12134
  ),
12129
12135
  dynamicScopeIdentifier,
12130
- import_compiler61.types.stringLiteral(
12136
+ import_compiler62.types.stringLiteral(
12131
12137
  getResumeRegisterId(
12132
12138
  tagSection,
12133
12139
  node.var.extra?.binding,
@@ -12139,7 +12145,7 @@ var dynamic_tag_default = {
12139
12145
  )
12140
12146
  );
12141
12147
  } else {
12142
- statements.push(import_compiler61.types.expressionStatement(dynamicTagExpr));
12148
+ statements.push(import_compiler62.types.expressionStatement(dynamicTagExpr));
12143
12149
  }
12144
12150
  for (const replacement of tag.replaceWithMultiple(statements)) {
12145
12151
  replacement.skip();
@@ -12158,9 +12164,9 @@ var dynamic_tag_default = {
12158
12164
  tagVarSignal.register = true;
12159
12165
  tagVarSignal.buildAssignment = (valueSection, value) => {
12160
12166
  const changeArgs = [
12161
- import_compiler61.types.memberExpression(
12167
+ import_compiler62.types.memberExpression(
12162
12168
  getScopeExpression(tagVarSignal.section, valueSection),
12163
- import_compiler61.types.stringLiteral(
12169
+ import_compiler62.types.stringLiteral(
12164
12170
  getAccessorPrefix().BranchScopes + getScopeAccessor(nodeBinding)
12165
12171
  ),
12166
12172
  true
@@ -12168,28 +12174,28 @@ var dynamic_tag_default = {
12168
12174
  value
12169
12175
  ];
12170
12176
  if (!isOptimize()) {
12171
- changeArgs.push(import_compiler61.types.stringLiteral(varBinding.name));
12177
+ changeArgs.push(import_compiler62.types.stringLiteral(varBinding.name));
12172
12178
  }
12173
- return import_compiler61.types.callExpression(importRuntime("_var_change"), changeArgs);
12179
+ return import_compiler62.types.callExpression(importRuntime("_var_change"), changeArgs);
12174
12180
  };
12175
12181
  }
12176
12182
  signal.build = () => {
12177
12183
  return callRuntime(
12178
12184
  "_dynamic_tag",
12179
12185
  getScopeAccessorLiteral(nodeBinding, true),
12180
- bodySection && import_compiler61.types.identifier(bodySection.name),
12181
- tagVarSignal ? import_compiler61.types.arrowFunctionExpression([], tagVarSignal.identifier) : void 0,
12182
- hasTagArgs && import_compiler61.types.numericLiteral(1)
12186
+ bodySection && import_compiler62.types.identifier(bodySection.name),
12187
+ tagVarSignal ? import_compiler62.types.arrowFunctionExpression([], tagVarSignal.identifier) : void 0,
12188
+ hasTagArgs && import_compiler62.types.numericLiteral(1)
12183
12189
  );
12184
12190
  };
12185
12191
  if (args.length) {
12186
- const argsOrInput = hasTagArgs ? import_compiler61.types.arrayExpression(args) : args[0];
12187
- if (!import_compiler61.types.isObjectExpression(argsOrInput) || argsOrInput.properties.length) {
12192
+ const argsOrInput = hasTagArgs ? import_compiler62.types.arrayExpression(args) : args[0];
12193
+ if (!import_compiler62.types.isObjectExpression(argsOrInput) || argsOrInput.properties.length) {
12188
12194
  signal.extraArgs = [
12189
- import_compiler61.types.arrowFunctionExpression(
12195
+ import_compiler62.types.arrowFunctionExpression(
12190
12196
  [],
12191
- statements.length ? import_compiler61.types.blockStatement(
12192
- statements.concat(import_compiler61.types.returnStatement(argsOrInput))
12197
+ statements.length ? import_compiler62.types.blockStatement(
12198
+ statements.concat(import_compiler62.types.returnStatement(argsOrInput))
12193
12199
  ) : argsOrInput
12194
12200
  )
12195
12201
  ];
@@ -12209,7 +12215,7 @@ function enableDynamicTagResume(tag) {
12209
12215
  if (attr.type === "MarkoSpreadAttribute" || attr.type === "MarkoAttribute" && isEventOrChangeHandler(attr.name)) {
12210
12216
  importedDynamicTagResume.add(program);
12211
12217
  program.body.push(
12212
- import_compiler61.types.expressionStatement(callRuntime("_resume_dynamic_tag"))
12218
+ import_compiler62.types.expressionStatement(callRuntime("_resume_dynamic_tag"))
12213
12219
  );
12214
12220
  return;
12215
12221
  }
@@ -12320,7 +12326,7 @@ var tag_default = {
12320
12326
  };
12321
12327
 
12322
12328
  // src/translator/visitors/text.ts
12323
- var import_compiler63 = require("@marko/compiler");
12329
+ var import_compiler64 = require("@marko/compiler");
12324
12330
  var text_default = {
12325
12331
  translate: {
12326
12332
  exit(text) {
@@ -1,4 +1,4 @@
1
- import type { types as t } from "@marko/compiler";
1
+ import { types as t } from "@marko/compiler";
2
2
  declare const _default: {
3
3
  analyze(this: unknown, scriptlet: t.NodePath<t.MarkoScriptlet>): void;
4
4
  translate: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.120",
3
+ "version": "6.0.121",
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.43",
51
+ "@marko/compiler": "^5.39.44",
52
52
  "csstype": "^3.1.3",
53
53
  "magic-string": "^0.30.17"
54
54
  },