babel-plugin-transform-bigint
Advanced tools
Comparing version 1.0.14 to 1.0.15
@@ -163,1 +163,13 @@ // to run this test file use `npx jest` in the parent folder or `npm run test` | ||
}); | ||
it('it does not mutable variables2', function () { | ||
const example = ` | ||
function f() { | ||
let i = 1; | ||
i = -i; | ||
return i * i; | ||
} | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); |
21
index.js
@@ -53,3 +53,3 @@ // see https://github.com/babel/babel/pull/6015 | ||
const visited = new Map(); | ||
let visited = new Map(); | ||
const canBeBigInt = function (path) { | ||
@@ -101,3 +101,3 @@ if (visited.get(path) != null) { | ||
if (path.node.type === 'AssignmentExpression') { | ||
return and(canBeBigInt(path.get('left')), canBeBigInt(path.get('right'))); | ||
return canBeBigInt(path.get('right')); | ||
} | ||
@@ -122,2 +122,19 @@ if (path.node.type === 'Identifier') { | ||
} | ||
if (visited.get(path) === maybeJSBI) { // assume that variable type is the same | ||
const visitedOriginal = new Map(visited.entries()); | ||
visited.set(path, X); | ||
for (const e of visited.entries()) { | ||
if (e[1] === maybeJSBI) { | ||
visited.delete(e[0]); | ||
} | ||
} | ||
let allAssignmentsHaveSameType = true; | ||
for (const path of binding.constantViolations) { | ||
allAssignmentsHaveSameType = allAssignmentsHaveSameType && canBeBigInt(path) === X; | ||
} | ||
if (allAssignmentsHaveSameType) { | ||
return X; | ||
} | ||
visited = visitedOriginal; | ||
} | ||
} | ||
@@ -124,0 +141,0 @@ } |
{ | ||
"name": "babel-plugin-transform-bigint", | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"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
37230
698