@@ -28,7 +28,7 @@ private extension HTMLElement {
28
28
if key == " acceptCharset " {
29
29
key = " accept-charset "
30
30
}
31
- if let string: String = parse_attribute ( elementType: elementType, key: key, expression: child. expression) {
31
+ if let string: String = parse_attribute ( context : context , elementType: elementType, key: key, expression: child. expression) {
32
32
attributes. append ( key + ( string. isEmpty ? " " : " = \\ \" " + string + " \\ \" " ) )
33
33
}
34
34
}
@@ -68,7 +68,7 @@ private extension HTMLElement {
68
68
value = function. arguments. last!. expression. stringLiteral!. string
69
69
break
70
70
default :
71
- if let string: String = parse_attribute ( elementType: elementType, key: key, expression: key_element) {
71
+ if let string: String = parse_attribute ( context : context , elementType: elementType, key: key, expression: key_element) {
72
72
value = string
73
73
}
74
74
break
@@ -128,17 +128,24 @@ private extension HTMLElement {
128
128
}
129
129
}
130
130
131
- static func parse_attribute( elementType: HTMLElementType , key: String , expression: ExprSyntax ) -> String ? {
131
+ static func parse_attribute( context : some MacroExpansionContext , elementType: HTMLElementType , key: String , expression: ExprSyntax ) -> String ? {
132
132
if let ( string, returnType) : ( String , LiteralReturnType ) = parse_literal_value ( elementType: elementType, key: key, expression: expression) {
133
133
switch returnType {
134
134
case . boolean: return string. elementsEqual ( " true " ) ? " " : nil
135
135
case . string: return string
136
136
case . interpolation: return " \\ ( " + string + " ) "
137
137
}
138
138
}
139
+ let separator : String = get_separator ( key: key)
140
+ let string_return_logic : ( ExprSyntax , String ) -> String = {
141
+ if $1. contains ( separator) {
142
+ context. diagnose ( Diagnostic ( node: $0, message: ErrorDiagnostic ( id: " characterNotAllowedInDeclaration " , message: " Character \" " + separator + " \" is not allowed when declaring values for \" " + key + " \" . " ) ) )
143
+ }
144
+ return $1
145
+ }
139
146
if let value: String = expression. array? . elements. compactMap ( {
140
147
if let string: String = $0. expression. stringLiteral? . string {
141
- return string
148
+ return string_return_logic ( $0 . expression , string)
142
149
}
143
150
if let string: String = $0. expression. integerLiteral? . literal. text {
144
151
return string
@@ -147,7 +154,7 @@ private extension HTMLElement {
147
154
return HTMLElementAttribute . Extra. htmlValue ( enumName: enumName ( elementType: elementType, key: key) , for: string)
148
155
}
149
156
return nil
150
- } ) . joined ( separator: get_separator ( key : key ) ) {
157
+ } ) . joined ( separator: separator ) {
151
158
return value
152
159
}
153
160
func member( _ value: String ) -> String {
0 commit comments