Skip to content

Commit ee82dae

Browse files
committed
added class as a constant keyword to generated code
1 parent b5195b8 commit ee82dae

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Scope.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,22 @@ function setter(instance, path, value){
4646
///////////////////////////////////
4747

4848
var getterFnCache = {};
49-
var JS_KEYWORDS = ["this", "throw", "for", "foreach", "var", "const"];
49+
var JS_KEYWORDS = {};
50+
foreach(
51+
["break", "const", "continue", "class", "delete",
52+
"do", "while", "for", "function", "if",
53+
"instanceof", "new", "return", "switch",
54+
"this", "throw", "try", "catch", "with"],
55+
function(key){ JS_KEYWORDS[key] = true;}
56+
);
5057
function getterFn(path){
5158
var fn = getterFnCache[path];
5259
if (fn) return fn;
5360

5461
var code = 'function (self){\n';
5562
code += ' var last, fn, type;\n';
5663
foreach(path.split('.'), function(key) {
57-
key = (includes(JS_KEYWORDS, key)) ? '["' + key + '"]' : '.' + key;
64+
key = (JS_KEYWORDS[key]) ? '["' + key + '"]' : '.' + key;
5865
code += ' if(!self) return self;\n';
5966
code += ' last = self;\n';
6067
code += ' self = self' + key + ';\n';

test/BinderTest.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,14 +396,12 @@ BinderTest.prototype.testBindClass = function() {
396396
c.scope.$set('class', 'testClass');
397397
c.scope.$eval();
398398

399-
assertEquals(sortedHtml(c.node),
400-
'<div class="testClass" ng:class="class"></div>');
399+
assertEquals('<div class="testClass" ng:class="class"></div>', sortedHtml(c.node));
401400

402401
c.scope.$set('class', ['a', 'b']);
403402
c.scope.$eval();
404403

405-
assertEquals(sortedHtml(c.node),
406-
'<div class="a b" ng:class="class"></div>');
404+
assertEquals('<div class="a b" ng:class="class"></div>', sortedHtml(c.node));
407405
};
408406

409407
BinderTest.prototype.testBindClassEvenOdd = function() {

0 commit comments

Comments
 (0)