mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Remove TreeStateObserver
This commit is contained in:
parent
96e4c24415
commit
67aa311108
File diff suppressed because it is too large
Load Diff
@ -69,6 +69,18 @@ namespace ts {
|
||||
return node.kind === SyntaxKind.ImportKeyword;
|
||||
}
|
||||
|
||||
export function isCommaToken(node: Node): node is Token<SyntaxKind.CommaToken> {
|
||||
return node.kind === SyntaxKind.CommaToken;
|
||||
}
|
||||
|
||||
export function isQuestionToken(node: Node): node is Token<SyntaxKind.QuestionToken> {
|
||||
return node.kind === SyntaxKind.QuestionToken;
|
||||
}
|
||||
|
||||
export function isExclamationToken(node: Node): node is Token<SyntaxKind.ExclamationToken> {
|
||||
return node.kind === SyntaxKind.ExclamationToken;
|
||||
}
|
||||
|
||||
// Signature elements
|
||||
|
||||
export function isTypeParameterDeclaration(node: Node): node is TypeParameterDeclaration {
|
||||
|
||||
@ -141,23 +141,7 @@ namespace ts {
|
||||
createBaseNode: kind => countNode(new NodeConstructor(kind, /*pos*/ 0, /*end*/ 0))
|
||||
};
|
||||
|
||||
const factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters, baseNodeFactory, {
|
||||
onSetChild(parent, child) {
|
||||
if (setParentNodes) {
|
||||
setParent(child, parent);
|
||||
}
|
||||
},
|
||||
onSetChildren(parent, children) {
|
||||
if (setParentNodes) {
|
||||
setEachParent(children, parent);
|
||||
}
|
||||
},
|
||||
onFinishNode(node) {
|
||||
if (setParentNodes && hasJSDocNodes(node)) {
|
||||
setEachParent(node.jsDoc, node);
|
||||
}
|
||||
}
|
||||
});
|
||||
const factory = createNodeFactory(NodeFactoryFlags.NoParenthesizerRules | NodeFactoryFlags.NoNodeConverters, baseNodeFactory);
|
||||
|
||||
let fileName: string;
|
||||
let sourceFlags: NodeFlags;
|
||||
@ -174,7 +158,6 @@ namespace ts {
|
||||
let identifiers: Map<string>;
|
||||
let privateIdentifiers: Map<string>;
|
||||
let identifierCount: number;
|
||||
let setParentNodes: boolean;
|
||||
|
||||
let parsingContext: ParsingContext;
|
||||
|
||||
@ -271,10 +254,14 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind, setParentNodes);
|
||||
initializeState(fileName, sourceText, languageVersion, syntaxCursor, scriptKind);
|
||||
|
||||
const result = parseSourceFileWorker(languageVersion, setParentNodes, scriptKind);
|
||||
|
||||
if (setParentNodes) {
|
||||
fixupParentReferences(result);
|
||||
}
|
||||
|
||||
clearState();
|
||||
|
||||
return result;
|
||||
@ -282,7 +269,7 @@ namespace ts {
|
||||
|
||||
export function parseIsolatedEntityName(content: string, languageVersion: ScriptTarget): EntityName | undefined {
|
||||
// Choice of `isDeclarationFile` should be arbitrary
|
||||
initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS, /*setParentNodes*/ false);
|
||||
initializeState("", content, languageVersion, /*syntaxCursor*/ undefined, ScriptKind.JS);
|
||||
// Prime the scanner.
|
||||
nextToken();
|
||||
const entityName = parseEntityName(/*allowReservedWords*/ true);
|
||||
@ -292,7 +279,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function parseJsonText(fileName: string, sourceText: string, languageVersion: ScriptTarget = ScriptTarget.ES2015, syntaxCursor?: IncrementalParser.SyntaxCursor, setParentNodes = false): JsonSourceFile {
|
||||
initializeState(fileName, sourceText, languageVersion, syntaxCursor, ScriptKind.JSON, setParentNodes);
|
||||
initializeState(fileName, sourceText, languageVersion, syntaxCursor, ScriptKind.JSON);
|
||||
sourceFlags = contextFlags;
|
||||
|
||||
// Prime the scanner.
|
||||
@ -360,15 +347,13 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
function initializeState(_fileName: string, _sourceText: string, _languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor | undefined, _scriptKind: ScriptKind, _setParentNodes: boolean) {
|
||||
function initializeState(_fileName: string, _sourceText: string, _languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor | undefined, _scriptKind: ScriptKind) {
|
||||
NodeConstructor = objectAllocator.getNodeConstructor();
|
||||
TokenConstructor = objectAllocator.getTokenConstructor();
|
||||
IdentifierConstructor = objectAllocator.getIdentifierConstructor();
|
||||
PrivateIdentifierConstructor = objectAllocator.getPrivateIdentifierConstructor();
|
||||
SourceFileConstructor = objectAllocator.getSourceFileConstructor();
|
||||
|
||||
setParentNodes = _setParentNodes;
|
||||
|
||||
fileName = normalizePath(_fileName);
|
||||
sourceText = _sourceText;
|
||||
languageVersion = _languageVersion;
|
||||
@ -412,7 +397,6 @@ namespace ts {
|
||||
scanner.setOnError(undefined);
|
||||
|
||||
// Clear any data. We don't want to accidentally hold onto it for too long.
|
||||
setParentNodes = false;
|
||||
sourceText = undefined!;
|
||||
languageVersion = undefined!;
|
||||
syntaxCursor = undefined;
|
||||
@ -6334,7 +6318,7 @@ namespace ts {
|
||||
|
||||
export namespace JSDocParser {
|
||||
export function parseJSDocTypeExpressionForTests(content: string, start: number | undefined, length: number | undefined): { jsDocTypeExpression: JSDocTypeExpression, diagnostics: Diagnostic[] } | undefined {
|
||||
initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS, /*setParentNodes*/ false);
|
||||
initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS);
|
||||
factory.setSkipTransformationFlags(/*value*/ true); // reset in 'clearState'
|
||||
scanner.setText(content, start, length);
|
||||
currentToken = scanner.scan();
|
||||
@ -6368,7 +6352,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function parseIsolatedJSDocComment(content: string, start: number | undefined, length: number | undefined): { jsDoc: JSDoc, diagnostics: Diagnostic[] } | undefined {
|
||||
initializeState("", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS, /*setParentNodes*/ false);
|
||||
initializeState("", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS);
|
||||
factory.setSkipTransformationFlags(/*value*/ true); // reset in 'clearState'
|
||||
const jsDoc = doInsideOfContext(NodeFlags.JSDoc, () => parseJSDocCommentWorker(start, length));
|
||||
|
||||
|
||||
@ -6229,11 +6229,8 @@ namespace ts {
|
||||
ContainsHoistedDeclarationOrCompletion = 1 << 20,
|
||||
ContainsDynamicImport = 1 << 21,
|
||||
ContainsClassFields = 1 << 22,
|
||||
|
||||
// Please leave this as 1 << 29.
|
||||
// It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system.
|
||||
// It is a good reminder of how much room we have left
|
||||
HasComputedFlags = 1 << 29, // Transform flags have been computed.
|
||||
// NOTE: Please do not add flags with a value higher than 1 << 29, as that is the maximum bit we can set
|
||||
// before we outgrow the size of a v8 small integer (SMI) on an x86 system.
|
||||
|
||||
// Assertions
|
||||
// - Bitmasks that are used to assert facts about the syntax of a node and its subtree.
|
||||
@ -6252,7 +6249,7 @@ namespace ts {
|
||||
// Scope Exclusions
|
||||
// - Bitmasks that exclude flags from propagating out of a specific context
|
||||
// into the subtree flags of their container.
|
||||
OuterExpressionExcludes = HasComputedFlags,
|
||||
OuterExpressionExcludes = None,
|
||||
PropertyAccessExcludes = OuterExpressionExcludes,
|
||||
NodeExcludes = PropertyAccessExcludes,
|
||||
ArrowFunctionExcludes = NodeExcludes | ContainsTypeScriptClassSyntax | ContainsBlockScopedBinding | ContainsYield | ContainsAwait | ContainsHoistedDeclarationOrCompletion | ContainsBindingPattern | ContainsObjectRestOrSpread,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user