Skip to content

Commit

Permalink
small refactor from Standard Clojure Style Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
oakmac committed Nov 7, 2024
1 parent f2229bb commit 281f75b
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions lib/standard-clojure-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,11 @@
}

function isStringNode (n) {
return n.name === 'string'
return n && n.name === 'string' && isArray(n.children) && arraySize(n.children) === 3 && n.children[1].name === '.body'
}

function getTextFromStringNode (n) {
return n.children[1].text
}

function isCommentNode (n) {
Expand Down Expand Up @@ -1886,10 +1890,7 @@

// collect the docstring
} else if (insideNsForm && idx > nsNodeIdx && parenNestingDepth === 1 && !beyondNsMetadata && !insideNsMetadataShorthand && !insideNsMetadataHashMap && isStringNode(node)) {
// NOTE: this should always be true, but I like being defensive
if (arraySize(node.children) === 3 && node.children[1].name === '.body') {
result.docstring = node.children[1].text
}
result.docstring = getTextFromStringNode(node)

// collect :refer-clojure :exclude
} else if (insideReferClojureForm && idx > referClojureNodeIdx && isExcludeKeyword(node)) {
Expand Down Expand Up @@ -2260,13 +2261,8 @@
result.requires[activeRequireIdx].platform = currentReaderConditionalPlatform
}

// NOTE: this should always be true, but I like being defensive
if (arraySize(node.children) === 3 && node.children[1].name === '.body') {
result.requires[activeRequireIdx].symbol = strConcat3('"', node.children[1].text, '"')
result.requires[activeRequireIdx].symbolIsString = true
} else {
// FIXME: throw here?
}
result.requires[activeRequireIdx].symbol = strConcat3('"', getTextFromStringNode(node), '"')
result.requires[activeRequireIdx].symbolIsString = true

// collect :import packages not inside of a list or vector
} else if (insideImportForm && idx > importNodeIdx && !insideImportPackageList && isTokenNode2 && isTextNode) {
Expand Down Expand Up @@ -2364,10 +2360,7 @@

// :gen-class :prefix value
} else if (insideGenClass && idx > genClassNodeIdx && genClassToggle === 1 && genClassKeyStr === 'prefix' && isStringNode(node)) {
// NOTE: this should always be true, but I like being defensive
if (arraySize(node.children) === 3 && node.children[1].name === '.body') {
result.genClass.prefix.value = strConcat3('"', node.children[1].text, '"')
}
result.genClass.prefix.value = strConcat3('"', getTextFromStringNode(node), '"')
genClassToggle = 0
genClassValueLineNo = lineNo
// other :gen-class values
Expand Down

0 comments on commit 281f75b

Please sign in to comment.