Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
commenting: use full variable path
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 13, 2018
1 parent 7ff2785 commit 1ae4de5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions lib/es5/index.js
Expand Up @@ -300,7 +300,6 @@ function (_Transform) {
rawBuffer = _this$state.rawBuffer,
escapeIsQuote = _this$state.escapeIsQuote,
trimChars = _this$state.trimChars;
var commenting = this.state.commenting;
var buf;

if (previousBuf === undefined && nextBuf !== undefined) {
Expand Down Expand Up @@ -374,7 +373,7 @@ function (_Transform) {
// TODO: need to compare bytes instead of single char


if (commenting === false && chr === quote) {
if (this.state.commenting === false && chr === quote) {
if (this.state.quoting === true) {
var nextChr = buf[pos + 1];

Expand Down Expand Up @@ -423,7 +422,7 @@ function (_Transform) {
if (this.state.quoting === false) {
if (recordDelimiterLength !== 0) {
// Do not emit comments which take a full line
var skipCommentLine = commenting && this.state.record.length === 0 && this.state.field.length === 0;
var skipCommentLine = this.state.commenting && this.state.record.length === 0 && this.state.field.length === 0;

if (skipCommentLine) {
// TODO: update the doc, a line with comment is considered an
Expand Down Expand Up @@ -460,12 +459,12 @@ function (_Transform) {
}
}

this.state.commenting = commenting = false;
this.state.commenting = false;
pos += recordDelimiterLength - 1;
continue;
}

if (commenting) {
if (this.state.commenting) {
continue;
}

Expand All @@ -476,7 +475,7 @@ function (_Transform) {
this.info.comment_lines++;
}

this.state.commenting = commenting = true;
this.state.commenting = true;
continue;
}

Expand All @@ -492,7 +491,7 @@ function (_Transform) {
}
}

if (commenting === false && max_record_size !== 0) {
if (this.state.commenting === false && max_record_size !== 0) {
if (this.state.record_length + this.state.field.length > max_record_size) {
var _err2 = this.__error("Max Record Size: record exceed the maximum number of tolerated bytes of ".concat(max_record_size, " on line ").concat(this.info.lines));

Expand Down
13 changes: 6 additions & 7 deletions lib/index.js
Expand Up @@ -202,7 +202,6 @@ class Parser extends Transform {
const {comment, escape, from, from_line, ltrim, max_record_size, quote, raw, relax, rtrim, skip_empty_lines, to, to_line} = this.options
let {record_delimiter} = this.options
const {previousBuf, rawBuffer, escapeIsQuote, trimChars} = this.state
let {commenting} = this.state
let buf
if(previousBuf === undefined && nextBuf !== undefined){
buf = nextBuf
Expand Down Expand Up @@ -264,7 +263,7 @@ class Parser extends Transform {
}
// Not currently escaping and chr is a quote
// TODO: need to compare bytes instead of single char
if(commenting === false && chr === quote){
if(this.state.commenting === false && chr === quote){
if(this.state.quoting === true){
const nextChr = buf[pos+1]
const isNextChrTrimable = rtrim && this.__isCharTrimable(nextChr)
Expand Down Expand Up @@ -306,7 +305,7 @@ class Parser extends Transform {
if(this.state.quoting === false){
if(recordDelimiterLength !== 0){
// Do not emit comments which take a full line
const skipCommentLine = commenting && (this.state.record.length === 0 && this.state.field.length === 0)
const skipCommentLine = this.state.commenting && (this.state.record.length === 0 && this.state.field.length === 0)
if(skipCommentLine){
// TODO: update the doc, a line with comment is considered an
// empty line in the sense that no record is found inside
Expand All @@ -333,19 +332,19 @@ class Parser extends Transform {
return
}
}
this.state.commenting = commenting = false
this.state.commenting = false
pos += recordDelimiterLength - 1
continue
}
if(commenting){
if(this.state.commenting){
continue
}
const commentCount = comment === null ? 0 : this.__compareBytes(comment, buf, pos, chr)
if(commentCount !== 0){
if(this.state.record.length === 0 && this.state.field.length === 0 && this.state.wasQuoting === false){
this.info.comment_lines++
}
this.state.commenting = commenting = true
this.state.commenting = true
continue
}
let delimiterLength = this.__isDelimiter(chr, buf, pos)
Expand All @@ -357,7 +356,7 @@ class Parser extends Transform {
}
}
}
if(commenting === false && max_record_size !== 0){
if(this.state.commenting === false && max_record_size !== 0){
if(this.state.record_length + this.state.field.length > max_record_size){
const err = this.__error(`Max Record Size: record exceed the maximum number of tolerated bytes of ${max_record_size} on line ${this.info.lines}`)
if(err !== undefined) return err
Expand Down

0 comments on commit 1ae4de5

Please sign in to comment.