UnrefinedBrain / vue-metamorph

AST-based Codemod Framework for Vue projects
https://vue-metamorph.dev/
MIT License
87 stars 1 forks source link

Found some parsing/transform issues #59

Closed adrienWeiss closed 5 months ago

adrienWeiss commented 5 months ago

Hi again checking the tool against a large codebase, I found a few issues that you may want to look into :

double setup in test plugin

something looks not right here, looks like the transformer is always adding a setup attribute (although it's just the stringLiteralPlugin test plugin at fault here) https://github.com/UnrefinedBrain/vue-metamorph/blob/6cc36972d83ec53a4dc1e0bbb4ca176875f926ba/src/transform.spec.ts#L169-L172

cannot parse empty script tag

this is not critical but I think an empty script tag is technically legit

it('should not fail when the script tag is empty', () => {
    const i = `<template>
      <div>
        Hi
      </div>
    </template>
    <script></script>
    `;

    expect(transform(i, 'file.vue', [stringLiteralPlugin]).code).toMatchInlineSnapshot(`
      "<template>
            <strong hi>
              Hi
            </strong>
          </template>
          <script></script>
          "
    `);
  });

this raises an error Serialized Error: { code: 'BABEL_PARSER_SYNTAX_ERROR', reasonCode: 'UnterminatedRegExp'

using v-bind in style blocks

For this one I'm not entirely sure,

it('can use v-bind in CSS', () => {
    const i = `
      <template>
        <div class="className">
          Hi 
        </div>
      </template>
      <script setup>
      import { ref } from 'vue';
      const color = ref('red');
      </script>
      <style lang="css" scoped>
      .className {
        color: v-bind(color);
      }
      </style>
      `;

    expect(transform(i, 'file.vue', []).code).toMatchInlineSnapshot();
  });

this raises errors in the tests, but on my codebase it only fails when using v-bind in another css function, such as clamp(10px, v-bind(myVar), 100px); 🤔 Anyhow I guess it's more related to postcss than vue-metamorph, but I figured you'd want to know just in case

Cheers

UnrefinedBrain commented 5 months ago

I fixed the 2nd and 3rd errors - thanks for reporting them.

Less concerned about the test codemod at the moment- I've been working on writing some better tests so that'll go away eventually

adrienWeiss commented 5 months ago

I can happily report 0 error when running it (without any plugin) on 1484 files 🎉

we'll do our best to report (& fix) any upcoming issues running vue-upgrade-tool plugins soon