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

Incorrect AST generated when a Vue template binding contains a greater than operator #63

Open
prashantpalikhe opened this issue Dec 4, 2023 · 0 comments

Comments

@prashantpalikhe
Copy link

If we have a simple script like this that simulates a Vue attribute binding. And it contains a greater than operator.

// index.mjs
import { parse, walkSync, ELEMENT_NODE, render } from "ultrahtml";

const ast = parse(`<h1 :foo="bar > 1 ? 2 : 1">Hello world!</h1>`);

walkSync(ast, (node) => {
  if (node.type === ELEMENT_NODE && node.name === "script") {
    throw new Error("Found a script!");
  }
});

console.dir(ast, { depth: null });

render(ast).then(console.log);

And if you run this script node index.mjs, the generated AST is incorrect:

<ref *1> {
  type: 0,
  children: [
    <ref *2> {
      type: 1,
      name: 'h1',
      attributes: { ':foo': '"bar' },
      parent: [Circular *1],
      children: [
        {
          type: 2,
          value: ' 1 ? 2 : 1">Hello world!',
          parent: [Circular *2]
        }
      ],
      loc: [ { start: 0, end: 15 }, { start: 39, end: 44 } ]
    },
    { type: 2, value: '', parent: [Circular *1] }
  ]
}

Here you can see the attributes :foo's value is incorrect. It should be bar > 1 ? 2 : 1, but it is just bar.

And, the rendered HTML ends up being incorrect

<h1 :foo=""bar"> 1 ? 2 : 1">Hello world!</h1>

Notice the double "" before bar

prashantpalikhe added a commit to prashantpalikhe/nuxt-ssr-lit that referenced this issue May 9, 2024
`ultrahtml` has some shortcomings e.g.

natemoo-re/ultrahtml#63

This PR switches to using the vue compiler for
ast generation.
prashantpalikhe added a commit to prashantpalikhe/nuxt-ssr-lit that referenced this issue May 9, 2024
`ultrahtml` has some shortcomings e.g.

natemoo-re/ultrahtml#63

This PR switches to using the vue compiler for
ast generation.
prashantpalikhe added a commit to prashantpalikhe/nuxt-ssr-lit that referenced this issue May 9, 2024
`ultrahtml` has some shortcomings e.g.

natemoo-re/ultrahtml#63

This PR switches to using the vue compiler for
ast generation.
prashantpalikhe added a commit to prashantpalikhe/nuxt-ssr-lit that referenced this issue May 9, 2024
`ultrahtml` has some shortcomings e.g.

natemoo-re/ultrahtml#63

This PR switches to using the vue compiler for
ast generation.
prashantpalikhe added a commit to prashantpalikhe/nuxt-ssr-lit that referenced this issue May 9, 2024
`ultrahtml` has some shortcomings e.g.

natemoo-re/ultrahtml#63

This PR switches to using the vue compiler for
ast generation.
prashantpalikhe added a commit to prashantpalikhe/nuxt-ssr-lit that referenced this issue May 9, 2024
`ultrahtml` has some shortcomings e.g.

natemoo-re/ultrahtml#63

This PR switches to using the vue compiler for
ast generation.
prashantpalikhe added a commit to prashantpalikhe/nuxt-ssr-lit that referenced this issue May 9, 2024
`ultrahtml` has some shortcomings e.g.

natemoo-re/ultrahtml#63

This PR switches to using the vue compiler for
ast generation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant