fkling / astexplorer

A web tool to explore the ASTs generated by various parsers.
https://astexplorer.net/
MIT License
6.21k stars 739 forks source link

Unable to save snippet with empty code #704

Open j4k0xb opened 11 months ago

j4k0xb commented 11 months ago

Describe the bug It's not possible to save or update snippets when the code is empty. I wanna bookmark them to paste the code later.

Error: Unable to create snippet.

To Reproduce Steps to reproduce the behavior:

  1. Go to https://astexplorer.net
  2. Delete the placeholder code
  3. Enable the babelv7 transform
  4. Paste

    export default function (babel) {
    const { types: t } = babel;
    
    return {
    name: "ast-transform", // not required
    visitor: {
      VariableDeclarator(path) {
        const binding = path.scope.getBinding(path.node.id.name);
        if (!binding) return;
        if (!binding.constant) return;
        if (!t.isLiteral(path.node.init)) return;
        binding.referencePaths.forEach(ref => {
          ref.replaceWith(path.node.init);
        });
        path.remove();
      }
    }
    };
    }
  5. Click save

Expected behavior Successfully create a snippet

Screenshots image

Browser (please complete the following information):

astexplorer settings:

Additional context Response: 500 Internal Server Error - Something went wrong