浏览代码

set jitoffset in test definitions

Robin Herbots 7 年之前
父节点
当前提交
8a751203d2
共有 1 个文件被更改,包括 7 次插入5 次删除
  1. 7 5
      js/inputmask.js

+ 7 - 5
js/inputmask.js

@@ -975,8 +975,7 @@
                     matches = [],
                     insertStop = false,
                     latestMatch,
-                    cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "",
-                    offset = 0;
+                    cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "";
 
                 function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitializer contains a set of indexes to speedup searches in the mtokens
                     function handleMatch(match, loopNdx, quantifierRecurse) {
@@ -1041,8 +1040,8 @@
 
                         function staticCanMatchDefinition(source, target) {
                             var sloc = source.locator.slice(source.alternation).join(""),
-                                tloc = target.locator.slice(target.alternation).join(""), canMatch = sloc == tloc,
-                                canMatch = canMatch && source.match.fn === null && target.match.fn !== null ? target.match.fn.test(source.match.def, getMaskSet(), pos, false, opts, false) : false;
+                                tloc = target.locator.slice(target.alternation).join(""), canMatch = sloc == tloc;
+                            canMatch = canMatch && source.match.fn === null && target.match.fn !== null ? target.match.fn.test(source.match.def, getMaskSet(), pos, false, opts, false) : false;
 
                             return canMatch;
                         }
@@ -1213,6 +1212,9 @@
                                             testPos = pos; //match the position after the group
                                             break; //stop quantifierloop && search for next possible match
                                         }
+                                        if (latestMatch.jit && !latestMatch.optionalQuantifier) {
+                                            latestMatch.jitOffset = tokenGroup.matches.indexOf(latestMatch);
+                                        }
                                         return true;
                                     }
                                 }
@@ -1306,7 +1308,7 @@
                     return $.extend(true, [], matches);
                 }
                 getMaskSet().tests[pos] = $.extend(true, [], matches); //set a clone to prevent overwriting some props
-                // console.log(pos + " - " + JSON.stringify(matches));
+                console.log(pos + " - " + JSON.stringify(matches));
                 return getMaskSet().tests[pos];
             }