mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 00:34:47 -05:00
Merge branch 'master' into FixAbsoluteTripleSlashCompletions
This commit is contained in:
@@ -2746,8 +2746,9 @@ namespace ts {
|
||||
|
||||
// Type parameters are always visible
|
||||
case SyntaxKind.TypeParameter:
|
||||
// Source file is always visible
|
||||
// Source file and namespace export are always visible
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.NamespaceExportDeclaration:
|
||||
return true;
|
||||
|
||||
// Export assignments do not create name bindings outside the module
|
||||
|
||||
@@ -126,14 +126,22 @@ namespace ts {
|
||||
context: TransformationContext,
|
||||
node: VariableDeclaration,
|
||||
value?: Expression,
|
||||
visitor?: (node: Node) => VisitResult<Node>) {
|
||||
visitor?: (node: Node) => VisitResult<Node>,
|
||||
recordTempVariable?: (node: Identifier) => void) {
|
||||
const declarations: VariableDeclaration[] = [];
|
||||
|
||||
let pendingAssignments: Expression[];
|
||||
flattenDestructuring(context, node, value, node, emitAssignment, emitTempVariableAssignment, visitor);
|
||||
|
||||
return declarations;
|
||||
|
||||
function emitAssignment(name: Identifier, value: Expression, location: TextRange, original: Node) {
|
||||
if (pendingAssignments) {
|
||||
pendingAssignments.push(value);
|
||||
value = inlineExpressions(pendingAssignments);
|
||||
pendingAssignments = undefined;
|
||||
}
|
||||
|
||||
const declaration = createVariableDeclaration(name, /*type*/ undefined, value, location);
|
||||
declaration.original = original;
|
||||
|
||||
@@ -146,8 +154,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
function emitTempVariableAssignment(value: Expression, location: TextRange) {
|
||||
const name = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
emitAssignment(name, value, location, /*original*/ undefined);
|
||||
const name = createTempVariable(recordTempVariable);
|
||||
if (recordTempVariable) {
|
||||
const assignment = createAssignment(name, value, location);
|
||||
if (pendingAssignments) {
|
||||
pendingAssignments.push(assignment);
|
||||
}
|
||||
else {
|
||||
pendingAssignments = [assignment];
|
||||
}
|
||||
}
|
||||
else {
|
||||
emitAssignment(name, value, location, /*original*/ undefined);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,6 +163,7 @@ namespace ts {
|
||||
let currentText: string;
|
||||
let currentParent: Node;
|
||||
let currentNode: Node;
|
||||
let enclosingVariableStatement: VariableStatement;
|
||||
let enclosingBlockScopeContainer: Node;
|
||||
let enclosingBlockScopeContainerParent: Node;
|
||||
let containingNonArrowFunction: FunctionLikeDeclaration | ClassElement;
|
||||
@@ -210,6 +211,7 @@ namespace ts {
|
||||
const savedSuperScopeContainer = superScopeContainer;
|
||||
const savedCurrentParent = currentParent;
|
||||
const savedCurrentNode = currentNode;
|
||||
const savedEnclosingVariableStatement = enclosingVariableStatement;
|
||||
const savedEnclosingBlockScopeContainer = enclosingBlockScopeContainer;
|
||||
const savedEnclosingBlockScopeContainerParent = enclosingBlockScopeContainerParent;
|
||||
|
||||
@@ -227,6 +229,7 @@ namespace ts {
|
||||
superScopeContainer = savedSuperScopeContainer;
|
||||
currentParent = savedCurrentParent;
|
||||
currentNode = savedCurrentNode;
|
||||
enclosingVariableStatement = savedEnclosingVariableStatement;
|
||||
enclosingBlockScopeContainer = savedEnclosingBlockScopeContainer;
|
||||
enclosingBlockScopeContainerParent = savedEnclosingBlockScopeContainerParent;
|
||||
return visited;
|
||||
@@ -320,7 +323,7 @@ namespace ts {
|
||||
return visitFunctionExpression(<FunctionExpression>node);
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return visitVariableDeclaration(<VariableDeclaration>node, /*offset*/ undefined);
|
||||
return visitVariableDeclaration(<VariableDeclaration>node);
|
||||
|
||||
case SyntaxKind.Identifier:
|
||||
return visitIdentifier(<Identifier>node);
|
||||
@@ -432,6 +435,25 @@ namespace ts {
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// keep track of the enclosing variable statement when in the context of
|
||||
// variable statements, variable declarations, binding elements, and binding
|
||||
// patterns.
|
||||
switch (currentParent.kind) {
|
||||
case SyntaxKind.VariableStatement:
|
||||
enclosingVariableStatement = <VariableStatement>currentParent;
|
||||
break;
|
||||
|
||||
case SyntaxKind.VariableDeclarationList:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
break;
|
||||
|
||||
default:
|
||||
enclosingVariableStatement = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1334,7 +1356,7 @@ namespace ts {
|
||||
return setOriginalNode(
|
||||
createFunctionDeclaration(
|
||||
/*decorators*/ undefined,
|
||||
/*modifiers*/ undefined,
|
||||
node.modifiers,
|
||||
node.asteriskToken,
|
||||
node.name,
|
||||
/*typeParameters*/ undefined,
|
||||
@@ -1663,13 +1685,13 @@ namespace ts {
|
||||
*
|
||||
* @param node A VariableDeclaration node.
|
||||
*/
|
||||
function visitVariableDeclarationInLetDeclarationList(node: VariableDeclaration, offset: number) {
|
||||
function visitVariableDeclarationInLetDeclarationList(node: VariableDeclaration) {
|
||||
// For binding pattern names that lack initializers there is no point to emit
|
||||
// explicit initializer since downlevel codegen for destructuring will fail
|
||||
// in the absence of initializer so all binding elements will say uninitialized
|
||||
const name = node.name;
|
||||
if (isBindingPattern(name)) {
|
||||
return visitVariableDeclaration(node, offset);
|
||||
return visitVariableDeclaration(node);
|
||||
}
|
||||
|
||||
if (!node.initializer && shouldEmitExplicitInitializerForLetDeclaration(node)) {
|
||||
@@ -1686,10 +1708,13 @@ namespace ts {
|
||||
*
|
||||
* @param node A VariableDeclaration node.
|
||||
*/
|
||||
function visitVariableDeclaration(node: VariableDeclaration, offset: number): VisitResult<VariableDeclaration> {
|
||||
function visitVariableDeclaration(node: VariableDeclaration): VisitResult<VariableDeclaration> {
|
||||
// If we are here it is because the name contains a binding pattern.
|
||||
if (isBindingPattern(node.name)) {
|
||||
return flattenVariableDestructuring(context, node, /*value*/ undefined, visitor);
|
||||
const recordTempVariablesInLine = !enclosingVariableStatement
|
||||
|| !hasModifier(enclosingVariableStatement, ModifierFlags.Export);
|
||||
return flattenVariableDestructuring(context, node, /*value*/ undefined, visitor,
|
||||
recordTempVariablesInLine ? undefined : hoistVariableDeclaration);
|
||||
}
|
||||
|
||||
return visitEachChild(node, visitor, context);
|
||||
@@ -1765,7 +1790,7 @@ namespace ts {
|
||||
// Note also that because an extra statement is needed to assign to the LHS,
|
||||
// for-of bodies are always emitted as blocks.
|
||||
|
||||
const expression = node.expression;
|
||||
const expression = visitNode(node.expression, visitor, isExpression);
|
||||
const initializer = node.initializer;
|
||||
const statements: Statement[] = [];
|
||||
|
||||
@@ -2014,7 +2039,7 @@ namespace ts {
|
||||
case SyntaxKind.ForOfStatement:
|
||||
const initializer = (<ForStatement | ForInStatement | ForOfStatement>node).initializer;
|
||||
if (initializer && initializer.kind === SyntaxKind.VariableDeclarationList) {
|
||||
loopInitializer = <VariableDeclarationList>(<ForStatement | ForInStatement | ForOfStatement>node).initializer;
|
||||
loopInitializer = <VariableDeclarationList>initializer;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -573,11 +573,11 @@ namespace ts {
|
||||
operationLocations = undefined;
|
||||
state = createTempVariable(/*recordTempVariable*/ undefined);
|
||||
|
||||
const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
|
||||
|
||||
// Build the generator
|
||||
startLexicalEnvironment();
|
||||
|
||||
const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
|
||||
|
||||
transformAndEmitStatements(body.statements, statementOffset);
|
||||
|
||||
const buildResult = build();
|
||||
@@ -615,6 +615,11 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
// Do not hoist custom prologues.
|
||||
if (node.emitFlags & NodeEmitFlags.CustomPrologue) {
|
||||
return node;
|
||||
}
|
||||
|
||||
for (const variable of node.declarationList.declarations) {
|
||||
hoistVariableDeclaration(<Identifier>variable.name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user