Skip to content

Commit aeaf009

Browse files
committed
cleanup node inheritance
1 parent 7306e0e commit aeaf009

13 files changed

Lines changed: 30 additions & 18 deletions

File tree

lib/node/binary.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use strict';
2-
3-
var BinaryNode = module.exports = require(__dirname).define({
2+
var Node = require(__dirname);
3+
var BinaryNode = module.exports = Node.define({
44
type: 'BINARY',
55
constructor: function(config) {
6+
Node.call(this);
67
this.left = config.left;
78
this.operator = config.operator;
89
this.right = config.right;

lib/node/column.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var Node = require(__dirname);
55
module.exports = Node.define({
66
type: 'COLUMN',
77
constructor: function(config) {
8+
Node.call(this);
89
this.name = config.name;
910
this.alias = config.alias;
1011
this.star = config.star;

lib/node/index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var util = require('util');
34
var assert = require('assert');
45

56
var Node = function(type) {
@@ -25,20 +26,14 @@ Node.prototype.addAll = function(nodes) {
2526

2627
Node.define = function(def) {
2728
var c = function() {
28-
Node.apply(this, arguments);
29+
Node.call(this);
2930
};
3031
//allow custom sub-class constructor
31-
if(def.constructor) {
32-
c = function() {
33-
Node.apply(this, arguments);
34-
def.constructor.apply(this, arguments);
35-
};
32+
if(def.constructor && def.constructor != {}.constructor) {
33+
c = def.constructor;
3634
}
37-
var key;
38-
for(key in Node.prototype) {
39-
c.prototype[key] = Node.prototype[key];
40-
}
41-
for(key in def) {
35+
util.inherits(c, Node);
36+
for(var key in def) {
4237
c.prototype[key] = def[key];
4338
}
4439
return c;

lib/node/insert.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var DefaultNode = require('./default');
77
var Insert = Node.define({
88
type: 'INSERT',
99
constructor: function () {
10+
Node.call(this);
1011
this.names = [];
1112
this.columns = [];
1213
this.valueSets = [];

lib/node/join.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3-
var JoinNode = module.exports = require(__dirname).define({
3+
var Node = require(__dirname);
4+
var JoinNode = module.exports = Node.define({
45
type: 'JOIN',
56
constructor: function(subType, from, to) {
7+
Node.call(this);
68
this.subType = subType;
79
this.from = from.toNode();
810
this.to = to.toNode();

lib/node/orderByColumn.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3-
var OrderByColumn = module.exports = require(__dirname).define({
3+
var Node = require(__dirname);
4+
var OrderByColumn = module.exports = Node.define({
45
type: 'ORDER BY COLUMN',
56
constructor: function(config) {
7+
Node.call(this);
68
this.column = config.column;
79
this.direction = config.direction;
810
}

lib/node/parameter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3-
module.exports = require(__dirname).define({
3+
var Node = require(__dirname);
4+
module.exports = Node.define({
45
type: 'PARAMETER',
56
constructor: function(val) {
7+
Node.call(this);
68
this._val = val;
79
},
810
value: function() {

lib/node/query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var Modifier = Node.define({
3535
var Query = Node.define({
3636
type: 'QUERY',
3737
constructor: function(table) {
38+
Node.call(this);
3839
this.table = table;
3940
},
4041
select: function() {

lib/node/table.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3-
module.exports = require(__dirname).define({
3+
var Node = require(__dirname);
4+
module.exports = Node.define({
45
type: 'TABLE',
56
constructor: function(table) {
7+
Node.call(this);
68
this.table = table;
79
}
810
});

lib/node/text.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var Node = require(__dirname);
55
module.exports = Node.define({
66
type: 'TEXT',
77
constructor: function(text) {
8+
Node.call(this);
89
this.text = text;
910
}
1011
});

0 commit comments

Comments
 (0)