Add missing return types for babel__traverse unshiftContainer and replaceWithMultiple (#42407)

* Add missing return types

* try this

* Fix test

* babel core depends on babel traverse

* increase ts version on plugin-macros

* this should be the last one depending on babel/traverse

* try a rerun

* trigger a rerun
This commit is contained in:
Jan Potoms
2020-02-20 19:25:41 +01:00
committed by GitHub
parent 007b40797f
commit 4fccaa038e
5 changed files with 58 additions and 6 deletions

View File

@@ -3,7 +3,8 @@
// Definitions by: Billy Kwok <https://github.com/billykwok>
// Jake Runzer <https://github.com/coffee-cup>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
// Minimum TypeScript Version: 3.4
import * as Babel from '@babel/core';
export interface References {

View File

@@ -5,7 +5,7 @@
// Melvin Groenhoff <https://github.com/mgroenhoff>
// Jessica Franco <https://github.com/Jessidhia>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
// Minimum TypeScript Version: 3.4
import { GeneratorOptions } from "@babel/generator";
import traverse, { Visitor, NodePath } from "@babel/traverse";

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/babel/babel/tree/master/packages/babel-standalone
// Definitions by: Matheus Goncalves da Silva <https://github.com/PlayMa256>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
// Minimum TypeScript Version: 3.4
import { TransformOptions, types, FileResultCallback } from '@babel/core';

View File

@@ -99,6 +99,55 @@ const v1: Visitor = {
path.scope.rename("n", "x");
path.scope.rename("n");
},
ExportDefaultDeclaration(path) {
{
const [stringPath, booleanPath] = path.replaceWithMultiple([
t.stringLiteral('hello'),
t.booleanLiteral(false)
]);
// $ExpectType NodePath<BooleanLiteral | StringLiteral>
stringPath;
// $ExpectType NodePath<BooleanLiteral | StringLiteral>
booleanPath;
}
{
const [stringPath, booleanPath] = path.replaceWithMultiple<[t.StringLiteral, t.BooleanLiteral]>([
t.stringLiteral('hello'),
t.booleanLiteral(false)
]);
// $ExpectType NodePath<StringLiteral>
stringPath;
// $ExpectType NodePath<BooleanLiteral>
booleanPath;
}
},
Program(path) {
{
const [newPath] = path.unshiftContainer('body', t.stringLiteral('hello'));
// $ExpectType NodePath<StringLiteral>
newPath;
}
{
const [stringPath, booleanPath] = path.unshiftContainer('body', [
t.stringLiteral('hello'),
t.booleanLiteral(false)
]);
// $ExpectType NodePath<BooleanLiteral | StringLiteral>
stringPath;
// $ExpectType NodePath<BooleanLiteral | StringLiteral>
booleanPath;
}
{
const [stringPath, booleanPath] = path.unshiftContainer<[t.StringLiteral, t.BooleanLiteral]>('body', [
t.stringLiteral('hello'),
t.booleanLiteral(false)
]);
// $ExpectType NodePath<StringLiteral>
stringPath;
// $ExpectType NodePath<BooleanLiteral>
booleanPath;
}
}
};

View File

@@ -6,7 +6,7 @@
// Melvin Groenhoff <https://github.com/mgroenhoff>
// Dean L. <https://github.com/dlgrit>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
// Minimum TypeScript Version: 3.4
import * as t from "@babel/types";
@@ -171,6 +171,8 @@ export interface VisitNodeObject<S, P> {
exit?: VisitNodeFunction<S, P>;
}
export type NodePaths<T extends Node | Node[]> = T extends Node[] ? { [K in keyof T]: NodePath<T[K]> } : [NodePath<T>];
export class NodePath<T = Node> {
constructor(hub: Hub, parent: Node);
parent: Node;
@@ -272,7 +274,7 @@ export class NodePath<T = Node> {
* - Insert the provided nodes after the current node.
* - Remove the current node.
*/
replaceWithMultiple(nodes: Node[]): void;
replaceWithMultiple<Nodes extends Node[]>(nodes: Nodes): NodePaths<Nodes>;
/**
* Parse a string as an expression and replace the current node with the result.
@@ -433,7 +435,7 @@ export class NodePath<T = Node> {
* @param listKey - The key at which the child nodes are stored (usually body).
* @param nodes - the nodes to insert.
*/
unshiftContainer(listKey: string, nodes: Node | Node[]): void;
unshiftContainer<Nodes extends Node | Node[]>(listKey: string, nodes: Nodes): NodePaths<Nodes>;
/**
* Insert child nodes at the end of the current node.