@vtj/coder 0.7.0
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/LICENSE +21 -0
- package/dist/index.cjs +66 -0
- package/dist/index.mjs +477 -0
- package/package.json +38 -0
- package/types/collecter.d.ts +25 -0
- package/types/formatters.d.ts +19 -0
- package/types/generator.d.ts +9 -0
- package/types/index.d.ts +2 -0
- package/types/parser/dataSources.d.ts +2 -0
- package/types/parser/emits.d.ts +1 -0
- package/types/parser/functions.d.ts +2 -0
- package/types/parser/imports.d.ts +2 -0
- package/types/parser/index.d.ts +21 -0
- package/types/parser/inject.d.ts +2 -0
- package/types/parser/props.d.ts +2 -0
- package/types/parser/state.d.ts +2 -0
- package/types/parser/template.d.ts +10 -0
- package/types/parser/watch.d.ts +5 -0
- package/types/templates.d.ts +3 -0
- package/types/utils.d.ts +12 -0
- package/types/version.d.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 陈华春
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@vtj/base"),C=require("prettier/standalone"),W=require("prettier/plugins/html"),B=require("prettier/plugins/babel"),V=require("prettier/plugins/postcss"),D=require("prettier/plugins/estree");function b(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,n.get?n:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const M=b(W),Q=b(B),z=b(V),G=b(D);/**!
|
|
2
|
+
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
|
+
* @name @vtj/coder
|
|
4
|
+
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
+
* @version 0.7.0
|
|
6
|
+
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
+
*/const H="0.7.0",O={arrowParens:"always",bracketSpacing:!0,bracketSameLine:!0,endOfLine:"lf",htmlWhitespaceSensitivity:"css",insertPragma:!1,jsxBracketSameLine:!0,jsxSingleQuote:!0,printWidth:80,proseWrap:"preserve",quoteProps:"as-needed",requirePragma:!1,semi:!0,singleQuote:!0,tabWidth:2,trailingComma:"none",useTabs:!1,vueIndentScriptAndStyle:!0};async function U(t,e){return e?t:await C.format(t,{parser:"html",...O,plugins:[M]})}async function X(t,e){return e?t:await C.format(t,{parser:"babel-ts",...O,plugins:[Q,G]})}async function Y(t,e){return e?t:C.format(t,{parser:"scss",...O,plugins:[z]})}function k(t){return t&&t.type==="JSExpression"}function x(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function P(t){return k(t)||x(t)}function F(t){return t.replace(new RegExp("this.","g"),"")}function E(t){return t.replace(new RegExp("this.context.","g"),"")}function p(t,e=!0,r=!0){const n=P(t)?t.value:e?JSON.stringify(t):t;return r?F(E(n)):E(n)}function _(t,e=[]){let r=t;for(const n of e)r=r.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return r}function N(t){let e=t.trim();return e.startsWith("{")||(e.startsWith("async function")?e=e.replace(/^async function/,"async"):e.startsWith("function")?e=e.replace(/^function/,""):e=e.replace("=>","")),e}function Z(t={}){return Object.entries(t).map(([e,r])=>`"${e}": ${p(r)}`)}function I(t={},e=!1){const r=Object.keys(t);return e?r.map(n=>"."+n):r}class K{constructor(e,r){this.dsl=e,this.dependencies=r,this.libraryRegex=this.collectLibrary(),this.walk(e),this.walkNodes(e),this.members=this.getLibraryMember()}imports={};context={};members=[];libraryRegex=[];collectLibrary(){return this.dependencies.filter(e=>!!e.library).map(e=>new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`,"g"))}collectImport(e){const r=e.split(".");if(r.length===4){const n=r.pop(),i=r.join(".")+".",s=r.pop();if(n&&s){const o=this.dependencies.find(a=>a.library===s)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(n)}return{name:n,path:i,library:s}}return null}replaceLibraryPath(e){const{libraryRegex:r}=this;let n=e.value;for(const i of r){const s=e.value.match(i)||[];for(const o of s){const a=this.collectImport(o);a&&(n=n.replace(new RegExp(a.path,"g"),""))}}return n}walk(e){const r=n=>{if(!n||typeof n!="object")return;if(Array.isArray(n)){for(let s of n)r(s);return}const i=Object.values(n);for(const s of i)P(s)?s.value=this.replaceLibraryPath(s):r(s)};r(e)}getLibraryMember(e=[]){let r=[...e];for(const n of Object.values(this.imports))r=r.concat(Array.from(n));return u.dedupArray(r)}collectContext(e,r){const n=new Set(r?.id?this.context[r.id]:[]),i=(e.directives||[]).find(a=>a.name==="vFor");let s=new Set(Array.from(n));if(i){const{item:a="item",index:c="index"}=i.iterator||{};s=new Set([a,c,...Array.from(s)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],c=a.length?a:[`scope_${r?.id}`];s=new Set([...c,...Array.from(s)])}this.context[e.id]=s}walkNodes(e){const r=(n,i)=>{this.collectContext(n,i),Array.isArray(n.children)&&n.children.forEach(s=>r(s,n))};Array.isArray(e.nodes)&&e.nodes.forEach(n=>r(n))}}function ee(t={}){return Object.entries(t).map(([e,r])=>{const n=p(r,!1);return`${e}:${n}`})}function te(t=[]){return t.map(e=>`${e.name}: {
|
|
8
|
+
from: '${e.from||e.name}',
|
|
9
|
+
default: ${p(e.default,!0,!1)}
|
|
10
|
+
}`)}function re(t=[]){const e=r=>r?`[${u.toArray(r).map(s=>s.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(r=>typeof r=="string"?`${r}: {}`:`${r.name}: {
|
|
11
|
+
type:${e(r.type)},
|
|
12
|
+
required: ${r.required},
|
|
13
|
+
default: ${p(r.default,!0,!1)}
|
|
14
|
+
}`)}function ne(t=[]){return t.map(e=>`'${e}'`)}function $(t={},e=[]){return Object.entries(t).map(([r,n])=>{let i=N(p(n,!1,!1));return i=_(i,e),i.startsWith("async")?`async ${r}${i.replace(/^async/,"")}`:`${r}${i}`})}function se(t=[],e=[]){const r=t.reduce((s,o)=>(o.id&&x(o.source)&&(s[`watcher_${o.id}`]=o.source),s),{}),n=$(r,e),i=t.map(s=>`watcher_${s.id}: {
|
|
15
|
+
deep: ${s.deep},
|
|
16
|
+
immediate:${s.immediate},
|
|
17
|
+
handler${N(s.handler.value)}
|
|
18
|
+
}`);return{computed:n,watches:i}}function oe(t={}){return Object.values(t).map(e=>{const r=x(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
19
|
+
return await this.provider.apis.${e.ref}.apply(this, args).then(${r});
|
|
20
|
+
}`})}function R(t,e,r=[],n={},i){const s=[];let o={},a=[],c=[];return ie(t).forEach(h=>{const y=[];for(const l of h.children){let{id:v,name:f,invisible:g,from:w}=l;if(g)continue;const A=ae(f,e,w);A&&a.push(A),ce(w)&&c.push({id:w.id,name:f});const{props:q,events:T,handlers:J}=me(v,l.props,l.events,n,r),L=de(l.directives).join(" "),m=l.children?ye(l.children,r,e,n,l):"";Object.assign(o,J);let S="";typeof m=="string"?S=m:(S=(m?.nodes||[]).join(`
|
|
21
|
+
`),Object.assign(o,m?.methods||{}),a=a.concat(m?.components||[]),c=c.concat(m?.importBlocks||[])),y.push(`<${f} ${L} ${q} ${T}>
|
|
22
|
+
${S}
|
|
23
|
+
</${f}>`)}const j=ge(h.slot,y.join(`
|
|
24
|
+
`),i?.id);s.push(j)}),{nodes:s,methods:o,components:u.dedupArray(a),importBlocks:u.dedupArray(c,"id")}}function ie(t=[]){const e=new Map;for(const r of t){const n=typeof r.slot=="string"?r.slot:r.slot?.name,i=e.get(n);i?i.children.push(r):e.set(n,{slot:r.slot,children:[r]})}return e}function ae(t,e,r){if(["slot","component","template"].includes(t))return null;const n=e.get(t);if(n&&n.alias){const i=n.parent?`${n.parent}.${n.alias}`:n.alias;return`${t}: ${i}`}return r||n?t:null}function ce(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function ue(t,e,r=[]){return typeof e=="string"?`${t}="${e}"`:P(e)?`:${t}="${p({...e,value:_(e.value,r)})}"`:u.isPlainObject(e)?`:${t}='{${Z(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function pe(t={},e=[]){return Object.entries(t).map(([r,n])=>ue(r,n,e))}function le(t,e,r,n){const i=I(e.modifiers,!0);return n&&n.length>0?`@${t}${i.join("")}="(...args:any[]) => ${r}"`:`@${t}${i.join("")}="${r}"`}function fe(t,e={},r={}){const n={},i=Array.from(r[t]||new Set([])),s=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,c])=>{const d=`${u.camelCase(a)}_handler_${t}${s}`;return n[d]=i.length?{type:"JSFunction",value:`{
|
|
25
|
+
return (${c.handler.value}).apply(this, args);
|
|
26
|
+
}`}:c.handler,le(a,c,d,i)}),handlers:n}}function me(t,e={},r={},n={},i){const{binders:s,handlers:o}=fe(t,r,n);return{props:pe(e,i).join(" "),handlers:o,binders:s,events:s.join(" ")}}function de(t=[]){const e=[],{vIf:r,vShow:n,vModels:i,vFor:s}=he(t);if(r&&e.push(`v-if="${p(r.value)}"`),n&&e.push(`v-show="${p(n.value)}"`),i.forEach(o=>{const a=I(o.modifiers,!0),c=o.arg?k(o.arg)?`:[${p(o.arg)}]`:`:${o.arg}`:"";e.push(`v-model${c}${a}="${p(o.value)}"`)}),s){const{item:o,index:a}={item:"item",index:"index",...s.iterator};e.push(`v-for="(${o}, ${a}) in ${p(s.value)}"`)}return e}function he(t=[]){const e=t.find(o=>u.camelCase(o.name)==="vIf"),r=t.find(o=>u.camelCase(o.name)==="vFor"),n=t.find(o=>u.camelCase(o.name)==="vShow"),i=t.find(o=>u.camelCase(o.name)==="vBind"),s=t.filter(o=>u.camelCase(o.name)==="vModel");return{vIf:e,vFor:r,vShow:n,vModels:s,vBind:i}}function ye(t,e,r,n,i){if(typeof t=="string")return t;if(k(t)){let s=p(t,!1);return s=_(s,e),s=F(s),`{{ ${s} }}`}return Array.isArray(t)?R(t,r,e,n,i):""}function ge(t,e,r){if(!t)return e;const n=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${n.name}="${n.params?.length>0?`{${n.params?.join(",")}}`:`scope_${r}`}"`}>
|
|
27
|
+
${e}
|
|
28
|
+
</template>`}function $e(t,e=[],r=[],n={}){const i={vue:["defineComponent","reactive"]};for(const s of e){const o=t.get(s.split(":")[0]);o&&o.package&&(i[o.package]??(i[o.package]=[])).push(o.parent||(o.alias||"").split(".")[0]||o.name)}for(const[s,o]of Object.entries(n))(i[s]??(i[s]=[])).push(...Array.from(o));return Object.entries(i).filter(([s,o])=>!!o.length).map(([s,o])=>`import { ${u.dedupArray(o).join(",")}} from '${s}';`).concat(r)}function be(t,e){const{dsl:r}=t,n=Object.keys(r.computed||{}),i=$(r.lifeCycles,n),s=$(r.computed,n),o=se(r.watch,n),a=oe(r.dataSources),{methods:c,nodes:d,components:h,importBlocks:y}=R(r.nodes||[],e,n,t.context),j=[...s,...o.computed],l=$({...c,...r.methods||{}},n),v=y.map(g=>`import ${g.name} from '$vtj/raw/${g.id}.vue';`),f=$e(e,h,v,t.imports);return{id:r.id,version:r.__VERSION__,name:r.name,state:ee(r.state).join(","),inject:te(r.inject).join(","),props:re(r.props).join(","),emits:ne(r.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:j.join(","),methods:[...a,...l].join(","),imports:f.join(`
|
|
29
|
+
`),components:h.join(","),returns:t.members.join(","),template:d.join(`
|
|
30
|
+
`),css:r.css||""}}const je=`
|
|
31
|
+
<%= imports %>
|
|
32
|
+
import { useProvider } from '@vtj/renderer';
|
|
33
|
+
export default defineComponent({
|
|
34
|
+
name: '<%= name %>',
|
|
35
|
+
<% if(inject) { %> inject: { <%= inject %>}, <% } %>
|
|
36
|
+
<% if(components) { %> components: { <%= components %> }, <% } %>
|
|
37
|
+
<% if(props) { %> props: { <%= props %> }, <% } %>
|
|
38
|
+
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
39
|
+
setup(props) {
|
|
40
|
+
const provider = useProvider({
|
|
41
|
+
id: '<%= id %>',
|
|
42
|
+
version: '<%= version %>'
|
|
43
|
+
});
|
|
44
|
+
const state = reactive({ <%= state %> });
|
|
45
|
+
return {
|
|
46
|
+
state,
|
|
47
|
+
props,
|
|
48
|
+
provider
|
|
49
|
+
<% if(returns) { %>, <%= returns %> <% } %>
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
<% if(computed) { %> computed: { <%= computed %> }, <% } %>
|
|
53
|
+
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
54
|
+
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
55
|
+
});
|
|
56
|
+
`.replace(/(\n|\r|\t)/g,""),ve=`
|
|
57
|
+
<template>
|
|
58
|
+
<%= template %>
|
|
59
|
+
</template>
|
|
60
|
+
<script lang="ts">
|
|
61
|
+
<%= script %>
|
|
62
|
+
<\/script>
|
|
63
|
+
<style lang="scss" scoped>
|
|
64
|
+
<%= css %>
|
|
65
|
+
</style>
|
|
66
|
+
`,we=u.template(je),Se=u.template(ve);async function Ce(t,e=new Map,r=[],n){const i=new K(u.cloneDeep(t),r),s=be(i,e),o=we(s),a=Se({template:s.template,css:await Y(s.css,n),script:await X(o,n)});return await U(a,n)}exports.VTJ_CODER_VERSION=H;exports.generator=Ce;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
import { dedupArray as v, toArray as V, camelCase as m, isPlainObject as q, template as F, cloneDeep as D } from "@vtj/base";
|
|
2
|
+
import { format as x } from "prettier/standalone";
|
|
3
|
+
import * as M from "prettier/plugins/html";
|
|
4
|
+
import * as Q from "prettier/plugins/babel";
|
|
5
|
+
import * as z from "prettier/plugins/postcss";
|
|
6
|
+
import * as G from "prettier/plugins/estree";
|
|
7
|
+
/**!
|
|
8
|
+
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
|
+
* @name @vtj/coder
|
|
10
|
+
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
+
* @version 0.7.0
|
|
12
|
+
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
+
*/
|
|
14
|
+
const ke = "0.7.0", k = {
|
|
15
|
+
arrowParens: "always",
|
|
16
|
+
bracketSpacing: !0,
|
|
17
|
+
bracketSameLine: !0,
|
|
18
|
+
endOfLine: "lf",
|
|
19
|
+
htmlWhitespaceSensitivity: "css",
|
|
20
|
+
insertPragma: !1,
|
|
21
|
+
jsxBracketSameLine: !0,
|
|
22
|
+
jsxSingleQuote: !0,
|
|
23
|
+
printWidth: 80,
|
|
24
|
+
proseWrap: "preserve",
|
|
25
|
+
quoteProps: "as-needed",
|
|
26
|
+
requirePragma: !1,
|
|
27
|
+
semi: !0,
|
|
28
|
+
singleQuote: !0,
|
|
29
|
+
tabWidth: 2,
|
|
30
|
+
trailingComma: "none",
|
|
31
|
+
useTabs: !1,
|
|
32
|
+
vueIndentScriptAndStyle: !0
|
|
33
|
+
};
|
|
34
|
+
async function H(t, e) {
|
|
35
|
+
return e ? t : await x(t, {
|
|
36
|
+
parser: "html",
|
|
37
|
+
...k,
|
|
38
|
+
plugins: [M]
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function U(t, e) {
|
|
42
|
+
return e ? t : await x(t, {
|
|
43
|
+
parser: "babel-ts",
|
|
44
|
+
...k,
|
|
45
|
+
plugins: [Q, G]
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async function X(t, e) {
|
|
49
|
+
return e ? t : x(t, {
|
|
50
|
+
parser: "scss",
|
|
51
|
+
...k,
|
|
52
|
+
plugins: [z]
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function C(t) {
|
|
56
|
+
return t && t.type === "JSExpression";
|
|
57
|
+
}
|
|
58
|
+
function O(t) {
|
|
59
|
+
return typeof t == "object" && t && t.type === "JSFunction";
|
|
60
|
+
}
|
|
61
|
+
function A(t) {
|
|
62
|
+
return C(t) || O(t);
|
|
63
|
+
}
|
|
64
|
+
function N(t) {
|
|
65
|
+
return t.replace(new RegExp("this.", "g"), "");
|
|
66
|
+
}
|
|
67
|
+
function _(t) {
|
|
68
|
+
return t.replace(new RegExp("this.context.", "g"), "");
|
|
69
|
+
}
|
|
70
|
+
function p(t, e = !0, r = !0) {
|
|
71
|
+
const n = A(t) ? t.value : e ? JSON.stringify(t) : t;
|
|
72
|
+
return r ? N(_(n)) : _(n);
|
|
73
|
+
}
|
|
74
|
+
function E(t, e = []) {
|
|
75
|
+
let r = t;
|
|
76
|
+
for (const n of e)
|
|
77
|
+
r = r.replace(
|
|
78
|
+
new RegExp(`this.${n}.value`, "g"),
|
|
79
|
+
`this.${n}`
|
|
80
|
+
);
|
|
81
|
+
return r;
|
|
82
|
+
}
|
|
83
|
+
function I(t) {
|
|
84
|
+
let e = t.trim();
|
|
85
|
+
return e.startsWith("{") || (e.startsWith("async function") ? e = e.replace(/^async function/, "async") : e.startsWith("function") ? e = e.replace(/^function/, "") : e = e.replace("=>", "")), e;
|
|
86
|
+
}
|
|
87
|
+
function Y(t = {}) {
|
|
88
|
+
return Object.entries(t).map(([e, r]) => `"${e}": ${p(r)}`);
|
|
89
|
+
}
|
|
90
|
+
function R(t = {}, e = !1) {
|
|
91
|
+
const r = Object.keys(t);
|
|
92
|
+
return e ? r.map((n) => "." + n) : r;
|
|
93
|
+
}
|
|
94
|
+
class Z {
|
|
95
|
+
constructor(e, r) {
|
|
96
|
+
this.dsl = e, this.dependencies = r, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* { 'element-plus': ['ElButton', 'ElInput' ...] }
|
|
100
|
+
*/
|
|
101
|
+
imports = {};
|
|
102
|
+
context = {};
|
|
103
|
+
members = [];
|
|
104
|
+
libraryRegex = [];
|
|
105
|
+
collectLibrary() {
|
|
106
|
+
return this.dependencies.filter((e) => !!e.library).map((e) => new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`, "g"));
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 收集 import 信息
|
|
110
|
+
* @param regexMatchItem ex: this.$libs.ElementPlus.ElButton
|
|
111
|
+
* @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
|
|
112
|
+
*/
|
|
113
|
+
collectImport(e) {
|
|
114
|
+
const r = e.split(".");
|
|
115
|
+
if (r.length === 4) {
|
|
116
|
+
const n = r.pop(), i = r.join(".") + ".", s = r.pop();
|
|
117
|
+
if (n && s) {
|
|
118
|
+
const o = this.dependencies.find((a) => a.library === s)?.package;
|
|
119
|
+
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(n);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
name: n,
|
|
123
|
+
path: i,
|
|
124
|
+
library: s
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
// 代码中包含依赖库的引用,需要从代码中移除
|
|
130
|
+
replaceLibraryPath(e) {
|
|
131
|
+
const { libraryRegex: r } = this;
|
|
132
|
+
let n = e.value;
|
|
133
|
+
for (const i of r) {
|
|
134
|
+
const s = e.value.match(i) || [];
|
|
135
|
+
for (const o of s) {
|
|
136
|
+
const a = this.collectImport(o);
|
|
137
|
+
a && (n = n.replace(new RegExp(a.path, "g"), ""));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return n;
|
|
141
|
+
}
|
|
142
|
+
walk(e) {
|
|
143
|
+
const r = (n) => {
|
|
144
|
+
if (!n || typeof n != "object")
|
|
145
|
+
return;
|
|
146
|
+
if (Array.isArray(n)) {
|
|
147
|
+
for (let s of n)
|
|
148
|
+
r(s);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const i = Object.values(n);
|
|
152
|
+
for (const s of i)
|
|
153
|
+
A(s) ? s.value = this.replaceLibraryPath(s) : r(s);
|
|
154
|
+
};
|
|
155
|
+
r(e);
|
|
156
|
+
}
|
|
157
|
+
getLibraryMember(e = []) {
|
|
158
|
+
let r = [...e];
|
|
159
|
+
for (const n of Object.values(this.imports))
|
|
160
|
+
r = r.concat(Array.from(n));
|
|
161
|
+
return v(r);
|
|
162
|
+
}
|
|
163
|
+
collectContext(e, r) {
|
|
164
|
+
const n = new Set(r?.id ? this.context[r.id] : []), i = (e.directives || []).find((a) => a.name === "vFor");
|
|
165
|
+
let s = new Set(Array.from(n));
|
|
166
|
+
if (i) {
|
|
167
|
+
const { item: a = "item", index: c = "index" } = i.iterator || {};
|
|
168
|
+
s = /* @__PURE__ */ new Set([a, c, ...Array.from(s)]);
|
|
169
|
+
}
|
|
170
|
+
const o = e.slot;
|
|
171
|
+
if (o) {
|
|
172
|
+
const a = typeof o == "string" ? [] : o.params || [], c = a.length ? a : [`scope_${r?.id}`];
|
|
173
|
+
s = /* @__PURE__ */ new Set([...c, ...Array.from(s)]);
|
|
174
|
+
}
|
|
175
|
+
this.context[e.id] = s;
|
|
176
|
+
}
|
|
177
|
+
walkNodes(e) {
|
|
178
|
+
const r = (n, i) => {
|
|
179
|
+
this.collectContext(n, i), Array.isArray(n.children) && n.children.forEach((s) => r(s, n));
|
|
180
|
+
};
|
|
181
|
+
Array.isArray(e.nodes) && e.nodes.forEach((n) => r(n));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function K(t = {}) {
|
|
185
|
+
return Object.entries(t).map(([e, r]) => {
|
|
186
|
+
const n = p(r, !1);
|
|
187
|
+
return `${e}:${n}`;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function ee(t = []) {
|
|
191
|
+
return t.map((e) => `${e.name}: {
|
|
192
|
+
from: '${e.from || e.name}',
|
|
193
|
+
default: ${p(e.default, !0, !1)}
|
|
194
|
+
}`);
|
|
195
|
+
}
|
|
196
|
+
function te(t = []) {
|
|
197
|
+
const e = (r) => r ? `[${V(r).map((s) => s.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
198
|
+
return t.map((r) => typeof r == "string" ? `${r}: {}` : `${r.name}: {
|
|
199
|
+
type:${e(r.type)},
|
|
200
|
+
required: ${r.required},
|
|
201
|
+
default: ${p(r.default, !0, !1)}
|
|
202
|
+
}`);
|
|
203
|
+
}
|
|
204
|
+
function re(t = []) {
|
|
205
|
+
return t.map((e) => `'${e}'`);
|
|
206
|
+
}
|
|
207
|
+
function g(t = {}, e = []) {
|
|
208
|
+
return Object.entries(t).map(([r, n]) => {
|
|
209
|
+
let i = I(p(n, !1, !1));
|
|
210
|
+
return i = E(i, e), i.startsWith("async") ? `async ${r}${i.replace(/^async/, "")}` : `${r}${i}`;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
function ne(t = [], e = []) {
|
|
214
|
+
const r = t.reduce(
|
|
215
|
+
(s, o) => (o.id && O(o.source) && (s[`watcher_${o.id}`] = o.source), s),
|
|
216
|
+
{}
|
|
217
|
+
), n = g(r, e), i = t.map((s) => `watcher_${s.id}: {
|
|
218
|
+
deep: ${s.deep},
|
|
219
|
+
immediate:${s.immediate},
|
|
220
|
+
handler${I(s.handler.value)}
|
|
221
|
+
}`);
|
|
222
|
+
return {
|
|
223
|
+
computed: n,
|
|
224
|
+
watches: i
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function se(t = {}) {
|
|
228
|
+
return Object.values(t).map((e) => {
|
|
229
|
+
const r = O(e.transform) && e.transform.value || "(res) => res";
|
|
230
|
+
return `async ${e.name}(...args:any[]) {
|
|
231
|
+
return await this.provider.apis.${e.ref}.apply(this, args).then(${r});
|
|
232
|
+
}`;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function J(t, e, r = [], n = {}, i) {
|
|
236
|
+
const s = [];
|
|
237
|
+
let o = {}, a = [], c = [];
|
|
238
|
+
return oe(t).forEach((h) => {
|
|
239
|
+
const $ = [];
|
|
240
|
+
for (const u of h.children) {
|
|
241
|
+
let { id: b, name: l, invisible: y, from: w } = u;
|
|
242
|
+
if (y)
|
|
243
|
+
continue;
|
|
244
|
+
const P = ie(l, e, w);
|
|
245
|
+
P && a.push(P), ae(w) && c.push({ id: w.id, name: l });
|
|
246
|
+
const { props: L, events: W, handlers: B } = fe(
|
|
247
|
+
b,
|
|
248
|
+
u.props,
|
|
249
|
+
u.events,
|
|
250
|
+
n,
|
|
251
|
+
r
|
|
252
|
+
), T = me(u.directives).join(" "), f = u.children ? he(
|
|
253
|
+
u.children,
|
|
254
|
+
r,
|
|
255
|
+
e,
|
|
256
|
+
n,
|
|
257
|
+
u
|
|
258
|
+
) : "";
|
|
259
|
+
Object.assign(o, B);
|
|
260
|
+
let S = "";
|
|
261
|
+
typeof f == "string" ? S = f : (S = (f?.nodes || []).join(`
|
|
262
|
+
`), Object.assign(o, f?.methods || {}), a = a.concat(f?.components || []), c = c.concat(f?.importBlocks || [])), $.push(
|
|
263
|
+
`<${l} ${T} ${L} ${W}>
|
|
264
|
+
${S}
|
|
265
|
+
</${l}>`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
const j = $e(h.slot, $.join(`
|
|
269
|
+
`), i?.id);
|
|
270
|
+
s.push(j);
|
|
271
|
+
}), {
|
|
272
|
+
nodes: s,
|
|
273
|
+
methods: o,
|
|
274
|
+
components: v(a),
|
|
275
|
+
importBlocks: v(c, "id")
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function oe(t = []) {
|
|
279
|
+
const e = /* @__PURE__ */ new Map();
|
|
280
|
+
for (const r of t) {
|
|
281
|
+
const n = typeof r.slot == "string" ? r.slot : r.slot?.name, i = e.get(n);
|
|
282
|
+
i ? i.children.push(r) : e.set(n, { slot: r.slot, children: [r] });
|
|
283
|
+
}
|
|
284
|
+
return e;
|
|
285
|
+
}
|
|
286
|
+
function ie(t, e, r) {
|
|
287
|
+
if (["slot", "component", "template"].includes(t))
|
|
288
|
+
return null;
|
|
289
|
+
const n = e.get(t);
|
|
290
|
+
if (n && n.alias) {
|
|
291
|
+
const i = n.parent ? `${n.parent}.${n.alias}` : n.alias;
|
|
292
|
+
return `${t}: ${i}`;
|
|
293
|
+
}
|
|
294
|
+
return r || n ? t : null;
|
|
295
|
+
}
|
|
296
|
+
function ae(t) {
|
|
297
|
+
return !!t && typeof t == "object" && t.type === "Schema";
|
|
298
|
+
}
|
|
299
|
+
function ce(t, e, r = []) {
|
|
300
|
+
return typeof e == "string" ? `${t}="${e}"` : A(e) ? `:${t}="${p({
|
|
301
|
+
...e,
|
|
302
|
+
value: E(e.value, r)
|
|
303
|
+
})}"` : q(e) ? `:${t}='{${Y(
|
|
304
|
+
e
|
|
305
|
+
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
306
|
+
}
|
|
307
|
+
function pe(t = {}, e = []) {
|
|
308
|
+
return Object.entries(t).map(([r, n]) => ce(r, n, e));
|
|
309
|
+
}
|
|
310
|
+
function ue(t, e, r, n) {
|
|
311
|
+
const i = R(e.modifiers, !0);
|
|
312
|
+
return n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${r}"` : `@${t}${i.join("")}="${r}"`;
|
|
313
|
+
}
|
|
314
|
+
function le(t, e = {}, r = {}) {
|
|
315
|
+
const n = {}, i = Array.from(r[t] || /* @__PURE__ */ new Set([])), s = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
316
|
+
return {
|
|
317
|
+
binders: Object.entries(e).map(([a, c]) => {
|
|
318
|
+
const d = `${m(a)}_handler_${t}${s}`;
|
|
319
|
+
return n[d] = i.length ? {
|
|
320
|
+
type: "JSFunction",
|
|
321
|
+
value: `{
|
|
322
|
+
return (${c.handler.value}).apply(this, args);
|
|
323
|
+
}`
|
|
324
|
+
} : c.handler, ue(a, c, d, i);
|
|
325
|
+
}),
|
|
326
|
+
handlers: n
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function fe(t, e = {}, r = {}, n = {}, i) {
|
|
330
|
+
const { binders: s, handlers: o } = le(t, r, n);
|
|
331
|
+
return {
|
|
332
|
+
props: pe(e, i).join(" "),
|
|
333
|
+
handlers: o,
|
|
334
|
+
binders: s,
|
|
335
|
+
events: s.join(" ")
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function me(t = []) {
|
|
339
|
+
const e = [], { vIf: r, vShow: n, vModels: i, vFor: s } = de(t);
|
|
340
|
+
if (r && e.push(`v-if="${p(r.value)}"`), n && e.push(`v-show="${p(n.value)}"`), i.forEach((o) => {
|
|
341
|
+
const a = R(o.modifiers, !0), c = o.arg ? C(o.arg) ? `:[${p(o.arg)}]` : `:${o.arg}` : "";
|
|
342
|
+
e.push(`v-model${c}${a}="${p(o.value)}"`);
|
|
343
|
+
}), s) {
|
|
344
|
+
const { item: o, index: a } = { item: "item", index: "index", ...s.iterator };
|
|
345
|
+
e.push(`v-for="(${o}, ${a}) in ${p(s.value)}"`);
|
|
346
|
+
}
|
|
347
|
+
return e;
|
|
348
|
+
}
|
|
349
|
+
function de(t = []) {
|
|
350
|
+
const e = t.find((o) => m(o.name) === "vIf"), r = t.find((o) => m(o.name) === "vFor"), n = t.find((o) => m(o.name) === "vShow"), i = t.find((o) => m(o.name) === "vBind"), s = t.filter((o) => m(o.name) === "vModel");
|
|
351
|
+
return {
|
|
352
|
+
vIf: e,
|
|
353
|
+
vFor: r,
|
|
354
|
+
vShow: n,
|
|
355
|
+
vModels: s,
|
|
356
|
+
vBind: i
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function he(t, e, r, n, i) {
|
|
360
|
+
if (typeof t == "string")
|
|
361
|
+
return t;
|
|
362
|
+
if (C(t)) {
|
|
363
|
+
let s = p(t, !1);
|
|
364
|
+
return s = E(s, e), s = N(s), `{{ ${s} }}`;
|
|
365
|
+
}
|
|
366
|
+
return Array.isArray(t) ? J(t, r, e, n, i) : "";
|
|
367
|
+
}
|
|
368
|
+
function $e(t, e, r) {
|
|
369
|
+
if (!t)
|
|
370
|
+
return e;
|
|
371
|
+
const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
|
|
372
|
+
return `<template ${`#${n.name}="${n.params?.length > 0 ? `{${n.params?.join(",")}}` : `scope_${r}`}"`}>
|
|
373
|
+
${e}
|
|
374
|
+
</template>`;
|
|
375
|
+
}
|
|
376
|
+
function ye(t, e = [], r = [], n = {}) {
|
|
377
|
+
const i = {
|
|
378
|
+
vue: ["defineComponent", "reactive"]
|
|
379
|
+
};
|
|
380
|
+
for (const s of e) {
|
|
381
|
+
const o = t.get(s.split(":")[0]);
|
|
382
|
+
o && o.package && (i[o.package] ?? (i[o.package] = [])).push(o.parent || (o.alias || "").split(".")[0] || o.name);
|
|
383
|
+
}
|
|
384
|
+
for (const [s, o] of Object.entries(n))
|
|
385
|
+
(i[s] ?? (i[s] = [])).push(...Array.from(o));
|
|
386
|
+
return Object.entries(i).filter(([s, o]) => !!o.length).map(([s, o]) => `import { ${v(o).join(
|
|
387
|
+
","
|
|
388
|
+
)}} from '${s}';`).concat(r);
|
|
389
|
+
}
|
|
390
|
+
function ge(t, e) {
|
|
391
|
+
const { dsl: r } = t, n = Object.keys(r.computed || {}), i = g(r.lifeCycles, n), s = g(r.computed, n), o = ne(r.watch, n), a = se(r.dataSources), { methods: c, nodes: d, components: h, importBlocks: $ } = J(
|
|
392
|
+
r.nodes || [],
|
|
393
|
+
e,
|
|
394
|
+
n,
|
|
395
|
+
t.context
|
|
396
|
+
), j = [...s, ...o.computed], u = g(
|
|
397
|
+
{
|
|
398
|
+
...c,
|
|
399
|
+
...r.methods || {}
|
|
400
|
+
},
|
|
401
|
+
n
|
|
402
|
+
), b = $.map((y) => `import ${y.name} from '$vtj/raw/${y.id}.vue';`), l = ye(
|
|
403
|
+
e,
|
|
404
|
+
h,
|
|
405
|
+
b,
|
|
406
|
+
t.imports
|
|
407
|
+
);
|
|
408
|
+
return {
|
|
409
|
+
id: r.id,
|
|
410
|
+
version: r.__VERSION__,
|
|
411
|
+
name: r.name,
|
|
412
|
+
state: K(r.state).join(","),
|
|
413
|
+
inject: ee(r.inject).join(","),
|
|
414
|
+
props: te(r.props).join(","),
|
|
415
|
+
emits: re(r.emits).join(","),
|
|
416
|
+
watch: o.watches.join(","),
|
|
417
|
+
lifeCycles: i.join(","),
|
|
418
|
+
computed: j.join(","),
|
|
419
|
+
methods: [...a, ...u].join(","),
|
|
420
|
+
imports: l.join(`
|
|
421
|
+
`),
|
|
422
|
+
components: h.join(","),
|
|
423
|
+
returns: t.members.join(","),
|
|
424
|
+
template: d.join(`
|
|
425
|
+
`),
|
|
426
|
+
css: r.css || ""
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
const ve = `
|
|
430
|
+
<%= imports %>
|
|
431
|
+
import { useProvider } from '@vtj/renderer';
|
|
432
|
+
export default defineComponent({
|
|
433
|
+
name: '<%= name %>',
|
|
434
|
+
<% if(inject) { %> inject: { <%= inject %>}, <% } %>
|
|
435
|
+
<% if(components) { %> components: { <%= components %> }, <% } %>
|
|
436
|
+
<% if(props) { %> props: { <%= props %> }, <% } %>
|
|
437
|
+
<% if(emits) {%> emits: [<%= emits %>], <% } %>
|
|
438
|
+
setup(props) {
|
|
439
|
+
const provider = useProvider({
|
|
440
|
+
id: '<%= id %>',
|
|
441
|
+
version: '<%= version %>'
|
|
442
|
+
});
|
|
443
|
+
const state = reactive({ <%= state %> });
|
|
444
|
+
return {
|
|
445
|
+
state,
|
|
446
|
+
props,
|
|
447
|
+
provider
|
|
448
|
+
<% if(returns) { %>, <%= returns %> <% } %>
|
|
449
|
+
};
|
|
450
|
+
},
|
|
451
|
+
<% if(computed) { %> computed: { <%= computed %> }, <% } %>
|
|
452
|
+
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
453
|
+
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
454
|
+
});
|
|
455
|
+
`.replace(/(\n|\r|\t)/g, ""), je = `
|
|
456
|
+
<template>
|
|
457
|
+
<%= template %>
|
|
458
|
+
</template>
|
|
459
|
+
<script lang="ts">
|
|
460
|
+
<%= script %>
|
|
461
|
+
<\/script>
|
|
462
|
+
<style lang="scss" scoped>
|
|
463
|
+
<%= css %>
|
|
464
|
+
</style>
|
|
465
|
+
`, be = F(ve), we = F(je);
|
|
466
|
+
async function Ce(t, e = /* @__PURE__ */ new Map(), r = [], n) {
|
|
467
|
+
const i = new Z(D(t), r), s = ge(i, e), o = be(s), a = we({
|
|
468
|
+
template: s.template,
|
|
469
|
+
css: await X(s.css, n),
|
|
470
|
+
script: await U(o, n)
|
|
471
|
+
});
|
|
472
|
+
return await H(a, n);
|
|
473
|
+
}
|
|
474
|
+
export {
|
|
475
|
+
ke as VTJ_CODER_VERSION,
|
|
476
|
+
Ce as generator
|
|
477
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vtj/coder",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "0.7.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "vue-tsc && vite build",
|
|
8
|
+
"test": "vitest run",
|
|
9
|
+
"vitest": "vitest",
|
|
10
|
+
"coverage": "vitest run --coverage"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@vtj/base": "^0.7.0",
|
|
14
|
+
"@vtj/core": "^0.7.0",
|
|
15
|
+
"prettier": "~3.2.1"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@vtj/cli": "^0.7.0"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./types/index.d.ts",
|
|
23
|
+
"import": "./dist/index.mjs",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"main": "./dist/index.cjs",
|
|
28
|
+
"module": "./dist/index.mjs",
|
|
29
|
+
"types": "./types/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"types"
|
|
33
|
+
],
|
|
34
|
+
"gitHead": "b65d1b19322cbd0721173d094db1b5ece018d980",
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type BlockSchema, type Dependencie } from '@vtj/core';
|
|
2
|
+
export declare class Collecter {
|
|
3
|
+
dsl: BlockSchema;
|
|
4
|
+
dependencies: Dependencie[];
|
|
5
|
+
/**
|
|
6
|
+
* { 'element-plus': ['ElButton', 'ElInput' ...] }
|
|
7
|
+
*/
|
|
8
|
+
imports: Record<string, Set<string>>;
|
|
9
|
+
context: Record<string, Set<string>>;
|
|
10
|
+
members: string[];
|
|
11
|
+
private libraryRegex;
|
|
12
|
+
constructor(dsl: BlockSchema, dependencies: Dependencie[]);
|
|
13
|
+
private collectLibrary;
|
|
14
|
+
/**
|
|
15
|
+
* 收集 import 信息
|
|
16
|
+
* @param regexMatchItem ex: this.$libs.ElementPlus.ElButton
|
|
17
|
+
* @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
|
|
18
|
+
*/
|
|
19
|
+
private collectImport;
|
|
20
|
+
private replaceLibraryPath;
|
|
21
|
+
private walk;
|
|
22
|
+
private getLibraryMember;
|
|
23
|
+
private collectContext;
|
|
24
|
+
private walkNodes;
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 代码格式化工具
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* 格式化HTMl代码
|
|
6
|
+
*/
|
|
7
|
+
export declare function htmlFormatter(content: string, disabled?: boolean): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* 格式化ts代码
|
|
10
|
+
*/
|
|
11
|
+
export declare function tsFormatter(content: string, disabled?: boolean): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* 格式化js代码s
|
|
14
|
+
*/
|
|
15
|
+
export declare function jsFormatter(content: string, disabled?: boolean): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* 格式化css代码
|
|
18
|
+
*/
|
|
19
|
+
export declare function cssFormatter(content: string, disabled?: boolean): Promise<string>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type BlockSchema, type MaterialDescription, type Dependencie } from '@vtj/core';
|
|
2
|
+
/**
|
|
3
|
+
* 代码生成器 处理过程:
|
|
4
|
+
* 1. Generator 读取 dsl、componentMap、dependencies
|
|
5
|
+
* 2. Collecter 预处理收集信息
|
|
6
|
+
* 3. Parser 解析 dsl,提取 token
|
|
7
|
+
* 4. Compiled token 注入模板生成代码文件字符串
|
|
8
|
+
*/
|
|
9
|
+
export declare function generator(dsl: BlockSchema, componentMap?: Map<string, MaterialDescription>, dependencies?: Dependencie[], formatterDisabled?: boolean): Promise<string>;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseEmits(emits?: string[]): string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type MaterialDescription } from '@vtj/core';
|
|
2
|
+
import { Collecter } from '../collecter';
|
|
3
|
+
export interface Token {
|
|
4
|
+
id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
name: string;
|
|
7
|
+
state: string;
|
|
8
|
+
inject: string;
|
|
9
|
+
props: string;
|
|
10
|
+
emits: string;
|
|
11
|
+
watch: string;
|
|
12
|
+
lifeCycles: string;
|
|
13
|
+
computed: string;
|
|
14
|
+
methods: string;
|
|
15
|
+
imports: string;
|
|
16
|
+
components: string;
|
|
17
|
+
returns: string;
|
|
18
|
+
template: string;
|
|
19
|
+
css: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function parser(collecter: Collecter, componentMap: Map<string, MaterialDescription>): Token;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type NodeSchema, type MaterialDescription, type JSFunction } from '@vtj/core';
|
|
2
|
+
export declare function parseTemplate(children: NodeSchema[], componentMap: Map<string, MaterialDescription>, computedKeys?: string[], context?: Record<string, Set<string>>, parent?: NodeSchema): {
|
|
3
|
+
nodes: string[];
|
|
4
|
+
methods: Record<string, JSFunction>;
|
|
5
|
+
components: string[];
|
|
6
|
+
importBlocks: {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type JSExpression, type JSFunction } from '@vtj/core';
|
|
2
|
+
export declare function isJSExpression(data: any): data is JSExpression;
|
|
3
|
+
export declare function isJSFunction(x: any): x is JSFunction;
|
|
4
|
+
export declare function isJSCode(data: unknown): data is JSExpression | JSFunction;
|
|
5
|
+
export declare function JSCodeToString(data: unknown): string;
|
|
6
|
+
export declare function replaceThis(content: string): string;
|
|
7
|
+
export declare function replaceContext(content: string): string;
|
|
8
|
+
export declare function parseValue(val: unknown, stringify?: boolean, noThis?: boolean): string;
|
|
9
|
+
export declare function replaceComputedValue(content: string, keys?: string[]): string;
|
|
10
|
+
export declare function replaceFunctionTag(content: string): string;
|
|
11
|
+
export declare function parsePlainObjectValue(obj?: Record<string, any>): string[];
|
|
12
|
+
export declare function getModifiers(modifiers?: Record<string, boolean>, isToString?: boolean): string[];
|