Skip to content

Commit 1cb5eb9

Browse files
Merge branch 'master' into correctlyCacheTaggedTemplates
2 parents 9907453 + 8f97248 commit 1cb5eb9

File tree

8,136 files changed

+673584
-2406
lines changed

Some content is hidden

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

8,136 files changed

+673584
-2406
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ internal/
5959
.idea
6060
yarn.lock
6161
package-lock.json
62-
.parallelperf.json
62+
.parallelperf.*

src/compiler/binder.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,11 +1456,6 @@ namespace ts {
14561456
}
14571457

14581458
function declareSymbolAndAddToSymbolTable(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
1459-
// Just call this directly so that the return type of this function stays "void".
1460-
return declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
1461-
}
1462-
1463-
function declareSymbolAndAddToSymbolTableWorker(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
14641459
switch (container.kind) {
14651460
// Modules, source files, and classes need specialized handling for how their
14661461
// members are declared (for example, a member of a class will go into a specific
@@ -1683,6 +1678,9 @@ namespace ts {
16831678

16841679
function bindAnonymousDeclaration(node: Declaration, symbolFlags: SymbolFlags, name: __String) {
16851680
const symbol = createSymbol(symbolFlags, name);
1681+
if (symbolFlags & SymbolFlags.EnumMember) {
1682+
symbol.parent = container.symbol;
1683+
}
16861684
addDeclarationToSymbol(symbol, node, symbolFlags);
16871685
}
16881686

src/compiler/checker.ts

Lines changed: 63 additions & 70 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,6 @@ namespace ts {
994994

995995
/**
996996
* Gets the owned, enumerable property keys of a map-like.
997-
*
998-
* NOTE: This is intended for use with MapLike<T> objects. For Map<T> objects, use
999-
* Object.keys instead as it offers better performance.
1000-
*
1001-
* @param map A map-like.
1002997
*/
1003998
export function getOwnKeys<T>(map: MapLike<T>): string[] {
1004999
const keys: string[] = [];
@@ -1011,6 +1006,17 @@ namespace ts {
10111006
return keys;
10121007
}
10131008

1009+
export function getOwnValues<T>(sparseArray: T[]): T[] {
1010+
const values: T[] = [];
1011+
for (const key in sparseArray) {
1012+
if (hasOwnProperty.call(sparseArray, key)) {
1013+
values.push(sparseArray[key]);
1014+
}
1015+
}
1016+
1017+
return values;
1018+
}
1019+
10141020
/** Shims `Array.from`. */
10151021
export function arrayFrom<T, U>(iterator: Iterator<T>, map: (t: T) => U): U[];
10161022
export function arrayFrom<T>(iterator: Iterator<T>): T[];

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,6 +3507,10 @@
35073507
"category": "Error",
35083508
"code": 8020
35093509
},
3510+
"JSDoc '@typedef' tag should either have a type annotation or be followed by '@property' or '@member' tags.": {
3511+
"category": "Error",
3512+
"code": 8021
3513+
},
35103514
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause.": {
35113515
"category": "Error",
35123516
"code": 9002

src/compiler/emitter.ts

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,9 @@ namespace ts {
18631863

18641864
function emitModuleDeclaration(node: ModuleDeclaration) {
18651865
emitModifiers(node, node.modifiers);
1866-
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
1866+
if (~node.flags & NodeFlags.GlobalAugmentation) {
1867+
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
1868+
}
18671869
emit(node.name);
18681870

18691871
let body = node.body;

src/compiler/factory.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,30 @@ namespace ts {
12071207
: node;
12081208
}
12091209

1210+
export function createTemplateHead(text: string) {
1211+
const node = <TemplateHead>createSynthesizedNode(SyntaxKind.TemplateHead);
1212+
node.text = text;
1213+
return node;
1214+
}
1215+
1216+
export function createTemplateMiddle(text: string) {
1217+
const node = <TemplateMiddle>createSynthesizedNode(SyntaxKind.TemplateMiddle);
1218+
node.text = text;
1219+
return node;
1220+
}
1221+
1222+
export function createTemplateTail(text: string) {
1223+
const node = <TemplateTail>createSynthesizedNode(SyntaxKind.TemplateTail);
1224+
node.text = text;
1225+
return node;
1226+
}
1227+
1228+
export function createNoSubstitutionTemplateLiteral(text: string) {
1229+
const node = <NoSubstitutionTemplateLiteral>createSynthesizedNode(SyntaxKind.NoSubstitutionTemplateLiteral);
1230+
node.text = text;
1231+
return node;
1232+
}
1233+
12101234
export function createYield(expression?: Expression): YieldExpression;
12111235
export function createYield(asteriskToken: AsteriskToken, expression: Expression): YieldExpression;
12121236
export function createYield(asteriskTokenOrExpression?: AsteriskToken | Expression, expression?: Expression) {

src/compiler/parser.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6135,11 +6135,14 @@ namespace ts {
61356135
}
61366136

61376137
// Parses out a JSDoc type expression.
6138-
/* @internal */
6139-
export function parseJSDocTypeExpression(): JSDocTypeExpression {
6138+
export function parseJSDocTypeExpression(): JSDocTypeExpression;
6139+
export function parseJSDocTypeExpression(requireBraces: true): JSDocTypeExpression | undefined;
6140+
export function parseJSDocTypeExpression(requireBraces?: boolean): JSDocTypeExpression | undefined {
61406141
const result = <JSDocTypeExpression>createNode(SyntaxKind.JSDocTypeExpression, scanner.getTokenPos());
61416142

6142-
parseExpected(SyntaxKind.OpenBraceToken);
6143+
if (!parseExpected(SyntaxKind.OpenBraceToken) && requireBraces) {
6144+
return undefined;
6145+
}
61436146
result.type = doInsideOfContext(NodeFlags.JSDoc, parseType);
61446147
parseExpected(SyntaxKind.CloseBraceToken);
61456148

@@ -6486,14 +6489,8 @@ namespace ts {
64866489
}
64876490

64886491
function tryParseTypeExpression(): JSDocTypeExpression | undefined {
6489-
return tryParse(() => {
6490-
skipWhitespace();
6491-
if (token() !== SyntaxKind.OpenBraceToken) {
6492-
return undefined;
6493-
}
6494-
6495-
return parseJSDocTypeExpression();
6496-
});
6492+
skipWhitespace();
6493+
return token() === SyntaxKind.OpenBraceToken ? parseJSDocTypeExpression() : undefined;
64976494
}
64986495

64996496
function parseBracketNameInPropertyAndParamTag(): { name: EntityName, isBracketed: boolean } {
@@ -6602,12 +6599,12 @@ namespace ts {
66026599
const result = <JSDocTypeTag>createNode(SyntaxKind.JSDocTypeTag, atToken.pos);
66036600
result.atToken = atToken;
66046601
result.tagName = tagName;
6605-
result.typeExpression = tryParseTypeExpression();
6602+
result.typeExpression = parseJSDocTypeExpression(/*requireBraces*/ true);
66066603
return finishNode(result);
66076604
}
66086605

66096606
function parseAugmentsTag(atToken: AtToken, tagName: Identifier): JSDocAugmentsTag {
6610-
const typeExpression = tryParseTypeExpression();
6607+
const typeExpression = parseJSDocTypeExpression(/*requireBraces*/ true);
66116608

66126609
const result = <JSDocAugmentsTag>createNode(SyntaxKind.JSDocAugmentsTag, atToken.pos);
66136610
result.atToken = atToken;

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,7 @@ namespace ts {
14621462

14631463
// file.imports may not be undefined if there exists dynamic import
14641464
let imports: StringLiteral[];
1465-
let moduleAugmentations: Array<StringLiteral | Identifier>;
1465+
let moduleAugmentations: (StringLiteral | Identifier)[];
14661466
let ambientModules: string[];
14671467

14681468
// If we are importing helpers, we need to add a synthetic reference to resolve the

src/compiler/symbolWalker.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,29 @@ namespace ts {
1414
return getSymbolWalker;
1515

1616
function getSymbolWalker(accept: (symbol: Symbol) => boolean = () => true): SymbolWalker {
17-
const visitedTypes = createMap<Type>(); // Key is id as string
18-
const visitedSymbols = createMap<Symbol>(); // Key is id as string
17+
const visitedTypes: Type[] = []; // Sparse array from id to type
18+
const visitedSymbols: Symbol[] = []; // Sparse array from id to symbol
1919

2020
return {
2121
walkType: type => {
22-
visitedTypes.clear();
23-
visitedSymbols.clear();
24-
visitType(type);
25-
return { visitedTypes: arrayFrom(visitedTypes.values()), visitedSymbols: arrayFrom(visitedSymbols.values()) };
22+
try {
23+
visitType(type);
24+
return { visitedTypes: getOwnValues(visitedTypes), visitedSymbols: getOwnValues(visitedSymbols) };
25+
}
26+
finally {
27+
clear(visitedTypes);
28+
clear(visitedSymbols);
29+
}
2630
},
2731
walkSymbol: symbol => {
28-
visitedTypes.clear();
29-
visitedSymbols.clear();
30-
visitSymbol(symbol);
31-
return { visitedTypes: arrayFrom(visitedTypes.values()), visitedSymbols: arrayFrom(visitedSymbols.values()) };
32+
try {
33+
visitSymbol(symbol);
34+
return { visitedTypes: getOwnValues(visitedTypes), visitedSymbols: getOwnValues(visitedSymbols) };
35+
}
36+
finally {
37+
clear(visitedTypes);
38+
clear(visitedSymbols);
39+
}
3240
},
3341
};
3442

@@ -37,11 +45,10 @@ namespace ts {
3745
return;
3846
}
3947

40-
const typeIdString = type.id.toString();
41-
if (visitedTypes.has(typeIdString)) {
48+
if (visitedTypes[type.id]) {
4249
return;
4350
}
44-
visitedTypes.set(typeIdString, type);
51+
visitedTypes[type.id] = type;
4552

4653
// Reuse visitSymbol to visit the type's symbol,
4754
// but be sure to bail on recuring into the type if accept declines the symbol.
@@ -79,26 +86,17 @@ namespace ts {
7986
}
8087
}
8188

82-
function visitTypeList(types: Type[]): void {
83-
if (!types) {
84-
return;
85-
}
86-
for (let i = 0; i < types.length; i++) {
87-
visitType(types[i]);
88-
}
89-
}
90-
9189
function visitTypeReference(type: TypeReference): void {
9290
visitType(type.target);
93-
visitTypeList(type.typeArguments);
91+
forEach(type.typeArguments, visitType);
9492
}
9593

9694
function visitTypeParameter(type: TypeParameter): void {
9795
visitType(getConstraintFromTypeParameter(type));
9896
}
9997

10098
function visitUnionOrIntersectionType(type: UnionOrIntersectionType): void {
101-
visitTypeList(type.types);
99+
forEach(type.types, visitType);
102100
}
103101

104102
function visitIndexType(type: IndexType): void {
@@ -122,7 +120,7 @@ namespace ts {
122120
if (signature.typePredicate) {
123121
visitType(signature.typePredicate.type);
124122
}
125-
visitTypeList(signature.typeParameters);
123+
forEach(signature.typeParameters, visitType);
126124

127125
for (const parameter of signature.parameters){
128126
visitSymbol(parameter);
@@ -133,8 +131,8 @@ namespace ts {
133131

134132
function visitInterfaceType(interfaceT: InterfaceType): void {
135133
visitObjectType(interfaceT);
136-
visitTypeList(interfaceT.typeParameters);
137-
visitTypeList(getBaseTypes(interfaceT));
134+
forEach(interfaceT.typeParameters, visitType);
135+
forEach(getBaseTypes(interfaceT), visitType);
138136
visitType(interfaceT.thisType);
139137
}
140138

@@ -161,11 +159,11 @@ namespace ts {
161159
if (!symbol) {
162160
return;
163161
}
164-
const symbolIdString = getSymbolId(symbol).toString();
165-
if (visitedSymbols.has(symbolIdString)) {
162+
const symbolId = getSymbolId(symbol);
163+
if (visitedSymbols[symbolId]) {
166164
return;
167165
}
168-
visitedSymbols.set(symbolIdString, symbol);
166+
visitedSymbols[symbolId] = symbol;
169167
if (!accept(symbol)) {
170168
return true;
171169
}

0 commit comments

Comments
 (0)