Skip to content

Commit

Permalink
fix(cli): color mark wrong, dom-walk fixed
Browse files Browse the repository at this point in the history
deps resolved log error in watch mode, cause module's color marks make wrong. other hand,
html2parser return an array instead of root object, we need to loop the array and find deps in wxml
files.
  • Loading branch information
Genuifx committed Aug 19, 2019
1 parent a19e164 commit 2fead70
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
3 changes: 0 additions & 3 deletions packages/wxa-cli/src/resolvers/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,4 @@ export default class ComponentManager {
}
}, []);
}

findComponentSource(com, mdl) {
}
}
17 changes: 8 additions & 9 deletions packages/wxa-cli/src/resolvers/xml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,28 @@ class XMLManager {
parse(mdl) {
if (mdl.xml == null) return null;

let libs = this.walkXML(mdl.xml, mdl);
let libs = [];

debug('libs in xml %O %O', mdl.xml, libs);
mdl.xml.forEach((element) => {
libs = libs.concat(this.walkXML(element, mdl));
});

mdl.code = new Coder().decodeTemplate(domSerializer(mdl.xml, {xmlMode: true}));

return libs;
}

walkXML(xml, mdl) {
debug('walk xml start %s', xml.nodeType);
let libs = [];
// ignore comment
if (xml.nodeType === NODE.COMMENT_NODE) return libs;
if (xml.type === 'comment') return libs;

if (xml.nodeType === NODE.ELEMENT_NODE) {
// element p view
debug('xml %O', xml);
if (xml.type === 'tag') {
libs = libs.concat(this.walkAttr(xml.attribs, mdl));
}

if (xml.childNodes) {
libs = libs.concat(Array.prototype.slice.call(xml.childNodes).reduce((ret, child)=>{
if (xml.children) {
libs = libs.concat(Array.prototype.slice.call(xml.children).reduce((ret, child)=>{
return ret.concat(this.walkXML(child, mdl));
}, []));
}
Expand Down
17 changes: 9 additions & 8 deletions packages/wxa-cli/src/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ class Schedule {
}

async $parse(dep) {
if (dep.color === COLOR.COMPILED) return [];
if (dep.color === COLOR.CHANGED) dep.code = void(0);
// calc hash
// cause not every module is actually exists, we can not promise all module has hash here.
let content = dep.content ? dep.content : readFile(dep.src);
Expand Down Expand Up @@ -293,26 +295,25 @@ class Schedule {
output: new Set([dep.meta.outputPath]),
outerDependencies: new Set(),
dependency: function(file) {
// let DR = new DependencyResolver(scheduler.wxaConfigs.resolve, scheduler.meta);
// let {source} = DR.resolveDep(file, this);

// debugger;
this.outerDependencies.add(file);
},
};


if (this.$indexOfModule.has(dep.src)) {
let indexedModule = this.$indexOfModule.get(dep.src);

// check hash
child.hash = !child.isAbstract && child.content ? getHashWithString(child.content) : getHash(child.src);

if (child.hash !== indexedModule.hash) {
// module changed, clean up mdl.
// module changed: clean up mdl, mark module as changed.
if (
child.hash !== indexedModule.hash &&
indexedModule.color === COLOR.COMPILED
) {
indexedModule.content = child.content;
indexedModule.code = void(0);
indexedModule.hash = child.hash;
indexedModule.color = COLOR.CHANGED;
}

// merge reference, cause the module is parsed
Expand All @@ -329,7 +330,7 @@ class Schedule {

child = indexedModule;
}
// debugger;

if (child.color !== COLOR.COMPILED) this.$depPending.push(child);
if (child.color === COLOR.INIT) this.$indexOfModule.set(child.src, child);

Expand Down

0 comments on commit 2fead70

Please sign in to comment.