From 64c70d33e467f1521c4903116e00e648e260ab35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?halwu=28=E5=90=B4=E6=B5=A9=E9=BA=9F=29?= Date: Tue, 1 Aug 2017 17:58:26 +0800 Subject: [PATCH] fix: parse5 attr value undefined error --- lib/util.js | 17 ++++++++++------- package.json | 10 +++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/util.js b/lib/util.js index d0511f5..8eed174 100644 --- a/lib/util.js +++ b/lib/util.js @@ -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); } /** diff --git a/package.json b/package.json index 800ae8e..18a2c58 100644 --- a/package.json +++ b/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", @@ -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" } }