mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-09 07:14:44 +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 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){
|
function getterFn(path){
|
||||||
var fn = getterFnCache[path];
|
var fn = getterFnCache[path];
|
||||||
if (fn) return fn;
|
if (fn) return fn;
|
||||||
|
|
@ -54,7 +61,7 @@ function getterFn(path){
|
||||||
var code = 'function (self){\n';
|
var code = 'function (self){\n';
|
||||||
code += ' var last, fn, type;\n';
|
code += ' var last, fn, type;\n';
|
||||||
foreach(path.split('.'), function(key) {
|
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 += ' if(!self) return self;\n';
|
||||||
code += ' last = self;\n';
|
code += ' last = self;\n';
|
||||||
code += ' self = self' + key + ';\n';
|
code += ' self = self' + key + ';\n';
|
||||||
|
|
|
||||||
|
|
@ -396,14 +396,12 @@ BinderTest.prototype.testBindClass = function() {
|
||||||
c.scope.$set('class', 'testClass');
|
c.scope.$set('class', 'testClass');
|
||||||
c.scope.$eval();
|
c.scope.$eval();
|
||||||
|
|
||||||
assertEquals(sortedHtml(c.node),
|
assertEquals('<div class="testClass" ng:class="class"></div>', sortedHtml(c.node));
|
||||||
'<div class="testClass" ng:class="class"></div>');
|
|
||||||
|
|
||||||
c.scope.$set('class', ['a', 'b']);
|
c.scope.$set('class', ['a', 'b']);
|
||||||
c.scope.$eval();
|
c.scope.$eval();
|
||||||
|
|
||||||
assertEquals(sortedHtml(c.node),
|
assertEquals('<div class="a b" ng:class="class"></div>', sortedHtml(c.node));
|
||||||
'<div class="a b" ng:class="class"></div>');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BinderTest.prototype.testBindClassEvenOdd = function() {
|
BinderTest.prototype.testBindClassEvenOdd = function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue