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

Lines changed: 20 additions & 20 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
/*!
55
* License
66
*/
7-
```
7+
```

docs/compiler/ast-tip-children.md

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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+
```

0 commit comments

Comments
 (0)