File tree Expand file tree Collapse file tree 8 files changed +74
-8
lines changed Expand file tree Collapse file tree 8 files changed +74
-8
lines changed Original file line number Diff line number Diff line change 1-
21coverage
32dist
4- node_modules
3+ node_modules
4+ node_modules_back
Original file line number Diff line number Diff line change 1+ ## 1.1.9
2+
3+ - fix: props name style is kebab case type error
4+ - fix: not found: Error: Can't resolve 'vue-class-setup'
5+
16## 1.1.8
27
38- fix: Set props default error
9+
410## 1.1.7
511
612- docs: Optimize document picture capitalization
Original file line number Diff line number Diff line change 11{
22 "name" : " vue-class-setup" ,
3- "version" : " 1.1.8 " ,
4- "main" : " dist/index.js" ,
3+ "version" : " 1.1.9 " ,
4+ "main" : " dist/index.cjs. js" ,
55 "module" : " dist/index.es.js" ,
66 "types" : " dist/index.d.ts" ,
77 "repository" :
" [email protected] :fmfe/vue-class-setup.git" ,
1515 "node" : " ./dist/index.mjs" ,
1616 "default" : " ./dist/index.es.js"
1717 },
18- "require" : " ./dist/index.js"
18+ "require" : " ./dist/index.cjs. js"
1919 },
2020 "./package.json" : " ./package.json"
2121 },
Original file line number Diff line number Diff line change 22
33rm -rf node_modules
44yarn install
5+ yarn lint
56yarn run build
67yarn run coverage
78
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ export function initDefine(target: InstanceType<DefineConstructor>) {
6868 let value = props [ k ] ;
6969
7070 if ( typeof value === 'boolean' ) {
71- if ( ! hasValue ( target . $vm , k ) ) {
71+ if ( ! hasDefaultValue ( target . $vm , k ) ) {
7272 value = target . $defaultProps [ k ] ;
7373 }
7474 } else if ( isNull ( value ) ) {
@@ -80,19 +80,29 @@ export function initDefine(target: InstanceType<DefineConstructor>) {
8080 } ) ;
8181}
8282
83- function hasValue ( vm : VueInstance , key : string ) : boolean {
83+ function hasDefaultValue ( vm : VueInstance , key : string ) : boolean {
8484 let props : Record < string , any > | null = null ;
8585 if ( isVue2 ) {
8686 props = vm . $options && vm . $options [ 'propsData' ] ;
8787 } else {
8888 props = vm . $ && vm . $ . vnode && vm . $ . vnode . props ;
8989 }
9090 if ( props ) {
91- return ! isNull ( props [ key ] ) ;
91+ return ! isNull ( props [ key ] || props [ kebabCase ( key ) ] ) ;
9292 }
9393 return false ;
9494}
9595
9696function isNull ( value : unknown ) {
9797 return typeof value === 'undefined' || value === null ;
9898}
99+
100+ const KEBAB_REGEX = / [ A - Z ] / g;
101+
102+ function kebabCase ( str : string ) {
103+ return str
104+ . replace ( KEBAB_REGEX , ( match ) => {
105+ return '-' + match . toLowerCase ( ) ;
106+ } )
107+ . replace ( / ^ - / , '' ) ;
108+ }
Original file line number Diff line number Diff line change 1+ <script lang="ts">
2+ import { defineComponent } from ' vue' ;
3+ import { Setup , Define } from ' vue-class-setup' ;
4+
5+ @Setup
6+ class App extends Define <Props , Emit > {}
7+ </script >
8+ <script lang="ts" setup>
9+ export interface Props {
10+ NameOne: string ;
11+ nameAndAge: number ;
12+ sSSS: number ;
13+ }
14+
15+ export interface Emit {
16+ (event : ' click' ): void ;
17+ }
18+
19+ defineProps <Props >();
20+ defineEmits <Emit >();
21+
22+ const app = new App ();
23+ </script >
24+ <template >
25+ <p class =" name" >{{ app.NameOne }}</p >
26+ <p class =" name-and-age" >{{ app.nameAndAge }}</p >
27+ <p class =" ssss" >{{ app.sSSS }}</p >
28+ </template >
Original file line number Diff line number Diff line change 1+ <script lang="ts" setup>
2+ import KebabCasePropsChild from ' ./kebab-case-props-child.vue' ;
3+ </script >
4+ <template >
5+ <KebabCasePropsChild
6+ NameOne =" vue-class-setup"
7+ :name-and-age =" 100"
8+ :s-s-s-s =" 50"
9+ />
10+ </template >
Original file line number Diff line number Diff line change 1+ import { assert , test } from 'vitest' ;
2+ import { mount } from '@vue/test-utils' ;
3+
4+ import KebabCasePropsParent from './kebab-case-props-parent.vue' ;
5+
6+ test ( 'Base' , async ( ) => {
7+ const wrapper = mount ( KebabCasePropsParent ) ;
8+ assert . equal ( wrapper . find ( '.name' ) . text ( ) , 'vue-class-setup' ) ;
9+ assert . equal ( wrapper . find ( '.name-and-age' ) . text ( ) , '100' ) ;
10+ assert . equal ( wrapper . find ( '.ssss' ) . text ( ) , '50' ) ;
11+ } ) ;
You can’t perform that action at this time.
0 commit comments