Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f3959444c | ||
|
|
0ba9216d6f | ||
|
|
6dfe66bce3 | ||
|
|
9e08a6f084 | ||
|
|
b9f3f1e2a9 | ||
|
|
4f18ed406c | ||
|
|
4d8e5f728a | ||
|
|
54857ceac7 | ||
|
|
5b961ea3e7 | ||
|
|
35b28cf722 | ||
|
|
c5bfbf37f0 | ||
|
|
cfee68aa67 | ||
|
|
7d0dae129c | ||
|
|
f9d14fa2ed | ||
|
|
11d55e661e | ||
|
|
0544e98fb1 | ||
|
|
59d918ea67 | ||
|
|
b4232699d2 | ||
|
|
6bd67ca660 | ||
|
|
4722c0ce56 | ||
|
|
25a5caa0fc | ||
|
|
6f05466cf5 | ||
|
|
1ad9edb57c | ||
|
|
c6ae33c5a2 | ||
|
|
e0d620b1d5 | ||
|
|
5588bf56eb | ||
|
|
a0e500de6c | ||
|
|
bf8d9801ce | ||
|
|
68b99a7004 | ||
|
|
5ae4f8eec7 | ||
|
|
d9a3eadad7 | ||
|
|
b1cc5419a4 | ||
|
|
c6a7a9c401 | ||
|
|
608df54b02 | ||
|
|
2ac83ec95b | ||
|
|
e4596f638d | ||
|
|
1425af9b2a | ||
|
|
9351c6470f | ||
|
|
7b8a50509a | ||
|
|
1400dee0c1 | ||
|
|
9e2fc6db9c | ||
|
|
aef5b89492 | ||
|
|
e0bf6f698e | ||
|
|
1ac459a05d | ||
|
|
1b49835b27 | ||
|
|
db7b6a4972 | ||
|
|
79045e15c5 | ||
|
|
b7e6d8f998 | ||
|
|
88c6ce4e48 | ||
|
|
8c97f1d92e | ||
|
|
833e8b091b | ||
|
|
23ebb23944 | ||
|
|
778cab33d5 | ||
|
|
5849c6af17 | ||
|
|
bb0655d8f6 | ||
|
|
9977a5f614 | ||
|
|
9318d63b5c | ||
|
|
b2ab0dbedc | ||
|
|
e0d3e18865 | ||
|
|
3a3ad4775b | ||
|
|
40fdd2a828 | ||
|
|
12f66e852a | ||
|
|
c61c9aab56 | ||
|
|
7adc919bb6 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,7 +6,7 @@ test/tmp
|
||||
/templates.json
|
||||
/tests.json
|
||||
/browser.js
|
||||
/polyfill.js
|
||||
/browser-polyfill.js
|
||||
/runtime.js
|
||||
coverage
|
||||
dist
|
||||
|
||||
@@ -9,3 +9,11 @@ branches:
|
||||
|
||||
before_script: "npm install -g codeclimate-test-reporter"
|
||||
script: "make test-travis"
|
||||
|
||||
notifications:
|
||||
webhooks:
|
||||
urls:
|
||||
- https://webhooks.gitter.im/e/acf1870e9d223c65e8d5
|
||||
on_success: always
|
||||
on_failure: always
|
||||
on_start: false
|
||||
|
||||
18
CHANGELOG.md
Normal file
18
CHANGELOG.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# 1.12.0
|
||||
|
||||
* Combine `jsx` and `react` transformers to `react`.
|
||||
* Update `react` syntax output to React v0.12.
|
||||
|
||||
# 1.11.15
|
||||
|
||||
* Fix JSX literal whitespace generation.
|
||||
|
||||
# 1.11.14
|
||||
|
||||
* Avoid using a switch for let-scoping continue and break statements and use an if statement instead.
|
||||
* Remove excess whitespace and newlines from JSX literals.
|
||||
|
||||
# 1.11.13
|
||||
|
||||
* Update regenerator-6to5
|
||||
* Add support for most escodegen formatting options
|
||||
16
Makefile
16
Makefile
@@ -6,7 +6,7 @@ MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
|
||||
export NODE_ENV = test
|
||||
|
||||
.PHONY: clean test test-cov test-travis test-browser publish bench build
|
||||
.PHONY: clean test test-cov tlint est-travis test-appveyor test-browser publish bench build
|
||||
|
||||
clean:
|
||||
rm -rf coverage templates.json test/tmp dist
|
||||
@@ -15,16 +15,22 @@ bench:
|
||||
npm install es6-transpiler traceur esnext es6now jstransform
|
||||
node node_modules/matcha/bin/_matcha
|
||||
|
||||
test:
|
||||
lint:
|
||||
$(JSHINT_CMD) lib bin benchmark/index.js
|
||||
|
||||
test:
|
||||
make lint
|
||||
$(MOCHA_CMD)
|
||||
|
||||
test-cov:
|
||||
rm -rf coverage
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
|
||||
|
||||
test-travis:
|
||||
test-appveyor:
|
||||
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- --reporter spec
|
||||
|
||||
test-travis:
|
||||
make test-appveyor
|
||||
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
|
||||
|
||||
test-browser:
|
||||
@@ -60,7 +66,7 @@ publish:
|
||||
|
||||
make build
|
||||
cp dist/6to5.min.js browser.js
|
||||
cp dist/polyfill.min.js polyfill.js
|
||||
cp dist/polyfill.min.js browser-polyfill.js
|
||||
cp dist/runtime.min.js runtime.js
|
||||
|
||||
node bin/cache-templates
|
||||
@@ -72,4 +78,4 @@ publish:
|
||||
|
||||
git push --follow-tags
|
||||
|
||||
rm -rf templates.json browser.js runtime.js polyfill.js
|
||||
rm -rf templates.json browser.js runtime.js browser-polyfill.js
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5.svg?branch=master&style=flat&label=travis">
|
||||
</a>
|
||||
|
||||
<a href="https://ci.appveyor.com/project/sebmck/6to5">
|
||||
<img alt="Appveyor Status" src="http://img.shields.io/appveyor/ci/sebmck/6to5.svg?style=flat&label=appveyor">
|
||||
</a>
|
||||
|
||||
<a href="https://codeclimate.com/github/6to5/6to5">
|
||||
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/6to5/6to5.svg?style=flat">
|
||||
</a>
|
||||
@@ -342,8 +346,8 @@ require("6to5/polyfill");
|
||||
|
||||
### Browser
|
||||
|
||||
Available from the `polyfill.js` file within the 6to5 directory of an npm
|
||||
release.
|
||||
Available from the `browser-polyfill.js` file within the 6to5 directory of an
|
||||
npm release.
|
||||
|
||||
## Optional runtime
|
||||
|
||||
|
||||
17
appveyor.yml
Normal file
17
appveyor.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
environment:
|
||||
matrix:
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.11"
|
||||
|
||||
install:
|
||||
- "npm install"
|
||||
- "cinst make"
|
||||
|
||||
test_script:
|
||||
- "node --version"
|
||||
- "npm --version"
|
||||
- "make test-appveyor"
|
||||
|
||||
build: "off"
|
||||
|
||||
version: "{build}"
|
||||
@@ -6,7 +6,9 @@ var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.readdirFilter = function (filename) {
|
||||
return readdir(filename).filter(util.canCompile);
|
||||
return readdir(filename).filter(function (filename) {
|
||||
return util.canCompile(filename);
|
||||
});
|
||||
};
|
||||
|
||||
exports.transform = function (filename, code, opts) {
|
||||
|
||||
@@ -11,7 +11,7 @@ var _ = require("lodash");
|
||||
|
||||
function File(opts) {
|
||||
this.opts = File.normaliseOptions(opts);
|
||||
this.moduleFormatter = this.getModuleFormatter(opts.modules);
|
||||
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
|
||||
|
||||
this.declarations = {};
|
||||
this.uids = {};
|
||||
@@ -21,7 +21,7 @@ function File(opts) {
|
||||
File.declarations = ["extends", "class-props", "slice"];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
opts = opts || {};
|
||||
opts = _.cloneDeep(opts || {});
|
||||
|
||||
_.defaults(opts, {
|
||||
whitespace: true,
|
||||
@@ -33,6 +33,9 @@ File.normaliseOptions = function (opts) {
|
||||
runtime: false
|
||||
});
|
||||
|
||||
// normalise windows path separators to unix
|
||||
opts.filename = opts.filename.replace(/\\/g, "/");
|
||||
|
||||
_.defaults(opts, {
|
||||
sourceFileName: opts.filename,
|
||||
sourceMapName: opts.filename
|
||||
@@ -110,6 +113,8 @@ File.prototype.errorWithNode = function (node, msg, Error) {
|
||||
};
|
||||
|
||||
File.prototype.parse = function (code) {
|
||||
code = (code || "") + "";
|
||||
|
||||
var self = this;
|
||||
|
||||
this.code = code;
|
||||
@@ -141,7 +146,7 @@ File.prototype.generate = function () {
|
||||
|
||||
if (this.shebang) {
|
||||
// add back shebang
|
||||
result.code = this.shebang + result.code;
|
||||
result.code = this.shebang + "\n" + result.code;
|
||||
}
|
||||
|
||||
if (opts.sourceMap === "inline") {
|
||||
|
||||
@@ -16,29 +16,38 @@ var _ = require("lodash");
|
||||
function CodeGenerator(ast, opts, code) {
|
||||
opts = opts || {};
|
||||
|
||||
this.style = {
|
||||
semicolons: true,
|
||||
comments: true,
|
||||
compact: false,
|
||||
indent: {
|
||||
char: " ",
|
||||
width: 2
|
||||
}
|
||||
};
|
||||
|
||||
this.comments = ast.comments || [];
|
||||
this.tokens = ast.tokens || [];
|
||||
this.opts = opts;
|
||||
this.ast = ast;
|
||||
this.buf = "";
|
||||
|
||||
this._indent = 0;
|
||||
this.format = CodeGenerator.normaliseOptions(opts);
|
||||
this._indent = this.format.indent.base;
|
||||
|
||||
this.whitespace = new Whitespace(this.tokens, this.comments);
|
||||
this.position = new Position;
|
||||
this.map = new SourceMap(this.position, opts, code);
|
||||
}
|
||||
|
||||
CodeGenerator.normaliseOptions = function (opts) {
|
||||
opts = opts.format || {};
|
||||
|
||||
opts = _.merge({
|
||||
parentheses: true,
|
||||
semicolons: true,
|
||||
comments: true,
|
||||
compact: false,
|
||||
indent: {
|
||||
adjustMultilineComment: true,
|
||||
style: " ",
|
||||
base: 0
|
||||
}
|
||||
}, opts);
|
||||
|
||||
return opts;
|
||||
};
|
||||
|
||||
CodeGenerator.generators = {
|
||||
arrayComprehensions: require("./generators/array-comprehensions"),
|
||||
templateLiterals: require("./generators/template-literals"),
|
||||
@@ -58,7 +67,7 @@ _.each(CodeGenerator.generators, function (generator) {
|
||||
|
||||
CodeGenerator.prototype.newline = function (i, removeLast) {
|
||||
if (!this.buf) return;
|
||||
if (this.style.compact) return;
|
||||
if (this.format.compact) return;
|
||||
if (this.endsWith("{\n")) return;
|
||||
|
||||
if (_.isBoolean(i)) {
|
||||
@@ -89,7 +98,7 @@ CodeGenerator.prototype.removeLast = function (cha) {
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.semicolon = function () {
|
||||
if (this.style.semicolons) this.push(";");
|
||||
if (this.format.semicolons) this.push(";");
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.ensureSemicolon = function () {
|
||||
@@ -145,15 +154,15 @@ CodeGenerator.prototype.isLast = function (cha, trimRight) {
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.getIndent = function () {
|
||||
if (this.style.compact) {
|
||||
if (this.format.compact) {
|
||||
return "";
|
||||
} else {
|
||||
return util.repeat(this.indentSize(), this.style.indent.char);
|
||||
return util.repeat(this._indent, this.format.indent.style);
|
||||
}
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.indentSize = function () {
|
||||
return this._indent * this.style.indent.width;
|
||||
return this.getIndent().length;
|
||||
};
|
||||
|
||||
CodeGenerator.prototype.indent = function () {
|
||||
@@ -353,8 +362,8 @@ CodeGenerator.prototype._getComments = function (key, node) {
|
||||
};
|
||||
|
||||
CodeGenerator.prototype._printComments = function (comments) {
|
||||
if (this.style.compact) return;
|
||||
if (!this.style.comments) return;
|
||||
if (this.format.compact) return;
|
||||
if (!this.format.comments) return;
|
||||
if (!comments || !comments.length) return;
|
||||
|
||||
var self = this;
|
||||
@@ -373,14 +382,16 @@ CodeGenerator.prototype._printComments = function (comments) {
|
||||
|
||||
//
|
||||
|
||||
var offset = comment.loc.start.column;
|
||||
if (offset) {
|
||||
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
}
|
||||
if (comment.type === "Block" && self.format.indent.adjustMultilineComment) {
|
||||
var offset = comment.loc.start.column;
|
||||
if (offset) {
|
||||
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
|
||||
val = val.replace(newlineRegex, "\n");
|
||||
}
|
||||
|
||||
var indent = Math.max(self.indentSize(), column);
|
||||
val = val.replace(/\n/g, "\n" + util.repeat(indent));
|
||||
var indent = Math.max(self.indentSize(), column);
|
||||
val = val.replace(/\n/g, "\n" + util.repeat(indent));
|
||||
}
|
||||
|
||||
if (column === 0) {
|
||||
val = self.getIndent() + val;
|
||||
|
||||
@@ -44,9 +44,11 @@ exports.ConditionalExpression = function (node, print) {
|
||||
exports.NewExpression = function (node, print) {
|
||||
this.push("new ");
|
||||
print(node.callee);
|
||||
this.push("(");
|
||||
print.join(node.arguments, { separator: ", " });
|
||||
this.push(")");
|
||||
if (node.arguments.length || this.format.parentheses) {
|
||||
this.push("(");
|
||||
print.join(node.arguments, { separator: ", " });
|
||||
this.push(")");
|
||||
}
|
||||
};
|
||||
|
||||
exports.SequenceExpression = function (node, print) {
|
||||
@@ -64,15 +66,20 @@ exports.CallExpression = function (node, print) {
|
||||
this.push(")");
|
||||
};
|
||||
|
||||
exports.YieldExpression = function (node, print) {
|
||||
this.push("yield");
|
||||
if (node.delegate) this.push("*");
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
print(node.argument);
|
||||
}
|
||||
var buildYieldAwait = function (keyword) {
|
||||
return function (node, print) {
|
||||
this.push(keyword);
|
||||
if (node.delegate) this.push("*");
|
||||
if (node.argument) {
|
||||
this.space();
|
||||
print(node.argument);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.YieldExpression = buildYieldAwait("yield");
|
||||
exports.AwaitExpression = buildYieldAwait("await");
|
||||
|
||||
exports.EmptyStatement = function () {
|
||||
this.semicolon();
|
||||
};
|
||||
|
||||
@@ -46,15 +46,11 @@ exports.XJSElement = function (node, print) {
|
||||
|
||||
this.indent();
|
||||
_.each(node.children, function (child) {
|
||||
if (t.isLiteral(child) && typeof child.value === "string") {
|
||||
if (/\S/.test(child.value)) {
|
||||
return self.push(child.value.replace(/^\s+|\s+$/g, ""));
|
||||
} else if (/\n/.test(child.value)) {
|
||||
return self.newline();
|
||||
}
|
||||
if (t.isLiteral(child)) {
|
||||
self.push(child.value);
|
||||
} else {
|
||||
print(child);
|
||||
}
|
||||
|
||||
print(child);
|
||||
});
|
||||
this.dedent();
|
||||
|
||||
|
||||
@@ -80,6 +80,10 @@ Node.prototype.needsWhitespace = function (type) {
|
||||
if (t.isProperty(node) && parent.properties[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (t.isSwitchCase(node) && parent.cases[0] === node) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (type === "after") {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
var transform = require("./transformation/transform");
|
||||
var util = require("./util");
|
||||
var fs = require("fs");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -14,6 +15,8 @@ exports.polyfill = function () {
|
||||
require("./polyfill");
|
||||
};
|
||||
|
||||
exports.canCompile = util.canCompile;
|
||||
|
||||
exports.transform = transform;
|
||||
|
||||
exports.transformFile = function (filename, opts, callback) {
|
||||
|
||||
@@ -11,16 +11,7 @@ module.exports = function (namespace) {
|
||||
var container = t.functionExpression(null, [], t.blockStatement(body));
|
||||
var tree = t.program([t.expressionStatement(t.callExpression(container, []))]);
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(t.identifier("self"), t.conditionalExpression(
|
||||
t.binaryExpression("===",
|
||||
t.unaryExpression("typeof", t.identifier("global"), true),
|
||||
t.literal("undefined")
|
||||
),
|
||||
t.identifier("window"),
|
||||
t.identifier("global"))
|
||||
)
|
||||
]));
|
||||
body.push(util.template("self-global", true));
|
||||
|
||||
body.push(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(
|
||||
|
||||
1
lib/6to5/templates/let-scoping-return.js
Normal file
1
lib/6to5/templates/let-scoping-return.js
Normal file
@@ -0,0 +1 @@
|
||||
if (typeof RETURN === "object") return RETURN.v;
|
||||
1
lib/6to5/templates/self-global.js
Normal file
1
lib/6to5/templates/self-global.js
Normal file
@@ -0,0 +1 @@
|
||||
var self = typeof global === "undefined" ? window : global;
|
||||
@@ -5,9 +5,6 @@ var File = require("../file");
|
||||
var _ = require("lodash");
|
||||
|
||||
function transform(code, opts) {
|
||||
opts = opts || {};
|
||||
code = (code || "") + "";
|
||||
|
||||
var file = new File(opts);
|
||||
return file.parse(code);
|
||||
}
|
||||
@@ -20,7 +17,16 @@ transform._ensureTransformerNames = function (type, keys) {
|
||||
});
|
||||
};
|
||||
|
||||
transform.transformers = {
|
||||
transform.transformers = {};
|
||||
|
||||
transform.moduleFormatters = {
|
||||
common: require("./modules/common"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
};
|
||||
|
||||
_.each({
|
||||
modules: require("./transformers/modules"),
|
||||
propertyNameShorthand: require("./transformers/property-name-shorthand"),
|
||||
constants: require("./transformers/constants"),
|
||||
@@ -40,28 +46,18 @@ transform.transformers = {
|
||||
letScoping: require("./transformers/let-scoping"),
|
||||
forOf: require("./transformers/for-of"),
|
||||
unicodeRegex: require("./transformers/unicode-regex"),
|
||||
generators: require("./transformers/generators"),
|
||||
numericLiterals: require("./transformers/numeric-literals"),
|
||||
|
||||
react: require("./transformers/react"),
|
||||
jsx: require("./transformers/jsx"),
|
||||
|
||||
_aliasFunctions: require("./transformers/_alias-functions"),
|
||||
_blockHoist: require("./transformers/_block-hoist"),
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
|
||||
generators: require("./transformers/generators"),
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
|
||||
_moduleFormatter: require("./transformers/_module-formatter")
|
||||
};
|
||||
|
||||
transform.moduleFormatters = {
|
||||
common: require("./modules/common"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
};
|
||||
|
||||
_.each(transform.transformers, function (transformer, key) {
|
||||
}, function (transformer, key) {
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
var esutils = require("esutils");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.Property = function (node) {
|
||||
// ignore key literals that are valid identifiers
|
||||
var key = node.key;
|
||||
if (t.isLiteral(key) && esutils.keyword.isIdentifierName(key.value)) {
|
||||
if (t.isLiteral(key) && _.isString(key.value) && esutils.keyword.isIdentifierName(key.value)) {
|
||||
key.type = "Identifier";
|
||||
key.name = key.value;
|
||||
delete key.value;
|
||||
|
||||
@@ -17,10 +17,14 @@ exports.ForStatement = function (node, parent, file) {
|
||||
});
|
||||
};
|
||||
|
||||
var getIds = function (node) {
|
||||
return t.getIds(node, false, ["MemberExpression"]);
|
||||
};
|
||||
|
||||
_.each(node.body, function (child) {
|
||||
if (child && t.isVariableDeclaration(child, { kind: "const" })) {
|
||||
_.each(child.declarations, function (declar) {
|
||||
_.each(t.getIds(declar), function (name) {
|
||||
_.each(getIds(declar), function (name) {
|
||||
check(declar, [name]);
|
||||
constants.push(name);
|
||||
});
|
||||
@@ -39,7 +43,7 @@ exports.ForStatement = function (node, parent, file) {
|
||||
if (child._ignoreConstant) return;
|
||||
|
||||
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
|
||||
check(child, t.getIds(child));
|
||||
check(child, getIds(child));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -11,21 +11,7 @@ var buildVariableAssign = function (kind, id, init) {
|
||||
}
|
||||
};
|
||||
|
||||
var normalise = function (node) {
|
||||
if (t.isParenthesizedExpression(node)) {
|
||||
return node.expression;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
};
|
||||
|
||||
var isPattern = function (node) {
|
||||
return t.isPattern(normalise(node));
|
||||
};
|
||||
|
||||
var push = function (kind, nodes, elem, parentId) {
|
||||
elem = normalise(elem);
|
||||
|
||||
if (t.isObjectPattern(elem)) {
|
||||
pushObjectPattern(kind, nodes, elem, parentId);
|
||||
} else if (t.isArrayPattern(elem)) {
|
||||
@@ -42,7 +28,7 @@ var pushObjectPattern = function (kind, nodes, pattern, parentId) {
|
||||
var pattern2 = prop.value;
|
||||
var patternId2 = t.memberExpression(parentId, prop.key);
|
||||
|
||||
if (isPattern(pattern2)) {
|
||||
if (t.isPattern(pattern2)) {
|
||||
push(kind, nodes, pattern2, patternId2);
|
||||
} else {
|
||||
nodes.push(buildVariableAssign(kind, pattern2, patternId2));
|
||||
@@ -94,7 +80,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
|
||||
if (!t.isVariableDeclaration(declar)) return;
|
||||
|
||||
var pattern = declar.declarations[0].id;
|
||||
if (!isPattern(pattern)) return;
|
||||
if (!t.isPattern(pattern)) return;
|
||||
|
||||
var key = t.identifier(file.generateUid("ref", scope));
|
||||
node.left = t.variableDeclaration(declar.kind, [
|
||||
@@ -117,7 +103,7 @@ exports.Function = function (node, parent, file, scope) {
|
||||
var hasDestructuring = false;
|
||||
|
||||
node.params = node.params.map(function (pattern) {
|
||||
if (!isPattern(pattern)) return pattern;
|
||||
if (!t.isPattern(pattern)) return pattern;
|
||||
|
||||
hasDestructuring = true;
|
||||
var parentId = t.identifier(file.generateUid("ref", scope));
|
||||
@@ -146,7 +132,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
|
||||
var expr = node.expression;
|
||||
if (expr.type !== "AssignmentExpression") return;
|
||||
|
||||
if (!isPattern(expr.left)) return;
|
||||
if (!t.isPattern(expr.left)) return;
|
||||
|
||||
var nodes = [];
|
||||
|
||||
@@ -167,7 +153,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
|
||||
|
||||
var hasPattern = false;
|
||||
_.each(node.declarations, function (declar) {
|
||||
if (isPattern(declar.id)) {
|
||||
if (t.isPattern(declar.id)) {
|
||||
hasPattern = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser)
|
||||
// https://github.com/RReverser/jsx-transpiler
|
||||
|
||||
var esutils = require("esutils");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var JSX_ANNOTATION_REGEX = /^\*\s*@jsx\s+([^\s]+)/;
|
||||
|
||||
exports.Program = function (node, parent, file) {
|
||||
var jsx = "React.DOM";
|
||||
|
||||
// looking for namespace annotation
|
||||
_.each(node.leadingComments, function (comment) {
|
||||
var matches = JSX_ANNOTATION_REGEX.exec(comment.value);
|
||||
if (matches) jsx = matches[1];
|
||||
});
|
||||
|
||||
// prebuilding AST node
|
||||
file.jsx = jsx.split(".").map(t.identifier).reduce(function (object, property) {
|
||||
return t.memberExpression(object, property);
|
||||
});
|
||||
};
|
||||
|
||||
exports.XJSIdentifier = function (node) {
|
||||
if (esutils.keyword.isIdentifierName(node.name)) {
|
||||
node.type = "Identifier";
|
||||
} else {
|
||||
return t.literal(node.name);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSNamespacedName = function () {
|
||||
throw new Error("Namespace tags are not supported. ReactJSX is not XML.");
|
||||
};
|
||||
|
||||
exports.XJSMemberExpression = {
|
||||
exit: function (node) {
|
||||
node.computed = t.isLiteral(node.property);
|
||||
node.type = "MemberExpression";
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSExpressionContainer = function (node) {
|
||||
return node.expression;
|
||||
};
|
||||
|
||||
exports.XJSAttribute = {
|
||||
exit: function (node) {
|
||||
var value = node.value || t.literal(true);
|
||||
return t.property("init", node.name, value);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSOpeningElement = {
|
||||
exit: function (node, parent, file) {
|
||||
var tagExpr = node.name;
|
||||
|
||||
if (t.isIdentifier(tagExpr)) {
|
||||
var tagName = tagExpr.name;
|
||||
|
||||
if (/[a-z]/.exec(tagName[0]) || _.contains(tagName, "-")) {
|
||||
tagExpr = t.memberExpression(file.jsx, tagExpr);
|
||||
}
|
||||
}
|
||||
|
||||
var props = node.attributes;
|
||||
if (props.length) {
|
||||
props = t.objectExpression(props);
|
||||
} else {
|
||||
props = t.literal(null);
|
||||
}
|
||||
|
||||
return t.callExpression(tagExpr, [props]);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSElement = {
|
||||
exit: function (node) {
|
||||
var callExpr = node.openingElement;
|
||||
var children = node.children;
|
||||
|
||||
_.each(children, function (child) {
|
||||
callExpr.arguments.push(child);
|
||||
});
|
||||
|
||||
return t.inherits(callExpr, node);
|
||||
}
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
var traverse = require("../../traverse");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
@@ -132,7 +133,7 @@ var checkFor = function (forParent, block) {
|
||||
} else if (t.isReturnStatement(node)) {
|
||||
has.hasReturn = true;
|
||||
replace = t.returnStatement(t.objectExpression([
|
||||
t.property("init", t.identifier("v"), node.argument)
|
||||
t.property("init", t.identifier("v"), node.argument || t.identifier("undefined"))
|
||||
]));
|
||||
}
|
||||
|
||||
@@ -285,17 +286,13 @@ var run = function (forParent, block, parent, file, scope) {
|
||||
|
||||
var retCheck;
|
||||
|
||||
var cases = [];
|
||||
|
||||
if (has.hasReturn) {
|
||||
// typeof ret === "object"
|
||||
retCheck = t.ifStatement(
|
||||
t.binaryExpression("===", t.unaryExpression("typeof", ret, true), t.literal("object")),
|
||||
t.returnStatement(t.memberExpression(ret, t.identifier("v")))
|
||||
);
|
||||
|
||||
// there's no `break` or `continue` so we can just push in the `if`
|
||||
if (!has.hasBreak && !has.hasContinue) {
|
||||
body.push(retCheck);
|
||||
}
|
||||
retCheck = util.template("let-scoping-return", {
|
||||
RETURN: ret,
|
||||
});
|
||||
}
|
||||
|
||||
if (has.hasBreak || has.hasContinue) {
|
||||
@@ -303,8 +300,6 @@ var run = function (forParent, block, parent, file, scope) {
|
||||
// need to be able to access it
|
||||
var label = forParent.label = forParent.label || t.identifier(file.generateUid("loop", scope));
|
||||
|
||||
var cases = [];
|
||||
|
||||
if (has.hasBreak) {
|
||||
cases.push(t.switchCase(t.literal("break"), [t.breakStatement(label)]));
|
||||
}
|
||||
@@ -317,7 +312,17 @@ var run = function (forParent, block, parent, file, scope) {
|
||||
cases.push(t.switchCase(null, [retCheck]));
|
||||
}
|
||||
|
||||
body.push(t.switchStatement(ret, cases));
|
||||
if (cases.length === 1) {
|
||||
var single = cases[0];
|
||||
body.push(t.ifStatement(
|
||||
t.binaryExpression("===", ret, single.test),
|
||||
single.consequent[0]
|
||||
));
|
||||
} else {
|
||||
body.push(t.switchStatement(ret, cases));
|
||||
}
|
||||
} else {
|
||||
if (has.hasReturn) body.push(retCheck);
|
||||
}
|
||||
} else {
|
||||
body.push(t.expressionStatement(call));
|
||||
|
||||
99
lib/6to5/transformation/transformers/react.js
vendored
99
lib/6to5/transformation/transformers/react.js
vendored
@@ -1,5 +1,100 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser)
|
||||
// https://github.com/RReverser/jsx-transpiler
|
||||
|
||||
// jsx
|
||||
|
||||
var esutils = require("esutils");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.XJSIdentifier = function (node) {
|
||||
if (esutils.keyword.isIdentifierName(node.name)) {
|
||||
node.type = "Identifier";
|
||||
} else {
|
||||
return t.literal(node.name);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSNamespacedName = function (node, parent, file) {
|
||||
throw file.errorWithNode(node, "Namespace tags are not supported. ReactJSX is not XML.");
|
||||
};
|
||||
|
||||
exports.XJSMemberExpression = {
|
||||
exit: function (node) {
|
||||
node.computed = t.isLiteral(node.property);
|
||||
node.type = "MemberExpression";
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSExpressionContainer = function (node) {
|
||||
return node.expression;
|
||||
};
|
||||
|
||||
exports.XJSAttribute = {
|
||||
exit: function (node) {
|
||||
var value = node.value || t.literal(true);
|
||||
return t.property("init", node.name, value);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSOpeningElement = {
|
||||
exit: function (node) {
|
||||
var tagExpr = node.name;
|
||||
var args = [];
|
||||
|
||||
var tagName;
|
||||
if (t.isIdentifier(tagExpr)) {
|
||||
tagName = tagExpr.name;
|
||||
} else if (t.isLiteral(tagExpr)) {
|
||||
tagName = tagExpr.value;
|
||||
}
|
||||
|
||||
if (tagName && (/[a-z]/.exec(tagName[0]) || _.contains(tagName, "-"))) {
|
||||
args.push(t.literal(tagName));
|
||||
} else {
|
||||
args.push(tagExpr);
|
||||
}
|
||||
|
||||
var props = node.attributes;
|
||||
if (props.length) {
|
||||
var first = props[0];
|
||||
if (t.isXJSSpreadAttribute(first)) {
|
||||
props.shift();
|
||||
props = t.callExpression(
|
||||
t.memberExpression(t.identifier("React"), t.identifier("__spread")),
|
||||
[t.objectExpression([]), first.argument, t.objectExpression(props)]
|
||||
);
|
||||
} else {
|
||||
props = t.objectExpression(props);
|
||||
}
|
||||
} else {
|
||||
props = t.literal(null);
|
||||
}
|
||||
|
||||
args.push(props);
|
||||
|
||||
tagExpr = t.memberExpression(t.identifier("React"), t.identifier("createElement"));
|
||||
return t.callExpression(tagExpr, args);
|
||||
}
|
||||
};
|
||||
|
||||
exports.XJSElement = {
|
||||
exit: function (node) {
|
||||
var callExpr = node.openingElement;
|
||||
|
||||
var childrenToRender = node.children.filter(function(child) {
|
||||
return !(t.isLiteral(child) && _.isString(child.value) && child.value.match(/^[ \t]*[\r\n][ \t\r\n]*$/));
|
||||
});
|
||||
|
||||
_.each(childrenToRender, function (child) {
|
||||
callExpr.arguments.push(child);
|
||||
});
|
||||
|
||||
return t.inherits(callExpr, node);
|
||||
}
|
||||
};
|
||||
|
||||
// display names
|
||||
|
||||
var addDisplayName = function (id, call) {
|
||||
if (!call || !t.isCallExpression(call)) return;
|
||||
|
||||
@@ -40,8 +40,6 @@ function traverse(parent, callbacks, opts) {
|
||||
// type is blacklisted
|
||||
if (_.contains(blacklistTypes, node.type)) return;
|
||||
|
||||
var result;
|
||||
|
||||
// replace node
|
||||
var maybeReplace = function (result) {
|
||||
if (result === false) return;
|
||||
@@ -54,12 +52,11 @@ function traverse(parent, callbacks, opts) {
|
||||
|
||||
// enter
|
||||
if (callbacks.enter) {
|
||||
result = callbacks.enter(node, parent, opts2.scope);
|
||||
var result = callbacks.enter(node, parent, opts2.scope);
|
||||
maybeReplace(result);
|
||||
|
||||
// stop iteration
|
||||
if (result === false) return;
|
||||
|
||||
maybeReplace(result);
|
||||
}
|
||||
|
||||
// traverse node
|
||||
@@ -114,25 +111,18 @@ traverse.hasType = function (tree, type, blacklistTypes) {
|
||||
|
||||
var has = false;
|
||||
|
||||
if (_.isArray(tree)) {
|
||||
// array of nodes, find the first
|
||||
return tree.some(function (node) {
|
||||
return traverse.hasType(node, type, blacklistTypes);
|
||||
});
|
||||
} else {
|
||||
// the node we're searching in is blacklisted
|
||||
if (_.contains(blacklistTypes, tree.type)) return false;
|
||||
// the node we're searching in is blacklisted
|
||||
if (_.contains(blacklistTypes, tree.type)) return false;
|
||||
|
||||
// the type we're looking for is the same as the passed node
|
||||
if (tree.type === type) return true;
|
||||
// the type we're looking for is the same as the passed node
|
||||
if (tree.type === type) return true;
|
||||
|
||||
traverse(tree, function (node) {
|
||||
if (node.type === type) {
|
||||
has = true;
|
||||
return false;
|
||||
}
|
||||
}, { blacklist: blacklistTypes });
|
||||
}
|
||||
traverse(tree, function (node) {
|
||||
if (node.type === type) {
|
||||
has = true;
|
||||
return false;
|
||||
}
|
||||
}, { blacklist: blacklistTypes });
|
||||
|
||||
return has;
|
||||
};
|
||||
|
||||
@@ -156,37 +156,26 @@ t.toBlock = function (node, parent) {
|
||||
return t.blockStatement(node);
|
||||
};
|
||||
|
||||
t.getIds = function (node, map) {
|
||||
t.getIds = function (node, map, ignoreTypes) {
|
||||
ignoreTypes = ignoreTypes || [];
|
||||
|
||||
var search = [node];
|
||||
var ids = {};
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
if (!id) continue;
|
||||
if (_.contains(ignoreTypes, id.type)) continue;
|
||||
|
||||
var nodeKey = t.getIds.nodes[id.type];
|
||||
var arrKey = t.getIds.arrays[id.type];
|
||||
|
||||
if (t.isIdentifier(id)) {
|
||||
ids[id.name] = id;
|
||||
} else if (t.isArrayPattern(id)) {
|
||||
_.each(id.elements, function (elem) {
|
||||
search.push(elem);
|
||||
});
|
||||
} else if (t.isAssignmentExpression(id)) {
|
||||
search.push(id.left);
|
||||
} else if (t.isObjectPattern(id)) {
|
||||
_.each(id.properties, function (prop) {
|
||||
search.push(prop.value);
|
||||
});
|
||||
} else if (t.isVariableDeclaration(id)) {
|
||||
search = search.concat(id.declarations);
|
||||
} else if (t.isImportSpecifier(id) || t.isExportSpecifier(id) || t.isVariableDeclarator(id) || t.isFunctionDeclaration(id) || t.isClassDeclaration(id)) {
|
||||
search.push(id.id);
|
||||
} else if (t.isSpreadElement(id)) {
|
||||
search.push(id.argument);
|
||||
} else if (t.isExportDeclaration(id) || t.isImportDeclaration(id)) {
|
||||
search = search.concat(id.specifiers);
|
||||
} else if (t.isMemberExpression(id)) {
|
||||
search.push(id.object);
|
||||
} else if (t.isParenthesizedExpression(id)) {
|
||||
search.push(id.expression);
|
||||
} else if (nodeKey) {
|
||||
if (id[nodeKey]) search.push(id[nodeKey]);
|
||||
} else if (arrKey) {
|
||||
search = search.concat(id[arrKey] || []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,11 +183,34 @@ t.getIds = function (node, map) {
|
||||
return ids;
|
||||
};
|
||||
|
||||
t.getIds.nodes = {
|
||||
AssignmentExpression: "left",
|
||||
ImportSpecifier: "id",
|
||||
ExportSpecifier: "id",
|
||||
VariableDeclarator: "id",
|
||||
FunctionDeclaration: "id",
|
||||
ClassDeclaration: "id",
|
||||
ParenthesizedExpression: "expression",
|
||||
MemeberExpression: "object",
|
||||
SpreadElement: "argument",
|
||||
Property: "value"
|
||||
};
|
||||
|
||||
t.getIds.arrays = {
|
||||
ExportDeclaration: "specifiers",
|
||||
ImportDeclaration: "specifiers",
|
||||
VariableDeclaration: "declarations",
|
||||
ArrayPattern: "elements",
|
||||
ObjectPattern: "properties"
|
||||
};
|
||||
|
||||
t.inherits = function (child, parent) {
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
child.range = parent.range;
|
||||
child.start = parent.start;
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
child.range = parent.range;
|
||||
child.start = parent.start;
|
||||
child.leadingComments = parent.leadingComments;
|
||||
child.trailingComments = parent.trailingComments;
|
||||
return child;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
"ArrayPattern": ["elements"],
|
||||
"ArrowFunctionExpression": ["params", "defaults", "rest", "body"],
|
||||
"AssignmentExpression": ["left", "right"],
|
||||
"AwaitExpression": ["argument"],
|
||||
"BinaryExpression": ["left", "right"],
|
||||
"BlockStatement": ["body"],
|
||||
"BreakStatement": ["label"],
|
||||
@@ -70,6 +71,6 @@
|
||||
"XJSMemberExpression": ["object", "property"],
|
||||
"XJSNamespacedName": ["namespace", "name"],
|
||||
"XJSOpeningElement": ["name", "attributes"],
|
||||
"XJSSpreadAttribute": [],
|
||||
"XJSSpreadAttribute": ["argument"],
|
||||
"YieldExpression": ["argument"]
|
||||
}
|
||||
|
||||
@@ -11,6 +11,12 @@ var _ = require("lodash");
|
||||
|
||||
exports.inherits = util.inherits;
|
||||
|
||||
exports.canCompile = function (filename, altExts) {
|
||||
var exts = altExts || [".js", ".jsx", ".es6"];
|
||||
var ext = path.extname(filename);
|
||||
return _.contains(exts, ext);
|
||||
};
|
||||
|
||||
exports.resolve = function (loc) {
|
||||
try {
|
||||
return require.resolve(loc);
|
||||
@@ -46,11 +52,6 @@ exports.isAbsolute = function (loc) {
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.canCompile = function (filename) {
|
||||
var ext = path.extname(filename);
|
||||
return _.contains([".js", ".es6"], ext);
|
||||
};
|
||||
|
||||
exports.sourceMapToComment = function (map) {
|
||||
var json = JSON.stringify(map);
|
||||
var base64 = new Buffer(json).toString("base64");
|
||||
@@ -111,6 +112,11 @@ exports.template = function (name, nodes, keepExpression) {
|
||||
var template = exports.templates[name];
|
||||
if (!template) throw new ReferenceError("unknown template " + name);
|
||||
|
||||
if (nodes === true) {
|
||||
keepExpression = true;
|
||||
nodes = null;
|
||||
}
|
||||
|
||||
template = _.cloneDeep(template);
|
||||
|
||||
var inherits = false;
|
||||
@@ -192,13 +198,14 @@ exports.parse = function (opts, code, callback) {
|
||||
var tokens = [];
|
||||
|
||||
var ast = acorn.parse(code, {
|
||||
preserveParens: true,
|
||||
ecmaVersion: Infinity,
|
||||
strictMode: true,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
allowReturnOutsideFunction: true,
|
||||
preserveParens: true,
|
||||
ecmaVersion: Infinity,
|
||||
strictMode: true,
|
||||
onComment: comments,
|
||||
locations: true,
|
||||
onToken: tokens,
|
||||
ranges: true
|
||||
});
|
||||
|
||||
estraverse.attachComments(ast, comments, tokens);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.11.2",
|
||||
"version": "1.12.0",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
@@ -44,11 +44,11 @@
|
||||
"es6-symbol": "0.1.1",
|
||||
"regexpu": "0.3.0",
|
||||
"source-map": "0.1.40",
|
||||
"regenerator-6to5": "https://github.com/6to5/regenerator-6to5/archive/b7bc53e1a655879974aad53a8ceb93a70efaa08d.tar.gz",
|
||||
"regenerator-6to5": "https://github.com/6to5/regenerator-6to5/archive/62d1bfcb331dcf0bbcdbbee8043da0c6408f09cf.tar.gz",
|
||||
"chokidar": "0.10.5",
|
||||
"source-map-support": "0.2.8",
|
||||
"esutils": "1.1.4",
|
||||
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/f5110383517eef0bea78c2da2a1fb01fbed74e4e.tar.gz",
|
||||
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/0384a0d51f630f66ed591769c1765581a17d2124.tar.gz",
|
||||
"estraverse": "^1.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
1
polyfill.js
Normal file
1
polyfill.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("./lib/6to5/polyfill");
|
||||
@@ -5,9 +5,11 @@ var humanise = function (val) {
|
||||
return val.replace(/-/g, " ");
|
||||
};
|
||||
|
||||
var readFile = function (filename) {
|
||||
var readFile = exports.readFile = function (filename) {
|
||||
if (fs.existsSync(filename)) {
|
||||
return fs.readFileSync(filename, "utf8").trim();
|
||||
var file = fs.readFileSync(filename, "utf8").trim();
|
||||
file = file.replace(/\r\n/g, "\n");
|
||||
return file;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
12
test/bin.js
12
test/bin.js
@@ -1,4 +1,5 @@
|
||||
var readdir = require("fs-readdir-recursive");
|
||||
var helper = require("./_helper");
|
||||
var assert = require("assert");
|
||||
var rimraf = require("rimraf");
|
||||
var mkdirp = require("mkdirp");
|
||||
@@ -11,15 +12,11 @@ var _ = require("lodash");
|
||||
var fixtureLoc = __dirname + "/fixtures/bin";
|
||||
var tmpLoc = __dirname + "/tmp";
|
||||
|
||||
var readFile = function (filename) {
|
||||
return fs.readFileSync(filename, "utf8").trim();
|
||||
};
|
||||
|
||||
var readDir = function (loc) {
|
||||
var files = {};
|
||||
if (fs.existsSync(loc)) {
|
||||
_.each(readdir(loc), function (filename) {
|
||||
var contents = readFile(loc + "/" + filename);
|
||||
var contents = helper.readFile(loc + "/" + filename);
|
||||
files[filename] = contents;
|
||||
});
|
||||
}
|
||||
@@ -51,6 +48,7 @@ var assertTest = function (stdout, stderr, opts) {
|
||||
|
||||
var expectStdout = opts.stdout.trim();
|
||||
stdout = stdout.trim();
|
||||
stdout = stdout.replace(/\\/g, "/");
|
||||
|
||||
if (opts.stdout) {
|
||||
if (opts.stdoutContains) {
|
||||
@@ -63,7 +61,7 @@ var assertTest = function (stdout, stderr, opts) {
|
||||
}
|
||||
|
||||
_.each(opts.outFiles, function (expect, filename) {
|
||||
var actual = readFile(filename);
|
||||
var actual = helper.readFile(filename);
|
||||
chai.expect(actual).to.equal(expect, "out-file " + filename);
|
||||
});
|
||||
};
|
||||
@@ -138,7 +136,7 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
|
||||
_.each(["stdout", "stdin", "stderr"], function (key) {
|
||||
var loc = testLoc + "/" + key + ".txt";
|
||||
if (fs.existsSync(loc)) {
|
||||
opts[key] = readFile(loc);
|
||||
opts[key] = helper.readFile(loc);
|
||||
} else {
|
||||
opts[key] = opts[key] || "";
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
({ t: t }) = obj;
|
||||
({
|
||||
t: { C: C }
|
||||
}) = obj;
|
||||
({ a, b, c }) = obj;
|
||||
@@ -1,5 +0,0 @@
|
||||
({ t: t }) = obj;
|
||||
({
|
||||
t: { C: C }
|
||||
}) = obj;
|
||||
({ a, b, c }) = obj;
|
||||
@@ -1,2 +1 @@
|
||||
[a, b] = f();
|
||||
({ x }) = e();
|
||||
|
||||
@@ -4,6 +4,3 @@ var _ref = f();
|
||||
|
||||
a = _ref[0];
|
||||
b = _ref[1];
|
||||
var _ref2 = e();
|
||||
|
||||
x = _ref2.x;
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
/** @jsx CUSTOM_DOM */
|
||||
|
||||
<a></a>
|
||||
@@ -1,5 +0,0 @@
|
||||
/** @jsx CUSTOM_DOM */
|
||||
|
||||
"use strict";
|
||||
|
||||
CUSTOM_DOM.a(null);
|
||||
@@ -1 +0,0 @@
|
||||
<X>{}</X>
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
X(null, null);
|
||||
@@ -1,2 +0,0 @@
|
||||
<X data-prop={x ? <Y prop={2} /> : <Z>
|
||||
</Z>}></X>
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
X({
|
||||
"data-prop": x ? Y({
|
||||
prop: 2
|
||||
}) : Z(null, "\n")
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
(<X>{a}</X>);
|
||||
|
||||
(<X>{a} {b}</X>);
|
||||
|
||||
(<X prop={a} yes></X>);
|
||||
@@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
(X(null, a));
|
||||
|
||||
(X(null, a, " ", b));
|
||||
|
||||
(X({
|
||||
prop: a,
|
||||
yes: true
|
||||
}));
|
||||
@@ -1 +0,0 @@
|
||||
<a></a>
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
React.DOM.a(null);
|
||||
@@ -1 +0,0 @@
|
||||
<Test.X></Test.X>
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
Test.X(null);
|
||||
@@ -1 +0,0 @@
|
||||
<Test:X></Test:X>
|
||||
@@ -1,3 +0,0 @@
|
||||
(<X />);
|
||||
|
||||
(<X prop="1" />);
|
||||
@@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
(X(null));
|
||||
|
||||
(X({
|
||||
prop: "1"
|
||||
}));
|
||||
@@ -1 +0,0 @@
|
||||
<X></X>
|
||||
@@ -1,3 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
X(null);
|
||||
@@ -1,3 +0,0 @@
|
||||
(<X prop="2"><Y /></X>);
|
||||
|
||||
(<X prop="2"><Y /><Z /></X>);
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
(X({
|
||||
prop: "2"
|
||||
}, Y(null)));
|
||||
|
||||
(X({
|
||||
prop: "2"
|
||||
}, Y(null), Z(null)));
|
||||
@@ -1,13 +0,0 @@
|
||||
(<X> </X>);
|
||||
|
||||
(<X>
|
||||
</X>);
|
||||
|
||||
(<X>
|
||||
string
|
||||
</X>);
|
||||
|
||||
(<X>
|
||||
string
|
||||
string
|
||||
</X>);
|
||||
@@ -1,9 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
(X(null, " "));
|
||||
|
||||
(X(null, "\n"));
|
||||
|
||||
(X(null, "\n string\n"));
|
||||
|
||||
(X(null, "\n string\n string\n "));
|
||||
10
test/fixtures/transformation/let-scoping/for-break-continue-return/actual.js
vendored
Normal file
10
test/fixtures/transformation/let-scoping/for-break-continue-return/actual.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
for (let i in nums) {
|
||||
fns.push(function () { return i; });
|
||||
if (i === 1) {
|
||||
continue;
|
||||
} else if (i === 2) {
|
||||
break;
|
||||
} else if (i === 3) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
24
test/fixtures/transformation/let-scoping/for-break-continue-return/expected.js
vendored
Normal file
24
test/fixtures/transformation/let-scoping/for-break-continue-return/expected.js
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
|
||||
_loop: for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
});
|
||||
if (i === 1) {
|
||||
return "continue";
|
||||
} else if (i === 2) {
|
||||
return "break";
|
||||
} else if (i === 3) {
|
||||
return {
|
||||
v: i
|
||||
};
|
||||
}
|
||||
})(i);
|
||||
|
||||
switch (_ret) {
|
||||
case "break": break _loop;
|
||||
case "continue": continue _loop;
|
||||
default: if (typeof _ret === "object") return _ret.v;
|
||||
}
|
||||
}
|
||||
4
test/fixtures/transformation/let-scoping/for-break/actual.js
vendored
Normal file
4
test/fixtures/transformation/let-scoping/for-break/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
for (let i in nums) {
|
||||
fns.push(function () { return i; });
|
||||
break;
|
||||
}
|
||||
12
test/fixtures/transformation/let-scoping/for-break/expected.js
vendored
Normal file
12
test/fixtures/transformation/let-scoping/for-break/expected.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
_loop: for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
});
|
||||
return "break";
|
||||
})(i);
|
||||
|
||||
if (_ret === "break") break _loop;
|
||||
}
|
||||
4
test/fixtures/transformation/let-scoping/for-continue/actual.js
vendored
Normal file
4
test/fixtures/transformation/let-scoping/for-continue/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
for (let i in nums) {
|
||||
fns.push(function () { return i; });
|
||||
continue;
|
||||
}
|
||||
12
test/fixtures/transformation/let-scoping/for-continue/expected.js
vendored
Normal file
12
test/fixtures/transformation/let-scoping/for-continue/expected.js
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
_loop: for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
});
|
||||
return "continue";
|
||||
})(i);
|
||||
|
||||
if (_ret === "continue") continue _loop;
|
||||
}
|
||||
4
test/fixtures/transformation/let-scoping/for-return-undefined/actual.js
vendored
Normal file
4
test/fixtures/transformation/let-scoping/for-return-undefined/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
for (let i in nums) {
|
||||
fns.push(function () { return i; });
|
||||
return;
|
||||
}
|
||||
14
test/fixtures/transformation/let-scoping/for-return-undefined/expected.js
vendored
Normal file
14
test/fixtures/transformation/let-scoping/for-return-undefined/expected.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
});
|
||||
return {
|
||||
v: undefined
|
||||
};
|
||||
})(i);
|
||||
|
||||
if (typeof _ret === "object") return _ret.v;
|
||||
}
|
||||
4
test/fixtures/transformation/let-scoping/for-return/actual.js
vendored
Normal file
4
test/fixtures/transformation/let-scoping/for-return/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
for (let i in nums) {
|
||||
fns.push(function () { return i; });
|
||||
return i;
|
||||
}
|
||||
14
test/fixtures/transformation/let-scoping/for-return/expected.js
vendored
Normal file
14
test/fixtures/transformation/let-scoping/for-return/expected.js
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
|
||||
for (var i in nums) {
|
||||
var _ret = (function (i) {
|
||||
fns.push(function () {
|
||||
return i;
|
||||
});
|
||||
return {
|
||||
v: i
|
||||
};
|
||||
})(i);
|
||||
|
||||
if (typeof _ret === "object") return _ret.v;
|
||||
}
|
||||
3
test/fixtures/transformation/let-scoping/function/actual.js
vendored
Normal file
3
test/fixtures/transformation/let-scoping/function/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function test() {
|
||||
let foo = "bar";
|
||||
}
|
||||
5
test/fixtures/transformation/let-scoping/function/expected.js
vendored
Normal file
5
test/fixtures/transformation/let-scoping/function/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function test() {
|
||||
var foo = "bar";
|
||||
}
|
||||
1
test/fixtures/transformation/let-scoping/program/actual.js
vendored
Normal file
1
test/fixtures/transformation/let-scoping/program/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
let test = "foo";
|
||||
3
test/fixtures/transformation/let-scoping/program/expected.js
vendored
Normal file
3
test/fixtures/transformation/let-scoping/program/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
var test = "foo";
|
||||
3
test/fixtures/transformation/misc/custom-runtime/actual.js
vendored
Normal file
3
test/fixtures/transformation/misc/custom-runtime/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function foo(...test) {
|
||||
|
||||
}
|
||||
5
test/fixtures/transformation/misc/custom-runtime/expected.js
vendored
Normal file
5
test/fixtures/transformation/misc/custom-runtime/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
var test = customNamespace.slice.call(arguments);
|
||||
}
|
||||
3
test/fixtures/transformation/misc/custom-runtime/options.json
vendored
Normal file
3
test/fixtures/transformation/misc/custom-runtime/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"runtime": "customNamespace"
|
||||
}
|
||||
3
test/fixtures/transformation/misc/property-literals/actual.js
vendored
Normal file
3
test/fixtures/transformation/misc/property-literals/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var obj = {
|
||||
"foobar": "lol"
|
||||
};
|
||||
5
test/fixtures/transformation/misc/property-literals/expected.js
vendored
Normal file
5
test/fixtures/transformation/misc/property-literals/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
var obj = {
|
||||
foobar: "lol"
|
||||
};
|
||||
3
test/fixtures/transformation/misc/runtime/actual.js
vendored
Normal file
3
test/fixtures/transformation/misc/runtime/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
function foo(...test) {
|
||||
|
||||
}
|
||||
5
test/fixtures/transformation/misc/runtime/expected.js
vendored
Normal file
5
test/fixtures/transformation/misc/runtime/expected.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
|
||||
function foo() {
|
||||
var test = to5Runtime.slice.call(arguments);
|
||||
}
|
||||
3
test/fixtures/transformation/misc/runtime/options.json
vendored
Normal file
3
test/fixtures/transformation/misc/runtime/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"runtime": true
|
||||
}
|
||||
3
test/fixtures/transformation/misc/shebang/actual.js
vendored
Normal file
3
test/fixtures/transformation/misc/shebang/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
foobar();
|
||||
4
test/fixtures/transformation/misc/shebang/expected.js
vendored
Normal file
4
test/fixtures/transformation/misc/shebang/expected.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
foobar();
|
||||
@@ -0,0 +1 @@
|
||||
<div> </div>;
|
||||
@@ -0,0 +1 @@
|
||||
React.createElement("div", null, "\u00A0 ");
|
||||
@@ -0,0 +1 @@
|
||||
<div> </div>;
|
||||
@@ -0,0 +1 @@
|
||||
React.createElement("div", null, "\u00A0");
|
||||
@@ -0,0 +1,13 @@
|
||||
var x = (
|
||||
<div>
|
||||
{/* A comment at the beginning */}
|
||||
{/* A second comment at the beginning */}
|
||||
<span>
|
||||
{/* A nested comment */}
|
||||
</span>
|
||||
{/* A sandwiched comment */}
|
||||
<br />
|
||||
{/* A comment at the end */}
|
||||
{/* A second comment at the end */}
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,11 @@
|
||||
var x = (React.createElement("div", null,
|
||||
/* A comment at the beginning */
|
||||
/* A second comment at the beginning */
|
||||
React.createElement("span", null
|
||||
/* A nested comment */
|
||||
),
|
||||
/* A sandwiched comment */
|
||||
React.createElement("br", null)
|
||||
/* A comment at the end */
|
||||
/* A second comment at the end */
|
||||
));
|
||||
10
test/fixtures/transformation/react/.should-properly-handle-comments-between-props/actual.js
vendored
Normal file
10
test/fixtures/transformation/react/.should-properly-handle-comments-between-props/actual.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
var x = (
|
||||
<div
|
||||
/* a multi-line
|
||||
comment */
|
||||
attr1="foo">
|
||||
<span // a double-slash comment
|
||||
attr2="bar"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
var x = (React.createElement("div", {
|
||||
/* a multi-line
|
||||
comment */
|
||||
attr1: "foo"},
|
||||
React.createElement("span", {// a double-slash comment
|
||||
attr2: "bar"}
|
||||
)
|
||||
));
|
||||
@@ -0,0 +1,3 @@
|
||||
<Component
|
||||
{...this.props}
|
||||
sound="moo" />
|
||||
@@ -0,0 +1,3 @@
|
||||
React.createElement(Component, React.__spread({}, this.props, {
|
||||
sound: "moo"
|
||||
}));
|
||||
@@ -1,5 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
var Component;
|
||||
Component = React.createClass({
|
||||
displayName: "Component",
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
var Whateva = React.createClass({
|
||||
displayName: "Whatever",
|
||||
render: function () {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
exports = {
|
||||
Component: React.createClass({
|
||||
displayName: "Component",
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
exports.Component = React.createClass({
|
||||
displayName: "Component",
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
var Component = React.createClass({
|
||||
displayName: "Component",
|
||||
|
||||
|
||||
3
test/fixtures/transformation/react/options.json
vendored
Normal file
3
test/fixtures/transformation/react/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"blacklist": ["useStrict"]
|
||||
}
|
||||
1
test/fixtures/transformation/react/should-allow-constructor-as-prop/actual.js
vendored
Normal file
1
test/fixtures/transformation/react/should-allow-constructor-as-prop/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<Component constructor="foo" />;
|
||||
3
test/fixtures/transformation/react/should-allow-constructor-as-prop/expected.js
vendored
Normal file
3
test/fixtures/transformation/react/should-allow-constructor-as-prop/expected.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
React.createElement(Component, {
|
||||
constructor: "foo"
|
||||
});
|
||||
1
test/fixtures/transformation/react/should-allow-deeper-js-namespacing/actual.js
vendored
Normal file
1
test/fixtures/transformation/react/should-allow-deeper-js-namespacing/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<Namespace.DeepNamespace.Component />;
|
||||
1
test/fixtures/transformation/react/should-allow-deeper-js-namespacing/expected.js
vendored
Normal file
1
test/fixtures/transformation/react/should-allow-deeper-js-namespacing/expected.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
React.createElement(Namespace.DeepNamespace.Component, null);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user