Fork me on GitHub
#clojurescript
<
2018-01-04
>
jeaye02:01:05

This is causing me some issues on the latest ClojureScript: https://github.com/jeaye/cljs-macro-arity-bug/blob/master/src/test/macro.cljc

jeaye02:01:44

I've boiled it down to just those few lines of code; anyone see this before, or am I missing something very silly? That repo is a full repro as well.

jeaye02:01:59

In the browser, I see "Invalid arity: 0" but I originally ran into this issue with React Native, where I was seeing "SyntaxError: Return statements are only valid inside functions."

dnolen02:01:15

@jeaye yes that won’t work

dnolen02:01:00

you cannot directly require macro files with :require

dnolen02:01:07

you need to use :require-macros

dnolen02:01:16

nothing to do with latest ClojureScript btw, always been true

jeaye02:01:37

@dnolen That's a repro issue, not the original issue.

dnolen02:01:12

@jeaye I don’t understand what you mean by repro - since that just won’t work

jeaye02:01:28

The require has nothing to do with it.

jeaye02:01:38

Just an artifact that slipped into my repro.

jeaye02:01:56

The issue is regarding macros and multi-arity fns.

jeaye02:01:37

@dnolen Sorry for the confusion. I've updated the repro to better convey the issue I'm seeing, though it doesn't manifest in the same exact error message. It sure does something weird though.

jeaye03:01:56

@dnolen Did I lose you? 🙂

dnolen03:01:24

@jeaye sorry have to run, but your repo still isn’t really valid ClojureScript

dnolen03:01:07

defmacro isn’t allowed in .cljs files or .cljc files read as :cljs

dnolen03:01:22

perhaps someone else can clarify further

jeaye03:01:26

I certainly believe you know cljs far better than me, but why would it cleanly compile?

jeaye03:01:04

Furthermore, even if we wrap the defmacro in a reader conditional, the problem exists (and I've updated the repo to show that).

aconanlai05:01:05

how would one go about setting up environment variables in a figwheel project?

bthesorceror06:01:53

anyone using cursive see a warning that .querySelector cannot be resolved? been looking all over and can't find much about it.

cfleming06:01:02

@bthesorceror That’s possible - accurately resolving JS interop is hard/impossible.

cfleming06:01:27

I’ve been meaning to reduce that warning so it’s not so shouty since it can’t really work properly.

cfleming06:01:12

Whoops, I just saw you posted this over in #cursive as well, probably better to discuss it over there.

bthesorceror06:01:04

thanks @cfleming just wanted to make sure I wasn't missing something. I always prefer no warnings but understandable.

cfleming07:01:56

@bthesorceror Yeah, normally all those warnings are configurable, but that one is not for legacy reasons. I’ll try to fix that shortly.

ekz10:01:58

how could I assign a value that comes form destructuring? const {app, Menu, Tray} = require(‘electron’)

roman01la10:01:28

@francoleocan there’s no built-in destructuring syntax for host platform data structures

roman01la10:01:55

(def electron (nodejs/require "electron"))
(def app (goog.object/get electron "app"))
;; ...

dnolen12:01:07

@jeaye the issue is a subtle one - it needs to work for bootstrapped ClojureScript, it may be possible to warn in the usual case - but no one has worked on that

dnolen12:01:05

your minimal case repo on GitHub makes it challenging to track the problem since you include no description of what you believe to be the defect there especially after your changes

sggdfgf14:01:01

hi, why [:script "alert('You alerted!');"] not working 😢

sggdfgf14:01:36

@rauh [:div {:dangerouslySetInnerHTML {:__html "<script>alert('Script runs');</script>"}}] looks like giving normal html, but allert does not come 😞

sggdfgf14:01:39

could it be figwheel interference or something?

thheller14:01:33

why are you not calling alert directly instead of rendering it as html?

sggdfgf14:01:00

It has to be hiccup

sggdfgf14:01:01

I am embedding it into [react/view

sggdfgf14:01:24

did you mean to write alert into separate file and then load?

thheller14:01:32

not sure what you are trying to do but emitting a :script via react just isn’t useful

thheller14:01:41

you probably want to use one of the lifecycle fns instead

thheller14:01:56

eg. in componentDidMount call js/alert

thheller14:01:27

no idea how lifecycle fns work with reagent though

sggdfgf14:01:01

maybe what you say is good approach, but the first thing came to me fist hiccup all the HTML from examples into the view 🙂

aconanlai14:01:21

hi all, i'm trying to set up environment variables in my cljs / figwheel project, to avoid commiting API keys to source control - any idea how?

sggdfgf14:01:58

@aconanlai how will I on componentDidMount execute custom script in the browser? (allert was just a place holder for development)

jeaye19:01:45

@dnolen I linked to the generated code, which is quite incorrect, and gave instructions requiring one command to be able to see the error.

jeaye19:01:29

To anyone else willing to verify, this looks like a cljs bug to me. https://github.com/jeaye/cljs-macro-arity-bug

dnolen19:01:26

@jeaye it’s preferable to have a full description so I don’t have to run anything

dnolen19:01:34

and I can just tell you what the problem is

jeaye19:01:39

@dnolen Ok. I'll approach this a different way. Do you have any idea why cljs would generate code which causes this to be thrown "SyntaxError: Return statements are only valid inside functions."

dnolen19:01:37

no idea, but this yet another different problem than what you described yesterday

dnolen19:01:07

this is why a description of what you expect and what you got can be more helpful than me running something

jeaye19:01:11

That quote is from yesterday.

dnolen19:01:11

and guessing those things

dnolen19:01:39

but you were talking about a bunch of other things

dnolen19:01:49

macros, multi-arity macros

dnolen19:01:55

do any of those concerns still apply?

dnolen19:01:59

@jeaye your repo is more confusing than before

dnolen19:01:04

why do you have 3 namespaces now?

dnolen19:01:50

which ones matter?

jeaye19:01:51

They're all of 26 lines total and they all matter, for the reproduction of this issue. I came in here preemptively, to try to save some time in case this was a common error or something (return statements only being valid inside fns from generated clj code). So far, I think it's just been counterproductive for the both of us, so I'll keep trying until I can pinpoint exactly where things are going wrong, so you needn't run anything.

dnolen19:01:21

@jeaye the problem I’m having some much trouble is I don’t even understand your example, sorry if we’re talking past each other

dnolen19:01:29

you’ve just made the example more oblique

jeaye19:01:58

Unfortunately, I don't think it's a trivial problem. I'll let you know when I know more.

dnolen19:01:37

I mean your code just doesn’t make sense to me

dnolen19:01:44

as I don’t know what you are trying to do at all

dnolen19:01:05

far as I can tell you are attempting to

dnolen19:01:53

1) load test.macro from a .cljs file

dnolen19:01:10

2) have foo invoke a macro from another ns

dnolen19:01:20

but I don’t see how that can work

jeaye19:01:24

I'm attempting to reproduce the situation which causes what appears to be an issue with codegen. The actual macros used are far removed from anything practical.

jeaye19:01:37

@dnolen Can fns called from macros not call other macros?

dnolen19:01:10

why do you need these reader conditionals?

dnolen19:01:18

are they important? if not remove them

dnolen19:01:25

otherwise I will keep being confused

jeaye19:01:30

Darnit, man.

jeaye19:01:59

I added those reader conditionals because you wouldn't look beyond me using defmacro in a cljc.

dnolen19:01:25

just that could be another bug

dnolen19:01:30

and not the one you’re interested in

jeaye19:01:32

They're completely unrelated to the problem, as is the initial require bit you pointed out, but I've been trying to placate you so you can look at the actual issue I'm pointing out.

dnolen19:01:51

you’re misunderstanding the original request

dnolen19:01:57

removing variables from your problem

jeaye19:01:51

Is defmacro within a cljc file which is required from cljs a problem (assuming it's not in a reader conditional)?

dnolen19:01:24

ok I think I know what the problem is

dnolen19:01:39

you want a macro to call another macro

dnolen19:01:58

but that other macro is in a namespace never actually required by a ClojureScript file

dnolen19:01:07

this won’t work

dnolen20:01:13

not without fully qualifying

dnolen20:01:47

test.print/foo-print not foo-print

darwin20:01:43

@jeaye I just tested the repo, and the code compiled without any errors/warnings. And it generated (println "foo") as I would expect by reading the code, am I missing something?

jeaye20:01:35

@darwin No, it's me who's missing something. I'm missing an exact repro, so I'll keep hunting.

jeaye20:01:42

Thanks for looking.

dnolen20:01:32

and ignore what what I said 😛

dnolen20:01:48

that symbol should resolve just fine

jeaye20:01:59

@dnolen Sorry, I'm certainly not ignoring you.

dnolen20:01:25

I was being serious

dnolen20:01:35

@darwin is right, it does look fine

dnolen20:01:23

the repo was just tricky for me to follow

jeaye20:01:31

After cleaning my actual project, my original repro is gone.

noisesmith20:01:45

caching is the devil