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

babel-plugin-ava-throws-helper

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-ava-throws-helper - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

78

index.js
'use strict';
var t = require('babel-types');
var template = require('babel-template');
module.exports = function (babel) {
var template = babel.template;
var t = babel.types;
var wrapWithHelper = template([
'HELPER_ID(function () {',
' return EXP;',
'}, {',
' line: LINE,',
' column: COLUMN,',
' source: SOURCE',
'});'
].join('\n'));
var wrapWithHelper = template([
'HELPER_ID(function () {',
' return EXP;',
'}, {',
' line: LINE,',
' column: COLUMN,',
' source: SOURCE',
'});'
].join('\n'));
var buildHelper = template([
'function HELPER_ID(fn, data) {',
' try {',
' return fn();',
' } catch (e) {',
' var type = typeof e;',
' if (e !== null && (type === "object" || type === "function")) {',
' try {',
' Object.defineProperty(e, "_avaThrowsHelperData", {',
' value: data',
' });',
' } catch (e) {}',
' }',
' throw e;',
' }',
'}'
].join('\n'));
var buildHelper = template([
'function HELPER_ID(fn, data) {',
' try {',
' return fn();',
' } catch (e) {',
' e._avaTryCatchHelperData = data;',
' throw e;',
' }',
'}'
].join('\n'));
var assertionVisitor = {
CallExpression: function (path, state) {
if (isThrowsMember(path.get('callee'))) {
var arg0 = path.node.arguments[0];
path.node.arguments[0] = wrapWithHelper({
HELPER_ID: t.identifier(this.avaThrowHelper()),
EXP: arg0,
LINE: t.numericLiteral(arg0.loc.start.line),
COLUMN: t.numericLiteral(arg0.loc.start.column),
SOURCE: t.stringLiteral(state.file.code.substring(arg0.start, arg0.end))
}).expression;
}
var assertionVisitor = {
CallExpression: function (path, state) {
if (isThrowsMember(path.get('callee'))) {
var arg0 = path.node.arguments[0];
path.node.arguments[0] = wrapWithHelper({
HELPER_ID: t.identifier(this.avaThrowHelper()),
EXP: arg0,
LINE: t.numericLiteral(arg0.loc.start.line),
COLUMN: t.numericLiteral(arg0.loc.start.column),
SOURCE: t.stringLiteral(state.file.code.substring(arg0.start, arg0.end))
}).expression;
}
};
}
};
module.exports = function () {
return {

@@ -44,0 +50,0 @@ visitor: {

{
"name": "babel-plugin-ava-throws-helper",
"version": "0.0.2",
"version": "0.0.3",
"description": "My cool module",

@@ -16,3 +16,4 @@ "license": "MIT",

"scripts": {
"test": "xo && ava"
"test": "xo && ava",
"preversion": "WRITE_EXAMPLES=1 npm run test && git add example-output.md"
},

@@ -25,3 +26,6 @@ "files": [

],
"dependencies": {},
"dependencies": {
"babel-template": "^6.7.0",
"babel-types": "^6.7.2"
},
"devDependencies": {

@@ -28,0 +32,0 @@ "ava": "^0.14.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