Switch from 'deferred' modifier to 'immediate' modifier

This commit is contained in:
Anders Hejlsberg 2024-08-08 10:25:21 -07:00
Родитель f392aa3003
Коммит 5ae48a223a
11 изменённых файлов: 59 добавлений и 59 удалений

Просмотреть файл

@ -28554,7 +28554,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// circularities. Instead, we simply check if any signature has a deferred callback marker in the
// particular argument position.
signatures ??= getSignaturesOfType(getTypeOfExpression(flow.node.expression), SignatureKind.Call);
if (!some(signatures, sig => !!(getModifiersAtPosition(sig, i) & (ModifierFlags.Deferred | ModifierFlags.JSDocDeferred)))) {
if (some(signatures, sig => !!(getModifiersAtPosition(sig, i) & (ModifierFlags.Immediate | ModifierFlags.JSDocImmediate)))) {
const lambdaType = getTypeFromFlowType(getTypeAtFlowNode(lambda.returnFlowNode));
if (lambdaType !== initialType) {
lambdaTypes ??= [initialType];
@ -41140,10 +41140,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (node.dotDotDotToken && !isBindingPattern(node.name) && !isTypeAssignableTo(getReducedType(getTypeOfSymbol(node.symbol)), anyReadonlyArrayType)) {
error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type);
}
if (hasEffectiveModifier(node, ModifierFlags.Deferred | ModifierFlags.JSDocDeferred)) {
if (hasEffectiveModifier(node, ModifierFlags.Immediate | ModifierFlags.JSDocImmediate)) {
const funcType = node.dotDotDotToken ? createArrayType(globalFunctionType, /*readonly*/ true) : globalFunctionType;
if (!areTypesComparable(getTypeOfSymbol(node.symbol), funcType)) {
error(node, Diagnostics.A_deferred_parameter_must_have_a_type_that_permits_functions);
error(node, Diagnostics.An_immediate_parameter_must_have_a_type_that_permits_functions);
}
}
}
@ -51025,26 +51025,26 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
break;
}
case SyntaxKind.DeferredKeyword:
case SyntaxKind.ImmediateKeyword:
if (node.kind !== SyntaxKind.Parameter) {
return grammarErrorOnNode(modifier, Diagnostics.deferred_modifier_can_only_appear_on_a_parameter_declaration);
return grammarErrorOnNode(modifier, Diagnostics.immediate_modifier_can_only_appear_on_a_parameter_declaration);
}
if (flags & ModifierFlags.Deferred) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "deferred");
if (flags & ModifierFlags.Immediate) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_already_seen, "immediate");
}
if (flags & ModifierFlags.Public) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "deferred", "public");
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "immediate", "public");
}
if (flags & ModifierFlags.Protected) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "deferred", "protected");
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "immediate", "protected");
}
if (flags & ModifierFlags.Private) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "deferred", "private");
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "immediate", "private");
}
if (flags & ModifierFlags.Readonly) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "deferred", "readonly");
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_must_precede_1_modifier, "immediate", "readonly");
}
flags |= ModifierFlags.Deferred;
flags |= ModifierFlags.Immediate;
break;
}
}

Просмотреть файл

@ -971,7 +971,7 @@
"category": "Error",
"code": 1293
},
"'deferred' modifier can only appear on a parameter declaration.": {
"'immediate' modifier can only appear on a parameter declaration.": {
"category": "Error",
"code": 1294
},
@ -3944,7 +3944,7 @@
"category": "Error",
"code": 2873
},
"A 'deferred' parameter must have a type that permits functions.": {
"An 'immediate' parameter must have a type that permits functions.": {
"category": "Error",
"code": 2874
},

Просмотреть файл

@ -222,10 +222,10 @@ import {
JSDocCallbackTag,
JSDocClassTag,
JSDocComment,
JSDocDeferredTag,
JSDocDeprecatedTag,
JSDocEnumTag,
JSDocFunctionType,
JSDocImmediateTag,
JSDocImplementsTag,
JSDocImportTag,
JSDocLink,
@ -939,11 +939,11 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
get updateJSDocDeprecatedTag() {
return getJSDocSimpleTagUpdateFunction<JSDocDeprecatedTag>(SyntaxKind.JSDocDeprecatedTag);
},
get createJSDocDeferredTag() {
return getJSDocSimpleTagCreateFunction<JSDocDeferredTag>(SyntaxKind.JSDocDeferredTag);
get createJSDocImmediateTag() {
return getJSDocSimpleTagCreateFunction<JSDocImmediateTag>(SyntaxKind.JSDocImmediateTag);
},
get updateJSDocDeferredTag() {
return getJSDocSimpleTagUpdateFunction<JSDocDeferredTag>(SyntaxKind.JSDocDeferredTag);
get updateJSDocImmediateTag() {
return getJSDocSimpleTagUpdateFunction<JSDocImmediateTag>(SyntaxKind.JSDocImmediateTag);
},
get createJSDocThrowsTag() {
return getJSDocTypeLikeTagCreateFunction<JSDocThrowsTag>(SyntaxKind.JSDocThrowsTag);
@ -1478,7 +1478,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
case SyntaxKind.ReadonlyKeyword:
case SyntaxKind.AbstractKeyword:
case SyntaxKind.DeclareKeyword:
case SyntaxKind.DeferredKeyword:
case SyntaxKind.ImmediateKeyword:
case SyntaxKind.ConstKeyword:
case SyntaxKind.AnyKeyword:
case SyntaxKind.NumberKeyword:
@ -1563,7 +1563,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
if (flags & ModifierFlags.Ambient) result.push(createModifier(SyntaxKind.DeclareKeyword));
if (flags & ModifierFlags.Default) result.push(createModifier(SyntaxKind.DefaultKeyword));
if (flags & ModifierFlags.Const) result.push(createModifier(SyntaxKind.ConstKeyword));
if (flags & ModifierFlags.Deferred) result.push(createModifier(SyntaxKind.DeferredKeyword));
if (flags & ModifierFlags.Immediate) result.push(createModifier(SyntaxKind.ImmediateKeyword));
if (flags & ModifierFlags.Public) result.push(createModifier(SyntaxKind.PublicKeyword));
if (flags & ModifierFlags.Private) result.push(createModifier(SyntaxKind.PrivateKeyword));
if (flags & ModifierFlags.Protected) result.push(createModifier(SyntaxKind.ProtectedKeyword));

Просмотреть файл

@ -87,10 +87,10 @@ import {
JSDocAuthorTag,
JSDocCallbackTag,
JSDocClassTag,
JSDocDeferredTag,
JSDocDeprecatedTag,
JSDocEnumTag,
JSDocFunctionType,
JSDocImmediateTag,
JSDocImplementsTag,
JSDocImportTag,
JSDocLink,
@ -1138,8 +1138,8 @@ export function isJSDocDeprecatedTag(node: Node): node is JSDocDeprecatedTag {
return node.kind === SyntaxKind.JSDocDeprecatedTag;
}
export function isJSDocDeferredTag(node: Node): node is JSDocDeferredTag {
return node.kind === SyntaxKind.JSDocDeferredTag;
export function isJSDocImmediateTag(node: Node): node is JSDocImmediateTag {
return node.kind === SyntaxKind.JSDocImmediateTag;
}
export function isJSDocSeeTag(node: Node): node is JSDocSeeTag {

Просмотреть файл

@ -9081,8 +9081,8 @@ namespace Parser {
hasDeprecatedTag = true;
tag = parseSimpleTag(start, factory.createJSDocDeprecatedTag, tagName, margin, indentText);
break;
case "deferred":
tag = parseSimpleTag(start, factory.createJSDocDeferredTag, tagName, margin, indentText);
case "immediate":
tag = parseSimpleTag(start, factory.createJSDocImmediateTag, tagName, margin, indentText);
break;
case "this":
tag = parseThisTag(start, tagName, margin, indentText);

Просмотреть файл

@ -3342,7 +3342,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.ReadonlyKeyword:
case SyntaxKind.DeclareKeyword:
case SyntaxKind.DeferredKeyword:
case SyntaxKind.ImmediateKeyword:
case SyntaxKind.AbstractKeyword:
case SyntaxKind.OverrideKeyword:
case SyntaxKind.InKeyword:

Просмотреть файл

@ -150,7 +150,6 @@ export const textToKeywordObj: MapLike<KeywordSyntaxKind> = {
debugger: SyntaxKind.DebuggerKeyword,
declare: SyntaxKind.DeclareKeyword,
default: SyntaxKind.DefaultKeyword,
deferred: SyntaxKind.DeferredKeyword,
delete: SyntaxKind.DeleteKeyword,
do: SyntaxKind.DoKeyword,
else: SyntaxKind.ElseKeyword,
@ -164,6 +163,7 @@ export const textToKeywordObj: MapLike<KeywordSyntaxKind> = {
function: SyntaxKind.FunctionKeyword,
get: SyntaxKind.GetKeyword,
if: SyntaxKind.IfKeyword,
immediate: SyntaxKind.ImmediateKeyword,
implements: SyntaxKind.ImplementsKeyword,
import: SyntaxKind.ImportKeyword,
in: SyntaxKind.InKeyword,
@ -352,7 +352,7 @@ const commentDirectiveRegExSingleLine = /^\/\/\/?\s*@(ts-expect-error|ts-ignore)
*/
const commentDirectiveRegExMultiLine = /^(?:\/|\*)*\s*@(ts-expect-error|ts-ignore)/;
const jsDocSeeOrLinkOrDeferred = /@(?:see|link|deferred)/i;
const jsDocSeeOrLinkOrImmediate = /@(?:see|link|immediate)/i;
function lookupInUnicodeMap(code: number, map: readonly number[]): boolean {
// Bail out quickly if it couldn't possibly be in the map.
@ -2397,7 +2397,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
return false;
}
return jsDocSeeOrLinkOrDeferred.test(text.slice(fullStartPos, pos));
return jsDocSeeOrLinkOrImmediate.test(text.slice(fullStartPos, pos));
}
function reScanInvalidIdentifier(): SyntaxKind {

Просмотреть файл

@ -661,7 +661,7 @@ export function transformTypeScript(context: TransformationContext) {
case SyntaxKind.OverrideKeyword:
case SyntaxKind.ConstKeyword:
case SyntaxKind.DeclareKeyword:
case SyntaxKind.DeferredKeyword:
case SyntaxKind.ImmediateKeyword:
case SyntaxKind.ReadonlyKeyword:
case SyntaxKind.InKeyword:
case SyntaxKind.OutKeyword:

Просмотреть файл

@ -195,8 +195,8 @@ export const enum SyntaxKind {
BooleanKeyword,
ConstructorKeyword,
DeclareKeyword,
DeferredKeyword,
GetKeyword,
ImmediateKeyword,
InferKeyword,
IntrinsicKeyword,
IsKeyword,
@ -420,7 +420,7 @@ export const enum SyntaxKind {
JSDocImplementsTag,
JSDocAuthorTag,
JSDocDeprecatedTag,
JSDocDeferredTag,
JSDocImmediateTag,
JSDocClassTag,
JSDocPublicTag,
JSDocPrivateTag,
@ -599,7 +599,6 @@ export type KeywordSyntaxKind =
| SyntaxKind.DebuggerKeyword
| SyntaxKind.DeclareKeyword
| SyntaxKind.DefaultKeyword
| SyntaxKind.DeferredKeyword
| SyntaxKind.DeleteKeyword
| SyntaxKind.DoKeyword
| SyntaxKind.ElseKeyword
@ -614,6 +613,7 @@ export type KeywordSyntaxKind =
| SyntaxKind.GetKeyword
| SyntaxKind.GlobalKeyword
| SyntaxKind.IfKeyword
| SyntaxKind.ImmediateKeyword
| SyntaxKind.ImplementsKeyword
| SyntaxKind.ImportKeyword
| SyntaxKind.InferKeyword
@ -671,8 +671,8 @@ export type ModifierSyntaxKind =
| SyntaxKind.ConstKeyword
| SyntaxKind.DeclareKeyword
| SyntaxKind.DefaultKeyword
| SyntaxKind.DeferredKeyword
| SyntaxKind.ExportKeyword
| SyntaxKind.ImmediateKeyword
| SyntaxKind.InKeyword
| SyntaxKind.PrivateKeyword
| SyntaxKind.ProtectedKeyword
@ -869,11 +869,11 @@ export const enum ModifierFlags {
In = 1 << 13, // Contravariance modifier
Out = 1 << 14, // Covariance modifier
Decorator = 1 << 15, // Contains a decorator.
Deferred = 1 << 16, // Parameter
Immediate = 1 << 16, // Parameter
// JSDoc-only modifiers
Deprecated = 1 << 17, // Deprecated tag.
JSDocDeferred = 1 << 18, // Parameter
JSDocImmediate = 1 << 18, // Parameter
// Cache-only JSDoc-modifiers. Should match order of Syntactic/JSDoc modifiers, above.
/** @internal */ JSDocPublic = 1 << 23, // if this value changes, `selectEffectiveModifierFlags` must change accordingly
@ -883,10 +883,10 @@ export const enum ModifierFlags {
/** @internal */ JSDocOverride = 1 << 27,
/** @internal */ SyntacticOrJSDocModifiers = Public | Private | Protected | Readonly | Override,
/** @internal */ SyntacticOnlyModifiers = Export | Ambient | Abstract | Static | Accessor | Async | Default | Const | In | Out | Decorator | Deferred,
/** @internal */ SyntacticOnlyModifiers = Export | Ambient | Abstract | Static | Accessor | Async | Default | Const | In | Out | Decorator | Immediate,
/** @internal */ SyntacticModifiers = SyntacticOrJSDocModifiers | SyntacticOnlyModifiers,
/** @internal */ JSDocCacheOnlyModifiers = JSDocPublic | JSDocPrivate | JSDocProtected | JSDocReadonly | JSDocOverride,
/** @internal */ JSDocOnlyModifiers = Deprecated | JSDocDeferred,
/** @internal */ JSDocOnlyModifiers = Deprecated | JSDocImmediate,
/** @internal */ NonCacheOnlyModifiers = SyntacticOrJSDocModifiers | SyntacticOnlyModifiers | JSDocOnlyModifiers,
HasComputedJSDocModifiers = 1 << 28, // Indicates the computed modifier flags include modifiers from JSDoc.
@ -897,9 +897,9 @@ export const enum ModifierFlags {
ParameterPropertyModifier = AccessibilityModifier | Readonly | Override,
NonPublicAccessibilityModifier = Private | Protected,
TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const | Override | In | Out | Deferred,
TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const | Override | In | Out | Immediate,
ExportDefault = Export | Default,
All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Accessor | Async | Default | Const | Deprecated | Override | In | Out | Deferred | Decorator,
All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Accessor | Async | Default | Const | Deprecated | Override | In | Out | Immediate | Decorator,
Modifier = All & ~Decorator,
}
@ -1636,8 +1636,8 @@ export type AsyncKeyword = ModifierToken<SyntaxKind.AsyncKeyword>;
export type ConstKeyword = ModifierToken<SyntaxKind.ConstKeyword>;
export type DeclareKeyword = ModifierToken<SyntaxKind.DeclareKeyword>;
export type DefaultKeyword = ModifierToken<SyntaxKind.DefaultKeyword>;
export type DeferredKeyword = ModifierToken<SyntaxKind.DeferredKeyword>;
export type ExportKeyword = ModifierToken<SyntaxKind.ExportKeyword>;
export type ImmediateKeyword = ModifierToken<SyntaxKind.ImmediateKeyword>;
export type InKeyword = ModifierToken<SyntaxKind.InKeyword>;
export type PrivateKeyword = ModifierToken<SyntaxKind.PrivateKeyword>;
export type ProtectedKeyword = ModifierToken<SyntaxKind.ProtectedKeyword>;
@ -1654,8 +1654,8 @@ export type Modifier =
| ConstKeyword
| DeclareKeyword
| DefaultKeyword
| DeferredKeyword
| ExportKeyword
| ImmediateKeyword
| InKeyword
| PrivateKeyword
| ProtectedKeyword
@ -3994,8 +3994,8 @@ export interface JSDocDeprecatedTag extends JSDocTag {
kind: SyntaxKind.JSDocDeprecatedTag;
}
export interface JSDocDeferredTag extends JSDocTag {
kind: SyntaxKind.JSDocDeferredTag;
export interface JSDocImmediateTag extends JSDocTag {
kind: SyntaxKind.JSDocImmediateTag;
}
export interface JSDocClassTag extends JSDocTag {
@ -9057,8 +9057,8 @@ export interface NodeFactory {
updateJSDocUnknownTag(node: JSDocUnknownTag, tagName: Identifier, comment: string | NodeArray<JSDocComment> | undefined): JSDocUnknownTag;
createJSDocDeprecatedTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeprecatedTag;
updateJSDocDeprecatedTag(node: JSDocDeprecatedTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeprecatedTag;
createJSDocDeferredTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeferredTag;
updateJSDocDeferredTag(node: JSDocDeferredTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocDeferredTag;
createJSDocImmediateTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocImmediateTag;
updateJSDocImmediateTag(node: JSDocImmediateTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocImmediateTag;
createJSDocOverrideTag(tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocOverrideTag;
updateJSDocOverrideTag(node: JSDocOverrideTag, tagName: Identifier | undefined, comment?: string | NodeArray<JSDocComment>): JSDocOverrideTag;
createJSDocThrowsTag(tagName: Identifier, typeExpression: JSDocTypeExpression | undefined, comment?: string | NodeArray<JSDocComment>): JSDocThrowsTag;

Просмотреть файл

@ -169,8 +169,8 @@ import {
getDirectoryPath,
getImpliedNodeFormatForEmitWorker,
getJSDocAugmentsTag,
getJSDocDeferredTagNoCache,
getJSDocDeprecatedTagNoCache,
getJSDocImmediateTagNoCache,
getJSDocImplementsTags,
getJSDocOverrideTagNoCache,
getJSDocParameterTags,
@ -7108,7 +7108,7 @@ function getRawJSDocModifierFlagsNoCache(node: Node): ModifierFlags {
}
}
if (!isParameter(node) && getJSDocDeprecatedTagNoCache(node)) flags |= ModifierFlags.Deprecated;
if (getJSDocDeferredTagNoCache(node)) flags |= ModifierFlags.JSDocDeferred;
if (getJSDocImmediateTagNoCache(node)) flags |= ModifierFlags.JSDocImmediate;
}
return flags;
@ -7198,8 +7198,8 @@ export function modifierToFlag(token: SyntaxKind): ModifierFlags {
return ModifierFlags.In;
case SyntaxKind.OutKeyword:
return ModifierFlags.Out;
case SyntaxKind.DeferredKeyword:
return ModifierFlags.Deferred;
case SyntaxKind.ImmediateKeyword:
return ModifierFlags.Immediate;
case SyntaxKind.Decorator:
return ModifierFlags.Decorator;
}

Просмотреть файл

@ -137,10 +137,10 @@ import {
isJSDoc,
isJSDocAugmentsTag,
isJSDocClassTag,
isJSDocDeferredTag,
isJSDocDeprecatedTag,
isJSDocEnumTag,
isJSDocFunctionType,
isJSDocImmediateTag,
isJSDocImplementsTag,
isJSDocOverloadTag,
isJSDocOverrideTag,
@ -182,9 +182,9 @@ import {
JSDocClassTag,
JSDocComment,
JSDocContainer,
JSDocDeferredTag,
JSDocDeprecatedTag,
JSDocEnumTag,
JSDocImmediateTag,
JSDocImplementsTag,
JSDocLink,
JSDocLinkCode,
@ -1163,14 +1163,14 @@ export function getJSDocDeprecatedTagNoCache(node: Node): JSDocDeprecatedTag | u
return getFirstJSDocTag(node, isJSDocDeprecatedTag, /*noCache*/ true);
}
/** Gets the JSDoc deferred tag for the node if present */
export function getJSDocDeferredTag(node: Node): JSDocDeferredTag | undefined {
return getFirstJSDocTag(node, isJSDocDeferredTag);
/** Gets the JSDoc immediate tag for the node if present */
export function getJSDocImmediateTag(node: Node): JSDocImmediateTag | undefined {
return getFirstJSDocTag(node, isJSDocImmediateTag);
}
/** @internal */
export function getJSDocDeferredTagNoCache(node: Node): JSDocDeferredTag | undefined {
return getFirstJSDocTag(node, isJSDocDeferredTag, /*noCache*/ true);
export function getJSDocImmediateTagNoCache(node: Node): JSDocImmediateTag | undefined {
return getFirstJSDocTag(node, isJSDocImmediateTag, /*noCache*/ true);
}
/** Gets the JSDoc enum tag for the node if present */
@ -1609,8 +1609,8 @@ export function isModifierKind(token: SyntaxKind): token is Modifier["kind"] {
case SyntaxKind.ConstKeyword:
case SyntaxKind.DeclareKeyword:
case SyntaxKind.DefaultKeyword:
case SyntaxKind.DeferredKeyword:
case SyntaxKind.ExportKeyword:
case SyntaxKind.ImmediateKeyword:
case SyntaxKind.InKeyword:
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword: