babel-plugin-transform-bigint
Advanced tools
Comparing version 1.0.21 to 1.0.22
@@ -271,1 +271,22 @@ // to run this test file use `npx jest` in the parent folder or `npm run test` | ||
it('CallExpression\'s type', function () { | ||
const example = ` | ||
function n() { | ||
return 3; | ||
} | ||
console.log(n() * n()); | ||
function b() { | ||
return 3n; | ||
} | ||
console.log(b() * b()); | ||
function nb() { | ||
if (Math.random() < 0.5) { | ||
return 3; | ||
} | ||
return 3n; | ||
} | ||
console.log(nb() * nb()); | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); |
17
index.js
@@ -326,10 +326,21 @@ // see https://github.com/babel/babel/pull/6015 | ||
if (binding.path.node.type === 'FunctionDeclaration') { | ||
const statements = binding.path.get('body').get('body'); | ||
//console.log('binding.path', binding.path); | ||
//const statements = binding.path.get('body').get('body'); | ||
const statements = []; | ||
binding.path.getScope().traverse(binding.path.node, {ReturnStatement: function(path){ statements.push(path); }}, this); | ||
let returnType = undefined; | ||
for (const statement of statements) { | ||
if (statement.type === 'ReturnStatement') { | ||
if (canBeBigInt(statement.get('argument')) === false) { | ||
return false; | ||
const t = canBeBigInt(statement.get('argument')); | ||
if (returnType === undefined) { | ||
returnType = t; | ||
} | ||
if (returnType !== t) { | ||
returnType = maybeJSBI; | ||
} | ||
} | ||
} | ||
if (returnType === false || returnType == JSBI) { | ||
return returnType; | ||
} | ||
} | ||
@@ -336,0 +347,0 @@ } |
{ | ||
"name": "babel-plugin-transform-bigint", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54102
897