added class as a constant keyword to generated code

This commit is contained in:
Misko Hevery 2010-07-08 10:40:54 -07:00
parent b5195b8f67
commit ee82dae318
2 changed files with 11 additions and 6 deletions

View file

@ -46,7 +46,14 @@ function setter(instance, path, value){
///////////////////////////////////
var getterFnCache = {};
var JS_KEYWORDS = ["this", "throw", "for", "foreach", "var", "const"];
var JS_KEYWORDS = {};
foreach(
["break", "const", "continue", "class", "delete",
"do", "while", "for", "function", "if",
"instanceof", "new", "return", "switch",
"this", "throw", "try", "catch", "with"],
function(key){ JS_KEYWORDS[key] = true;}
);
function getterFn(path){
var fn = getterFnCache[path];
if (fn) return fn;
@ -54,7 +61,7 @@ function getterFn(path){
var code = 'function (self){\n';
code += ' var last, fn, type;\n';
foreach(path.split('.'), function(key) {
key = (includes(JS_KEYWORDS, key)) ? '["' + key + '"]' : '.' + key;
key = (JS_KEYWORDS[key]) ? '["' + key + '"]' : '.' + key;
code += ' if(!self) return self;\n';
code += ' last = self;\n';
code += ' self = self' + key + ';\n';

View file

@ -396,14 +396,12 @@ BinderTest.prototype.testBindClass = function() {
c.scope.$set('class', 'testClass');
c.scope.$eval();
assertEquals(sortedHtml(c.node),
'<div class="testClass" ng:class="class"></div>');
assertEquals('<div class="testClass" ng:class="class"></div>', sortedHtml(c.node));
c.scope.$set('class', ['a', 'b']);
c.scope.$eval();
assertEquals(sortedHtml(c.node),
'<div class="a b" ng:class="class"></div>');
assertEquals('<div class="a b" ng:class="class"></div>', sortedHtml(c.node));
};
BinderTest.prototype.testBindClassEvenOdd = function() {