Skip to content

Commit 9a1a605

Browse files
committed
Merge branch 'master' into emitHelper
2 parents 63b1540 + 3110f40 commit 9a1a605

File tree

3 files changed

+20
-43
lines changed

3 files changed

+20
-43
lines changed

src/compiler/transformer.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ namespace ts {
7878
export function transformFiles(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformers: Transformer[]): TransformationResult {
7979
const enabledSyntaxKindFeatures = new Array<SyntaxKindFeatureFlags>(SyntaxKind.Count);
8080

81-
let scopeModificationDisabled = false;
81+
let lexicalEnvironmentDisabled = false;
8282

8383
let lexicalEnvironmentVariableDeclarations: VariableDeclaration[];
8484
let lexicalEnvironmentFunctionDeclarations: FunctionDeclaration[];
@@ -118,7 +118,7 @@ namespace ts {
118118
const transformed = map(sourceFiles, transformSourceFile);
119119

120120
// Disable modification of the lexical environment.
121-
scopeModificationDisabled = true;
121+
lexicalEnvironmentDisabled = true;
122122

123123
return {
124124
transformed,
@@ -213,7 +213,7 @@ namespace ts {
213213
* Records a hoisted variable declaration for the provided name within a lexical environment.
214214
*/
215215
function hoistVariableDeclaration(name: Identifier): void {
216-
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
216+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
217217
const decl = createVariableDeclaration(name);
218218
if (!lexicalEnvironmentVariableDeclarations) {
219219
lexicalEnvironmentVariableDeclarations = [decl];
@@ -227,7 +227,7 @@ namespace ts {
227227
* Records a hoisted function declaration within a lexical environment.
228228
*/
229229
function hoistFunctionDeclaration(func: FunctionDeclaration): void {
230-
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
230+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
231231
if (!lexicalEnvironmentFunctionDeclarations) {
232232
lexicalEnvironmentFunctionDeclarations = [func];
233233
}
@@ -241,7 +241,7 @@ namespace ts {
241241
* are pushed onto a stack, and the related storage variables are reset.
242242
*/
243243
function startLexicalEnvironment(): void {
244-
Debug.assert(!scopeModificationDisabled, "Cannot start a lexical environment during the print phase.");
244+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot start a lexical environment during the print phase.");
245245
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is suspended.");
246246

247247
// Save the current lexical environment. Rather than resizing the array we adjust the
@@ -257,14 +257,14 @@ namespace ts {
257257

258258
/** Suspends the current lexical environment, usually after visiting a parameter list. */
259259
function suspendLexicalEnvironment(): void {
260-
Debug.assert(!scopeModificationDisabled, "Cannot suspend a lexical environment during the print phase.");
260+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot suspend a lexical environment during the print phase.");
261261
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is already suspended.");
262262
lexicalEnvironmentSuspended = true;
263263
}
264264

265265
/** Resumes a suspended lexical environment, usually before visiting a function body. */
266266
function resumeLexicalEnvironment(): void {
267-
Debug.assert(!scopeModificationDisabled, "Cannot resume a lexical environment during the print phase.");
267+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot resume a lexical environment during the print phase.");
268268
Debug.assert(lexicalEnvironmentSuspended, "Lexical environment is not suspended.");
269269
lexicalEnvironmentSuspended = false;
270270
}
@@ -274,7 +274,7 @@ namespace ts {
274274
* any hoisted declarations added in this environment are returned.
275275
*/
276276
function endLexicalEnvironment(): Statement[] {
277-
Debug.assert(!scopeModificationDisabled, "Cannot end a lexical environment during the print phase.");
277+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot end a lexical environment during the print phase.");
278278
Debug.assert(!lexicalEnvironmentSuspended, "Lexical environment is suspended.");
279279

280280
let statements: Statement[];
@@ -310,13 +310,13 @@ namespace ts {
310310
}
311311

312312
function requestEmitHelper(helper: EmitHelper): void {
313-
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
313+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
314314
Debug.assert(!helper.scoped, "Cannot request a scoped emit helper.");
315315
emitHelpers = append(emitHelpers, helper);
316316
}
317317

318318
function readEmitHelpers(): EmitHelper[] | undefined {
319-
Debug.assert(!scopeModificationDisabled, "Cannot modify the lexical environment during the print phase.");
319+
Debug.assert(!lexicalEnvironmentDisabled, "Cannot modify the lexical environment during the print phase.");
320320
const helpers = emitHelpers;
321321
emitHelpers = undefined;
322322
return helpers;

src/compiler/transformers/destructuring.ts

+8-31
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace ts {
66
interface FlattenContext {
77
context: TransformationContext;
88
level: FlattenLevel;
9-
doNotRecordTempVariablesInLine: boolean;
9+
hoistTempVariables: boolean;
1010
emitExpression: (value: Expression) => void;
1111
emitBindingOrAssignment: (target: BindingOrAssignmentElementTarget, value: Expression, location: TextRange, original: Node) => void;
1212
createArrayBindingOrAssignmentPattern: (elements: BindingOrAssignmentElement[]) => ArrayBindingOrAssignmentPattern;
@@ -57,7 +57,7 @@ namespace ts {
5757
const flattenContext: FlattenContext = {
5858
context,
5959
level,
60-
doNotRecordTempVariablesInLine: true,
60+
hoistTempVariables: true,
6161
emitExpression,
6262
emitBindingOrAssignment,
6363
createArrayBindingOrAssignmentPattern: makeArrayAssignmentPattern,
@@ -126,7 +126,7 @@ namespace ts {
126126
* @param context The transformation context.
127127
* @param boundValue The value bound to the declaration.
128128
* @param skipInitializer A value indicating whether to ignore the initializer of `node`.
129-
* @param doNotRecordTempVariablesInLine Indicates whether temporary variables should not be recored in-line.
129+
* @param hoistTempVariables Indicates whether temporary variables should not be recorded in-line.
130130
* @param level Indicates the extent to which flattening should occur.
131131
*/
132132
export function flattenDestructuringBinding(
@@ -135,29 +135,26 @@ namespace ts {
135135
context: TransformationContext,
136136
level: FlattenLevel,
137137
rval?: Expression,
138-
doNotRecordTempVariablesInLine?: boolean,
138+
hoistTempVariables?: boolean,
139139
skipInitializer?: boolean): VariableDeclaration[] {
140-
141140
let pendingExpressions: Expression[];
142141
const pendingDeclarations: { pendingExpressions?: Expression[], name: BindingName, value: Expression, location?: TextRange, original?: Node; }[] = [];
143142
const declarations: VariableDeclaration[] = [];
144143
const flattenContext: FlattenContext = {
145144
context,
146145
level,
147-
doNotRecordTempVariablesInLine,
146+
hoistTempVariables,
148147
emitExpression,
149148
emitBindingOrAssignment,
150149
createArrayBindingOrAssignmentPattern: makeArrayBindingPattern,
151150
createObjectBindingOrAssignmentPattern: makeObjectBindingPattern,
152151
createArrayBindingOrAssignmentElement: makeBindingElement,
153152
visitor
154153
};
155-
156154
flattenBindingOrAssignmentElement(flattenContext, node, rval, node, skipInitializer);
157-
158155
if (pendingExpressions) {
159156
const temp = createTempVariable(/*recordTempVariable*/ undefined);
160-
if (doNotRecordTempVariablesInLine) {
157+
if (hoistTempVariables) {
161158
const value = inlineExpressions(pendingExpressions);
162159
pendingExpressions = undefined;
163160
emitBindingOrAssignment(temp, value, /*location*/ undefined, /*original*/ undefined);
@@ -173,7 +170,6 @@ namespace ts {
173170
pendingDeclaration.value = temp;
174171
}
175172
}
176-
177173
for (const { pendingExpressions, name, value, location, original } of pendingDeclarations) {
178174
const variable = createVariableDeclaration(
179175
name,
@@ -187,7 +183,6 @@ namespace ts {
187183
aggregateTransformFlags(variable);
188184
declarations.push(variable);
189185
}
190-
191186
return declarations;
192187

193188
function emitExpression(value: Expression) {
@@ -330,7 +325,7 @@ namespace ts {
330325
// can perform the ObjectRest destructuring in a different declaration
331326
if (element.transformFlags & TransformFlags.ContainsObjectRest) {
332327
const temp = createTempVariable(/*recordTempVariable*/ undefined);
333-
if (flattenContext.doNotRecordTempVariablesInLine) {
328+
if (flattenContext.hoistTempVariables) {
334329
flattenContext.context.hoistVariableDeclaration(temp);
335330
}
336331

@@ -419,7 +414,7 @@ namespace ts {
419414
}
420415
else {
421416
const temp = createTempVariable(/*recordTempVariable*/ undefined);
422-
if (flattenContext.doNotRecordTempVariablesInLine) {
417+
if (flattenContext.hoistTempVariables) {
423418
flattenContext.context.hoistVariableDeclaration(temp);
424419
flattenContext.emitExpression(createAssignment(temp, value, location));
425420
}
@@ -430,46 +425,28 @@ namespace ts {
430425
}
431426
}
432427

433-
/**
434-
* Creates an ArrayBindingPattern from an array of BindingOrAssignmentElement nodes.
435-
*/
436428
function makeArrayBindingPattern(elements: BindingOrAssignmentElement[]) {
437429
Debug.assertEachNode(elements, isArrayBindingElement);
438430
return createArrayBindingPattern(<ArrayBindingElement[]>elements);
439431
}
440432

441-
/**
442-
* Creates an ArrayLiteralExpression assignment pattern from an array of BindingOrAssignmentElement nodes.
443-
*/
444433
function makeArrayAssignmentPattern(elements: BindingOrAssignmentElement[]) {
445434
return createArrayLiteral(map(elements, convertToArrayAssignmentElement));
446435
}
447436

448-
/**
449-
* Creates an ObjectBindingPattern from an array of BindingOrAssignmentElement nodes.
450-
*/
451437
function makeObjectBindingPattern(elements: BindingOrAssignmentElement[]) {
452438
Debug.assertEachNode(elements, isBindingElement);
453439
return createObjectBindingPattern(<BindingElement[]>elements);
454440
}
455441

456-
/**
457-
* Creates an ObjectLiteralExpression assignment pattern from an array of BindingOrAssignmentElement nodes.
458-
*/
459442
function makeObjectAssignmentPattern(elements: BindingOrAssignmentElement[]) {
460443
return createObjectLiteral(map(elements, convertToObjectAssignmentElement));
461444
}
462445

463-
/**
464-
* Creates a BindingElement for a name.
465-
*/
466446
function makeBindingElement(name: Identifier) {
467447
return createBindingElement(/*propertyName*/ undefined, /*dotDotDotToken*/ undefined, name);
468448
}
469449

470-
/**
471-
* Creates an assignment element for a name.
472-
*/
473450
function makeAssignmentElement(name: Identifier) {
474451
return name;
475452
}

src/compiler/transformers/es2015.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1907,15 +1907,15 @@ namespace ts {
19071907
function visitVariableDeclaration(node: VariableDeclaration): VisitResult<VariableDeclaration> {
19081908
// If we are here it is because the name contains a binding pattern.
19091909
if (isBindingPattern(node.name)) {
1910-
const doNotRecordTempVariablesInLine = enclosingVariableStatement
1910+
const hoistTempVariables = enclosingVariableStatement
19111911
&& hasModifier(enclosingVariableStatement, ModifierFlags.Export);
19121912
return flattenDestructuringBinding(
19131913
node,
19141914
visitor,
19151915
context,
19161916
FlattenLevel.All,
19171917
/*value*/ undefined,
1918-
doNotRecordTempVariablesInLine
1918+
hoistTempVariables
19191919
);
19201920
}
19211921

0 commit comments

Comments
 (0)