mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Cleanup, fix linter errors, follow hoisted declarations.
This commit is contained in:
@@ -2484,6 +2484,7 @@ namespace ts {
|
||||
const modifierFlags = getModifierFlags(node);
|
||||
const body = node.body;
|
||||
const typeParameters = node.typeParameters;
|
||||
const asteriskToken = node.asteriskToken;
|
||||
|
||||
// A MethodDeclaration is TypeScript syntax if it is either async, abstract, overloaded,
|
||||
// generic, or has a decorator.
|
||||
@@ -2495,7 +2496,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Currently, we only support generators that were originally async function bodies.
|
||||
if (node.asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
|
||||
if (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
|
||||
transformFlags |= TransformFlags.AssertGenerator;
|
||||
}
|
||||
|
||||
@@ -2546,7 +2547,7 @@ namespace ts {
|
||||
transformFlags = TransformFlags.AssertTypeScript;
|
||||
}
|
||||
else {
|
||||
transformFlags = subtreeFlags;
|
||||
transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclaration;
|
||||
|
||||
// If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax.
|
||||
if (modifierFlags & ModifierFlags.Export) {
|
||||
@@ -2566,7 +2567,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Currently, we only support generators that were originally async function bodies.
|
||||
if (node.asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
|
||||
if (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
|
||||
transformFlags |= TransformFlags.AssertGenerator;
|
||||
}
|
||||
}
|
||||
@@ -2592,7 +2593,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Currently, we only support generators that were originally async function bodies.
|
||||
if (node.asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
|
||||
if (asteriskToken && node.emitFlags & NodeEmitFlags.AsyncFunctionBody) {
|
||||
transformFlags |= TransformFlags.AssertGenerator;
|
||||
}
|
||||
|
||||
@@ -2725,7 +2726,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function computeVariableDeclarationList(node: VariableDeclarationList, subtreeFlags: TransformFlags) {
|
||||
let transformFlags = subtreeFlags;
|
||||
let transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclaration;
|
||||
|
||||
if (subtreeFlags & TransformFlags.ContainsBindingPattern) {
|
||||
transformFlags |= TransformFlags.AssertES6;
|
||||
|
||||
@@ -137,12 +137,11 @@ namespace ts {
|
||||
Endfinally // Marks the end of a `finally` block
|
||||
}
|
||||
|
||||
type OperationArguments =
|
||||
[Label] |
|
||||
[Label, Expression] |
|
||||
[Statement] |
|
||||
[Expression] |
|
||||
[Expression, Expression];
|
||||
type OperationArguments = [Label]
|
||||
| [Label, Expression]
|
||||
| [Statement]
|
||||
| [Expression]
|
||||
| [Expression, Expression];
|
||||
|
||||
// whether a generated code block is opening or closing at the current operation for a FunctionBuilder
|
||||
const enum BlockAction {
|
||||
@@ -394,8 +393,16 @@ namespace ts {
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return visitAccessorDeclaration(<AccessorDeclaration>node);
|
||||
case SyntaxKind.VariableStatement:
|
||||
return visitVariableStatement(<VariableStatement>node);
|
||||
case SyntaxKind.BreakStatement:
|
||||
return visitBreakStatement(<BreakStatement>node);
|
||||
case SyntaxKind.ContinueStatement:
|
||||
return visitContinueStatement(<ContinueStatement>node);
|
||||
case SyntaxKind.ReturnStatement:
|
||||
return visitReturnStatement(<ReturnStatement>node);
|
||||
default:
|
||||
if (node.transformFlags & (TransformFlags.ContainsGenerator | TransformFlags.ContainsYield)) {
|
||||
if (node.transformFlags & (TransformFlags.ContainsGenerator | TransformFlags.ContainsYield | TransformFlags.ContainsHoistedDeclaration)) {
|
||||
return visitEachChild(node, visitor, context);
|
||||
}
|
||||
else {
|
||||
@@ -943,19 +950,20 @@ namespace ts {
|
||||
// _a);
|
||||
|
||||
const properties = node.properties;
|
||||
const numInitialProperties = countInitialNodesWithoutYield(node.properties);
|
||||
const multiLine = node.multiLine;
|
||||
const numInitialProperties = countInitialNodesWithoutYield(properties);
|
||||
|
||||
const temp = declareLocal();
|
||||
emitAssignment(temp,
|
||||
createObjectLiteral(
|
||||
visitNodes(node.properties, visitor, isObjectLiteralElement, 0, numInitialProperties),
|
||||
visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialProperties),
|
||||
/*location*/ undefined,
|
||||
node.multiLine
|
||||
multiLine
|
||||
)
|
||||
);
|
||||
|
||||
const expressions = reduceLeft(node.properties, reduceProperty, <Expression[]>[], numInitialProperties);
|
||||
addNode(expressions, getMutableClone(temp), node.multiLine);
|
||||
const expressions = reduceLeft(properties, reduceProperty, <Expression[]>[], numInitialProperties);
|
||||
addNode(expressions, getMutableClone(temp), multiLine);
|
||||
return inlineExpressions(expressions);
|
||||
|
||||
function reduceProperty(expressions: Expression[], property: ObjectLiteralElement) {
|
||||
@@ -965,7 +973,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const expression = createExpressionForObjectLiteralElement(node, property, temp);
|
||||
addNode(expressions, visitNode(expression, visitor, isExpression), node.multiLine);
|
||||
addNode(expressions, visitNode(expression, visitor, isExpression), multiLine);
|
||||
return expressions;
|
||||
}
|
||||
}
|
||||
@@ -1867,7 +1875,8 @@ namespace ts {
|
||||
labelOffsets = [];
|
||||
}
|
||||
|
||||
const label = nextLabelId++;
|
||||
const label = nextLabelId;
|
||||
nextLabelId++;
|
||||
labelOffsets[label] = -1;
|
||||
return label;
|
||||
}
|
||||
@@ -2023,7 +2032,6 @@ namespace ts {
|
||||
const exception = <ExceptionBlock>peekBlock();
|
||||
Debug.assert(exception.state < ExceptionBlockState.Finally);
|
||||
|
||||
const state = exception.state;
|
||||
const endLabel = exception.endLabel;
|
||||
emitBreak(endLabel);
|
||||
|
||||
@@ -2344,14 +2352,6 @@ namespace ts {
|
||||
return createCall(createPropertyAccess(state, "sent"), /*typeArguments*/ undefined, [], location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a NOP (no operation). This is often used to ensure a new operation location exists
|
||||
* when marking labels.
|
||||
*/
|
||||
function emitNop(): void {
|
||||
emitWorker(OpCode.Nop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a Statement.
|
||||
*
|
||||
@@ -2421,16 +2421,6 @@ namespace ts {
|
||||
emitWorker(OpCode.Yield, [expression], location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a YieldStar operation for the provided expression.
|
||||
*
|
||||
* @param expression A value for the operation.
|
||||
* @param location An optional source map location for the assignment.
|
||||
*/
|
||||
function emitYieldStar(expression: Expression, location?: TextRange): void {
|
||||
emitWorker(OpCode.YieldStar, [expression], location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits a Return operation for the provided expression.
|
||||
*
|
||||
@@ -2651,7 +2641,6 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
|
||||
let isLabel: boolean = false;
|
||||
for (let label = 0; label < labelOffsets.length; label++) {
|
||||
if (labelOffsets[label] === operationIndex) {
|
||||
flushLabel();
|
||||
@@ -2659,7 +2648,7 @@ namespace ts {
|
||||
labelNumbers = [];
|
||||
}
|
||||
if (labelNumbers[labelNumber] === undefined) {
|
||||
labelNumbers[labelNumber] = [label]
|
||||
labelNumbers[labelNumber] = [label];
|
||||
}
|
||||
else {
|
||||
labelNumbers[labelNumber].push(label);
|
||||
|
||||
@@ -2987,6 +2987,7 @@ namespace ts {
|
||||
ContainsBlockScopedBinding = 1 << 20,
|
||||
ContainsBindingPattern = 1 << 21,
|
||||
ContainsYield = 1 << 22,
|
||||
ContainsHoistedDeclaration = 1 << 23,
|
||||
|
||||
HasComputedFlags = 1 << 29, // Transform flags have been computed.
|
||||
|
||||
@@ -3002,12 +3003,12 @@ namespace ts {
|
||||
// - Bitmasks that exclude flags from propagating out of a specific context
|
||||
// into the subtree flags of their container.
|
||||
NodeExcludes = TypeScript | Jsx | ES7 | ES6 | DestructuringAssignment | HasComputedFlags,
|
||||
ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield,
|
||||
FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield,
|
||||
ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield,
|
||||
MethodOrAccessorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield,
|
||||
ArrowFunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclaration,
|
||||
FunctionExcludes = NodeExcludes | ContainsDecorators | ContainsDefaultValueAssignments | ContainsCapturedLexicalThis | ContainsLexicalThis | ContainsParameterPropertyAssignments | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclaration,
|
||||
ConstructorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclaration,
|
||||
MethodOrAccessorExcludes = NodeExcludes | ContainsDefaultValueAssignments | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsYield | ContainsHoistedDeclaration,
|
||||
ClassExcludes = NodeExcludes | ContainsDecorators | ContainsPropertyInitializer | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsComputedPropertyName | ContainsParameterPropertyAssignments | ContainsLexicalThisInComputedPropertyName,
|
||||
ModuleExcludes = NodeExcludes | ContainsDecorators | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding,
|
||||
ModuleExcludes = NodeExcludes | ContainsDecorators | ContainsLexicalThis | ContainsCapturedLexicalThis | ContainsBlockScopedBinding | ContainsHoistedDeclaration,
|
||||
TypeExcludes = ~ContainsTypeScript,
|
||||
ObjectLiteralExcludes = NodeExcludes | ContainsDecorators | ContainsComputedPropertyName | ContainsLexicalThisInComputedPropertyName,
|
||||
ArrayLiteralOrCallOrNewExcludes = NodeExcludes | ContainsSpreadElementExpression,
|
||||
|
||||
Reference in New Issue
Block a user