aboutsummaryrefslogtreecommitdiff
path: root/tools/fix_closure.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-01-10 18:41:38 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-01-10 18:41:38 -0800
commited02667266b2bb5d11db9c9639427beaa8ee5c88 (patch)
treeb88cc7e5a6cb60e3a6799f3683fdfff9f296ee25 /tools/fix_closure.py
parentf4e239ed21d9f6ea79693f003f2d595143937108 (diff)
fix fix_closure bug with the relevant line being split over several lines
Diffstat (limited to 'tools/fix_closure.py')
-rwxr-xr-xtools/fix_closure.py54
1 files changed, 26 insertions, 28 deletions
diff --git a/tools/fix_closure.py b/tools/fix_closure.py
index 086dddfa..d6a64b22 100755
--- a/tools/fix_closure.py
+++ b/tools/fix_closure.py
@@ -48,35 +48,33 @@ class ObjectParser:
string = 0
i += 1
-lines = infile.readlines()
-i = 0
-while i < len(lines):
- line = lines[i]
- curr = line.find('=[0,0,')
- if curr > 0:
- # a suspect
- target = line[curr-1]
- curr += 5
- parser = ObjectParser()
- add = []
- while line[curr] != ']':
- assert line[curr] == ','
+line = infile.read()
+curr = 0
+while True:
+ curr = line.find('=[0,0,', curr)
+ if curr < 0: break
+ # a suspect
+ target = line[curr-1]
+ curr += 5
+ parser = ObjectParser()
+ add = []
+ while line[curr] != ']':
+ assert line[curr] == ','
+ curr += 1
+ next, is_func = parser.read(curr, line)
+ if is_func:
+ text = line[curr:next]
+ assert text.startswith('function(')
+ ident = 'uninline_' + target + '_' + str(curr) # these idents should be unique, but might in theory collide with the rest of the JS code! XXX
+ line = line[:curr] + ident + line[next:]
+ add += 'function ' + ident + '(' + text[len('function('):]
+ while line[curr] != ',' and line[curr] != ']':
curr += 1
- next, is_func = parser.read(curr, line)
- if is_func:
- text = line[curr:next]
- assert text.startswith('function(')
- ident = 'uninline_' + target + '_' + str(curr) # these idents should be unique, but might in theory collide with the rest of the JS code! XXX
- line = line[:curr] + ident + line[next:]
- add += 'function ' + ident + '(' + text[len('function('):]
- while line[curr] != ',' and line[curr] != ']':
- curr += 1
- lines[i] = line
- lines = lines[:i] + add + lines[i:]
- i += len(add)
- i += 1
+ curr += 1
+ assert line[curr] == ';'
+ curr += 1
+ line = line[:curr] + ''.join(add) + line[curr:]
-for line in lines:
- outfile.write(line)
+outfile.write(line)
outfile.close()