@@ -46,10 +46,6 @@ export async function visitAsync(
46
46
await Promise . all ( promises )
47
47
}
48
48
49
- // if one of the props in a toJSX call has the CH_CODE_CONFIG_PLACEHOLDER value
50
- // it will be replaced with a reference to the CH_CODE_CONFIG_VAR_NAME var
51
- export const CH_CODE_CONFIG_PLACEHOLDER =
52
- "CH_CodeConfig" as any
53
49
export const CH_CODE_CONFIG_VAR_NAME = "chCodeConfig"
54
50
55
51
/**
@@ -64,14 +60,15 @@ export function toJSX(
64
60
props,
65
61
name,
66
62
appendProps = false ,
63
+ addConfigProp = false ,
67
64
} : {
68
65
type ?: string
69
66
props : Record < string , any >
70
67
name ?: string
71
68
appendProps ?: boolean
69
+ addConfigProp ?: boolean
72
70
}
73
71
) {
74
- // console.log(`transforming ${node.name} to ${name}`)
75
72
node . type = type
76
73
if ( name ) {
77
74
node . name = name
@@ -82,26 +79,26 @@ export function toJSX(
82
79
node . attributes = node . attributes || [ ]
83
80
}
84
81
82
+ if ( addConfigProp ) {
83
+ node . attributes . push (
84
+ toAttribute ( "codeConfig" , CH_CODE_CONFIG_VAR_NAME , {
85
+ type : "Identifier" ,
86
+ name : CH_CODE_CONFIG_VAR_NAME ,
87
+ } )
88
+ )
89
+ }
90
+
85
91
Object . keys ( props ) . forEach ( key => {
86
92
if ( props [ key ] === undefined ) {
87
93
return
88
94
}
89
- if ( props [ key ] === CH_CODE_CONFIG_PLACEHOLDER ) {
90
- node . attributes . push (
91
- toAttribute ( key , CH_CODE_CONFIG_VAR_NAME , {
92
- type : "Identifier" ,
93
- name : CH_CODE_CONFIG_VAR_NAME ,
94
- } )
95
+ node . attributes . push (
96
+ toAttribute (
97
+ key ,
98
+ JSON . stringify ( props [ key ] ) ,
99
+ valueToEstree ( props [ key ] )
95
100
)
96
- } else {
97
- node . attributes . push (
98
- toAttribute (
99
- key ,
100
- JSON . stringify ( props [ key ] ) ,
101
- valueToEstree ( props [ key ] )
102
- )
103
- )
104
- }
101
+ )
105
102
} )
106
103
}
107
104
0 commit comments