Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve transpilation error handling for missing closing tags #168

Open
dfabulich opened this issue May 13, 2020 · 0 comments
Open

Improve transpilation error handling for missing closing tags #168

dfabulich opened this issue May 13, 2020 · 0 comments

Comments

@dfabulich
Copy link

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants