Socket
Socket
Sign inDemoInstall

babel-plugin-transform-bigint

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-bigint - npm Package Compare versions

Comparing version 1.0.16 to 1.0.17

53

__tests__/index-test.js

@@ -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 @@ },

2

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc