Compare commits
108 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54f8889a30 | ||
|
|
bab159bc08 | ||
|
|
23950963e5 | ||
|
|
d1daac5550 | ||
|
|
d93ece5ccf | ||
|
|
c8c667bf16 | ||
|
|
49cdacbcb4 | ||
|
|
f97bd584f7 | ||
|
|
f1328aa82f | ||
|
|
e298a5d350 | ||
|
|
89a6ef0b26 | ||
|
|
c7ac9b7815 | ||
|
|
55c99b9122 | ||
|
|
545c8c3adb | ||
|
|
d093dc8231 | ||
|
|
eaf9d58b8d | ||
|
|
6131cea5b2 | ||
|
|
ca4831febe | ||
|
|
9cf8d05a19 | ||
|
|
2a4f03330b | ||
|
|
83bc614bad | ||
|
|
99ccb4111a | ||
|
|
f6c72e9ae9 | ||
|
|
a90730d4bf | ||
|
|
29503d2d37 | ||
|
|
35451ed408 | ||
|
|
7167aeb65a | ||
|
|
29d0489443 | ||
|
|
82aa2686f9 | ||
|
|
24616fa08a | ||
|
|
9f3e1eabfd | ||
|
|
286d2f84bd | ||
|
|
7fc484d82e | ||
|
|
ad6ab57fe3 | ||
|
|
348fe045d3 | ||
|
|
980b20316b | ||
|
|
5b52e507ca | ||
|
|
9853c9d78d | ||
|
|
72ec771725 | ||
|
|
75e97d9f7e | ||
|
|
295faf185c | ||
|
|
54b05f33f2 | ||
|
|
1985146760 | ||
|
|
13a52dd300 | ||
|
|
9d4bea70e6 | ||
|
|
421906bcc1 | ||
|
|
508b3531e5 | ||
|
|
c67c407cd0 | ||
|
|
aa552fea0d | ||
|
|
9bbf109dc8 | ||
|
|
393d52088a | ||
|
|
5783973734 | ||
|
|
55e01afd0d | ||
|
|
1231dc6cef | ||
|
|
b08f2061b5 | ||
|
|
1536d3de91 | ||
|
|
fddacb1612 | ||
|
|
9d1ff2b71b | ||
|
|
1c8d24f78c | ||
|
|
b619e843a9 | ||
|
|
e6a71c5849 | ||
|
|
682668c219 | ||
|
|
dd64297838 | ||
|
|
944a9d3908 | ||
|
|
d6922c9b75 | ||
|
|
fb0fcc7138 | ||
|
|
89148e6029 | ||
|
|
28d10b8eb4 | ||
|
|
3509990563 | ||
|
|
c5960fb9f7 | ||
|
|
07131576cf | ||
|
|
e75e778300 | ||
|
|
f6cb14c975 | ||
|
|
af1912ab7a | ||
|
|
8c478f29bc | ||
|
|
5b4d6d7ba9 | ||
|
|
1776b072b0 | ||
|
|
726fad1b6c | ||
|
|
23c16b0094 | ||
|
|
24f70ee4d0 | ||
|
|
fe9b0afd95 | ||
|
|
47695a8710 | ||
|
|
e1c7584280 | ||
|
|
3e63e6cd4b | ||
|
|
ba643680e5 | ||
|
|
611137c7d7 | ||
|
|
6240e5111f | ||
|
|
324a4a1b22 | ||
|
|
035f667a8f | ||
|
|
98985dd253 | ||
|
|
0a207903ce | ||
|
|
90437d262b | ||
|
|
4aba7ec192 | ||
|
|
a924c9c218 | ||
|
|
a2ed0ea9c5 | ||
|
|
c5cd729c3d | ||
|
|
b065d43a6d | ||
|
|
281003c7bd | ||
|
|
6650336c64 | ||
|
|
f904734695 | ||
|
|
0528560d81 | ||
|
|
4362ba93de | ||
|
|
ca12e87370 | ||
|
|
ebaa735adc | ||
|
|
62e406a6fe | ||
|
|
0d45a8975c | ||
|
|
8f64fe2332 | ||
|
|
a8a7587c1f |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ test/tmp
|
||||
/runtime.js
|
||||
coverage
|
||||
dist
|
||||
.package.json
|
||||
|
||||
@@ -9,3 +9,4 @@ Makefile
|
||||
dist
|
||||
tests.json
|
||||
CHANGELOG.md
|
||||
.package.json
|
||||
|
||||
72
CHANGELOG.md
72
CHANGELOG.md
@@ -11,6 +11,78 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 2.10.1
|
||||
|
||||
* **Internal**
|
||||
* Upgrade `core-js` to `0.4.4`.
|
||||
* **New Feature**
|
||||
* Added `--include-regenerator` option to CLI and `includeRegenerator` option to API that includes the regenerator runtime if necessary.
|
||||
|
||||
## 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**
|
||||
|
||||
18
Makefile
18
Makefile
@@ -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:
|
||||
|
||||
6
NOTES.md
6
NOTES.md
@@ -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.
|
||||
|
||||
@@ -15,14 +15,17 @@ 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.option("-E, --include-regenerator", "Include the regenerator runtime if necessary", false);
|
||||
|
||||
commander.on("--help", function(){
|
||||
var outKeys = function (title, obj) {
|
||||
@@ -98,17 +101,24 @@ if (errors.length) {
|
||||
//
|
||||
|
||||
exports.opts = {
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules
|
||||
includeRegenerator: commander.includeRegenerator,
|
||||
sourceMapName: commander.outFile,
|
||||
experimental: commander.experimental,
|
||||
reactCompat: commander.reactCompat,
|
||||
playground: commander.playground,
|
||||
moduleIds: commander.amdModuleIds || commander.moduleIds,
|
||||
blacklist: commander.blacklist,
|
||||
whitelist: commander.whitelist,
|
||||
sourceMap: commander.sourceMaps || commander.sourceMapsInline,
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules,
|
||||
format: {
|
||||
indent: {
|
||||
style: util.repeat(parseInt(commander.indent))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var fn;
|
||||
|
||||
@@ -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
11
bin/generate-core-package-json
Executable 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, " "));
|
||||
@@ -35,7 +35,8 @@ File.helpers = [
|
||||
"async-to-generator",
|
||||
"interop-require-wildcard",
|
||||
"typeof",
|
||||
"exports-wildcard"
|
||||
"extends",
|
||||
"get"
|
||||
];
|
||||
|
||||
File.excludeHelpersFromRuntime = [
|
||||
@@ -47,21 +48,22 @@ File.normaliseOptions = function (opts) {
|
||||
opts = _.cloneDeep(opts || {});
|
||||
|
||||
_.defaults(opts, {
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
optional: [],
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
code: true,
|
||||
ast: true
|
||||
includeRegenerator: false,
|
||||
experimental: false,
|
||||
reactCompat: false,
|
||||
playground: false,
|
||||
whitespace: true,
|
||||
moduleIds: opts.amdModuleIds || false,
|
||||
blacklist: [],
|
||||
whitelist: [],
|
||||
sourceMap: false,
|
||||
optional: [],
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
runtime: false,
|
||||
code: true,
|
||||
ast: true
|
||||
});
|
||||
|
||||
// normalise windows path separators to unix
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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(")");
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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" });
|
||||
|
||||
@@ -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--;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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])
|
||||
]));
|
||||
};
|
||||
|
||||
12
lib/6to5/transformation/modules/_strict.js
Normal file
12
lib/6to5/transformation/modules/_strict.js
Normal 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;
|
||||
};
|
||||
1
lib/6to5/transformation/modules/amd-strict.js
Normal file
1
lib/6to5/transformation/modules/amd-strict.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("./_strict")(require("./amd"));
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
1
lib/6to5/transformation/modules/common-strict.js
Normal file
1
lib/6to5/transformation/modules/common-strict.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("./_strict")(require("./common"));
|
||||
@@ -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);
|
||||
|
||||
1
lib/6to5/transformation/modules/umd-strict.js
Normal file
1
lib/6to5/transformation/modules/umd-strict.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("./_strict")(require("./umd"));
|
||||
@@ -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"));
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
(function () {
|
||||
if (SUPER_NAME != null) {
|
||||
SUPER_NAME.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
module.exports = Object.assign(exports["default"], exports);
|
||||
module.exports = EXTENDS_HELPER(exports["default"], exports);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
(function (obj) {
|
||||
for (var i in obj) {
|
||||
if (exports[i] !== undefined) {
|
||||
exports[i] = obj[i];
|
||||
}
|
||||
}
|
||||
})
|
||||
9
lib/6to5/transformation/templates/extends.js
Normal file
9
lib/6to5/transformation/templates/extends.js
Normal 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;
|
||||
})
|
||||
13
lib/6to5/transformation/templates/for-of-fast.js
Normal file
13
lib/6to5/transformation/templates/for-of-fast.js
Normal 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;
|
||||
}
|
||||
}
|
||||
23
lib/6to5/transformation/templates/get.js
Normal file
23
lib/6to5/transformation/templates/get.js
Normal 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);
|
||||
}
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
(function (KEY) {
|
||||
CONTENT;
|
||||
return KEY;
|
||||
})(OBJECT);
|
||||
@@ -1 +0,0 @@
|
||||
Object.defineProperties(OBJECT, PROPS);
|
||||
1
lib/6to5/transformation/templates/test-exports.js
Normal file
1
lib/6to5/transformation/templates/test-exports.js
Normal file
@@ -0,0 +1 @@
|
||||
typeof exports !== "undefined"
|
||||
1
lib/6to5/transformation/templates/test-module.js
Normal file
1
lib/6to5/transformation/templates/test-module.js
Normal file
@@ -0,0 +1 @@
|
||||
typeof module !== "undefined"
|
||||
@@ -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"),
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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, [
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
var regenerator = require("regenerator");
|
||||
|
||||
exports.ast = {
|
||||
before: require("regenerator").transform
|
||||
before: function (ast, file) {
|
||||
regenerator.transform(ast, {
|
||||
includeRuntime: file.opts.includeRegenerator && "if used"
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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)]
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
@@ -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)
|
||||
|
||||
37
lib/6to5/transformation/transformers/optional-for-of-fast.js
Normal file
37
lib/6to5/transformation/transformers/optional-for-of-fast.js
Normal 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;
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
26
lib/6to5/transformation/transformers/react.js
vendored
26
lib/6to5/transformation/transformers/react.js
vendored
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
6
lib/6to5/transformation/transformers/spec-setters.js
Normal file
6
lib/6to5/transformation/transformers/spec-setters.js
Normal 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");
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"],
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.7.2",
|
||||
"version": "2.10.1",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -39,11 +39,11 @@
|
||||
"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",
|
||||
"core-js": "^0.4.1",
|
||||
"core-js": "^0.4.4",
|
||||
"estraverse": "1.8.0",
|
||||
"esutils": "1.1.6",
|
||||
"esvalid": "^1.1.0",
|
||||
|
||||
@@ -12,7 +12,7 @@ suite("browserify", function() {
|
||||
assert.ok(bundle.length, "bundle output code");
|
||||
|
||||
// ensure that the code runs without throwing an exception
|
||||
vm.runInNewContext(bundle, {});
|
||||
vm.runInNewContext("var global = this;\n" + bundle, {});
|
||||
done();
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
if (!process.env.ALL_6TO5_TESTS) return;
|
||||
|
||||
require("./_transformation-helper")({
|
||||
name: "esnext"
|
||||
});
|
||||
|
||||
@@ -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'; }
|
||||
|
||||
|
||||
@@ -7,4 +7,5 @@ var test = {
|
||||
* Inside bracket init
|
||||
*/
|
||||
"b"]: "2"
|
||||
}, ok = 42;
|
||||
},
|
||||
ok = 42;
|
||||
|
||||
@@ -3,6 +3,7 @@ function test() {
|
||||
// Leading to VariableDeclarator
|
||||
// Leading to VariableDeclarator
|
||||
i = 20,
|
||||
|
||||
// Leading to VariableDeclarator
|
||||
// Leading to VariableDeclarator
|
||||
j = 20;
|
||||
|
||||
@@ -5,6 +5,7 @@ function test() {
|
||||
* Leading to VariableDeclarator
|
||||
*/
|
||||
i = 20,
|
||||
|
||||
/*
|
||||
* Leading to VariableDeclarator
|
||||
* Leading to VariableDeclarator
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
++i;
|
||||
i++;
|
||||
(foo++).test();
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
++i;
|
||||
i++;
|
||||
(foo++).test();
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -3,7 +3,6 @@ class Test extends Foo {
|
||||
woops.super.test();
|
||||
super();
|
||||
super.test();
|
||||
foob(super);
|
||||
|
||||
super(...arguments);
|
||||
super("test", ...arguments);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
5
test/fixtures/transformation/es6-classes/bare-super/actual.js
vendored
Normal file
5
test/fixtures/transformation/es6-classes/bare-super/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
class Test {
|
||||
constructor() {
|
||||
console.log(super);
|
||||
}
|
||||
}
|
||||
3
test/fixtures/transformation/es6-classes/bare-super/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-classes/bare-super/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "illegal use of bare super"
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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;
|
||||
})();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
var { x, y } = coords, foo = "bar";
|
||||
var { x, y } = coords,
|
||||
foo = "bar";
|
||||
|
||||
8
test/fixtures/transformation/es6-modules-amd-strict/exports-default/actual.js
vendored
Normal file
8
test/fixtures/transformation/es6-modules-amd-strict/exports-default/actual.js
vendored
Normal 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 {}
|
||||
17
test/fixtures/transformation/es6-modules-amd-strict/exports-default/expected.js
vendored
Normal file
17
test/fixtures/transformation/es6-modules-amd-strict/exports-default/expected.js
vendored
Normal 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;
|
||||
});
|
||||
0
test/fixtures/transformation/es6-modules-amd-strict/exports-default/untitled
vendored
Normal file
0
test/fixtures/transformation/es6-modules-amd-strict/exports-default/untitled
vendored
Normal file
6
test/fixtures/transformation/es6-modules-amd-strict/exports-from/actual.js
vendored
Normal file
6
test/fixtures/transformation/es6-modules-amd-strict/exports-from/actual.js
vendored
Normal 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";
|
||||
29
test/fixtures/transformation/es6-modules-amd-strict/exports-from/expected.js
vendored
Normal file
29
test/fixtures/transformation/es6-modules-amd-strict/exports-from/expected.js
vendored
Normal 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;
|
||||
});
|
||||
5
test/fixtures/transformation/es6-modules-amd-strict/exports-named/actual.js
vendored
Normal file
5
test/fixtures/transformation/es6-modules-amd-strict/exports-named/actual.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export {foo};
|
||||
export {foo, bar};
|
||||
export {foo as bar};
|
||||
export {foo as default};
|
||||
export {foo as default, bar};
|
||||
11
test/fixtures/transformation/es6-modules-amd-strict/exports-named/expected.js
vendored
Normal file
11
test/fixtures/transformation/es6-modules-amd-strict/exports-named/expected.js
vendored
Normal 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;
|
||||
});
|
||||
9
test/fixtures/transformation/es6-modules-amd-strict/exports-variable/actual.js
vendored
Normal file
9
test/fixtures/transformation/es6-modules-amd-strict/exports-variable/actual.js
vendored
Normal 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 {}
|
||||
17
test/fixtures/transformation/es6-modules-amd-strict/exports-variable/expected.js
vendored
Normal file
17
test/fixtures/transformation/es6-modules-amd-strict/exports-variable/expected.js
vendored
Normal 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;
|
||||
});
|
||||
11
test/fixtures/transformation/es6-modules-amd-strict/hoist-function-exports/actual.js
vendored
Normal file
11
test/fixtures/transformation/es6-modules-amd-strict/hoist-function-exports/actual.js
vendored
Normal 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);
|
||||
15
test/fixtures/transformation/es6-modules-amd-strict/hoist-function-exports/expected.js
vendored
Normal file
15
test/fixtures/transformation/es6-modules-amd-strict/hoist-function-exports/expected.js
vendored
Normal 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);
|
||||
});
|
||||
2
test/fixtures/transformation/es6-modules-amd-strict/imports-default/actual.js
vendored
Normal file
2
test/fixtures/transformation/es6-modules-amd-strict/imports-default/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import foo from "foo";
|
||||
import {default as foo2} from "foo";
|
||||
11
test/fixtures/transformation/es6-modules-amd-strict/imports-default/expected.js
vendored
Normal file
11
test/fixtures/transformation/es6-modules-amd-strict/imports-default/expected.js
vendored
Normal 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);
|
||||
});
|
||||
1
test/fixtures/transformation/es6-modules-amd-strict/imports-glob/actual.js
vendored
Normal file
1
test/fixtures/transformation/es6-modules-amd-strict/imports-glob/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import * as foo from "foo";
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user