@jsenv/ast 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/html/html_node.js +9 -3
package/package.json
CHANGED
package/src/html/html_node.js
CHANGED
|
@@ -104,11 +104,11 @@ const injectWithWhitespaces = (nodeToInsert, futureParentNode, futureIndex) => {
|
|
|
104
104
|
const previousSiblings = childNodes.slice(0, futureIndex)
|
|
105
105
|
const nextSiblings = childNodes.slice(futureIndex)
|
|
106
106
|
const futureChildNodes = []
|
|
107
|
-
const previousSibling = previousSiblings[
|
|
107
|
+
const previousSibling = previousSiblings[previousSiblings.length - 1]
|
|
108
108
|
if (previousSibling) {
|
|
109
109
|
futureChildNodes.push(...previousSiblings)
|
|
110
110
|
}
|
|
111
|
-
if (!previousSibling || previousSibling
|
|
111
|
+
if (!previousSibling || !isWhitespaceNode(previousSibling)) {
|
|
112
112
|
futureChildNodes.push({
|
|
113
113
|
nodeName: "#text",
|
|
114
114
|
value: "\n ",
|
|
@@ -117,7 +117,7 @@ const injectWithWhitespaces = (nodeToInsert, futureParentNode, futureIndex) => {
|
|
|
117
117
|
}
|
|
118
118
|
futureChildNodes.push(nodeToInsert)
|
|
119
119
|
const nextSibling = nextSiblings[0]
|
|
120
|
-
if (!nextSibling || nextSibling
|
|
120
|
+
if (!nextSibling || !isWhitespaceNode(nextSibling)) {
|
|
121
121
|
futureChildNodes.push({
|
|
122
122
|
nodeName: "#text",
|
|
123
123
|
value: "\n ",
|
|
@@ -130,6 +130,12 @@ const injectWithWhitespaces = (nodeToInsert, futureParentNode, futureIndex) => {
|
|
|
130
130
|
futureParentNode.childNodes = futureChildNodes
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
const isWhitespaceNode = (node) => {
|
|
134
|
+
if (node.nodeName !== "#text") return false
|
|
135
|
+
if (node.value.length === 0) return false
|
|
136
|
+
return /^\s+$/.test(node.value)
|
|
137
|
+
}
|
|
138
|
+
|
|
133
139
|
const findChild = ({ childNodes = [] }, predicate) => childNodes.find(predicate)
|
|
134
140
|
|
|
135
141
|
const stringifyAttributes = (object) => {
|