Skip to content

Commit ebbd992

Browse files
authored
chore: use typescript to refactor test and fix some bugs(#42)
* style: formate code * chore: disable no-non-null-assertion * chore: test vHtml and vText * chore: set optimize as true in test * style: fix eslint warning * chore: v-model test * fix: v-model has not type should use vModelText * chore: use typescript to refactor test * fix: slots test * feat: support isCustomElement
1 parent 84b006b commit ebbd992

18 files changed

+720
-489
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ module.exports = {
3030
'import/extensions': [2, 'ignorePackages', { ts: 'never' }],
3131
'@typescript-eslint/ban-ts-comment': [0],
3232
'@typescript-eslint/explicit-module-boundary-types': [0],
33-
'@typescript-eslint/no-explicit-any': [0]
33+
'@typescript-eslint/no-explicit-any': [0],
34+
'@typescript-eslint/no-non-null-assertion': [0]
3435
},
3536
settings: {
3637
'import/resolver': {

global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
declare module '*.js';
12
declare module '@babel/helper-module-imports';
23
declare module '@babel/plugin-syntax-jsx';
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
module.exports = {
22
presets: [
3-
[
4-
'@babel/env',
5-
{
6-
// modules: 'cjs',
7-
},
8-
],
3+
'@babel/preset-env',
4+
'@babel/preset-typescript',
95
],
106
plugins: [
117
/* eslint-disable-next-line global-require */
12-
[require('./dist/index.js'), { transformOn: true }],
8+
[require('./dist/index.js'), { optimize: true, isCustomElement: (tag) => /^x-/.test(tag) }],
139
],
1410
};
Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,30 @@
1-
import { createApp, ref, defineComponent } from 'vue';
1+
import { createApp, defineComponent } from 'vue';
22

3-
const SuperButton = (props, context) => {
4-
const obj = {
5-
mouseover: () => {
6-
context.emit('mouseover');
7-
},
8-
click: () => {
9-
context.emit('click');
10-
},
11-
};
12-
return (
13-
<div class={props.class}>
14-
Super
15-
<button
16-
on={obj}
17-
>
18-
{ props.buttonText }
19-
{context.slots.default()}
20-
</button>
21-
</div>
22-
);
23-
};
3+
const Child = defineComponent({
4+
props: ['foo'],
5+
setup(props) {
6+
return () => <div>{props.foo}</div>;
7+
},
8+
});
249

25-
SuperButton.inheritAttrs = false;
10+
Child.inheritAttrs = false;
2611

27-
const App = defineComponent(() => {
28-
const count = ref(0);
29-
const inc = () => {
30-
count.value++;
31-
};
12+
const App = defineComponent({
13+
data: () => ({
14+
test: '1',
15+
}),
16+
render() {
17+
return (
18+
<>
19+
<input type="radio" value="1" v-model={this.test} name="test" />
20+
<input type="radio" value="2" v-model={this.test} name="test" />
21+
</>
22+
);
23+
},
24+
});
3225

33-
const obj = {
34-
click: inc,
35-
mouseover: inc,
36-
};
26+
const app = createApp(App);
3727

38-
return () => (
39-
<div>
40-
Foo {count.value}
41-
<SuperButton
42-
buttonText="VueComponent"
43-
class="xxx"
44-
vShow={true}
45-
on={obj}
46-
>
47-
<button>1234</button>
48-
</SuperButton>
49-
</div>
50-
);
51-
});
28+
app.mount('#app');
5229

53-
createApp(App).mount('#app');
30+
console.log(app);
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
module.exports = {
2-
setupFiles: ['./test/setup.js'],
2+
setupFiles: ['./test/setup.ts'],
3+
transform: {
4+
'\\.(ts|tsx)$': 'ts-jest',
5+
},
6+
globals: {
7+
'ts-jest': {
8+
babelConfig: true,
9+
},
10+
},
311
};

packages/babel-plugin-jsx/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"devDependencies": {
3737
"@babel/core": "^7.0.0",
3838
"@babel/preset-env": "^7.0.0",
39+
"@babel/preset-typescript": "^7.10.4",
3940
"@rollup/plugin-babel": "^5.0.3",
41+
"@types/jest": "^26.0.7",
4042
"@types/svg-tags": "^1.0.0",
4143
"@typescript-eslint/eslint-plugin": "^3.6.1",
4244
"@typescript-eslint/parser": "^3.6.1",
@@ -47,6 +49,7 @@
4749
"jest": "^26.0.1",
4850
"regenerator-runtime": "^0.13.5",
4951
"rollup": "^2.13.1",
52+
"ts-jest": "^26.1.3",
5053
"typescript": "^3.9.6",
5154
"vue": "3.0.0-rc.4",
5255
"webpack": "^4.43.0",

0 commit comments

Comments
 (0)