Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Improve transpilation error handling for missing closing tags

未關閉
#168 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
52/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
babel, javascript
領域
build-system

研究方向

執行提供的 shell script 以重現此行為,從 .babelrc 中的 Babel 外掛程式設定和 index.js 輸入開始。將產生的輸出與預期的失敗進行比較:轉譯應拒絕缺少的結束標籤,而不是靜默捨棄 h1 元素。

由索引模型根據 Issue 內容生成。

描述

debugging proposal

Consider this sample code, which accidentally omits a closing tag.

import htm from 'htm'
const h = (type, props, ...children) => ({type, props, children});
const html = htm.bind(h)

console.log(JSON.stringify(html`<h1>Hello, world!`));

In this case, the user intended to include a closing tag </h1>, and so the user's desired logged result is {"type":"h1","props":null,"children":["Hello, world!"]}

Transpile htm away using this script.

shell script
#!/bin/sh -ex

rm -rf babel-htm-errors
mkdir babel-htm-errors
cd babel-htm-errors
npm init -y
npm i -D @babel/cli @babel/core babel-plugin-htm
cat <<EOF > .babelrc
{
  "plugins": [
    ["htm", {
      "pragma": "h"
    }]
  ]
}
EOF
cat <<EOF > index.js
import htm from 'htm'
const h = (type, props, ...children) => ({type, props, children});
const html = htm.bind(h)

console.log(JSON.stringify(html\`<h1>Hello, world!\`));
EOF
npx babel index.js > output.mjs
node output.mjs

Expected: Transpilation should fail with an error.

Actual: The html line transpiles to:

console.log(JSON.stringify("Hello, world!"));

The <h1> tag is silently dropped.

(Note that this error behavior is different from the runtime behavior of htm with mismatching closing tags; see issue #166.)

主要語言
JavaScript
星號
9k
分支
181
PR 合併指標
30 天內沒有已合併 PR

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

developit/htm 的其他 Issue

查看 developit/htm 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。