Skip to content

Commit abf9961

Browse files
committed
Merge branch 'master' into lint-nested-++
2 parents 401a393 + 827fec6 commit abf9961

4,274 files changed

Lines changed: 34136 additions & 13509 deletions

File tree

Some content is hidden

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

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ Your pull request should:
3636

3737
The library sources are in: [src/lib](https://github.com/Microsoft/TypeScript/tree/master/src/lib)
3838

39-
To build the library files, run
39+
Library files in `built/local/` are updated by running
4040
```Shell
41-
jake lib
41+
jake
4242
```
4343

44+
The files in `lib/` are used to bootstrap compilation and usually do not need to be updated.
45+
4446
#### `src/lib/dom.generated.d.ts` and `src/lib/webworker.generated.d.ts`
4547

4648
These two files represent the DOM typings and are auto-generated. To make any modifications to them, please submit a PR to https://github.com/Microsoft/TSJS-lib-generator

Jakefile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ compileFile(word2mdJs,
533533
// The generated spec.md; built for the 'generate-spec' task
534534
file(specMd, [word2mdJs, specWord], function () {
535535
var specWordFullPath = path.resolve(specWord);
536-
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd;
536+
var specMDFullPath = path.resolve(specMd);
537+
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + '"' + specMDFullPath + '"';
537538
console.log(cmd);
538539
child_process.exec(cmd, function () {
539540
complete();
@@ -913,7 +914,8 @@ function lintFileAsync(options, path, cb) {
913914
var lintTargets = compilerSources
914915
.concat(harnessCoreSources)
915916
.concat(serverCoreSources)
916-
.concat(tslintRulesFiles);
917+
.concat(tslintRulesFiles)
918+
.concat([path.join(servicesDirectory, "services.ts")]);
917919

918920
desc("Runs tslint on the compiler sources");
919921
task("lint", ["build-rules"], function() {

doc/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory contains miscellaneous documentation such as the TypeScript language specification and logo.
2+
If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook).
3+
4+
# Spec Contributions
5+
6+
The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats.
7+
Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests.
-662 Bytes
Binary file not shown.
936 Bytes
Binary file not shown.

doc/spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ x = "hello"; // Ok
13231323
x = 42; // Ok
13241324
x = test; // Error, boolean not assignable
13251325
x = test ? 5 : "five"; // Ok
1326-
x = test ? 0 : false; // Error, number | boolean not asssignable
1326+
x = test ? 0 : false; // Error, number | boolean not assignable
13271327
```
13281328

13291329
it is possible to assign 'x' a value of type `string`, `number`, or the union type `string | number`, but not any other type. To access a value in 'x', a type guard can be used to first narrow the type of 'x' to either `string` or `number`:

lib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Read this!
22

33
These files are not meant to be edited by hand.
4-
If you need to make modifications, the respective files should be changed within the repository's top-level `src` directory.
4+
If you need to make modifications, the respective files should be changed within the repository's top-level `src` directory. Running `jake LKG` will then appropriately update the files in this directory.

src/compiler/binder.ts

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,21 @@ namespace ts {
222222
case SyntaxKind.ExportAssignment:
223223
return (<ExportAssignment>node).isExportEquals ? "export=" : "default";
224224
case SyntaxKind.BinaryExpression:
225-
// Binary expression case is for JS module 'module.exports = expr'
226-
return "export=";
225+
switch (getSpecialPropertyAssignmentKind(node)) {
226+
case SpecialPropertyAssignmentKind.ModuleExports:
227+
// module.exports = ...
228+
return "export=";
229+
case SpecialPropertyAssignmentKind.ExportsProperty:
230+
case SpecialPropertyAssignmentKind.ThisProperty:
231+
// exports.x = ... or this.y = ...
232+
return ((node as BinaryExpression).left as PropertyAccessExpression).name.text;
233+
case SpecialPropertyAssignmentKind.PrototypeProperty:
234+
// className.prototype.methodName = ...
235+
return (((node as BinaryExpression).left as PropertyAccessExpression).expression as PropertyAccessExpression).name.text;
236+
}
237+
Debug.fail("Unknown binary declaration kind");
238+
break;
239+
227240
case SyntaxKind.FunctionDeclaration:
228241
case SyntaxKind.ClassDeclaration:
229242
return node.flags & NodeFlags.Default ? "default" : undefined;
@@ -1166,11 +1179,25 @@ namespace ts {
11661179
return checkStrictModeIdentifier(<Identifier>node);
11671180
case SyntaxKind.BinaryExpression:
11681181
if (isInJavaScriptFile(node)) {
1169-
if (isExportsPropertyAssignment(node)) {
1170-
bindExportsPropertyAssignment(<BinaryExpression>node);
1171-
}
1172-
else if (isModuleExportsAssignment(node)) {
1173-
bindModuleExportsAssignment(<BinaryExpression>node);
1182+
const specialKind = getSpecialPropertyAssignmentKind(node);
1183+
switch (specialKind) {
1184+
case SpecialPropertyAssignmentKind.ExportsProperty:
1185+
bindExportsPropertyAssignment(<BinaryExpression>node);
1186+
break;
1187+
case SpecialPropertyAssignmentKind.ModuleExports:
1188+
bindModuleExportsAssignment(<BinaryExpression>node);
1189+
break;
1190+
case SpecialPropertyAssignmentKind.PrototypeProperty:
1191+
bindPrototypePropertyAssignment(<BinaryExpression>node);
1192+
break;
1193+
case SpecialPropertyAssignmentKind.ThisProperty:
1194+
bindThisPropertyAssignment(<BinaryExpression>node);
1195+
break;
1196+
case SpecialPropertyAssignmentKind.None:
1197+
// Nothing to do
1198+
break;
1199+
default:
1200+
Debug.fail("Unknown special property assignment kind");
11741201
}
11751202
}
11761203
return checkStrictModeBinaryExpression(<BinaryExpression>node);
@@ -1189,7 +1216,8 @@ namespace ts {
11891216
case SyntaxKind.ThisType:
11901217
seenThisKeyword = true;
11911218
return;
1192-
1219+
case SyntaxKind.TypePredicate:
1220+
return checkTypePredicate(node as TypePredicateNode);
11931221
case SyntaxKind.TypeParameter:
11941222
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes);
11951223
case SyntaxKind.Parameter:
@@ -1275,6 +1303,17 @@ namespace ts {
12751303
}
12761304
}
12771305

1306+
function checkTypePredicate(node: TypePredicateNode) {
1307+
const { parameterName, type } = node;
1308+
if (parameterName && parameterName.kind === SyntaxKind.Identifier) {
1309+
checkStrictModeIdentifier(parameterName as Identifier);
1310+
}
1311+
if (parameterName && parameterName.kind === SyntaxKind.ThisType) {
1312+
seenThisKeyword = true;
1313+
}
1314+
bind(type);
1315+
}
1316+
12781317
function bindSourceFileIfExternalModule() {
12791318
setExportContextFlag(file);
12801319
if (isExternalModule(file)) {
@@ -1339,6 +1378,34 @@ namespace ts {
13391378
bindExportAssignment(node);
13401379
}
13411380

1381+
function bindThisPropertyAssignment(node: BinaryExpression) {
1382+
// Declare a 'member' in case it turns out the container was an ES5 class
1383+
if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) {
1384+
container.symbol.members = container.symbol.members || {};
1385+
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
1386+
}
1387+
}
1388+
1389+
function bindPrototypePropertyAssignment(node: BinaryExpression) {
1390+
// We saw a node of the form 'x.prototype.y = z'. Declare a 'member' y on x if x was a function.
1391+
1392+
// Look up the function in the local scope, since prototype assignments should
1393+
// follow the function declaration
1394+
const classId = <Identifier>(<PropertyAccessExpression>(<PropertyAccessExpression>node.left).expression).expression;
1395+
const funcSymbol = container.locals[classId.text];
1396+
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) {
1397+
return;
1398+
}
1399+
1400+
// Set up the members collection if it doesn't exist already
1401+
if (!funcSymbol.members) {
1402+
funcSymbol.members = {};
1403+
}
1404+
1405+
// Declare the method/property
1406+
declareSymbol(funcSymbol.members, funcSymbol, <PropertyAccessExpression>node.left, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
1407+
}
1408+
13421409
function bindCallExpression(node: CallExpression) {
13431410
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
13441411
// this check if we've already seen the module indicator
@@ -1432,10 +1499,7 @@ namespace ts {
14321499

14331500
// If this is a property-parameter, then also declare the property symbol into the
14341501
// containing class.
1435-
if (node.flags & NodeFlags.AccessibilityModifier &&
1436-
node.parent.kind === SyntaxKind.Constructor &&
1437-
isClassLike(node.parent.parent)) {
1438-
1502+
if (isParameterPropertyDeclaration(node)) {
14391503
const classDeclaration = <ClassLikeDeclaration>node.parent.parent;
14401504
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
14411505
}

0 commit comments

Comments
 (0)