1 | var Hack = require('./hack');
|
---|
2 |
|
---|
3 | var Marker = require('../tokenizer/marker');
|
---|
4 |
|
---|
5 | var ASTERISK_HACK = '*';
|
---|
6 | var BACKSLASH_HACK = '\\';
|
---|
7 | var IMPORTANT_TOKEN = '!important';
|
---|
8 | var UNDERSCORE_HACK = '_';
|
---|
9 | var BANG_HACK = '!ie';
|
---|
10 |
|
---|
11 | function restoreFromOptimizing(properties, restoreCallback) {
|
---|
12 | var property;
|
---|
13 | var restored;
|
---|
14 | var current;
|
---|
15 | var i;
|
---|
16 |
|
---|
17 | for (i = properties.length - 1; i >= 0; i--) {
|
---|
18 | property = properties[i];
|
---|
19 |
|
---|
20 | if (property.dynamic && property.important) {
|
---|
21 | restoreImportant(property);
|
---|
22 | continue;
|
---|
23 | }
|
---|
24 |
|
---|
25 | if (property.dynamic) {
|
---|
26 | continue;
|
---|
27 | }
|
---|
28 |
|
---|
29 | if (property.unused) {
|
---|
30 | continue;
|
---|
31 | }
|
---|
32 |
|
---|
33 | if (!property.dirty && !property.important && !property.hack) {
|
---|
34 | continue;
|
---|
35 | }
|
---|
36 |
|
---|
37 | if (property.optimizable && restoreCallback) {
|
---|
38 | restored = restoreCallback(property);
|
---|
39 | property.value = restored;
|
---|
40 | } else {
|
---|
41 | restored = property.value;
|
---|
42 | }
|
---|
43 |
|
---|
44 | if (property.important) {
|
---|
45 | restoreImportant(property);
|
---|
46 | }
|
---|
47 |
|
---|
48 | if (property.hack) {
|
---|
49 | restoreHack(property);
|
---|
50 | }
|
---|
51 |
|
---|
52 | if ('all' in property) {
|
---|
53 | current = property.all[property.position];
|
---|
54 | current[1][1] = property.name;
|
---|
55 |
|
---|
56 | current.splice(2, current.length - 1);
|
---|
57 | Array.prototype.push.apply(current, restored);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | function restoreImportant(property) {
|
---|
63 | property.value[property.value.length - 1][1] += IMPORTANT_TOKEN;
|
---|
64 | }
|
---|
65 |
|
---|
66 | function restoreHack(property) {
|
---|
67 | if (property.hack[0] == Hack.UNDERSCORE) {
|
---|
68 | property.name = UNDERSCORE_HACK + property.name;
|
---|
69 | } else if (property.hack[0] == Hack.ASTERISK) {
|
---|
70 | property.name = ASTERISK_HACK + property.name;
|
---|
71 | } else if (property.hack[0] == Hack.BACKSLASH) {
|
---|
72 | property.value[property.value.length - 1][1] += BACKSLASH_HACK + property.hack[1];
|
---|
73 | } else if (property.hack[0] == Hack.BANG) {
|
---|
74 | property.value[property.value.length - 1][1] += Marker.SPACE + BANG_HACK;
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | module.exports = restoreFromOptimizing;
|
---|