From ccc2d5898fe0b38b3bb3c55880cff913b0cd6f1e Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 12 Jun 2016 00:40:54 -0700 Subject: [PATCH] Experiment with decaffeinate. #829 --- Makefile | 2 +- package.json | 1 + src/meta/jshint.json | 1 + src/meta/npm-shrinkwrap.json | 202 +++++++++++++++++++++++++++++++++++ tools/chain.js | 19 +++- 5 files changed, 221 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 45357473ba..d6b708a000 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ endef $(foreach s,$(sources),$(eval $(call check_source,$(subst $$,$$$$,$(s))))) -.events/compile : $(updates) $(template_deps) $(coffee_deps) tools/chain.js +.events/compile : $(updates) $(template_deps) $(coffee_deps) node_modules/decaffeinate/package.json tools/chain.js node tools/chain.js $(call QUOTE, \ $(subst .events/,tmp/, \ $(if $(filter-out $(updates),$?), \ diff --git a/package.json b/package.json index 0ee38e8908..0be8901ca0 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "devDependencies": { "coffee-script": "=1.9.3", "crx": "^3.0.3", + "decaffeinate": "^2.13.0", "esprima": "^2.7.2", "font-awesome": "=4.6.3", "jshint": "^2.9.2", diff --git a/src/meta/jshint.json b/src/meta/jshint.json index 46db38fc05..48876e0229 100644 --- a/src/meta/jshint.json +++ b/src/meta/jshint.json @@ -1,4 +1,5 @@ { + "esnext": true, "undef": true, "unused": true, "eqnull": true, diff --git a/src/meta/npm-shrinkwrap.json b/src/meta/npm-shrinkwrap.json index 090258834d..887b93373f 100644 --- a/src/meta/npm-shrinkwrap.json +++ b/src/meta/npm-shrinkwrap.json @@ -1,6 +1,11 @@ { "name": "4chan-X", "dependencies": { + "add-variable-declarations": { + "version": "1.6.1", + "from": "add-variable-declarations@>=1.6.1 <2.0.0", + "resolved": "https://registry.npmjs.org/add-variable-declarations/-/add-variable-declarations-1.6.1.tgz" + }, "ansi-regex": { "version": "2.0.0", "from": "ansi-regex@>=2.0.0 <3.0.0", @@ -36,11 +41,21 @@ "from": "assert-plus@>=0.2.0 <0.3.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.2.0.tgz" }, + "ast-processor-babylon-config": { + "version": "1.0.0", + "from": "ast-processor-babylon-config@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/ast-processor-babylon-config/-/ast-processor-babylon-config-1.0.0.tgz" + }, "async": { "version": "1.5.2", "from": "async@>=1.5.2 <2.0.0", "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz" }, + "automatic-semicolon-insertion": { + "version": "1.0.2", + "from": "automatic-semicolon-insertion@>=1.0.1 <2.0.0", + "resolved": "https://registry.npmjs.org/automatic-semicolon-insertion/-/automatic-semicolon-insertion-1.0.2.tgz" + }, "aws-sign2": { "version": "0.6.0", "from": "aws-sign2@>=0.6.0 <0.7.0", @@ -51,11 +66,69 @@ "from": "aws4@>=1.2.1 <2.0.0", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.4.1.tgz" }, + "babel-code-frame": { + "version": "6.8.0", + "from": "babel-code-frame@>=6.8.0 <7.0.0", + "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.8.0.tgz" + }, + "babel-messages": { + "version": "6.8.0", + "from": "babel-messages@>=6.8.0 <7.0.0", + "resolved": "https://registry.npmjs.org/babel-messages/-/babel-messages-6.8.0.tgz" + }, + "babel-runtime": { + "version": "6.9.2", + "from": "babel-runtime@>=6.9.0 <7.0.0", + "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.9.2.tgz" + }, + "babel-traverse": { + "version": "6.9.0", + "from": "babel-traverse@>=6.9.0 <7.0.0", + "resolved": "https://registry.npmjs.org/babel-traverse/-/babel-traverse-6.9.0.tgz", + "dependencies": { + "debug": { + "version": "2.2.0", + "from": "debug@>=2.2.0 <3.0.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz" + }, + "lodash": { + "version": "4.13.1", + "from": "lodash@>=4.2.0 <5.0.0", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.13.1.tgz" + }, + "ms": { + "version": "0.7.1", + "from": "ms@0.7.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz" + } + } + }, + "babel-types": { + "version": "6.10.0", + "from": "babel-types@>=6.9.0 <7.0.0", + "resolved": "https://registry.npmjs.org/babel-types/-/babel-types-6.10.0.tgz", + "dependencies": { + "lodash": { + "version": "4.13.1", + "from": "lodash@>=4.2.0 <5.0.0" + } + } + }, + "babylon": { + "version": "6.8.1", + "from": "babylon@>=6.7.0 <7.0.0", + "resolved": "https://registry.npmjs.org/babylon/-/babylon-6.8.1.tgz" + }, "balanced-match": { "version": "0.4.1", "from": "balanced-match@>=0.4.1 <0.5.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.1.tgz" }, + "binary-search": { + "version": "1.3.0", + "from": "binary-search@>=1.2.0 <2.0.0", + "resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.0.tgz" + }, "bl": { "version": "1.1.2", "from": "bl@>=1.1.2 <1.2.0", @@ -108,6 +181,11 @@ "from": "cli@>=0.6.0 <0.7.0", "resolved": "https://registry.npmjs.org/cli/-/cli-0.6.6.tgz" }, + "coffee-lex": { + "version": "1.4.2", + "from": "coffee-lex@>=1.4.1 <2.0.0", + "resolved": "https://registry.npmjs.org/coffee-lex/-/coffee-lex-1.4.2.tgz" + }, "coffee-script": { "version": "1.9.3", "from": "coffee-script@1.9.3", @@ -133,6 +211,11 @@ "from": "console-browserify@>=1.1.0 <1.2.0", "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz" }, + "core-js": { + "version": "2.4.0", + "from": "core-js@>=2.4.0 <3.0.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.4.0.tgz" + }, "core-util-is": { "version": "1.0.2", "from": "core-util-is@>=1.0.0 <1.1.0", @@ -175,6 +258,23 @@ "from": "debug@>=1.0.2 <1.1.0", "resolved": "https://registry.npmjs.org/debug/-/debug-1.0.4.tgz" }, + "decaffeinate": { + "version": "2.13.0", + "from": "decaffeinate@latest", + "resolved": "https://registry.npmjs.org/decaffeinate/-/decaffeinate-2.13.0.tgz" + }, + "decaffeinate-parser": { + "version": "1.3.0", + "from": "decaffeinate-parser@>=1.3.0 <2.0.0", + "resolved": "https://registry.npmjs.org/decaffeinate-parser/-/decaffeinate-parser-1.3.0.tgz", + "dependencies": { + "coffee-script": { + "version": "1.10.0", + "from": "coffee-script@>=1.10.0 <2.0.0", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.10.0.tgz" + } + } + }, "deflate-crc32-stream": { "version": "0.1.2", "from": "deflate-crc32-stream@>=0.1.0 <0.2.0", @@ -185,6 +285,11 @@ "from": "delayed-stream@>=1.0.0 <1.1.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz" }, + "detect-indent": { + "version": "4.0.0", + "from": "detect-indent@>=4.0.0 <5.0.0", + "resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-4.0.0.tgz" + }, "dom-serializer": { "version": "0.1.0", "from": "dom-serializer@>=0.0.0 <1.0.0", @@ -237,11 +342,28 @@ "from": "escape-string-regexp@>=1.0.2 <2.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz" }, + "esnext": { + "version": "2.0.0", + "from": "esnext@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/esnext/-/esnext-2.0.0.tgz", + "dependencies": { + "magic-string": { + "version": "0.10.2", + "from": "magic-string@>=0.10.2 <0.11.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.10.2.tgz" + } + } + }, "esprima": { "version": "2.7.2", "from": "esprima@>=2.7.2 <3.0.0", "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.2.tgz" }, + "esutils": { + "version": "2.0.2", + "from": "esutils@>=2.0.2 <3.0.0", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz" + }, "exit": { "version": "0.1.2", "from": "exit@>=0.1.0 <0.2.0", @@ -299,6 +421,11 @@ "from": "generate-object-property@>=1.1.0 <2.0.0", "resolved": "https://registry.npmjs.org/generate-object-property/-/generate-object-property-1.2.0.tgz" }, + "get-stdin": { + "version": "4.0.1", + "from": "get-stdin@>=4.0.1 <5.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz" + }, "getpass": { "version": "0.1.6", "from": "getpass@>=0.1.1 <0.2.0", @@ -323,6 +450,11 @@ } } }, + "globals": { + "version": "8.18.0", + "from": "globals@>=8.3.0 <9.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-8.18.0.tgz" + }, "graceful-readlink": { "version": "1.0.1", "from": "graceful-readlink@>=1.0.0", @@ -380,6 +512,16 @@ "from": "inherits@>=2.0.0 <3.0.0", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz" }, + "invariant": { + "version": "2.2.1", + "from": "invariant@>=2.2.0 <3.0.0", + "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.1.tgz" + }, + "is-finite": { + "version": "1.0.1", + "from": "is-finite@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.1.tgz" + }, "is-my-json-valid": { "version": "2.13.1", "from": "is-my-json-valid@>=2.12.4 <3.0.0", @@ -415,6 +557,11 @@ "from": "jodid25519@>=1.0.0 <2.0.0", "resolved": "https://registry.npmjs.org/jodid25519/-/jodid25519-1.0.2.tgz" }, + "js-tokens": { + "version": "1.0.3", + "from": "js-tokens@>=1.0.2 <2.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-1.0.3.tgz" + }, "jsbn": { "version": "0.1.0", "from": "jsbn@>=0.1.0 <0.2.0", @@ -539,11 +686,21 @@ "from": "lodash.tostring@>=4.0.0 <5.0.0", "resolved": "https://registry.npmjs.org/lodash.tostring/-/lodash.tostring-4.1.3.tgz" }, + "loose-envify": { + "version": "1.2.0", + "from": "loose-envify@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.2.0.tgz" + }, "lru-cache": { "version": "2.7.3", "from": "lru-cache@>=2.0.0 <3.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz" }, + "magic-string": { + "version": "0.15.1", + "from": "magic-string@>=0.15.0 <0.16.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.15.1.tgz" + }, "markdown-it": { "version": "6.0.2", "from": "markdown-it@latest", @@ -581,6 +738,16 @@ "from": "minimatch@>=0.2.12 <0.3.0", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz" }, + "minimist": { + "version": "0.0.8", + "from": "minimist@0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" + }, + "mkdirp": { + "version": "0.5.1", + "from": "mkdirp@>=0.5.1 <0.6.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz" + }, "ms": { "version": "0.6.2", "from": "ms@0.6.2", @@ -603,6 +770,11 @@ "from": "node-uuid@>=1.4.7 <1.5.0", "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.7.tgz" }, + "number-is-nan": { + "version": "1.0.0", + "from": "number-is-nan@>=1.0.0 <2.0.0", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.0.tgz" + }, "oauth-sign": { "version": "0.8.2", "from": "oauth-sign@>=0.8.1 <0.9.0", @@ -663,6 +835,16 @@ "from": "readable-stream@>=1.0.24 <1.1.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz" }, + "regenerator-runtime": { + "version": "0.9.5", + "from": "regenerator-runtime@>=0.9.5 <0.10.0", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.9.5.tgz" + }, + "repeating": { + "version": "2.0.1", + "from": "repeating@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/repeating/-/repeating-2.0.1.tgz" + }, "request": { "version": "2.72.0", "from": "request@latest", @@ -685,6 +867,11 @@ "from": "rimraf@>=2.2.2 <2.3.0", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.2.8.tgz" }, + "shebang-regex": { + "version": "2.0.0", + "from": "shebang-regex@>=2.0.0 <3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-2.0.0.tgz" + }, "shelljs": { "version": "0.3.0", "from": "shelljs@>=0.3.0 <0.4.0", @@ -737,6 +924,11 @@ "from": "strip-ansi@>=3.0.0 <4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz" }, + "strip-indent": { + "version": "1.0.1", + "from": "strip-indent@>=1.0.1 <2.0.0", + "resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-1.0.1.tgz" + }, "strip-json-comments": { "version": "1.0.4", "from": "strip-json-comments@>=1.0.0 <1.1.0", @@ -752,6 +944,11 @@ "from": "temp@>=0.8.1 <0.9.0", "resolved": "https://registry.npmjs.org/temp/-/temp-0.8.3.tgz" }, + "to-fast-properties": { + "version": "1.0.2", + "from": "to-fast-properties@>=1.0.1 <2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.2.tgz" + }, "tough-cookie": { "version": "2.2.2", "from": "tough-cookie@>=2.2.0 <2.3.0", @@ -782,6 +979,11 @@ "from": "verror@1.3.6", "resolved": "https://registry.npmjs.org/verror/-/verror-1.3.6.tgz" }, + "vlq": { + "version": "0.2.1", + "from": "vlq@>=0.2.1 <0.3.0", + "resolved": "https://registry.npmjs.org/vlq/-/vlq-0.2.1.tgz" + }, "webstore-upload": { "version": "0.0.7", "from": "webstore-upload@latest", diff --git a/tools/chain.js b/tools/chain.js index b239953d8b..12a914325c 100644 --- a/tools/chain.js +++ b/tools/chain.js @@ -1,6 +1,7 @@ var fs = require('fs'); var template = require('./template'); var coffee = require('coffee-script'); +var decaffeinate = require('decaffeinate'); for (var name of process.argv.slice(2)) { try { @@ -11,10 +12,22 @@ for (var name of process.argv.slice(2)) { script = template(script, {type: parts[2]}, sourceName); if (parts[4] === 'coffee') { var definesVar = /^[$A-Z][$\w]*$/.test(parts[3]); - if (definesVar) { - script = `${script}\nreturn ${parts[3]};\n`; + try { + script = decaffeinate.convert(script).code; + script = script.trim() + if (definesVar) { + script += `\n\nreturn ${parts[3]};`; + } + script = script.replace(/^(?!$)/gm, ' '); + script = `(function() {\n${script}\n})();\n`; + console.log(`decaffeinate succeeded for ${name}`); + } catch(err) { + console.log(`decaffeinate failed for ${name}: ${err.message}`); + if (definesVar) { + script = `${script}\nreturn ${parts[3]};\n`; + } + script = coffee.compile(script); } - script = coffee.compile(script); if (definesVar) { script = `${parts[3]} = ${script}`; }