babel-plugin-transform-bigint
Advanced tools
Comparing version 1.0.16 to 1.0.17
@@ -175,1 +175,54 @@ // to run this test file use `npx jest` in the parent folder or `npm run test` | ||
}); | ||
it('default values', function () { | ||
const example = ` | ||
function f(y = unknown(), z = y * y) { | ||
if (typeof y !== 'bigint') { | ||
throw new RangeError(); | ||
} | ||
return y * y; | ||
} | ||
`; | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('arguments in non-strict mode', function () { | ||
const example = ` | ||
function func(a) { | ||
if (typeof a !== 'number') { | ||
throw new RangeError(); | ||
} | ||
arguments[0] = 99n; | ||
console.log(a * a); | ||
} | ||
func(10); // prints 9801 | ||
`; | ||
try { | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
} catch (error) { | ||
console.assert(error instanceof RangeError); | ||
} | ||
}); | ||
it('eval in non-strict mode', function () { | ||
const example = ` | ||
function func(a) { | ||
if (typeof a !== 'number') { | ||
throw new RangeError(); | ||
} | ||
eval('a = 99n') | ||
console.log(a * a); | ||
} | ||
func(10); // prints 9801 | ||
`; | ||
try { | ||
const {code} = babel.transform(example, {plugins: [plugin]}); | ||
expect(code).toMatchSnapshot(); | ||
} catch (error) { | ||
console.assert(error instanceof RangeError); | ||
} | ||
}); |
35
index.js
@@ -90,2 +90,15 @@ // see https://github.com/babel/babel/pull/6015 | ||
} | ||
if (path.node.type === 'NullLiteral') { | ||
return false; | ||
} | ||
if (path.node.type === 'RegExpLiteral') { | ||
return false; | ||
} | ||
if (path.node.type === 'BooleanLiteral') { | ||
return false; | ||
} | ||
if (path.node.type === 'TemplateLiteral') { | ||
return false; | ||
} | ||
if (path.node.type === 'UnaryExpression') { | ||
@@ -106,2 +119,3 @@ if (path.node.operator === '+') { // +0n is not allowed | ||
} | ||
if (path.node.type === 'Identifier') { | ||
@@ -186,3 +200,3 @@ const binding = path.scope.getBinding(path.node.name); | ||
const functionDeclaration = path.findParent(path => path.isFunctionDeclaration()); | ||
if (functionDeclaration != null) { | ||
if (functionDeclaration != null && functionDeclaration.node.params.filter(param => !types.isIdentifier(param)).length == 0) { | ||
const body = functionDeclaration.get('body'); | ||
@@ -225,2 +239,3 @@ const x = body.get('body')[0]; | ||
} | ||
if (path.node.type === 'ConditionalExpression') { | ||
@@ -235,5 +250,2 @@ return canBeBigInt(path.get('consequent')) !== false || canBeBigInt(path.get('alternate')) !== false ? maybeJSBI : false; | ||
} | ||
if (path.node.type === 'NullLiteral') { | ||
return false; | ||
} | ||
if (path.node.type === 'LogicalExpression') { | ||
@@ -285,2 +297,9 @@ return false;//? | ||
} | ||
if (path.node.type === 'MemberExpression') { | ||
return maybeJSBI; | ||
} | ||
if (path.node.type === 'ObjectExpression') { | ||
return false; | ||
} | ||
console.debug('unknown path.node.type: ' + path.node.type); | ||
//TODO: | ||
@@ -542,2 +561,10 @@ return maybeJSBI; | ||
path.unshiftContainer('body', importDeclaration); | ||
}, | ||
Identifier: function (path) { | ||
if (path.node.name === 'arguments') { | ||
throw new RangeError('arguments should not be used'); | ||
} | ||
if (path.node.name === 'eval') { | ||
throw new RangeError('eval should not be used'); | ||
} | ||
} | ||
@@ -544,0 +571,0 @@ }, |
{ | ||
"name": "babel-plugin-transform-bigint", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"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
42745
773