Skip to content

Commit c56a415

Browse files
committed
Use lodash.create instead of underscore.clone
1 parent 0d9bce7 commit c56a415

15 files changed

+80
-45
lines changed

src/XMLAttribute.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ module.exports = class XMLAttribute
2121
@value = @stringify.attValue value
2222

2323

24+
# Creates and returns a deep clone of `this`
25+
clone: () ->
26+
_.create XMLAttribute.prototype, @
27+
28+
2429
# Converts the XML fragment to string
2530
#
2631
# `options.pretty` pretty prints the result

src/XMLCData.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ module.exports = class XMLCData extends XMLNode
1818
@text = @stringify.cdata text
1919

2020

21+
# Creates and returns a deep clone of `this`
22+
clone: () ->
23+
_.create XMLCData.prototype, @
24+
25+
2126
# Converts the XML fragment to string
2227
#
2328
# `options.pretty` pretty prints the result

src/XMLComment.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ module.exports = class XMLComment extends XMLNode
1818
@text = @stringify.comment text
1919

2020

21+
# Creates and returns a deep clone of `this`
22+
clone: () ->
23+
_.create XMLComment.prototype, @
24+
25+
2126
# Converts the XML fragment to string
2227
#
2328
# `options.pretty` pretty prints the result

src/XMLDTDAttList.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ module.exports = class XMLDTDAttList
3939
@defaultValueType = defaultValueType
4040

4141

42+
# Creates and returns a deep clone of `this`
43+
clone: () ->
44+
_.create XMLDTDAttList.prototype, @
45+
46+
4247
# Converts the XML fragment to string
4348
#
4449
# `options.pretty` pretty prints the result

src/XMLDTDElement.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ module.exports = class XMLDTDElement
2323
@value = @stringify.dtdElementValue value
2424

2525

26+
# Creates and returns a deep clone of `this`
27+
clone: () ->
28+
_.create XMLDTDElement.prototype, @
29+
30+
2631
# Converts the XML fragment to string
2732
#
2833
# `options.pretty` pretty prints the result

src/XMLDTDEntity.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ module.exports = class XMLDTDEntity
4141
throw new Error "Notation declaration is not allowed in a parameter entity"
4242

4343

44+
# Creates and returns a deep clone of `this`
45+
clone: () ->
46+
_.create XMLDTDEntity.prototype, @
47+
48+
4449
# Converts the XML fragment to string
4550
#
4651
# `options.pretty` pretty prints the result

src/XMLDTDNotation.coffee

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ module.exports = class XMLDTDNotation
2323
@pubID = @stringify.dtdPubID value.pubID if value.pubID?
2424
@sysID = @stringify.dtdSysID value.sysID if value.sysID?
2525

26+
27+
# Creates and returns a deep clone of `this`
28+
clone: () ->
29+
_.create XMLDTDNotation.prototype, @
30+
31+
2632
# Converts the XML fragment to string
2733
#
2834
# `options.pretty` pretty prints the result

src/XMLDeclaration.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ module.exports = class XMLDeclaration extends XMLNode
3232
@standalone = @stringify.xmlStandalone standalone
3333

3434

35+
# Creates and returns a deep clone of `this`
36+
clone: () ->
37+
_.create XMLDeclaration.prototype, @
38+
39+
3540
# Converts to string
3641
#
3742
# `options.pretty` pretty prints the result

src/XMLDocType.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ module.exports = class XMLDocType
2727
@sysID = @stringify.dtdSysID sysID if sysID?
2828

2929

30+
# Creates and returns a deep clone of `this`
31+
clone: () ->
32+
_.create XMLDocType.prototype, @
33+
34+
3035
# Creates an element type declaration
3136
#
3237
# `name` element name

src/XMLElement.coffee

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,27 @@ module.exports = class XMLElement extends XMLNode
2727
@attribute attributes if attributes?
2828

2929

30-
# Clones self
30+
# Creates and returns a deep clone of `this`
3131
#
32-
# `deep` true to clone child nodes as well
33-
clone: (deep) ->
34-
# shallow copy
35-
clonedSelf = _.clone @
32+
clone: () ->
33+
clonedSelf = _.create XMLElement.prototype, @
3634

3735
# clone attributes
3836
clonedSelf.attributes = {}
3937
for own attName, att of @attributes
40-
clonedSelf.attributes[attName] = _.clone att
38+
clonedSelf.attributes[attName] = att.clone()
4139

4240
# clone processing instructions
4341
clonedSelf.instructions = []
4442
for pi in @instructions
45-
clonedSelf.instructions.push _.clone pi
43+
clonedSelf.instructions.push pi.clone()
4644

47-
clonedSelf.children = []
4845
# clone child nodes
49-
if deep
50-
@children.forEach (child) ->
51-
clonedChild = child.clone(deep)
52-
clonedChild.parent = clonedSelf
53-
clonedSelf.children.push clonedChild
46+
clonedSelf.children = []
47+
@children.forEach (child) ->
48+
clonedChild = child.clone()
49+
clonedChild.parent = clonedSelf
50+
clonedSelf.children.push clonedChild
5451

5552
return clonedSelf
5653

0 commit comments

Comments
 (0)