Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
c3faf0f
Added visitor API
rbuckton Feb 4, 2016
3855261
removed unused function
rbuckton Feb 4, 2016
cadda66
Adds transform flags aggregation to binder and visitor
rbuckton Feb 4, 2016
f8e574f
Added ArrayKind, moved createNode, changed JSDocParsing tests to use …
rbuckton Feb 4, 2016
8bf176a
Cleanup and reorganization of node tests
rbuckton Feb 5, 2016
ba9181c
Merge branch 'transforms-visitor' into transforms-flags
rbuckton Feb 5, 2016
1e35593
Adds the transformFiles API
rbuckton Feb 5, 2016
b3e9d26
Moved createNode back to parser, added local createNode to factory
rbuckton Feb 8, 2016
34489a4
Merge branch 'transforms-visitor' into transforms-flags
rbuckton Feb 8, 2016
cbb910a
Merge branch 'transforms-flags' into transforms-transformer
rbuckton Feb 8, 2016
af24b16
PR Feedback
rbuckton Feb 9, 2016
1a0b877
Merge branch 'transforms-visitor' into transforms-flags
rbuckton Feb 9, 2016
51dd27a
Moved TreansformFlags assertions after markers
rbuckton Feb 9, 2016
6fa4002
Merge branch 'transforms-flags' into transforms-transformer
rbuckton Feb 9, 2016
0f2bbb1
Moved LexicalEnvironment to types.ts, minor fixes
rbuckton Feb 9, 2016
6b381ec
Added printer
rbuckton Feb 9, 2016
fb19e81
Fixed linter error
rbuckton Feb 9, 2016
e545f1b
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 9, 2016
49d2d93
Adds destructuring logic and placeholders for each transformer.
rbuckton Feb 9, 2016
f948b14
Adds the TypeScript transformer
rbuckton Feb 12, 2016
387b30c
Some cleanup and reorganization
rbuckton Feb 12, 2016
4577441
Merge branch 'transforms-visitor' into transforms-flags
rbuckton Feb 12, 2016
319ff61
PR Feedback
rbuckton Feb 12, 2016
ceae78b
Merge branch 'transforms-flags' into transforms-transformer
rbuckton Feb 12, 2016
f8ed021
PR feedback and cleanup
rbuckton Feb 13, 2016
ab811f9
Updates to TransformationContext and transformer.ts
rbuckton Feb 13, 2016
c634a36
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 13, 2016
0f16e68
PR Feedback
rbuckton Feb 17, 2016
8ec3932
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 17, 2016
357171f
PR feedback, switched to getEmitScriptTarget/getEmitModuleKind
rbuckton Feb 17, 2016
c4dc2ae
Merge branch 'transforms-transformer' into transforms-transformer-ts
rbuckton Feb 17, 2016
6c0551f
Adds initial jsx transformer
rbuckton Feb 17, 2016
1ceb02a
Added initial ES7 transformer
rbuckton Feb 17, 2016
dd2dc78
Enables source maps for exceptions thrown in the compiler (when avail…
rbuckton Feb 20, 2016
c759b63
Adds ES6 transformer
rbuckton Feb 20, 2016
39628d7
Added CommonJS/AMD/UMD module transformer
rbuckton Feb 20, 2016
5564537
Added initial SystemJS transformer.
rbuckton Feb 22, 2016
ad64877
Merged some changes from other branches.
rbuckton Feb 22, 2016
ab8e83e
Merge branch 'transforms-visitor' into transforms-flags
rbuckton Feb 22, 2016
cd7c229
Merged some changes from other branches.
rbuckton Feb 22, 2016
024eff1
Merge branch 'transforms-flags' into transforms-transformer
rbuckton Feb 22, 2016
11d54ba
Merged some changes from other branches.
rbuckton Feb 22, 2016
2ab8877
Fix for new linter warning
rbuckton Feb 22, 2016
8e0d28e
Merge branch 'transforms-flags' into transforms-transformer
rbuckton Feb 22, 2016
80f89a1
PR feedback
rbuckton Feb 22, 2016
7d72c18
Merge branch 'transforms-flags' into transforms-transformer
rbuckton Feb 22, 2016
90a317f
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 22, 2016
6d27336
Merged some changes from other branches.
rbuckton Feb 23, 2016
f52a30b
Merged some changes from other branches.
rbuckton Feb 23, 2016
efa5353
Fix new linter warning.
rbuckton Feb 23, 2016
64e7aa8
PR Feedback.
rbuckton Feb 23, 2016
0a325ee
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
3d8cb51
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 23, 2016
0145009
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Feb 23, 2016
dc0b043
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Feb 23, 2016
0b64048
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Feb 23, 2016
f3179da
Fixed issue with test dependencies
rbuckton Feb 23, 2016
617e511
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
61fe61b
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
c166a2d
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 23, 2016
5b7bd63
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Feb 23, 2016
6d111e3
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Feb 23, 2016
4a81dde
Fixed issue with smartindenter
rbuckton Feb 23, 2016
2e47e2e
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
e5cd8fe
Added temporary compat flag to control emit output to fix tests
rbuckton Feb 23, 2016
b3adade
PR Feedback
rbuckton Feb 23, 2016
61f3ba6
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
ad314b0
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
0937cec
Added additional auto-parenthesizing to visitor.
rbuckton Feb 23, 2016
98ab964
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
52c62d0
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
f484ff4
Reenabled transforms.
rbuckton Feb 23, 2016
635347e
Fixed typo in visitEachChild
rbuckton Feb 23, 2016
9871d3b
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
de9866f
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
02b85f8
PR feedback
rbuckton Feb 23, 2016
f92c24b
Removed unused liftNode function
rbuckton Feb 23, 2016
40b61fb
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
4f03b31
Updated lift behavior
rbuckton Feb 23, 2016
75b2181
Merge branch 'transforms-transformer' into transforms-printer
rbuckton Feb 23, 2016
951ce55
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 23, 2016
08036b7
Fixed linter warnings, added comments and minor cleanup.
rbuckton Feb 24, 2016
608822d
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 24, 2016
c9f5253
Fixed linter warnings
rbuckton Feb 24, 2016
25f4102
Reverted change to emitter to force use of printFiles
rbuckton Feb 24, 2016
cde3b34
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Feb 24, 2016
5a9b131
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Feb 24, 2016
78dfab8
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Feb 24, 2016
0d8e152
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Feb 24, 2016
72bfd2f
Fixed linter warnings.
rbuckton Feb 24, 2016
cd2cf7d
PR Feedback and defer makeUniqueName/getGeneratedNameForNode to printer.
rbuckton Feb 29, 2016
b1d8828
Remove transformCompatibleEmit flag and make it the default.
rbuckton Feb 29, 2016
8e5e5f8
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Feb 29, 2016
359875b
PR Feedback
rbuckton Feb 29, 2016
fe7ad5f
Minor tweaks to naming
rbuckton Feb 29, 2016
a0dbe76
PR Feedback
rbuckton Mar 1, 2016
a7f9cda
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Mar 1, 2016
7d05ba2
Fixed visitJsxText, plus PR Feedback
rbuckton Mar 1, 2016
186f5c8
PR Feedback
rbuckton Mar 1, 2016
2c9cd2e
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Mar 1, 2016
88e1772
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Mar 1, 2016
30433c2
ES6 cleanup
rbuckton Mar 2, 2016
2d2709f
Fixed typo in visitCallExpression
rbuckton Mar 2, 2016
70cbb9b
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Mar 2, 2016
ebb4764
Switch from onBefore/onAfterEmitNode to onEmitNode
rbuckton Mar 2, 2016
e66e51d
Merge branch 'transforms-printer' into transforms-transformer-ts
rbuckton Mar 2, 2016
8b35af4
Switched to onEmitNode
rbuckton Mar 2, 2016
1fdaf74
Merge branch 'transforms-transformer-ts' into transforms-transformer-jsx
rbuckton Mar 2, 2016
593fbd4
Merge branch 'transforms-transformer-jsx' into transforms-transformer…
rbuckton Mar 2, 2016
7b28b48
Merge branch 'transforms-transformer-es7' into transforms-transformer…
rbuckton Mar 2, 2016
1c73818
Switched to onEmitNode
rbuckton Mar 2, 2016
c4a75ba
Merge branch 'transforms-transformer-es6' into transforms-transformer…
rbuckton Mar 2, 2016
72eebdb
Switched to onEmitNode
rbuckton Mar 2, 2016
1cf183b
Fixed invalid assertion in ts transformer
rbuckton Mar 4, 2016
d89e21a
General fixes and cleanup
rbuckton Mar 8, 2016
5b8cf96
Moved modifier related flags to separate enum
rbuckton Mar 10, 2016
99e6ad8
Removed ModifiersArray
rbuckton Mar 10, 2016
47cdfbe
Add support for array return values from visitors
rbuckton Mar 10, 2016
2699bf9
Removed NodeArrayNode in favor of arrays
rbuckton Mar 10, 2016
94018a1
cleaned up assertions and removed flattenNodes.
rbuckton Mar 10, 2016
ad0dd4e
Fixed perf issue in binder, plus PR feedback
rbuckton Mar 18, 2016
44ca7d4
Updated baselines
rbuckton Mar 18, 2016
ae7843d
PR Feedback
rbuckton Mar 18, 2016
3c5f170
Merge pull request #7206 from Microsoft/transforms-transformer-module
rbuckton Mar 18, 2016
07a3d18
Merge pull request #7194 from Microsoft/transforms-transformer-es6
rbuckton Mar 18, 2016
cc00f4c
Merge pull request #7193 from Microsoft/transforms-transformer-es7
rbuckton Mar 18, 2016
829a9df
Merge pull request #7192 from Microsoft/transforms-transformer-jsx
rbuckton Mar 18, 2016
ca9148e
Merge pull request #7191 from Microsoft/transforms-transformer-ts
rbuckton Mar 18, 2016
85ae53d
Merge pull request #6987 from Microsoft/transforms-printer
rbuckton Mar 18, 2016
a212e2b
Merge pull request #6986 from Microsoft/transforms-transformer
rbuckton Mar 18, 2016
f9cb493
Merge pull request #6983 from Microsoft/transforms-flags
rbuckton Mar 18, 2016
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
4 changes: 4 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ var compilerSources = [
"utilities.ts",
"binder.ts",
"checker.ts",
"factory.ts",
"visitor.ts",
"sourcemap.ts",
"declarationEmitter.ts",
"emitter.ts",
Expand All @@ -60,6 +62,8 @@ var servicesSources = [
"utilities.ts",
"binder.ts",
"checker.ts",
"factory.ts",
"visitor.ts",
"sourcemap.ts",
"declarationEmitter.ts",
"emitter.ts",
Expand Down
37 changes: 33 additions & 4 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

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 every here.

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) {
Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would cast initial upfront like so:

let result = <U>initial;
if (arguments.length <= 2) {
  ...

This gets rid of the else as well as the casts elsewhere in the function too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigning result to initial to start is an unnecessary extra assignment in some cases. If I change the signature of the function, I can also avoid all of the casts (though either case has no impact on actual runtime performance):

    export function reduceLeft<T, U>(array: T[], f: (a: U, x: T) => U, initial: U): U;
    export function reduceLeft<T>(array: T[], f: (a: T, x: T) => T): T;
    export function reduceLeft<T>(array: T[], f: (a: T, x: T) => T, initial?: T): T {
      ...
    }

if (arguments.length <= 2) {
result = array[pos];
pos++;
}
else {
result = initial;
}
while (pos < count) {
result = f(<U>result, array[pos]);
pos++;
Expand All @@ -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--;
Expand Down
56 changes: 56 additions & 0 deletions src/compiler/factory.ts
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you feed NodeArrayNode<T> as a type argument instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would end up being createNodeArray<T | NodeArrayNode<T>, NodeArrayNode<T>>(elements)), which isn't as clear.

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;
}
}
2 changes: 2 additions & 0 deletions src/compiler/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"utilities.ts",
"binder.ts",
"checker.ts",
"factory.ts",
"visitor.ts",
"emitter.ts",
"program.ts",
"commandLineParser.ts",
Expand Down
12 changes: 10 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ namespace ts {

// Synthesized list
SyntaxList,
NodeArrayNode,
// Enum value count
Count,
// Markers
Expand Down Expand Up @@ -444,7 +445,8 @@ namespace ts {
decorators?: NodeArray<Decorator>; // Array of decorators (in document order)
modifiers?: ModifiersArray; // Array of modifiers
/* @internal */ id?: number; // Unique id (used to look up NodeLinks)
parent?: Node; // Parent node (initialized by binding
parent?: Node; // Parent node (initialized by binding)
/* @internal */ original?: Node; // The original node if this is an updated node.
/* @internal */ jsDocComment?: JSDocComment; // JSDoc for the node, if it has any. Only for .js files.
/* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding)
/* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding)
Expand All @@ -456,6 +458,10 @@ namespace ts {
hasTrailingComma?: boolean;
}

// @kind(SyntaxKind.NodeArrayNode)
export interface NodeArrayNode<T> extends Node, NodeArray<T | NodeArrayNode<T>> {
}

export interface ModifiersArray extends NodeArray<Modifier> {
flags: number;
}
Expand Down Expand Up @@ -1287,13 +1293,15 @@ namespace ts {
statements: NodeArray<Statement>;
}

export type ModuleReference = EntityName | ExternalModuleReference;

// @kind(SyntaxKind.ImportEqualsDeclaration)
export interface ImportEqualsDeclaration extends DeclarationStatement {
name: Identifier;

// 'EntityName' for an internal module reference, 'ExternalModuleReference' for an external
// module reference.
moduleReference: EntityName | ExternalModuleReference;
moduleReference: ModuleReference;
}

// @kind(SyntaxKind.ExternalModuleReference)
Expand Down
Loading