Repository navigation
Write <script> contents as JavaScript or JSON - #15
Open
Demonstrandum wants to merge 1 commit into
Open
Demonstrandum wants to merge 1 commit into
Demonstrandum wants to merge 1 commit into
Conversation
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.
A `script` element with s-expressions in it was written out as the s-expressions themselves, even though the JavaScript formatter now exists. `style` already goes through the CSS formatter; `script` now does the same, by its `type`:
Contents that start on a new line are written over several lines; otherwise on one line.
```lisp
<script type="module"> import {a} from "./a.js"; a((n) => n * 2); </script> <script type="importmap">{"imports":{"a":"./a.js"}}</script>(script :type module
(import (a) from "./a.js")
(a (=> (n) (* n 2))))
(script :type importmap (:imports (:a "./a.js")))
```
gives
```html
```
The pretty-printed JavaScript isn't re-indented to match the HTML, since that would change multi-line template strings.
Breaking: `(script f("x"))`-style source, kept as written before, is now read as s-expressions, so it must be a string or written as `(f "x")`.
Note
Medium Risk
Behavior change for existing
<script>markup is breaking where bodies were previously echoed as s-expressions; generated JS/JSON in pages affects runtime but is localized to HTML assembly.Overview
<script>elements now compile s-expression bodies through the same formatters as%formatter/jsand%formatter/json, mirroring how<style>already uses the CSS formatter.The HTML assembler picks a formatter from the script’s
type: missing/module/JavaScript MIME types use JSFormatter;application/json,importmap,speculationrules, and...+jsonuse JSONFormatter; other types still emit s-expressions verbatim via the oldgenerate_scriptpath. A lone string or raw node is unchanged—output is copied as written. When the first child starts on a new line, output is pretty-printed with a leading newline.Docs (
USAGE.md,docs/javascript.md) describe writing scripts without wrapping(%formatter/js ...), and tests cover module imports, import maps, unknown types, and multi-line layout.Breaking: ambiguous forms like
(script f("x"))are no longer treated as raw-ish source; use a single string or proper s-expressions such as(f "x").Reviewed by Cursor Bugbot for commit 23fdeea. Bugbot is set up for automated code reviews on this repo. Configure here.