提交 72931bc8 编写于 作者: 5 592767809

加载器抽取优化

上级 90a75563
!function(e){function n(data){for(var n,t,d=data[0],l=data[1],f=data[2],i=0,m=[];i<d.length;i++)t=d[i],Object.prototype.hasOwnProperty.call(o,t)&&o[t]&&m.push(o[t][0]),o[t]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(h&&h(data);m.length;)m.shift()();return c.push.apply(c,f||[]),r()}function r(){for(var e,i=0;i<c.length;i++){for(var n=c[i],r=!0,t=1;t<n.length;t++){var l=n[t];0!==o[l]&&(r=!1)}r&&(c.splice(i--,1),e=d(d.s=n[0]))}return e}var t={},o={31:0},c=[];function d(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,d),r.l=!0,r.exports}d.e=function(e){var n=[],r=o[e];if(0!==r)if(r)n.push(r[2]);else{var t=new Promise((function(n,t){r=o[e]=[n,t]}));n.push(r[2]=t);var c,script=document.createElement("script");script.charset="utf-8",script.timeout=120,d.nc&&script.setAttribute("nonce",d.nc),script.src=function(e){return d.p+""+({0:"commons/5b7f9e1d",1:"vendors/f2d66b02",2:"vendors/0f68e262",5:"pages/album_detail/_index",6:"pages/callback",7:"pages/down/index",8:"pages/downtingshu/index",9:"pages/index",10:"pages/logout/index",11:"pages/musician/index",12:"pages/musician/page",13:"pages/mvplay/_index",14:"pages/mvs/index",15:"pages/play_detail/_index",16:"pages/playlist_detail/_index",17:"pages/playlists/index",18:"pages/rankList/index",19:"pages/search",20:"pages/search/album",21:"pages/search/list",22:"pages/search/mv",23:"pages/search/playlist",24:"pages/search/singers",25:"pages/singer_detail/_index",26:"pages/singer_detail/index/album",27:"pages/singer_detail/index/index",28:"pages/singer_detail/index/info",29:"pages/singer_detail/index/mv",30:"pages/singers/index"}[e]||e)+"."+{0:"d536e95",1:"0f4fa0b",2:"5b01abc",5:"c53c23e",6:"c6c6835",7:"ffdae64",8:"cedc462",9:"ab70afa",10:"e2220e2",11:"931220d",12:"fad1e94",13:"9bf3f8e",14:"d920d6a",15:"213c3d5",16:"cf19ebc",17:"30478e4",18:"7f48ab9",19:"cfd9038",20:"85c386a",21:"0bef0c1",22:"ed18fac",23:"da962f3",24:"537ff5d",25:"e297d8c",26:"ea1087e",27:"492aacd",28:"7b8bdff",29:"fbe5785",30:"ce749e7"}[e]+".js"}(e);var l=new Error;c=function(n){script.onerror=script.onload=null,clearTimeout(f);var r=o[e];if(0!==r){if(r){var t=n&&("load"===n.type?"missing":n.type),c=n&&n.target&&n.target.src;l.message="Loading chunk "+e+" failed.\n("+t+": "+c+")",l.name="ChunkLoadError",l.type=t,l.request=c,r[1](l)}o[e]=void 0}};var f=setTimeout((function(){c({type:"timeout",target:script})}),12e4);script.onerror=script.onload=c,document.head.appendChild(script)}return Promise.all(n)},d.m=e,d.c=t,d.d=function(e,n,r){d.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},d.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},d.t=function(e,n){if(1&n&&(e=d(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(d.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var t in e)d.d(r,t,function(n){return e[n]}.bind(null,t));return r},d.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return d.d(n,"a",n),n},d.o=function(object,e){return Object.prototype.hasOwnProperty.call(object,e)},d.p="https://h5static.kuwo.cn/www/kw-www/",d.oe=function(e){throw console.error(e),e};var l=window.webpackJsonp=window.webpackJsonp||[],f=l.push.bind(l);l.push=n,l=l.slice();for(var i=0;i<l.length;i++)n(l[i]);var h=f;r()}([]);
\ No newline at end of file
const parser = require("@babel/parser");
const t = require("@babel/types");
const generator = require("@babel/generator");
const traverse = require("@babel/traverse").default;
const fs = require("fs");
function wtofile(path, flags, code) {
......@@ -24,25 +25,48 @@ function run(loader_path, out_path, modular_path) {
}else{
loader_body = loader_ast.program.body[0].expression.callee.body.body;
}
let export_function = null;
traverse(loader_ast, {
FunctionDeclaration(path){
if(path.toString().includes("exports:")){
export_function = path.node.id.name
}
}
});
if(export_function == null){
throw "未找到导出函数错误"
}
for (let i = 0; i < loader_body.length; i++){
if (loader_body[i].type === 'VariableDeclaration'){
let j = i + 1;
while (j < loader_body.length){
if (loader_body[j].type === 'VariableDeclaration'){
loader_body.splice(j, (loader_body.length - j));
loader_body.splice(0, i);
let tempname = '';
loader_body.forEach(function (item, index) {
if (item.type === 'FunctionDeclaration'){
tempname = item.id.name;
}
});
loader_body.push(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(tempname)));
}else {
j++;
let item = loader_body[i];
if(item.type === 'ExpressionStatement'){
if(item.expression.type === 'SequenceExpression' && item.expression.expressions[0].left.type === 'MemberExpression' && item.expression.expressions[0].left.object.type === 'Identifier' && item.expression.expressions[0].left.object.name === export_function){
let j = 1;
while (j < item.expression.expressions.length){
let item2 = item.expression.expressions[j];
if(item2.left &&item2.left.type === 'MemberExpression' && item2.left.object.type === 'Identifier' && item2.left.object.name === export_function){
j++
}else{
item.expression.expressions.splice(j, item.expression.expressions.length - j);
break
}
}
loader_body.splice(i + 1, loader_body.length - i - 1);
loader_body.push(t.expressionStatement(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(export_function))));
}
}else if(item.type === 'ReturnStatement'){
loader_body[i] = t.expressionStatement(item.argument);
let j = 0;
while (j < loader_body[i].expression.expressions.length){
let item2 = loader_body[i].expression.expressions[j];
if(item2.left &&item2.left.type === 'MemberExpression' && item2.left.object.type === 'Identifier' && item2.left.object.name === export_function){
j++
}else{
loader_body[i].expression.expressions.splice(j, loader_body[i].expression.expressions.length - j);
break
}
}
break;
loader_body.push(t.expressionStatement(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(export_function))));
}
}
......
const parser = require("@babel/parser");
const t = require("@babel/types");
const generator = require("@babel/generator");
const traverse = require("@babel/traverse").default;
const fs = require("fs");
function wtofile(path, flags, code) {
......@@ -24,26 +25,57 @@ function run(loader_path, out_path, modular_path) {
}else{
loader_body = loader_ast.program.body[0].expression.callee.body.body;
}
let export_function = null;
traverse(loader_ast, {
FunctionDeclaration(path){
if(path.toString().includes("exports:")){
export_function = path.node.id.name
}
}
});
if(export_function == null){
throw "未找到导出函数错误"
}
for (let i = 0; i < loader_body.length; i++){
if (loader_body[i].type === 'VariableDeclaration'){
let j = i + 1;
while (j < loader_body.length){
if (loader_body[j].type === 'VariableDeclaration'){
loader_body.splice(j, (loader_body.length - j));
loader_body.splice(0, i);
let tempname = '';
loader_body.forEach(function (item, index) {
if (item.type === 'FunctionDeclaration'){
tempname = item.id.name;
}
});
loader_body.push(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(tempname)));
}else {
j++;
let item = loader_body[i];
if(item.type === 'ExpressionStatement'){
if(item.expression.type === 'SequenceExpression' && item.expression.expressions[0].left.type === 'MemberExpression' && item.expression.expressions[0].left.object.type === 'Identifier' && item.expression.expressions[0].left.object.name === export_function){
let j = 1;
while (j < item.expression.expressions.length){
let item2 = item.expression.expressions[j];
if(item2.left.type === 'MemberExpression' && item2.left.object.type === 'Identifier' && item2.left.object.name === export_function){
j++
}else{
item.expression.expressions.splice(j, item.expression.expressions.length - j);
break
}
}
loader_body.splice(i + 1, loader_body.length - i - 1);
loader_body.push(t.expressionStatement(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(export_function))));
}
break;
}else if(item.type === 'ReturnStatement'){
}
// if (loader_body[i].type === 'VariableDeclaration'){
// let j = i + 1;
// while (j < loader_body.length){
// if (loader_body[j].type === 'VariableDeclaration' || loader_body[j].type === 'ReturnStatement'){
// loader_body.splice(j, (loader_body.length - j));
// loader_body.splice(0, i);
// let tempname = '';
// loader_body.forEach(function (item, index) {
// if (item.type === 'FunctionDeclaration'){
// tempname = item.id.name;
// }
// });
// loader_body.push(t.assignmentExpression("=", t.identifier("export_function"), t.identifier(tempname)));
// }else {
// j++;
// }
// }
// break;
// }
}
// 导入加载器中的函数体
......
var export_function;
!function (e) {
function n(data) {
for (var n, t, d = data[0], l = data[1], f = data[2], i = 0, m = []; i < d.length; i++) t = d[i], Object.prototype.hasOwnProperty.call(o, t) && o[t] && m.push(o[t][0]), o[t] = 0;
for (n in l) Object.prototype.hasOwnProperty.call(l, n) && (e[n] = l[n]);
for (h && h(data); m.length;) m.shift()();
return c.push.apply(c, f || []), r();
}
function r() {
for (var e, i = 0; i < c.length; i++) {
for (var n = c[i], r = !0, t = 1; t < n.length; t++) {
var l = n[t];
0 !== o[l] && (r = !1);
}
r && (c.splice(i--, 1), e = d(d.s = n[0]));
}
return e;
}
var t = {},
o = {
31: 0
......@@ -149,7 +172,7 @@ var export_function;
}, d.p = "https://h5static.kuwo.cn/www/kw-www/", d.oe = function (e) {
throw console.error(e), e;
};
export_function = d
export_function = d;
}({
0: function (t, e, n) {
"use strict";
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册