Socket
Socket
Sign inDemoInstall

constantinople

Package Overview
Dependencies
5
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.2 to 4.0.0

.editorconfig

12

lib/index.d.ts

@@ -1,4 +0,4 @@

import { BabylonOptions } from 'babylon';
import * as b from 'babel-types';
export { BabylonOptions };
import { ParserOptions } from '@babel/parser';
import * as b from '@babel/types';
export { ParserOptions as BabylonOptions };
export interface ExpressionToConstantOptions {

@@ -8,3 +8,3 @@ constants?: any;

export interface Options extends ExpressionToConstantOptions {
babylon?: BabylonOptions;
babylon?: ParserOptions;
}

@@ -18,4 +18,4 @@ export declare function expressionToConstant(expression: b.Expression, options?: ExpressionToConstantOptions): {

};
export declare function isConstant(src: string, constants?: any, options?: BabylonOptions): boolean;
export declare function toConstant(src: string, constants?: any, options?: BabylonOptions): any;
export declare function isConstant(src: string, constants?: any, options?: ParserOptions): boolean;
export declare function toConstant(src: string, constants?: any, options?: ParserOptions): any;
export default isConstant;
"use strict";
exports.__esModule = true;
var babylon_1 = require("babylon");
var b = require("babel-types");
var parser_1 = require("@babel/parser");
var b = require("@babel/types");
var binaryOperation_1 = require("./binaryOperation");

@@ -25,5 +25,8 @@ function expressionToConstant(expression, options) {

}
else {
else if (b.isExpression(element)) {
result_1.push(toConstant(element));
}
else {
constant = false;
}
}

@@ -53,5 +56,8 @@ return result_1;

}
else {
else if (b.isExpression(arg)) {
args.push(toConstant(arg));
}
else {
constant = false;
}
}

@@ -156,6 +162,11 @@ if (!constant)

return;
var value = toConstant(property.value);
if (!constant)
return;
result_2[key] = value;
if (b.isExpression(property.value)) {
var value = toConstant(property.value);
if (!constant)
return;
result_2[key] = value;
}
else {
constant = false;
}
}

@@ -332,3 +343,3 @@ else if (b.isObjectMethod(property)) {

try {
ast = babylon_1.parseExpression(src, options);
ast = parser_1.parseExpression(src, options);
}

@@ -335,0 +346,0 @@ catch (ex) {

{
"name": "constantinople",
"version": "3.1.2",
"version": "4.0.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"description": "Determine whether a JavaScript expression evaluates to a constant (using acorn)",
"description": "Determine whether a JavaScript expression evaluates to a constant",
"keywords": [
"acorn",
"constant",
"ast",

@@ -13,6 +13,4 @@ "tooling"

"dependencies": {
"@types/babel-types": "^7.0.0",
"@types/babylon": "^6.16.2",
"babel-types": "^6.26.0",
"babylon": "^6.18.0"
"@babel/types": "^7.6.1",
"@babel/parser": "^7.6.0"
},

@@ -19,0 +17,0 @@ "devDependencies": {

@@ -1,6 +0,6 @@

import {parseExpression, BabylonOptions} from 'babylon';
import * as b from 'babel-types';
import {parseExpression, ParserOptions} from '@babel/parser';
import * as b from '@babel/types';
import binaryOperation from './binaryOperation';
export {BabylonOptions};
export {ParserOptions as BabylonOptions};

@@ -12,3 +12,3 @@ export interface ExpressionToConstantOptions {

export interface Options extends ExpressionToConstantOptions {
babylon?: BabylonOptions;
babylon?: ParserOptions;
}

@@ -20,3 +20,3 @@ export function expressionToConstant(

let constant = true;
function toConstant(expression: b.Expression): any {
function toConstant(expression: b.CallExpression['callee']): any {
if (!constant) return;

@@ -34,4 +34,6 @@ if (b.isArrayExpression(expression)) {

}
} else if (b.isExpression(element)) {
result.push(toConstant(element));
} else {
result.push(toConstant(element));
constant = false;
}

@@ -60,4 +62,6 @@ }

}
} else if (b.isExpression(arg)) {
args.push(toConstant(arg));
} else {
args.push(toConstant(arg));
constant = false;
}

@@ -159,5 +163,9 @@ }

if (!constant) return;
const value = toConstant(property.value);
if (!constant) return;
result[key] = value;
if (b.isExpression(property.value)) {
const value = toConstant(property.value);
if (!constant) return;
result[key] = value;
} else {
constant = false;
}
} else if (b.isObjectMethod(property)) {

@@ -324,3 +332,3 @@ constant = false;

constants: any = EMPTY_OBJECT,
options: BabylonOptions = EMPTY_OBJECT,
options: ParserOptions = EMPTY_OBJECT,
) {

@@ -349,3 +357,3 @@ if (

constants: any = EMPTY_OBJECT,
options: BabylonOptions = EMPTY_OBJECT,
options: ParserOptions = EMPTY_OBJECT,
) {

@@ -352,0 +360,0 @@ if (!isConstant(src, constants, options)) {

@@ -31,4 +31,4 @@ 'use strict';

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

@@ -39,4 +39,4 @@ });

constaninople.isConstant(
'({}).toString.constructor("console.log(1)")()',
) === false,
'({}).toString.constructor("console.log(1)")()'
) === false
);

@@ -85,5 +85,5 @@ });

false,
'(function () { while (true); return 10; }()) should result in an error',
'(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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc