@dacely/toildefender 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/estest.js CHANGED
@@ -1,49 +1,49 @@
1
- "use strict";
2
-
3
- var assert = require("assert");
4
-
5
- var _ = require("lodash");
6
-
7
- const EXPRESSIONS = [
8
- "Identifier"
9
- ];
10
-
11
- const COMPOUND_STATEMENTS = [
12
- "BlockStatement",
13
- "WithStatement",
14
- "IfStatement",
15
- "SwitchStatement",
16
- "TryStatement",
17
- "WhileStatement",
18
- "DoWhileStatement",
19
- "ForStatement",
20
- "ForInStatement"
21
- ];
22
-
23
- exports.isNode = function (x) {
24
- return x != null && typeof x.type == "string";
25
- };
26
-
27
- exports.isStatement = function (x) {
28
- assert.ok(exports.isNode(x));
29
-
30
- return x.type == "Program" || _.endsWith(x.type, "Statement") || _.endsWith(x.type, "Declaration");
31
- };
32
-
33
- exports.isCompoundStatement = function (x) {
34
- assert.ok(exports.isNode(x));
35
-
36
- return _.includes(COMPOUND_STATEMENTS.indexOf, x.type);
37
- };
38
-
39
- exports.isExpression = function (x) {
40
- assert.ok(exports.isNode(x));
41
-
42
- return _.includes(EXPRESSIONS, x.type) || _.endsWith(x.type, "Expression");
43
- };
44
-
45
- exports.isFunction = function (x) {
46
- assert.ok(exports.isNode(x));
47
-
48
- return _.startsWith(x.type, "Function");
49
- };
1
+ "use strict";
2
+
3
+ var assert = require("assert");
4
+
5
+ var _ = require("lodash");
6
+
7
+ const EXPRESSIONS = [
8
+ "Identifier"
9
+ ];
10
+
11
+ const COMPOUND_STATEMENTS = [
12
+ "BlockStatement",
13
+ "WithStatement",
14
+ "IfStatement",
15
+ "SwitchStatement",
16
+ "TryStatement",
17
+ "WhileStatement",
18
+ "DoWhileStatement",
19
+ "ForStatement",
20
+ "ForInStatement"
21
+ ];
22
+
23
+ exports.isNode = function (x) {
24
+ return x != null && typeof x.type == "string";
25
+ };
26
+
27
+ exports.isStatement = function (x) {
28
+ assert.ok(exports.isNode(x));
29
+
30
+ return x.type == "Program" || _.endsWith(x.type, "Statement") || _.endsWith(x.type, "Declaration");
31
+ };
32
+
33
+ exports.isCompoundStatement = function (x) {
34
+ assert.ok(exports.isNode(x));
35
+
36
+ return _.includes(COMPOUND_STATEMENTS.indexOf, x.type);
37
+ };
38
+
39
+ exports.isExpression = function (x) {
40
+ assert.ok(exports.isNode(x));
41
+
42
+ return _.includes(EXPRESSIONS, x.type) || _.endsWith(x.type, "Expression");
43
+ };
44
+
45
+ exports.isFunction = function (x) {
46
+ assert.ok(exports.isNode(x));
47
+
48
+ return _.startsWith(x.type, "Function");
49
+ };
package/esutils.js CHANGED
@@ -1,107 +1,107 @@
1
- "use strict";
2
-
3
- var assert = require("assert");
4
-
5
- var estest = require("./estest");
6
- var traverser = require("./traverser");
7
-
8
- module.exports = function (logger) {
9
-
10
- this.setParents = function (node) {
11
- assert.ok(estest.isNode(node));
12
-
13
- traverser.visitChildrenEx(node, (child, key) => {
14
- Object.defineProperty(child, "veilmark$parent", {
15
- value: node,
16
- configurable: true
17
- });
18
- return child;
19
- });
20
- };
21
-
22
- this.setParentsRecursive = function (node) {
23
- assert.ok(estest.isNode(node));
24
-
25
- traverser.visitChildrenEx(node, (child, key) => {
26
- Object.defineProperty(child, "veilmark$parent", {
27
- value: node,
28
- configurable: true
29
- });
30
- this.setParentsRecursive(child);
31
- return child;
32
- });
33
- };
34
-
35
- this.insertIntoScope = function (scope, node, idx) {
36
- assert.ok(estest.isNode(node));
37
-
38
- idx = idx || 0;
39
-
40
- if (scope.block.body.type == "Program" || scope.block.body.type == "BlockStatement") {
41
- scope.block.body.body.splice(idx, 0, node);
42
-
43
- Object.defineProperty(node, "veilmark$parent", {
44
- value: scope.block.body,
45
- configurable: true
46
- });
47
- } else if (scope.block.type == "Program" || scope.block.type == "BlockStatement") {
48
- scope.block.body.splice(idx, 0, node);
49
-
50
- Object.defineProperty(node, "veilmark$parent", {
51
- value: scope.block,
52
- configurable: true
53
- });
54
- } else {
55
- throw new Error("Cannot insert into scope.block of type " + scope.block.type);
56
- }
57
- };
58
-
59
- this.replaceNode = function (root, child, replacement) {
60
- assert.ok(estest.isNode(root));
61
- assert.ok(estest.isNode(child));
62
- assert.ok(estest.isNode(replacement));
63
- assert.equal(estest.isStatement(child), estest.isStatement(replacement), `Replacee ${child.type} is not of the same type as replacement ${replacement.type}`);
64
- assert.equal(estest.isExpression(child), estest.isExpression(replacement), `Replacee ${child.type} is not of the same type as replacement ${replacement.type}`);
65
-
66
- var _this = this;
67
- root = this.getParent(child) || root;
68
- traverser.traverseEx(root, [], function (node, stack) {
69
- if (node == child) {
70
- this.abort();
71
- Object.defineProperty(replacement, "veilmark$parent", {
72
- value: child.veilmark$parent,
73
- configurable: true
74
- });
75
- _this.setParents(replacement);
76
- return replacement;
77
- } else {
78
- return node;
79
- }
80
- });
81
- };
82
-
83
- this.getParent = function (node) {
84
- assert.ok(estest.isNode(node));
85
-
86
- var parent = node.veilmark$parent;
87
- var legit = false;
88
- if (parent) {
89
- traverser.visitChildren(parent, child => {
90
- if (node == child) {
91
- legit = true;
92
- }
93
- return child;
94
- });
95
- }
96
- if (legit) {
97
- return parent;
98
- } else if (parent) {
99
- logger.debug("Child has wrong parent");
100
- return null;
101
- } else {
102
- logger.debug("Child has no parent");
103
- return null;
104
- }
105
- };
106
-
107
- };
1
+ "use strict";
2
+
3
+ var assert = require("assert");
4
+
5
+ var estest = require("./estest");
6
+ var traverser = require("./traverser");
7
+
8
+ module.exports = function (logger) {
9
+
10
+ this.setParents = function (node) {
11
+ assert.ok(estest.isNode(node));
12
+
13
+ traverser.visitChildrenEx(node, (child, key) => {
14
+ Object.defineProperty(child, "veilmark$parent", {
15
+ value: node,
16
+ configurable: true
17
+ });
18
+ return child;
19
+ });
20
+ };
21
+
22
+ this.setParentsRecursive = function (node) {
23
+ assert.ok(estest.isNode(node));
24
+
25
+ traverser.visitChildrenEx(node, (child, key) => {
26
+ Object.defineProperty(child, "veilmark$parent", {
27
+ value: node,
28
+ configurable: true
29
+ });
30
+ this.setParentsRecursive(child);
31
+ return child;
32
+ });
33
+ };
34
+
35
+ this.insertIntoScope = function (scope, node, idx) {
36
+ assert.ok(estest.isNode(node));
37
+
38
+ idx = idx || 0;
39
+
40
+ if (scope.block.body.type == "Program" || scope.block.body.type == "BlockStatement") {
41
+ scope.block.body.body.splice(idx, 0, node);
42
+
43
+ Object.defineProperty(node, "veilmark$parent", {
44
+ value: scope.block.body,
45
+ configurable: true
46
+ });
47
+ } else if (scope.block.type == "Program" || scope.block.type == "BlockStatement") {
48
+ scope.block.body.splice(idx, 0, node);
49
+
50
+ Object.defineProperty(node, "veilmark$parent", {
51
+ value: scope.block,
52
+ configurable: true
53
+ });
54
+ } else {
55
+ throw new Error("Cannot insert into scope.block of type " + scope.block.type);
56
+ }
57
+ };
58
+
59
+ this.replaceNode = function (root, child, replacement) {
60
+ assert.ok(estest.isNode(root));
61
+ assert.ok(estest.isNode(child));
62
+ assert.ok(estest.isNode(replacement));
63
+ assert.equal(estest.isStatement(child), estest.isStatement(replacement), `Replacee ${child.type} is not of the same type as replacement ${replacement.type}`);
64
+ assert.equal(estest.isExpression(child), estest.isExpression(replacement), `Replacee ${child.type} is not of the same type as replacement ${replacement.type}`);
65
+
66
+ var _this = this;
67
+ root = this.getParent(child) || root;
68
+ traverser.traverseEx(root, [], function (node, stack) {
69
+ if (node == child) {
70
+ this.abort();
71
+ Object.defineProperty(replacement, "veilmark$parent", {
72
+ value: child.veilmark$parent,
73
+ configurable: true
74
+ });
75
+ _this.setParents(replacement);
76
+ return replacement;
77
+ } else {
78
+ return node;
79
+ }
80
+ });
81
+ };
82
+
83
+ this.getParent = function (node) {
84
+ assert.ok(estest.isNode(node));
85
+
86
+ var parent = node.veilmark$parent;
87
+ var legit = false;
88
+ if (parent) {
89
+ traverser.visitChildren(parent, child => {
90
+ if (node == child) {
91
+ legit = true;
92
+ }
93
+ return child;
94
+ });
95
+ }
96
+ if (legit) {
97
+ return parent;
98
+ } else if (parent) {
99
+ logger.debug("Child has wrong parent");
100
+ return null;
101
+ } else {
102
+ logger.debug("Child has no parent");
103
+ return null;
104
+ }
105
+ };
106
+
107
+ };
package/logger.js CHANGED
@@ -1,28 +1,28 @@
1
-
2
- module.exports = function (adapter) {
3
-
4
- adapter = adapter || function (level, args) {
5
- console.log(level + ": " + JSON.stringify(args));
6
- };
7
-
8
- this.log = function () {
9
- adapter("log", Array.prototype.slice.call(arguments));
10
- };
11
-
12
- this.error = function () {
13
- adapter("error", Array.prototype.slice.call(arguments));
14
- };
15
-
16
- this.warn = function () {
17
- adapter("warn", Array.prototype.slice.call(arguments));
18
- };
19
-
20
- this.info = function () {
21
- adapter("info", Array.prototype.slice.call(arguments));
22
- };
23
-
24
- this.debug = function () {
25
- adapter("debug", Array.prototype.slice.call(arguments));
26
- };
27
-
28
- };
1
+
2
+ module.exports = function (adapter) {
3
+
4
+ adapter = adapter || function (level, args) {
5
+ console.log(level + ": " + JSON.stringify(args));
6
+ };
7
+
8
+ this.log = function () {
9
+ adapter("log", Array.prototype.slice.call(arguments));
10
+ };
11
+
12
+ this.error = function () {
13
+ adapter("error", Array.prototype.slice.call(arguments));
14
+ };
15
+
16
+ this.warn = function () {
17
+ adapter("warn", Array.prototype.slice.call(arguments));
18
+ };
19
+
20
+ this.info = function () {
21
+ adapter("info", Array.prototype.slice.call(arguments));
22
+ };
23
+
24
+ this.debug = function () {
25
+ adapter("debug", Array.prototype.slice.call(arguments));
26
+ };
27
+
28
+ };