Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BobobUnicorn committed Aug 5, 2021
2 parents c7264f0 + 1f85123 commit 90345f8
Show file tree
Hide file tree
Showing 85 changed files with 2,201 additions and 1,302 deletions.
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1666,11 +1666,15 @@ namespace ts {
}

function bindJSDocTypeAlias(node: JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag) {
setParent(node.tagName, node);
bind(node.tagName);
if (node.kind !== SyntaxKind.JSDocEnumTag && node.fullName) {
// don't bind the type name yet; that's delayed until delayedBindJSDocTypedefTag
setParent(node.fullName, node);
setParentRecursive(node.fullName, /*incremental*/ false);
}
if (typeof node.comment !== "string") {
bindEach(node.comment);
}
}

function bindJSDocClassTag(node: JSDocClassTag) {
Expand Down
104 changes: 84 additions & 20 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ namespace ts {
getResolvedSignatureWorker(node, candidatesOutArray, argumentCount, CheckMode.IsForSignatureHelp),
getExpandedParameters,
hasEffectiveRestParameter,
containsArgumentsReference,
getConstantValue: nodeIn => {
const node = getParseTreeNode(nodeIn, canHaveConstantValue);
return node ? getConstantValue(node) : undefined;
Expand All @@ -580,6 +581,7 @@ namespace ts {
getEmitResolver,
getExportsOfModule: getExportsOfModuleAsArray,
getExportsAndPropertiesOfModule,
forEachExportAndPropertyOfModule,
getSymbolWalker: createGetSymbolWalker(
getRestTypeOfSignature,
getTypePredicateOfSignature,
Expand Down Expand Up @@ -920,6 +922,7 @@ namespace ts {
let deferredGlobalAsyncGeneratorType: GenericType;
let deferredGlobalTemplateStringsArraySymbol: Symbol;
let deferredGlobalImportMetaType: ObjectType;
let deferredGlobalImportMetaExpressionType: ObjectType;
let deferredGlobalExtractSymbol: Symbol;
let deferredGlobalOmitSymbol: Symbol;
let deferredGlobalBigIntType: ObjectType;
Expand Down Expand Up @@ -3530,6 +3533,24 @@ namespace ts {
return exports;
}

function forEachExportAndPropertyOfModule(moduleSymbol: Symbol, cb: (symbol: Symbol, key: __String) => void): void {
const exports = getExportsOfModule(moduleSymbol);
exports.forEach((symbol, key) => {
if (!isReservedMemberName(key)) {
cb(symbol, key);
}
});
const exportEquals = resolveExternalModuleSymbol(moduleSymbol);
if (exportEquals !== moduleSymbol) {
const type = getTypeOfSymbol(exportEquals);
if (shouldTreatPropertiesOfExternalModuleAsExports(type)) {
getPropertiesOfType(type).forEach(symbol => {
cb(symbol, symbol.escapedName);
});
}
}
}

function tryGetMemberInModuleExports(memberName: __String, moduleSymbol: Symbol): Symbol | undefined {
const symbolTable = getExportsOfModule(moduleSymbol);
if (symbolTable) {
Expand Down Expand Up @@ -13323,6 +13344,24 @@ namespace ts {
return deferredGlobalImportMetaType || (deferredGlobalImportMetaType = getGlobalType("ImportMeta" as __String, /*arity*/ 0, /*reportErrors*/ true)) || emptyObjectType;
}

function getGlobalImportMetaExpressionType() {
if (!deferredGlobalImportMetaExpressionType) {
// Create a synthetic type `ImportMetaExpression { meta: MetaProperty }`
const symbol = createSymbol(SymbolFlags.None, "ImportMetaExpression" as __String);
const importMetaType = getGlobalImportMetaType();

const metaPropertySymbol = createSymbol(SymbolFlags.Property, "meta" as __String, CheckFlags.Readonly);
metaPropertySymbol.parent = symbol;
metaPropertySymbol.type = importMetaType;

const members = createSymbolTable([metaPropertySymbol]);
symbol.members = members;

deferredGlobalImportMetaExpressionType = createAnonymousType(symbol, members, emptyArray, emptyArray, emptyArray);
}
return deferredGlobalImportMetaExpressionType;
}

function getGlobalESSymbolConstructorSymbol(reportErrors: boolean) {
return deferredGlobalESSymbolConstructorSymbol || (deferredGlobalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol" as __String, reportErrors));
}
Expand Down Expand Up @@ -16441,25 +16480,6 @@ namespace ts {
(hasContextSensitiveParameters(node) || hasContextSensitiveReturnExpression(node));
}

function hasContextSensitiveParameters(node: FunctionLikeDeclaration) {
// Functions with type parameters are not context sensitive.
if (!node.typeParameters) {
// Functions with any parameters that lack type annotations are context sensitive.
if (some(node.parameters, p => !getEffectiveTypeAnnotationNode(p))) {
return true;
}
if (node.kind !== SyntaxKind.ArrowFunction) {
// If the first parameter is not an explicit 'this' parameter, then the function has
// an implicit 'this' parameter which is subject to contextual typing.
const parameter = firstOrUndefined(node.parameters);
if (!(parameter && parameterIsThisKeyword(parameter))) {
return true;
}
}
}
return false;
}

function hasContextSensitiveReturnExpression(node: FunctionLikeDeclaration) {
// TODO(anhans): A block should be context-sensitive if it has a context-sensitive return value.
return !node.typeParameters && !getEffectiveReturnTypeNode(node) && !!node.body && node.body.kind !== SyntaxKind.Block && isContextSensitive(node.body);
Expand Down Expand Up @@ -30509,6 +30529,18 @@ namespace ts {
return Debug.assertNever(node.keywordToken);
}

function checkMetaPropertyKeyword(node: MetaProperty): Type {
switch (node.keywordToken) {
case SyntaxKind.ImportKeyword:
return getGlobalImportMetaExpressionType();
case SyntaxKind.NewKeyword:
const type = checkNewTargetMetaProperty(node);
return type === errorType ? errorType : createNewTargetExpressionType(type);
default:
Debug.assertNever(node.keywordToken);
}
}

function checkNewTargetMetaProperty(node: MetaProperty) {
const container = getNewTargetContainer(node);
if (!container) {
Expand All @@ -30531,7 +30563,6 @@ namespace ts {
}
const file = getSourceFileOfNode(node);
Debug.assert(!!(file.flags & NodeFlags.PossiblyContainsImportMeta), "Containing file is missing import meta node flag.");
Debug.assert(!!file.externalModuleIndicator, "Containing file should be a module.");
return node.name.escapedText === "meta" ? getGlobalImportMetaType() : errorType;
}

Expand Down Expand Up @@ -30893,6 +30924,19 @@ namespace ts {
return promiseType;
}

function createNewTargetExpressionType(targetType: Type): Type {
// Create a synthetic type `NewTargetExpression { target: TargetType; }`
const symbol = createSymbol(SymbolFlags.None, "NewTargetExpression" as __String);

const targetPropertySymbol = createSymbol(SymbolFlags.Property, "target" as __String, CheckFlags.Readonly);
targetPropertySymbol.parent = symbol;
targetPropertySymbol.type = targetType;

const members = createSymbolTable([targetPropertySymbol]);
symbol.members = members;
return createAnonymousType(symbol, members, emptyArray, emptyArray, emptyArray);
}

function getReturnTypeFromBody(func: FunctionLikeDeclaration, checkMode?: CheckMode): Type {
if (!func.body) {
return errorType;
Expand Down Expand Up @@ -39828,6 +39872,16 @@ namespace ts {
return propertyDeclaration;
}
}
else if (isMetaProperty(parent)) {
const parentType = getTypeOfNode(parent);
const propertyDeclaration = getPropertyOfType(parentType, (node as Identifier).escapedText);
if (propertyDeclaration) {
return propertyDeclaration;
}
if (parent.keywordToken === SyntaxKind.NewKeyword) {
return checkNewTargetMetaProperty(parent).symbol;
}
}
}

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

case SyntaxKind.ImportKeyword:
case SyntaxKind.NewKeyword:
return isMetaProperty(node.parent) ? checkMetaPropertyKeyword(node.parent).symbol : undefined;
case SyntaxKind.MetaProperty:
return checkExpression(node as Expression).symbol;

default:
return undefined;
}
Expand Down Expand Up @@ -40001,6 +40061,10 @@ namespace ts {
}
}

if (isMetaProperty(node.parent) && node.parent.keywordToken === node.kind) {
return checkMetaPropertyKeyword(node.parent);
}

return errorType;
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ namespace ts {
type: "boolean",
showInSimplifiedHelpView: true,
category: Diagnostics.Output_Formatting,
description: Diagnostics.Enable_color_and_formatting_in_output_to_make_compiler_errors_easier_to_read,
description: Diagnostics.Enable_color_and_formatting_in_TypeScript_s_output_to_make_compiler_errors_easier_to_read,
defaultValueDescription: "true"
},
{
Expand Down Expand Up @@ -553,7 +553,7 @@ namespace ts {
type: "boolean",
showInSimplifiedHelpView: true,
category: Diagnostics.Emit,
description: Diagnostics.Disable_emitting_file_from_a_compilation,
description: Diagnostics.Disable_emitting_files_from_a_compilation,
transpileOptionValue: undefined,
defaultValueDescription: "false"
},
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5459,7 +5459,7 @@
"category": "Message",
"code": 6659
},
"Disable emitting file from a compilation.": {
"Disable emitting files from a compilation.": {
"category": "Message",
"code": 6660
},
Expand Down Expand Up @@ -5559,7 +5559,7 @@
"category": "Message",
"code": 6684
},
"Enable color and formatting in output to make compiler errors easier to read": {
"Enable color and formatting in TypeScript's output to make compiler errors easier to read": {
"category": "Message",
"code": 6685
},
Expand Down Expand Up @@ -5788,7 +5788,7 @@
"category": "Message",
"code": 6923
},
"Ignoring tsconfig.json, compiles the specified files with default compiler options": {
"Ignoring tsconfig.json, compiles the specified files with default compiler options.": {
"category": "Message",
"code": 6924
},
Expand All @@ -5800,15 +5800,15 @@
"category": "Message",
"code": 6926
},
"Compiles the TypeScript project located at the specified path": {
"Compiles the TypeScript project located at the specified path.": {
"category": "Message",
"code": 6927
},
"An expanded version of this information, showing all possible compiler options": {
"category": "Message",
"code": 6928
},
"Compiles the current project, with additional settings": {
"Compiles the current project, with additional settings.": {
"category": "Message",
"code": 6929
},
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/factory/nodeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ namespace ts {
return node.kind === SyntaxKind.StaticKeyword;
}

/* @internal */
export function isAbstractModifier(node: Node): node is AbstractKeyword {
return node.kind === SyntaxKind.AbstractKeyword;
}

/*@internal*/
export function isSuperKeyword(node: Node): node is SuperExpression {
return node.kind === SyntaxKind.SuperKeyword;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ namespace ts {
visitNode(cbNode, (node as JSDocTypedefTag).fullName) ||
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined))
: visitNode(cbNode, (node as JSDocTypedefTag).fullName) ||
visitNode(cbNode, (node as JSDocTypedefTag).typeExpression)) ||
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined));
visitNode(cbNode, (node as JSDocTypedefTag).typeExpression) ||
(typeof (node as JSDoc).comment === "string" ? undefined : visitNodes(cbNode, cbNodes, (node as JSDoc).comment as NodeArray<JSDocComment> | undefined)));
case SyntaxKind.JSDocCallbackTag:
return visitNode(cbNode, (node as JSDocTag).tagName) ||
visitNode(cbNode, (node as JSDocCallbackTag).fullName) ||
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/transformers/taggedTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ namespace ts {
// Examples: `\n` is converted to "\\n", a template string with a newline to "\n".
let text = node.rawText;
if (text === undefined) {
Debug.assertIsDefined(currentSourceFile,
"Template literal node is missing 'rawText' and does not have a source file. Possibly bad transform.");
text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node);

// text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"),
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4205,6 +4205,8 @@ namespace ts {
/* @internal */ getResolvedSignatureForSignatureHelp(node: CallLikeExpression, candidatesOutArray?: Signature[], argumentCount?: number): Signature | undefined;
/* @internal */ getExpandedParameters(sig: Signature): readonly (readonly Symbol[])[];
/* @internal */ hasEffectiveRestParameter(sig: Signature): boolean;
/* @internal */ containsArgumentsReference(declaration: SignatureDeclaration): boolean;

getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature | undefined;
isImplementationOfOverload(node: SignatureDeclaration): boolean | undefined;
isUndefinedSymbol(symbol: Symbol): boolean;
Expand All @@ -4223,6 +4225,7 @@ namespace ts {
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
/** Unlike `getExportsOfModule`, this includes properties of an `export =` value. */
/* @internal */ getExportsAndPropertiesOfModule(moduleSymbol: Symbol): Symbol[];
/* @internal */ forEachExportAndPropertyOfModule(moduleSymbol: Symbol, cb: (symbol: Symbol, key: __String) => void): void;
getJsxIntrinsicTagNamesAt(location: Node): Symbol[];
isOptionalParameter(node: ParameterDeclaration): boolean;
getAmbientModules(): Symbol[];
Expand Down
Loading

0 comments on commit 90345f8

Please sign in to comment.