Skip to content

Commit 5d99110

Browse files
committed
Add initial slim AstNode API
1 parent 31afb98 commit 5d99110

File tree

95 files changed

+20631
-5726
lines changed

Some content is hidden

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

95 files changed

+20631
-5726
lines changed

scripts/build/options.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os from "os";
44
const ci = ["1", "true"].includes(process.env.CI ?? "");
55

66
const parsed = minimist(process.argv.slice(2), {
7-
boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci", "bundle", "typecheck", "lint", "coverage"],
7+
boolean: ["dirty", "light", "colors", "lkg", "soft", "fix", "failed", "keepFailed", "force", "built", "ci", "bundle", "typecheck", "lint", "coverage", "bail"],
88
string: ["browser", "tests", "break", "host", "reporter", "stackTraceLimit", "timeout", "shards", "shardId"],
99
alias: {
1010
b: "browser",
@@ -66,6 +66,7 @@ export default options;
6666
* @property {boolean} built
6767
* @property {boolean} soft
6868
* @property {boolean} fix
69+
* @property {boolean} bail
6970
* @property {string} browser
7071
* @property {string} tests
7172
* @property {boolean} skipSysTests

scripts/build/tests.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export async function runConsoleTests(runJs, defaultReporter, runInParallel, opt
9898
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
9999
if (!runInParallel) {
100100
args.push(mochaJs);
101+
if (cmdLineOptions.bail) args.push("--bail");
101102
args.push("-R", findUpFile("scripts/failed-tests.cjs"));
102103
args.push("-O", '"reporter=' + reporter + (keepFailed ? ",keepFailed=true" : "") + '"');
103104
if (tests) {

src/compiler/_namespaces/ts.ast.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @internal */
2+
export * from "../ast.js";
3+
/** @internal */
4+
export * from "../factory/astNodeTests.js";
5+
/** @internal */
6+
export * from "../factory/astNodeFactory.js";
7+
/** @internal */
8+
export * from "../factory/astParenthesizerRules.js";

src/compiler/_namespaces/ts.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export * from "../diagnosticInformationMap.generated.js";
1313
export * from "../scanner.js";
1414
export * from "../utilitiesPublic.js";
1515
export * from "../utilities.js";
16-
export * from "../factory/baseNodeFactory.js";
1716
export * from "../factory/parenthesizerRules.js";
1817
export * from "../factory/nodeConverters.js";
1918
export * from "../factory/nodeFactory.js";
@@ -76,3 +75,7 @@ import * as moduleSpecifiers from "./ts.moduleSpecifiers.js";
7675
export { moduleSpecifiers };
7776
import * as performance from "./ts.performance.js";
7877
export { performance };
78+
/** @internal */
79+
import * as ast from "./ts.ast.js";
80+
/** @internal */
81+
export { ast };

src/compiler/ast.ts

+10,422
Large diffs are not rendered by default.

src/compiler/debug.ts

+14-145
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,12 @@ import {
1111
FlowLabel,
1212
FlowNode,
1313
FlowSwitchClause,
14-
getEffectiveModifierFlagsNoCache,
15-
getEmitFlags,
1614
getOwnKeys,
17-
getParseTreeNode,
1815
getSourceFileOfNode,
1916
getSourceTextOfNodeFromSourceFile,
2017
hasProperty,
21-
idText,
2218
IntrinsicType,
23-
isArrayTypeNode,
24-
isBigIntLiteral,
25-
isCallSignatureDeclaration,
26-
isConditionalTypeNode,
27-
isConstructorDeclaration,
28-
isConstructorTypeNode,
29-
isConstructSignatureDeclaration,
3019
isDefaultClause,
31-
isFunctionTypeNode,
32-
isGeneratedIdentifier,
33-
isGetAccessorDeclaration,
34-
isIdentifier,
35-
isImportTypeNode,
36-
isIndexedAccessTypeNode,
37-
isIndexSignatureDeclaration,
38-
isInferTypeNode,
39-
isIntersectionTypeNode,
40-
isLiteralTypeNode,
41-
isMappedTypeNode,
42-
isNamedTupleMember,
43-
isNumericLiteral,
44-
isOptionalTypeNode,
45-
isParameter,
46-
isParenthesizedTypeNode,
47-
isParseTreeNode,
48-
isPrivateIdentifier,
49-
isRestTypeNode,
50-
isSetAccessorDeclaration,
51-
isStringLiteral,
52-
isThisTypeNode,
53-
isTupleTypeNode,
54-
isTypeLiteralNode,
55-
isTypeOperatorNode,
56-
isTypeParameterDeclaration,
57-
isTypePredicateNode,
58-
isTypeQueryNode,
59-
isTypeReferenceNode,
60-
isUnionTypeNode,
6120
LiteralType,
6221
map,
6322
MatchingKeys,
@@ -67,7 +26,6 @@ import {
6726
NodeArray,
6827
NodeCheckFlags,
6928
NodeFlags,
70-
nodeIsSynthesized,
7129
noop,
7230
objectAllocator,
7331
ObjectFlags,
@@ -362,8 +320,7 @@ export namespace Debug {
362320
* This is useful in cases where we switch on `node.kind` and can be reasonably sure the type is accurate, and
363321
* as a result can reduce the number of unnecessary casts.
364322
*/
365-
export function type<T>(value: unknown): asserts value is T;
366-
export function type(_value: unknown) {}
323+
export function type<T>(value: unknown): asserts value is T {}
367324

368325
export function getFunctionName(func: AnyFunction) {
369326
if (typeof func !== "function") {
@@ -607,6 +564,16 @@ export namespace Debug {
607564
}
608565
}
609566

567+
const debugInfoRegistrations: (() => void)[] = [];
568+
export function registerDebugInfo(cb: () => void) {
569+
if (isDebugInfoEnabled) {
570+
cb();
571+
}
572+
else {
573+
debugInfoRegistrations.push(cb);
574+
}
575+
}
576+
610577
/**
611578
* Injects debug information into frequently used types.
612579
*/
@@ -615,8 +582,6 @@ export namespace Debug {
615582

616583
// avoid recomputing
617584
const weakTypeTextMap = new WeakMap<Type, string>();
618-
const weakNodeTextMap = new WeakMap<Node, string>();
619-
620585
// Add additional properties in debug mode to assist with debugging.
621586
Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, {
622587
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
@@ -702,106 +667,10 @@ export namespace Debug {
702667
},
703668
});
704669

705-
const nodeConstructors = [
706-
objectAllocator.getNodeConstructor(),
707-
objectAllocator.getIdentifierConstructor(),
708-
objectAllocator.getTokenConstructor(),
709-
objectAllocator.getSourceFileConstructor(),
710-
];
711-
712-
for (const ctor of nodeConstructors) {
713-
if (!hasProperty(ctor.prototype, "__debugKind")) {
714-
Object.defineProperties(ctor.prototype, {
715-
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
716-
__tsDebuggerDisplay: {
717-
value(this: Node) {
718-
const nodeHeader = isGeneratedIdentifier(this) ? "GeneratedIdentifier" :
719-
isIdentifier(this) ? `Identifier '${idText(this)}'` :
720-
isPrivateIdentifier(this) ? `PrivateIdentifier '${idText(this)}'` :
721-
isStringLiteral(this) ? `StringLiteral ${JSON.stringify(this.text.length < 10 ? this.text : this.text.slice(10) + "...")}` :
722-
isNumericLiteral(this) ? `NumericLiteral ${this.text}` :
723-
isBigIntLiteral(this) ? `BigIntLiteral ${this.text}n` :
724-
isTypeParameterDeclaration(this) ? "TypeParameterDeclaration" :
725-
isParameter(this) ? "ParameterDeclaration" :
726-
isConstructorDeclaration(this) ? "ConstructorDeclaration" :
727-
isGetAccessorDeclaration(this) ? "GetAccessorDeclaration" :
728-
isSetAccessorDeclaration(this) ? "SetAccessorDeclaration" :
729-
isCallSignatureDeclaration(this) ? "CallSignatureDeclaration" :
730-
isConstructSignatureDeclaration(this) ? "ConstructSignatureDeclaration" :
731-
isIndexSignatureDeclaration(this) ? "IndexSignatureDeclaration" :
732-
isTypePredicateNode(this) ? "TypePredicateNode" :
733-
isTypeReferenceNode(this) ? "TypeReferenceNode" :
734-
isFunctionTypeNode(this) ? "FunctionTypeNode" :
735-
isConstructorTypeNode(this) ? "ConstructorTypeNode" :
736-
isTypeQueryNode(this) ? "TypeQueryNode" :
737-
isTypeLiteralNode(this) ? "TypeLiteralNode" :
738-
isArrayTypeNode(this) ? "ArrayTypeNode" :
739-
isTupleTypeNode(this) ? "TupleTypeNode" :
740-
isOptionalTypeNode(this) ? "OptionalTypeNode" :
741-
isRestTypeNode(this) ? "RestTypeNode" :
742-
isUnionTypeNode(this) ? "UnionTypeNode" :
743-
isIntersectionTypeNode(this) ? "IntersectionTypeNode" :
744-
isConditionalTypeNode(this) ? "ConditionalTypeNode" :
745-
isInferTypeNode(this) ? "InferTypeNode" :
746-
isParenthesizedTypeNode(this) ? "ParenthesizedTypeNode" :
747-
isThisTypeNode(this) ? "ThisTypeNode" :
748-
isTypeOperatorNode(this) ? "TypeOperatorNode" :
749-
isIndexedAccessTypeNode(this) ? "IndexedAccessTypeNode" :
750-
isMappedTypeNode(this) ? "MappedTypeNode" :
751-
isLiteralTypeNode(this) ? "LiteralTypeNode" :
752-
isNamedTupleMember(this) ? "NamedTupleMember" :
753-
isImportTypeNode(this) ? "ImportTypeNode" :
754-
formatSyntaxKind(this.kind);
755-
return `${nodeHeader}${this.flags ? ` (${formatNodeFlags(this.flags)})` : ""}`;
756-
},
757-
},
758-
__debugKind: {
759-
get(this: Node) {
760-
return formatSyntaxKind(this.kind);
761-
},
762-
},
763-
__debugNodeFlags: {
764-
get(this: Node) {
765-
return formatNodeFlags(this.flags);
766-
},
767-
},
768-
__debugModifierFlags: {
769-
get(this: Node) {
770-
return formatModifierFlags(getEffectiveModifierFlagsNoCache(this));
771-
},
772-
},
773-
__debugTransformFlags: {
774-
get(this: Node) {
775-
return formatTransformFlags(this.transformFlags);
776-
},
777-
},
778-
__debugIsParseTreeNode: {
779-
get(this: Node) {
780-
return isParseTreeNode(this);
781-
},
782-
},
783-
__debugEmitFlags: {
784-
get(this: Node) {
785-
return formatEmitFlags(getEmitFlags(this));
786-
},
787-
},
788-
__debugGetText: {
789-
value(this: Node, includeTrivia?: boolean) {
790-
if (nodeIsSynthesized(this)) return "";
791-
// avoid recomputing
792-
let text = weakNodeTextMap.get(this);
793-
if (text === undefined) {
794-
const parseNode = getParseTreeNode(this);
795-
const sourceFile = parseNode && getSourceFileOfNode(parseNode);
796-
text = sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : "";
797-
weakNodeTextMap.set(this, text);
798-
}
799-
return text;
800-
},
801-
},
802-
});
803-
}
670+
for (const cb of debugInfoRegistrations) {
671+
cb();
804672
}
673+
debugInfoRegistrations.length = 0;
805674

806675
isDebugInfoEnabled = true;
807676
}

0 commit comments

Comments
 (0)