diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-01-11 11:38:46 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-01-11 11:38:46 -0800 |
commit | 20c28230c1d9a20cd70e0e2ab52a3bacbd2e8db4 (patch) | |
tree | e20cc7b6ecb6070defcb2418acd12754c0a1d765 /tools/fix_closure.py | |
parent | 7b7f8f4d66918d306654dd711ffb44d3137fa7bb (diff) |
fix fix_closure bug with newlines
Diffstat (limited to 'tools/fix_closure.py')
-rwxr-xr-x | tools/fix_closure.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/tools/fix_closure.py b/tools/fix_closure.py index d6a64b22..5237c7b1 100755 --- a/tools/fix_closure.py +++ b/tools/fix_closure.py @@ -20,7 +20,7 @@ class ObjectParser: ''' Read an element of the FUNCTION_TABLE until the end (a comma or the end of FUNCTION_TABLE), returning that location ''' - assert line[s-1] == ',' # we are a new element, after a comma + #print 'zz start parsing!', line[s-1:s+100] curly = 0 paren = 0 string = 0 @@ -28,6 +28,7 @@ class ObjectParser: i = s while True: c = line[i] + #print 'parsing! CPSF', c, curly, paren, string, is_func if not string: if c == '"' or c == "'": string = 1 @@ -42,6 +43,7 @@ class ObjectParser: paren -= 1 elif not curly and not paren: if c in [',', ']']: + #print 'zz done,', line[s:i], line[s:i].startswith('function(') return (i, is_func and line[s:i].startswith('function(')) else: if c == '"' or c == "'": @@ -54,6 +56,7 @@ while True: curr = line.find('=[0,0,', curr) if curr < 0: break # a suspect + #print 'zz suspect!', curr, line[curr-10:curr+10] target = line[curr-1] curr += 5 parser = ObjectParser() @@ -61,17 +64,22 @@ while True: while line[curr] != ']': assert line[curr] == ',' curr += 1 + while line[curr] in ['\n', ' ']: + curr += 1 next, is_func = parser.read(curr, line) if is_func: text = line[curr:next] + #print 'zz func!', text 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('):] + #print 'zz after func fix:', line[curr:curr+100] while line[curr] != ',' and line[curr] != ']': curr += 1 + #print 'zz exited:', line[curr:curr+100] curr += 1 - assert line[curr] == ';' + assert line[curr] == ';', 'odd char: ' + str([line[curr], line[curr-10:curr+10]]) curr += 1 line = line[:curr] + ''.join(add) + line[curr:] |