Merge pull request #17517 from tinganho/IgnoredCatchParameter

Ignored catch parameter
This commit is contained in:
Ron Buckton
2017-08-08 16:15:18 -07:00
committed by GitHub
21 changed files with 204 additions and 117 deletions
+4 -1
View File
@@ -2921,7 +2921,10 @@ namespace ts {
function computeCatchClause(node: CatchClause, subtreeFlags: TransformFlags) {
let transformFlags = subtreeFlags;
if (node.variableDeclaration && isBindingPattern(node.variableDeclaration.name)) {
if (!node.variableDeclaration) {
transformFlags |= TransformFlags.AssertESNext;
}
else if (isBindingPattern(node.variableDeclaration.name)) {
transformFlags |= TransformFlags.AssertES2015;
}
+1 -1
View File
@@ -481,7 +481,7 @@ namespace ts {
Type,
ResolvedBaseConstructorType,
DeclaredType,
ResolvedReturnType
ResolvedReturnType,
}
const enum CheckMode {
+6 -4
View File
@@ -2133,10 +2133,12 @@ namespace ts {
function emitCatchClause(node: CatchClause) {
const openParenPos = writeToken(SyntaxKind.CatchKeyword, node.pos);
write(" ");
writeToken(SyntaxKind.OpenParenToken, openParenPos);
emit(node.variableDeclaration);
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration ? node.variableDeclaration.end : openParenPos);
write(" ");
if (node.variableDeclaration) {
writeToken(SyntaxKind.OpenParenToken, openParenPos);
emit(node.variableDeclaration);
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration.end);
write(" ");
}
emit(node.block);
}
+2 -2
View File
@@ -2128,14 +2128,14 @@ namespace ts {
: node;
}
export function createCatchClause(variableDeclaration: string | VariableDeclaration, block: Block) {
export function createCatchClause(variableDeclaration: string | VariableDeclaration | undefined, block: Block) {
const node = <CatchClause>createSynthesizedNode(SyntaxKind.CatchClause);
node.variableDeclaration = typeof variableDeclaration === "string" ? createVariableDeclaration(variableDeclaration) : variableDeclaration;
node.block = block;
return node;
}
export function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration, block: Block) {
export function updateCatchClause(node: CatchClause, variableDeclaration: VariableDeclaration | undefined, block: Block) {
return node.variableDeclaration !== variableDeclaration
|| node.block !== block
? updateNode(createCatchClause(variableDeclaration, block), node)
+7 -2
View File
@@ -4799,11 +4799,16 @@ namespace ts {
function parseCatchClause(): CatchClause {
const result = <CatchClause>createNode(SyntaxKind.CatchClause);
parseExpected(SyntaxKind.CatchKeyword);
if (parseExpected(SyntaxKind.OpenParenToken)) {
if (parseOptional(SyntaxKind.OpenParenToken)) {
result.variableDeclaration = parseVariableDeclaration();
parseExpected(SyntaxKind.CloseParenToken);
}
else {
// Keep shape of node to avoid degrading performance.
result.variableDeclaration = undefined;
}
parseExpected(SyntaxKind.CloseParenToken);
result.block = parseBlock(/*ignoreMissingOpenBrace*/ false);
return finishNode(result);
}
+2 -1
View File
@@ -2491,7 +2491,7 @@ namespace ts {
const catchVariable = getGeneratedNameForNode(errorRecord);
const returnMethod = createTempVariable(/*recordTempVariable*/ undefined);
const values = createValuesHelper(context, expression, node.expression);
const next = createCall(createPropertyAccess(iterator, "next" ), /*typeArguments*/ undefined, []);
const next = createCall(createPropertyAccess(iterator, "next"), /*typeArguments*/ undefined, []);
hoistVariableDeclaration(errorRecord);
hoistVariableDeclaration(returnMethod);
@@ -3173,6 +3173,7 @@ namespace ts {
function visitCatchClause(node: CatchClause): CatchClause {
const ancestorFacts = enterSubtree(HierarchyFacts.BlockScopeExcludes, HierarchyFacts.BlockScopeIncludes);
let updated: CatchClause;
Debug.assert(!!node.variableDeclaration, "Catch clause variable should always be present when downleveling ES2015.");
if (isBindingPattern(node.variableDeclaration.name)) {
const temp = createTempVariable(/*recordTempVariable*/ undefined);
const newVariableDeclaration = createVariableDeclaration(temp);
+13
View File
@@ -101,6 +101,8 @@ namespace ts {
return visitExpressionStatement(node as ExpressionStatement);
case SyntaxKind.ParenthesizedExpression:
return visitParenthesizedExpression(node as ParenthesizedExpression, noDestructuringValue);
case SyntaxKind.CatchClause:
return visitCatchClause(node as CatchClause);
default:
return visitEachChild(node, visitor, context);
}
@@ -212,6 +214,17 @@ namespace ts {
return visitEachChild(node, noDestructuringValue ? visitorNoDestructuringValue : visitor, context);
}
function visitCatchClause(node: CatchClause): CatchClause {
if (!node.variableDeclaration) {
return updateCatchClause(
node,
createVariableDeclaration(createTempVariable(/*recordTempVariable*/ undefined)),
visitNode(node.block, visitor, isBlock)
);
}
return visitEachChild(node, visitor, context);
}
/**
* Visits a BinaryExpression that contains a destructuring assignment.
*
+1 -2
View File
@@ -1808,7 +1808,7 @@ namespace ts {
export interface CatchClause extends Node {
kind: SyntaxKind.CatchClause;
parent?: TryStatement;
variableDeclaration: VariableDeclaration;
variableDeclaration?: VariableDeclaration;
block: Block;
}
@@ -4020,7 +4020,6 @@ namespace ts {
ContainsBindingPattern = 1 << 23,
ContainsYield = 1 << 24,
ContainsHoistedDeclarationOrCompletion = 1 << 25,
ContainsDynamicImport = 1 << 26,
// Please leave this as 1 << 29.