Skip to content

Commit 7dbd48b

Browse files
committed
Merge branch 'master' into nodeFactory
# Conflicts: # src/compiler/transformers/es2015.ts # src/compiler/transformers/module/system.ts
2 parents d810aeb + 4bda7ce commit 7dbd48b

File tree

139 files changed

+1828
-529
lines changed

Some content is hidden

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

139 files changed

+1828
-529
lines changed

.github/ISSUE_TEMPLATE/Bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ assignees: ''
77

88
---
99

10-
<!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨
10+
<!-- 🚨 STOP 🚨 STOP 🚨 STOP 🚨
1111
1212
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!
1313

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"node": ">=4.2.0"
3030
},
3131
"devDependencies": {
32-
"@octokit/rest": "17.11.2",
32+
"@octokit/rest": "latest",
3333
"@types/browserify": "latest",
3434
"@types/chai": "latest",
3535
"@types/convert-source-map": "latest",

scripts/request-pr-review.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ main().catch(console.error);
4242

4343
async function main() {
4444
const gh = new Octokit({ auth: options.token });
45-
const response = await gh.pulls.createReviewRequest({
45+
const response = await gh.pulls.requestReviewers({
4646
owner: options.owner,
4747
repo: options.repo,
4848
pull_number,

src/compiler/checker.ts

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3489,16 +3489,17 @@ namespace ts {
34893489
* Attempts to find the symbol corresponding to the container a symbol is in - usually this
34903490
* is just its' `.parent`, but for locals, this value is `undefined`
34913491
*/
3492-
function getContainersOfSymbol(symbol: Symbol, enclosingDeclaration: Node | undefined): Symbol[] | undefined {
3492+
function getContainersOfSymbol(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags): Symbol[] | undefined {
34933493
const container = getParentOfSymbol(symbol);
34943494
// Type parameters end up in the `members` lists but are not externally visible
34953495
if (container && !(symbol.flags & SymbolFlags.TypeParameter)) {
34963496
const additionalContainers = mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer);
34973497
const reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration);
3498+
const objectLiteralContainer = getVariableDeclarationOfObjectLiteral(container, meaning);
34983499
if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, SymbolFlags.Namespace, /*externalOnly*/ false)) {
3499-
return concatenate(concatenate([container], additionalContainers), reexportContainers); // This order expresses a preference for the real container if it is in scope
3500+
return append(concatenate(concatenate([container], additionalContainers), reexportContainers), objectLiteralContainer); // This order expresses a preference for the real container if it is in scope
35003501
}
3501-
const res = append(additionalContainers, container);
3502+
const res = append(append(additionalContainers, container), objectLiteralContainer);
35023503
return concatenate(res, reexportContainers);
35033504
}
35043505
const candidates = mapDefined(symbol.declarations, d => {
@@ -3523,6 +3524,18 @@ namespace ts {
35233524
}
35243525
}
35253526

3527+
function getVariableDeclarationOfObjectLiteral(symbol: Symbol, meaning: SymbolFlags) {
3528+
// If we're trying to reference some object literal in, eg `var a = { x: 1 }`, the symbol for the literal, `__object`, is distinct
3529+
// from the symbol of the declaration it is being assigned to. Since we can use the declaration to refer to the literal, however,
3530+
// we'd like to make that connection here - potentially causing us to paint the declaration's visibility, and therefore the literal.
3531+
const firstDecl: Node | false = !!length(symbol.declarations) && first(symbol.declarations);
3532+
if (meaning & SymbolFlags.Value && firstDecl && firstDecl.parent && isVariableDeclaration(firstDecl.parent)) {
3533+
if (isObjectLiteralExpression(firstDecl) && firstDecl === firstDecl.parent.initializer || isTypeLiteralNode(firstDecl) && firstDecl === firstDecl.parent.type) {
3534+
return getSymbolOfNode(firstDecl.parent);
3535+
}
3536+
}
3537+
}
3538+
35263539
function getFileSymbolIfFileSymbolExportEqualsContainer(d: Declaration, container: Symbol) {
35273540
const fileSymbol = getExternalModuleContainer(d);
35283541
const exported = fileSymbol && fileSymbol.exports && fileSymbol.exports.get(InternalSymbolName.ExportEquals);
@@ -3916,16 +3929,7 @@ namespace ts {
39163929
// But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible
39173930
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
39183931

3919-
let containers = getContainersOfSymbol(symbol, enclosingDeclaration);
3920-
// If we're trying to reference some object literal in, eg `var a = { x: 1 }`, the symbol for the literal, `__object`, is distinct
3921-
// from the symbol of the declaration it is being assigned to. Since we can use the declaration to refer to the literal, however,
3922-
// we'd like to make that connection here - potentially causing us to paint the declaration's visibility, and therefore the literal.
3923-
const firstDecl: Node | false = !!length(symbol.declarations) && first(symbol.declarations);
3924-
if (!length(containers) && meaning & SymbolFlags.Value && firstDecl && isObjectLiteralExpression(firstDecl)) {
3925-
if (firstDecl.parent && isVariableDeclaration(firstDecl.parent) && firstDecl === firstDecl.parent.initializer) {
3926-
containers = [getSymbolOfNode(firstDecl.parent)];
3927-
}
3928-
}
3932+
const containers = getContainersOfSymbol(symbol, enclosingDeclaration, meaning);
39293933
const parentResult = isAnySymbolAccessible(containers, enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible, allowModules);
39303934
if (parentResult) {
39313935
return parentResult;
@@ -4417,8 +4421,8 @@ namespace ts {
44174421
context.inferTypeParameters = (<ConditionalType>type).root.inferTypeParameters;
44184422
const extendsTypeNode = typeToTypeNodeHelper((<ConditionalType>type).extendsType, context);
44194423
context.inferTypeParameters = saveInferTypeParameters;
4420-
const trueTypeNode = typeToTypeNodeHelper(getTrueTypeFromConditionalType(<ConditionalType>type), context);
4421-
const falseTypeNode = typeToTypeNodeHelper(getFalseTypeFromConditionalType(<ConditionalType>type), context);
4424+
const trueTypeNode = typeToTypeNodeOrCircularityElision(getTrueTypeFromConditionalType(<ConditionalType>type));
4425+
const falseTypeNode = typeToTypeNodeOrCircularityElision(getFalseTypeFromConditionalType(<ConditionalType>type));
44224426
context.approximateLength += 15;
44234427
return factory.createConditionalTypeNode(checkTypeNode, extendsTypeNode, trueTypeNode, falseTypeNode);
44244428
}
@@ -4428,6 +4432,21 @@ namespace ts {
44284432

44294433
return Debug.fail("Should be unreachable.");
44304434

4435+
4436+
function typeToTypeNodeOrCircularityElision(type: Type) {
4437+
if (type.flags & TypeFlags.Union) {
4438+
if (context.visitedTypes && context.visitedTypes.has("" + getTypeId(type))) {
4439+
if (!(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
4440+
context.encounteredError = true;
4441+
context.tracker?.reportCyclicStructureError?.();
4442+
}
4443+
return createElidedInformationPlaceholder(context);
4444+
}
4445+
return visitAndTransformType(type, type => typeToTypeNodeHelper(type, context));
4446+
}
4447+
return typeToTypeNodeHelper(type, context);
4448+
}
4449+
44314450
function createMappedTypeNodeFromType(type: MappedType) {
44324451
Debug.assert(!!(type.flags & TypeFlags.Object));
44334452
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>factory.createToken(type.declaration.readonlyToken.kind) : undefined;
@@ -5135,7 +5154,7 @@ namespace ts {
51355154
needsQualification(accessibleSymbolChain[0], context.enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) {
51365155

51375156
// Go up and add our parent.
5138-
const parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration);
5157+
const parents = getContainersOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol, context.enclosingDeclaration, meaning);
51395158
if (length(parents)) {
51405159
parentSpecifiers = parents!.map(symbol =>
51415160
some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)
@@ -13072,10 +13091,12 @@ namespace ts {
1307213091
return links.resolvedType;
1307313092
}
1307413093

13075-
function createIndexedAccessType(objectType: Type, indexType: Type) {
13094+
function createIndexedAccessType(objectType: Type, indexType: Type, aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined) {
1307613095
const type = <IndexedAccessType>createType(TypeFlags.IndexedAccess);
1307713096
type.objectType = objectType;
1307813097
type.indexType = indexType;
13098+
type.aliasSymbol = aliasSymbol;
13099+
type.aliasTypeArguments = aliasTypeArguments;
1307913100
return type;
1308013101
}
1308113102

@@ -13410,11 +13431,11 @@ namespace ts {
1341013431
return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper);
1341113432
}
1341213433

13413-
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression): Type {
13414-
return getIndexedAccessTypeOrUndefined(objectType, indexType, accessNode, AccessFlags.None) || (accessNode ? errorType : unknownType);
13434+
function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): Type {
13435+
return getIndexedAccessTypeOrUndefined(objectType, indexType, accessNode, AccessFlags.None, aliasSymbol, aliasTypeArguments) || (accessNode ? errorType : unknownType);
1341513436
}
1341613437

13417-
function getIndexedAccessTypeOrUndefined(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, accessFlags = AccessFlags.None): Type | undefined {
13438+
function getIndexedAccessTypeOrUndefined(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, accessFlags = AccessFlags.None, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): Type | undefined {
1341813439
if (objectType === wildcardType || indexType === wildcardType) {
1341913440
return wildcardType;
1342013441
}
@@ -13436,7 +13457,7 @@ namespace ts {
1343613457
const id = objectType.id + "," + indexType.id;
1343713458
let type = indexedAccessTypes.get(id);
1343813459
if (!type) {
13439-
indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType));
13460+
indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType, aliasSymbol, aliasTypeArguments));
1344013461
}
1344113462
return type;
1344213463
}
@@ -13464,7 +13485,7 @@ namespace ts {
1346413485
if (wasMissingProp) {
1346513486
return undefined;
1346613487
}
13467-
return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes) : getUnionType(propTypes);
13488+
return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes, aliasSymbol, aliasTypeArguments) : getUnionType(propTypes, UnionReduction.Literal, aliasSymbol, aliasTypeArguments);
1346813489
}
1346913490
return getPropertyTypeForIndexType(objectType, apparentObjectType, indexType, indexType, /* supressNoImplicitAnyError */ false, accessNode, accessFlags | AccessFlags.CacheSymbol);
1347013491
}
@@ -13474,7 +13495,8 @@ namespace ts {
1347413495
if (!links.resolvedType) {
1347513496
const objectType = getTypeFromTypeNode(node.objectType);
1347613497
const indexType = getTypeFromTypeNode(node.indexType);
13477-
const resolved = getIndexedAccessType(objectType, indexType, node);
13498+
const potentialAlias = getAliasSymbolForTypeNode(node);
13499+
const resolved = getIndexedAccessType(objectType, indexType, node, potentialAlias, getTypeArgumentsForAliasSymbol(potentialAlias));
1347813500
links.resolvedType = resolved.flags & TypeFlags.IndexedAccess &&
1347913501
(<IndexedAccessType>resolved).objectType === objectType &&
1348013502
(<IndexedAccessType>resolved).indexType === indexType ?
@@ -14631,7 +14653,7 @@ namespace ts {
1463114653
return getIndexType(instantiateType((<IndexType>type).type, mapper));
1463214654
}
1463314655
if (flags & TypeFlags.IndexedAccess) {
14634-
return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper));
14656+
return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper), /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
1463514657
}
1463614658
if (flags & TypeFlags.Conditional) {
1463714659
return getConditionalTypeInstantiation(<ConditionalType>type, combineTypeMappers((<ConditionalType>type).mapper, mapper));
@@ -22689,7 +22711,7 @@ namespace ts {
2268922711
const id = lhs.expression;
2269022712
const parentSymbol = resolveName(id, id.escapedText, SymbolFlags.Value, undefined, id.escapedText, /*isUse*/ true);
2269122713
if (parentSymbol) {
22692-
const annotated = getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
22714+
const annotated = parentSymbol.valueDeclaration && getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
2269322715
if (annotated) {
2269422716
const nameStr = getElementOrPropertyAccessName(lhs);
2269522717
if (nameStr !== undefined) {
@@ -36194,15 +36216,16 @@ namespace ts {
3619436216
// Emitter support
3619536217

3619636218
function isArgumentsLocalBinding(nodeIn: Identifier): boolean {
36197-
if (!isGeneratedIdentifier(nodeIn)) {
36198-
const node = getParseTreeNode(nodeIn, isIdentifier);
36199-
if (node) {
36200-
const isPropertyName = node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node;
36201-
return !isPropertyName && getReferencedValueSymbol(node) === argumentsSymbol;
36202-
}
36203-
}
36204-
36205-
return false;
36219+
// Note: does not handle isShorthandPropertyAssignment (and probably a few more)
36220+
if (isGeneratedIdentifier(nodeIn)) return false;
36221+
const node = getParseTreeNode(nodeIn, isIdentifier);
36222+
if (!node) return false;
36223+
const parent = node.parent;
36224+
if (!parent) return false;
36225+
const isPropertyName = ((isPropertyAccessExpression(parent)
36226+
|| isPropertyAssignment(parent))
36227+
&& parent.name === node);
36228+
return !isPropertyName && getReferencedValueSymbol(node) === argumentsSymbol;
3620636229
}
3620736230

3620836231
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,10 @@ namespace ts {
31203120
};
31213121
}
31223122
if (isImplicitGlob(spec)) {
3123-
return { key: spec, flags: WatchDirectoryFlags.Recursive };
3123+
return {
3124+
key: useCaseSensitiveFileNames ? spec : toFileNameLowerCase(spec),
3125+
flags: WatchDirectoryFlags.Recursive
3126+
};
31243127
}
31253128
return undefined;
31263129
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,6 +3533,10 @@
35333533
"category": "Error",
35343534
"code": 5087
35353535
},
3536+
"The inferred type of '{0}' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary.": {
3537+
"category": "Error",
3538+
"code": 5088
3539+
},
35363540

35373541
"Generates a sourcemap for each corresponding '.d.ts' file.": {
35383542
"category": "Message",

src/compiler/transformers/declarations.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace ts {
7070
trackSymbol,
7171
reportInaccessibleThisError,
7272
reportInaccessibleUniqueSymbolError,
73+
reportCyclicStructureError,
7374
reportPrivateInBaseOfClassExpression,
7475
reportLikelyUnsafeImportRequiredError,
7576
moduleResolverHost: host,
@@ -173,6 +174,13 @@ namespace ts {
173174
}
174175
}
175176

177+
function reportCyclicStructureError() {
178+
if (errorNameNode) {
179+
context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_a_type_with_a_cyclic_structure_which_cannot_be_trivially_serialized_A_type_annotation_is_necessary,
180+
declarationNameToString(errorNameNode)));
181+
}
182+
}
183+
176184
function reportInaccessibleThisError() {
177185
if (errorNameNode) {
178186
context.addDiagnostic(createDiagnosticForNode(errorNameNode, Diagnostics.The_inferred_type_of_0_references_an_inaccessible_1_type_A_type_annotation_is_necessary,

0 commit comments

Comments
 (0)