From c16994142686c8a55d87537eedeae443ba78ea57 Mon Sep 17 00:00:00 2001 From: Emanuele Tamponi Date: Fri, 10 Nov 2017 16:49:32 +0100 Subject: [PATCH] more cleanup and fixes, ready for PR --- package-lock.json | 4 ++-- package.json | 6 +++--- src/SkipVisitor.coffee | 19 ++++++++++++------- test/istanbul/pragmaTests.coffee | 8 ++++---- test/mocha.opts | 3 ++- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7c7cda1..c5e47f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "coffee-coverage-v2", - "version": "2.0.2", + "name": "coffee-coverage", + "version": "3.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3b5e853..163ebc5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "coffee-coverage-v2", + "name": "coffee-coverage", "description": "Istanbul and JSCoverage-style instrumentation for CoffeeScript files.", "keywords": [ "javascript", @@ -12,7 +12,7 @@ "jscoverage", "coveralls" ], - "version": "2.0.3", + "version": "3.0.0", "author": "Benbria (http://www.benbria.com/)", "contributors": [ "Jason Walton (https://github.com/jwalton)", @@ -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", diff --git a/src/SkipVisitor.coffee b/src/SkipVisitor.coffee index 2dd133d..d41939a 100644 --- a/src/SkipVisitor.coffee +++ b/src/SkipVisitor.coffee @@ -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 } @@ -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 } @@ -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" diff --git a/test/istanbul/pragmaTests.coffee b/test/istanbul/pragmaTests.coffee index 81fe8a5..d1c37cf 100644 --- a/test/istanbul/pragmaTests.coffee +++ b/test/istanbul/pragmaTests.coffee @@ -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" @@ -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" @@ -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" @@ -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}} diff --git a/test/mocha.opts b/test/mocha.opts index 06fa929..3b1c242 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,4 +1,5 @@ --compilers coffee:coffeescript/register +--require ./register-istanbul --reporter spec --recursive ---growl \ No newline at end of file +--growl