Repository navigation
Add a JavaScript formatter, written as s-expressions - #13
Merged
Merged
Conversation
--json and %formatter/json write a list of attributes as an object, any other list as an array, and true, false and null as themselves. %json and %yaml now read unquoted numbers, booleans and null as numbers and symbols instead of strings, so JSON read in is written back the same. Raw text inside a <script> is written as is, so JSON can be given to a script, and the blog sample gains a JSON Feed.
Writing JavaScript as seam source is fragile, since ; starts a comment, and strings were written back with Rust's escapes. A script that is a single string is now written as it is, as with style, and otherwise strings in a script are written as JavaScript strings. JSON is best given to scripts as a data block, which is what the docs now show.
--js and %formatter/js write a list as a call unless it starts with an operator or a keyword: (+ a b), (. a b), (const x 1), (=> (x) body), (if c then else), (for x of xs ...), and so on. A list of attributes is an object, and strings are JavaScript strings, so scripts can be written with seam's syntax and macros without its comments and strings getting in the way. The js-concept sample now compiles.
The JavaScript formatter now writes every form in docs/javascript.md: arrays, objects and destructuring, ([] a i) access, optional chaining, templates, regexes, every operator, declarations, functions, generators, async, classes, every statement, labels, comments, imports and exports. An escaped head, (\array x), is always a call. A symbol written \% is no longer a macro, and \\ is a backslash.
… text. Only a declaration, or a named function or class, can be exported, so (export (async (=> ...))) is an error instead of invalid JavaScript. (. 1 toString) is written (1).toString, and template text, regexes and comments write </ as <\/, so they cannot end an HTML script.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e7b75fa. Configure here.
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.

Builds on #12 (JSON formatter). Until that is merged, this diff includes it.
Adds JavaScript output, with
--jsand(%formatter/js ...). JavaScript is written as s-expressions, so scripts can use seam's macros, and seam's;comments and strings no longer get in the way.(f a b)→f(a, b)and((. a b) 1)→a.b(1). Symbols are written as they are, so(console.log x)works too.(+ a b c),(- a), comparisons,&&/||/??,!,typeof,await, and assignments (=,+=, ...). A nested operation is always put in parentheses, so precedence never matters.(. a b "c-d" 0)→a.b["c-d"][0],(at a i),(new Map),(? c a b)and(array ...). A list of attributes is an object, the same as for JSON.const/let/var(if c then else), using(do ...)for blocks(for x of xs ...)and(for k in o ...)while,return,throw,break,continueimport, which is written word for word(export (const ...))and(export default x)(=> (x (= y 1)) body...)and(function name (params) body...). A function returns its last expression.if, the error suggests(? ...)instead.%formatter/jsis compact unless given:document true.The output is raw text, so
(script (%formatter/js ...))is written as it is. It isn't applied to<script>automatically, so existing pages are unchanged.samples/js-concept.sex(the 2020 mockup) now compiles. Its tagged templates (Color`black`) became calls with strings, since seam has no template syntax.I checked with
node --checkthat the indented and compact output of the sample both parse, and ran a small generated program in node to check its results. Tests cover each form and the errors.Note
Medium Risk
Large formatter/parser changes affect HTML emission and macro expansion, so regressions could break builds or script output despite strong tests.
Overview
Introduces JSON and JavaScript markup formatters exposed via
--json/--js,%formatter/json, and%formatter/js, includingdocs/javascript.md,USAGE.md, and README updates plus a JSON Feed sample (feed.json.sex, build wiring,samples/js-concept.sexrefresh).HTML
<script>emission now prefers raw string bodies, otherwise walks children through a newgenerate_scripthelper that quotes strings with sharedwrite_string, while macro recognition relies onNode::macro_name, YAML scalars become typed nodes, string escaping handles\\, and extensive tests cover JSON, JS, script safety, and escaped symbols.Reviewed by Cursor Bugbot for commit 78b1611. Bugbot is set up for automated code reviews on this repo. Configure here.