Skip to content

Commit

Permalink
Test set Attribute#quoteMark
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed Mar 30, 2018
1 parent 3c52465 commit 9aa8646
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,17 @@ testDeprecation('smart quotes', '[data-foo=bar]', (t, tree) => {
attr.setValue('smart with "double quotes"', {smart: true});
t.deepEqual(attr.toString(), "[data-foo='smart with \"double quotes\"']");
});

testDeprecation('set Attribute#quoteMark', '[data-foo=bar]', (t, tree) => {
let attr = tree.nodes[0].nodes[0];
attr.quoteMark = '"';
t.deepEqual(attr.toString(), '[data-foo="bar"]');
attr.quoteMark = "'";
t.deepEqual(attr.toString(), "[data-foo='bar']");
attr.quoteMark = null;
t.deepEqual(attr.toString(), "[data-foo=bar]");
attr.value = "has space";
t.deepEqual(attr.toString(), "[data-foo=has\\ space]");
attr.quoteMark = '"';
t.deepEqual(attr.toString(), '[data-foo="has space"]');
});
12 changes: 5 additions & 7 deletions src/selectors/attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ export default class Attribute extends Namespace {
_syncRawValue () {
let rawValue = cssesc(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]);
if (rawValue === this._value) {
delete this.raws.value;
if (this.raws) {
delete this.raws.value;
}
} else {
this.raws.value = rawValue;
}
Expand Down Expand Up @@ -262,12 +264,8 @@ export default class Attribute extends Namespace {
return;
}
this._value = unescaped;
this.quoteMark = quoteMark;
if (unescaped === this._value) {
delete this.raws.value;
} else {
this.raws.value = v;
}
this._quoteMark = quoteMark;
this._syncRawValue();
} else {
this._value = v;
}
Expand Down

0 comments on commit 9aa8646

Please sign in to comment.