Skip to content

Commit e4890b0

Browse files
committed
Apply feedback
1 parent 0990352 commit e4890b0

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/languages/css-language.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
6161
function 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
/**

tests/languages/css-language.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ describe("CSSLanguage", () => {
275275
const language = new CSSLanguage();
276276
const options = { tolerant: true, customSyntax: { foo: "bar" } };
277277
const result = language.normalizeLanguageOptions(options);
278-
assert.strictEqual(result, options);
278+
assert.deepStrictEqual(result, options);
279279
assert.strictEqual(typeof result.toJSON, "function");
280280
});
281281

@@ -299,8 +299,8 @@ describe("CSSLanguage", () => {
299299
},
300300
},
301301
};
302-
language.normalizeLanguageOptions(options);
303-
const json = options.toJSON();
302+
const normalized = language.normalizeLanguageOptions(options);
303+
const json = normalized.toJSON();
304304
assert.deepStrictEqual(json, {
305305
tolerant: false,
306306
customSyntax: {

0 commit comments

Comments
 (0)