babel-plugin-transform-bigint
Advanced tools
Comparing version 1.0.20 to 1.0.21
@@ -153,2 +153,3 @@ // to run this test file use `npx jest` in the parent folder or `npm run test` | ||
} | ||
export {f1, f2, f3, f4, f5}; | ||
`; | ||
@@ -243,2 +244,3 @@ const {code} = babel.transform(example, {plugins: [plugin]}); | ||
} | ||
export default f; | ||
`; | ||
@@ -248,1 +250,24 @@ const {code} = babel.transform(example, {plugins: [plugin]}); | ||
}); | ||
it('internal number function', function () { | ||
const example = ` | ||
function f(a) { | ||
return a * a; | ||
} | ||
console.log(f(3)); | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('internal bigint function', function () { | ||
const example = ` | ||
function f(a) { | ||
return a * a; | ||
} | ||
console.log(f(3n)); | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
38
index.js
@@ -163,2 +163,40 @@ // see https://github.com/babel/babel/pull/6015 | ||
} | ||
if (binding.path.node.type === 'Identifier' && binding.path.parentPath.node.type === 'FunctionDeclaration') { | ||
//console.log(binding.path.parentPath.node, '!!!'); | ||
const functionPath = binding.path.parentPath; | ||
const id = functionPath.get('id'); | ||
const functionBinding = functionPath.scope.getBinding(id.node.name); | ||
if (functionBinding != null) { | ||
let argIsBigInt = undefined; | ||
//TODO: check no exports | ||
for (const path of functionBinding.referencePaths) { | ||
//console.log('function call: ' + path.parentPath + '', path.parentPath); | ||
const functionCall = path.parentPath; | ||
if (types.isCallExpression(functionCall)) { | ||
//TODO: check arguments | ||
const args = functionCall.get('arguments'); | ||
for (let i = 0; i < args.length; i += 1) { | ||
const a = args[i]; | ||
//console.log('arg', a); | ||
const t = canBeBigInt(a); | ||
if (t === false && (argIsBigInt == undefined || argIsBigInt === 'false')) { | ||
argIsBigInt = 'false'; | ||
} else if (t === JSBI && (argIsBigInt == undefined || argIsBigInt === 'true')) { | ||
argIsBigInt = 'true'; | ||
} else { | ||
argIsBigInt = 'NO'; | ||
} | ||
} | ||
} else { | ||
argIsBigInt = 'NO'; | ||
} | ||
} | ||
if (argIsBigInt === 'false') { | ||
return false; | ||
} | ||
if (argIsBigInt === 'true') { | ||
return JSBI; | ||
} | ||
} | ||
} | ||
} else { | ||
@@ -165,0 +203,0 @@ if (path.node.name === 'undefined') { |
{ | ||
"name": "babel-plugin-transform-bigint", | ||
"version": "1.0.20", | ||
"version": "1.0.21", | ||
"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
49813
866