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

feat: fix regression in TSTypeParameter node #111

Merged
merged 1 commit 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
2 changes: 1 addition & 1 deletion src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
case SyntaxKind.TypeParameter: {
Object.assign(result, {
type: AST_NODE_TYPES.TSTypeParameter,
name: node.name.text,
name: convertChildType(node.name),
constraint: node.constraint
? convertChildType(node.constraint)
: undefined,
Expand Down
24 changes: 24 additions & 0 deletions tests/ast-alignment/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import isPlainObject from 'lodash.isplainobject';
import { AST_NODE_TYPES } from '../../src/ast-node-types';

/**
* By default, pretty-format (within Jest matchers) retains the names/types of nodes from the babylon AST,
Expand Down Expand Up @@ -194,6 +195,29 @@ export function preprocessBabylonAST(ast: any): any {
node.params = node.parameters;
delete node.parameters;
}
},
/**
* We want this node to be different
* @see https://github.com/JamesHenry/typescript-estree/issues/109
*/
TSTypeParameter(node: any) {
Copy link
Contributor Author

@armano2 armano2 Jan 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was able to transform babel node TSTypeParameter[name] to Identifier, and we still can do alignment tests for other parts of AST

if (node.name) {
node.name = {
loc: {
start: {
column: node.loc.start.column,
line: node.loc.start.line
},
end: {
column: node.loc.start.column + node.name.length,
line: node.loc.start.line
}
},
name: node.name,
range: [node.range[0], node.range[0] + node.name.length],
type: AST_NODE_TYPES.Identifier
};
}
}
}
);
Expand Down
Loading