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

Syntax error compiling with figwheel #58

Open
2food opened this issue Mar 15, 2019 · 4 comments
Open

Syntax error compiling with figwheel #58

2food opened this issue Mar 15, 2019 · 4 comments

Comments

@2food
Copy link

2food commented Mar 15, 2019

When using camel-snake-kebab in clojurescript, running fighweel and tests at the same time i get this error:

Error refreshing environment: Syntax error compiling at (camel_snake_kebab/core.cljc:16:1).

The line specified is the first line where a conversion is defined with the defconversion macro from camel-snake-kebab.macros:

(defconversion "PascalCase"           clojure.string/capitalize clojure.string/capitalize "")

I don't know the exact reason for why this fails, but it has something to do with the conversion functions being defined with a macro. Redefining the conversion functions with defn and not requiring camel-snake-kebab-core solves the issue for me:

(ns my-conversions
  (:require [camel-snake-kebab.internals.misc :as csk-misc]
            [camel-snake-kebab.extras :as cks-extras]
            [camel-snake-kebab.internals.alter-name :refer [alter-name]]
            [clojure.string :as string]))


(defn convert-case
  [first-fn rest-fn sep s]
  (alter-name s (partial csk-misc/convert-case first-fn rest-fn sep)))

(defn ->PascalCase [x] (convert-case string/capitalize string/capitalize "" x))
(defn ->Camel_Snake_Case [x] (convert-case string/capitalize string/capitalize "_" x))
(defn ->camelCase [x] (convert-case string/lower-case string/capitalize "" x))
(defn ->SCREAMING_SNAKE_CASE [x] (convert-case string/upper-case string/upper-case "_" x))
(defn ->snake_case [x] (convert-case string/lower-case string/lower-case "_" x))
(defn ->kebab-case [x] (convert-case string/lower-case string/lower-case "-" x))
(defn ->HTTP-Header-Case [x] (convert-case csk-misc/capitalize-http-header csk-misc/capitalize-http-header "_" x))

All of these are type preserving, but I don't see the need for defining explicit type converting functions like ->kebab-case-keyword when you can just do (comp keyword ->kebab-case)?

As far as I can tell this works the same as when using defconversion, I might be missing something here though so please correct me if I'm wrong.

@Luke1298
Copy link

+1

@marianboda
Copy link

marianboda commented Jul 7, 2021

I'm running into the same problem with tools.namespace/refresh. If I remove this lib, refresh works correctly.

Versions:

[org.clojure/clojurescript "1.10.773"]
[camel-snake-kebab "0.4.2"]

Error:

:error-while-loading camel-snake-kebab.core
#error {
 :cause "camel-snake-kebab.internals.alter-name"
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message "Syntax error compiling at (camel_snake_kebab/core.cljc:49:1)."
   :data #:clojure.error{:phase :compile-syntax-check, :line 49, :column 1, :source "camel_snake_kebab/core.cljc"}
   :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 7115]}
  {:type java.lang.ClassNotFoundException
   :message "camel-snake-kebab.internals.alter-name"
   :at [java.net.URLClassLoader findClass "URLClassLoader.java" 435]}]
 ...

@fr33m0nk
Copy link

fr33m0nk commented May 6, 2022

I am also facing this exact issue.
Was there a workaround found?

@fr33m0nk
Copy link

fr33m0nk commented May 6, 2022

I have found a solution to the problem.

The problem was caused by figwheel-main's need to have the output directory e.g. target/dev on classpath.
Figwheel-main after building cljs files also puts camel-case-kebab.core in the output directory.
By default, tools.namespace/refresh looks first at var #'clojure.tools.namespace.repl/refresh-dirs which is empty and then tries to reloads the classpath which has Figwheel-main's output directory e.g. target/dev.
JVM think camel-snake-kebab.core is incorrectly placed in Figwheel-main's output directory e.g.target/dev which causes below error:

:error-while-loading camel-snake-kebab.core
#error {
 :cause "camel-snake-kebab.internals.alter-name"
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message "Syntax error compiling at (camel_snake_kebab/core.cljc:49:1)."
   :data #:clojure.error{:phase :compile-syntax-check, :line 49, :column 1, :source "camel_snake_kebab/core.cljc"}
   :at [clojure.lang.Compiler analyzeSeq "Compiler.java" 7115]}
  {:type java.lang.ClassNotFoundException
   :message "camel-snake-kebab.internals.alter-name"
   :at [java.net.URLClassLoader findClass "URLClassLoader.java" 435]}]
 ...

Fix for this is to alter var #'clojure.tools.namespace.repl/refresh-dirs and set its value to a collection that has everything from classpath except Figwheel-main's output directory.

Below is the function I am using now. I have tested this and it works great.

(ns user
    (:require
      [clojure.java.classpath :as cp]
      [clojure.string :as str])
    (:use
      [dev]
      [dev-extras :exclude [go]])
    (:import (java.io File)))

(defn go
  ([] 
   (go "target/dev"))
  ([figwheel-output-directory]
   (let [directories-to-reload (into []
                                     (filter #(not (str/includes? (.getPath ^File %) figwheel-output-directory)))
                                     (cp/classpath))]
     (alter-var-root #'clojure.tools.namespace.repl/refresh-dirs (constantly directories-to-reload))
     (dev-extras/go))))

Now, after calling (go), I can call (reset) without any problem.
There's also an open issue somewhat related to this.

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

4 participants