-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Adds the visitor API foundation for tree transformations. #6892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
c3faf0f
3855261
cadda66
f8e574f
8bf176a
ba9181c
1e35593
b3e9d26
34489a4
cbb910a
af24b16
1a0b877
51dd27a
6fa4002
0f2bbb1
6b381ec
fb19e81
e545f1b
49d2d93
f948b14
387b30c
4577441
319ff61
ceae78b
f8ed021
ab811f9
c634a36
0f16e68
8ec3932
357171f
c4dc2ae
6c0551f
1ceb02a
dd2dc78
c759b63
39628d7
5564537
ad64877
ab8e83e
cd7c229
024eff1
11d54ba
2ab8877
8e0d28e
80f89a1
7d72c18
90a317f
6d27336
f52a30b
efa5353
64e7aa8
0a325ee
3d8cb51
0145009
dc0b043
0b64048
f3179da
617e511
61fe61b
c166a2d
5b7bd63
6d111e3
4a81dde
2e47e2e
e5cd8fe
b3adade
61f3ba6
ad314b0
0937cec
98ab964
52c62d0
f484ff4
635347e
9871d3b
de9866f
02b85f8
f92c24b
40b61fb
4f03b31
75b2181
951ce55
08036b7
608822d
c9f5253
25f4102
cde3b34
5a9b131
78dfab8
0d8e152
72bfd2f
cd2cf7d
b1d8828
8e5e5f8
359875b
fe7ad5f
a0dbe76
a7f9cda
7d05ba2
186f5c8
2c9cd2e
88e1772
30433c2
2d2709f
70cbb9b
ebb4764
e66e51d
8b35af4
1fdaf74
593fbd4
7b28b48
1c73818
c4a75ba
72eebdb
1cf183b
d89e21a
5b8cf96
99e6ad8
47cdfbe
2699bf9
94018a1
ad0dd4e
44ca7d4
ae7843d
3c5f170
07a3d18
cc00f4c
829a9df
ca9148e
85ae53d
a212e2b
f9cb493
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,23 @@ namespace ts { | |
| return undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Iterates through `array` by index and performs the callback on each element of array until the callback | ||
| * returns a falsey value, then returns false. | ||
| * If no such value is found, the callback is applied to each element of array and `true` is returned. | ||
| */ | ||
| export function trueForAll<T>(array: T[], callback: (element: T, index: number) => boolean): boolean { | ||
| if (array) { | ||
| for (let i = 0, len = array.length; i < len; i++) { | ||
| if (!callback(array[i], i)) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| export function contains<T>(array: T[], value: T): boolean { | ||
| if (array) { | ||
| for (const v of array) { | ||
|
|
@@ -242,8 +259,14 @@ namespace ts { | |
| const count = array.length; | ||
| if (count > 0) { | ||
| let pos = 0; | ||
| let result = arguments.length <= 2 ? array[pos] : initial; | ||
| pos++; | ||
| let result: T | U; | ||
|
||
| if (arguments.length <= 2) { | ||
| result = array[pos]; | ||
| pos++; | ||
| } | ||
| else { | ||
| result = initial; | ||
| } | ||
| while (pos < count) { | ||
| result = f(<U>result, array[pos]); | ||
| pos++; | ||
|
|
@@ -260,8 +283,14 @@ namespace ts { | |
| if (array) { | ||
| let pos = array.length - 1; | ||
| if (pos >= 0) { | ||
| let result = arguments.length <= 2 ? array[pos] : initial; | ||
| pos--; | ||
| let result: T | U; | ||
| if (arguments.length <= 2) { | ||
| result = array[pos]; | ||
| pos--; | ||
| } | ||
| else { | ||
| result = initial; | ||
| } | ||
| while (pos >= 0) { | ||
| result = f(<U>result, array[pos]); | ||
| pos--; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /// <reference path="types.ts"/> | ||
| /// <reference path="utilities.ts"/> | ||
| /* @internal */ | ||
| namespace ts { | ||
| export function createNodeArray<T extends Node>(elements?: T[], location?: TextRange): NodeArray<T>; | ||
| export function createNodeArray<T extends Node, TArray extends NodeArray<T>>(elements: TArray, location?: TextRange): TArray; | ||
| export function createNodeArray<T extends Node, TArray extends NodeArray<T>>(elements?: T[], location?: TextRange): TArray { | ||
| const array = <TArray>(elements || []); | ||
| if (location) { | ||
| array.pos = location.pos; | ||
| array.end = location.end; | ||
| } | ||
| else if (array.pos === undefined || array.end === undefined) { | ||
| array.pos = -1; | ||
| array.end = -1; | ||
| } | ||
|
|
||
| return array; | ||
| } | ||
|
|
||
| export function createNodeArrayNode<T extends Node>(elements?: (T | NodeArrayNode<T>)[]): NodeArrayNode<T> { | ||
| const array = <NodeArrayNode<T>>createNodeArray(elements); | ||
|
||
| array.kind = SyntaxKind.NodeArrayNode; | ||
| return array; | ||
| } | ||
|
|
||
| export function createReturn(expression?: Expression): ReturnStatement { | ||
| const node = <ReturnStatement>createSynthesizedNode(SyntaxKind.ReturnStatement); | ||
| node.expression = expression; | ||
| return node; | ||
| } | ||
|
|
||
| export function createStatement(expression: Expression): ExpressionStatement { | ||
| const node = <ExpressionStatement>createSynthesizedNode(SyntaxKind.ExpressionStatement); | ||
| node.expression = expression; | ||
| return node; | ||
| } | ||
|
|
||
| export function createVariableStatement(declarationList: VariableDeclarationList): VariableStatement { | ||
| const node = <VariableStatement>createSynthesizedNode(SyntaxKind.VariableStatement); | ||
| node.declarationList = declarationList; | ||
| return node; | ||
| } | ||
|
|
||
| export function createVariableDeclarationList(declarations: VariableDeclaration[]): VariableDeclarationList { | ||
| const node = <VariableDeclarationList>createSynthesizedNode(SyntaxKind.VariableDeclarationList); | ||
| node.declarations = createNodeArray(declarations); | ||
| return node; | ||
| } | ||
|
|
||
| export function createBlock(statements: Statement[]): Block { | ||
| const block = <Block>createSynthesizedNode(SyntaxKind.Block); | ||
| block.statements = createNodeArray(statements); | ||
| return block; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the ES5 name
everyhere.