Skip to content

Commit de13cc4

Browse files
committed
Merge remote-tracking branch 'origin/master' into importOutlining
2 parents f1713c9 + 1a320fc commit de13cc4

File tree

1,509 files changed

+5857
-5544
lines changed

Some content is hidden

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

1,509 files changed

+5857
-5544
lines changed

.github/ISSUE_TEMPLATE/Bug_report.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
5+
---
6+
7+
<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨
8+
9+
Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common "Bugs" That Aren't Bugs section!
10+
11+
Please help us by doing the following steps before logging an issue:
12+
* Search: https://github.com/Microsoft/TypeScript/search?type=Issues
13+
* Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ
14+
15+
Please fill in the *entire* template below.
16+
-->
17+
18+
<!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->
19+
**TypeScript Version:** 2.9.0-dev.201xxxxx
20+
21+
<!-- Search terms you tried before logging this (so others can find this issue more easily) -->
22+
**Search Terms:**
23+
24+
**Code**
25+
26+
```ts
27+
// A *self-contained* demonstration of the problem follows...
28+
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
29+
```
30+
31+
**Expected behavior:**
32+
33+
**Actual behavior:**
34+
35+
**Playground Link:** <!-- A link to a TypeScript Playground "Share" link which demonstrates this behavior -->
36+
37+
**Related Issues:** <!-- Did you find other bugs that looked similar? -->
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
5+
---
6+
7+
<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨
8+
9+
Half of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Please read the FAQ first, especially the "Common Feature Requests" section.
10+
11+
-->
12+
13+
## Search Terms
14+
15+
<!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily -->
16+
17+
## Suggestion
18+
19+
<!-- A summary of what you'd like to see added or changed -->
20+
21+
## Use Cases
22+
23+
<!--
24+
What do you want to use this for?
25+
What shortcomings exist with current approaches?
26+
-->
27+
28+
## Examples
29+
30+
<!-- Show how this would be used and what the behavior would be -->
31+
32+
## Checklist
33+
34+
My suggestion meets these guidelines:
35+
[ ] This wouldn't be a breaking change in existing TypeScript / JavaScript code
36+
[ ] This wouldn't change the runtime behavior of existing JavaScript code
37+
[ ] This could be implemented without emitting different JS based on the types of the expressions
38+
[ ] This isn't a runtime feature (e.g. new expression-level syntax)
39+

.github/ISSUE_TEMPLATE/Question.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: Question
3+
about: The issue tracker is not for questions. Please use Stack Overflow or other resources for help writing TypeScript code.
4+
5+
---
6+
7+
THE ISSUE TRACKER IS NOT FOR QUESTIONS.
8+
9+
DO NOT CREATE A NEW ISSUE TO ASK A QUESTION.
10+
11+
IF YOU ARE HAVING PROBLEMS WITH YOUR TYPESCRIPT CODE, DO NOT ASK A QUESTION HERE.
12+
13+
Tens of thousands of TypeScript questions have been asked and answered on StackOverflow; see https://stackoverflow.com/questions/tagged/typescript . You can ask questions there or on other websites.
14+
15+
The only exception is if you have a question about *the TypeScript compiler API itself*. Please post a complete example of what you're trying to do and precisely describe what your question is.
File renamed without changes.
File renamed without changes.

.npmignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ built
22
doc
33
Gulpfile.ts
44
internal
5-
issue_template.md
65
jenkins.sh
76
lib/README.md
87
lib/enu
98
netci.groovy
10-
pull_request_template.md
119
scripts
1210
src
1311
tests
@@ -24,3 +22,4 @@ Jakefile.js
2422
test.config
2523
package-lock.json
2624
yarn.lock
25+
.github/

Jakefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,8 @@ task("LKG", ["clean", "release", "local"].concat(libraryTargets), function () {
650650
return !fs.existsSync(f);
651651
});
652652
if (missingFiles.length > 0) {
653-
fail("Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
654-
". The following files are missing:\n" + missingFiles.join("\n"));
653+
fail(new Error("Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
654+
". The following files are missing:\n" + missingFiles.join("\n")));
655655
}
656656
// Copy all the targets into the LKG directory
657657
jake.mkdirP(LKGDirectory);

src/compiler/checker.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,7 +3158,16 @@ namespace ts {
31583158
Debug.assert(!!(type.flags & TypeFlags.Object));
31593159
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>createToken(type.declaration.readonlyToken.kind) : undefined;
31603160
const questionToken = type.declaration.questionToken ? <QuestionToken | PlusToken | MinusToken>createToken(type.declaration.questionToken.kind) : undefined;
3161-
const typeParameterNode = typeParameterToDeclaration(getTypeParameterFromMappedType(type), context, getConstraintTypeFromMappedType(type));
3161+
let appropriateConstraintTypeNode: TypeNode;
3162+
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
3163+
// We have a { [P in keyof T]: X }
3164+
// We do this to ensure we retain the toplevel keyof-ness of the type which may be lost due to keyof distribution during `getConstraintTypeFromMappedType`
3165+
appropriateConstraintTypeNode = createTypeOperatorNode(typeToTypeNodeHelper(getModifiersTypeFromMappedType(type), context));
3166+
}
3167+
else {
3168+
appropriateConstraintTypeNode = typeToTypeNodeHelper(getConstraintTypeFromMappedType(type), context);
3169+
}
3170+
const typeParameterNode = typeParameterToDeclarationWithConstraint(getTypeParameterFromMappedType(type), context, appropriateConstraintTypeNode);
31623171
const templateTypeNode = typeToTypeNodeHelper(getTemplateTypeFromMappedType(type), context);
31633172
const mappedTypeNode = createMappedTypeNode(readonlyToken, typeParameterNode, questionToken, templateTypeNode);
31643173
return setEmitFlags(mappedTypeNode, EmitFlags.SingleLine);
@@ -3534,17 +3543,21 @@ namespace ts {
35343543
return createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments);
35353544
}
35363545

3537-
function typeParameterToDeclaration(type: TypeParameter, context: NodeBuilderContext, constraint = getConstraintFromTypeParameter(type)): TypeParameterDeclaration {
3546+
function typeParameterToDeclarationWithConstraint(type: TypeParameter, context: NodeBuilderContext, constraintNode: TypeNode): TypeParameterDeclaration {
35383547
const savedContextFlags = context.flags;
35393548
context.flags &= ~NodeBuilderFlags.WriteTypeParametersInQualifiedName; // Avoids potential infinite loop when building for a claimspace with a generic
35403549
const name = symbolToName(type.symbol, context, SymbolFlags.Type, /*expectsIdentifier*/ true);
3541-
const constraintNode = constraint && typeToTypeNodeHelper(constraint, context);
35423550
const defaultParameter = getDefaultFromTypeParameter(type);
35433551
const defaultParameterNode = defaultParameter && typeToTypeNodeHelper(defaultParameter, context);
35443552
context.flags = savedContextFlags;
35453553
return createTypeParameterDeclaration(name, constraintNode, defaultParameterNode);
35463554
}
35473555

3556+
function typeParameterToDeclaration(type: TypeParameter, context: NodeBuilderContext, constraint = getConstraintFromTypeParameter(type)): TypeParameterDeclaration {
3557+
const constraintNode = constraint && typeToTypeNodeHelper(constraint, context);
3558+
return typeParameterToDeclarationWithConstraint(type, context, constraintNode);
3559+
}
3560+
35483561
function symbolToParameterDeclaration(parameterSymbol: Symbol, context: NodeBuilderContext, preserveModifierFlags?: boolean): ParameterDeclaration {
35493562
const parameterDeclaration = getDeclarationOfKind<ParameterDeclaration>(parameterSymbol, SyntaxKind.Parameter);
35503563
Debug.assert(!!parameterDeclaration || isTransientSymbol(parameterSymbol) && !!parameterSymbol.isRestParameter);
@@ -6221,10 +6234,8 @@ namespace ts {
62216234
const templateType = getTemplateTypeFromMappedType(<MappedType>type.target || type);
62226235
const modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
62236236
const templateModifiers = getMappedTypeModifiers(type);
6224-
const constraintDeclaration = type.declaration.typeParameter.constraint;
62256237
const include = keyofStringsOnly ? TypeFlags.StringLiteral : TypeFlags.StringOrNumberLiteralOrUnique;
6226-
if (constraintDeclaration.kind === SyntaxKind.TypeOperator &&
6227-
(<TypeOperatorNode>constraintDeclaration).operator === SyntaxKind.KeyOfKeyword) {
6238+
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
62286239
// We have a { [P in keyof T]: X }
62296240
for (const prop of getPropertiesOfType(modifiersType)) {
62306241
addMemberForKeyType(getLiteralTypeFromPropertyName(prop, include), /*_index*/ undefined, prop);
@@ -6301,15 +6312,23 @@ namespace ts {
63016312
unknownType);
63026313
}
63036314

6315+
function getConstraintDeclarationForMappedType(type: MappedType) {
6316+
return type.declaration.typeParameter.constraint;
6317+
}
6318+
6319+
function isMappedTypeWithKeyofConstraintDeclaration(type: MappedType) {
6320+
const constraintDeclaration = getConstraintDeclarationForMappedType(type);
6321+
return constraintDeclaration.kind === SyntaxKind.TypeOperator &&
6322+
(<TypeOperatorNode>constraintDeclaration).operator === SyntaxKind.KeyOfKeyword;
6323+
}
6324+
63046325
function getModifiersTypeFromMappedType(type: MappedType) {
63056326
if (!type.modifiersType) {
6306-
const constraintDeclaration = type.declaration.typeParameter.constraint;
6307-
if (constraintDeclaration.kind === SyntaxKind.TypeOperator &&
6308-
(<TypeOperatorNode>constraintDeclaration).operator === SyntaxKind.KeyOfKeyword) {
6327+
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
63096328
// If the constraint declaration is a 'keyof T' node, the modifiers type is T. We check
63106329
// AST nodes here because, when T is a non-generic type, the logic below eagerly resolves
63116330
// 'keyof T' to a literal union type and we can't recover T from that type.
6312-
type.modifiersType = instantiateType(getTypeFromTypeNode((<TypeOperatorNode>constraintDeclaration).type), type.mapper || identityMapper);
6331+
type.modifiersType = instantiateType(getTypeFromTypeNode((<TypeOperatorNode>getConstraintDeclarationForMappedType(type)).type), type.mapper || identityMapper);
63136332
}
63146333
else {
63156334
// Otherwise, get the declared constraint type, and if the constraint type is a type parameter,

0 commit comments

Comments
 (0)