diff --git a/.gitignore b/.gitignore index 01136bfda75548e4cf695839791da8b65685341d..24aad38c554b9b6822f72bb3c9372ed3c22d3f21 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,7 @@ package-lock.json pnpm-lock.yaml /packages/**/node_modules -dist +# to ignore all dist folders in all levels +**/dist .history +dumped* diff --git a/packages/inula-novdom/package.json b/packages/inula-novdom/package.json index 21d04ecc81af8e5e83677f637f2fa7d3a8c80e41..0ef2f8878618b26b6b1d43cbe28ade9cb830f734 100644 --- a/packages/inula-novdom/package.json +++ b/packages/inula-novdom/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "vitest --ui", "bench": "vitest bench", - "dump-test": "babel tests --out-dir dumped-tests --extensions .tsx --presets=babel-preset-inula-jsx --copy-files --out-file-extension .ts" + "dump-test": "babel tests --out-dir dumped-tests --extensions .ts,.tsx --presets babel-preset-inula-jsx --copy-files --out-file-extension .ts" }, "dependencies": { "@babel/cli": "^7.23.9", diff --git a/packages/inula-novdom/vitest.config.ts b/packages/inula-novdom/vitest.config.ts index 20abc8ae57b92211db8c4e5b8a83f8177934fc63..417cc23ef8d34a2e876012edbaf1ad1a5792d314 100644 --- a/packages/inula-novdom/vitest.config.ts +++ b/packages/inula-novdom/vitest.config.ts @@ -26,7 +26,7 @@ export default defineConfig({ }, plugins: [ // @ts-expect-error TODO: fix vite plugin interface is not compatible - inula(), + inula({ packageName: 'inula-reactive' }), ], test: { environment: 'jsdom', // or 'jsdom', 'node' diff --git a/packages/transpiler/babel-preset-inula-jsx/src/pluginProvider.ts b/packages/transpiler/babel-preset-inula-jsx/src/pluginProvider.ts index 0c5d80a8d9b6894de6c47121b2d635dc9eafdfae..30b5529569620575912c7049fcd536d8be070862 100644 --- a/packages/transpiler/babel-preset-inula-jsx/src/pluginProvider.ts +++ b/packages/transpiler/babel-preset-inula-jsx/src/pluginProvider.ts @@ -8,7 +8,7 @@ import { attributeMap, htmlTags, importMap } from './const'; export class PluginProvider { - private static readonly inulaPackageName = 'inula-reactive'; + private inulaPackageName = 'inula-reactive'; // ---- Plugin Level ---- private readonly babelApi: typeof babel private readonly t: typeof t @@ -34,6 +34,7 @@ export class PluginProvider { this.htmlTags = options.htmlTags ?? htmlTags; this.parseTemplate = options.parseTemplate ?? true; this.attributeMap = options.attributeMap ?? attributeMap; + options.packageName && (this.inulaPackageName = options.packageName); } // ---- Two levels of enter: @@ -56,7 +57,7 @@ export class PluginProvider { this.t.isImportDeclaration(n) ) as t.ImportDeclaration[]; const inulaImports = this.allImports.filter( - n => n.source.value === PluginProvider.inulaPackageName + n => n.source.value === this.inulaPackageName ); // ---- @Enter2 if (inulaImports.length === 0) { diff --git a/packages/transpiler/babel-preset-inula-jsx/src/test/mock.ts b/packages/transpiler/babel-preset-inula-jsx/src/test/mock.ts index d828ed3f85d6ee134872451cb7b406dbebbeab1b..87129799ad31202a15b47855fae20bfb6abf7379 100644 --- a/packages/transpiler/babel-preset-inula-jsx/src/test/mock.ts +++ b/packages/transpiler/babel-preset-inula-jsx/src/test/mock.ts @@ -1,22 +1,20 @@ -import babel, { transform, types as t, parseSync } from '@babel/core'; +import babel, { transform, types as t, parseSync } from '@babel/core'; import inula from '../'; import babelJSX from '@babel/plugin-syntax-jsx'; import generate from '@babel/generator'; import { expect as ep } from 'vitest'; function formatCode(code: string) { - return generate( - parseSync(code, {plugins: [babelJSX]})! - )!.code; + return generate(parseSync(code, { plugins: [babelJSX] })!)!.code; } export function transformInula(code: string) { return transform(code, { - presets: [[inula, {'files': '*'}]] + presets: [[inula, { files: '*', packageName: 'inula' }]], })?.code; } export function expect(ori: string, expected: string) { const transformed = transformInula(ori)!; ep(formatCode(transformed)).toBe(formatCode(expected)); -} \ No newline at end of file +} diff --git a/packages/transpiler/babel-preset-inula-jsx/src/types.ts b/packages/transpiler/babel-preset-inula-jsx/src/types.ts index 51f07da9b46dfb2dea19b9f3f53b7feeb3715067..cbe311f5338177f889b050680e031cf1273d3d11 100644 --- a/packages/transpiler/babel-preset-inula-jsx/src/types.ts +++ b/packages/transpiler/babel-preset-inula-jsx/src/types.ts @@ -27,4 +27,9 @@ export interface InulaOption { * @example { createElement: 'createElement' } */ parseTemplate?: boolean + /** + * @brief The package name of inula. It will be used to identify whether we should transform the file. + * @default inula + */ + packageName?: string } diff --git a/packages/transpiler/jsx-view-generator/dist/index.cjs b/packages/transpiler/jsx-view-generator/dist/index.cjs deleted file mode 100644 index 3c793ebebbff048b26ee650f778e92fa907ec903..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-generator/dist/index.cjs +++ /dev/null @@ -1,2 +0,0 @@ -"use strict";var v=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var A=(h,t,e)=>t in h?v(h,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[t]=e;var j=(h,t)=>{for(var e in t)v(h,e,{get:t[e],enumerable:!0})},I=(h,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of T(t))!L.call(h,s)&&s!==e&&v(h,s,{get:()=>t[s],enumerable:!(i=V(t,s))||i.enumerable});return h};var W=h=>I(v({},"__esModule",{value:!0}),h);var U=(h,t,e)=>(A(h,typeof t!="symbol"?t+"":t,e),e);var H={};j(H,{generateNew:()=>x,generateView:()=>u,viewGeneratorMap:()=>S});module.exports=W(H);var d=class{viewUnit;config;t;traverse;elementAttributeMap;importMap;constructor(t,e){this.config=e,this.t=e.babelApi.types,this.traverse=e.babelApi.traverse,this.importMap=e.importMap,this.viewUnit=t,this.elementAttributeMap=e.attributeMap?Object.entries(e.attributeMap).reduce((i,[s,o])=>(o.forEach(r=>{i[r]||(i[r]=[]),i[r].push(s)}),i),{}):{}}initStatements=[];addStatement(...t){this.initStatements.push(...t)}templates=[];addTemplate(...t){this.templates.push(...t)}run(){return""}generate(){return[this.run(),this.initStatements,this.templates]}checkReactive(t){if(this.t.isFunction(t))return!1;let e=!1;return this.traverse(this.wrapWithFile(t),{MemberExpression:i=>{this.t.isIdentifier(i.node.property,{name:"get"})&&(e=!0,i.stop())}}),e}prefixMap={node:"$node",template:"$template"};nodeIdx=-1;geneNodeName(t){return`${this.prefixMap.node}${t??++this.nodeIdx}`}templateIdx=-1;generateTemplateName(){return`${this.prefixMap.template}${++this.templateIdx}`}wrapWithFile(t){return this.t.file(this.t.program([this.t.expressionStatement(t)]))}addWatch(t){return this.t.callExpression(this.t.identifier(this.importMap.watch),[this.t.arrowFunctionExpression([],t)])}createCollector(){let t=[];function e(i){Array.isArray(i)?t.push(...i):i&&t.push(i)}return[t,e]}parseViewProp(t,e){let i=t.value,s=t.viewPropMap,o=Object.fromEntries(Object.entries(s).map(([r,a])=>{let[p,m]=e(a,this.config,this.templateIdx);return this.addTemplate(...p),[r,m]}));return this.traverse(this.wrapWithFile(i),{StringLiteral:r=>{let a=r.node.value;o[a]&&(this.t.isNodesEquivalent(i,r.node)&&(i=o[a].expression),r.replaceWith(o[a]))}}),i}parseProps(t,e){return Object.fromEntries(Object.entries(t).map(([i,s])=>[i,this.parseViewProp(s,e)]))}};var E=class extends d{run(){let{tag:t,props:e,children:i}=this.viewUnit,s=this.parseProps(e,u),[o,r]=this.declareCompNode(t,s,i);return this.addStatement(r),o}declareCompNode(t,e,i){let s=this.geneNodeName(),o=[];if(Object.keys(e).length>0||i.length>0){let r=this.t.objectExpression(Object.entries(e).map(([a,p])=>this.checkReactive(p)?this.t.objectMethod("get",this.t.identifier(a),[],this.t.blockStatement([this.t.returnStatement(p)])):this.t.objectProperty(this.t.identifier(a),p)));if(i.length>0){let a=C(i,this.config);r.properties.push(this.t.objectMethod("get",this.t.identifier("children"),[],a))}o.push(r)}return[s,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(s),this.t.callExpression(this.t.identifier(this.importMap.createComponent),[t,...o]))])]}};var D=class extends d{addHTMLProp(t,e,i,s){let o=this.checkReactive(s),r=this.setDynamicHTMLProp(t,e,i,s,o);return o&&(r=this.addWatch(r)),this.t.expressionStatement(r)}setStyle(t,e){return this.t.callExpression(this.t.identifier(this.importMap.setStyle),[this.t.identifier(t),e])}setDataset(t,e){return this.t.callExpression(this.t.identifier(this.importMap.setDataset),[this.t.identifier(t),e])}setStaticProperty(t,e,i){return this.t.assignmentExpression("=",this.t.memberExpression(this.t.identifier(t),this.t.identifier(e)),i)}setDynamicProperty(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.setProperty),[this.t.identifier(t),this.t.stringLiteral(e),i])}setStaticAttribute(t,e,i){return this.t.callExpression(this.t.memberExpression(this.t.identifier(t),this.t.identifier("setAttribute")),[this.t.stringLiteral(e),i])}setDynamicAttribute(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.setAttribute),[this.t.identifier(t),this.t.stringLiteral(e),i])}setDelegatedEvent(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.delegateEvent),[this.t.identifier(t),this.t.stringLiteral(e),i])}setStaticEvent(t,e,i){return this.t.callExpression(this.t.memberExpression(this.t.identifier(t),this.t.identifier("addEventListener")),[this.t.stringLiteral(e),i])}setDynamicEvent(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.addEventListener),[this.t.identifier(t),this.t.stringLiteral(e),i])}setDynamicHTMLProp(t,e,i,s,o){if(i==="style")return this.setStyle(t,s);if(i==="dataset")return this.setDataset(t,s);if(i.startsWith("on")){let r=i.slice(2).toLowerCase();return D.DelegatedEvents.has(r)?this.setDelegatedEvent(t,r,s):this[o?"setDynamicEvent":"setStaticEvent"](t,r,s)}return this.isInternalAttribute(e,i)?(i==="class"?i="className":i==="for"&&(i="htmlFor"),this[o?"setDynamicProperty":"setStaticProperty"](t,i,s)):this[o?"setDynamicAttribute":"setStaticAttribute"](t,i,s)}isInternalAttribute(t,e){return this.elementAttributeMap["*"]?.includes(e)||this.elementAttributeMap[t]?.includes(e)}},g=D;U(g,"DelegatedEvents",new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]));var N=class extends g{run(){let{tag:t,props:e,children:i}=this.viewUnit,s=this.parseProps(e,u),[o,r]=this.declareHTMLNode(t);this.addStatement(r);let a=this.t.isStringLiteral(t)?t.value:"ANY";return Object.entries(s).forEach(([p,m])=>{this.addStatement(this.addHTMLProp(o,a,p,m))}),i.forEach(p=>{let[m,n]=x(this,p);this.addStatement(...n),this.addStatement(this.insertChildNode(o,m))}),o}declareHTMLNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.callExpression(this.t.identifier("createElement"),[t]))])]}insertChildNode(t,e){return this.t.expressionStatement(this.t.callExpression(this.t.identifier(this.importMap.insert),[this.t.identifier(t),this.t.identifier(e)]))}};var b=class extends g{run(){let{template:t,mutableUnits:e,props:i}=this.viewUnit,s=this.generateTemplate(t),[o,r]=this.declareTemplateNode(s);this.addStatement(r);let a=[];i.forEach(({path:n})=>{a.push(n)}),e.forEach(({path:n})=>{a.push(n.slice(0,-1)),n[n.length-1]!==-1&&a.push(n)});let[p,m]=this.insertElements(a,o);return this.addStatement(...p),i.forEach(({tag:n,path:c,key:l,value:f})=>{let M=m[c.join(".")],P=this.t.isStringLiteral(n)?n.value:"ANY";this.addStatement(this.addHTMLProp(M,P,l,f))}),e.forEach(n=>{let c=n.path,l=m[c.slice(0,-1).join(".")],f=m[c.join(".")];console.log(f,c);let[M,P]=x(this,n);this.addStatement(...P),this.addStatement(this.insertChildNode(l,M,f))}),o}generateTemplate(t){let e=this.generateTemplateName(),[i,s]=x(this,t,!1),o=this.t.returnStatement(this.t.identifier(i));return this.addTemplate(this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.arrowFunctionExpression([],this.t.blockStatement([...s,o])))])),e}declareTemplateNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.callExpression(this.t.memberExpression(this.t.identifier(t),this.t.identifier("cloneNode")),[this.t.identifier("true")]))])]}insertChildNode(t,e,i){let s=i?[this.t.identifier(i)]:[];return this.t.expressionStatement(this.t.callExpression(this.t.identifier(this.importMap.insert),[this.t.identifier(t),this.t.identifier(e),...s]))}insertElement(t,e,i){let s=this.geneNodeName();if(e.length===0)return this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(s),Array.from({length:i}).reduce(n=>this.t.memberExpression(n,this.t.identifier("nextSibling")),this.t.identifier(t)))]);let o=n=>this.t.memberExpression(n,this.t.identifier("firstChild")),r=n=>this.t.memberExpression(o(n),this.t.identifier("nextSibling")),a=n=>this.t.memberExpression(r(n),this.t.identifier("nextSibling")),p=(n,c)=>this.t.memberExpression(this.t.memberExpression(n,this.t.identifier("childNodes")),this.t.numericLiteral(c),!0),m=n=>this.t.memberExpression(n,this.t.identifier("nextSibling"));return this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(s),e.reduce((n,c,l)=>{if(l===0&&i>0)for(let f=0;f{let m=b.findBestNodeAndPath(o,p,e),[,n,c]=m,l=m[0];(n.length!==0||c!==0)&&(s(this.insertElement(l,n,c)),l=this.geneNodeName(this.nodeIdx),o[l]=p)});let a=Object.fromEntries(Object.entries(o).map(([p,m])=>[m.join("."),p]));return[i,a]}static pathWithCommonPrefix(t){let e=[...t].sort(),i=[...e];i.forEach(r=>{i.forEach(a=>{if(r!==a){for(let p=0;pr.length!==a.length?r.length-a.length:r[0]-a[0]);return[...new Set(s.map(r=>r.join(".")))].map(r=>r.split(".").filter(Boolean).map(Number))}static findBestNodeAndPath(t,e,i){let s=0,o,r;return Object.entries(t).forEach(([a,p])=>{let m=0,n=p.length;for(let c=0;c0&&c<=3&&(r=[a,m,c])}m===p.length&&m>s&&(o=a,s=m)}),r?[r[0],e.slice(r[1]+1),r[2]]:o?[o,e.slice(s),0]:[i,e,0]}};var w=class extends d{run(){let{content:t}=this.viewUnit,[e,i]=this.declareTextNode(t);return this.addStatement(i),e}declareTextNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.callExpression(this.t.identifier(this.importMap.createText),[t]))])]}};var y=class extends d{run(){let{content:t}=this.viewUnit,e=this.parseViewProp(t,u),[i,s]=this.declareExpressionNode(e);return this.addStatement(s),i}declareExpressionNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),t)])]}};var S={html:N,comp:E,template:b,text:w,exp:y,if:E,env:E};function x(h,t,e=!0){let i=new S[t.type](t,h.config);e&&(i.nodeIdx=h.nodeIdx);let[s,o,r]=i.generate();return e&&(h.nodeIdx=i.nodeIdx),[s,o,r]}function C(h,t){let e=t.babelApi.types,i=[],s=h.flatMap(r=>{let a=new S[r.type](r,t),[p,m]=a.generate();return i.push(p),m}),o=e.returnStatement(e.arrayExpression(i.map(r=>e.identifier(r))));return e.blockStatement(s.concat(o))}function u(h,t,e=-1){let i=t.babelApi.types,s=[],o=[],r=-1,a=h.flatMap(m=>{let n=new S[m.type](m,t);n.templateIdx=e,n.nodeIdx=r;let[c,l,f]=n.generate();return e=n.templateIdx,r=n.nodeIdx,s.push(c),o.push(...f),l}),p=i.returnStatement(i.arrayExpression(s.map(m=>i.identifier(m))));return[o,i.expressionStatement(i.callExpression(i.arrowFunctionExpression([],i.blockStatement(a.concat(p))),[]))]}0&&(module.exports={generateNew,generateView,viewGeneratorMap}); -//# sourceMappingURL=index.cjs.map \ No newline at end of file diff --git a/packages/transpiler/jsx-view-generator/dist/index.cjs.map b/packages/transpiler/jsx-view-generator/dist/index.cjs.map deleted file mode 100644 index 4f5cf1501066de01acf7f8d57abbe2c098a09e13..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-generator/dist/index.cjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/index.ts","../src/HelperGenerators/BaseGenerator.ts","../src/NodeGenerators/CompGenerator.ts","../src/HelperGenerators/HTMLPropGenerator.ts","../src/NodeGenerators/HTMLGenerator.ts","../src/NodeGenerators/TemplateGenerator.ts","../src/NodeGenerators/TextGenerator.ts","../src/NodeGenerators/ExpressionGenerator.ts","../src/generate.ts"],"sourcesContent":["export {generateView, generateNew, viewGeneratorMap} from './generate';\nexport type {ViewGeneratorConfig} from './types';","import { UnitProp, ViewUnit } from '@inula/jsx-view-parser';\nimport { ViewGeneratorConfig } from '../types';\nimport type { types as t, traverse } from '@babel/core';\n\n\nexport default class BaseGenerator {\n readonly viewUnit: ViewUnit\n readonly config: ViewGeneratorConfig\n readonly t\n readonly traverse: typeof traverse\n readonly elementAttributeMap\n readonly importMap\n\n constructor(viewUnit: ViewUnit, config: ViewGeneratorConfig) {\n this.config = config;\n this.t = config.babelApi.types;\n this.traverse = config.babelApi.traverse;\n this.importMap = config.importMap;\n this.viewUnit = viewUnit;\n this.elementAttributeMap = config.attributeMap\n ? Object.entries(config.attributeMap).reduce>(\n (acc, [key, elements]) => {\n elements.forEach(element => {\n if (!acc[element]) acc[element] = [];\n acc[element].push(key);\n });\n return acc;\n },\n {}\n )\n : {};\n }\n\n // ---- Init Statements\n private readonly initStatements: t.Statement[] = []\n addStatement(...statements: t.Statement[]) {\n this.initStatements.push(...statements);\n }\n\n private readonly templates: t.Statement[] = []\n addTemplate(...template: t.Statement[]) {\n this.templates.push(...template);\n }\n\n // ---- Generate ----\n /**\n * @brief To be implemented by the subclass\n */\n run(): string {\n return ''; \n }\n\n generate(): [string, t.Statement[], t.Statement[]]{\n const nodeName = this.run();\n return [nodeName, this.initStatements, this.templates];\n }\n \n // ---- Reactivity ----\n /**\n * @brief Check if the expression is reactive, which satisfies the following conditions:\n * 1. Contains .get() property\n * 2. The whole expression is not a function\n * @param expression \n * @returns \n */\n checkReactive(expression: t.Expression) {\n if (this.t.isFunction(expression)) return false;\n let reactive = false;\n this.traverse(this.wrapWithFile(expression), {\n MemberExpression: path => {\n if (this.t.isIdentifier(path.node.property, { name: 'get' })) {\n reactive = true;\n path.stop();\n }\n }\n });\n return reactive;\n }\n\n // ---- Names ----\n private readonly prefixMap = {\n node: '$node',\n template: '$template',\n }\n\n nodeIdx = -1;\n geneNodeName(idx?: number): string {\n return `${this.prefixMap.node}${idx ?? ++this.nodeIdx}`;\n }\n templateIdx = -1;\n generateTemplateName() {\n return `${this.prefixMap.template}${++this.templateIdx}`;\n }\n\n\n // ---- Utils ----\n /**\n * @brief Wrap the value in a file\n * @param node\n * @returns wrapped value\n */\n wrapWithFile(node: t.Expression): t.File {\n return this.t.file(this.t.program([this.t.expressionStatement(node)]));\n }\n\n addWatch(value: t.Expression) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.watch),\n [this.t.arrowFunctionExpression([], value)]\n );\n }\n\n createCollector(): [t.Statement[], (statement: t.Statement | t.Statement[] | null) => void]{\n const statements: t.Statement[] = [];\n function collect(statement: t.Statement | t.Statement[] | null) {\n if (Array.isArray(statement)) {\n statements.push(...statement);\n } else if (statement) {\n statements.push(statement);\n }\n }\n return [statements, collect];\n }\n\n parseViewProp(prop: UnitProp, generateView: (units: ViewUnit[], config: ViewGeneratorConfig, templateIdx: number) => [t.Statement[], t.ExpressionStatement]): t.Expression {\n let value = prop.value;\n const viewPropMap = prop.viewPropMap;\n const propNodeMap = Object.fromEntries(\n Object.entries(viewPropMap).map(([key, units]) => {\n const [templates, statement] = generateView(units, this.config, this.templateIdx);\n this.addTemplate(...templates);\n return [key, statement];\n })\n );\n\n this.traverse(this.wrapWithFile(value), {\n StringLiteral: path => {\n const key = path.node.value;\n if (propNodeMap[key]) {\n if (this.t.isNodesEquivalent(value, path.node)) {\n value = (propNodeMap[key] as t.ExpressionStatement).expression;\n }\n path.replaceWith(propNodeMap[key]);\n }\n }\n });\n \n return value;\n }\n\n parseProps(props: Record, generateView: (units: ViewUnit[], config: ViewGeneratorConfig) => [t.Statement[], t.ExpressionStatement]) {\n return Object.fromEntries(\n Object.entries(props).map(([key, prop]) => {\n return [key, this.parseViewProp(prop, generateView)];\n })\n );\n }\n}\n","import { CompUnit, ViewUnit } from '@inula/jsx-view-parser';\nimport BaseGenerator from '../HelperGenerators/BaseGenerator';\nimport type { types as t } from '@babel/core';\nimport { generateBlock, generateView } from '../generate';\n\nexport class CompGenerator extends BaseGenerator {\n run(): string {\n const { tag, props: propsWithView, children } = this.viewUnit as CompUnit;\n const props = this.parseProps(propsWithView, generateView);\n\n const [nodeName, statement] = this.declareCompNode(tag, props, children);\n this.addStatement(statement);\n\n return nodeName;\n }\n\n /**\n * @View\n * const $el = createComponent(tag, {\n * ...props\n * }, spreadProps)\n */\n declareCompNode(tag: t.Expression, props: Record, children: ViewUnit[]): [string, t.Statement] {\n const name = this.geneNodeName();\n const nodes = [];\n if (Object.keys(props).length > 0 || children.length > 0) {\n const propNode = this.t.objectExpression(Object.entries(props).map(([key, value]) => {\n const isReactive = this.checkReactive(value);\n if (isReactive) {\n /**\n * @View\n * get reactiveValue() {\n * return value\n * }\n */\n return (\n this.t.objectMethod('get', this.t.identifier(key), [],\n this.t.blockStatement([\n this.t.returnStatement(value)\n ])\n )\n );\n }\n return this.t.objectProperty(\n this.t.identifier(key),\n value\n );\n }));\n if (children.length > 0) {\n const statement = generateBlock(children, this.config);\n propNode.properties.push(\n this.t.objectMethod('get', this.t.identifier('children'), [], statement)\n );\n }\n nodes.push(propNode);\n }\n\n\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.identifier(this.importMap.createComponent),\n [tag, ...nodes]\n )\n )\n ])];\n }\n}","import BaseGenerator from './BaseGenerator';\nimport type { types as t } from '@babel/core';\n\nexport class HTMLPropGenerator extends BaseGenerator {\n static DelegatedEvents = new Set([\n 'beforeinput',\n 'click',\n 'dblclick',\n 'contextmenu',\n 'focusin',\n 'focusout',\n 'input',\n 'keydown',\n 'keyup',\n 'mousedown',\n 'mousemove',\n 'mouseout',\n 'mouseover',\n 'mouseup',\n 'pointerdown',\n 'pointermove',\n 'pointerout',\n 'pointerover',\n 'pointerup',\n 'touchend',\n 'touchmove',\n 'touchstart',\n ])\n\n addHTMLProp(\n nodeName: string, \n tag: string,\n key: string,\n value: t.Expression,\n ): t.Statement {\n const shouldWatch = this.checkReactive(value);\n let expression = this.setDynamicHTMLProp(nodeName, tag, key, value, shouldWatch);\n if (shouldWatch) expression = this.addWatch(expression);\n\n return this.t.expressionStatement(expression);\n }\n\n /**\n * @View\n * setStyle($node, value)\n */\n private setStyle(\n nodeName: string, \n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setStyle),\n [this.t.identifier(nodeName), value]\n );\n }\n\n /**\n * @View\n * setDataset($node, value)\n */\n private setDataset(\n nodeName: string, \n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setDataset),\n [this.t.identifier(nodeName), value]\n );\n }\n\n /**\n * @View\n * $node.key = value\n */\n private setStaticProperty(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.assignmentExpression(\n '=',\n this.t.memberExpression(\n this.t.identifier(nodeName),\n this.t.identifier(key),\n ),\n value\n );\n }\n\n /**\n * @View\n * setProperty($node, key, value)\n */\n private setDynamicProperty(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setProperty),\n [this.t.identifier(nodeName), this.t.stringLiteral(key), value]\n );\n }\n\n /**\n * @View\n * $node.setAttribute(key, value)\n */\n private setStaticAttribute(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.memberExpression(\n this.t.identifier(nodeName),\n this.t.identifier('setAttribute'),\n ),\n [this.t.stringLiteral(key), value]\n );\n }\n\n\n /**\n * @View\n * setAttribute($node, key, value)\n */\n private setDynamicAttribute(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setAttribute),\n [this.t.identifier(nodeName), this.t.stringLiteral(key), value]\n );\n }\n\n /**\n * @View\n * delegateEvent($node, eventName, value)\n */\n private setDelegatedEvent(\n nodeName: string, \n eventName: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.delegateEvent),\n [this.t.identifier(nodeName), this.t.stringLiteral(eventName), value]\n );\n }\n\n /**\n * @View\n * $node.addEventListener(eventName, value)\n */\n private setStaticEvent(\n nodeName: string, \n eventName: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.memberExpression(\n this.t.identifier(nodeName),\n this.t.identifier('addEventListener'),\n ),\n [this.t.stringLiteral(eventName), value]\n );\n }\n\n /**\n * @View\n * addEventListener($node, eventName, value)\n */\n private setDynamicEvent(\n nodeName: string, \n eventName: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.addEventListener),\n [this.t.identifier(nodeName), this.t.stringLiteral(eventName), value]\n );\n }\n\n private setDynamicHTMLProp(\n nodeName: string, \n tag: string,\n key: string,\n value: t.Expression,\n dynamic: boolean\n ): t.Expression {\n if (key === 'style') return this.setStyle(nodeName, value);\n if (key === 'dataset') return this.setDataset(nodeName, value);\n if (key.startsWith('on')) {\n const event = key.slice(2).toLowerCase();\n if (HTMLPropGenerator.DelegatedEvents.has(event)) {\n return this.setDelegatedEvent(nodeName, event, value);\n }\n return this[dynamic ? 'setDynamicEvent' : 'setStaticEvent'](nodeName, event, value);\n }\n if (this.isInternalAttribute(tag, key)) {\n if (key === 'class') key = 'className';\n else if (key === 'for') key = 'htmlFor';\n return this[dynamic ? 'setDynamicProperty' : 'setStaticProperty'](nodeName, key, value);\n }\n return this[dynamic ? 'setDynamicAttribute' : 'setStaticAttribute'](nodeName, key, value);\n }\n\n /**\n * @brief Check if the attribute is internal, i.e., can be accessed as js property\n * @param tag\n * @param attribute\n * @returns true if the attribute is internal\n */\n isInternalAttribute(tag: string, attribute: string): boolean {\n return (\n this.elementAttributeMap['*']?.includes(attribute) ||\n this.elementAttributeMap[tag]?.includes(attribute)\n );\n }\n}","import { HTMLUnit } from '@inula/jsx-view-parser';\nimport type { types as t } from '@babel/core';\nimport { HTMLPropGenerator } from '../HelperGenerators/HTMLPropGenerator';\nimport { generateNew, generateView } from '../generate';\n\nexport class HTMLGenerator extends HTMLPropGenerator {\n run(){\n const { tag, props: propsWithView, children } = this.viewUnit as HTMLUnit;\n const props = this.parseProps(propsWithView, generateView);\n const [nodeName, statement] = this.declareHTMLNode(tag);\n this.addStatement(statement);\n\n // ---- Use the tag name to check if the prop is internal for the tag,\n // for dynamic tag, we can't check it, so we just assume it's not internal\n // represent by the \"ANY\" tag name\n const tagName = this.t.isStringLiteral(tag) ? tag.value : 'ANY';\n\n Object.entries(props).forEach(([key, prop]) => {\n this.addStatement(this.addHTMLProp(nodeName, tagName, key, prop));\n });\n\n children.forEach(child => {\n const [childNodeName, childStatements] = generateNew(this, child);\n this.addStatement(...childStatements);\n this.addStatement(this.insertChildNode(nodeName, childNodeName));\n });\n\n return nodeName;\n }\n\n /**\n * @View \n * const $el = createElement(tag)\n */\n declareHTMLNode(tag: t.Expression): [string, t.Statement] {\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.identifier('createElement'),\n [tag]\n )\n )\n ])];\n }\n\n /**\n * @View\n * $insert($el, childNode)\n */\n private insertChildNode(\n parent: string, \n child: string\n ) {\n return this.t.expressionStatement(\n this.t.callExpression(\n this.t.identifier(this.importMap.insert),\n [this.t.identifier(parent), this.t.identifier(child)]\n )\n );\n }\n}","import { HTMLUnit, TemplateUnit } from '@inula/jsx-view-parser';\nimport { HTMLPropGenerator } from '../HelperGenerators/HTMLPropGenerator';\nimport { generateNew } from '../generate';\nimport type { types as t } from '@babel/core';\n\n\nexport class TemplateGenerator extends HTMLPropGenerator{\n run(): string {\n const { template, mutableUnits, props } = this.viewUnit as TemplateUnit;\n\n const templateName = this.generateTemplate(template);\n const [nodeName, statement] = this.declareTemplateNode(templateName);\n this.addStatement(statement);\n\n // ---- Insert elements first\n const paths: number[][] = [];\n props.forEach(({ path }) => {\n paths.push(path);\n });\n mutableUnits.forEach(({ path }) => {\n // ---- ParentPath and NextPath\n paths.push(path.slice(0, -1));\n if (path[path.length - 1] !== -1) paths.push(path);\n });\n const [insertElementStatements, pathNameMap] = this.insertElements(\n paths,\n nodeName\n );\n\n this.addStatement(...insertElementStatements);\n\n // ---- Resolve props\n props.forEach(\n ({\n tag,\n path,\n key,\n value,\n }) => {\n const name = pathNameMap[path.join('.')];\n\n const tagName = this.t.isStringLiteral(tag) ? tag.value : 'ANY';\n this.addStatement(\n this.addHTMLProp(\n name,\n tagName,\n key,\n value,\n )\n );\n }\n );\n\n // ---- Resolve mutable units\n mutableUnits.forEach(unit => {\n const path = unit.path;\n // ---- Find parent htmlElement\n const parentName = pathNameMap[path.slice(0, -1).join('.')];\n const nextName = pathNameMap[path.join('.')];\n console.log(nextName, path);\n const [childName, childStatements] = generateNew(this, unit);\n this.addStatement(...childStatements);\n this.addStatement(this.insertChildNode(parentName, childName, nextName));\n });\n\n\n return nodeName;\n }\n\n private generateTemplate(template: HTMLUnit): string {\n const templateName = this.generateTemplateName();\n const [name, statements] = generateNew(this, template, false);\n const returnStatement = this.t.returnStatement(this.t.identifier(name));\n\n this.addTemplate(\n this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(templateName),\n this.t.arrowFunctionExpression([], this.t.blockStatement([...statements, returnStatement]))\n )\n ])\n );\n\n return templateName;\n }\n\n /**\n * @View\n * const $el = template.cloneNode(true)\n */\n private declareTemplateNode(templateName: string): [string, t.Statement]{\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.memberExpression(\n this.t.identifier(templateName),\n this.t.identifier('cloneNode')\n ), [this.t.identifier('true')]\n )\n )\n ])];\n }\n\n /**\n * @View\n * $insert($el, childNode)\n */\n private insertChildNode(\n parent: string, \n child: string,\n nextName: string\n ) {\n const nextNode = nextName ? [this.t.identifier(nextName)] : [];\n return this.t.expressionStatement(\n this.t.callExpression(\n this.t.identifier(this.importMap.insert),\n [this.t.identifier(parent), this.t.identifier(child), ...nextNode]\n )\n );\n }\n\n\n /**\n * @View\n * ${dlNodeName}.firstChild\n * or\n * ${dlNodeName}.firstChild.nextSibling\n * or\n * ...\n * ${dlNodeName}.childNodes[${num}]\n */\n private insertElement(\n dlNodeName: string,\n path: number[],\n offset: number\n ): t.Statement {\n const newNodeName = this.geneNodeName();\n if (path.length === 0) {\n return this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(newNodeName),\n Array.from({ length: offset }).reduce(\n (acc: t.Expression) =>\n this.t.memberExpression(acc, this.t.identifier('nextSibling')),\n this.t.identifier(dlNodeName)\n )\n )\n ]);\n }\n const addFirstChild = (object: t.Expression) =>\n // ---- ${object}.firstChild\n this.t.memberExpression(object, this.t.identifier('firstChild'));\n const addSecondChild = (object: t.Expression) =>\n // ---- ${object}.firstChild.nextSibling\n this.t.memberExpression(\n addFirstChild(object),\n this.t.identifier('nextSibling')\n );\n const addThirdChild = (object: t.Expression) =>\n // ---- ${object}.firstChild.nextSibling.nextSibling\n this.t.memberExpression(\n addSecondChild(object),\n this.t.identifier('nextSibling')\n );\n const addOtherChild = (object: t.Expression, num: number) =>\n // ---- ${object}.childNodes[${num}]\n this.t.memberExpression(\n this.t.memberExpression(object, this.t.identifier('childNodes')),\n this.t.numericLiteral(num),\n true\n );\n const addNextSibling = (object: t.Expression) =>\n // ---- ${object}.nextSibling\n this.t.memberExpression(object, this.t.identifier('nextSibling'));\n\n return this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(newNodeName),\n path.reduce((acc: t.Expression, cur: number, idx) => {\n if (idx === 0 && offset > 0) {\n for (let i = 0; i < offset; i++) acc = addNextSibling(acc);\n }\n if (cur === 0) return addFirstChild(acc);\n if (cur === 1) return addSecondChild(acc);\n if (cur === 2) return addThirdChild(acc);\n return addOtherChild(acc, cur);\n }, this.t.identifier(dlNodeName))\n )\n ]);\n }\n\n /**\n * @brief Insert elements to the template node from the paths\n * @param paths\n * @param dlNodeName\n * @returns\n */\n private insertElements(\n paths: number[][],\n dlNodeName: string\n ): [t.Statement[], Record] {\n const [statements, collect] = this.createCollector();\n const nameMap: Record = { [dlNodeName]: [] };\n\n const commonPrefixPaths = TemplateGenerator.pathWithCommonPrefix(paths);\n\n commonPrefixPaths.forEach(path => {\n const res = TemplateGenerator.findBestNodeAndPath(\n nameMap,\n path,\n dlNodeName\n );\n const [, pat, offset] = res;\n let name = res[0];\n\n if (pat.length !== 0 || offset !== 0) {\n collect(this.insertElement(name, pat, offset));\n name = this.geneNodeName(this.nodeIdx);\n nameMap[name] = path;\n }\n });\n const pathNameMap = Object.fromEntries(\n Object.entries(nameMap).map(([name, path]) => [path.join('.'), name])\n );\n\n return [statements, pathNameMap];\n }\n\n // ---- Path related\n /**\n * @brief Extract common prefix from paths\n * e.g.\n * [0, 1, 2, 3] + [0, 1, 2, 4] => [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 4]\n * [0, 1, 2] is the common prefix\n * @param paths\n * @returns paths with common prefix\n */\n private static pathWithCommonPrefix(paths: number[][]): number[][] {\n const allPaths = [...paths].sort();\n const ps = [...allPaths];\n ps.forEach(path0 => {\n ps.forEach(path1 => {\n if (path0 === path1) return;\n for (let i = 0; i < path0.length; i++) {\n if (path0[i] !== path1[i]) {\n if (i !== 0) {\n allPaths.push(path0.slice(0, i));\n }\n break;\n }\n }\n });\n });\n\n // ---- Sort by length and then by first element, small to large\n const sortedPaths = allPaths.sort((a, b) => {\n if (a.length !== b.length) return a.length - b.length;\n return a[0] - b[0];\n });\n\n // ---- Deduplicate\n const deduplicatedPaths = [\n ...new Set(sortedPaths.map(path => path.join('.'))),\n ].map(path => path.split('.').filter(Boolean).map(Number));\n\n return deduplicatedPaths;\n }\n\n /**\n * @brief Find the best node name and path for the given path by looking into the nameMap.\n * If there's a full match, return the name and an empty path\n * If there's a partly match, return the name and the remaining path\n * If there's a nextSibling match, return the name and the remaining path with sibling offset\n * @param nameMap\n * @param path\n * @param defaultName\n * @returns [name, path, siblingOffset]\n */\n private static findBestNodeAndPath(\n nameMap: Record,\n path: number[],\n defaultName: string\n ): [string, number[], number] {\n let bestMatchCount = 0;\n let bestMatchName: string | undefined;\n let bestHalfMatch: [string, number, number] | undefined;\n Object.entries(nameMap).forEach(([name, pat]) => {\n let matchCount = 0;\n const pathLength = pat.length;\n for (let i = 0; i < pathLength; i++) {\n if (pat[i] === path[i]) matchCount++;\n }\n // console.log(name, matchCount, pathLength - 1, pat);\n if (matchCount === pathLength - 1) {\n const offset = path[pathLength - 1] - pat[pathLength - 1];\n if (offset > 0 && offset <= 3) {\n bestHalfMatch = [name, matchCount, offset];\n }\n }\n if (matchCount !== pat.length) return;\n if (matchCount > bestMatchCount) {\n bestMatchName = name;\n bestMatchCount = matchCount;\n }\n });\n if (bestHalfMatch) {\n return [\n bestHalfMatch[0],\n path.slice(bestHalfMatch[1] + 1),\n bestHalfMatch[2],\n ];\n }\n if (!bestMatchName) {\n return [defaultName, path, 0];\n }\n return [bestMatchName, path.slice(bestMatchCount), 0];\n }\n}","import { TextUnit } from '@inula/jsx-view-parser';\nimport BaseGenerator from '../HelperGenerators/BaseGenerator';\nimport type { types as t } from '@babel/core';\n\nexport class TextGenerator extends BaseGenerator {\n run() {\n const { content } = this.viewUnit as TextUnit;\n const [nodeName, statement] = this.declareTextNode(content);\n this.addStatement(statement);\n return nodeName;\n }\n\n declareTextNode(content: t.Literal): [string, t.Statement] {\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.identifier(this.importMap.createText),\n [content]\n )\n )\n ])];\n }\n}","import { ExpUnit } from '@inula/jsx-view-parser';\nimport BaseGenerator from '../HelperGenerators/BaseGenerator';\nimport type { types as t } from '@babel/core';\nimport { generateView } from '../generate';\n\nexport class ExpressionGenerator extends BaseGenerator {\n run() {\n const { content: contentWithProp } = this.viewUnit as ExpUnit;\n const content = this.parseViewProp(contentWithProp, generateView);\n const [nodeName, statement] = this.declareExpressionNode(content);\n this.addStatement(statement);\n return nodeName;\n }\n\n\n declareExpressionNode(expression: t.Expression): [string, t.Statement] {\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n expression\n )\n ])];\n }\n}","import { ViewUnit } from '@inula/jsx-view-parser';\nimport { CompGenerator } from './NodeGenerators/CompGenerator';\nimport { HTMLGenerator } from './NodeGenerators/HTMLGenerator';\nimport { ViewGeneratorConfig } from './types';\nimport type { types as t } from '@babel/core';\nimport { TemplateGenerator } from './NodeGenerators/TemplateGenerator';\nimport { TextGenerator } from './NodeGenerators/TextGenerator';\nimport { ExpressionGenerator } from './NodeGenerators/ExpressionGenerator';\n\nexport const viewGeneratorMap = {\n html: HTMLGenerator,\n comp: CompGenerator,\n template: TemplateGenerator,\n text: TextGenerator,\n exp: ExpressionGenerator,\n if: CompGenerator,\n env: CompGenerator,\n} as const;\n\n\nexport function generateNew(oldGenerator: any, viewUnit: ViewUnit, resetIdx = true): [string, t.Statement[], t.Statement[]]{\n const generator = new viewGeneratorMap[viewUnit.type](viewUnit, oldGenerator.config);\n if (resetIdx) generator.nodeIdx = oldGenerator.nodeIdx;\n const [name, statements, templates] = generator.generate();\n if (resetIdx) oldGenerator.nodeIdx = generator.nodeIdx;\n return [name, statements, templates];\n}\n\nexport function generateBlock(viewUnits: ViewUnit[], config: ViewGeneratorConfig) {\n const t = config.babelApi.types;\n const names: string[] = [];\n const statements = viewUnits.flatMap(viewUnit => {\n const generator = new viewGeneratorMap[viewUnit.type](viewUnit, config);\n const [name, statements] = generator.generate();\n names.push(name);\n return statements;\n });\n\n const returnStatement = t.returnStatement(t.arrayExpression(names.map(name => t.identifier(name))));\n return (\n t.blockStatement(statements.concat(returnStatement))\n );\n}\n\nexport function generateView(viewUnits: ViewUnit[], config: ViewGeneratorConfig, templateIdx=-1): [t.Statement[], t.ExpressionStatement] {\n const t = config.babelApi.types;\n const names: string[] = [];\n const allTemplates: t.Statement[] = [];\n let nodeIdx = -1;\n const statements = viewUnits.flatMap(viewUnit => {\n const generator = new viewGeneratorMap[viewUnit.type](viewUnit, config);\n generator.templateIdx = templateIdx;\n generator.nodeIdx = nodeIdx;\n const [name, statements, templates] = generator.generate();\n templateIdx = generator.templateIdx;\n nodeIdx = generator.nodeIdx;\n names.push(name);\n allTemplates.push(...templates);\n return statements;\n });\n\n const returnStatement = t.returnStatement(t.arrayExpression(names.map(name => t.identifier(name))));\n\n return [allTemplates, (\n t.expressionStatement(\n t.callExpression(\n t.arrowFunctionExpression([], t.blockStatement(statements.concat(returnStatement))),\n []\n )\n )\n )];\n}"],"mappings":"qjBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iBAAAE,EAAA,iBAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAL,GCKA,IAAqBM,EAArB,KAAmC,CACxB,SACA,OACA,EACA,SACA,oBACA,UAET,YAAYC,EAAoBC,EAA6B,CAC3D,KAAK,OAASA,EACd,KAAK,EAAIA,EAAO,SAAS,MACzB,KAAK,SAAWA,EAAO,SAAS,SAChC,KAAK,UAAYA,EAAO,UACxB,KAAK,SAAWD,EAChB,KAAK,oBAAsBC,EAAO,aAC9B,OAAO,QAAQA,EAAO,YAAY,EAAE,OAClC,CAACC,EAAK,CAACC,EAAKC,CAAQ,KAClBA,EAAS,QAAQC,GAAW,CACrBH,EAAIG,CAAO,IAAGH,EAAIG,CAAO,EAAI,CAAC,GACnCH,EAAIG,CAAO,EAAE,KAAKF,CAAG,CACvB,CAAC,EACMD,GAET,CAAC,CACH,EACA,CAAC,CACP,CAGiB,eAAgC,CAAC,EAClD,gBAAgBI,EAA2B,CACzC,KAAK,eAAe,KAAK,GAAGA,CAAU,CACxC,CAEiB,UAA2B,CAAC,EAC7C,eAAeC,EAA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IAAIV,EAAiBQ,EAAS,IAAI,EAAEA,EAAUQ,CAAM,EACtEN,EAAU,YAAcW,EACxBX,EAAU,QAAUa,EACpB,GAAM,CAACZ,EAAMC,EAAYC,CAAS,EAAIH,EAAU,SAAS,EACzD,OAAAW,EAAcX,EAAU,YACxBa,EAAUb,EAAU,QACpBQ,EAAM,KAAKP,CAAI,EACfW,EAAa,KAAK,GAAGT,CAAS,EACvBD,CACT,CAAC,EAEKO,EAAkBF,EAAE,gBAAgBA,EAAE,gBAAgBC,EAAM,IAAIP,GAAQM,EAAE,WAAWN,CAAI,CAAC,CAAC,CAAC,EAElG,MAAO,CAACW,EACNL,EAAE,oBACAA,EAAE,eACAA,EAAE,wBAAwB,CAAC,EAAIA,EAAE,eAAeL,EAAW,OAAOO,CAAe,CAAC,CAAC,EACnF,CAAC,CACH,CACF,CACD,CACH","names":["src_exports","__export","generateNew","generateView","viewGeneratorMap","__toCommonJS","BaseGenerator","viewUnit","config","acc","key","elements","element","statements","template","expression","reactive","path","idx","node","value","collect","statement","prop","generateView","viewPropMap","propNodeMap","units","templates","props","CompGenerator","BaseGenerator","tag","propsWithView","children","props","generateView","nodeName","statement","name","nodes","propNode","key","value","generateBlock","_HTMLPropGenerator","BaseGenerator","nodeName","tag","key","value","shouldWatch","expression","eventName","dynamic","event","attribute","HTMLPropGenerator","__publicField","HTMLGenerator","HTMLPropGenerator","tag","propsWithView","children","props","generateView","nodeName","statement","tagName","key","prop","child","childNodeName","childStatements","generateNew","name","parent","TemplateGenerator","HTMLPropGenerator","template","mutableUnits","props","templateName","nodeName","statement","paths","path","insertElementStatements","pathNameMap","tag","key","value","name","tagName","unit","parentName","nextName","childName","childStatements","generateNew","statements","returnStatement","parent","child","nextNode","dlNodeName","offset","newNodeName","acc","addFirstChild","object","addSecondChild","addThirdChild","addOtherChild","num","addNextSibling","cur","idx","i","collect","nameMap","res","pat","allPaths","ps","path0","path1","sortedPaths","a","b","defaultName","bestMatchCount","bestMatchName","bestHalfMatch","matchCount","pathLength","TextGenerator","BaseGenerator","content","nodeName","statement","name","ExpressionGenerator","BaseGenerator","contentWithProp","content","generateView","nodeName","statement","expression","name","viewGeneratorMap","HTMLGenerator","CompGenerator","TemplateGenerator","TextGenerator","ExpressionGenerator","generateNew","oldGenerator","viewUnit","resetIdx","generator","name","statements","templates","generateBlock","viewUnits","config","t","names","returnStatement","generateView","templateIdx","allTemplates","nodeIdx"]} \ No newline at end of file diff --git a/packages/transpiler/jsx-view-generator/dist/index.d.ts b/packages/transpiler/jsx-view-generator/dist/index.d.ts deleted file mode 100644 index e21dbd93227c477968ad7fdee2acd8eafd023819..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-generator/dist/index.d.ts +++ /dev/null @@ -1,217 +0,0 @@ -import { ViewUnit, UnitProp } from '@inula/jsx-view-parser'; -import Babel, { types, traverse } from '@babel/core'; - -interface ViewGeneratorConfig { - babelApi: typeof Babel; - importMap: Record; - /** - * @brief Using AttributeMap to identify propertyfied attributes - * Reason for adding this: - * `el.prop = xxx` is faster than `el.setAttribute('prop', xxx)` - * @example { href: ["a", "area", "base", "link"], id: ["*"] } - */ - attributeMap?: Record; -} - -declare class BaseGenerator { - readonly viewUnit: ViewUnit; - readonly config: ViewGeneratorConfig; - readonly t: typeof types; - readonly traverse: typeof traverse; - readonly elementAttributeMap: Record; - readonly importMap: Record; - constructor(viewUnit: ViewUnit, config: ViewGeneratorConfig); - private readonly initStatements; - addStatement(...statements: types.Statement[]): void; - private readonly templates; - addTemplate(...template: types.Statement[]): void; - /** - * @brief To be implemented by the subclass - */ - run(): string; - generate(): [string, types.Statement[], types.Statement[]]; - /** - * @brief Check if the expression is reactive, which satisfies the following conditions: - * 1. Contains .get() property - * 2. The whole expression is not a function - * @param expression - * @returns - */ - checkReactive(expression: types.Expression): boolean; - private readonly prefixMap; - nodeIdx: number; - geneNodeName(idx?: number): string; - templateIdx: number; - generateTemplateName(): string; - /** - * @brief Wrap the value in a file - * @param node - * @returns wrapped value - */ - wrapWithFile(node: types.Expression): types.File; - addWatch(value: types.Expression): types.CallExpression; - createCollector(): [types.Statement[], (statement: types.Statement | types.Statement[] | null) => void]; - parseViewProp(prop: UnitProp, generateView: (units: ViewUnit[], config: ViewGeneratorConfig, templateIdx: number) => [types.Statement[], types.ExpressionStatement]): types.Expression; - parseProps(props: Record, generateView: (units: ViewUnit[], config: ViewGeneratorConfig) => [types.Statement[], types.ExpressionStatement]): { - [k: string]: types.Expression; - }; -} - -declare class CompGenerator extends BaseGenerator { - run(): string; - /** - * @View - * const $el = createComponent(tag, { - * ...props - * }, spreadProps) - */ - declareCompNode(tag: types.Expression, props: Record, children: ViewUnit[]): [string, types.Statement]; -} - -declare class HTMLPropGenerator extends BaseGenerator { - static DelegatedEvents: Set; - addHTMLProp(nodeName: string, tag: string, key: string, value: types.Expression): types.Statement; - /** - * @View - * setStyle($node, value) - */ - private setStyle; - /** - * @View - * setDataset($node, value) - */ - private setDataset; - /** - * @View - * $node.key = value - */ - private setStaticProperty; - /** - * @View - * setProperty($node, key, value) - */ - private setDynamicProperty; - /** - * @View - * $node.setAttribute(key, value) - */ - private setStaticAttribute; - /** - * @View - * setAttribute($node, key, value) - */ - private setDynamicAttribute; - /** - * @View - * delegateEvent($node, eventName, value) - */ - private setDelegatedEvent; - /** - * @View - * $node.addEventListener(eventName, value) - */ - private setStaticEvent; - /** - * @View - * addEventListener($node, eventName, value) - */ - private setDynamicEvent; - private setDynamicHTMLProp; - /** - * @brief Check if the attribute is internal, i.e., can be accessed as js property - * @param tag - * @param attribute - * @returns true if the attribute is internal - */ - isInternalAttribute(tag: string, attribute: string): boolean; -} - -declare class HTMLGenerator extends HTMLPropGenerator { - run(): string; - /** - * @View - * const $el = createElement(tag) - */ - declareHTMLNode(tag: types.Expression): [string, types.Statement]; - /** - * @View - * $insert($el, childNode) - */ - private insertChildNode; -} - -declare class TemplateGenerator extends HTMLPropGenerator { - run(): string; - private generateTemplate; - /** - * @View - * const $el = template.cloneNode(true) - */ - private declareTemplateNode; - /** - * @View - * $insert($el, childNode) - */ - private insertChildNode; - /** - * @View - * ${dlNodeName}.firstChild - * or - * ${dlNodeName}.firstChild.nextSibling - * or - * ... - * ${dlNodeName}.childNodes[${num}] - */ - private insertElement; - /** - * @brief Insert elements to the template node from the paths - * @param paths - * @param dlNodeName - * @returns - */ - private insertElements; - /** - * @brief Extract common prefix from paths - * e.g. - * [0, 1, 2, 3] + [0, 1, 2, 4] => [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 4] - * [0, 1, 2] is the common prefix - * @param paths - * @returns paths with common prefix - */ - private static pathWithCommonPrefix; - /** - * @brief Find the best node name and path for the given path by looking into the nameMap. - * If there's a full match, return the name and an empty path - * If there's a partly match, return the name and the remaining path - * If there's a nextSibling match, return the name and the remaining path with sibling offset - * @param nameMap - * @param path - * @param defaultName - * @returns [name, path, siblingOffset] - */ - private static findBestNodeAndPath; -} - -declare class TextGenerator extends BaseGenerator { - run(): string; - declareTextNode(content: types.Literal): [string, types.Statement]; -} - -declare class ExpressionGenerator extends BaseGenerator { - run(): string; - declareExpressionNode(expression: types.Expression): [string, types.Statement]; -} - -declare const viewGeneratorMap: { - readonly html: typeof HTMLGenerator; - readonly comp: typeof CompGenerator; - readonly template: typeof TemplateGenerator; - readonly text: typeof TextGenerator; - readonly exp: typeof ExpressionGenerator; - readonly if: typeof CompGenerator; - readonly env: typeof CompGenerator; -}; -declare function generateNew(oldGenerator: any, viewUnit: ViewUnit, resetIdx?: boolean): [string, types.Statement[], types.Statement[]]; -declare function generateView(viewUnits: ViewUnit[], config: ViewGeneratorConfig, templateIdx?: number): [types.Statement[], types.ExpressionStatement]; - -export { ViewGeneratorConfig, generateNew, generateView, viewGeneratorMap }; diff --git a/packages/transpiler/jsx-view-generator/dist/index.js b/packages/transpiler/jsx-view-generator/dist/index.js deleted file mode 100644 index 524a166df820944a015cdde90e462394b167d535..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-generator/dist/index.js +++ /dev/null @@ -1,2 +0,0 @@ -var C=Object.defineProperty;var V=(c,t,e)=>t in c?C(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var D=(c,t,e)=>(V(c,typeof t!="symbol"?t+"":t,e),e);var d=class{viewUnit;config;t;traverse;elementAttributeMap;importMap;constructor(t,e){this.config=e,this.t=e.babelApi.types,this.traverse=e.babelApi.traverse,this.importMap=e.importMap,this.viewUnit=t,this.elementAttributeMap=e.attributeMap?Object.entries(e.attributeMap).reduce((i,[s,o])=>(o.forEach(r=>{i[r]||(i[r]=[]),i[r].push(s)}),i),{}):{}}initStatements=[];addStatement(...t){this.initStatements.push(...t)}templates=[];addTemplate(...t){this.templates.push(...t)}run(){return""}generate(){return[this.run(),this.initStatements,this.templates]}checkReactive(t){if(this.t.isFunction(t))return!1;let e=!1;return this.traverse(this.wrapWithFile(t),{MemberExpression:i=>{this.t.isIdentifier(i.node.property,{name:"get"})&&(e=!0,i.stop())}}),e}prefixMap={node:"$node",template:"$template"};nodeIdx=-1;geneNodeName(t){return`${this.prefixMap.node}${t??++this.nodeIdx}`}templateIdx=-1;generateTemplateName(){return`${this.prefixMap.template}${++this.templateIdx}`}wrapWithFile(t){return this.t.file(this.t.program([this.t.expressionStatement(t)]))}addWatch(t){return this.t.callExpression(this.t.identifier(this.importMap.watch),[this.t.arrowFunctionExpression([],t)])}createCollector(){let t=[];function e(i){Array.isArray(i)?t.push(...i):i&&t.push(i)}return[t,e]}parseViewProp(t,e){let i=t.value,s=t.viewPropMap,o=Object.fromEntries(Object.entries(s).map(([r,a])=>{let[p,m]=e(a,this.config,this.templateIdx);return this.addTemplate(...p),[r,m]}));return this.traverse(this.wrapWithFile(i),{StringLiteral:r=>{let a=r.node.value;o[a]&&(this.t.isNodesEquivalent(i,r.node)&&(i=o[a].expression),r.replaceWith(o[a]))}}),i}parseProps(t,e){return Object.fromEntries(Object.entries(t).map(([i,s])=>[i,this.parseViewProp(s,e)]))}};var b=class extends d{run(){let{tag:t,props:e,children:i}=this.viewUnit,s=this.parseProps(e,u),[o,r]=this.declareCompNode(t,s,i);return this.addStatement(r),o}declareCompNode(t,e,i){let s=this.geneNodeName(),o=[];if(Object.keys(e).length>0||i.length>0){let r=this.t.objectExpression(Object.entries(e).map(([a,p])=>this.checkReactive(p)?this.t.objectMethod("get",this.t.identifier(a),[],this.t.blockStatement([this.t.returnStatement(p)])):this.t.objectProperty(this.t.identifier(a),p)));if(i.length>0){let a=U(i,this.config);r.properties.push(this.t.objectMethod("get",this.t.identifier("children"),[],a))}o.push(r)}return[s,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(s),this.t.callExpression(this.t.identifier(this.importMap.createComponent),[t,...o]))])]}};var P=class extends d{addHTMLProp(t,e,i,s){let o=this.checkReactive(s),r=this.setDynamicHTMLProp(t,e,i,s,o);return o&&(r=this.addWatch(r)),this.t.expressionStatement(r)}setStyle(t,e){return this.t.callExpression(this.t.identifier(this.importMap.setStyle),[this.t.identifier(t),e])}setDataset(t,e){return this.t.callExpression(this.t.identifier(this.importMap.setDataset),[this.t.identifier(t),e])}setStaticProperty(t,e,i){return this.t.assignmentExpression("=",this.t.memberExpression(this.t.identifier(t),this.t.identifier(e)),i)}setDynamicProperty(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.setProperty),[this.t.identifier(t),this.t.stringLiteral(e),i])}setStaticAttribute(t,e,i){return this.t.callExpression(this.t.memberExpression(this.t.identifier(t),this.t.identifier("setAttribute")),[this.t.stringLiteral(e),i])}setDynamicAttribute(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.setAttribute),[this.t.identifier(t),this.t.stringLiteral(e),i])}setDelegatedEvent(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.delegateEvent),[this.t.identifier(t),this.t.stringLiteral(e),i])}setStaticEvent(t,e,i){return this.t.callExpression(this.t.memberExpression(this.t.identifier(t),this.t.identifier("addEventListener")),[this.t.stringLiteral(e),i])}setDynamicEvent(t,e,i){return this.t.callExpression(this.t.identifier(this.importMap.addEventListener),[this.t.identifier(t),this.t.stringLiteral(e),i])}setDynamicHTMLProp(t,e,i,s,o){if(i==="style")return this.setStyle(t,s);if(i==="dataset")return this.setDataset(t,s);if(i.startsWith("on")){let r=i.slice(2).toLowerCase();return P.DelegatedEvents.has(r)?this.setDelegatedEvent(t,r,s):this[o?"setDynamicEvent":"setStaticEvent"](t,r,s)}return this.isInternalAttribute(e,i)?(i==="class"?i="className":i==="for"&&(i="htmlFor"),this[o?"setDynamicProperty":"setStaticProperty"](t,i,s)):this[o?"setDynamicAttribute":"setStaticAttribute"](t,i,s)}isInternalAttribute(t,e){return this.elementAttributeMap["*"]?.includes(e)||this.elementAttributeMap[t]?.includes(e)}},g=P;D(g,"DelegatedEvents",new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]));var S=class extends g{run(){let{tag:t,props:e,children:i}=this.viewUnit,s=this.parseProps(e,u),[o,r]=this.declareHTMLNode(t);this.addStatement(r);let a=this.t.isStringLiteral(t)?t.value:"ANY";return Object.entries(s).forEach(([p,m])=>{this.addStatement(this.addHTMLProp(o,a,p,m))}),i.forEach(p=>{let[m,n]=E(this,p);this.addStatement(...n),this.addStatement(this.insertChildNode(o,m))}),o}declareHTMLNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.callExpression(this.t.identifier("createElement"),[t]))])]}insertChildNode(t,e){return this.t.expressionStatement(this.t.callExpression(this.t.identifier(this.importMap.insert),[this.t.identifier(t),this.t.identifier(e)]))}};var x=class extends g{run(){let{template:t,mutableUnits:e,props:i}=this.viewUnit,s=this.generateTemplate(t),[o,r]=this.declareTemplateNode(s);this.addStatement(r);let a=[];i.forEach(({path:n})=>{a.push(n)}),e.forEach(({path:n})=>{a.push(n.slice(0,-1)),n[n.length-1]!==-1&&a.push(n)});let[p,m]=this.insertElements(a,o);return this.addStatement(...p),i.forEach(({tag:n,path:h,key:l,value:f})=>{let y=m[h.join(".")],M=this.t.isStringLiteral(n)?n.value:"ANY";this.addStatement(this.addHTMLProp(y,M,l,f))}),e.forEach(n=>{let h=n.path,l=m[h.slice(0,-1).join(".")],f=m[h.join(".")];console.log(f,h);let[y,M]=E(this,n);this.addStatement(...M),this.addStatement(this.insertChildNode(l,y,f))}),o}generateTemplate(t){let e=this.generateTemplateName(),[i,s]=E(this,t,!1),o=this.t.returnStatement(this.t.identifier(i));return this.addTemplate(this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.arrowFunctionExpression([],this.t.blockStatement([...s,o])))])),e}declareTemplateNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.callExpression(this.t.memberExpression(this.t.identifier(t),this.t.identifier("cloneNode")),[this.t.identifier("true")]))])]}insertChildNode(t,e,i){let s=i?[this.t.identifier(i)]:[];return this.t.expressionStatement(this.t.callExpression(this.t.identifier(this.importMap.insert),[this.t.identifier(t),this.t.identifier(e),...s]))}insertElement(t,e,i){let s=this.geneNodeName();if(e.length===0)return this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(s),Array.from({length:i}).reduce(n=>this.t.memberExpression(n,this.t.identifier("nextSibling")),this.t.identifier(t)))]);let o=n=>this.t.memberExpression(n,this.t.identifier("firstChild")),r=n=>this.t.memberExpression(o(n),this.t.identifier("nextSibling")),a=n=>this.t.memberExpression(r(n),this.t.identifier("nextSibling")),p=(n,h)=>this.t.memberExpression(this.t.memberExpression(n,this.t.identifier("childNodes")),this.t.numericLiteral(h),!0),m=n=>this.t.memberExpression(n,this.t.identifier("nextSibling"));return this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(s),e.reduce((n,h,l)=>{if(l===0&&i>0)for(let f=0;f{let m=x.findBestNodeAndPath(o,p,e),[,n,h]=m,l=m[0];(n.length!==0||h!==0)&&(s(this.insertElement(l,n,h)),l=this.geneNodeName(this.nodeIdx),o[l]=p)});let a=Object.fromEntries(Object.entries(o).map(([p,m])=>[m.join("."),p]));return[i,a]}static pathWithCommonPrefix(t){let e=[...t].sort(),i=[...e];i.forEach(r=>{i.forEach(a=>{if(r!==a){for(let p=0;pr.length!==a.length?r.length-a.length:r[0]-a[0]);return[...new Set(s.map(r=>r.join(".")))].map(r=>r.split(".").filter(Boolean).map(Number))}static findBestNodeAndPath(t,e,i){let s=0,o,r;return Object.entries(t).forEach(([a,p])=>{let m=0,n=p.length;for(let h=0;h0&&h<=3&&(r=[a,m,h])}m===p.length&&m>s&&(o=a,s=m)}),r?[r[0],e.slice(r[1]+1),r[2]]:o?[o,e.slice(s),0]:[i,e,0]}};var v=class extends d{run(){let{content:t}=this.viewUnit,[e,i]=this.declareTextNode(t);return this.addStatement(i),e}declareTextNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),this.t.callExpression(this.t.identifier(this.importMap.createText),[t]))])]}};var N=class extends d{run(){let{content:t}=this.viewUnit,e=this.parseViewProp(t,u),[i,s]=this.declareExpressionNode(e);return this.addStatement(s),i}declareExpressionNode(t){let e=this.geneNodeName();return[e,this.t.variableDeclaration("const",[this.t.variableDeclarator(this.t.identifier(e),t)])]}};var w={html:S,comp:b,template:x,text:v,exp:N,if:b,env:b};function E(c,t,e=!0){let i=new w[t.type](t,c.config);e&&(i.nodeIdx=c.nodeIdx);let[s,o,r]=i.generate();return e&&(c.nodeIdx=i.nodeIdx),[s,o,r]}function U(c,t){let e=t.babelApi.types,i=[],s=c.flatMap(r=>{let a=new w[r.type](r,t),[p,m]=a.generate();return i.push(p),m}),o=e.returnStatement(e.arrayExpression(i.map(r=>e.identifier(r))));return e.blockStatement(s.concat(o))}function u(c,t,e=-1){let i=t.babelApi.types,s=[],o=[],r=-1,a=c.flatMap(m=>{let n=new w[m.type](m,t);n.templateIdx=e,n.nodeIdx=r;let[h,l,f]=n.generate();return e=n.templateIdx,r=n.nodeIdx,s.push(h),o.push(...f),l}),p=i.returnStatement(i.arrayExpression(s.map(m=>i.identifier(m))));return[o,i.expressionStatement(i.callExpression(i.arrowFunctionExpression([],i.blockStatement(a.concat(p))),[]))]}export{E as generateNew,u as generateView,w as viewGeneratorMap}; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/transpiler/jsx-view-generator/dist/index.js.map b/packages/transpiler/jsx-view-generator/dist/index.js.map deleted file mode 100644 index defd0524539f6717714916ba54f295d17989ab0a..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-generator/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/HelperGenerators/BaseGenerator.ts","../src/NodeGenerators/CompGenerator.ts","../src/HelperGenerators/HTMLPropGenerator.ts","../src/NodeGenerators/HTMLGenerator.ts","../src/NodeGenerators/TemplateGenerator.ts","../src/NodeGenerators/TextGenerator.ts","../src/NodeGenerators/ExpressionGenerator.ts","../src/generate.ts"],"sourcesContent":["import { UnitProp, ViewUnit } from '@inula/jsx-view-parser';\nimport { ViewGeneratorConfig } from '../types';\nimport type { types as t, traverse } from '@babel/core';\n\n\nexport default class BaseGenerator {\n readonly viewUnit: ViewUnit\n readonly config: ViewGeneratorConfig\n readonly t\n readonly traverse: typeof traverse\n readonly elementAttributeMap\n readonly importMap\n\n constructor(viewUnit: ViewUnit, config: ViewGeneratorConfig) {\n this.config = config;\n this.t = config.babelApi.types;\n this.traverse = config.babelApi.traverse;\n this.importMap = config.importMap;\n this.viewUnit = viewUnit;\n this.elementAttributeMap = config.attributeMap\n ? Object.entries(config.attributeMap).reduce>(\n (acc, [key, elements]) => {\n elements.forEach(element => {\n if (!acc[element]) acc[element] = [];\n acc[element].push(key);\n });\n return acc;\n },\n {}\n )\n : {};\n }\n\n // ---- Init Statements\n private readonly initStatements: t.Statement[] = []\n addStatement(...statements: t.Statement[]) {\n this.initStatements.push(...statements);\n }\n\n private readonly templates: t.Statement[] = []\n addTemplate(...template: t.Statement[]) {\n this.templates.push(...template);\n }\n\n // ---- Generate ----\n /**\n * @brief To be implemented by the subclass\n */\n run(): string {\n return ''; \n }\n\n generate(): [string, t.Statement[], t.Statement[]]{\n const nodeName = this.run();\n return [nodeName, this.initStatements, this.templates];\n }\n \n // ---- Reactivity ----\n /**\n * @brief Check if the expression is reactive, which satisfies the following conditions:\n * 1. Contains .get() property\n * 2. The whole expression is not a function\n * @param expression \n * @returns \n */\n checkReactive(expression: t.Expression) {\n if (this.t.isFunction(expression)) return false;\n let reactive = false;\n this.traverse(this.wrapWithFile(expression), {\n MemberExpression: path => {\n if (this.t.isIdentifier(path.node.property, { name: 'get' })) {\n reactive = true;\n path.stop();\n }\n }\n });\n return reactive;\n }\n\n // ---- Names ----\n private readonly prefixMap = {\n node: '$node',\n template: '$template',\n }\n\n nodeIdx = -1;\n geneNodeName(idx?: number): string {\n return `${this.prefixMap.node}${idx ?? ++this.nodeIdx}`;\n }\n templateIdx = -1;\n generateTemplateName() {\n return `${this.prefixMap.template}${++this.templateIdx}`;\n }\n\n\n // ---- Utils ----\n /**\n * @brief Wrap the value in a file\n * @param node\n * @returns wrapped value\n */\n wrapWithFile(node: t.Expression): t.File {\n return this.t.file(this.t.program([this.t.expressionStatement(node)]));\n }\n\n addWatch(value: t.Expression) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.watch),\n [this.t.arrowFunctionExpression([], value)]\n );\n }\n\n createCollector(): [t.Statement[], (statement: t.Statement | t.Statement[] | null) => void]{\n const statements: t.Statement[] = [];\n function collect(statement: t.Statement | t.Statement[] | null) {\n if (Array.isArray(statement)) {\n statements.push(...statement);\n } else if (statement) {\n statements.push(statement);\n }\n }\n return [statements, collect];\n }\n\n parseViewProp(prop: UnitProp, generateView: (units: ViewUnit[], config: ViewGeneratorConfig, templateIdx: number) => [t.Statement[], t.ExpressionStatement]): t.Expression {\n let value = prop.value;\n const viewPropMap = prop.viewPropMap;\n const propNodeMap = Object.fromEntries(\n Object.entries(viewPropMap).map(([key, units]) => {\n const [templates, statement] = generateView(units, this.config, this.templateIdx);\n this.addTemplate(...templates);\n return [key, statement];\n })\n );\n\n this.traverse(this.wrapWithFile(value), {\n StringLiteral: path => {\n const key = path.node.value;\n if (propNodeMap[key]) {\n if (this.t.isNodesEquivalent(value, path.node)) {\n value = (propNodeMap[key] as t.ExpressionStatement).expression;\n }\n path.replaceWith(propNodeMap[key]);\n }\n }\n });\n \n return value;\n }\n\n parseProps(props: Record, generateView: (units: ViewUnit[], config: ViewGeneratorConfig) => [t.Statement[], t.ExpressionStatement]) {\n return Object.fromEntries(\n Object.entries(props).map(([key, prop]) => {\n return [key, this.parseViewProp(prop, generateView)];\n })\n );\n }\n}\n","import { CompUnit, ViewUnit } from '@inula/jsx-view-parser';\nimport BaseGenerator from '../HelperGenerators/BaseGenerator';\nimport type { types as t } from '@babel/core';\nimport { generateBlock, generateView } from '../generate';\n\nexport class CompGenerator extends BaseGenerator {\n run(): string {\n const { tag, props: propsWithView, children } = this.viewUnit as CompUnit;\n const props = this.parseProps(propsWithView, generateView);\n\n const [nodeName, statement] = this.declareCompNode(tag, props, children);\n this.addStatement(statement);\n\n return nodeName;\n }\n\n /**\n * @View\n * const $el = createComponent(tag, {\n * ...props\n * }, spreadProps)\n */\n declareCompNode(tag: t.Expression, props: Record, children: ViewUnit[]): [string, t.Statement] {\n const name = this.geneNodeName();\n const nodes = [];\n if (Object.keys(props).length > 0 || children.length > 0) {\n const propNode = this.t.objectExpression(Object.entries(props).map(([key, value]) => {\n const isReactive = this.checkReactive(value);\n if (isReactive) {\n /**\n * @View\n * get reactiveValue() {\n * return value\n * }\n */\n return (\n this.t.objectMethod('get', this.t.identifier(key), [],\n this.t.blockStatement([\n this.t.returnStatement(value)\n ])\n )\n );\n }\n return this.t.objectProperty(\n this.t.identifier(key),\n value\n );\n }));\n if (children.length > 0) {\n const statement = generateBlock(children, this.config);\n propNode.properties.push(\n this.t.objectMethod('get', this.t.identifier('children'), [], statement)\n );\n }\n nodes.push(propNode);\n }\n\n\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.identifier(this.importMap.createComponent),\n [tag, ...nodes]\n )\n )\n ])];\n }\n}","import BaseGenerator from './BaseGenerator';\nimport type { types as t } from '@babel/core';\n\nexport class HTMLPropGenerator extends BaseGenerator {\n static DelegatedEvents = new Set([\n 'beforeinput',\n 'click',\n 'dblclick',\n 'contextmenu',\n 'focusin',\n 'focusout',\n 'input',\n 'keydown',\n 'keyup',\n 'mousedown',\n 'mousemove',\n 'mouseout',\n 'mouseover',\n 'mouseup',\n 'pointerdown',\n 'pointermove',\n 'pointerout',\n 'pointerover',\n 'pointerup',\n 'touchend',\n 'touchmove',\n 'touchstart',\n ])\n\n addHTMLProp(\n nodeName: string, \n tag: string,\n key: string,\n value: t.Expression,\n ): t.Statement {\n const shouldWatch = this.checkReactive(value);\n let expression = this.setDynamicHTMLProp(nodeName, tag, key, value, shouldWatch);\n if (shouldWatch) expression = this.addWatch(expression);\n\n return this.t.expressionStatement(expression);\n }\n\n /**\n * @View\n * setStyle($node, value)\n */\n private setStyle(\n nodeName: string, \n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setStyle),\n [this.t.identifier(nodeName), value]\n );\n }\n\n /**\n * @View\n * setDataset($node, value)\n */\n private setDataset(\n nodeName: string, \n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setDataset),\n [this.t.identifier(nodeName), value]\n );\n }\n\n /**\n * @View\n * $node.key = value\n */\n private setStaticProperty(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.assignmentExpression(\n '=',\n this.t.memberExpression(\n this.t.identifier(nodeName),\n this.t.identifier(key),\n ),\n value\n );\n }\n\n /**\n * @View\n * setProperty($node, key, value)\n */\n private setDynamicProperty(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setProperty),\n [this.t.identifier(nodeName), this.t.stringLiteral(key), value]\n );\n }\n\n /**\n * @View\n * $node.setAttribute(key, value)\n */\n private setStaticAttribute(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.memberExpression(\n this.t.identifier(nodeName),\n this.t.identifier('setAttribute'),\n ),\n [this.t.stringLiteral(key), value]\n );\n }\n\n\n /**\n * @View\n * setAttribute($node, key, value)\n */\n private setDynamicAttribute(\n nodeName: string, \n key: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.setAttribute),\n [this.t.identifier(nodeName), this.t.stringLiteral(key), value]\n );\n }\n\n /**\n * @View\n * delegateEvent($node, eventName, value)\n */\n private setDelegatedEvent(\n nodeName: string, \n eventName: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.delegateEvent),\n [this.t.identifier(nodeName), this.t.stringLiteral(eventName), value]\n );\n }\n\n /**\n * @View\n * $node.addEventListener(eventName, value)\n */\n private setStaticEvent(\n nodeName: string, \n eventName: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.memberExpression(\n this.t.identifier(nodeName),\n this.t.identifier('addEventListener'),\n ),\n [this.t.stringLiteral(eventName), value]\n );\n }\n\n /**\n * @View\n * addEventListener($node, eventName, value)\n */\n private setDynamicEvent(\n nodeName: string, \n eventName: string,\n value: t.Expression,\n ) {\n return this.t.callExpression(\n this.t.identifier(this.importMap.addEventListener),\n [this.t.identifier(nodeName), this.t.stringLiteral(eventName), value]\n );\n }\n\n private setDynamicHTMLProp(\n nodeName: string, \n tag: string,\n key: string,\n value: t.Expression,\n dynamic: boolean\n ): t.Expression {\n if (key === 'style') return this.setStyle(nodeName, value);\n if (key === 'dataset') return this.setDataset(nodeName, value);\n if (key.startsWith('on')) {\n const event = key.slice(2).toLowerCase();\n if (HTMLPropGenerator.DelegatedEvents.has(event)) {\n return this.setDelegatedEvent(nodeName, event, value);\n }\n return this[dynamic ? 'setDynamicEvent' : 'setStaticEvent'](nodeName, event, value);\n }\n if (this.isInternalAttribute(tag, key)) {\n if (key === 'class') key = 'className';\n else if (key === 'for') key = 'htmlFor';\n return this[dynamic ? 'setDynamicProperty' : 'setStaticProperty'](nodeName, key, value);\n }\n return this[dynamic ? 'setDynamicAttribute' : 'setStaticAttribute'](nodeName, key, value);\n }\n\n /**\n * @brief Check if the attribute is internal, i.e., can be accessed as js property\n * @param tag\n * @param attribute\n * @returns true if the attribute is internal\n */\n isInternalAttribute(tag: string, attribute: string): boolean {\n return (\n this.elementAttributeMap['*']?.includes(attribute) ||\n this.elementAttributeMap[tag]?.includes(attribute)\n );\n }\n}","import { HTMLUnit } from '@inula/jsx-view-parser';\nimport type { types as t } from '@babel/core';\nimport { HTMLPropGenerator } from '../HelperGenerators/HTMLPropGenerator';\nimport { generateNew, generateView } from '../generate';\n\nexport class HTMLGenerator extends HTMLPropGenerator {\n run(){\n const { tag, props: propsWithView, children } = this.viewUnit as HTMLUnit;\n const props = this.parseProps(propsWithView, generateView);\n const [nodeName, statement] = this.declareHTMLNode(tag);\n this.addStatement(statement);\n\n // ---- Use the tag name to check if the prop is internal for the tag,\n // for dynamic tag, we can't check it, so we just assume it's not internal\n // represent by the \"ANY\" tag name\n const tagName = this.t.isStringLiteral(tag) ? tag.value : 'ANY';\n\n Object.entries(props).forEach(([key, prop]) => {\n this.addStatement(this.addHTMLProp(nodeName, tagName, key, prop));\n });\n\n children.forEach(child => {\n const [childNodeName, childStatements] = generateNew(this, child);\n this.addStatement(...childStatements);\n this.addStatement(this.insertChildNode(nodeName, childNodeName));\n });\n\n return nodeName;\n }\n\n /**\n * @View \n * const $el = createElement(tag)\n */\n declareHTMLNode(tag: t.Expression): [string, t.Statement] {\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.identifier('createElement'),\n [tag]\n )\n )\n ])];\n }\n\n /**\n * @View\n * $insert($el, childNode)\n */\n private insertChildNode(\n parent: string, \n child: string\n ) {\n return this.t.expressionStatement(\n this.t.callExpression(\n this.t.identifier(this.importMap.insert),\n [this.t.identifier(parent), this.t.identifier(child)]\n )\n );\n }\n}","import { HTMLUnit, TemplateUnit } from '@inula/jsx-view-parser';\nimport { HTMLPropGenerator } from '../HelperGenerators/HTMLPropGenerator';\nimport { generateNew } from '../generate';\nimport type { types as t } from '@babel/core';\n\n\nexport class TemplateGenerator extends HTMLPropGenerator{\n run(): string {\n const { template, mutableUnits, props } = this.viewUnit as TemplateUnit;\n\n const templateName = this.generateTemplate(template);\n const [nodeName, statement] = this.declareTemplateNode(templateName);\n this.addStatement(statement);\n\n // ---- Insert elements first\n const paths: number[][] = [];\n props.forEach(({ path }) => {\n paths.push(path);\n });\n mutableUnits.forEach(({ path }) => {\n // ---- ParentPath and NextPath\n paths.push(path.slice(0, -1));\n if (path[path.length - 1] !== -1) paths.push(path);\n });\n const [insertElementStatements, pathNameMap] = this.insertElements(\n paths,\n nodeName\n );\n\n this.addStatement(...insertElementStatements);\n\n // ---- Resolve props\n props.forEach(\n ({\n tag,\n path,\n key,\n value,\n }) => {\n const name = pathNameMap[path.join('.')];\n\n const tagName = this.t.isStringLiteral(tag) ? tag.value : 'ANY';\n this.addStatement(\n this.addHTMLProp(\n name,\n tagName,\n key,\n value,\n )\n );\n }\n );\n\n // ---- Resolve mutable units\n mutableUnits.forEach(unit => {\n const path = unit.path;\n // ---- Find parent htmlElement\n const parentName = pathNameMap[path.slice(0, -1).join('.')];\n const nextName = pathNameMap[path.join('.')];\n console.log(nextName, path);\n const [childName, childStatements] = generateNew(this, unit);\n this.addStatement(...childStatements);\n this.addStatement(this.insertChildNode(parentName, childName, nextName));\n });\n\n\n return nodeName;\n }\n\n private generateTemplate(template: HTMLUnit): string {\n const templateName = this.generateTemplateName();\n const [name, statements] = generateNew(this, template, false);\n const returnStatement = this.t.returnStatement(this.t.identifier(name));\n\n this.addTemplate(\n this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(templateName),\n this.t.arrowFunctionExpression([], this.t.blockStatement([...statements, returnStatement]))\n )\n ])\n );\n\n return templateName;\n }\n\n /**\n * @View\n * const $el = template.cloneNode(true)\n */\n private declareTemplateNode(templateName: string): [string, t.Statement]{\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.memberExpression(\n this.t.identifier(templateName),\n this.t.identifier('cloneNode')\n ), [this.t.identifier('true')]\n )\n )\n ])];\n }\n\n /**\n * @View\n * $insert($el, childNode)\n */\n private insertChildNode(\n parent: string, \n child: string,\n nextName: string\n ) {\n const nextNode = nextName ? [this.t.identifier(nextName)] : [];\n return this.t.expressionStatement(\n this.t.callExpression(\n this.t.identifier(this.importMap.insert),\n [this.t.identifier(parent), this.t.identifier(child), ...nextNode]\n )\n );\n }\n\n\n /**\n * @View\n * ${dlNodeName}.firstChild\n * or\n * ${dlNodeName}.firstChild.nextSibling\n * or\n * ...\n * ${dlNodeName}.childNodes[${num}]\n */\n private insertElement(\n dlNodeName: string,\n path: number[],\n offset: number\n ): t.Statement {\n const newNodeName = this.geneNodeName();\n if (path.length === 0) {\n return this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(newNodeName),\n Array.from({ length: offset }).reduce(\n (acc: t.Expression) =>\n this.t.memberExpression(acc, this.t.identifier('nextSibling')),\n this.t.identifier(dlNodeName)\n )\n )\n ]);\n }\n const addFirstChild = (object: t.Expression) =>\n // ---- ${object}.firstChild\n this.t.memberExpression(object, this.t.identifier('firstChild'));\n const addSecondChild = (object: t.Expression) =>\n // ---- ${object}.firstChild.nextSibling\n this.t.memberExpression(\n addFirstChild(object),\n this.t.identifier('nextSibling')\n );\n const addThirdChild = (object: t.Expression) =>\n // ---- ${object}.firstChild.nextSibling.nextSibling\n this.t.memberExpression(\n addSecondChild(object),\n this.t.identifier('nextSibling')\n );\n const addOtherChild = (object: t.Expression, num: number) =>\n // ---- ${object}.childNodes[${num}]\n this.t.memberExpression(\n this.t.memberExpression(object, this.t.identifier('childNodes')),\n this.t.numericLiteral(num),\n true\n );\n const addNextSibling = (object: t.Expression) =>\n // ---- ${object}.nextSibling\n this.t.memberExpression(object, this.t.identifier('nextSibling'));\n\n return this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(newNodeName),\n path.reduce((acc: t.Expression, cur: number, idx) => {\n if (idx === 0 && offset > 0) {\n for (let i = 0; i < offset; i++) acc = addNextSibling(acc);\n }\n if (cur === 0) return addFirstChild(acc);\n if (cur === 1) return addSecondChild(acc);\n if (cur === 2) return addThirdChild(acc);\n return addOtherChild(acc, cur);\n }, this.t.identifier(dlNodeName))\n )\n ]);\n }\n\n /**\n * @brief Insert elements to the template node from the paths\n * @param paths\n * @param dlNodeName\n * @returns\n */\n private insertElements(\n paths: number[][],\n dlNodeName: string\n ): [t.Statement[], Record] {\n const [statements, collect] = this.createCollector();\n const nameMap: Record = { [dlNodeName]: [] };\n\n const commonPrefixPaths = TemplateGenerator.pathWithCommonPrefix(paths);\n\n commonPrefixPaths.forEach(path => {\n const res = TemplateGenerator.findBestNodeAndPath(\n nameMap,\n path,\n dlNodeName\n );\n const [, pat, offset] = res;\n let name = res[0];\n\n if (pat.length !== 0 || offset !== 0) {\n collect(this.insertElement(name, pat, offset));\n name = this.geneNodeName(this.nodeIdx);\n nameMap[name] = path;\n }\n });\n const pathNameMap = Object.fromEntries(\n Object.entries(nameMap).map(([name, path]) => [path.join('.'), name])\n );\n\n return [statements, pathNameMap];\n }\n\n // ---- Path related\n /**\n * @brief Extract common prefix from paths\n * e.g.\n * [0, 1, 2, 3] + [0, 1, 2, 4] => [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 4]\n * [0, 1, 2] is the common prefix\n * @param paths\n * @returns paths with common prefix\n */\n private static pathWithCommonPrefix(paths: number[][]): number[][] {\n const allPaths = [...paths].sort();\n const ps = [...allPaths];\n ps.forEach(path0 => {\n ps.forEach(path1 => {\n if (path0 === path1) return;\n for (let i = 0; i < path0.length; i++) {\n if (path0[i] !== path1[i]) {\n if (i !== 0) {\n allPaths.push(path0.slice(0, i));\n }\n break;\n }\n }\n });\n });\n\n // ---- Sort by length and then by first element, small to large\n const sortedPaths = allPaths.sort((a, b) => {\n if (a.length !== b.length) return a.length - b.length;\n return a[0] - b[0];\n });\n\n // ---- Deduplicate\n const deduplicatedPaths = [\n ...new Set(sortedPaths.map(path => path.join('.'))),\n ].map(path => path.split('.').filter(Boolean).map(Number));\n\n return deduplicatedPaths;\n }\n\n /**\n * @brief Find the best node name and path for the given path by looking into the nameMap.\n * If there's a full match, return the name and an empty path\n * If there's a partly match, return the name and the remaining path\n * If there's a nextSibling match, return the name and the remaining path with sibling offset\n * @param nameMap\n * @param path\n * @param defaultName\n * @returns [name, path, siblingOffset]\n */\n private static findBestNodeAndPath(\n nameMap: Record,\n path: number[],\n defaultName: string\n ): [string, number[], number] {\n let bestMatchCount = 0;\n let bestMatchName: string | undefined;\n let bestHalfMatch: [string, number, number] | undefined;\n Object.entries(nameMap).forEach(([name, pat]) => {\n let matchCount = 0;\n const pathLength = pat.length;\n for (let i = 0; i < pathLength; i++) {\n if (pat[i] === path[i]) matchCount++;\n }\n // console.log(name, matchCount, pathLength - 1, pat);\n if (matchCount === pathLength - 1) {\n const offset = path[pathLength - 1] - pat[pathLength - 1];\n if (offset > 0 && offset <= 3) {\n bestHalfMatch = [name, matchCount, offset];\n }\n }\n if (matchCount !== pat.length) return;\n if (matchCount > bestMatchCount) {\n bestMatchName = name;\n bestMatchCount = matchCount;\n }\n });\n if (bestHalfMatch) {\n return [\n bestHalfMatch[0],\n path.slice(bestHalfMatch[1] + 1),\n bestHalfMatch[2],\n ];\n }\n if (!bestMatchName) {\n return [defaultName, path, 0];\n }\n return [bestMatchName, path.slice(bestMatchCount), 0];\n }\n}","import { TextUnit } from '@inula/jsx-view-parser';\nimport BaseGenerator from '../HelperGenerators/BaseGenerator';\nimport type { types as t } from '@babel/core';\n\nexport class TextGenerator extends BaseGenerator {\n run() {\n const { content } = this.viewUnit as TextUnit;\n const [nodeName, statement] = this.declareTextNode(content);\n this.addStatement(statement);\n return nodeName;\n }\n\n declareTextNode(content: t.Literal): [string, t.Statement] {\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n this.t.callExpression(\n this.t.identifier(this.importMap.createText),\n [content]\n )\n )\n ])];\n }\n}","import { ExpUnit } from '@inula/jsx-view-parser';\nimport BaseGenerator from '../HelperGenerators/BaseGenerator';\nimport type { types as t } from '@babel/core';\nimport { generateView } from '../generate';\n\nexport class ExpressionGenerator extends BaseGenerator {\n run() {\n const { content: contentWithProp } = this.viewUnit as ExpUnit;\n const content = this.parseViewProp(contentWithProp, generateView);\n const [nodeName, statement] = this.declareExpressionNode(content);\n this.addStatement(statement);\n return nodeName;\n }\n\n\n declareExpressionNode(expression: t.Expression): [string, t.Statement] {\n const name = this.geneNodeName();\n return [name, this.t.variableDeclaration('const', [\n this.t.variableDeclarator(\n this.t.identifier(name),\n expression\n )\n ])];\n }\n}","import { ViewUnit } from '@inula/jsx-view-parser';\nimport { CompGenerator } from './NodeGenerators/CompGenerator';\nimport { HTMLGenerator } from './NodeGenerators/HTMLGenerator';\nimport { ViewGeneratorConfig } from './types';\nimport type { types as t } from '@babel/core';\nimport { TemplateGenerator } from './NodeGenerators/TemplateGenerator';\nimport { TextGenerator } from './NodeGenerators/TextGenerator';\nimport { ExpressionGenerator } from './NodeGenerators/ExpressionGenerator';\n\nexport const viewGeneratorMap = {\n html: HTMLGenerator,\n comp: CompGenerator,\n template: TemplateGenerator,\n text: TextGenerator,\n exp: ExpressionGenerator,\n if: CompGenerator,\n env: CompGenerator,\n} as const;\n\n\nexport function generateNew(oldGenerator: any, viewUnit: ViewUnit, resetIdx = true): [string, t.Statement[], t.Statement[]]{\n const generator = new viewGeneratorMap[viewUnit.type](viewUnit, oldGenerator.config);\n if (resetIdx) generator.nodeIdx = oldGenerator.nodeIdx;\n const [name, statements, templates] = generator.generate();\n if (resetIdx) oldGenerator.nodeIdx = generator.nodeIdx;\n return [name, statements, templates];\n}\n\nexport function generateBlock(viewUnits: ViewUnit[], config: ViewGeneratorConfig) {\n const t = config.babelApi.types;\n const names: string[] = [];\n const statements = viewUnits.flatMap(viewUnit => {\n const generator = new viewGeneratorMap[viewUnit.type](viewUnit, config);\n const [name, statements] = generator.generate();\n names.push(name);\n return statements;\n });\n\n const returnStatement = t.returnStatement(t.arrayExpression(names.map(name => t.identifier(name))));\n return (\n t.blockStatement(statements.concat(returnStatement))\n );\n}\n\nexport function generateView(viewUnits: ViewUnit[], config: ViewGeneratorConfig, templateIdx=-1): [t.Statement[], t.ExpressionStatement] {\n const t = config.babelApi.types;\n const names: string[] = [];\n const allTemplates: t.Statement[] = [];\n let nodeIdx = -1;\n const statements = viewUnits.flatMap(viewUnit => {\n const generator = new viewGeneratorMap[viewUnit.type](viewUnit, config);\n generator.templateIdx = templateIdx;\n generator.nodeIdx = nodeIdx;\n const [name, statements, templates] = generator.generate();\n templateIdx = generator.templateIdx;\n nodeIdx = generator.nodeIdx;\n names.push(name);\n allTemplates.push(...templates);\n return statements;\n });\n\n const returnStatement = t.returnStatement(t.arrayExpression(names.map(name => t.identifier(name))));\n\n return [allTemplates, (\n t.expressionStatement(\n t.callExpression(\n t.arrowFunctionExpression([], t.blockStatement(statements.concat(returnStatement))),\n []\n )\n )\n )];\n}"],"mappings":"wKAKA,IAAqBA,EAArB,KAAmC,CACxB,SACA,OACA,EACA,SACA,oBACA,UAET,YAAYC,EAAoBC,EAA6B,CAC3D,KAAK,OAASA,EACd,KAAK,EAAIA,EAAO,SAAS,MACzB,KAAK,SAAWA,EAAO,SAAS,SAChC,KAAK,UAAYA,EAAO,UACxB,KAAK,SAAWD,EAChB,KAAK,oBAAsBC,EAAO,aAC9B,OAAO,Q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CAAC,EAEKO,EAAkBF,EAAE,gBAAgBA,EAAE,gBAAgBC,EAAM,IAAIP,GAAQM,EAAE,WAAWN,CAAI,CAAC,CAAC,CAAC,EAClG,OACEM,EAAE,eAAeL,EAAW,OAAOO,CAAe,CAAC,CAEvD,CAEO,SAASC,EAAaL,EAAuBC,EAA6BK,EAAY,GAA4C,CACvI,IAAMJ,EAAID,EAAO,SAAS,MACpBE,EAAkB,CAAC,EACnBI,EAA8B,CAAC,EACjCC,EAAU,GACRX,EAAaG,EAAU,QAAQP,GAAY,CAC/C,IAAME,EAAY,IAAIV,EAAiBQ,EAAS,IAAI,EAAEA,EAAUQ,CAAM,EACtEN,EAAU,YAAcW,EACxBX,EAAU,QAAUa,EACpB,GAAM,CAACZ,EAAMC,EAAYC,CAAS,EAAIH,EAAU,SAAS,EACzD,OAAAW,EAAcX,EAAU,YACxBa,EAAUb,EAAU,QACpBQ,EAAM,KAAKP,CAAI,EACfW,EAAa,KAAK,GAAGT,CAAS,EACvBD,CACT,CAAC,EAEKO,EAAkBF,EAAE,gBAAgBA,EAAE,gBAAgBC,EAAM,IAAIP,GAAQM,EAAE,WAAWN,CAAI,CAAC,CAAC,CAAC,EAElG,MAAO,CAACW,EACNL,EAAE,oBACAA,EAAE,eACAA,EAAE,wBAAwB,CAAC,EAAIA,EAAE,eAAeL,EAAW,OAAOO,CAAe,CAAC,CAAC,EACnF,CAAC,CACH,CACF,CACD,CACH","names":["BaseGenerator","viewUnit","config","acc","key","elements","element","statements","template","expression","reactive","path","idx","node","value","collect","statement","prop","generateView","viewPropMap","propNodeMap","units","templates","props","CompGenerator","BaseGenerator","tag","propsWithView","children","props","generateView","nodeName","statement","name","nodes","propNode","key","value","generateBlock","_HTMLPropGenerator","BaseGenerator","nodeName","tag","key","value","shouldWatch","expression","eventName","dynamic","event","attribute","HTMLPropGenerator","__publicField","HTMLGenerator","HTMLPropGenerator","tag","propsWithView","children","props","generateView","nodeName","statement","tagName","key","prop","child","childNodeName","childStatements","generateNew","name","parent","TemplateGenerator","HTMLPropGenerator","template","mutableUnits","props","templateName","nodeName","statement","paths","path","insertElementStatements","pathNameMap","tag","key","value","name","tagName","unit","parentName","nextName","childName","childStatements","generateNew","statements","returnStatement","parent","child","nextNode","dlNodeName","offset","newNodeName","acc","addFirstChild","object","addSecondChild","addThirdChild","addOtherChild","num","addNextSibling","cur","idx","i","collect","nameMap","res","pat","allPaths","ps","path0","path1","sortedPaths","a","b","defaultName","bestMatchCount","bestMatchName","bestHalfMatch","matchCount","pathLength","TextGenerator","BaseGenerator","content","nodeName","statement","name","ExpressionGenerator","BaseGenerator","contentWithProp","content","generateView","nodeName","statement","expression","name","viewGeneratorMap","HTMLGenerator","CompGenerator","TemplateGenerator","TextGenerator","ExpressionGenerator","generateNew","oldGenerator","viewUnit","resetIdx","generator","name","statements","templates","generateBlock","viewUnits","config","t","names","returnStatement","generateView","templateIdx","allTemplates","nodeIdx"]} \ No newline at end of file diff --git a/packages/transpiler/jsx-view-generator/src/HelperGenerators/HTMLPropGenerator.ts b/packages/transpiler/jsx-view-generator/src/HelperGenerators/HTMLPropGenerator.ts index 5f2183869b8aff47badef52a037d79a25be5e5b9..e4189df0fd0e7a9d49a3a0d6a3fe83fa326cd931 100644 --- a/packages/transpiler/jsx-view-generator/src/HelperGenerators/HTMLPropGenerator.ts +++ b/packages/transpiler/jsx-view-generator/src/HelperGenerators/HTMLPropGenerator.ts @@ -146,7 +146,7 @@ export class HTMLPropGenerator extends BaseGenerator { value: t.Expression, ) { return this.t.callExpression( - this.t.identifier(this.importMap.delegateEvents), + this.t.identifier(this.importMap.delegateEvent), [this.t.identifier(nodeName), this.t.stringLiteral(eventName), value] ); } diff --git a/packages/transpiler/jsx-view-generator/src/test/const.ts b/packages/transpiler/jsx-view-generator/src/test/const.ts index 1383b408a7ee23f497ff8897e3a94f9edf056d0f..9e24bde419c1b767e382dd8f6e335c509496a547 100644 --- a/packages/transpiler/jsx-view-generator/src/test/const.ts +++ b/packages/transpiler/jsx-view-generator/src/test/const.ts @@ -1,12 +1,12 @@ export const importMap = [ - 'createElement', - 'setStyle', - 'setAttribute', - 'setDataset', - 'setProperty', - 'setEvent', - 'delegateEvent', + 'createElement', + 'setStyle', + 'setAttribute', + 'setDataset', + 'setProperty', + 'setEvent', + 'delegateEvent', 'addEventListener', 'watch', 'insert', @@ -510,4 +510,4 @@ export const attributeMap = { ariaRowIndex: ['*'], ariaRowSpan: ['*'], ariaSetSize: ['*'], -}; \ No newline at end of file +}; diff --git a/packages/transpiler/jsx-view-parser/dist/index.cjs b/packages/transpiler/jsx-view-parser/dist/index.cjs deleted file mode 100644 index 4f61c13ed7a6b560221edc09fb6e5a8a1c97eca8..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-parser/dist/index.cjs +++ /dev/null @@ -1,2 +0,0 @@ -"use strict";var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var u=(o,t)=>{for(var e in t)c(o,e,{get:t[e],enumerable:!0})},T=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of g(t))!v.call(o,i)&&i!==e&&c(o,i,{get:()=>t[i],enumerable:!(r=f(t,i))||r.enumerable});return o};var d=o=>T(c({},"__esModule",{value:!0}),o);var y={};u(y,{parseView:()=>w});module.exports=d(y);var h=class{htmlNamespace="html";htmlTagNamespace="tag";compTagNamespace="comp";envTagName="env";ifTagName="if";elseIfTagName="else-if";elseTagName="else";customHTMLProps=["ref"];config;htmlTags;willParseTemplate;t;traverse;viewUnits=[];constructor(t){this.config=t,this.t=t.babelApi.types,this.traverse=t.babelApi.traverse,this.htmlTags=t.htmlTags,this.willParseTemplate=t.parseTemplate??!0}parse(t){return this.t.isJSXText(t)?this.parseText(t):this.t.isJSXExpressionContainer(t)?this.parseExpression(t.expression):this.t.isJSXElement(t)?this.parseElement(t):this.t.isJSXFragment(t)&&t.children.forEach(e=>{this.parse(e)}),this.viewUnits}parseText(t){let e=t.value.trim();e&&this.viewUnits.push({type:"text",content:this.t.stringLiteral(e)})}parseExpression(t){if(!this.t.isJSXEmptyExpression(t)){if(this.t.isLiteral(t)&&!this.t.isTemplateLiteral(t)){this.viewUnits.push({type:"text",content:t});return}this.viewUnits.push({type:"exp",content:this.parseProp(t)})}}parseElement(t){let e,r,i=t.openingElement.name;if(this.t.isJSXIdentifier(i)){let n=i.name;if([this.ifTagName,this.elseIfTagName,this.elseTagName].includes(n))return this.parseIf(t);if(n===this.envTagName)return this.parseEnv(t);this.htmlTags.includes(n)?(e="html",r=this.t.stringLiteral(n)):(e="comp",r=this.t.identifier(n))}else if(this.t.isJSXMemberExpression(i)){e="comp";let n=m=>this.t.isJSXMemberExpression(m.object)?this.t.memberExpression(n(m.object),this.t.identifier(m.property.name)):this.t.memberExpression(this.t.identifier(m.object.name),this.t.identifier(m.property.name));r=n(i)}else{let n=i.namespace.name;switch(n){case this.compTagNamespace:e="comp",r=this.t.identifier(i.name.name);break;case this.htmlNamespace:e="html",r=this.t.stringLiteral(i.name.name);break;case this.htmlTagNamespace:e="html",r=this.t.identifier(i.name.name);break;default:e="html",r=this.t.stringLiteral(`${n}:${i.name.name}`);break}}let s=t.openingElement.attributes,p=Object.fromEntries(s.map(n=>this.parseJSXProp(n))),l=t.children.map(n=>this.parseView(n)).flat(),a={type:e,tag:r,props:p,children:l};if(a.type==="html"&&l.length===1&&l[0].type==="text"){let n=l[0];a={...a,children:[],props:{...a.props,textContent:{value:n.content,viewPropMap:{}}}}}a.type==="html"&&(a=this.transformTemplate(a)),this.viewUnits.push(a)}parseEnv(t){let e=t.openingElement.attributes,r=Object.fromEntries(e.map(s=>this.parseJSXProp(s))),i=t.children.map(s=>this.parseView(s)).flat();this.viewUnits.push({type:"env",props:r,children:i})}parseIf(t){let e=t.openingElement.name.name;if(e===this.elseTagName){let s=this.viewUnits[this.viewUnits.length-1];if(!s||s.type!=="if")throw new Error(`Missing if for ${e}`);s.branches.push({condition:this.t.booleanLiteral(!0),children:t.children.map(p=>this.parseView(p)).flat()});return}let r=t.openingElement.attributes.filter(s=>this.t.isJSXAttribute(s)&&s.name.name==="cond")[0];if(!r)throw new Error(`Missing condition for ${e}`);if(!this.t.isJSXAttribute(r))throw new Error(`JSXSpreadAttribute is not supported for ${e} condition`);if(!this.t.isJSXExpressionContainer(r.value)||!this.t.isExpression(r.value.expression))throw new Error(`Invalid condition for ${e}`);if(e===this.ifTagName){this.viewUnits.push({type:"if",branches:[{condition:r.value.expression,children:t.children.map(s=>this.parseView(s)).flat()}]});return}let i=this.viewUnits[this.viewUnits.length-1];if(!i||i.type!=="if")throw new Error(`Missing if for ${e}`);i.branches.push({condition:r.value.expression,children:t.children.map(s=>this.parseView(s)).flat()})}parseJSXProp(t){if(this.t.isJSXAttribute(t)){let e,r;this.t.isJSXNamespacedName(t.name)?(e=t.name.name.name,r=t.name.namespace.name):e=t.name.name;let i=this.t.isJSXExpressionContainer(t.value)?t.value.expression:t.value;return this.t.isJSXEmptyExpression(i)&&(i=void 0),[e,this.parseProp(i,r)]}return["*spread*",this.parseProp(t.argument)]}parseProp(t,e){if(!t)return{value:this.t.booleanLiteral(!0),viewPropMap:{}};let r={},i=s=>{let p=this.uid(),l=s.node;r[p]=this.parseView(l);let a=this.t.stringLiteral(p);l===t&&(t=a),s.replaceWith(a),s.skip()};return this.traverse(this.wrapWithFile(t),{JSXElement:i,JSXFragment:i}),{value:t,viewPropMap:r,specifier:e}}transformTemplate(t){return!this.willParseTemplate||!this.isHTMLTemplate(t)?t:(t=t,{type:"template",template:this.generateTemplate(t),mutableUnits:this.generateMutableUnits(t),props:this.parseTemplateProps(t)})}generateTemplate(t){let e=Object.fromEntries(this.filterTemplateProps(Object.entries(t.props??[]).filter(([,i])=>this.isStaticProp(i)&&!(this.t.isBooleanLiteral(i.value)&&!i.value.value)))),r=[];return t.children&&(r=t.children.map(i=>{if(i.type==="text")return i;if(i.type==="html"&&this.t.isStringLiteral(i.tag))return this.generateTemplate(i)}).filter(Boolean)),{type:"html",tag:t.tag,props:e,children:r}}generateMutableUnits(t){let e=[],r=(i,s=[])=>{let p=i.children?.filter(a=>a.type==="html"&&this.t.isStringLiteral(a.tag)||a.type==="text").length,l=-1;i.children?.forEach(a=>{if(!(a.type==="html"&&this.t.isStringLiteral(a.tag))&&a.type!=="text"){let n=l+1>=p?-1:l+1;e.push({path:[...s,n],...this.transformTemplate(a)})}else l++}),i.children?.filter(a=>a.type==="html"&&this.t.isStringLiteral(a.tag)).forEach((a,n)=>{r(a,[...s,n])})};return r(t),e}parseTemplateProps(t){let e=[],r=(i,s)=>{i.props&&Object.entries(i.props).filter(([,p])=>!this.isStaticProp(p)).forEach(([p,l])=>{e.push({tag:i.tag,name:i.tag.value,key:p,path:s,value:l.value})}),i.children?.filter(p=>p.type==="html"&&this.t.isStringLiteral(p.tag)).forEach((p,l)=>{r(p,[...s,l])})};return r(t,[]),e}isHTMLTemplate(t){return t.type==="html"&&this.t.isStringLiteral(t.tag)&&!!t.children?.some(e=>e.type==="html"&&this.t.isStringLiteral(e.tag))}isStaticProp(t){return this.t.isStringLiteral(t.value)||this.t.isNumericLiteral(t.value)||this.t.isBooleanLiteral(t.value)||this.t.isNullLiteral(t.value)}filterTemplateProps(t){return t.filter(([e])=>!e.startsWith("on")).filter(([e])=>!this.customHTMLProps.includes(e))}parseView(t){return new h({...this.config,parseTemplate:!1}).parse(t)}wrapWithFile(t){return this.t.file(this.t.program([this.t.expressionStatement(t)]))}uid(){return Math.random().toString(36).slice(2)}};function w(o,t){return new h(t).parse(o)}0&&(module.exports={parseView}); -//# sourceMappingURL=index.cjs.map \ No newline at end of file diff --git a/packages/transpiler/jsx-view-parser/dist/index.cjs.map b/packages/transpiler/jsx-view-parser/dist/index.cjs.map deleted file mode 100644 index 66dbe19f29ee9cfaa0c695aaf566f75f4736904e..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-parser/dist/index.cjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/index.ts","../src/parser.ts"],"sourcesContent":["import { ViewParser } from './parser';\nimport type { ViewUnit, ViewParserConfig, AllowedJSXNode } from './types';\n\n/**\n * @brief Generate view units from a babel ast\n * @param statement\n * @param config\n * @returns ViewUnit[]\n */\nexport function parseView(\n node: AllowedJSXNode,\n config: ViewParserConfig\n): ViewUnit[] {\n return new ViewParser(config).parse(node);\n}\n\nexport type * from './types';\n","import type { NodePath, types as t, traverse as tr } from '@babel/core';\nimport type {\n UnitProp,\n ViewUnit,\n ViewParserConfig,\n AllowedJSXNode,\n HTMLUnit,\n TextUnit,\n MutableUnit,\n TemplateProp,\n} from './types';\n\nexport class ViewParser {\n // ---- Namespace and tag name\n private readonly htmlNamespace: string = 'html'\n private readonly htmlTagNamespace: string = 'tag'\n private readonly compTagNamespace: string = 'comp'\n private readonly envTagName: string = 'env'\n private readonly ifTagName: string = 'if'\n private readonly elseIfTagName: string = 'else-if'\n private readonly elseTagName: string = 'else'\n private readonly customHTMLProps: string[] = ['ref']\n\n private readonly config: ViewParserConfig\n private readonly htmlTags: string[]\n private readonly willParseTemplate: boolean\n\n private readonly t: typeof t\n private readonly traverse: typeof tr\n\n private readonly viewUnits: ViewUnit[] = []\n\n /**\n * @brief Constructor\n * @param config\n */\n constructor(config: ViewParserConfig) {\n this.config = config;\n this.t = config.babelApi.types;\n this.traverse = config.babelApi.traverse;\n this.htmlTags = config.htmlTags;\n this.willParseTemplate = config.parseTemplate ?? true;\n }\n\n /**\n * @brief Parse the node into view units\n * @param node\n * @returns ViewUnit[]\n */\n parse(node: AllowedJSXNode): ViewUnit[] {\n if (this.t.isJSXText(node)) this.parseText(node);\n else if (this.t.isJSXExpressionContainer(node)) this.parseExpression(node.expression);\n else if (this.t.isJSXElement(node)) this.parseElement(node);\n else if (this.t.isJSXFragment(node)) {\n node.children.forEach(child => {\n this.parse(child);\n });\n }\n \n return this.viewUnits;\n }\n\n /**\n * @brief Parse JSXText\n * @param node\n */\n private parseText(node: t.JSXText): void {\n const text = node.value.trim();\n if (!text) return;\n this.viewUnits.push({\n type: 'text',\n content: this.t.stringLiteral(text),\n });\n }\n\n /**\n * @brief Parse JSXExpressionContainer\n * @param node\n */\n private parseExpression(node: t.Expression | t.JSXEmptyExpression): void {\n if (this.t.isJSXEmptyExpression(node)) return;\n if (this.t.isLiteral(node) && !this.t.isTemplateLiteral(node)) {\n // ---- Treat literal as text except template literal\n // Cuz template literal may have viewProp inside like:\n // <>{i18n`hello ${}`}\n this.viewUnits.push({\n type: 'text',\n content: node\n });\n return; \n }\n this.viewUnits.push({\n type: 'exp',\n content: this.parseProp(node),\n });\n }\n\n /**\n * @brief Parse JSXElement\n * @param node \n */\n private parseElement(node: t.JSXElement): void {\n let type: 'html' | 'comp';\n let tag: t.Expression;\n\n // ---- Parse tag and type\n const openingName = node.openingElement.name;\n if (this.t.isJSXIdentifier(openingName)) {\n // ---- Opening name is a JSXIdentifier, e.g.,
\n const name = openingName.name;\n // ---- Specially parse if and env\n if ([this.ifTagName, this.elseIfTagName, this.elseTagName].includes(name)) \n return this.parseIf(node);\n if (name === this.envTagName) return this.parseEnv(node);\n else if (this.htmlTags.includes(name)) {\n type = 'html';\n tag = this.t.stringLiteral(name);\n } else {\n // ---- If the name is not in htmlTags, treat it as a comp\n type = 'comp';\n tag = this.t.identifier(name);\n }\n } else if (this.t.isJSXMemberExpression(openingName)) {\n // ---- Opening name is a JSXMemberExpression, e.g., \n // Treat it as a comp and set the tag as the opening name\n type = 'comp';\n // ---- Turn JSXMemberExpression into MemberExpression recursively\n const toMemberExpression = (node: t.JSXMemberExpression): t.MemberExpression => {\n if (this.t.isJSXMemberExpression(node.object)) {\n return this.t.memberExpression(\n toMemberExpression(node.object),\n this.t.identifier(node.property.name)\n );\n }\n return this.t.memberExpression(\n this.t.identifier(node.object.name),\n this.t.identifier(node.property.name)\n );\n };\n tag = toMemberExpression(openingName);\n } else {\n // ---- isJSXNamespacedName\n const namespace = openingName.namespace.name;\n switch (namespace) {\n case this.compTagNamespace:\n // ---- If the namespace is the same as the compTagNamespace, treat it as a comp\n // and set the tag as an identifier\n // e.g., => [\"comp\", div]\n // this means you've declared a component named \"div\" and force it to be a comp instead an html\n type = 'comp';\n tag = this.t.identifier(openingName.name.name);\n break;\n case this.htmlNamespace:\n // ---- If the namespace is the same as the htmlTagNamespace, treat it as an html\n // and set the tag as a string literal\n // e.g., => [\"html\", \"MyWebComponent\"]\n // the tag will be treated as a string, i.e., \n type = 'html';\n tag = this.t.stringLiteral(openingName.name.name);\n break;\n case this.htmlTagNamespace:\n // ---- If the namespace is the same as the htmlTagNamespace, treat it as an html\n // and set the tag as an identifier\n // e.g., => [\"html\", variable]\n // this unit will be htmlUnit and the html string tag is stored in \"variable\"\n type = 'html';\n tag = this.t.identifier(openingName.name.name);\n break;\n default:\n // ---- Otherwise, treat it as an html tag and make the tag as the namespace:name\n type = 'html';\n tag = this.t.stringLiteral(`${namespace}:${openingName.name.name}`);\n break;\n }\n }\n\n // ---- Parse the props\n const props = node.openingElement.attributes;\n const propMap: Record = Object.fromEntries(\n props.map(prop => this.parseJSXProp(prop))\n );\n\n // ---- Parse the children\n const childUnits = node.children.map(child => this.parseView(child)).flat();\n\n let unit: ViewUnit = { type, tag, props: propMap, children: childUnits };\n \n if (unit.type === 'html' && childUnits.length === 1 && childUnits[0].type === 'text') {\n // ---- If the html unit only has one text child, merge the text into the html unit\n const text = childUnits[0] as TextUnit;\n unit = {\n ...unit,\n children: [],\n props: {\n ...unit.props,\n textContent: {\n value: text.content,\n viewPropMap: {},\n },\n },\n };\n }\n\n if (unit.type === 'html') unit = this.transformTemplate(unit);\n\n this.viewUnits.push(unit);\n }\n\n /**\n * @brief Parse EnvUnit\n * @param node\n */\n private parseEnv(node: t.JSXElement): void {\n const props = node.openingElement.attributes;\n const propMap: Record = Object.fromEntries(\n props.map(prop => this.parseJSXProp(prop))\n );\n const children = node.children.map(child => this.parseView(child)).flat();\n this.viewUnits.push({\n type: 'env',\n props: propMap,\n children,\n });\n }\n\n private parseIf(node: t.JSXElement): void {\n const name = (node.openingElement.name as t.JSXIdentifier).name;\n // ---- else\n if (name === this.elseTagName) {\n const lastUnit = this.viewUnits[this.viewUnits.length - 1];\n if (!lastUnit || lastUnit.type !== 'if') throw new Error(`Missing if for ${name}`);\n lastUnit.branches.push({\n condition: this.t.booleanLiteral(true),\n children: node.children.map(child => this.parseView(child)).flat(),\n });\n return;\n }\n\n const condition = node.openingElement.attributes.filter(attr => \n this.t.isJSXAttribute(attr) && attr.name.name === 'cond'\n )[0];\n if (!condition) throw new Error(`Missing condition for ${name}`);\n if (!this.t.isJSXAttribute(condition)) throw new Error(`JSXSpreadAttribute is not supported for ${name} condition`);\n if (!this.t.isJSXExpressionContainer(condition.value) || !this.t.isExpression(condition.value.expression))\n throw new Error(`Invalid condition for ${name}`);\n \n // ---- if\n if (name === this.ifTagName) {\n this.viewUnits.push({\n type: 'if',\n branches: [{\n condition: condition.value.expression,\n children: node.children.map(child => this.parseView(child)).flat(),\n }],\n });\n return;\n } \n\n // ---- else-if\n const lastUnit = this.viewUnits[this.viewUnits.length - 1];\n if (!lastUnit || lastUnit.type !== 'if') \n throw new Error(`Missing if for ${name}`);\n\n lastUnit.branches.push({\n condition: condition.value.expression,\n children: node.children.map(child => this.parseView(child)).flat(),\n });\n }\n\n /**\n * @brief Parse JSXAttribute or JSXSpreadAttribute into UnitProp,\n * considering both namespace and expression\n * @param prop \n * @returns [propName, propValue]\n */\n private parseJSXProp(prop: t.JSXAttribute | t.JSXSpreadAttribute): [string, UnitProp] {\n if (this.t.isJSXAttribute(prop)) {\n let propName: string, specifier: string | undefined;\n if (this.t.isJSXNamespacedName(prop.name)) {\n // ---- If the prop name is a JSXNamespacedName, e.g., bind:value\n // give it a special tag\n propName = prop.name.name.name;\n specifier = prop.name.namespace.name;\n } else {\n propName = prop.name.name;\n }\n let value = this.t.isJSXExpressionContainer(prop.value) ? prop.value.expression : prop.value;\n if (this.t.isJSXEmptyExpression(value)) value = undefined;\n return [propName, this.parseProp(value, specifier)];\n }\n // ---- Use *spread* as the propName to avoid conflict with other props\n return ['*spread*', this.parseProp(prop.argument)];\n }\n\n /**\n * @brief Parse the prop node into UnitProp\n * @param propNode\n * @param specifier\n * @returns UnitProp\n */\n private parseProp(propNode: t.Expression | undefined | null, specifier?: string): UnitProp {\n // ---- If there is no propNode, set the default prop as true\n if (!propNode) {\n return {\n value: this.t.booleanLiteral(true),\n viewPropMap: {},\n };\n }\n\n // ---- Collect sub jsx nodes as Prop\n const viewPropMap: Record = {};\n const parseViewProp = (innerPath: NodePath): void => {\n const id = this.uid();\n const node = innerPath.node;\n viewPropMap[id] = this.parseView(node);\n const newNode = this.t.stringLiteral(id);\n if (node === propNode) {\n // ---- If the node is the propNode, replace it with the new node\n propNode = newNode;\n }\n // ---- Replace the node and skip the inner path\n innerPath.replaceWith(newNode);\n innerPath.skip();\n };\n\n // ---- Apply the parseViewProp to JSXElement and JSXFragment\n this.traverse(this.wrapWithFile(propNode), {\n JSXElement: parseViewProp,\n JSXFragment: parseViewProp,\n });\n\n return {\n value: propNode,\n viewPropMap,\n specifier,\n };\n }\n\n transformTemplate(unit: ViewUnit): ViewUnit {\n if (!this.willParseTemplate) return unit;\n if (!this.isHTMLTemplate(unit)) return unit;\n unit = unit as HTMLUnit;\n return {\n type: 'template',\n template: this.generateTemplate(unit),\n mutableUnits: this.generateMutableUnits(unit),\n props: this.parseTemplateProps(unit),\n };\n }\n\n /**\n * @brief Generate the entire HTMLUnit\n * @param unit\n * @returns HTMLUnit\n */\n private generateTemplate(unit: HTMLUnit): HTMLUnit {\n const staticProps = Object.fromEntries(this.filterTemplateProps(\n // ---- Get all the static props\n Object.entries(unit.props ?? []).filter(\n ([, prop]) =>\n this.isStaticProp(prop) &&\n // ---- Filter out props with false values\n !(this.t.isBooleanLiteral(prop.value) && !prop.value.value)\n )\n ));\n\n let children: (HTMLUnit | TextUnit)[] = [];\n if (unit.children) {\n children = unit.children\n .map(unit => {\n if (unit.type === 'text') return unit;\n if (unit.type === 'html' && this.t.isStringLiteral(unit.tag)) {\n return this.generateTemplate(unit);\n }\n })\n .filter(Boolean) as (HTMLUnit | TextUnit)[];\n }\n return {\n type: 'html',\n tag: unit.tag,\n props: staticProps,\n children,\n };\n }\n\n /**\n * @brief Collect all the mutable nodes in a static HTMLUnit\n * We use this function to collect mutable nodes' path and props,\n * so that in the generator, we know which position to insert the mutable nodes\n * @param htmlUnit\n * @returns mutable particles\n */\n private generateMutableUnits(htmlUnit: HTMLUnit): MutableUnit[] {\n const mutableUnits: MutableUnit[] = [];\n\n const generateMutableUnit = (unit: HTMLUnit, path: number[] = []) => {\n const maxHtmlIdx = unit.children?.filter(\n child => (child.type === 'html' && this.t.isStringLiteral(child.tag)) ||\n child.type === 'text'\n ).length;\n let htmlIdx = -1;\n // ---- Generate mutable unit for current HTMLUnit\n unit.children?.forEach((child) => {\n if (\n !(child.type === 'html' && this.t.isStringLiteral(child.tag)) &&\n !(child.type === 'text')\n ) {\n const idx = htmlIdx + 1 >= maxHtmlIdx ? -1 : htmlIdx + 1;\n mutableUnits.push({\n path: [...path, idx],\n ...this.transformTemplate(child),\n });\n } else {\n htmlIdx++;\n }\n });\n // ---- Recursively generate mutable units for static HTMLUnit children\n unit.children\n ?.filter(\n child => child.type === 'html' && this.t.isStringLiteral(child.tag)\n )\n .forEach((child, idx) => {\n generateMutableUnit(child as HTMLUnit, [...path, idx]);\n });\n };\n generateMutableUnit(htmlUnit);\n\n return mutableUnits;\n }\n\n /**\n * @brief Collect all the props in a static HTMLUnit or its nested HTMLUnit children\n * Just like the mutable nodes, props are also equipped with path,\n * so that we know which HTML ChildNode to insert the props\n * @param htmlUnit\n * @returns props\n */\n private parseTemplateProps(htmlUnit: HTMLUnit): TemplateProp[] {\n const templateProps: TemplateProp[] = [];\n const generateVariableProp = (unit: HTMLUnit, path: number[]) => {\n // ---- Generate all non-static(string/number/boolean) props for current HTMLUnit\n // to be inserted further in the generator\n unit.props && Object.entries(unit.props)\n .filter(([, prop]) => !this.isStaticProp(prop))\n .forEach(([key, prop]) => {\n templateProps.push({\n tag: unit.tag,\n name: (unit.tag as t.StringLiteral).value,\n key,\n path,\n value: prop.value,\n });\n });\n // ---- Recursively generate props for static HTMLUnit children\n unit.children\n ?.filter(child => child.type === 'html' && this.t.isStringLiteral(child.tag))\n .forEach((child, idx) => {\n generateVariableProp(child as HTMLUnit, [...path, idx]);\n });\n };\n generateVariableProp(htmlUnit, []);\n\n return templateProps;\n }\n\n /**\n * @brief Check if a ViewUnit is a static HTMLUnit that can be parsed into a template\n * Must satisfy:\n * 1. type is html\n * 2. tag is a string literal, i.e., non-dynamic tag\n * 3. has at least one child that is a static HTMLUnit,\n * or else just call a createElement function, no need for template clone\n * @param viewUnit\n * @returns is a static HTMLUnit\n */\n private isHTMLTemplate(viewUnit: ViewUnit): boolean {\n return (\n viewUnit.type === 'html' &&\n this.t.isStringLiteral(viewUnit.tag) &&\n !!viewUnit.children?.some(\n child => child.type === 'html' && this.t.isStringLiteral(child.tag)\n )\n );\n }\n\n private isStaticProp(prop: UnitProp): boolean {\n return (\n this.t.isStringLiteral(prop.value) ||\n this.t.isNumericLiteral(prop.value) ||\n this.t.isBooleanLiteral(prop.value) ||\n this.t.isNullLiteral(prop.value)\n );\n }\n\n /**\n * @brief Filter out some props that are not needed in the template,\n * these are all special props to be parsed differently in the generator\n * @param props\n * @returns filtered props\n */\n private filterTemplateProps(\n props: Array<[string, T]>\n ): Array<[string, T]> {\n return (\n props\n // ---- Filter out event listeners\n .filter(([key]) => !key.startsWith('on'))\n // ---- Filter out specific props\n .filter(([key]) => !this.customHTMLProps.includes(key))\n );\n }\n\n /**\n * @brief Parse the view by duplicating current parser's classRootPath, statements and htmlTags\n * @param statements\n * @returns ViewUnit[]\n */\n private parseView(node: AllowedJSXNode): ViewUnit[] {\n return new ViewParser({...this.config, parseTemplate:false}).parse(node);\n }\n \n\n /**\n * @brief Wrap the value in a file\n * @param node\n * @returns wrapped value\n */\n private wrapWithFile(node: t.Expression): t.File {\n return this.t.file(this.t.program([this.t.expressionStatement(node)]));\n }\n\n /**\n * @brief Generate a unique id\n * @returns a unique id\n */\n private uid(): string {\n return Math.random().toString(36).slice(2);\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAAA,eAAAC,EAAAH,GCYO,IAAMI,EAAN,KAAiB,CAEL,cAAwB,OACxB,iBAA2B,MAC3B,iBAA2B,OAC3B,WAAqB,MACrB,UAAoB,KACpB,cAAwB,UACxB,YAAsB,OACtB,gBAA4B,CAAC,KAAK,EAElC,OACA,SACA,kBAEA,EACA,SAEA,UAAwB,CAAC,EAM1C,YAAYC,EAA0B,CACpC,KAAK,OAASA,EACd,KAAK,EAAIA,EAAO,SAAS,MACzB,KAAK,SAAWA,EAAO,SAAS,SAChC,KAAK,SAAWA,EAAO,SACvB,KAAK,kBAAoBA,EAAO,eAAiB,EACnD,CAOA,MAAMC,EAAkC,CACtC,OAAI,KAAK,EAAE,UAAUA,CAAI,EAAG,KAAK,UAAUA,CAAI,EACtC,KAAK,EAAE,yBAAyBA,CAAI,EAAG,KAAK,gBAAgBA,EAAK,UAAU,EAC3E,KAAK,EAAE,aAAaA,CAAI,EAAG,KAAK,aAAaA,CAAI,EACjD,KAAK,EAAE,cAAcA,CAAI,GAChCA,EAAK,SAAS,QAAQC,GAAS,CAC7B,KAAK,MAAMA,CAAK,CAClB,CAAC,EAGI,KAAK,SACd,CAMQ,UAAUD,EAAuB,CACvC,IAAME,EAAOF,EAAK,MAAM,KAAK,EACxBE,GACL,KAAK,UAAU,KAAK,CAClB,KAAM,OACN,QAAS,KAAK,EAAE,cAAcA,CAAI,CACpC,CAAC,CACH,CAMQ,gBAAgBF,EAAiD,CACvE,GAAI,MAAK,EAAE,qBAAqBA,CAAI,EACpC,IAAI,KAAK,EAAE,UAAUA,CAAI,GAAK,CAAC,KAAK,EAAE,kBAAkBA,CAAI,EAAG,CAI7D,KAAK,UAAU,KAAK,CAClB,KAAM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Q,cAAc,EAAK,CAAC,EAAE,MAAME,CAAI,CACzE,CAQQ,aAAaA,EAA4B,CAC/C,OAAO,KAAK,EAAE,KAAK,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,oBAAoBA,CAAI,CAAC,CAAC,CAAC,CACvE,CAMQ,KAAc,CACpB,OAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAC3C,CACF,EDjhBO,SAASuC,EACdC,EACAC,EACY,CACZ,OAAQ,IAAIC,EAAWD,CAAM,EAAE,MAAMD,CAAI,CAC3C","names":["src_exports","__export","parseView","__toCommonJS","ViewParser","config","node","child","text","type","tag","openingName","name","toMemberExpression","namespace","props","propMap","prop","childUnits","unit","children","lastUnit","condition","attr","propName","specifier","value","propNode","viewPropMap","parseViewProp","innerPath","id","newNode","staticProps","htmlUnit","mutableUnits","generateMutableUnit","path","maxHtmlIdx","htmlIdx","idx","templateProps","generateVariableProp","key","viewUnit","parseView","node","config","ViewParser"]} \ No newline at end of file diff --git a/packages/transpiler/jsx-view-parser/dist/index.d.ts b/packages/transpiler/jsx-view-parser/dist/index.d.ts deleted file mode 100644 index 4712c6b14586e64dbe1976ea26f19def41d2cd2e..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-parser/dist/index.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -import Babel, { types } from '@babel/core'; - -interface UnitProp { - value: types.Expression; - viewPropMap: Record; - specifier?: string; -} -interface TextUnit { - type: 'text'; - content: types.Literal; -} -type MutableUnit = ViewUnit & { - path: number[]; -}; -interface TemplateProp { - tag: types.Expression; - name: string; - key: string; - path: number[]; - value: types.Expression; -} -interface TemplateUnit { - type: 'template'; - template: HTMLUnit; - mutableUnits: MutableUnit[]; - props: TemplateProp[]; -} -interface HTMLUnit { - type: 'html'; - tag: types.Expression; - props: Record; - children: ViewUnit[]; -} -interface CompUnit { - type: 'comp'; - tag: types.Expression; - props: Record; - children: ViewUnit[]; -} -interface IfBranch { - condition: types.Expression; - children: ViewUnit[]; -} -interface IfUnit { - type: 'if'; - branches: IfBranch[]; -} -interface ExpUnit { - type: 'exp'; - content: UnitProp; -} -interface EnvUnit { - type: 'env'; - props: Record; - children: ViewUnit[]; -} -type ViewUnit = TextUnit | HTMLUnit | CompUnit | IfUnit | ExpUnit | EnvUnit | TemplateUnit; -interface ViewParserConfig { - babelApi: typeof Babel; - htmlTags: string[]; - parseTemplate?: boolean; -} -type AllowedJSXNode = types.JSXElement | types.JSXFragment | types.JSXText | types.JSXExpressionContainer | types.JSXSpreadChild; - -/** - * @brief Generate view units from a babel ast - * @param statement - * @param config - * @returns ViewUnit[] - */ -declare function parseView(node: AllowedJSXNode, config: ViewParserConfig): ViewUnit[]; - -export { AllowedJSXNode, CompUnit, EnvUnit, ExpUnit, HTMLUnit, IfBranch, IfUnit, MutableUnit, TemplateProp, TemplateUnit, TextUnit, UnitProp, ViewParserConfig, ViewUnit, parseView }; diff --git a/packages/transpiler/jsx-view-parser/dist/index.js b/packages/transpiler/jsx-view-parser/dist/index.js deleted file mode 100644 index 73087f869154dcd9836dc276b368fb2030c8cfc2..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-parser/dist/index.js +++ /dev/null @@ -1,2 +0,0 @@ -var o=class{htmlNamespace="html";htmlTagNamespace="tag";compTagNamespace="comp";envTagName="env";ifTagName="if";elseIfTagName="else-if";elseTagName="else";customHTMLProps=["ref"];config;htmlTags;willParseTemplate;t;traverse;viewUnits=[];constructor(t){this.config=t,this.t=t.babelApi.types,this.traverse=t.babelApi.traverse,this.htmlTags=t.htmlTags,this.willParseTemplate=t.parseTemplate??!0}parse(t){return this.t.isJSXText(t)?this.parseText(t):this.t.isJSXExpressionContainer(t)?this.parseExpression(t.expression):this.t.isJSXElement(t)?this.parseElement(t):this.t.isJSXFragment(t)&&t.children.forEach(e=>{this.parse(e)}),this.viewUnits}parseText(t){let e=t.value.trim();e&&this.viewUnits.push({type:"text",content:this.t.stringLiteral(e)})}parseExpression(t){if(!this.t.isJSXEmptyExpression(t)){if(this.t.isLiteral(t)&&!this.t.isTemplateLiteral(t)){this.viewUnits.push({type:"text",content:t});return}this.viewUnits.push({type:"exp",content:this.parseProp(t)})}}parseElement(t){let e,r,i=t.openingElement.name;if(this.t.isJSXIdentifier(i)){let n=i.name;if([this.ifTagName,this.elseIfTagName,this.elseTagName].includes(n))return this.parseIf(t);if(n===this.envTagName)return this.parseEnv(t);this.htmlTags.includes(n)?(e="html",r=this.t.stringLiteral(n)):(e="comp",r=this.t.identifier(n))}else if(this.t.isJSXMemberExpression(i)){e="comp";let n=h=>this.t.isJSXMemberExpression(h.object)?this.t.memberExpression(n(h.object),this.t.identifier(h.property.name)):this.t.memberExpression(this.t.identifier(h.object.name),this.t.identifier(h.property.name));r=n(i)}else{let n=i.namespace.name;switch(n){case this.compTagNamespace:e="comp",r=this.t.identifier(i.name.name);break;case this.htmlNamespace:e="html",r=this.t.stringLiteral(i.name.name);break;case this.htmlTagNamespace:e="html",r=this.t.identifier(i.name.name);break;default:e="html",r=this.t.stringLiteral(`${n}:${i.name.name}`);break}}let s=t.openingElement.attributes,p=Object.fromEntries(s.map(n=>this.parseJSXProp(n))),l=t.children.map(n=>this.parseView(n)).flat(),a={type:e,tag:r,props:p,children:l};if(a.type==="html"&&l.length===1&&l[0].type==="text"){let n=l[0];a={...a,children:[],props:{...a.props,textContent:{value:n.content,viewPropMap:{}}}}}a.type==="html"&&(a=this.transformTemplate(a)),this.viewUnits.push(a)}parseEnv(t){let e=t.openingElement.attributes,r=Object.fromEntries(e.map(s=>this.parseJSXProp(s))),i=t.children.map(s=>this.parseView(s)).flat();this.viewUnits.push({type:"env",props:r,children:i})}parseIf(t){let e=t.openingElement.name.name;if(e===this.elseTagName){let s=this.viewUnits[this.viewUnits.length-1];if(!s||s.type!=="if")throw new Error(`Missing if for ${e}`);s.branches.push({condition:this.t.booleanLiteral(!0),children:t.children.map(p=>this.parseView(p)).flat()});return}let r=t.openingElement.attributes.filter(s=>this.t.isJSXAttribute(s)&&s.name.name==="cond")[0];if(!r)throw new Error(`Missing condition for ${e}`);if(!this.t.isJSXAttribute(r))throw new Error(`JSXSpreadAttribute is not supported for ${e} condition`);if(!this.t.isJSXExpressionContainer(r.value)||!this.t.isExpression(r.value.expression))throw new Error(`Invalid condition for ${e}`);if(e===this.ifTagName){this.viewUnits.push({type:"if",branches:[{condition:r.value.expression,children:t.children.map(s=>this.parseView(s)).flat()}]});return}let i=this.viewUnits[this.viewUnits.length-1];if(!i||i.type!=="if")throw new Error(`Missing if for ${e}`);i.branches.push({condition:r.value.expression,children:t.children.map(s=>this.parseView(s)).flat()})}parseJSXProp(t){if(this.t.isJSXAttribute(t)){let e,r;this.t.isJSXNamespacedName(t.name)?(e=t.name.name.name,r=t.name.namespace.name):e=t.name.name;let i=this.t.isJSXExpressionContainer(t.value)?t.value.expression:t.value;return this.t.isJSXEmptyExpression(i)&&(i=void 0),[e,this.parseProp(i,r)]}return["*spread*",this.parseProp(t.argument)]}parseProp(t,e){if(!t)return{value:this.t.booleanLiteral(!0),viewPropMap:{}};let r={},i=s=>{let p=this.uid(),l=s.node;r[p]=this.parseView(l);let a=this.t.stringLiteral(p);l===t&&(t=a),s.replaceWith(a),s.skip()};return this.traverse(this.wrapWithFile(t),{JSXElement:i,JSXFragment:i}),{value:t,viewPropMap:r,specifier:e}}transformTemplate(t){return!this.willParseTemplate||!this.isHTMLTemplate(t)?t:(t=t,{type:"template",template:this.generateTemplate(t),mutableUnits:this.generateMutableUnits(t),props:this.parseTemplateProps(t)})}generateTemplate(t){let e=Object.fromEntries(this.filterTemplateProps(Object.entries(t.props??[]).filter(([,i])=>this.isStaticProp(i)&&!(this.t.isBooleanLiteral(i.value)&&!i.value.value)))),r=[];return t.children&&(r=t.children.map(i=>{if(i.type==="text")return i;if(i.type==="html"&&this.t.isStringLiteral(i.tag))return this.generateTemplate(i)}).filter(Boolean)),{type:"html",tag:t.tag,props:e,children:r}}generateMutableUnits(t){let e=[],r=(i,s=[])=>{let p=i.children?.filter(a=>a.type==="html"&&this.t.isStringLiteral(a.tag)||a.type==="text").length,l=-1;i.children?.forEach(a=>{if(!(a.type==="html"&&this.t.isStringLiteral(a.tag))&&a.type!=="text"){let n=l+1>=p?-1:l+1;e.push({path:[...s,n],...this.transformTemplate(a)})}else l++}),i.children?.filter(a=>a.type==="html"&&this.t.isStringLiteral(a.tag)).forEach((a,n)=>{r(a,[...s,n])})};return r(t),e}parseTemplateProps(t){let e=[],r=(i,s)=>{i.props&&Object.entries(i.props).filter(([,p])=>!this.isStaticProp(p)).forEach(([p,l])=>{e.push({tag:i.tag,name:i.tag.value,key:p,path:s,value:l.value})}),i.children?.filter(p=>p.type==="html"&&this.t.isStringLiteral(p.tag)).forEach((p,l)=>{r(p,[...s,l])})};return r(t,[]),e}isHTMLTemplate(t){return t.type==="html"&&this.t.isStringLiteral(t.tag)&&!!t.children?.some(e=>e.type==="html"&&this.t.isStringLiteral(e.tag))}isStaticProp(t){return this.t.isStringLiteral(t.value)||this.t.isNumericLiteral(t.value)||this.t.isBooleanLiteral(t.value)||this.t.isNullLiteral(t.value)}filterTemplateProps(t){return t.filter(([e])=>!e.startsWith("on")).filter(([e])=>!this.customHTMLProps.includes(e))}parseView(t){return new o({...this.config,parseTemplate:!1}).parse(t)}wrapWithFile(t){return this.t.file(this.t.program([this.t.expressionStatement(t)]))}uid(){return Math.random().toString(36).slice(2)}};function g(m,t){return new o(t).parse(m)}export{g as parseView}; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/transpiler/jsx-view-parser/dist/index.js.map b/packages/transpiler/jsx-view-parser/dist/index.js.map deleted file mode 100644 index 4e63b85a261548de11d2633d1def10c6822ee3fe..0000000000000000000000000000000000000000 --- a/packages/transpiler/jsx-view-parser/dist/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["../src/parser.ts","../src/index.ts"],"sourcesContent":["import type { NodePath, types as t, traverse as tr } from '@babel/core';\nimport type {\n UnitProp,\n ViewUnit,\n ViewParserConfig,\n AllowedJSXNode,\n HTMLUnit,\n TextUnit,\n MutableUnit,\n TemplateProp,\n} from './types';\n\nexport class ViewParser {\n // ---- Namespace and tag name\n private readonly htmlNamespace: string = 'html'\n private readonly htmlTagNamespace: string = 'tag'\n private readonly compTagNamespace: string = 'comp'\n private readonly envTagName: string = 'env'\n private readonly ifTagName: string = 'if'\n private readonly elseIfTagName: string = 'else-if'\n private readonly elseTagName: string = 'else'\n private readonly customHTMLProps: string[] = ['ref']\n\n private readonly config: ViewParserConfig\n private readonly htmlTags: string[]\n private readonly willParseTemplate: boolean\n\n private readonly t: typeof t\n private readonly traverse: typeof tr\n\n private readonly viewUnits: ViewUnit[] = []\n\n /**\n * @brief Constructor\n * @param config\n */\n constructor(config: ViewParserConfig) {\n this.config = config;\n this.t = config.babelApi.types;\n this.traverse = config.babelApi.traverse;\n this.htmlTags = config.htmlTags;\n this.willParseTemplate = config.parseTemplate ?? true;\n }\n\n /**\n * @brief Parse the node into view units\n * @param node\n * @returns ViewUnit[]\n */\n parse(node: AllowedJSXNode): ViewUnit[] {\n if (this.t.isJSXText(node)) this.parseText(node);\n else if (this.t.isJSXExpressionContainer(node)) this.parseExpression(node.expression);\n else if (this.t.isJSXElement(node)) this.parseElement(node);\n else if (this.t.isJSXFragment(node)) {\n node.children.forEach(child => {\n this.parse(child);\n });\n }\n \n return this.viewUnits;\n }\n\n /**\n * @brief Parse JSXText\n * @param node\n */\n private parseText(node: t.JSXText): void {\n const text = node.value.trim();\n if (!text) return;\n this.viewUnits.push({\n type: 'text',\n content: this.t.stringLiteral(text),\n });\n }\n\n /**\n * @brief Parse JSXExpressionContainer\n * @param node\n */\n private parseExpression(node: t.Expression | t.JSXEmptyExpression): void {\n if (this.t.isJSXEmptyExpression(node)) return;\n if (this.t.isLiteral(node) && !this.t.isTemplateLiteral(node)) {\n // ---- Treat literal as text except template literal\n // Cuz template literal may have viewProp inside like:\n // <>{i18n`hello ${}`}\n this.viewUnits.push({\n type: 'text',\n content: node\n });\n return; \n }\n this.viewUnits.push({\n type: 'exp',\n content: this.parseProp(node),\n });\n }\n\n /**\n * @brief Parse JSXElement\n * @param node \n */\n private parseElement(node: t.JSXElement): void {\n let type: 'html' | 'comp';\n let tag: t.Expression;\n\n // ---- Parse tag and type\n const openingName = node.openingElement.name;\n if (this.t.isJSXIdentifier(openingName)) {\n // ---- Opening name is a JSXIdentifier, e.g.,
\n const name = openingName.name;\n // ---- Specially parse if and env\n if ([this.ifTagName, this.elseIfTagName, this.elseTagName].includes(name)) \n return this.parseIf(node);\n if (name === this.envTagName) return this.parseEnv(node);\n else if (this.htmlTags.includes(name)) {\n type = 'html';\n tag = this.t.stringLiteral(name);\n } else {\n // ---- If the name is not in htmlTags, treat it as a comp\n type = 'comp';\n tag = this.t.identifier(name);\n }\n } else if (this.t.isJSXMemberExpression(openingName)) {\n // ---- Opening name is a JSXMemberExpression, e.g., \n // Treat it as a comp and set the tag as the opening name\n type = 'comp';\n // ---- Turn JSXMemberExpression into MemberExpression recursively\n const toMemberExpression = (node: t.JSXMemberExpression): t.MemberExpression => {\n if (this.t.isJSXMemberExpression(node.object)) {\n return this.t.memberExpression(\n toMemberExpression(node.object),\n this.t.identifier(node.property.name)\n );\n }\n return this.t.memberExpression(\n this.t.identifier(node.object.name),\n this.t.identifier(node.property.name)\n );\n };\n tag = toMemberExpression(openingName);\n } else {\n // ---- isJSXNamespacedName\n const namespace = openingName.namespace.name;\n switch (namespace) {\n case this.compTagNamespace:\n // ---- If the namespace is the same as the compTagNamespace, treat it as a comp\n // and set the tag as an identifier\n // e.g., => [\"comp\", div]\n // this means you've declared a component named \"div\" and force it to be a comp instead an html\n type = 'comp';\n tag = this.t.identifier(openingName.name.name);\n break;\n case this.htmlNamespace:\n // ---- If the namespace is the same as the htmlTagNamespace, treat it as an html\n // and set the tag as a string literal\n // e.g., => [\"html\", \"MyWebComponent\"]\n // the tag will be treated as a string, i.e., \n type = 'html';\n tag = this.t.stringLiteral(openingName.name.name);\n break;\n case this.htmlTagNamespace:\n // ---- If the namespace is the same as the htmlTagNamespace, treat it as an html\n // and set the tag as an identifier\n // e.g., => [\"html\", variable]\n // this unit will be htmlUnit and the html string tag is stored in \"variable\"\n type = 'html';\n tag = this.t.identifier(openingName.name.name);\n break;\n default:\n // ---- Otherwise, treat it as an html tag and make the tag as the namespace:name\n type = 'html';\n tag = this.t.stringLiteral(`${namespace}:${openingName.name.name}`);\n break;\n }\n }\n\n // ---- Parse the props\n const props = node.openingElement.attributes;\n const propMap: Record = Object.fromEntries(\n props.map(prop => this.parseJSXProp(prop))\n );\n\n // ---- Parse the children\n const childUnits = node.children.map(child => this.parseView(child)).flat();\n\n let unit: ViewUnit = { type, tag, props: propMap, children: childUnits };\n \n if (unit.type === 'html' && childUnits.length === 1 && childUnits[0].type === 'text') {\n // ---- If the html unit only has one text child, merge the text into the html unit\n const text = childUnits[0] as TextUnit;\n unit = {\n ...unit,\n children: [],\n props: {\n ...unit.props,\n textContent: {\n value: text.content,\n viewPropMap: {},\n },\n },\n };\n }\n\n if (unit.type === 'html') unit = this.transformTemplate(unit);\n\n this.viewUnits.push(unit);\n }\n\n /**\n * @brief Parse EnvUnit\n * @param node\n */\n private parseEnv(node: t.JSXElement): void {\n const props = node.openingElement.attributes;\n const propMap: Record = Object.fromEntries(\n props.map(prop => this.parseJSXProp(prop))\n );\n const children = node.children.map(child => this.parseView(child)).flat();\n this.viewUnits.push({\n type: 'env',\n props: propMap,\n children,\n });\n }\n\n private parseIf(node: t.JSXElement): void {\n const name = (node.openingElement.name as t.JSXIdentifier).name;\n // ---- else\n if (name === this.elseTagName) {\n const lastUnit = this.viewUnits[this.viewUnits.length - 1];\n if (!lastUnit || lastUnit.type !== 'if') throw new Error(`Missing if for ${name}`);\n lastUnit.branches.push({\n condition: this.t.booleanLiteral(true),\n children: node.children.map(child => this.parseView(child)).flat(),\n });\n return;\n }\n\n const condition = node.openingElement.attributes.filter(attr => \n this.t.isJSXAttribute(attr) && attr.name.name === 'cond'\n )[0];\n if (!condition) throw new Error(`Missing condition for ${name}`);\n if (!this.t.isJSXAttribute(condition)) throw new Error(`JSXSpreadAttribute is not supported for ${name} condition`);\n if (!this.t.isJSXExpressionContainer(condition.value) || !this.t.isExpression(condition.value.expression))\n throw new Error(`Invalid condition for ${name}`);\n \n // ---- if\n if (name === this.ifTagName) {\n this.viewUnits.push({\n type: 'if',\n branches: [{\n condition: condition.value.expression,\n children: node.children.map(child => this.parseView(child)).flat(),\n }],\n });\n return;\n } \n\n // ---- else-if\n const lastUnit = this.viewUnits[this.viewUnits.length - 1];\n if (!lastUnit || lastUnit.type !== 'if') \n throw new Error(`Missing if for ${name}`);\n\n lastUnit.branches.push({\n condition: condition.value.expression,\n children: node.children.map(child => this.parseView(child)).flat(),\n });\n }\n\n /**\n * @brief Parse JSXAttribute or JSXSpreadAttribute into UnitProp,\n * considering both namespace and expression\n * @param prop \n * @returns [propName, propValue]\n */\n private parseJSXProp(prop: t.JSXAttribute | t.JSXSpreadAttribute): [string, UnitProp] {\n if (this.t.isJSXAttribute(prop)) {\n let propName: string, specifier: string | undefined;\n if (this.t.isJSXNamespacedName(prop.name)) {\n // ---- If the prop name is a JSXNamespacedName, e.g., bind:value\n // give it a special tag\n propName = prop.name.name.name;\n specifier = prop.name.namespace.name;\n } else {\n propName = prop.name.name;\n }\n let value = this.t.isJSXExpressionContainer(prop.value) ? prop.value.expression : prop.value;\n if (this.t.isJSXEmptyExpression(value)) value = undefined;\n return [propName, this.parseProp(value, specifier)];\n }\n // ---- Use *spread* as the propName to avoid conflict with other props\n return ['*spread*', this.parseProp(prop.argument)];\n }\n\n /**\n * @brief Parse the prop node into UnitProp\n * @param propNode\n * @param specifier\n * @returns UnitProp\n */\n private parseProp(propNode: t.Expression | undefined | null, specifier?: string): UnitProp {\n // ---- If there is no propNode, set the default prop as true\n if (!propNode) {\n return {\n value: this.t.booleanLiteral(true),\n viewPropMap: {},\n };\n }\n\n // ---- Collect sub jsx nodes as Prop\n const viewPropMap: Record = {};\n const parseViewProp = (innerPath: NodePath): void => {\n const id = this.uid();\n const node = innerPath.node;\n viewPropMap[id] = this.parseView(node);\n const newNode = this.t.stringLiteral(id);\n if (node === propNode) {\n // ---- If the node is the propNode, replace it with the new node\n propNode = newNode;\n }\n // ---- Replace the node and skip the inner path\n innerPath.replaceWith(newNode);\n innerPath.skip();\n };\n\n // ---- Apply the parseViewProp to JSXElement and JSXFragment\n this.traverse(this.wrapWithFile(propNode), {\n JSXElement: parseViewProp,\n JSXFragment: parseViewProp,\n });\n\n return {\n value: propNode,\n viewPropMap,\n specifier,\n };\n }\n\n transformTemplate(unit: ViewUnit): ViewUnit {\n if (!this.willParseTemplate) return unit;\n if (!this.isHTMLTemplate(unit)) return unit;\n unit = unit as HTMLUnit;\n return {\n type: 'template',\n template: this.generateTemplate(unit),\n mutableUnits: this.generateMutableUnits(unit),\n props: this.parseTemplateProps(unit),\n };\n }\n\n /**\n * @brief Generate the entire HTMLUnit\n * @param unit\n * @returns HTMLUnit\n */\n private generateTemplate(unit: HTMLUnit): HTMLUnit {\n const staticProps = Object.fromEntries(this.filterTemplateProps(\n // ---- Get all the static props\n Object.entries(unit.props ?? []).filter(\n ([, prop]) =>\n this.isStaticProp(prop) &&\n // ---- Filter out props with false values\n !(this.t.isBooleanLiteral(prop.value) && !prop.value.value)\n )\n ));\n\n let children: (HTMLUnit | TextUnit)[] = [];\n if (unit.children) {\n children = unit.children\n .map(unit => {\n if (unit.type === 'text') return unit;\n if (unit.type === 'html' && this.t.isStringLiteral(unit.tag)) {\n return this.generateTemplate(unit);\n }\n })\n .filter(Boolean) as (HTMLUnit | TextUnit)[];\n }\n return {\n type: 'html',\n tag: unit.tag,\n props: staticProps,\n children,\n };\n }\n\n /**\n * @brief Collect all the mutable nodes in a static HTMLUnit\n * We use this function to collect mutable nodes' path and props,\n * so that in the generator, we know which position to insert the mutable nodes\n * @param htmlUnit\n * @returns mutable particles\n */\n private generateMutableUnits(htmlUnit: HTMLUnit): MutableUnit[] {\n const mutableUnits: MutableUnit[] = [];\n\n const generateMutableUnit = (unit: HTMLUnit, path: number[] = []) => {\n const maxHtmlIdx = unit.children?.filter(\n child => (child.type === 'html' && this.t.isStringLiteral(child.tag)) ||\n child.type === 'text'\n ).length;\n let htmlIdx = -1;\n // ---- Generate mutable unit for current HTMLUnit\n unit.children?.forEach((child) => {\n if (\n !(child.type === 'html' && this.t.isStringLiteral(child.tag)) &&\n !(child.type === 'text')\n ) {\n const idx = htmlIdx + 1 >= maxHtmlIdx ? -1 : htmlIdx + 1;\n mutableUnits.push({\n path: [...path, idx],\n ...this.transformTemplate(child),\n });\n } else {\n htmlIdx++;\n }\n });\n // ---- Recursively generate mutable units for static HTMLUnit children\n unit.children\n ?.filter(\n child => child.type === 'html' && this.t.isStringLiteral(child.tag)\n )\n .forEach((child, idx) => {\n generateMutableUnit(child as HTMLUnit, [...path, idx]);\n });\n };\n generateMutableUnit(htmlUnit);\n\n return mutableUnits;\n }\n\n /**\n * @brief Collect all the props in a static HTMLUnit or its nested HTMLUnit children\n * Just like the mutable nodes, props are also equipped with path,\n * so that we know which HTML ChildNode to insert the props\n * @param htmlUnit\n * @returns props\n */\n private parseTemplateProps(htmlUnit: HTMLUnit): TemplateProp[] {\n const templateProps: TemplateProp[] = [];\n const generateVariableProp = (unit: HTMLUnit, path: number[]) => {\n // ---- Generate all non-static(string/number/boolean) props for current HTMLUnit\n // to be inserted further in the generator\n unit.props && Object.entries(unit.props)\n .filter(([, prop]) => !this.isStaticProp(prop))\n .forEach(([key, prop]) => {\n templateProps.push({\n tag: unit.tag,\n name: (unit.tag as t.StringLiteral).value,\n key,\n path,\n value: prop.value,\n });\n });\n // ---- Recursively generate props for static HTMLUnit children\n unit.children\n ?.filter(child => child.type === 'html' && this.t.isStringLiteral(child.tag))\n .forEach((child, idx) => {\n generateVariableProp(child as HTMLUnit, [...path, idx]);\n });\n };\n generateVariableProp(htmlUnit, []);\n\n return templateProps;\n }\n\n /**\n * @brief Check if a ViewUnit is a static HTMLUnit that can be parsed into a template\n * Must satisfy:\n * 1. type is html\n * 2. tag is a string literal, i.e., non-dynamic tag\n * 3. has at least one child that is a static HTMLUnit,\n * or else just call a createElement function, no need for template clone\n * @param viewUnit\n * @returns is a static HTMLUnit\n */\n private isHTMLTemplate(viewUnit: ViewUnit): boolean {\n return (\n viewUnit.type === 'html' &&\n this.t.isStringLiteral(viewUnit.tag) &&\n !!viewUnit.children?.some(\n child => child.type === 'html' && this.t.isStringLiteral(child.tag)\n )\n );\n }\n\n private isStaticProp(prop: UnitProp): boolean {\n return (\n this.t.isStringLiteral(prop.value) ||\n this.t.isNumericLiteral(prop.value) ||\n this.t.isBooleanLiteral(prop.value) ||\n this.t.isNullLiteral(prop.value)\n );\n }\n\n /**\n * @brief Filter out some props that are not needed in the template,\n * these are all special props to be parsed differently in the generator\n * @param props\n * @returns filtered props\n */\n private filterTemplateProps(\n props: Array<[string, T]>\n ): Array<[string, T]> {\n return (\n props\n // ---- Filter out event listeners\n .filter(([key]) => !key.startsWith('on'))\n // ---- Filter out specific props\n .filter(([key]) => !this.customHTMLProps.includes(key))\n );\n }\n\n /**\n * @brief Parse the view by duplicating current parser's classRootPath, statements and htmlTags\n * @param statements\n * @returns ViewUnit[]\n */\n private parseView(node: AllowedJSXNode): ViewUnit[] {\n return new ViewParser({...this.config, parseTemplate:false}).parse(node);\n }\n \n\n /**\n * @brief Wrap the value in a file\n * @param node\n * @returns wrapped value\n */\n private wrapWithFile(node: t.Expression): t.File {\n return this.t.file(this.t.program([this.t.expressionStatement(node)]));\n }\n\n /**\n * @brief Generate a unique id\n * @returns a unique id\n */\n private uid(): string {\n return Math.random().toString(36).slice(2);\n }\n}\n","import { ViewParser } from './parser';\nimport type { ViewUnit, ViewParserConfig, AllowedJSXNode } from './types';\n\n/**\n * @brief Generate view units from a babel ast\n * @param statement\n * @param config\n * @returns ViewUnit[]\n */\nexport function parseView(\n node: AllowedJSXNode,\n config: ViewParserConfig\n): ViewUnit[] {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AAC,CAAC,CAAC,CACvE,CAMQ,KAAc,CACpB,OAAO,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAC3C,CACF,ECjhBO,SAASuC,EACdC,EACAC,EACY,CACZ,OAAQ,IAAIC,EAAWD,CAAM,EAAE,MAAMD,CAAI,CAC3C","names":["ViewParser","config","node","child","text","type","tag","openingName","name","toMemberExpression","namespace","props","propMap","prop","childUnits","unit","children","lastUnit","condition","attr","propName","specifier","value","propNode","viewPropMap","parseViewProp","innerPath","id","newNode","staticProps","htmlUnit","mutableUnits","generateMutableUnit","path","maxHtmlIdx","htmlIdx","idx","templateProps","generateVariableProp","key","viewUnit","parseView","node","config","ViewParser"]} \ No newline at end of file