Skip to content

Commit d6e483b

Browse files
Zamiellsandersn
andauthored
fix(48887) exposing rest helper functions externally (microsoft#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>
1 parent e2bd89b commit d6e483b

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

src/compiler/utilities.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,16 +2866,6 @@ namespace ts {
28662866
return typeParameters && find(typeParameters, p => p.name.escapedText === name);
28672867
}
28682868

2869-
export function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean {
2870-
const last = lastOrUndefined<ParameterDeclaration | JSDocParameterTag>(s.parameters);
2871-
return !!last && isRestParameter(last);
2872-
}
2873-
2874-
export function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean {
2875-
const type = isJSDocParameterTag(node) ? (node.typeExpression && node.typeExpression.type) : node.type;
2876-
return (node as ParameterDeclaration).dotDotDotToken !== undefined || !!type && type.kind === SyntaxKind.JSDocVariadicType;
2877-
}
2878-
28792869
export function hasTypeArguments(node: Node): node is HasTypeArguments {
28802870
return !!(node as HasTypeArguments).typeArguments;
28812871
}

src/compiler/utilitiesPublic.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,5 +2015,16 @@ namespace ts {
20152015
export function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain {
20162016
return node.kind === SyntaxKind.JSDocLink || node.kind === SyntaxKind.JSDocLinkCode || node.kind === SyntaxKind.JSDocLinkPlain;
20172017
}
2018+
2019+
export function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean {
2020+
const last = lastOrUndefined<ParameterDeclaration | JSDocParameterTag>(s.parameters);
2021+
return !!last && isRestParameter(last);
2022+
}
2023+
2024+
export function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean {
2025+
const type = isJSDocParameterTag(node) ? (node.typeExpression && node.typeExpression.type) : node.type;
2026+
return (node as ParameterDeclaration).dotDotDotToken !== undefined || !!type && type.kind === SyntaxKind.JSDocVariadicType;
2027+
}
2028+
20182029
// #endregion
20192030
}

src/harness/harnessIO.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,22 +1389,27 @@ namespace Harness {
13891389
else {
13901390
IO.writeFile(actualFileName, encodedActual);
13911391
}
1392+
const errorMessage = getBaselineFileChangedErrorMessage(relativeFileName);
13921393
if (!!require && opts && opts.PrintDiff) {
13931394
const Diff = require("diff");
13941395
const patch = Diff.createTwoFilesPatch("Expected", "Actual", expected, actual, "The current baseline", "The new version");
1395-
throw new Error(`The baseline file ${relativeFileName} has changed.${ts.ForegroundColorEscapeSequences.Grey}\n\n${patch}`);
1396+
throw new Error(`${errorMessage}${ts.ForegroundColorEscapeSequences.Grey}\n\n${patch}`);
13961397
}
13971398
else {
13981399
if (!IO.fileExists(expected)) {
13991400
throw new Error(`New baseline created at ${IO.joinPath("tests", "baselines","local", relativeFileName)}`);
14001401
}
14011402
else {
1402-
throw new Error(`The baseline file ${relativeFileName} has changed.`);
1403+
throw new Error(errorMessage);
14031404
}
14041405
}
14051406
}
14061407
}
14071408

1409+
function getBaselineFileChangedErrorMessage(relativeFileName: string): string {
1410+
return `The baseline file ${relativeFileName} has changed. (Run "gulp baseline-accept" if the new baseline is correct.)`;
1411+
}
1412+
14081413
export function runBaseline(relativeFileName: string, actual: string | null, opts?: BaselineOptions): void {
14091414
const actualFileName = localPath(relativeFileName, opts && opts.Baselinefolder, opts && opts.Subfolder);
14101415
if (actual === undefined) {

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4510,6 +4510,8 @@ declare namespace ts {
45104510
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
45114511
function isStringLiteralLike(node: Node): node is StringLiteralLike;
45124512
function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain;
4513+
function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean;
4514+
function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean;
45134515
}
45144516
declare namespace ts {
45154517
const factory: NodeFactory;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4510,6 +4510,8 @@ declare namespace ts {
45104510
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement;
45114511
function isStringLiteralLike(node: Node): node is StringLiteralLike;
45124512
function isJSDocLinkLike(node: Node): node is JSDocLink | JSDocLinkCode | JSDocLinkPlain;
4513+
function hasRestParameter(s: SignatureDeclaration | JSDocSignature): boolean;
4514+
function isRestParameter(node: ParameterDeclaration | JSDocParameterTag): boolean;
45134515
}
45144516
declare namespace ts {
45154517
const factory: NodeFactory;

0 commit comments

Comments
 (0)