Skip to content

Commit

Permalink
fix: parse5 attr value undefined error
Browse files Browse the repository at this point in the history
  • Loading branch information
halwu(吴浩麟) committed Aug 1, 2017
1 parent dd24c2f commit 64c70d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
17 changes: 10 additions & 7 deletions lib/util.js
Expand Up @@ -111,23 +111,26 @@ function replaceNodesWithNodes(oldNodes, newNodes = []) {
childNodes.splice(index, 0, ...newNodes);
}

/**
* concat parse5 attrs object like Object.assign
* @param attrsTo
* @param attrsFrom
* @returns {*}
*/
function assignParse5Attrs(attrsTo, attrsFrom) {
attrsFrom.forEach((attrFrom) => {
const index = attrsTo.findIndex((attrTo) => {
return attrTo.name === attrFrom.name;
});
// if find in attrFrom then replace value
if (index >= 0) {
if (attrFrom.value === undefined) {
// remove value's undefined attr
attrsTo.splice(index, 1);
} else {
attrsTo[index].value = attrFrom.value;
}
attrsTo[index].value = attrFrom.value;
} else {
attrsTo.push(attrFrom);
}
});
return attrsTo;
// remove undefined value attr
return attrsTo.filter(attrTo => attrTo.value !== undefined);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "web-webpack-plugin",
"version": "1.9.0",
"version": "1.9.1",
"description": "web plugin for webpack, alternatives for html-webpack-plugin, use HTML as entry",
"keywords": [
"webpack",
Expand Down Expand Up @@ -48,13 +48,13 @@
},
"devDependencies": {
"css-loader": "^0.28.4",
"ejs": "^2.5.6",
"eslint": "^4.2.0",
"ejs": "^2.5.7",
"eslint": "^4.3.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"html-minifier": "^3.5.2",
"html-minifier": "^3.5.3",
"husky": "^0.14.3",
"style-loader": "^0.18.2",
"webpack-dev-server": "^2.5.1"
"webpack-dev-server": "^2.6.1"
}
}

0 comments on commit 64c70d3

Please sign in to comment.