mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Do not transform the emit of function with rest parameter unless declared in AST
Fixes #7749
This commit is contained in:
@@ -13771,7 +13771,7 @@ namespace ts {
|
||||
|
||||
function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) {
|
||||
// no rest parameters \ declaration context \ overload - no codegen impact
|
||||
if (!hasRestParameter(node) || isInAmbientContext(node) || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
|
||||
if (!hasDeclaredRestParameter(node) || isInAmbientContext(node) || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4467,7 +4467,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
}
|
||||
|
||||
function emitRestParameter(node: FunctionLikeDeclaration) {
|
||||
if (languageVersion < ScriptTarget.ES6 && hasRestParameter(node)) {
|
||||
if (languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node)) {
|
||||
const restIndex = node.parameters.length - 1;
|
||||
const restParam = node.parameters[restIndex];
|
||||
|
||||
@@ -4624,7 +4624,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
if (node) {
|
||||
const parameters = node.parameters;
|
||||
const skipCount = node.parameters.length && (<Identifier>node.parameters[0].name).text === "this" ? 1 : 0;
|
||||
const omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameter(node) ? 1 : 0;
|
||||
const omitCount = languageVersion < ScriptTarget.ES6 && hasDeclaredRestParameter(node) ? 1 : 0;
|
||||
emitList(parameters, skipCount, parameters.length - omitCount - skipCount, /*multiLine*/ false, /*trailingComma*/ false);
|
||||
}
|
||||
write(")");
|
||||
|
||||
+15
-12
@@ -1500,23 +1500,26 @@ namespace ts {
|
||||
return isRestParameter(lastOrUndefined(s.parameters));
|
||||
}
|
||||
|
||||
export function isRestParameter(node: ParameterDeclaration) {
|
||||
if (node) {
|
||||
if (node.flags & NodeFlags.JavaScriptFile) {
|
||||
if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType) {
|
||||
return true;
|
||||
}
|
||||
export function hasDeclaredRestParameter(s: SignatureDeclaration): boolean {
|
||||
return isDeclaredRestParam(lastOrUndefined(s.parameters));
|
||||
}
|
||||
|
||||
const paramTag = getCorrespondingJSDocParameterTag(node);
|
||||
if (paramTag && paramTag.typeExpression) {
|
||||
return paramTag.typeExpression.type.kind === SyntaxKind.JSDocVariadicType;
|
||||
}
|
||||
export function isRestParameter(node: ParameterDeclaration) {
|
||||
if (node && (node.flags & NodeFlags.JavaScriptFile)) {
|
||||
if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return node.dotDotDotToken !== undefined;
|
||||
const paramTag = getCorrespondingJSDocParameterTag(node);
|
||||
if (paramTag && paramTag.typeExpression) {
|
||||
return paramTag.typeExpression.type.kind === SyntaxKind.JSDocVariadicType;
|
||||
}
|
||||
}
|
||||
return isDeclaredRestParam(node);
|
||||
}
|
||||
|
||||
return false;
|
||||
export function isDeclaredRestParam(node: ParameterDeclaration) {
|
||||
return node && node.dotDotDotToken !== undefined;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,11 +36,7 @@ define("_apply", ["require", "exports"], function (require, exports) {
|
||||
* @param {...*} args The arguments to invoke `func` with.
|
||||
* @returns {*} Returns the result of `func`.
|
||||
*/
|
||||
function apply(func, thisArg) {
|
||||
var args = [];
|
||||
for (var _i = 2; _i < arguments.length; _i++) {
|
||||
args[_i - 2] = arguments[_i];
|
||||
}
|
||||
function apply(func, thisArg, args) {
|
||||
var length = args.length;
|
||||
switch (length) {
|
||||
case 0: return func.call(thisArg);
|
||||
|
||||
Reference in New Issue
Block a user