@wevu/compiler 6.15.1 → 6.15.4

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 (2) hide show
  1. package/dist/index.mjs +30 -15
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -4942,10 +4942,22 @@ function withSlotProps(context, mapping, fn) {
4942
4942
  }
4943
4943
  }
4944
4944
  const IDENTIFIER_RE$3 = /^[A-Z_$][\w$]*$/i;
4945
+ const BIND_SHORTHAND_ARG_RE = /^[A-Z_$][\w$]*(?:-[A-Z_$][\w$]*)*$/i;
4945
4946
  const BACKSLASH_RE$2 = /\\/g;
4946
4947
  const SINGLE_QUOTE_RE$2 = /'/g;
4947
4948
  const CR_RE$1 = /\r/g;
4948
4949
  const LF_RE$1 = /\n/g;
4950
+ function camelizeBindShorthandArg(value) {
4951
+ return value.replace(/-([\w$])/g, (_, char) => char.toUpperCase());
4952
+ }
4953
+ function getBindDirectiveExpression(node) {
4954
+ const rawExp = node.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? node.exp.content : "";
4955
+ if (rawExp) return rawExp;
4956
+ if (node.name !== "bind" || node.arg?.type !== NodeTypes.SIMPLE_EXPRESSION || !node.arg.isStatic) return "";
4957
+ const rawArg = node.arg.content.trim();
4958
+ if (!rawArg || !BIND_SHORTHAND_ARG_RE.test(rawArg)) return "";
4959
+ return camelizeBindShorthandArg(rawArg);
4960
+ }
4949
4961
  function collectScopePropMapping(context) {
4950
4962
  const mapping = {};
4951
4963
  if (!context.slotMultipleInstance) return mapping;
@@ -4955,15 +4967,15 @@ function collectScopePropMapping(context) {
4955
4967
  }
4956
4968
  return mapping;
4957
4969
  }
4970
+ function toWxmlStringLiteral$1(value) {
4971
+ return `'${value.replace(BACKSLASH_RE$2, "\\\\").replace(SINGLE_QUOTE_RE$2, "\\'").replace(CR_RE$1, "\\r").replace(LF_RE$1, "\\n")}'`;
4972
+ }
4958
4973
  function buildScopePropsExpression(context) {
4959
4974
  const mapping = collectScopePropMapping(context);
4960
4975
  const keys = Object.keys(mapping);
4961
4976
  if (!keys.length) return null;
4962
4977
  return `[${keys.map((key) => `${toWxmlStringLiteral$1(key)},${key}`).join(",")}]`;
4963
4978
  }
4964
- function toWxmlStringLiteral$1(value) {
4965
- return `'${value.replace(BACKSLASH_RE$2, "\\\\").replace(SINGLE_QUOTE_RE$2, "\\'").replace(CR_RE$1, "\\r").replace(LF_RE$1, "\\n")}'`;
4966
- }
4967
4979
  function hashString(input) {
4968
4980
  let hash = 0;
4969
4981
  for (let i = 0; i < input.length; i++) {
@@ -5735,11 +5747,10 @@ const SIMPLE_MEMBER_PATH_RE = /^[A-Z_$][\w$]*(?:\.[A-Z_$][\w$]*)*$/i;
5735
5747
  const isSimpleIdentifier = (value) => SIMPLE_IDENTIFIER_RE$1.test(value);
5736
5748
  const isSimpleMemberPath = (value) => SIMPLE_MEMBER_PATH_RE.test(value);
5737
5749
  function transformBindDirective(node, context, forInfo) {
5738
- const { exp, arg } = node;
5750
+ const { arg } = node;
5739
5751
  if (!arg) return null;
5740
5752
  const argValue = arg.type === NodeTypes.SIMPLE_EXPRESSION ? arg.content : "";
5741
- if (!exp) return null;
5742
- const rawExpValue = exp.type === NodeTypes.SIMPLE_EXPRESSION ? exp.content : "";
5753
+ const rawExpValue = getBindDirectiveExpression(node);
5743
5754
  if (!rawExpValue) return null;
5744
5755
  if (argValue === "key") {
5745
5756
  const expValue = normalizeWxmlExpressionWithContext(rawExpValue, context);
@@ -6013,7 +6024,7 @@ function collectElementAttributes(node, context, options) {
6013
6024
  if (prop.type === NodeTypes.DIRECTIVE) {
6014
6025
  if (options?.skipSlotDirective && prop.name === "slot") continue;
6015
6026
  if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "ref") {
6016
- const rawExp = prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : "";
6027
+ const rawExp = getBindDirectiveExpression(prop);
6017
6028
  if (rawExp) {
6018
6029
  const expAst = normalizeJsExpressionWithContext(rawExp, context, { hint: "ref 绑定" });
6019
6030
  if (expAst) templateRef = { expAst };
@@ -6025,12 +6036,12 @@ function collectElementAttributes(node, context, options) {
6025
6036
  context.warnings.push("暂不支持动态 layout-host,已忽略该绑定。");
6026
6037
  continue;
6027
6038
  }
6028
- if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "class" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
6029
- dynamicClassExp = prop.exp.content;
6039
+ if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "class") {
6040
+ dynamicClassExp = getBindDirectiveExpression(prop) || void 0;
6030
6041
  continue;
6031
6042
  }
6032
- if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "style" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
6033
- dynamicStyleExp = prop.exp.content;
6043
+ if (prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "style") {
6044
+ dynamicStyleExp = getBindDirectiveExpression(prop) || void 0;
6034
6045
  continue;
6035
6046
  }
6036
6047
  if (prop.name === "show" && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION) {
@@ -6144,7 +6155,7 @@ function collectSlotBindingExpression(node, context) {
6144
6155
  if (prop.type === NodeTypes.ATTRIBUTE && prop.name === "name") continue;
6145
6156
  if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind") {
6146
6157
  if (prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION) {
6147
- const rawExpValue = prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : "";
6158
+ const rawExpValue = getBindDirectiveExpression(prop);
6148
6159
  if (prop.arg.content === "name") continue;
6149
6160
  if (rawExpValue) namedBindings.push({
6150
6161
  key: prop.arg.content,
@@ -6202,7 +6213,7 @@ function resolveSlotNameFromSlotElement(node) {
6202
6213
  }
6203
6214
  if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind") {
6204
6215
  if (prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === "name") {
6205
- const raw = prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION ? prop.exp.content : "";
6216
+ const raw = getBindDirectiveExpression(prop);
6206
6217
  if (raw) return {
6207
6218
  type: "dynamic",
6208
6219
  exp: raw
@@ -6441,11 +6452,15 @@ function transformComponentElement(node, context, transformNode) {
6441
6452
  break;
6442
6453
  }
6443
6454
  }
6444
- if (!isDirective || !isDirective.exp) {
6455
+ if (!isDirective) {
6456
+ context.warnings.push("<component> 未提供 :is 绑定,将按普通元素处理。");
6457
+ return transformNormalElement(node, context, transformNode);
6458
+ }
6459
+ const componentVar = getBindDirectiveExpression(isDirective);
6460
+ if (!componentVar) {
6445
6461
  context.warnings.push("<component> 未提供 :is 绑定,将按普通元素处理。");
6446
6462
  return transformNormalElement(node, context, transformNode);
6447
6463
  }
6448
- const componentVar = isDirective.exp.type === NodeTypes.SIMPLE_EXPRESSION ? isDirective.exp.content : "";
6449
6464
  const otherProps = node.props.filter((prop) => prop !== isDirective);
6450
6465
  const attrs = [];
6451
6466
  const slotDirective = findSlotDirective(node);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wevu/compiler",
3
3
  "type": "module",
4
- "version": "6.15.1",
4
+ "version": "6.15.4",
5
5
  "description": "wevu 编译器基础包,面向小程序模板的编译与转换",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -43,15 +43,15 @@
43
43
  "dependencies": {
44
44
  "@vue/compiler-core": "^3.5.32",
45
45
  "@vue/compiler-dom": "^3.5.32",
46
- "comment-json": "^4.6.2",
47
- "lru-cache": "^11.3.3",
46
+ "comment-json": "^5.0.0",
47
+ "lru-cache": "^11.3.5",
48
48
  "magic-string": "^0.30.21",
49
49
  "merge": "^2.1.1",
50
50
  "pathe": "^2.0.3",
51
51
  "vue": "^3.5.32",
52
- "@weapp-core/constants": "0.1.0",
52
+ "@weapp-core/constants": "^0.1.1",
53
53
  "@weapp-core/shared": "3.0.3",
54
- "@weapp-vite/ast": "6.15.1",
54
+ "@weapp-vite/ast": "6.15.4",
55
55
  "rolldown-require": "2.0.13"
56
56
  },
57
57
  "publishConfig": {