Skip to content

Commit aeb899a

Browse files
committed
Merge branch 'master' into literalTypesAlways
2 parents 3ea1b79 + 2305c68 commit aeb899a

Some content is hidden

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

47 files changed

+607
-365
lines changed

Jakefile.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ var servicesSources = [
126126
"classifier.ts",
127127
"completions.ts",
128128
"documentHighlights.ts",
129+
"documentRegistry.ts",
129130
"findAllReferences.ts",
130131
"goToDefinition.ts",
131132
"jsDoc.ts",
@@ -1003,15 +1004,18 @@ function acceptBaseline(containerFolder) {
10031004
var deleteEnding = '.delete';
10041005
for (var i in files) {
10051006
var filename = files[i];
1006-
if (filename.substr(filename.length - deleteEnding.length) === deleteEnding) {
1007-
filename = filename.substr(0, filename.length - deleteEnding.length);
1008-
fs.unlinkSync(path.join(targetFolder, filename));
1009-
} else {
1010-
var target = path.join(targetFolder, filename);
1011-
if (fs.existsSync(target)) {
1012-
fs.unlinkSync(target);
1007+
var fullLocalPath = path.join(sourceFolder, filename);
1008+
if (fs.statSync(fullLocalPath).isFile()) {
1009+
if (filename.substr(filename.length - deleteEnding.length) === deleteEnding) {
1010+
filename = filename.substr(0, filename.length - deleteEnding.length);
1011+
fs.unlinkSync(path.join(targetFolder, filename));
1012+
} else {
1013+
var target = path.join(targetFolder, filename);
1014+
if (fs.existsSync(target)) {
1015+
fs.unlinkSync(target);
1016+
}
1017+
fs.renameSync(path.join(sourceFolder, filename), target);
10131018
}
1014-
fs.renameSync(path.join(sourceFolder, filename), target);
10151019
}
10161020
}
10171021
}

lib/lib.es2015.collection.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface Map<K, V> {
2020
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
2121
get(key: K): V | undefined;
2222
has(key: K): boolean;
23-
set(key: K, value?: V): this;
23+
set(key: K, value: V): this;
2424
readonly size: number;
2525
}
2626

@@ -36,7 +36,7 @@ interface WeakMap<K, V> {
3636
delete(key: K): boolean;
3737
get(key: K): V | undefined;
3838
has(key: K): boolean;
39-
set(key: K, value?: V): this;
39+
set(key: K, value: V): this;
4040
}
4141

4242
interface WeakMapConstructor {

scripts/tslint/preferConstRule.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ class PreferConstWalker extends Lint.RuleWalker {
9393

9494
private visitBindingPatternIdentifiers(pattern: ts.BindingPattern) {
9595
for (const element of pattern.elements) {
96-
if (element.name.kind === ts.SyntaxKind.Identifier) {
97-
this.markAssignment(element.name as ts.Identifier);
96+
if (element.kind !== ts.SyntaxKind.BindingElement) {
97+
continue;
98+
}
99+
100+
const name = (<ts.BindingElement>element).name;
101+
if (name.kind === ts.SyntaxKind.Identifier) {
102+
this.markAssignment(name as ts.Identifier);
98103
}
99104
else {
100-
this.visitBindingPatternIdentifiers(element.name as ts.BindingPattern);
105+
this.visitBindingPatternIdentifiers(name as ts.BindingPattern);
101106
}
102107
}
103108
}
@@ -191,7 +196,9 @@ class PreferConstWalker extends Lint.RuleWalker {
191196

192197
private collectBindingPatternIdentifiers(value: ts.VariableDeclaration, pattern: ts.BindingPattern, table: ts.MapLike<DeclarationUsages>) {
193198
for (const element of pattern.elements) {
194-
this.collectNameIdentifiers(value, element.name, table);
199+
if (element.kind === ts.SyntaxKind.BindingElement) {
200+
this.collectNameIdentifiers(value, (<ts.BindingElement>element).name, table);
201+
}
195202
}
196203
}
197204
}

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,8 @@ namespace ts {
11631163
currentFlow = finishFlowLabel(postExpressionLabel);
11641164
}
11651165

1166-
function bindInitializedVariableFlow(node: VariableDeclaration | BindingElement) {
1167-
const name = node.name;
1166+
function bindInitializedVariableFlow(node: VariableDeclaration | ArrayBindingElement) {
1167+
const name = !isOmittedExpression(node) ? node.name : undefined;
11681168
if (isBindingPattern(name)) {
11691169
for (const child of name.elements) {
11701170
bindInitializedVariableFlow(child);

src/compiler/checker.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ namespace ts {
10431043
const moduleSymbol = resolveExternalModuleName(node, (<ImportDeclaration>node.parent).moduleSpecifier);
10441044

10451045
if (moduleSymbol) {
1046-
const exportDefaultSymbol = isShorthandAmbientModule(moduleSymbol.valueDeclaration) ?
1046+
const exportDefaultSymbol = isShorthandAmbientModuleSymbol(moduleSymbol) ?
10471047
moduleSymbol :
10481048
moduleSymbol.exports["export="] ?
10491049
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
@@ -1119,7 +1119,7 @@ namespace ts {
11191119
if (targetSymbol) {
11201120
const name = specifier.propertyName || specifier.name;
11211121
if (name.text) {
1122-
if (isShorthandAmbientModule(moduleSymbol.valueDeclaration)) {
1122+
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
11231123
return moduleSymbol;
11241124
}
11251125

@@ -2505,8 +2505,8 @@ namespace ts {
25052505
}
25062506
}
25072507

2508-
function buildBindingElementDisplay(bindingElement: BindingElement, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2509-
if (bindingElement.kind === SyntaxKind.OmittedExpression) {
2508+
function buildBindingElementDisplay(bindingElement: ArrayBindingElement, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2509+
if (isOmittedExpression(bindingElement)) {
25102510
return;
25112511
}
25122512
Debug.assert(bindingElement.kind === SyntaxKind.BindingElement);
@@ -3129,7 +3129,7 @@ namespace ts {
31293129
}
31303130

31313131
// Return the type implied by an object binding pattern
3132-
function getTypeFromObjectBindingPattern(pattern: BindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
3132+
function getTypeFromObjectBindingPattern(pattern: ObjectBindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
31333133
const members = createMap<Symbol>();
31343134
let hasComputedProperties = false;
31353135
forEach(pattern.elements, e => {
@@ -3160,11 +3160,12 @@ namespace ts {
31603160
// Return the type implied by an array binding pattern
31613161
function getTypeFromArrayBindingPattern(pattern: BindingPattern, includePatternInType: boolean, reportErrors: boolean): Type {
31623162
const elements = pattern.elements;
3163-
if (elements.length === 0 || elements[elements.length - 1].dotDotDotToken) {
3163+
const lastElement = lastOrUndefined(elements);
3164+
if (elements.length === 0 || (!isOmittedExpression(lastElement) && lastElement.dotDotDotToken)) {
31643165
return languageVersion >= ScriptTarget.ES6 ? createIterableType(anyType) : anyArrayType;
31653166
}
31663167
// If the pattern has at least one element, and no rest element, then it should imply a tuple type.
3167-
const elementTypes = map(elements, e => e.kind === SyntaxKind.OmittedExpression ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors));
3168+
const elementTypes = map(elements, e => isOmittedExpression(e) ? anyType : getTypeFromBindingElement(e, includePatternInType, reportErrors));
31683169
let result = createTupleType(elementTypes);
31693170
if (includePatternInType) {
31703171
result = cloneTypeReference(result);
@@ -3182,8 +3183,8 @@ namespace ts {
31823183
// the parameter.
31833184
function getTypeFromBindingPattern(pattern: BindingPattern, includePatternInType?: boolean, reportErrors?: boolean): Type {
31843185
return pattern.kind === SyntaxKind.ObjectBindingPattern
3185-
? getTypeFromObjectBindingPattern(pattern, includePatternInType, reportErrors)
3186-
: getTypeFromArrayBindingPattern(pattern, includePatternInType, reportErrors);
3186+
? getTypeFromObjectBindingPattern(<ObjectBindingPattern>pattern, includePatternInType, reportErrors)
3187+
: getTypeFromArrayBindingPattern(<ArrayBindingPattern>pattern, includePatternInType, reportErrors);
31873188
}
31883189

31893190
// Return the type associated with a variable, parameter, or property declaration. In the simple case this is the type
@@ -3385,7 +3386,7 @@ namespace ts {
33853386
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
33863387
const links = getSymbolLinks(symbol);
33873388
if (!links.type) {
3388-
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModule(<ModuleDeclaration>symbol.valueDeclaration)) {
3389+
if (symbol.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && isShorthandAmbientModuleSymbol(symbol)) {
33893390
links.type = anyType;
33903391
}
33913392
else {
@@ -8970,6 +8971,7 @@ namespace ts {
89708971
const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter;
89718972
const declarationContainer = getControlFlowContainer(declaration);
89728973
let flowContainer = getControlFlowContainer(node);
8974+
const isOuterVariable = flowContainer !== declarationContainer;
89738975
// When the control flow originates in a function expression or arrow function and we are referencing
89748976
// a const variable or parameter from an outer function, we extend the origin of the control flow
89758977
// analysis to include the immediately enclosing function.
@@ -8982,7 +8984,7 @@ namespace ts {
89828984
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
89838985
// declaration container are the same).
89848986
const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter ||
8985-
flowContainer !== declarationContainer || isInAmbientContext(declaration);
8987+
isOuterVariable || isInAmbientContext(declaration);
89868988
const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer);
89878989
// A variable is considered uninitialized when it is possible to analyze the entire control flow graph
89888990
// from declaration to use, and when the variable's declared type doesn't include undefined but the
@@ -12437,7 +12439,7 @@ namespace ts {
1243712439
function assignBindingElementTypes(node: VariableLikeDeclaration) {
1243812440
if (isBindingPattern(node.name)) {
1243912441
for (const element of (<BindingPattern>node.name).elements) {
12440-
if (element.kind !== SyntaxKind.OmittedExpression) {
12442+
if (!isOmittedExpression(element)) {
1244112443
if (element.name.kind === SyntaxKind.Identifier) {
1244212444
getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
1244312445
}
@@ -13880,7 +13882,12 @@ namespace ts {
1388013882
pattern: BindingPattern,
1388113883
predicateVariableNode: Node,
1388213884
predicateVariableName: string) {
13883-
for (const { name } of pattern.elements) {
13885+
for (const element of pattern.elements) {
13886+
if (isOmittedExpression(element)) {
13887+
continue;
13888+
}
13889+
13890+
const name = element.name;
1388413891
if (name.kind === SyntaxKind.Identifier &&
1388513892
(<Identifier>name).text === predicateVariableName) {
1388613893
error(predicateVariableNode,
@@ -18356,8 +18363,8 @@ namespace ts {
1835618363

1835718364
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
1835818365
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
18359-
if (!moduleSymbol) {
18360-
// module not found - be conservative
18366+
if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol)) {
18367+
// If the module is not found or is shorthand, assume that it may export a value.
1836118368
return true;
1836218369
}
1836318370

@@ -19990,7 +19997,7 @@ namespace ts {
1999019997
else {
1999119998
const elements = (<BindingPattern>name).elements;
1999219999
for (const element of elements) {
19993-
if (element.kind !== SyntaxKind.OmittedExpression) {
20000+
if (!isOmittedExpression(element)) {
1999420001
checkGrammarNameInLetOrConstDeclarations(element.name);
1999520002
}
1999620003
}

src/compiler/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ const _super = (function (geti, seti) {
554554

555555
// Binding patterns
556556
case SyntaxKind.ObjectBindingPattern:
557-
return emitObjectBindingPattern(<BindingPattern>node);
557+
return emitObjectBindingPattern(<ObjectBindingPattern>node);
558558
case SyntaxKind.ArrayBindingPattern:
559-
return emitArrayBindingPattern(<BindingPattern>node);
559+
return emitArrayBindingPattern(<ArrayBindingPattern>node);
560560
case SyntaxKind.BindingElement:
561561
return emitBindingElement(<BindingElement>node);
562562

src/compiler/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,13 @@ namespace ts {
368368
return node;
369369
}
370370

371-
export function createArrayBindingPattern(elements: BindingElement[], location?: TextRange) {
371+
export function createArrayBindingPattern(elements: ArrayBindingElement[], location?: TextRange) {
372372
const node = <ArrayBindingPattern>createNode(SyntaxKind.ArrayBindingPattern, location);
373373
node.elements = createNodeArray(elements);
374374
return node;
375375
}
376376

377-
export function updateArrayBindingPattern(node: ArrayBindingPattern, elements: BindingElement[]) {
377+
export function updateArrayBindingPattern(node: ArrayBindingPattern, elements: ArrayBindingElement[]) {
378378
if (node.elements !== elements) {
379379
return updateNode(createArrayBindingPattern(elements, node), node);
380380
}

src/compiler/parser.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,9 +4815,9 @@ namespace ts {
48154815

48164816
// DECLARATIONS
48174817

4818-
function parseArrayBindingElement(): BindingElement {
4818+
function parseArrayBindingElement(): ArrayBindingElement {
48194819
if (token() === SyntaxKind.CommaToken) {
4820-
return <BindingElement>createNode(SyntaxKind.OmittedExpression);
4820+
return <OmittedExpression>createNode(SyntaxKind.OmittedExpression);
48214821
}
48224822
const node = <BindingElement>createNode(SyntaxKind.BindingElement);
48234823
node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken);
@@ -4842,16 +4842,16 @@ namespace ts {
48424842
return finishNode(node);
48434843
}
48444844

4845-
function parseObjectBindingPattern(): BindingPattern {
4846-
const node = <BindingPattern>createNode(SyntaxKind.ObjectBindingPattern);
4845+
function parseObjectBindingPattern(): ObjectBindingPattern {
4846+
const node = <ObjectBindingPattern>createNode(SyntaxKind.ObjectBindingPattern);
48474847
parseExpected(SyntaxKind.OpenBraceToken);
48484848
node.elements = parseDelimitedList(ParsingContext.ObjectBindingElements, parseObjectBindingElement);
48494849
parseExpected(SyntaxKind.CloseBraceToken);
48504850
return finishNode(node);
48514851
}
48524852

4853-
function parseArrayBindingPattern(): BindingPattern {
4854-
const node = <BindingPattern>createNode(SyntaxKind.ArrayBindingPattern);
4853+
function parseArrayBindingPattern(): ArrayBindingPattern {
4854+
const node = <ArrayBindingPattern>createNode(SyntaxKind.ArrayBindingPattern);
48554855
parseExpected(SyntaxKind.OpenBracketToken);
48564856
node.elements = parseDelimitedList(ParsingContext.ArrayBindingElements, parseArrayBindingElement);
48574857
parseExpected(SyntaxKind.CloseBracketToken);

src/compiler/transformers/destructuring.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,15 @@ namespace ts {
326326
}
327327
for (let i = 0; i < numElements; i++) {
328328
const element = elements[i];
329-
if (name.kind === SyntaxKind.ObjectBindingPattern) {
329+
if (isOmittedExpression(element)) {
330+
continue;
331+
}
332+
else if (name.kind === SyntaxKind.ObjectBindingPattern) {
330333
// Rewrite element to a declaration with an initializer that fetches property
331334
const propName = element.propertyName || <Identifier>element.name;
332335
emitBindingElement(element, createDestructuringPropertyAccess(value, propName));
333336
}
334-
else if (element.kind !== SyntaxKind.OmittedExpression) {
337+
else {
335338
if (!element.dotDotDotToken) {
336339
// Rewrite element to a declaration that accesses array element at index i
337340
emitBindingElement(element, createElementAccess(value, i));

src/compiler/transformers/es6.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,9 @@ namespace ts {
19451945
}
19461946
else {
19471947
for (const element of (<BindingPattern>node).elements) {
1948-
visit(element.name);
1948+
if (!isOmittedExpression(element)) {
1949+
visit(element.name);
1950+
}
19491951
}
19501952
}
19511953
}
@@ -2289,7 +2291,9 @@ namespace ts {
22892291
const name = decl.name;
22902292
if (isBindingPattern(name)) {
22912293
for (const element of name.elements) {
2292-
processLoopVariableDeclaration(element, loopParameters, loopOutParameters);
2294+
if (!isOmittedExpression(element)) {
2295+
processLoopVariableDeclaration(element, loopParameters, loopOutParameters);
2296+
}
22932297
}
22942298
}
22952299
else {

0 commit comments

Comments
 (0)