babel-plugin-transform-bigint
Advanced tools
Comparing version 1.0.27 to 1.0.28
@@ -296,2 +296,34 @@ // to run this test file use `npx jest` in the parent folder or `npm run test` | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
}); | ||
it('maybeJSBI', function () { | ||
const example = ` | ||
function f(a) { | ||
return Number(BigInt.asUintN(64, a)); | ||
} | ||
console.log(f(3n)); | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('maybeJSBI2', function () { | ||
const example = ` | ||
function f(a) { | ||
return Number(BigInt(a) < BigInt(0)); | ||
} | ||
console.log(f(3n)); | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('maybeJSBI2a', function () { | ||
const example = ` | ||
function f(a) { | ||
const x = BigInt(a) < BigInt(0); | ||
return Number(x); | ||
} | ||
console.log(f(3n)); | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); |
12
index.js
@@ -110,2 +110,5 @@ // see https://github.com/babel/babel/pull/6015 | ||
if (path.node.type === 'BinaryExpression') { | ||
if (getRelationalFunctionName(path.node.operator) != null) { | ||
return false; | ||
} | ||
return and(canBeBigInt(path.get('left')), canBeBigInt(path.get('right'))); | ||
@@ -325,3 +328,8 @@ } | ||
path.node.callee.object.type === 'Identifier' && | ||
path.node.callee.object.name === 'JSBI') { | ||
(path.node.callee.object.name === 'JSBI' || path.node.callee.object.name === 'BigInt')) { | ||
if (path.node.callee.object.name === 'JSBI') { | ||
if (['lessThan', 'greateThan', 'equal', 'notEqual', 'lessThanOrEqual', 'greaterThanOrEqual', 'toNumber'].indexOf(path.node.callee.property.name) !== -1) { | ||
return false; | ||
} | ||
} | ||
return JSBI; | ||
@@ -484,3 +492,3 @@ } | ||
BinaryExpression: function (path, state) { | ||
const JSBI = canBeBigInt(path); | ||
const JSBI = and(canBeBigInt(path.get('left')), canBeBigInt(path.get('right'))); | ||
const operator = path.node.operator; | ||
@@ -487,0 +495,0 @@ if (JSBI !== false) { |
{ | ||
"name": "babel-plugin-transform-bigint", | ||
"version": "1.0.27", | ||
"version": "1.0.28", | ||
"description": "A plugin for babel to transform `x * y` into something like `JSBI.multiply(x, y)` to support bigints.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
56250
965