{"version":3,"sources":["../src/index.ts","../src/plugin.ts","../src/htmlTags.ts"],"sourcesContent":["import easyCss from \"babel-preset-easy-css\"\nimport dlightEasyCss from \"./plugin\"\nimport atomic from \"@iandx/easy-css-atomic\"\nimport utility from \"@iandx/easy-css-utility\"\n\nexport interface DLightOption {\n  /**\n   * Files that will be included\n   * @default ** /*.{js,jsx,ts,tsx}\n   */\n  files?: string | string[]\n  /**\n   * Files that will be excludes\n   * @default ** /{dist,node_modules,lib}/*.{js,ts}\n   */\n  excludeFiles?: string | string[]\n}\n\nexport default function(api: any, dlOptions: DLightOption) {\n  const options = {\n    ...dlOptions,\n    utilities: [{\n      easyFuncMap: atomic,\n      safeName: \"dlightEasyCssAtomic\"\n    }, {\n      easyFuncMap: utility,\n      safeName: \"dlightEasyCssUtility\"\n    }],\n    easyCssAlias: \"@dlightjs/easy-css\"\n  }\n  return {\n    presets: [[easyCss, options]],\n    plugins: [[dlightEasyCss, options]]\n  }\n}\n","import * as t from \"@babel/types\"\nimport { isAHtmlTag } from \"./htmlTags\"\nimport { minimatch } from \"minimatch\"\n\ninterface EasyCssOption {\n  utilities?: Array<{\n    easyFuncMap: Record<string, ((...args: any) => string)>\n    safeName: string\n  }>\n  /**\n   * Files that will be included\n   * @default ** /*.{js,jsx,ts,tsx}\n   */\n  files?: string | string[]\n  /**\n   * Files that will be excludes\n   * @default ** /{dist,node_modules,lib}/*.{js,ts}\n   */\n  excludeFiles?: string | string[]\n}\n\nexport default function(api: any, options: EasyCssOption) {\n  const {\n    utilities,\n    files: preFiles = \"**/*.{js,jsx,ts,tsx}\",\n    excludeFiles: preExcludeFiles = \"**/{dist,node_modules,lib}/*.{js,ts}\"\n  } = options\n  const files = Array.isArray(preFiles) ? preFiles : [preFiles]\n  const excludeFiles = Array.isArray(preExcludeFiles) ? preExcludeFiles : [preExcludeFiles]\n\n  let safeNames: string[] = []\n\n  const handle = function(path: any) {\n    path.scope.traverse(path.node, {\n      ClassMethod(bodyPath: any) {\n        const node = bodyPath.node as t.ClassMethod\n        if (!(t.isIdentifier(node.key) && (\n          node.key.name === \"Body\" || (\n            node.decorators &&\n            t.isIdentifier(node.decorators[0].expression) &&\n            node.decorators[0].expression.name === \"SubView\"\n          )))) return\n        bodyPath.scope.traverse(node, {\n          ExpressionStatement(path: any) {\n            path.scope.traverse(path.node, {\n              Identifier(path: any) {\n                const node = path.node as t.Identifier\n                let key: string | undefined\n                let safeName: string | undefined\n                for (const { easyFuncMap, safeName: sn } of utilities!) {\n                  if (easyFuncMap[node.name]) {\n                    key = node.name\n                    safeName = sn\n                  }\n                }\n                if (!key || !safeName) return\n                // ---- 确保不是div()的tag\n                if (!t.isMemberExpression(path.parentPath.node)) return\n                // ---- 去除闭包中的情况\n                let tempPath = path.parentPath\n                while (tempPath && tempPath !== bodyPath) {\n                  // 遍历上去只能是 member: xx.margin / call: xx.margin() / block: {xx.margin()} / for / if\n                  if (!(\n                    t.isMemberExpression(tempPath.node) ||\n                    t.isCallExpression(tempPath.node) ||\n                    t.isBlockStatement(tempPath.node) ||\n                    t.isForOfStatement(tempPath.node) ||\n                    t.isIfStatement(tempPath.node) ||\n                    t.isDoExpression(tempPath.node)\n                  )) return\n                  tempPath = tempPath.parentPath\n                }\n                // ---- 找到 div().a().b().c().margin()中的div，只可能是 member 和 call\n                let tagNode = path.parentPath.node\n                while (tagNode.object || tagNode.callee) {\n                  if (t.isMemberExpression(tagNode)) tagNode = tagNode.object\n                  else if (t.isCallExpression(tagNode)) tagNode = tagNode.callee\n                  else break\n                }\n                // ---- 如果不是htmlTag，就不要\n                const tagName = tagNode.name\n                if (!(tagName === \"htmlTag\" || isAHtmlTag(tagName))) return\n                // ---- 添加进import\n                safeNames.push(safeName)\n                safeNames = [...new Set(safeNames)]\n                // ---- 正式开始replace\n                // xxx.margin(\"20px\") ->  xxx.className()\n                path.replaceWith(t.identifier(\"className\"))\n                //  xxx.className() -> xxx.className(margin(\"20px\"))\n                let callPath = path.parentPath\n                while (!t.isCallExpression(callPath.node)) {\n                  callPath = callPath.parentPath\n                }\n                callPath.replaceWith(t.callExpression(\n                  callPath.node.callee,\n                  [t.callExpression(\n                    safeName\n                      ? t.memberExpression(t.identifier(safeName), t.identifier(key))\n                      : t.identifier(key),\n                    callPath.node.arguments\n                  )]\n                ))\n                callPath.skip()\n                path.skip()\n              }\n            })\n          }\n        })\n      }\n    })\n  }\n\n  return {\n    visitor: {\n      Program: {\n        enter(path: any, state: any) {\n          if (state.filename) {\n            for (const allowedPath of files) {\n              if (minimatch(state.filename, allowedPath)) {\n                this.enter = true\n                break\n              }\n            }\n            for (const notAllowedPath of excludeFiles) {\n              if (minimatch(state.filename, notAllowedPath)) {\n                this.enter = false\n                break\n              }\n            }\n          } else {\n            this.enter = true\n          }\n          if (!this.enter) return\n          if (!utilities) return\n          safeNames = []\n        },\n        exit(path: any) {\n          if (!this.enter) return\n          if (!utilities) return\n          if (safeNames.length === 0) return\n          path.node.body.unshift(t.importDeclaration(\n            safeNames.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))),\n            t.stringLiteral(\"@dlightjs/easy-css\")\n          ))\n          safeNames = []\n        }\n      },\n      ClassDeclaration(path: any) {\n        if (!this.enter) return\n        if (!utilities) return\n        if (!(t.isIdentifier(path.node.superClass) && path.node.superClass.name === \"View\")) return\n        handle(path)\n      },\n      ClassExpression(path: any) {\n        if (!this.enter) return\n        if (!utilities) return\n        if (!(t.isIdentifier(path.node.superClass) && path.node.superClass.name === \"View\")) return\n        handle(path)\n      }\n    }\n  }\n}\n","const htmlTags = [\"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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C,KAAK,MAAQ,GACb,YAIJ,KAAK,MAAQ,GAEV,KAAK,OACLrB,IACLK,EAAY,CAAC,EACf,EACA,KAAKE,EAAW,CACT,KAAK,OACLP,GACDK,EAAU,SAAW,IACzBE,EAAK,KAAK,KAAK,QAAU,oBACvBF,EAAU,IAAIiB,GAAU,kBAAkB,aAAWA,CAAI,EAAK,aAAWA,CAAI,CAAC,CAAC,EAC7E,gBAAc,oBAAoB,CACtC,CAAC,EACDjB,EAAY,CAAC,EACf,CACF,EACA,iBAAiBE,EAAW,CACrB,KAAK,OACLP,GACG,eAAaO,EAAK,KAAK,UAAU,GAAKA,EAAK,KAAK,WAAW,OAAS,QAC5ED,EAAOC,CAAI,CACb,EACA,gBAAgBA,EAAW,CACpB,KAAK,OACLP,GACG,eAAaO,EAAK,KAAK,UAAU,GAAKA,EAAK,KAAK,WAAW,OAAS,QAC5ED,EAAOC,CAAI,CACb,CACF,CACF,CACF,CD/JA,IAAAgB,EAAmB,uCACnBC,EAAoB,wCAeL,SAARC,EAAiBC,EAAUC,EAAyB,CACzD,IAAMC,EAAU,CACd,GAAGD,EACH,UAAW,CAAC,CACV,YAAa,EAAAE,QACb,SAAU,qBACZ,EAAG,CACD,YAAa,EAAAC,QACb,SAAU,sBACZ,CAAC,EACD,aAAc,oBAChB,EACA,MAAO,CACL,QAAS,CAAC,CAAC,EAAAC,QAASH,CAAO,CAAC,EAC5B,QAAS,CAAC,CAACI,EAAeJ,CAAO,CAAC,CACpC,CACF","names":["src_exports","__export","src_default","__toCommonJS","import_babel_preset_easy_css","t","htmlTags","isAHtmlTag","key","import_minimatch","plugin_default","api","options","utilities","preFiles","preExcludeFiles","files","excludeFiles","safeNames","handle","path","bodyPath","node","key","safeName","easyFuncMap","sn","tempPath","tagNode","tagName","isAHtmlTag","callPath","state","allowedPath","notAllowedPath","name","import_easy_css_atomic","import_easy_css_utility","src_default","api","dlOptions","options","atomic","utility","easyCss","plugin_default"]}