Compare commits

..

12 Commits

Author SHA1 Message Date
Sebastian McKenzie
4763b95a0d v3.3.2 2015-02-02 01:43:47 +11:00
Sebastian McKenzie
9fe1e37ca7 fix t.buildMatchMemberExpression 2015-02-02 01:41:39 +11:00
Sebastian McKenzie
8a9aac3e68 fix linting errors 2015-02-02 01:37:27 +11:00
Sebastian McKenzie
27138abd29 simplify member expression checking, flesh out react component optimiser #653 2015-02-02 01:30:06 +11:00
Sebastian McKenzie
dcf91db475 add react component optimisation base #653 2015-02-02 00:50:25 +11:00
Sebastian McKenzie
ab63345764 3.3.1 2015-02-01 18:44:46 +11:00
Sebastian McKenzie
a35e63fb29 v3.3.1 2015-02-01 18:44:07 +11:00
Sebastian McKenzie
3fe7df9a48 fix regenerator destructuring test 2015-02-01 18:42:15 +11:00
Sebastian McKenzie
5288f3afda add 3.3.1 changelog 2015-02-01 18:33:54 +11:00
Sebastian McKenzie
25566a24f6 block hoist assignment pattern destructuring - fixes #652 2015-02-01 18:33:36 +11:00
Sebastian McKenzie
2ff6dee0ec 3.3.0 2015-02-01 16:52:23 +11:00
Sebastian McKenzie
491d1238c2 fix buildHelpers function name 2015-02-01 16:51:57 +11:00
14 changed files with 265 additions and 33 deletions

View File

@@ -11,6 +11,11 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 3.3.1
* **Bug Fix**
* Block hoist assignment pattern destructuring.
## 3.3.0
* **Bug Fix**

View File

@@ -0,0 +1,22 @@
var t = require("../../types");
var isCreateClassCallExpression = t.buildMatchMemberExpression("React.createClass");
exports.isCreateClass = function (node) {
if (!node || !t.isCallExpression(node)) return false;
// not React.createClass call member object
if (!isCreateClassCallExpression(node.callee)) return false;
// no call arguments
var args = node.arguments;
if (args.length !== 1) return false;
// first node arg is not an object
var first = args[0];
if (!t.isObjectExpression(first)) return false;
return true;
};
exports.isReactComponent = t.buildMatchMemberExpression("React.Component");

View File

@@ -46,9 +46,11 @@ var push = function (opts, nodes, elem, parentId) {
var pushAssignmentPattern = function (opts, nodes, pattern, parentId) {
var tempParentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
nodes.push(t.variableDeclaration("var", [
var declar = t.variableDeclaration("var", [
t.variableDeclarator(tempParentId, parentId)
]));
]);
declar._blockHoist = opts.blockHoist;
nodes.push(declar);
nodes.push(buildVariableAssign(
opts,

View File

@@ -12,6 +12,7 @@ module.exports = {
"playground.objectGetterMemoization": require("./playground/object-getter-memoization"),
react: require("./other/react"),
"optimisation.react": require("./optimisation/react"),
_modules: require("./internal/modules"),

View File

@@ -0,0 +1,55 @@
module.exports = BaseOptimiser;
var object = require("../../../../helpers/object");
/**
* Description
*
* @param {Node} node
*/
function BaseOptimiser(node) {
this.methods = object();
this.types = object();
this.node = node;
}
/**
* Description
*/
BaseOptimiser.prototype.run = function () {
this.getMethods();
this.getTypes();
};
/**
* Add an `ObjectExpression` `node` that contains `propTypes`.
*
* Search it and match it against the types that we can optimise
* and register it for consumption later.
*
* @param {Node} node
*/
BaseOptimiser.prototype.addPropTypes = function (node) {
var props = node.properties;
for (var i = 0; i < props.length; i++) {
this.addPropType(props[i]);
}
};
/**
* Register a `Property` node as a prop type.
*
* We'll try and resolve it to a known type if we can and normalise
* it for consumption later.
*
* @param {Node} prop
*/
BaseOptimiser.prototype.addPropType = function () {
};

View File

@@ -0,0 +1,51 @@
module.exports = CreateClassOptimiser;
var BaseOptimiser = require("./base");
var util = require("../../../../util");
var t = require("../../../../types");
function CreateClassOptimiser() {
BaseOptimiser.apply(this, arguments);
}
util.inherits(CreateClassOptimiser, BaseOptimiser);
/**
* Get all function expressions.
*/
CreateClassOptimiser.prototype.getMethods = function () {
var props = this.node.properties;
for (var i = 0; i < props.length; i++) {
var prop = props[i];
// irrelevant
if (!t.isFunctionExpression(prop.value)) continue;
// deopt
if (prop.computed) continue;
this.methods[prop.key.name] = prop;
}
};
/**
* Find a `propTypes` property.
*/
CreateClassOptimiser.prototype.getTypes = function () {
var props = this.node.properties;
for (var i = 0; i < props.length; i++) {
var prop = props[i];
var key = t.toComputedKey(prop, prop.key);
if (t.isLiteral(key, { value: "propTypes" }) && t.isObjectExpression(prop.value)) {
this.addPropTypes(prop.value);
return;
}
}
// not found
};

View File

@@ -0,0 +1,17 @@
var CreateClassOptimiser = require("./create-class");
var NativeClassOptimiser = require("./native-class");
var react = require("../../../helpers/react");
exports.optional = true;
exports.CallExpression = function (node) {
if (react.isCreateClass(node)) {
new CreateClassOptimiser(node.arguments[0]).run();
}
};
exports.CallExpression = function (node) {
if (react.isReactComponent(node.superClass)) {
new NativeClassOptimiser(node).run();
}
};

View File

@@ -0,0 +1,42 @@
module.exports = NativeClassOptimiser;
var BaseOptimiser = require("./base");
var util = require("../../../../util");
var t = require("../../../../types");
function NativeClassOptimiser() {
BaseOptimiser.apply(this, arguments);
}
util.inherits(NativeClassOptimiser, BaseOptimiser);
/**
* Get all instance methods.
*/
NativeClassOptimiser.prototype.getMethods = function () {
var body = this.node.body;
for (var i = 0; i < body.length; i++) {
var node = body[i];
// PrivateDeclaration etc
if (!t.isMethodDefinition(node)) continue;
// deopt
if (node.computed) continue;
// irrelevant
if (node.static) continue;
this.methods[node.key.name] = node;
}
};
/**
* Description
*/
NativeClassOptimiser.prototype.getTypes = function () {
};

View File

@@ -6,6 +6,7 @@
// jsx
var esutils = require("esutils");
var react = require("../../helpers/react");
var t = require("../../../types");
exports.JSXIdentifier = function (node, parent) {
@@ -197,33 +198,8 @@ var cleanJSXElementLiteralChild = function (child, args) {
// display names
var isCreateClass = function (call) {
if (!call || !t.isCallExpression(call)) return false;
var callee = call.callee;
if (!t.isMemberExpression(callee)) return false;
// not React call member object
var obj = callee.object;
if (!t.isIdentifier(obj, { name: "React" })) return false;
// not createClass call member property
var prop = callee.property;
if (!t.isIdentifier(prop, { name: "createClass" })) return false;
// no call arguments
var args = call.arguments;
if (args.length !== 1) return false;
// first call arg is not an object
var first = args[0];
if (!t.isObjectExpression(first)) return;
return true;
};
var addDisplayName = function (id, call) {
if (!isCreateClass(call)) return;
if (!react.isCreateClass(call)) return;
var props = call.arguments[0].properties;
var safe = true;

View File

@@ -399,6 +399,60 @@ t.ensureBlock = function (node, key) {
node[key] = t.toBlock(node[key], node);
};
/**
* Build a function that when called will return whether or not the
* input `node` `MemberExpression` matches the input `match`.
*
* For example, given the match `React.createClass` it would match the
* parsed nodes of `React.createClass` and `React["createClass"]`.
*
* @param {String} match Dot delimetered string
* @returns {Function}
*/
t.buildMatchMemberExpression = function (match) {
var parts = match.split(".");
return function (member) {
// not a member expression
if (!t.isMemberExpression(member)) return false;
var search = [member];
var i = 0;
while (search.length) {
var node = search.shift();
if (t.isIdentifier(node)) {
// this part doesn't match
if (parts[i] !== node.name) return false;
} else if (t.isLiteral(node)) {
// this part doesn't match
if (parts[i] !== node.value) return false;
} else if (t.isMemberExpression(node)) {
if (node.computed && !t.isLiteral(node.property)) {
// we can't deal with this
return false;
} else {
search.push(node.object);
search.push(node.property);
continue;
}
} else {
// we can't deal with this
return false;
}
// too many parts
if (++i > parts.length) {
return false;
}
}
return true;
};
};
/**
* Description
*

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "3.3.0",
"version": "3.3.2",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://6to5.org/",
"repository": "6to5/6to5",

View File

@@ -1,7 +1,7 @@
{
"name": "6to5-runtime",
"description": "6to5 selfContained runtime",
"version": "3.2.1",
"version": "3.3.1",
"repository": "6to5/6to5",
"author": "Sebastian McKenzie <sebmck@gmail.com>"
}

View File

@@ -30,7 +30,7 @@ var updatePackage = function () {
writeFile("package.json", JSON.stringify(pkg, null, 2));
};
var buildHelpers = function () {
var buildHelpers2 = function () {
var body = [];
var tree = t.program(body);
@@ -41,7 +41,7 @@ var buildHelpers = function () {
}).code;
};
writeFile("helpers.js", buildHelpers());
writeFile("helpers.js", buildHelpers2());
writeFile("core-js.js", readFile("core-js/library"));
writeFile("regenerator/index.js", readFile("regenerator-6to5/runtime-module"));
writeFile("regenerator/runtime.js", readFile("regenerator-6to5/runtime"));

View File

@@ -3,4 +3,11 @@ function* foo() {
return bar;
}
assert.deepEqual(foo().next().value, "bar");
assert.equal(foo().next().value, "bar");
function* foo2({ bar = 0 }) {
return bar;
}
assert.equal(foo2({ bar: undefined }).next().value, 0);
assert.equal(foo2({ bar: 3 }).next().value, 3);