diff --git a/.eslintrc.json b/.eslintrc.json index e474d8566..3df051d4a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -74,7 +74,8 @@ "balanced": true }, "exceptions": ["*"] - }] + }], + "es5/no-es6-methods": ["warn"] }, "env": { "browser": true @@ -83,5 +84,8 @@ "Blockly": true, "goog": true }, - "extends": "eslint:recommended" + "extends": [ + "eslint:recommended", + "plugin:es5/no-es2015" + ] } diff --git a/core/utils/object.js b/core/utils/object.js index f8b6a55ba..2a9b848a9 100644 --- a/core/utils/object.js +++ b/core/utils/object.js @@ -55,7 +55,9 @@ Blockly.utils.object.mixin = function(target, source) { */ Blockly.utils.object.values = function(obj) { if (Object.values) { + /* eslint-disable es5/no-es6-methods */ return Object.values(obj); + /* eslint-enable es5/no-es6-methods */ } // Fallback for IE. return Object.keys(obj).map(function(e) { diff --git a/gulpfile.js b/gulpfile.js index ce232b7c0..8959fbc42 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -88,6 +88,7 @@ function compile(compilerOptions, opt_verbose) { if (!compilerOptions) compilerOptions = {}; compilerOptions.compilation_level = 'SIMPLE_OPTIMIZATIONS'; compilerOptions.warning_level = opt_verbose ? 'VERBOSE' : 'DEFAULT'; + compilerOptions.language_in = 'ECMASCRIPT5_STRICT'; compilerOptions.language_out = 'ECMASCRIPT5_STRICT'; compilerOptions.rewrite_polyfills = false; compilerOptions.hide_warnings_for = 'node_modules'; diff --git a/package-lock.json b/package-lock.json index e149f20aa..fcf27e0d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1612,6 +1612,12 @@ "text-table": "^0.2.0" } }, + "eslint-plugin-es5": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-es5/-/eslint-plugin-es5-1.4.1.tgz", + "integrity": "sha512-kktkmkF2O7pnSZYgrMiYMbt3wCKRIiXePwILv8USDG95YgP0PzhIxSIROLLKmiQQ/Z6LuhDGWTHK04gnbXBvkg==", + "dev": true + }, "eslint-scope": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.3.tgz", diff --git a/package.json b/package.json index 612470f57..d03df46a2 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "chai": "^4.2.0", "concurrently": "^4.1.2", "eslint": "^5.13.0", + "eslint-plugin-es5": "^1.4.1", "fs": "0.0.1-security", "google-closure-compiler": "^20190618.0.0", "google-closure-library": "^20190618.0.0", diff --git a/tests/compile/compile.sh b/tests/compile/compile.sh index 94d1e5b18..66486303c 100755 --- a/tests/compile/compile.sh +++ b/tests/compile/compile.sh @@ -80,6 +80,8 @@ COMPILATION_COMMAND="java -jar $COMPILER --js='$BLOCKLY_ROOT/tests/compile/main. --generate_exports \ --externs $BLOCKLY_ROOT/externs/svg-externs.js \ --compilation_level ADVANCED_OPTIMIZATIONS \ + --language_in ECMASCRIPT5_STRICT \ + --language_out ECMASCRIPT5_STRICT \ --dependency_mode=STRICT --entry_point=Main \ --js_output_file $BLOCKLY_ROOT/tests/compile/main_compressed.js" echo "$COMPILATION_COMMAND" diff --git a/tests/node/run_node_test.js b/tests/node/run_node_test.js index 7e2530662..2c3890348 100644 --- a/tests/node/run_node_test.js +++ b/tests/node/run_node_test.js @@ -22,28 +22,28 @@ var assert = require('chai').assert; var Blockly = require('../../dist/'); -var xmlText = ` - - - - Hello from Blockly! - - - -`; +var xmlText = '\n' + +' \n' + +' \n' + +' \n' + +' Hello from Blockly!\n' + +' \n' + +' \n' + +' \n' + +''; suite('Test Node.js', function() { test('Import XML', function() { - const xml = Blockly.Xml.textToDom(xmlText); + var xml = Blockly.Xml.textToDom(xmlText); // Create workspace and import the XML - const workspace = new Blockly.Workspace(); + var workspace = new Blockly.Workspace(); Blockly.Xml.domToWorkspace(xml, workspace); }); test('Roundtrip XML', function() { - const xml = Blockly.Xml.textToDom(xmlText); + var xml = Blockly.Xml.textToDom(xmlText); - const workspace = new Blockly.Workspace(); + var workspace = new Blockly.Workspace(); Blockly.Xml.domToWorkspace(xml, workspace); var headlessXml = Blockly.Xml.workspaceToDom(workspace, true); @@ -52,17 +52,17 @@ suite('Test Node.js', function() { assert.equal(headlessText, xmlText, 'equal'); }); test('Generate Code', function() { - const xml = Blockly.Xml.textToDom(xmlText); + var xml = Blockly.Xml.textToDom(xmlText); // Create workspace and import the XML - const workspace = new Blockly.Workspace(); + var workspace = new Blockly.Workspace(); Blockly.Xml.domToWorkspace(xml, workspace); // Convert code - const code = Blockly.JavaScript.workspaceToCode(workspace); + var code = Blockly.JavaScript.workspaceToCode(workspace); // Check output - assert.equal(`window.alert('Hello from Blockly!');`, code.trim(), 'equal'); + assert.equal('window.alert(\'Hello from Blockly!\');', code.trim(), 'equal'); }); });