Permalink
Browse files

Fixes #60

  • Loading branch information...
1 parent 3e56943 commit 240606d0bbafae491d9d474c2b2037d580ce0584 @goatslacker goatslacker committed Aug 7, 2012
Showing with 10 additions and 8 deletions.
  1. +6 −8 fixmyjs.js
  2. +2 −0 test/fixtures/broken/dotnotation.js
  3. +2 −0 test/fixtures/ok/dotnotation.js
View
@@ -153,15 +153,13 @@
// `person['name']` -> `person.name`
dotNotation: function (str, o) {
var dot = o.a;
- var rx = new RegExp('\\[[\'"]' + dot + '[\'"]\\]');
- var sqbNotation;
+ var rx = new RegExp('\\[[\'"]' +
+ dot + '[\'"]\\]?(?!.*\\[[\'"]' +
+ dot + '[\'"]\\]?)');
- if (rx.test(str)) {
- sqbNotation = rx.exec(str);
- str = str.replace(sqbNotation[0], "." + dot);
- }
-
- return str;
+ return str.replace(rx, function () {
+ return '.' + dot;
+ });
},
// Immediate functions are executed within the parenthesis.
@@ -18,3 +18,5 @@ lol["cats"];
hello["return"];
foo["for"]; foo["that"]; foo['this'];
+
+window['foo'] = window['foo'] || function () {};
@@ -18,3 +18,5 @@ lol.cats;
hello["return"];
foo["for"]; foo.that; foo['this'];
+
+window.foo = window.foo || function () {};

0 comments on commit 240606d

Please sign in to comment.