diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-24 16:48:42 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-03 15:31:03 -0700 |
commit | 0af083b4a07ea912f7d6e1b558fde0e38086da06 (patch) | |
tree | 75eee8dba10ec4b6b3b0f9b2df4a5755ada23780 | |
parent | f2178dcdd562f49c9f668c6afae20386168c72b6 (diff) |
start to parse imports
-rw-r--r-- | emlink.py | 14 | ||||
-rw-r--r-- | tools/js_optimizer.py | 1 |
2 files changed, 14 insertions, 1 deletions
@@ -29,9 +29,17 @@ print 'Output:', out class AsmModule(): def __init__(self, filename): self.js = open(filename).read() + # imports + imports_js = self.js[self.js.find(js_optimizer.start_asm_marker):self.js.rfind(js_optimizer.start_funcs_marker)] + self.imports = [m.group(0) for m in js_optimizer.import_sig.finditer(imports_js)] + #print 'imports', self.imports + + # funcs funcs_js = self.js[self.js.find(js_optimizer.start_funcs_marker):self.js.rfind(js_optimizer.end_funcs_marker)] self.funcs = [m.group(2) for m in js_optimizer.func_sig.finditer(funcs_js)] - print filename, self.funcs + #print 'funcs', self.funcs + + # exports def relocate(self, main): # Find function name replacements TODO: do not rename duplicate names with duplicate contents, just merge them @@ -44,8 +52,12 @@ class AsmModule(): replacements[func] = rep print replacements + def write(self, out): + open(out, 'w').write(self.js) + main = AsmModule(main) side = AsmModule(side) side.relocate(main) +#main.write(out) diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py index 58b0af6d..7cefe90a 100644 --- a/tools/js_optimizer.py +++ b/tools/js_optimizer.py @@ -19,6 +19,7 @@ WINDOWS = sys.platform.startswith('win') DEBUG = os.environ.get('EMCC_DEBUG') +import_sig = re.compile('( *)var ([_\w$]+) *=.*;') func_sig = re.compile('( *)function ([_\w$]+)\(') class Minifier: |