Skip to content

Commit ff1d89c

Browse files
committed
Remove duplicate null checks
1 parent 6188652 commit ff1d89c

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

src/XMLAttribute.coffee

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ module.exports = class XMLAttribute
1414

1515
if not name?
1616
throw new Error "Missing attribute name"
17-
18-
# evaluate if function
19-
value = value.apply() if _.isFunction value
17+
if not value?
18+
throw new Error "Missing attribute value"
2019

2120
@name = @stringify.attName name
2221
@value = @stringify.attValue value

src/XMLElement.coffee

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = class XMLElement extends XMLNode
3737
clonedSelf = _.clone @
3838

3939
# clone attributes
40-
clonedSelf.attributes = {}
40+
clonedSelf.attributes = {}
4141
for own attName, att of @attributes
4242
clonedSelf.attributes[attName] = _.clone att
4343

@@ -62,14 +62,8 @@ module.exports = class XMLElement extends XMLNode
6262
# `name` attribute name
6363
# `value` attribute value
6464
attribute: (name, value) ->
65-
if not name?
66-
throw new Error "Missing attribute name"
67-
if not value?
68-
throw new Error "Missing attribute value"
69-
70-
@attributes ?= {}
65+
value = value.apply() if _.isFunction value
7166
@attributes[name] = new XMLAttribute @, name, value
72-
7367
return @
7468

7569

@@ -90,6 +84,7 @@ module.exports = class XMLElement extends XMLNode
9084
# `target` instruction target
9185
# `value` instruction value
9286
instruction: (target, value) ->
87+
value = value.apply() if _.isFunction value
9388
instruction = new XMLProcessingInstruction @, target, value
9489
@instructions.push instruction
9590
return @

src/XMLProcessingInstruction.coffee

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ module.exports = class XMLProcessingInstruction
1515
if not target?
1616
throw new Error "Missing instruction target"
1717

18-
# evaluate if function
19-
value = value.apply() if _.isFunction value
20-
2118
@target = @stringify.insTarget target
2219
@value = @stringify.insValue value if value
2320

0 commit comments

Comments
 (0)