mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-11 06:02:53 -05:00
fix(48887) exposing rest helper functions externally (#48888)
* fix(48887) exposing rest helper functions externally * fixing baseline + adding hint about how to fix baseline * Update src/harness/harnessIO.ts Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
This commit is contained in:
@@ -2866,16 +2866,6 @@ namespace ts {
|
||||
return typeParameters && find(typeParameters, p => p.name.escapedText === name);
|
||||
}
|
||||
|
||||
export function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean {
|
||||
const last = lastOrUndefined<ParameterDeclaration | JSDocParameterTag>(s.parameters);
|
||||
return !!last && isRestParameter(last);
|
||||
}
|
||||
|
||||
export function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean {
|
||||
const type = isJSDocParameterTag(node) ? (node.typeExpression && node.typeExpression.type) : node.type;
|
||||
return (node as ParameterDeclaration).dotDotDotToken !== undefined || !!type && type.kind === SyntaxKind.JSDocVariadicType;
|
||||
}
|
||||
|
||||
export function hasTypeArguments(node: Node): node is HasTypeArguments {
|
||||
return !!(node as HasTypeArguments).typeArguments;
|
||||
}
|
||||
|
||||
@@ -2015,5 +2015,16 @@ namespace ts {
|
||||
export function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain {
|
||||
return node.kind === SyntaxKind.JSDocLink || node.kind === SyntaxKind.JSDocLinkCode || node.kind === SyntaxKind.JSDocLinkPlain;
|
||||
}
|
||||
|
||||
export function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean {
|
||||
const last = lastOrUndefined<ParameterDeclaration | JSDocParameterTag>(s.parameters);
|
||||
return !!last && isRestParameter(last);
|
||||
}
|
||||
|
||||
export function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean {
|
||||
const type = isJSDocParameterTag(node) ? (node.typeExpression && node.typeExpression.type) : node.type;
|
||||
return (node as ParameterDeclaration).dotDotDotToken !== undefined || !!type && type.kind === SyntaxKind.JSDocVariadicType;
|
||||
}
|
||||
|
||||
// #endregion
|
||||
}
|
||||
|
||||
@@ -1389,22 +1389,27 @@ namespace Harness {
|
||||
else {
|
||||
IO.writeFile(actualFileName, encodedActual);
|
||||
}
|
||||
const errorMessage = getBaselineFileChangedErrorMessage(relativeFileName);
|
||||
if (!!require && opts && opts.PrintDiff) {
|
||||
const Diff = require("diff");
|
||||
const patch = Diff.createTwoFilesPatch("Expected", "Actual", expected, actual, "The current baseline", "The new version");
|
||||
throw new Error(`The baseline file ${relativeFileName} has changed.${ts.ForegroundColorEscapeSequences.Grey}\n\n${patch}`);
|
||||
throw new Error(`${errorMessage}${ts.ForegroundColorEscapeSequences.Grey}\n\n${patch}`);
|
||||
}
|
||||
else {
|
||||
if (!IO.fileExists(expected)) {
|
||||
throw new Error(`New baseline created at ${IO.joinPath("tests", "baselines","local", relativeFileName)}`);
|
||||
}
|
||||
else {
|
||||
throw new Error(`The baseline file ${relativeFileName} has changed.`);
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getBaselineFileChangedErrorMessage(relativeFileName: string): string {
|
||||
return `The baseline file ${relativeFileName} has changed. (Run "gulp baseline-accept" if the new baseline is correct.)`;
|
||||
}
|
||||
|
||||
export function runBaseline(relativeFileName: string, actual: string | null, opts?: BaselineOptions): void {
|
||||
const actualFileName = localPath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);
|
||||
if (actual === undefined) {
|
||||
|
||||
@@ -4510,6 +4510,8 @@ declare namespace ts {
|
||||
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
|
||||
function isStringLiteralLike(node: Node): node is StringLiteralLike;
|
||||
function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain;
|
||||
function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean;
|
||||
function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean;
|
||||
}
|
||||
declare namespace ts {
|
||||
const factory: NodeFactory;
|
||||
|
||||
@@ -4510,6 +4510,8 @@ declare namespace ts {
|
||||
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
|
||||
function isStringLiteralLike(node: Node): node is StringLiteralLike;
|
||||
function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain;
|
||||
function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean;
|
||||
function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean;
|
||||
}
|
||||
declare namespace ts {
|
||||
const factory: NodeFactory;
|
||||
|
||||
Reference in New Issue
Block a user