Skip to content

Issue #191 - support nested :require prefix list syntax #192

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

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/standard-clojure-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@
let prevNodeIsNewline = false
let lineOfLastCommentRecording = -1
let insidePrefixList = false
let prefixListParenNestingDepth = -1
let prefixListPrefix = null
let prefixListLineNo = -1
const prefixListComments = {}
Expand Down Expand Up @@ -1784,10 +1785,13 @@
if (insideRequireForm && requireSymbolIdx > 0) {
requireSymbolIdx = -1
}
if (insideRequireForm && insidePrefixList) {

if (insideRequireForm && insidePrefixList && prefixListParenNestingDepth !== -1 && parenNestingDepth === dec(prefixListParenNestingDepth)) {
insidePrefixList = false
prefixListPrefix = null
prefixListParenNestingDepth = -1
}

if (insideReaderConditional && parenNestingDepth === dec(readerConditionalParenNestingDepth)) {
insideReaderConditional = false
currentReaderConditionalPlatform = null
Expand Down Expand Up @@ -2319,6 +2323,7 @@
if (isPrefixList) {
const prefixListId = createId()
insidePrefixList = true
prefixListParenNestingDepth = parenNestingDepth
prefixListLineNo = lineNo
prefixListPrefix = node.text
currentPrefixListId = prefixListId
Expand Down
17 changes: 17 additions & 0 deletions test_format/ns.eno
Original file line number Diff line number Diff line change
Expand Up @@ -1985,3 +1985,20 @@
(:require
[garden.selectors :refer [&] :rename {& parent}]))
--Expected

# GitHub Issue #191 - expand nested prefix lists

--Input
(ns com.example.my-app
(:require
[com.example.my-app.foo
[bar :as bar :refer [fred]] ;; a comment
[baz :refer [qux] :as plugh]])) ;; another comment
--Input

--Expected
(ns com.example.my-app
(:require
[com.example.my-app.foo.bar :as bar :refer [fred]] ;; a comment
[com.example.my-app.foo.baz :as plugh :refer [qux]])) ;; another comment
--Expected
28 changes: 28 additions & 0 deletions test_parse_ns/parse_ns.eno
Original file line number Diff line number Diff line change
Expand Up @@ -3232,3 +3232,31 @@
]
}
--Expected

# GitHub Issue #191 - expand nested prefix lists

--Input
(ns com.example.my-app
(:require
[com.example.my-app.foo
[bar :as bar]
[baz :refer [qux]]]))
--Input

--Expected
{
"nsSymbol": "com.example.my-app",
"requires": [
{
"symbol": "com.example.my-app.foo.bar",
"as": "bar"
},
{
"symbol": "com.example.my-app.foo.baz",
"refer": [
{"symbol": "qux"}
]
}
]
}
--Expected