source: trip-planner-front/node_modules/csso/lib/replace/AttributeSelector.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 981 bytes
Line 
1// Can unquote attribute detection
2// Adopted implementation of Mathias Bynens
3// https://github.com/mathiasbynens/mothereff.in/blob/master/unquoted-attributes/eff.js
4var escapesRx = /\\([0-9A-Fa-f]{1,6})(\r\n|[ \t\n\f\r])?|\\./g;
5var blockUnquoteRx = /^(-?\d|--)|[\u0000-\u002c\u002e\u002f\u003A-\u0040\u005B-\u005E\u0060\u007B-\u009f]/;
6
7function canUnquote(value) {
8 if (value === '' || value === '-') {
9 return;
10 }
11
12 // Escapes are valid, so replace them with a valid non-empty string
13 value = value.replace(escapesRx, 'a');
14
15 return !blockUnquoteRx.test(value);
16}
17
18module.exports = function(node) {
19 var attrValue = node.value;
20
21 if (!attrValue || attrValue.type !== 'String') {
22 return;
23 }
24
25 var unquotedValue = attrValue.value.replace(/^(.)(.*)\1$/, '$2');
26 if (canUnquote(unquotedValue)) {
27 node.value = {
28 type: 'Identifier',
29 loc: attrValue.loc,
30 name: unquotedValue
31 };
32 }
33};
Note: See TracBrowser for help on using the repository browser.