Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oakmac committed Dec 3, 2024
1 parent 689024f commit 2ec7a18
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
55 changes: 29 additions & 26 deletions lib/standard-clojure-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,7 @@
let insideReaderComment = false
let idOfLastNodeInsideReaderComment = -1
let requireRenameIdx = -1
let requireRenameParenNestingDepth = -1
let skipNodesUntilWeReachThisId = -1
let sectionToAttachEolCommentsTo = null
let nextTokenIsRequireDefaultSymbol = false
Expand Down Expand Up @@ -1753,6 +1754,9 @@
collectRequireExcludeSymbols = false
requireExcludeSymbolParenDepth = -1
}
if (insideRequireForm && parenNestingDepth < requireRenameParenNestingDepth) {
requireRenameParenNestingDepth = -1
}

requireMacrosReferNodeIdx = -1
requireMacrosRenameIdx = -1
Expand Down Expand Up @@ -2127,7 +2131,6 @@
} else if (idx > requireNodeIdx && insideRequireForm && isTokenNode2 && isReferKeyword(node)) {
referIdx = idx
referParenNestingDepth = parenNestingDepth
console.log('AAAAAAAAA')

// is this :require :default ?
} else if (idx > requireNodeIdx && insideRequireForm && isTokenNode2 && isDefaultKeyword(node)) {
Expand All @@ -2154,15 +2157,36 @@
// collect :refer :all
} else if (idx > referIdx && insideRequireForm && isTokenNode2 && isAllNode(node)) {
result.requires[activeRequireIdx].refer = 'all'
console.log('BBBBBBBBBB')

// collect :refer :default symbol
} else if (idx > referIdx && insideRequireForm && isTokenNode2 && nextTokenIsRequireDefaultSymbol) {
result.requires[activeRequireIdx].default = node.text
nextTokenIsRequireDefaultSymbol = false

// collect :require renames
} else if (insideRequireForm && insideRequireList && requireRenameIdx > 0 && idx > requireRenameIdx && parenNestingDepth > requireRenameParenNestingDepth && isTokenNode2 && isTextNode) {
stackPush(renamesTmp, node.text)

if (arraySize(renamesTmp) === 2) {
const itm = {}
itm.fromSymbol = renamesTmp[0]
itm.toSymbol = renamesTmp[1]

if (insideReaderConditional && currentReaderConditionalPlatform) {
itm.platform = currentReaderConditionalPlatform
}

if (!isArray(result.requires[activeRequireIdx].rename)) {
result.requires[activeRequireIdx].rename = []
}

stackPush(result.requires[activeRequireIdx].rename, itm)

renamesTmp = []
}

// collect :require :refer symbols
} else if (idx > referIdx && insideRequireForm && parenNestingDepth === inc(referParenNestingDepth) && isTokenNode2 && isTextNode) {
} else if (idx > referIdx && insideRequireForm && referParenNestingDepth !== -1 && parenNestingDepth > referParenNestingDepth && isTokenNode2 && isTextNode) {
if (!isArray(result.requires[activeRequireIdx].refer)) {
result.requires[activeRequireIdx].refer = []
}
Expand Down Expand Up @@ -2213,28 +2237,6 @@
requireFormLineNo = lineNo
insidePrefixList = true

// collect :require renames
} else if (insideRequireForm && insideRequireList && requireRenameIdx > 0 && idx > requireRenameIdx && isTokenNode2 && isTextNode) {
stackPush(renamesTmp, node.text)

if (arraySize(renamesTmp) === 2) {
const itm = {}
itm.fromSymbol = renamesTmp[0]
itm.toSymbol = renamesTmp[1]

if (insideReaderConditional && currentReaderConditionalPlatform) {
itm.platform = currentReaderConditionalPlatform
}

if (!isArray(result.requires[activeRequireIdx].rename)) {
result.requires[activeRequireIdx].rename = []
}

stackPush(result.requires[activeRequireIdx].rename, itm)

renamesTmp = []
}

// collect :require symbol inside of a list / vector
} else if (insideRequireForm && insideRequireList && idx > requireNodeIdx && isTokenNode2 && isTextNode && requireSymbolIdx === -1 && !isKeywordNode(node)) {
if (!isArray(result.requires)) {
Expand Down Expand Up @@ -2290,9 +2292,10 @@
}
}

// :rename inside require
// :rename inside require
} else if (insideRequireForm && insideRequireList && idx > requireNodeIdx && isRenameKeyword(node)) {
requireRenameIdx = idx
requireRenameParenNestingDepth = parenNestingDepth
renamesTmp = []

// collect require Strings in ClojureScript
Expand Down
2 changes: 1 addition & 1 deletion test/parse_ns.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('All test_parse_ns/ cases should have unique names', () => {

// dev convenience: set this to true and add specific test cases
// only those cases will run
const onlyRunSpecificTests = true
const onlyRunSpecificTests = false
const specificTests = new Set()
specificTests.add('GitHub Issue #166 - :require :refer :all bug')

Expand Down

0 comments on commit 2ec7a18

Please sign in to comment.