Skip to content

Commit f03fecb

Browse files
committed
Merge branch 'master' into object-spread
2 parents 83e95d4 + ed4fead commit f03fecb

File tree

63 files changed

+1677
-427
lines changed

Some content is hidden

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

63 files changed

+1677
-427
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"travis-fold": "latest",
7777
"ts-node": "latest",
7878
"tsd": "latest",
79-
"tslint": "next",
79+
"tslint": "4.0.0-dev.0",
8080
"typescript": "next"
8181
},
8282
"scripts": {

src/compiler/binder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,11 @@ namespace ts {
12371237
const postExpressionLabel = createBranchLabel();
12381238
bindCondition(node.condition, trueLabel, falseLabel);
12391239
currentFlow = finishFlowLabel(trueLabel);
1240+
bind(node.questionToken);
12401241
bind(node.whenTrue);
12411242
addAntecedent(postExpressionLabel, currentFlow);
12421243
currentFlow = finishFlowLabel(falseLabel);
1244+
bind(node.colonToken);
12431245
bind(node.whenFalse);
12441246
addAntecedent(postExpressionLabel, currentFlow);
12451247
currentFlow = finishFlowLabel(postExpressionLabel);

src/compiler/checker.ts

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ namespace ts {
107107

108108
getJsxElementAttributesType,
109109
getJsxIntrinsicTagNames,
110-
isOptionalParameter
110+
isOptionalParameter,
111+
tryFindAmbientModuleWithoutAugmentations: moduleName => {
112+
// we deliberately exclude augmentations
113+
// since we are only interested in declarations of the module itself
114+
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
115+
}
111116
};
112117

113118
const tupleTypes: GenericType[] = [];
@@ -1370,16 +1375,11 @@ namespace ts {
13701375
return;
13711376
}
13721377

1373-
const isRelative = isExternalModuleNameRelative(moduleName);
1374-
const quotedName = '"' + moduleName + '"';
1375-
if (!isRelative) {
1376-
const symbol = getSymbol(globals, quotedName, SymbolFlags.ValueModule);
1377-
if (symbol) {
1378-
// merged symbol is module declaration symbol combined with all augmentations
1379-
return getMergedSymbol(symbol);
1380-
}
1378+
const ambientModule = tryFindAmbientModule(moduleName, /*withAugmentations*/ true);
1379+
if (ambientModule) {
1380+
return ambientModule;
13811381
}
1382-
1382+
const isRelative = isExternalModuleNameRelative(moduleName);
13831383
const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference);
13841384
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
13851385
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
@@ -4762,6 +4762,15 @@ namespace ts {
47624762
}
47634763
}
47644764

4765+
function tryFindAmbientModule(moduleName: string, withAugmentations: boolean) {
4766+
if (isExternalModuleNameRelative(moduleName)) {
4767+
return undefined;
4768+
}
4769+
const symbol = getSymbol(globals, `"${moduleName}"`, SymbolFlags.ValueModule);
4770+
// merged symbol is module declaration symbol combined with all augmentations
4771+
return symbol && withAugmentations ? getMergedSymbol(symbol) : symbol;
4772+
}
4773+
47654774
function isOptionalParameter(node: ParameterDeclaration) {
47664775
if (hasQuestionToken(node) || isJSDocOptionalParameter(node)) {
47674776
return true;
@@ -6908,6 +6917,27 @@ namespace ts {
69086917
}
69096918
}
69106919

6920+
if (target.flags & TypeFlags.TypeParameter) {
6921+
// Given a type parameter K with a constraint keyof T, a type S is
6922+
// assignable to K if S is assignable to keyof T.
6923+
const constraint = getConstraintOfTypeParameter(<TypeParameter>target);
6924+
if (constraint && constraint.flags & TypeFlags.Index) {
6925+
if (result = isRelatedTo(source, constraint, reportErrors)) {
6926+
return result;
6927+
}
6928+
}
6929+
}
6930+
else if (target.flags & TypeFlags.Index) {
6931+
// Given a type parameter T with a constraint C, a type S is assignable to
6932+
// keyof T if S is assignable to keyof C.
6933+
const constraint = getConstraintOfTypeParameter((<IndexType>target).type);
6934+
if (constraint) {
6935+
if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
6936+
return result;
6937+
}
6938+
}
6939+
}
6940+
69116941
if (source.flags & TypeFlags.TypeParameter) {
69126942
let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
69136943

@@ -11632,6 +11662,21 @@ namespace ts {
1163211662
diagnostics.add(createDiagnosticForNodeFromMessageChain(propNode, errorInfo));
1163311663
}
1163411664

11665+
function markPropertyAsReferenced(prop: Symbol) {
11666+
if (prop &&
11667+
noUnusedIdentifiers &&
11668+
(prop.flags & SymbolFlags.ClassMember) &&
11669+
prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) {
11670+
if (prop.flags & SymbolFlags.Instantiated) {
11671+
getSymbolLinks(prop).target.isReferenced = true;
11672+
11673+
}
11674+
else {
11675+
prop.isReferenced = true;
11676+
}
11677+
}
11678+
}
11679+
1163511680
function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
1163611681
const type = checkNonNullExpression(left);
1163711682
if (isTypeAny(type) || type === silentNeverType) {
@@ -11651,17 +11696,7 @@ namespace ts {
1165111696
return unknownType;
1165211697
}
1165311698

11654-
if (noUnusedIdentifiers &&
11655-
(prop.flags & SymbolFlags.ClassMember) &&
11656-
prop.valueDeclaration && (getModifierFlags(prop.valueDeclaration) & ModifierFlags.Private)) {
11657-
if (prop.flags & SymbolFlags.Instantiated) {
11658-
getSymbolLinks(prop).target.isReferenced = true;
11659-
11660-
}
11661-
else {
11662-
prop.isReferenced = true;
11663-
}
11664-
}
11699+
markPropertyAsReferenced(prop);
1166511700

1166611701
getNodeLinks(node).resolvedSymbol = prop;
1166711702

@@ -16453,6 +16488,7 @@ namespace ts {
1645316488
const parentType = getTypeForBindingElementParent(parent);
1645416489
const name = node.propertyName || <Identifier>node.name;
1645516490
const property = getPropertyOfType(parentType, getTextOfPropertyName(name));
16491+
markPropertyAsReferenced(property);
1645616492
if (parent.initializer && property && getParentOfSymbol(property)) {
1645716493
checkClassPropertyAccess(parent, parent.initializer, parentType, property);
1645816494
}

src/compiler/core.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,18 @@ namespace ts {
11271127
};
11281128
}
11291129

1130+
export function createCompilerDiagnosticFromMessageChain(chain: DiagnosticMessageChain): Diagnostic {
1131+
return {
1132+
file: undefined,
1133+
start: undefined,
1134+
length: undefined,
1135+
1136+
code: chain.code,
1137+
category: chain.category,
1138+
messageText: chain.next ? chain : chain.messageText
1139+
};
1140+
}
1141+
11301142
export function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage, ...args: any[]): DiagnosticMessageChain;
11311143
export function chainDiagnosticMessages(details: DiagnosticMessageChain, message: DiagnosticMessage): DiagnosticMessageChain {
11321144
let text = getLocaleSpecificMessage(message);

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,14 @@
28932893
"category": "Error",
28942894
"code": 6143
28952895
},
2896+
"Module '{0}' was resolved as locally declared ambient module in file '{1}'.": {
2897+
"category": "Message",
2898+
"code": 6144
2899+
},
2900+
"Module '{0}' was resolved as ambient module declared in '{1}' since this file was not modified.": {
2901+
"category": "Message",
2902+
"code": 6145
2903+
},
28962904
"Variable '{0}' implicitly has an '{1}' type.": {
28972905
"category": "Error",
28982906
"code": 7005
@@ -3154,5 +3162,9 @@
31543162
"Implement inherited abstract class": {
31553163
"category": "Message",
31563164
"code": 90007
3165+
},
3166+
"Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig": {
3167+
"category": "Error",
3168+
"code": 90009
31573169
}
31583170
}

src/compiler/moduleNameResolver.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
/// <reference path="diagnosticInformationMap.generated.ts" />
33

44
namespace ts {
5-
function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void;
6-
function trace(host: ModuleResolutionHost): void {
5+
6+
/* @internal */
7+
export function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void;
8+
export function trace(host: ModuleResolutionHost): void {
79
host.trace(formatMessage.apply(undefined, arguments));
810
}
911

10-
function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean {
12+
/* @internal */
13+
export function isTraceEnabled(compilerOptions: CompilerOptions, host: ModuleResolutionHost): boolean {
1114
return compilerOptions.traceResolution && host.trace !== undefined;
1215
}
1316

0 commit comments

Comments
 (0)