Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fix dist] 0.6.0

fixes #3
minor jshint adjustments
  • Loading branch information...
commit 58b4294f76816b05fcb11e480d03e2dbe88bfe43 1 parent c5570c1
@dscape authored
Showing with 29 additions and 12 deletions.
  1. +18 −11 clarinet.js
  2. +1 −1  package.json
  3. +10 −0 test/clarinet.js
View
29 clarinet.js
@@ -123,7 +123,7 @@ if(typeof FastList === 'function') {
}
}
- var stringTokenPattern = /[\\"\n]/g
+ var stringTokenPattern = /[\\"\n]/g;
function CParser (opt) {
if (!(this instanceof CParser)) return new CParser (opt);
@@ -226,13 +226,15 @@ if(typeof FastList === 'function') {
}
function emitNode(parser, event, data) {
- if (parser.textNode) closeValue(parser);
+ closeValue(parser);
emit(parser, event, data);
}
function closeValue(parser, event) {
parser.textNode = textopts(parser.opt, parser.textNode);
- if (parser.textNode) emit(parser, (event ? event : "onvalue"), parser.textNode);
+ if (parser.textNode) {
+ emit(parser, (event ? event : "onvalue"), parser.textNode);
+ }
parser.textNode = "";
}
@@ -413,6 +415,9 @@ if(typeof FastList === 'function') {
if (c === '"' && !slashed) {
parser.state = parser.stack.pop() || S.VALUE;
parser.textNode += chunk.substring(starti, i-1);
+ if(!parser.textNode) {
+ emit(parser, "onvalue", "");
+ }
break;
}
if (c === '\\' && !slashed) {
@@ -423,25 +428,27 @@ if(typeof FastList === 'function') {
}
if (slashed) {
slashed = false;
- if (c === 'n') parser.textNode += '\n'
- else if (c === 'r') parser.textNode += '\r'
- else if (c === 't') parser.textNode += '\t'
- else if (c === 'f') parser.textNode += '\f'
- else if (c === 'b') parser.textNode += '\b'
+ if (c === 'n') { parser.textNode += '\n'; }
+ else if (c === 'r') { parser.textNode += '\r'; }
+ else if (c === 't') { parser.textNode += '\t'; }
+ else if (c === 'f') { parser.textNode += '\f'; }
+ else if (c === 'b') { parser.textNode += '\b'; }
else if (c === 'u') {
// \uxxxx. meh!
unicodeI = 1;
parser.unicodeS = '';
- } else parser.textNode += c
+ } else {
+ parser.textNode += c;
+ }
c = chunk.charAt(i++);
starti = i-1;
if (!c) break;
else continue;
}
- stringTokenPattern.lastIndex = i
+ stringTokenPattern.lastIndex = i;
var reResult = stringTokenPattern.exec(chunk);
- if (reResult == null) {
+ if (reResult === null) {
i = chunk.length+1;
parser.textNode += chunk.substring(starti, i-1);
break;
View
2  package.json
@@ -6,7 +6,7 @@
[ "Jann Horn (https://github.com/thejh)"
, "Justin Makeig <jmpublic+github@makeig.com> (http://www.audiblepop.com)"
]
-, "version" : "0.5.8"
+, "version" : "0.6.0"
, "main" : "./clarinet.js"
, "homepage" : "https://github.com/dscape/clarinet"
, "repository" :
View
10 test/clarinet.js
@@ -42,6 +42,16 @@ var seps = [undefined, /\t|\n|\r/, '']
, ['ready' , undefined]
]
}
+ , empty_value :
+ { text : '{"foo": ""}'
+ , events :
+ [ ["openobject" , "foo"]
+ , ["value" , ""]
+ , ["closeobject" , undefined]
+ , ['end' , undefined]
+ , ['ready' , undefined]
+ ]
+ }
, three_byte_utf8 :
{ text : '{"matzue": "松江", "asakusa": "浅草"}'
, events :
Please sign in to comment.
Something went wrong with that request. Please try again.