Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

defs

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defs - npm Package Compare versions

Comparing version 0.6.2 to 1.0.0

build/inline-version.js

42

build/es5/defs-cmd.js

@@ -7,11 +7,23 @@ "use strict";

var defs = require("./defs-main");
var version = "1.0.0";
var yargs = require("yargs")
.options("config", {});
var argv = yargs.argv;
if (process.argv.length <= 2) {
console.log("USAGE: defs file.js");
if (!argv._.length) {
var usage = [
"defs v" + version + "",
"",
"Usage: defs OPTIONS <file>",
"",
"Options: ",
" --config use specified defs-config.js instead of searching for it",
].join("\n");
console.error(usage);
process.exit(-1);
}
var filename = process.argv[2];
var filename = argv._[0];
if (!fs.existsSync(filename)) {
console.log(fmt("error: file not found <{0}>", filename));
console.error("error: file not found <%s>", filename);
process.exit(-1);

@@ -43,2 +55,16 @@ }

function findAndReadConfig() {
if (argv.config) {
var config = tryor(function() { return String(fs.readFileSync(argv.config)) }, null);
if (!config) {
console.error("error: config file not found <%s>", argv.config);
process.exit(-1);
}
var json = tryor(function() { return JSON.parse(config) }, null);
if (!json) {
console.error("error: config file is not valid JSON <%s>", argv.config);
process.exit(-1);
}
return json;
}
var path = "";

@@ -51,10 +77,10 @@ var filename = "defs-config.json";

if (fs.existsSync(filenamePath)) {
var config = tryor(function() {
var config$0 = tryor(function() {
return JSON.parse(String(fs.readFileSync(filenamePath)));
}, null);
if (config === null) {
console.error("error: bad JSON in %s", filenamePath);
if (config$0 === null) {
console.error("error: config file is not valid JSON <%s>", filenamePath);
process.exit(-1);
}
return config;
return config$0;
}

@@ -61,0 +87,0 @@

21

build/es5/defs-main.js

@@ -13,2 +13,3 @@ "use strict";

var error = require("./error");
var getline = error.getline;
var options = require("./options");

@@ -19,6 +20,2 @@ var Stats = require("./stats");

function getline(node) {
return node.loc.start.line;
}
function isConstLet(kind) {

@@ -40,6 +37,10 @@ return is.someof(kind, ["const", "let"]);

function isForInWithConstLet(node) {
return node.type === "ForInStatement" && node.left.type === "VariableDeclaration" && isConstLet(node.left.kind);
function isForInOfWithConstLet(node) {
return isForInOf(node) && node.left.type === "VariableDeclaration" && isConstLet(node.left.kind);
}
function isForInOf(node) {
return is.someof(node.type, ["ForInStatement", "ForOfStatement"]);
}
function isFunction(node) {

@@ -50,3 +51,3 @@ return is.someof(node.type, ["FunctionDeclaration", "FunctionExpression"]);

function isLoop(node) {
return is.someof(node.type, ["ForStatement", "ForInStatement", "WhileStatement", "DoWhileStatement"]);
return is.someof(node.type, ["ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement"]);
}

@@ -130,4 +131,4 @@

} else if (isForWithConstLet(node) || isForInWithConstLet(node)) {
// For(In) loop with const|let declaration is a scope, with declaration in it
} else if (isForWithConstLet(node) || isForInOfWithConstLet(node)) {
// For(In/Of) loop with const|let declaration is a scope, with declaration in it
// There may be a block-scope under it

@@ -496,3 +497,3 @@ node.$scope = new Scope({

var forInName = (node.type === "ForInStatement" && node.left.declarations[0].id.name);;
var forInName = (isForInOf(node) && node.left.declarations[0].id.name);;
var iifeHead = fmt("(function({0}){", forInName ? forInName : "");

@@ -499,0 +500,0 @@ var iifeTail = fmt("}).call(this{0});", forInName ? ", " + forInName : "");

@@ -19,4 +19,11 @@ "use strict";

error.getline = function(node) {
if (node && node.loc && node.loc.start) {
return node.loc.start.line;
}
return -1;
};
error.reset();
module.exports = error;

@@ -9,2 +9,3 @@ "use strict";

var error = require("./error");
var getline = error.getline;
var options = require("./options");

@@ -88,3 +89,3 @@

if (scope.decls.has(name) && isConstLet(scope.decls.get(name).kind)) { // could be caught
return error(node.loc.start.line, "{0} is already declared", name);
return error(getline(node), "{0} is already declared", name);
}

@@ -96,3 +97,3 @@ scope = scope.parent;

if (scope.decls.has(name) && (options.disallowDuplicated || isConstLet(scope.decls.get(name).kind) || isConstLet(kind))) {
return error(node.loc.start.line, "{0} is already declared", name);
return error(getline(node), "{0} is already declared", name);
}

@@ -194,3 +195,3 @@

if (scope.getKind(name) === "let" && !scope.written.has(name)) {
return error(scope.getNode(name).loc.start.line, "{0} is declared as let but never modified so could be const", name);
return error(getline(scope.getNode(name)), "{0} is declared as let but never modified so could be const", name);
}

@@ -201,3 +202,3 @@ });

scope.children.forEach(function(childScope) {
detect(childScope);;
detect(childScope);
});

@@ -204,0 +205,0 @@ }

@@ -7,11 +7,23 @@ "use strict";

const defs = require("./defs-main");
const version = require("./package.json").version;
const yargs = require("yargs")
.options("config", {});
const argv = yargs.argv;
if (process.argv.length <= 2) {
console.log("USAGE: defs file.js");
if (!argv._.length) {
const usage = [
"defs v" + version + "",
"",
"Usage: defs OPTIONS <file>",
"",
"Options: ",
" --config use specified defs-config.js instead of searching for it",
].join("\n");
console.error(usage);
process.exit(-1);
}
const filename = process.argv[2];
const filename = argv._[0];
if (!fs.existsSync(filename)) {
console.log(fmt("error: file not found <{0}>", filename));
console.error("error: file not found <%s>", filename);
process.exit(-1);

@@ -43,2 +55,16 @@ }

function findAndReadConfig() {
if (argv.config) {
const config = tryor(function() { return String(fs.readFileSync(argv.config)) }, null);
if (!config) {
console.error("error: config file not found <%s>", argv.config);
process.exit(-1);
}
const json = tryor(function() { return JSON.parse(config) }, null);
if (!json) {
console.error("error: config file is not valid JSON <%s>", argv.config);
process.exit(-1);
}
return json;
}
let path = "";

@@ -55,3 +81,3 @@ let filename = "defs-config.json";

if (config === null) {
console.error("error: bad JSON in %s", filenamePath);
console.error("error: config file is not valid JSON <%s>", filenamePath);
process.exit(-1);

@@ -58,0 +84,0 @@ }

@@ -13,2 +13,3 @@ "use strict";

const error = require("./error");
const getline = error.getline;
const options = require("./options");

@@ -19,6 +20,2 @@ const Stats = require("./stats");

function getline(node) {
return node.loc.start.line;
}
function isConstLet(kind) {

@@ -40,6 +37,10 @@ return is.someof(kind, ["const", "let"]);

function isForInWithConstLet(node) {
return node.type === "ForInStatement" && node.left.type === "VariableDeclaration" && isConstLet(node.left.kind);
function isForInOfWithConstLet(node) {
return isForInOf(node) && node.left.type === "VariableDeclaration" && isConstLet(node.left.kind);
}
function isForInOf(node) {
return is.someof(node.type, ["ForInStatement", "ForOfStatement"]);
}
function isFunction(node) {

@@ -50,3 +51,3 @@ return is.someof(node.type, ["FunctionDeclaration", "FunctionExpression"]);

function isLoop(node) {
return is.someof(node.type, ["ForStatement", "ForInStatement", "WhileStatement", "DoWhileStatement"]);
return is.someof(node.type, ["ForStatement", "ForInStatement", "ForOfStatement", "WhileStatement", "DoWhileStatement"]);
}

@@ -130,4 +131,4 @@

} else if (isForWithConstLet(node) || isForInWithConstLet(node)) {
// For(In) loop with const|let declaration is a scope, with declaration in it
} else if (isForWithConstLet(node) || isForInOfWithConstLet(node)) {
// For(In/Of) loop with const|let declaration is a scope, with declaration in it
// There may be a block-scope under it

@@ -496,3 +497,3 @@ node.$scope = new Scope({

const forInName = (node.type === "ForInStatement" && node.left.declarations[0].id.name);;
const forInName = (isForInOf(node) && node.left.declarations[0].id.name);;
const iifeHead = fmt("(function({0}){", forInName ? forInName : "");

@@ -499,0 +500,0 @@ const iifeTail = fmt("}).call(this{0});", forInName ? ", " + forInName : "");

@@ -19,4 +19,11 @@ "use strict";

error.getline = function(node) {
if (node && node.loc && node.loc.start) {
return node.loc.start.line;
}
return -1;
};
error.reset();
module.exports = error;
{
"name": "defs",
"version": "0.6.2",
"version": "1.0.0",
"description": "Static scope analysis and transpilation of ES6 block scoped const and let variables, to ES3.",

@@ -12,4 +12,5 @@ "main": "build/es5/defs-main.js",

"alter": "~0.2.0",
"breakable": "~0.1.0",
"ast-traverse": "~0.1.1",
"breakable": "~1.0.0",
"esprima": "git://github.com/ariya/esprima.git#harmony",
"simple-fmt": "~0.1.0",

@@ -20,6 +21,6 @@ "simple-is": "~0.2.0",

"tryor": "~0.1.2",
"esprima": "~1.0.0"
"yargs": "~1.2.6"
},
"devDependencies": {
"diff": "~1.0.7"
"diff": "~1.0.8"
},

@@ -26,0 +27,0 @@ "keywords": [

@@ -41,2 +41,4 @@ # defs.js

directory. If not found there, it searches parent directories until it hits `/`.
You may instead pass a custom `defs-config.json` using `--config`, i.e.
`defs --config path/to/defs-config.json file.js > output.js`.

@@ -43,0 +45,0 @@ Example `defs-config.json`:

@@ -9,2 +9,3 @@ "use strict";

const error = require("./error");
const getline = error.getline;
const options = require("./options");

@@ -88,3 +89,3 @@

if (scope.decls.has(name) && isConstLet(scope.decls.get(name).kind)) { // could be caught
return error(node.loc.start.line, "{0} is already declared", name);
return error(getline(node), "{0} is already declared", name);
}

@@ -96,3 +97,3 @@ scope = scope.parent;

if (scope.decls.has(name) && (options.disallowDuplicated || isConstLet(scope.decls.get(name).kind) || isConstLet(kind))) {
return error(node.loc.start.line, "{0} is already declared", name);
return error(getline(node), "{0} is already declared", name);
}

@@ -194,3 +195,3 @@

if (scope.getKind(name) === "let" && !scope.written.has(name)) {
return error(scope.getNode(name).loc.start.line, "{0} is declared as let but never modified so could be const", name);
return error(getline(scope.getNode(name)), "{0} is declared as let but never modified so could be const", name);
}

@@ -201,3 +202,3 @@ });

scope.children.forEach(function(childScope) {
detect(childScope);;
detect(childScope);
});

@@ -204,0 +205,0 @@ }

@@ -10,3 +10,3 @@ "use strict";

// can be transformed (common manual work-around)
for (var x$0 in [0,1,2]) {
for (var x$0 = 0; x$0 < 3; x$0++) {
arr.push((function(x) { return function() { return x; } })(x$0));

@@ -84,2 +84,13 @@ }

// For-Of
for (var x$9 of [0,1,2]) {(function(x){
arr.push(function() { return x; });
}).call(this, x$9);}
// Block-less For-Of
for (var x$10 of [0,1,2]) (function(x){arr.push(function() { return x; });}).call(this, x$10);/*with semicolon*/
for (var x$11 of [0,1,2]) (function(x){arr.push(function() { return x; })/*no semicolon*/
}).call(this, x$11);null; // previous semicolon-less for statement's range ends just before 'n' in 'null'
// While

@@ -86,0 +97,0 @@ while (true) {(function(){

@@ -10,3 +10,3 @@ "use strict";

// can be transformed (common manual work-around)
for (let x in [0,1,2]) {
for (let x = 0; x < 3; x++) {
arr.push((function(x) { return function() { return x; } })(x));

@@ -84,2 +84,13 @@ }

// For-Of
for (let x of [0,1,2]) {
arr.push(function() { return x; });
}
// Block-less For-Of
for (let x of [0,1,2]) arr.push(function() { return x; });/*with semicolon*/
for (let x of [0,1,2]) arr.push(function() { return x; })/*no semicolon*/
null; // previous semicolon-less for statement's range ends just before 'n' in 'null'
// While

@@ -86,0 +97,0 @@ while (true) {

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