From 79a8fd1e66395dcf70954b8e8fcd4130d1daa629 Mon Sep 17 00:00:00 2001 From: Boom Lee Date: Sat, 15 Feb 2020 12:09:31 +0800 Subject: [PATCH] Fix #17, add test case, release 0.23 (#18) * Fix #17, add test case, release 0.23 * Fix eslint for travis * Tweak travis * Tweak test case --- .eslintrc | 5 +---- .travis.yml | 7 ++++--- README.md | 2 +- lib/Builder.js | 5 ++++- package.json | 4 +++- test/issue-17-test.js | 16 ++++++++++++++++ 6 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 test/issue-17-test.js diff --git a/.eslintrc b/.eslintrc index 2052e44..1d0a4a1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,5 @@ { - "ecmaFeatures": { - "modules": true - }, - "env": { + "env": { "node": true, "es6": true, "mocha": true diff --git a/.travis.yml b/.travis.yml index 138cf6d..ec02ede 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,15 @@ language: node_js node_js: - - "6" + - 8 + - 10 + - 12 cache: - node_modules install: - npm install - - npm install -g eslint - npm install -g codecov script: - - eslint . + - npm run lint - istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec - codecov diff --git a/README.md b/README.md index 4e67cfb..e57f4b1 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ query .get() // /[a-z]{3}[0-9]*$/g ``` -Required Node 6.0+ for the ES6 support, Or you can use [Babel](http://babeljs.io/) to support Node below 6.0. +Required Node 8.0+ for the ES6 support, Or you can use [Babel](http://babeljs.io/) to support Node below 6.0. Using [Webpack](http://webpack.github.io) and [babel-loader](https://github.com/babel/babel-loader) to pack it if want to use in browsers. diff --git a/lib/Builder.js b/lib/Builder.js index 5e5d483..96398ad 100644 --- a/lib/Builder.js +++ b/lib/Builder.js @@ -215,7 +215,7 @@ class Builder { noDigit() { this._validateAndAddMethodType(METHOD_TYPE_CHARACTER, METHOD_TYPES_ALLOWED_FOR_CHARACTERS) - return this.add(`[^0-9]`) + return this.add('[^0-9]') } /** @@ -761,6 +761,9 @@ class Builder { _mapCaptureIndexToName(result) { const names = this._captureNames + // No match + if (!result) {return null} + return Array.prototype.reduce.call(result.slice(1), (result, current, index) => { if (names[index]) { result[names[index]] = current || '' diff --git a/package.json b/package.json index bd24ba3..cbac627 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "srl", - "version": "0.2.2", + "version": "0.2.3", "description": "Simple Regex Language", "main": "lib/SRL.js", "scripts": { "test": "mocha", + "lint": "eslint lib --fix", "coverage": "istanbul cover _mocha" }, "repository": { @@ -30,6 +31,7 @@ }, "homepage": "https://simple-regex.com", "devDependencies": { + "eslint": "^6.8.0", "istanbul": "^0.4.5", "mocha": "^3.0.2", "mocha-lcov-reporter": "^1.2.0" diff --git a/test/issue-17-test.js b/test/issue-17-test.js new file mode 100644 index 0000000..2a30be1 --- /dev/null +++ b/test/issue-17-test.js @@ -0,0 +1,16 @@ +'use strict' + +const assert = require('assert') +const SRL = require('../') + +describe('Fix issue 17', () => { + it('Capture group name assignment fails', () => { + assert.doesNotThrow(() => { + const query = new SRL('capture (literally "TEST") as test') + const match = query.getMatch('WORD NOT HERE') + assert.equal(match, null) + }, TypeError) + }) +}) + +