BuilderIO/mitosis

Comments cause crash

Ouverte

#250 ouverte le 28 mars 2022

 (6 commentaires) (0 réaction) (0 personne assignée)TypeScript (411 forks)batch import
buggood first issue

Métriques du dépôt

Stars
 (9 803 étoiles)
Métriques de merge PR
 (Merge moyen 1j 1h) (6 PRs mergées en 30 j)

Description

There are a bunch of different places where comments cause the compiler to crash, because we try to JSON5 parse the given block (and comments aren't JSON5 parse-able).

Describe the bug comments right above function declarations in useState cause endless loop/crash in Mitosis

To Reproduce

import { useState } from "@builder.io/mitosis";

export default function MyComponent(props) {
  const state = useState({
    // a comment
    name: 'steve',

    // another comment
    handleFn() {}
  })
  
  
  return (
    <div>
      <input
        css={{
          color: "red",
        }}
        value={state.name}
        onChange={(event) => state.name = (event.target.value)}
      />
      Hello
      {name}! I can run in React, Vue, Solid, or Liquid!
    </div>
  );
}

If possible, a link to a https://mitosis.builder.io/ fiddle containing the bug: Fiddle causes infinite loop, so I put a code block here instead.

Expected behavior Expect comments to be ignored/stripped before any Mitosis logic runs, and not cause any issues

Additional context The comment above a constant property works fine, but one above a function declaration isn't

Guide contributeur