Skip to content

Commit 99355c5

Browse files
committed
Merge branch 'master' into preserveTypeAliases
# Conflicts: # tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt # tests/baselines/reference/reactDefaultPropsInferenceSuccess.errors.txt # tests/baselines/reference/variadicTuples1.errors.txt
2 parents 3fce1b9 + e1fda83 commit 99355c5

File tree

122 files changed

+4652
-1183
lines changed

Some content is hidden

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

122 files changed

+4652
-1183
lines changed

Diff for: .github/ISSUE_TEMPLATE/Bug_report.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If possible, please try testing the nightly version of TS to see if it's already
2929
For npm: `typescript@next`
3030
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly
3131
32-
Note: The TypeScript Playground can be used to try older verions of TypeScript.
32+
Note: The TypeScript Playground can be used to try older versions of TypeScript.
3333
3434
Please keep and fill in the line that best applies:
3535
-->

Diff for: src/compiler/checker.ts

+198-150
Large diffs are not rendered by default.

Diff for: src/compiler/diagnosticMessages.json

+26-6
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,6 @@
843843
"category": "Error",
844844
"code": 1255
845845
},
846-
"A rest element must be last in a tuple type.": {
847-
"category": "Error",
848-
"code": 1256
849-
},
850846
"A required element cannot follow an optional element.": {
851847
"category": "Error",
852848
"code": 1257
@@ -875,6 +871,14 @@
875871
"category": "Error",
876872
"code": 1264
877873
},
874+
"A rest element cannot follow another rest element.": {
875+
"category": "Error",
876+
"code": 1265
877+
},
878+
"An optional element cannot follow a rest element.": {
879+
"category": "Error",
880+
"code": 1266
881+
},
878882

879883
"'with' statements are not allowed in an async function block.": {
880884
"category": "Error",
@@ -2621,9 +2625,25 @@
26212625
"category": "Error",
26222626
"code": 2621
26232627
},
2624-
"Element at index {0} is variadic in one type but not in the other.": {
2628+
"Source provides no match for required element at position {0} in target.": {
2629+
"category": "Error",
2630+
"code": 2623
2631+
},
2632+
"Source provides no match for variadic element at position {0} in target.": {
2633+
"category": "Error",
2634+
"code": 2624
2635+
},
2636+
"Variadic element at position {0} in source does not match element at position {1} in target.": {
2637+
"category": "Error",
2638+
"code": 2625
2639+
},
2640+
"Type at position {0} in source is not compatible with type at position {1} in target.": {
2641+
"category": "Error",
2642+
"code": 2626
2643+
},
2644+
"Type at positions {0} through {1} in source is not compatible with type at position {2} in target.": {
26252645
"category": "Error",
2626-
"code": 2622
2646+
"code": 2627
26272647
},
26282648

26292649
"Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": {

Diff for: src/compiler/factory/utilities.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,12 @@ namespace ts {
511511
* 3- The containing SourceFile has an entry in renamedDependencies for the import as requested by some module loaders (e.g. System).
512512
* Otherwise, a new StringLiteral node representing the module name will be returned.
513513
*/
514-
export function getExternalModuleNameLiteral(factory: NodeFactory, importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) {
515-
const moduleName = getExternalModuleName(importNode)!; // TODO: GH#18217
516-
if (moduleName.kind === SyntaxKind.StringLiteral) {
514+
export function getExternalModuleNameLiteral(factory: NodeFactory, importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration | ImportCall, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, compilerOptions: CompilerOptions) {
515+
const moduleName = getExternalModuleName(importNode);
516+
if (moduleName && isStringLiteral(moduleName)) {
517517
return tryGetModuleNameFromDeclaration(importNode, host, factory, resolver, compilerOptions)
518-
|| tryRenameExternalModule(factory, <StringLiteral>moduleName, sourceFile)
519-
|| factory.cloneNode(<StringLiteral>moduleName);
518+
|| tryRenameExternalModule(factory, moduleName, sourceFile)
519+
|| factory.cloneNode(moduleName);
520520
}
521521

522522
return undefined;
@@ -528,7 +528,7 @@ namespace ts {
528528
*/
529529
function tryRenameExternalModule(factory: NodeFactory, moduleName: LiteralExpression, sourceFile: SourceFile) {
530530
const rename = sourceFile.renamedDependencies && sourceFile.renamedDependencies.get(moduleName.text);
531-
return rename && factory.createStringLiteral(rename);
531+
return rename ? factory.createStringLiteral(rename) : undefined;
532532
}
533533

534534
/**
@@ -551,7 +551,7 @@ namespace ts {
551551
return undefined;
552552
}
553553

554-
function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration, host: EmitHost, factory: NodeFactory, resolver: EmitResolver, compilerOptions: CompilerOptions) {
554+
function tryGetModuleNameFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ImportCall, host: EmitHost, factory: NodeFactory, resolver: EmitResolver, compilerOptions: CompilerOptions) {
555555
return tryGetModuleNameFromFile(factory, resolver.getExternalModuleFileFromDeclaration(declaration), host, compilerOptions);
556556
}
557557

Diff for: src/compiler/transformers/classFields.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ namespace ts {
9090
return visitPropertyDeclaration(node as PropertyDeclaration);
9191
case SyntaxKind.VariableStatement:
9292
return visitVariableStatement(node as VariableStatement);
93-
case SyntaxKind.ComputedPropertyName:
94-
return visitComputedPropertyName(node as ComputedPropertyName);
9593
case SyntaxKind.PropertyAccessExpression:
9694
return visitPropertyAccessExpression(node as PropertyAccessExpression);
9795
case SyntaxKind.PrefixUnaryExpression:
@@ -184,7 +182,7 @@ namespace ts {
184182
let node = visitEachChild(name, visitor, context);
185183
if (some(pendingExpressions)) {
186184
const expressions = pendingExpressions;
187-
expressions.push(name.expression);
185+
expressions.push(node.expression);
188186
pendingExpressions = [];
189187
node = factory.updateComputedPropertyName(
190188
node,

Diff for: src/compiler/transformers/module/module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,10 @@ namespace ts {
609609
}
610610

611611
function visitImportCallExpression(node: ImportCall): Expression {
612-
const argument = visitNode(firstOrUndefined(node.arguments), moduleExpressionElementVisitor);
612+
const externalModuleName = getExternalModuleNameLiteral(factory, node, currentSourceFile, host, resolver, compilerOptions);
613+
const firstArgument = visitNode(firstOrUndefined(node.arguments), moduleExpressionElementVisitor);
614+
// Only use the external module name if it differs from the first argument. This allows us to preserve the quote style of the argument on output.
615+
const argument = externalModuleName && (!firstArgument || !isStringLiteral(firstArgument) || firstArgument.text !== externalModuleName.text) ? externalModuleName : firstArgument;
613616
const containsLexicalThis = !!(node.transformFlags & TransformFlags.ContainsLexicalThis);
614617
switch (compilerOptions.module) {
615618
case ModuleKind.AMD:

Diff for: src/compiler/transformers/module/system.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1495,13 +1495,17 @@ namespace ts {
14951495
// }
14961496
// };
14971497
// });
1498+
const externalModuleName = getExternalModuleNameLiteral(factory, node, currentSourceFile, host, resolver, compilerOptions);
1499+
const firstArgument = visitNode(firstOrUndefined(node.arguments), destructuringAndImportCallVisitor);
1500+
// Only use the external module name if it differs from the first argument. This allows us to preserve the quote style of the argument on output.
1501+
const argument = externalModuleName && (!firstArgument || !isStringLiteral(firstArgument) || firstArgument.text !== externalModuleName.text) ? externalModuleName : firstArgument;
14981502
return factory.createCallExpression(
14991503
factory.createPropertyAccessExpression(
15001504
contextObject,
15011505
factory.createIdentifier("import")
15021506
),
15031507
/*typeArguments*/ undefined,
1504-
some(node.arguments) ? [visitNode(node.arguments[0], destructuringAndImportCallVisitor)] : []
1508+
argument ? [argument] : []
15051509
);
15061510
}
15071511

Diff for: src/compiler/types.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -4607,7 +4607,7 @@ namespace ts {
46074607
isOptionalParameter(node: ParameterDeclaration): boolean;
46084608
moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean;
46094609
isArgumentsLocalBinding(node: Identifier): boolean;
4610-
getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): SourceFile | undefined;
4610+
getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode | ImportCall): SourceFile | undefined;
46114611
getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): string[] | undefined;
46124612
getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[] | undefined;
46134613
isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean;
@@ -5251,18 +5251,21 @@ namespace ts {
52515251
}
52525252

52535253
export const enum ElementFlags {
5254-
Required = 1 << 0, // T
5255-
Optional = 1 << 1, // T?
5256-
Rest = 1 << 2, // ...T[]
5257-
Variadic = 1 << 3, // ...T
5258-
Variable = Rest | Variadic,
5254+
Required = 1 << 0, // T
5255+
Optional = 1 << 1, // T?
5256+
Rest = 1 << 2, // ...T[]
5257+
Variadic = 1 << 3, // ...T
5258+
Fixed = Required | Optional,
5259+
Variable = Rest | Variadic,
5260+
NonRequired = Optional | Rest | Variadic,
5261+
NonRest = Required | Optional | Variadic,
52595262
}
52605263

52615264
export interface TupleType extends GenericType {
52625265
elementFlags: readonly ElementFlags[];
5263-
minLength: number;
5264-
fixedLength: number;
5265-
hasRestElement: boolean;
5266+
minLength: number; // Number of required or variadic elements
5267+
fixedLength: number; // Number of initial required or optional elements
5268+
hasRestElement: boolean; // True if tuple has any rest or variadic elements
52665269
combinedFlags: ElementFlags;
52675270
readonly: boolean;
52685271
labeledElementDeclarations?: readonly (NamedTupleMember | ParameterDeclaration)[];

Diff for: src/compiler/utilities.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,10 @@ namespace ts {
907907
}
908908
}
909909

910+
export function hasPossibleExternalModuleReference(node: Node): node is AnyImportOrReExport | ModuleDeclaration | ImportTypeNode | ImportCall {
911+
return isAnyImportOrReExport(node) || isModuleDeclaration(node) || isImportTypeNode(node) || isImportCall(node);
912+
}
913+
910914
export function isAnyImportOrReExport(node: Node): node is AnyImportOrReExport {
911915
return isAnyImportSyntax(node) || isExportDeclaration(node);
912916
}
@@ -2426,7 +2430,7 @@ namespace ts {
24262430
}
24272431
}
24282432

2429-
export function getExternalModuleName(node: AnyImportOrReExport | ImportTypeNode): Expression | undefined {
2433+
export function getExternalModuleName(node: AnyImportOrReExport | ImportTypeNode | ImportCall): Expression | undefined {
24302434
switch (node.kind) {
24312435
case SyntaxKind.ImportDeclaration:
24322436
case SyntaxKind.ExportDeclaration:
@@ -2435,6 +2439,8 @@ namespace ts {
24352439
return node.moduleReference.kind === SyntaxKind.ExternalModuleReference ? node.moduleReference.expression : undefined;
24362440
case SyntaxKind.ImportType:
24372441
return isLiteralImportTypeNode(node) ? node.argument.literal : undefined;
2442+
case SyntaxKind.CallExpression:
2443+
return node.arguments[0];
24382444
default:
24392445
return Debug.assertNever(node);
24402446
}
@@ -3065,14 +3071,7 @@ namespace ts {
30653071
return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind);
30663072
}
30673073

3068-
export type TriviaKind =
3069-
SyntaxKind.SingleLineCommentTrivia
3070-
| SyntaxKind.MultiLineCommentTrivia
3071-
| SyntaxKind.NewLineTrivia
3072-
| SyntaxKind.WhitespaceTrivia
3073-
| SyntaxKind.ShebangTrivia
3074-
| SyntaxKind.ConflictMarkerTrivia;
3075-
export function isTrivia(token: SyntaxKind): token is TriviaKind {
3074+
export function isTrivia(token: SyntaxKind): token is TriviaSyntaxKind {
30763075
return SyntaxKind.FirstTriviaToken <= token && token <= SyntaxKind.LastTriviaToken;
30773076
}
30783077

@@ -3580,7 +3579,8 @@ namespace ts {
35803579
}
35813580

35823581
// TODO: Should prefix `++` and `--` be moved to the `Update` precedence?
3583-
// TODO: We are missing `TypeAssertionExpression`
3582+
case SyntaxKind.TypeAssertionExpression:
3583+
case SyntaxKind.NonNullExpression:
35843584
case SyntaxKind.PrefixUnaryExpression:
35853585
case SyntaxKind.TypeOfExpression:
35863586
case SyntaxKind.VoidExpression:
@@ -3602,6 +3602,9 @@ namespace ts {
36023602
case SyntaxKind.ElementAccessExpression:
36033603
return OperatorPrecedence.Member;
36043604

3605+
case SyntaxKind.AsExpression:
3606+
return OperatorPrecedence.Relational;
3607+
36053608
case SyntaxKind.ThisKeyword:
36063609
case SyntaxKind.SuperKeyword:
36073610
case SyntaxKind.Identifier:

0 commit comments

Comments
 (0)