Skip to content

Commit

Permalink
Merge pull request #51 from davidchambers/harmony
Browse files Browse the repository at this point in the history
switch to esprima-fb for Harmony support
  • Loading branch information
davidchambers committed Mar 6, 2015
2 parents ca2aa8f + 51bcce8 commit db07a31
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- "0.10"
- "0.11"
- "0.12"
install:
- make setup
script:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ test: \
test/public/shared/index.coffee \
test/public/shared/index.js \
test/public/style.css
$(COFFEE) test/index.coffee
$(COFFEE) --nodejs --harmony -- test/index.coffee

test/public/bundle.js: \
bower_components/coffee-script/extras/coffee-script.js \
bower_components/esprima/esprima.js \
node_modules/esprima-fb/esprima.js \
bower_components/jquery/dist/jquery.js \
bower_components/qunit/qunit/qunit.js \
bower_components/ramda/dist/ramda.js \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function toFahrenheit(degreesCelsius) {

2. Add script tags:

<script src="path/to/bower_components/esprima/esprima.js"></script>
<script src="path/to/node_modules/esprima-fb/esprima.js"></script>
<script src="path/to/bower_components/jquery/dist/jquery.js"></script>
<script src="path/to/bower_components/qunit/qunit/qunit.js"></script>
<script src="path/to/bower_components/ramda/dist/ramda.js"></script>
Expand Down
14 changes: 13 additions & 1 deletion bin/doctest
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
#!/usr/bin/env node

require('../lib/command');
// Based on:
// https://github.com/jashkenas/coffeescript/blob/1.9.1/src/command.coffee#L431-L441
var args = process.argv.slice(1);
var idx = args.indexOf('--nodejs');
if (idx < 0 || idx === args.length - 1) {
require('../lib/command');
} else {
require('child_process').spawn(
process.execPath,
args[idx + 1].split(/\s+/).concat(args.slice(0, idx), args.slice(idx + 2)),
{cwd: process.cwd(), env: process.env, stdio: [0, 1, 2]}
).on('exit', process.exit);
}
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
],
"dependencies": {
"coffee-script": "1.8.x",
"esprima": "1.2.x",
"jquery": "2.1.x",
"ramda": "0.10.x"
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
"dependencies": {
"coffee-script": "1.8.x",
"commander": "2.5.x",
"esprima": "1.2.x",
"esprima-fb": "13001.1001.0-dev-harmony-fb",
"ramda": "0.10.x"
},
"devDependencies": {
"bower": "1.3.x",
"semver": "4.3.x",
"xyz": "0.5.x"
}
}
1 change: 1 addition & 0 deletions src/command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ program
.version doctest.version
.usage '[options] path/to/js/or/coffee/module'
.option '-m, --module <type>', 'specify module system ("amd" or "commonjs")'
.option ' --nodejs', 'pass options directly to the "node" binary'
.option '-p, --print', 'output the rewritten source without running tests'
.option '-s, --silent', 'suppress output'
.option '-t, --type <type>', 'specify file type ("coffee" or "js")'
Expand Down
2 changes: 1 addition & 1 deletion src/doctest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ else
fs = require 'fs'
pathlib = require 'path'
CoffeeScript = require 'coffee-script'
esprima = require 'esprima'
esprima = require 'esprima-fb'
R = require 'ramda'
module.exports = doctest

Expand Down
22 changes: 22 additions & 0 deletions test/harmony/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function* fibonacci() {
var prev = 0;
var curr = 1;
while (true) {
yield curr;
var next = prev + curr;
prev = curr;
curr = next;
}
}

// > seq.next().value
// 1
// > seq.next().value
// 1
// > seq.next().value
// 2
// > seq.next().value
// 3
// > seq.next().value
// 5
var seq = fibonacci();
7 changes: 7 additions & 0 deletions test/harmony/results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = [
['seq.next().value', [true, 1, 1, 13]],
['seq.next().value', [true, 1, 1, 15]],
['seq.next().value', [true, 2, 2, 17]],
['seq.next().value', [true, 3, 3, 19]],
['seq.next().value', [true, 5, 5, 21]],
];
2 changes: 2 additions & 0 deletions test/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pathlib = require 'path'

R = require 'ramda'
semver = require 'semver'

doctest = require '../lib/doctest'

Expand Down Expand Up @@ -57,6 +58,7 @@ testModule 'test/commonjs/exports/index.js', module: 'commonjs'
testModule 'test/commonjs/module.exports/index.js', module: 'commonjs'
testModule 'test/commonjs/strict/index.js', module: 'commonjs'
testModule 'test/bin/executable', type: 'js'
testModule 'test/harmony/index.js' if semver.gte process.version, '0.12.0'

testCommand 'bin/doctest --xxx',
code: 1
Expand Down

0 comments on commit db07a31

Please sign in to comment.