File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
packages/babel-plugin-jsx/src Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 11import * as t from '@babel/types' ;
22import { type NodePath } from '@babel/traverse' ;
3- import { createIdentifier } from './utils' ;
3+ import { camelize , capitalize , createIdentifier } from './utils' ;
44import type { State } from './interface' ;
55
66export type Tag =
@@ -184,8 +184,7 @@ const resolveDirective = (
184184 }
185185 return modelToUse ;
186186 }
187- const referenceName =
188- 'v' + directiveName [ 0 ] . toUpperCase ( ) + directiveName . slice ( 1 ) ;
187+ const referenceName = 'v' + capitalize ( camelize ( directiveName ) ) ;
189188 let scope = path . scope ;
190189 do {
191190 if ( scope . references [ referenceName ] ) {
Original file line number Diff line number Diff line change @@ -254,6 +254,14 @@ const onRE = /^on[^a-z]/;
254254
255255export const isOn = ( key : string ) => onRE . test ( key ) ;
256256
257+ const camelizeRE = / - ( \w ) / g;
258+ export const camelize = ( str : string ) : string => {
259+ return str . replace ( camelizeRE , ( _ , c ) => ( c ? c . toUpperCase ( ) : '' ) ) ;
260+ } ;
261+ export const capitalize = < T extends string > ( str : T ) : Capitalize < T > => {
262+ return ( str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ) as Capitalize < T > ;
263+ } ;
264+
257265const mergeAsArray = (
258266 existing : t . ObjectProperty ,
259267 incoming : t . ObjectProperty
You can’t perform that action at this time.
0 commit comments