#249 PR3: extract pure logic from explorer.qmd to ES modules#12
Merged
Conversation
Extract 10 closure-free functions out of the explorer.qmd OJS god-block
into two unit-testable ES modules, following the source-palette.js
dynamic-import precedent. No behavior change.
- assets/js/sql-builders.js: escSql, escapeIlikePattern, textSearchWhere,
textSearchScore
- assets/js/explorer-utils.js: escapeHtml, searchTerms, parseNum,
csvParamValues, sourceUrl, readHash. readHash gains a
hashStr=location.hash default param so it is Node-testable; all 3 call
sites are zero-arg and unchanged.
Wiring: each former `function name(){...}` OJS cell is replaced in place
by a single `name = _module.name` binding cell. OJS forbids two cells of
the same name, so the import block and the inline definitions cannot
coexist -- the swap is atomic rather than "import above, inline below".
- tests/unit/{sql-builders,explorer-utils}.test.mjs: 13 node:test cases
pinning exact outputs (escapeIlikePattern metachar escaping +
single-quote doubling; readHash clamping and defaults).
- .github/workflows/explorer-e2e.yml: add a `node --test` step as a fast
PR gate ahead of the slow Quarto/Playwright steps.
- _quarto.yml: add the two modules to the resources allowlist so they are
copied into docs/ on render and deploy (same treatment as
source-palette.js).
- package.json: `npm run test:unit` convenience script.
Verified behavior-neutral locally: unit (13) + smoke (4) +
characterization (7) all green; explorer renders and boots with no
uncaught JS errors.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isamplesorg#249 PR3 — extract pure logic from
explorer.qmdto ES modulesThird step of the strangler refactor (isamplesorg#249), behind the PR1 smoke gate (#9) and
PR2 characterization tests (#11). Extracts 10 closure-free functions out of the
explorer.qmdOJS god-block into two unit-testable ES modules. Behavior-neutral.What moved
assets/js/sql-builders.js—escSql,escapeIlikePattern,textSearchWhere,textSearchScoreassets/js/explorer-utils.js—escapeHtml,searchTerms,parseNum,csvParamValues,sourceUrl,readHashSame path-relative dynamic-import pattern as the existing
source-palette.js.Notable mechanics
import-above / inline-below coexistence step is impossible. Each formerfunction name(){...}cell is replaced in place by a singlename = _module.namebinding cell. Verified: no duplicate cells, no leftover inline defs.readHash()→readHash(hashStr = location.hash)so it's Node-testable. All 3 call sites are zero-arg; the default-paramlocationreference is lazy (never hit in tests)._quarto.yml: added both modules to theresources:allowlist — required for them to be copied intodocs/on render & deploy (same assource-palette.js; the deploy workflow shipsdocs/).Tests / gate
tests/unit/{sql-builders,explorer-utils}.test.mjs— 13node:testcases pinning exact outputs (esp.escapeIlikePatternmetachar+quote escaping andreadHashclamping/defaults).explorer-e2e.yml: new fastnode --test tests/unit/*.test.mjsstep, ahead of the slow Quarto/Playwright steps.npm run test:unitfor local use.Verification (all green, local)
quarto render explorer.qmd✓ → modules present underdocs/assets/js/main:explorer.qmd(all executable-MATCH;sourceUrlonly moved comments) and re-ran the gate.Diff:
explorer.qmd−79/+20; +2 modules, +2 unit specs.🤖 Generated with Claude Code