Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
add strip-asserts plugin option
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jun 2, 2016
1 parent 1a970f5 commit c61c8c2
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 118 deletions.
16 changes: 0 additions & 16 deletions .eslintrc

This file was deleted.

15 changes: 15 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"parser": "babel-eslint",
"extends": "eslint:recommended",
"env": {
"browser": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"rules": {
"semi": [2, "never"]
}
}
15 changes: 9 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,6 @@ exports.default = function (_ref) {
return t.expressionStatement(assert);
}

function isObjectStructureAnnotation(typeAnnotation) {
// Example: function foo(x : { bar: t.String })
return typeAnnotation.type === 'ObjectTypeAnnotation' && typeAnnotation.indexers.length !== 1;
}

function getAssert(_ref3) {
var name = _ref3.name;
var optional = _ref3.optional;
Expand Down Expand Up @@ -297,6 +292,10 @@ exports.default = function (_ref) {
return [t.variableDeclaration('const', [t.variableDeclarator(id, t.callExpression(t.memberExpression(t.functionExpression(null, params, node.body), t.identifier('call')), [t.identifier('this')].concat(callParams)))]), assert, t.returnStatement(id)];
}

//
// visitors
//

return {
visitor: {
Program: {
Expand Down Expand Up @@ -330,7 +329,11 @@ exports.default = function (_ref) {
ensureTcombLocalName();
path.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(node.id, getType(node.right, t.stringLiteral(node.id.name)))]));
},
Function: function Function(path) {
Function: function Function(path, state) {
if (state.opts['strip-asserts']) {
return;
}

var node = path.node;


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Babel plugin for runtime type checking using tcomb",
"main": "lib/index.js",
"scripts": {
"lint": "eslint src/index.js",
"lint": "eslint src",
"build": "babel --plugins syntax-flow -d ./lib ./src",
"test": "mocha --compilers js:babel-core/register"
},
Expand All @@ -24,7 +24,7 @@
"babel-eslint": "6.0.3",
"babel-plugin-syntax-flow": "6.5.0",
"babel-preset-es2015": "6.6.0",
"eslint": "2.8.0",
"eslint": "2.9.0",
"mocha": "2.4.5",
"tcomb": "^3.0.0"
},
Expand Down
Loading

0 comments on commit c61c8c2

Please sign in to comment.