/usr/lib/nodejs/constantinople/index.js is in node-constantinople 2.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 'use strict'
var uglify = require('uglify-js')
var lastSRC = '(null)'
var lastRes = true
var lastConstants = undefined;
module.exports = isConstant
function isConstant(src, constants) {
src = '(' + src + ')'
if (lastSRC === src && lastConstants === constants) return lastRes
lastSRC = src
try {
return lastRes = (detect(src).filter(function (key) {
return !constants || !(key in constants)
}).length === 0)
} catch (ex) {
return lastRes = false
}
}
isConstant.isConstant = isConstant
isConstant.toConstant = toConstant
function toConstant(src, constants) {
if (!isConstant(src, constants)) throw new Error(JSON.stringify(src) + ' is not constant.')
return Function(Object.keys(constants || {}).join(','), 'return (' + src + ')').apply(null, Object.keys(constants || {}).map(function (key) {
return constants[key];
}));
}
function detect(src) {
var ast = uglify.parse(src.toString())
ast.figure_out_scope()
var globals = ast.globals
.map(function (node, name) {
return name
})
return globals
}
|