11import type { AtRule } from 'postcss' ;
22import type { DiagnosticPosition , DiagnosticWithDetachedLocation , Location } from '../type.js' ;
3+ import { JS_IDENTIFIER_PATTERN } from '../util.js' ;
34
45interface ValueDeclaration {
56 type : 'valueDeclaration' ;
@@ -83,6 +84,17 @@ export function parseAtValue(atValue: AtRule): ParseAtValueResult {
8384 column : start . column + name . length ,
8485 offset : start . offset + name . length ,
8586 } ;
87+
88+ if ( ! JS_IDENTIFIER_PATTERN . test ( name ) ) {
89+ diagnostics . push ( {
90+ start : { line : start . line , column : start . column } ,
91+ length : name . length ,
92+ text : `css-modules-kit does not support non-JavaScript identifier as value names.` ,
93+ category : 'error' ,
94+ } ) ;
95+ continue ;
96+ }
97+
8698 const result = { name, loc : { start, end } } ;
8799 if ( localName === undefined ) {
88100 values . push ( result ) ;
@@ -98,6 +110,17 @@ export function parseAtValue(atValue: AtRule): ParseAtValueResult {
98110 column : start . column + localName . length ,
99111 offset : start . offset + localName . length ,
100112 } ;
113+
114+ if ( ! JS_IDENTIFIER_PATTERN . test ( localName ) ) {
115+ diagnostics . push ( {
116+ start : { line : start . line , column : start . column } ,
117+ length : localName . length ,
118+ text : `css-modules-kit does not support non-JavaScript identifier as value names.` ,
119+ category : 'error' ,
120+ } ) ;
121+ continue ;
122+ }
123+
101124 values . push ( { ...result , localName, localLoc : { start, end } } ) ;
102125 }
103126 } else {
@@ -154,6 +177,17 @@ export function parseAtValue(atValue: AtRule): ParseAtValueResult {
154177 column : start . column + name . length ,
155178 offset : start . offset + name . length ,
156179 } ;
180+
181+ if ( ! JS_IDENTIFIER_PATTERN . test ( name ) ) {
182+ diagnostics . push ( {
183+ start : { line : start . line , column : start . column } ,
184+ length : name . length ,
185+ text : `css-modules-kit does not support non-JavaScript identifier as value names.` ,
186+ category : 'error' ,
187+ } ) ;
188+ return { diagnostics } ;
189+ }
190+
157191 const parsedAtValue : ValueDeclaration = {
158192 type : 'valueDeclaration' ,
159193 name,
0 commit comments