[Pkg-javascript-commits] [node-character-parser] 02/08: Imported Upstream version 1.2.1

Leo Iannacone l3on-guest at moszumanska.debian.org
Sat Oct 11 16:07:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

l3on-guest pushed a commit to branch master
in repository node-character-parser.

commit 33f48500247943826f387fb42b26565108331d15
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Sat Oct 11 17:50:06 2014 +0200

    Imported Upstream version 1.2.1
---
 README.md     |  2 +-
 index.js      | 14 ++++++++++++++
 package.json  |  2 +-
 test/index.js | 14 +++++++++++++-
 4 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index b530291..02a0b99 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 
 Parse JavaScript one character at a time to look for snippets in Templates.  This is not a validator, it's just designed to allow you to have sections of JavaScript delimited by brackets robustly.
 
-[![Build Status](https://travis-ci.org/ForbesLindesay/character-parser.png?branch=master)](https://travis-ci.org/ForbesLindesay/character-parser)
+[![Build Status](https://img.shields.io/travis/ForbesLindesay/character-parser/master.svg)](https://travis-ci.org/ForbesLindesay/character-parser)
 
 ## Installation
 
diff --git a/index.js b/index.js
index 8d0f395..271fa28 100644
--- a/index.js
+++ b/index.js
@@ -59,8 +59,17 @@ exports.parseChar = parseChar;
 function parseChar(character, state) {
   if (character.length !== 1) throw new Error('Character must be a string of length 1');
   state = state || exports.defaultState();
+  state.src = state.src || '';
+  state.src += character;
   var wasComment = state.blockComment || state.lineComment;
   var lastChar = state.history ? state.history[0] : '';
+
+  if (state.regexpStart) {
+    if (character === '/' || character == '*') {
+      state.regexp = false;
+    }
+    state.regexpStart = false;
+  }
   if (state.lineComment) {
     if (character === '\n') {
       state.lineComment = false;
@@ -101,6 +110,7 @@ function parseChar(character, state) {
     state.blockComment = true;
   } else if (character === '/' && isRegexp(state.history)) {
     state.regexp = true;
+    state.regexpStart = true;
   } else if (character === '\'') {
     state.singleQuote = true;
   } else if (character === '"') {
@@ -119,6 +129,7 @@ function parseChar(character, state) {
     state.squareDepth--;
   }
   if (!state.blockComment && !state.lineComment && !wasComment) state.history = character + state.history;
+  state.lastChar = character; // store last character for ending block comments
   return state;
 }
 
@@ -130,6 +141,7 @@ function State() {
   this.singleQuote = false;
   this.doubleQuote = false;
   this.regexp = false;
+
   this.escaped = false;
 
   this.roundDepth = 0;
@@ -137,6 +149,7 @@ function State() {
   this.squareDepth = 0;
 
   this.history = ''
+  this.lastChar = ''
 }
 State.prototype.isString = function () {
   return this.singleQuote || this.doubleQuote;
@@ -154,6 +167,7 @@ function startsWith(str, start, i) {
 
 exports.isPunctuator = isPunctuator
 function isPunctuator(c) {
+  if (!c) return true; // the start of a string is a punctuator
   var code = c.charCodeAt(0)
 
   switch (code) {
diff --git a/package.json b/package.json
index dc7bb9c..bbdbc7a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "character-parser",
-  "version": "1.2.0",
+  "version": "1.2.1",
   "description": "Parse JavaScript one character at a time to look for snippets in Templates.  This is not a validator, it's just designed to allow you to have sections of JavaScript delimited by brackets robustly.",
   "main": "index.js",
   "scripts": {
diff --git a/test/index.js b/test/index.js
index 3860427..4b561d7 100644
--- a/test/index.js
+++ b/test/index.js
@@ -52,4 +52,16 @@ describe('regressions', function () {
       assert(section.src = 'foo = typeof /\\//g, bar="}"');
     })
   })
-})
\ No newline at end of file
+  describe('#6', function () {
+    it('parses block comments', function () {
+      var section = parser.parseMax('/* ) */) bing bong');
+      assert(section.start === 0);
+      assert(section.end === 7);//exclusive end of string
+      assert(section.src = '/* ) */)');
+      var section = parser.parseMax('/* /) */) bing bong');
+      assert(section.start === 0);
+      assert(section.end === 8);//exclusive end of string
+      assert(section.src = '/* ) */)');
+    })
+  })
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-character-parser.git



More information about the Pkg-javascript-commits mailing list