mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #65868 [mvdan-sh] Add typings and tests for Parser's interactive methods by @Rossil2012
* Add missing typings for class Parser * Add tests for Parser's interactive methods
This commit is contained in:
5
types/mvdan-sh/index.d.ts
vendored
5
types/mvdan-sh/index.d.ts
vendored
@@ -3,6 +3,8 @@
|
||||
// Definitions by: JounQin <https://github.com/JounQin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
// eslint-disable-next-line no-const-enum
|
||||
declare const enum LangVariant {
|
||||
LangBash = 0,
|
||||
@@ -70,6 +72,9 @@ declare namespace sh {
|
||||
|
||||
interface Parser {
|
||||
Parse(text: string, path?: string): File;
|
||||
Interactive(r: { read: (size?: number) => string | Buffer | null }, fn: (stmts: Stmt[]) => boolean): void;
|
||||
InteractiveStep(line: string): Stmt[];
|
||||
Incomplete(): boolean;
|
||||
}
|
||||
|
||||
interface Printer {
|
||||
|
||||
@@ -27,3 +27,31 @@ syntax
|
||||
syntax.FunctionNextLine(false),
|
||||
)
|
||||
.Print(node);
|
||||
|
||||
// Test the methods of Parser.
|
||||
// The following tests are ported from https://github.com/mvdan/sh/blob/master/_js/testmain.js
|
||||
const parser = syntax.NewParser();
|
||||
const lines = [
|
||||
"foo\n",
|
||||
"bar; baz\n"
|
||||
];
|
||||
|
||||
// Test parser.InteractiveStep
|
||||
for (const line of lines) {
|
||||
const stmts = parser.InteractiveStep(line); // $ExpectType Stmt[]
|
||||
}
|
||||
|
||||
const src = {
|
||||
read: (size?: number): string | null => {
|
||||
if (lines.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return lines.shift()!;
|
||||
}
|
||||
};
|
||||
|
||||
// Test parser.Interactive && parser.Incomplete
|
||||
parser.Interactive(src, (stmts: sh.Stmt[]) => {
|
||||
const incomplete = parser.Incomplete(); // $ExpectType boolean
|
||||
return true;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user