Compare commits

..

100 Commits

Author SHA1 Message Date
Sebastian McKenzie
f1328aa82f v2.10.0 2015-01-12 11:52:32 +11:00
Sebastian McKenzie
e298a5d350 remove unused check function 2015-01-12 11:50:45 +11:00
Sebastian McKenzie
89a6ef0b26 add 2.10.0 changelog 2015-01-12 11:50:19 +11:00
Sebastian McKenzie
c7ac9b7815 rename --reactCompat arg to --react-compat 2015-01-12 11:47:04 +11:00
Sebastian McKenzie
55c99b9122 upgrade acorn-6to5 2015-01-12 11:45:21 +11:00
Sebastian McKenzie
545c8c3adb define class methods instead of assigning them - fixes #454 2015-01-12 11:44:23 +11:00
Sebastian McKenzie
d093dc8231 disallow setters without one parameter - fixes #455 2015-01-12 10:25:37 +11:00
Sebastian McKenzie
eaf9d58b8d Merge branch 'master' of github.com:6to5/6to5 2015-01-12 10:19:53 +11:00
Sebastian McKenzie
6131cea5b2 add classesFastSuper optional transformer - fixes #451 2015-01-12 10:19:22 +11:00
Sebastian McKenzie
ca4831febe Merge pull request #453 from amasad/master
Add --reactCompat option to cli
2015-01-12 09:57:21 +11:00
Amjad Masad
9cf8d05a19 Add --reactCompat option to cli 2015-01-11 12:47:17 -05:00
Sebastian McKenzie
2a4f03330b better bin name for 6to5-node 2015-01-11 22:59:36 +11:00
Sebastian McKenzie
83bc614bad add note about splitting up super transforming #411 2015-01-11 22:42:45 +11:00
Sebastian McKenzie
99ccb4111a start adding support for this mapping for supers 2015-01-11 22:15:56 +11:00
Sebastian McKenzie
f6c72e9ae9 add newline to scope 2015-01-11 22:15:56 +11:00
Sebastian McKenzie
a90730d4bf Merge pull request #449 from monsanto/fix-6to5-node-name
fix _6to5-node name in help screen
2015-01-11 18:19:04 +11:00
Christopher Monsanto
29503d2d37 fix _6to5-node name in help screen 2015-01-10 23:04:13 -05:00
Sebastian McKenzie
35451ed408 Merge pull request #447 from fkling/cli
Fix short --whitelist option
2015-01-11 11:21:41 +11:00
Felix Kling
7167aeb65a Fix short --whitelist option
`6to5 -w generators` doesn't work because `-w` is also short for
`--watch`. This changes the short option for `--whitelist` to `-l`.
2015-01-10 11:03:26 -08:00
Sebastian McKenzie
29d0489443 add autoindentation note 2015-01-11 04:55:34 +11:00
Sebastian McKenzie
82aa2686f9 fix writable being set on accessors 2015-01-11 04:55:27 +11:00
Sebastian McKenzie
24616fa08a fix linting errors 2015-01-11 03:35:37 +11:00
Sebastian McKenzie
9f3e1eabfd simplify define properties 2015-01-11 03:21:05 +11:00
Sebastian McKenzie
286d2f84bd add configurable and writable property to defined properties 2015-01-11 02:43:17 +11:00
Sebastian McKenzie
7fc484d82e add ES5 getter/setter split up note - closes #444 2015-01-11 02:30:11 +11:00
Sebastian McKenzie
ad6ab57fe3 only use raw type references in coreAliasing on Symbol - fixes #421 2015-01-11 01:00:04 +11:00
Sebastian McKenzie
348fe045d3 reformat for of transformers and add pattern support 2015-01-11 00:35:41 +11:00
Sebastian McKenzie
980b20316b Merge pull request #441 from monsanto/fast-for-of
Optional for-of transformer that puts arrays in fast path
2015-01-11 00:32:56 +11:00
Sebastian McKenzie
5b52e507ca fix non-identifier class super tests 2015-01-10 22:55:19 +11:00
Sebastian McKenzie
9853c9d78d add empty statement case to toBlock 2015-01-10 22:42:35 +11:00
Sebastian McKenzie
72ec771725 fix unnecessarily shifting super ref 2015-01-10 22:42:20 +11:00
Sebastian McKenzie
75e97d9f7e format scope default declarations better 2015-01-10 22:34:08 +11:00
Sebastian McKenzie
295faf185c remove unnecessary ensureBlock in let scoping transformer #434 2015-01-10 22:33:57 +11:00
Sebastian McKenzie
54b05f33f2 move super reference into closure 2015-01-10 22:26:51 +11:00
Sebastian McKenzie
1985146760 use Array.isArray instead of _.isArray 2015-01-10 22:26:37 +11:00
Sebastian McKenzie
13a52dd300 always use an IIFE for classes - fixes #435 2015-01-10 22:18:30 +11:00
Sebastian McKenzie
9d4bea70e6 Merge pull request #433 from gaearon/perf-traverse-refactor
Refactor traversal to avoid closures for perf
2015-01-10 22:06:08 +11:00
Dan Abramov
421906bcc1 Refactor traversal to avoid closures 2015-01-10 14:02:08 +03:00
Sebastian McKenzie
508b3531e5 Merge pull request #432 from gaearon/perf-stable
Replace _.each and for-in with for loop in hot paths
2015-01-10 21:49:37 +11:00
Sebastian McKenzie
c67c407cd0 v2.9.4 2015-01-10 16:28:02 +11:00
Sebastian McKenzie
aa552fea0d add 2.9.4 changelog 2015-01-10 16:25:39 +11:00
Sebastian McKenzie
9bbf109dc8 support UpdateExpressions as MemberExpression objects - fixes #440 2015-01-10 16:24:17 +11:00
Christopher Monsanto
393d52088a optional for-of transformer that puts arrays in fast path 2015-01-09 20:53:48 -05:00
Dan Abramov
5783973734 A few minor perf improvements 2015-01-09 22:00:07 +03:00
Dan Abramov
55e01afd0d Improve performance on hot paths by using for loops 2015-01-09 16:51:34 +03:00
Dan Abramov
1231dc6cef Replace _.each and for-in with for loop in hot paths 2015-01-09 16:00:53 +03:00
Sebastian McKenzie
b08f2061b5 fix destructuring tests 2015-01-09 21:43:24 +11:00
Sebastian McKenzie
1536d3de91 Revert "add base optional object observe transformer"
This reverts commit b619e843a9.
2015-01-09 21:18:55 +11:00
Sebastian McKenzie
fddacb1612 don't assign array expressions to a temp variable in destructuring #431 2015-01-09 21:18:51 +11:00
Sebastian McKenzie
9d1ff2b71b v2.9.3 2015-01-09 20:10:17 +11:00
Sebastian McKenzie
1c8d24f78c remove exportsWildcard helper in favor of defaults #430 2015-01-09 20:08:05 +11:00
Sebastian McKenzie
b619e843a9 add base optional object observe transformer 2015-01-09 19:57:21 +11:00
Sebastian McKenzie
e6a71c5849 move npm version up 2015-01-09 19:56:22 +11:00
Sebastian McKenzie
682668c219 v2.9.2 2015-01-09 19:51:44 +11:00
Sebastian McKenzie
dd64297838 add 2.9.2 changelog 2015-01-09 19:49:10 +11:00
Sebastian McKenzie
944a9d3908 pass exports to exportsWildcard - fixes #430 2015-01-09 19:48:11 +11:00
Sebastian McKenzie
d6922c9b75 v2.9.1 2015-01-09 19:34:28 +11:00
Sebastian McKenzie
fb0fcc7138 fix runtime generator breaking the helper inclusion loop - fixes #429 2015-01-09 19:31:43 +11:00
Sebastian McKenzie
89148e6029 Merge pull request #424 from 6to5/more-super-issues
Ensure more than one level of superclass works.
2015-01-09 08:35:40 +11:00
Brian Donovan
28d10b8eb4 Ensure more than one level of superclass works. 2015-01-08 13:33:02 -08:00
Sebastian McKenzie
3509990563 enable esnext tests by default 2015-01-09 07:23:17 +11:00
Sebastian McKenzie
c5960fb9f7 Merge pull request #408 from 6to5/fix-esnext-class-tests
[WIP] Fix super with getters and setters and with class prototypes changing.
2015-01-09 07:22:35 +11:00
Brian Donovan
07131576cf Use undefined instead of void 0. 2015-01-08 11:59:01 -08:00
Sebastian McKenzie
e75e778300 v2.9.0 2015-01-09 06:02:43 +11:00
Sebastian McKenzie
f6cb14c975 upgrade acorn-6to5 2015-01-09 06:00:19 +11:00
Brian Donovan
af1912ab7a Ensure constructors use the current super class.
This is an extension of 324a4a1b22.
2015-01-08 09:31:18 -08:00
Brian Donovan
8c478f29bc Use desc.writable instead of "writable" in desc as suggested by @stefanpenner. 2015-01-08 09:21:35 -08:00
Brian Donovan
5b4d6d7ba9 Replace superIdentifier with superProperty.
This also disallows the usage of bare `super` that is not part of a
member expression, call expression, or new expression.
2015-01-08 09:21:32 -08:00
Sebastian McKenzie
1776b072b0 v2.8.2 2015-01-09 00:08:42 +11:00
Sebastian McKenzie
726fad1b6c move publish-core into publish task 2015-01-09 00:06:21 +11:00
Sebastian McKenzie
23c16b0094 fix github url in no templates directory 2015-01-09 00:06:12 +11:00
Sebastian McKenzie
24f70ee4d0 add alternate core package - fixes #387 2015-01-08 23:31:03 +11:00
Sebastian McKenzie
fe9b0afd95 v2.8.1 2015-01-08 23:14:56 +11:00
Sebastian McKenzie
47695a8710 add 2.8.1 changelog 2015-01-08 23:12:36 +11:00
Sebastian McKenzie
e1c7584280 fix computed accessors on objects 2015-01-08 23:11:58 +11:00
Sebastian McKenzie
3e63e6cd4b v2.8.0 2015-01-08 22:49:23 +11:00
Sebastian McKenzie
ba643680e5 add 2.8.0 changelog 2015-01-08 22:46:16 +11:00
Sebastian McKenzie
611137c7d7 add umd strict and amd strict module formatter, also fix bug with wrong amd module constructor - fixes #415 2015-01-08 22:44:51 +11:00
Sebastian McKenzie
6240e5111f add modules common strict formatter - fixes #418 2015-01-08 22:29:24 +11:00
Brian Donovan
324a4a1b22 Fix super with getters and setters and with class prototypes changing. 2015-01-07 21:10:36 -08:00
Sebastian McKenzie
035f667a8f update notes with additional 3.0.0 breaking change and add a reference to the export default issue 2015-01-08 13:09:59 +11:00
Sebastian McKenzie
98985dd253 Merge pull request #416 from monsanto/indent
Add --indent option to change indent width
2015-01-08 12:43:41 +11:00
Christopher Monsanto
0a207903ce Add --indent option to change indent width 2015-01-07 18:27:58 -05:00
Sebastian McKenzie
90437d262b v2.7.4 2015-01-08 01:02:39 +11:00
Sebastian McKenzie
4aba7ec192 fix generation tests and add variable kind length 2015-01-08 01:00:32 +11:00
Sebastian McKenzie
a924c9c218 fix up declarations being split up and use a new algorithm to determine whether or not we should align them 2015-01-08 00:54:01 +11:00
Sebastian McKenzie
a2ed0ea9c5 only align variable declarations if at least one declarator has an init 2015-01-08 00:44:53 +11:00
Sebastian McKenzie
c5cd729c3d add 2.7.4 changelog 2015-01-08 00:40:43 +11:00
Sebastian McKenzie
b065d43a6d add custom level to buffer getIndent 2015-01-08 00:37:46 +11:00
Sebastian McKenzie
281003c7bd properly align multi declarator var declarations - fixes #413 2015-01-08 00:37:32 +11:00
Sebastian McKenzie
6650336c64 inherit assign from declaration in destructuring - fixes #413 2015-01-08 00:37:07 +11:00
Sebastian McKenzie
f904734695 rename prettyPrint to the more descriptive prettyCall 2015-01-08 00:36:40 +11:00
Sebastian McKenzie
0528560d81 v2.7.3 2015-01-07 22:55:09 +11:00
Sebastian McKenzie
4362ba93de fix verison number in changelog 2015-01-07 22:53:02 +11:00
Sebastian McKenzie
ca12e87370 remove unused variables 2015-01-07 22:50:24 +11:00
Sebastian McKenzie
ebaa735adc add 2.7.2 changelog 2015-01-07 22:49:21 +11:00
Sebastian McKenzie
62e406a6fe fix better jsx output 2015-01-07 22:47:37 +11:00
Sebastian McKenzie
0d45a8975c normalise module name paths 2015-01-07 22:43:05 +11:00
Sebastian McKenzie
8f64fe2332 add extends helper instead of using Object.assign 2015-01-07 22:42:26 +11:00
Sebastian McKenzie
a8a7587c1f better jsx output #369 2015-01-07 22:42:03 +11:00
245 changed files with 2465 additions and 645 deletions

1
.gitignore vendored
View File

@@ -10,3 +10,4 @@ test/tmp
/runtime.js
coverage
dist
.package.json

View File

@@ -9,3 +9,4 @@ Makefile
dist
tests.json
CHANGELOG.md
.package.json

View File

@@ -11,6 +11,71 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 2.10.0
* **New Feature**
* Add `classesFastSuper` optional transformer that doesn't support parent getters and prototype changing.
* Add `forOfFast` transformer that speeds up `for...of` on arrays but produces more code.
* Add `--react-compat` to `bin/6to5`.
* **Spec Compliancy**
* Disallow setters without a single parameter.
* Add `configurable` and `writable` to defined properties.
* Use define instead of assignment for class methods.
* **Polish**
* Fix bin name in `6to5-node --help`.
* Fix shorthand `--whitelist` name in `bin/6to5`.
* **Internal**
* Hot code optimisation of traversal etc thanks to [gaearon](https://github.com/gaearon).
## 2.9.4
* **Bug Fix**
* Support `UpdateExpression`s as `MemberExpression` objects.
## 2.9.3
* **Bug Fix**
* Remove `exportsWildcard` helper in favor of `defaults`.
## 2.9.2
* **Bug Fix**
* Pass `exports` to `exportWildcard` helper to allow for use inside the optional runtime.
## 2.9.1
* **Bug Fix**
* Fix runtime generator breaking the helper inclusion loop.
## 2.9.0
* **Internal**
* Upgrade `acorn-6to5`.
* Now supports destructuring shorthand properties.
## 2.8.1
* **Bug Fix**
* Fix computed accessors on object literals.
## 2.8.0
* **New Feature**
* Add `commonStrict`, `amdStrict` and `umdStrict` module formatters that remove `module.exports` interop assignment.
* Add `--indent` option to the 6to5 CLI.
## 2.7.4
* **Polish**
* Inherit assignments from their declaration in destructuring.
* Properly align multi-declarator variable declarations.
## 2.7.3
* **Polish**
* Indent and add newlines to `React.createElement` calls in `react` transformer.
* Remove `Object.assign` calls and replace it with an `extends` helper.
## 2.7.1
* **New Feature**

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-simple test-all test-browser publish build bootstrap
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap publish-core
build:
mkdir -p dist
@@ -71,6 +71,9 @@ publish:
make test
read -p "Version: " version; \
npm version $$version --message "v%s"
make build
cp dist/6to5.min.js browser.js
cp dist/polyfill.min.js browser-polyfill.js
@@ -79,12 +82,21 @@ publish:
node bin/cache-templates
test -f templates.json
read -p "Version: " version; \
npm version $$version --message "v%s"
npm publish
git push --follow-tags
# generate
bin/generate-core-package-json >package2.json
mv package.json .package.json
mv package2.json package.json
npm publish
# restore
rm -rf package.json
mv .package.json package.json
rm -rf templates.json browser.js runtime.js browser-polyfill.js
bootstrap:

View File

@@ -1,8 +1,12 @@
# Notes
* Wildcard exports/imports wont normalise if `export default` is a non-object.
* Wildcard exports/imports wont normalise if `export default` is a non-object. See [#224](https://github.com/6to5/6to5/issues/224).
## 3.0.0 breaking changes
* Remove `allowImportExportEverywhere` option from acorn.
* Remove this shorthand from playground.
* Remove `super()` inside non-constructors - add descriptive error message.
* Split up ES5 getter/setter transforming and ES6 property methods into separate transformers.
* Add autoindentation.
* Move `super` transformation from classes into a separate transformer that also supports object expressions.

View File

@@ -15,14 +15,16 @@ commander.option("-e, --experimental", "Enable experimental support for proposed
commander.option("-p, --playground", "Enable playground support");
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
commander.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
commander.option("-i, --optional [list]", "List of optional transformers to enable", util.list);
commander.option("-o, --out-file [out]", "Compile all input files into a single file");
commander.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory");
commander.option("-c, --remove-comments", "Remove comments from the compiled code", false);
commander.option("-I, --indent [width]", "Indent width [2]", 2);
commander.option("-a, --amd-module-ids", "Insert module id in AMD modules", false); // todo: remove in 3.0.0
commander.option("-m, --module-ids", "Insert module id in modules", false);
commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code");
commander.on("--help", function(){
var outKeys = function (title, obj) {
@@ -108,7 +110,13 @@ exports.opts = {
optional: commander.optional,
comments: !commander.removeComments,
runtime: commander.runtime,
modules: commander.modules
modules: commander.modules,
reactCompat: commander.reactCompat,
format: {
indent: {
style: util.repeat(parseInt(commander.indent))
}
}
};
var fn;

View File

@@ -10,29 +10,31 @@ var util = require("../lib/6to5/util");
var vm = require("vm");
var _ = require("lodash");
commander.option("-e, --eval [script]", "Evaluate script");
commander.option("-p, --print", "Evaluate script and print result");
commander.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
commander.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
commander.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
commander.option("-g, --playground", "Enable playground support");
commander.option("-c, --cache", "Cache compiled files and require paths");
var program = new commander.Command("6to5-node");
program.option("-e, --eval [script]", "Evaluate script");
program.option("-p, --print", "Evaluate script and print result");
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js]");
program.option("-r, --experimental", "Enable experimental support for proposed ES7 features");
program.option("-g, --playground", "Enable playground support");
program.option("-c, --cache", "Cache compiled files and require paths");
var pkg = require("../package.json");
commander.version(pkg.version);
commander.usage("[options] [ -e script | script.js ] [arguments]");
commander.parse(process.argv);
program.version(pkg.version);
program.usage("[options] [ -e script | script.js ] [arguments]");
program.parse(process.argv);
if (commander.cache) roadrunner.load();
if (program.cache) roadrunner.load();
//
to5.register({
experimental: commander.experimental,
extensions: commander.extensions,
playground: commander.playground,
ignore: commander.ignore,
cache: commander.cache && roadrunner.get("6to5")
experimental: program.experimental,
extensions: program.extensions,
playground: program.playground,
ignore: program.ignore,
cache: program.cache && roadrunner.get("6to5")
});
//
@@ -41,17 +43,17 @@ var _eval = function (code, filename) {
code = to5.transform(code, {
filename: filename,
blacklist: ["useStrict"],
experimental: commander.experimental,
playground: commander.playground
experimental: program.experimental,
playground: program.playground
}).code;
return vm.runInThisContext(code, filename);
};
if (commander.eval) {
var result = _eval(commander.eval, "eval");
if (commander.print) console.log(result);
if (program.eval) {
var result = _eval(program.eval, "eval");
if (program.print) console.log(result);
} else {
if (commander.args.length) {
if (program.args.length) {
// slice all arguments up to the first filename since they're 6to5 args that we handle
var args = process.argv.slice(2);
@@ -77,7 +79,7 @@ if (commander.eval) {
}
}
if (commander.cache) roadrunner.save();
if (program.cache) roadrunner.save();
function replStart() {
repl.start({

11
bin/generate-core-package-json Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env node
var pkg = require("../package.json");
pkg.name += "-core";
delete pkg.dependencies.chokidar;
delete pkg.optionalDependencies;
delete pkg.devDependencies;
delete pkg.preferGlobal;
delete pkg.scripts;
delete pkg.bin;
console.log(JSON.stringify(pkg, null, " "));

View File

@@ -35,7 +35,8 @@ File.helpers = [
"async-to-generator",
"interop-require-wildcard",
"typeof",
"exports-wildcard"
"extends",
"get"
];
File.excludeHelpersFromRuntime = [

View File

@@ -61,7 +61,7 @@ Buffer.prototype.space = function () {
Buffer.prototype.removeLast = function (cha) {
if (!this.isLast(cha)) return;
this.buf = this.buf.slice(0, -1);
this.buf = this.buf.substr(0, this.buf.length - 1);
this.position.unshift(cha);
};
@@ -77,10 +77,9 @@ Buffer.prototype.newline = function (i, removeLast) {
if (this.endsWith("{\n")) i--;
if (this.endsWith(util.repeat(i, "\n"))) return;
var self = this;
_.times(i, function () {
self.newline(null, removeLast);
});
for (var j = 0; j < i; j++) {
this.newline(null, removeLast);
}
return;
}
@@ -115,13 +114,18 @@ Buffer.prototype._push = function (str) {
};
Buffer.prototype.endsWith = function (str) {
return this.buf.slice(-str.length) === str;
var d = this.buf.length - str.length;
return d >= 0 && this.buf.lastIndexOf(str) === d;
};
Buffer.prototype.isLast = function (cha, trimRight) {
var buf = this.buf;
if (trimRight) buf = util.trimRight(buf);
var last = buf[buf.length - 1];
var chars = [].concat(cha);
return _.contains(chars, _.last(buf));
if (Array.isArray(cha)) {
return _.contains(cha, last);
} else {
return cha === last;
}
};

View File

@@ -57,8 +57,28 @@ exports.ThisExpression = function () {
exports.CallExpression = function (node, print) {
print(node.callee);
this.push("(");
print.join(node.arguments, { separator: ", " });
var separator = ",";
if (node._prettyCall) {
separator += "\n";
this.newline();
this.indent();
} else {
separator += " ";
}
print.join(node.arguments, {
separator: separator
});
if (node._prettyCall) {
this.newline();
this.dedent();
}
this.push(")");
};

View File

@@ -1,4 +1,5 @@
var t = require("../../types");
var util = require("../../util");
var t = require("../../types");
exports.WithStatement = function (node, print) {
this.keyword("with");
@@ -157,7 +158,24 @@ exports.DebuggerStatement = function () {
exports.VariableDeclaration = function (node, print, parent) {
this.push(node.kind + " ");
print.join(node.declarations, { separator: ", " });
var inits = 0;
var noInits = 0;
for (var i in node.declarations) {
if (node.declarations[i].init) {
inits++;
} else {
noInits++;
}
}
var sep = ",";
if (inits > noInits) { // more inits than noinits
sep += "\n" + util.repeat(node.kind.length + 1);
} else {
sep += " ";
}
print.join(node.declarations, { separator: sep });
if (!t.isFor(parent)) {
this.semicolon();

View File

@@ -6,14 +6,19 @@ var t = require("../../types");
var _ = require("lodash");
var find = function (obj, node, parent) {
if (!obj) return;
var result;
_.each(obj, function (fn, type) {
var types = Object.keys(obj);
for (var i = 0; i < types.length; i++) {
var type = types[i];
if (t["is" + type](node)) {
var fn = obj[type];
result = fn(node, parent);
if (result != null) return false;
if (result != null) break;
}
});
}
return result;
};
@@ -99,7 +104,13 @@ _.each(Node.prototype, function (fn, key) {
Node[key] = function (node, parent) {
var n = new Node(node, parent);
var args = _.toArray(arguments).slice(2);
// Avoid leaking arguments to prevent deoptimization
var skipCount = 2;
var args = new Array(arguments.length - skipCount);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i + 2];
}
return n[key].apply(n, args);
};
});

View File

@@ -21,6 +21,13 @@ _.each([
});
});
exports.UpdateExpression = function (node, parent) {
if (t.isMemberExpression(parent) && parent.object === node) {
// (foo++).test()
return true;
}
};
exports.ObjectExpression = function (node, parent) {
if (t.isExpressionStatement(parent)) {
// ({ foo: "bar" });

View File

@@ -1,33 +1,27 @@
module.exports = Position;
var _ = require("lodash");
function Position() {
this.line = 1;
this.column = 0;
}
Position.prototype.push = function (str) {
var self = this;
_.each(str, function (cha) {
if (cha === "\n") {
self.line++;
self.column = 0;
for (var i = 0; i < str.length; i++) {
if (str[i] === "\n") {
this.line++;
this.column = 0;
} else {
self.column++;
this.column++;
}
});
}
};
Position.prototype.unshift = function (str) {
var self = this;
_.each(str, function (cha) {
if (cha === "\n") {
self.line--;
for (var i = 0; i < str.length; i++) {
if (str[i] === "\n") {
this.line--;
} else {
self.column--;
this.column--;
}
});
}
};

View File

@@ -11,15 +11,18 @@ Whitespace.prototype.getNewlinesBefore = function (node) {
var startToken;
var endToken;
var tokens = this.tokens;
var token;
for (var i = 0; i < tokens.length; i++) {
token = tokens[i];
_.each(tokens, function (token, i) {
// this is the token this node starts with
if (node.start === token.start) {
startToken = tokens[i - 1];
endToken = token;
return false;
break;
}
});
}
return this.getNewlinesBetween(startToken, endToken);
};
@@ -28,15 +31,18 @@ Whitespace.prototype.getNewlinesAfter = function (node) {
var startToken;
var endToken;
var tokens = this.tokens;
var token;
for (var i = 0; i < tokens.length; i++) {
token = tokens[i];
_.each(tokens, function (token, i) {
// this is the token this node ends with
if (node.end === token.end) {
startToken = token;
endToken = tokens[i + 1];
return false;
break;
}
});
}
if (endToken.type.type === "eof") {
return 1;

View File

@@ -20,7 +20,7 @@ module.exports = function (namespace) {
_.each(File.helpers, function (name) {
if (_.contains(File.excludeHelpersFromRuntime, name)) {
return false;
return;
}
var key = t.identifier(t.toIdentifier(name));

View File

@@ -161,6 +161,9 @@ DefaultFormatter.prototype.getModuleName = function () {
moduleName += filenameRelative;
// normalise path separators
moduleName = moduleName.replace(/\\/g, "/");
return moduleName;
};
@@ -214,7 +217,8 @@ DefaultFormatter.prototype._exportSpecifier = function (getRef, specifier, node,
};
DefaultFormatter.prototype._exportsWildcard = function (objectIdentifier) {
return t.expressionStatement(t.callExpression(this.file.addHelper("exports-wildcard"), [
return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [
t.identifier("exports"),
t.callExpression(this.file.addHelper("interop-require-wildcard"), [objectIdentifier])
]));
};

View File

@@ -0,0 +1,12 @@
var util = require("../../util");
module.exports = function (Parent) {
var Constructor = function () {
this.noInteropExport = true;
Parent.apply(this, arguments);
};
util.inherits(Constructor, Parent);
return Constructor;
};

View File

@@ -0,0 +1 @@
module.exports = require("./_strict")(require("./amd"));

View File

@@ -7,8 +7,8 @@ var t = require("../../types");
var _ = require("lodash");
function AMDFormatter() {
DefaultFormatter.apply(this, arguments);
this.ids = {};
CommonFormatter.apply(this, arguments);
this.ids = {};
}
util.inherits(AMDFormatter, DefaultFormatter);
@@ -101,7 +101,7 @@ AMDFormatter.prototype.importSpecifier = function (specifier, node, nodes) {
};
AMDFormatter.prototype.exportDeclaration = function (node) {
if (node.default) {
if (node.default && !this.noInteropExport) {
this.passModuleArg = true;
}

View File

@@ -0,0 +1 @@
module.exports = require("./_strict")(require("./common"));

View File

@@ -61,7 +61,7 @@ CommonJSFormatter.prototype.importDeclaration = function (node, nodes) {
};
CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
if (node.default && !this.exportIdentifier) {
if (node.default && !this.noInteropRequire && !this.noInteropExport) {
var declar = node.declaration;
var assign;
@@ -83,10 +83,12 @@ CommonJSFormatter.prototype.exportDeclaration = function (node, nodes) {
// this export isn't a function so we can't hoist it to the top so we need to set it
// at the very end of the file with something like:
//
// module.exports = Object.assign(exports["default"], exports)
// module.exports = _extends(exports["default"], exports)
//
assign = util.template("common-export-default-assign", true);
assign = util.template("common-export-default-assign", {
EXTENDS_HELPER: this.file.addHelper("extends")
}, true);
assign._blockHoist = 0;
nodes.push(assign);

View File

@@ -0,0 +1 @@
module.exports = require("./_strict")(require("./umd"));

View File

@@ -38,10 +38,9 @@ UMDFormatter.prototype.transform = function (ast) {
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 testExports = util.template("test-exports");
var testModule = util.template("test-module");
var commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
var commonArgs = [t.identifier("exports")];
if (this.passModuleArg) commonArgs.push(t.identifier("module"));

View File

@@ -0,0 +1,5 @@
(function () {
if (SUPER_NAME != null) {
SUPER_NAME.apply(this, arguments);
}
});

View File

@@ -1,3 +1,3 @@
if (SUPER_NAME !== null) {
SUPER_NAME.apply(this, arguments);
if (Object.getPrototypeOf(CLASS_NAME) !== null) {
Object.getPrototypeOf(CLASS_NAME).apply(this, arguments);
}

View File

@@ -1 +1 @@
module.exports = Object.assign(exports["default"], exports);
module.exports = EXTENDS_HELPER(exports["default"], exports);

View File

@@ -1,7 +0,0 @@
(function (obj) {
for (var i in obj) {
if (exports[i] !== undefined) {
exports[i] = obj[i];
}
}
})

View File

@@ -0,0 +1,9 @@
(function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
target[key] = source[key];
}
}
return target;
})

View File

@@ -0,0 +1,13 @@
for (var LOOP_OBJECT = OBJECT,
IS_ARRAY = Array.isArray(LOOP_OBJECT),
INDEX = 0,
LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {
if (IS_ARRAY) {
if (INDEX >= LOOP_OBJECT.length) break;
ID = LOOP_OBJECT[INDEX++];
} else {
INDEX = LOOP_OBJECT.next();
if (INDEX.done) break;
ID = INDEX.value;
}
}

View File

@@ -0,0 +1,23 @@
(function get(object, property, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc && desc.writable) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
});

View File

@@ -1,5 +0,0 @@
(function (KEY) {
CONTENT;
return KEY;
})(OBJECT);

View File

@@ -1 +0,0 @@
Object.defineProperties(OBJECT, PROPS);

View File

@@ -0,0 +1 @@
typeof exports !== "undefined"

View File

@@ -0,0 +1 @@
typeof module !== "undefined"

View File

@@ -31,15 +31,19 @@ transform._ensureTransformerNames = function (type, keys) {
transform.transformers = {};
transform.moduleFormatters = {
common: require("./modules/common"),
system: require("./modules/system"),
ignore: require("./modules/ignore"),
amd: require("./modules/amd"),
umd: require("./modules/umd")
commonStrict: require("./modules/common-strict"),
umdStrict: require("./modules/umd-strict"),
amdStrict: require("./modules/amd-strict"),
common: require("./modules/common"),
system: require("./modules/system"),
ignore: require("./modules/ignore"),
amd: require("./modules/amd"),
umd: require("./modules/umd")
};
_.each({
specNoForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
specSetters: require("./transformers/spec-setters"),
// playground
methodBinding: require("./transformers/playground-method-binding"),
@@ -55,17 +59,18 @@ _.each({
arrayComprehension: require("./transformers/es7-array-comprehension"),
generatorComprehension: require("./transformers/es7-generator-comprehension"),
arrowFunctions: require("./transformers/es6-arrow-functions"),
classesFastSuper: require("./transformers/optional-classes-fast-super"),
classes: require("./transformers/es6-classes"),
computedPropertyNames: require("./transformers/es6-computed-property-names"),
objectSpread: require("./transformers/es7-object-spread"),
exponentiationOperator: require("./transformers/es7-exponentiation-operator"),
spread: require("./transformers/es6-spread"),
templateLiterals: require("./transformers/es6-template-literals"),
propertyMethodAssignment: require("./transformers/es6-property-method-assignment"),
computedPropertyNames: require("./transformers/es6-computed-property-names"),
destructuring: require("./transformers/es6-destructuring"),
defaultParameters: require("./transformers/es6-default-parameters"),
forOfFast: require("./transformers/optional-for-of-fast"),
forOf: require("./transformers/es6-for-of"),
unicodeRegex: require("./transformers/es6-unicode-regex"),
abstractReferences: require("./transformers/es7-abstract-references"),

View File

@@ -3,36 +3,11 @@ var util = require("../../util");
var t = require("../../types");
exports.ClassDeclaration = function (node, parent, file, scope) {
var closure = true;
if (t.isProgram(parent) || t.isBlockStatement(parent)) {
closure = false;
}
var factory = new Class(node, file, scope, closure);
var newNode = factory.run();
if (factory.closure) {
if (closure) {
// declaration in an expression context...
// export default class Foo {}
scope.push({
kind: "var",
key: node.id.key,
id: node.id
});
return t.assignmentExpression("=", node.id, newNode);
} else {
// has a super class or PrivateDeclaration etc
return t.variableDeclaration("let", [
t.variableDeclarator(node.id, newNode)
]);
}
} else {
return newNode;
}
return new Class(node, file, scope, true).run();
};
exports.ClassExpression = function (node, parent, file, scope) {
return new Class(node, file, scope, true).run();
return new Class(node, file, scope, false).run();
};
/**
@@ -44,11 +19,11 @@ exports.ClassExpression = function (node, parent, file, scope) {
* @param {Boolean} closure
*/
function Class(node, file, scope, closure) {
this.closure = closure;
this.scope = scope;
this.node = node;
this.file = file;
function Class(node, file, scope, isStatement) {
this.isStatement = isStatement;
this.scope = scope;
this.node = node;
this.file = file;
this.hasInstanceMutators = false;
this.hasStaticMutators = false;
@@ -83,17 +58,20 @@ Class.prototype.run = function () {
t.variableDeclarator(className, constructor)
]));
var closureArgs = [];
var closureParams = [];
//
if (superName) {
this.closure = true;
closureArgs.push(superName);
// so we're only evaluating it once
var superRef = this.scope.generateUidBasedOnNode(superName, this.file);
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(superRef, superName)
]));
superName = superRef;
if (!t.isIdentifier(superName)) {
var superRef = this.scope.generateUidBasedOnNode(superName, this.file);
superName = superRef;
}
closureParams.push(superName);
this.superName = superName;
body.push(t.expressionStatement(t.callExpression(file.addHelper("inherits"), [className, superName])));
@@ -103,19 +81,25 @@ Class.prototype.run = function () {
t.inheritsComments(body[0], this.node);
if (this.closure) {
if (body.length === 1) {
// only a constructor so no need for a closure container
return constructor;
} else {
body.push(t.returnStatement(className));
return t.callExpression(
t.functionExpression(null, [], t.blockStatement(body)),
[]
);
}
var init;
if (body.length === 1) {
// only a constructor so no need for a closure container
init = constructor;
} else {
return body;
body.push(t.returnStatement(className));
init = t.callExpression(
t.functionExpression(null, closureParams, t.blockStatement(body)),
closureArgs
);
}
if (this.isStatement) {
return t.variableDeclaration("let", [
t.variableDeclarator(className, init)
]);
} else {
return init;
}
};
@@ -149,7 +133,7 @@ Class.prototype.buildBody = function () {
if (!this.hasConstructor && superName && !t.isFalsyExpression(superName)) {
constructor.body.body.push(util.template("class-super-constructor-call", {
SUPER_NAME: superName
CLASS_NAME: className
}, true));
}
@@ -157,15 +141,11 @@ Class.prototype.buildBody = function () {
var staticProps;
if (this.hasInstanceMutators) {
var protoId = util.template("prototype-identifier", {
CLASS_NAME: className
});
instanceProps = util.buildDefineProperties(this.instanceMutatorMap, protoId);
instanceProps = util.buildDefineProperties(this.instanceMutatorMap);
}
if (this.hasStaticMutators) {
staticProps = util.buildDefineProperties(this.staticMutatorMap, className);
staticProps = util.buildDefineProperties(this.staticMutatorMap);
}
if (instanceProps || staticProps) {
@@ -190,70 +170,49 @@ Class.prototype.pushMethod = function (node) {
var methodName = node.key;
var kind = node.kind;
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
if (kind === "") {
// method
var className = this.className;
if (!node.static) className = t.memberExpression(className, t.identifier("prototype"));
methodName = t.memberExpression(className, methodName, node.computed);
var expr = t.expressionStatement(t.assignmentExpression("=", methodName, node.value));
t.inheritsComments(expr, node);
this.body.push(expr);
} else {
// mutator
var mutatorMap = this.instanceMutatorMap;
if (node.static) {
this.hasStaticMutators = true;
mutatorMap = this.staticMutatorMap;
} else {
this.hasInstanceMutators = true;
}
util.pushMutatorMap(mutatorMap, methodName, kind, node);
kind = "value";
}
util.pushMutatorMap(mutatorMap, methodName, kind, node.computed, node);
};
/**
* Given a `methodNode`, produce a `MemberExpression` super class reference.
* Gets a node representing the super class value of the named property.
*
* @param {Node} methodNode MethodDefinition
* @param {Node} node Identifier
* @param {Node} parent
* @example
*
* _get(Object.getPrototypeOf(CLASS.prototype), "METHOD", this)
*
* @param {Node} property
* @param {boolean} isStatic
* @param {boolean} isComputed
*
* @returns {Node}
*/
Class.prototype.superIdentifier = function (methodNode, id, parent) {
var methodName = methodNode.key;
var superName = this.superName || t.identifier("Function");
if (parent.property === id) {
return;
} else if (t.isCallExpression(parent, { callee: id })) {
// super(); -> ClassName.prototype.MethodName.call(this);
parent.arguments.unshift(t.thisExpression());
if (methodName.name === "constructor") {
// constructor() { super(); }
return t.memberExpression(superName, t.identifier("call"));
} else {
id = superName;
// foo() { super(); }
if (!methodNode.static) {
id = t.memberExpression(id, t.identifier("prototype"));
}
id = t.memberExpression(id, methodName, methodNode.computed);
return t.memberExpression(id, t.identifier("call"));
}
} else if (t.isMemberExpression(parent) && !methodNode.static) {
// super.test -> ClassName.prototype.test
return t.memberExpression(superName, t.identifier("prototype"));
} else {
return superName;
}
Class.prototype.superProperty = function (property, isStatic, isComputed, thisExpression) {
return t.callExpression(
this.file.addHelper("get"),
[
t.callExpression(
t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")),
[
isStatic ? this.className : t.memberExpression(this.className, t.identifier("prototype"))
]
),
isComputed ? property : t.literal(property.name),
thisExpression
]
);
};
/**
@@ -264,20 +223,53 @@ Class.prototype.superIdentifier = function (methodNode, id, parent) {
Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
var method = methodNode.value;
var self = this;
var self = this;
traverse(method, {
enter: function (node, parent) {
var property;
var computed;
var args;
if (t.isIdentifier(node, { name: "super" })) {
return self.superIdentifier(methodNode, node, parent);
if (!(t.isMemberExpression(parent) && !parent.computed && parent.property === node)) {
throw self.file.errorWithNode(node, "illegal use of bare super");
}
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
if (t.isIdentifier(callee, { name: "super" })) {
// super(); -> _get(Object.getPrototypeOf(ClassName), "MethodName", this).call(this);
property = methodNode.key;
computed = methodNode.computed;
args = node.arguments;
} else {
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
// super.test(); -> ClassName.prototype.MethodName.call(this);
t.appendToMemberExpression(callee, t.identifier("call"));
node.arguments.unshift(t.thisExpression());
// super.test(); -> _get(Object.getPrototypeOf(ClassName.prototype), "test", this).call(this);
property = callee.property;
computed = callee.computed;
args = node.arguments;
}
} else if (t.isMemberExpression(node)) {
if (!t.isIdentifier(node.object, { name: "super" })) return;
// super.name; -> _get(Object.getPrototypeOf(ClassName.prototype), "name", this);
property = node.property;
computed = node.computed;
}
if (property) {
var thisExpression = t.thisExpression();
var superProperty = self.superProperty(property, methodNode.static, computed, thisExpression);
if (args) {
return t.callExpression(
t.memberExpression(superProperty, t.identifier("call"), false),
[thisExpression].concat(args)
);
} else {
return superProperty;
}
}
}
});
@@ -290,7 +282,7 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
*/
Class.prototype.pushConstructor = function (method) {
if (method.kind !== "") {
if (method.kind) {
throw this.file.errorWithNode(method, "illegal kind for constructor method");
}

View File

@@ -7,7 +7,7 @@ exports.ObjectExpression = function (node, parent, file, scope) {
var i;
for (i in node.properties) {
hasComputed = t.isProperty(node.properties[i], { computed: true });
hasComputed = t.isProperty(node.properties[i], { computed: true, kind: "init" });
if (hasComputed) break;
}
@@ -25,6 +25,8 @@ exports.ObjectExpression = function (node, parent, file, scope) {
for (i in props) {
prop = props[i];
if (prop.kind !== "init") continue;
key = prop.key;
if (!prop.computed && t.isIdentifier(key)) {
@@ -44,7 +46,7 @@ exports.ObjectExpression = function (node, parent, file, scope) {
broken = true;
}
if (!broken || t.isLiteral(t.toComputedKey(prop, prop.key), { value: "__proto__" })) {
if (prop.kind !== "init" || !broken || t.isLiteral(t.toComputedKey(prop, prop.key), { value: "__proto__" })) {
initProps.push(prop);
props[i] = null;
}

View File

@@ -134,7 +134,7 @@ var pushPattern = function (opts) {
var file = opts.file;
var scope = opts.scope;
if (!t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
if (!t.isArrayExpression(parentId) && !t.isMemberExpression(parentId) && !t.isIdentifier(parentId)) {
var key = scope.generateUidBasedOnNode(parentId, file);
nodes.push(t.variableDeclaration("var", [
@@ -300,10 +300,17 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
file: file,
scope: scope
};
if (t.isPattern(pattern) && patternId) {
pushPattern(opts);
if (+i !== node.declarations.length - 1) {
// we aren't the last declarator so let's just make the
// last transformed node inherit from us
t.inherits(nodes[nodes.length - 1], declar);
}
} else {
nodes.push(buildVariableAssign(opts, declar.id, declar.init));
nodes.push(t.inherits(buildVariableAssign(opts, declar.id, declar.init), declar));
}
}

View File

@@ -8,7 +8,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
var stepKey = file.generateUidIdentifier("step", scope);
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
if (t.isIdentifier(left)) {
if (t.isIdentifier(left) || t.isPattern(left)) {
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
} else if (t.isVariableDeclaration(left)) {
declar = t.variableDeclaration(left.kind, [

View File

@@ -37,7 +37,6 @@ exports.VariableDeclaration = function (node, parent) {
exports.Loop = function (node, parent, file, scope) {
var init = node.left || node.init;
if (isLet(init, node)) {
t.ensureBlock(node);
node.body._letDeclars = [init];
}

View File

@@ -46,14 +46,14 @@ exports.Property = function (node, parent, file, scope) {
}
};
exports.ObjectExpression = function (node, parent, file, scope) {
exports.ObjectExpression = function (node) {
var mutatorMap = {};
var hasAny = false;
node.properties = node.properties.filter(function (prop) {
if (prop.kind === "get" || prop.kind === "set") {
hasAny = true;
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.value);
util.pushMutatorMap(mutatorMap, prop.key, prop.kind, prop.computed, prop.value);
return false;
} else {
return true;
@@ -62,21 +62,8 @@ exports.ObjectExpression = function (node, parent, file, scope) {
if (!hasAny) return;
if (node.properties.length) {
var objId = scope.generateUidBasedOnNode(parent, file);
return util.template("object-define-properties-closure", {
KEY: objId,
OBJECT: node,
CONTENT: util.template("object-define-properties", {
OBJECT: objId,
PROPS: util.buildDefineProperties(mutatorMap)
})
});
} else {
return util.template("object-define-properties", {
OBJECT: node,
PROPS: util.buildDefineProperties(mutatorMap)
});
}
return t.callExpression(
t.memberExpression(t.identifier("Object"), t.identifier("defineProperties")),
[node, util.buildDefineProperties(mutatorMap)]
);
};

View File

@@ -4,7 +4,7 @@ var t = require("../../types");
exports.experimental = true;
exports.ObjectExpression = function (node) {
exports.ObjectExpression = function (node, parent, file) {
var hasSpread = false;
var i;
var prop;
@@ -42,5 +42,5 @@ exports.ObjectExpression = function (node) {
args.unshift(t.objectExpression([]));
}
return t.callExpression(t.memberExpression(t.identifier("Object"), t.identifier("assign")), args);
return t.callExpression(file.addHelper("extends"), args);
};

View File

@@ -0,0 +1,74 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
exports.optional = true;
exports.Class = function (node) {
var superClass = node.superClass || t.identifier("Function");
var hasConstructor = false;
var body = node.body.body;
for (var i in body) {
var methodNode = body[i];
hasConstructor = hasConstructor || methodNode.key.name === "constructor";
traverse(methodNode, {
enter: function (node, parent) {
if (t.isIdentifier(node, { name: "super" })) {
return superIdentifier(superClass, methodNode, node, parent);
} else if (t.isCallExpression(node)) {
var callee = node.callee;
if (!t.isMemberExpression(callee)) return;
if (callee.object.name !== "super") return;
// super.test(); -> ClassName.prototype.MethodName.call(this);
t.appendToMemberExpression(callee, t.identifier("call"));
node.arguments.unshift(t.thisExpression());
}
}
});
}
if (node.superClass && !hasConstructor) {
body.unshift(t.methodDefinition(
t.identifier("constructor"),
util.template("class-super-constructor-call-fast", {
SUPER_NAME: superClass
})
));
}
};
var superIdentifier = function (superClass, methodNode, id, parent) {
var methodName = methodNode.key;
if (parent.property === id) {
return;
} else if (t.isCallExpression(parent, { callee: id })) {
// super(); -> ClassName.prototype.MethodName.call(this);
parent.arguments.unshift(t.thisExpression());
if (methodName.name === "constructor") {
// constructor() { super(); }
return t.memberExpression(superClass, t.identifier("call"));
} else {
id = superClass;
// foo() { super(); }
if (!methodNode.static) {
id = t.memberExpression(id, t.identifier("prototype"));
}
id = t.memberExpression(id, methodName, methodNode.computed);
return t.memberExpression(id, t.identifier("call"));
}
} else if (t.isMemberExpression(parent) && !methodNode.static) {
// super.test -> ClassName.prototype.test
return t.memberExpression(superClass, t.identifier("prototype"));
} else {
return superClass;
}
};

View File

@@ -31,8 +31,8 @@ exports.ast = {
this.skip();
return t.prependToMemberExpression(node, file._coreId);
}
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && coreHas(node)) {
// new Promise -> new _core.Promise
} else if (t.isIdentifier(node) && !t.isMemberExpression(parent) && t.isReferenced(node, parent) && node.name === "Symbol") {
// new Symbol -> new _core.Symbol
return t.memberExpression(file._coreId, node);
} else if (t.isCallExpression(node)) {
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)

View File

@@ -0,0 +1,37 @@
var util = require("../../util");
var t = require("../../types");
exports.optional = true;
exports.ForOfStatement = function (node, parent, file, scope) {
var left = node.left;
var declar, id;
if (t.isIdentifier(left) || t.isPattern(left)) {
id = left;
} else if (t.isVariableDeclaration(left)) {
id = left.declarations[0].id;
declar = t.variableDeclaration(left.kind, [
t.variableDeclarator(id)
]);
} else {
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
}
var node2 = util.template("for-of-fast", {
LOOP_OBJECT: file.generateUidIdentifier("loopObject", scope),
IS_ARRAY: file.generateUidIdentifier("isArray", scope),
OBJECT: node.right,
INDEX: file.generateUidIdentifier("i", scope),
ID: id
});
t.inheritsComments(node2, node);
t.ensureBlock(node);
var block = node2.body;
if (declar) block.body.unshift(declar);
block.body = block.body.concat(node.body.body);
return node2;
};

View File

@@ -1,8 +1,6 @@
var t = require("../../types");
var _ = require("lodash");
var OBJECT_ASSIGN_MEMBER = t.memberExpression(t.identifier("Object"), t.identifier("assign"));
var isProtoKey = function (node) {
return t.isLiteral(t.toComputedKey(node, node.key), { value: "__proto__" });
};
@@ -43,7 +41,7 @@ exports.ExpressionStatement = function (node, parent, file) {
}
};
exports.ObjectExpression = function (node) {
exports.ObjectExpression = function (node, parent, file) {
var proto;
for (var i in node.properties) {
@@ -58,6 +56,6 @@ exports.ObjectExpression = function (node) {
if (proto) {
var args = [t.objectExpression([]), proto];
if (node.properties.length) args.push(node);
return t.callExpression(OBJECT_ASSIGN_MEMBER, args);
return t.callExpression(file.addHelper("extends"), args);
}
};

View File

@@ -32,7 +32,7 @@ exports.XJSExpressionContainer = function (node) {
exports.XJSAttribute = {
exit: function (node) {
var value = node.value || t.literal(true);
return t.property("init", node.name, value);
return t.inherits(t.property("init", node.name, value), node);
}
};
@@ -107,26 +107,18 @@ exports.XJSOpeningElement = {
if (tagName && isTag(tagName)) {
return t.callExpression(
t.memberExpression(
t.memberExpression(
t.identifier('React'),
t.identifier('DOM'),
false
),
t.memberExpression(t.identifier("React"), t.identifier("DOM")),
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);
}
return t.callExpression(tagExpr, args);
}
};
@@ -148,16 +140,16 @@ exports.XJSElement = {
var isLastLine = +i === lines.length - 1;
// replace rendered whitespace tabs with spaces
var trimmedLine = line.replace(/\t/g, ' ');
var trimmedLine = line.replace(/\t/g, " ");
// trim whitespace touching a newline
if (!isFirstLine) {
trimmedLine = trimmedLine.replace(/^[ ]+/, '');
trimmedLine = trimmedLine.replace(/^[ ]+/, "");
}
// trim whitespace touching an endline
if (!isLastLine) {
trimmedLine = trimmedLine.replace(/[ ]+$/, '');
trimmedLine = trimmedLine.replace(/[ ]+$/, "");
}
if (trimmedLine) {
@@ -173,6 +165,10 @@ exports.XJSElement = {
callExpr.arguments.push(child);
}
if (callExpr.arguments.length >= 3) {
callExpr._prettyCall = true;
}
return t.inherits(callExpr, node);
}
};

View File

@@ -0,0 +1,6 @@
exports.MethodDefinition =
exports.Property = function (node, parent, file) {
if (node.kind === "set" && node.value.params.length !== 1) {
throw file.errorWithNode(node.value, "Setters must have only one parameter");
}
};

View File

@@ -4,15 +4,101 @@ var Scope = require("./scope");
var t = require("../types");
var _ = require("lodash");
function TraversalContext(previousContext) {
this.didSkip = false;
this.didRemove = false;
this.didStop = false;
this.didFlatten = previousContext ? previousContext.didFlatten : false;
}
TraversalContext.prototype.flatten = function () {
this.didFlatten = true;
};
TraversalContext.prototype.remove = function () {
this.didRemove = true;
this.skip();
};
TraversalContext.prototype.skip = function () {
this.didSkip = true;
};
TraversalContext.prototype.stop = function () {
this.didStop = true;
this.skip();
};
TraversalContext.prototype.maybeReplace = function (result, obj, key, node) {
if (result === false) return node;
if (result == null) return node;
var isArray = Array.isArray(result);
// inherit comments from original node to the first replacement node
var inheritTo = result;
if (isArray) inheritTo = result[0];
if (inheritTo) t.inheritsComments(inheritTo, node);
// replace the node
node = obj[key] = result;
// we're replacing a statement or block node with an array of statements so we better
// ensure that it's a block
if (isArray && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
t.ensureBlock(obj, key);
}
if (isArray) {
this.flatten();
}
return node;
};
TraversalContext.prototype.visit = function (obj, key, opts, scope, parent) {
var node = obj[key];
if (!node) return;
// type is blacklisted
if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) return;
var result;
var ourScope = scope;
if (t.isScope(node)) ourScope = new Scope(node, scope);
// enter
if (opts.enter) {
result = opts.enter.call(this, node, parent, ourScope);
node = this.maybeReplace(result, obj, key, node);
if (this.didRemove) {
obj[key] = null;
this.flatten();
}
// stop traversal
if (this.didSkip) return;
}
// traverse node
traverse(node, opts, ourScope);
// exit
if (opts.exit) {
result = opts.exit.call(this, node, parent, ourScope);
node = this.maybeReplace(result, obj, key, node);
}
};
function traverse(parent, opts, scope) {
// falsy node
if (!parent) return;
// array of nodes
if (_.isArray(parent)) {
_.each(parent, function (node) {
traverse(node, opts, scope);
});
if (Array.isArray(parent)) {
for (var i = 0; i < parent.length; i++)
traverse(parent[i], opts, scope);
return;
}
@@ -21,99 +107,21 @@ function traverse(parent, opts, scope) {
if (!keys) return;
opts = opts || {};
var context = null;
var stopped = false;
for (var i in keys) {
var key = keys[i];
for (var j = 0; j < keys.length; j++) {
var key = keys[j];
var nodes = parent[key];
if (!nodes) continue;
var flatten = false;
var handle = function (obj, key) {
var node = obj[key];
if (!node) return;
// type is blacklisted
if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) return;
// replace node
var maybeReplace = function (result) {
if (result === false) return;
if (result == null) return;
var isArray = _.isArray(result);
// inherit comments from original node to the first replacement node
var inheritTo = result;
if (isArray) inheritTo = result[0];
if (inheritTo) t.inheritsComments(inheritTo, node);
// replace the node
node = obj[key] = result;
if (isArray) flatten = true;
// we're replacing a statement or block node with an array of statements so we better
// ensure that it's a block
if (isArray && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
t.ensureBlock(obj, key);
}
};
var skipped = false;
var removed = false;
var context = {
stop: function () {
skipped = stopped = true;
},
skip: function () {
skipped = true;
},
remove: function () {
this.skip();
removed = true;
}
};
//
var ourScope = scope;
if (t.isScope(node)) ourScope = new Scope(node, scope);
// enter
if (opts.enter) {
var result = opts.enter.call(context, node, parent, ourScope);
maybeReplace(result);
if (removed) {
obj[key] = null;
flatten = true;
}
// stop iteration
if (skipped) return;
if (Array.isArray(nodes)) {
for (var k = 0; k < nodes.length; k++) {
context = new TraversalContext(context);
context.visit(nodes, k, opts, scope, parent);
if (context.didStop) return;
}
// traverse node
traverse(node, opts, ourScope);
// exit
if (opts.exit) {
maybeReplace(opts.exit.call(context, node, parent, ourScope));
}
};
if (_.isArray(nodes)) {
for (i in nodes) {
handle(nodes, i);
if (stopped) return;
}
if (flatten) {
if (context && context.didFlatten) {
parent[key] = _.flatten(parent[key]);
if (key === "body") {
@@ -122,8 +130,9 @@ function traverse(parent, opts, scope) {
}
}
} else {
handle(parent, key);
if (stopped) return;
context = new TraversalContext(context);
context.visit(parent, key, opts, scope, parent);
if (context.didStop) return;
}
}
}

View File

@@ -24,7 +24,13 @@ function Scope(block, parent) {
}
var vars = require("jshint/src/vars");
Scope.defaultDeclarations = _.flatten([vars.newEcmaIdentifiers, vars.node, vars.ecmaIdentifiers, vars.reservedVars].map(_.keys));
Scope.defaultDeclarations = _.flatten([
vars.newEcmaIdentifiers,
vars.node,
vars.ecmaIdentifiers,
vars.reservedVars
].map(_.keys));
Scope.add = function (node, references) {
if (!node) return;

View File

@@ -16,6 +16,7 @@
"Literal": ["value"],
"LogicalExpression": ["operator", "left", "right"],
"MemberExpression": ["object", "property", "computed"],
"MethodDefinition": ["key", "value", "computed", "kind"],
"NewExpression": ["callee", "arguments"],
"ObjectExpression": ["properties"],
"Program": ["body"],

View File

@@ -320,7 +320,11 @@ t.toBlock = function (node, parent) {
return node;
}
if (!_.isArray(node)) {
if (t.isEmptyStatement(node)) {
node = [];
}
if (!Array.isArray(node)) {
if (!t.isStatement(node)) {
if (t.isFunction(parent)) {
node = t.returnStatement(node);

View File

@@ -39,7 +39,7 @@ exports.list = function (val) {
exports.regexify = function (val) {
if (!val) return new RegExp(/.^/);
if (_.isArray(val)) val = val.join("|");
if (Array.isArray(val)) val = val.join("|");
if (_.isString(val)) return new RegExp(val);
if (_.isRegExp(val)) return val;
throw new TypeError("illegal type for regexify");
@@ -48,7 +48,7 @@ exports.regexify = function (val) {
exports.arrayify = function (val) {
if (!val) return [];
if (_.isString(val)) return exports.list(val);
if (_.isArray(val)) return val;
if (Array.isArray(val)) return val;
throw new TypeError("illegal type for arrayify");
};
@@ -65,12 +65,12 @@ exports.sourceMapToComment = function (map) {
return "//# sourceMappingURL=data:application/json;base64," + base64;
};
exports.pushMutatorMap = function (mutatorMap, key, kind, method) {
exports.pushMutatorMap = function (mutatorMap, key, kind, computed, method) {
var alias;
if (t.isIdentifier(key)) {
alias = key.name;
if (method.computed) alias = "computed:" + alias;
if (computed) alias = "computed:" + alias;
} else if (t.isLiteral(key)) {
alias = String(key.value);
} else {
@@ -86,7 +86,7 @@ exports.pushMutatorMap = function (mutatorMap, key, kind, method) {
mutatorMap[alias] = map;
map._key = key;
if (method.computed) {
if (computed) {
map._computed = true;
}
@@ -101,7 +101,12 @@ exports.buildDefineProperties = function (mutatorMap) {
var propNode = t.property("init", map._key, mapNode, map._computed);
if (!map.get && !map.set) {
map.writable = t.literal(true);
}
map.enumerable = t.literal(true);
map.configurable = t.literal(true);
_.each(map, function (node, key) {
if (key[0] === "_") return;
@@ -188,7 +193,13 @@ exports.codeFrame = function (lines, lineNumber, colNumber) {
exports.repeat = function (width, cha) {
cha = cha || " ";
return new Array(width + 1).join(cha);
var result = "";
for (var i = 0; i < width; i++) {
result += cha;
}
return result;
};
exports.normaliseAst = function (ast, comments, tokens) {
@@ -256,7 +267,7 @@ var loadTemplates = function () {
if (!fs.existsSync(templatesLoc)) {
throw new Error("no templates directory - this is most likely the " +
"result of a broken `npm publish`. Please report to " +
"https://githut.com/6to5/6to5/issues");
"https://github.com/6to5/6to5/issues");
}
_.each(fs.readdirSync(templatesLoc), function (name) {

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.7.2",
"version": "2.10.0",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -39,7 +39,7 @@
"test": "make test"
},
"dependencies": {
"acorn-6to5": "0.11.1-11",
"acorn-6to5": "0.11.1-13",
"ast-types": "~0.6.1",
"chokidar": "0.11.1",
"commander": "2.5.0",

View File

@@ -1,5 +1,3 @@
if (!process.env.ALL_6TO5_TESTS) return;
require("./_transformation-helper")({
name: "esnext"
});

View File

@@ -1,9 +1,11 @@
class Animal {
class Base {
get sound() {
return 'I am a ' + this.type + '.';
}
}
class Animal extends Base {}
class Cat extends Animal {
get type() { return 'cat'; }

View File

@@ -7,4 +7,5 @@ var test = {
* Inside bracket init
*/
"b"]: "2"
}, ok = 42;
},
ok = 42;

View File

@@ -3,6 +3,7 @@ function test() {
// Leading to VariableDeclarator
// Leading to VariableDeclarator
i = 20,
// Leading to VariableDeclarator
// Leading to VariableDeclarator
j = 20;

View File

@@ -5,6 +5,7 @@ function test() {
* Leading to VariableDeclarator
*/
i = 20,
/*
* Leading to VariableDeclarator
* Leading to VariableDeclarator

View File

@@ -1,5 +1,6 @@
function* foo() {
var a = yield wat(), b = 2;
var a = yield wat(),
b = 2;
var c = yield a = b;
yield a, yield b;
yield a = b;

View File

@@ -1,2 +1,3 @@
++i;
i++;
(foo++).test();

View File

@@ -1,2 +1,3 @@
++i;
i++;
(foo++).test();

View File

@@ -8,6 +8,9 @@ const foo = "foo";
let foo, bar = "bar";
var foo, bar = "bar";
let foo = "foo", bar = "bar";
var foo = "foo", bar = "bar";
const foo = "foo", bar = "bar";
let foo = "foo",
bar = "bar";
var foo = "foo",
bar = "bar";
const foo = "foo",
bar = "bar";

View File

@@ -3,7 +3,6 @@ class Test extends Foo {
woops.super.test();
super();
super.test();
foob(super);
super(...arguments);
super("test", ...arguments);

View File

@@ -1,6 +1,33 @@
"use strict";
var _slice = Array.prototype.slice;
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _get = function get(object, property, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc && desc.writable) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
@@ -16,37 +43,47 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
var _Foo$prototype$test, _Foo$prototype$test2;
var _get2, _get3, _get4, _get5;
woops["super"].test();
_Foo.call(this);
_Foo.prototype.test.call(this);
foob(_Foo);
_get(Object.getPrototypeOf(Test.prototype), "constructor", this).call(this);
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
_Foo.call.apply(_Foo, [this].concat(_slice.call(arguments)));
_Foo.call.apply(_Foo, [this, "test"].concat(_slice.call(arguments)));
(_get2 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get2, [this].concat(_slice.call(arguments)));
(_get3 = _get(Object.getPrototypeOf(Test.prototype), "constructor", this)).call.apply(_get3, [this, "test"].concat(_slice.call(arguments)));
(_Foo$prototype$test = _Foo.prototype.test).call.apply(_Foo$prototype$test, [this].concat(_slice.call(arguments)));
(_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(_slice.call(arguments)));
(_get4 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get4, [this].concat(_slice.call(arguments)));
(_get5 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get5, [this, "test"].concat(_slice.call(arguments)));
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
Test.prototype.test = function () {
var _Foo$prototype$test3, _Foo$prototype$test4;
_Foo.prototype.test.call(this);
(_Foo$prototype$test3 = _Foo.prototype.test).call.apply(_Foo$prototype$test3, [this].concat(_slice.call(arguments)));
(_Foo$prototype$test4 = _Foo.prototype.test).call.apply(_Foo$prototype$test4, [this, "test"].concat(_slice.call(arguments)));
};
Test.foo = function () {
var _Foo$foo, _Foo$foo2;
_Foo.foo.call(this);
(_Foo$foo = _Foo.foo).call.apply(_Foo$foo, [this].concat(_slice.call(arguments)));
(_Foo$foo2 = _Foo.foo).call.apply(_Foo$foo2, [this, "test"].concat(_slice.call(arguments)));
};
_prototypeProperties(Test, {
foo: {
value: function () {
var _get6, _get7;
_get(Object.getPrototypeOf(Test), "foo", this).call(this);
(_get6 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get6, [this].concat(_slice.call(arguments)));
(_get7 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get7, [this, "test"].concat(_slice.call(arguments)));
},
writable: true,
enumerable: true,
configurable: true
}
}, {
test: {
value: function () {
var _get8, _get9;
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
(_get8 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get8, [this].concat(_slice.call(arguments)));
(_get9 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get9, [this, "test"].concat(_slice.call(arguments)));
},
writable: true,
enumerable: true,
configurable: true
}
});
return Test;
})();
})(Foo);

View File

@@ -1,5 +1,27 @@
"use strict";
var _get = function get(object, property, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc && desc.writable) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
@@ -15,14 +37,13 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
_Foo.prototype.test;
_Foo.prototype.test.whatever;
_get(Object.getPrototypeOf(Test.prototype), "test", this);
_get(Object.getPrototypeOf(Test.prototype), "test", this).whatever;
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
return Test;
})();
})(Foo);

View File

@@ -0,0 +1,5 @@
class Test {
constructor() {
console.log(super);
}
}

View File

@@ -0,0 +1,3 @@
{
"throws": "illegal use of bare super"
}

View File

@@ -1,5 +1,32 @@
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _get = function get(object, property, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc && desc.writable) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var _inherits = function (child, parent) {
if (typeof parent !== "function" && parent !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof parent);
@@ -15,18 +42,24 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
_Foo.prototype.test.whatever();
_Foo.prototype.test.call(this);
_get(Object.getPrototypeOf(Test.prototype), "test", this).whatever();
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
Test.test = function () {
return _Foo.wow.call(this);
};
_prototypeProperties(Test, {
test: {
value: function () {
return _get(Object.getPrototypeOf(Test), "wow", this).call(this);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Test;
})();
})(Foo);

View File

@@ -19,13 +19,12 @@ var Test = function Test() {
this.state = "test";
};
var Foo = (function () {
var _Bar = Bar;
var Foo = (function (Bar) {
var Foo = function Foo() {
this.state = "test";
};
_inherits(Foo, _Bar);
_inherits(Foo, Bar);
return Foo;
})();
})(Bar);

View File

@@ -5,16 +5,21 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function Test() {};
var Test = (function () {
var Test = function Test() {};
_prototypeProperties(Test, null, {
test: {
get: function () {
return 5 + 5;
},
set: function (val) {
this._test = val;
},
enumerable: true
}
});
_prototypeProperties(Test, null, {
test: {
get: function () {
return 5 + 5;
},
set: function (val) {
this._test = val;
},
enumerable: true,
configurable: true
}
});
return Test;
})();

View File

@@ -5,13 +5,18 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function Test() {};
var Test = (function () {
var Test = function Test() {};
_prototypeProperties(Test, null, {
test: {
get: function () {
return 5 + 5;
},
enumerable: true
}
});
_prototypeProperties(Test, null, {
test: {
get: function () {
return 5 + 5;
},
enumerable: true,
configurable: true
}
});
return Test;
})();

View File

@@ -1,7 +1,23 @@
"use strict";
var Test = function Test() {};
Test.prototype.test = function () {
return 5 + 5;
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = (function () {
var Test = function Test() {};
_prototypeProperties(Test, null, {
test: {
value: function () {
return 5 + 5;
},
writable: true,
enumerable: true,
configurable: true
}
});
return Test;
})();

View File

@@ -5,13 +5,18 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Test = function Test() {};
var Test = (function () {
var Test = function Test() {};
_prototypeProperties(Test, null, {
test: {
set: function (val) {
this._test = val;
},
enumerable: true
}
});
_prototypeProperties(Test, null, {
test: {
set: function (val) {
this._test = val;
},
enumerable: true,
configurable: true
}
});
return Test;
})();

View File

@@ -1,5 +1,10 @@
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var BaseView = function BaseView() {
this.autoRender = true;
};
@@ -11,9 +16,16 @@ var BaseView = function () {
var BaseView = (function () {
var _class2 = function () {};
_class2.prototype.foo = function () {
this.autoRender = true;
};
_prototypeProperties(_class2, null, {
foo: {
value: function () {
this.autoRender = true;
},
writable: true,
enumerable: true,
configurable: true
}
});
return _class2;
})();

View File

@@ -5,14 +5,23 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var A = function A() {};
var A = (function () {
var A = function A() {};
A.a = function () {};
_prototypeProperties(A, {
a: {
value: function () {},
writable: true,
enumerable: true,
configurable: true
},
b: {
get: function () {},
set: function (b) {},
enumerable: true,
configurable: true
}
});
_prototypeProperties(A, {
b: {
get: function () {},
set: function (b) {},
enumerable: true
}
});
return A;
})();

View File

@@ -15,28 +15,26 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var BaseController = (function () {
var _Chaplin$Controller = Chaplin.Controller;
var BaseController = (function (_Chaplin$Controller) {
var BaseController = function BaseController() {
if (_Chaplin$Controller !== null) {
_Chaplin$Controller.apply(this, arguments);
if (Object.getPrototypeOf(BaseController) !== null) {
Object.getPrototypeOf(BaseController).apply(this, arguments);
}
};
_inherits(BaseController, _Chaplin$Controller);
return BaseController;
})();
})(Chaplin.Controller);
var BaseController2 = (function () {
var _Chaplin$Controller$Another = Chaplin.Controller.Another;
var BaseController2 = (function (_Chaplin$Controller$Another) {
var BaseController2 = function BaseController2() {
if (_Chaplin$Controller$Another !== null) {
_Chaplin$Controller$Another.apply(this, arguments);
if (Object.getPrototypeOf(BaseController2) !== null) {
Object.getPrototypeOf(BaseController2).apply(this, arguments);
}
};
_inherits(BaseController2, _Chaplin$Controller$Another);
return BaseController2;
})();
})(Chaplin.Controller.Another);

View File

@@ -15,15 +15,14 @@ var _inherits = function (child, parent) {
if (parent) child.__proto__ = parent;
};
var Test = (function () {
var _Foo = Foo;
var Test = (function (Foo) {
var Test = function Test() {
if (_Foo !== null) {
_Foo.apply(this, arguments);
if (Object.getPrototypeOf(Test) !== null) {
Object.getPrototypeOf(Test).apply(this, arguments);
}
};
_inherits(Test, _Foo);
_inherits(Test, Foo);
return Test;
})();
})(Foo);

View File

@@ -1,5 +1,28 @@
"use strict";
var Test = function Test() {
Function.prototype.hasOwnProperty.call(this, "test");
var _get = function get(object, property, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc && desc.writable) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var Test = function Test() {
_get(Object.getPrototypeOf(Test.prototype), "hasOwnProperty", this).call(this, "test");
};

View File

@@ -1,38 +1,18 @@
"use strict";
var _slicedToArray = function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else {
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
if (i && _arr.length === i) break;
}
return _arr;
}
};
var _ref = [1, 2];
var _ref2 = _slicedToArray(_ref, 2);
var a = _ref[0];
var b = _ref[1];
var _ref2 = [3, 4];
var a = _ref2[0];
var b = _ref2[1];
var _ref3 = [3, 4];
var c = _ref2[0];
var d = _ref2[1];
var _ref3 = { e: 5, f: 6 };
var _ref3 = _slicedToArray(_ref3, 2);
var e = _ref3.e;
var f = _ref3.f;
var _ref4 = { a: 7, b: 8 };
var c = _ref3[0];
var d = _ref3[1];
var _ref4 = { e: 5, f: 6 };
var e = _ref4.e;
var f = _ref4.f;
var _ref5 = { a: 7, b: 8 };
var g = _ref5.a;
var h = _ref5.b;
var g = _ref4.a;
var h = _ref4.b;

View File

@@ -18,13 +18,11 @@ var _slicedToArray = function (arr, i) {
var _ref = ["hello", [", ", "junk"], ["world"]];
var _ref2 = _slicedToArray(_ref, 4);
var a = _ref[0];
var _ref$1 = _slicedToArray(_ref[1], 1);
var a = _ref2[0];
var _ref2$1 = _slicedToArray(_ref2[1], 1);
var b = _ref$1[0];
var _ref$2 = _slicedToArray(_ref[2], 1);
var b = _ref2$1[0];
var _ref2$2 = _slicedToArray(_ref2[2], 1);
var c = _ref2$2[0];
var d = _ref2[3];
var c = _ref$2[0];
var d = _ref[3];

View File

@@ -18,13 +18,11 @@ var _slicedToArray = function (arr, i) {
var _ref = ["foo", "hello", [", ", "junk"], ["world"]];
var _ref2 = _slicedToArray(_ref, 5);
var a = _ref[1];
var _ref$2 = _slicedToArray(_ref[2], 1);
var a = _ref2[1];
var _ref2$2 = _slicedToArray(_ref2[2], 1);
var b = _ref$2[0];
var _ref$3 = _slicedToArray(_ref[3], 1);
var b = _ref2$2[0];
var _ref2$3 = _slicedToArray(_ref2[3], 1);
var c = _ref2$3[0];
var d = _ref2[4];
var c = _ref$3[0];
var d = _ref[4];

View File

@@ -1 +1,2 @@
var { x, y } = coords, foo = "bar";
var { x, y } = coords,
foo = "bar";

View File

@@ -0,0 +1,8 @@
export default 42;
export default {};
export default [];
export default foo;
export default function () {}
export default class {}
export default function foo () {}
export default class Foo {}

View File

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

View File

@@ -0,0 +1,6 @@
export * from "foo";
export {foo} from "foo";
export {foo, bar} from "foo";
export {foo as bar} from "foo";
export {foo as default} from "foo";
export {foo as default, bar} from "foo";

View File

@@ -0,0 +1,29 @@
define(["exports", "foo"], function (exports, _foo) {
"use strict";
var _interopRequireWildcard = function (obj) {
return obj && obj.constructor === Object ? obj : {
"default": obj
};
};
var _defaults = function (obj, defaults) {
for (var key in defaults) {
if (obj[key] === undefined) {
obj[key] = defaults[key];
}
}
return obj;
};
_defaults(exports, _interopRequireWildcard(_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

@@ -0,0 +1,5 @@
export {foo};
export {foo, bar};
export {foo as bar};
export {foo as default};
export {foo as default, bar};

View File

@@ -0,0 +1,11 @@
define(["exports"], function (exports) {
"use strict";
exports.foo = foo;
exports.foo = foo;
exports.bar = bar;
exports.bar = foo;
exports["default"] = foo;
exports["default"] = foo;
exports.bar = bar;
});

View File

@@ -0,0 +1,9 @@
export var foo = 1;
export var foo = 1, bar = 2;
export var foo2 = function () {};
export var foo3;
export let foo4 = 2;
export let foo5;
export const foo6 = 3;
export function foo7 () {}
export class foo8 {}

View File

@@ -0,0 +1,17 @@
define(["exports"], function (exports) {
"use strict";
exports.foo7 = foo7;
var foo = exports.foo = 1;
var foo = exports.foo = 1;
var bar = exports.bar = 2;
var foo2 = exports.foo2 = function () {};
var foo3 = exports.foo3 = undefined;
var foo4 = exports.foo4 = 2;
var foo5 = exports.foo5 = undefined;
var foo6 = exports.foo6 = 3;
function foo7() {}
var foo8 = function foo8() {};
exports.foo8 = foo8;
});

View File

@@ -0,0 +1,11 @@
import { isEven } from "./evens";
export function nextOdd(n) {
return isEven(n) ? n + 1 : n + 2;
}
export var isOdd = (function (isEven) {
return function (n) {
return !isEven(n);
};
})(isEven);

View File

@@ -0,0 +1,15 @@
define(["exports", "./evens"], function (exports, _evens) {
"use strict";
exports.nextOdd = nextOdd;
var isEven = _evens.isEven;
function nextOdd(n) {
return isEven(n) ? n + 1 : n + 2;
}
var isOdd = exports.isOdd = (function (isEven) {
return function (n) {
return !isEven(n);
};
})(isEven);
});

View File

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

View File

@@ -0,0 +1,11 @@
define(["exports", "foo"], function (exports, _foo) {
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var foo = _interopRequire(_foo);
var foo2 = _interopRequire(_foo);
});

View File

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

View File

@@ -0,0 +1,5 @@
define(["exports", "foo"], function (exports, _foo) {
"use strict";
var foo = _foo;
});

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