Skip to content

Commit f6bff93

Browse files
author
James Whitney
committed
Normalise braces, trailing whitespace, and EOL's
1 parent 0d796e7 commit f6bff93

Some content is hidden

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

56 files changed

+218
-251
lines changed

docs/arrow-functions.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
### Arrow Functions
22

3-
Lovingly called the *fat arrow* (because `->` is a thin arrow and `=>` is a fat arrow) and also called a *lambda function* (because of other languages). Another commonly used feature is the fat arrow function `()=>something`. The motivation for a *fat arrow* is:
3+
Lovingly called the *fat arrow* (because `->` is a thin arrow and `=>` is a fat arrow) and also called a *lambda function* (because of other languages). Another commonly used feature is the fat arrow function `()=>something`. The motivation for a *fat arrow* is:
44
1. You don't need to keep typing `function`
55
2. It lexically captures the meaning of `this`
66
2. It lexically captures the meaning of `arguments`
77

8-
For a language that claims to be functional, in JavaScript you tend to be typing `function` quite a lot. The fat arrow makes it simple for you to create a function
8+
For a language that claims to be functional, in JavaScript you tend to be typing `function` quite a lot. The fat arrow makes it simple for you to create a function
99
```ts
1010
var inc = (x)=>x+1;
1111
```
12-
`this` has traditionally been a pain point in JavaScript. As a wise man once said "I hate JavaScript as it tends to lose the meaning of `this` all too easily". Fat arrows fix it by capturing the meaning of `this` from the surrounding context. Consider this pure JavaScript class:
12+
`this` has traditionally been a pain point in JavaScript. As a wise man once said "I hate JavaScript as it tends to lose the meaning of `this` all too easily". Fat arrows fix it by capturing the meaning of `this` from the surrounding context. Consider this pure JavaScript class:
1313

1414
```ts
1515
function Person(age) {
1616
this.age = age
17-
this.growOld = function(){
17+
this.growOld = function() {
1818
this.age++;
1919
}
2020
}
21-
var person = new Person(1);
21+
var person = new Person(1);
2222
setTimeout(person.growOld,1000);
2323

24-
setTimeout(function(){ console.log(person.age); },2000); // 1, should have been 2
24+
setTimeout(function() { console.log(person.age); },2000); // 1, should have been 2
2525
```
26-
If you run this code in the browser `this` within the function is going to point to `window` because `window` is going to be what executes the `growOld` function. Fix is to use an arrow function:
26+
If you run this code in the browser `this` within the function is going to point to `window` because `window` is going to be what executes the `growOld` function. Fix is to use an arrow function:
2727
```ts
2828
function Person(age) {
2929
this.age = age
3030
this.growOld = () => {
3131
this.age++;
3232
}
3333
}
34-
var person = new Person(1);
34+
var person = new Person(1);
3535
setTimeout(person.growOld,1000);
3636

37-
setTimeout(function(){ console.log(person.age); },2000); // 2
37+
setTimeout(function() { console.log(person.age); },2000); // 2
3838
```
39-
The reason why this works is the reference to `this` is captured by the arrow function from outside the function body. This is equivalent to the following JavaScript code (which is what you would write yourself if you didn't have TypeScript):
39+
The reason why this works is the reference to `this` is captured by the arrow function from outside the function body. This is equivalent to the following JavaScript code (which is what you would write yourself if you didn't have TypeScript):
4040
```ts
4141
function Person(age) {
4242
this.age = age
@@ -45,33 +45,33 @@ function Person(age) {
4545
_this.age++; // use the captured this
4646
}
4747
}
48-
var person = new Person(1);
48+
var person = new Person(1);
4949
setTimeout(person.growOld,1000);
5050

51-
setTimeout(function(){ console.log(person.age); },2000); // 2
51+
setTimeout(function() { console.log(person.age); },2000); // 2
5252
```
53-
Note that since you are using TypeScript you can be even sweeter in syntax and combine arrows with classes:
53+
Note that since you are using TypeScript you can be even sweeter in syntax and combine arrows with classes:
5454
```ts
5555
class Person {
56-
constructor(public age:number){}
56+
constructor(public age:number) {}
5757
growOld = () => {
5858
this.age++;
5959
}
6060
}
61-
var person = new Person(1);
61+
var person = new Person(1);
6262
setTimeout(person.growOld,1000);
6363

64-
setTimeout(function(){ console.log(person.age); },2000); // 2
64+
setTimeout(function() { console.log(person.age); },2000); // 2
6565
```
6666

6767
#### Tip: Arrow Function Need
68-
Beyond the terse syntax, you only *need* to use the fat arrow if you are going to give the function to someone else to call. Effectively:
68+
Beyond the terse syntax, you only *need* to use the fat arrow if you are going to give the function to someone else to call. Effectively:
6969
```ts
70-
var growOld = person.growOld;
70+
var growOld = person.growOld;
7171
// Then later someone else calls it:
7272
growOld();
7373
```
74-
If you are going to call it yourself, i.e.
74+
If you are going to call it yourself, i.e.
7575
```ts
7676
person.growOld();
7777
```
@@ -86,7 +86,7 @@ Many libraries do this e.g `jQuery` iterables (one example http://api.jquery.com
8686

8787
```ts
8888
let _self = this;
89-
something.each(function(){
89+
something.each(function() {
9090
console.log(_self); // the lexically scoped value
9191
console.log(this); // the library passed value
9292
});

docs/classes-extensibility.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#### Class extensibility
22

3-
People often add properties to classes from other JavaScript libraries. Here is a simple JavaScript example of this:
3+
People often add properties to classes from other JavaScript libraries. Here is a simple JavaScript example of this:
44

55
```js
66
// Original Library
7-
function Foo{}
7+
function Foo {}
88

9-
// Third party extension to add new member properties
9+
// Third party extension to add new member properties
1010
```

docs/classes-super.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#### `super`
22

3-
Note that if you call `super` on a child class it is redirected to the `prototype` as shown below:
3+
Note that if you call `super` on a child class it is redirected to the `prototype` as shown below:
44

55
```ts
66
class Base {
@@ -11,7 +11,7 @@ class Child extends Base {
1111
log() { super.log() };
1212
}
1313
```
14-
generates:
14+
generates:
1515

1616
```js
1717
var Base = (function () {
@@ -56,8 +56,7 @@ module quz {
5656

5757
class Child extends Base {
5858
// ERROR : only `public` and `protected` methods of base class are accessible via `super`
59-
logWorld() { super.log() };
59+
logWorld() { super.log() };
6060
}
6161
}
6262
```
63-

docs/classes.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ foo.z; // ERROR : protected
9999

100100
// EFFECT ON CHILD CLASSES
101101
class FooChild extends FooBase {
102-
constructor(){
102+
constructor() {
103103
super();
104104
this.x; // okay
105105
this.y; // ERROR: private
@@ -120,18 +120,18 @@ As always these modifiers work for both member properties and member functions.
120120
Having a member in a class and initializing it like below:
121121

122122
```ts
123-
class Foo{
123+
class Foo {
124124
x: number;
125-
constructor(x:number){
125+
constructor(x:number) {
126126
this.x = x;
127127
}
128128
}
129129
```
130130
is such a common pattern that TypeScript provides a shorthand where you can prefix the member with an *access modifier* and it is automatically declared on the class and copied from the constructor. So the previous example can be re-written as (notice `public x:number`):
131131

132132
```ts
133-
class Foo{
134-
constructor(public x:number){
133+
class Foo {
134+
constructor(public x:number) {
135135
}
136136
}
137137
```
@@ -140,9 +140,9 @@ class Foo{
140140
This is a nifty feature supported by TypeScript (from ES7 actually). You can initialize any member of the class outside the class constructor, useful to provide default (notice `members = []`)
141141

142142
```ts
143-
class Foo{
143+
class Foo {
144144
members = []; // Initialize directly
145-
add(x){
145+
add(x) {
146146
this.members.push(x);
147147
}
148148
}

docs/compiler-options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
/*!
55
* License
66
*/
7-
```
7+
```

docs/compiler/ast-tip-children.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function forEachChild<T>(node: Node, cbNode: (node: Node) => T, cbNodeArr
2525
2626
Basically it checks `node.kind` and based on that assumes an interface offered by the `node` and calls the `cbNode` on the children. Note however that this function doesn't call `visitNode` for *all* children (e.g. SyntaxKind.SemicolonToken). If you want *all* the children of a node in the AST just call `.getChildren` member function of the `Node`.
2727
28-
E.g. here is a function that prints the verbose `AST` of a node:
28+
E.g. here is a function that prints the verbose `AST` of a node:
2929
3030
```ts
3131
function printAllChildren(node: ts.Node, depth = 0) {
@@ -35,4 +35,4 @@ function printAllChildren(node: ts.Node, depth = 0) {
3535
}
3636
```
3737
38-
We will see a sample usage of this function when we discuss the parser further.
38+
We will see a sample usage of this function when we discuss the parser further.

docs/compiler/ast-tip-syntaxkind.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### AST Tip: SyntaxKind
22

3-
`SyntaxKind` is defined as a `const enum`, here is a sample:
3+
`SyntaxKind` is defined as a `const enum`, here is a sample:
44

55
```ts
66
export const enum SyntaxKind {
@@ -10,11 +10,10 @@ export const enum SyntaxKind {
1010
// ... LOTS more
1111
```
1212
13-
It's a `const enum` (a concept [we covered previously](../enums.md)) so that it gets *inlined* (e.g. `ts.SyntaxKind.EndOfFileToken` becomes `1`) and we don't get a dereferencing cost when working with AST. However the compiler is compiled with `--preserveConstEnums` compiler flag so that the enum *is still available at runtime*. So in JavaScript you can use `ts.SyntaxKind.EndOfFileToken` if you want. Additionally you can convert these enum members to display strings using the following function:
13+
It's a `const enum` (a concept [we covered previously](../enums.md)) so that it gets *inlined* (e.g. `ts.SyntaxKind.EndOfFileToken` becomes `1`) and we don't get a dereferencing cost when working with AST. However the compiler is compiled with `--preserveConstEnums` compiler flag so that the enum *is still available at runtime*. So in JavaScript you can use `ts.SyntaxKind.EndOfFileToken` if you want. Additionally you can convert these enum members to display strings using the following function:
1414
1515
```ts
1616
export function syntaxKindToName(kind: ts.SyntaxKind) {
1717
return (<any>ts).SyntaxKind[kind];
1818
}
1919
```
20-

docs/compiler/binder-container.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Container
22

3-
An AST node can be a container. This determines the kinds of `SymbolTables` the Node and associated Symbol will have. Container is an abstract concept (i.e. has no associated data structure). The concept is driven by a few things, one being the `ContainerFlags` enum. The function `getContainerFlags` (in `binder.ts`) drives this flag and is presented below:
3+
An AST node can be a container. This determines the kinds of `SymbolTables` the Node and associated Symbol will have. Container is an abstract concept (i.e. has no associated data structure). The concept is driven by a few things, one being the `ContainerFlags` enum. The function `getContainerFlags` (in `binder.ts`) drives this flag and is presented below:
44

55
```ts
66
function getContainerFlags(node: Node): ContainerFlags {
@@ -62,7 +62,7 @@ function getContainerFlags(node: Node): ContainerFlags {
6262
}
6363
```
6464

65-
It is *only* invoked from the binder's `bindChildren` function which sets up a node as a `container` and/or a `blockScopedContainer` depending upon the evaluation of the `getContainerFlags` function. The function `bindChildren` is presented below:
65+
It is *only* invoked from the binder's `bindChildren` function which sets up a node as a `container` and/or a `blockScopedContainer` depending upon the evaluation of the `getContainerFlags` function. The function `bindChildren` is presented below:
6666

6767
```ts
6868
// All container nodes are kept on a linked list in declaration order. This list is used by
@@ -121,4 +121,3 @@ function bindChildren(node: Node) {
121121
```
122122

123123
As you might recall from section on binder functions : `bindChildren` is called from the `bind` function. So we have the recursive bindig setup : `bind` calls `bindChildren` calls `bind` for each child.
124-

docs/compiler/binder-declarations.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Symbols and Declarations
2-
Linking between a `node` and a `symbol` is performed by a few functions. One function that is used to bind the `SourceFile` node to the source file Symbol (in case of an external module) is the `addDeclarationToSymbol` function
2+
Linking between a `node` and a `symbol` is performed by a few functions. One function that is used to bind the `SourceFile` node to the source file Symbol (in case of an external module) is the `addDeclarationToSymbol` function
33

4-
Note : the `Symbol` for an external module source file is setup as `flags : SymbolFlags.ValueModule` and `name: '"' + removeFileExtension(file.fileName) + '"'`).
4+
Note : the `Symbol` for an external module source file is setup as `flags : SymbolFlags.ValueModule` and `name: '"' + removeFileExtension(file.fileName) + '"'`).
55

66
```ts
77
function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolFlags: SymbolFlags) {
@@ -28,8 +28,8 @@ function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolFlags:
2828
}
2929
```
3030

31-
The important linking portions:
32-
* creates a link to the Symbol from the AST node (`node.symbol`).
31+
The important linking portions:
32+
* creates a link to the Symbol from the AST node (`node.symbol`).
3333
* add the node as *one of* the declarations of the Symbol (`symbol.declarations`).
3434

3535
#### Declaration

docs/compiler/binder-diagnostics.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
### Binder Error Reporting
22

3-
Binding errors are added to the sourceFile's list of `bindDiagnostics`.
3+
Binding errors are added to the sourceFile's list of `bindDiagnostics`.
44

5-
An example error detected during binding is the use of `eval` or `arguments` as a variable name in `use strict` scenario. The relevant code is presented in its entirety below (`checkStrictModeEvalOrArguments` is called from multiple places, call stacks originating from `bindWorker` which calls different functions for different node `SyntaxKind`):
5+
An example error detected during binding is the use of `eval` or `arguments` as a variable name in `use strict` scenario. The relevant code is presented in its entirety below (`checkStrictModeEvalOrArguments` is called from multiple places, call stacks originating from `bindWorker` which calls different functions for different node `SyntaxKind`):
66

77
```ts
88
function checkStrictModeEvalOrArguments(contextNode: Node, name: Node) {
@@ -36,4 +36,4 @@ function getStrictModeEvalOrArgumentsMessage(node: Node) {
3636

3737
return Diagnostics.Invalid_use_of_0_in_strict_mode;
3838
}
39-
```
39+
```

docs/compiler/binder-functions.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Basically checks if the `file.locals` is defined, if not it hands over to (a loc
66

77
Note: `locals` is defined on `Node` and is of type `SymbolTable`. Note that `SourceFile` is also a `Node` (in fact a root node in the AST).
88

9-
TIP: local functions are used heavily within the TypeScript compiler. A local function very likely uses variables from the parent function (captured by closure). In the case of `bind` (a local function within `bindSourceFile`) it (or function it calls) will setup the `symbolCount` and `classifiableNames` among others, that are then stored on the returned `SourceFile`.
9+
TIP: local functions are used heavily within the TypeScript compiler. A local function very likely uses variables from the parent function (captured by closure). In the case of `bind` (a local function within `bindSourceFile`) it (or function it calls) will setup the `symbolCount` and `classifiableNames` among others, that are then stored on the returned `SourceFile`.
1010

1111
#### `bind`
1212
Bind takes any `Node` (not just `SourceFile`). First thing it does is assign the `node.parent` (if `parent` variable has been setup ... which again is something the binder does during its processing within the `bindChildren` function), then hands off to `bindWorker` which does the *heavy* lifting. Finally it calls `bindChildren` (a function that simply stores the binder state e.g. current `parent` within its function local vars, then calls `bind` on each child, and then restores the binder state). Now lets look at `bindWorker` which is the more interesting function.
@@ -15,7 +15,7 @@ Bind takes any `Node` (not just `SourceFile`). First thing it does is assign the
1515
This function switches on `node.kind` (of type `SyntaxKind`) and delegates work to the appropriate `bindFoo` function (also defined within `binder.ts`). For example if the `node` is a `SourceFile` it calls (eventually and only if its an external file module) `bindAnonymousDeclaration`
1616

1717
#### `bindFoo` functions
18-
There are few pattern common to `bindFoo` functions as well as some utility functions that these use. One function that is almost always used is the `createSymbol` function. It is presented in its entirety below:
18+
There are few pattern common to `bindFoo` functions as well as some utility functions that these use. One function that is almost always used is the `createSymbol` function. It is presented in its entirety below:
1919

2020
```ts
2121
function createSymbol(flags: SymbolFlags, name: string): Symbol {

docs/compiler/binder-symbolflags.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Symbols have `SymbolFlags`. Below we eplain the meaning of the important ones
33

44
#### ValueModule
5-
`ValueModule // Instantiated module` is the SymbolFlag used for `SourceFile` if it an external module.
5+
`ValueModule // Instantiated module` is the SymbolFlag used for `SourceFile` if it an external module.

docs/compiler/checker-global.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ forEach(host.getSourceFiles(), file => {
1010
});
1111
```
1212

13-
Which basically merges all the `global` symbols into the `let globals: SymbolTable = {};` (in `createTypeChecker`) SymbolTable. `mergeSymbolTable` primarily calls `mergeSymbol`.
13+
Which basically merges all the `global` symbols into the `let globals: SymbolTable = {};` (in `createTypeChecker`) SymbolTable. `mergeSymbolTable` primarily calls `mergeSymbol`.

docs/compiler/checker.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ program.getTypeChecker ->
1616
### Association with Emitter
1717
True type checking happens once a call is made to `getDiagnostics`. This function is called e.g. once a request is made to `Program.emit`, in which case the checker returns an `EmitResolver` (progarm calls the checkers `getEmitResolver` function) which is just a set of functions local to `createTypeChecker`. We will mention this again when we look at the emitter.
1818

19-
Here is the call stack right down to `checkSourceFile` (a function local to `createTypeChecker`).
19+
Here is the call stack right down to `checkSourceFile` (a function local to `createTypeChecker`).
2020

2121
```
22-
program.emit ->
23-
emitWorker (program local) ->
22+
program.emit ->
23+
emitWorker (program local) ->
2424
createTypeChecker.getEmitResolver ->
2525
// First call the following functions local to createTypeChecker
26-
call getDiagnostics ->
27-
getDiagnosticsWorker ->
26+
call getDiagnostics ->
27+
getDiagnosticsWorker ->
2828
checkSourceFile
29-
29+
3030
// then
31-
return resolver
31+
return resolver
3232
(already initialized in createTypeChecker using a call to local createResolver())
3333
```
34-

docs/compiler/contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ Test can be created by adding a new file `yourtest.ts` to `tests/cases/compiler`
5858

5959
Run all of these in isolation using `jake runtests tests=compiler`, or just your new file using `jake runtests tests=compiler/yourtest`
6060

61-
I will even often do `jake runtests tests=compiler/yourtest || jake baseline-accept[soft]` and get the diff in `git`.
61+
I will even often do `jake runtests tests=compiler/yourtest || jake baseline-accept[soft]` and get the diff in `git`.

docs/compiler/emitter.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ There are two `emitters` provided with the TypeScript compiler:
77
We will look at `emitter.ts` in this section.
88

99
### Usage by `program`
10-
Program provides an `emit` function. This function primarily delegates to `emitFiles` function in `emitter.ts`. Here is the call stack:
10+
Program provides an `emit` function. This function primarily delegates to `emitFiles` function in `emitter.ts`. Here is the call stack:
1111

1212
```
13-
Program.emit ->
13+
Program.emit ->
1414
`emitWorker` (local in program.ts createProgram) ->
1515
`emitFiles` (function in emitter.ts)
1616
```
17-
One thing that the `emitWorker` provides to the emitter (via an argument to `emitFiles`) is an `EmitResolver`. `EmitResolver` is provided by the program's TypeChecker, basically it a subset of *local* functions from `createChecker`.
17+
One thing that the `emitWorker` provides to the emitter (via an argument to `emitFiles`) is an `EmitResolver`. `EmitResolver` is provided by the program's TypeChecker, basically it a subset of *local* functions from `createChecker`.

0 commit comments

Comments
 (0)