diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-07-04 12:50:37 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-07-04 12:50:37 -0700 |
commit | 1efbaae03148633014f6d62ed2b3132c5ec5d6c0 (patch) | |
tree | ff2ab024afc0249d077db6e3b10db9269895a42a | |
parent | 6335ad37c27d21780e3b4c25698db1282415a4d0 (diff) |
pass the eliminator the filename to avoid OS-specific issues with reading from stdin using node
-rwxr-xr-x | tests/runner.py | 3 | ||||
-rw-r--r-- | tools/eliminator/eliminator.coffee | 18 | ||||
-rw-r--r-- | tools/js-optimizer.js | 2 | ||||
-rw-r--r-- | tools/shared.py | 2 |
4 files changed, 9 insertions, 16 deletions
diff --git a/tests/runner.py b/tests/runner.py index 9abbd7d9..19ef538b 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7091,9 +7091,8 @@ f.close() self.assertContained('prepre\npre-run\nhello from main\n', run_js(os.path.join(self.get_dir(), 'a.out.js'))) def test_eliminator(self): - input = open(path_from_root('tools', 'eliminator', 'eliminator-test.js')).read() expected = open(path_from_root('tools', 'eliminator', 'eliminator-test-output.js')).read() - output = Popen([NODE_JS, COFFEESCRIPT, VARIABLE_ELIMINATOR], stdin=PIPE, stdout=PIPE).communicate(input)[0] + output = Popen([NODE_JS, COFFEESCRIPT, VARIABLE_ELIMINATOR, path_from_root('tools', 'eliminator', 'eliminator-test.js')], stdout=PIPE).communicate()[0] self.assertIdentical(expected, output) def test_fix_closure(self): diff --git a/tools/eliminator/eliminator.coffee b/tools/eliminator/eliminator.coffee index f83b4a52..05e3788b 100644 --- a/tools/eliminator/eliminator.coffee +++ b/tools/eliminator/eliminator.coffee @@ -383,14 +383,8 @@ class ExpressionOptimizer # function, then writes the optimized result to stdout. main = -> # Get the parse tree. - if os.platform().substr(0, 3) != 'win' - src = fs.readFileSync('/dev/stdin').toString() - else - # The following seems to work on windows, but fails on linux.. - src = '' - size = fs.fstatSync(process.stdin.fd).size - if size > 0 - src = fs.readSync(process.stdin.fd, size)[0] + #process.stderr.write(JSON.stringify(process.argv[2]) + '\n') + src = fs.readFileSync(process.argv[2]).toString() throw 'Cannot identify generated functions' if GENERATED_FUNCTIONS_MARKER in src generatedFunctionsLine = src.split('\n').filter (line) -> @@ -399,22 +393,22 @@ main = -> ast = uglify.parser.parse src - #process.stderr.write(JSON.stringify(ast) + '\n') + ##process.stderr.write(JSON.stringify(ast) + '\n') # Run on all functions. traverse ast, (node, type) -> if type in ['defun', 'function'] and isGenerated node[1] # Run the eliminator - process.stderr.write (node[1] || '(anonymous)') + '\n' + #process.stderr.write (node[1] || '(anonymous)') + '\n' eliminated = new Eliminator(node).run() if eliminated? - process.stderr.write " Eliminated #{eliminated} vars.\n" + #process.stderr.write " Eliminated #{eliminated} vars.\n" # Run the expression optimizer new ExpressionOptimizer(node[3]).run() else - process.stderr.write ' Skipped.\n' + #process.stderr.write ' Skipped.\n' return undefined diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 2f6b2ff3..29887e62 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -1312,7 +1312,7 @@ function registerize(ast) { } getStatements(fun).unshift(['var', vars]); } - printErr(fun[1] + ': saved ' + saved + ' / ' + (saved + nextReg - 1) + ' vars through registerization'); // not totally accurate + //printErr(fun[1] + ': saved ' + saved + ' / ' + (saved + nextReg - 1) + ' vars through registerization'); // not totally accurate }); } diff --git a/tools/shared.py b/tools/shared.py index e0ed3707..0d99a22d 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -850,7 +850,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e coffee = path_from_root('tools', 'eliminator', 'node_modules', 'coffee-script', 'bin', 'coffee') eliminator = path_from_root('tools', 'eliminator', 'eliminator.coffee') input = open(filename, 'r').read() - output = Popen([NODE_JS, coffee, eliminator], stdin=PIPE, stdout=PIPE).communicate(input)[0] + output = Popen([NODE_JS, coffee, eliminator, filename], stdout=PIPE).communicate()[0] assert len(output) > 0, 'Error in eliminator: ' + output filename += '.el.js' f = open(filename, 'w') |