Skip to content

Commit

Permalink
pass $gwx\d for #71
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty472123 committed Jun 9, 2018
1 parent 1c92ca7 commit 9135d26
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion wuWxss.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const {VM}=require('vm2');
const cssbeautify=require('cssbeautify');
const csstree=require('css-tree');
function doWxss(dir,cb){
function GwxCfg(){}
GwxCfg.prototype={$gwx(){}};
for(let i=0;i<100;i++)GwxCfg.prototype["$gwx"+i]=GwxCfg.prototype.$gwx;
let runList={},pureData={},result={},actualPure={},importCnt={},frameName="",onlyTest=true,blockCss=[];//custom block css file which won't be imported by others.(no extension name)
function cssRebuild(data){//need to bind this as {cssFile:__name__} before call
let cssFile;
Expand Down Expand Up @@ -62,7 +65,7 @@ function doWxss(dir,cb){
}
function runVM(name,code){
let wxAppCode={},handle={cssFile:name};
let vm=new VM({sandbox:{$gwx(){},__wxAppCode__:wxAppCode,setCssToHead:cssRebuild.bind(handle)}});
let vm=new VM({sandbox:Object.assign(new GwxCfg(),{__wxAppCode__:wxAppCode,setCssToHead:cssRebuild.bind(handle)})});
vm.run(code);
for(let name in wxAppCode)if(name.endsWith(".wxss")){
handle.cssFile=path.resolve(frameName,"..",name);
Expand Down

0 comments on commit 9135d26

Please # to comment.