aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2010-12-07 11:47:24 -0800
committerMisko Hevery2010-12-08 14:36:51 -0800
commite5e69d9b90850eb653883f52c76e28dd870ee067 (patch)
treea6b8fdbffebe9e6a51a0a33327da56db4a860527
parentfa722447f89e0215463cb39dfd1532189057fea8 (diff)
downloadangular.js-e5e69d9b90850eb653883f52c76e28dd870ee067.tar.bz2
Remove RegExp parser
- RegExp parser is rearly used, feature, and one should not have RegExps in views anyways, so we are removing it BACKWARD INCOMPATIBLE CHANGE!!!
-rw-r--r--CHANGELOG.md5
-rw-r--r--src/Scope.js2
-rw-r--r--src/parser.js33
-rw-r--r--src/validators.js3
-rw-r--r--test/ParserSpec.js25
-rw-r--r--test/ScopeSpec.js5
6 files changed, 13 insertions, 60 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 56a43cfa..ef12d078 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,11 @@
### Bug Fixes
- Fixed failed assignments of form obj[0].name=value (issue #169)
+### Breaking changes
+- Angular expressions in the view used to support regular expressions. This feature was rarely
+ used and added unnecessary complexity. It not a good idea to have regexps in the view anyway,
+ so we removed this support. If you had any regexp in your views, you will have to move them to
+ your controllers.
# <angular/> 0.9.6 night-vision (2010-12-06) #
diff --git a/src/Scope.js b/src/Scope.js
index 203507a3..27df770d 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -66,7 +66,7 @@ function getterFn(path){
code += 'if(!s) return s;\n' +
'l=s;\n' +
's=s' + key + ';\n' +
- 'if(typeof s=="function") s = function(){ return l'+key+'.apply(l, arguments); };\n';
+ 'if(typeof s=="function" && !(s instanceof RegExp)) s = function(){ return l'+key+'.apply(l, arguments); };\n';
if (key.charAt(1) == '$') {
// special code for super-imposed functions
var name = key.substr(2);
diff --git a/src/parser.js b/src/parser.js
index 621b0045..01edb3f1 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -40,8 +40,6 @@ function lex(text, parseStringsForObjects){
readString(ch);
} else if (isNumber(ch) || is('.') && isNumber(peek())) {
readNumber();
- } else if ( was('({[:,;') && is('/') ) {
- readRegexp();
} else if (isIdent(ch)) {
readIdent();
if (was('{,') && json[0]=='{' &&
@@ -207,37 +205,6 @@ function lex(text, parseStringsForObjects){
}
throwError("Unterminated quote", start);
}
- function readRegexp(quote) {
- var start = index;
- index++;
- var regexp = "";
- var escape = false;
- while (index < text.length) {
- var ch = text.charAt(index);
- if (escape) {
- regexp += ch;
- escape = false;
- } else if (ch === '\\') {
- regexp += ch;
- escape = true;
- } else if (ch === '/') {
- index++;
- var flags = "";
- if (isIdent(text.charAt(index))) {
- readIdent();
- flags = tokens.pop().text;
- }
- var compiledRegexp = new RegExp(regexp, flags);
- tokens.push({index:start, text:regexp, flags:flags,
- fn:function(){return compiledRegexp;}});
- return;
- } else {
- regexp += ch;
- }
- index++;
- }
- throwError("Unterminated RegExp", start);
- }
}
/////////////////////////////////////////
diff --git a/src/validators.js b/src/validators.js
index 7318333a..8e288882 100644
--- a/src/validators.js
+++ b/src/validators.js
@@ -13,8 +13,9 @@ extend(angularValidator, {
* @css ng-validation-error
*
* @example
+ * <script> var ssn = /^\d\d\d-\d\d-\d\d\d\d$/; </script>
* Enter valid SSN:
- * <input name="ssn" value="123-45-6789" ng:validate="regexp:/^\d\d\d-\d\d-\d\d\d\d$/" >
+ * <input name="ssn" value="123-45-6789" ng:validate="regexp:$window.ssn" >
*
* @scenario
* it('should invalidate non ssn', function(){
diff --git a/test/ParserSpec.js b/test/ParserSpec.js
index c26125da..c237aa40 100644
--- a/test/ParserSpec.js
+++ b/test/ParserSpec.js
@@ -59,14 +59,6 @@ describe('parser', function() {
expect(undefined).toEqual(tokens[i].fn());
});
- it('should tokenize RegExp', function() {
- var tokens = lex("/r 1/");
- var i = 0;
- expect(tokens[i].index).toEqual(0);
- expect(tokens[i].text).toEqual('r 1');
- expect("r 1".match(tokens[i].fn())[0]).toEqual('r 1');
- });
-
it('should tokenize quoted string', function() {
var str = "['\\'', \"\\\"\"]";
var tokens = lex(str);
@@ -91,23 +83,6 @@ describe('parser', function() {
expect(tokens[0].string).toEqual('\u00a0');
});
- it('should tokenize RegExp with options', function() {
- var tokens = lex("/r/g");
- var i = 0;
- expect(tokens[i].index).toEqual(0);
- expect(tokens[i].text).toEqual('r');
- expect(tokens[i].flags).toEqual('g');
- expect("rr".match(tokens[i].fn()).length).toEqual(2);
- });
-
- it('should tokenize RegExp with escaping', function() {
- var tokens = lex("/\\/\\d/");
- var i = 0;
- expect(tokens[i].index).toEqual(0);
- expect(tokens[i].text).toEqual('\\/\\d');
- expect("/1".match(tokens[i].fn())[0]).toEqual('/1');
- });
-
it('should ignore whitespace', function() {
var tokens = lex("a \t \n \r b");
expect(tokens[0].text).toEqual('a');
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js
index acded34b..354ddc72 100644
--- a/test/ScopeSpec.js
+++ b/test/ScopeSpec.js
@@ -52,6 +52,11 @@ describe('scope/model', function(){
model.$eval('name="works"');
expect(model.name).toEqual('works');
});
+
+ it('should not bind regexps', function(){
+ model.exp = /abc/;
+ expect(model.$eval('exp')).toEqual(model.exp);
+ });
it('should do nothing on empty string and not update view', function(){
var onEval = jasmine.createSpy('onEval');