Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
7736fa11f2 | ||
|
|
d203924541 | ||
|
|
cd23e500a1 | ||
|
|
bf24a0d6b5 |
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
|
||||
|
||||
44
CHANGELOG.md
44
CHANGELOG.md
@@ -11,6 +11,50 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 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:
|
||||
|
||||
3
NOTES.md
3
NOTES.md
@@ -1,8 +1,9 @@
|
||||
# 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.
|
||||
|
||||
@@ -21,6 +21,7 @@ commander.option("-i, --optional [list]", "List of optional transformers to enab
|
||||
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);
|
||||
|
||||
@@ -108,7 +109,12 @@ exports.opts = {
|
||||
optional: commander.optional,
|
||||
comments: !commander.removeComments,
|
||||
runtime: commander.runtime,
|
||||
modules: commander.modules
|
||||
modules: commander.modules,
|
||||
format: {
|
||||
indent: {
|
||||
style: util.repeat(parseInt(commander.indent))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var fn;
|
||||
|
||||
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,12 +35,23 @@ File.helpers = [
|
||||
"async-to-generator",
|
||||
"interop-require-wildcard",
|
||||
"typeof",
|
||||
"exports-wildcard"
|
||||
"extends",
|
||||
"get",
|
||||
"observe-delete",
|
||||
"observe-get",
|
||||
"observe-update",
|
||||
"observe-notify",
|
||||
"observe-create"
|
||||
];
|
||||
|
||||
File.excludeHelpersFromRuntime = [
|
||||
"async-to-generator",
|
||||
"typeof"
|
||||
"typeof",
|
||||
"observe-delete",
|
||||
"observe-get",
|
||||
"observe-update",
|
||||
"observe-notify",
|
||||
"observe-create"
|
||||
];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -13,7 +13,7 @@ function DefaultFormatter(file) {
|
||||
|
||||
this.remapAssignments();
|
||||
|
||||
this.checkCollisions();
|
||||
//this.checkCollisions();
|
||||
}
|
||||
|
||||
DefaultFormatter.prototype.getLocalExports = function () {
|
||||
@@ -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"));
|
||||
|
||||
@@ -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;
|
||||
})
|
||||
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);
|
||||
}
|
||||
});
|
||||
4
lib/6to5/transformation/templates/observe-create.js
Normal file
4
lib/6to5/transformation/templates/observe-create.js
Normal file
@@ -0,0 +1,4 @@
|
||||
(function (obj, callback) {
|
||||
global._6to5Obsevers = global._6to5Obsevers || [];
|
||||
global._6to5Obsevers.push([obj, callback]);
|
||||
});
|
||||
3
lib/6to5/transformation/templates/observe-delete.js
Normal file
3
lib/6to5/transformation/templates/observe-delete.js
Normal file
@@ -0,0 +1,3 @@
|
||||
(function () {
|
||||
|
||||
})
|
||||
3
lib/6to5/transformation/templates/observe-get.js
Normal file
3
lib/6to5/transformation/templates/observe-get.js
Normal file
@@ -0,0 +1,3 @@
|
||||
(function () {
|
||||
|
||||
})
|
||||
3
lib/6to5/transformation/templates/observe-notify.js
Normal file
3
lib/6to5/transformation/templates/observe-notify.js
Normal file
@@ -0,0 +1,3 @@
|
||||
(function () {
|
||||
|
||||
})
|
||||
3
lib/6to5/transformation/templates/observe-update.js
Normal file
3
lib/6to5/transformation/templates/observe-update.js
Normal file
@@ -0,0 +1,3 @@
|
||||
(function () {
|
||||
|
||||
})
|
||||
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,14 +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"),
|
||||
|
||||
// playground
|
||||
methodBinding: require("./transformers/playground-method-binding"),
|
||||
memoizationOperator: require("./transformers/playground-memoization-operator"),
|
||||
@@ -55,13 +60,12 @@ _.each({
|
||||
arrowFunctions: require("./transformers/es6-arrow-functions"),
|
||||
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"),
|
||||
forOf: require("./transformers/es6-for-of"),
|
||||
@@ -76,6 +80,7 @@ _.each({
|
||||
generators: require("./transformers/es6-generators"),
|
||||
restParameters: require("./transformers/es6-rest-parameters"),
|
||||
|
||||
objectObserve: require("./transformers/optional-object-observe"),
|
||||
protoToAssign: require("./transformers/optional-proto-to-assign"),
|
||||
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
|
||||
@@ -149,7 +149,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));
|
||||
}
|
||||
|
||||
@@ -210,50 +210,50 @@ Class.prototype.pushMethod = function (node) {
|
||||
} else {
|
||||
this.hasInstanceMutators = true;
|
||||
}
|
||||
util.pushMutatorMap(mutatorMap, methodName, kind, node);
|
||||
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) {
|
||||
return t.callExpression(
|
||||
this.file.addHelper("get"),
|
||||
[
|
||||
t.callExpression(
|
||||
t.memberExpression(
|
||||
t.identifier("Object"),
|
||||
t.identifier("getPrototypeOf"),
|
||||
false
|
||||
),
|
||||
[
|
||||
isStatic ?
|
||||
this.className :
|
||||
t.memberExpression(
|
||||
this.className,
|
||||
t.identifier("prototype"),
|
||||
false
|
||||
)
|
||||
]
|
||||
),
|
||||
isComputed ?
|
||||
property :
|
||||
t.literal(property.name),
|
||||
t.thisExpression()
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -268,16 +268,48 @@ Class.prototype.replaceInstanceSuperReferences = function (methodNode) {
|
||||
|
||||
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) && 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 superProperty = self.superProperty(property, methodNode.static, computed);
|
||||
if (args) {
|
||||
return t.callExpression(
|
||||
t.memberExpression(superProperty, t.identifier("call"), false),
|
||||
[t.thisExpression()].concat(args)
|
||||
);
|
||||
} else {
|
||||
return superProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ exports.ObjectExpression = function (node, parent, file, scope) {
|
||||
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;
|
||||
|
||||
@@ -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 @@
|
||||
exports.optional = true;
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
var t = require("../../types");
|
||||
|
||||
exports.ForInStatement =
|
||||
exports.ForOfStatement = function (node, parent, file) {
|
||||
var left = node.left;
|
||||
if (t.isVariableDeclaration(left)) {
|
||||
var declar = left.declarations[0];
|
||||
if (declar.init) throw file.errorWithNode(declar, "No assignments allowed in for-in/of head");
|
||||
}
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -146,10 +146,10 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
var node = template.body[0];
|
||||
|
||||
if (!keepExpression && t.isExpressionStatement(node)) {
|
||||
node = node.expression;
|
||||
return node.expression;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
exports.codeFrame = function (lines, lineNumber, colNumber) {
|
||||
@@ -256,7 +256,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.1",
|
||||
"version": "2.9.3",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -39,7 +39,7 @@
|
||||
"test": "make test"
|
||||
},
|
||||
"dependencies": {
|
||||
"acorn-6to5": "0.11.1-11",
|
||||
"acorn-6to5": "0.11.1-12",
|
||||
"ast-types": "~0.6.1",
|
||||
"chokidar": "0.11.1",
|
||||
"commander": "2.5.0",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,28 @@
|
||||
"use strict";
|
||||
|
||||
var _slice = Array.prototype.slice;
|
||||
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);
|
||||
@@ -19,34 +41,34 @@ var _inherits = function (child, parent) {
|
||||
var Test = (function () {
|
||||
var _Foo = 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);
|
||||
|
||||
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)));
|
||||
var _get6, _get7;
|
||||
_get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
|
||||
(_get6 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get6, [this].concat(_slice.call(arguments)));
|
||||
(_get7 = _get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_get7, [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)));
|
||||
var _get8, _get9;
|
||||
_get(Object.getPrototypeOf(Test), "foo", this).call(this);
|
||||
(_get8 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get8, [this].concat(_slice.call(arguments)));
|
||||
(_get9 = _get(Object.getPrototypeOf(Test), "foo", this)).call.apply(_get9, [this, "test"].concat(_slice.call(arguments)));
|
||||
};
|
||||
|
||||
return Test;
|
||||
})();
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -18,11 +40,12 @@ var _inherits = function (child, parent) {
|
||||
var Test = (function () {
|
||||
var _Foo = 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);
|
||||
|
||||
return Test;
|
||||
})();
|
||||
|
||||
|
||||
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,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);
|
||||
@@ -18,15 +40,16 @@ var _inherits = function (child, parent) {
|
||||
var Test = (function () {
|
||||
var _Foo = 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);
|
||||
|
||||
Test.test = function () {
|
||||
return _Foo.wow.call(this);
|
||||
return _get(Object.getPrototypeOf(Test), "wow", this).call(this);
|
||||
};
|
||||
|
||||
return Test;
|
||||
})();
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ var _inherits = function (child, parent) {
|
||||
var BaseController = (function () {
|
||||
var _Chaplin$Controller = 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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -31,8 +31,8 @@ var BaseController = (function () {
|
||||
var BaseController2 = (function () {
|
||||
var _Chaplin$Controller$Another = 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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ var _inherits = function (child, parent) {
|
||||
var Test = (function () {
|
||||
var _Foo = Foo;
|
||||
var Test = function Test() {
|
||||
if (_Foo !== null) {
|
||||
_Foo.apply(this, arguments);
|
||||
if (Object.getPrototypeOf(Test) !== null) {
|
||||
Object.getPrototypeOf(Test).apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 +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";
|
||||
5
test/fixtures/transformation/es6-modules-amd-strict/imports-glob/expected.js
vendored
Normal file
5
test/fixtures/transformation/es6-modules-amd-strict/imports-glob/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
define(["exports", "foo"], function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var foo = _foo;
|
||||
});
|
||||
1
test/fixtures/transformation/es6-modules-amd-strict/imports-mixing/actual.js
vendored
Normal file
1
test/fixtures/transformation/es6-modules-amd-strict/imports-mixing/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import foo, {baz as xyz} from "foo";
|
||||
11
test/fixtures/transformation/es6-modules-amd-strict/imports-mixing/expected.js
vendored
Normal file
11
test/fixtures/transformation/es6-modules-amd-strict/imports-mixing/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 xyz = _foo.baz;
|
||||
});
|
||||
4
test/fixtures/transformation/es6-modules-amd-strict/imports-named/actual.js
vendored
Normal file
4
test/fixtures/transformation/es6-modules-amd-strict/imports-named/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import {bar} from "foo";
|
||||
import {bar2, baz} from "foo";
|
||||
import {bar as baz2} from "foo";
|
||||
import {bar as baz3, xyz} from "foo";
|
||||
10
test/fixtures/transformation/es6-modules-amd-strict/imports-named/expected.js
vendored
Normal file
10
test/fixtures/transformation/es6-modules-amd-strict/imports-named/expected.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
define(["exports", "foo"], function (exports, _foo) {
|
||||
"use strict";
|
||||
|
||||
var bar = _foo.bar;
|
||||
var bar2 = _foo.bar2;
|
||||
var baz = _foo.baz;
|
||||
var baz2 = _foo.bar;
|
||||
var baz3 = _foo.bar;
|
||||
var xyz = _foo.xyz;
|
||||
});
|
||||
3
test/fixtures/transformation/es6-modules-amd-strict/imports/actual.js
vendored
Normal file
3
test/fixtures/transformation/es6-modules-amd-strict/imports/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import "foo";
|
||||
import "foo-bar";
|
||||
import "./directory/foo-bar";
|
||||
3
test/fixtures/transformation/es6-modules-amd-strict/imports/expected.js
vendored
Normal file
3
test/fixtures/transformation/es6-modules-amd-strict/imports/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
"use strict";
|
||||
});
|
||||
1
test/fixtures/transformation/es6-modules-amd-strict/module-name/actual.js
vendored
Normal file
1
test/fixtures/transformation/es6-modules-amd-strict/module-name/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foobar();
|
||||
5
test/fixtures/transformation/es6-modules-amd-strict/module-name/expected.js
vendored
Normal file
5
test/fixtures/transformation/es6-modules-amd-strict/module-name/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
define("es6-modules-amd-strict/module-name/expected", ["exports"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
foobar();
|
||||
});
|
||||
3
test/fixtures/transformation/es6-modules-amd-strict/module-name/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-modules-amd-strict/module-name/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"amdModuleIds": true
|
||||
}
|
||||
3
test/fixtures/transformation/es6-modules-amd-strict/options.json
vendored
Normal file
3
test/fixtures/transformation/es6-modules-amd-strict/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"modules": "amdStrict"
|
||||
}
|
||||
12
test/fixtures/transformation/es6-modules-amd-strict/overview/actual.js
vendored
Normal file
12
test/fixtures/transformation/es6-modules-amd-strict/overview/actual.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import "foo";
|
||||
import "foo-bar";
|
||||
import "./directory/foo-bar";
|
||||
import foo from "foo";
|
||||
import * as foo2 from "foo";
|
||||
import {bar} from "foo";
|
||||
import {foo as bar2} from "foo";
|
||||
|
||||
export {test};
|
||||
export var test2 = 5;
|
||||
|
||||
export default test;
|
||||
17
test/fixtures/transformation/es6-modules-amd-strict/overview/expected.js
vendored
Normal file
17
test/fixtures/transformation/es6-modules-amd-strict/overview/expected.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
define(["exports", "foo", "foo-bar", "./directory/foo-bar"], function (exports, _foo, _fooBar, _directoryFooBar) {
|
||||
"use strict";
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
|
||||
var foo = _interopRequire(_foo);
|
||||
|
||||
var foo2 = _foo;
|
||||
var bar = _foo.bar;
|
||||
var bar2 = _foo.foo;
|
||||
exports.test = test;
|
||||
var test2 = exports.test2 = 5;
|
||||
|
||||
exports["default"] = test;
|
||||
});
|
||||
9
test/fixtures/transformation/es6-modules-amd-strict/remap/actual.js
vendored
Normal file
9
test/fixtures/transformation/es6-modules-amd-strict/remap/actual.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export var test = 2;
|
||||
test = 5;
|
||||
test++;
|
||||
|
||||
(function () {
|
||||
var test = 2;
|
||||
test = 3;
|
||||
test++;
|
||||
})();
|
||||
13
test/fixtures/transformation/es6-modules-amd-strict/remap/expected.js
vendored
Normal file
13
test/fixtures/transformation/es6-modules-amd-strict/remap/expected.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
define(["exports"], function (exports) {
|
||||
"use strict";
|
||||
|
||||
var test = exports.test = 2;
|
||||
test = exports.test = 5;
|
||||
test = exports.test += 1;
|
||||
|
||||
(function () {
|
||||
var test = 2;
|
||||
test = 3;
|
||||
test++;
|
||||
})();
|
||||
});
|
||||
@@ -7,15 +7,17 @@ define(["exports", "foo"], function (exports, _foo) {
|
||||
};
|
||||
};
|
||||
|
||||
var _exportsWildcard = function (obj) {
|
||||
for (var i in obj) {
|
||||
if (exports[i] !== undefined) {
|
||||
exports[i] = obj[i];
|
||||
var _defaults = function (obj, defaults) {
|
||||
for (var key in defaults) {
|
||||
if (obj[key] === undefined) {
|
||||
obj[key] = defaults[key];
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
_exportsWildcard(_interopRequireWildcard(_foo));
|
||||
_defaults(exports, _interopRequireWildcard(_foo));
|
||||
|
||||
exports.foo = _foo.foo;
|
||||
exports.foo = _foo.foo;
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
define(["exports", "module", "foo", "foo-bar", "./directory/foo-bar"], function (exports, module, _foo, _fooBar, _directoryFooBar) {
|
||||
"use strict";
|
||||
|
||||
var _extends = 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;
|
||||
};
|
||||
|
||||
var _interopRequire = function (obj) {
|
||||
return obj && (obj["default"] || obj);
|
||||
};
|
||||
@@ -13,5 +24,6 @@ define(["exports", "module", "foo", "foo-bar", "./directory/foo-bar"], function
|
||||
exports.test = test;
|
||||
var test2 = exports.test2 = 5;
|
||||
|
||||
module.exports = test;
|
||||
exports["default"] = test;
|
||||
module.exports = _extends(exports["default"], exports);
|
||||
});
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user