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

Commit 525a544

Browse files
soda0289JamesHenry
authored andcommitted
Fix: Set node type to ExperimentalRestProperty (fixes #276) (#279)
1 parent eb32fed commit 525a544

24 files changed

+4778
-19
lines changed

lib/convert.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -930,17 +930,26 @@ module.exports = function convert(config) {
930930
} else {
931931
return arrayItem;
932932
}
933-
} else {
933+
} else if (parent.kind === SyntaxKind.ObjectBindingPattern) {
934934

935-
Object.assign(result, {
936-
type: AST_NODE_TYPES.Property,
937-
key: convertChild(node.propertyName || node.name),
938-
value: convertChild(node.name),
939-
computed: false,
940-
method: false,
941-
shorthand: !node.propertyName,
942-
kind: "init"
943-
});
935+
if (node.dotDotDotToken) {
936+
Object.assign(result, {
937+
type: AST_NODE_TYPES.ExperimentalRestProperty,
938+
argument: convertChild(node.propertyName || node.name),
939+
computed: Boolean(node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName),
940+
shorthand: !node.propertyName
941+
});
942+
} else {
943+
Object.assign(result, {
944+
type: AST_NODE_TYPES.Property,
945+
key: convertChild(node.propertyName || node.name),
946+
value: convertChild(node.name),
947+
computed: Boolean(node.propertyName && node.propertyName.kind === SyntaxKind.ComputedPropertyName),
948+
method: false,
949+
shorthand: !node.propertyName,
950+
kind: "init"
951+
});
952+
}
944953

945954
if (node.initializer) {
946955
result.value = {
@@ -951,7 +960,6 @@ module.exports = function convert(config) {
951960
loc: nodeUtils.getLocFor(node.name.getStart(), node.initializer.end, ast)
952961
};
953962
}
954-
955963
}
956964
break;
957965

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

10551063
case SyntaxKind.SpreadElement:
1056-
case SyntaxKind.SpreadAssignment:
10571064
Object.assign(result, {
10581065
type: AST_NODE_TYPES.SpreadElement,
10591066
argument: convertChild(node.expression)
10601067
});
10611068
break;
1069+
case SyntaxKind.SpreadAssignment: {
1070+
let type = AST_NODE_TYPES.ExperimentalSpreadProperty;
1071+
1072+
if (node.parent &&
1073+
node.parent.parent.kind === SyntaxKind.BinaryExpression
1074+
) {
1075+
if (node.parent.parent.right === node.parent) {
1076+
type = AST_NODE_TYPES.ExperimentalSpreadProperty;
1077+
} else if (node.parent.parent.left === node.parent) {
1078+
type = AST_NODE_TYPES.ExperimentalRestProperty;
1079+
}
1080+
}
1081+
1082+
Object.assign(result, {
1083+
type,
1084+
argument: convertChild(node.expression)
1085+
});
1086+
break;
1087+
}
10621088

10631089
case SyntaxKind.Parameter: {
10641090
let parameter;

0 commit comments

Comments
 (0)