Skip to content

Commit 88f79de

Browse files
committed
Merge branch 'master' into transitiveReferences
2 parents dd34314 + 51ff0d3 commit 88f79de

File tree

196 files changed

+3482
-770
lines changed

Some content is hidden

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

196 files changed

+3482
-770
lines changed

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

src/compiler/binder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,6 @@ namespace ts {
11811181
}
11821182
const preCaseLabel = createBranchLabel();
11831183
addAntecedent(preCaseLabel, createFlowSwitchClause(preSwitchCaseFlow!, node.parent, clauseStart, i + 1));
1184-
addAntecedent(preCaseLabel, createFlowSwitchClause(preSwitchCaseFlow!, node.parent, clauseStart, i + 1));
11851184
addAntecedent(preCaseLabel, fallthroughFlow);
11861185
currentFlow = finishFlowLabel(preCaseLabel);
11871186
const clause = clauses[i];
@@ -3445,7 +3444,9 @@ namespace ts {
34453444
// ES6 syntax, and requires a lexical `this` binding.
34463445
if (transformFlags & TransformFlags.Super) {
34473446
transformFlags ^= TransformFlags.Super;
3448-
transformFlags |= TransformFlags.ContainsSuper;
3447+
// super inside of an async function requires hoisting the super access (ES2017).
3448+
// same for super inside of an async generator, which is ESNext.
3449+
transformFlags |= TransformFlags.ContainsSuper | TransformFlags.ContainsES2017 | TransformFlags.ContainsESNext;
34493450
}
34503451

34513452
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
@@ -3461,7 +3462,9 @@ namespace ts {
34613462
// ES6 syntax, and requires a lexical `this` binding.
34623463
if (expressionFlags & TransformFlags.Super) {
34633464
transformFlags &= ~TransformFlags.Super;
3464-
transformFlags |= TransformFlags.ContainsSuper;
3465+
// super inside of an async function requires hoisting the super access (ES2017).
3466+
// same for super inside of an async generator, which is ESNext.
3467+
transformFlags |= TransformFlags.ContainsSuper | TransformFlags.ContainsES2017 | TransformFlags.ContainsESNext;
34653468
}
34663469

34673470
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;

src/compiler/builderState.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,39 @@ namespace ts.BuilderState {
148148
});
149149
}
150150

151+
// Add module augmentation as references
152+
if (sourceFile.moduleAugmentations.length) {
153+
const checker = program.getTypeChecker();
154+
for (const moduleName of sourceFile.moduleAugmentations) {
155+
if (!isStringLiteral(moduleName)) { continue; }
156+
const symbol = checker.getSymbolAtLocation(moduleName);
157+
if (!symbol) { continue; }
158+
159+
// Add any file other than our own as reference
160+
addReferenceFromAmbientModule(symbol);
161+
}
162+
}
163+
164+
// From ambient modules
165+
for (const ambientModule of program.getTypeChecker().getAmbientModules()) {
166+
if (ambientModule.declarations.length > 1) {
167+
addReferenceFromAmbientModule(ambientModule);
168+
}
169+
}
170+
151171
return referencedFiles;
152172

173+
function addReferenceFromAmbientModule(symbol: Symbol) {
174+
// Add any file other than our own as reference
175+
for (const declaration of symbol.declarations) {
176+
const declarationSourceFile = getSourceFileOfNode(declaration);
177+
if (declarationSourceFile &&
178+
declarationSourceFile !== sourceFile) {
179+
addReferencedFile(declarationSourceFile.resolvedPath);
180+
}
181+
}
182+
}
183+
153184
function addReferencedFile(referencedPath: Path) {
154185
if (!referencedFiles) {
155186
referencedFiles = createMap<true>();

src/compiler/checker.ts

Lines changed: 164 additions & 99 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
@@ -2116,6 +2116,10 @@
21162116
"category": "Error",
21172117
"code": 2586
21182118
},
2119+
"JSDoc type '{0}' circularly references itself.": {
2120+
"category": "Error",
2121+
"code": 2587
2122+
},
21192123
"JSX element attributes type '{0}' may not be a union type.": {
21202124
"category": "Error",
21212125
"code": 2600

src/compiler/moduleSpecifiers.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,18 @@ namespace ts.moduleSpecifiers {
260260
}
261261

262262
function tryGetModuleNameAsNodeModule(moduleFileName: string, { getCanonicalFileName, sourceDirectory }: Info, host: ModuleSpecifierResolutionHost, options: CompilerOptions): string | undefined {
263+
if (!host.fileExists || !host.readFile) {
264+
return undefined;
265+
}
263266
const parts: NodeModulePathParts = getNodeModulePathParts(moduleFileName)!;
264267
if (!parts) {
265268
return undefined;
266269
}
267270

268271
const packageRootPath = moduleFileName.substring(0, parts.packageRootIndex);
269272
const packageJsonPath = combinePaths(packageRootPath, "package.json");
270-
const packageJsonContent = host.fileExists!(packageJsonPath)
271-
? JSON.parse(host.readFile!(packageJsonPath)!)
273+
const packageJsonContent = host.fileExists(packageJsonPath)
274+
? JSON.parse(host.readFile(packageJsonPath)!)
272275
: undefined;
273276
const versionPaths = packageJsonContent && packageJsonContent.typesVersions
274277
? getPackageJsonTypesVersionsPaths(packageJsonContent.typesVersions)
@@ -325,11 +328,12 @@ namespace ts.moduleSpecifiers {
325328
}
326329

327330
function tryGetAnyFileFromPath(host: ModuleSpecifierResolutionHost, path: string) {
331+
if (!host.fileExists) return;
328332
// We check all js, `node` and `json` extensions in addition to TS, since node module resolution would also choose those over the directory
329333
const extensions = getSupportedExtensions({ allowJs: true }, [{ extension: "node", isMixedContent: false }, { extension: "json", isMixedContent: false, scriptKind: ScriptKind.JSON }]);
330334
for (const e of extensions) {
331335
const fullPath = path + e;
332-
if (host.fileExists!(fullPath)) { // TODO: GH#18217
336+
if (host.fileExists(fullPath)) {
333337
return fullPath;
334338
}
335339
}

src/compiler/parser.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6308,7 +6308,7 @@ namespace ts {
63086308

63096309
// Parses out a JSDoc type expression.
63106310
export function parseJSDocTypeExpression(mayOmitBraces?: boolean): JSDocTypeExpression {
6311-
const result = <JSDocTypeExpression>createNode(SyntaxKind.JSDocTypeExpression, scanner.getTokenPos());
6311+
const result = <JSDocTypeExpression>createNode(SyntaxKind.JSDocTypeExpression);
63126312

63136313
const hasBrace = (mayOmitBraces ? parseOptional : parseExpected)(SyntaxKind.OpenBraceToken);
63146314
result.type = doInsideOfContext(NodeFlags.JSDoc, parseJSDocType);
@@ -6441,13 +6441,6 @@ namespace ts {
64416441
indent += asterisk.length;
64426442
}
64436443
break;
6444-
case SyntaxKind.Identifier:
6445-
// Anything else is doc comment text. We just save it. Because it
6446-
// wasn't a tag, we can no longer parse a tag on this line until we hit the next
6447-
// line break.
6448-
pushComment(scanner.getTokenText());
6449-
state = JSDocState.SavingComments;
6450-
break;
64516444
case SyntaxKind.WhitespaceTrivia:
64526445
// only collect whitespace if we're already saving comments or have just crossed the comment indent margin
64536446
const whitespace = scanner.getTokenText();
@@ -6462,7 +6455,9 @@ namespace ts {
64626455
case SyntaxKind.EndOfFileToken:
64636456
break loop;
64646457
default:
6465-
// anything other than whitespace or asterisk at the beginning of the line starts the comment text
6458+
// Anything else is doc comment text. We just save it. Because it
6459+
// wasn't a tag, we can no longer parse a tag on this line until we hit the next
6460+
// line break.
64666461
state = JSDocState.SavingComments;
64676462
pushComment(scanner.getTokenText());
64686463
break;
@@ -6517,7 +6512,7 @@ namespace ts {
65176512
}
65186513
}
65196514

6520-
function skipWhitespaceOrAsterisk(next: () => void): void {
6515+
function skipWhitespaceOrAsterisk(): void {
65216516
if (token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia) {
65226517
if (lookAhead(isNextNonwhitespaceTokenEndOfFile)) {
65236518
return; // Don't skip whitespace prior to EoF (or end of comment) - that shouldn't be included in any node's range
@@ -6532,7 +6527,7 @@ namespace ts {
65326527
else if (token() === SyntaxKind.AsteriskToken) {
65336528
precedingLineBreak = false;
65346529
}
6535-
next();
6530+
nextJSDocToken();
65366531
}
65376532
}
65386533

@@ -6542,9 +6537,8 @@ namespace ts {
65426537
atToken.end = scanner.getTextPos();
65436538
nextJSDocToken();
65446539

6545-
// Use 'nextToken' instead of 'nextJsDocToken' so we can parse a type like 'number' in `@enum number`
6546-
const tagName = parseJSDocIdentifierName(/*message*/ undefined, nextToken);
6547-
skipWhitespaceOrAsterisk(nextToken);
6540+
const tagName = parseJSDocIdentifierName(/*message*/ undefined);
6541+
skipWhitespaceOrAsterisk();
65486542

65496543
let tag: JSDocTag | undefined;
65506544
switch (tagName.escapedText) {
@@ -6688,7 +6682,7 @@ namespace ts {
66886682
}
66896683

66906684
function tryParseTypeExpression(): JSDocTypeExpression | undefined {
6691-
skipWhitespaceOrAsterisk(nextJSDocToken);
6685+
skipWhitespaceOrAsterisk();
66926686
return token() === SyntaxKind.OpenBraceToken ? parseJSDocTypeExpression() : undefined;
66936687
}
66946688

@@ -6728,7 +6722,7 @@ namespace ts {
67286722
function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, target: PropertyLikeParse, indent: number): JSDocParameterTag | JSDocPropertyTag {
67296723
let typeExpression = tryParseTypeExpression();
67306724
let isNameFirst = !typeExpression;
6731-
skipWhitespaceOrAsterisk(nextJSDocToken);
6725+
skipWhitespaceOrAsterisk();
67326726

67336727
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
67346728
skipWhitespace();
@@ -6862,7 +6856,7 @@ namespace ts {
68626856

68636857
function parseTypedefTag(atToken: AtToken, tagName: Identifier, indent: number): JSDocTypedefTag {
68646858
const typeExpression = tryParseTypeExpression();
6865-
skipWhitespaceOrAsterisk(nextJSDocToken);
6859+
skipWhitespaceOrAsterisk();
68666860

68676861
const typedefTag = <JSDocTypedefTag>createNode(SyntaxKind.JSDocTypedefTag, atToken.pos);
68686862
typedefTag.atToken = atToken;
@@ -7115,7 +7109,7 @@ namespace ts {
71157109
return entity;
71167110
}
71177111

7118-
function parseJSDocIdentifierName(message?: DiagnosticMessage, next: () => void = nextJSDocToken): Identifier {
7112+
function parseJSDocIdentifierName(message?: DiagnosticMessage): Identifier {
71197113
if (!tokenIsIdentifierOrKeyword(token())) {
71207114
return createMissingNode<Identifier>(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ !message, message || Diagnostics.Identifier_expected);
71217115
}
@@ -7126,7 +7120,7 @@ namespace ts {
71267120
result.escapedText = escapeLeadingUnderscores(scanner.getTokenText());
71277121
finishNode(result, end);
71287122

7129-
next();
7123+
nextJSDocToken();
71307124
return result;
71317125
}
71327126
}

0 commit comments

Comments
 (0)