Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ms.macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default createMacro(({ babel: { types: t }, references: { default: paths
const value = getValue(parentPath);
if (value) {
const newValue = ms(value);
if (newValue) {
if (typeof newValue === 'number' && !Number.isNaN(newValue)) {
parentPath.replaceWith(t.numericLiteral(newValue));
} else {
const { line } = parentPath.node.loc.start;
Expand Down
3 changes: 3 additions & 0 deletions src/ms.macro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ const run = code => transform(code, {

{
const expected = stripIndent`
const ZERO_DAYS = 0;
const ONE_DAY = 86400000;
const TWO_DAYS = 172800000;
`;

test('CallExpression', (t) => {
const input = stripIndent`
import ms from './ms.macro';
const ZERO_DAYS = ms('0 days');
const ONE_DAY = ms('1 day');
const TWO_DAYS = ms('2 days');
`;
Expand All @@ -28,6 +30,7 @@ const run = code => transform(code, {
test('TaggedTemplateExpression', (t) => {
const input = stripIndent`
import ms from './ms.macro';
const ZERO_DAYS = ms\`0 days\`;
const ONE_DAY = ms\`1 day\`;
const TWO_DAYS = ms\`2 days\`;
`;
Expand Down