@lark.js/mvc 0.0.3 → 0.0.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.
- package/README.md +554 -786
- package/dist/{chunk-Y72BUONO.js → chunk-ANWA22AX.js} +94 -82
- package/dist/index.cjs +789 -649
- package/dist/index.d.cts +1672 -983
- package/dist/index.d.ts +1672 -983
- package/dist/index.js +788 -647
- package/dist/vite.cjs +94 -82
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +94 -82
- package/dist/webpack.js +1 -1
- package/package.json +1 -1
package/dist/webpack.cjs
CHANGED
|
@@ -14735,7 +14735,7 @@ function convertArtSyntax(source, debug) {
|
|
|
14735
14735
|
}
|
|
14736
14736
|
if (blockStack.length > 0) {
|
|
14737
14737
|
const unclosed = blockStack.map((b) => `"${b.ctrl}" at line ${b.line}`).join(", ");
|
|
14738
|
-
throw new Error(`[@lark/mvc error] unclosed block(s): ${unclosed}`);
|
|
14738
|
+
throw new Error(`[@lark.js/mvc error] unclosed block(s): ${unclosed}`);
|
|
14739
14739
|
}
|
|
14740
14740
|
return result.join("");
|
|
14741
14741
|
}
|
|
@@ -14829,12 +14829,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14829
14829
|
}
|
|
14830
14830
|
return `${debugPrefix}<%}else{%>`;
|
|
14831
14831
|
}
|
|
14832
|
-
case "
|
|
14833
|
-
blockStack.push({ ctrl: "
|
|
14832
|
+
case "forOf": {
|
|
14833
|
+
blockStack.push({ ctrl: "forOf", line: lineNo });
|
|
14834
14834
|
const object = tokens[0];
|
|
14835
14835
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14836
14836
|
throw new Error(
|
|
14837
|
-
`[@lark/mvc error] bad
|
|
14837
|
+
`[@lark.js/mvc error] bad forOf syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{forOf list as item [index]}}`
|
|
14838
14838
|
);
|
|
14839
14839
|
}
|
|
14840
14840
|
const restTokens = tokens.slice(2);
|
|
@@ -14856,12 +14856,12 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14856
14856
|
}
|
|
14857
14857
|
return `${debugPrefix}<%for(let ${index}=0${refExpr},${refObjCount}=${refObj}.length${lastCount};${index}<${refObjCount};${index}++){${firstAndLast}${valueDecl}%>`;
|
|
14858
14858
|
}
|
|
14859
|
-
case "
|
|
14860
|
-
blockStack.push({ ctrl: "
|
|
14859
|
+
case "forIn": {
|
|
14860
|
+
blockStack.push({ ctrl: "forIn", line: lineNo });
|
|
14861
14861
|
const object = tokens[0];
|
|
14862
14862
|
if (tokens.length > 1 && tokens[1] !== "as") {
|
|
14863
14863
|
throw new Error(
|
|
14864
|
-
`[@lark/mvc error] bad
|
|
14864
|
+
`[@lark.js/mvc error] bad forIn syntax: {{${code}}}. Expected "as" keyword, got "${tokens[1]}". Usage: {{for-in obj as val [key]}}`
|
|
14865
14865
|
);
|
|
14866
14866
|
}
|
|
14867
14867
|
const restTokens2 = tokens.slice(2);
|
|
@@ -14881,19 +14881,19 @@ function convertArtExpression(code, debug, lineNo, blockStack = []) {
|
|
|
14881
14881
|
case "set":
|
|
14882
14882
|
return `${debugPrefix}<%let ${tokens.join(" ")};%>`;
|
|
14883
14883
|
case "/if":
|
|
14884
|
-
case "/
|
|
14885
|
-
case "/
|
|
14884
|
+
case "/forOf":
|
|
14885
|
+
case "/forIn":
|
|
14886
14886
|
case "/for": {
|
|
14887
14887
|
const expectedCtrl = keyword.substring(1);
|
|
14888
14888
|
const last = blockStack.pop();
|
|
14889
14889
|
if (!last) {
|
|
14890
14890
|
throw new Error(
|
|
14891
|
-
`[@lark/mvc error] unexpected {{${code}}}: no matching open block`
|
|
14891
|
+
`[@lark.js/mvc error] unexpected {{${code}}}: no matching open block`
|
|
14892
14892
|
);
|
|
14893
14893
|
}
|
|
14894
14894
|
if (last.ctrl !== expectedCtrl) {
|
|
14895
14895
|
throw new Error(
|
|
14896
|
-
`[@lark/mvc error] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
14896
|
+
`[@lark.js/mvc error] unexpected {{${code}}}: expected {{/${last.ctrl}}} to close block opened at line ${last.line}`
|
|
14897
14897
|
);
|
|
14898
14898
|
}
|
|
14899
14899
|
return `${debugPrefix}<%}%>`;
|
|
@@ -14957,7 +14957,7 @@ function parseAsExpr(expr) {
|
|
|
14957
14957
|
function compileToFunction(source, debug, file) {
|
|
14958
14958
|
const matcher = /<%([@=!:])?([\s\S]*?)%>|$/g;
|
|
14959
14959
|
let index = 0;
|
|
14960
|
-
let funcSource = `$
|
|
14960
|
+
let funcSource = `$out+='`;
|
|
14961
14961
|
let hasAtRule = false;
|
|
14962
14962
|
const escapeSlashRegExp = /\\|'/g;
|
|
14963
14963
|
const escapeBreakReturnRegExp = /\r|\n/g;
|
|
@@ -14983,17 +14983,17 @@ function compileToFunction(source, debug, file) {
|
|
|
14983
14983
|
}
|
|
14984
14984
|
if (operate === "@") {
|
|
14985
14985
|
hasAtRule = true;
|
|
14986
|
-
funcSource += `'+($
|
|
14986
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',$refFn($refAlt,${content}))+'`;
|
|
14987
14987
|
} else if (operate === "=" || operate === ":") {
|
|
14988
|
-
funcSource += `'+($
|
|
14988
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',$encHtml(${content}))+'`;
|
|
14989
14989
|
} else if (operate === "!") {
|
|
14990
|
-
if (!content.startsWith("$
|
|
14991
|
-
content = `$
|
|
14990
|
+
if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
|
|
14991
|
+
content = `$strSafe(${content})`;
|
|
14992
14992
|
}
|
|
14993
|
-
funcSource += `'+($
|
|
14993
|
+
funcSource += `'+($dbgExpr='<%${operate + expr}%>',${content})+'`;
|
|
14994
14994
|
} else if (content) {
|
|
14995
14995
|
if (line > -1) {
|
|
14996
|
-
funcSource += `';$
|
|
14996
|
+
funcSource += `';$dbgLine=${line};$dbgArt='${art}';`;
|
|
14997
14997
|
content = "";
|
|
14998
14998
|
} else {
|
|
14999
14999
|
funcSource += `';`;
|
|
@@ -15002,19 +15002,19 @@ function compileToFunction(source, debug, file) {
|
|
|
15002
15002
|
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15003
15003
|
}
|
|
15004
15004
|
if (expr) {
|
|
15005
|
-
funcSource += `$
|
|
15005
|
+
funcSource += `$dbgExpr='<%${expr}%>';`;
|
|
15006
15006
|
}
|
|
15007
|
-
funcSource += content + `;$
|
|
15007
|
+
funcSource += content + `;$out+='`;
|
|
15008
15008
|
}
|
|
15009
15009
|
} else {
|
|
15010
15010
|
if (operate === "@") {
|
|
15011
15011
|
hasAtRule = true;
|
|
15012
|
-
funcSource += `'+$
|
|
15012
|
+
funcSource += `'+$refFn($refAlt,${content})+'`;
|
|
15013
15013
|
} else if (operate === "=" || operate === ":") {
|
|
15014
|
-
funcSource += `'+$
|
|
15014
|
+
funcSource += `'+$encHtml(${content})+'`;
|
|
15015
15015
|
} else if (operate === "!") {
|
|
15016
|
-
if (!content.startsWith("$
|
|
15017
|
-
content = `$
|
|
15016
|
+
if (!content.startsWith("$encUri(") || !content.endsWith(")")) {
|
|
15017
|
+
content = `$strSafe(${content})`;
|
|
15018
15018
|
}
|
|
15019
15019
|
funcSource += `'+${content}+'`;
|
|
15020
15020
|
} else if (content) {
|
|
@@ -15022,28 +15022,28 @@ function compileToFunction(source, debug, file) {
|
|
|
15022
15022
|
if (funcSource.endsWith(`+'';`)) {
|
|
15023
15023
|
funcSource = funcSource.substring(0, funcSource.length - 4) + ";";
|
|
15024
15024
|
}
|
|
15025
|
-
funcSource += `${content};$
|
|
15025
|
+
funcSource += `${content};$out+='`;
|
|
15026
15026
|
}
|
|
15027
15027
|
}
|
|
15028
15028
|
return match;
|
|
15029
15029
|
});
|
|
15030
15030
|
funcSource += `';`;
|
|
15031
|
-
funcSource = funcSource.replace(/\$
|
|
15032
|
-
funcSource = funcSource.replace(/\$
|
|
15031
|
+
funcSource = funcSource.replace(/\$out\+='';/g, "");
|
|
15032
|
+
funcSource = funcSource.replace(/\$out\+=''\+/g, "$out+=");
|
|
15033
15033
|
if (debug) {
|
|
15034
15034
|
const filePart = file ? `\\r\\n\\tat file:${file}` : "";
|
|
15035
|
-
funcSource = `let $
|
|
15035
|
+
funcSource = `let $dbgExpr,$dbgArt,$dbgLine;try{${funcSource}}catch(ex){let msg='render view error:'+(ex.message||ex);if($dbgArt)msg+='\\r\\n\\tsrc art:{{'+$dbgArt+'}}\\r\\n\\tat line:'+$dbgLine;msg+='\\r\\n\\t'+($dbgArt?'translate to:':'expr:');msg+=$dbgExpr+'${filePart}';throw msg;}`;
|
|
15036
15036
|
}
|
|
15037
15037
|
const viewIdRegExp = new RegExp(String.fromCharCode(31), "g");
|
|
15038
15038
|
funcSource = funcSource.replace(viewIdRegExp, `'+$viewId+'`);
|
|
15039
|
-
const atRule = hasAtRule ? `if(!$
|
|
15040
|
-
const encode = `if(!$
|
|
15041
|
-
const encodeURIMore = `if(!$
|
|
15042
|
-
const encodeQuote = `if(!$
|
|
15043
|
-
const refFallback = "if(
|
|
15039
|
+
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;}}` : "";
|
|
15040
|
+
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)}`;
|
|
15041
|
+
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)}`;
|
|
15042
|
+
const encodeQuote = `if(!$encQuote){let $qReg=/['"\\\\]/g;$encQuote=v=>$strSafe(v).replace($qReg,'\\\\$&')}`;
|
|
15043
|
+
const refFallback = "if(!$refAlt)$refAlt=$data;";
|
|
15044
15044
|
const fns = `${refFallback}${encode}${encodeURIMore}${encodeQuote}${atRule};`;
|
|
15045
|
-
const fullSource = `${fns}let $
|
|
15046
|
-
return `(
|
|
15045
|
+
const fullSource = `${fns}let $splitter='\\x1e',$tmp,$out=''{{VARS}};${funcSource}return $out`;
|
|
15046
|
+
return `($data,$viewId,$refAlt,$encHtml,$strSafe,$encUri,$refFn,$encQuote)=>{${fullSource}}`;
|
|
15047
15047
|
}
|
|
15048
15048
|
function compileTemplate(source, options = {}) {
|
|
15049
15049
|
const { debug = false, globalVars = [], file } = options;
|
|
@@ -15052,17 +15052,17 @@ function compileTemplate(source, options = {}) {
|
|
|
15052
15052
|
const viewEventProcessed = processViewEvents(converted);
|
|
15053
15053
|
const finalSource = restoreComments(viewEventProcessed, comments);
|
|
15054
15054
|
const funcBody = compileToFunction(finalSource, debug, file);
|
|
15055
|
-
const varDeclarations = globalVars.map((key) => `,${key}
|
|
15055
|
+
const varDeclarations = globalVars.map((key) => `,${key}=$data.${key}`).join("");
|
|
15056
15056
|
const funcWithVars = funcBody.replace("{{VARS}}", () => varDeclarations);
|
|
15057
15057
|
return `export default function(data, selfId, refData) {
|
|
15058
|
-
let
|
|
15058
|
+
let $data = data || {},
|
|
15059
15059
|
$viewId = selfId || '';
|
|
15060
|
-
return (${funcWithVars})(
|
|
15061
|
-
/* $
|
|
15062
|
-
/* $
|
|
15063
|
-
/* $
|
|
15064
|
-
/* $
|
|
15065
|
-
/* $
|
|
15060
|
+
return (${funcWithVars})($data, $viewId, refData,
|
|
15061
|
+
/* $encHtml */ v => String(v == null ? '' : v).replace(/[&<>"'\`]/g, m => '&' + ({'&':'amp','<':'lt','>':'gt','"':'#34',"'":'#39','\`':'#96'})[m] + ';'),
|
|
15062
|
+
/* $strSafe */ v => String(v == null ? '' : v),
|
|
15063
|
+
/* $encUri */ null,
|
|
15064
|
+
/* $refFn */ null,
|
|
15065
|
+
/* $encQuote */ null
|
|
15066
15066
|
);
|
|
15067
15067
|
}`;
|
|
15068
15068
|
}
|
|
@@ -15171,7 +15171,7 @@ function fallbackExtractVariables(source) {
|
|
|
15171
15171
|
while ((m = outputRegExp.exec(source)) !== null) {
|
|
15172
15172
|
vars.add(m[1]);
|
|
15173
15173
|
}
|
|
15174
|
-
const eachRegExp = /\{\{
|
|
15174
|
+
const eachRegExp = /\{\{forOf\s+([a-zA-Z_$][\w$]*)\s+as/g;
|
|
15175
15175
|
while ((m = eachRegExp.exec(source)) !== null) {
|
|
15176
15176
|
vars.add(m[1]);
|
|
15177
15177
|
}
|
|
@@ -15217,52 +15217,64 @@ var BUILTIN_GLOBALS = {
|
|
|
15217
15217
|
//
|
|
15218
15218
|
// These variables appear in the generated template function signature
|
|
15219
15219
|
// or body. They must be excluded from extractGlobalVars() so that
|
|
15220
|
-
// they are not mistaken for user data variables and destructured from
|
|
15220
|
+
// they are not mistaken for user data variables and destructured from $data.
|
|
15221
15221
|
// SPLITTER character constant (same as \x1e), used as namespace separator
|
|
15222
15222
|
// for refData keys, event attribute encoding, and internal data structures.
|
|
15223
|
-
// Declared as: let $
|
|
15224
|
-
$
|
|
15225
|
-
//
|
|
15226
|
-
// User variables are destructured from
|
|
15227
|
-
// let {name, age} =
|
|
15223
|
+
// Declared as: let $splitter='\x1e'
|
|
15224
|
+
$splitter: 1,
|
|
15225
|
+
// Data — the data object passed from Updater to the template function.
|
|
15226
|
+
// User variables are destructured from $data at the top of the function:
|
|
15227
|
+
// let {name, age} = $data;
|
|
15228
15228
|
// This is the first parameter of the generated arrow function.
|
|
15229
|
-
|
|
15229
|
+
$data: 1,
|
|
15230
15230
|
// Null-safe toString: v => '' + (v == null ? '' : v)
|
|
15231
15231
|
// Converts null/undefined to empty string, otherwise calls toString().
|
|
15232
15232
|
// Wraps every {{!raw}} output to prevent "null" / "undefined" rendering.
|
|
15233
|
-
$
|
|
15234
|
-
// HTML entity encoder: v => $
|
|
15233
|
+
$strSafe: 1,
|
|
15234
|
+
// HTML entity encoder: v => $strSafe(v).replace(/[&<>"'`]/g, entityMap)
|
|
15235
15235
|
// Encodes &, <, >, ", ', ` to HTML entities (& < etc.)
|
|
15236
15236
|
// Applied to all {{=escaped}} and {{:binding}} outputs.
|
|
15237
|
-
$
|
|
15238
|
-
// HTML entity map — internal object used by $
|
|
15237
|
+
$encHtml: 1,
|
|
15238
|
+
// HTML entity map — internal object used by $encHtml:
|
|
15239
15239
|
// {'&':'amp','<':'gt','>':'gt','"':'#34','\'':'#39','`':'#96'}
|
|
15240
|
-
// Not a standalone function; referenced inside $
|
|
15241
|
-
$
|
|
15242
|
-
// HTML entity RegExp — internal regexp used by $
|
|
15240
|
+
// Not a standalone function; referenced inside $encHtml's closure.
|
|
15241
|
+
$entMap: 1,
|
|
15242
|
+
// HTML entity RegExp — internal regexp used by $encHtml:
|
|
15243
15243
|
// /[&<>"'`]/g
|
|
15244
|
-
$
|
|
15245
|
-
// HTML entity replacer function — internal helper used by $
|
|
15246
|
-
// m => '&' + $
|
|
15247
|
-
// Maps
|
|
15248
|
-
$
|
|
15244
|
+
$entReg: 1,
|
|
15245
|
+
// HTML entity replacer function — internal helper used by $encHtml:
|
|
15246
|
+
// m => '&' + $entMap[m] + ';'
|
|
15247
|
+
// Maps matched character to its entity string.
|
|
15248
|
+
$entFn: 1,
|
|
15249
15249
|
// Output buffer — the string accumulator for rendered HTML.
|
|
15250
|
-
// All template output is appended via $
|
|
15251
|
-
// Declared as: let $
|
|
15252
|
-
$
|
|
15250
|
+
// All template output is appended via $out += '...'.
|
|
15251
|
+
// Declared as: let $out = ''
|
|
15252
|
+
$out: 1,
|
|
15253
15253
|
// Reference lookup: (refData, value) => key
|
|
15254
15254
|
// Finds or allocates a SPLITTER-prefixed key in refData for a given
|
|
15255
15255
|
// object reference. Used by {{@ref}} operator for passing object
|
|
15256
15256
|
// references to child views via v-lark attributes.
|
|
15257
|
-
$
|
|
15258
|
-
// URI encoder: v => encodeURIComponent($
|
|
15257
|
+
$refFn: 1,
|
|
15258
|
+
// URI encoder: v => encodeURIComponent($strSafe(v)).replace(/[!')(*]/g, extraMap)
|
|
15259
15259
|
// Extends encodeURIComponent with encoding of ! ' ( ) *.
|
|
15260
15260
|
// Applied to values in @event URL parameters and {{!uri}} contexts.
|
|
15261
|
-
$
|
|
15262
|
-
//
|
|
15261
|
+
$encUri: 1,
|
|
15262
|
+
// URI encode map — internal object used by $encUri:
|
|
15263
|
+
// {'!':'%21','\'':'%27','(':'%28',')':'%29','*':'%2A'}
|
|
15264
|
+
$uriMap: 1,
|
|
15265
|
+
// URI encode replacer — internal helper used by $encUri:
|
|
15266
|
+
// m => $uriMap[m]
|
|
15267
|
+
$uriFn: 1,
|
|
15268
|
+
// URI encode regexp — internal regexp used by $encUri:
|
|
15269
|
+
// /[!')(*]/g
|
|
15270
|
+
$uriReg: 1,
|
|
15271
|
+
// Quote encoder: v => $strSafe(v).replace(/['"\\]/g, '\\$&')
|
|
15263
15272
|
// Escapes quotes and backslashes for safe embedding in HTML attribute
|
|
15264
15273
|
// values (e.g. data-json='...').
|
|
15265
|
-
$
|
|
15274
|
+
$encQuote: 1,
|
|
15275
|
+
// Quote encode regexp — internal regexp used by $encQuote:
|
|
15276
|
+
// /['"\\]/g
|
|
15277
|
+
$qReg: 1,
|
|
15266
15278
|
// View ID — the unique identifier of the owning View instance.
|
|
15267
15279
|
// Injected into @event attribute values at render time so that
|
|
15268
15280
|
// EventDelegator can dispatch events to the correct View handler.
|
|
@@ -15270,23 +15282,23 @@ var BUILTIN_GLOBALS = {
|
|
|
15270
15282
|
$viewId: 1,
|
|
15271
15283
|
// Debug: current expression text — stores the template expression being
|
|
15272
15284
|
// evaluated, for error reporting. Only present in debug mode.
|
|
15273
|
-
// e.g. $
|
|
15274
|
-
$
|
|
15285
|
+
// e.g. $dbgExpr='<%=user.name%>'
|
|
15286
|
+
$dbgExpr: 1,
|
|
15275
15287
|
// Debug: original art syntax — stores the {{}} template syntax before
|
|
15276
15288
|
// conversion, for error reporting. Only present in debug mode.
|
|
15277
|
-
// e.g. $
|
|
15278
|
-
$
|
|
15289
|
+
// e.g. $dbgArt='{{=user.name}}'
|
|
15290
|
+
$dbgArt: 1,
|
|
15279
15291
|
// Debug: source line number — tracks the current line in the template
|
|
15280
15292
|
// source, for error reporting. Only present in debug mode.
|
|
15281
|
-
$
|
|
15282
|
-
//
|
|
15283
|
-
// Defaults to
|
|
15284
|
-
// Ensures $
|
|
15285
|
-
|
|
15293
|
+
$dbgLine: 1,
|
|
15294
|
+
// RefData alias — fallback reference lookup table.
|
|
15295
|
+
// Defaults to $data when no explicit $refAlt is provided.
|
|
15296
|
+
// Ensures $refFn() does not crash when @ operator is used without refData.
|
|
15297
|
+
$refAlt: 1,
|
|
15286
15298
|
// Temporary variable — used by the compiler for intermediate
|
|
15287
15299
|
// expression results in generated code (e.g. loop variables,
|
|
15288
|
-
// conditional branches). Declared as: let $
|
|
15289
|
-
$
|
|
15300
|
+
// conditional branches). Declared as: let $tmp
|
|
15301
|
+
$tmp: 1,
|
|
15290
15302
|
// JS literals
|
|
15291
15303
|
undefined: 1,
|
|
15292
15304
|
null: 1,
|
package/dist/webpack.js
CHANGED