|
|
@@ -149,16 +149,14 @@ export default class Element extends Node {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Creates a copy of this element and returns it. Created element has same name and attributes as original element.
|
|
|
- * If clone is not deep, children of copied element are references to the same nodes as in original element.
|
|
|
- * If clone is deep, original element's children are also cloned.
|
|
|
+ * Creates a copy of this element and returns it. Created element has the same name and attributes as the original element.
|
|
|
+ * If clone is deep, the original element's children are also cloned. If not, then empty element is removed.
|
|
|
*
|
|
|
- * @param {Boolean} [deep=false] Decides whether children of this element should also be cloned (`true`) or not (`false`).
|
|
|
+ * @param {Boolean} [deep=false] If set to `true` clones element and all its children recursively. When set to `false`,
|
|
|
+ * element will be cloned without any child.
|
|
|
*/
|
|
|
clone( deep = false ) {
|
|
|
- const children = deep ?
|
|
|
- Array.from( this._children ).map( ( node ) => node.clone() ) :
|
|
|
- Array.from( this._children );
|
|
|
+ const children = deep ? Array.from( this._children ).map( ( node ) => node.clone( true ) ) : null;
|
|
|
|
|
|
return new Element( this.name, this.getAttributes(), children );
|
|
|
}
|