Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode + Calva + nRepl - typing * causes SyntaxError in nbb #288

Closed
davidyang opened this issue Dec 14, 2022 · 5 comments
Closed

VSCode + Calva + nRepl - typing * causes SyntaxError in nbb #288

davidyang opened this issue Dec 14, 2022 · 5 comments

Comments

@davidyang
Copy link

[ To keep development of this project going, consider sponsoring. If you are
already a sponsor, thank you! ]

version

nbb v1.1.151

platform

MacOS 13
Node 16.15.0

problem

  • Start a nbb script
  • Start a nREPL server
  • Connect from VSCode Calva
  • Type *

I get this error in the console:

SyntaxError: Invalid regular expression: /*/: Nothing to repeat
    at new RegExp (<anonymous>)
    at Object.$APP.xj (file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:150:174)
    at file:///Users/davidtest/node_modules/nbb/lib/nbb_api.js:15:492
    at file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:974:214
    at file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:974:227
    at Nf (file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:92:145)
    at $APP.Mf.$APP.l.ea (file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:905:22)
    at Object.$APP.w (file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:67:94)
    at file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:917:70
    at Nf (file:///Users/davidtest/node_modules/nbb/lib/nbb_core.js:92:145)

repro

This file as test.cljs works for me to reproduce the error whenever I type *

(ns test
  (:require  [nbb.nrepl-server :as nrepl]))

(nrepl/start-server! {:port 1337})

*

expected behavior

No syntax error.

@borkdude
Copy link
Collaborator

Hi @davidyang - I have problems reproducing this with Calva and nbb (1.1.151). Maybe I'm missing something?

Screenshot 2022-12-14 at 16 06 46

@davidyang
Copy link
Author

davidyang commented Dec 14, 2022 via email

@borkdude
Copy link
Collaborator

OK, the culprit is likely here:

(let [pat (re-pattern query)]

which can be reproduced using:

cljs.user=> (re-pattern "*")
Execution error (SyntaxError) at (<cljs repl>:1).
Invalid regular expression: nothing to repeat

which can be fixed like this:

cljs.user=> (re-pattern (str/replace "*" #"[.*+?^${}()|[\]\\]" "\\$&"))
#"\*"
cljs.user=> (re-find (re-pattern (str/replace "*" #"[.*+?^${}()|[\]\\]" "\\$&")) "foo*foo")

(cf https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex)

@borkdude
Copy link
Collaborator

Thanks for the issue. Now publishing 1.1.152.

@davidyang
Copy link
Author

davidyang commented Dec 14, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants