Improve transpilation error handling for missing closing tags
- Vorherrschende Sprache
- JavaScript
- Sterne
- 9k
- Forks
- 181
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Consider this sample code, which accidentally omits a closing tag.
```js
import htm from 'htm'
const h = (type, props, ...children) => ({type, props, children});
const html = htm.bind(h)
console.log(JSON.stringify(html`
Hello, world!`));
```
In this case, the user intended to include a closing tag ``, and so the user's desired logged result is `{"type":"h1","props":null,"children":["Hello, world!"]}`
Transpile `htm` away using this script.
shell script
```sh
#!/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 < .babelrc
{
"plugins": [
["htm", {
"pragma": "h"
}]
]
}
EOF
cat < index.js
import htm from 'htm'
const h = (type, props, ...children) => ({type, props, children});
const html = htm.bind(h)
console.log(JSON.stringify(html\`
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:
```js
console.log(JSON.stringify("Hello, world!"));
```
The `
` tag is silently dropped.
(Note that this error behavior is different from the runtime behavior of htm with mismatching closing tags; see issue #166.)
Beitragsleitfaden
Rechercherichtung
Führen Sie das bereitgestellte Shell-Skript aus, um das Verhalten zu reproduzieren, beginnend mit der Babel-Plugin-Konfiguration in .babelrc und der Eingabe in index.js. Vergleichen Sie die generierte Ausgabe mit dem erwarteten Fehler: Die Transpilierung sollte das fehlende schließende Tag zurückweisen, anstatt das h1-Element stillschweigend zu entfernen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- babel, javascript
- Bereich
- build-system
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 52/100