Improve support >ES5 and Node.

Adds ‘yield’ and ‘**’ to JS order list.
Build generates files (more) parsable by Node.
This PR should have no effect on existing code.
This commit is contained in:
Neil Fraser
2018-01-25 09:29:31 -08:00
committed by Neil Fraser
parent f0b68fad66
commit a4ec65d85d
3 changed files with 30 additions and 33 deletions

View File

@@ -104,16 +104,10 @@ class Gen_uncompressed(threading.Thread):
f = open(self.target_filename, 'w')
f.write(HEADER)
f.write("""
var isNodeJS = !!(typeof module !== 'undefined' && module.exports &&
typeof window === 'undefined');
this.IS_NODE_JS = !!(typeof module !== 'undefined' && module.exports);
if (isNodeJS) {
var window = {};
require('closure-library');
}
window.BLOCKLY_DIR = (function() {
if (!isNodeJS) {
this.BLOCKLY_DIR = (function(root) {
if (!root.IS_NODE_JS) {
// Find name of current directory.
var scripts = document.getElementsByTagName('script');
var re = new RegExp('(.+)[\/]blockly_(.*)uncompressed\.js$');
@@ -126,21 +120,23 @@ window.BLOCKLY_DIR = (function() {
alert('Could not detect Blockly\\'s directory name.');
}
return '';
})();
})(this);
this.BLOCKLY_BOOT = function(root) {
if (root.IS_NODE_JS) {
require('google-closure-library');
} else if (typeof goog == 'undefined') {
alert('Error: Closure not found. Read this:\\n' +
'developers.google.com/blockly/guides/modify/web/closure');
}
window.BLOCKLY_BOOT = function() {
var dir = '';
if (isNodeJS) {
require('closure-library');
if (root.IS_NODE_JS) {
dir = 'blockly';
} else {
// Execute after Closure has loaded.
if (!window.goog) {
alert('Error: Closure not found. Read this:\\n' +
'developers.google.com/blockly/guides/modify/web/closure');
}
dir = window.BLOCKLY_DIR.match(/[^\\/]+$/)[0];
dir = this.BLOCKLY_DIR.match(/[^\\/]+$/)[0];
}
// Execute after Closure has loaded.
""")
add_dependency = []
base_path = calcdeps.FindClosureBasePath(self.search_paths)
@@ -167,20 +163,21 @@ window.BLOCKLY_BOOT = function() {
f.write("goog.require('%s');\n" % provide)
f.write("""
delete this.BLOCKLY_DIR;
delete this.BLOCKLY_BOOT;
delete root.BLOCKLY_DIR;
delete root.BLOCKLY_BOOT;
delete root.IS_NODE_JS;
};
if (isNodeJS) {
window.BLOCKLY_BOOT();
if (this.IS_NODE_JS) {
this.BLOCKLY_BOOT(this);
module.exports = Blockly;
} else {
// Delete any existing Closure (e.g. Soy's nogoog_shim).
document.write('<script>var goog = undefined;</script>');
// Load fresh Closure Library.
document.write('<script src="' + window.BLOCKLY_DIR +
document.write('<script src="' + this.BLOCKLY_DIR +
'/../closure-library/closure/goog/base.js"></script>');
document.write('<script>window.BLOCKLY_BOOT();</script>');
document.write('<script>this.BLOCKLY_BOOT(this);</script>');
}
""")
f.close()

View File

@@ -84,8 +84,9 @@ Blockly.JavaScript.ORDER_TYPEOF = 4.5; // typeof
Blockly.JavaScript.ORDER_VOID = 4.6; // void
Blockly.JavaScript.ORDER_DELETE = 4.7; // delete
Blockly.JavaScript.ORDER_AWAIT = 4.8; // await
Blockly.JavaScript.ORDER_DIVISION = 5.1; // /
Blockly.JavaScript.ORDER_MULTIPLICATION = 5.2; // *
Blockly.JavaScript.ORDER_EXPONENTIATION = 5.0; // **
Blockly.JavaScript.ORDER_MULTIPLICATION = 5.1; // *
Blockly.JavaScript.ORDER_DIVISION = 5.2; // /
Blockly.JavaScript.ORDER_MODULUS = 5.3; // %
Blockly.JavaScript.ORDER_SUBTRACTION = 6.1; // -
Blockly.JavaScript.ORDER_ADDITION = 6.2; // +
@@ -100,7 +101,8 @@ Blockly.JavaScript.ORDER_BITWISE_OR = 12; // |
Blockly.JavaScript.ORDER_LOGICAL_AND = 13; // &&
Blockly.JavaScript.ORDER_LOGICAL_OR = 14; // ||
Blockly.JavaScript.ORDER_CONDITIONAL = 15; // ?:
Blockly.JavaScript.ORDER_ASSIGNMENT = 16; // = += -= *= /= %= <<= >>= ...
Blockly.JavaScript.ORDER_ASSIGNMENT = 16; // = += -= **= *= /= %= <<= >>= ...
Blockly.JavaScript.ORDER_YIELD = 16.5; // yield
Blockly.JavaScript.ORDER_COMMA = 17; // ,
Blockly.JavaScript.ORDER_NONE = 99; // (...)

View File

@@ -24,7 +24,8 @@
"license": "Apache-2.0",
"private": true,
"devDependencies": {
"jshint": "latest"
"jshint": "latest",
"eslint": "2.9.0"
},
"jshintConfig": {
"globalstrict": true,
@@ -41,12 +42,9 @@
"unused": true
},
"dependencies": {
"google-closure-library": "^20171203.0.0",
"install": "^0.8.8",
"npm": "^4.4.4",
"closure-library": "^1.43629075.2",
"webdriverio": "^4.6.2"
},
"devDependencies": {
"eslint": "2.9.0"
}
}