babel-plugin-transform-comment-to-assert
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -11,8 +11,15 @@ 'use strict'; | ||
var t = _ref.types, | ||
template = _ref.template, | ||
transform = _ref.transform; | ||
var assertTemplate = template('\n assert.deepEqual($0, $1)\n '); | ||
var assertExpression = function assertExpression(actual, expected, loc) { | ||
var exp = t.callExpression(t.memberExpression(t.identifier('assert'), t.identifier('deepEqual')), [actual, expected]); | ||
exp.loc = loc; | ||
return exp; | ||
}; | ||
var throwsTemplate = template('\n assert.throws(() => { $0 } , $1);\n '); | ||
var throwsExpression = function throwsExpression(body, arg, loc) { | ||
var exp = t.callExpression(t.memberExpression(t.identifier('assert'), t.identifier('throws')), [t.arrowFunctionExpression([], body), arg]); | ||
exp.loc = loc; | ||
return exp; | ||
}; | ||
@@ -29,2 +36,3 @@ return { | ||
var commentLoc = comments[0].loc; | ||
var rawComment = comments[0].value.replace(arrowRegex, '').trim(); | ||
@@ -37,5 +45,5 @@ var comment = transform('() => (' + rawComment + ')').ast.program.body[0].expression.body; | ||
if (throws) { | ||
path.insertAfter(throwsTemplate(code, comment)); | ||
path.insertAfter(t.expressionStatement(throwsExpression(code, comment, commentLoc))); | ||
} else { | ||
path.insertAfter(assertTemplate(code, comment)); | ||
path.insertAfter(t.expressionStatement(assertExpression(code, comment, commentLoc))); | ||
} | ||
@@ -45,5 +53,5 @@ } else { | ||
if (throws) { | ||
path.replaceWith(throwsTemplate(child, comment)); | ||
path.replaceWith(throwsExpression(child, comment, commentLoc)); | ||
} else { | ||
path.replaceWith(assertTemplate(child, comment)); | ||
path.replaceWith(assertExpression(child, comment, commentLoc)); | ||
} | ||
@@ -50,0 +58,0 @@ } |
{ | ||
"name": "babel-plugin-transform-comment-to-assert", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Replace commented expressions with assert statements", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -65,5 +65,3 @@ # babel-plugin-transform-comment-to-assert [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] | ||
}; | ||
assert.throws(() => { | ||
a(); | ||
}, Error);` | ||
assert.throws(() => a(), Error);` | ||
*/ | ||
@@ -83,5 +81,3 @@ ``` | ||
}; | ||
assert.throws(() => { | ||
a(); | ||
}, /fail/);` | ||
assert.throws(() => a(), /fail/);` | ||
*/ | ||
@@ -88,0 +84,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6166
50
86