@@ -1881,10 +1881,9 @@ namespace ts {
1881
1881
// The ES6 spec permits export * declarations in a module to circularly reference the module itself. For example,
1882
1882
// module 'a' can 'export * from "b"' and 'b' can 'export * from "a"' without error.
1883
1883
function visit(symbol: Symbol): SymbolTable {
1884
- if (!(symbol && symbol.flags & SymbolFlags.HasExports && !contains (visitedSymbols, symbol))) {
1884
+ if (!(symbol && symbol.flags & SymbolFlags.HasExports && pushIfUnique (visitedSymbols, symbol))) {
1885
1885
return;
1886
1886
}
1887
- visitedSymbols.push(symbol);
1888
1887
const symbols = cloneMap(symbol.exports);
1889
1888
// All export * declarations are collected in an __export symbol by the binder
1890
1889
const exportStars = symbol.exports.get(InternalSymbolName.ExportStar);
@@ -2060,10 +2059,10 @@ namespace ts {
2060
2059
}
2061
2060
2062
2061
function getAccessibleSymbolChainFromSymbolTableWorker(symbols: SymbolTable, visitedSymbolTables: SymbolTable[]): Symbol[] {
2063
- if (contains<SymbolTable> (visitedSymbolTables, symbols)) {
2062
+ if (!pushIfUnique (visitedSymbolTables, symbols)) {
2064
2063
return undefined;
2065
2064
}
2066
- visitedSymbolTables.push(symbols);
2065
+
2067
2066
const result = trySymbolTable(symbols);
2068
2067
visitedSymbolTables.pop();
2069
2068
return result;
@@ -2276,14 +2275,7 @@ namespace ts {
2276
2275
// since we will do the emitting later in trackSymbol.
2277
2276
if (shouldComputeAliasToMakeVisible) {
2278
2277
getNodeLinks(declaration).isVisible = true;
2279
- if (aliasesToMakeVisible) {
2280
- if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
2281
- aliasesToMakeVisible.push(anyImportSyntax);
2282
- }
2283
- }
2284
- else {
2285
- aliasesToMakeVisible = [anyImportSyntax];
2286
- }
2278
+ aliasesToMakeVisible = appendIfUnique(aliasesToMakeVisible, anyImportSyntax);
2287
2279
}
2288
2280
return true;
2289
2281
}
@@ -3981,9 +3973,7 @@ namespace ts {
3981
3973
forEach(declarations, declaration => {
3982
3974
getNodeLinks(declaration).isVisible = true;
3983
3975
const resultNode = getAnyImportSyntax(declaration) || declaration;
3984
- if (!contains(result, resultNode)) {
3985
- result.push(resultNode);
3986
- }
3976
+ pushIfUnique(result, resultNode);
3987
3977
3988
3978
if (isInternalModuleImportEqualsDeclaration(declaration)) {
3989
3979
// Add the referenced top container visible
@@ -4793,12 +4783,7 @@ namespace ts {
4793
4783
function appendTypeParameters(typeParameters: TypeParameter[], declarations: ReadonlyArray<TypeParameterDeclaration>): TypeParameter[] {
4794
4784
for (const declaration of declarations) {
4795
4785
const tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration));
4796
- if (!typeParameters) {
4797
- typeParameters = [tp];
4798
- }
4799
- else if (!contains(typeParameters, tp)) {
4800
- typeParameters.push(tp);
4801
- }
4786
+ typeParameters = appendIfUnique(typeParameters, tp);
4802
4787
}
4803
4788
return typeParameters;
4804
4789
}
@@ -5521,9 +5506,7 @@ namespace ts {
5521
5506
if (!match) {
5522
5507
return undefined;
5523
5508
}
5524
- if (!contains(result, match)) {
5525
- (result || (result = [])).push(match);
5526
- }
5509
+ result = appendIfUnique(result, match);
5527
5510
}
5528
5511
return result;
5529
5512
}
@@ -6073,12 +6056,7 @@ namespace ts {
6073
6056
const modifiers = prop ? getDeclarationModifierFlagsFromSymbol(prop) : 0;
6074
6057
if (prop && !(modifiers & excludeModifiers)) {
6075
6058
commonFlags &= prop.flags;
6076
- if (!props) {
6077
- props = [prop];
6078
- }
6079
- else if (!contains(props, prop)) {
6080
- props.push(prop);
6081
- }
6059
+ props = appendIfUnique(props, prop);
6082
6060
checkFlags |= (isReadonlySymbol(prop) ? CheckFlags.Readonly : 0) |
6083
6061
(!(modifiers & ModifierFlags.NonPublicAccessibilityModifier) ? CheckFlags.ContainsPublic : 0) |
6084
6062
(modifiers & ModifierFlags.Protected ? CheckFlags.ContainsProtected : 0) |
@@ -6237,12 +6215,7 @@ namespace ts {
6237
6215
let result: TypeParameter[];
6238
6216
forEach(getEffectiveTypeParameterDeclarations(declaration), node => {
6239
6217
const tp = getDeclaredTypeOfTypeParameter(node.symbol);
6240
- if (!contains(result, tp)) {
6241
- if (!result) {
6242
- result = [];
6243
- }
6244
- result.push(tp);
6245
- }
6218
+ result = appendIfUnique(result, tp);
6246
6219
});
6247
6220
return result;
6248
6221
}
@@ -11715,9 +11688,7 @@ namespace ts {
11715
11688
if (type === declaredType && declaredType === initialType) {
11716
11689
return type;
11717
11690
}
11718
- if (!contains(antecedentTypes, type)) {
11719
- antecedentTypes.push(type);
11720
- }
11691
+ pushIfUnique(antecedentTypes, type);
11721
11692
// If an antecedent type is not a subset of the declared type, we need to perform
11722
11693
// subtype reduction. This happens when a "foreign" type is injected into the control
11723
11694
// flow using the instanceof operator or a user defined type predicate.
@@ -11783,9 +11754,7 @@ namespace ts {
11783
11754
if (cached) {
11784
11755
return cached;
11785
11756
}
11786
- if (!contains(antecedentTypes, type)) {
11787
- antecedentTypes.push(type);
11788
- }
11757
+ pushIfUnique(antecedentTypes, type);
11789
11758
// If an antecedent type is not a subset of the declared type, we need to perform
11790
11759
// subtype reduction. This happens when a "foreign" type is injected into the control
11791
11760
// flow using the instanceof operator or a user defined type predicate.
@@ -16826,9 +16795,7 @@ namespace ts {
16826
16795
? Diagnostics.Type_of_iterated_elements_of_a_yield_Asterisk_operand_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member
16827
16796
: Diagnostics.Type_of_yield_operand_in_an_async_generator_must_either_be_a_valid_promise_or_must_not_contain_a_callable_then_member);
16828
16797
}
16829
- if (!contains(aggregatedTypes, type)) {
16830
- aggregatedTypes.push(type);
16831
- }
16798
+ pushIfUnique(aggregatedTypes, type);
16832
16799
}
16833
16800
});
16834
16801
@@ -16880,9 +16847,7 @@ namespace ts {
16880
16847
if (type.flags & TypeFlags.Never) {
16881
16848
hasReturnOfTypeNever = true;
16882
16849
}
16883
- else if (!contains(aggregatedTypes, type)) {
16884
- aggregatedTypes.push(type);
16885
- }
16850
+ pushIfUnique(aggregatedTypes, type);
16886
16851
}
16887
16852
else {
16888
16853
hasReturnWithNoExpression = true;
@@ -16893,9 +16858,7 @@ namespace ts {
16893
16858
return undefined;
16894
16859
}
16895
16860
if (strictNullChecks && aggregatedTypes.length && hasReturnWithNoExpression) {
16896
- if (!contains(aggregatedTypes, undefinedType)) {
16897
- aggregatedTypes.push(undefinedType);
16898
- }
16861
+ pushIfUnique(aggregatedTypes, undefinedType);
16899
16862
}
16900
16863
return aggregatedTypes;
16901
16864
}
0 commit comments