babel-plugin-ava-throws-helper
Advanced tools
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", |
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
5117
71
2
+ Addedbabel-template@^6.7.0
+ Addedbabel-types@^6.7.2
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedglobals@9.18.0(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedjs-tokens@3.0.2(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedto-fast-properties@1.0.3(transitive)