Skip to content

Commit

Permalink
test: add cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zcf0508 committed Jul 12, 2024
1 parent 46a3f05 commit 34c1aab
Show file tree
Hide file tree
Showing 20 changed files with 1,646 additions and 91 deletions.
120 changes: 120 additions & 0 deletions fixtures/vue/options-base-2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<h1>{{ msg }}</h1>

<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank">VSCode</a>
+
<a href="https://marketplace.visualstudio.com/items?itemName=octref.vetur" target="_blank"> Vetur </a>
or
<a href="https://github.com/johnsoncodehk/volar" target="_blank">Volar</a>
(if using
<code>&lt;script setup&gt;</code>)
</p>

<p>See <code>README.md</code> for more information.</p>

<p>
<a href="https://vitejs.dev/guide/features.html" target="_blank"> Vite Docs </a>
|
<a href="https://v3.vuejs.org/" target="_blank">Vue 3 Docs</a>
</p>

<button type="button" @click="plus">
count is: {{ count }}
</button>
<p class="my-2">
<label for="number_input">
<input
id="number_input"
v-model="number"
w:p="l-2"
w:border="~ gray-100"
w:appearance="none"
w:outline="focus:none"
type="number"
>
</label>
<button
w:m="l-2"
w:p="x-2"
w:bg="green-500"
w:text="white"
w:rounded="~"
@click="add"
>
ADD
</button>
</p>
<p>
Edit
<code>components/HelloWorld.vue</code> to test hot module replacement.
</p>
</template>

<script lang="ts">
export default {
name: 'TestComponent',
props: {
msg: {
type: String,
required: true,
},
},
data: function() {
return {
number: 0,
}
},
computed: {
count:()=> {
return counterStore.count
}
},
methods: {
plus:()=> {
counterStore.increment();
this.plus();
},
add() {
counterStore.add(Number(this.number));
this.add();
}
},
provide() {
return {
count: this.count,
number: this.number
}
},
watch: {
'count': {
handler:()=> {
console.log(this.number)
},
}
},
created: function() {
this.add()
console.log(this.number)
}
}
</script>

<style scoped>
a {
color: #42b983;
}
label {
margin: 0 0.5em;
font-weight: bold;
}
code {
background-color: #eee;
padding: 2px 4px;
border-radius: 4px;
color: #304455;
}
</style>
2 changes: 1 addition & 1 deletion fixtures/vue/options-base-jsx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
add() {
counterStore.add(Number(this.number));
this.add();
this.plus();
}
},
provide() {
Expand Down
60 changes: 60 additions & 0 deletions fixtures/vue/options-base-jsx2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script lang="tsx">
export default {
name: 'TestComponent',
props: {
msg: {
type: String,
required: true,
},
},
data: function() {
return {
number: 0,
}
},
computed: {
count:()=> {
return counterStore.count
}
},
methods: {
plus:()=> {
counterStore.increment();
this.plus();
},
add() {
counterStore.add(Number(this.number));
this.add();
}
},
provide() {
return {
count: this.count,
}
},
render(){
return (<div>
<div>{this.count}</div>
<button onClick={this.plus}></button>
</div>)
}
}
</script>
<style scoped>
a {
color: #42b983;
}
label {
margin: 0 0.5em;
font-weight: bold;
}
code {
background-color: #eee;
padding: 2px 4px;
border-radius: 4px;
color: #304455;
}
</style>
11 changes: 9 additions & 2 deletions fixtures/vue/options-base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@
},
}
},
provide() {
return {
count: this.count,
number: this.number
}
},
created() {
console.log(this.count)
}
this.add()
console.log(this.number)
},
}
</script>

Expand Down
34 changes: 29 additions & 5 deletions fixtures/vue/options-setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,59 @@ export default {
},
setup() {
const data = reactive({
...{
a: 1
},
a: 2,
/** 这是注释 */number: 0,
});
const count = computed(() => counterStore.count);
const dataNumber = computed(() => data.number);
const number = count.value
const methods = {
...{
a: 1
},
a: 2,
plus: ()=> {
counterStore.increment();
methods.plus();
},
add() {
counterStore.add(Number(data.number));
methods.add();
console.log(count)
}
};
function add() {
counterStore.add(Number(data.number));
methods.plus();
console.log(count)
return count;
}
const a = {count};
const b = {count: count.value};
const [userinfo, setUserinfo] = useUserinfo(a, b.count, data.number)
const { userinfo2 } = useUserinfo2(a, b.count, data.number)
const ComponentD = () => (<>hello d</>);
const msgRef = ref();
return {
...toRefs(data),
number,
b,
c: count,
dataNumber,
...methods,
ComponentD,
msgRef,
add,
userinfo,
userinfo2,
}
}
Expand Down
43 changes: 43 additions & 0 deletions fixtures/vue/setup-block.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { add } from 'lodash-es';
const props = defineProps({
msg: String
})
Expand Down Expand Up @@ -42,6 +44,13 @@ function funA() {
}
const { varB } = funA()
const varB2 = varB
const ddd = {
getDdd: () => varB.value
}
/** 这是注释 */
function funC(varB) { // 这是注释
const varD = 1
Expand All @@ -62,15 +71,49 @@ const props1 = withDefaults(defineProps<{test: number}>(), {
provide('funC', funC)
const [userinfo, setUserinfo] = useUserinfo(a, b.count)
const aaa1 = ref(0)
const bbb2 = computed(() => aaa1.value + 2)
const cc333 = computed(() => bbb2.value + 2)
const updateBBB = () => {
if(cc333.value< 20) {
aaa1.value = aaa1.value + ddd.getDdd()
}
}
const ddd4 = ref(1)
const eee5 = computed(() => ddd4.value * 2)
const add1111 = ref(1111)
function add2222(){
add1111.value = add1111 ++
}
const add333 =() => {
add2222()
}
const add4444 =() => {
add333()
}
</script>

<template>
<div>
<input v-model="lmsg" />
<div>{{ `path: ${path}` }}</div>
{{ age }}
{{ userinfo }}
<input :value="data['name' as string]" @input="updateName" />
<button @click="addAge"></button>
<button @click="add4444"></button>
</div>
</template>

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFileSync } from 'node:fs';
import { basename } from 'node:path';
import { inspect } from 'node:util';
import fg from 'fast-glob';
import { analyzeOptions, analyzeSetupScript, analyzeStyle, analyzeTemplate, analyzeTsx, parse } from '@/index';

Expand All @@ -13,7 +14,6 @@ describe('fixtures', async () => {
const source = readFileSync(test, 'utf-8');
if (framework === 'vue') {
const sfc = parse(source);

const nodesUsedInStyle = analyzeStyle(sfc.descriptor.styles || []);

if (test.includes('tsx')) {
Expand Down
Loading

0 comments on commit 34c1aab

Please sign in to comment.