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

^:inline does not work on 2nd element #141

Closed
chpill opened this issue Jan 7, 2017 · 2 comments
Closed

^:inline does not work on 2nd element #141

chpill opened this issue Jan 7, 2017 · 2 comments

Comments

@chpill
Copy link

chpill commented Jan 7, 2017

Hello~ First thanks a lot for sablono, it is an awesome library.

I have tried to use the ^:inline metadata to get read of the interpret calls in the code emitted by sablono. It seems that it does not work in all cases though. I have made a dummy project to illustrate the issue, but here is the gist of it:

(ns sablono-bug.core
  (:require [sablono.core :as sablono]))

(defn my-react-component
  "Dummy function that returns a react component"
  []
  (sablono/html [:span "plop"]))

(def a
  "Here, inlining works just fine"
  (sablono/html [:div
                 {}
                 ^:inline (my-react-component)]))

(def b
  "Here it does not work"
  (sablono/html [:div
                 ^:inline (my-react-component)]))

Case a compiles to the following js:

sablono_bug.core.a = React.createElement("div",null,sablono_bug.core.my_react_component.call(null));

Case b compiles to the following js (indented for clarity):

sablono_bug.core.b = (function (){
  var attrs8164 = sablono_bug.core.my_react_component.call(null);
  return cljs.core.apply.call(
    null,
    React.createElement,
    "div",
    ((cljs.core.map_QMARK_.call(null,attrs8164)) ?
      sablono.interpreter.attributes.call(null,attrs8164):null),
      ((cljs.core.map_QMARK_.call(null,attrs8164)) ?
        null :
        new cljs.core.PersistentVector(
          null,
          1,
          5,
          cljs.core.PersistentVector.EMPTY_NODE, [sablono.interpreter.interpret.call(null,attrs8164)], null)));
})();

I have not had the time to dive in the code yet, but maybe you have an idea why it does not work in case b?

@r0man
Copy link
Owner

r0man commented Jan 8, 2017

@chpill Should be fixed in master. Can you try it out with 0.7.7-SNAPSHOT.

@chpill
Copy link
Author

chpill commented Jan 8, 2017

I just tried it, works like a charm! No more interpret calls in my generated js. Thanks!

@chpill chpill closed this as completed Jan 8, 2017
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