babel-preset-dlight
Advanced tools
Comparing version 1.0.0-alpha.31 to 1.0.0-alpha.32
@@ -1,2 +0,2 @@ | ||
var O=Object.defineProperty;var L=(c,e,t)=>e in c?O(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var M=(c,e,t)=>(L(c,typeof e!="symbol"?e+"":e,t),t);import $ from"babel-plugin-syntax-typescript-new";import V from"@babel/plugin-syntax-decorators";import{minimatch as k}from"minimatch";import{parseView as I}from"@dlightjs/view-parser";import{parseReactivity as N}from"@dlightjs/reactivity-parser";import{generateSubView as T,generateView as j}from"@dlightjs/view-generator";var P=process.env.NODE_ENV==="development",C=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","acronym","applet","basefont","bgsound","big","blink","center","dir","font","frame","frameset","isindex","keygen","listing","marquee","menuitem","multicol","nextid","nobr","noembed","noframes","param","plaintext","rb","rtc","spacer","strike","tt","xmp","animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tspan","use","view"],E=["Static","Prop","Env","Content","Children"],u="@dlightjs/dlight",f=Object.fromEntries(["createTemplate","setStyle","setDataset","setEvent","setHTMLProp","setHTMLAttr","setHTMLProps","setHTMLAttrs","insertNode","createElement","ForNode","CondNode","EnvNode","createTextNode","updateText","ExpNode","PropView","SubViewNode"].map((c,e)=>P?[c,c]:[c,`$${e}$`])),w={acceptCharset:"accept-charset",colSpan:"colspan",contentEditable:"contenteditable",formAction:"formaction",formEnctype:"formenctype",formMethod:"formmethod",formNoValidate:"formnovalidate",formTarget:"formtarget",httpEquiv:"http-equiv",intrinsicSize:"intrinsicsize",inputMode:"inputmode",itemProp:"itemprop",maxLength:"maxlength",minLength:"minlength",noValidate:"novalidate",playsInline:"playsinline",referrerPolicy:"referrerpolicy",rowSpan:"rowspan",tabIndex:"tabindex",ariaAutocomplete:"aria-autocomplete",ariaChecked:"aria-checked",ariaDisabled:"aria-disabled",ariaErrorMessage:"aria-errormessage",ariaExpanded:"aria-expanded",ariaHasPopup:"aria-haspopup",ariaHidden:"aria-hidden",ariaInvalid:"aria-invalid",ariaLabel:"aria-label",ariaLevel:"aria-level",ariaModal:"aria-modal",ariaMultiline:"aria-multiline",ariaMultiSelectable:"aria-multiselectable",ariaOrientation:"aria-orientation",ariaPlaceholder:"aria-placeholder",ariaPressed:"aria-pressed",ariaReadonly:"aria-readonly",ariaRequired:"aria-required",ariaSelected:"aria-selected",ariaSort:"aria-sort",ariaValuemax:"aria-valuemax",ariaValuemin:"aria-valuemin",ariaValueNow:"aria-valuenow",ariaValueText:"aria-valuetext",ariaBusy:"aria-busy",ariaLive:"aria-live",ariaRelevant:"aria-relevant",ariaAtomic:"aria-atomic",ariaDropEffect:"aria-dropeffect",ariaGrabbed:"aria-grabbed",ariaActiveDescendant:"aria-activedescendant",ariaColCount:"aria-colcount",ariaColIndex:"aria-colindex",ariaColSpan:"aria-colspan",ariaControls:"aria-controls",ariaDescribedBy:"aria-describedby",ariaDescription:"aria-description",ariaDetails:"aria-details",ariaFlowTo:"aria-flowto",ariaLabelLedBy:"aria-labelledby",ariaOwns:"aria-owns",ariaPosInset:"aria-posinset",ariaRowCount:"aria-rowcount",ariaRowIndex:"aria-rowindex",ariaRowSpan:"aria-rowspan",ariaSetSize:"aria-setsize"},D={textContent:["*"],innerHTML:["*"],accept:["form","input"],acceptCharset:["form"],accesskey:["*"],action:["form"],align:["caption","col","colgroup","hr","iframe","img","table","tbody","td","tfoot","th","thead","tr"],allow:["iframe"],alt:["area","img","input"],async:["script"],autocapitalize:["*"],autocomplete:["form","input","select","textarea"],autofocus:["button","input","select","textarea"],autoplay:["audio","video"],background:["body","table","td","th"],bgColor:["body","col","colgroup","marquee","table","tbody","tfoot","td","th","tr"],border:["img","object","table"],buffered:["audio","video"],capture:["input"],charset:["meta"],checked:["input"],cite:["blockquote","del","ins","q"],class:["*"],color:["font","hr"],cols:["textarea"],colSpan:["td","th"],content:["meta"],contentEditable:["*"],contextmenu:["*"],controls:["audio","video"],coords:["area"],crossOrigin:["audio","img","link","script","video"],csp:["iframe"],data:["object"],dateTime:["del","ins","time"],decoding:["img"],default:["track"],defer:["script"],dir:["*"],dirname:["input","textarea"],disabled:["button","fieldset","input","optgroup","option","select","textarea"],download:["a","area"],draggable:["*"],enctype:["form"],enterKeyHint:["textarea","contenteditable"],for:["label","output"],form:["button","fieldset","input","label","meter","object","output","progress","select","textarea"],formAction:["input","button"],formEnctype:["button","input"],formMethod:["button","input"],formNoValidate:["button","input"],formTarget:["button","input"],headers:["td","th"],height:["canvas","embed","iframe","img","input","object","video"],hidden:["*"],high:["meter"],href:["a","area","base","link"],hreflang:["a","link"],httpEquiv:["meta"],id:["*"],integrity:["link","script"],intrinsicSize:["img"],inputMode:["textarea","contenteditable"],ismap:["img"],itemProp:["*"],kind:["track"],label:["optgroup","option","track"],lang:["*"],language:["script"],loading:["img","iframe"],list:["input"],loop:["audio","marquee","video"],low:["meter"],manifest:["html"],max:["input","meter","progress"],maxLength:["input","textarea"],minLength:["input","textarea"],media:["a","area","link","source","style"],method:["form"],min:["input","meter"],multiple:["input","select"],muted:["audio","video"],name:["button","form","fieldset","iframe","input","object","output","select","textarea","map","meta","param"],noValidate:["form"],open:["details","dialog"],optimum:["meter"],pattern:["input"],ping:["a","area"],placeholder:["input","textarea"],playsInline:["video"],poster:["video"],preload:["audio","video"],readonly:["input","textarea"],referrerPolicy:["a","area","iframe","img","link","script"],rel:["a","area","link"],required:["input","select","textarea"],reversed:["ol"],role:["*"],rows:["textarea"],rowSpan:["td","th"],sandbox:["iframe"],scope:["th"],scoped:["style"],selected:["option"],shape:["a","area"],size:["input","select"],sizes:["link","img","source"],slot:["*"],span:["col","colgroup"],spellcheck:["*"],src:["audio","embed","iframe","img","input","script","source","track","video"],srcdoc:["iframe"],srclang:["track"],srcset:["img","source"],start:["ol"],step:["input"],style:["*"],summary:["table"],tabIndex:["*"],target:["a","area","base","form"],title:["*"],translate:["*"],type:["button","input","embed","object","ol","script","source","style","menu","link"],usemap:["img","input","object"],value:["button","data","input","li","meter","option","progress","param","text"],width:["canvas","embed","iframe","img","input","object","video"],wrap:["textarea"],ariaAutocomplete:["*"],ariaChecked:["*"],ariaDisabled:["*"],ariaErrorMessage:["*"],ariaExpanded:["*"],ariaHasPopup:["*"],ariaHidden:["*"],ariaInvalid:["*"],ariaLabel:["*"],ariaLevel:["*"],ariaModal:["*"],ariaMultiline:["*"],ariaMultiSelectable:["*"],ariaOrientation:["*"],ariaPlaceholder:["*"],ariaPressed:["*"],ariaReadonly:["*"],ariaRequired:["*"],ariaSelected:["*"],ariaSort:["*"],ariaValuemax:["*"],ariaValuemin:["*"],ariaValueNow:["*"],ariaValueText:["*"],ariaBusy:["*"],ariaLive:["*"],ariaRelevant:["*"],ariaAtomic:["*"],ariaDropEffect:["*"],ariaGrabbed:["*"],ariaActiveDescendant:["*"],ariaColCount:["*"],ariaColIndex:["*"],ariaColSpan:["*"],ariaControls:["*"],ariaDescribedBy:["*"],ariaDescription:["*"],ariaDetails:["*"],ariaFlowTo:["*"],ariaLabelledBy:["*"],ariaOwns:["*"],ariaPosInset:["*"],ariaRowCount:["*"],ariaRowIndex:["*"],ariaRowSpan:["*"],ariaSetSize:["*"]};var b=class{dlightPackageName=u;babelApi;t;traverse;enableDevTools;includes;excludes;htmlTags;attributeMap;alteredAttrMap;parseTemplate;constructor(e,t,r,i,s,o,n,a,d){this.babelApi=e,this.t=t,this.traverse=e.traverse,this.includes=r,this.excludes=i,this.enableDevTools=P&&s,this.htmlTags=typeof o=="function"?o(C):o.includes("*")?[...new Set([...C,...o])].filter(l=>l!=="*"):o,this.attributeMap=n,this.alteredAttrMap=a,this.parseTemplate=d}classDeclarationNode;classBodyNode;propertiesContainer={};dependencyMap={};enter=!0;enterClassNode=!1;className;programNode;allImports=[];didAlterImports=!1;clearNode(){this.classDeclarationNode=void 0,this.classBodyNode=void 0,this.propertiesContainer={},this.dependencyMap={},this.enter=!0,this.enterClassNode=!1,this.className=void 0}get availableProperties(){return Object.entries(this.propertiesContainer).filter(([e,{isWatcher:t,isStatic:r,isChildren:i}])=>e!=="_$compName"&&!t&&!r&&!i).map(([e])=>e)}initNode(e){let t=e.node;if(this.classDeclarationNode=t,this.classBodyNode=t.body,this.propertiesContainer={},t.id?.name||(t.id=this.t.identifier(`Anonymous_${b.uid()}`)),this.className=t.id?.name,this.handleClassCustomDecorators(),this.enableDevTools&&this.classBodyNode.body.unshift(this.t.classProperty(this.t.identifier("_$compName"),this.t.stringLiteral(this.className))),!this.didAlterImports){let r=this.allImports.filter(i=>i.source.value===u);this.dlightPackageName!==u&&r.forEach(i=>{i.source.value=this.dlightPackageName}),this.programNode.body.unshift(this.t.importDeclaration(Object.entries(f).map(([i,s])=>this.t.importSpecifier(this.t.identifier(s),this.t.identifier(i))),this.t.stringLiteral(this.dlightPackageName))),this.didAlterImports=!0}}enterProgram(e){}programEnterVisitor(e,t){if(this.enter=this.fileAllowed(t),!this.enter)return;if(this.allImports=e.node.body.filter(i=>this.t.isImportDeclaration(i)),this.allImports.filter(i=>i.source.value===u).length===0){this.enter=!1;return}this.programNode=e.node,this.enterProgram(e)}exitProgram(e){}programExitVisitor(e){this.enter&&(this.didAlterImports=!1,this.allImports=[],this.programNode=void 0,this.exitProgram(e))}enterClass(e){}classEnter(e){this.enter&&(this.enterClassNode=this.isDLightView(e),this.enterClass&&(this.initNode(e),this.enterClass(e)))}exitClass(e){}classExit(e){this.enter&&this.enterClassNode&&(this.transformDLightClass(),this.exitClass(e),this.clearNode(),this.enterClassNode=!1)}visitClassMethod(e){}classMethodVisitor(e){if(!this.enterClassNode||!this.t.isIdentifier(e.node.key))return;let t=e.node.key.name;if(t==="View"||this.findDecoratorByName(e.node.decorators,"View"))return;let i=e.node,s=this.findDecoratorByName(i.decorators,"Watch");if(!s){if(this.t.isIdentifier(i.key)&&["constructor","willMount","didMount","willUnmount","didUnmount"].includes(i.key.name))return;this.autoBindMethods(i);return}let o=[];if(this.t.isIdentifier(s))o=this.getDependencies(e);else{let n=s.arguments[0];this.t.isArrayExpression(n)&&(o=n.elements.filter(a=>this.t.isStringLiteral(a)).map(a=>a.value),o=[...new Set(o)])}this.propertiesContainer[t]={node:i,deps:o,isWatcher:!0},i.decorators=this.removeDecorators(i.decorators,["Watch"]),this.visitClassMethod(e)}visitClassProperty(e){}classPropertyVisitor(e){if(!this.enterClassNode)return;let t=e.node;if(!this.t.isIdentifier(t.key))return;let r=t.key.name;if(r==="View")return;let i=t.decorators;if(this.findDecoratorByName(i,"View"))return;let o=!!this.findDecoratorByName(i,"Prop"),n=!!this.findDecoratorByName(i,"Env"),a=!!this.findDecoratorByName(t.decorators,"Children"),d=a?[]:this.getDependencies(e);this.propertiesContainer[r]={node:t,deps:d,isStatic:!!this.findDecoratorByName(i,"Static"),isContent:!!this.findDecoratorByName(i,"Content"),isChildren:a,isPropOrEnv:o?"Prop":n?"Env":void 0},t.decorators=this.removeDecorators(i,E),this.visitClassProperty(e)}resolveWatcherDecorator(e){if(!this.t.isIdentifier(e.key))return;let t=e.key.name,r=this.classBodyNode.body.indexOf(e),i=this.t.classProperty(this.t.identifier(`$w$${t}`));this.classBodyNode.body.splice(r,0,i)}resolveChildrenDecorator(e){if(!this.classBodyNode||!this.t.isIdentifier(e.key))return;let t=e.key.name,r=this.classBodyNode.body.indexOf(e),i=this.t.memberExpression(this.t.thisExpression(),this.t.identifier("_$children")),s=this.t.classMethod("get",this.t.identifier(t),[],this.t.blockStatement([this.t.returnStatement(i)]));this.classBodyNode.body.splice(r,1,s)}resolveContentDecorator(e){if(!this.classBodyNode||!this.t.isIdentifier(e.key)||this.classBodyNode.body.some(s=>this.t.isClassProperty(s)&&s.key.name==="_$contentKey"))return;let t=e.key.name,r=this.classBodyNode.body.indexOf(e),i=this.t.classProperty(this.t.identifier("_$contentKey"),this.t.stringLiteral(t));this.classBodyNode.body.splice(r,0,i)}resolvePropDecorator(e,t){if(!this.classBodyNode||!this.t.isIdentifier(e.key))return;let r=e.key.name,i=this.classBodyNode.body.indexOf(e),s=t.toLowerCase()==="prop"?"p":"e",o=this.t.classProperty(this.t.identifier(`$${s}$${r}`));this.classBodyNode.body.splice(i,0,o)}resolveStateDecorator(e,t,r){if(!this.classBodyNode||!this.t.isIdentifier(e.key))return;let i=e.key.name;e.key.name=`$${i}`;let s=this.classBodyNode.body.indexOf(e),o=this.t.classProperty(this.t.identifier(`$$${i}`),this.t.numericLiteral(1<<t)),n=r?[this.t.classProperty(this.t.identifier(`$s$${i}`),this.t.arrayExpression([...r].map(l=>this.t.stringLiteral(l))))]:[],a=this.t.classMethod("get",this.t.identifier(i),[],this.t.blockStatement([this.t.returnStatement(this.t.memberExpression(this.t.thisExpression(),this.t.identifier(`$${i}`)))])),d=this.t.classMethod("set",this.t.identifier(i),[this.t.identifier("value")],this.t.blockStatement([this.t.expressionStatement(this.t.callExpression(this.t.memberExpression(this.t.thisExpression(),this.t.identifier("_$updateProp")),[this.t.stringLiteral(i),this.t.identifier("value")]))]));this.classBodyNode.body.splice(s+1,0,o,...n,a,d)}handleClassCustomDecorators(){if(!this.classBodyNode)return;let e=this.classDeclarationNode?.decorators;if(!e)return;this.findDecoratorByName(e,"ForwardProps")&&(this.classBodyNode.body.unshift(this.t.classProperty(this.t.identifier("_$forwardProps")),this.t.classProperty(this.t.identifier("_$forwardPropsSet"),this.t.newExpression(this.t.identifier("Set"),[])),this.t.classProperty(this.t.identifier("_$forwardPropsId"),this.t.arrayExpression([]))),this.classDeclarationNode.decorators=this.removeDecorators(e,["ForwardProps"]))}transformDLightClass(){let e=this.handleView(),t=Object.entries(this.propertiesContainer).reverse(),r=this.dependencyMapReversed();for(let[i,{node:s,deps:o,isStatic:n,isChildren:a,isPropOrEnv:d,isWatcher:l,isContent:p}]of t){if(a){this.resolveChildrenDecorator(s);continue}o.length>0&&(e.push(...o),l?this.resolveWatcherDecorator(s):this.handleDerivedProperty(s)),d&&this.resolvePropDecorator(s,d),p&&(this.resolvePropDecorator(s,"Prop"),this.resolveContentDecorator(s)),!n&&e.includes(i)&&this.resolveStateDecorator(s,this.availableProperties.indexOf(i),r[i])}}handleView(){if(!this.classBodyNode)return[];let e=new Set,t,r=[];for(let a of this.classBodyNode.body){if(!this.t.isClassProperty(a)&&!this.t.isClassMethod(a)||!this.t.isIdentifier(a.key))continue;let d=this.findDecoratorByName(a.decorators,"View"),l=a.key.name==="View";if(!(!d&&!l)){if(this.t.isClassProperty(a)){let p=a.value;for(;this.t.isTSAsExpression(p);)p=p.expression;if(!this.t.isArrowFunctionExpression(p))continue;a.value=p;let h=this.arrowFunctionPropertyToMethod(a);if(!h)continue;a=h}d?(a.decorators=null,r.push(a)):t=a}}let i=r.map(a=>a.key.name),s=Object.fromEntries(r.map(a=>{let d=a.params[0];if(!d||!this.t.isObjectPattern(d))return["-",null];let l=Object.fromEntries(d.properties.map(p=>{if(!this.t.isObjectProperty(p))return["-",null];let h=p.key.name,y=this.getIdentifiers(this.t.assignmentExpression("=",this.t.objectPattern([this.t.objectProperty(this.t.numericLiteral(0),p.value)]),this.t.numericLiteral(0))).filter(g=>g!==h);return[h,y]}).filter(([p,h])=>h));return[a.key.name,l]}).filter(([a,d])=>d)),o=-1;if(t){let a;[a,o]=this.alterMainView(t,i,s),a.forEach(e.add.bind(e))}r.forEach(a=>{let d;[d,o]=this.alterSubView(a,i,s,o),d.forEach(e.add.bind(e))});let n=[];return this.availableProperties.forEach(a=>{e.has(a)&&n.push(a)}),n}alterMainView(e,t,r){let i=I(e.body,{babelApi:this.babelApi,subviewNames:t,htmlTags:this.htmlTags}),[s,o]=N(i,{babelApi:this.babelApi,availableProperties:this.availableProperties,dependencyMap:this.dependencyMap,alteredAttrMap:this.alteredAttrMap,parseTemplate:this.parseTemplate}),[n,a,d]=j(s,{babelApi:this.babelApi,className:this.className,importMap:f,subViewPropMap:Object.fromEntries(Object.entries(r).map(([l,p])=>[l,Object.keys(p)])),templateIdx:-1,attributeMap:this.attributeMap});return e.body=n,this.classBodyNode?.body.push(...a),[o,d]}alterSubView(e,t,r,i){e.params.length===0?e.params.push(this.t.identifier("_$"),this.t.identifier("$subviewNode")):e.params.length===1?e.params.push(this.t.identifier("$subviewNode")):(e.params[1]=this.t.identifier("$subviewNode"),e.params.length=2);let s=I(e.body,{babelApi:this.babelApi,subviewNames:t,htmlTags:this.htmlTags}),[o,n]=N(s,{babelApi:this.babelApi,availableProperties:this.availableProperties,dependencyMap:this.dependencyMap,alteredAttrMap:this.alteredAttrMap}),a=r[e.key.name]??[],d={};Object.entries(a).forEach(([v,x])=>{x.forEach(B=>{d[B]=[v]})});let[l]=N(s,{babelApi:this.babelApi,availableProperties:Object.keys(a),dependencyMap:this.dependencyMap,dependencyParseType:"identifier",identifierDepMap:d,alteredAttrMap:this.alteredAttrMap}),p=Object.fromEntries(Object.entries(r).map(([v,x])=>[v,Object.keys(x)])),[h,y,g]=T(o,l,e.params[0],{babelApi:this.babelApi,className:this.className,importMap:f,subViewPropMap:p,templateIdx:i,attributeMap:this.attributeMap});return e.body=h,this.classBodyNode?.body.push(...y),[n,g]}fileAllowed(e){return this.includes.includes("*")?!0:!(!e||this.excludes.some(t=>k(e,t))||!this.includes.some(t=>k(e,t)))}isDLightView(e){let t=e.node;return(t.decorators??[]).find(s=>this.t.isIdentifier(s.expression,{name:"View"}))&&(t.superClass=this.t.identifier("View"),t.decorators=t.decorators?.filter(s=>!this.t.isIdentifier(s.expression,{name:"View"}))),this.t.isIdentifier(t.superClass,{name:"View"})}removeDecorators(e,t){return e?e.filter(r=>!(this.t.isIdentifier(r.expression)&&t.includes(r.expression.name)||this.t.isCallExpression(r.expression)&&this.t.isIdentifier(r.expression.callee)&&t.includes(r.expression.callee.name))):[]}findDecoratorByName(e,t){if(e)return e.find(r=>this.t.isIdentifier(r.expression,{name:t})||this.t.isCallExpression(r.expression)&&this.t.isIdentifier(r.expression.callee,{name:t}))?.expression}addConstructor(){let e=this.classBodyNode.body.find(t=>this.t.isClassMethod(t,{kind:"constructor"}));return e||(e=this.t.classMethod("constructor",this.t.identifier("constructor"),[],this.t.blockStatement([this.t.expressionStatement(this.t.callExpression(this.t.super(),[]))])),this.classBodyNode.body.unshift(e),e)}autoBindMethods(e){this.addConstructor().body.body.push(this.t.expressionStatement(this.t.assignmentExpression("=",this.t.memberExpression(this.t.thisExpression(),e.key),this.t.callExpression(this.t.memberExpression(this.t.memberExpression(this.t.thisExpression(),e.key),this.t.identifier("bind")),[this.t.thisExpression()]))))}handleDerivedProperty(e){if(!this.t.isIdentifier(e.key))return;let t=e.key.name,r=e.value,i=this.classBodyNode.body.indexOf(e),s=this.t.classMethod("get",this.t.identifier(`$f$${t}`),[],this.t.blockStatement([this.t.returnStatement(r)]));this.classBodyNode.body.splice(i+1,0,s),e.value=null}getDependencies(e){let t=e.node;if(!this.t.isIdentifier(t.key))return[];let r=new Set,i=new Set;e.scope.traverse(t,{MemberExpression:n=>{if(!this.t.isIdentifier(n.node.property))return;let a=n.node.property.name;this.isAssignmentExpressionLeft(n)?i.add(a):this.availableProperties.includes(a)&&this.t.isThisExpression(n.node.object)&&!this.isMemberInEscapeFunction(n,this.classDeclarationNode)&&!this.isMemberInManualFunction(n,this.classDeclarationNode)&&!this.isAssignmentExpressionRight(n,this.classDeclarationNode)&&(r.add(a),this.dependencyMap[a]?.forEach(r.add.bind(r)))}}),i.forEach(r.delete.bind(r));let s=t.key.name,o=[...r];return r.size>0&&(this.dependencyMap[s]=o),o}dependencyMapReversed(){let e={};return Object.entries(this.dependencyMap).forEach(([t,r])=>{r.forEach(i=>{e[i]||(e[i]=new Set),e[i].add(t)})}),e}arrowFunctionPropertyToMethod(e){if(!this.t.isArrowFunctionExpression(e.value))return;let t=e.value;if(!this.t.isBlockStatement(t.body))return;let r=this.classBodyNode.body.indexOf(e),i=this.t.classMethod("method",e.key,t.params,t.body);return this.classBodyNode.body.splice(r,1,i),i}isMemberExpressionProperty(e,t){return this.t.isMemberExpression(e)&&!e.computed&&e.property===t}isObjectKey(e,t){return this.t.isObjectProperty(e)&&e.key===t}valueWithArrowFunc(e){e.value||(e.value=this.t.identifier("undefined")),e.value=this.t.arrowFunctionExpression([],e.value)}valueWrapper(e){return this.t.file(this.t.program([this.t.isStatement(e)?e:this.t.expressionStatement(e)]))}isAttrFromFunction(e,t){let r=e.parentPath,i=s=>this.t.isIdentifier(s)?s.name===t:this.t.isAssignmentPattern(s)?i(s.left):this.t.isArrayPattern(s)?s.elements.filter(Boolean).map(o=>i(o)).includes(!0):this.t.isObjectPattern(s)?s.properties.filter(o=>this.t.isObjectProperty(o)&&this.t.isIdentifier(o.key)).map(o=>o.key.name).includes(t):this.t.isRestElement(s)?i(s.argument):!1;for(;r;){let s=r.node;if(this.t.isArrowFunctionExpression(s)||this.t.isFunctionDeclaration(s)){for(let o of s.params)if(i(o))return!0}r=r.parentPath}return!1}isStandAloneIdentifier(e){let t=e.node,r=e.parentPath?.node;if(this.t.isMemberExpression(r)&&r.property===t||this.isAttrFromFunction(e,t.name))return!1;for(;e.parentPath;){if(this.t.isVariableDeclarator(e.parentPath.node)||this.t.isObjectProperty(e.parentPath.node)&&e.parentPath.node.key===e.node&&!e.parentPath.node.computed)return!1;e=e.parentPath}return!0}getIdentifiers(e){if(this.t.isIdentifier(e))return[e.name];let t=new Set;return this.traverse(this.valueWrapper(e),{Identifier:r=>{this.isStandAloneIdentifier(r)&&t.add(r.node.name)}}),[...t]}isAssignmentExpressionLeft(e){let t=e.parentPath?.node;return this.t.isAssignmentExpression(t)&&t.left===e.node||this.t.isUpdateExpression(t)}isAssignmentExpressionRight(e,t){let r=e.node,i=!1,s=e.parentPath;for(;s&&s.node!==t;){if(this.t.isAssignmentExpression(s.node)){let o=s.node.left,n=r.type===o.type,a=r.property.name===o.property.name;i=n&&a}s=s.parentPath}return i}isMemberInEscapeFunction(e,t){let r=!1,i=e.parentPath;for(;i&&i.node!==t;){let s=i.node;if(this.t.isCallExpression(s)&&this.t.isIdentifier(s.callee)&&b.escapeNamings.includes(s.callee.name)){r=!0;break}i=i.parentPath}return r}isMemberInManualFunction(e,t){let r=!1,i=e.parentPath;for(;i&&i.node!==t;){let s=i.node,o=i.parentPath?.node,n=this.t.isFunctionExpression(s)||this.t.isArrowFunctionExpression(s),a=this.t.isCallExpression(o)&&this.t.isIdentifier(o.callee)&&o.callee.name==="manual";if(n&&a){r=!0;break}i=i.parentPath}return r}static uid(e=4){return Math.random().toString(32).slice(2,e+2)}},m=b;M(m,"escapeNamings",["escape","$"]);var S=m;function A(c,e){let{types:t}=c,{files:r="**/*.{js,jsx,ts,tsx}",excludeFiles:i="**/{dist,node_modules,lib}/*.{js,ts}",enableDevTools:s=!1,htmlTags:o=p=>p,alteredAttrMap:n=w,attributeMap:a=D,parseTemplate:d=!0}=e,l=new S(c,t,Array.isArray(r)?r:[r],Array.isArray(i)?i:[i],s,o,a,n,d);return{visitor:{Program:{enter(p,{filename:h}){return l.programEnterVisitor(p,h)},exit:l.programExitVisitor.bind(l)},ClassDeclaration:{enter:l.classEnter.bind(l),exit:l.classExit.bind(l)},ClassExpression:{enter:l.classEnter.bind(l),exit:l.classExit.bind(l)},ClassMethod:l.classMethodVisitor.bind(l),ClassProperty:l.classPropertyVisitor.bind(l)}}}function ee(c,e){return{plugins:[$,[V.default??V,{legacy:!0}],[A,e]]}}export{ee as default}; | ||
var B=Object.defineProperty;var O=(c,e,t)=>e in c?B(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t;var E=(c,e,t)=>(O(c,typeof e!="symbol"?e+"":e,t),t);import L from"babel-plugin-syntax-typescript-new";import A from"@babel/plugin-syntax-decorators";import{minimatch as w}from"minimatch";import{parseView as k}from"@dlightjs/view-parser";import{parseReactivity as C}from"@dlightjs/reactivity-parser";import{generateSubView as T,generateView as j}from"@dlightjs/view-generator";var x=process.env.NODE_ENV==="development",N=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","menu","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","acronym","applet","basefont","bgsound","big","blink","center","dir","font","frame","frameset","isindex","keygen","listing","marquee","menuitem","multicol","nextid","nobr","noembed","noframes","param","plaintext","rb","rtc","spacer","strike","tt","xmp","animate","animateMotion","animateTransform","circle","clipPath","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","image","line","linearGradient","marker","mask","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tspan","use","view"],M=["Static","Prop","Env","Content","Children"],u="@dlightjs/dlight",f=Object.fromEntries(["createElement","setStyle","setDataset","setEvent","setHTMLProp","setHTMLAttr","setHTMLProps","setHTMLAttrs","createTextNode","updateText","insertNode","ForNode","CondNode","ExpNode","EnvNode","SubViewNode","PropView"].map((c,e)=>x?[c,c]:[c,`$${e}$`])),D={textContent:["*"],innerHTML:["*"],accept:["form","input"],acceptCharset:["form"],accesskey:["*"],action:["form"],align:["caption","col","colgroup","hr","iframe","img","table","tbody","td","tfoot","th","thead","tr"],allow:["iframe"],alt:["area","img","input"],async:["script"],autocapitalize:["*"],autocomplete:["form","input","select","textarea"],autofocus:["button","input","select","textarea"],autoplay:["audio","video"],background:["body","table","td","th"],bgColor:["body","col","colgroup","marquee","table","tbody","tfoot","td","th","tr"],border:["img","object","table"],buffered:["audio","video"],capture:["input"],charset:["meta"],checked:["input"],cite:["blockquote","del","ins","q"],class:["*"],color:["font","hr"],cols:["textarea"],colSpan:["td","th"],content:["meta"],contentEditable:["*"],contextmenu:["*"],controls:["audio","video"],coords:["area"],crossOrigin:["audio","img","link","script","video"],csp:["iframe"],data:["object"],dateTime:["del","ins","time"],decoding:["img"],default:["track"],defer:["script"],dir:["*"],dirname:["input","textarea"],disabled:["button","fieldset","input","optgroup","option","select","textarea"],download:["a","area"],draggable:["*"],enctype:["form"],enterKeyHint:["textarea","contenteditable"],for:["label","output"],form:["button","fieldset","input","label","meter","object","output","progress","select","textarea"],formAction:["input","button"],formEnctype:["button","input"],formMethod:["button","input"],formNoValidate:["button","input"],formTarget:["button","input"],headers:["td","th"],height:["canvas","embed","iframe","img","input","object","video"],hidden:["*"],high:["meter"],href:["a","area","base","link"],hreflang:["a","link"],httpEquiv:["meta"],id:["*"],integrity:["link","script"],intrinsicSize:["img"],inputMode:["textarea","contenteditable"],ismap:["img"],itemProp:["*"],kind:["track"],label:["optgroup","option","track"],lang:["*"],language:["script"],loading:["img","iframe"],list:["input"],loop:["audio","marquee","video"],low:["meter"],manifest:["html"],max:["input","meter","progress"],maxLength:["input","textarea"],minLength:["input","textarea"],media:["a","area","link","source","style"],method:["form"],min:["input","meter"],multiple:["input","select"],muted:["audio","video"],name:["button","form","fieldset","iframe","input","object","output","select","textarea","map","meta","param"],noValidate:["form"],open:["details","dialog"],optimum:["meter"],pattern:["input"],ping:["a","area"],placeholder:["input","textarea"],playsInline:["video"],poster:["video"],preload:["audio","video"],readonly:["input","textarea"],referrerPolicy:["a","area","iframe","img","link","script"],rel:["a","area","link"],required:["input","select","textarea"],reversed:["ol"],role:["*"],rows:["textarea"],rowSpan:["td","th"],sandbox:["iframe"],scope:["th"],scoped:["style"],selected:["option"],shape:["a","area"],size:["input","select"],sizes:["link","img","source"],slot:["*"],span:["col","colgroup"],spellcheck:["*"],src:["audio","embed","iframe","img","input","script","source","track","video"],srcdoc:["iframe"],srclang:["track"],srcset:["img","source"],start:["ol"],step:["input"],style:["*"],summary:["table"],tabIndex:["*"],target:["a","area","base","form"],title:["*"],translate:["*"],type:["button","input","embed","object","ol","script","source","style","menu","link"],usemap:["img","input","object"],value:["button","data","input","li","meter","option","progress","param","text"],width:["canvas","embed","iframe","img","input","object","video"],wrap:["textarea"],ariaAutocomplete:["*"],ariaChecked:["*"],ariaDisabled:["*"],ariaErrorMessage:["*"],ariaExpanded:["*"],ariaHasPopup:["*"],ariaHidden:["*"],ariaInvalid:["*"],ariaLabel:["*"],ariaLevel:["*"],ariaModal:["*"],ariaMultiline:["*"],ariaMultiSelectable:["*"],ariaOrientation:["*"],ariaPlaceholder:["*"],ariaPressed:["*"],ariaReadonly:["*"],ariaRequired:["*"],ariaSelected:["*"],ariaSort:["*"],ariaValuemax:["*"],ariaValuemin:["*"],ariaValueNow:["*"],ariaValueText:["*"],ariaBusy:["*"],ariaLive:["*"],ariaRelevant:["*"],ariaAtomic:["*"],ariaDropEffect:["*"],ariaGrabbed:["*"],ariaActiveDescendant:["*"],ariaColCount:["*"],ariaColIndex:["*"],ariaColSpan:["*"],ariaControls:["*"],ariaDescribedBy:["*"],ariaDescription:["*"],ariaDetails:["*"],ariaFlowTo:["*"],ariaLabelledBy:["*"],ariaOwns:["*"],ariaPosInset:["*"],ariaRowCount:["*"],ariaRowIndex:["*"],ariaRowSpan:["*"],ariaSetSize:["*"]};var b=class{dlightPackageName=u;babelApi;t;traverse;enableDevTools;includes;excludes;htmlTags;attributeMap;parseTemplate;constructor(e,t,s,i,r,a,d,o){this.babelApi=e,this.t=t,this.traverse=e.traverse,this.includes=s,this.excludes=i,this.enableDevTools=x&&r,this.htmlTags=typeof a=="function"?a(N):a.includes("*")?[...new Set([...N,...a])].filter(n=>n!=="*"):a,this.attributeMap=d,this.parseTemplate=o}classDeclarationNode;classBodyNode;propertiesContainer={};dependencyMap={};enter=!0;enterClassNode=!1;className;programNode;allImports=[];didAlterImports=!1;clearNode(){this.classDeclarationNode=void 0,this.classBodyNode=void 0,this.propertiesContainer={},this.dependencyMap={},this.enter=!0,this.enterClassNode=!1,this.className=void 0}get availableProperties(){return Object.entries(this.propertiesContainer).filter(([e,{isWatcher:t,isStatic:s,isChildren:i}])=>e!=="_$compName"&&!t&&!s&&!i).map(([e])=>e)}initNode(e){let t=e.node;if(this.classDeclarationNode=t,this.classBodyNode=t.body,this.propertiesContainer={},t.id?.name||(t.id=this.t.identifier(`Anonymous_${b.uid()}`)),this.className=t.id?.name,this.handleClassCustomDecorators(),this.enableDevTools&&this.classBodyNode.body.unshift(this.t.classProperty(this.t.identifier("_$compName"),this.t.stringLiteral(this.className))),!this.didAlterImports){let s=this.allImports.filter(i=>i.source.value===u);this.dlightPackageName!==u&&s.forEach(i=>{i.source.value=this.dlightPackageName}),this.programNode.body.unshift(this.t.importDeclaration(Object.entries(f).map(([i,r])=>this.t.importSpecifier(this.t.identifier(r),this.t.identifier(i))),this.t.stringLiteral(this.dlightPackageName))),this.didAlterImports=!0}}enterProgram(e){}programEnterVisitor(e,t){if(this.enter=this.fileAllowed(t),!this.enter)return;if(this.allImports=e.node.body.filter(i=>this.t.isImportDeclaration(i)),this.allImports.filter(i=>i.source.value===u).length===0){this.enter=!1;return}this.programNode=e.node,this.enterProgram(e)}exitProgram(e){}programExitVisitor(e){this.enter&&(this.didAlterImports=!1,this.allImports=[],this.programNode=void 0,this.exitProgram(e))}enterClass(e){}classEnter(e){this.enter&&(this.enterClassNode=this.isDLightView(e),this.enterClass&&(this.initNode(e),this.enterClass(e)))}exitClass(e){}classExit(e){this.enter&&this.enterClassNode&&(this.transformDLightClass(),this.exitClass(e),this.clearNode(),this.enterClassNode=!1)}visitClassMethod(e){}classMethodVisitor(e){if(!this.enterClassNode||!this.t.isIdentifier(e.node.key))return;let t=e.node.key.name;if(t==="View"||this.findDecoratorByName(e.node.decorators,"View"))return;let i=e.node,r=this.findDecoratorByName(i.decorators,"Watch");if(!r){if(this.t.isIdentifier(i.key,{name:"constructor"}))return;this.autoBindMethods(i);return}let a=[];if(this.t.isIdentifier(r))a=this.getDependencies(e);else{let d=r.arguments[0];this.t.isArrayExpression(d)&&(a=d.elements.filter(o=>this.t.isStringLiteral(o)).map(o=>o.value),a=[...new Set(a)])}this.propertiesContainer[t]={node:i,deps:a,isWatcher:!0},i.decorators=this.removeDecorators(i.decorators,["Watch"]),this.visitClassMethod(e)}visitClassProperty(e){}classPropertyVisitor(e){if(!this.enterClassNode)return;let t=e.node;if(!this.t.isIdentifier(t.key))return;let s=t.key.name;if(s==="View")return;let i=t.decorators;if(this.findDecoratorByName(i,"View"))return;let a=!!this.findDecoratorByName(i,"Prop"),d=!!this.findDecoratorByName(i,"Env"),o=!!this.findDecoratorByName(t.decorators,"Children"),n=o?[]:this.getDependencies(e);this.propertiesContainer[s]={node:t,deps:n,isStatic:!!this.findDecoratorByName(i,"Static"),isContent:!!this.findDecoratorByName(i,"Content"),isChildren:o,isPropOrEnv:a?"Prop":d?"Env":void 0},t.decorators=this.removeDecorators(i,M),this.visitClassProperty(e)}resolveWatcherDecorator(e){if(!this.t.isIdentifier(e.key))return;let t=e.key.name,s=this.classBodyNode.body.indexOf(e),i=this.t.classProperty(this.t.identifier(`$w$${t}`));this.classBodyNode.body.splice(s,0,i)}resolveChildrenDecorator(e){if(!this.classBodyNode||!this.t.isIdentifier(e.key))return;let t=e.key.name,s=this.classBodyNode.body.indexOf(e),i=this.t.memberExpression(this.t.thisExpression(),this.t.identifier("_$children")),r=this.t.classMethod("get",this.t.identifier(t),[],this.t.blockStatement([this.t.returnStatement(i)]));this.classBodyNode.body.splice(s,1,r)}resolveContentDecorator(e){if(!this.classBodyNode||!this.t.isIdentifier(e.key)||this.classBodyNode.body.some(r=>this.t.isClassProperty(r)&&r.key.name==="_$contentKey"))return;let t=e.key.name,s=this.classBodyNode.body.indexOf(e),i=this.t.classProperty(this.t.identifier("_$contentKey"),this.t.stringLiteral(t));this.classBodyNode.body.splice(s,0,i)}resolvePropDecorator(e,t){if(!this.classBodyNode||!this.t.isIdentifier(e.key))return;let s=e.key.name,i=this.classBodyNode.body.indexOf(e),r=t.toLowerCase()==="prop"?"p":"e",a=this.t.classProperty(this.t.identifier(`$${r}$${s}`));this.classBodyNode.body.splice(i,0,a)}resolveStateDecorator(e,t,s){if(!this.classBodyNode||!this.t.isIdentifier(e.key))return;let i=e.key.name;e.key.name=`$${i}`;let r=this.classBodyNode.body.indexOf(e),a=this.t.classProperty(this.t.identifier(`$$${i}`),this.t.numericLiteral(1<<t)),d=s?[this.t.classProperty(this.t.identifier(`$s$${i}`),this.t.arrayExpression([...s].map(p=>this.t.stringLiteral(p))))]:[],o=this.t.classMethod("get",this.t.identifier(i),[],this.t.blockStatement([this.t.returnStatement(this.t.memberExpression(this.t.thisExpression(),this.t.identifier(`$${i}`)))])),n=this.t.classMethod("set",this.t.identifier(i),[this.t.identifier("value")],this.t.blockStatement([this.t.expressionStatement(this.t.callExpression(this.t.memberExpression(this.t.thisExpression(),this.t.identifier("_$updateProp")),[this.t.stringLiteral(i),this.t.identifier("value")]))]));this.classBodyNode.body.splice(r+1,0,a,...d,o,n)}handleClassCustomDecorators(){if(!this.classBodyNode)return;let e=this.classDeclarationNode?.decorators;if(!e)return;this.findDecoratorByName(e,"ForwardProps")&&(this.classBodyNode.body.unshift(this.t.classProperty(this.t.identifier("_$forwardProps")),this.t.classProperty(this.t.identifier("_$forwardPropsSet"),this.t.newExpression(this.t.identifier("Set"),[])),this.t.classProperty(this.t.identifier("_$forwardPropsId"),this.t.arrayExpression([]))),this.classDeclarationNode.decorators=this.removeDecorators(e,["ForwardProps"]))}transformDLightClass(){let e=this.handleView(),t=Object.entries(this.propertiesContainer).reverse(),s=this.dependencyMapReversed();for(let[i,{node:r,deps:a,isStatic:d,isChildren:o,isPropOrEnv:n,isWatcher:p,isContent:l}]of t){if(o){this.resolveChildrenDecorator(r);continue}a.length>0&&(e.push(...a),p?this.resolveWatcherDecorator(r):this.handleDerivedProperty(r)),n&&this.resolvePropDecorator(r,n),l&&(this.resolvePropDecorator(r,"Prop"),this.resolveContentDecorator(r)),!d&&e.includes(i)&&this.resolveStateDecorator(r,this.availableProperties.indexOf(i),s[i])}}handleView(){if(!this.classBodyNode)return[];let e=new Set,t,s=[];for(let o of this.classBodyNode.body){if(!this.t.isClassProperty(o)&&!this.t.isClassMethod(o)||!this.t.isIdentifier(o.key))continue;let n=this.findDecoratorByName(o.decorators,"View"),p=o.key.name==="View";if(!(!n&&!p)){if(this.t.isClassProperty(o)){let l=o.value;for(;this.t.isTSAsExpression(l);)l=l.expression;if(!this.t.isArrowFunctionExpression(l))continue;o.value=l;let h=this.arrowFunctionPropertyToMethod(o);if(!h)continue;o=h}n?(o.decorators=null,s.push(o)):t=o}}let i=s.map(o=>o.key.name),r=Object.fromEntries(s.map(o=>{let n=o.params[0];if(!n||!this.t.isObjectPattern(n))return["-",null];let p=Object.fromEntries(n.properties.map(l=>{if(!this.t.isObjectProperty(l))return["-",null];let h=l.key.name,y=this.getIdentifiers(this.t.assignmentExpression("=",this.t.objectPattern([this.t.objectProperty(this.t.numericLiteral(0),l.value)]),this.t.numericLiteral(0))).filter(g=>g!==h);return[h,y]}).filter(([l,h])=>h));return[o.key.name,p]}).filter(([o,n])=>n)),a=-1;if(t){let o;[o,a]=this.alterMainView(t,i,r),o.forEach(e.add.bind(e))}s.forEach(o=>{let n;[n,a]=this.alterSubView(o,i,r,a),n.forEach(e.add.bind(e))});let d=[];return this.availableProperties.forEach(o=>{e.has(o)&&d.push(o)}),d}alterMainView(e,t,s){let i=k(e.body,{babelApi:this.babelApi,subviewNames:t,htmlTags:this.htmlTags}),[r,a]=C(i,{babelApi:this.babelApi,availableProperties:this.availableProperties,dependencyMap:this.dependencyMap,parseTemplate:this.parseTemplate}),[d,o,n]=j(r,{babelApi:this.babelApi,className:this.className,importMap:f,subViewPropMap:Object.fromEntries(Object.entries(s).map(([p,l])=>[p,Object.keys(l)])),templateIdx:-1,attributeMap:this.attributeMap});return e.body=d,this.classBodyNode?.body.push(...o),[a,n]}alterSubView(e,t,s,i){e.params.length===0?e.params.push(this.t.identifier("_$"),this.t.identifier("$subviewNode")):e.params.length===1?e.params.push(this.t.identifier("$subviewNode")):(e.params[1]=this.t.identifier("$subviewNode"),e.params.length=2);let r=k(e.body,{babelApi:this.babelApi,subviewNames:t,htmlTags:this.htmlTags}),[a,d]=C(r,{babelApi:this.babelApi,availableProperties:this.availableProperties,dependencyMap:this.dependencyMap}),o=s[e.key.name]??[],n={};Object.entries(o).forEach(([v,P])=>{P.forEach(V=>{n[V]=[v]})});let[p]=C(r,{babelApi:this.babelApi,availableProperties:Object.keys(o),dependencyMap:this.dependencyMap,dependencyParseType:"identifier",identifierDepMap:n}),l=Object.fromEntries(Object.entries(s).map(([v,P])=>[v,Object.keys(P)])),[h,y,g]=T(a,p,e.params[0],{babelApi:this.babelApi,className:this.className,importMap:f,subViewPropMap:l,templateIdx:i,attributeMap:this.attributeMap});return e.body=h,this.classBodyNode?.body.push(...y),[d,g]}fileAllowed(e){return this.includes.includes("*")?!0:!(!e||this.excludes.some(t=>w(e,t))||!this.includes.some(t=>w(e,t)))}isDLightView(e){let t=e.node;return(t.decorators??[]).find(r=>this.t.isIdentifier(r.expression,{name:"View"}))&&(t.superClass=this.t.identifier("View"),t.decorators=t.decorators?.filter(r=>!this.t.isIdentifier(r.expression,{name:"View"}))),this.t.isIdentifier(t.superClass,{name:"View"})}removeDecorators(e,t){return e?e.filter(s=>!(this.t.isIdentifier(s.expression)&&t.includes(s.expression.name)||this.t.isCallExpression(s.expression)&&this.t.isIdentifier(s.expression.callee)&&t.includes(s.expression.callee.name))):[]}findDecoratorByName(e,t){if(e)return e.find(s=>this.t.isIdentifier(s.expression,{name:t})||this.t.isCallExpression(s.expression)&&this.t.isIdentifier(s.expression.callee,{name:t}))?.expression}addConstructor(){let e=this.classBodyNode.body.find(t=>this.t.isClassMethod(t,{kind:"constructor"}));return e||(e=this.t.classMethod("constructor",this.t.identifier("constructor"),[],this.t.blockStatement([this.t.expressionStatement(this.t.callExpression(this.t.super(),[]))])),this.classBodyNode.body.unshift(e),e)}autoBindMethods(e){this.addConstructor().body.body.push(this.t.expressionStatement(this.t.assignmentExpression("=",this.t.memberExpression(this.t.thisExpression(),e.key),this.t.callExpression(this.t.memberExpression(this.t.memberExpression(this.t.thisExpression(),e.key),this.t.identifier("bind")),[this.t.thisExpression()]))))}handleDerivedProperty(e){if(!this.t.isIdentifier(e.key))return;let t=e.key.name,s=e.value,i=this.classBodyNode.body.indexOf(e),r=this.t.classMethod("get",this.t.identifier(`$f$${t}`),[],this.t.blockStatement([this.t.returnStatement(s)]));this.classBodyNode.body.splice(i+1,0,r),e.value=null}getDependencies(e){let t=e.node;if(!this.t.isIdentifier(t.key))return[];let s=new Set,i=new Set;e.scope.traverse(t,{MemberExpression:d=>{if(!this.t.isIdentifier(d.node.property))return;let o=d.node.property.name;this.isAssignmentExpressionLeft(d)?i.add(o):this.availableProperties.includes(o)&&this.t.isThisExpression(d.node.object)&&!this.isMemberInEscapeFunction(d,this.classDeclarationNode)&&!this.isMemberInManualFunction(d,this.classDeclarationNode)&&!this.isAssignmentExpressionRight(d,this.classDeclarationNode)&&(s.add(o),this.dependencyMap[o]?.forEach(s.add.bind(s)))}}),i.forEach(s.delete.bind(s));let r=t.key.name,a=[...s];return s.size>0&&(this.dependencyMap[r]=a),a}dependencyMapReversed(){let e={};return Object.entries(this.dependencyMap).forEach(([t,s])=>{s.forEach(i=>{e[i]||(e[i]=new Set),e[i].add(t)})}),e}arrowFunctionPropertyToMethod(e){if(!this.t.isArrowFunctionExpression(e.value))return;let t=e.value;if(!this.t.isBlockStatement(t.body))return;let s=this.classBodyNode.body.indexOf(e),i=this.t.classMethod("method",e.key,t.params,t.body);return this.classBodyNode.body.splice(s,1,i),i}isMemberExpressionProperty(e,t){return this.t.isMemberExpression(e)&&!e.computed&&e.property===t}isObjectKey(e,t){return this.t.isObjectProperty(e)&&e.key===t}valueWithArrowFunc(e){e.value||(e.value=this.t.identifier("undefined")),e.value=this.t.arrowFunctionExpression([],e.value)}valueWrapper(e){return this.t.file(this.t.program([this.t.isStatement(e)?e:this.t.expressionStatement(e)]))}isAttrFromFunction(e,t){let s=e.parentPath,i=r=>this.t.isIdentifier(r)?r.name===t:this.t.isAssignmentPattern(r)?i(r.left):this.t.isArrayPattern(r)?r.elements.filter(Boolean).map(a=>i(a)).includes(!0):this.t.isObjectPattern(r)?r.properties.filter(a=>this.t.isObjectProperty(a)&&this.t.isIdentifier(a.key)).map(a=>a.key.name).includes(t):this.t.isRestElement(r)?i(r.argument):!1;for(;s;){let r=s.node;if(this.t.isArrowFunctionExpression(r)||this.t.isFunctionDeclaration(r)){for(let a of r.params)if(i(a))return!0}s=s.parentPath}return!1}isStandAloneIdentifier(e){let t=e.node,s=e.parentPath?.node;if(this.t.isMemberExpression(s)&&s.property===t||this.isAttrFromFunction(e,t.name))return!1;for(;e.parentPath;){if(this.t.isVariableDeclarator(e.parentPath.node)||this.t.isObjectProperty(e.parentPath.node)&&e.parentPath.node.key===e.node&&!e.parentPath.node.computed)return!1;e=e.parentPath}return!0}getIdentifiers(e){if(this.t.isIdentifier(e))return[e.name];let t=new Set;return this.traverse(this.valueWrapper(e),{Identifier:s=>{this.isStandAloneIdentifier(s)&&t.add(s.node.name)}}),[...t]}isAssignmentExpressionLeft(e){let t=e.parentPath?.node;return this.t.isAssignmentExpression(t)&&t.left===e.node||this.t.isUpdateExpression(t)}isAssignmentExpressionRight(e,t){let s=e.node,i=!1,r=e.parentPath;for(;r&&r.node!==t;){if(this.t.isAssignmentExpression(r.node)){let a=r.node.left,d=s.type===a.type,o=s.property.name===a.property.name;i=d&&o}r=r.parentPath}return i}isMemberInEscapeFunction(e,t){let s=!1,i=e.parentPath;for(;i&&i.node!==t;){let r=i.node;if(this.t.isCallExpression(r)&&this.t.isIdentifier(r.callee)&&b.escapeNamings.includes(r.callee.name)){s=!0;break}i=i.parentPath}return s}isMemberInManualFunction(e,t){let s=!1,i=e.parentPath;for(;i&&i.node!==t;){let r=i.node,a=i.parentPath?.node,d=this.t.isFunctionExpression(r)||this.t.isArrowFunctionExpression(r),o=this.t.isCallExpression(a)&&this.t.isIdentifier(a.callee)&&a.callee.name==="manual";if(d&&o){s=!0;break}i=i.parentPath}return s}static uid(e=4){return Math.random().toString(32).slice(2,e+2)}},m=b;E(m,"escapeNamings",["escape","$"]);var I=m;function S(c,e){let{types:t}=c,{files:s="**/*.{js,jsx,ts,tsx}",excludeFiles:i="**/{dist,node_modules,lib}/*.{js,ts}",enableDevTools:r=!1,htmlTags:a=p=>p,attributeMap:d=D,parseTemplate:o=!0}=e,n=new I(c,t,Array.isArray(s)?s:[s],Array.isArray(i)?i:[i],r,a,d,o);return{visitor:{Program:{enter(p,{filename:l}){return n.programEnterVisitor(p,l)},exit:n.programExitVisitor.bind(n)},ClassDeclaration:{enter:n.classEnter.bind(n),exit:n.classExit.bind(n)},ClassExpression:{enter:n.classEnter.bind(n),exit:n.classExit.bind(n)},ClassMethod:n.classMethodVisitor.bind(n),ClassProperty:n.classPropertyVisitor.bind(n)}}}function Z(c,e){return{plugins:[L,[A.default??A,{legacy:!0}],[S,e]]}}export{Z as default}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "babel-preset-dlight", | ||
"version": "1.0.0-alpha.31", | ||
"version": "1.0.0-alpha.32", | ||
"description": "DLight transpiler babel preset", | ||
@@ -30,6 +30,6 @@ "author": { | ||
"minimatch": "^9.0.3", | ||
"@dlightjs/reactivity-parser": "1.0.0-alpha.7", | ||
"@dlightjs/view-generator": "1.0.0-alpha.28", | ||
"babel-plugin-syntax-typescript-new": "1.0.0", | ||
"@dlightjs/view-generator": "1.0.0-alpha.29", | ||
"@dlightjs/view-parser": "1.0.0-alpha.4", | ||
"babel-plugin-syntax-typescript-new": "1.0.0" | ||
"@dlightjs/reactivity-parser": "1.0.0-alpha.8" | ||
}, | ||
@@ -36,0 +36,0 @@ "tsup": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
209480
225
+ Added@dlightjs/reactivity-parser@1.0.0-alpha.8(transitive)
+ Added@dlightjs/view-generator@1.0.0-alpha.29(transitive)
- Removed@dlightjs/reactivity-parser@1.0.0-alpha.7(transitive)
- Removed@dlightjs/view-generator@1.0.0-alpha.28(transitive)