This repository was archived by the owner on Dec 25, 2024. It is now read-only.
Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork41
fix: avoid native tag as component#159
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
12 commits Select commitHold shift + click to select a range
dca9435
fix: avoid HTML elements as component
jaw528d18abd
test: add more test cases
jaw5246f677c
test: add more
jaw52a703fb6
test: add svg
jaw524c19212
chore: update
jaw52f65a253
fix: case mode correction
jaw52ee95ee0
chore: update test snap
jaw52c09c884
chore: lint
jaw527cfbf97
chore: update test
jaw523bbbfcc
chore: lint
jaw52033d4ec
chore: add set
jaw5278086ad
chore: to LF
jaw52File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 3 additions & 1 deletionplayground/src/App.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletionsplayground/src/ButtonTest.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script setup lang="ts"> | ||
import Button from './Foo.vue'; | ||
import button from './Foo.vue'; | ||
</script> | ||
<template> | ||
<div> | ||
<button>{{ Button }}</button> | ||
<Button>{{ button }}</Button> | ||
</div> | ||
</template> |
7 changes: 6 additions & 1 deletionplayground/src/Foo.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
<template> | ||
<div> | ||
Button Component: <slot></slot> | ||
</div> | ||
</template> |
1 change: 1 addition & 0 deletionssrc/core/parseSFC.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletionsrc/core/transformScriptSetup.ts
xiaoxiangmoe marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionssrc/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
109 changes: 107 additions & 2 deletionstest/__snapshots__/transform.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,6 +3,7 @@ | ||
exports[`transform > fixtures > playground/src/App.vue 1`] = ` | ||
"<script lang=\\"ts\\"> | ||
import { defineAsyncComponent } from '@vue/composition-api'; | ||
import ButtonTest from './ButtonTest.vue'; | ||
import HelloWorld from './HelloWorld.vue'; | ||
const AsyncComponent = defineAsyncComponent(() => import('./Async.vue')); | ||
const __sfc_main = {}; | ||
@@ -16,13 +17,16 @@ __sfc_main.setup = (__props, __ctx) => { | ||
}; | ||
}; | ||
__sfc_main.components = Object.assign({ | ||
ButtonTest, | ||
HelloWorld, | ||
AsyncComponent | ||
}, __sfc_main.components); | ||
export default __sfc_main; | ||
</script> | ||
<template> | ||
<div> | ||
<ButtonTest /> | ||
<HelloWorld name=\\"Vue 2\\" @update=\\"onUpdate\\" /> | ||
<AsyncComponent /> | ||
@@ -45,9 +49,41 @@ exports[`transform > fixtures > playground/src/Bar.vue 1`] = ` | ||
" | ||
`; | ||
exports[`transform > fixtures > playground/src/ButtonTest.vue 1`] = ` | ||
"<script lang=\\"ts\\"> | ||
import Button from './Foo.vue'; | ||
import button from './Foo.vue'; | ||
const __sfc_main = {}; | ||
__sfc_main.setup = (__props, __ctx) => { | ||
return { | ||
Button, | ||
button | ||
}; | ||
}; | ||
__sfc_main.components = Object.assign({ | ||
Button | ||
}, __sfc_main.components); | ||
export default __sfc_main; | ||
</script> | ||
<template> | ||
<div> | ||
<button>{{ Button }}</button> | ||
<Button>{{ button }}</Button> | ||
</div> | ||
</template> | ||
" | ||
`; | ||
exports[`transform > fixtures > playground/src/Foo.vue 1`] = ` | ||
"<script lang=\\"ts\\"> | ||
const __sfc_main = {}; | ||
export default __sfc_main; | ||
</script> | ||
<template> | ||
<div> | ||
Button Component: <slot></slot> | ||
</div> | ||
</template> | ||
" | ||
`; | ||
@@ -330,6 +366,75 @@ 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\\"); | ||
let h3 = 'test'; | ||
let H3 = ''; | ||
return { | ||
p, | ||
Div, | ||
h3, | ||
H3 | ||
}; | ||
}; | ||
__sfc_main.components = Object.assign({ | ||
Enum | ||
}, __sfc_main.components); | ||
export default __sfc_main; | ||
</script> | ||
<template> | ||
<div> | ||
<Enum /> | ||
<h3></h3> | ||
{{ H3 }} | ||
{{ h3 }} | ||
{{ Div }} | ||
<p>{{ p }}</p> | ||
</div> | ||
</template> | ||
" | ||
`; | ||
exports[`transform > fixtures > test/fixtures/HtmlTag2.vue 1`] = ` | ||
"<script lang=\\"ts\\"> | ||
import Button from './DynamicStyle.vue'; | ||
import button from './DynamicStyle.vue'; | ||
import { defineAsyncComponent } from '@vue/composition-api'; | ||
const footer = defineAsyncComponent(() => import('./ScriptOnly.vue')); | ||
import { ref } from '@vue/composition-api'; | ||
const __sfc_main = {}; | ||
jaw52 marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
__sfc_main.setup = (__props, __ctx) => { | ||
const p = ref(\\"hello word\\"); | ||
return { | ||
Button, | ||
button, | ||
p | ||
}; | ||
}; | ||
__sfc_main.components = Object.assign({ | ||
Button | ||
}, __sfc_main.components); | ||
export default __sfc_main; | ||
</script> | ||
<template> | ||
<div> | ||
<p>{{ p }}</p> | ||
<button>{{ Button }}</button> | ||
<Button>{{ button }}</Button> | ||
<footer>FOOTER</footer> | ||
</div> | ||
</template> | ||
" | ||
`; | ||
exports[`transform > fixtures > test/fixtures/JSLongComment.vue 1`] = ` | ||
"<script lang=\\"ts\\"> | ||
const __sfc_main = {}; | ||
20 changes: 20 additions & 0 deletionstest/fixtures/HtmlTag.vue
xiaoxiangmoe marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script setup lang="ts"> | ||
import Enum from './Enum.vue' | ||
import { ref } from '@vue/composition-api'; | ||
let p = "hello word"; | ||
let Div = ref("hello word"); | ||
let h3 = 'test' | ||
let H3 = '' | ||
</script> | ||
<template> | ||
<div> | ||
<Enum /> | ||
<h3></h3> | ||
{{ H3 }} | ||
{{ h3 }} | ||
{{ Div }} | ||
<p>{{ p }}</p> | ||
</div> | ||
</template> |
20 changes: 20 additions & 0 deletionstest/fixtures/HtmlTag2.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<script setup lang="ts"> | ||
import Button from './DynamicStyle.vue'; | ||
import button from './DynamicStyle.vue'; | ||
import { defineAsyncComponent } from '@vue/composition-api' | ||
const footer = defineAsyncComponent(() => import('./ScriptOnly.vue')) | ||
import { ref } from '@vue/composition-api'; | ||
const p = ref("hello word"); | ||
</script> | ||
<template> | ||
<div> | ||
<p>{{ p }}</p> | ||
<button>{{ Button }}</button> | ||
<Button>{{ button }}</Button> | ||
<footer>FOOTER</footer> | ||
</div> | ||
</template> |
2 changes: 2 additions & 0 deletionstest/identifiers.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletionstest/nativeTag.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { transform } from '../src' | ||
describe('filter native tags as vue components', () => { | ||
describe('no components output', () => { | ||
const cases: string[] = [ | ||
` | ||
<script setup lang="ts"> | ||
import button from './DynamicStyle.vue'; | ||
</script> | ||
<template> | ||
<button>{{ Button }}</button> | ||
</template> | ||
`, | ||
` | ||
<script setup lang="ts"> | ||
let p='hello' | ||
let Div='hello' | ||
</script> | ||
<template> | ||
<div> | ||
<p>{{ p }}</p> | ||
<Button>{{ Div }}</Button> | ||
</div> | ||
</template> | ||
`, | ||
` | ||
<script setup lang="ts"> | ||
let svg='hello' | ||
</script> | ||
<template> | ||
<div> | ||
<p>{{ svg }}</p> | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 283.46 283.46"> | ||
<defs> | ||
<style> | ||
.cls-1{fill:#231815;} | ||
@media (prefers-color-scheme: dark) { .cls-1{fill:#ffffff;} } | ||
</style> | ||
</defs> | ||
<path class="cls-1" d="M144.89,89.86c-33.46,0-54.44,14.56-66.14,26.76a86,86,0,0,0-23.69,58.94c0,22.64,8.81,43.48,24.8,58.67,15.7,14.92,36.9,23.14,59.68,23.14,23.81,0,46-8.49,62.49-23.91,17-15.9,26.37-37.93,26.37-62C228.4,120.37,185.94,89.86,144.89,89.86Zm.49,153.67a61.49,61.49,0,0,1-46.45-20.4c-12.33-13.76-18.85-32.64-18.85-54.62,0-20.7,6.07-37.67,17.57-49.07,10.11-10,24.39-15.62,40.19-15.74,19,0,35.22,6.56,46.76,19,12.6,13.58,19.27,34,19.27,58.95C203.87,224.39,174.49,243.53,145.38,243.53Z"/> | ||
<polygon class="cls-1" points="198.75 74.96 179.45 74.96 142.09 37.83 104.51 74.96 86.14 74.96 138.09 24.25 146.81 24.25 198.75 74.96"/> | ||
</svg> | ||
</div> | ||
</template> | ||
`, | ||
] | ||
for (const input of cases) { | ||
it(input, async () => { | ||
const result = await transform(input, 'Lang.vue', { reactivityTransform: true }) | ||
expect(result?.code.includes('__sfc_main.components')).toEqual(false) | ||
}) | ||
} | ||
}) | ||
it('capitalized native tags as components', async () => { | ||
const input = ` | ||
<script setup lang="ts"> | ||
import Button from './DynamicStyle.vue'; | ||
</script> | ||
<template> | ||
<Button>{{ Button }}</Button> | ||
</template> | ||
` | ||
const result = await transform(input, 'Lang.vue', { reactivityTransform: true }) | ||
expect(result?.code.includes('__sfc_main.components = Object.assign({\n Button\n}, __sfc_main.components);')).toEqual(true) | ||
}) | ||
it('keep non-native components', async () => { | ||
const input = ` | ||
<script setup lang="ts"> | ||
import Button from './DynamicStyle.vue'; | ||
import DynamicStyle from './DynamicStyle.vue'; | ||
let p='hello' | ||
</script> | ||
<template> | ||
<dynamic-style/> | ||
<p>{{ p }}</p> | ||
<button>{{ Button }}</button> | ||
</template> | ||
` | ||
const result = await transform(input, 'Lang.vue', { reactivityTransform: true }) | ||
expect(result?.code.includes('__sfc_main.components = Object.assign({\n DynamicStyle\n}, __sfc_main.components);')).toEqual(true) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.