Skip to content

Commit 90345f8

Browse files
authored
Merge branch 'microsoft:main' into main
2 parents c7264f0 + 1f85123 commit 90345f8

File tree

85 files changed

+2201
-1302
lines changed

Some content is hidden

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

85 files changed

+2201
-1302
lines changed

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/binder.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,11 +1666,15 @@ namespace ts {
16661666
}
16671667

16681668
function bindJSDocTypeAlias(node: JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag) {
1669-
setParent(node.tagName, node);
1669+
bind(node.tagName);
16701670
if (node.kind !== SyntaxKind.JSDocEnumTag && node.fullName) {
1671+
// don't bind the type name yet; that's delayed until delayedBindJSDocTypedefTag
16711672
setParent(node.fullName, node);
16721673
setParentRecursive(node.fullName, /*incremental*/ false);
16731674
}
1675+
if (typeof node.comment !== "string") {
1676+
bindEach(node.comment);
1677+
}
16741678
}
16751679

16761680
function bindJSDocClassTag(node: JSDocClassTag) {

src/compiler/checker.ts

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ namespace ts {
555555
getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, CheckMode.IsForSignatureHelp),
556556
getExpandedParameters,
557557
hasEffectiveRestParameter,
558+
containsArgumentsReference,
558559
getConstantValue: nodeIn => {
559560
const node = getParseTreeNode(nodeIn, canHaveConstantValue);
560561
return node ? getConstantValue(node) : undefined;
@@ -580,6 +581,7 @@ namespace ts {
580581
getEmitResolver,
581582
getExportsOfModule: getExportsOfModuleAsArray,
582583
getExportsAndPropertiesOfModule,
584+
forEachExportAndPropertyOfModule,
583585
getSymbolWalker: createGetSymbolWalker(
584586
getRestTypeOfSignature,
585587
getTypePredicateOfSignature,
@@ -920,6 +922,7 @@ namespace ts {
920922
let deferredGlobalAsyncGeneratorType: GenericType;
921923
let deferredGlobalTemplateStringsArraySymbol: Symbol;
922924
let deferredGlobalImportMetaType: ObjectType;
925+
let deferredGlobalImportMetaExpressionType: ObjectType;
923926
let deferredGlobalExtractSymbol: Symbol;
924927
let deferredGlobalOmitSymbol: Symbol;
925928
let deferredGlobalBigIntType: ObjectType;
@@ -3530,6 +3533,24 @@ namespace ts {
35303533
return exports;
35313534
}
35323535

3536+
function forEachExportAndPropertyOfModule(moduleSymbol: Symbol, cb: (symbol: Symbol, key: __String) => void): void {
3537+
const exports = getExportsOfModule(moduleSymbol);
3538+
exports.forEach((symbol, key) => {
3539+
if (!isReservedMemberName(key)) {
3540+
cb(symbol, key);
3541+
}
3542+
});
3543+
const exportEquals = resolveExternalModuleSymbol(moduleSymbol);
3544+
if (exportEquals !== moduleSymbol) {
3545+
const type = getTypeOfSymbol(exportEquals);
3546+
if (shouldTreatPropertiesOfExternalModuleAsExports(type)) {
3547+
getPropertiesOfType(type).forEach(symbol => {
3548+
cb(symbol, symbol.escapedName);
3549+
});
3550+
}
3551+
}
3552+
}
3553+
35333554
function tryGetMemberInModuleExports(memberName: __String, moduleSymbol: Symbol): Symbol | undefined {
35343555
const symbolTable = getExportsOfModule(moduleSymbol);
35353556
if (symbolTable) {
@@ -13323,6 +13344,24 @@ namespace ts {
1332313344
return deferredGlobalImportMetaType || (deferredGlobalImportMetaType = getGlobalType("ImportMeta" as __String, /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType;
1332413345
}
1332513346

13347+
function getGlobalImportMetaExpressionType() {
13348+
if (!deferredGlobalImportMetaExpressionType) {
13349+
// Create a synthetic type `ImportMetaExpression { meta: MetaProperty }`
13350+
const symbol = createSymbol(SymbolFlags.None, "ImportMetaExpression" as __String);
13351+
const importMetaType = getGlobalImportMetaType();
13352+
13353+
const metaPropertySymbol = createSymbol(SymbolFlags.Property, "meta" as __String, CheckFlags.Readonly);
13354+
metaPropertySymbol.parent = symbol;
13355+
metaPropertySymbol.type = importMetaType;
13356+
13357+
const members = createSymbolTable([metaPropertySymbol]);
13358+
symbol.members = members;
13359+
13360+
deferredGlobalImportMetaExpressionType = createAnonymousType(symbol, members, emptyArray, emptyArray, emptyArray);
13361+
}
13362+
return deferredGlobalImportMetaExpressionType;
13363+
}
13364+
1332613365
function getGlobalESSymbolConstructorSymbol(reportErrors: boolean) {
1332713366
return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol" as __String, reportErrors));
1332813367
}
@@ -16441,25 +16480,6 @@ namespace ts {
1644116480
(hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node));
1644216481
}
1644316482

16444-
function hasContextSensitiveParameters(node: FunctionLikeDeclaration) {
16445-
// Functions with type parameters are not context sensitive.
16446-
if (!node.typeParameters) {
16447-
// Functions with any parameters that lack type annotations are context sensitive.
16448-
if (some(node.parameters, p => !getEffectiveTypeAnnotationNode(p))) {
16449-
return true;
16450-
}
16451-
if (node.kind !== SyntaxKind.ArrowFunction) {
16452-
// If the first parameter is not an explicit 'this' parameter, then the function has
16453-
// an implicit 'this' parameter which is subject to contextual typing.
16454-
const parameter = firstOrUndefined(node.parameters);
16455-
if (!(parameter && parameterIsThisKeyword(parameter))) {
16456-
return true;
16457-
}
16458-
}
16459-
}
16460-
return false;
16461-
}
16462-
1646316483
function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
1646416484
// TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value.
1646516485
return !node.typeParameters && !getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body);
@@ -30509,6 +30529,18 @@ namespace ts {
3050930529
return Debug.assertNever(node.keywordToken);
3051030530
}
3051130531

30532+
function checkMetaPropertyKeyword(node: MetaProperty): Type {
30533+
switch (node.keywordToken) {
30534+
case SyntaxKind.ImportKeyword:
30535+
return getGlobalImportMetaExpressionType();
30536+
case SyntaxKind.NewKeyword:
30537+
const type = checkNewTargetMetaProperty(node);
30538+
return type === errorType ? errorType : createNewTargetExpressionType(type);
30539+
default:
30540+
Debug.assertNever(node.keywordToken);
30541+
}
30542+
}
30543+
3051230544
function checkNewTargetMetaProperty(node: MetaProperty) {
3051330545
const container = getNewTargetContainer(node);
3051430546
if (!container) {
@@ -30531,7 +30563,6 @@ namespace ts {
3053130563
}
3053230564
const file = getSourceFileOfNode(node);
3053330565
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
30534-
Debug.assert(!!file.externalModuleIndicator, "Containing file should be a module.");
3053530566
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
3053630567
}
3053730568

@@ -30893,6 +30924,19 @@ namespace ts {
3089330924
return promiseType;
3089430925
}
3089530926

30927+
function createNewTargetExpressionType(targetType: Type): Type {
30928+
// Create a synthetic type `NewTargetExpression { target: TargetType; }`
30929+
const symbol = createSymbol(SymbolFlags.None, "NewTargetExpression" as __String);
30930+
30931+
const targetPropertySymbol = createSymbol(SymbolFlags.Property, "target" as __String, CheckFlags.Readonly);
30932+
targetPropertySymbol.parent = symbol;
30933+
targetPropertySymbol.type = targetType;
30934+
30935+
const members = createSymbolTable([targetPropertySymbol]);
30936+
symbol.members = members;
30937+
return createAnonymousType(symbol, members, emptyArray, emptyArray, emptyArray);
30938+
}
30939+
3089630940
function getReturnTypeFromBody(func: FunctionLikeDeclaration, checkMode?: CheckMode): Type {
3089730941
if (!func.body) {
3089830942
return errorType;
@@ -39828,6 +39872,16 @@ namespace ts {
3982839872
return propertyDeclaration;
3982939873
}
3983039874
}
39875+
else if (isMetaProperty(parent)) {
39876+
const parentType = getTypeOfNode(parent);
39877+
const propertyDeclaration = getPropertyOfType(parentType, (node as Identifier).escapedText);
39878+
if (propertyDeclaration) {
39879+
return propertyDeclaration;
39880+
}
39881+
if (parent.keywordToken === SyntaxKind.NewKeyword) {
39882+
return checkNewTargetMetaProperty(parent).symbol;
39883+
}
39884+
}
3983139885
}
3983239886

3983339887
switch (node.kind) {
@@ -39902,6 +39956,12 @@ namespace ts {
3990239956
case SyntaxKind.ExportKeyword:
3990339957
return isExportAssignment(node.parent) ? Debug.checkDefined(node.parent.symbol) : undefined;
3990439958

39959+
case SyntaxKind.ImportKeyword:
39960+
case SyntaxKind.NewKeyword:
39961+
return isMetaProperty(node.parent) ? checkMetaPropertyKeyword(node.parent).symbol : undefined;
39962+
case SyntaxKind.MetaProperty:
39963+
return checkExpression(node as Expression).symbol;
39964+
3990539965
default:
3990639966
return undefined;
3990739967
}
@@ -40001,6 +40061,10 @@ namespace ts {
4000140061
}
4000240062
}
4000340063

40064+
if (isMetaProperty(node.parent) && node.parent.keywordToken === node.kind) {
40065+
return checkMetaPropertyKeyword(node.parent);
40066+
}
40067+
4000440068
return errorType;
4000540069
}
4000640070

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ namespace ts {
223223
type: "boolean",
224224
showInSimplifiedHelpView: true,
225225
category: Diagnostics.Output_Formatting,
226-
description: Diagnostics.Enable_color_and_formatting_in_output_to_make_compiler_errors_easier_to_read,
226+
description: Diagnostics.Enable_color_and_formatting_in_TypeScript_s_output_to_make_compiler_errors_easier_to_read,
227227
defaultValueDescription: "true"
228228
},
229229
{
@@ -553,7 +553,7 @@ namespace ts {
553553
type: "boolean",
554554
showInSimplifiedHelpView: true,
555555
category: Diagnostics.Emit,
556-
description: Diagnostics.Disable_emitting_file_from_a_compilation,
556+
description: Diagnostics.Disable_emitting_files_from_a_compilation,
557557
transpileOptionValue: undefined,
558558
defaultValueDescription: "false"
559559
},

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5459,7 +5459,7 @@
54595459
"category": "Message",
54605460
"code": 6659
54615461
},
5462-
"Disable emitting file from a compilation.": {
5462+
"Disable emitting files from a compilation.": {
54635463
"category": "Message",
54645464
"code": 6660
54655465
},
@@ -5559,7 +5559,7 @@
55595559
"category": "Message",
55605560
"code": 6684
55615561
},
5562-
"Enable color and formatting in output to make compiler errors easier to read": {
5562+
"Enable color and formatting in TypeScript's output to make compiler errors easier to read": {
55635563
"category": "Message",
55645564
"code": 6685
55655565
},
@@ -5788,7 +5788,7 @@
57885788
"category": "Message",
57895789
"code": 6923
57905790
},
5791-
"Ignoring tsconfig.json, compiles the specified files with default compiler options": {
5791+
"Ignoring tsconfig.json, compiles the specified files with default compiler options.": {
57925792
"category": "Message",
57935793
"code": 6924
57945794
},
@@ -5800,15 +5800,15 @@
58005800
"category": "Message",
58015801
"code": 6926
58025802
},
5803-
"Compiles the TypeScript project located at the specified path": {
5803+
"Compiles the TypeScript project located at the specified path.": {
58045804
"category": "Message",
58055805
"code": 6927
58065806
},
58075807
"An expanded version of this information, showing all possible compiler options": {
58085808
"category": "Message",
58095809
"code": 6928
58105810
},
5811-
"Compiles the current project, with additional settings": {
5811+
"Compiles the current project, with additional settings.": {
58125812
"category": "Message",
58135813
"code": 6929
58145814
},

src/compiler/factory/nodeTests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ namespace ts {
129129
return node.kind === SyntaxKind.StaticKeyword;
130130
}
131131

132+
/* @internal */
133+
export function isAbstractModifier(node: Node): node is AbstractKeyword {
134+
return node.kind === SyntaxKind.AbstractKeyword;
135+
}
136+
132137
/*@internal*/
133138
export function isSuperKeyword(node: Node): node is SuperExpression {
134139
return node.kind === SyntaxKind.SuperKeyword;

src/compiler/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ namespace ts {
530530
visitNode(cbNode, (node as JSDocTypedefTag).fullName) ||
531531
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined))
532532
: visitNode(cbNode, (node as JSDocTypedefTag).fullName) ||
533-
visitNode(cbNode, (node as JSDocTypedefTag).typeExpression)) ||
534-
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined));
533+
visitNode(cbNode, (node as JSDocTypedefTag).typeExpression) ||
534+
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined)));
535535
case SyntaxKind.JSDocCallbackTag:
536536
return visitNode(cbNode, (node as JSDocTag).tagName) ||
537537
visitNode(cbNode, (node as JSDocCallbackTag).fullName) ||

src/compiler/transformers/taggedTemplate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ namespace ts {
8181
// Examples: `\n` is converted to "\\n", a template string with a newline to "\n".
8282
let text = node.rawText;
8383
if (text === undefined) {
84+
Debug.assertIsDefined(currentSourceFile,
85+
"Template literal node is missing 'rawText' and does not have a source file. Possibly bad transform.");
8486
text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
8587

8688
// text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"),

src/compiler/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4205,6 +4205,8 @@ namespace ts {
42054205
/* @internal */ getResolvedSignatureForSignatureHelp(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined;
42064206
/* @internal */ getExpandedParameters(sig: Signature): readonly (readonly Symbol[])[];
42074207
/* @internal */ hasEffectiveRestParameter(sig: Signature): boolean;
4208+
/* @internal */ containsArgumentsReference(declaration: SignatureDeclaration): boolean;
4209+
42084210
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined;
42094211
isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined;
42104212
isUndefinedSymbol(symbol: Symbol): boolean;
@@ -4223,6 +4225,7 @@ namespace ts {
42234225
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
42244226
/** Unlike `getExportsOfModule`, this includes properties of an `export =` value. */
42254227
/* @internal */ getExportsAndPropertiesOfModule(moduleSymbol: Symbol): Symbol[];
4228+
/* @internal */ forEachExportAndPropertyOfModule(moduleSymbol: Symbol, cb: (symbol: Symbol, key: __String) => void): void;
42264229
getJsxIntrinsicTagNamesAt(location: Node): Symbol[];
42274230
isOptionalParameter(node: ParameterDeclaration): boolean;
42284231
getAmbientModules(): Symbol[];

0 commit comments

Comments
 (0)