btford/ngmin

Fails on certain regex string.

rhys-vdw opened this issue · 7 comments

The following code:

  }).filter('formatPhoneNumber', function() {
    return function(phoneNumber) {
      return phoneNumber.replace(/[()- ]/gi, '');
    };

Causes ng-min to shit itself with the following stacktrace.

sprima.js:3062:20)
  at parseSourceElements (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/ngmin/node_modules/esprima/esprima.js:3095:29)
  at parseProgram (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/ngmin/node_modules/esprima/esprima.js:3109:19)
  at /Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/ngmin/node_modules/esprima/esprima.js:3609:38
  at Object.parse (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/ngmin/node_modules/esprima/esprima.js:3856:23)
  at Object.exports.annotate (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/ngmin/main.js:16:21)
  at Transform._transform (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/index.js:19:37)
  at Transform._read (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:184:10)
  at Transform._write (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:12)
  at doWrite (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:238:10)
  at writeOrBuffer (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:228:5)
  at Transform.Writable.write (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ngmin/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:195:11)
  at Stream.ondata (stream.js:51:26)
  at Stream.EventEmitter.emit (events.js:95:17)
  at Stream.modifyFile (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-coffee/index.js:52:10)
  at Stream.stream.write (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-coffee/node_modules/event-stream/node_modules/through/index.js:26:11)
  at Stream.ondata (stream.js:51:26)
  at Stream.EventEmitter.emit (events.js:95:17)
  at queueData (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:43:21)
  at next (/Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:71:7)
  at /Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp/node_modules/vinyl-fs/node_modules/map-stream/index.js:85:7
  at /Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp/node_modules/vinyl-fs/lib/src/bufferFile.js:8:5
  at fs.js:266:14
  at /Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp-ruby-sass/node_modules/temp-write/node_modules/graceful-fs/graceful-fs.js:104:5
  at /Users/rhysvanderwaerden/Projects/hummingbird/hummingbird-frontend/node_modules/gulp/node_modules/vinyl-fs/node_modules/graceful-fs/graceful-fs.js:104:5
  at Object.oncomplete (fs.js:107:15)

Removing the space in the regex string fixes the problem.

I'm using gulp-ngmin 0.3.0, and ng-min 0.5.0.

Try using ng-annotate and if that doesn't work then file an issue there

Is ng-min deprecated now?

olov commented
~/projects/ng-annotate % ng-annotate -a issue99.js
error: couldn't process source due to parse error
Line 1: Invalid regular expression

Change your regexp to [()\- ]/gi and it works fine.

Ah yeah, cheers, but fixing it is not a problem. It's more problematic that
it crashes ng-min. If I had made more than one change before saving I would
have been mighty confused!

On 2 July 2014 17:59, Olov Lassus notifications@github.com wrote:

~/projects/ng-annotate % ng-annotate -a issue99.js
error: couldn't process source due to parse error
Line 1: Invalid regular expression

Change your regexp to [()- ]/gi and it works fine.


Reply to this email directly or view it on GitHub
#99 (comment).

olov commented

Sure. Feel free to try out ng-annotate. As you can see in my previous comment it gives you a friendly error message on your broken regexp. (To be fair, Esprima does). If it gives you any problem then file an issue and we'll fix it.

For more info on ng-annotate and ngmin, see The future of ngmin and ng-annotate.

@rhys-vdw You can consider ng-min deprecated. As soon as I get time I am going to implement the changes in that issue @olov linked you to

Thanks guys. I'll switch over to ng-annotate before I go live and raise any
relevant issues there.

On 3 July 2014 03:30, Eddie Monge notifications@github.com wrote:

Closed #99 #99.


Reply to this email directly or view it on GitHub
#99 (comment).