opentiny / tiny-vue-playground

tiny-vue playground,support both Vue.js 2 and Vue.js 3,support JSX and TSX,support Less
https://opentiny.github.io/tiny-vue-playground/
MIT License
20 stars 12 forks source link

An error is still reported when the JSX example is loaded. #12

Open zzcr opened 1 year ago

zzcr commented 1 year ago

error tips: Identifier '_createVNode' has already been declared. (119:66)

mengqiuleo commented 1 year ago

能否给个demo链接?

mengqiuleo commented 1 year ago

出现这种报错的原因是:babel 转义 JSX 时,会导入一些依赖,比如:import createVNode as _createVNode, 同样的,vue在生成 render函数时,也会导入一些依赖,导致 _createVNode 被导入了两次

我目前的解决办法是,将 babel 的导入语句和 vue 的导入语句合并,相关代码在这:extractVueImportmergeVueImports 主要依靠 extractVueImportmergeVueImports 这两个函数,

可能我对于一些 边缘case 没有考虑到,能否给个 demo

zzcr commented 1 year ago

https://opentiny.github.io/tiny-vue-playground/#eyJzcmMvQXBwLnZ1ZSI6Ijx0ZW1wbGF0ZT5cbiAgPHRpbnktZ3JpZCA6ZGF0YT1cInRhYmxlRGF0YVwiIGJvcmRlciA6ZWRpdC1jb25maWc9XCJ7IHRyaWdnZXI6ICdjbGljaycsIG1vZGU6ICdjZWxsJywgc2hvd1N0YXR1czogdHJ1ZSB9XCI+XG4gICAgPHRpbnktZ3JpZC1jb2x1bW4gdHlwZT1cImluZGV4XCIgd2lkdGg9XCI2MFwiPjwvdGlueS1ncmlkLWNvbHVtbj5cbiAgICA8dGlueS1ncmlkLWNvbHVtbiB0eXBlPVwic2VsZWN0aW9uXCIgd2lkdGg9XCI2MFwiPjwvdGlueS1ncmlkLWNvbHVtbj5cbiAgICA8dGlueS1ncmlkLWNvbHVtbiBmaWVsZD1cImVtcGxveWVlc1wiIHRpdGxlPVwi5ZGY5bel5pWwXCI+PC90aW55LWdyaWQtY29sdW1uPlxuICAgIDx0aW55LWdyaWQtY29sdW1uIGZpZWxkPVwiY3JlYXRlZERhdGVcIiB0aXRsZT1cIuWIm+W7uuaXpeacn1wiPjwvdGlueS1ncmlkLWN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biAgICAgICAgY2l0eTogJ+i1pOWjgScsXG4gICAgICAgIGVtcGxveWVlczogNDAwLFxuICAgICAgICBjcmVhdGVkRGF0ZTogJzIwMTYtMDQtMzAgMjM6NTY6MDAnLFxuICAgICAgICBib29sZTogZmFsc2VcbiAgICAgIH0sXG4gICAgICB7XG4gICAgICAgIGlkOiAnOCcsXG4gICAgICAgIG5hbWU6ICfmt7HlnLPluILnpo/lvrflrp3nvZHnu5zmioDmnK9ZWOWFrOWPuCcsXG4gICAgICAgIGJvb2xlOiB0cnVlLFxuICAgICAgICBjaXR5OiAn5Y6m6ZeoJyxcbiAgICAgICAgY3JlYXRlZERhdGU6ICcyMDE2LTA2LTAzIDEzOjUzOjI1JyxcbiAgICAgICAgZW1wbG95ZWVzOiA1NDBcbiAgICAgIH1cbiAgICBdXG4gICAgcmV0dXJuIHtcbiAgICAgIG9wOiB7XG4gICAgICAgIGVkaXRDb25maWc6IHtcbiAgICAgICAgICB0cmlnZ2VyOiAnY2xpY2snLFxuICAgICAgICAgIG1vZGU6ICdjZWxsJyxcbiAgICAgICAgICBzaG93U3RhdHVzOiB0cnVlXG4gICAgICAgIH0sXG4gICAgICAgIGNvbHVtbnM6IFtcbiAgICAgICAgICB7XG4gICAgICAgICAgICB0eXBlOiAnaW5kZXgnLFxuICAgICAgICAgICAgd2lkdGg6IDYwXG4gICAgICAgICAgfSxcbiAgICAgICAgICB7XG4gICAgICAgICAgICB0eXBlOiAnc2VsZWN0aW9uJyxcbiAgICAgICAgICAgIHdpZHRoOiA2MFxuICAgICAgICAgIH0sXG4gICAgICAgICAge1xuICAgICAgICAgICAgZmllbGQ6ICdlbXBsb3llZXMnLFxuICAgICAgICAgICAgdGl0bGU6ICflkZjlt6XmlbAnXG4gICAgICAgICAgfSxcbiAgICAgICAgICB7XG4gICAgICAgICAgICBmaWVsZDogJ2NyZWF0ZWREYXRlJyxcbiAgICAgICAgICAgIHRpdGxlOiAn5Yib5bu65pel5pyfJ1xuICAgICAgICAgIH0sXG4gICAgICAgICAge1xuICAgICAgICAgICAgZmllbGQ6ICdjaXR5JyxcbiAgICAgICAgICAgIHRpdGxlOiAn5Z+O5biCJ1xuICAgICAgICAgIH0sXG4gICAgICAgICAge1xuICAgICAgICAgICAgZmllbGQ6ICdib29sZScsXG4gICAgICAgICAgICB0aXRsZTogJ+W4g+WwlOWAvCcsXG4gICAgICAgICAgICBhbGlnbjogJ2NlbnRlcicsXG4gICAgICAgICAgICBmb3JtYXRUZXh0OiAnYm9vbGUnLFxuICAgICAgICAgICAgZWRpdG9yOiB0aGlzLmNoZWNrYm94RWRpdFxuICAgICAgICAgIH1cbiAgICAgICAgXSxcbiAgICAgICAgZGF0YTogdGFibGVEYXRhXG4gICAgICB9LFxuICAgICAgdGFibGVEYXRhXG4gICAgfVxuICB9LFxuICBtZXRob2RzOiB7XG4gICAgY2hlY2tib3hFZGl0KGgsIHsgcm93IH0pIHtcbiAgICAgIHJldHVybiAoXG4gICAgICAgIDxpbnB1dFxuICAgICAgICAgIHR5cGU9XCJjaGVja2JveFwiXG4gICAgICAgICAgY2hlY2tlZD17cm93LmJvb2xlfVxuICAgICAgICAgIG9uQ2hhbmdlPXsoZXZlbnQpID0+IHtcbiAgICAgICAgICAgIHJvdy5ib29sZSA9IGV2ZW50LnRhcmdldC5jaGVja2VkXG4gICAgICAgICAgfX1cbiAgICAgICAgLz5cbiAgICAgIClcbiAgICB9XG4gIH1cbn1cbjwvc2NyaXB0PlxuIiwiaW1wb3J0LW1hcC5qc29uIjoie1xuICBcImltcG9ydHNcIjoge31cbn0iLCJ0c2NvbmZpZy5qc29uIjoie1xuICBcImNvbXBpbGVyT3B0aW9uc1wiOiB7XG4gICAgXCJhbGxvd0pzXCI6IHRydWUsXG4gICAgXCJjaGVja0pzXCI6IHRydWUsXG4gICAgXCJqc3hcIjogXCJwcmVzZXJ2ZVwiLFxuICAgIFwidGFyZ2V0XCI6IFwiRVNOZXh0XCIsXG4gICAgXCJtb2R1bGVcIjogXCJFU05leHRcIixcbiAgICBcIm1vZHVsZVJlc29sdXRpb25cIjogXCJCdW5kbGVyXCIsXG4gICAgXCJhbGxvd0ltcG9ydGluZ1RzRXh0ZW5zaW9uc1wiOiB0cnVlXG4gIH0sXG4gIFwidnVlQ29tcGlsZXJPcHRpb25zXCI6IHtcbiAgICBcInRhcmdldFwiOiAzLjNcbiAgfVxufVxuIiwiX28iOnt9fQ==

zzcr commented 1 year ago

错误的链接已发

mengqiuleo commented 1 year ago

问题已修复