You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

constantinople

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.1 to 3.0.2

68

index.js
'use strict'
var detect = require('acorn-globals');
var acorn = require('acorn');
var walk = require('acorn/dist/walk');

@@ -9,2 +10,24 @@ var lastSRC = '(null)';

var STATEMENT_WHITE_LIST = {
'EmptyStatement': true,
'ExpressionStatement': true,
};
var EXPRESSION_WHITE_LIST = {
'ParenthesizedExpression': true,
'ArrayExpression': true,
'ObjectExpression': true,
'SequenceExpression': true,
'TemplateLiteral': true,
'UnaryExpression': true,
'BinaryExpression': true,
'LogicalExpression': true,
'ConditionalExpression': true,
'Identifier': true,
'Literal': true,
'ComprehensionExpression': true,
'TaggedTemplateExpression': true,
'MemberExpression': true,
'CallExpression': true,
'NewExpression': true,
};
module.exports = isConstant;

@@ -16,10 +39,45 @@ function isConstant(src, constants) {

lastConstants = constants;
if (!isExpression(src)) return lastRes = false;
var ast;
try {
isExpression(src);
return lastRes = (detect(src).filter(function (key) {
return !constants || !(key.name in constants);
}).length === 0);
ast = acorn.parse(src, {
ecmaVersion: 6,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowHashBang: true
});
} catch (ex) {
return lastRes = false;
}
var isConstant = true;
walk.simple(ast, {
Statement: function (node) {
if (isConstant) {
if (STATEMENT_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
Expression: function (node) {
if (isConstant) {
if (EXPRESSION_WHITE_LIST[node.type] !== true) {
isConstant = false;
}
}
},
MemberExpression: function (node) {
if (isConstant) {
if (node.computed) isConstant = false;
else if (node.property.name[0] === '_') isConstant = false;
}
},
Identifier: function (node) {
if (isConstant) {
if (!constants || !(node.name in constants)) {
isConstant = false;
}
}
},
});
return lastRes = isConstant;
}

@@ -26,0 +84,0 @@ isConstant.isConstant = isConstant;

4

package.json
{
"name": "constantinople",
"version": "3.0.1",
"version": "3.0.2",
"description": "Determine whether a JavaScript expression evaluates to a constant (using UglifyJS)",
"keywords": [],
"dependencies": {
"acorn-globals": "^1.0.0"
"acorn": "^2.1.0"
},

@@ -9,0 +9,0 @@ "devDependencies": {

@@ -0,0 +0,0 @@ # constantinople

@@ -28,2 +28,5 @@ 'use strict'

})
it('handles "(function () { while (true); return 10; }())"', function () {
assert(constaninople.isConstant('(function () { while (true); return 10; }())') === false)
})
})

@@ -61,2 +64,10 @@

})
it('handles "(function () { while (true); return 10; }())"', function () {
try {
constaninople.toConstant('(function () { while (true); return 10; }())')
} catch (ex) {
return
}
assert(false, '(function () { while (true); return 10; }()) should result in an error')
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc