Skip to content

Commit e6bea90

Browse files
authored
Merge pull request #11769 from Microsoft/moveModuleTransformToEnd
Move module transformers to end of transformations
2 parents 50e2fd8 + 82c300a commit e6bea90

File tree

428 files changed

+3423
-2675
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

428 files changed

+3423
-2675
lines changed

Jakefile.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ var compilerSources = [
7070
"visitor.ts",
7171
"transformers/destructuring.ts",
7272
"transformers/ts.ts",
73-
"transformers/module/es2015.ts",
74-
"transformers/module/system.ts",
75-
"transformers/module/module.ts",
7673
"transformers/jsx.ts",
7774
"transformers/es2017.ts",
7875
"transformers/es2016.ts",
7976
"transformers/es2015.ts",
8077
"transformers/generators.ts",
8178
"transformers/es5.ts",
79+
"transformers/module/es2015.ts",
80+
"transformers/module/system.ts",
81+
"transformers/module/module.ts",
8282
"transformer.ts",
8383
"sourcemap.ts",
8484
"comments.ts",
@@ -106,15 +106,15 @@ var servicesSources = [
106106
"visitor.ts",
107107
"transformers/destructuring.ts",
108108
"transformers/ts.ts",
109-
"transformers/module/es2015.ts",
110-
"transformers/module/system.ts",
111-
"transformers/module/module.ts",
112109
"transformers/jsx.ts",
113110
"transformers/es2017.ts",
114111
"transformers/es2016.ts",
115112
"transformers/es2015.ts",
116113
"transformers/generators.ts",
117114
"transformers/es5.ts",
115+
"transformers/module/es2015.ts",
116+
"transformers/module/system.ts",
117+
"transformers/module/module.ts",
118118
"transformer.ts",
119119
"sourcemap.ts",
120120
"comments.ts",

src/compiler/binder.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,7 @@ namespace ts {
25342534
&& (leftKind === SyntaxKind.ObjectLiteralExpression
25352535
|| leftKind === SyntaxKind.ArrayLiteralExpression)) {
25362536
// Destructuring assignments are ES6 syntax.
2537-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.DestructuringAssignment;
2537+
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertDestructuringAssignment;
25382538
}
25392539
else if (operatorTokenKind === SyntaxKind.AsteriskAsteriskToken
25402540
|| operatorTokenKind === SyntaxKind.AsteriskAsteriskEqualsToken) {
@@ -2615,9 +2615,9 @@ namespace ts {
26152615

26162616
// A class with a parameter property assignment, property initializer, or decorator is
26172617
// TypeScript syntax.
2618-
// An exported declaration may be TypeScript syntax.
2618+
// An exported declaration may be TypeScript syntax, but is handled by the visitor
2619+
// for a namespace declaration.
26192620
if ((subtreeFlags & TransformFlags.TypeScriptClassSyntaxMask)
2620-
|| (modifierFlags & ModifierFlags.Export)
26212621
|| node.typeParameters) {
26222622
transformFlags |= TransformFlags.AssertTypeScript;
26232623
}
@@ -2787,11 +2787,6 @@ namespace ts {
27872787
else {
27882788
transformFlags = subtreeFlags | TransformFlags.ContainsHoistedDeclarationOrCompletion;
27892789

2790-
// If a FunctionDeclaration is exported, then it is either ES6 or TypeScript syntax.
2791-
if (modifierFlags & ModifierFlags.Export) {
2792-
transformFlags |= TransformFlags.AssertTypeScript | TransformFlags.AssertES2015;
2793-
}
2794-
27952790
// TypeScript-specific modifiers, type parameters, and type annotations are TypeScript
27962791
// syntax.
27972792
if (modifierFlags & ModifierFlags.TypeScriptModifier
@@ -2933,11 +2928,6 @@ namespace ts {
29332928
else {
29342929
transformFlags = subtreeFlags;
29352930

2936-
// If a VariableStatement is exported, then it is either ES6 or TypeScript syntax.
2937-
if (modifierFlags & ModifierFlags.Export) {
2938-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
2939-
}
2940-
29412931
if (declarationListTransformFlags & TransformFlags.ContainsBindingPattern) {
29422932
transformFlags |= TransformFlags.AssertES2015;
29432933
}
@@ -3054,12 +3044,6 @@ namespace ts {
30543044
transformFlags |= TransformFlags.AssertJsx;
30553045
break;
30563046

3057-
case SyntaxKind.ExportKeyword:
3058-
// This node is both ES6 and TypeScript syntax.
3059-
transformFlags |= TransformFlags.AssertES2015 | TransformFlags.AssertTypeScript;
3060-
break;
3061-
3062-
case SyntaxKind.DefaultKeyword:
30633047
case SyntaxKind.NoSubstitutionTemplateLiteral:
30643048
case SyntaxKind.TemplateHead:
30653049
case SyntaxKind.TemplateMiddle:
@@ -3068,6 +3052,7 @@ namespace ts {
30683052
case SyntaxKind.TaggedTemplateExpression:
30693053
case SyntaxKind.ShorthandPropertyAssignment:
30703054
case SyntaxKind.ForOfStatement:
3055+
case SyntaxKind.StaticKeyword:
30713056
// These nodes are ES6 syntax.
30723057
transformFlags |= TransformFlags.AssertES2015;
30733058
break;

src/compiler/core.ts

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,16 @@ namespace ts {
424424

425425
export function some<T>(array: T[], predicate?: (value: T) => boolean): boolean {
426426
if (array) {
427-
for (const v of array) {
428-
if (!predicate || predicate(v)) {
429-
return true;
427+
if (predicate) {
428+
for (const v of array) {
429+
if (predicate(v)) {
430+
return true;
431+
}
430432
}
431433
}
434+
else {
435+
return array.length > 0;
436+
}
432437
}
433438
return false;
434439
}
@@ -523,14 +528,35 @@ namespace ts {
523528
return result;
524529
}
525530

526-
export function addRange<T>(to: T[], from: T[]): void {
527-
if (to && from) {
528-
for (const v of from) {
529-
if (v !== undefined) {
530-
to.push(v);
531-
}
532-
}
531+
/**
532+
* Appends a value to an array, returning the array.
533+
*
534+
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
535+
* is created if `value` was appended.
536+
* @param value The value to append to the array. If `value` is `undefined`, nothing is
537+
* appended.
538+
*/
539+
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined {
540+
if (value === undefined) return to;
541+
if (to === undefined) to = [];
542+
to.push(value);
543+
return to;
544+
}
545+
546+
/**
547+
* Appends a range of value to an array, returning the array.
548+
*
549+
* @param to The array to which `value` is to be appended. If `to` is `undefined`, a new array
550+
* is created if `value` was appended.
551+
* @param from The values to append to the array. If `from` is `undefined`, nothing is
552+
* appended. If an element of `from` is `undefined`, that element is not appended.
553+
*/
554+
export function addRange<T>(to: T[] | undefined, from: T[] | undefined): T[] | undefined {
555+
if (from === undefined) return to;
556+
for (const v of from) {
557+
to = append(to, v);
533558
}
559+
return to;
534560
}
535561

536562
export function rangeEquals<T>(array1: T[], array2: T[], pos: number, end: number) {
@@ -543,33 +569,43 @@ namespace ts {
543569
return true;
544570
}
545571

572+
/**
573+
* Returns the first element of an array if non-empty, `undefined` otherwise.
574+
*/
546575
export function firstOrUndefined<T>(array: T[]): T {
547576
return array && array.length > 0
548577
? array[0]
549578
: undefined;
550579
}
551580

581+
/**
582+
* Returns the last element of an array if non-empty, `undefined` otherwise.
583+
*/
584+
export function lastOrUndefined<T>(array: T[]): T {
585+
return array && array.length > 0
586+
? array[array.length - 1]
587+
: undefined;
588+
}
589+
590+
/**
591+
* Returns the only element of an array if it contains only one element, `undefined` otherwise.
592+
*/
552593
export function singleOrUndefined<T>(array: T[]): T {
553594
return array && array.length === 1
554595
? array[0]
555596
: undefined;
556597
}
557598

599+
/**
600+
* Returns the only element of an array if it contains only one element; otheriwse, returns the
601+
* array.
602+
*/
558603
export function singleOrMany<T>(array: T[]): T | T[] {
559604
return array && array.length === 1
560605
? array[0]
561606
: array;
562607
}
563608

564-
/**
565-
* Returns the last element of an array if non-empty, undefined otherwise.
566-
*/
567-
export function lastOrUndefined<T>(array: T[]): T {
568-
return array && array.length > 0
569-
? array[array.length - 1]
570-
: undefined;
571-
}
572-
573609
export function replaceElement<T>(array: T[], index: number, value: T): T[] {
574610
const result = array.slice(0);
575611
result[index] = value;
@@ -874,7 +910,7 @@ namespace ts {
874910
* Adds the value to an array of values associated with the key, and returns the array.
875911
* Creates the array if it does not already exist.
876912
*/
877-
export function multiMapAdd<V>(map: Map<V[]>, key: string, value: V): V[] {
913+
export function multiMapAdd<V>(map: Map<V[]>, key: string | number, value: V): V[] {
878914
const values = map[key];
879915
if (values) {
880916
values.push(value);

0 commit comments

Comments
 (0)