Skip to content

Commit ebe058c

Browse files
committed
GitHub Issue #183 - all types of quoted ns meta
This commit improves quoted namespace metadata value handling. Pull Reuqest #182 added quoted ns metadata value handling for nodes with children (maps, lists etc.) but didn't address all the possible types a wrap node body might have. This commit checks if the skip target candidate node has children, and if yes it picks the last child and repeats the check until it finds the correct skip target.
1 parent 66c81dd commit ebe058c

File tree

3 files changed

+79
-15
lines changed

3 files changed

+79
-15
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
## [Unreleased]
66

77
- [Issue #184] - fix bug with tagged literals in `ns` metadata ([PR-185])
8+
- [Issue #183] - fix bug with quoted values other than maps, lists etc. in `ns` metadata ([PR-186])
89

910
## [0.21.0] - 2025-02-26
1011

@@ -240,6 +241,7 @@ All notable changes to this project will be documented in this file.
240241
[Issue #166]:https://github.com/oakmac/standard-clojure-style-js/issues/166
241242
[Issue #178]:https://github.com/oakmac/standard-clojure-style-js/issues/178
242243
[Issue #181]:https://github.com/oakmac/standard-clojure-style-js/issues/181
244+
[Issue #183]:https://github.com/oakmac/standard-clojure-style-js/issues/183
243245
[Issue #184]:https://github.com/oakmac/standard-clojure-style-js/issues/184
244246

245247
[commit #db857ff4]:https://github.com/oakmac/standard-clojure-style-js/commit/db857ff413f0a8625c0cd0c975684244d875705e
@@ -289,3 +291,4 @@ All notable changes to this project will be documented in this file.
289291
[PR-179]:https://github.com/oakmac/standard-clojure-style-js/pull/179
290292
[PR-182]:https://github.com/oakmac/standard-clojure-style-js/pull/182
291293
[PR-185]:https://github.com/oakmac/standard-clojure-style-js/pull/185
294+
[PR-186]:https://github.com/oakmac/standard-clojure-style-js/pull/186

lib/standard-clojure-style.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -818,10 +818,6 @@
818818
return n && n.name === '.close' && (n.text === ')' || n.text === ']' || n.text === '}')
819819
}
820820

821-
function isWrap (n) {
822-
return n && n.name === 'wrap'
823-
}
824-
825821
function isTokenNode (n) {
826822
return n.name === 'token'
827823
}
@@ -1849,17 +1845,14 @@
18491845
metadataValueNodeId = -1
18501846

18511847
// skip any forward nodes that we have just collected as text
1852-
let unwrappedNode
1853-
if (isWrap(node)) {
1854-
const wrapBody = arrayLast(node.children)
1855-
unwrappedNode = arrayLast(wrapBody.children)
1856-
} else {
1857-
unwrappedNode = node
1858-
}
1859-
1860-
if (isArray(unwrappedNode.children)) {
1861-
const lastChildNode = arrayLast(unwrappedNode.children)
1862-
skipNodesUntilWeReachThisId = lastChildNode.id
1848+
let skipCandidate = node
1849+
while (skipCandidate) {
1850+
if (isArray(skipCandidate.children)) {
1851+
skipCandidate = arrayLast(skipCandidate.children)
1852+
skipNodesUntilWeReachThisId = skipCandidate.id
1853+
} else {
1854+
skipCandidate = null
1855+
}
18631856
}
18641857
}
18651858

test_parse_ns/parse_ns.eno

+68
Original file line numberDiff line numberDiff line change
@@ -3109,3 +3109,71 @@
31093109
]
31103110
}
31113111
--Expected
3112+
3113+
# GitHub Issue #183 - handle all types of quoted ns metadata hash map values
3114+
3115+
> https://github.com/oakmac/standard-clojure-style-js/issues/183
3116+
3117+
--Input
3118+
(ns my.namespace
3119+
{:token 'token
3120+
:string '"string"
3121+
:parens '(parens)
3122+
:brackets '[brackets]
3123+
:braces '{:braces true}
3124+
:wrap ''wrap
3125+
:deep-wrap ''''''wrap
3126+
:meta '^:meta [1 2 3]
3127+
:tagged ' #tag [1 2 3]}
3128+
(:require [clojure.string :as str]))
3129+
--Input
3130+
3131+
--Expected
3132+
{
3133+
"nsSymbol": "my.namespace",
3134+
"nsMetadata": [
3135+
{
3136+
"key": ":token",
3137+
"value": "'token"
3138+
},
3139+
{
3140+
"key": ":string",
3141+
"value": "'\"string\""
3142+
},
3143+
{
3144+
"key": ":parens",
3145+
"value": "'(parens)"
3146+
},
3147+
{
3148+
"key": ":brackets",
3149+
"value": "'[brackets]"
3150+
},
3151+
{
3152+
"key": ":braces",
3153+
"value": "'{:braces true}"
3154+
},
3155+
{
3156+
"key": ":wrap",
3157+
"value": "''wrap"
3158+
},
3159+
{
3160+
"key": ":deep-wrap",
3161+
"value": "''''''wrap"
3162+
},
3163+
{
3164+
"key": ":meta",
3165+
"value": "'^:meta [1 2 3]"
3166+
},
3167+
{
3168+
"key": ":tagged",
3169+
"value": "' #tag [1 2 3]"
3170+
}
3171+
],
3172+
"requires": [
3173+
{
3174+
"symbol": "clojure.string",
3175+
"as": "str"
3176+
}
3177+
]
3178+
}
3179+
--Expected

0 commit comments

Comments
 (0)