Skip to content

Commit 926df59

Browse files
radenoshellscape
authored andcommitted
fix: add time value units (shellscape#87)
1 parent b73b1d9 commit 926df59

File tree

4 files changed

+296
-2
lines changed

4 files changed

+296
-2
lines changed

lib/nodes/Numeric.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { registerWalker } = require('../walker');
1414

1515
const Node = require('./Node');
1616

17-
const unitRegex = /%|ch|cm|em|ex|in|mm|pc|pt|px|q|rem|vh|vmax|vmin|vw$/i;
17+
const unitRegex = /%|ch|cm|em|ex|in|mm|ms|pc|pt|px|s|q|rem|vh|vmax|vmin|vw$/i;
1818

1919
class Numeric extends Node {
2020
constructor(options = {}) {

test/fixtures/numeric.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ module.exports = {
3131
'1E+10',
3232
'-.567800E-0012780em',
3333
'.1E-10',
34-
'.1E+10'
34+
'.1E+10',
35+
'0.5s',
36+
'500ms',
37+
'0.5s + 0.5s',
38+
'-.3s',
39+
'-.3s + 0.5s'
3540
],
3641
throws: ['+-2.', '.', '.rem', '.2.3rem']
3742
};

test/snapshots/numeric.test.js.md

Lines changed: 289 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,3 +1051,292 @@ Generated by [AVA](https://ava.li).
10511051
value: '5',
10521052
},
10531053
]
1054+
1055+
## -.3s
1056+
1057+
> Snapshot 1
1058+
1059+
'-.3s'
1060+
1061+
> Snapshot 2
1062+
1063+
'-.3s'
1064+
1065+
> Snapshot 3
1066+
1067+
[
1068+
Numeric {
1069+
raws: {
1070+
after: '',
1071+
before: '',
1072+
},
1073+
source: {
1074+
end: {
1075+
column: 1,
1076+
line: 1,
1077+
},
1078+
input: Input {
1079+
css: '-.3s',
1080+
hasBOM: false,
1081+
id: '<input css 26>',
1082+
},
1083+
start: {
1084+
column: 1,
1085+
line: 1,
1086+
},
1087+
},
1088+
type: 'numeric',
1089+
unit: 's',
1090+
value: '-.3',
1091+
},
1092+
]
1093+
1094+
## -.3s + 0.5s
1095+
1096+
> Snapshot 1
1097+
1098+
'-.3s'
1099+
1100+
> Snapshot 2
1101+
1102+
'-.3s + 0.5s'
1103+
1104+
> Snapshot 3
1105+
1106+
[
1107+
Numeric {
1108+
raws: {
1109+
after: '',
1110+
before: '',
1111+
},
1112+
source: {
1113+
end: {
1114+
column: 1,
1115+
line: 1,
1116+
},
1117+
input: Input {
1118+
css: '-.3s + 0.5s',
1119+
hasBOM: false,
1120+
id: '<input css 27>',
1121+
},
1122+
start: {
1123+
column: 1,
1124+
line: 1,
1125+
},
1126+
},
1127+
type: 'numeric',
1128+
unit: 's',
1129+
value: '-.3',
1130+
},
1131+
Operator {
1132+
raws: {
1133+
after: '',
1134+
before: ' ',
1135+
},
1136+
source: {
1137+
end: {
1138+
column: 6,
1139+
line: 1,
1140+
},
1141+
input: Input {
1142+
css: '-.3s + 0.5s',
1143+
hasBOM: false,
1144+
id: '<input css 27>',
1145+
},
1146+
start: {
1147+
column: 6,
1148+
line: 1,
1149+
},
1150+
},
1151+
type: 'operator',
1152+
value: '+',
1153+
},
1154+
Numeric {
1155+
raws: {
1156+
after: '',
1157+
before: ' ',
1158+
},
1159+
source: {
1160+
end: {
1161+
column: 8,
1162+
line: 1,
1163+
},
1164+
input: Input {
1165+
css: '-.3s + 0.5s',
1166+
hasBOM: false,
1167+
id: '<input css 27>',
1168+
},
1169+
start: {
1170+
column: 8,
1171+
line: 1,
1172+
},
1173+
},
1174+
type: 'numeric',
1175+
unit: 's',
1176+
value: '0.5',
1177+
},
1178+
]
1179+
1180+
## 0.5s
1181+
1182+
> Snapshot 1
1183+
1184+
'0.5s'
1185+
1186+
> Snapshot 2
1187+
1188+
'0.5s'
1189+
1190+
> Snapshot 3
1191+
1192+
[
1193+
Numeric {
1194+
raws: {
1195+
after: '',
1196+
before: '',
1197+
},
1198+
source: {
1199+
end: {
1200+
column: 1,
1201+
line: 1,
1202+
},
1203+
input: Input {
1204+
css: '0.5s',
1205+
hasBOM: false,
1206+
id: '<input css 23>',
1207+
},
1208+
start: {
1209+
column: 1,
1210+
line: 1,
1211+
},
1212+
},
1213+
type: 'numeric',
1214+
unit: 's',
1215+
value: '0.5',
1216+
},
1217+
]
1218+
1219+
## 0.5s + 0.5s
1220+
1221+
> Snapshot 1
1222+
1223+
'0.5s'
1224+
1225+
> Snapshot 2
1226+
1227+
'0.5s + 0.5s'
1228+
1229+
> Snapshot 3
1230+
1231+
[
1232+
Numeric {
1233+
raws: {
1234+
after: '',
1235+
before: '',
1236+
},
1237+
source: {
1238+
end: {
1239+
column: 1,
1240+
line: 1,
1241+
},
1242+
input: Input {
1243+
css: '0.5s + 0.5s',
1244+
hasBOM: false,
1245+
id: '<input css 25>',
1246+
},
1247+
start: {
1248+
column: 1,
1249+
line: 1,
1250+
},
1251+
},
1252+
type: 'numeric',
1253+
unit: 's',
1254+
value: '0.5',
1255+
},
1256+
Operator {
1257+
raws: {
1258+
after: '',
1259+
before: ' ',
1260+
},
1261+
source: {
1262+
end: {
1263+
column: 6,
1264+
line: 1,
1265+
},
1266+
input: Input {
1267+
css: '0.5s + 0.5s',
1268+
hasBOM: false,
1269+
id: '<input css 25>',
1270+
},
1271+
start: {
1272+
column: 6,
1273+
line: 1,
1274+
},
1275+
},
1276+
type: 'operator',
1277+
value: '+',
1278+
},
1279+
Numeric {
1280+
raws: {
1281+
after: '',
1282+
before: ' ',
1283+
},
1284+
source: {
1285+
end: {
1286+
column: 8,
1287+
line: 1,
1288+
},
1289+
input: Input {
1290+
css: '0.5s + 0.5s',
1291+
hasBOM: false,
1292+
id: '<input css 25>',
1293+
},
1294+
start: {
1295+
column: 8,
1296+
line: 1,
1297+
},
1298+
},
1299+
type: 'numeric',
1300+
unit: 's',
1301+
value: '0.5',
1302+
},
1303+
]
1304+
1305+
## 500ms
1306+
1307+
> Snapshot 1
1308+
1309+
'500ms'
1310+
1311+
> Snapshot 2
1312+
1313+
'500ms'
1314+
1315+
> Snapshot 3
1316+
1317+
[
1318+
Numeric {
1319+
raws: {
1320+
after: '',
1321+
before: '',
1322+
},
1323+
source: {
1324+
end: {
1325+
column: 1,
1326+
line: 1,
1327+
},
1328+
input: Input {
1329+
css: '500ms',
1330+
hasBOM: false,
1331+
id: '<input css 24>',
1332+
},
1333+
start: {
1334+
column: 1,
1335+
line: 1,
1336+
},
1337+
},
1338+
type: 'numeric',
1339+
unit: 'ms',
1340+
value: '500',
1341+
},
1342+
]

test/snapshots/numeric.test.js.snap

551 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)