Skip to content

Commit

Permalink
more cleanup and fixes, ready for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele Tamponi committed Nov 10, 2017
1 parent 6ef9056 commit c169941
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
@@ -1,5 +1,5 @@
{
"name": "coffee-coverage-v2",
"name": "coffee-coverage",
"description": "Istanbul and JSCoverage-style instrumentation for CoffeeScript files.",
"keywords": [
"javascript",
Expand All @@ -12,7 +12,7 @@
"jscoverage",
"coveralls"
],
"version": "2.0.3",
"version": "3.0.0",
"author": "Benbria (http://www.benbria.com/)",
"contributors": [
"Jason Walton <dev@lucid.thedreaming.org> (https://github.com/jwalton)",
Expand Down Expand Up @@ -53,7 +53,7 @@
"sinon": "^1.14.1"
},
"scripts": {
"prepublish": "npm run build",
"prepublish": "npm run build && mocha",
"test": "npm run build && mocha && istanbul report",
"coverage-report": "istanbul report text-summary lcov",
"build": "coffee -c -o lib src",
Expand Down
19 changes: 12 additions & 7 deletions src/SkipVisitor.coffee
Expand Up @@ -75,7 +75,7 @@ PRAGMAS = [
if node.type is "Value" and node.node.base.constructor?.name is "PassthroughLiteral"
throw new Error "Pragma '#{match[0]}' at #{self._toLocString node} has no next statement"

ifNode = self.checkType node, match, "If"
ifNode = self.getIfNode node, match
ifNode.mark 'skipIf', true
ifNode.child('body')?.markAll 'skip', true
}
Expand All @@ -89,8 +89,10 @@ PRAGMAS = [
fn: (self, node, match, options={}) ->
if node.type is "IdentifierLiteral"
return
if node.type is "Value" and node.node.base.constructor?.name is "PassthroughLiteral"
throw new Error "Pragma '#{match[0]}' at #{self._toLocString node} has no next statement"

ifNode = self.checkType node, match, "If"
ifNode = self.getIfNode node, match
ifNode.mark 'skipElse', true
ifNode.child('elseBody')?.markAll 'skip', true
}
Expand Down Expand Up @@ -123,9 +125,12 @@ module.exports = class SkipVisitor
_toLocString: (node) ->
return "#{@fileName} (#{node.locationData.first_line + 1}:#{node.locationData.first_column + 1})"

# Get the next non-comment statement.
checkType: (node, match, type=null) ->
if type? and node.type isnt type
throw new Error "Statement after pragma '#{match[0]}' at #{@_toLocString node} is not of type #{type}"
node
getIfNode: (node, match) ->
if node.type is "If"
return node
if node.parent?.parent?.type is "If"
return node.parent.parent
if node.parent?.parent?.parent?.type is "If"
return node.parent.parent.parent

throw new Error "Statement after pragma '#{match[0]}' at #{@_toLocString node} is not of type If"
8 changes: 4 additions & 4 deletions test/istanbul/pragmaTests.coffee
Expand Up @@ -85,7 +85,7 @@ module.exports = (run) ->
istanbulStyle = """
console.log "hello"
### istanbul ignore else ###
if x
if x is true
console.log "world"
else
console.log "earth"
Expand All @@ -109,7 +109,7 @@ module.exports = (run) ->
{instrumentor, result} = run """
console.log "hello"
### !pragma no-coverage-next ###
if x
if x is true
console.log "world"
else
console.log "bar"
Expand All @@ -124,7 +124,7 @@ module.exports = (run) ->
{instrumentor, result} = run """
console.log "hello"
#{skipPragma}
if x
if x is true
console.log "world"
else
console.log "earth"
Expand All @@ -143,7 +143,7 @@ module.exports = (run) ->
{instrumentor, result} = run """
console.log "hello"
#{skipPragma}
if x
if x is true
console.log "world"
""", counts: {f: 0, s: 3, b: {1:2}}

Expand Down
3 changes: 2 additions & 1 deletion test/mocha.opts
@@ -1,4 +1,5 @@
--compilers coffee:coffeescript/register
--require ./register-istanbul
--reporter spec
--recursive
--growl
--growl

0 comments on commit c169941

Please sign in to comment.