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

feat: rest element should contain information about type annotation #108

Merged
merged 2 commits into from
Jan 10, 2019
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
17 changes: 8 additions & 9 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,34 +1435,33 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
}

case SyntaxKind.Parameter: {
let parameter;
let parameter: ESTreeNode;

if (node.dotDotDotToken) {
parameter = convertChild(node.name);
Object.assign(result, {
type: AST_NODE_TYPES.RestElement,
argument: parameter
argument: convertChild(node.name)
});
parameter = result;
} else if (node.initializer) {
parameter = convertChild(node.name);
parameter = convertChild(node.name)!;
Object.assign(result, {
type: AST_NODE_TYPES.AssignmentPattern,
left: parameter,
right: convertChild(node.initializer)
});
} else {
parameter = convert({
parameter = result = convert({
node: node.name,
parent,
ast,
additionalOptions
});
(result as any) = parameter;
})!;
}

if (node.type) {
parameter!.typeAnnotation = convertTypeAnnotation(node.type);
fixTypeAnnotationParentLocation(parameter!);
parameter.typeAnnotation = convertTypeAnnotation(node.type);
fixTypeAnnotationParentLocation(parameter);
}

if (node.questionToken) {
Expand Down
5 changes: 1 addition & 4 deletions tests/ast-alignment/fixtures-to-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ tester.addFixturePatternConfig('typescript/basics', {
'class-with-implements-generic',
'class-with-implements',
'class-with-extends-and-implements',
'class-with-mixin',
/**
* Babel error: parameterName is not included into range of TSTypeAnnotation
* TODO: report it to babel
Expand All @@ -363,8 +364,6 @@ tester.addFixturePatternConfig('typescript/basics', {
/**
* Other major AST differences (e.g. fundamentally different node types)
*/
'class-with-mixin',
'function-with-types-assignation',
'interface-extends-multiple',
'interface-extends',
'interface-type-parameters',
Expand Down Expand Up @@ -499,8 +498,6 @@ tester.addFixturePatternConfig('typescript/types', {
/**
* AST difference
*/
'function-with-rest',
'constructor-with-rest',
'index-signature',
'index-signature-readonly',
'literal-number-negative'
Expand Down
Loading