miniprogram-ci 1.9.8 → 1.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/@types/config.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare const hash: any;
|
|
|
4
4
|
declare const transformSync: any;
|
|
5
5
|
declare const traverse: any;
|
|
6
6
|
declare const parse: any;
|
|
7
|
+
declare const nodePath: any;
|
|
7
8
|
declare const buildBindFunc: (func: any) => any;
|
|
8
9
|
declare const buildWorkletFunc: (func: any) => any;
|
|
9
10
|
declare const globals: Set<string>;
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
!function(require, directRequire){
|
|
2
|
-
"use strict";var COMPILE_TYPE;Object.defineProperty(exports,"__esModule",{value:!0}),exports.extendedLibMap=exports.jsonVariablePropertyWhiteList=exports.DefaultProjectAttr=exports.TABBAR_ICON_WHITE_LIST=exports.COMPILE_TYPE=exports.APP_TYPE=exports.MINI_GAME_WORKERS_PACKAGE_ROOT=exports.MINI_GAME_MAIN_PACKAGE_ROOT=exports.MINI_PROGRAM_MAIN_PACKAGE_ROOT=exports.PROJECT_TYPE_ERROR=exports.GET_LATEST_VERSION_CGI_ERR=exports.UPLOAD_JS_SERVER_CGI_ERR=exports.CODE_PROTECT_TRANSLATE_FILENAME=exports.UPLOAD_CGI_ERR=exports.GENERATE_LOCAL_SIGNATURE_ERR=exports.GET_SIGNATURE_RAND_STRING_ERR=exports.APP_JSON_NOT_FOUND=exports.JSON_CONTENT_ERR=exports.FILE_NOT_UTF8=exports.JSON_PARSE_ERR=exports.FILE_NOT_FOUND=exports.PLUGIN_JSON_PARSE_ERR=exports.PLUGIN_JSON_CONTENT_ERR=exports.PLUGIN_JSON_FILE_NOT_FOUND=exports.GAME_PLUGIN_LIB_MD5_NOT_MATCH=exports.SUMMER_PLUGIN_CODE_ERR=exports.SUMMER_PLUGIN_ERR=exports.MINIFY_WXML_ERR=exports.POST_WXSS_ERR=exports.FILE_FLAT_ERR=exports.JS_ES6_ERR=exports.BABILI_JS_ERR=exports.UGLIFY_JS_ERR=exports.BABEL_TRANS_JS_ERR=exports.JS_NOT_FOUND=exports.WXML_NOT_FOUND=exports.PARAM_ERROR=exports.CI_VERSION=void 0,exports.CI_VERSION="1.9.
|
|
2
|
+
"use strict";var COMPILE_TYPE;Object.defineProperty(exports,"__esModule",{value:!0}),exports.extendedLibMap=exports.jsonVariablePropertyWhiteList=exports.DefaultProjectAttr=exports.TABBAR_ICON_WHITE_LIST=exports.COMPILE_TYPE=exports.APP_TYPE=exports.MINI_GAME_WORKERS_PACKAGE_ROOT=exports.MINI_GAME_MAIN_PACKAGE_ROOT=exports.MINI_PROGRAM_MAIN_PACKAGE_ROOT=exports.PROJECT_TYPE_ERROR=exports.GET_LATEST_VERSION_CGI_ERR=exports.UPLOAD_JS_SERVER_CGI_ERR=exports.CODE_PROTECT_TRANSLATE_FILENAME=exports.UPLOAD_CGI_ERR=exports.GENERATE_LOCAL_SIGNATURE_ERR=exports.GET_SIGNATURE_RAND_STRING_ERR=exports.APP_JSON_NOT_FOUND=exports.JSON_CONTENT_ERR=exports.FILE_NOT_UTF8=exports.JSON_PARSE_ERR=exports.FILE_NOT_FOUND=exports.PLUGIN_JSON_PARSE_ERR=exports.PLUGIN_JSON_CONTENT_ERR=exports.PLUGIN_JSON_FILE_NOT_FOUND=exports.GAME_PLUGIN_LIB_MD5_NOT_MATCH=exports.SUMMER_PLUGIN_CODE_ERR=exports.SUMMER_PLUGIN_ERR=exports.MINIFY_WXML_ERR=exports.POST_WXSS_ERR=exports.FILE_FLAT_ERR=exports.JS_ES6_ERR=exports.BABILI_JS_ERR=exports.UGLIFY_JS_ERR=exports.BABEL_TRANS_JS_ERR=exports.JS_NOT_FOUND=exports.WXML_NOT_FOUND=exports.PARAM_ERROR=exports.CI_VERSION=void 0,exports.CI_VERSION="1.9.9",exports.PARAM_ERROR=1e4,exports.WXML_NOT_FOUND=10007,exports.JS_NOT_FOUND=10008,exports.BABEL_TRANS_JS_ERR=10032,exports.UGLIFY_JS_ERR=10033,exports.BABILI_JS_ERR=10034,exports.JS_ES6_ERR=10035,exports.FILE_FLAT_ERR=10036,exports.POST_WXSS_ERR=10037,exports.MINIFY_WXML_ERR=10038,exports.SUMMER_PLUGIN_ERR=10045,exports.SUMMER_PLUGIN_CODE_ERR=10046,exports.GAME_PLUGIN_LIB_MD5_NOT_MATCH=10081,exports.PLUGIN_JSON_FILE_NOT_FOUND=10091,exports.PLUGIN_JSON_CONTENT_ERR=10092,exports.PLUGIN_JSON_PARSE_ERR=10093,exports.FILE_NOT_FOUND=10005,exports.JSON_PARSE_ERR=10006,exports.FILE_NOT_UTF8=10031,exports.JSON_CONTENT_ERR=10009,exports.APP_JSON_NOT_FOUND=2e4,exports.GET_SIGNATURE_RAND_STRING_ERR=20001,exports.GENERATE_LOCAL_SIGNATURE_ERR=20002,exports.UPLOAD_CGI_ERR=20003,exports.CODE_PROTECT_TRANSLATE_FILENAME=20004,exports.UPLOAD_JS_SERVER_CGI_ERR=20005,exports.GET_LATEST_VERSION_CGI_ERR=20006,exports.PROJECT_TYPE_ERROR=3e4,exports.MINI_PROGRAM_MAIN_PACKAGE_ROOT="__APP__",exports.MINI_GAME_MAIN_PACKAGE_ROOT="__GAME__",exports.MINI_GAME_WORKERS_PACKAGE_ROOT="workers.js",exports.APP_TYPE={NORMAL:0,PLUGIN:1,SHOP:2,MINISHOP:3,GAME:4,CARD:5,NATIVE:7},function(_){_.miniProgram="miniProgram",_.miniProgramPlugin="miniProgramPlugin",_.miniGame="miniGame",_.miniGamePlugin="miniGamePlugin"}(COMPILE_TYPE=exports.COMPILE_TYPE||(exports.COMPILE_TYPE={})),exports.TABBAR_ICON_WHITE_LIST=[".png",".jpg",".jpeg"],exports.DefaultProjectAttr={platform:!1,appType:0,isSandbox:!1,released:!1,setting:{MaxCodeSize:2,MaxSubpackageSubCodeSize:2,MaxSubpackageFullCodeSize:12,NavigateMiniprogramLimit:10,MaxSubPackageLimit:100,MinTabbarCount:2,MaxTabbarCount:5,MaxTabbarIconSize:40}},exports.jsonVariablePropertyWhiteList={windowPropertWhiteList:["navigationBarBackgroundColor","navigationBarTextStyle","backgroundColor","backgroundTextStyle","backgroundColorTop","backgroundColorBottom","backgroundColorContent"],tabBarPropertyWhiteList:["color","selectedColor","backgroundColor","borderStyle"],tabbarListItemPropertyWhiteList:["iconPath","selectedIconPath"]},exports.extendedLibMap={kbone:{packages:["miniprogram-element","miniprogram-render"]},weui:{packages:["weui-miniprogram"]}};
|
|
3
3
|
}(require("licia/lazyImport")(require), require)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
!function(require, directRequire){
|
|
2
|
-
"use strict";function findAllDescendant(e,t){let n;n=Array.isArray(e)?e:[e];const s=n.slice(0),
|
|
2
|
+
"use strict";function findAllDescendant(e,t){let n;n=Array.isArray(e)?e:[e];const s=n.slice(0),o=[],a=[];for(;s.length>0;){const e=s.pop();o.push(e),e.childModules.forEach(e=>{s.indexOf(e)<0&&o.indexOf(e)<0&&(s.push(e),e.type===t&&a.push(e))})}return a}function findModsByType(e,t){var n;return(null===(n=null==e?void 0:e.graph)||void 0===n?void 0:n.modules.filter(e=>e.type===t))||[]}function findModByTypeAndPath(e,t,n){var s;return null===(s=e.graph)||void 0===s?void 0:s.modules.find(e=>e.type===t&&e.path===n)}function findPageMods(e,t){return(findModsByType(e,"Page")||[]).filter(e=>t.includes(e.path.replace(/\.json$/,"")))}function findGlobalCompMods(e){const t=findModByTypeAndPath(e,"MainPackage","app.json");return(null==t?void 0:t.childModules.filter(e=>"Component"===e.type))||[]}function getAllSubpackagePath(e){return findModsByType(e,"SubPackage").map(e=>e.path)}function innerGetSortedJSFiles(e,t){const n=new Set,s=new Set,o=new Set,a=[];for(const t of e){const e=t.findChild("Js");e&&(t.config?o.add(e.path):s.add(e.path),n.add(e.path),a.push(e))}const i=findAllDescendant(e.concat(t),"Component");for(const e of i.concat(t)){const t=e.findChild("Js");t&&(o.add(t.path),n.add(t.path),a.push(t))}const l=findAllDescendant(a,"Js");for(const e of l){const t=e.path;n.add(t)}return{allFiles:Array.from(n),pageFiles:Array.from(s),componentFiles:Array.from(o)}}function groupBySubpackage(e,t){const n=[],s={};for(const o of e){const e=t.find(e=>o.startsWith(e));e?(s[e]||(s[e]=[]),s[e].push(o)):n.push(o)}return{main:n,subs:s}}function partialGetSubPkgSortedJSFiles(e,t,n){const s=findPageMods(e,t);let{allFiles:o,pageFiles:a,componentFiles:i}=innerGetSortedJSFiles(s,[]);const l=getAllSubpackagePath(e);return{allFiles:groupBySubpackage(o,l).subs[n]||[],pageFiles:groupBySubpackage(a,l).subs[n]||[],componentFiles:groupBySubpackage(i,l).subs[n]||[]}}function partialGetMainPkgSortedJSFiles(e,t){const n=findPageMods(e,t),s=findGlobalCompMods(e);let{allFiles:o,pageFiles:a,componentFiles:i}=innerGetSortedJSFiles(n,s),l=!1;const p=findModByTypeAndPath(e,"Js","app.js");if(p){l=!0,o.push(p.path);const e=findAllDescendant([p],"Js");for(const t of e){const e=t.path;o.indexOf(e)<0&&o.push(e)}}const r=getAllSubpackagePath(e);return{hasAppJS:l,allFiles:groupBySubpackage(o,r).main,pageFiles:groupBySubpackage(a,r).main,componentFiles:groupBySubpackage(i,r).main}}function partialWholePkgGetSortedJSFiles(e,t){const n=findPageMods(e,t),s=findGlobalCompMods(e);let{allFiles:o,pageFiles:a,componentFiles:i}=innerGetSortedJSFiles(n,s),l=!1;const p=findModByTypeAndPath(e,"Js","app.js");if(p){l=!0,o.push(p.path);const e=findAllDescendant([p],"Js");for(const t of e){const e=t.path;o.indexOf(e)<0&&o.push(e)}}return{hasAppJS:l,allFiles:o,pageFiles:a,componentFiles:i}}function innerGetResourceFiles(e,t){let n=[];for(const s of e){const e=findAllDescendant(s,t);n=n.concat(e.map(e=>e.path))}return n}function partialGetWxmlAndWxsFiles(e,t,n){const s=findPageMods(e,t),o=findGlobalCompMods(e),a=innerGetResourceFiles(s.concat(o),"Wxml"),i=innerGetResourceFiles(s.concat(o),"Wxs"),l=getAllSubpackagePath(e),p=groupBySubpackage(a,l),r=groupBySubpackage(i,l);return{wxmlFiles:n?p.main.concat(p.subs[n]||[]):p.main,wxsFiles:n?r.main.concat(r.subs[n]||[]):r.main}}function partialGetWxssFiles(e,t,n){const s=findPageMods(e,t),o=findGlobalCompMods(e),a=innerGetResourceFiles(s.concat(o),"Wxss"),i=findModByTypeAndPath(e,"Wxss","app.wxss");if(i&&!a.includes(i.path)){a.push(i.path);const e=findAllDescendant(i,"Wxss");for(const t of e)a.includes(t.path)||a.push(t.path)}const l=groupBySubpackage(a,getAllSubpackagePath(e));return n?l.main.concat(l.subs[n]||[]):l.main}function partialGetCodeFiles(e,t){const n=new Set,s=findModByTypeAndPath(e,"MainPackage","app.json");n.add("app.json");const o=new Set;function a(e){switch(o.add(e),e.type){case"Page":case"Component":case"Wxml":case"Wxss":case"Wxs":case"Js":case"Config":n.add(e.path)}for(const t of e.childModules)o.has(t)||a(t)}for(const e of null==s?void 0:s.childModules)if("Page"===e.type)t.includes(e.path.replace(/\.json$/,""))&&a(e);else if("SubPackage"===e.type)for(const n of e.childModules)t.includes(n.path.replace(/\.json$/,""))&&a(n);else a(e);return console.log("[partial-compile] compile",n),Array.from(n)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.partialGetCodeFiles=exports.partialGetWxssFiles=exports.partialGetWxmlAndWxsFiles=exports.partialWholePkgGetSortedJSFiles=exports.partialGetMainPkgSortedJSFiles=exports.partialGetSubPkgSortedJSFiles=exports.findAllDescendant=void 0,exports.findAllDescendant=findAllDescendant,exports.partialGetSubPkgSortedJSFiles=partialGetSubPkgSortedJSFiles,exports.partialGetMainPkgSortedJSFiles=partialGetMainPkgSortedJSFiles,exports.partialWholePkgGetSortedJSFiles=partialWholePkgGetSortedJSFiles,exports.partialGetWxmlAndWxsFiles=partialGetWxmlAndWxsFiles,exports.partialGetWxssFiles=partialGetWxssFiles,exports.partialGetCodeFiles=partialGetCodeFiles;
|
|
3
3
|
}(require("licia/lazyImport")(require), require)
|
package/dist/manifest.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
!function(require, directRequire){
|
|
2
|
-
"use strict";const template=require("@babel/template").default,generate=require("@babel/generator").default,hash=require("string-hash-64"),{transformSync:transformSync}=require("@babel/core"),traverse=require("@babel/traverse").default,parse=require("@babel/parser").parse,buildBindFunc=e=>template.ast(`\n var ${e} = this.${e}.bind(this);\n`),buildWorkletFunc=e=>template.ast(`\n var ${e} = this._${e}_worklet_factory_();\n`),globals=new Set(["this","console","_setGlobalConsole","Date","Array","ArrayBuffer","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","Float32Array","Float64Array","Date","HermesInternal","JSON","Math","Number","Object","String","Symbol","undefined","null","UIManager","requestAnimationFrame","_WORKLET","arguments","Boolean","parseInt","parseFloat","Map","Set","_log","_updateProps","RegExp","Error","global","_measure","_scrollTo","_setGestureState","_getCurrentTime","_eventTimestamp","_frameTimestamp","isNaN","LayoutAnimationRepository","_stopObservingProgress","_startObservingProgress","setTimeout","globalThis","workletUIModule"]),blacklistedFunctions=new Set(["stopCapturing","toString","map","filter","forEach","valueOf","toPrecision","toExponential","constructor","toFixed","toLocaleString","toSource","charAt","charCodeAt","concat","indexOf","lastIndexOf","localeCompare","length","match","replace","search","slice","split","substr","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","every","join","pop","push","reduce","reduceRight","reverse","shift","slice","some","sort","splice","unshift","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","bind","apply","call","__callAsync","includes"]),possibleOptFunction=new Set(["interpolate"]);class ClosureGenerator{constructor(){this.trie=[{},!1]}mergeAns(e,t){const[r,n]=e,[o,i]=t;return 0!==o.length?[r.concat(o),i]:[r,n]}findPrefixRec(e){const t=[[],null];if(!e||"MemberExpression"!==e.node.type)return t;const r=e.node;if("Identifier"!==r.property.type)return t;if(r.computed||"value"===r.property.name||blacklistedFunctions.has(r.property.name))return t;if(e.parent&&"AssignmentExpression"===e.parent.type&&e.parent.left===e.node)return t;const n=[r.property.name],o=r,i=this.findPrefixRec(e.parentPath);return this.mergeAns([n,o],i)}findPrefix(e,t){const r=[e],n=t.node,o=this.findPrefixRec(t.parentPath);return this.mergeAns([r,n],o)}addPath(e,t){const[r,n]=this.findPrefix(e,t);let o=this.trie,i=-1;for(const e of r)i++,o[1]||(o[0][e]||(o[0][e]=[{},!1]),i===r.length-1&&(o[0][e]=[n,!0]),o=o[0][e])}generateNodeForBase(e,t,r){const n=r[0][t];return n[1]?n[0]:e.objectExpression(Object.keys(n[0]).map(t=>e.objectProperty(e.identifier(t),this.generateNodeForBase(e,t,n),!1,!0)))}generate(e,t,r){const n=[...r];return e.objectExpression(t.map((t,r)=>e.objectProperty(e.identifier(t.name),this.generateNodeForBase(e,n[r],this.trie),!1,!0)))}}function buildWorkletString(e,t,r,n){traverse(t,{enter(t){e.removeComments(t.node)}});const o=e.functionExpression(e.identifier(n),t.program.body[0].expression.params,function(t,r){return 0===t.length?r:e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern(t.map(t=>e.objectProperty(e.identifier(t.name),e.identifier(t.name),!1,!0))),e.memberExpression(e.identifier("jsThis"),e.identifier("_closure")))]),r])}(r,t.program.body[0].expression.body));return generate(o,{compact:!0}).code}function generateWorkletFactory(e,t){const r=new Map;t.traverse({CallExpression:{enter(t){if(!e.isMemberExpression(t.node.callee))return;const n=[];let o=t.node.callee;for(;e.isMemberExpression(o);){const e=o.property.name;n.unshift(e),o=o.object}if(!e.isThisExpression(o))return;let i=n[n.length-1];if("bind"===i)return i=n[n.length-2],r.set(i,"bind"),void t.replaceWith(e.identifier(i));t.get("callee").replaceWith(e.identifier(i)),r.set(i,"worklet")}}});const n=[];r.forEach((e,t)=>{const r="bind"===e?(o=t,template.ast(`\n var ${o} = this.${o}.bind(this);\n`)):buildWorkletFunc(t);var o;n.push(r)});const o=e.arrowFunctionExpression(t.node.params,t.node.body),i=e.identifier("f");return e.functionExpression(null,[],e.blockStatement([...n,e.variableDeclaration("var",[e.variableDeclarator(i,o)]),e.returnStatement(i)]))}function removeWorkletDirective(e){let t;const r=parse("\n("+e.toString()+"\n)");return traverse(r,{DirectiveLiteral(e){"worklet"===e.node.value&&e.parentPath.remove()},Program:{exit(e){t=e.get("body.0.expression").node}}}),t}function makeWorkletName(e,t){return e.isObjectMethod(t)?t.node.key.name:e.isFunctionDeclaration(t)||e.isFunctionExpression(t)&&e.isIdentifier(t.node.id)?t.node.id.name:"_f"}function makeWorklet(e,t,r){const n=makeWorkletName(e,t),o=new Map,i=new Set,s=new ClosureGenerator,a={};t.traverse({DirectiveLiteral(e){"worklet"===e.node.value&&e.getFunctionParent()===t&&e.parentPath.remove()}});const l="\n("+(e.isObjectMethod(t)?"function ":"")+t.toString()+"\n)",c=transformSync(l,{filename:r,ast:!0,babelrc:!1,configFile:!1});t.parent&&t.parent.callee&&"createAnimatedStyle"===t.parent.callee.name&&(a.optFlags=isPossibleOptimization(c.ast)),traverse(c.ast,{ReferencedIdentifier(e){const r=e.node.name;if(globals.has(r)||t.node.id&&t.node.id.name===r)return;const n=e.parent;if("MemberExpression"===n.type&&n.property===e.node&&!n.computed)return;if("ObjectProperty"===n.type&&"ObjectExpression"===e.parentPath.parent.type&&e.node!==n.value)return;let i=e.scope;for(;null!=i;){if(null!=i.bindings[r])return;i=i.parent}o.set(r,e.node),s.addPath(r,e)},AssignmentExpression(t){const r=t.node.left;e.isMemberExpression(r)&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"value"})&&i.add(r.object.name)}});const p=Array.from(o.values()),u=e.identifier("_f"),d=e.cloneNode(t.node);let m;m="BlockStatement"===d.body.type?e.functionExpression(null,d.params,d.body):d;const f=buildWorkletString(e,c.ast,p,n),b=hash(f),h=t&&t.node&&t.node.loc&&t.node.loc.start;if(h){const{line:e,column:t}=h;"number"==typeof e&&"number"==typeof t&&(r=`${r} (${e}:${t})`)}const g=[e.variableDeclaration("const",[e.variableDeclarator(u,m)]),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("_closure"),!1),s.generate(e,p,o.keys()))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("asString"),!1),e.stringLiteral(f))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("__workletHash"),!1),e.numericLiteral(b))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("__location"),!1),e.stringLiteral(r))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("__worklet"),!1),e.booleanLiteral(!0)))];g.push(e.returnStatement(u));return e.functionExpression(t.id,[],e.blockStatement(g))}function processWorkletFunction(e,t,r){if(!e.isFunctionParent(t))return;if(t.parentPath.isObjectProperty()){const r=t.parent.key.name,n=removeWorkletDirective(t),o=generateWorkletFactory(e,t),i=`_${r}_worklet_factory_`;return void t.parentPath.replaceWithMultiple([e.objectProperty(e.identifier(r),n,!1,!1),e.objectProperty(e.identifier(i),o,!1,!1)])}const n=makeWorklet(e,t,r),o=e.callExpression(n,[]),i=e.isScopable(t.parent)||e.isExportNamedDeclaration(t.parent);t.replaceWith(t.node.id&&i?e.variableDeclaration("const",[e.variableDeclarator(t.node.id,o)]):o)}function processIfWorkletNode(e,t,r){t.traverse({DirectiveLiteral(n){if("worklet"===n.node.value&&n.getFunctionParent()===t){const n=t.node.body.directives;n&&n.length>0&&n.some(t=>e.isDirectiveLiteral(t.value)&&"worklet"===t.value.value)&&processWorkletFunction(e,t,r)}}})}const FUNCTIONLESS_FLAG=1,STATEMENTLESS_FLAG=2;function isPossibleOptimization(e){let t=!1,r=!1;traverse(e,{CallExpression(e){possibleOptFunction.has(e.node.callee.name)||(t=!0)},IfStatement(){r=!0}});let n=0;return t||(n|=1),r||(n|=2),n}module.exports=function({types:e}){return{pre(){null!=this.opts&&Array.isArray(this.opts.globals)&&this.opts.globals.forEach(e=>{globals.add(e)})},visitor:{"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression":{exit(t,r){const n=r.file.opts.filename||r.file.opts.sourceFileName;processIfWorkletNode(e,t,n)}}}}},module.exports.version="0.0.
|
|
2
|
+
"use strict";const template=require("@babel/template").default,generate=require("@babel/generator").default,hash=require("string-hash-64"),{transformSync:transformSync}=require("@babel/core"),traverse=require("@babel/traverse").default,parse=require("@babel/parser").parse,nodePath=require("path"),buildBindFunc=e=>template.ast(`\n var _${e}_ = this.${e}.bind(this);\n`),buildWorkletFunc=e=>template.ast(`\n var ${e} = this._${e}_worklet_factory_();\n`),globals=new Set(["this","console","_setGlobalConsole","Date","Array","ArrayBuffer","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","Float32Array","Float64Array","Date","HermesInternal","JSON","Math","Number","Object","String","Symbol","undefined","null","UIManager","requestAnimationFrame","_WORKLET","arguments","Boolean","parseInt","parseFloat","Map","Set","_log","_updateProps","RegExp","Error","global","_measure","_scrollTo","_setGestureState","_getCurrentTime","_eventTimestamp","_frameTimestamp","isNaN","LayoutAnimationRepository","_stopObservingProgress","_startObservingProgress","setTimeout","globalThis","workletUIModule"]),blacklistedFunctions=new Set(["stopCapturing","toString","map","filter","forEach","valueOf","toPrecision","toExponential","constructor","toFixed","toLocaleString","toSource","charAt","charCodeAt","concat","indexOf","lastIndexOf","localeCompare","length","match","replace","search","slice","split","substr","substring","toLocaleLowerCase","toLocaleUpperCase","toLowerCase","toUpperCase","every","join","pop","push","reduce","reduceRight","reverse","shift","slice","some","sort","splice","unshift","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","bind","apply","call","__callAsync","includes"]),possibleOptFunction=new Set(["interpolate"]);class ClosureGenerator{constructor(){this.trie=[{},!1]}mergeAns(e,t){const[r,n]=e,[o,i]=t;return 0!==o.length?[r.concat(o),i]:[r,n]}findPrefixRec(e){const t=[[],null];if(!e||"MemberExpression"!==e.node.type)return t;const r=e.node;if("Identifier"!==r.property.type)return t;if(r.computed||"value"===r.property.name||blacklistedFunctions.has(r.property.name))return t;if(e.parent&&"AssignmentExpression"===e.parent.type&&e.parent.left===e.node)return t;const n=[r.property.name],o=r,i=this.findPrefixRec(e.parentPath);return this.mergeAns([n,o],i)}findPrefix(e,t){const r=[e],n=t.node,o=this.findPrefixRec(t.parentPath);return this.mergeAns([r,n],o)}addPath(e,t){const[r,n]=this.findPrefix(e,t);let o=this.trie,i=-1;for(const e of r)i++,o[1]||(o[0][e]||(o[0][e]=[{},!1]),i===r.length-1&&(o[0][e]=[n,!0]),o=o[0][e])}generateNodeForBase(e,t,r){const n=r[0][t];return n[1]?n[0]:e.objectExpression(Object.keys(n[0]).map(t=>e.objectProperty(e.identifier(t),this.generateNodeForBase(e,t,n),!1,!0)))}generate(e,t,r){const n=[...r];return e.objectExpression(t.map((t,r)=>e.objectProperty(e.identifier(t.name),this.generateNodeForBase(e,n[r],this.trie),!1,!0)))}}function buildWorkletString(e,t,r,n){traverse(t,{enter(t){e.removeComments(t.node)}});const o=e.functionExpression(e.identifier(n),t.program.body[0].expression.params,function(t,r){return 0===t.length?r:e.blockStatement([e.variableDeclaration("const",[e.variableDeclarator(e.objectPattern(t.map(t=>e.objectProperty(e.identifier(t.name),e.identifier(t.name),!1,!0))),e.memberExpression(e.identifier("jsThis"),e.identifier("_closure")))]),r])}(r,t.program.body[0].expression.body));return generate(o,{compact:!0}).code}function generateWorkletFactory(e,t){const r=new Map;t.traverse({CallExpression:{enter(t){if(!e.isMemberExpression(t.node.callee))return;const n=[];let o=t.node.callee;for(;e.isMemberExpression(o);){const e=o.property.name;n.unshift(e),o=o.object}if(!e.isThisExpression(o))return;let i=n[n.length-1];if("bind"===i)return i=n[n.length-2],r.set(i,"bind"),void t.replaceWith(e.identifier(`_${i}_`));t.get("callee").replaceWith(e.identifier(i)),r.set(i,"worklet")}}});const n=[];r.forEach((e,t)=>{const r="bind"===e?(o=t,template.ast(`\n var _${o}_ = this.${o}.bind(this);\n`)):buildWorkletFunc(t);var o;n.push(r)});const o=e.arrowFunctionExpression(t.node.params,t.node.body),i=e.identifier("f");return e.functionExpression(null,[],e.blockStatement([...n,e.variableDeclaration("var",[e.variableDeclarator(i,o)]),e.returnStatement(i)]))}function removeWorkletDirective(e){let t;const r=parse("\n("+e.toString()+"\n)");return traverse(r,{DirectiveLiteral(e){"worklet"===e.node.value&&e.parentPath.remove()},Program:{exit(e){t=e.get("body.0.expression").node}}}),t}function makeWorkletName(e,t){return e.isObjectMethod(t)?t.node.key.name:e.isFunctionDeclaration(t)||e.isFunctionExpression(t)&&e.isIdentifier(t.node.id)?t.node.id.name:"_f"}function makeWorklet(e,t,r){const n=makeWorkletName(e,t),o=new Map,i=new Set,s=new ClosureGenerator,a={};t.traverse({DirectiveLiteral(e){"worklet"===e.node.value&&e.getFunctionParent()===t&&e.parentPath.remove()}});const l="\n("+(e.isObjectMethod(t)?"function ":"")+t.toString()+"\n)",c=transformSync(l,{filename:r,ast:!0,babelrc:!1,configFile:!1});t.parent&&t.parent.callee&&"createAnimatedStyle"===t.parent.callee.name&&(a.optFlags=isPossibleOptimization(c.ast)),traverse(c.ast,{ReferencedIdentifier(e){const r=e.node.name;if(globals.has(r)||t.node.id&&t.node.id.name===r)return;const n=e.parent;if("MemberExpression"===n.type&&n.property===e.node&&!n.computed)return;if("ObjectProperty"===n.type&&"ObjectExpression"===e.parentPath.parent.type&&e.node!==n.value)return;let i=e.scope;for(;null!=i;){if(null!=i.bindings[r])return;i=i.parent}o.set(r,e.node),s.addPath(r,e)},AssignmentExpression(t){const r=t.node.left;e.isMemberExpression(r)&&e.isIdentifier(r.object)&&e.isIdentifier(r.property,{name:"value"})&&i.add(r.object.name)}});const p=Array.from(o.values()),u=e.identifier("_f"),d=e.cloneNode(t.node);let m;m="BlockStatement"===d.body.type?e.functionExpression(null,d.params,d.body):d;const f=buildWorkletString(e,c.ast,p,n),b=hash(f),h=t&&t.node&&t.node.loc&&t.node.loc.start;if(h){const{line:e,column:t}=h;"number"==typeof e&&"number"==typeof t&&(r=`${r} (${e}:${t})`)}const g=[e.variableDeclaration("const",[e.variableDeclarator(u,m)]),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("_closure"),!1),s.generate(e,p,o.keys()))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("asString"),!1),e.stringLiteral(f))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("__workletHash"),!1),e.numericLiteral(b))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("__location"),!1),e.stringLiteral(r))),e.expressionStatement(e.assignmentExpression("=",e.memberExpression(u,e.identifier("__worklet"),!1),e.booleanLiteral(!0)))];g.push(e.returnStatement(u));return e.functionExpression(t.id,[],e.blockStatement(g))}function processWorkletFunction(e,t,r){if(!e.isFunctionParent(t))return;if(t.parentPath.isObjectProperty()){const r=t.parent.key.name,n=removeWorkletDirective(t),o=generateWorkletFactory(e,t),i=`_${r}_worklet_factory_`;return void t.parentPath.replaceWithMultiple([e.objectProperty(e.identifier(r),n,!1,!1),e.objectProperty(e.identifier(i),o,!1,!1)])}const n=makeWorklet(e,t,r),o=e.callExpression(n,[]),i=e.isScopable(t.parent)||e.isExportNamedDeclaration(t.parent);t.replaceWith(t.node.id&&i?e.variableDeclaration("const",[e.variableDeclarator(t.node.id,o)]):o)}function processIfWorkletNode(e,t,r){t.traverse({DirectiveLiteral(n){if("worklet"===n.node.value&&n.getFunctionParent()===t){const n=t.node.body.directives;n&&n.length>0&&n.some(t=>e.isDirectiveLiteral(t.value)&&"worklet"===t.value.value)&&processWorkletFunction(e,t,r)}}})}const FUNCTIONLESS_FLAG=1,STATEMENTLESS_FLAG=2;function isPossibleOptimization(e){let t=!1,r=!1;traverse(e,{CallExpression(e){possibleOptFunction.has(e.node.callee.name)||(t=!0)},IfStatement(){r=!0}});let n=0;return t||(n|=1),r||(n|=2),n}module.exports=function({types:e}){return{pre(){null!=this.opts&&Array.isArray(this.opts.globals)&&this.opts.globals.forEach(e=>{globals.add(e)})},visitor:{"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression":{exit(t,r){const n=r.file.opts.filename||r.file.opts.sourceFileName;processIfWorkletNode(e,t,n)}}}}},module.exports.version="0.0.7";
|
|
3
3
|
}(require("licia/lazyImport")(require), require)
|
package/package.json
CHANGED