Reviewers: metaweta,



Please review this at http://codereview.appspot.com/110121

Affected files:
  M     src/com/google/caja/parser/js/RegexpLiteral.java
  M     src/com/google/caja/parser/quasiliteral/DefaultValijaRewriter.java


Index: src/com/google/caja/parser/quasiliteral/DefaultValijaRewriter.java
===================================================================
--- src/com/google/caja/parser/quasiliteral/DefaultValijaRewriter.java (revision 3674) +++ src/com/google/caja/parser/quasiliteral/DefaultValijaRewriter.java (working copy)
@@ -177,9 +177,9 @@
         return NONE;
       }
     },
-
+
     // static module loading
-
+
     new Rule() {
       @Override
       @RuleDescription(
@@ -193,8 +193,8 @@
         if (bindings != null && scope.isOuter("includeScript")) {
           ParseTreeNode arg = bindings.get("arg");
           if (arg instanceof StringLiteral) {
-            return substV("arg",
-                new StringLiteral(FilePosition.UNKNOWN,
+            return substV("arg",
+                new StringLiteral(FilePosition.UNKNOWN,
                     ((StringLiteral) arg).getUnquotedValue()));
           } else {
             mq.addMessage(
@@ -206,7 +206,7 @@
         return NONE;
       }
     },
-
+
////////////////////////////////////////////////////////////////////////
     // Module envelope
////////////////////////////////////////////////////////////////////////
@@ -1391,13 +1391,11 @@
           substitutes="$v.construct(RegExp, [...@pattern, @modifiers?])")
       public ParseTreeNode fire(ParseTreeNode node, Scope scope) {
         if (node instanceof RegexpLiteral) {
-          RegexpLiteral re = (RegexpLiteral) node;
-          StringLiteral pattern = StringLiteral.valueOf(
-              re.getFilePosition(), re.getMatchText());
+ RegexpLiteral.RegexpWrapper re = ((RegexpLiteral) node).getValue();
+          FilePosition pos = node.getFilePosition();
+ StringLiteral pattern = StringLiteral.valueOf(pos, re.getMatchText());
           StringLiteral modifiers = !"".equals(re.getModifiers())
-              ? StringLiteral.valueOf(
- FilePosition.endOf(re.getFilePosition()), re.getModifiers())
-              : null;
+              ? StringLiteral.valueOf(pos, re.getModifiers()) : null;
           return substV(
               "pattern", pattern,
               "modifiers", modifiers);
Index: src/com/google/caja/parser/js/RegexpLiteral.java
===================================================================
--- src/com/google/caja/parser/js/RegexpLiteral.java    (revision 3674)
+++ src/com/google/caja/parser/js/RegexpLiteral.java    (working copy)
@@ -56,8 +56,8 @@
     TokenConsumer out = rc.getOut();
     out.mark(getFilePosition());

-    String body = getMatchText();
-    String mods = getModifiers();
+    String body = value.getMatchText();
+    String mods = value.getModifiers();
     if ("".equals(body) || !areRegexpModifiersValid(mods)) {
       // (new (/./.constructor))('', 'g')
       out.consume("(");
@@ -114,6 +114,14 @@
       sb.append('/').append(modifiers);
       return new RegexpWrapper(sb.toString());
     }
+
+    public String getMatchText() {
+      return regexpText.substring(1, regexpText.lastIndexOf('/'));
+    }
+
+    public String getModifiers() {
+      return regexpText.substring(regexpText.lastIndexOf('/') + 1);
+    }
   }

   @Override
@@ -155,14 +163,4 @@
     }
     return true;
   }
-
-  public String getMatchText() {
-    String text = this.value.toString();
-    return text.substring(1, text.lastIndexOf('/'));
-  }
-
-  public String getModifiers() {
-    String text = this.value.toString();
-    return text.substring(text.lastIndexOf('/') + 1);
-  }
 }


Reply via email to