Remove helper functions in favor of using a smarter next() function in while loops.
This commit is contained in:
2
packages/js/core/dist/document.cjs
vendored
2
packages/js/core/dist/document.cjs
vendored
@@ -1 +1 @@
|
||||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("./parser.cjs");function g(w,b=" "){let c=0;const i=m.createLineData("",b);async function f(){switch(c){case 0:c=1;break;case 2:return c=1,!1}const e=await w.next();return e===null?(c=3,!0):(i.line=e,m.parseLine(i),!1)}const y=()=>c=2,o=()=>i.level,d=()=>i.line.slice(i.offsetHead),u=()=>i.line.slice(i.offsetHead,i.offsetTail),s=()=>i.line.slice(i.offsetTail),j=e=>e===u();async function h(e){const a=c===0?-1:o();for(;;){if(await f())return;if(o()<=a)return y();if(await e())return}}async function p(e=-1,a=[d()]){var n;return e===-1&&(e=o()+1),await f()?a:o()<e?(y(),a):(a.push(((n=i.line)==null?void 0:n.slice(e))||""),p(e,a))}async function x(e={},a=!1){const n=[];let t={};return Object.keys(e).length?Object.keys(e).forEach(r=>{e[r]===!0&&(t[r]={type:a?"collection":"normal",handle:()=>s().trim()}),typeof e[r]=="function"&&(t[r]={type:a?"collection":"normal",handle:e[r]}),typeof e[r]=="object"&&(t[r]=e[r])}):t={"#any":{type:a?"collection":"normal",handle:()=>s().trim()}},await h(async()=>{const r=u();if(!r)return;const l=t[r]||t["#any"];!l||(l.type==="normal"?n.push(await l.handle()):l.type==="collection"&&n.push({[r]:await l.handle()}))}),n}async function O(e={}){const a={};let n={};return Object.keys(e).length?Object.keys(e).forEach(t=>{t==="#tail"?n[t]={type:"tail",handle:()=>{}}:t==="#text"?n[t]={type:"text",handle:()=>{}}:e[t]===!0?n[t]={type:"normal",handle:()=>s().trim()}:typeof e[t]=="function"?n[t]={type:"normal",handle:e[t]}:typeof e[t]=="object"&&(n[t]=e[t])}):n={"#any":{type:"normal",handle:()=>s().trim()}},n["#tail"]&&(a["#tail"]=s().trim()),await h(async()=>{const t=u();if(!t)return;const r=n[t]||n["#any"]||n["#text"];if(!!r&&(r.type==="normal"?a[t]=await r.handle():r.type==="collection"?(a[t]||(a[t]=[]),a[t].push(await r.handle())):r.type==="text"&&(a["#text"]=await p(o())),n&&Object.keys(n).every(l=>["collection"].includes(n[l].type)?!1:a[l]!==void 0)))return!0}),a}async function v(){const e=[["root",[]]];for(;!await f();){const a=o(),n=a+1,t=e[a];if(!t)continue;e.length=n;const r=e[n]=[d(),[]];t[1].push(r)}return e[0]}return{next:f,line:d,head:u,tail:s,level:o,match:j,each:h,blockAsText:p,toObject:O,toArray:x,toLineArray:v}}exports.useDocument=g;
|
||||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("./parser.cjs");function f(r,c=" "){const e=i.createLineData("",c);let t=!1;async function o(n=-1){if(t)t=!1;else{const a=await r.next();if(a===null)return!1;e.line=a,i.parseLine(e)}return l()<=n?(t=!0,!1):!0}const l=()=>e.level,u=()=>e.line.slice(e.offsetHead),s=()=>e.line.slice(e.offsetHead,e.offsetTail);return{next:o,level:l,line:u,head:s,tail:()=>e.line.slice(e.offsetTail),match:n=>n===s()}}exports.useDocument=f;
|
||||
|
||||
103
packages/js/core/dist/document.js
vendored
103
packages/js/core/dist/document.js
vendored
@@ -1,89 +1,28 @@
|
||||
import { parseLine as v, createLineData as H } from "./parser.js";
|
||||
function g(y, w = " ") {
|
||||
let c = 0;
|
||||
const i = H("", w);
|
||||
async function s() {
|
||||
switch (c) {
|
||||
case 0:
|
||||
c = 1;
|
||||
break;
|
||||
case 2:
|
||||
return c = 1, !1;
|
||||
import { parseLine as r, createLineData as u } from "./parser.js";
|
||||
function h(s, f = " ") {
|
||||
const e = u("", f);
|
||||
let t = !1;
|
||||
async function c(n = -1) {
|
||||
if (t)
|
||||
t = !1;
|
||||
else {
|
||||
const i = await s.next();
|
||||
if (i === null)
|
||||
return !1;
|
||||
e.line = i, r(e);
|
||||
}
|
||||
const e = await y.next();
|
||||
return e === null ? (c = 3, !0) : (i.line = e, v(i), !1);
|
||||
}
|
||||
const p = () => c = 2, o = () => i.level, h = () => i.line.slice(i.offsetHead), u = () => i.line.slice(i.offsetHead, i.offsetTail), f = () => i.line.slice(i.offsetTail), b = (e) => e === u();
|
||||
async function d(e) {
|
||||
const a = c === 0 ? -1 : o();
|
||||
for (; ; ) {
|
||||
if (await s())
|
||||
return;
|
||||
if (o() <= a)
|
||||
return p();
|
||||
if (await e())
|
||||
return;
|
||||
}
|
||||
}
|
||||
async function m(e = -1, a = [h()]) {
|
||||
var n;
|
||||
return e === -1 && (e = o() + 1), await s() ? a : o() < e ? (p(), a) : (a.push(((n = i.line) == null ? void 0 : n.slice(e)) || ""), m(e, a));
|
||||
}
|
||||
async function j(e = {}, a = !1) {
|
||||
const n = [];
|
||||
let t = {};
|
||||
return Object.keys(e).length ? Object.keys(e).forEach((r) => {
|
||||
e[r] === !0 && (t[r] = { type: a ? "collection" : "normal", handle: () => f().trim() }), typeof e[r] == "function" && (t[r] = { type: a ? "collection" : "normal", handle: e[r] }), typeof e[r] == "object" && (t[r] = e[r]);
|
||||
}) : t = { "#any": { type: a ? "collection" : "normal", handle: () => f().trim() } }, await d(async () => {
|
||||
const r = u();
|
||||
if (!r)
|
||||
return;
|
||||
const l = t[r] || t["#any"];
|
||||
!l || (l.type === "normal" ? n.push(await l.handle()) : l.type === "collection" && n.push({ [r]: await l.handle() }));
|
||||
}), n;
|
||||
}
|
||||
async function x(e = {}) {
|
||||
const a = {};
|
||||
let n = {};
|
||||
return Object.keys(e).length ? Object.keys(e).forEach((t) => {
|
||||
t === "#tail" ? n[t] = { type: "tail", handle: () => {
|
||||
} } : t === "#text" ? n[t] = { type: "text", handle: () => {
|
||||
} } : e[t] === !0 ? n[t] = { type: "normal", handle: () => f().trim() } : typeof e[t] == "function" ? n[t] = { type: "normal", handle: e[t] } : typeof e[t] == "object" && (n[t] = e[t]);
|
||||
}) : n = { "#any": { type: "normal", handle: () => f().trim() } }, n["#tail"] && (a["#tail"] = f().trim()), await d(async () => {
|
||||
const t = u();
|
||||
if (!t)
|
||||
return;
|
||||
const r = n[t] || n["#any"] || n["#text"];
|
||||
if (!!r && (r.type === "normal" ? a[t] = await r.handle() : r.type === "collection" ? (a[t] || (a[t] = []), a[t].push(await r.handle())) : r.type === "text" && (a["#text"] = await m(o())), n && Object.keys(n).every((l) => ["collection"].includes(n[l].type) ? !1 : a[l] !== void 0)))
|
||||
return !0;
|
||||
}), a;
|
||||
}
|
||||
async function O() {
|
||||
const e = [["root", []]];
|
||||
for (; !await s(); ) {
|
||||
const a = o(), n = a + 1, t = e[a];
|
||||
if (!t)
|
||||
continue;
|
||||
e.length = n;
|
||||
const r = e[n] = [h(), []];
|
||||
t[1].push(r);
|
||||
}
|
||||
return e[0];
|
||||
return l() <= n ? (t = !0, !1) : !0;
|
||||
}
|
||||
const l = () => e.level, o = () => e.line.slice(e.offsetHead), a = () => e.line.slice(e.offsetHead, e.offsetTail);
|
||||
return {
|
||||
next: s,
|
||||
line: h,
|
||||
head: u,
|
||||
tail: f,
|
||||
level: o,
|
||||
match: b,
|
||||
each: d,
|
||||
blockAsText: m,
|
||||
toObject: x,
|
||||
toArray: j,
|
||||
toLineArray: O
|
||||
next: c,
|
||||
level: l,
|
||||
line: o,
|
||||
head: a,
|
||||
tail: () => e.line.slice(e.offsetTail),
|
||||
match: (n) => n === a()
|
||||
};
|
||||
}
|
||||
export {
|
||||
g as useDocument
|
||||
h as useDocument
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user