Browse files

adding support for private closure

  • Loading branch information...
1 parent 5ba69bb commit b33b64466f109630f53e1bda43ac3bae2b3fcf3f @jeffsu committed Jun 23, 2011
View
3 CHANGELOG
@@ -1,3 +1,6 @@
+0.3.19
+ * SYNTAX: added private closure block support "private { var foo = 'bar' }" within classes
+
0.3.18
* COMMAND: updaters should be using targetDir instead of outDir
* JSML: fixed empty space problem
View
29 dist/browser/js2-full.js
@@ -605,7 +605,7 @@ function mainFunction (arg) {
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -782,9 +782,26 @@ function mainFunction (arg) {
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
+ });
+
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
});
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -793,6 +810,7 @@ function mainFunction (arg) {
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
@@ -1128,6 +1146,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1237,6 +1256,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1282,6 +1302,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1353,6 +1374,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1439,6 +1461,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1483,6 +1506,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1682,6 +1706,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return (out.length ? ' ' : '') + out.join(' ');
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
(function (undefined, JS2) {
View
2 dist/browser/js2.js
@@ -269,6 +269,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -469,6 +470,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
View
3 dist/gem/CHANGELOG
@@ -1,3 +1,6 @@
+0.3.19
+ * SYNTAX: added private closure block support "private { var foo = 'bar' }" within classes
+
0.3.18
* COMMAND: updaters should be using targetDir instead of outDir
* JSML: fixed empty space problem
View
29 dist/gem/lib/js2/js2.js
@@ -601,7 +601,7 @@ function mainFunction (arg) {
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -778,9 +778,26 @@ function mainFunction (arg) {
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
+ });
+
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
});
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -789,6 +806,7 @@ function mainFunction (arg) {
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
@@ -1124,6 +1142,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1252,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1298,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1370,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1457,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1502,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1678,6 +1702,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return (out.length ? ' ' : '') + out.join(' ');
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
View
3 dist/npm/CHANGELOG
@@ -1,3 +1,6 @@
+0.3.19
+ * SYNTAX: added private closure block support "private { var foo = 'bar' }" within classes
+
0.3.18
* COMMAND: updaters should be using targetDir instead of outDir
* JSML: fixed empty space problem
View
30 dist/npm/lib/js2.js
@@ -601,7 +601,7 @@ function mainFunction (arg) {
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -778,9 +778,26 @@ function mainFunction (arg) {
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
});
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
+ });
+
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -789,6 +806,7 @@ function mainFunction (arg) {
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
@@ -1124,6 +1142,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1252,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1298,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1370,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1457,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1502,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1678,6 +1702,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return (out.length ? ' ' : '') + out.join(' ');
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
@@ -1732,6 +1757,7 @@ JS2.TEMPLATES = { jsml: JS2.JSML };
});
});
+
JS2.fs = new JS2.FileSystem(new JS2.NodeFileAdapter());
js2.DECORATOR = new JS2.NodeDecorator();
View
29 flavors/browser-full.js
@@ -605,7 +605,7 @@ function mainFunction (arg) {
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -782,9 +782,26 @@ function mainFunction (arg) {
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
+ });
+
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
});
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -793,6 +810,7 @@ function mainFunction (arg) {
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
@@ -1128,6 +1146,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1237,6 +1256,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1282,6 +1302,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1353,6 +1374,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1439,6 +1461,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1483,6 +1506,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1682,6 +1706,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return (out.length ? ' ' : '') + out.join(' ');
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
(function (undefined, JS2) {
View
2 flavors/browser.js
@@ -269,6 +269,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -469,6 +470,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
View
30 flavors/node.js
@@ -601,7 +601,7 @@ function mainFunction (arg) {
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -778,9 +778,26 @@ function mainFunction (arg) {
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
});
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
+ });
+
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -789,6 +806,7 @@ function mainFunction (arg) {
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
@@ -1124,6 +1142,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1252,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1298,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1370,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1457,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1502,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1678,6 +1702,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return (out.length ? ' ' : '') + out.join(' ');
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
@@ -1732,6 +1757,7 @@ JS2.TEMPLATES = { jsml: JS2.JSML };
});
});
+
JS2.fs = new JS2.FileSystem(new JS2.NodeFileAdapter());
js2.DECORATOR = new JS2.NodeDecorator();
View
30 flavors/ringo-full.js
@@ -603,7 +603,7 @@ function mainFunction (arg) {
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -780,9 +780,26 @@ function mainFunction (arg) {
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
});
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
+ });
+
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -791,6 +808,7 @@ function mainFunction (arg) {
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
@@ -1126,6 +1144,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1235,6 +1254,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1280,6 +1300,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1351,6 +1372,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1437,6 +1459,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1481,6 +1504,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1680,6 +1704,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return (out.length ? ' ' : '') + out.join(' ');
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
@@ -1735,6 +1760,7 @@ JS2.TEMPLATES = { jsml: JS2.JSML };
});
});
+
JS2.fs = new FileSystem(new RingoFileAdapter());
JS2.DECORATOR = new JS2.RingoDecorator();
View
2 flavors/ringo.js
@@ -266,6 +266,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -466,6 +467,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
View
29 flavors/ruby.js
@@ -601,7 +601,7 @@ function mainFunction (arg) {
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -778,9 +778,26 @@ function mainFunction (arg) {
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
+ });
+
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
});
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -789,6 +806,7 @@ function mainFunction (arg) {
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
@@ -1124,6 +1142,7 @@ JS2.Array.prototype.any = function() {
return this.length > 0;
};
+
JS2.Class.extend('FileSystem', function(KLASS, OO){
OO.addMember("initialize",function (adapter) {
this.adapter = adapter;
@@ -1233,6 +1252,7 @@ JS2.Class.extend('FileSystem', function(KLASS, OO){
});
});
+
JS2.Class.extend('Updater', function(KLASS, OO){
OO.addMember("initialize",function (fs, inDir, outDir, recursive) {
this.recursive = recursive;
@@ -1278,6 +1298,7 @@ JS2.Class.extend('Updater', function(KLASS, OO){
});
});
+
JS2.Class.extend('Config', function(KLASS, OO){
OO.addMember("CLI_REGEX",/^-(r|i|f|n|v|m)(=(\w+))?$/);
OO.addMember("optsLookup",{
@@ -1349,6 +1370,7 @@ JS2.Class.extend('Config', function(KLASS, OO){
});
+
JS2.Class.extend('Commander', function(KLASS, OO){
OO.addMember("BANNER","js2 <command> [options] <arguments>\n" +
"VERSION: " + JS2.VERSION + "\n" +
@@ -1435,6 +1457,7 @@ JS2.Class.extend('Commander', function(KLASS, OO){
});
+
JS2.Class.extend('BrowserDecorator', function(KLASS, OO){
OO.addMember("file",function (code) {
return code;
@@ -1479,6 +1502,7 @@ JS2.Class.extend('RingoDecorator', function(KLASS, OO){
JS2.DECORATOR = JS2.DECORATOR || new JS2.BrowserDecorator();
+
JS2.Class.extend('JSML', function(KLASS, OO){
OO.addStaticMember("process",function (txt) {
return new KLASS(txt);
@@ -1678,6 +1702,7 @@ JS2.Class.extend('JSMLElement', function(KLASS, OO){
return (out.length ? ' ' : '') + out.join(' ');
});
});
+
JS2.TEMPLATES = { jsml: JS2.JSML };
View
22 src/core/js2-parser.js
@@ -12,7 +12,7 @@
}
};
- var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null };
+ var KEYWORDS = { 'var': null, 'class': null, 'function': null, 'in': null, 'with': null, 'curry': null, 'static': null, 'module':null, 'private':null };
var IDS = JS2.Lexer.IDS;
IDS['NODE'] = -1;
@@ -189,9 +189,26 @@
if (this.tokens.isBalancedCurly(this) && token[0] == '}') {
this.closed = true;
}
- }
+ }
});
+ var Private = Content.extend({
+ name: 'Private',
+ handOff: function(token) {
+ if (this.started) this.closed = true;
+ switch (token[0]) {
+ case '{': this.started = true; return Block;
+ }
+ },
+
+ toString: function() {
+ var v = this.validate(/(private)(\s+)/);
+ var last = v.last;
+ return "// private closure\n" + last.replace(/^\{/, '').replace(/\}$/, '');
+ }
+ });
+
+
var KlassBlock = Block.extend({
name: 'KlassBlock',
handOff: function(token) {
@@ -200,6 +217,7 @@
case 'function': return Method;
case 'static': return StaticMember;
case 'include': return Include;
+ case 'private': return Private;
}
},
View
14 tests/src/private.js2
@@ -0,0 +1,14 @@
+class Foo {
+ private {
+ var hello = "hello";
+ }
+
+ function getHello() {
+ return hello;
+ }
+}
+
+js2.test(#(assert){
+ var foo = new Foo();
+ assert.eq(foo.getHello(), 'hello');
+});

0 comments on commit b33b644

Please sign in to comment.