Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-comment-to-assert

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-comment-to-assert - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

22

lib/index.js

@@ -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 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc