Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/__tests__/sync-configured-options.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import parser from "../../dist/index.js";

for (const method of ["astSync", "transformSync", "processSync"]) {
test(`${method} respects configured updates and per-call overrides`, () => {
const processor = parser(
(root) => {
root.first.first.value = "new";
},
{ updateSelector: true },
);
const rule = { selector: ".old" };
processor[method](rule);
assert.equal(rule.selector, ".new");
const preserved = { selector: ".old" };
processor[method](preserved, { updateSelector: false });
assert.equal(preserved.selector, ".old");
const defaultRule = { selector: ".old" };
parser((root) => {
root.first.first.value = "new";
})[method](defaultRule);
assert.equal(defaultRule.selector, ".old");
});
}
3 changes: 2 additions & 1 deletion src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export default class Processor {
throw new Error("Selector processor returned a promise to a synchronous call.");
}
let string = undefined;
if (options.updateSelector && typeof rule !== "string") {
const merged = Object.assign({}, this.options, options);
if (merged.updateSelector && typeof rule !== "string") {
string = root.toString(this._stringifyOptions(options));
rule.selector = string;
}
Expand Down
Loading