Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

fix: avoid native tag as component #159

Merged
merged 12 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@vue/reactivity-transform": "^3.3.4",
"@vue/shared": "^3.3.4",
"defu": "^6.1.2",
"html-tags": "^3.3.1",
"magic-string": "^0.30.0",
"unplugin": "^1.3.1"
},
Expand Down
12 changes: 7 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/core/transformScriptSetup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { capitalize } from '@vue/shared'
import type { Node, ObjectExpression, Statement } from '@babel/types'
import { notNullish, partition, uniq } from '@antfu/utils'
import htmlTags from 'html-tags'
import type { ParsedSFC, ScriptSetupTransformOptions } from '../types'
import { applyMacros } from './macros'
import { getIdentifierDeclarations } from './identifiers'
Expand Down Expand Up @@ -54,7 +55,9 @@ export function transformScriptSetup(
return t.objectProperty(id, id, false, true)
})

const pascalizeHtmlTags = htmlTags.map(pascalize)
const components = Array.from(template.components)
.filter(component => !pascalizeHtmlTags.includes(component))
.map(
component =>
declarationArray.find(declare => declare === component)
Expand Down
27 changes: 27 additions & 0 deletions test/__snapshots__/transform.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,33 @@ export default __sfc_main;
"
`;

exports[`transform > fixtures > test/fixtures/HtmlTag.vue 1`] = `
"<script lang=\\"ts\\">
import Enum from './Enum.vue';
import { ref } from '@vue/composition-api';
const __sfc_main = {};
__sfc_main.setup = (__props, __ctx) => {
let p = \\"hello word\\";
let div = ref(\\"hello word\\");
return {
p
};
};
__sfc_main.components = Object.assign({
Enum
}, __sfc_main.components);
export default __sfc_main;
</script>

<template>
<div>
<Enum/>
<p>{{ p }}</p>
</div>
</template>
"
`;

exports[`transform > fixtures > test/fixtures/JSLongComment.vue 1`] = `
"<script lang=\\"ts\\">
const __sfc_main = {};
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/HtmlTag.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script setup lang="ts">
import Enum from './Enum.vue';
import { ref } from '@vue/composition-api';
let p = "hello word";
let div = ref("hello word");
</script>

<template>
<div>
<Enum/>
<p>{{ p }}</p>
</div>
</template>