Comparing version 2.1.2 to 2.2.0
# Tippex changelog | ||
## 2.2.0 | ||
* Include `default` among keywords that signal `/` should be treated as start of regex literal ([#1](https://github.com/Rich-Harris/tippex/issues/1)) | ||
* More informative error message than 'state is not a function' | ||
## 2.1.2 | ||
@@ -4,0 +9,0 @@ |
@@ -1,2 +0,20 @@ | ||
var keywords = /(case|delete|do|else|in|instanceof|new|return|throw|typeof|void)\s*$/; | ||
function getLocation ( source, charIndex ) { | ||
var lines = source.split( '\n' ); | ||
var len = lines.length; | ||
for ( var i = 0, lineStart = 0; i < len; i += 1 ) { | ||
var line = lines[i]; | ||
var lineEnd = lineStart + line.length + 1; // +1 for newline | ||
if ( lineEnd > charIndex ) { | ||
return { line: i + 1, column: charIndex - lineStart }; | ||
} | ||
lineStart = lineEnd; | ||
} | ||
throw new Error( ("Could not determine location of character " + charIndex) ); | ||
} | ||
var keywords = /(case|default|delete|do|else|in|instanceof|new|return|throw|typeof|void)\s*$/; | ||
var punctuators = /(^|\{|\(|\[\.|;|,|<|>|<=|>=|==|!=|===|!==|\+|-|\*\%|<<|>>|>>>|&|\||\^|!|~|&&|\|\||\?|:|=|\+=|-=|\*=|%=|<<=|>>=|>>>=|&=|\|=|\^=|\/=|\/)\s*$/; | ||
@@ -154,2 +172,14 @@ var ambiguous = /(\}|\)|\+\+|--)\s*$/; | ||
for ( var i = 0; i < str.length; i += 1 ) { | ||
if ( !state ) { | ||
var ref = getLocation( str, i ), line = ref.line, column = ref.column; | ||
var before = str.slice( 0, i ); | ||
var beforeLine = /(^|\n).+$/.exec( before )[0]; | ||
var after = str.slice( i ); | ||
var afterLine = /.+(\n|$)/.exec( after )[0]; | ||
var snippet = "" + beforeLine + afterLine + "\n" + (Array( beforeLine.length + 1 ).join( ' ' )) + "^"; | ||
throw new Error( ("Unexpected character (" + line + ":" + column + "). If this is valid JavaScript, it's probably a bug in tippex. Please raise an issue at https://github.com/Rich-Harris/tippex/issues – thanks!\n\n" + snippet) ); | ||
} | ||
state = state( str[i], i ); | ||
@@ -156,0 +186,0 @@ } |
@@ -7,3 +7,21 @@ (function (global, factory) { | ||
var keywords = /(case|delete|do|else|in|instanceof|new|return|throw|typeof|void)\s*$/; | ||
function getLocation ( source, charIndex ) { | ||
var lines = source.split( '\n' ); | ||
var len = lines.length; | ||
for ( var i = 0, lineStart = 0; i < len; i += 1 ) { | ||
var line = lines[i]; | ||
var lineEnd = lineStart + line.length + 1; // +1 for newline | ||
if ( lineEnd > charIndex ) { | ||
return { line: i + 1, column: charIndex - lineStart }; | ||
} | ||
lineStart = lineEnd; | ||
} | ||
throw new Error( ("Could not determine location of character " + charIndex) ); | ||
} | ||
var keywords = /(case|default|delete|do|else|in|instanceof|new|return|throw|typeof|void)\s*$/; | ||
var punctuators = /(^|\{|\(|\[\.|;|,|<|>|<=|>=|==|!=|===|!==|\+|-|\*\%|<<|>>|>>>|&|\||\^|!|~|&&|\|\||\?|:|=|\+=|-=|\*=|%=|<<=|>>=|>>>=|&=|\|=|\^=|\/=|\/)\s*$/; | ||
@@ -161,2 +179,14 @@ var ambiguous = /(\}|\)|\+\+|--)\s*$/; | ||
for ( var i = 0; i < str.length; i += 1 ) { | ||
if ( !state ) { | ||
var ref = getLocation( str, i ), line = ref.line, column = ref.column; | ||
var before = str.slice( 0, i ); | ||
var beforeLine = /(^|\n).+$/.exec( before )[0]; | ||
var after = str.slice( i ); | ||
var afterLine = /.+(\n|$)/.exec( after )[0]; | ||
var snippet = "" + beforeLine + afterLine + "\n" + (Array( beforeLine.length + 1 ).join( ' ' )) + "^"; | ||
throw new Error( ("Unexpected character (" + line + ":" + column + "). If this is valid JavaScript, it's probably a bug in tippex. Please raise an issue at https://github.com/Rich-Harris/tippex/issues – thanks!\n\n" + snippet) ); | ||
} | ||
state = state( str[i], i ); | ||
@@ -163,0 +193,0 @@ } |
{ | ||
"name": "tippex", | ||
"description": "Find and erase strings and comments in JavaScript code", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"author": "Rich Harris", | ||
@@ -29,5 +29,5 @@ "main": "dist/tippex.umd.js", | ||
"rollup": "^0.25.8", | ||
"rollup-plugin-buble": "^0.5.0", | ||
"rollup-plugin-buble": "^0.6.0", | ||
"source-map-support": "^0.4.0" | ||
} | ||
} |
@@ -1,2 +0,4 @@ | ||
const keywords = /(case|delete|do|else|in|instanceof|new|return|throw|typeof|void)\s*$/; | ||
import getLocation from './getLocation.js'; | ||
const keywords = /(case|default|delete|do|else|in|instanceof|new|return|throw|typeof|void)\s*$/; | ||
const punctuators = /(^|\{|\(|\[\.|;|,|<|>|<=|>=|==|!=|===|!==|\+|-|\*\%|<<|>>|>>>|&|\||\^|!|~|&&|\|\||\?|:|=|\+=|-=|\*=|%=|<<=|>>=|>>>=|&=|\|=|\^=|\/=|\/)\s*$/; | ||
@@ -154,2 +156,14 @@ const ambiguous = /(\}|\)|\+\+|--)\s*$/; | ||
for ( let i = 0; i < str.length; i += 1 ) { | ||
if ( !state ) { | ||
const { line, column } = getLocation( str, i ); | ||
const before = str.slice( 0, i ); | ||
const beforeLine = /(^|\n).+$/.exec( before )[0]; | ||
const after = str.slice( i ); | ||
const afterLine = /.+(\n|$)/.exec( after )[0]; | ||
const snippet = `${beforeLine}${afterLine}\n${ Array( beforeLine.length + 1 ).join( ' ' )}^`; | ||
throw new Error( `Unexpected character (${line}:${column}). If this is valid JavaScript, it's probably a bug in tippex. Please raise an issue at https://github.com/Rich-Harris/tippex/issues – thanks!\n\n${snippet}` ); | ||
} | ||
state = state( str[i], i ); | ||
@@ -156,0 +170,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
72180
10
747