move transformers over to using ast-types when constructing new nodes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
var util = require("../util");
|
||||
var b = require("ast-types").builders;
|
||||
var _ = require("lodash");
|
||||
|
||||
var isPattern = function (id) {
|
||||
@@ -20,15 +21,9 @@ exports.VariableDeclaration = function (node, parent, opts, generateUid) {
|
||||
//
|
||||
|
||||
var buildVariableAssign = function (id, init) {
|
||||
return {
|
||||
type: "VariableDeclaration",
|
||||
kind: node.kind,
|
||||
declarations: [{
|
||||
type: "VariableDeclarator",
|
||||
id: id,
|
||||
init: init
|
||||
}]
|
||||
};
|
||||
return b.variableDeclaration(node.kind, [
|
||||
b.variableDeclarator(id, init)
|
||||
]);
|
||||
};
|
||||
|
||||
var push = function (pattern, parentId) {
|
||||
@@ -43,11 +38,7 @@ exports.VariableDeclaration = function (node, parent, opts, generateUid) {
|
||||
_.each(pattern.properties, function (prop) {
|
||||
var id = prop.value;
|
||||
|
||||
var init = {
|
||||
type: "MemberExpression",
|
||||
object: parentId,
|
||||
property: prop.key
|
||||
};
|
||||
var init = b.memberExpression(parentId, prop.key, false);
|
||||
|
||||
if (isPattern(id)) {
|
||||
push(id, init);
|
||||
@@ -59,15 +50,7 @@ exports.VariableDeclaration = function (node, parent, opts, generateUid) {
|
||||
|
||||
var pushArrayPattern = function (pattern, parentId) {
|
||||
_.each(pattern.elements, function (id, i) {
|
||||
var init = {
|
||||
type: "MemberExpression",
|
||||
computed: true,
|
||||
object: parentId,
|
||||
property: {
|
||||
type: "Literal",
|
||||
value: i
|
||||
}
|
||||
};
|
||||
var init = b.memberExpression(parentId, b.literal(i), true);
|
||||
|
||||
if (id.type === "Identifier") {
|
||||
nodes.push(buildVariableAssign(id, init));
|
||||
@@ -86,10 +69,7 @@ exports.VariableDeclaration = function (node, parent, opts, generateUid) {
|
||||
VALUE: init
|
||||
}, true));
|
||||
|
||||
init = {
|
||||
type: "Identifier",
|
||||
name: key
|
||||
};
|
||||
init = b.identifier(key);
|
||||
}
|
||||
|
||||
push(id, init);
|
||||
|
||||
Reference in New Issue
Block a user