Skip to content

Commit 0ac29ef

Browse files
authored
GitHub Issue #191 - support nested :require prefix list syntax (#192)
1 parent b9e6a57 commit 0ac29ef

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

lib/standard-clojure-style.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,7 @@
16321632
let prevNodeIsNewline = false
16331633
let lineOfLastCommentRecording = -1
16341634
let insidePrefixList = false
1635+
let prefixListParenNestingDepth = -1
16351636
let prefixListPrefix = null
16361637
let prefixListLineNo = -1
16371638
const prefixListComments = {}
@@ -1784,10 +1785,13 @@
17841785
if (insideRequireForm && requireSymbolIdx > 0) {
17851786
requireSymbolIdx = -1
17861787
}
1787-
if (insideRequireForm && insidePrefixList) {
1788+
1789+
if (insideRequireForm && insidePrefixList && prefixListParenNestingDepth !== -1 && parenNestingDepth === dec(prefixListParenNestingDepth)) {
17881790
insidePrefixList = false
17891791
prefixListPrefix = null
1792+
prefixListParenNestingDepth = -1
17901793
}
1794+
17911795
if (insideReaderConditional && parenNestingDepth === dec(readerConditionalParenNestingDepth)) {
17921796
insideReaderConditional = false
17931797
currentReaderConditionalPlatform = null
@@ -2319,6 +2323,7 @@
23192323
if (isPrefixList) {
23202324
const prefixListId = createId()
23212325
insidePrefixList = true
2326+
prefixListParenNestingDepth = parenNestingDepth
23222327
prefixListLineNo = lineNo
23232328
prefixListPrefix = node.text
23242329
currentPrefixListId = prefixListId

test_format/ns.eno

+17
Original file line numberDiff line numberDiff line change
@@ -1985,3 +1985,20 @@
19851985
(:require
19861986
[garden.selectors :refer [&] :rename {& parent}]))
19871987
--Expected
1988+
1989+
# GitHub Issue #191 - expand nested prefix lists
1990+
1991+
--Input
1992+
(ns com.example.my-app
1993+
(:require
1994+
[com.example.my-app.foo
1995+
[bar :as bar :refer [fred]] ;; a comment
1996+
[baz :refer [qux] :as plugh]])) ;; another comment
1997+
--Input
1998+
1999+
--Expected
2000+
(ns com.example.my-app
2001+
(:require
2002+
[com.example.my-app.foo.bar :as bar :refer [fred]] ;; a comment
2003+
[com.example.my-app.foo.baz :as plugh :refer [qux]])) ;; another comment
2004+
--Expected

test_parse_ns/parse_ns.eno

+28
Original file line numberDiff line numberDiff line change
@@ -3232,3 +3232,31 @@
32323232
]
32333233
}
32343234
--Expected
3235+
3236+
# GitHub Issue #191 - expand nested prefix lists
3237+
3238+
--Input
3239+
(ns com.example.my-app
3240+
(:require
3241+
[com.example.my-app.foo
3242+
[bar :as bar]
3243+
[baz :refer [qux]]]))
3244+
--Input
3245+
3246+
--Expected
3247+
{
3248+
"nsSymbol": "com.example.my-app",
3249+
"requires": [
3250+
{
3251+
"symbol": "com.example.my-app.foo.bar",
3252+
"as": "bar"
3253+
},
3254+
{
3255+
"symbol": "com.example.my-app.foo.baz",
3256+
"refer": [
3257+
{"symbol": "qux"}
3258+
]
3259+
}
3260+
]
3261+
}
3262+
--Expected

0 commit comments

Comments
 (0)