mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 23:40:23 +00:00
added class as a constant keyword to generated code
This commit is contained in:
parent
b5195b8f67
commit
ee82dae318
2 changed files with 11 additions and 6 deletions
11
src/Scope.js
11
src/Scope.js
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue