Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Fix: Set node type to ExperimentalRestProperty (fixes #276) #279

Merged
merged 2 commits into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,17 +930,26 @@ module.exports = function convert(config) {
} else {
return arrayItem;
}
} else {
} else if (parent.kind === SyntaxKind.ObjectBindingPattern) {

Object.assign(result, {
type: AST_NODE_TYPES.Property,
key: convertChild(node.propertyName || node.name),
value: convertChild(node.name),
computed: false,
method: false,
shorthand: !node.propertyName,
kind: "init"
});
if (node.dotDotDotToken) {
Object.assign(result, {
type: AST_NODE_TYPES.ExperimentalRestProperty,
argument: convertChild(node.propertyName || node.name),
computed: Boolean(node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName),
shorthand: !node.propertyName
});
} else {
Object.assign(result, {
type: AST_NODE_TYPES.Property,
key: convertChild(node.propertyName || node.name),
value: convertChild(node.name),
computed: Boolean(node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName),
method: false,
shorthand: !node.propertyName,
kind: "init"
});
}

if (node.initializer) {
result.value = {
Expand All @@ -951,7 +960,6 @@ module.exports = function convert(config) {
loc: nodeUtils.getLocFor(node.name.getStart(), node.initializer.end, ast)
};
}

}
break;

Expand Down Expand Up @@ -1053,12 +1061,30 @@ module.exports = function convert(config) {
// Patterns

case SyntaxKind.SpreadElement:
case SyntaxKind.SpreadAssignment:
Object.assign(result, {
type: AST_NODE_TYPES.SpreadElement,
argument: convertChild(node.expression)
});
break;
case SyntaxKind.SpreadAssignment: {
let type = AST_NODE_TYPES.ExperimentalSpreadProperty;

if (node.parent &&
node.parent.parent.kind === SyntaxKind.BinaryExpression
) {
if (node.parent.parent.right === node.parent) {
type = AST_NODE_TYPES.ExperimentalSpreadProperty;
} else if (node.parent.parent.left === node.parent) {
type = AST_NODE_TYPES.ExperimentalRestProperty;
}
}

Object.assign(result, {
type,
argument: convertChild(node.expression)
});
break;
}

case SyntaxKind.Parameter: {
let parameter;
Expand Down
Loading