Skip to content

Commit c91fbbf

Browse files
committed
Limit some conversions
1 parent 6625d3e commit c91fbbf

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

src/js/css-calc.js

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const resolveDimension = (token, opt = {}) => {
4242
}
4343
const [, value,,, detail = {}] = token;
4444
const { unit, value: relativeValue } = detail;
45-
const { dimension = {}, format } = opt;
45+
const { dimension = {} } = opt;
4646
if (unit === 'px') {
4747
return value;
4848
}
@@ -53,42 +53,22 @@ export const resolveDimension = (token, opt = {}) => {
5353
pixelValue = dimension[unit];
5454
} else if (typeof dimension.callback === 'function') {
5555
pixelValue = dimension.callback(unit);
56-
} else if (/^(?:ch|ex|lh)$/.test(unit) &&
56+
} else if (/^(?:ch|lh)$/.test(unit) &&
5757
Object.hasOwnProperty.call(dimension, 'em')) {
5858
const { em } = dimension;
5959
if (unit === 'lh') {
6060
pixelValue = em * 1.2;
6161
} else {
6262
pixelValue = em / 2;
6363
}
64-
} else if (/^(?:rch|rex|rlh)$/.test(unit) &&
64+
} else if (/^(?:rch|rlh)$/.test(unit) &&
6565
Object.hasOwnProperty.call(dimension, 'rem')) {
6666
const { rem } = dimension;
6767
if (unit === 'rlh') {
6868
pixelValue = rem * 1.2;
6969
} else {
7070
pixelValue = rem / 2;
7171
}
72-
} else if (format === VAL_SPEC) {
73-
const lengthInPx = {
74-
ch: 8,
75-
cm: 96 / 2.54,
76-
em: 16,
77-
ex: 8,
78-
in: 96,
79-
lh: 1.2 * 16,
80-
mm: 96 / 2.54 / 10,
81-
pc: 16,
82-
pt: 16 / 12,
83-
q: 96 / 2.54 / 40,
84-
rch: 8,
85-
rem: 16,
86-
rex: 8,
87-
rlh: 1.2 * 16
88-
};
89-
if (Object.hasOwnProperty.call(lengthInPx, unit)) {
90-
pixelValue = lengthInPx[unit];
91-
}
9272
}
9373
if (Number.isFinite(pixelValue)) {
9474
res = `${relativeValue * pixelValue}px`;

test/css-calc.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ describe('resolve dimension', () => {
168168
assert.strictEqual(res, '600px', 'result');
169169
});
170170

171-
it('should get value', () => {
171+
it('should get null', () => {
172172
const token = [
173173
'dimension-token',
174174
'100ex',
@@ -188,7 +188,7 @@ describe('resolve dimension', () => {
188188
vw: 10.26
189189
}
190190
});
191-
assert.strictEqual(res, '600px', 'result');
191+
assert.strictEqual(res, null, 'result');
192192
});
193193

194194
it('should get value', () => {
@@ -238,7 +238,7 @@ describe('resolve dimension', () => {
238238
assert.strictEqual(res, '80px', 'result');
239239
});
240240

241-
it('should get value', () => {
241+
it('should get null', () => {
242242
const token = [
243243
'dimension-token',
244244
'10rex',
@@ -258,7 +258,7 @@ describe('resolve dimension', () => {
258258
vw: 10.26
259259
}
260260
});
261-
assert.strictEqual(res, '80px', 'result');
261+
assert.strictEqual(res, null, 'result');
262262
});
263263

264264
it('should get value', () => {
@@ -285,7 +285,7 @@ describe('resolve dimension', () => {
285285
assert.strictEqual(res, '1920px', 'result');
286286
});
287287

288-
it('should get value', () => {
288+
it('should get null', () => {
289289
const token = [
290290
'dimension-token',
291291
'100em',
@@ -301,7 +301,7 @@ describe('resolve dimension', () => {
301301
const res = func(token, {
302302
format: 'specifiedValue'
303303
});
304-
assert.strictEqual(res, '1600px', 'result');
304+
assert.strictEqual(res, null, 'result');
305305
});
306306
});
307307

0 commit comments

Comments
 (0)