Skip to content

Commit c2b79df

Browse files
committed
Merge branch 'master' into fixGenericSignatureRelation
2 parents 39c263b + 7a3e68f commit c2b79df

File tree

49 files changed

+1580
-629
lines changed

Some content is hidden

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

49 files changed

+1580
-629
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ gulp tests # Build the test infrastructure using the built compiler.
7979
gulp runtests # Run tests using the built compiler and test infrastructure.
8080
# You can override the host or specify a test for this command.
8181
# Use --host=<hostName> or --tests=<testPath>.
82-
gulp runtests-browser # Runs the tests using the built run.js file. Syntax is gulp runtests. Optional
83-
parameters '--host=', '--tests=[regex], --reporter=[list|spec|json|<more>]'.
8482
gulp baseline-accept # This replaces the baseline test results with the results obtained from gulp runtests.
8583
gulp lint # Runs tslint on the TypeScript source.
8684
gulp help # List the above commands.

scripts/perf-result-post.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ gh.issues.createComment({
2222
owner: "Microsoft",
2323
repo: "TypeScript",
2424
body: `@${requester}
25-
The results of the perf run you requested are in! Here they are:
26-
27-
${outputTableText}`
25+
The results of the perf run you requested are in!
26+
<details><summary> Here they are:</summary><p>
27+
${outputTableText}
28+
</p></details>`
2829
}).then(async data => {
2930
console.log(`Results posted!`);
3031
const newCommentUrl = data.data.html_url;

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ namespace ts {
16481648
if (result && isInExternalModule && (meaning & SymbolFlags.Value) === SymbolFlags.Value && !(originalLocation!.flags & NodeFlags.JSDoc)) {
16491649
const merged = getMergedSymbol(result);
16501650
if (length(merged.declarations) && every(merged.declarations, d => isNamespaceExportDeclaration(d) || isSourceFile(d) && !!d.symbol.globalExports)) {
1651-
error(errorLocation!, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name)); // TODO: GH#18217
1651+
errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation!, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name));
16521652
}
16531653
}
16541654
}
@@ -11261,7 +11261,7 @@ namespace ts {
1126111261
// If the anonymous type originates in a declaration of a function, method, class, or
1126211262
// interface, in an object type literal, or in an object literal expression, we may need
1126311263
// to instantiate the type because it might reference a type parameter.
11264-
return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ?
11264+
return couldContainTypeVariables(type) ?
1126511265
getAnonymousTypeInstantiation(<AnonymousType>type, mapper) : type;
1126611266
}
1126711267
if (objectFlags & ObjectFlags.Mapped) {
@@ -11300,7 +11300,7 @@ namespace ts {
1130011300
}
1130111301
else {
1130211302
const sub = instantiateType((<SubstitutionType>type).substitute, mapper);
11303-
if (sub.flags & TypeFlags.AnyOrUnknown || isTypeSubtypeOf(getRestrictiveInstantiation(maybeVariable), getRestrictiveInstantiation(sub))) {
11303+
if (sub.flags & TypeFlags.AnyOrUnknown || isTypeAssignableTo(getRestrictiveInstantiation(maybeVariable), getRestrictiveInstantiation(sub))) {
1130411304
return maybeVariable;
1130511305
}
1130611306
return sub;
@@ -14561,7 +14561,7 @@ namespace ts {
1456114561
const objectFlags = getObjectFlags(type);
1456214562
return !!(type.flags & TypeFlags.Instantiable ||
1456314563
objectFlags & ObjectFlags.Reference && forEach((<TypeReference>type).typeArguments, couldContainTypeVariables) ||
14564-
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) ||
14564+
objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ||
1456514565
objectFlags & ObjectFlags.Mapped ||
1456614566
type.flags & TypeFlags.UnionOrIntersection && couldUnionOrIntersectionContainTypeVariables(<UnionOrIntersectionType>type));
1456714567
}
@@ -20447,7 +20447,7 @@ namespace ts {
2044720447

2044820448
function getArrayifiedType(type: Type) {
2044920449
if (forEachType(type, t => !(t.flags & (TypeFlags.Any | TypeFlags.Instantiable) || isArrayType(t) || isTupleType(t)))) {
20450-
return createArrayType(getIndexTypeOfType(type, IndexKind.Number) || errorType);
20450+
return createArrayType(getIndexedAccessType(type, numberType));
2045120451
}
2045220452
return type;
2045320453
}

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,13 @@ namespace ts {
588588
category: Diagnostics.Module_Resolution_Options,
589589
description: Diagnostics.Do_not_resolve_the_real_path_of_symlinks,
590590
},
591+
{
592+
name: "allowUmdGlobalAccess",
593+
type: "boolean",
594+
affectsSemanticDiagnostics: true,
595+
category: Diagnostics.Module_Resolution_Options,
596+
description: Diagnostics.Allow_accessing_UMD_globals_from_modules,
597+
},
591598

592599
// Source Maps
593600
{

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,5 +4946,9 @@
49464946
"Convert parameters to destructured object": {
49474947
"category": "Message",
49484948
"code": 95075
4949+
},
4950+
"Allow accessing UMD globals from modules.": {
4951+
"category": "Message",
4952+
"code": 95076
49494953
}
49504954
}

src/compiler/parser.ts

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,10 @@ namespace ts {
10811081
return currentToken = scanner.scan();
10821082
}
10831083

1084+
function nextTokenJSDoc(): JSDocSyntaxKind {
1085+
return currentToken = scanner.scanJsDocToken();
1086+
}
1087+
10841088
function reScanGreaterToken(): SyntaxKind {
10851089
return currentToken = scanner.reScanGreaterToken();
10861090
}
@@ -1198,6 +1202,15 @@ namespace ts {
11981202
return false;
11991203
}
12001204

1205+
function parseExpectedJSDoc(kind: JSDocSyntaxKind) {
1206+
if (token() === kind) {
1207+
nextTokenJSDoc();
1208+
return true;
1209+
}
1210+
parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(kind));
1211+
return false;
1212+
}
1213+
12011214
function parseOptional(t: SyntaxKind): boolean {
12021215
if (token() === t) {
12031216
nextToken();
@@ -1214,18 +1227,38 @@ namespace ts {
12141227
return undefined;
12151228
}
12161229

1230+
function parseOptionalTokenJSDoc<TKind extends JSDocSyntaxKind>(t: TKind): Token<TKind>;
1231+
function parseOptionalTokenJSDoc(t: JSDocSyntaxKind): Node | undefined {
1232+
if (token() === t) {
1233+
return parseTokenNodeJSDoc();
1234+
}
1235+
return undefined;
1236+
}
1237+
12171238
function parseExpectedToken<TKind extends SyntaxKind>(t: TKind, diagnosticMessage?: DiagnosticMessage, arg0?: any): Token<TKind>;
12181239
function parseExpectedToken(t: SyntaxKind, diagnosticMessage?: DiagnosticMessage, arg0?: any): Node {
12191240
return parseOptionalToken(t) ||
12201241
createMissingNode(t, /*reportAtCurrentPosition*/ false, diagnosticMessage || Diagnostics._0_expected, arg0 || tokenToString(t));
12211242
}
12221243

1244+
function parseExpectedTokenJSDoc<TKind extends JSDocSyntaxKind>(t: TKind): Token<TKind>;
1245+
function parseExpectedTokenJSDoc(t: JSDocSyntaxKind): Node {
1246+
return parseOptionalTokenJSDoc(t) ||
1247+
createMissingNode(t, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(t));
1248+
}
1249+
12231250
function parseTokenNode<T extends Node>(): T {
12241251
const node = <T>createNode(token());
12251252
nextToken();
12261253
return finishNode(node);
12271254
}
12281255

1256+
function parseTokenNodeJSDoc<T extends Node>(): T {
1257+
const node = <T>createNode(token());
1258+
nextTokenJSDoc();
1259+
return finishNode(node);
1260+
}
1261+
12291262
function canParseSemicolon() {
12301263
// If there's a real semicolon, then we can always parse it out.
12311264
if (token() === SyntaxKind.SemicolonToken) {
@@ -6345,7 +6378,7 @@ namespace ts {
63456378
const hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(SyntaxKind.OpenBraceToken);
63466379
result.type = doInsideOfContext(NodeFlags.JSDoc, parseJSDocType);
63476380
if (!mayOmitBraces || hasBrace) {
6348-
parseExpected(SyntaxKind.CloseBraceToken);
6381+
parseExpectedJSDoc(SyntaxKind.CloseBraceToken);
63496382
}
63506383

63516384
fixupParentReferences(result);
@@ -6432,7 +6465,7 @@ namespace ts {
64326465
indent += text.length;
64336466
}
64346467

6435-
nextJSDocToken();
6468+
nextTokenJSDoc();
64366469
while (parseOptionalJsdoc(SyntaxKind.WhitespaceTrivia));
64376470
if (parseOptionalJsdoc(SyntaxKind.NewLineTrivia)) {
64386471
state = JSDocState.BeginningOfLine;
@@ -6493,7 +6526,7 @@ namespace ts {
64936526
pushComment(scanner.getTokenText());
64946527
break;
64956528
}
6496-
nextJSDocToken();
6529+
nextTokenJSDoc();
64976530
}
64986531
removeLeadingNewlines(comments);
64996532
removeTrailingWhitespace(comments);
@@ -6522,7 +6555,7 @@ namespace ts {
65226555
function isNextNonwhitespaceTokenEndOfFile(): boolean {
65236556
// We must use infinite lookahead, as there could be any number of newlines :(
65246557
while (true) {
6525-
nextJSDocToken();
6558+
nextTokenJSDoc();
65266559
if (token() === SyntaxKind.EndOfFileToken) {
65276560
return true;
65286561
}
@@ -6539,7 +6572,7 @@ namespace ts {
65396572
}
65406573
}
65416574
while (token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia) {
6542-
nextJSDocToken();
6575+
nextTokenJSDoc();
65436576
}
65446577
}
65456578

@@ -6563,15 +6596,15 @@ namespace ts {
65636596
else if (token() === SyntaxKind.AsteriskToken) {
65646597
precedingLineBreak = false;
65656598
}
6566-
nextJSDocToken();
6599+
nextTokenJSDoc();
65676600
}
65686601
return seenLineBreak ? indentText : "";
65696602
}
65706603

65716604
function parseTag(margin: number) {
65726605
Debug.assert(token() === SyntaxKind.AtToken);
65736606
const start = scanner.getTokenPos();
6574-
nextJSDocToken();
6607+
nextTokenJSDoc();
65756608

65766609
const tagName = parseJSDocIdentifierName(/*message*/ undefined);
65776610
const indentText = skipWhitespaceOrAsterisk();
@@ -6643,7 +6676,7 @@ namespace ts {
66436676
pushComment(initialMargin);
66446677
state = JSDocState.SavingComments;
66456678
}
6646-
let tok = token() as JsDocSyntaxKind;
6679+
let tok = token() as JSDocSyntaxKind;
66476680
loop: while (true) {
66486681
switch (tok) {
66496682
case SyntaxKind.NewLineTrivia:
@@ -6674,11 +6707,11 @@ namespace ts {
66746707
break;
66756708
case SyntaxKind.OpenBraceToken:
66766709
state = JSDocState.SavingComments;
6677-
if (lookAhead(() => nextJSDocToken() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextJSDocToken()) && scanner.getTokenText() === "link")) {
6710+
if (lookAhead(() => nextTokenJSDoc() === SyntaxKind.AtToken && tokenIsIdentifierOrKeyword(nextTokenJSDoc()) && scanner.getTokenText() === "link")) {
66786711
pushComment(scanner.getTokenText());
6679-
nextJSDocToken();
6712+
nextTokenJSDoc();
66806713
pushComment(scanner.getTokenText());
6681-
nextJSDocToken();
6714+
nextTokenJSDoc();
66826715
}
66836716
pushComment(scanner.getTokenText());
66846717
break;
@@ -6696,7 +6729,7 @@ namespace ts {
66966729
pushComment(scanner.getTokenText());
66976730
break;
66986731
}
6699-
tok = nextJSDocToken();
6732+
tok = nextTokenJSDoc();
67006733
}
67016734

67026735
removeLeadingNewlines(comments);
@@ -6730,16 +6763,19 @@ namespace ts {
67306763
}
67316764

67326765
function parseBracketNameInPropertyAndParamTag(): { name: EntityName, isBracketed: boolean } {
6733-
if (token() === SyntaxKind.NoSubstitutionTemplateLiteral) {
6734-
// a markdown-quoted name: `arg` is not legal jsdoc, but occurs in the wild
6735-
return { name: createIdentifier(/*isIdentifier*/ true), isBracketed: false };
6736-
}
67376766
// Looking for something like '[foo]', 'foo', '[foo.bar]' or 'foo.bar'
6738-
const isBracketed = parseOptional(SyntaxKind.OpenBracketToken);
6767+
const isBracketed = parseOptionalJsdoc(SyntaxKind.OpenBracketToken);
6768+
if (isBracketed) {
6769+
skipWhitespace();
6770+
}
6771+
// a markdown-quoted name: `arg` is not legal jsdoc, but occurs in the wild
6772+
const isBackquoted = parseOptionalJsdoc(SyntaxKind.BacktickToken);
67396773
const name = parseJSDocEntityName();
6774+
if (isBackquoted) {
6775+
parseExpectedTokenJSDoc(SyntaxKind.BacktickToken);
6776+
}
67406777
if (isBracketed) {
67416778
skipWhitespace();
6742-
67436779
// May have an optional default, e.g. '[foo = 42]'
67446780
if (parseOptionalToken(SyntaxKind.EqualsToken)) {
67456781
parseExpression();
@@ -7022,7 +7058,7 @@ namespace ts {
70227058
let canParseTag = true;
70237059
let seenAsterisk = false;
70247060
while (true) {
7025-
switch (nextJSDocToken()) {
7061+
switch (nextTokenJSDoc()) {
70267062
case SyntaxKind.AtToken:
70277063
if (canParseTag) {
70287064
const child = tryParseChildTag(target, indent);
@@ -7057,7 +7093,7 @@ namespace ts {
70577093
function tryParseChildTag(target: PropertyLikeParse, indent: number): JSDocTypeTag | JSDocPropertyTag | JSDocParameterTag | false {
70587094
Debug.assert(token() === SyntaxKind.AtToken);
70597095
const start = scanner.getStartPos();
7060-
nextJSDocToken();
7096+
nextTokenJSDoc();
70617097

70627098
const tagName = parseJSDocIdentifierName();
70637099
skipWhitespace();
@@ -7109,13 +7145,9 @@ namespace ts {
71097145
return result;
71107146
}
71117147

7112-
function nextJSDocToken(): JsDocSyntaxKind {
7113-
return currentToken = scanner.scanJSDocToken();
7114-
}
7115-
7116-
function parseOptionalJsdoc(t: JsDocSyntaxKind): boolean {
7148+
function parseOptionalJsdoc(t: JSDocSyntaxKind): boolean {
71177149
if (token() === t) {
7118-
nextJSDocToken();
7150+
nextTokenJSDoc();
71197151
return true;
71207152
}
71217153
return false;
@@ -7150,7 +7182,7 @@ namespace ts {
71507182
result.escapedText = escapeLeadingUnderscores(scanner.getTokenText());
71517183
finishNode(result, end);
71527184

7153-
nextJSDocToken();
7185+
nextTokenJSDoc();
71547186
return result;
71557187
}
71567188
}

src/compiler/scanner.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ts {
3333
reScanJsxToken(): JsxTokenSyntaxKind;
3434
reScanLessThanToken(): SyntaxKind;
3535
scanJsxToken(): JsxTokenSyntaxKind;
36-
scanJSDocToken(): JsDocSyntaxKind;
36+
scanJsDocToken(): JSDocSyntaxKind;
3737
scan(): SyntaxKind;
3838
getText(): string;
3939
// Sets the text for the scanner to scan. An optional subrange starting point and length
@@ -886,7 +886,7 @@ namespace ts {
886886
reScanJsxToken,
887887
reScanLessThanToken,
888888
scanJsxToken,
889-
scanJSDocToken,
889+
scanJsDocToken,
890890
scan,
891891
getText,
892892
setText,
@@ -2050,7 +2050,7 @@ namespace ts {
20502050
}
20512051
}
20522052

2053-
function scanJSDocToken(): JsDocSyntaxKind {
2053+
function scanJsDocToken(): JSDocSyntaxKind {
20542054
startPos = tokenPos = pos;
20552055
tokenFlags = 0;
20562056
if (pos >= end) {
@@ -2093,12 +2093,7 @@ namespace ts {
20932093
case CharacterCodes.dot:
20942094
return token = SyntaxKind.DotToken;
20952095
case CharacterCodes.backtick:
2096-
while (pos < end && text.charCodeAt(pos) !== CharacterCodes.backtick) {
2097-
pos++;
2098-
}
2099-
tokenValue = text.substring(tokenPos + 1, pos);
2100-
pos++;
2101-
return token = SyntaxKind.NoSubstitutionTemplateLiteral;
2096+
return token = SyntaxKind.BacktickToken;
21022097
}
21032098

21042099
if (isIdentifierStart(ch, ScriptTarget.Latest)) {

0 commit comments

Comments
 (0)