Skip to content

Commit 21d6932

Browse files
authored
Add CoffeeScript2 as an example repo (#130)
The CS2 compiler is a good example of CS2 code, so it's probably the most reasonable test case. For now, this is based off of the config for CS1, but it may need to be tweaked.
1 parent bb4df27 commit 21d6932

File tree

5 files changed

+263
-0
lines changed

5 files changed

+263
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!test/*.js
2+
examples-tmp

examples/coffeescript2/babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"presets": ["env"],
3+
"plugins": ["transform-remove-strict-mode"],
4+
"parserOpts": {
5+
"allowReturnOutsideFunction": true
6+
}
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
searchDirectory: '.',
3+
filesToProcess: ['./Cakefile'],
4+
customNames: {
5+
'./Cakefile': './Cakefile.js',
6+
},
7+
fileFilterFn: path => !path.includes('test/importing/') && !path.includes('documentation'),
8+
jscodeshiftScripts: [
9+
'top-level-this-to-exports.js',
10+
],
11+
decaffeinateArgs: ['--use-cs2'],
12+
};

examples/coffeescript2/config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default {
2+
cloneUrl: 'https://github.com/jashkenas/coffeescript.git',
3+
forkUrl: '[email protected]:decaffeinate-examples/coffeescript2.git',
4+
useDefaultConfig: true,
5+
extraDependencies: [
6+
'babel-plugin-transform-remove-strict-mode',
7+
'js-cake',
8+
'require-uncached',
9+
],
10+
testCommands: [`
11+
set -e
12+
npm install
13+
./node_modules/.bin/babel src -d lib/coffee-script
14+
git commit -a -m 'Rebuild CoffeeScript with new code'
15+
./check-coffeescript-examples.sh
16+
./node_modules/.bin/js-cake test
17+
`],
18+
expectConversionSuccess: true,
19+
expectTestSuccess: true,
20+
};
Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
diff --git a/Cakefile.js b/Cakefile.js
2+
index a70d4c7..3bb3e35 100644
3+
--- a/Cakefile.js
4+
+++ b/Cakefile.js
5+
@@ -458,6 +458,8 @@ task('bench', 'quick benchmark of compilation time', () => {
6+
// Run the CoffeeScript test suite.
7+
var runTests = function (CoffeeScript) {
8+
CoffeeScript.register();
9+
+ require('babel-register');
10+
+ require('babel-polyfill');
11+
const startTime = Date.now();
12+
let currentFile = null;
13+
let passedTests = 0;
14+
@@ -510,14 +512,14 @@ var runTests = function (CoffeeScript) {
15+
const files = fs.readdirSync('test');
16+
17+
for (const file of Array.from(files)) {
18+
- if (helpers.isCoffee(file)) {
19+
+ if (file.endsWith('.js')) {
20+
var filename;
21+
22+
const literate = helpers.isLiterate(file);
23+
currentFile = (filename = path.join('test', file));
24+
const code = fs.readFileSync(filename);
25+
try {
26+
- CoffeeScript.run(code.toString(), { filename, literate });
27+
+ require(`./${filename}`);
28+
} catch (error1) {
29+
const error = error1;
30+
failures.push({ filename, error });
31+
diff --git a/check-coffeescript-examples.sh b/check-coffeescript-examples.sh
32+
new file mode 100755
33+
index 0000000..5d768d2
34+
--- /dev/null
35+
+++ b/check-coffeescript-examples.sh
36+
@@ -0,0 +1,20 @@
37+
+#!/bin/bash
38+
+
39+
+# Simple shell script to compare the decaffeinated CoffeeScript compiler
40+
+# with the official one, running it on all CoffeeScript files in the repo and
41+
+# making sure the output is the same. For now, it just fails on the first error.
42+
+
43+
+set -e
44+
+
45+
+rm -rf examples-tmp
46+
+mkdir examples-tmp
47+
+cd examples-tmp
48+
+git clone https://github.com/jashkenas/coffeescript.git
49+
+
50+
+for path in $(find coffeescript -name '*.coffee'); do
51+
+ echo "Comparing ${path}..."
52+
+ (./coffeescript/bin/coffee --compile --print ${path} || echo 'ERROR') > expected.js
53+
+ (../bin/coffee --compile --print ${path} || echo 'ERROR') > actual.js
54+
+ cmp expected.js actual.js
55+
+ echo 'Passed!'
56+
+done
57+
diff --git a/test/classes.js b/test/classes.js
58+
index ffff3f6..fe1bf20 100644
59+
--- a/test/classes.js
60+
+++ b/test/classes.js
61+
@@ -146,7 +146,8 @@ test("Overriding the static property new doesn't clobber Function::new", () => {
62+
63+
Function.prototype.new = function () { return new (this)(...arguments); };
64+
65+
- ok((TwoClass.new('three')).name === 'three');
66+
+ // https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#static-property-inheritance-is-implemented-differently
67+
+ // ok((TwoClass.new('three')).name === 'three');
68+
ok((new OneClass()).function === 'function');
69+
ok(OneClass.new === 'new');
70+
71+
@@ -610,7 +611,8 @@ test('variables in constructor bodies are correctly scoped', () => {
72+
73+
const a = new A();
74+
eq(a.captured().x, 10);
75+
- return eq(a.captured().y, 2);
76+
+ // https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#executable-class-bodies-can-have-their-statements-reordered
77+
+ return eq(a.captured().y, 20);
78+
});
79+
80+
81+
@@ -671,7 +673,8 @@ test('ensure that constructors invoked with splats return a new object', () => {
82+
// Ensure that constructors invoked with splats cache the function.
83+
let called = 0;
84+
const get = function () { if (called++) { return false; } return (Type = class Type {}); };
85+
- return new get()(...Array.from(args || []));
86+
+ // https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#classes-cannot-be-called-without-new
87+
+ return new (get())(...Array.from(args || []));
88+
});
89+
90+
test("`new` shouldn't add extra parens", () => ok(new Date().constructor === Date));
91+
@@ -1115,7 +1118,8 @@ test('#2599: other typed constructors should be inherited', () => {
92+
return ok(!((new Base()) instanceof Base));
93+
});
94+
95+
-test('#2359: extending native objects that use other typed constructors requires defining a constructor', () => {
96+
+// https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#subclassing-built-ins-is-allowed-in-different-situations
97+
+skippedTest('#2359: extending native objects that use other typed constructors requires defining a constructor', () => {
98+
class BrokenArray extends Array {
99+
method() { return 'no one will call me'; }
100+
}
101+
diff --git a/test/cluster.js b/test/cluster.js
102+
index aa78e2a..2c5a25d 100644
103+
--- a/test/cluster.js
104+
+++ b/test/cluster.js
105+
@@ -12,6 +12,10 @@
106+
107+
if (typeof testingBrowser !== 'undefined' && testingBrowser !== null) { return; }
108+
109+
+// CoffeeScript overwrites process.argv, which this test depends on, so manually
110+
+// overwrite it instead.
111+
+process.argv[1] = __filename;
112+
+
113+
const cluster = require('cluster');
114+
115+
if (cluster.isMaster) {
116+
diff --git a/test/error_messages.js b/test/error_messages.js
117+
index 18862a4..5c11837 100644
118+
--- a/test/error_messages.js
119+
+++ b/test/error_messages.js
120+
@@ -84,7 +84,7 @@ if (typeof require !== 'undefined' && require !== null) {
121+
122+
test('patchStackTrace line patching', () => {
123+
const err = new Error('error');
124+
- return ok(err.stack.match(/test[\/\\]error_messages\.coffee:\d+:\d+\b/));
125+
+ return ok(err.stack.match(/test[\/\\]error_messages\.js:\d+:\d+\b/));
126+
});
127+
128+
test('patchStackTrace stack prelude consistent with V8', () => {
129+
diff --git a/test/functions.js b/test/functions.js
130+
index b5e72c4..bc03139 100644
131+
--- a/test/functions.js
132+
+++ b/test/functions.js
133+
@@ -118,7 +118,8 @@ test('self-referencing functions', () => {
134+
return eq(changeMe, 2);
135+
});
136+
137+
-test("#2009: don't touch `` `this` ``", () => {
138+
+// https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#inline-js-that-relies-on-coffeescript-implementation-details-may-not-be-transformed-correctly
139+
+skippedTest("#2009: don't touch `` `this` ``", () => {
140+
const nonceA = {};
141+
const nonceB = {};
142+
let fn = null;
143+
diff --git a/test/importing.js b/test/importing.js
144+
index f8dec2a..91e3edd 100644
145+
--- a/test/importing.js
146+
+++ b/test/importing.js
147+
@@ -33,7 +33,8 @@ if ((typeof window === 'undefined' || window === null) && (typeof testingBrowser
148+
} else {
149+
global[magicKey] = {};
150+
if ((typeof require !== 'undefined' && require !== null ? require.extensions : undefined) != null) {
151+
- ok(require(__filename).method() === magicValue);
152+
+ const requireUncached = require('require-uncached');
153+
+ ok(requireUncached(__filename).method() === magicValue);
154+
}
155+
return delete global[magicKey];
156+
}
157+
diff --git a/test/operators.js b/test/operators.js
158+
index 72dec42..0f89850 100644
159+
--- a/test/operators.js
160+
+++ b/test/operators.js
161+
@@ -268,7 +268,8 @@ test('#1100: precedence in or-test compilation of `in`', () => {
162+
return ok(!([1, 0 || 1].includes(0)));
163+
});
164+
165+
-test('#1630: `in` should check `hasOwnProperty`', () => {
166+
+// https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#undefined-in-arr-returns-true-for-sparse-arrays-without-explicit-undefineds
167+
+skippedTest('#1630: `in` should check `hasOwnProperty`', () => {
168+
let needle;
169+
return ok((needle = undefined, !Array.from({ length: 1 }).includes(needle)));
170+
});
171+
@@ -471,7 +472,8 @@ test('#3363: Modulo operator coercing order', () => {
172+
return eq(5, count);
173+
});
174+
175+
-test('#3598: Unary + and - coerce the operand once when it is an identifier', () => {
176+
+// https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#side-effects-in-valueof-and-getters-may-be-called-multiple-times
177+
+skippedTest('#3598: Unary + and - coerce the operand once when it is an identifier', () => {
178+
// Unary + and - do not generate `_ref`s when the operand is a number, for
179+
// readability. To make sure that they do when the operand is an identifier,
180+
// test that they are consistent with another unary operator as well as another
181+
diff --git a/test/scope.js b/test/scope.js
182+
index 2c94e51..d35d984 100644
183+
--- a/test/scope.js
184+
+++ b/test/scope.js
185+
@@ -118,19 +118,19 @@ test('loop variable should be accessible after for-from loop', () => {
186+
})());
187+
return eq(x, 2);
188+
});
189+
-
190+
-class Array {
191+
+// https://github.com/decaffeinate/decaffeinate/blob/master/docs/correctness-issues.md#globals-like-object-and-array-may-be-accessed-by-name-from-generated-code
192+
+class Array_ {
193+
static initClass() {
194+
this.prototype.slice = fail;
195+
}
196+
}
197+
-Array.initClass(); // needs to be global
198+
-class Object {
199+
+Array_.initClass(); // needs to be global
200+
+class Object_ {
201+
static initClass() {
202+
this.prototype.hasOwnProperty = fail;
203+
}
204+
}
205+
-Object.initClass();
206+
+Object_.initClass();
207+
test("#1973: redefining Array/Object constructors shouldn't confuse __X helpers", () => {
208+
const arr = [1, 2, 3, 4];
209+
arrayEq([3, 4], arr.slice(2));
210+
diff --git a/test/support/helpers.js b/test/support/helpers.js
211+
index 2d0578a..a50a6b7 100644
212+
--- a/test/support/helpers.js
213+
+++ b/test/support/helpers.js
214+
@@ -9,6 +9,8 @@
215+
*/
216+
// TODO: This file was created by bulk-decaffeinate.
217+
// Fix any style issues and re-enable lint.
218+
+global.skippedTest = function (description, fn) {};
219+
+
220+
/*
221+
* decaffeinate suggestions:
222+
* DS102: Remove unnecessary code created because of implicit returns

0 commit comments

Comments
 (0)