Refactor sx.js: extract string renderer, deduplicate helpers, remove dead code
Extract Node-only string renderer (renderToString, renderStr, etc.) to sx-test.js. Add shared helpers (_processOOBSwaps, _postSwap, _processBindings, _evalCond, _logParseError) replacing duplicated logic. Remove dead isTruthy and _sxCssKnown class-list fallback. Compress section banners. sx.js goes from 2652 to 2279 lines (-14%) with zero browser-side behavior change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,14 +15,16 @@ from shared.sx.html import render as py_render
|
||||
from shared.sx.evaluator import evaluate
|
||||
|
||||
SX_JS = Path(__file__).resolve().parents[2] / "static" / "scripts" / "sx.js"
|
||||
SX_TEST_JS = Path(__file__).resolve().parents[2] / "static" / "scripts" / "sx-test.js"
|
||||
|
||||
|
||||
def _js_render(sx_text: str, components_text: str = "") -> str:
|
||||
"""Run sx.js in Node and return the renderToString result."""
|
||||
"""Run sx.js + sx-test.js in Node and return the renderToString result."""
|
||||
# Build a small Node script
|
||||
script = f"""
|
||||
global.document = undefined; // no DOM needed for string render
|
||||
{SX_JS.read_text()}
|
||||
{SX_TEST_JS.read_text()}
|
||||
if ({json.dumps(components_text)}) Sx.loadComponents({json.dumps(components_text)});
|
||||
var result = Sx.renderToString({json.dumps(sx_text)});
|
||||
process.stdout.write(result);
|
||||
|
||||
Reference in New Issue
Block a user