Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

JSX preserve mode spreads an `@unboxed` props record (`{..."x"}` instead of `"x"`)

Geschlossen
#8,813 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Ein zugehöriger Pull Request wurde bereits gemerged.

  • #8847 von @cknitt — ohne Merge geschlossen
  • #8857 von @cknitt — gemerged

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Veraltet
Tech-Stack
javascript, ocaml
Bereich
compilers

Rechercherichtung

Start with jsx_props_of in compiler/ml/translcore.ml and jsx_printable in compiler/core/js_dump.ml, then compare the preserve-mode output with the reproduction and expected output in the issue. Done means both @unboxed record examples preserve the string as the props value instead of spreading it. Pull request #8847 is already open for this issue.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Found by adversarial experiments on semantic analysts.

What is broken

jsx_props_of turns every props expression that is not a Record_regular record literal into Jsx_props_spread:
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/translcore.ml#L1049-L1096

An @unboxed record literal compiles to its single field's value, which is not an object. jsx_printable does not reject this case:
https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/core/js_dump.ml#L176-L190

Reproduction

@@jsxConfig({version: 4, module_: "MyJsx"})
module MyJsx = {
  type element = int
  type component<'props> = 'props => element
  external component: component<'props> => component<'props> = "%identity"
  @module("rt") external jsx: (component<'props>, 'props) => element = "jsx"
  @module("rt") external jsxs: (component<'props>, 'props) => element = "jsxs"
  external array: array<element> => element = "%identity"
}
@unboxed type props = {title: string}
module C = {@module("lib") external make: MyJsx.component<props> = "C"}
module D = {@val external make: MyJsx.component<props> = "lowerD"}
let el = <C title="x" />
let el2 = <D title="y" />

bsc -nopervasives -bs-jsx 4 -bs-jsx-preserve K12.res at master:

let el = <Lib.C
  {..."x"}
/>;
let el2 = Rt.jsx(lowerD, {..."y"});

Expected, as printed by bsc -nopervasives -bs-jsx 4 and by preserve mode at ece8b148:

let el = Rt.jsx(Lib.C, "x");
let el2 = Rt.jsx(lowerD, "y");

Introduced

#8754 (a7721303a).

Impact

The component receives {0: "x"} instead of "x": the generated code is wrong, with no error or warning. The case is rare, because the props type must be an @unboxed record.

Vorherrschende Sprache
ReScript
Sterne
7.5k
Forks
483
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
120

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus rescript-lang/rescript

Alle Issues in rescript-lang/rescript

Ähnliche Issues

Weitere Issues zu Compilers

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.