mirror of
https://github.com/status-im/metro.git
synced 2025-02-04 23:33:33 +00:00
Do not transform -0
Reviewed By: rubennorte Differential Revision: D8095511 fbshipit-source-id: 8f75cdf04cce58691b59b2c9dcac620150706ab3
This commit is contained in:
parent
adce40d38d
commit
f0a0e92f5f
@ -259,4 +259,16 @@ describe('constant expressions', () => {
|
||||
|
||||
expect(fold('arbitrary.js', code)).toEqual('var x=2;{z();}');
|
||||
});
|
||||
|
||||
it('does not mess up -0', () => {
|
||||
const code = `
|
||||
var plusZero = +0;
|
||||
var zero = 0;
|
||||
var minusZero = -0;
|
||||
`;
|
||||
|
||||
expect(fold('arbitrary.js', code)).toEqual(
|
||||
'var plusZero=0;var zero=0;var minusZero=-0;',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -63,7 +63,9 @@ function constantFoldingPlugin(context: {types: BabelTypes}) {
|
||||
const result = path.evaluate();
|
||||
|
||||
if (result.confident) {
|
||||
path.replaceWith(t.valueToNode(result.value));
|
||||
if (!Object.is(result.value, -0)) {
|
||||
path.replaceWith(t.valueToNode(result.value));
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user