Skip to content

Commit 52686f7

Browse files
committed
feat(unassert-cli): unassert-cli begins
0 parents  commit 52686f7

File tree

22 files changed

+293
-0
lines changed

22 files changed

+293
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
npm-debug.log
3+
.idea/

bin/cmd.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* unassert-cli
5+
* Command line tool to encourage reliable programming by writing assertions in production code, and compiling them away from release
6+
*
7+
* https://github.com/twada/unassert-cli
8+
*
9+
* Copyright (c) 2016 Takuto Wada
10+
* Licensed under the MIT license.
11+
* http://twada.mit-license.org/
12+
*/
13+
'use strict';
14+
15+
var fs = require('fs');
16+
var concat = require('concat-stream');
17+
var esprima = require('esprima');
18+
var escodegen = require('escodegen');
19+
var unassert = require('unassert');
20+
21+
function transform (code) {
22+
var ast = esprima.parse(code, { sourceType: 'module' });
23+
return escodegen.generate(unassert(ast));
24+
}
25+
26+
var args = process.argv.slice(2);
27+
var file = args[0];
28+
var input, filepath;
29+
30+
if (file && file !== '-') {
31+
filepath = file;
32+
input = fs.createReadStream(file);
33+
} else {
34+
input = process.stdin;
35+
}
36+
37+
input.pipe(concat(function(buf) {
38+
console.log(transform(buf.toString('utf8')));
39+
}));
40+

package.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "unassert-cli",
3+
"description": "Command line tool for unassert",
4+
"version": "0.0.1",
5+
"author": {
6+
"name": "Takuto Wada",
7+
"email": "takuto.wada@gmail.com",
8+
"url": "https://github.com/twada"
9+
},
10+
"bin": {
11+
"unassert": "./bin/cmd.js"
12+
},
13+
"bugs": "https://github.com/twada/unassert-cli/issues",
14+
"dependencies": {
15+
"concat-stream": "^1.5.1",
16+
"escodegen": "^1.8.0",
17+
"esprima": "^2.7.1",
18+
"unassert": "^1.3.1"
19+
},
20+
"devDependencies": {
21+
"mocha": "^2.3.4"
22+
},
23+
"files": [
24+
"CHANGELOG.md",
25+
"README.md",
26+
"bin",
27+
"package.json"
28+
],
29+
"homepage": "https://github.com/twada/unassert-cli",
30+
"keywords": [
31+
"DbC",
32+
"assert",
33+
"assertion",
34+
"unassert"
35+
],
36+
"license": "MIT",
37+
"repository": {
38+
"type": "git",
39+
"url": "https://github.com/twada/unassert-cli.git"
40+
},
41+
"scripts": {
42+
"test": "mocha"
43+
}
44+
}

test/fixtures/assignment/expected.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var assert;
2+
function add(a, b) {
3+
return a + b;
4+
}

test/fixtures/assignment/fixture.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var assert;
2+
assert = require('assert');
3+
function add (a, b) {
4+
console.assert(typeof a === 'number');
5+
assert(!isNaN(a));
6+
assert.equal(typeof b, 'number');
7+
assert.ok(!isNaN(b));
8+
return a + b;
9+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var add, assert;
2+
add = function (a, b) {
3+
return a + b;
4+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var add, assert;
2+
assert = require('assert');
3+
add = function (a, b) {
4+
console.assert(typeof a === 'number');
5+
assert(!isNaN(a));
6+
assert.equal(typeof b, 'number');
7+
assert.ok(!isNaN(b));
8+
return a + b;
9+
};

test/fixtures/commonjs/expected.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
function add(a, b) {
3+
return a + b;
4+
}

test/fixtures/commonjs/fixture.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
var assert = require('assert');
4+
5+
function add (a, b) {
6+
assert(!isNaN(a));
7+
assert.equal(typeof b, 'number');
8+
assert.ok(!isNaN(b));
9+
return a + b;
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
function add(a, b) {
3+
return a + b;
4+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy