From 2ec7a18c75104c408d645be4f9066aad10ae0808 Mon Sep 17 00:00:00 2001 From: Chris Oakman Date: Mon, 2 Dec 2024 18:25:37 -0600 Subject: [PATCH] WIP --- lib/standard-clojure-style.js | 55 ++++++++++++++++++----------------- test/parse_ns.test.js | 2 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/lib/standard-clojure-style.js b/lib/standard-clojure-style.js index 590603d..177f2ee 100644 --- a/lib/standard-clojure-style.js +++ b/lib/standard-clojure-style.js @@ -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 @@ -1753,6 +1754,9 @@ collectRequireExcludeSymbols = false requireExcludeSymbolParenDepth = -1 } + if (insideRequireForm && parenNestingDepth < requireRenameParenNestingDepth) { + requireRenameParenNestingDepth = -1 + } requireMacrosReferNodeIdx = -1 requireMacrosRenameIdx = -1 @@ -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)) { @@ -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 = [] } @@ -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)) { @@ -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 diff --git a/test/parse_ns.test.js b/test/parse_ns.test.js index 91faf13..6cde57a 100644 --- a/test/parse_ns.test.js +++ b/test/parse_ns.test.js @@ -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')