forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Babel to minimise whitespace and comments
- Loading branch information
1 parent
003a287
commit dc559dd
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"name": "emscripten", | ||
"version": "1.13.0", | ||
"dependencies": { | ||
"babel-core": "^6.26.0", | ||
"ws": "~0.4.28" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// -*- Mode: javascript; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 ; js-indent-level : 2 ; js-curly-indent-offset: 0 -*- | ||
// vim: set ts=2 et sw=2: | ||
|
||
/* | ||
A version of the JS Optimizer that uses Babel | ||
*/ | ||
|
||
var babel = require("babel-core"); | ||
|
||
// *** Environment setup code *** | ||
|
||
var ENVIRONMENT_IS_NODE = typeof process === 'object'; | ||
var ENVIRONMENT_IS_WEB = typeof window === 'object'; | ||
var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function'; | ||
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; | ||
|
||
if (ENVIRONMENT_IS_NODE) { | ||
// Expose functionality in the same simple way that the shells work | ||
// Note that we pollute the global namespace here, otherwise we break in node | ||
print = function(x) { | ||
process['stdout'].write(x + '\n'); | ||
}; | ||
printErr = function(x) { | ||
process['stderr'].write(x + '\n'); | ||
}; | ||
|
||
var nodeFS = require('fs'); | ||
var nodePath = require('path'); | ||
|
||
if (!nodeFS.existsSync) { | ||
nodeFS.existsSync = function(path) { | ||
try { | ||
return !!nodeFS.readFileSync(path); | ||
} catch(e) { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
function find(filename) { | ||
var prefixes = [nodePath.join(__dirname, '..', 'src'), process.cwd()]; | ||
for (var i = 0; i < prefixes.length; ++i) { | ||
var combined = nodePath.join(prefixes[i], filename); | ||
if (nodeFS.existsSync(combined)) { | ||
return combined; | ||
} | ||
} | ||
return filename; | ||
} | ||
|
||
read = function(filename) { | ||
var absolute = find(filename); | ||
return nodeFS['readFileSync'](absolute).toString(); | ||
}; | ||
|
||
load = function(f) { | ||
globalEval(read(f)); | ||
}; | ||
|
||
arguments_ = process['argv'].slice(2); | ||
|
||
} else if (ENVIRONMENT_IS_SHELL) { | ||
// Polyfill over SpiderMonkey/V8 differences | ||
if (!this['read']) { | ||
this['read'] = function(f) { snarf(f) }; | ||
} | ||
|
||
if (typeof scriptArgs != 'undefined') { | ||
arguments_ = scriptArgs; | ||
} else if (typeof arguments != 'undefined') { | ||
arguments_ = arguments; | ||
} | ||
|
||
} else if (ENVIRONMENT_IS_WEB) { | ||
this['print'] = printErr = function(x) { | ||
console.log(x); | ||
}; | ||
|
||
this['read'] = function(url) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('GET', url, false); | ||
xhr.send(null); | ||
return xhr.responseText; | ||
}; | ||
|
||
if (this['arguments']) { | ||
arguments_ = arguments; | ||
} | ||
} else if (ENVIRONMENT_IS_WORKER) { | ||
// We can do very little here... | ||
|
||
this['load'] = importScripts; | ||
|
||
} else { | ||
throw 'Unknown runtime environment. Where are we?'; | ||
} | ||
|
||
// *** MAIN *** | ||
|
||
// Process the incoming arguments | ||
|
||
var arguments_ = process['argv'].slice(2); | ||
|
||
arguments_ = arguments_.filter(function (arg) { | ||
if (!/^--/.test(arg)) return true; | ||
|
||
if (arg === '--debug') debug = true; | ||
else throw new Error('Unrecognized flag: ' + arg); | ||
}); | ||
|
||
var src = read(arguments_[0]); | ||
|
||
function hasArg( arg ) | ||
{ | ||
return arguments_.indexOf( arg ) > -1; | ||
} | ||
|
||
// Run through Babel | ||
|
||
var options = { | ||
comments: !hasArg('minifyWhitespace'), | ||
minified: hasArg('minifyWhitespace'), | ||
}; | ||
|
||
var result = babel.transform(src, options); | ||
|
||
print(result.code); | ||
print('\n'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters