lang-core: member access on a component instance reads its internal fields instead of giving null

オープン 初心者向け
#1,693 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
compilers

調査の方向性

まず spec/language.md のセクション3.1を読み、次に runtime/evaluator.ts で Member、Index、pluck がどのように評価されるかを確認してください。現在、要素ノードはそこで内部フィールドを公開しているため、これらのアクセスは null を返すべきです。再現コードの Col.data が [null, null, null, null, [null, null]] になれば完了です。これは library.json フィクスチャを使い、packages/lang-core/src/__tests__/conformance.test.ts で実行される evaluation/ の新しいケースで示します。

索引モデルが issue の本文から書いたものです。

説明

bug

Describe the bug

spec/language.md section 3.1 says: "In an expression, a component instance acts like an object: toNumber gives 0 and member access gives null."

The lang-core evaluator does give 0 for toNumber, but member access on a component instance reads the internal ElementNode fields instead of giving null. card.typeName is "Card", card.props is the props object, card.type is "element", and the same happens with card["props"] and with a pluck over a list of components (cards.typeName). Fields that are not on the node (card.title) do give null, so the result depends on the node's internal shape.

To Reproduce

With the conformance test library (spec/fixtures/1.0/library.json):

root = Stack([Table([c1])])
card = Card("x")
cards = [card, Card("y")]
c1 = Col("m", [card.title, card.typeName, card.props, card["props"], cards.typeName])

Run it through createParser and evaluateRoot (for example as an evaluation/ case under OPENUI_FIXTURES, using the runner in packages/lang-core/src/__tests__/conformance.test.ts).

Col.data is:

[null, "Card", {"title": "x"}, {"title": "x"}, ["Card", "Card"]]

Expected behavior

Per section 3.1, every entry is null:

[null, null, null, null, [null, null]]

A small fix in runtime/evaluator.ts (return null for Member and Index on an element node, and null for element nodes in a pluck) plus an evaluation/ conformance case would cover it. Happy to open a PR once the direction is confirmed.

Additional context

  • @openuidev/lang-core 1.1.1, main at 054b6c4e9.
  • Node 26, no browser involved.
主要言語
TypeScript
スター
10k
フォーク
698
平均マージ
1日 7時間
マージ済み PR(30日)
123

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

thesysdev/openui のほかの issue

thesysdev/openui の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。