8000 Do not transform the emit of function with rest parameter unless decl… · creatio/TypeScript@1bccef7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1bccef7

Browse files
committed
Do not transform the emit of function with rest parameter unless declared in AST
Fixes microsoft#7749
1 parent dfb0f68 commit 1bccef7

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13771,7 +13771,7 @@ namespace ts {
1377113771

1377213772
function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) {
1377313773
// no rest parameters \ declaration context \ overload - no codegen impact
13774-
if (!hasRestParameter(node) || isInAmbientContext(node) || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
13774+
if (!hasDeclaredRestParameter(node) || isInAmbientContext(node) || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
1377513775
return;
1377613776
}
1377713777

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4467,7 +4467,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
44674467
}
44684468

44694469
function emitRestParameter(node: FunctionLikeDeclaration) {
4470-
if (languageVersion < ScriptTarget.ES6 && hasRestParameter(node)) {
4470+
if (languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node)) {
44714471
const restIndex = node.parameters.length - 1;
44724472
const restParam = node.parameters[restIndex];
44734473

@@ -4624,7 +4624,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
46244624
if (node) {
46254625
const parameters = node.parameters;
46264626
const skipCount = node.parameters.length && (<Identifier>node.parameters[0].name).text === "this" ? 1 : 0;
4627-
const omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameter(node) ? 1 : 0;
4627+
const omitCount = languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node) ? 1 : 0;
46284628
emitList(parameters, skipCount, parameters.length - omitCount - skipCount, /*multiLine*/ false, /*trailingComma*/ false);
46294629
}
46304630
write(")");

src/compiler/utilities.ts

Lines changed: 15 additions & 12 deletions
< 10000 /div>
Original file line numberDiff line numberDiff line change
@@ -1500,23 +1500,26 @@ namespace ts {
15001500
return isRestParameter(lastOrUndefined(s.parameters));
15011501
}
15021502

1503-
export function isRestParameter(node: ParameterDeclaration) {
1504-
if (node) {
1505-
if (node.flags & NodeFlags.JavaScriptFile) {
1506-
if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType) {
1507-
return true;
1508-
}
1503+
export function hasDeclaredRestParameter(s: SignatureDeclaration): boolean {
1504+
return isDeclaredRestParam(lastOrUndefined(s.parameters));
1505+
}
15091506

1510-
const paramTag = getCorrespondingJSDocParameterTag(node);
1511-
if (paramTag && paramTag.typeExpression) {
1512-
return paramTag.typeExpression.type.kind === SyntaxKind.JSDocVariadicType;
1513-
}
1507+
export function isRestParameter(node: ParameterDeclaration) {
1508+
if (node && (node.flags & NodeFlags.JavaScriptFile)) {
1509+
if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType) {
1510+
return true;
15141511
}
15151512

1516-
return node.dotDotDotToken !== undefined;
1513+
const paramTag = getCorrespondingJSDocParameterTag(node);
1514+
if (paramTag && paramTag.typeExpression) {
1515+
return paramTag.typeExpression.type.kind === SyntaxKind.JSDocVariadicType;
1516+
}
15171517
}
1518+
return isDeclaredRestParam(node);
1519+
}
15181520

1519-
return false;
1521+
export function isDeclaredRestParam(node: ParameterDeclaration) {
1522+
return node && node.dotDotDotToken !== undefined;
15201523
}
15211524

15221525

tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ define("_apply", ["require", "exports"], function (require, exports) {
3636
* @param {...*} args The arguments to invoke `func` with.
3737
* @returns {*} Returns the result of `func`.
3838
*/
39-
function apply(func, thisArg) {
40-
var args = [];
41-
for (var _i = 2; _i < arguments.length; _i++) {
42-
args[_i - 2] = arguments[_i];
43-
}
39+
function apply(func, thisArg, args) {
4440
var length = args.length;
4541
switch (length) {
4642
case 0: return func.call(thisArg);

0 commit comments

Comments
 (0)
0