@@ -8,19 +8,22 @@ import { generatePropTypes } from './generate-prop-types';
8
8
9
9
/**
10
10
* Generate a string based on the types that are defined within a component
11
+ * @param config the validated config for the Stencil project
11
12
* @param cmp the metadata for the component that a type definition string is generated for
12
13
* @param typeImportData locally/imported/globally used type names, which may be used to prevent naming collisions
13
14
* @param areTypesInternal `true` if types being generated are for a project's internal purposes, `false` otherwise
14
15
* @returns the generated types string alongside additional metadata
15
16
*/
16
17
export const generateComponentTypes = (
18
+ config : d . ValidatedConfig ,
17
19
cmp : d . ComponentCompilerMeta ,
18
20
typeImportData : d . TypesImportData ,
19
21
areTypesInternal : boolean ,
20
22
) : d . TypesModule => {
21
23
const tagName = cmp . tagName . toLowerCase ( ) ;
22
24
const tagNameAsPascal = dashToPascalCase ( tagName ) ;
23
25
const htmlElementName = `HTML${ tagNameAsPascal } Element` ;
26
+ const noDashCaseTypes = config . noDashCaseTypes ;
24
27
25
28
const propAttributes = generatePropTypes ( cmp , typeImportData ) ;
26
29
const methodAttributes = generateMethodTypes ( cmp , typeImportData ) ;
@@ -31,9 +34,15 @@ export const generateComponentTypes = (
31
34
[ ...propAttributes , ...methodAttributes ] ,
32
35
false ,
33
36
areTypesInternal ,
37
+ noDashCaseTypes ,
34
38
) ;
35
39
const isDep = cmp . isCollectionDependency ;
36
- const jsxAttributes = attributesToMultiLineString ( [ ...propAttributes , ...eventAttributes ] , true , areTypesInternal ) ;
40
+ const jsxAttributes = attributesToMultiLineString (
41
+ [ ...propAttributes , ...eventAttributes ] ,
42
+ true ,
43
+ areTypesInternal ,
44
+ noDashCaseTypes ,
45
+ ) ;
37
46
38
47
const element = [
39
48
...htmlElementEventMap ,
@@ -60,7 +69,12 @@ export const generateComponentTypes = (
60
69
} ;
61
70
} ;
62
71
63
- const attributesToMultiLineString = ( attributes : d . TypeInfo , jsxAttributes : boolean , internal : boolean ) => {
72
+ const attributesToMultiLineString = (
73
+ attributes : d . TypeInfo ,
74
+ jsxAttributes : boolean ,
75
+ internal : boolean ,
76
+ noDashCaseTypes : boolean ,
77
+ ) => {
64
78
const attributesStr = sortBy ( attributes , ( a ) => a . name )
65
79
. filter ( ( type ) => {
66
80
if ( jsxAttributes && ! internal && type . internal ) {
@@ -76,20 +90,21 @@ const attributesToMultiLineString = (attributes: d.TypeInfo, jsxAttributes: bool
76
90
}
77
91
const optional = jsxAttributes ? ! type . required : type . optional ;
78
92
fullList . push ( ` "${ type . name } "${ optional ? '?' : '' } : ${ type . type } ;` ) ;
79
-
80
- /**
81
- * deprecated usage of dash-casing in JSX, use camelCase instead
82
- */
83
- if ( type . attributeName && type . attributeName !== type . name ) {
84
- const padding = ' ' . repeat ( 8 ) ;
85
- fullList . push (
86
- [
87
- `${ padding } /**` ,
88
- `${ padding } * @deprecated use camelCase instead. Support for dash-casing will be removed in Stencil v5.` ,
89
- `${ padding } */` ,
90
- ] . join ( '\n' ) ,
91
- ) ;
92
- fullList . push ( `${ padding } "${ type . attributeName } "?: ${ type . type } ;` ) ;
93
+ if ( noDashCaseTypes === false ) {
94
+ /**
95
+ * deprecated usage of dash-casing in JSX, use camelCase instead
96
+ */
97
+ if ( type . attributeName && type . attributeName !== type . name ) {
98
+ const padding = ' ' . repeat ( 8 ) ;
99
+ fullList . push (
100
+ [
101
+ `${ padding } /**` ,
102
+ `${ padding } * @deprecated use camelCase instead. Support for dash-casing will be removed in Stencil v5.` ,
103
+ `${ padding } */` ,
104
+ ] . join ( '\n' ) ,
105
+ ) ;
106
+ fullList . push ( `${ padding } "${ type . attributeName } "?: ${ type . type } ;` ) ;
107
+ }
93
108
}
94
109
95
110
return fullList ;
0 commit comments