Skip to content

Commit 3c3b73e

Browse files
committed
Merge branch 'master' into release-2.3
2 parents 54b5635 + a0abadb commit 3c3b73e

File tree

88 files changed

+3388
-247
lines changed

Some content is hidden

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

88 files changed

+3388
-247
lines changed

src/compiler/checker.ts

Lines changed: 155 additions & 78 deletions
Large diffs are not rendered by default.

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,10 @@
21192119
"category": "Error",
21202120
"code": 2709
21212121
},
2122+
"'{0}' are specified twice. The attribute named '{0}' will be overwritten.": {
2123+
"category": "Error",
2124+
"code": 2710
2125+
},
21222126

21232127
"Import declaration '{0}' is using private name '{1}'.": {
21242128
"category": "Error",

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2457,7 +2457,7 @@ namespace ts {
24572457
let indentation: number;
24582458
for (const line of lines) {
24592459
for (let i = 0; i < line.length && (indentation === undefined || i < indentation); i++) {
2460-
if (!isWhiteSpace(line.charCodeAt(i))) {
2460+
if (!isWhiteSpaceLike(line.charCodeAt(i))) {
24612461
if (indentation === undefined || i < indentation) {
24622462
indentation = i;
24632463
break;

src/compiler/parser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3828,13 +3828,15 @@ namespace ts {
38283828

38293829
function parseJsxText(): JsxText {
38303830
const node = <JsxText>createNode(SyntaxKind.JsxText, scanner.getStartPos());
3831+
node.containsOnlyWhiteSpaces = currentToken === SyntaxKind.JsxTextAllWhiteSpaces;
38313832
currentToken = scanner.scanJsxToken();
38323833
return finishNode(node);
38333834
}
38343835

38353836
function parseJsxChild(): JsxChild {
38363837
switch (token()) {
38373838
case SyntaxKind.JsxText:
3839+
case SyntaxKind.JsxTextAllWhiteSpaces:
38383840
return parseJsxText();
38393841
case SyntaxKind.OpenBraceToken:
38403842
return parseJsxExpression(/*inExpressionContext*/ false);
@@ -3864,7 +3866,10 @@ namespace ts {
38643866
else if (token() === SyntaxKind.ConflictMarkerTrivia) {
38653867
break;
38663868
}
3867-
result.push(parseJsxChild());
3869+
const child = parseJsxChild();
3870+
if (child) {
3871+
result.push(child);
3872+
}
38683873
}
38693874

38703875
result.end = scanner.getTokenPos();

src/compiler/scanner.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ namespace ts {
367367
return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position);
368368
}
369369

370-
export function isWhiteSpace(ch: number): boolean {
370+
export function isWhiteSpaceLike(ch: number): boolean {
371371
return isWhiteSpaceSingleLine(ch) || isLineBreak(ch);
372372
}
373373

@@ -512,7 +512,7 @@ namespace ts {
512512
break;
513513

514514
default:
515-
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
515+
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
516516
pos++;
517517
continue;
518518
}
@@ -694,7 +694,7 @@ namespace ts {
694694
}
695695
break scan;
696696
default:
697-
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch))) {
697+
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpaceLike(ch))) {
698698
if (hasPendingCommentRange && isLineBreak(ch)) {
699699
pendingHasTrailingNewLine = true;
700700
}
@@ -1727,8 +1727,12 @@ namespace ts {
17271727
return token = SyntaxKind.OpenBraceToken;
17281728
}
17291729

1730+
// First non-whitespace character on this line.
1731+
let firstNonWhitespace = 0;
1732+
// These initial values are special because the first line is:
1733+
// firstNonWhitespace = 0 to indicate that we want leading whitspace,
1734+
17301735
while (pos < end) {
1731-
pos++;
17321736
char = text.charCodeAt(pos);
17331737
if (char === CharacterCodes.openBrace) {
17341738
break;
@@ -1740,8 +1744,23 @@ namespace ts {
17401744
}
17411745
break;
17421746
}
1747+
1748+
// FirstNonWhitespace is 0, then we only see whitespaces so far. If we see a linebreak, we want to ignore that whitespaces.
1749+
// i.e (- : whitespace)
1750+
// <div>----
1751+
// </div> becomes <div></div>
1752+
//
1753+
// <div>----</div> becomes <div>----</div>
1754+
if (isLineBreak(char) && firstNonWhitespace === 0) {
1755+
firstNonWhitespace = -1;
1756+
}
1757+
else if (!isWhiteSpaceLike(char)) {
1758+
firstNonWhitespace = pos;
1759+
}
1760+
pos++;
17431761
}
1744-
return token = SyntaxKind.JsxText;
1762+
1763+
return firstNonWhitespace === -1 ? SyntaxKind.JsxTextAllWhiteSpaces : SyntaxKind.JsxText;
17451764
}
17461765

17471766
// Scans a JSX identifier; these differ from normal identifiers in that

src/compiler/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ts {
1010

1111
/** ES6 Map interface. */
1212
export interface Map<T> {
13-
get(key: string): T;
13+
get(key: string): T | undefined;
1414
has(key: string): boolean;
1515
set(key: string, value: T): this;
1616
delete(key: string): boolean;
@@ -65,6 +65,7 @@ namespace ts {
6565
NumericLiteral,
6666
StringLiteral,
6767
JsxText,
68+
JsxTextAllWhiteSpaces,
6869
RegularExpressionLiteral,
6970
NoSubstitutionTemplateLiteral,
7071
// Pseudo-literals
@@ -1572,6 +1573,7 @@ namespace ts {
15721573

15731574
export interface JsxText extends Node {
15741575
kind: SyntaxKind.JsxText;
1576+
containsOnlyWhiteSpaces: boolean;
15751577
parent?: JsxElement;
15761578
}
15771579

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ namespace ts {
18701870
}
18711871
}
18721872

1873-
export function getAncestor(node: Node | undefined, kind: SyntaxKind): Node {
1873+
export function getAncestor(node: Node | undefined, kind: SyntaxKind): Node | undefined {
18741874
while (node) {
18751875
if (node.kind === kind) {
18761876
return node;

src/lib/dom.iterable.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ interface FormData {
2121
[Symbol.iterator](): IterableIterator<string | File>;
2222
}
2323

24+
interface Headers {
25+
[Symbol.iterator](): IterableIterator<[string, string]>;
26+
/**
27+
* Returns an iterator allowing to go through all key/value pairs contained in this object.
28+
*/
29+
entries(): IterableIterator<[string, string]>;
30+
/**
31+
* Returns an iterator allowing to go through all keys f the key/value pairs contained in this object.
32+
*/
33+
keys(): IterableIterator<string>;
34+
/**
35+
* Returns an iterator allowing to go through all values of the key/value pairs contained in this object.
36+
*/
37+
values(): IterableIterator<string>;
38+
}
39+
2440
interface NodeList {
2541
/**
2642
* Returns an array of key, value pairs for every entry in the list
@@ -70,3 +86,22 @@ interface NodeListOf<TNode extends Node> {
7086

7187
[Symbol.iterator](): IterableIterator<TNode>;
7288
}
89+
90+
interface URLSearchParams {
91+
/**
92+
* Returns an array of key, value pairs for every entry in the search params
93+
*/
94+
entries(): IterableIterator<[string, string]>;
95+
/**
96+
* Returns a list of keys in the search params
97+
*/
98+
keys(): IterableIterator<string>;
99+
/**
100+
* Returns a list of values in the search params
101+
*/
102+
values(): IterableIterator<string>;
103+
/**
104+
* iterate over key/value pairs
105+
*/
106+
[Symbol.iterator](): IterableIterator<[string, string]>;
107+
}

src/services/formatting/smartIndenter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace ts.formatting {
5454
let current = position;
5555
while (current > 0) {
5656
const char = sourceFile.text.charCodeAt(current);
57-
if (!isWhiteSpace(char)) {
57+
if (!isWhiteSpaceLike(char)) {
5858
break;
5959
}
6060
current--;

src/services/importTracker.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ namespace ts.FindAllReferences {
387387
symbol: Symbol;
388388
exportInfo: ExportInfo;
389389
}
390+
390391
/**
391392
* Given a local reference, we might notice that it's an import/export and recursively search for references of that.
392393
* If at an import, look locally for the symbol it imports.
@@ -398,7 +399,7 @@ namespace ts.FindAllReferences {
398399
return comingFromExport ? getExport() : getExport() || getImport();
399400

400401
function getExport(): ExportedSymbol | ImportedSymbol | undefined {
401-
const { parent } = node;
402+
const parent = node.parent!;
402403
if (symbol.flags & SymbolFlags.Export) {
403404
if (parent.kind === SyntaxKind.PropertyAccessExpression) {
404405
// When accessing an export of a JS module, there's no alias. The symbol will still be flagged as an export even though we're at the use.
@@ -414,8 +415,8 @@ namespace ts.FindAllReferences {
414415
}
415416
}
416417
else {
417-
const exportNode = parent.kind === SyntaxKind.VariableDeclaration ? getAncestor(parent, SyntaxKind.VariableStatement) : parent;
418-
if (hasModifier(exportNode, ModifierFlags.Export)) {
418+
const exportNode = getExportNode(parent);
419+
if (exportNode && hasModifier(exportNode, ModifierFlags.Export)) {
419420
if (exportNode.kind === SyntaxKind.ImportEqualsDeclaration && (exportNode as ImportEqualsDeclaration).moduleReference === node) {
420421
// We're at `Y` in `export import X = Y`. This is not the exported symbol, the left-hand-side is. So treat this as an import statement.
421422
if (comingFromExport) {
@@ -492,6 +493,16 @@ namespace ts.FindAllReferences {
492493
}
493494
}
494495

496+
// If a reference is a variable declaration, the exported node would be the variable statement.
497+
function getExportNode(parent: Node): Node | undefined {
498+
if (parent.kind === SyntaxKind.VariableDeclaration) {
499+
const p = parent as ts.VariableDeclaration;
500+
return p.parent.kind === ts.SyntaxKind.CatchClause ? undefined : p.parent.parent.kind === SyntaxKind.VariableStatement ? p.parent.parent : undefined;
501+
} else {
502+
return parent;
503+
}
504+
}
505+
495506
function isNodeImport(node: Node): { isNamedImport: boolean } | undefined {
496507
const { parent } = node;
497508
switch (parent.kind) {

0 commit comments

Comments
 (0)