marko 6.0.0-next.3.25 → 6.0.0-next.3.26

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.
@@ -966,38 +966,13 @@ function createSectionState(key, init) {
966
966
  // src/translator/util/tag-name-type.ts
967
967
  var import_compiler5 = require("@marko/compiler");
968
968
  var import_babel_utils6 = require("@marko/compiler/babel-utils");
969
-
970
- // src/translator/util/with-previous-location.ts
971
- function withPreviousLocation(newNode, originalNode) {
972
- newNode.start = originalNode.start;
973
- newNode.loc = originalNode.loc;
974
- newNode.end = originalNode.end;
975
- return newNode;
976
- }
977
-
978
- // src/translator/util/tag-name-type.ts
979
969
  var MARKO_FILE_REG = /^<.*>$|\.marko$/;
980
- var TAG_NAME_IDENTIFIER_REG = /^[A-Z][a-zA-Z0-9_$]*$/;
981
970
  function analyzeTagNameType(tag) {
982
971
  const extra = tag.node.extra ??= {};
983
972
  if (extra.tagNameType === void 0) {
984
973
  const name2 = tag.get("name");
985
974
  if (name2.isStringLiteral()) {
986
975
  extra.tagNameType = name2.node.value[0] === "@" ? 3 /* AttributeTag */ : (0, import_babel_utils6.isNativeTag)(tag) ? 0 /* NativeTag */ : 1 /* CustomTag */;
987
- if (extra.tagNameType === 1 /* CustomTag */) {
988
- const bindingName = name2.node.value;
989
- const bindingIdentifier = tag.scope.getBinding(bindingName)?.identifier;
990
- if (bindingIdentifier && TAG_NAME_IDENTIFIER_REG.test(bindingIdentifier.name)) {
991
- const tagIdentifier = withPreviousLocation(
992
- import_compiler5.types.identifier(bindingName),
993
- name2.node
994
- );
995
- tagIdentifier.extra = {
996
- referencedBindings: bindingIdentifier.extra?.binding
997
- };
998
- analyzeExpressionTagName(name2.replaceWith(tagIdentifier)[0], extra);
999
- }
1000
- }
1001
976
  extra.tagNameNullable = extra.tagNameNullable = false;
1002
977
  } else {
1003
978
  analyzeExpressionTagName(name2, extra);
@@ -2045,7 +2020,7 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
2045
2020
  buildSignalIntersections(signal)
2046
2021
  );
2047
2022
  };
2048
- } else if (referencedBindings.section !== section) {
2023
+ } else if (referencedBindings.section !== section && bindingUtil.find(section.closures, referencedBindings)) {
2049
2024
  getSignal(referencedBindings.section, referencedBindings).closures.set(
2050
2025
  section,
2051
2026
  signal
@@ -2066,7 +2041,6 @@ function getSignal(section, referencedBindings, name2 = generateSignalName(refer
2066
2041
  const intersection = buildSignalIntersections(signal);
2067
2042
  return isDynamicClosure ? callRuntime(
2068
2043
  "dynamicClosure",
2069
- getScopeAccessorLiteral(referencedBindings),
2070
2044
  render,
2071
2045
  isImmediateOwner ? null : import_compiler17.types.arrowFunctionExpression([scopeIdentifier], ownerScope),
2072
2046
  intersection
@@ -3219,6 +3193,14 @@ function isFunctionExpression(path5) {
3219
3193
  }
3220
3194
  }
3221
3195
 
3196
+ // src/translator/util/with-previous-location.ts
3197
+ function withPreviousLocation(newNode, originalNode) {
3198
+ newNode.start = originalNode.start;
3199
+ newNode.loc = originalNode.loc;
3200
+ newNode.end = originalNode.end;
3201
+ return newNode;
3202
+ }
3203
+
3222
3204
  // src/translator/util/references.ts
3223
3205
  var [getBindings] = createProgramState(() => /* @__PURE__ */ new Set());
3224
3206
  var [getNextBindingId, setNextBindingId] = createProgramState(() => 0);
@@ -9199,28 +9181,42 @@ var dynamic_tag_default = {
9199
9181
  };
9200
9182
 
9201
9183
  // src/translator/visitors/tag/index.ts
9184
+ var TAG_NAME_IDENTIFIER_REG = /^[A-Z][a-zA-Z0-9_$]*$/;
9202
9185
  var tag_default = {
9203
9186
  transform: {
9204
9187
  enter(tag) {
9205
- const attrs2 = tag.get("attributes");
9206
- for (let i = 0; i < attrs2.length; i++) {
9207
- const attr2 = attrs2[i];
9208
- if (import_compiler53.types.isMarkoAttribute(attr2.node) && attr2.node.bound) {
9209
- attr2.node.bound = false;
9188
+ const { node } = tag;
9189
+ const { name: name2, attributes } = tag.node;
9190
+ let crawl = false;
9191
+ if (import_compiler53.types.isStringLiteral(name2)) {
9192
+ const tagName = name2.value;
9193
+ if (tag.scope.getBinding(tagName) && TAG_NAME_IDENTIFIER_REG.test(tagName)) {
9194
+ node.name = withPreviousLocation(import_compiler53.types.identifier(tagName), name2);
9195
+ crawl = true;
9196
+ }
9197
+ }
9198
+ for (let i = 0; i < attributes.length; i++) {
9199
+ const attr2 = attributes[i];
9200
+ if (import_compiler53.types.isMarkoAttribute(attr2) && attr2.bound) {
9201
+ attr2.bound = false;
9210
9202
  const changeValue = getChangeHandler(tag, attr2);
9211
9203
  if (changeValue === null) {
9212
- throw attr2.buildCodeFrameError(
9204
+ throw tag.hub.buildError(
9205
+ attr2,
9213
9206
  "Attributes may only be bound to identifiers or member expressions"
9214
9207
  );
9215
9208
  }
9216
- tag.node.attributes.splice(
9217
- i + 1,
9209
+ attributes.splice(
9210
+ ++i,
9218
9211
  0,
9219
- import_compiler53.types.markoAttribute(attr2.node.name + "Change", changeValue)
9212
+ import_compiler53.types.markoAttribute(attr2.name + "Change", changeValue)
9220
9213
  );
9221
- tag.scope.crawl();
9214
+ crawl = true;
9222
9215
  }
9223
9216
  }
9217
+ if (crawl) {
9218
+ tag.scope.crawl();
9219
+ }
9224
9220
  }
9225
9221
  },
9226
9222
  analyze: {
@@ -9334,29 +9330,27 @@ var tag_default = {
9334
9330
  }
9335
9331
  };
9336
9332
  function getChangeHandler(tag, attr2) {
9337
- if (import_compiler53.types.isIdentifier(attr2.node.value)) {
9338
- const valueId = tag.scope.generateUidIdentifier(
9339
- "new_" + attr2.node.value.name
9340
- );
9333
+ if (import_compiler53.types.isIdentifier(attr2.value)) {
9334
+ const valueId = tag.scope.generateUidIdentifier("new_" + attr2.value.name);
9341
9335
  return import_compiler53.types.arrowFunctionExpression(
9342
9336
  [valueId],
9343
9337
  import_compiler53.types.blockStatement([
9344
9338
  import_compiler53.types.expressionStatement(
9345
- import_compiler53.types.assignmentExpression("=", import_compiler53.types.cloneNode(attr2.node.value), valueId)
9339
+ import_compiler53.types.assignmentExpression("=", import_compiler53.types.cloneNode(attr2.value), valueId)
9346
9340
  )
9347
9341
  ])
9348
9342
  );
9349
- } else if (import_compiler53.types.isMemberExpression(attr2.node.value)) {
9350
- const prop = attr2.node.value.property;
9343
+ } else if (import_compiler53.types.isMemberExpression(attr2.value)) {
9344
+ const prop = attr2.value.property;
9351
9345
  if (import_compiler53.types.isPrivateName(prop)) return null;
9352
9346
  if (import_compiler53.types.isIdentifier(prop)) {
9353
9347
  return import_compiler53.types.memberExpression(
9354
- import_compiler53.types.cloneNode(attr2.node.value.object),
9348
+ import_compiler53.types.cloneNode(attr2.value.object),
9355
9349
  import_compiler53.types.identifier(prop.name + "Change")
9356
9350
  );
9357
9351
  } else {
9358
9352
  return import_compiler53.types.memberExpression(
9359
- import_compiler53.types.cloneNode(attr2.node.value.object),
9353
+ import_compiler53.types.cloneNode(attr2.value.object),
9360
9354
  import_compiler53.types.binaryExpression("+", import_compiler53.types.cloneNode(prop), import_compiler53.types.stringLiteral("Change")),
9361
9355
  true
9362
9356
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.0-next.3.25",
3
+ "version": "6.0.0-next.3.26",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",