mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 15:44:16 -06:00
Removed NodeArrayNode in favor of arrays
This commit is contained in:
parent
47cdfbe55c
commit
2699bf923b
@ -102,12 +102,6 @@ namespace ts {
|
||||
return clone;
|
||||
}
|
||||
|
||||
export function createNodeArrayNode<T extends Node>(elements: T[]): NodeArrayNode<T> {
|
||||
const node = <NodeArrayNode<T>>createSynthesizedNode(SyntaxKind.NodeArrayNode);
|
||||
node.nodes = createNodeArray(elements);
|
||||
return node;
|
||||
}
|
||||
|
||||
// Literals
|
||||
|
||||
export function createLiteral(value: string, location?: TextRange): StringLiteral;
|
||||
|
||||
@ -1047,9 +1047,7 @@ namespace ts {
|
||||
// If we are here it is because the name contains a binding pattern.
|
||||
Debug.assert(isBindingPattern(node.name));
|
||||
|
||||
return createNodeArrayNode(
|
||||
flattenVariableDestructuring(node, /*value*/ undefined, visitor)
|
||||
);
|
||||
return flattenVariableDestructuring(node, /*value*/ undefined, visitor);
|
||||
}
|
||||
|
||||
function visitLabeledStatement(node: LabeledStatement) {
|
||||
|
||||
@ -281,7 +281,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
addExportImportAssignments(statements, node);
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@ -329,7 +329,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
addExportImportAssignments(statements, node);
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@ -370,7 +370,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
else {
|
||||
// export * from "mod";
|
||||
@ -395,7 +395,7 @@ namespace ts {
|
||||
if (!node.isExportEquals && resolver.isValueAliasDeclaration(node)) {
|
||||
const statements: Statement[] = [];
|
||||
addExportDefault(statements, node.expression, /*location*/ node);
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@ -540,7 +540,7 @@ namespace ts {
|
||||
/*location*/ node
|
||||
);
|
||||
}
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
function visitClassDeclaration(node: ClassDeclaration): OneOrMany<Statement> {
|
||||
@ -580,7 +580,7 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
function substituteExpression(node: Expression) {
|
||||
|
||||
@ -506,7 +506,7 @@ namespace ts {
|
||||
if (!node.moduleSpecifier) {
|
||||
const statements: Statement[] = [];
|
||||
addNodes(statements, map(node.exportClause.elements, visitExportSpecifier));
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@ -648,7 +648,7 @@ namespace ts {
|
||||
addNode(statements, createDeclarationExport(node));
|
||||
}
|
||||
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -408,7 +408,7 @@ namespace ts {
|
||||
*
|
||||
* @param node The node to transform.
|
||||
*/
|
||||
function visitClassDeclaration(node: ClassDeclaration): NodeArrayNode<Statement> {
|
||||
function visitClassDeclaration(node: ClassDeclaration): OneOrMany<Statement> {
|
||||
const staticProperties = getInitializedProperties(node, /*isStatic*/ true);
|
||||
const hasExtendsClause = getClassExtendsHeritageClauseElement(node) !== undefined;
|
||||
|
||||
@ -471,7 +471,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1870,10 +1870,10 @@ namespace ts {
|
||||
);
|
||||
|
||||
if (isNamespaceExport(node)) {
|
||||
return createNodeArrayNode([
|
||||
return [
|
||||
func,
|
||||
createNamespaceExport(getSynthesizedClone(node.name), getSynthesizedClone(node.name))
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
return func;
|
||||
@ -2150,7 +2150,7 @@ namespace ts {
|
||||
*
|
||||
* @param node The enum declaration node.
|
||||
*/
|
||||
function visitEnumDeclaration(node: EnumDeclaration) {
|
||||
function visitEnumDeclaration(node: EnumDeclaration): OneOrMany<Statement> {
|
||||
if (shouldElideEnumDeclaration(node)) {
|
||||
return undefined;
|
||||
}
|
||||
@ -2215,7 +2215,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
currentNamespaceLocalName = savedCurrentNamespaceLocalName;
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2362,7 +2362,7 @@ namespace ts {
|
||||
*
|
||||
* @param node The module declaration node.
|
||||
*/
|
||||
function visitModuleDeclaration(node: ModuleDeclaration) {
|
||||
function visitModuleDeclaration(node: ModuleDeclaration): OneOrMany<Statement> {
|
||||
if (shouldElideModuleDeclaration(node)) {
|
||||
return undefined;
|
||||
}
|
||||
@ -2435,7 +2435,7 @@ namespace ts {
|
||||
);
|
||||
|
||||
currentNamespaceLocalName = savedCurrentNamespaceLocalName;
|
||||
return createNodeArrayNode(statements);
|
||||
return statements;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -342,7 +342,7 @@ namespace ts {
|
||||
|
||||
// Synthesized list
|
||||
SyntaxList,
|
||||
NodeArrayNode,
|
||||
|
||||
// Enum value count
|
||||
Count,
|
||||
// Markers
|
||||
@ -469,19 +469,6 @@ namespace ts {
|
||||
hasTrailingComma?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A NodeArrayNode is a transient node used during transformations to indicate that more than
|
||||
* one node will substitute a single node in the source. When the source is a NodeArray (as
|
||||
* part of a call to `visitNodes`), the nodes of a NodeArrayNode will be spread into the
|
||||
* result array. When the source is a Node (as part of a call to `visitNode`), the NodeArrayNode
|
||||
* must be converted into a compatible node via the `lift` callback.
|
||||
*/
|
||||
/* @internal */
|
||||
// @kind(SyntaxKind.NodeArrayNode)
|
||||
export interface NodeArrayNode<T extends Node> extends Node {
|
||||
nodes: NodeArray<T>;
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.AbstractKeyword)
|
||||
// @kind(SyntaxKind.AsyncKeyword)
|
||||
// @kind(SyntaxKind.ConstKeyword)
|
||||
|
||||
@ -3471,13 +3471,6 @@ namespace ts {
|
||||
export function isEnumMember(node: Node): node is EnumMember {
|
||||
return node.kind === SyntaxKind.EnumMember;
|
||||
}
|
||||
|
||||
|
||||
// Synthesized
|
||||
|
||||
export function isNodeArrayNode<T extends Node>(node: Node): node is NodeArrayNode<T> {
|
||||
return node.kind === SyntaxKind.NodeArrayNode;
|
||||
}
|
||||
}
|
||||
|
||||
namespace ts {
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
export type OneOrMany<T extends Node> = T | NodeArrayNode<T> | T[];
|
||||
export type OneOrMany<T extends Node> = T | T[];
|
||||
|
||||
/**
|
||||
* Describes an edge of a Node, used when traversing a syntax tree.
|
||||
@ -512,9 +512,6 @@ namespace ts {
|
||||
if (isArray(visited)) {
|
||||
visitedNode = (lift || extractSingleNode)(<NodeArray<Node>>visited);
|
||||
}
|
||||
else if (isNodeArrayNode(visited)) {
|
||||
visitedNode = (lift || extractSingleNode)((<NodeArrayNode<Node>>visited).nodes);
|
||||
}
|
||||
else {
|
||||
visitedNode = visited;
|
||||
}
|
||||
@ -668,7 +665,7 @@ namespace ts {
|
||||
if (nodes) {
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
const node = nodes[i];
|
||||
if (result || node === undefined || isArray(node) || isNodeArrayNode(node)) {
|
||||
if (result || node === undefined || isArray(node)) {
|
||||
if (!result) {
|
||||
result = <T[]>nodes.slice(0, i);
|
||||
}
|
||||
@ -705,9 +702,6 @@ namespace ts {
|
||||
if (isArray(from)) {
|
||||
addNodesWorker(to, from, startOnNewLine, test, parenthesize, parentNode, isVisiting);
|
||||
}
|
||||
else if (isNodeArrayNode(from)) {
|
||||
addNodesWorker(to, from.nodes, startOnNewLine, test, parenthesize, parentNode, isVisiting);
|
||||
}
|
||||
else {
|
||||
const node = parenthesize !== undefined ? parenthesize(from, parentNode) : from;
|
||||
Debug.assert(test === undefined || test(node), "Wrong node type after visit.", () => `Node ${formatSyntaxKind(node.kind)} did not pass test ${(<any>test).name}.`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user