@@ -56,7 +56,7 @@ const blockCloserTokenTypes = new Map([
5656 * Used to make objects serializable for JSON output.
5757 *
5858 * @param {Record<string,any> } object The object to process.
59- * @returns {Record<string,any> } A copy of the object with all functions replaced by true.
59+ * @returns {Record<string,any>|unknown[]|unknown } A copy of the object with all functions replaced by true.
6060 */
6161function replaceFunctions ( object ) {
6262 if ( typeof object !== "object" || object === null ) {
@@ -164,11 +164,19 @@ export class CSSLanguage {
164164 if ( ! languageOptions ?. customSyntax ) {
165165 return languageOptions ;
166166 }
167+ // Shallow copy
168+ const clone = { ...languageOptions } ;
167169
168- Object . defineProperty ( languageOptions , "toJSON" , {
170+ Object . defineProperty ( clone , "toJSON" , {
169171 value ( ) {
170- // Shallow copy
171- const result = { ...languageOptions } ;
172+ // another shallow copy
173+ const result = { ...this } ;
174+
175+ // if there's no custom syntax, no changes are necessary
176+ if ( ! this . customSyntax ) {
177+ return result ;
178+ }
179+
172180 result . customSyntax = { ...result . customSyntax } ;
173181
174182 if ( result . customSyntax . node ) {
@@ -195,7 +203,7 @@ export class CSSLanguage {
195203 configurable : true ,
196204 } ) ;
197205
198- return languageOptions ;
206+ return clone ;
199207 }
200208
201209 /**
0 commit comments