Commit a8422ee
CLJS-3276 Support macros that expand to require statements
Support this pattern:
(ns foo.bar
(:require-macros [foo.baz :refer [macro-that-expands-to-require]]))
(macro-that-expands-to-require)
To do so we adapt ana/parse-ns to look for consecutive :ns/:ns* ops (ns and
require forms), until a non :ns/:ns* form is encountered. The information of
consecutive forms are merged so the ns-info that parse-ns returns is complete.
This was already happening for :ns* ops (require forms), but not for :ns forms.
This means that parse-ns analyzes/parses at least one form beyond the last
ns/require form, but this can be problematic since this modifies the compiler
env. For instance if the form after ns is a (def ^const ...) then analyzing this
twice will cause an error. Hence the check to only analyze macro forms or
ns/require forms. This should also help in general to avoid unnecessary work.
To make sure the invocation is seen as a macro, and is able to be expanded, we
need to keep track of namespace information in the env across multiple :ns/:ns*
ops. When encountering a macro invocation we load the macro ns on the fly by
invoking the ns-side-effects analyzer pass directly. After this we can call
analyze on the form.1 parent a4673b8 commit a8422ee
File tree
4 files changed
+71
-28
lines changed- src
- main/clojure/cljs
- test
- cljs_build/cljs_3276
- clojure/cljs
4 files changed
+71
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4329 | 4329 | | |
4330 | 4330 | | |
4331 | 4331 | | |
| 4332 | + | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
| 4336 | + | |
| 4337 | + | |
| 4338 | + | |
| 4339 | + | |
| 4340 | + | |
| 4341 | + | |
| 4342 | + | |
| 4343 | + | |
| 4344 | + | |
4332 | 4345 | | |
4333 | 4346 | | |
4334 | 4347 | | |
| |||
4354 | 4367 | | |
4355 | 4368 | | |
4356 | 4369 | | |
| 4370 | + | |
| 4371 | + | |
| 4372 | + | |
4357 | 4373 | | |
4358 | 4374 | | |
4359 | 4375 | | |
| |||
4370 | 4386 | | |
4371 | 4387 | | |
4372 | 4388 | | |
4373 | | - | |
| 4389 | + | |
| 4390 | + | |
4374 | 4391 | | |
4375 | 4392 | | |
4376 | 4393 | | |
| |||
4385 | 4402 | | |
4386 | 4403 | | |
4387 | 4404 | | |
4388 | | - | |
4389 | | - | |
| 4405 | + | |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | |
| 4409 | + | |
| 4410 | + | |
| 4411 | + | |
| 4412 | + | |
| 4413 | + | |
4390 | 4414 | | |
4391 | 4415 | | |
4392 | 4416 | | |
4393 | 4417 | | |
4394 | 4418 | | |
4395 | 4419 | | |
4396 | 4420 | | |
4397 | | - | |
4398 | | - | |
4399 | | - | |
4400 | | - | |
4401 | | - | |
4402 | | - | |
4403 | | - | |
4404 | | - | |
4405 | | - | |
4406 | | - | |
4407 | | - | |
4408 | | - | |
4409 | | - | |
4410 | | - | |
4411 | | - | |
4412 | | - | |
4413 | | - | |
4414 | | - | |
| 4421 | + | |
| 4422 | + | |
| 4423 | + | |
| 4424 | + | |
| 4425 | + | |
| 4426 | + | |
| 4427 | + | |
| 4428 | + | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
4415 | 4442 | | |
4416 | 4443 | | |
4417 | 4444 | | |
4418 | | - | |
4419 | | - | |
4420 | | - | |
4421 | | - | |
4422 | | - | |
4423 | | - | |
4424 | | - | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
4425 | 4453 | | |
4426 | 4454 | | |
4427 | 4455 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1492 | 1492 | | |
1493 | 1493 | | |
1494 | 1494 | | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
0 commit comments