HTML-like comments are read in Script code only under compat-annex-b
Date: 2026-11-30
Area: language, source pipeline, engine, test262
Refines: ADR 0177's "Annex B surfaces that already
ship stay as they are", for HTML-like comments only, and ADR 0140's
reparse of a detected Module, which gains a second reason; their other decisions stand.
Related: #2376, #2373,
#2074
Context
ES2026 B.1.1 (sec-html-like-comments) extends the comment syntax of §12.4 "except that this extension is not
allowed when parsing source text using the goal symbol Module" (SingleLineHTMLOpenComment,
SingleLineHTMLCloseComment and the HTMLCloseComment after a MultiLineComment). Module code keeps the plain
grammar, where <!-- is three operators. The extension is all or nothing by goal. The Annex B introduction adds that implementations "are discouraged from implementing these
features unless the implementation is part of a web browser or is required to run the same legacy ECMAScript code
that web browsers encounter".
ADR 0177 made Annex B part of the conformance target
and put each new Annex B surface behind --compat-annex-b. HTML-like comments then shipped unevenly: the engine's
own compile paths read them in every Script with no flag (Function code, eval code, the scripts the test262
runner compiles, the entry of the goccia engine binary), while the source pipeline, which compiles every entry
GocciaRunner and the other applications run, never read them, with the flag or without. The same text was a
comment in a Function body and a SyntaxError as an entry (#2376).
Two questions were open. Should Script code read them always, or only under the flag? And how is an entry lexed
whose goal detection (ADR 0140) settles only after the parse, when a <!--b is a comparison in a Module?
Decision
Johannes asked for the specification-compliant version (30 November 2026, "What's the spec compliant version?") and agreed to it ("Agreed").
- One switch, every Script-goal parse. Under
--compat-annex-b(the profile'sAnnexBswitch, the"compat-annex-b"configuration key,cfAnnexBin the source pipeline) every Script-goal parse reads HTML-like comments: a Script entry through the source pipeline, explicit or detected; a function body the engine compiles on its first call (the pre-parse lexes as the parse does, and the lazy source keeps the setting for its later compiles); direct and indirectevalcode andShadowRealm.prototype.evaluatecode; aFunctionconstructor's parameters and body; thegocciaengine binary's entry, which takes--compat-annex-b; and the scripts the test262 runner compiles. - Without the flag, no parse reads them. This ends the unflagged acceptance in the engine's compile paths
(
Goccia.Eval) and in thegocciabinary. The switch decides it in an unrestricted profile too: the whole language a zero profile stands for leaves HTML-like comments out unlessAnnexBis set (ProfileHTMLCommentsinGoccia.Core). The test262 host sets it for every case (InitTest262EngineinGoccia.Test262), so the test262 runner's profile has--compat-annex-bon, as ADR 0177 requires. - A Module never reads them. An explicit Module, an imported module, and a detected Module are all parsed without them, with the flag or without.
- A detected entry is read under the goal detection chose. With the flag on, a detected entry is lexed with
HTML-like comments, as Script code. When its parse settles on Module and an HTML-like comment was read, the source
is parsed again as a Module without them, as a detected Module is already parsed again strictly under
--compat-non-strict-mode. One parse that needs both reasons is one second parse. When that Module parse fails, an ambiguous top-levelawaitreading falls back to Script as it does after a failed strict parse; otherwise the Module's error is reported. Without the flag, detection does nothing new. - This surface moves behind the flag. ADR 0177 kept the Annex B surfaces that already shipped where they were. HTML-like comments are the exception: they never reached entries, their acceptance elsewhere depended on how code was loaded, and B.1.1 itself is per goal, so they follow the new-surface rule.
Consequences
- An entry, its
evalcode and itsFunctioncode read HTML-like comments the same way: with the flag in Script code, and nowhere without it. Code that relied onFunctionorevalreading them without the flag needs--compat-annex-b. - In the pinned test262 suite the
annexB/language/comments,language/comments,language/module-code/comment-*andannexB/built-ins/Function/createdynfn-*tests pass, and so does the rest ofannexBwith theeval, global, module,FunctionandShadowRealmareas. - Detection's maximum parse counts (ADR 0140) gain no new case: the second parse for an HTML-like comment is the same second parse a strict Module needs, and the Script fallback after it stays the third.
- Detection reads an entry as Script code first, so under the flag that reading decides two cases a Module reading
would decide otherwise. An entry whose Script reading fails because of an HTML-like comment, for example
if (a <!--b) {}beside anexport, reports thatSyntaxError, though a Module reading would parse. And module syntax after<!--on the same line is part of the comment, solet b = 1; 2 <!--b; export { b };settles on Script and runs as one.--source-type=modulereads either entry as a Module from the start. scripts/engine/html-like-comments-test.shchecks thegocciahost with and without the flag; the source pipeline's unit tests,scripts/test-cli-lexer.tsandtests/language/html-like-commentscheck the applications.