add a "spec" transformer namespace for transformers that nicen up code and make it well, more spec compliant
This commit is contained in:
parent
1c22c608a9
commit
e6da342e8b
@ -20,16 +20,21 @@ transform._ensureTransformerNames = function (type, keys) {
|
||||
transform.transformers = {};
|
||||
|
||||
transform.moduleFormatters = {
|
||||
common: require("./modules/common"),
|
||||
commonInterop: require("./modules/common-interop"),
|
||||
system: require("./modules/system"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
commonStrict: require("./modules/common-strict"),
|
||||
common: require("./modules/common"),
|
||||
system: require("./modules/system"),
|
||||
ignore: require("./modules/ignore"),
|
||||
amd: require("./modules/amd"),
|
||||
umd: require("./modules/umd")
|
||||
};
|
||||
|
||||
_.each({
|
||||
// plyground
|
||||
// spec
|
||||
_blockHoistFunctions: require("./transformers/spec-block-hoist-functions"),
|
||||
_noForInOfAssignment: require("./transformers/spec-no-for-in-of-assignment"),
|
||||
_noDuplicateProperties: require("./transformers/spec-no-duplicate-properties"),
|
||||
|
||||
// playground
|
||||
methodBinding: require("./transformers/playground-method-binding"),
|
||||
memoizationOperator: require("./transformers/playground-memoization-operator"),
|
||||
objectGetterMemoization: require("./transformers/playground-object-getter-memoization"),
|
||||
@ -59,16 +64,18 @@ _.each({
|
||||
constants: require("./transformers/es6-constants"),
|
||||
letScoping: require("./transformers/es6-let-scoping"),
|
||||
|
||||
generators: require("./transformers/es6-generators"),
|
||||
|
||||
_blockHoist: require("./transformers/_block-hoist"),
|
||||
_declarations: require("./transformers/_declarations"),
|
||||
|
||||
generators: require("./transformers/es6-generators"),
|
||||
|
||||
// spec
|
||||
_propertyLiterals: require("./transformers/spec-property-literals"),
|
||||
_memberExpressioLiterals: require("./transformers/spec-member-expression-literals"),
|
||||
|
||||
// wrap up
|
||||
_aliasFunctions: require("./transformers/_alias-functions"),
|
||||
|
||||
useStrict: require("./transformers/use-strict"),
|
||||
|
||||
_propertyLiterals: require("./transformers/_property-literals"),
|
||||
_memberExpressioLiterals: require("./transformers/_member-expression-literals"),
|
||||
_moduleFormatter: require("./transformers/_module-formatter")
|
||||
}, function (transformer, key) {
|
||||
transform.transformers[key] = new Transformer(key, transformer);
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.BlockStatement = function (node, parent) {
|
||||
if (t.isFunction(parent)) return;
|
||||
|
||||
node.body = node.body.map(function (node) {
|
||||
if (t.isFunction(node)) {
|
||||
node.type = "FunctionExpression";
|
||||
var declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, node)
|
||||
]);
|
||||
declar._blockHoist = true;
|
||||
return declar;
|
||||
} else {
|
||||
return node;
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -0,0 +1,25 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
exports.ObjectExpression = function (node, parent, file) {
|
||||
var keys = [];
|
||||
|
||||
_.each(node.properties, function (prop) {
|
||||
if (prop.computed || prop.kind !== "init") return;
|
||||
|
||||
var key = prop.key;
|
||||
if (t.isIdentifier(key)) {
|
||||
key = key.name;
|
||||
} else if (t.isLiteral(key)) {
|
||||
key = key.value;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_.contains(keys, key)) {
|
||||
throw file.errorWithNode(prop.key, "Duplicate property key");
|
||||
} else {
|
||||
keys.push(key);
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -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");
|
||||
}
|
||||
};
|
||||
@ -1,3 +0,0 @@
|
||||
var obj = {
|
||||
"foobar": "lol"
|
||||
};
|
||||
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var obj = {
|
||||
foobar: "lol"
|
||||
};
|
||||
1
test/fixtures/transformation/spec-no-duplicate-properties/identifiers/actual.js
vendored
Normal file
1
test/fixtures/transformation/spec-no-duplicate-properties/identifiers/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var obj = { a: 1, a: 2 };
|
||||
1
test/fixtures/transformation/spec-no-duplicate-properties/literals/actual.js
vendored
Normal file
1
test/fixtures/transformation/spec-no-duplicate-properties/literals/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var obj = { "a": 1, "a": 2 };
|
||||
1
test/fixtures/transformation/spec-no-duplicate-properties/mixed/actual.js
vendored
Normal file
1
test/fixtures/transformation/spec-no-duplicate-properties/mixed/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var obj = { a: 1, "a": 2 };
|
||||
3
test/fixtures/transformation/spec-no-duplicate-properties/options.json
vendored
Normal file
3
test/fixtures/transformation/spec-no-duplicate-properties/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Duplicate property key"
|
||||
}
|
||||
3
test/fixtures/transformation/spec-no-for-in-of-assignment/in/actual.js
vendored
Normal file
3
test/fixtures/transformation/spec-no-for-in-of-assignment/in/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
for (var i = 0 in obj) {
|
||||
|
||||
}
|
||||
3
test/fixtures/transformation/spec-no-for-in-of-assignment/of/actual.js
vendored
Normal file
3
test/fixtures/transformation/spec-no-for-in-of-assignment/of/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
for (var i = 0 of obj) {
|
||||
|
||||
}
|
||||
3
test/fixtures/transformation/spec-no-for-in-of-assignment/options.json
vendored
Normal file
3
test/fixtures/transformation/spec-no-for-in-of-assignment/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "No assignments allowed in for-in/of head"
|
||||
}
|
||||
5
test/fixtures/transformation/spec/block-hoist-functions/exec.js
vendored
Normal file
5
test/fixtures/transformation/spec/block-hoist-functions/exec.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
function f() { return 1; }
|
||||
{
|
||||
function f() { return 2; }
|
||||
}
|
||||
assert.equal(f(), 1);
|
||||
Loading…
x
Reference in New Issue
Block a user