mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(types): Properly format nested test type docstrings (#36126)
This commit is contained in:
parent
111f21ebac
commit
6626bba937
3628
packages/playwright/types/test.d.ts
vendored
3628
packages/playwright/types/test.d.ts
vendored
File diff suppressed because it is too large
Load Diff
@ -92,7 +92,7 @@ class TypesGenerator {
|
||||
return '';
|
||||
handledClasses.add(className);
|
||||
return this.writeComment(docClass.comment, '') + '\n';
|
||||
}, (className, methodName, overloadIndex) => {
|
||||
}, (className, methodName, overloadIndex, indent) => {
|
||||
if (methodName === '__call')
|
||||
methodName = '(call)';
|
||||
const docClass = this.docClassForName(className);
|
||||
@ -110,7 +110,7 @@ class TypesGenerator {
|
||||
return '';
|
||||
throw new Error(`Unknown override method "${className}.${methodName}"`);
|
||||
}
|
||||
return this.memberJSDOC(method, ' ').trimLeft();
|
||||
return this.memberJSDOC(method, indent).trimLeft();
|
||||
}, (className) => {
|
||||
const docClass = this.docClassForName(className);
|
||||
if (!docClass || !this.shouldGenerate(docClass.name))
|
||||
|
@ -20,7 +20,7 @@ const ts = require('typescript');
|
||||
/**
|
||||
* @param {string} filePath
|
||||
* @param {(className: string) => string} commentForClass
|
||||
* @param {(className: string, methodName: string, overloadIndex: number) => string} commentForMethod
|
||||
* @param {(className: string, methodName: string, overloadIndex: number, indent: string) => string} commentForMethod
|
||||
* @param {(className: string) => string} extraForClass
|
||||
*/
|
||||
async function parseOverrides(filePath, commentForClass, commentForMethod, extraForClass) {
|
||||
@ -42,6 +42,18 @@ async function parseOverrides(filePath, commentForClass, commentForMethod, extra
|
||||
}
|
||||
return src;
|
||||
|
||||
/**
|
||||
* @param {number} pos
|
||||
* @returns {string}
|
||||
*/
|
||||
function getIndentationAtPos(pos) {
|
||||
const text = file.text;
|
||||
const lineStart = text.lastIndexOf('\n', pos - 1) + 1;
|
||||
const textBeforeNodeOnLine = text.substring(lineStart, pos);
|
||||
const match = textBeforeNodeOnLine.match(/^(\s*)/);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!ts.Node} node
|
||||
*/
|
||||
@ -83,7 +95,7 @@ async function parseOverrides(filePath, commentForClass, commentForMethod, extra
|
||||
const pos = declaration.getStart(file, false);
|
||||
replacers.push({
|
||||
pos,
|
||||
text: commentForMethod(className, name, index),
|
||||
text: commentForMethod(className, name, index, getIndentationAtPos(pos)),
|
||||
});
|
||||
if (ts.isPropertySignature(declaration))
|
||||
ts.forEachChild(declaration, child => visitProperties(className, name, child));
|
||||
@ -108,14 +120,14 @@ async function parseOverrides(filePath, commentForClass, commentForMethod, extra
|
||||
const pos = node.getStart(file, false);
|
||||
replacers.push({
|
||||
pos,
|
||||
text: commentForMethod(className, `${prefix}.${name}`, 0),
|
||||
text: commentForMethod(className, `${prefix}.${name}`, 0, getIndentationAtPos(pos)),
|
||||
});
|
||||
ts.forEachChild(node, child => visitProperties(className, `${prefix}.${name}`, child));
|
||||
} else if (ts.isCallSignatureDeclaration(node)) {
|
||||
const pos = node.getStart(file, false);
|
||||
replacers.push({
|
||||
pos,
|
||||
text: commentForMethod(className, `${prefix}`, 0),
|
||||
text: commentForMethod(className, `${prefix}`, 0, getIndentationAtPos(pos)),
|
||||
});
|
||||
} else if (ts.isIntersectionTypeNode(node) || ts.isTypeLiteralNode(node)) {
|
||||
ts.forEachChild(node, child => visitProperties(className, prefix, child));
|
||||
|
Loading…
x
Reference in New Issue
Block a user