Compare commits

...

76 Commits

Author SHA1 Message Date
Sebastian McKenzie
7736fa11f2 v2.7.2 2015-01-07 18:38:00 +11:00
Sebastian McKenzie
d203924541 disable module import reassignment tests 2015-01-07 18:35:36 +11:00
Sebastian McKenzie
cd23e500a1 add back specNoForInOfAssignment transformer 2015-01-07 18:30:48 +11:00
Sebastian McKenzie
bf24a0d6b5 temporarily disable module collission detections 2015-01-07 18:30:33 +11:00
Sebastian McKenzie
279d1affea v2.7.1 2015-01-07 14:15:16 +11:00
Sebastian McKenzie
2a1e012240 upgrade core-js 2015-01-07 14:12:21 +11:00
Sebastian McKenzie
a307a961a6 add istanbul to travis test 2015-01-07 14:10:47 +11:00
Sebastian McKenzie
fe5b1dc542 add reactCompat default to file opts 2015-01-07 14:10:37 +11:00
Sebastian McKenzie
f057347ae9 add version to browser and node build 2015-01-07 14:10:27 +11:00
Sebastian McKenzie
98f2287267 v2.7.0 2015-01-07 14:01:44 +11:00
Sebastian McKenzie
e60e0e0b0e disable timeout on test262 tests 2015-01-07 13:58:47 +11:00
Sebastian McKenzie
81fb8647b6 fixing linting errors 2015-01-07 13:58:41 +11:00
Sebastian McKenzie
e8387c7de5 add 2.7.0 changelog 2015-01-07 13:57:04 +11:00
Sebastian McKenzie
655196f3ce Merge pull request #410 from amasad/master
Add support for React pre v0.12 transform
2015-01-07 13:54:23 +11:00
Amjad Masad
eef371c3df Add support for React pre v0.12 transform
This uses an option `reactCompat` to emit code that works with React pre v0.12
2015-01-06 21:49:35 -05:00
Sebastian McKenzie
a3d21f02c6 just call mocha instead of test-simple 2015-01-07 13:44:05 +11:00
Sebastian McKenzie
ad4386c0ed make test-travis use test-simple and remove test-spec task 2015-01-07 13:33:31 +11:00
Sebastian McKenzie
3c82a61af1 better lazy error description test262 2015-01-07 13:33:19 +11:00
Sebastian McKenzie
3c154f9f6d better test262 test aliases 2015-01-07 13:19:53 +11:00
Sebastian McKenzie
22c972e85b add bootstrap to travis test 2015-01-07 13:14:45 +11:00
Sebastian McKenzie
6d7e14fb2b fix test262 loc check 2015-01-07 13:14:08 +11:00
Sebastian McKenzie
9287449372 add test-all make command 2015-01-07 13:11:25 +11:00
Sebastian McKenzie
44a35400f5 better output messages for missing vendors 2015-01-07 13:10:12 +11:00
Sebastian McKenzie
2305e2447f fix hasOwnProperty object lookup conflict 2015-01-07 13:08:20 +11:00
Sebastian McKenzie
c420d1ffc3 add test262 2015-01-07 13:08:06 +11:00
Sebastian McKenzie
fa42b076a7 remove benchmarks 2015-01-07 11:47:09 +11:00
Sebastian McKenzie
0d23c1cfdb add todo for module collisions 2015-01-07 09:56:17 +11:00
Sebastian McKenzie
0dafdd6969 better support for import collision checking - todo: check exports for collisions 2015-01-07 09:08:34 +11:00
Sebastian McKenzie
a9af8d39a2 add member expression reassign test 2015-01-07 08:00:55 +11:00
Sebastian McKenzie
1cc606d4d0 make import reassignment illegal @eventualbuddha 2015-01-07 07:58:04 +11:00
Sebastian McKenzie
2a09c0a5a5 fix import specifier and export specifier keys 2015-01-07 07:57:36 +11:00
Sebastian McKenzie
92359520cd Merge pull request #379 from webpro/amd-port-interop
Port AMD interop
2015-01-07 07:52:44 +11:00
Lars Kappert
50e5bd4680 Merge remote-tracking branch 'origin/master' into amd-port-interop
Conflicts:
	test/fixtures/transformation/es6-modules-amd/exports-default/expected.js
	test/fixtures/transformation/es6-modules-amd/overview/expected.js
	test/fixtures/transformation/es6-modules-umd/exports-default/expected.js
	test/fixtures/transformation/es6-modules-umd/overview/expected.js
2015-01-06 20:21:00 +01:00
Sebastian McKenzie
64ef26a937 v2.6.3 2015-01-07 00:33:13 +11:00
Sebastian McKenzie
bfd6ffe471 add 2.6.3 changelog 2015-01-07 00:31:37 +11:00
Sebastian McKenzie
8c1760bea2 fix faulty export default source detection - fixes #406 2015-01-07 00:30:41 +11:00
Sebastian McKenzie
bdb8f87480 move docs to 6to5.github.io repo 2015-01-06 22:43:36 +11:00
Sebastian McKenzie
7f6bc54920 capitalise faq description 2015-01-06 22:40:03 +11:00
Sebastian McKenzie
b6af2f826d es6-transpiler doesn't do sourcemaps - closes 6to5/6to5.github.io#9 2015-01-06 22:34:17 +11:00
Sebastian McKenzie
7455b6d9b9 update faq copytext 2015-01-06 22:33:23 +11:00
Sebastian McKenzie
0d2e876178 doc/faq: pretty -> quite 2015-01-06 22:29:06 +11:00
Sebastian McKenzie
57ce1b201d better faq answer 2015-01-06 22:27:41 +11:00
Sebastian McKenzie
5f56da457c remove old spec tests 2015-01-06 22:19:34 +11:00
Sebastian McKenzie
ed988dc2bb is t.isValidIdentifier instead of esutils.keyword.isKeywordES6 2015-01-06 22:17:32 +11:00
Sebastian McKenzie
2c471968ea remove specBlockHoistFunctions and specNoForInOfAssignment 2015-01-06 22:17:15 +11:00
Sebastian McKenzie
fd1a91bf9c add transformer docs 2015-01-06 22:16:48 +11:00
Sebastian McKenzie
9e7de5ad2e add faq docs 2015-01-06 22:16:43 +11:00
Sebastian McKenzie
06927288ba remove this shorthand example from playground 2015-01-06 22:15:44 +11:00
Sebastian McKenzie
9342aee6bd fix up documentation links 2015-01-06 22:15:01 +11:00
Sebastian McKenzie
4f5669f53c v2.6.2 2015-01-06 20:16:33 +11:00
Sebastian McKenzie
262fd995da add 2.6.2 changelog 2015-01-06 20:15:58 +11:00
Sebastian McKenzie
1696f77980 fix rest parameter keys when on functions with params 2015-01-06 20:15:10 +11:00
Lars Kappert
dfa51954b8 Use unaryExpression for typeof 2015-01-06 10:12:08 +01:00
Lars Kappert
216b8c2fd1 Revert "Add types.TypeOfExpression"
This reverts commit 520dd7e947.
2015-01-06 10:05:44 +01:00
Sebastian McKenzie
ca2cbb02f1 v2.6.1 2015-01-06 20:04:54 +11:00
Sebastian McKenzie
b72427cdd0 fix rest parameter tests 2015-01-06 20:04:04 +11:00
Sebastian McKenzie
44e9812ad4 fix rest parameter arguments key - closes #405 2015-01-06 20:02:56 +11:00
Sebastian McKenzie
b7814e5e24 add documentation on optional protoToAssign transformer 2015-01-06 19:58:19 +11:00
Sebastian McKenzie
ec67a83326 add 3.0.0 breaking notes 2015-01-06 18:55:03 +11:00
Sebastian McKenzie
6a560cea25 Merge pull request #404 from thejameskyle/docs
Add new documentation
2015-01-06 18:44:14 +11:00
James Kyle
46f9ed7d74 Add new documentation 2015-01-05 23:27:46 -08:00
Sebastian McKenzie
92366dfc7b move incorrect tag in bug fix to internal 2015-01-06 18:08:42 +11:00
Sebastian McKenzie
f520a46175 better ordering of 2.6.0 changelog groups 2015-01-06 18:08:01 +11:00
Sebastian McKenzie
88bec1196b group 2.6.0 changelog 2015-01-06 18:07:10 +11:00
Sebastian McKenzie
ff0098f3f3 add additional 2.6.0 note 2015-01-06 17:54:34 +11:00
Sebastian McKenzie
d01d7722f4 add dynamic imports note to changelog 2015-01-06 17:49:32 +11:00
Lars Kappert
abc90778e8 Test for exportIdentifier before building exportDeclaration 2015-01-05 21:17:12 +01:00
Lars Kappert
56f1683f06 Also test for "module" identifier if needed 2015-01-05 14:57:52 +01:00
Lars Kappert
520dd7e947 Add types.TypeOfExpression 2015-01-05 14:51:50 +01:00
Lars Kappert
17ce21509d Move exports identifier from UMD template to commonArgs 2015-01-04 12:59:25 +01:00
Lars Kappert
a4c8895dc3 Conditionally pass "module" arg to AMD/UMD factory 2015-01-04 12:58:52 +01:00
Lars Kappert
af4009694a Simplify AMD export declaration fn to re-use CommonJS one 2015-01-04 12:53:17 +01:00
Lars Kappert
941a8cc5ea Remove unused templates 2015-01-04 12:51:34 +01:00
Lars Kappert
359c4e8786 Use module.exports in expectations 2015-01-04 12:51:19 +01:00
Lars Kappert
7ac98c1532 Add custom export declaration fn for AMD modules 2015-01-04 11:46:28 +01:00
Lars Kappert
61c3e0a3de Modify test expectations 2015-01-04 11:45:09 +01:00
106 changed files with 513 additions and 1924 deletions

3
.gitmodules vendored
View File

@@ -4,3 +4,6 @@
[submodule "vendor/regenerator"]
path = vendor/regenerator
url = https://github.com/facebook/regenerator
[submodule "vendor/test262"]
path = vendor/test262
url = https://github.com/tc39/test262

View File

@@ -7,25 +7,65 @@
> - [Breaking Change]
> - [Documentation]
> - [Internal]
> - [Misc]
> - [Polish]
_Note: Gaps between patch versions are faulty/broken releases._
## 2.7.1
* **New Feature**
* Expose `version` on browser and node API.
* **Internal**
* Upgrade `core-js` to 0.4.1
## 2.7.0
* **Spec Compliancy**
* Disallow reassignments of imports.
* **New Feature**
* `reactCompat` option to enable pre-v0.12 react components.
## 2.6.3
* **Bug Fix**
* Fix 2.6.0 regression caused by faulty export default from a source handling.
## 2.6.2
* **Bug Fix**
* Fix rest parameter keys when on functions with params.
## 2.6.1
* **Bug Fix**
* Fix rest parameter arguments key.
## 2.6.0
* [Internal] Fix incorrect AST node `identifier("this")`.
* [Spec Compliancy] Add `interopRequireWildcard` around wildcard imports and exports to handle non-object exports.
* [Internal] Upgrade `acorn-6to5`.
* [New Feature] Basic destructuring defaults
* [New Feature] Add `.es` to list of supported extensions.
* [New Feature] Add optional `typeofSymbol` transformer.
* [Bug Fix] Better handling of number literal property keys.
* [Bug Fix] [Internal] Better `toIdentifier` method that handles reserved words.
* [Internal] Upgrade to `core-js` 4.0.0.
* [Internal] Upgrade to `regenerator` 0.8.3.
* [Bug Fix] Handle `NewExpression` paren insertion edegcases better.
* [Spec Compliancy] Class inheritance now has a `function` or `null` type check.
* [Misc] Move `"use strict";` to inside module bodies instead of at the top of the file.
* **Bug Fix**
* Better handling of number literal property keys.
* Handle `NewExpression` paren insertion edegcases better.
* **Internal**
* Fix incorrect AST node `identifier("this")`.
* Better `toIdentifier` method that handles reserved words.
* Upgrade `acorn-6to5`.
* Fix exponentiation operator precedence.
* Fix line terminators after async contextual keywords.
* Add semicolons as class elements inside of a class body.
* Upgrade to `core-js` 4.0.0.
* Upgrade to `regenerator` 0.8.3.
* Fix non-loop labeled statements.
* **New Feature**
* Basic destructuring defaults
* Add `.es` to list of supported extensions.
* Add optional `typeofSymbol` transformer.
* Use a `for` loop for rest parameters instead of `Array.prototype.slice`.
* **Polish**
* Move `"use strict";` to inside module bodies instead of at the top of the file.
* Better handling of dynamic imports.
* **Spec Compliancy**
* Class inheritance now has a `function` or `null` type check.
* Add `interopRequireWildcard` around wildcard imports and exports to handle non-object exports.
## 2.5.0

View File

@@ -6,7 +6,7 @@ MOCHA_CMD = node_modules/mocha/bin/_mocha
export NODE_ENV = test
.PHONY: clean test test-cov test-clean lint test-travis test-spec test-browser publish bench build bootstrap
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap
build:
mkdir -p dist
@@ -27,12 +27,8 @@ build:
clean:
rm -rf coverage templates.json test/tmp dist
bench:
npm install es6-transpiler traceur esnext es6now jstransform
node node_modules/matcha/bin/_matcha
lint:
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin benchmark/index.js
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin
test-clean:
rm -rf test/tmp
@@ -41,14 +37,23 @@ test: lint
$(MOCHA_CMD)
make test-clean
test-simple:
# excludes test262
export SIMPLE_6TO5_TESTS=1
make test
test-all:
# includes traceur, esnext, regenerator
export ALL_6TO5_TESTS=1
make test
test-cov:
export SIMPLE_6TO5_TESTS=1
rm -rf coverage
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
test-spec:
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- --reporter spec
test-travis: test-spec
test-travis: bootstrap
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
test-browser:

View File

@@ -1,3 +1,8 @@
# Notes
* Wildcard exports/imports wont normalise if `export default` is a non-object.
## 3.0.0 breaking changes
* Remove `allowImportExportEverywhere` option from acorn.
* Remove this shorthand from playground.

View File

@@ -1,99 +0,0 @@
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var obj = {};
var foo = "foo";
var bar = "bar";
// constants
const MULTIPLIER = 5;
// classes
class Foo {
constructor() {
this.foo = "bar";
}
}
class Bar extends Foo {
constructor() {
super();
}
// default parameters
go(foo = "bar", bar = "foo") {
}
// not supported by jstransform
//get foo() {
// return this._foo;
//}
//set foo(val) {
// this._foo = val + " foo!";
//}
}
// arrow functions
arr.map(x => x * x);
// block binding
for (let key in arr) {
let val = arr[key];
console.log(key, val);
}
// computed property names
obj = {
["foo" + bar]: "foobar"
};
// destructuring
var [a, [b], c, d] = ["hello", [", ", "junk"], ["world"]];
console.log(a + b + c);
// array comprehension
// [for (i of [1, 2, 3]) i * i]; // not supported by es6now
// for-of
for (var i of [1, 2, 3]) {
console.log(i * i);
}
// property method assignment
obj = {
foo() {
return "foobar";
},
get bar() {
return this._bar;
},
set bar(val) {
this._bar = val;
}
};
// property name shorthand
function f(x, y) {
return { x, y };
}
// rest parameters
function printList(name, ...items) {
console.log("list %s has the following items", name);
items.forEach(function (item) {
console.log(item);
});
}
// spread
function add(x, y) {
return x + y;
}
var numbers = [5, 10];
add(...numbers);
// template literals
var x = 5;
var y = 10;
console.log(`${x} + ${y} = ${x + y}`);

View File

@@ -1,168 +0,0 @@
Error.stackTraceLimit = Infinity;
var jsTrans = require("jstransform");
var traceur = require("traceur");
//var es6tr = require("es6-transpiler");
var es6now = require("es6now");
//var esnext = require("esnext");
var to5 = require("../lib/6to5");
//var uglify = require("uglify-js");
var matcha = require("matcha");
var path = require("path");
var fs = require("fs");
var _ = require("lodash");
var readResolve = function (filename) {
try {
filename = require.resolve(filename);
} catch (err) {
return null;
}
return fs.readFileSync(filename, "utf8");
};
var getVersion = function (name) {
return require(name + "/package.json").version;
};
var jsTransVisitors = [];
_.each([
"arrow-function-visitors", "class-visitors", "destructuring-visitors",
"object-concise-method-visitors", "object-short-notation-visitors",
"rest-param-visitors", "template-visitors"
], function (name) {
var mod = require("jstransform/visitors/es6-" + name);
jsTransVisitors = jsTransVisitors.concat(mod.visitorList);
});
var compilers = {
"6to5": {
version: getVersion(".."),
compile: function (code, filename) {
return to5.transform(code, { filename: filename }).code;
}
},
traceur: {
runtime: readResolve("traceur/bin/traceur-runtime.js"),
compile: function (code) {
return traceur.compile(code, {
modules: "commonjs",
experimental: true
});
}
},
/*esnext: {
runtime: readResolve("esnext/node_modules/regenerator/runtime.js") || readResolve("regenerator/runtime.js"),
compile: function (code) {
return esnext.compile(code).code;
}
},*/
es6now: {
runtime: readResolve("es6now/runtime/ES6.js"),
compile: function (code) {
return es6now.translate(code);
}
},
/*"es6-transpiler": {
compile: function (code) {
var result = es6tr.run({ src: code });
if (result.errors.length) throw new Error(result.join("; "));
return result.src;
}
},*/
jstransform: {
compile: function (code) {
return jsTrans.transform(jsTransVisitors, code).code;
}
}
};
// versions
//var uglifyTitle = "uglify v" + getVersion("uglify-js");
_.each(compilers, function (compiler, name) {
compiler.title = name + " v" + (compiler.version || getVersion(name));
});
//
var sizeBenchmark = function (code, loc, name, compiler) {
var log = function (output, title) {
title = [compiler.title].concat(title || []).join(" + ");
var text;
var color;
if (output.stack) {
text = "error";
color = "red";
} else {
var kilo = (output.length / 1024).toFixed(2);
text = kilo + "KB";
color = "cyan";
}
text = matcha.utils.color(matcha.utils.padBefore(text, 22), color);
console.log(text, matcha.utils.color("» " + title, "gray"));
if (output.stack) {
console.error(output.stack);
}
};
var go = function (getOutput, title) {
var code;
try {
code = getOutput();
} catch (err) {
log(err, title);
return;
}
log(code, title);
};
var output;
go(function () {
return output = compiler.compile(code, loc);
});
if (!output) return;
//go(function () {
// return uglify.minify(output, { fromString: true }).code;
//}, uglifyTitle);
};
//
_.each(fs.readdirSync(__dirname + "/fixtures"), function (name) {
var alias = path.basename(name, path.extname(name));
suite(alias, function () {
set("delay", 0);
var loc = __dirname + "/fixtures/" + name;
var code = fs.readFileSync(loc, "utf8");
before(function () {
_.each(compilers, function (compiler, name) {
sizeBenchmark(code, loc, name, compiler);
});
});
_.each(compilers, function (compiler) {
bench(compiler.title, function () {
compiler.compile(code, loc);
});
});
});
});

View File

@@ -1,65 +0,0 @@
# Browser
A browser version of 6to5 is available from `browser.js` inside the 6to5
directory in an npm release.
## Scripts
While it's not recommended for serious use, when the browser version is included
all scripts with the type `text/ecmascript-6` and `text/6to5` are automatically
compiled and ran.
For example:
```html
<script src="node_modules/6to5/browser.js"></script>
<script type="text/6to5">
class Test {
test() {
return "test";
}
}
var test = new Test;
test.test();
</script>
```
## Build
You can build a browser version of the compiler by running the following in the
6to5 directory:
```sh
$ make build
```
This will output the files `dist/6to5.js` and `dist/6to5.min.js`.
## Test
To test 6to5 in your browser run:
```sh
$ make test-browser
```
And open `test/browser.html` in your browser if it doesn't open automatically.
## API
### to5.transform(code, [opts])
See [options](usage.md#options) for additional documentation.
```javascript
to5.transform("class Test {}").code;
```
### to5.run(code, [opts])
See [options](usage.md#options) for additional documentation.
```javascript
to5.run("class Test {}");
```

View File

@@ -1,62 +0,0 @@
# Caveats
In order for certain features to work they require certain polyfills. You can
satisfy **all** 6to5 feature requirements by using the included
[polyfill](polyfill.md).
You may alternatively selectively include what you need:
| Feature | Requirements |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| Abstract References | [experimental](experimental.md), `Symbol` |
| Array destructuring | `Array.from` |
| Async functions, Generators | [experimental](experimental.md), [regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) |
| Comprehensions | [experimental](experimental.md), `Array.from` |
| For Of | `Symbol`, `prototype[Symbol.iterator]` |
| Modules | `Object.assign`* |
| Object spread/rest | [experimental](experimental.md), `Object.assign` |
| Spread | `Array.from` |
*Only required for exporting a non-function `default` with additional `export`s.
## ES5
Since 6to5 assumes that your code will be ran in an ES5 environment it uses ES5
functions. So if you're using an environment that has limited or no support for
ES5 such as lower versions of IE then using the
[es5-shim](https://github.com/es-shims/es5-shim) along with the
[6to5 polyfill](polyfill.md) will add support for these methods.
## Internet Explorer
### Classes (10 and below)
If you're inheriting from a class then static properties are inherited from it
via [\_\_proto\_\_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto),
this is widely supported but you may run into problems with much older browsers.
**NOTE:** `__proto__` is not supported in IE <= 10 so static properties
**will not** be inherited. A possible workaround is to use `super();`:
```javascript
class Foo {
static foo() {
}
}
class Bar extends Foo {
static foo() {
super();
}
}
```
## Getters/setters (8 and below)
In IE8 `Object.defineProperty` can only be used on DOM objects. This is
unfortunate as it's required to set getters and setters. Due to this if
you plan on supporting IE8 or below then the user of getters and setters
isn't recommended.
**Reference**: [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Internet_Explorer_8_specific_notes).

View File

@@ -1,137 +0,0 @@
# Differences
There are three main points that separate 6to5 from all other transpilers.
### Readable code
The fundamental concept behind 6to5 is that the generated code must be close as
possible to the original, retaining all the same formatting and readability.
Many other transpilers are just concerned with making the code work while 6to5
is concerned with making sure it works **and** is readable at the same time.
For example, given the following array comprehension:
```javascript
var seattlers = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];
```
is generated to the following with 6to5:
```javascript
var seattlers = Array.from(customers).filter(function (c) {
return c.city == "Seattle";
}).map(function (c) {
return {
name: c.name,
age: c.age
};
});
```
The following is what Traceur generates:
```javascript
var seattlers = (function() {
var c;
var $__20 = 0,
$__21 = [];
for (var $__22 = customers[$traceurRuntime.toProperty(Symbol.iterator)](),
$__23; !($__23 = $__22.next()).done; ) {
c = $__23.value;
if (c.city == "Seattle")
$traceurRuntime.setProperty($__21, $__20++, {
name: c.name,
age: c.age
});
}
return $__21;
}());
```
As you can tell, it's not very pretty. Instead of mapping directly to a
runtime, like other transpilers, 6to5 maps directly to the equivalent ES5.
Sometimes there are little inline functions that 6to5 needs. These are
placed at the top of your file much like coffee-script does. If these
bother you then you can use the [optional runtime](optional-runtime.md).
We promise that these inline functions will never be significant and will
always be used as little as possible.
### Static analysis
6to5 uses a lot of static analysis to simplify code as much as possible.
Not many other transpilers do this, and those that do don't do it nearly
as much as 6to5. This process is pretty intensive but it leads to higher
quality code.
### Spec compliancy
6to5 prides itself on
[spec compliancy](https://kangax.github.io/compat-table/es6/). We have
excellent support for edgecases, something that many other transpilers
suffer from, including Traceur. When you use 6to5 you can be confident
that when you turn it off and use your code in a full ES6 environment
**it'll just work**.
## Comparison to other transpilers
### Features
| | 6to5 | Traceur | es6-transpiler | es6now | jstransform |
| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- |
| Source maps | ✓ | ✓ | ✓ | | ✓ |
| No compiler global pollution | ✓ | | ✓ | | ✓ |
| Optional runtime | ✓ | | ✓ | | ✓ |
| Browser compiler | ✓ | ✓ | | | |
### Language Support
| | 6to5 | Traceur | es6-transpiler | es6now | jstransform |
| ---------------------------- | ---- | ------- | -------------- | ------ | ----------- |
| Abstract references | ✓ | | | | |
| Array comprehension | ✓ | ✓ | ✓ | | |
| Arrow functions | ✓ | ✓ | ✓ | ✓ | ✓ |
| Async functions | ✓ | ✓ | | | |
| Async generator functions | ✓ | ✓ | | | |
| Classes | ✓ | ✓ | ✓ | ✓ | ✓ |
| Computed property names | ✓ | ✓ | ✓ | ✓ | |
| Constants | ✓ | ✓ | ✓ | | |
| Default parameters | ✓ | ✓ | ✓ | ✓ | |
| Destructuring | ✓ | ✓ | ✓ | ✓ | ✓ |
| Exponentiation operator | ✓ | ✓ | | | |
| Flow types | ✓ | | | | ✓ |
| For-of | ✓ | ✓ | ✓ | ✓ | |
| Generators | ✓ | ✓ | | | |
| Generator comprehension | ✓ | ✓ | | | |
| JSX | ✓ | | | | |
| Let scoping | ✓ | ✓ | ✓ | | |
| Modules | ✓ | ✓ | | ✓ | |
| Object rest/spread | ✓ | | | | ✓ |
| Property method assignment | ✓ | ✓ | ✓ | ✓ | ✓ |
| Property name shorthand | ✓ | ✓ | ✓ | ✓ | ✓ |
| Rest parameters | ✓ | ✓ | ✓ | ✓ | ✓ |
| React | ✓ | | | | |
| Spread | ✓ | ✓ | ✓ | ✓ | |
| Template literals | ✓ | ✓ | ✓ | ✓ | ✓ |
| Unicode regex | ✓ | ✓ | ✓ | | |
### [Traceur](https://github.com/google/traceur-compiler)
Traceur requires quite a bulky runtime (~75KB) and produces quite verbose code.
While this can be trimmed down by selectively building the runtime, it's an
unnecessary step when a large runtime can be eliminated entirely.
### [es6now](https://github.com/zenparsing/es6now)
es6now doesn't output sourcemaps. This is cited as a positive as line-to-line
mapping is the goal. This however obviously doesn't retain column mapping
resulting in the output code not being very pleasant.
### [es6-transpiler](https://github.com/termi/es6-transpiler)
The es6-transpiler compiler requires shims to operate which pollutes the global
scope resulting in possible collisions.
es6-transpiler maps line-by-line, just like es6now, this results in the same
issues such as lack of column information and unpleasant code output.

View File

@@ -1,8 +0,0 @@
## Experimental
6to5 also has experimental support for ES7 proposals. You can enable this with
the `experimental: true` option when using the [Node API](#node) or
`--experimental` when using the [CLI](#cli).
**WARNING:** These proposals are subject to change so use with
**extreme caution**.

View File

@@ -1,283 +0,0 @@
# Features
## Abstract references ([experimental](experimental.md)) ([spec](https://github.com/zenparsing/es-abstract-refs))
```javascript
foo::bar;
foo::bar = baz;
delete foo::bar;
```
## Array comprehensions ([experimental](experimental.md))
```javascript
var results = [for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]
```
## Arrow functions
```javascript
// Expression bodies
var odds = evens.map(v => v + 1);
var nums = evens.map((v, i) => v + i);
// Statement bodies
nums.forEach(v => {
if (v % 5 === 0)
fives.push(v);
});
// Lexical this
var bob = {
_name: "Bob",
_friends: [],
printFriends() {
this._friends.forEach(f => {
console.log(this._name + " knows " + f);
});
}
};
```
## Async functions ([experimental](experimental.md)) ([spec](https://github.com/lukehoban/ecmascript-asyncawait))
```javascript
async function chainAnimationsAsync(elem, animations) {
for (var anim of animations) {
await anim(elem);
}
}
```
## Async generator functions ([experimental](experimental.md)) ([spec](https://github.com/jhusain/asyncgenerator))
```javascript
```
## Classes
```javascript
class SkinnedMesh extends THREE.Mesh {
constructor(geometry, materials) {
super(geometry, materials);
this.idMatrix = SkinnedMesh.defaultMatrix();
this.bones = [];
this.boneMatrices = [];
//...
}
update(camera) {
//...
super.update();
}
static defaultMatrix() {
return new THREE.Matrix4();
}
}
```
## Computed property names
```javascript
var foo = "foo";
var bar = "bar";
var obj = {
["foo" + bar]: "heh",
["bar" + foo]: "noo",
foo: "foo",
bar: "bar"
};
```
## Constants
```javascript
const MULTIPLIER = 5;
console.log(2 * MULTIPLIER);
MULTIPLIER = 6; // error
var MULTIPLIER; // error
```
## Default parameters
```javascript
function f(x, y = 12) {
// y is 12 if not passed (or passed as undefined)
return x + y;
}
f(3) == 15
```
## Destructuring
```javascript
// list matching
var [a, , b] = [1,2,3];
// object matching
var { op: a, lhs: { op: b }, rhs: c } = getASTNode();
// object matching shorthand
// binds `op`, `lhs` and `rhs` in scope
var { op, lhs, rhs } = getASTNode();
// Can be used in parameter position
function g({ name: x }) {
console.log(x);
}
g({ name: 5 });
// Fail-soft destructuring
var [a] = [];
a === undefined;
```
## Exponentiation operator ([experimental](experimental.md)) ([spec](https://github.com/rwaldron/exponentiation-operator))
```javascript
var a = 2;
a **= 2;
var squared = 2 ** 2;
```
## For-of
```javascript
for (var i of [1, 2, 3]) {
console.log(i * i);
}
```
## Generators
```javascript
function* fibonacci() {
var pre = 0, cur = 1;
for (;;) {
var temp = pre;
pre = cur;
cur += temp;
yield cur;
}
}
for (var n of fibonacci()) {
// truncate the sequence at 1000
if (n > 1000) break;
console.log(n);
}
```
## Generator comprehensions ([experimental](experimental.md))
```javascript
var nums = [1, 2, 3, 4, 5, 6];
var multiples = (for (i of nums) if (i % 2) i * i);
assert.equal(multiples.next().value, 1);
assert.equal(multiples.next().value, 9);
assert.equal(multiples.next().value, 25);
```
## Let scoping
```javascript
for (let i in arr) {
let v = arr[i];
}
```
## Modules
```javascript
import "foo";
import foo from "foo";
import * as foo from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
export { test };
export var test = 5;
export function test() {}
export default test;
```
## Numeric literals
```javascript
0b111110111 === 503; // true
0o767 === 503; // true
```
## Object spread/rest ([experimental](experimental.md)) ([spec](https://github.com/sebmarkbage/ecmascript-rest-spread))
```javascript
var n = { x, y, ...z };
var { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
```
## Property method assignment
```javascript
var obj = {
foo() {
return "foobar";
},
get bar() {
return this._bar;
},
set bar(val) {
this._bar = val;
}
};
```
## Property name shorthand
```javascript
function f(x, y) {
return { x, y };
}
```
## Rest parameters
```javascript
function f(x, ...y) {
// y is an Array
return x * y.length;
}
f(3, "hello", true) == 6
```
## Spread
```javascript
function f(x, y, z) {
return x + y + z;
}
// Pass each elem of array as argument
f(...[1,2,3]) == 6
```
## Template literals
```javascript
var x = 5;
var y = 10;
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"
```
## Unicode regex
```javascript
var string = 'foo💩bar';
var match = string.match(/foo(.)bar/u);
console.log(match[1]);
```

View File

@@ -1,62 +1 @@
**6to5** turns ES6+ code into vanilla ES5, so you can use next generation features **today.**
- **Readable** - formatting is retained if possible so your generated code is as similar as possible.
- **Extensible** - with a large range of [plugins](plugins.md) and **browser support**.
- **Lossless** - **source map support** so you can debug your compiled code with ease.
- **Compact** - maps directly to the equivalent ES5 with **no runtime**[\*](caveats.md).
## Installation
It's as easy as:
$ npm install -g 6to5
## Usage
Once you've installed 6to5, there are multiple paths you can take depending on
how you want to use it.
6to5 will simply compile your ES6+ script to ES5 if you pass it as an argument
to the command-line tool `6to5`:
```sh
$ 6to5 script.js
```
If you have a file written using ES6+ and you just want to run it, `6to5-node`
has you covered:
```sh
$ 6to5-node script.js
```
And it doesn't end here! To see all the ways you can use 6to5, check out the
[Usage](http://6to5.github.io/usage.html) page.
## [Features](features.md)
- [Abstract references](features.md#abstract-references) ([experimental](experimental.md))
- [Array comprehension](features.md#array-comprehension) ([experimental](experimental.md))
- [Async functions](features.md#async-functions) ([experimental](experimental.md))
- [Async generator functions](features.md#async-generator-functions) ([experimental](experimental.md))
- [Arrow functions](features.md#arrow-functions)
- [Classes](features.md#classes)
- [Computed property names](features.md#computed-property-names)
- [Constants](features.md#constants)
- [Default parameters](features.md#default-parameters)
- [Destructuring](features.md#destructuring)
- [Exponentiation operator](features.md#exponentiation-operator) ([experimental](experimental.md))
- [For-of](features.md#for-of)
- [Generators](features.md#generators)
- [Generator comprehension](features.md#generator-comprehension) ([experimental](experimental.md))
- [Let scoping](features.md#let-scoping)
- [Modules](features.md#modules)
- [Numeric literals](features.md#numeric-literals)
- [Object rest/spread](features.md#object-rest-spread) ([experimental](experimental.md))
- [Property method assignment](features.md#property-method-assignment)
- [Property name shorthand](features.md#property-name-shorthand)
- [React/JSX](react.md)
- [Rest parameters](features.md#rest-parameters)
- [Spread](features.md#spread)
- [Template literals](features.md#template-literals)
- [Unicode regex](features.md#unicode-regex)
See [6to5.github.io/docs](https://github.com/6to5/6to5.github.io/tree/master/docs).

View File

@@ -1,257 +0,0 @@
# Modules
## Usage
### CLI
```sh
$ 6to5 --modules common script.js
```
### Node
```javascript
var to5 = require("6to5");
to5.transform('import "foo";', { modules: "common" });
```
## Formats
* [AMD](#amd)
* [Common (Default)](#common-default)
* [Ignore](#ignore)
* [System](#system)
* [UMD](#umd)
### Common
```sh
$ 6to5 --modules common
```
**In**
```javascript
export default test;
export {test};
export var test = 5;
import "foo";
import foo from "foo";
import * as foo from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
```
**Out**
```javascript
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
exports = module.exports = test;
exports.test = test;
var test = exports.test = 5;
require("foo");
var foo = _interopRequire(require("foo"));
var foo = require("foo");
var bar = require("foo").bar;
var bar = require("foo").foo;
```
### AMD
```sh
$ 6to5 --modules amd
```
**In**
```javascript
import foo from "foo";
export function bar() {
return foo("foobar");
}
```
**Out**
```javascript
define(["exports", "foo"], function (exports, _foo) {
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
exports.bar = bar;
var foo = _interopRequire(_foo);
function bar() {
return foo("foobar");
}
});
```
You can optionally specify to include the module id (using the `--amd-module-id` argument):
```javascript
define("filename", ["exports", "foo"], function (exports, _foo) {})
```
### UMD
```sh
$ 6to5 --modules umd
```
**In**
```javascript
import foo from "foo";
export function bar() {
return foo("foobar");
}
```
**Out**
```javascript
(function (factory) {
if (typeof define === "function" && define.amd) {
define(["exports", "foo"], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require("foo"));
}
})(function (exports, _foo) {
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
exports.bar = bar;
var foo = _interopRequire(_foo);
function bar() {
return foo("foobar");
}
});
```
### Ignore
```sh
$ 6to5 --modules ignore
```
**In**
```javascript
import foo from "foo";
export function bar() {
return foo("foobar");
}
```
**Out**
```javascript
function bar() {
return foo("foobar");
}
```
### System
```sh
$ 6to5 --modules system
```
**In**
```javascript
import foo from "foo";
export function bar() {
return foo("foobar");
}
```
**Out**
```javascript
System.register("bar", ["foo"], function (_export) {
"use strict";
var __moduleName = "bar";
var foo;
function bar() {
return foo("foobar");
}
return {
setters: [function (m) {
foo = m.default;
}],
execute: function () {
_export("bar", bar);
}
};
});
```
## Custom
You can alternatively specify module names instead of one of the built-in types.
```sh
$ 6to5 --modules custom-module-formatter
```
**node_modules/custom-module-formatter/index.js**
```javascript
module.exports = ModuleFormatter;
function ModuleFormatter() {
}
ModuleFormatter.prototype.transform = function (ast) {
// this is ran after all transformers have had their turn at modifying the ast
// feel free to modify this however
};
ModuleFormatter.prototype.importDeclaration = function (node, nodes) {
// node is an ImportDeclaration
};
ModuleFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
// specifier is an ImportSpecifier
// node is an ImportDeclaration
};
ModuleFormatter.prototype.exportDeclaration = function (node, nodes) {
// node is an ExportDeclaration
};
ModuleFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
// specifier is an ExportSpecifier
// node is an ExportDeclaration
};
```

View File

@@ -1,57 +0,0 @@
# Optional runtime
6to5 has a few helper functions that'll be placed at the top of the generated
code if needed so it's not inlined multiple times throughout that file. This may
become an issue if you have multiple files, especially when you're sending them
to the browser. gzip alleviates most of this concern but it's still not ideal.
You can tell 6to5 to not place any declarations at the top of your files and
instead just point them to a reference contained within the runtime.
Simply use the following option if you're using the [Node API](usage.md#node):
```javascript
{
runtime: true
}
```
or the following flag if you're using the [CLI](usage.md#cli):
```ssh
$ 6to5 --runtime
```
Then just include the runtime before your generated code.
## Getting the runtime
You can get the runtime via either:
```sh
$ 6to5-runtime
```
or
```javascript
require("6to5").runtime();
```
or from an npm release in `runtime.js` from the 6to5 directory.
## Customising namespace
You can also customise the runtime namespace by passing an optional namespace
argument:
```javascript
require("6to5").runtime("myCustomNamespace");
```
```sh
$ 6to5-runtime myCustomNamespace
```
See [Options - runtime](usage.md#options) for documentation on changing the
reference in generated code.

View File

@@ -1,140 +0,0 @@
# Playground
Playground is a proving ground for **possible** ES7 proposals.
**NOTE: These features are in no way endorsed by Ecma International and are not a part of ES6. They might become a part of ECMAScript in the future.**
## Usage
$ 6to5 --playground
```javascript
to5.transform("code", { playground: true });
```
**NOTE:** Enabling `playground` also enables [experimental support](experimental.md).
## Features
* [Memoization operator](#memoization-operator)
* [Method binding](#method-binding)
* [Method binding function shorthand](#method-binding-function-shorthand)
* [Object getter memoization](#object-getter-memoization)
* [This shorthand](#this-shorthand)
### Memoization assignment operator
The memoization assignment operator allows you to lazily set an object property.
It checks whether there's a property defined on the object and if there isn't then
the right hand value is set.
This means that `obj.x` in the following `var x = { x: undefined }; obj.x ?= 2;`
will still be `undefined` because it's already been defined on the object.
```javascript
var obj = {};
obj.x ?= 2;
obj.x; // 2
obj = { x: 1 };
obj.x ?= 2;
obj.x; // 1
obj = { x: undefined }
obj.x ?= 2;
obj.x; // undefined
```
```javascript
var obj = {};
obj.x ?= 2;
```
equivalent to
```javascript
var obj = {};
if (!Object.prototype.hasOwnProperty.call(obj, "x")) obj.x = 2;
```
### Method binding
```javascript
var fn = obj#method;
var fn = obj#method("foob");
```
equivalent to
```javascript
var fn = obj.method.bind(obj);
var fn = obj.method.bind(obj, "foob");
```
### Method binding function shorthand
```javascript
["foo", "bar"].map(#toUpperCase); // ["FOO", "BAR"]
[1.1234, 23.53245, 3].map(#toFixed(2)); // ["1.12", "23.53", "3.00"]
```
equivalent to
```javascript
["foo", "bar"].map(function (val) { return val.toUpperCase(); });
[1.1234, 23.53245, 3].map(function (val) { return val.toFixed(2); });
```
### Object getter memoization
```javascript
var foo = {
memo bar() {
return complex();
}
};
class Foo {
memo bar() {
return complex();
}
}
```
equivalent to
```javascript
var foo = {
get bar() {
return Object.defineProperty(this, "bar", {
value: complex(),
enumerable: true,
configurable: true,
writable: true
}).bar;
}
};
class Foo {
get bar() {
return Object.defineProperty(this, "bar", {
value: complex(),
enumerable: true,
configurable: true,
writable: true
}).bar;
}
}
```
### This shorthand
```javascript
@foo
```
equivalent to
```javascirpt
this.foo
```

View File

@@ -1,33 +0,0 @@
# Plugins
## Build systems
- [Broccoli](https://github.com/6to5/broccoli-6to5-transpiler)
- [Browserify](https://github.com/6to5/6to5ify)
- [Brunch](https://github.com/6to5/6to5-brunch)
- [Duo](https://github.com/6to5/duo6to5)
- [Gobble](https://github.com/6to5/gobble-6to5)
- [Gulp](https://github.com/6to5/gulp-6to5)
- [Grunt](https://github.com/6to5/grunt-6to5)
- [Sprockets](https://github.com/josh/sprockets-es6) or via [Browserify](https://github.com/6to5/6to5-rails)
- [webpack](https://github.com/6to5/6to5-loader)
## Integrations
- [Isparta](https://github.com/douglasduteil/isparta) - Code coverage with `karma` and `instanbul` using 6to5
- [JSXHint](https://github.com/STRML/JSXHint) - A wrapper around JSHint to allow linting of JSX files
## Bridges
- [Ruby](https://github.com/6to5/6to5-ruby)
## Testing
- [Jest](https://github.com/6to5/6to5-jest)
- [Karma](https://github.com/6to5/karma-6to5-preprocessor)
- [Mocha](https://github.com/6to5/6to5-mocha)
## Misc
- [Connect](https://github.com/6to5/6to5-connect)
- [Jade](https://github.com/6to5/jade-6to5)

View File

@@ -1,34 +0,0 @@
# Polyfill
6to5 includes a polyfill that includes a custom
[regenerator runtime](https://github.com/facebook/regenerator/blob/master/runtime.js) and
[core.js](https://github.com/zloirock/core-js).
This will emulate a full ES6 environment. This polyfill is automatically loaded
when using [6to5-node](usage.md#node) and [6to5/register](usage.md#register-hook).
## Usage
### Node/Browserify
You need to include the polyfill require at the top the **entry point** to your
application.
```javascript
require("6to5/polyfill");
```
Fortunately, this is automatically loaded when using:
```javascript
require("6to5/register");
```
### Browser
Available from the `browser-polyfill.js` file within the 6to5 directory of an
npm release. This needs to be included **before** all your compiled 6to5 code.
You can either prepend it to your compiled code or include it in a `<script>`
before it.
**NOTE:** Do not `require` this via browserify etc, use `6to5/polyfill`.

View File

@@ -1,17 +0,0 @@
# React/JSX
6to5 has built-in support for React v0.12. Tags are automatically transformed to
their equivalent `React.createElement(...)` and `displayName` is automatically
inferred and added to all `React.createClass` calls.
## Blacklist
To disable this behaviour add `react` to your blacklist:
```javascript
to5.transform("code", { blacklist: ["react"] });
```
```sh
$ 6to5 --blacklist react
```

View File

@@ -1,259 +0,0 @@
# Usage
## CLI
Compile the file `script.js` and output it to stdout.
```sh
$ 6to5 script.js
```
Compile the file `script.js` and output it to `script-compiled.js`.
```sh
$ 6to5 script.js --out-file script-compiled.js
```
Compile the file `script.js` and output it to `script-compiled.js` and save a
source map to `script-compiled.js.map`.
```sh
$ 6to5 script.js --source-maps --out-file script-compiled.js
```
Compile the file `script.js` and output it to `script-compiled.js` with a source
map embedded in a comment at the bottom.
```sh
$ 6to5 script.js --source-maps-inline --out-file script-compiled.js
```
Compile the entire `src` directory and output it to the `lib` directory.
```sh
$ 6to5 src --out-dir lib
```
Compile the entire `src` directory and output it to the one concatenated file.
```sh
$ 6to5 src --out-file script-compiled.js
```
Pipe a file in via stdin and output it to `script-compiled.js`
```sh
$ 6to5 --out-file script-compiled.js < script.js
```
### Node
Launch a repl.
```sh
$ 6to5-node
```
Evaluate code.
```sh
$ 6to5-node -e "class Test { }"
```
Compile and run `test.js`.
```sh
$ 6to5-node test
```
## Node
```javascript
var to5 = require("6to5");
```
### to5.transform(code, [opts]);
```javascript
var result = to5.transform("code();", options);
result.code;
result.map;
result.ast;
```
### to5.transformFileSync(filename, [opts])
```javascript
to5.transformFileSync("filename.js", options).code;
```
### to5.transformFile(filename, [opts], callback)
```javascript
to5.transformFile("filename.js", options, function (err, result) {
result.code;
});
```
### to5.transform.fromAst(ast, [code], [opts])
```javascript
var result = to5.transform.fromAst(ast, "var a = 2;", opts);
result.code;
result.map;
result.ast;
```
#### Options
```javascript
{
// Filename for use in errors etc.
// Default: "unknown"
filename: "filename",
// Filename relative to `sourceRoot`
// Default: `filename` option.
filenameRelative: "",
// List of transformers to EXCLUDE.
// Run `6to5 --help` to see a full list of transformers.
blacklist: [],
// List of transformers to ONLY use.
// Run `6to5 --help` to see a full list of transformers.
whitelist: [],
// Module formatter to use
// Run `6to5 --help` to see a full list of module formatters.
// Default: "common"
modules: "common",
// If truthy, adds a `map` property to returned output.
// If set to "inline", a comment with a sourceMappingURL directive is added to
// the bottom of the returned code.
// Default: false
sourceMap: true,
// Set `file` on returned source map.
// Default: `filenameRelative` option.
sourceMapName: "filename",
// Set `sources[0]` on returned source map.
// Default: `filenameRelative` option.
sourceFileName: "filename",
// The root from which all sources are relative
// Default: `moduleRoot` option.
sourceRoot: "assets/scripts",
// Optional prefix for the AMD module formatter that will be prepend to the
// filename on module definitions
// Default: `sourceRoot` option.
moduleRoot: "my-app",
// If truthy, insert an explicit id for each defined AMD/System module.
// By default, AMD/System modules are anonymous.
// Default: false
moduleIds: true,
// Optionally replace all 6to5 helper declarations with a referenece to this
// variable. If set to `true` then the default namespace is used "to5Runtime".
// Default: false
runtime: true,
// Enable support for experimental ES7 features
// Default: false
experimental: true,
// Set this to `false` if you don't want the transformed AST in the returned
// result
// Default: true
ast: true,
// Set this to `false` if you don't want the transformed code in the returned
// result
// Default: true
code: true,
format: {
// Output comments in generated output
// Default: true
comments: true,
// Do not include superfluous whitespace characters and line terminators
// Default: false
compact: false,
indent: {
// Preserve parentheses in new expressions that have no arguments
// Default: true
parentheses: true,
// Adjust the indentation of multiline comments to keep asterisks vertically aligned
// Default: true
adjustMultilineComment: true,
// Indent string
// Default: " "
style: " ",
// Base indent level
// Default: 0
base: 0
}
}
}
```
### Require hook
All subsequent files required by node with the extensions `.es6`, `.es` and `.js` will
be transformed by 6to5. The polyfill specified in [Polyfill](polyfill.md) is
also required; but this is automatically loaded when using:
Source maps are automatically configured so if any errors a thrown then line
number info is mapped and you'll get the correct source location.
```javascript
require("6to5/register");
```
**NOTE:** By default all requires to `node_modules` will be ignored. You can
override this by passing an ignore regex via:
```javascript
require("6to5/register")({
// This will override `node_modules` ignoring - you can alternatively pass
// a regex
ignore: false
});
```
**NOTE:** Using 6to5-node or `require("6to5/register")`, 6to5 will check what features are available in the current environment and blacklists them if they're supported.
#### Options
```javascript
require("6to5/register")({
// Optional ignore regex - if any filenames **do** match this regex then they
// aren't compiled
ignore: /regex/,
// Optional only regex - if any filenames **don't** match this regex then they
// aren't compiled
only: /my_es6_folder/,
// See options above for usage
whitelist: [],
blacklist: [],
// This will remove the currently hooked extensions of .es6 and .js so you'll
// have to add them back if you want them to be used again.
extensions: [".js", ".es6"],
// Enables `roadrunner` cache that will save to a `.roadrunner.json` file in your cwd
// Do not check this into git as it's user-specific
cache: true
});
```

View File

@@ -1,5 +1,7 @@
var transform = module.exports = require("./transformation/transform");
transform.version = require("../../package").version;
transform.transform = transform;
transform.run = function (code, opts) {

View File

@@ -48,6 +48,7 @@ File.normaliseOptions = function (opts) {
_.defaults(opts, {
experimental: false,
reactCompat: false,
playground: false,
whitespace: true,
moduleIds: opts.amdModuleIds || false,

View File

@@ -3,6 +3,8 @@ var util = require("./util");
var fs = require("fs");
var _ = require("lodash");
exports.version = require("../../package").version;
exports.types = require("./types");
exports.runtime = require("./runtime-generator");

View File

@@ -9,7 +9,11 @@ function DefaultFormatter(file) {
this.file = file;
this.localExports = this.getLocalExports();
this.localImports = this.getLocalImports();
this.remapAssignments();
//this.checkCollisions();
}
DefaultFormatter.prototype.getLocalExports = function () {
@@ -27,6 +31,53 @@ DefaultFormatter.prototype.getLocalExports = function () {
return localExports;
};
DefaultFormatter.prototype.getLocalImports = function () {
var localImports = {};
traverse(this.file.ast, {
enter: function (node) {
if (t.isImportDeclaration(node)) {
_.extend(localImports, t.getIds(node, true));
}
}
});
return localImports;
};
DefaultFormatter.prototype.checkCollisions = function () {
// todo: all check export collissions
var localImports = this.localImports;
var file = this.file;
var isLocalReference = function (node) {
return t.isIdentifier(node) && _.has(localImports, node.name) && localImports[node.name] !== node;
};
var check = function (node) {
if (isLocalReference(node)) {
throw file.errorWithNode(node, "Illegal assignment of module import");
}
};
traverse(file.ast, {
enter: function (node) {
if (t.isAssignmentExpression(node)) {
var left = node.left;
if (t.isMemberExpression(left)) {
while (left.object) left = left.object;
}
check(left);
} else if (t.isDeclaration(node)) {
_.each(t.getIds(node, true), check);
}
}
});
};
DefaultFormatter.prototype.remapExportAssignment = function (node) {
return t.assignmentExpression(
"=",
@@ -142,10 +193,11 @@ DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node,
nodes.push(this._exportsWildcard(getRef(), node));
} else {
var ref;
if (t.isSpecifierDefault(specifier.id) || this.noInteropRequire) {
ref = t.memberExpression(getRef(), specifier.id);
} else {
if (t.isSpecifierDefault(specifier) && !this.noInteropRequire) {
// importing a default so we need to normalise it
ref = t.callExpression(this.file.addHelper("interop-require"), [getRef()]);
} else {
ref = t.memberExpression(getRef(), specifier.id);
}
// export { foo } from "test";

View File

@@ -1,6 +1,7 @@
module.exports = AMDFormatter;
var DefaultFormatter = require("./_default");
var CommonFormatter = require("./common");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
@@ -30,12 +31,15 @@ AMDFormatter.prototype.transform = function (ast) {
// build an array of module names
var names = [t.literal("exports")].concat(this.buildDependencyLiterals());
var names = [t.literal("exports")];
if (this.passModuleArg) names.push(t.literal("module"));
names = names.concat(this.buildDependencyLiterals());
names = t.arrayExpression(names);
// build up define container
var params = _.values(this.ids);
if (this.passModuleArg) params.unshift(t.identifier("module"));
params.unshift(t.identifier("exports"));
var container = t.functionExpression(null, params, t.blockStatement(body));
@@ -96,6 +100,14 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
]));
};
AMDFormatter.prototype.exportDeclaration = function (node) {
if (node.default) {
this.passModuleArg = true;
}
CommonFormatter.prototype.exportDeclaration.apply(this, arguments);
};
AMDFormatter.prototype.exportSpecifier = function (specifier, node, nodes) {
var self = this;
return this._exportSpecifier(function () {

View File

@@ -61,7 +61,7 @@ CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
};
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
if (node.default) {
if (node.default && !this.exportIdentifier) {
var declar = node.declaration;
var assign;

View File

@@ -25,22 +25,37 @@ UMDFormatter.prototype.transform = function (ast) {
// factory
var ids = _.values(this.ids);
var args = [t.identifier("exports")].concat(ids);
var args = [t.identifier("exports")];
if (this.passModuleArg) args.push(t.identifier("module"));
args = args.concat(ids);
var factory = t.functionExpression(null, args, t.blockStatement(body));
// runner
var defineArgs = [t.arrayExpression([t.literal("exports")].concat(names))];
var defineArgs = [t.literal("exports")];
if (this.passModuleArg) defineArgs.push(t.literal("module"));
defineArgs = defineArgs.concat(names);
defineArgs = [t.arrayExpression(defineArgs)];
// typeof exports !== "undefined" && typeof module !== "undefined"
var testExports = t.binaryExpression("!==", t.unaryExpression("typeof", t.identifier("exports"), true), t.literal("undefined")),
testModule = t.binaryExpression("!==", t.unaryExpression("typeof", t.identifier("module"), true), t.literal("undefined")),
commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
var commonArgs = [t.identifier("exports")];
if (this.passModuleArg) commonArgs.push(t.identifier("module"));
commonArgs = commonArgs.concat(names.map(function (name) {
return t.callExpression(t.identifier("require"), [name]);
}));
var moduleName = this.getModuleName();
if (moduleName) defineArgs.unshift(t.literal(moduleName));
var runner = util.template("umd-runner-body", {
AMD_ARGUMENTS: defineArgs,
COMMON_ARGUMENTS: names.map(function (name) {
return t.callExpression(t.identifier("require"), [name]);
})
COMMON_TEST: commonTests,
COMMON_ARGUMENTS: commonArgs
});
//

View File

@@ -1,3 +1,3 @@
for (var KEY = START; KEY < ARGUMENTS.length; KEY++) {
ARRAY[$__0] = ARGUMENTS[KEY];
ARRAY[ARRAY_KEY] = ARGUMENTS[KEY];
}

View File

@@ -1,7 +1,7 @@
(function (factory) {
if (typeof define === "function" && define.amd) {
define(AMD_ARGUMENTS, factory);
} else if (typeof exports !== "undefined") {
factory(exports, COMMON_ARGUMENTS);
} else if (COMMON_TEST) {
factory(COMMON_ARGUMENTS);
}
});

View File

@@ -39,8 +39,6 @@ transform.moduleFormatters = {
};
_.each({
// spec
specBlockHoistFunctions: require("./transformers/spec-block-hoist-functions"),
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
// playground

View File

@@ -12,6 +12,14 @@ exports.Function = function (node, parent, file) {
var argsId = t.identifier("arguments");
argsId._ignoreAliasFunctions = true;
var start = t.literal(node.params.length);
var key = file.generateUidIdentifier("key");
var arrKey = key;
if (node.params.length) {
arrKey = t.binaryExpression("-", arrKey, start);
}
node.body.body.unshift(
t.variableDeclaration("var", [
t.variableDeclarator(rest, t.arrayExpression([]))
@@ -19,9 +27,10 @@ exports.Function = function (node, parent, file) {
util.template("rest", {
ARGUMENTS: argsId,
START: t.literal(node.params.length),
ARRAY_KEY: arrKey,
START: start,
ARRAY: rest,
KEY: file.generateUidIdentifier("key")
KEY: key
})
);
};

View File

@@ -36,8 +36,13 @@ exports.XJSAttribute = {
}
};
var isTag = function(tagName) {
return (/^[a-z]|\-/).test(tagName);
};
exports.XJSOpeningElement = {
exit: function (node) {
exit: function (node, parent, file) {
var reactCompat = file.opts.reactCompat;
var tagExpr = node.name;
var args = [];
@@ -48,10 +53,12 @@ exports.XJSOpeningElement = {
tagName = tagExpr.value;
}
if (tagName && (/[a-z]/.exec(tagName[0]) || tagName.indexOf("-") >= 0)) {
args.push(t.literal(tagName));
} else {
args.push(tagExpr);
if (!reactCompat) {
if (tagName && isTag(tagName)) {
args.push(t.literal(tagName));
} else {
args.push(tagExpr);
}
}
var props = node.attributes;
@@ -96,8 +103,30 @@ exports.XJSOpeningElement = {
args.push(props);
tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
return t.callExpression(tagExpr, args);
if (reactCompat) {
if (tagName && isTag(tagName)) {
return t.callExpression(
t.memberExpression(
t.memberExpression(
t.identifier('React'),
t.identifier('DOM'),
false
),
tagExpr,
t.isLiteral(tagExpr)
),
args
);
} else {
return t.callExpression(
tagExpr,
args
);
}
} else {
tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
return t.callExpression(tagExpr, args);
}
}
};

View File

@@ -1,18 +0,0 @@
var t = require("../../types");
exports.BlockStatement = function (node, parent) {
if (t.isFunction(parent)) return;
node.body = node.body.map(function (node) {
if (t.isFunction(node)) {
node.type = "FunctionExpression";
var declar = t.variableDeclaration("let", [
t.variableDeclarator(node.id, node)
]);
declar._blockHoist = true;
return declar;
} else {
return node;
}
});
};

View File

@@ -1,5 +1,4 @@
var esutils = require("esutils");
var t = require("../../types");
var t = require("../../types");
exports.MemberExpression = function (node) {
var prop = node.property;
@@ -7,7 +6,7 @@ exports.MemberExpression = function (node) {
// computed literal that is a valid identifier
node.property = t.identifier(prop.value);
node.computed = false;
} else if (!node.computed && t.isIdentifier(prop) && esutils.keyword.isKeywordES6(prop.name, true)) {
} else if (!node.computed && t.isIdentifier(prop) && !t.isValidIdentifier(prop.name)) {
node.property = t.literal(prop.name);
node.computed = true;
}

View File

@@ -1,5 +1,4 @@
var esutils = require("esutils");
var t = require("../../types");
var t = require("../../types");
exports.Property = function (node) {
var key = node.key;
@@ -7,7 +6,7 @@ exports.Property = function (node) {
// property key is a literal but a valid identifier
node.key = t.identifier(key.value);
node.computed = false;
} else if (!node.computed && t.isIdentifier(key) && esutils.keyword.isKeywordES6(key.name, true)) {
} else if (!node.computed && t.isIdentifier(key) && !t.isValidIdentifier(key.name)) {
// property key is a keyword
node.key = t.literal(key.name);
}

View File

@@ -355,16 +355,24 @@ t.getIds = function (node, map, ignoreTypes) {
if (!id) continue;
if (_.contains(ignoreTypes, id.type)) continue;
var nodeKey = t.getIds.nodes[id.type];
var nodeKeys = t.getIds.nodes[id.type];
var arrKeys = t.getIds.arrays[id.type];
var i, key;
if (t.isIdentifier(id)) {
ids[id.name] = id;
} else if (nodeKey) {
if (id[nodeKey]) search.push(id[nodeKey]);
} else if (nodeKeys) {
for (i in nodeKeys) {
key = nodeKeys[i];
if (id[key]) {
search.push(id[key]);
break;
}
}
} else if (arrKeys) {
for (var i in arrKeys) {
var key = arrKeys[i];
for (i in arrKeys) {
key = arrKeys[i];
search = search.concat(id[key] || []);
}
}
@@ -375,15 +383,16 @@ t.getIds = function (node, map, ignoreTypes) {
};
t.getIds.nodes = {
AssignmentExpression: "left",
ImportSpecifier: "name",
ExportSpecifier: "name",
VariableDeclarator: "id",
FunctionDeclaration: "id",
ClassDeclaration: "id",
MemeberExpression: "object",
SpreadElement: "argument",
Property: "value"
AssignmentExpression: ["left"],
ImportBatchSpecifier: ["name"],
ImportSpecifier: ["name", "id"],
ExportSpecifier: ["name", "id"],
VariableDeclarator: ["id"],
FunctionDeclaration: ["id"],
ClassDeclaration: ["id"],
MemeberExpression: ["object"],
SpreadElement: ["argument"],
Property: ["value"]
};
t.getIds.arrays = {

View File

@@ -146,10 +146,10 @@ exports.template = function (name, nodes, keepExpression) {
var node = template.body[0];
if (!keepExpression && t.isExpressionStatement(node)) {
node = node.expression;
return node.expression;
} else {
return node;
}
return node;
};
exports.codeFrame = function (lines, lineNumber, colNumber) {

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.6.0",
"version": "2.7.2",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -43,7 +43,7 @@
"ast-types": "~0.6.1",
"chokidar": "0.11.1",
"commander": "2.5.0",
"core-js": "^0.4.0",
"core-js": "^0.4.1",
"estraverse": "1.8.0",
"esutils": "1.1.6",
"esvalid": "^1.1.0",

View File

@@ -1,17 +1,17 @@
define(["exports"], function (exports) {
define(["exports", "module"], function (exports, module) {
"use strict";
exports["default"] = foo;
exports["default"] = 42;
exports["default"] = {};
exports["default"] = [];
exports["default"] = foo;
exports["default"] = function () {};
module.exports = foo;
module.exports = 42;
module.exports = {};
module.exports = [];
module.exports = foo;
module.exports = function () {};
exports["default"] = function () {};
module.exports = function () {};
function foo() {}
var Foo = function Foo() {};
exports["default"] = Foo;
});
module.exports = Foo;
});

View File

@@ -1,10 +1,6 @@
define(["exports", "foo"], function (exports, _foo) {
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var _interopRequireWildcard = function (obj) {
return obj && obj.constructor === Object ? obj : {
"default": obj
@@ -21,11 +17,11 @@ define(["exports", "foo"], function (exports, _foo) {
_exportsWildcard(_interopRequireWildcard(_foo));
exports.foo = _interopRequire(_foo);
exports.foo = _interopRequire(_foo);
exports.bar = _interopRequire(_foo);
exports.bar = _interopRequire(_foo);
exports["default"] = _interopRequire(_foo);
exports["default"] = _interopRequire(_foo);
exports.bar = _interopRequire(_foo);
});
exports.foo = _foo.foo;
exports.foo = _foo.foo;
exports.bar = _foo.bar;
exports.bar = _foo.foo;
exports["default"] = _foo.foo;
exports["default"] = _foo.foo;
exports.bar = _foo.bar;
});

View File

@@ -1,2 +1,2 @@
import foo from "foo";
import {default as foo} from "foo";
import {default as foo2} from "foo";

View File

@@ -7,5 +7,5 @@ define(["exports", "foo"], function (exports, _foo) {
var foo = _interopRequire(_foo);
var foo = _interopRequire(_foo);
});
var foo2 = _interopRequire(_foo);
});

View File

@@ -1,4 +1,4 @@
import {bar} from "foo";
import {bar, baz} from "foo";
import {bar as baz} from "foo";
import {bar as baz, xyz} from "foo";
import {bar2, baz} from "foo";
import {bar as baz2} from "foo";
import {bar as baz3, xyz} from "foo";

View File

@@ -2,9 +2,9 @@ define(["exports", "foo"], function (exports, _foo) {
"use strict";
var bar = _foo.bar;
var bar = _foo.bar;
var bar2 = _foo.bar2;
var baz = _foo.baz;
var baz = _foo.bar;
var baz = _foo.bar;
var baz2 = _foo.bar;
var baz3 = _foo.bar;
var xyz = _foo.xyz;
});
});

View File

@@ -2,11 +2,11 @@ import "foo";
import "foo-bar";
import "./directory/foo-bar";
import foo from "foo";
import * as foo from "foo";
import * as foo2 from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
import {foo as bar2} from "foo";
export {test};
export var test = 5;
export var test2 = 5;
export default test;

View File

@@ -1,4 +1,4 @@
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) {
define(["exports", "module", "foo", "foo-bar", "./directory/foo-bar"], function (exports, module, _foo, _fooBar, _directoryFooBar) {
"use strict";
var _interopRequire = function (obj) {
@@ -7,11 +7,11 @@ define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports,
var foo = _interopRequire(_foo);
var foo = _foo;
var foo2 = _foo;
var bar = _foo.bar;
var bar = _foo.foo;
var bar2 = _foo.foo;
exports.test = test;
var test = exports.test = 5;
var test2 = exports.test2 = 5;
exports["default"] = test;
});
module.exports = test;
});

View File

@@ -0,0 +1,2 @@
import { foo } from "foo";
var foo;

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import { foo } from "foo";
foo.bar = 1;

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import * as foo from "foo";
foo = 1;

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import * as foo from "foo";
var foo;

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import { foo as bar } from "foo";
var bar;

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import { foo as bar } from "foo";
bar = 1;

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import { foo } from "foo";
import { foo } from "bar";

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import { foo as bar } from "foo";
import { foo as bar } from "bar";

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -0,0 +1,2 @@
import { foo } from "foo";
foo = 1;

View File

@@ -0,0 +1,3 @@
{
"throws": "Illegal assignment of module import"
}

View File

@@ -1,9 +1,5 @@
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var _interopRequireWildcard = function (obj) {
return obj && obj.constructor === Object ? obj : {
"default": obj
@@ -20,10 +16,10 @@ var _exportsWildcard = function (obj) {
_exportsWildcard(_interopRequireWildcard(require("foo")));
exports.foo = _interopRequire(require("foo"));
exports.foo = _interopRequire(require("foo"));
exports.bar = _interopRequire(require("foo"));
exports.bar = _interopRequire(require("foo"));
exports["default"] = _interopRequire(require("foo"));
exports["default"] = _interopRequire(require("foo"));
exports.bar = _interopRequire(require("foo"));
exports.foo = require("foo").foo;
exports.foo = require("foo").foo;
exports.bar = require("foo").bar;
exports.bar = require("foo").foo;
exports["default"] = require("foo").foo;
exports["default"] = require("foo").foo;
exports.bar = require("foo").bar;

View File

@@ -1,2 +1,2 @@
import foo from "foo";
import {default as foo} from "foo";
import {default as foo2} from "foo";

View File

@@ -6,4 +6,4 @@ var _interopRequire = function (obj) {
var foo = _interopRequire(require("foo"));
var foo = _interopRequire(require("foo"));
var foo2 = _interopRequire(require("foo"));

View File

@@ -1,4 +1,4 @@
import {bar} from "foo";
import {bar, baz} from "foo";
import {bar as baz} from "foo";
import {bar as baz, xyz} from "foo";
import {bar2, baz} from "foo";
import {bar as baz2} from "foo";
import {bar as baz3, xyz} from "foo";

View File

@@ -1,8 +1,8 @@
"use strict";
var bar = require("foo").bar;
var bar = require("foo").bar;
var bar2 = require("foo").bar2;
var baz = require("foo").baz;
var baz = require("foo").bar;
var baz = require("foo").bar;
var baz2 = require("foo").bar;
var baz3 = require("foo").bar;
var xyz = require("foo").xyz;

View File

@@ -2,9 +2,9 @@ import "foo";
import "foo-bar";
import "./directory/foo-bar";
import foo from "foo";
import * as foo from "foo";
import * as foo2 from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
import {foo as bar2} from "foo";
export {test};
export var test = 5;

View File

@@ -18,9 +18,9 @@ require("./directory/foo-bar");
var foo = _interopRequire(require("foo"));
var foo = _interopRequireWildcard(require("foo"));
var foo2 = _interopRequireWildcard(require("foo"));
var bar = require("foo").bar;
var bar = require("foo").foo;
var bar2 = require("foo").foo;
exports.test = test;
var test = exports.test = 5;

View File

@@ -1,2 +1,2 @@
import foo from "foo";
import {default as foo} from "foo";
import {default as foo2} from "foo";

View File

@@ -1,4 +1,4 @@
import {bar} from "foo";
import {bar, baz} from "foo";
import {bar as baz} from "foo";
import {bar as baz, xyz} from "foo";
import {bar2, baz} from "foo";
import {bar as baz2} from "foo";
import {bar as baz3, xyz} from "foo";

View File

@@ -2,11 +2,11 @@ import "foo";
import "foo-bar";
import "./directory/foo-bar";
import foo from "foo";
import * as foo from "foo";
import * as foo2 from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
import {foo as bar2} from "foo";
export {test};
export var test = 5;
export var test2 = 5;
export default test;

View File

@@ -1,3 +1,3 @@
"use strict";
var test = 5;
var test2 = 5;

View File

@@ -1,2 +1,2 @@
import foo from "foo";
import {default as foo} from "foo";
import {default as foo2} from "foo";

View File

@@ -1,12 +1,12 @@
System.register(["foo"], function (_export) {
"use strict";
var foo, foo;
var foo, foo2;
return {
setters: [function (_foo) {
foo = _foo["default"];
foo = _foo["default"];
foo2 = _foo["default"];
}],
execute: function () {}
};
});
});

View File

@@ -1,4 +1,4 @@
import {bar} from "foo";
import {bar, baz} from "foo";
import {bar as baz} from "foo";
import {bar as baz, xyz} from "foo";
import {bar2, baz} from "foo";
import {bar as baz2} from "foo";
import {bar as baz3, xyz} from "foo";

View File

@@ -1,16 +1,16 @@
System.register(["foo"], function (_export) {
"use strict";
var bar, bar, baz, baz, baz, xyz;
var bar, bar2, baz, baz2, baz3, xyz;
return {
setters: [function (_foo) {
bar = _foo.bar;
bar = _foo.bar;
bar2 = _foo.bar2;
baz = _foo.baz;
baz = _foo.bar;
baz = _foo.bar;
baz2 = _foo.bar;
baz3 = _foo.bar;
xyz = _foo.xyz;
}],
execute: function () {}
};
});
});

View File

@@ -2,11 +2,11 @@ import "foo";
import "foo-bar";
import "./directory/foo-bar";
import foo from "foo";
import * as foo from "foo";
import * as foo2 from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
import {foo as bar2} from "foo";
export {test};
export var test = 5;
export var test2 = 5;
export default test;

View File

@@ -1,19 +1,19 @@
System.register(["foo", "foo-bar", "./directory/foo-bar"], function (_export) {
"use strict";
var foo, foo, bar, bar, test;
var foo, foo2, bar, bar2, test2;
return {
setters: [function (_foo) {
foo = _foo["default"];
foo = _foo;
foo2 = _foo;
bar = _foo.bar;
bar = _foo.foo;
bar2 = _foo.foo;
}, function (_fooBar) {}, function (_directoryFooBar) {}],
execute: function () {
_export("test", test);
test = _export("test", 5);
test2 = _export("test2", 5);
_export("default", test);
}
};
});
});

View File

@@ -1,23 +1,23 @@
(function (factory) {
if (typeof define === "function" && define.amd) {
define(["exports"], factory);
} else if (typeof exports !== "undefined") {
factory(exports);
define(["exports", "module"], factory);
} else if (typeof exports !== "undefined" && typeof module !== "undefined") {
factory(exports, module);
}
})(function (exports) {
})(function (exports, module) {
"use strict";
exports["default"] = foo;
exports["default"] = 42;
exports["default"] = {};
exports["default"] = [];
exports["default"] = foo;
exports["default"] = function () {};
module.exports = foo;
module.exports = 42;
module.exports = {};
module.exports = [];
module.exports = foo;
module.exports = function () {};
exports["default"] = function () {};
module.exports = function () {};
function foo() {}
var Foo = function Foo() {};
exports["default"] = Foo;
});
module.exports = Foo;
});

View File

@@ -7,10 +7,6 @@
})(function (exports, _foo) {
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var _interopRequireWildcard = function (obj) {
return obj && obj.constructor === Object ? obj : {
"default": obj
@@ -27,11 +23,11 @@
_exportsWildcard(_interopRequireWildcard(_foo));
exports.foo = _interopRequire(_foo);
exports.foo = _interopRequire(_foo);
exports.bar = _interopRequire(_foo);
exports.bar = _interopRequire(_foo);
exports["default"] = _interopRequire(_foo);
exports["default"] = _interopRequire(_foo);
exports.bar = _interopRequire(_foo);
});
exports.foo = _foo.foo;
exports.foo = _foo.foo;
exports.bar = _foo.bar;
exports.bar = _foo.foo;
exports["default"] = _foo.foo;
exports["default"] = _foo.foo;
exports.bar = _foo.bar;
});

View File

@@ -1,2 +1,2 @@
import foo from "foo";
import {default as foo} from "foo";
import {default as foo2} from "foo";

View File

@@ -13,5 +13,5 @@
var foo = _interopRequire(_foo);
var foo = _interopRequire(_foo);
});
var foo2 = _interopRequire(_foo);
});

View File

@@ -1,4 +1,4 @@
import {bar} from "foo";
import {bar, baz} from "foo";
import {bar as baz} from "foo";
import {bar as baz, xyz} from "foo";
import {bar2, baz} from "foo";
import {bar as baz2} from "foo";
import {bar as baz3, xyz} from "foo";

View File

@@ -8,9 +8,9 @@
"use strict";
var bar = _foo.bar;
var bar = _foo.bar;
var bar2 = _foo.bar2;
var baz = _foo.baz;
var baz = _foo.bar;
var baz = _foo.bar;
var baz2 = _foo.bar;
var baz3 = _foo.bar;
var xyz = _foo.xyz;
});
});

View File

@@ -2,11 +2,11 @@ import "foo";
import "foo-bar";
import "./directory/foo-bar";
import foo from "foo";
import * as foo from "foo";
import * as foo2 from "foo";
import {bar} from "foo";
import {foo as bar} from "foo";
import {foo as bar2} from "foo";
export {test};
export var test = 5;
export var test2 = 5;
export default test;

View File

@@ -1,10 +1,10 @@
(function (factory) {
if (typeof define === "function" && define.amd) {
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], factory);
} else if (typeof exports !== "undefined") {
factory(exports, require("foo"), require("foo-bar"), require("./directory/foo-bar"));
define(["exports", "module", "foo", "foo-bar", "./directory/foo-bar"], factory);
} else if (typeof exports !== "undefined" && typeof module !== "undefined") {
factory(exports, module, require("foo"), require("foo-bar"), require("./directory/foo-bar"));
}
})(function (exports, _foo, _fooBar, _directoryFooBar) {
})(function (exports, module, _foo, _fooBar, _directoryFooBar) {
"use strict";
var _interopRequire = function (obj) {
@@ -13,11 +13,11 @@
var foo = _interopRequire(_foo);
var foo = _foo;
var foo2 = _foo;
var bar = _foo.bar;
var bar = _foo.foo;
var bar2 = _foo.foo;
exports.test = test;
var test = exports.test = 5;
var test2 = exports.test2 = 5;
exports["default"] = test;
});
module.exports = test;
});

View File

@@ -4,6 +4,6 @@ var concat = function () {
var arrs = [];
for (var _key = 0; _key < arguments.length; _key++) {
arrs[$__0] = arguments[_key];
arrs[_key] = arguments[_key];
}
};

View File

@@ -4,7 +4,7 @@ var t = function (f) {
var items = [];
for (var _key = 1; _key < arguments.length; _key++) {
items[$__0] = arguments[_key];
items[_key - 1] = arguments[_key];
}
};
@@ -12,6 +12,6 @@ function t(f) {
var items = [];
for (var _key2 = 1; _key2 < arguments.length; _key2++) {
items[$__0] = arguments[_key2];
items[_key2 - 1] = arguments[_key2];
}
}

View File

@@ -4,7 +4,7 @@ var t = function () {
var items = [];
for (var _key = 0; _key < arguments.length; _key++) {
items[$__0] = arguments[_key];
items[_key] = arguments[_key];
}
};
@@ -12,6 +12,6 @@ function t() {
var items = [];
for (var _key2 = 0; _key2 < arguments.length; _key2++) {
items[$__0] = arguments[_key2];
items[_key2] = arguments[_key2];
}
}

View File

@@ -0,0 +1,3 @@
var x = <Component foo="bar">
<Namespace.Component />
</Component>

View File

@@ -0,0 +1,3 @@
var x = Component({
foo: "bar"
}, Namespace.Component(null));

View File

@@ -0,0 +1,3 @@
{
"reactCompat": true
}

View File

@@ -0,0 +1 @@
var x = <div foo="bar"><font-face></font-face></div>;

View File

@@ -0,0 +1,3 @@
var x = React.DOM.div({
foo: "bar"
}, React.DOM["font-face"](null));

View File

@@ -0,0 +1,3 @@
{
"reactCompat": true
}

View File

@@ -1,5 +0,0 @@
function f() { return 1; }
{
function f() { return 2; }
}
assert.equal(f(), 1);

Some files were not shown because too many files have changed in this diff Show More