@lark.js/mvc 0.0.4 → 0.0.6

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.
@@ -24,9 +24,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  mod
25
25
  ));
26
26
 
27
- // ../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js
27
+ // ../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js
28
28
  var require_lib = __commonJS({
29
- "../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js"(exports) {
29
+ "../../node_modules/.pnpm/@babel+parser@7.29.7/node_modules/@babel/parser/lib/index.js"(exports) {
30
30
  "use strict";
31
31
  Object.defineProperty(exports, "__esModule", {
32
32
  value: true
@@ -14601,8 +14601,8 @@ var require_lib = __commonJS({
14601
14601
 
14602
14602
  // src/compiler.ts
14603
14603
  var import_parser = __toESM(require_lib(), 1);
14604
- var SPLITTER = "";
14605
- var VIEW_ID_PLACEHOLDER = "";
14604
+ var SPLITTER = String.fromCharCode(30);
14605
+ var VIEW_ID_PLACEHOLDER = String.fromCharCode(31);
14606
14606
  function jsObjectToUrlParams(paramsStr) {
14607
14607
  const trimmed = paramsStr.trim();
14608
14608
  if (!/^[{[]/.test(trimmed) && /=/.test(trimmed)) {
@@ -14662,7 +14662,7 @@ function addLineMarkers(source) {
14662
14662
  if (parts.length > 1) {
14663
14663
  const reconstructed = parts.map((part, i) => {
14664
14664
  if (i === 0) return part;
14665
- return openTag + SPLITTER + ++lineNo;
14665
+ return openTag + SPLITTER + ++lineNo + part;
14666
14666
  }).join("");
14667
14667
  result.push(reconstructed);
14668
14668
  } else {
@@ -14798,7 +14798,7 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
14798
14798
  return `${debugPrefix}<%for(${forExpr}){%>`;
14799
14799
  }
14800
14800
  const tokens = code.split(/\s+/);
14801
- const keyword = tokens.shift();
14801
+ const keyword = tokens.shift() ?? "";
14802
14802
  switch (keyword) {
14803
14803
  case "if": {
14804
14804
  blockStack.push({ ctrl: "if", line: lineNo });
@@ -15022,13 +15022,9 @@ function compileToFunction(source, debug, file) {
15022
15022
  }
15023
15023
  const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
15024
15024
  funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
15025
- const atRule = hasAtRule ? `if(!$refFn){$refFn=(ref,v,k,f)=>{for(f=ref[$splitter];--f;)if(ref[k=$splitter+f]===v)return k;ref[k=$splitter+ref[$splitter]++]=v;return k;}}` : "";
15026
- const encode = `if(!$strSafe){let $entMap={'&':'amp','<':'lt','>':'gt','"':'#34','\\'':'#39','\`':'#96'},$entReg=/[&<>"'\`]/g,$entFn=m=>'&'+$entMap[m]+';';$strSafe=v=>''+(v==null?'':v);$encHtml=v=>$strSafe(v).replace($entReg,$entFn)}`;
15027
- const encodeURIMore = `if(!$encUri){let $uriMap={'!':'%21','\\'':'%27','(':'%28',')':'%29','*':'%2A'},$uriFn=m=>$uriMap[m],$uriReg=/[!')(*]/g;$encUri=v=>encodeURIComponent($strSafe(v)).replace($uriReg,$uriFn)}`;
15028
- const encodeQuote = `if(!$encQuote){let $qReg=/['"\\\\]/g;$encQuote=v=>$strSafe(v).replace($qReg,'\\\\$&')}`;
15025
+ void hasAtRule;
15029
15026
  const refFallback = "if(!$refAlt)$refAlt=$data;";
15030
- const fns = `${refFallback}${encode}${encodeURIMore}${encodeQuote}${atRule};`;
15031
- const fullSource = `${fns}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
15027
+ const fullSource = `${refFallback}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
15032
15028
  return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
15033
15029
  }
15034
15030
  function compileTemplate(source, options = {}) {
@@ -15040,15 +15036,12 @@ function compileTemplate(source, options = {}) {
15040
15036
  const funcBody = compileToFunction(finalSource, debug, file);
15041
15037
  const varDeclarations = globalVars.map((key) => `,${key}=$data.${key}`).join("");
15042
15038
  const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
15043
- return `export default function(data, selfId, refData) {
15039
+ return `import { encHtml as __larkEncHtml, strSafe as __larkStrSafe, encUri as __larkEncUri, encQuote as __larkEncQuote, refFn as __larkRefFn } from "@lark.js/mvc/runtime";
15040
+ export default function(data, viewId, refData) {
15044
15041
  let $data = data || {},
15045
- $viewId = selfId || '';
15042
+ $viewId = viewId || '';
15046
15043
  return (${funcWithVars})($data, $viewId, refData,
15047
- /* $encHtml */ v => String(v == null ? '' : v).replace(/[&<>"'\`]/g, m => '&' + ({'&':'amp','<':'lt','>':'gt','"':'#34',"'":'#39','\`':'#96'})[m] + ';'),
15048
- /* $strSafe */ v => String(v == null ? '' : v),
15049
- /* $encUri */ null,
15050
- /* $refFn */ null,
15051
- /* $encQuote */ null
15044
+ __larkEncHtml, __larkStrSafe, __larkEncUri, __larkRefFn, __larkEncQuote
15052
15045
  );
15053
15046
  }`;
15054
15047
  }
@@ -15062,7 +15055,7 @@ function extractGlobalVars(source) {
15062
15055
  const htmlStore = {};
15063
15056
  let htmlIndex = 0;
15064
15057
  let lastIndex = 0;
15065
- const htmlKey = "";
15058
+ const htmlKey = String.fromCharCode(5);
15066
15059
  template.replace(
15067
15060
  templateCmdRegExp,
15068
15061
  (match, operate, content, offset) => {
@@ -15173,31 +15166,37 @@ function walkAst(ast, visitors) {
15173
15166
  if (visitors[type]) {
15174
15167
  visitors[type](node);
15175
15168
  }
15169
+ const bag = node;
15176
15170
  for (const key of Object.keys(node)) {
15177
15171
  if (key === "type" || key === "start" || key === "end" || key === "loc" || key === "range")
15178
15172
  continue;
15179
- if (type === "MemberExpression" && key === "property" && !node.computed)
15180
- continue;
15181
- if (type === "ObjectProperty" && key === "key" && !node.computed) {
15182
- continue;
15173
+ if (type === "MemberExpression" && key === "property") {
15174
+ const me = node;
15175
+ if (!me.computed) continue;
15183
15176
  }
15184
- if (type === "ObjectMethod" && key === "key" && !node.computed) {
15185
- continue;
15177
+ if (type === "ObjectProperty" && key === "key") {
15178
+ const op = node;
15179
+ if (!op.computed) continue;
15186
15180
  }
15187
- const child = node[key];
15181
+ if (type === "ObjectMethod" && key === "key") {
15182
+ const om = node;
15183
+ if (!om.computed) continue;
15184
+ }
15185
+ const child = bag[key];
15188
15186
  if (Array.isArray(child)) {
15189
15187
  for (const item of child) {
15190
- if (item && typeof item === "object" && typeof item.type === "string") {
15191
- visit(item);
15192
- }
15188
+ if (isAstNode(item)) visit(item);
15193
15189
  }
15194
- } else if (child && typeof child === "object" && typeof child.type === "string") {
15190
+ } else if (isAstNode(child)) {
15195
15191
  visit(child);
15196
15192
  }
15197
15193
  }
15198
15194
  }
15199
15195
  visit(ast);
15200
15196
  }
15197
+ function isAstNode(v) {
15198
+ return !!v && typeof v === "object" && typeof v.type === "string";
15199
+ }
15201
15200
  var BUILTIN_GLOBALS = {
15202
15201
  // ─── Template runtime helpers (injected by compileToFunction) ───────
15203
15202
  //