From 630457399dd520e49e9526bb5d5f1ffff8a23f3f Mon Sep 17 00:00:00 2001 From: Spencer Tipping Date: Sat, 29 May 2010 17:52:02 -0600 Subject: [PATCH] Fixed an infinite looping bug that arose when escape characters appeared in interpolated strings. There is still the limitation that you shouldn't use escapes for newlines, cr's, Unicode, etc. in your code sequences --- divergence.rebase.js | 2 +- divergence.rebase.test.js | 8 ++++++-- rebase | 14 +++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/divergence.rebase.js b/divergence.rebase.js index 48bcca9..85ca0b8 100644 --- a/divergence.rebase.js +++ b/divergence.rebase.js @@ -198,7 +198,7 @@ // that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones. function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ? - '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e}, + '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e}, // Operator overloading. // Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node diff --git a/divergence.rebase.test.js b/divergence.rebase.test.js index 5de38d5..c1eb1fe 100644 --- a/divergence.rebase.test.js +++ b/divergence.rebase.test.js @@ -267,7 +267,7 @@ var d = (function () { // that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones. function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ? - '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e}, + '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e}, // Operator overloading. // Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node @@ -519,7 +519,7 @@ var d = (function () { // that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones. function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ? - '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e}, + '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e}, // Operator overloading. // Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node @@ -722,4 +722,8 @@ var d = (function () { d.rebase (function () { d.init ({}, {toString: _ >$> 'foo'}); + }) (); + + d.rebase (function () { + d.init ({}, {toString: _ >$> "foo#{3 + \"bar\"}"}); }) (); \ No newline at end of file diff --git a/rebase b/rebase index f0e7e5a..0d51055 100755 --- a/rebase +++ b/rebase @@ -284,7 +284,7 @@ var d = (function () { __NIlSU01DmtXtQOiufJrifEZEqH1adWhSPDZLF5RACD0 -meta::code('main', <<'__Iw1DFXCb9lg+s2/RisPHPChnOlJVs2eepM1wXrow8vA'); +meta::code('main', <<'__k56TYzidJTVX63ITsHcNSwOasAqIoPz0nEDtbOmekuM'); Divergence Rebase module | Spencer Tipping Licensed under the terms of the MIT source code license @@ -485,7 +485,7 @@ as a key there (e.g. 'foo'), then it will be sandwiched between binary operators that build strings. Unfortunately we won't be able to distinguish between single and double-quoted strings because SpiderMonkey converts them all to double-quoted ones. function (e) {return e.charAt && '\'"'.indexOf(e.charAt(0)) > -1 && /#\{[^}]+\}/.test(e) ? - '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code) + ')+' + e.charAt(0)}) + ')' : e}, + '(' + e.replace (/#\{([^}]+)\}/g, function (_, code) {return e.charAt(0) + '+(' + r.translate(code.replace(/\\(.)/g, '$1')) + ')+' + e.charAt(0)}) + ')' : e}, Operator overloading. Once we're done with all of the preprocessing we can actually replace the operators with method calls. I'm cheating just a bit here; normally you would encase the operation inside a [ node @@ -519,9 +519,9 @@ as a key there (e.g. 'foo'), then it will be sandwiched between binary operators enable it like this: r.enable_inline_macro = (function (enabled) {return function () {enabled || (enabled = !! d.inline_macros.push ('$0.toString()'.compose (r.transform).compose (r.parse)))}}) (false)}) (); -__Iw1DFXCb9lg+s2/RisPHPChnOlJVs2eepM1wXrow8vA +__k56TYzidJTVX63ITsHcNSwOasAqIoPz0nEDtbOmekuM -meta::code('test', <<'__M6nRCqxRlZGJS2N5v+qBH0mhHHc45Fhf8/HXozPPWBk'); +meta::code('test', <<'__HrZA6wBcRrjN5lvZ19w1hPesA5M5ikLFvWHY4i0ipd4'); Divergence Rebase unit tests | Spencer Tipping Licensed under the terms of the MIT source code license @@ -707,7 +707,11 @@ Parse tests. d.rebase (function () { d.init ({}, {toString: _ >$> 'foo'}); }) (); -__M6nRCqxRlZGJS2N5v+qBH0mhHHc45Fhf8/HXozPPWBk + + d.rebase (function () { + d.init ({}, {toString: _ >$> "foo#{3 + \"bar\"}"}); + }) (); +__HrZA6wBcRrjN5lvZ19w1hPesA5M5ikLFvWHY4i0ipd4 meta::code('test-utils', <<'__GQhahA9jt1+B2X1vxas2WOEFnHdUbgiwpAonT2s4VPs'); Unit test utilities.