Skip to content

Commit e35949f

Browse files
committed
clear raw values if a an arribute value changes.
1 parent 1c01788 commit e35949f

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/__tests__/attributes.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,18 @@ test('comments within attribute selectors (3)', '[href=test/* wow */i]', (t, tre
316316

317317
test('comments within attribute selectors (4)', '[ /*before*/ href /* after-attr */ = /* after-operator */ te/*inside-value*/st/* wow */ /*omg*/i/*bbq*/ /*whodoesthis*/]', (t, tree) => {
318318
let attr = tree.nodes[0].nodes[0];
319-
console.log(attr.spaces);
320-
console.log(attr.raws);
321319
t.deepEqual(attr.attribute, 'href');
322320
t.deepEqual(attr.value, 'test');
321+
t.deepEqual(attr.raws.value, 'te/*inside-value*/st');
323322
t.deepEqual(attr.raws.unquoted, 'test');
324323
t.deepEqual(attr.raws.spaces.value.after, '/* wow */ /*omg*/');
325324
t.truthy(attr.insensitive);
326325
t.deepEqual(attr.offsetOf("attribute"), 13);
327326
t.deepEqual(attr.offsetOf("operator"), 35);
328327
t.deepEqual(attr.offsetOf("insensitive"), 95);
329328
t.deepEqual(attr.raws.spaces.insensitive.after, '/*bbq*/ /*whodoesthis*/');
329+
attr.value = "foo";
330+
t.falsy(attr.raws.value);
330331
});
331332

332333
// test('attributes with escapes', '[ng\\:cloak]', (t, tree) => {

src/selectors/attribute.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default class Attribute extends Namespace {
66
super(opts);
77
this.type = ATTRIBUTE;
88
this.raws = this.raws || {};
9+
this._constructed = true;
910
}
1011

1112
get qualifiedAttribute () {
@@ -16,6 +17,61 @@ export default class Attribute extends Namespace {
1617
return this.insensitive ? 'i' : '';
1718
}
1819

20+
get value () {
21+
return this._value;
22+
}
23+
24+
set value (v) {
25+
this._value = v;
26+
if (this._constructed) {
27+
delete this.raws.value;
28+
}
29+
}
30+
31+
get value () {
32+
return this._value;
33+
}
34+
35+
set value (v) {
36+
this._value = v;
37+
if (this._constructed) {
38+
delete this.raws.value;
39+
}
40+
}
41+
42+
get namespace () {
43+
return this._namespace;
44+
}
45+
46+
set namespace (v) {
47+
this._namespace = v;
48+
if (this._constructed) {
49+
delete this.raws.namespace;
50+
}
51+
}
52+
53+
get namespace () {
54+
return this._namespace;
55+
}
56+
57+
set namespace (v) {
58+
this._namespace = v;
59+
if (this._constructed) {
60+
delete this.raws.namespace;
61+
}
62+
}
63+
64+
get attribute () {
65+
return this._attribute;
66+
}
67+
68+
set attribute (v) {
69+
this._attribute = v;
70+
if (this._constructed) {
71+
delete this.raws.attibute;
72+
}
73+
}
74+
1975
_spacesFor (name) {
2076
let attrSpaces = {before: '', after: ''};
2177
let spaces = this.spaces[name] || {};

0 commit comments

Comments
 (0)