Skip to content

Commit ea21cbf

Browse files
authored
Merge pull request #27 from ettic-team/wip
Fixed bug & code improvement
2 parents 5c1c666 + da8e7f3 commit ea21cbf

9 files changed

Lines changed: 56 additions & 8 deletions

classes/concatenation.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
/// class Concatenation
22

33
function Concatenation(value1, value2) {
4+
if (value1 === null) {
5+
throw new Error("value1 can't be null");
6+
}
7+
8+
if (value2 === null) {
9+
throw new Error("value1 can't be null");
10+
}
11+
412
this.values = [];
513
this.values.push(value1);
614
this.values.push(value2);
@@ -22,4 +30,4 @@ Concatenation.prototype.equals = function (val) {
2230
return val.values[0].equals(this.values[0]) && val.values[1].equals(this.values[1]);
2331
}
2432

25-
module.exports = Concatenation;
33+
module.exports = Concatenation;

classes/constant.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Constant.prototype.equals = function (val) {
1616
return this.value === val.value;
1717
}
1818

19-
module.exports = Constant;
19+
module.exports = Constant;

classes/function-argument.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
/// class FunctionArgument
22

33
function FunctionArgument(fnct, variableName, index) {
4+
if (!fnct) {
5+
throw new Error("Type of fnct must be string or object.");
6+
}
7+
8+
if (typeof variableName !== "string") {
9+
throw new Error("Type of variableName must be string.");
10+
}
11+
12+
if (typeof index !== "number") {
13+
throw new Error("Type of index must be number.");
14+
}
15+
416
this.name = variableName;
517
this.fnct = fnct;
618
this.index = index;

classes/function-invocation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ FunctionInvocation.prototype.equals = function (val) {
2929
return good;
3030
}
3131

32-
module.exports = FunctionInvocation;
32+
module.exports = FunctionInvocation;

classes/global-function-call.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
/// class GlobalFunctionCall
22

33
function GlobalFunctionCall(name, args) {
4+
if (typeof name !== "string") {
5+
throw new Error("Type of name must be string.");
6+
}
7+
8+
if (typeof args !== "object" || typeof args.length !== "number") {
9+
throw new Error("Type of args must be array.");
10+
}
11+
412
this.name = name;
513
this.arguments = args;
614
}
@@ -41,4 +49,4 @@ GlobalFunctionCall.prototype.equals = function (val) {
4149
return good;
4250
}
4351

44-
module.exports = GlobalFunctionCall;
52+
module.exports = GlobalFunctionCall;

classes/local-function-call.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
/// class LocalFunctionCall
22

33
function LocalFunctionCall(reference, args) {
4+
if (reference == null) {
5+
throw new Exception("Reference is null.");
6+
}
7+
8+
if (typeof args !== "object" || typeof args.length !== "number") {
9+
throw new Error("Type of args must be array.");
10+
}
11+
412
this.arguments = args;
513
this.reference = reference;
614
}
@@ -19,7 +27,7 @@ LocalFunctionCall.prototype.equals = function (val) {
1927
return false;
2028
}
2129

22-
if (!this.reference.equals(val.reference)) {
30+
if (this.reference !== val.reference) {
2331
return false;
2432
}
2533

@@ -38,4 +46,4 @@ LocalFunctionCall.prototype.equals = function (val) {
3846
return good;
3947
}
4048

41-
module.exports = LocalFunctionCall;
49+
module.exports = LocalFunctionCall;

classes/member-expression.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/// class MemberExpression
22

33
function MemberExpression(parts) {
4+
if (typeof parts !== "object" || typeof parts.length !== "number") {
5+
throw new Error("Type of parts must be array.");
6+
}
7+
48
this.parts = parts;
59
}
610

@@ -33,4 +37,4 @@ MemberExpression.prototype.equals = function (val) {
3337
return good;
3438
}
3539

36-
module.exports = MemberExpression;
40+
module.exports = MemberExpression;

classes/object-function-call.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
var MemberExpression = require("./member-expression");
44

55
function ObjectFunctionCall(members, args) {
6+
if (typeof args !== "object" || typeof args.length !== "number") {
7+
throw new Error("Type of args must be array.");
8+
}
9+
610
this.members = new MemberExpression(members);
711
this.arguments = args;
812
}

classes/reference.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
var CONST_SEPARATOR_ID = "&&&";
44

55
function Reference(name) {
6+
if (typeof name !== "string") {
7+
throw new Error("Type of name must be string.");
8+
}
9+
610
this.name = name;
711
}
812

@@ -18,4 +22,4 @@ Reference.prototype.equals = function (val) {
1822
return this.name === val.name;
1923
}
2024

21-
module.exports = Reference;
25+
module.exports = Reference;

0 commit comments

Comments
 (0)