sterpe / coffee-fmt

gofmt for coffee
MIT License
9 stars 4 forks source link

Infinite loop when processing SPECIAL_SYMBOL #16

Open Glavin001 opened 9 years ago

Glavin001 commented 9 years ago

I think it has something to do with RegExp shorthand. Here's the applicable portion of the debug logs:

087         return /^win/.test(process.platform)
>>> WHITESPACE      line=087, pos= 0, text=" "
>>> WHITESPACE      line=087, pos= 1, text=" "
>>> WHITESPACE      line=087, pos= 2, text=" "
>>> WHITESPACE      line=087, pos= 3, text=" "
>>> WHITESPACE      line=087, pos= 4, text=" "
>>> WHITESPACE      line=087, pos= 5, text=" "
>>> WHITESPACE      line=087, pos= 6, text=" "
>>> WHITESPACE      line=087, pos= 7, text=" "
>>> IDENTIFIER      line=087, pos= 8, text="return"
>>>                 value=return
>>> WHITESPACE      line=087, pos=14, text=" "
>>> SPECIAL_SYMBOL  line=087, pos=15, text="/"
>>>                 value=/
>>> SPECIAL_SYMBOL  line=087, pos=16, text=""
>>>                 value=
>>> SPECIAL_SYMBOL  line=087, pos=16, text=""
>>>                 value=
>>> SPECIAL_SYMBOL  line=087, pos=16, text=""
>>>                 value=

Note that

>>> SPECIAL_SYMBOL  line=087, pos=16, text=""
>>>                 value=

Now repeats infinitely.

I changed

return /^win/.test(process.platform)

to

        return new RegExp('^win').test(process.platform)

and things worked again.

Glavin001 commented 9 years ago

However, I have to say...

Great job!!!

I just beautified my entire Atom Beautify source code that was the only bug! I used an experimental feature I am working on, Atom Beautify - Beautify Directory, and was able to beautify all of my files effortlessly with Coffee-fmt + Atom Beautify. We make a great team. Awesome work so far!

Glavin001 commented 9 years ago

Actually I missed a few files. Here's another issue: #17 :stuck_out_tongue_winking_eye:

sterpe commented 9 years ago

Yes think I forgot about regular expressions entirely. Will take a look at this and #17.

nmaggioni commented 8 years ago

Same bug with this line of code:

Date.now() + '-' + file.originalname.replace(/[^0-9A-Za-z\.]+/g, '_').replace(/\.\.+/g, '_')

It hangs at the first square bracket, and I fixed it as @Glavin001 suggested:

Date.now() + '-' + file.originalname.replace(new RegExp('[^0-9A-Za-z\\.]+', 'g'), '_').replace(new RegExp('\\.\\.+', 'g'), '_')
sterpe commented 8 years ago

@nmaggioni

Yes, I forgot to implement regex syntax so the constructor method is okay. I'm pretty busy right now but would gladly accept a PR.

UziTech commented 7 years ago

The problem seems to be with the caret (^) in the regular expression.

It works fine with a regular expression without a caret.