Skip to content

Commit b033693

Browse files
committed
Merge remote-tracking branch 'origin/master' into emitImportsInDts
2 parents 202452b + 2fde7ab commit b033693

File tree

66 files changed

+917
-100
lines changed

Some content is hidden

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

66 files changed

+917
-100
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Issues that ask questions answered in the FAQ will be closed without elaboration
1313
## 3. Do you have a question?
1414

1515
The issue tracker is for **issues**, in other words, bugs and suggestions.
16-
If you have a *question*, please use [http://stackoverflow.com/questions/tagged/typescript](Stack Overflow), [https://gitter.im/Microsoft/TypeScript](Gitter), your favorite search engine, or other resources.
16+
If you have a *question*, please use [Stack Overflow](http://stackoverflow.com/questions/tagged/typescript), [Gitter](https://gitter.im/Microsoft/TypeScript), your favorite search engine, or other resources.
1717
Due to increased traffic, we can no longer answer questions in the issue tracker.
1818

1919
## 4. Did you find a bug?

doc/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# Read This!
2+
13
This directory contains miscellaneous documentation such as the TypeScript language specification and logo.
24
If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook).
35

46
# Spec Contributions
57

68
The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats.
7-
Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests.
9+
Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that **any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new)** rather than sent as pull requests.

lib/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Read this!
1+
# Read This!
22

3-
These files are not meant to be edited by hand.
4-
If you need to make modifications, the respective files should be changed within the repository's top-level `src` directory. Running `jake LKG` will then appropriately update the files in this directory.
3+
**These files are not meant to be edited by hand.**
4+
If you need to make modifications, the respective files should be changed within the repository's top-level `src` directory.
5+
Running `jake LKG` will then appropriately update the files in this directory.

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16214,7 +16214,7 @@ namespace ts {
1621416214
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, text, "async");
1621516215
}
1621616216
else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) {
16217-
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
16217+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, text);
1621816218
}
1621916219
else if (flags & NodeFlags.Abstract) {
1622016220
if (modifier.kind === SyntaxKind.PrivateKeyword) {
@@ -16238,7 +16238,7 @@ namespace ts {
1623816238
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "static", "async");
1623916239
}
1624016240
else if (node.parent.kind === SyntaxKind.ModuleBlock || node.parent.kind === SyntaxKind.SourceFile) {
16241-
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
16241+
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_module_or_namespace_element, "static");
1624216242
}
1624316243
else if (node.kind === SyntaxKind.Parameter) {
1624416244
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"category": "Error",
124124
"code": 1043
125125
},
126-
"'{0}' modifier cannot appear on a module element.": {
126+
"'{0}' modifier cannot appear on a module or namespace element.": {
127127
"category": "Error",
128128
"code": 1044
129129
},
@@ -1279,10 +1279,6 @@
12791279
"category": "Error",
12801280
"code": 2417
12811281
},
1282-
"Type name '{0}' in extends clause does not reference constructor function for '{0}'.": {
1283-
"category": "Error",
1284-
"code": 2419
1285-
},
12861282
"Class '{0}' incorrectly implements interface '{1}'.": {
12871283
"category": "Error",
12881284
"code": 2420

src/compiler/parser.ts

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,33 +2450,49 @@ namespace ts {
24502450
if (token === SyntaxKind.LessThanToken) {
24512451
return true;
24522452
}
2453-
24542453
return token === SyntaxKind.OpenParenToken && lookAhead(isUnambiguouslyStartOfFunctionType);
24552454
}
24562455

2456+
function skipParameterStart(): boolean {
2457+
if (isModifierKind(token)) {
2458+
// Skip modifiers
2459+
parseModifiers();
2460+
}
2461+
if (isIdentifier()) {
2462+
nextToken();
2463+
return true;
2464+
}
2465+
if (token === SyntaxKind.OpenBracketToken || token === SyntaxKind.OpenBraceToken) {
2466+
// Return true if we can parse an array or object binding pattern with no errors
2467+
const previousErrorCount = parseDiagnostics.length;
2468+
parseIdentifierOrPattern();
2469+
return previousErrorCount === parseDiagnostics.length;
2470+
}
2471+
return false;
2472+
}
2473+
24572474
function isUnambiguouslyStartOfFunctionType() {
24582475
nextToken();
24592476
if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) {
24602477
// ( )
24612478
// ( ...
24622479
return true;
24632480
}
2464-
if (isIdentifier() || isModifierKind(token)) {
2465-
nextToken();
2481+
if (skipParameterStart()) {
2482+
// We successfully skipped modifiers (if any) and an identifier or binding pattern,
2483+
// now see if we have something that indicates a parameter declaration
24662484
if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken ||
2467-
token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken ||
2468-
isIdentifier() || isModifierKind(token)) {
2469-
// ( id :
2470-
// ( id ,
2471-
// ( id ?
2472-
// ( id =
2473-
// ( modifier id
2485+
token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken) {
2486+
// ( xxx :
2487+
// ( xxx ,
2488+
// ( xxx ?
2489+
// ( xxx =
24742490
return true;
24752491
}
24762492
if (token === SyntaxKind.CloseParenToken) {
24772493
nextToken();
24782494
if (token === SyntaxKind.EqualsGreaterThanToken) {
2479-
// ( id ) =>
2495+
// ( xxx ) =>
24802496
return true;
24812497
}
24822498
}

src/compiler/sourcemap.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ namespace ts {
1616
}
1717

1818
let nullSourceMapWriter: SourceMapWriter;
19+
// Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans
20+
const defaultLastEncodedSourceMapSpan: SourceMapSpan = {
21+
emittedLine: 1,
22+
emittedColumn: 1,
23+
sourceLine: 1,
24+
sourceColumn: 1,
25+
sourceIndex: 0
26+
};
1927

2028
export function getNullSourceMapWriter(): SourceMapWriter {
2129
if (nullSourceMapWriter === undefined) {
@@ -79,13 +87,7 @@ namespace ts {
7987

8088
// Last recorded and encoded spans
8189
lastRecordedSourceMapSpan = undefined;
82-
lastEncodedSourceMapSpan = {
83-
emittedLine: 1,
84-
emittedColumn: 1,
85-
sourceLine: 1,
86-
sourceColumn: 1,
87-
sourceIndex: 0
88-
};
90+
lastEncodedSourceMapSpan = defaultLastEncodedSourceMapSpan;
8991
lastEncodedNameIndex = 0;
9092

9193
// Initialize source map data
@@ -159,10 +161,12 @@ namespace ts {
159161
// Pop sourceMapDecodedMappings to remove last entry
160162
sourceMapData.sourceMapDecodedMappings.pop();
161163

162-
// Change the last encoded source map
164+
// Point the lastEncodedSourceMapSpace to the previous encoded sourceMapSpan
165+
// If the list is empty which indicates that we are at the beginning of the file,
166+
// we have to reset it to default value (same value when we first initialize sourceMapWriter)
163167
lastEncodedSourceMapSpan = sourceMapData.sourceMapDecodedMappings.length ?
164168
sourceMapData.sourceMapDecodedMappings[sourceMapData.sourceMapDecodedMappings.length - 1] :
165-
undefined;
169+
defaultLastEncodedSourceMapSpan;
166170

167171
// TODO: Update lastEncodedNameIndex
168172
// Since we dont support this any more, lets not worry about it right now.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/parser/ecmascript5/Protected/Protected1.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module element.
1+
tests/cases/conformance/parser/ecmascript5/Protected/Protected1.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module or namespace element.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/Protected/Protected1.ts (1 errors) ====
55
protected class C {
66
~~~~~~~~~
7-
!!! error TS1044: 'protected' modifier cannot appear on a module element.
7+
!!! error TS1044: 'protected' modifier cannot appear on a module or namespace element.
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/conformance/parser/ecmascript5/Protected/Protected2.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module element.
1+
tests/cases/conformance/parser/ecmascript5/Protected/Protected2.ts(1,1): error TS1044: 'protected' modifier cannot appear on a module or namespace element.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/Protected/Protected2.ts (1 errors) ====
55
protected module M {
66
~~~~~~~~~
7-
!!! error TS1044: 'protected' modifier cannot appear on a module element.
7+
!!! error TS1044: 'protected' modifier cannot appear on a module or namespace element.
88
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//// [destructuringInFunctionType.ts]
2+
3+
interface a { a }
4+
interface b { b }
5+
interface c { c }
6+
7+
type T1 = ([a, b, c]);
8+
type F1 = ([a, b, c]) => void;
9+
10+
type T2 = ({ a });
11+
type F2 = ({ a }) => void;
12+
13+
type T3 = ([{ a: b }, { b: a }]);
14+
type F3 = ([{ a: b }, { b: a }]) => void;
15+
16+
type T4 = ([{ a: [b, c] }]);
17+
type F4 = ([{ a: [b, c] }]) => void;
18+
19+
type C1 = new ([{ a: [b, c] }]) => void;
20+
21+
var v1 = ([a, b, c]) => "hello";
22+
var v2: ([a, b, c]) => string;
23+
24+
25+
//// [destructuringInFunctionType.js]
26+
var v1 = function (_a) {
27+
var a = _a[0], b = _a[1], c = _a[2];
28+
return "hello";
29+
};
30+
var v2;
31+
32+
33+
//// [destructuringInFunctionType.d.ts]
34+
interface a {
35+
a: any;
36+
}
37+
interface b {
38+
b: any;
39+
}
40+
interface c {
41+
c: any;
42+
}
43+
declare type T1 = ([a, b, c]);
44+
declare type F1 = ([a, b, c]) => void;
45+
declare type T2 = ({
46+
a;
47+
});
48+
declare type F2 = ({a}) => void;
49+
declare type T3 = ([{
50+
a: b;
51+
}, {
52+
b: a;
53+
}]);
54+
declare type F3 = ([{a: b}, {b: a}]) => void;
55+
declare type T4 = ([{
56+
a: [b, c];
57+
}]);
58+
declare type F4 = ([{a: [b, c]}]) => void;
59+
declare type C1 = new ([{a: [b, c]}]) => void;
60+
declare var v1: ([a, b, c]: [any, any, any]) => string;
61+
declare var v2: ([a, b, c]) => string;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
=== tests/cases/conformance/es6/destructuring/destructuringInFunctionType.ts ===
2+
3+
interface a { a }
4+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 0, 0))
5+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 1, 13))
6+
7+
interface b { b }
8+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 1, 17))
9+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 2, 13))
10+
11+
interface c { c }
12+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 2, 17))
13+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 3, 13))
14+
15+
type T1 = ([a, b, c]);
16+
>T1 : Symbol(T1, Decl(destructuringInFunctionType.ts, 3, 17))
17+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 0, 0))
18+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 1, 17))
19+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 2, 17))
20+
21+
type F1 = ([a, b, c]) => void;
22+
>F1 : Symbol(F1, Decl(destructuringInFunctionType.ts, 5, 22))
23+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 6, 12))
24+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 6, 14))
25+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 6, 17))
26+
27+
type T2 = ({ a });
28+
>T2 : Symbol(T2, Decl(destructuringInFunctionType.ts, 6, 30))
29+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 8, 12))
30+
31+
type F2 = ({ a }) => void;
32+
>F2 : Symbol(F2, Decl(destructuringInFunctionType.ts, 8, 18))
33+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 9, 12))
34+
35+
type T3 = ([{ a: b }, { b: a }]);
36+
>T3 : Symbol(T3, Decl(destructuringInFunctionType.ts, 9, 26))
37+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 11, 13))
38+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 1, 17))
39+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 11, 23))
40+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 0, 0))
41+
42+
type F3 = ([{ a: b }, { b: a }]) => void;
43+
>F3 : Symbol(F3, Decl(destructuringInFunctionType.ts, 11, 33))
44+
>a : Symbol(a)
45+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 12, 13))
46+
>b : Symbol(b)
47+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 12, 23))
48+
49+
type T4 = ([{ a: [b, c] }]);
50+
>T4 : Symbol(T4, Decl(destructuringInFunctionType.ts, 12, 41))
51+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 14, 13))
52+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 1, 17))
53+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 2, 17))
54+
55+
type F4 = ([{ a: [b, c] }]) => void;
56+
>F4 : Symbol(F4, Decl(destructuringInFunctionType.ts, 14, 28))
57+
>a : Symbol(a)
58+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 15, 18))
59+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 15, 20))
60+
61+
type C1 = new ([{ a: [b, c] }]) => void;
62+
>C1 : Symbol(C1, Decl(destructuringInFunctionType.ts, 15, 36))
63+
>a : Symbol(a)
64+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 17, 22))
65+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 17, 24))
66+
67+
var v1 = ([a, b, c]) => "hello";
68+
>v1 : Symbol(v1, Decl(destructuringInFunctionType.ts, 19, 3))
69+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 19, 11))
70+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 19, 13))
71+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 19, 16))
72+
73+
var v2: ([a, b, c]) => string;
74+
>v2 : Symbol(v2, Decl(destructuringInFunctionType.ts, 20, 3))
75+
>a : Symbol(a, Decl(destructuringInFunctionType.ts, 20, 10))
76+
>b : Symbol(b, Decl(destructuringInFunctionType.ts, 20, 12))
77+
>c : Symbol(c, Decl(destructuringInFunctionType.ts, 20, 15))
78+

0 commit comments

Comments
 (0)