Comparing version 1.6.0 to 1.6.1
@@ -1,3 +0,3 @@ | ||
const EOL = require('os').EOL; | ||
const utils = require('./utils'); | ||
const {EOL} = require('os'); | ||
const {addInspection, messageGap} = require('./utils'); | ||
@@ -23,3 +23,3 @@ const parsingErrorCode = { | ||
const err = errorMessages[code].message; | ||
const message = 'Error parsing SQL at {line:' + position.line + ',col:' + position.column + '}: ' + err; | ||
const message = `Error parsing SQL at {line:${position.line},col:${position.column}}: ${err}`; | ||
super(message); | ||
@@ -36,9 +36,9 @@ this.name = this.constructor.name; | ||
level = level > 0 ? parseInt(level) : 0; | ||
const gap = utils.messageGap(level + 1); | ||
const gap = messageGap(level + 1); | ||
const lines = [ | ||
'SQLParsingError {', | ||
gap + 'code: parsingErrorCode.' + errorMessages[this.code].name, | ||
gap + 'error: "' + this.error + '"', | ||
gap + 'position: {line: ' + this.position.line + ', col: ' + this.position.column + '}', | ||
utils.messageGap(level) + '}' | ||
`SQLParsingError {`, | ||
`${gap}code: parsingErrorCode.${errorMessages[this.code].name}`, | ||
`${gap}error: "${this.error}"`, | ||
`${gap}position: {line: ${this.position.line}, col: ${this.position.column}}`, | ||
`${messageGap(level)}}` | ||
]; | ||
@@ -48,3 +48,3 @@ return lines.join(EOL); | ||
utils.addInspection(SQLParsingError.prototype, function () { | ||
addInspection(SQLParsingError.prototype, function () { | ||
return this.toString(); | ||
@@ -51,0 +51,0 @@ }); |
@@ -1,6 +0,4 @@ | ||
const errorLib = require('./error'); | ||
const utils = require('./utils'); | ||
const {parsingErrorCode, SQLParsingError} = require('./error'); | ||
const {getIndexPos} = require('./utils'); | ||
const PEC = errorLib.parsingErrorCode; | ||
// symbols that need no spaces around them: | ||
@@ -36,3 +34,3 @@ const compressors = '.,;:()[]=<>+-*/|!?@#'; | ||
if (isGap(s)) { | ||
while (++idx < len && isGap(sql[idx])); | ||
while (++idx < len && isGap(sql[idx])) ; | ||
if (idx < len) { | ||
@@ -72,3 +70,3 @@ space = true; | ||
idx = lastOpen; | ||
throwError(PEC.unclosedMLC); | ||
throwError(parsingErrorCode.unclosedMLC); | ||
} | ||
@@ -93,7 +91,7 @@ if (sql[idx + 2] === '!' && !options.removeAll) { | ||
if (closeIdx < 0) { | ||
throwError(PEC.unclosedQI); | ||
throwError(parsingErrorCode.unclosedQI); | ||
} | ||
text = sql.substring(idx, closeIdx + 1); | ||
if (text.indexOf('\n') > 0) { | ||
throwError(PEC.multiLineQI); | ||
throwError(parsingErrorCode.multiLineQI); | ||
} | ||
@@ -110,12 +108,12 @@ if (options.compress) { | ||
if (s === '\'') { | ||
if (s === `'`) { | ||
closeIdx = idx; | ||
do { | ||
closeIdx = sql.indexOf('\'', closeIdx + 1); | ||
closeIdx = sql.indexOf(`'`, closeIdx + 1); | ||
if (closeIdx > 0) { | ||
let i = closeIdx; | ||
while (sql[--i] === '\\'); | ||
while (sql[--i] === '\\') ; | ||
if ((closeIdx - i) % 2) { | ||
let step = closeIdx; | ||
while (++step < len && sql[step] === '\''); | ||
while (++step < len && sql[step] === `'`) ; | ||
if ((step - closeIdx) % 2) { | ||
@@ -130,3 +128,3 @@ closeIdx = step - 1; | ||
if (closeIdx < 0) { | ||
throwError(PEC.unclosedText); | ||
throwError(parsingErrorCode.unclosedText); | ||
} | ||
@@ -178,3 +176,3 @@ if (options.compress) { | ||
if (options.compress) { | ||
while (idx < len - 1 && isGap(sql[idx + 1]) && idx++); | ||
while (idx < len - 1 && isGap(sql[idx + 1]) && idx++) ; | ||
} | ||
@@ -193,4 +191,4 @@ } | ||
function throwError(code) { | ||
const position = utils.getIndexPos(sql, idx); | ||
throw new errorLib.SQLParsingError(code, position); | ||
const position = getIndexPos(sql, idx); | ||
throw new SQLParsingError(code, position); | ||
} | ||
@@ -197,0 +195,0 @@ } |
@@ -1,5 +0,5 @@ | ||
const util = require('util'); | ||
const {inspect} = require('util'); | ||
/////////////////////////////////////////////////////// | ||
// Returns {line, column} of an index within the text. | ||
///////////////////////////////////////////////////////////// | ||
// Returns {line, column} of an index within multi-line text. | ||
function getIndexPos(text, index) { | ||
@@ -13,3 +13,3 @@ let lineIdx = 0, colIdx = index, pos = 0; | ||
lineIdx++; | ||
pos += 1; | ||
pos++; | ||
colIdx = index - pos; | ||
@@ -32,3 +32,3 @@ } while (pos < index); | ||
function addInspection(type, cb) { | ||
type[util.inspect.custom] = cb; | ||
type[inspect.custom] = cb; | ||
} | ||
@@ -35,0 +35,0 @@ |
{ | ||
"name": "pg-minify", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "Minifies PostgreSQL scripts.", | ||
@@ -46,7 +46,7 @@ "main": "lib/index.js", | ||
"coveralls": "3.1.0", | ||
"eslint": "7.0.0", | ||
"eslint": "7.1.0", | ||
"istanbul": "0.4.5", | ||
"jasmine-node": "3.0.0", | ||
"typescript": "3.8.3" | ||
"typescript": "3.9.3" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14568
286