Skip to content

Commit e89afa2

Browse files
committed
Rename node.attributes to attribs to prevent name clash with DOM property with the same name.
1 parent d5e7995 commit e89afa2

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

src/XMLDocumentCB.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ module.exports = class XMLDocumentCB
8787
when NodeType.Comment then @comment node.value
8888
when NodeType.Element
8989
attributes = {}
90-
for own attName, att of node.attributes
90+
for own attName, att of node.attribs
9191
attributes[attName] = att.value
9292
@node node.name, attributes
9393
when NodeType.Dummy then @dummy()
@@ -186,9 +186,9 @@ module.exports = class XMLDocumentCB
186186
else
187187
value = value.apply() if isFunction value
188188
if @options.keepNullAttributes and not value?
189-
@currentNode.attributes[name] = new XMLAttribute @, name, ""
189+
@currentNode.attribs[name] = new XMLAttribute @, name, ""
190190
else if value?
191-
@currentNode.attributes[name] = new XMLAttribute @, name, value
191+
@currentNode.attribs[name] = new XMLAttribute @, name, value
192192

193193
return @
194194

@@ -425,7 +425,7 @@ module.exports = class XMLDocumentCB
425425
chunk = @writer.indent(node, @writerOptions, @currentLevel) + '<' + node.name
426426

427427
# attributes
428-
for own name, att of node.attributes
428+
for own name, att of node.attribs
429429
chunk += @writer.attribute att, @writerOptions, @currentLevel
430430

431431
chunk += (if node.children then '>' else '/>') + @writer.endline(node, @writerOptions, @currentLevel)

src/XMLElement.coffee

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = class XMLElement extends XMLNode
2121

2222
@name = @stringify.name name
2323
@type = NodeType.Element
24-
@attributes = {}
24+
@attribs = {}
2525

2626
@attribute attributes if attributes?
2727

@@ -50,9 +50,9 @@ module.exports = class XMLElement extends XMLNode
5050
clonedSelf.documentObject = null
5151

5252
# clone attributes
53-
clonedSelf.attributes = {}
54-
for own attName, att of @attributes
55-
clonedSelf.attributes[attName] = att.clone()
53+
clonedSelf.attribs = {}
54+
for own attName, att of @attribs
55+
clonedSelf.attribs[attName] = att.clone()
5656

5757
# clone child nodes
5858
clonedSelf.children = []
@@ -77,9 +77,9 @@ module.exports = class XMLElement extends XMLNode
7777
else
7878
value = value.apply() if isFunction value
7979
if @options.keepNullAttributes and not value?
80-
@attributes[name] = new XMLAttribute @, name, ""
80+
@attribs[name] = new XMLAttribute @, name, ""
8181
else if value?
82-
@attributes[name] = new XMLAttribute @, name, value
82+
@attribs[name] = new XMLAttribute @, name, value
8383

8484
return @
8585

@@ -96,9 +96,9 @@ module.exports = class XMLElement extends XMLNode
9696

9797
if Array.isArray name # expand if array
9898
for attName in name
99-
delete @attributes[attName]
99+
delete @attribs[attName]
100100
else
101-
delete @attributes[name]
101+
delete @attribs[name]
102102

103103
return @
104104

src/XMLNode.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = class XMLNode
5454
Object.defineProperty @, 'nextSibling', get: () ->
5555
i = @parent.children.indexOf @
5656
@parent.children[i + 1] or null
57-
#Object.defineProperty @, 'attributes', get: () -> @attributes # NamedNodeMap ???
57+
#Object.defineProperty @, 'attributes', get: () -> @attribs # NamedNodeMap ???
5858
Object.defineProperty @, 'ownerDocument', get: () -> @document()
5959

6060
# Creates a child element node

src/XMLStreamWriter.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ module.exports = class XMLStreamWriter extends XMLWriterBase
8787
@stream.write @indent(node, options, level) + '<' + node.name
8888

8989
# attributes
90-
for own name, att of node.attributes
90+
for own name, att of node.attribs
9191
@attribute att, options, level
9292

9393
childNodeCount = node.children.length

src/XMLWriterBase.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ module.exports = class XMLWriterBase
186186
r += @indent(node, options, level) + '<' + node.name
187187

188188
# attributes
189-
for own name, att of node.attributes
189+
for own name, att of node.attribs
190190
r += @attribute att, options, level
191191

192192
childNodeCount = node.children.length

test/basic/tostring.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ suite 'Test toString() function with built-in XML writer:', ->
22
test 'Nodes', ->
33
eq xml('root').doc().toString(), '<?xml version="1.0"?><root/>'
44
eq xml('root').toString(), '<root/>'
5-
eq xml('root').att('att', 'val').attributes['att'].toString(), ' att="val"'
5+
eq xml('root').att('att', 'val').attribs['att'].toString(), ' att="val"'
66
eq xml('root').dat('val').children[0].toString(), '<![CDATA[val]]>'
77
eq xml('root').com('val').children[0].toString(), '<!-- val -->'
88
eq xml('root').ins('target', 'val').children[0].toString(), '<?target val?>'

0 commit comments

Comments
 (0)