Skip to content

Commit c97696c

Browse files
committed
first commit
0 parents  commit c97696c

167 files changed

Lines changed: 2007 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.editorconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
insert_final_newline = true
5+
charset = utf-8
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.js]
10+
indent_style = space
11+
indent_size = 2

‎.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
node_modules
3+
*.log
4+
*.cache
5+
/templates.json
6+
coverage

‎.jshintignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
test

‎.jshintrc‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"esnext": true,
3+
"indent": 2,
4+
"maxlen": 80,
5+
"freeze": true,
6+
"camelcase": true,
7+
"unused": true,
8+
"eqnull": true,
9+
"proto": true,
10+
"newcap": true,
11+
"supernew": true,
12+
"noyield": true,
13+
"evil": true,
14+
"node": true,
15+
"boss": true,
16+
"expr": true,
17+
"undef": true,
18+
"loopfunc": true,
19+
"white": true,
20+
"maxparams": 5,
21+
"maxdepth": 4
22+
}

‎.npmignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
node_modules
3+
*.log
4+
*.cache
5+
lib/6to5/templates

‎.travis.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- 0.8
4+
- 0.10
5+
- 0.11

‎LICENSE‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 Sebastian McKenzie
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎Makefile‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MOCHA_CMD = node_modules/mocha/bin/_mocha
2+
3+
export NODE_ENV = test
4+
5+
.PHONY: clean test test-cov test-travis publish
6+
7+
clean:
8+
rm -rf coverage templates.json
9+
10+
test:
11+
$(MOCHA_CMD)
12+
13+
test-cov:
14+
make clean
15+
node node_modules/istanbul/lib/cli.js cover $(MOCHA_CMD) --
16+
17+
publish:
18+
make clean
19+
node bin/cache-templates
20+
npm publish
21+
make clean

‎README.md‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# 6to6
2+
3+
**6to5** turns ES6 code into vanilla ES5, so you can use ES6 features **today.**
4+
5+
6to5 is:
6+
7+
- Fast - [10x faster than Traceur](#comparison-to-traceur).
8+
- Compact - maps directly to the equivalent ES5.
9+
- Easy - with Browserify support, Node API, Connect Middleware and a CLI.
10+
- Concise - we do not pollute any scope with unneccesary variables or functions declarations.
11+
12+
## Features
13+
14+
| Name | Implemented |
15+
| -------------------------- | ----------- |
16+
| Arrow functions | ✓ |
17+
| Classes | ✓ |
18+
| Default parameters | ✓ |
19+
| Spread | ✓ |
20+
| Block binding | ✓ |
21+
| Property method assignment | ✓ |
22+
| Rest parameters | ✓ |
23+
| Template literals | ✓ |
24+
| Modules | ✓ |
25+
| Destructuring assignment | |
26+
| Generators | |
27+
28+
## Installation
29+
30+
$ npm install -g 6to5
31+
32+
## Usage
33+
34+
### CLI
35+
36+
Compile the file `script.js` and output it to `script-compiled.js`.
37+
38+
$ 6to5 script.js -o script-compiled.js
39+
40+
Compile the entire `src` directory and output it to the `lib` directory.
41+
42+
$ 6to5 src -d lib
43+
44+
Compile the file `script.js` and output it to stdout.
45+
46+
$ 6to5 script.js
47+
48+
### Node
49+
50+
```javascript
51+
var to5 = require("6to5");
52+
53+
to5.transform("code();");
54+
55+
to5.transformFileSync("script.js");
56+
57+
to5.transformFile("script.js", function (err, data) {
58+
59+
});
60+
```
61+
62+
##### Options
63+
64+
```javascript
65+
to5.transform("code();", {
66+
// List of transformers to EXCLUDE
67+
// See `features` for valid names.
68+
blacklist: [],
69+
70+
// List of transformers to ONLY use.
71+
// See `features` for valid names.
72+
whitelist: [],
73+
74+
// Append source map and comment to bottom of returned output.
75+
sourceMap: false,
76+
77+
// Filename for use in errors etc.
78+
filename: "unknown",
79+
80+
// Format options
81+
// See https://github.com/Constellation/escodegen/wiki/API for options.
82+
format: {}
83+
});
84+
```
85+
86+
#### Require hook
87+
88+
All subsequent files required by node will be transformed into ES5 compatible
89+
code.
90+
91+
```javascript
92+
require("6to5/register");
93+
```
94+
95+
#### Connect Middleware
96+
97+
```javascript
98+
var to5 = require("6to5");
99+
100+
app.use(6to5.middleware({
101+
transform: {
102+
// options to use when transforming files
103+
},
104+
src: "assets",
105+
dest: "cache"
106+
}));
107+
108+
app.use(connect.static("cache"));
109+
```
110+
111+
### Browserify
112+
113+
#### CLI
114+
115+
$ browserify script.js -t 6to5/browserify --outfile bundle.js
116+
117+
#### Node
118+
119+
```javascript
120+
var to5 = require("6to5");
121+
browserify()
122+
.transform(to5.browserify)
123+
.require("script.js", { entry: true })
124+
.bundle({ debug: true })
125+
.pipe(fs.createWriteStream("bundle.js"));
126+
```
127+
128+
## Caveats
129+
130+
### Generators
131+
132+
### Let
133+
134+
## Comparison to Traceur

‎bin/6to5‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env node
2+
3+
var commander = require("commander");
4+
var chokidar = require("chokidar");
5+
var readdir = require("fs-readdir-recursive");
6+
var mkdirp = require("mkdirp");
7+
var 6to5 = require("../lib/6to5/node");
8+
var path = require("path");
9+
var util = require("../lib/6to5/util");
10+
var fs = require("fs");
11+
var _ = require("lodash");
12+
13+
commander.option("-m, --source-maps", "Generate source maps alongside the compiled JavaScript files. Adds sourceMappingURL directives to the JavaScript as well.");
14+
//commander.option("-w, --watch", "Watch, only works with --out-dir");
15+
16+
var list = function (val) {
17+
return val ? val.split(",") : [];
18+
};
19+
20+
commander.option("-w, --whitelist [whitelist]", "Whitelist", list);
21+
commander.option("-b, --blacklist [blacklist]", "Blacklist", list);
22+
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
23+
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
24+
25+
var pkg = require("../package.json");
26+
commander.version(pkg.version);
27+
commander.usage("[options] <files ...>");
28+
commander.parse(process.argv);
29+
30+
//
31+
32+
var errors = [];
33+
34+
var filenames = commander.args;
35+
if (!filenames.length) errors.push("no filenames input");
36+
37+
_.each(filenames, function (filename) {
38+
if (!fs.existsSync(filename)) {
39+
errors.push(filename + " doesn't exist");
40+
}
41+
});
42+
43+
if (commander.outFile && commander.outDir) {
44+
errors.push("cannot have --out-file and --out-dir");
45+
}
46+
47+
if (errors.length) {
48+
console.error(errors.join(". "));
49+
process.exit(2);
50+
}
51+
52+
//
53+
54+
var readdirFilter = function (filename) {
55+
return readdir(filename).filter(util.canCompile);
56+
};
57+
58+
var mainOpts = {
59+
blacklist: commander.blacklist,
60+
whitelist: commander.whitelist,
61+
sourceMap: commander.sourceMaps,
62+
tolerant: commander.tolerant
63+
};
64+
65+
var data = [];
66+
67+
var compile = function (filename) {
68+
var opts = _.clone(mainOpts);
69+
opts.filename = filename;
70+
71+
var file = fs.readFileSync(filename);
72+
return 6to5.transform(file, opts);
73+
};
74+
75+
if (commander.outDir) {
76+
var write = function (src, relative) {
77+
var data = compile(src);
78+
79+
var dest = path.join(commander.outDir, relative);
80+
81+
var up = path.normalize(dest + "/..");
82+
mkdirp.sync(up);
83+
84+
fs.writeFileSync(dest, data);
85+
86+
console.log(src + " -> " + dest);
87+
};
88+
89+
var handle = function (filename) {
90+
var stat = fs.statSync(filename);
91+
92+
if (stat.isDirectory(filename)) {
93+
var dirname = filename;
94+
95+
_.each(readdirFilter(dirname), function (filename) {
96+
write(path.join(dirname, filename), filename);
97+
});
98+
} else {
99+
write(filename, filename);
100+
}
101+
};
102+
103+
_.each(filenames, handle);
104+
} else {
105+
var data = [];
106+
107+
var _filenames = filenames;
108+
filenames = [];
109+
110+
_.each(_filenames, function (filename) {
111+
var stat = fs.statSync(filename);
112+
if (stat.isDirectory()) {
113+
var dirname = filename;
114+
115+
_.each(readdirFilter(filename), function (filename) {
116+
filenames.push(path.join(dirname, filename));
117+
});
118+
} else {
119+
filenames.push(filename);
120+
}
121+
});
122+
123+
_.each(filenames, function (filename) {
124+
data.push(compile(filename) + "\n");
125+
});
126+
127+
data = data.join("");
128+
129+
if (commander.outFile) {
130+
fs.writeFileSync(commander.out, data);
131+
} else {
132+
console.log(data);
133+
}
134+
}

0 commit comments

Comments
 (0)