Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export const generateExtension = task({
const enumDefs = [
{ name: "SymbolFlags", goPrefix: "SymbolFlags", goFile: "tsc/internal/ast/symbolflags.go", outDir: "packages/typescript/src/enums" },
{ name: "CheckFlags", goPrefix: "CheckFlags", goFile: "tsc/internal/ast/checkflags.go", outDir: "packages/typescript/src/enums" },
{ name: "TypeFlags", goPrefix: "TypeFlags", goFile: "tsc/internal/checker/types.go", outDir: "packages/typescript/src/enums" },
{ name: "TypeFlags", goPrefix: "TypeFlags", goFile: "tsc/internal/checker/types.go", outDir: "packages/typescript/src/enums", excludeMembers: ["Reserved1", "Reserved2", "Reserved3", "IncludesConstrainedTypeVariable", "IncludesError", "IncludesNegated"] },
{ name: "ObjectFlags", goPrefix: "ObjectFlags", goFile: "tsc/internal/checker/types.go", outDir: "packages/typescript/src/enums" },
{ name: "SignatureFlags", goPrefix: "SignatureFlags", goFile: "tsc/internal/checker/types.go", outDir: "packages/typescript/src/enums" },
{ name: "SignatureKind", goPrefix: "SignatureKind", goFile: "tsc/internal/checker/types.go", outDir: "packages/typescript/src/enums" },
Expand Down Expand Up @@ -843,7 +843,7 @@ ${entries.join("\n")}
// A generic function call (unlike a constant conversion) forces Go to evaluate the conversion at
// runtime, truncating uint32-backed flags with a leading bitwise-not the same way JS's 32-bit
// bitwise operators would, instead of rejecting "constant overflows int32" at compile time.
func toInt32[T ~int8 | ~int16 | ~int32 | ~int | ~uint8 | ~uint16 | ~uint32](v T) int32 {
func toInt32[T ~int8 | ~int16 | ~int32 | ~int | ~uint8 | ~uint16 | ~uint32 | ~uint64](v T) int32 {
\treturn int32(v)
}

Expand Down Expand Up @@ -1445,8 +1445,8 @@ export const validate = task({
});

async function runSmokeTest() {
await run("./built/local/tsc", ["-p", "./tsc/testdata/fixtures/compiler", "--noEmit", "--singleThreaded"]);
await run("./built/local/tsc", ["-p", "./tsc/testdata/fixtures/compiler", "--noEmit"]);
await run("./built/local/tsc", ["-p", "./tsc/testdata/fixtures/compiler", "--noEmit", "--composite", "false", "--incremental", "false", "--singleThreaded"]);
await run("./built/local/tsc", ["-p", "./tsc/testdata/fixtures/compiler", "--noEmit", "--composite", "false", "--incremental", "false"]);
}

export const smokeTest = task({
Expand Down
13 changes: 13 additions & 0 deletions packages/typescript/src/api/async/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,11 @@ export class Checker {
return type.getNonNullableType();
}

/** Get the negation of a type. Always returns a type. */
async getNegatedType(type: Type): Promise<Type> {
return type.getNegatedType();
}

/**
* Get the type for a type node. Always returns a type; for type nodes whose
* type cannot be determined the checker yields the error type (use
Expand Down Expand Up @@ -2676,6 +2681,7 @@ class TypeObject implements Type {
private constraint: number | false;
private default: number | false;
private nonNullableType: number | false;
private negatedType: number | false;
private apparentType: number | false;
private reducedType: number | false;
private properties: readonly Symbol[] | false;
Expand Down Expand Up @@ -2750,6 +2756,7 @@ class TypeObject implements Type {
this.constraint = false;
this.default = false;
this.nonNullableType = false;
this.negatedType = false;
this.apparentType = false;
this.reducedType = false;
this.properties = false;
Expand Down Expand Up @@ -2804,6 +2811,12 @@ class TypeObject implements Type {
return result;
}

async getNegatedType(): Promise<Type> {
const result = await this.objectRegistry.fetchType(this, "getNegatedType", this.negatedType);
this.negatedType = result.id;
return result;
}

async getStringIndexType(): Promise<Type | undefined> {
if (this.stringIndexType === false) {
this.stringIndexType = await this.getStringIndexTypeWorker();
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/src/api/async/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export interface Type {
/** Get this type with `null` and `undefined` removed. */
getNonNullableType(): Promise<Type>;

/** Get the negation of this type. */
getNegatedType(): Promise<Type>;

/** Get this type's string index value type, if present. */
getStringIndexType(): Promise<Type | undefined>;

Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/api/node/encoder.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function getNodeCommonData(node: Node): number {
case SyntaxKind.ObjectLiteralExpression:
return ((node as ObjectLiteralExpression).multiLine ? 1 : 0) << 24;
case SyntaxKind.TypeOperator:
return ((node as TypeOperatorNode).operator === SyntaxKind.ReadonlyKeyword ? 1 : (node as TypeOperatorNode).operator === SyntaxKind.UniqueKeyword ? 2 : 0) << 24;
return ((node as TypeOperatorNode).operator === SyntaxKind.ReadonlyKeyword ? 1 : (node as TypeOperatorNode).operator === SyntaxKind.UniqueKeyword ? 2 : (node as TypeOperatorNode).operator === SyntaxKind.NotKeyword ? 3 : 0) << 24;
case SyntaxKind.ImportAttributes:
return ((node as ImportAttributes).multiLine ? 1 : 0) << 24 | ((node as ImportAttributes).token === SyntaxKind.AssertKeyword ? 1 : 0) << 25;
case SyntaxKind.JsxText:
Expand Down
1 change: 1 addition & 0 deletions packages/typescript/src/api/node/node.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ export class RemoteNode extends RemoteNodeBase implements Node {
const idx = (this.data >> 24) & 0x3;
if (idx === 1) return SyntaxKind.ReadonlyKeyword;
if (idx === 2) return SyntaxKind.UniqueKeyword;
if (idx === 3) return SyntaxKind.NotKeyword;
return SyntaxKind.KeyOfKeyword;
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/src/api/proto.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface APIMethodInfo {
getApparentPropertiesOfType: APIMethod<GetTypePropertyParams, SymbolResponse[]>;
getApparentType: APIMethod<GetTypePropertyParams, TypeResponse>;
getReducedType: APIMethod<GetTypePropertyParams, TypeResponse>;
getNegatedType: APIMethod<GetTypePropertyParams, TypeResponse>;
getPropertyOfType: APIMethod<GetPropertyOfTypeParams, SymbolResponse | null>;
getTypeOfPropertyOfType: APIMethod<GetPropertyOfTypeParams, TypeResponse | null>;
getIndexInfoOfType: APIMethod<GetIndexInfoOfTypeParams, IndexInfoResponse | null>;
Expand Down Expand Up @@ -1078,6 +1079,7 @@ export interface BatchRequest {
| "getMembersOfSymbol"
| "getModeForResolutionAtIndex"
| "getModeForUsageLocation"
| "getNegatedType"
| "getNeverType"
| "getNonMissingTypeOfSymbol"
| "getNonNullableType"
Expand Down Expand Up @@ -1238,6 +1240,7 @@ export interface BatchResponse {
| "getMembersOfSymbol"
| "getModeForResolutionAtIndex"
| "getModeForUsageLocation"
| "getNegatedType"
| "getNeverType"
| "getNonMissingTypeOfSymbol"
| "getNonNullableType"
Expand Down
41 changes: 41 additions & 0 deletions packages/typescript/src/api/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3866,6 +3866,24 @@ export class Checker {
);
}

/** Get the negation of a type. Always returns a type. */
get getNegatedType(): {
(type: Type): Type;
gen(type: Type): Generator<ProtocolRequest, Type, ProtocolResponse["result"]>;
} {
const owner = this;
return cacheGeneratorMethod(
owner,
"getNegatedType",
function (type: Type): Type {
return type.getNegatedType();
},
function* (type: Type): Generator<ProtocolRequest, Type, ProtocolResponse["result"]> {
return yield* type.getNegatedType.gen();
},
);
}

/**
* Get the type for a type node. Always returns a type; for type nodes whose
* type cannot be determined the checker yields the error type (use
Expand Down Expand Up @@ -5823,6 +5841,7 @@ class TypeObject implements Type {
private constraint: number | false;
private default: number | false;
private nonNullableType: number | false;
private negatedType: number | false;
private apparentType: number | false;
private reducedType: number | false;
private properties: readonly Symbol[] | false;
Expand Down Expand Up @@ -5897,6 +5916,7 @@ class TypeObject implements Type {
this.constraint = false;
this.default = false;
this.nonNullableType = false;
this.negatedType = false;
this.apparentType = false;
this.reducedType = false;
this.properties = false;
Expand Down Expand Up @@ -6056,6 +6076,27 @@ class TypeObject implements Type {
);
}

get getNegatedType(): {
(): Type;
gen(): Generator<ProtocolRequest, Type, ProtocolResponse["result"]>;
} {
const owner = this;
return cacheGeneratorMethod(
owner,
"getNegatedType",
function (): Type {
const result = owner.objectRegistry.fetchType(owner, "getNegatedType", owner.negatedType);
owner.negatedType = result.id;
return result;
},
function* (): Generator<ProtocolRequest, Type, ProtocolResponse["result"]> {
const result = yield* owner.objectRegistry.fetchType.gen(owner, "getNegatedType", owner.negatedType);
owner.negatedType = result.id;
return result;
},
);
}

get getStringIndexType(): {
(): Type | undefined;
gen(): Generator<ProtocolRequest, Type | undefined, ProtocolResponse["result"]>;
Expand Down
6 changes: 6 additions & 0 deletions packages/typescript/src/api/sync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ export interface Type {
gen(): Generator<ProtocolRequest, Type, ProtocolResponse["result"]>;
};

/** Get the negation of this type. */
getNegatedType: {
(): Type;
gen(): Generator<ProtocolRequest, Type, ProtocolResponse["result"]>;
};

/** Get this type's string index value type, if present. */
getStringIndexType: {
(): Type | undefined;
Expand Down
4 changes: 3 additions & 1 deletion packages/typescript/src/ast/ast.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export type KeywordSyntaxKind =
| SyntaxKind.ModuleKeyword
| SyntaxKind.NamespaceKeyword
| SyntaxKind.NeverKeyword
| SyntaxKind.NotKeyword
| SyntaxKind.OutKeyword
| SyntaxKind.ReadonlyKeyword
| SyntaxKind.RequireKeyword
Expand Down Expand Up @@ -311,6 +312,7 @@ export type TokenSyntaxKind =
| SyntaxKind.ModuleKeyword
| SyntaxKind.NamespaceKeyword
| SyntaxKind.NeverKeyword
| SyntaxKind.NotKeyword
| SyntaxKind.OutKeyword
| SyntaxKind.ReadonlyKeyword
| SyntaxKind.RequireKeyword
Expand Down Expand Up @@ -962,7 +964,7 @@ export interface ConditionalTypeNode extends TypeNodeBase {
}
export interface TypeOperatorNode extends TypeNodeBase {
readonly kind: SyntaxKind.TypeOperator;
readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword;
readonly operator: SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.NotKeyword;
readonly type: TypeNode;
}
export interface InferTypeNode extends TypeNodeBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/ast/factory.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ export function createConditionalTypeNode(checkType: TypeNode, extendsType: Type
}) as unknown as ConditionalTypeNode;
}

export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword, type: TypeNode): TypeOperatorNode {
export function createTypeOperatorNode(operator: SyntaxKind.KeyOfKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.NotKeyword, type: TypeNode): TypeOperatorNode {
return new NodeObject(SyntaxKind.TypeOperator, {
operator,
type,
Expand Down
1 change: 1 addition & 0 deletions packages/typescript/src/enums/objectFlags.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export enum ObjectFlags {
IsNeverIntersectionComputed = 1 << 25,
IsNeverIntersection = 1 << 26,
IsConstrainedTypeVariable = 1 << 27,
FreshNegated = 1 << 25,
}
1 change: 1 addition & 0 deletions packages/typescript/src/enums/objectFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export var ObjectFlags: any;
ObjectFlags[ObjectFlags["IsNeverIntersectionComputed"] = 33554432] = "IsNeverIntersectionComputed";
ObjectFlags[ObjectFlags["IsNeverIntersection"] = 67108864] = "IsNeverIntersection";
ObjectFlags[ObjectFlags["IsConstrainedTypeVariable"] = 134217728] = "IsConstrainedTypeVariable";
ObjectFlags[ObjectFlags["FreshNegated"] = 33554432] = "FreshNegated";
})(ObjectFlags || (ObjectFlags = {}));
Loading
Loading