Repository: DmitrySoshnikov/regexp-tree
Pull request #25 (2017-03-30 18:19:57)

Minor tweaks
Probably not the most useful PR, but still, worth a shot IMO.


Patch:
diff --git a/README.md b/README.md
index 989ec04..900f3ba 100644
--- a/README.md
+++ b/README.md
@@ -99,9 +99,7 @@ The parser can also be used as a Node module:
 ```js
 const regexpTree = require('regexp-tree');
 
-const regexpString = (/a|b/i).toString();
-
-console.log(regexpTree.parse(regexpString)); // RegExp AST
+console.log(regexpTree.parse(/a|b/i)); // RegExp AST
 ```
 
 ### Capturing locations
diff --git a/bin/regexp-tree b/bin/regexp-tree
index 04ae233..a7b6bac 100755
--- a/bin/regexp-tree
+++ b/bin/regexp-tree
@@ -3,7 +3,7 @@
 'use strict';
 
 const fs = require('fs');
-const regexpTree = require('../index');
+const regexpTree = require('..');
 
 const options = require('nomnom')
   .script('regexp-tree')
@@ -23,7 +23,7 @@ const options = require('nomnom')
   .parse();
 
 function main() {
-  let {
+  const {
     expression,
     loc,
   } = options;
@@ -39,5 +39,5 @@ function main() {
 }
 
 if (require.main === module) {
-    main();
+  main();
 }
\ No newline at end of file
diff --git a/package.json b/package.json
index c98eaa7..df6d9bc 100644
--- a/package.json
+++ b/package.json
@@ -3,16 +3,12 @@
   "version": "0.0.19",
   "license": "MIT",
   "description": "Regular Expressions parser in JavaScript",
-  "repository": {
-    "type": "git",
-    "url": "https://github.com/DmitrySoshnikov/regexp-tree.git"
-  },
+  "repository": "DmitrySoshnikov/regexp-tree",
   "homepage": "https://github.com/DmitrySoshnikov/regexp-tree",
   "bugs": "https://github.com/DmitrySoshnikov/regexp-tree/issues",
-  "main": "index.js",
   "scripts": {
     "build": "./scripts/build",
-    "test": "./scripts/test",
+    "test": "jest",
     "prepublish": "npm test && npm run build"
   },
   "bin": {
diff --git a/src/generator/index.js b/src/generator/index.js
index a74d412..7800bcf 100644
--- a/src/generator/index.js
+++ b/src/generator/index.js
@@ -22,7 +22,7 @@ const generator = {
 
   Alternative(node) {
     return (node.expressions || [])
-      .map(node => gen(node))
+      .map(gen)
       .join('');
   },
 
@@ -42,10 +42,11 @@ const generator = {
 
   Assertion(node) {
     switch (node.kind) {
-      case '^': return '^';
-      case '$': return '$';
-      case '\\b': return '\\b';
-      case '\\B': return '\\B';
+      case '^':
+      case '$':
+      case '\\b':
+      case '\\B':
+        return node.kind;
 
       case 'Lookahead': {
         const assertion = gen(node.assertion);
@@ -58,13 +59,13 @@ const generator = {
       }
 
       default:
-        throw new TypeError('Unknown Assertion kind: ' + node.kind);
+        throw new TypeError(`Unknown Assertion kind: ${node.kind}`);
     }
   },
 
   CharacterClass(node) {
     const expressions = (node.expressions || [])
-      .map(node => gen(node))
+      .map(gen)
       .join('');
 
     if (node.negative) {
@@ -88,13 +89,9 @@ const generator = {
 
     switch (node.kind) {
       case '+':
-        quantifier = `+`;
-        break;
       case '?':
-        quantifier = `?`;
-        break;
       case '*':
-        quantifier = `*`;
+        quantifier = node.kind;
         break;
       case 'Range':
         // Exact: {1}
@@ -111,7 +108,7 @@ const generator = {
         }
         break;
       default:
-        throw new TypeError('Unknown Quantifier kind: ' + node.kind);
+        throw new TypeError(`Unknown Quantifier kind: ${node.kind}`);
     }
 
     return `${quantifier}${greedy}`;
@@ -137,7 +134,7 @@ const generator = {
         return value;
 
       default:
-        throw new TypeError('Unknown Char kind: ' + node.kind);
+        throw new TypeError(`Unknown Char kind: ${node.kind}`);
     }
   },
 };


Test patch:
diff --git a/__tests__/integration-test.js b/__tests__/integration-test.js
index 990a291..e397961 100644
--- a/__tests__/integration-test.js
+++ b/__tests__/integration-test.js
@@ -3,7 +3,7 @@
  * Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
  */
 
-const regexpTree = require('../index');
+const regexpTree = require('..');
 
 describe('regexp-tree', () => {
 
diff --git a/scripts/test b/scripts/test
deleted file mode 100755
index a576728..0000000
--- a/scripts/test
+++ /dev/null
@@ -1,1 +0,0 @@
-node ./node_modules/jest-cli/bin/jest.js
\ No newline at end of file
diff --git a/src/generator/__tests__/generator-basic-test.js b/src/generator/__tests__/generator-basic-test.js
index 6d0e50e..5f1c4c9 100644
--- a/src/generator/__tests__/generator-basic-test.js
+++ b/src/generator/__tests__/generator-basic-test.js
@@ -4,7 +4,7 @@
  */
 
 const parser = require('../../parser');
-const generator = require('../index');
+const generator = require('..');
 
 function test(re) {
   const reStr = re.toString();
diff --git a/src/parser/__tests__/parser-basic-test.js b/src/parser/__tests__/parser-basic-test.js
index dd2897b..0acfbe3 100644
--- a/src/parser/__tests__/parser-basic-test.js
+++ b/src/parser/__tests__/parser-basic-test.js
@@ -3,7 +3,7 @@
  * Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
  */
 
-const regexpTree = require('../index');
+const regexpTree = require('..');
 
 function re(regexp) {
   return regexpTree.parse(regexp.toString());
diff --git a/src/parser/__tests__/parser-locations-test.js b/src/parser/__tests__/parser-locations-test.js
index cb6608d..f6f4475 100644
--- a/src/parser/__tests__/parser-locations-test.js
+++ b/src/parser/__tests__/parser-locations-test.js
@@ -3,7 +3,7 @@
  * Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
  */
 
-const regexpTree = require('../index');
+const regexpTree = require('..');
 
 regexpTree.setOptions({captureLocations: true});
 
diff --git a/src/parser/__tests__/parser-test262-test.js b/src/parser/__tests__/parser-test262-test.js
index 4206e26..fddd9cb 100644
--- a/src/parser/__tests__/parser-test262-test.js
+++ b/src/parser/__tests__/parser-test262-test.js
@@ -6,7 +6,7 @@
 // Below are the RegExp tests defined by `test262` suite:
 // https://github.com/tc39/test262/tree/master/test/built-ins/RegExp/
 
-const regexpTree = require('../index');
+const regexpTree = require('..');
 
 function re(regexp) {
   return regexpTree.parse(regexp.toString());
diff --git a/src/traverse/__tests__/traverse-basic-test.js b/src/traverse/__tests__/traverse-basic-test.js
index ff80539..add4262 100644
--- a/src/traverse/__tests__/traverse-basic-test.js
+++ b/src/traverse/__tests__/traverse-basic-test.js
@@ -3,7 +3,7 @@
  * Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
  */
 
-const traverse = require('../index');
+const traverse = require('..');
 const parser = require('../../parser');
 
 const defaultAst = parser.parse('/[a-z]+a/i');