Skip to content

Commit 0af52c3

Browse files
author
Yui T
committed
Merge branch 'master' into fix4211
2 parents 319a9cd + 2f447ee commit 0af52c3

4,998 files changed

Lines changed: 65815 additions & 28686 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: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var compilerSources = [
4040
"utilities.ts",
4141
"binder.ts",
4242
"checker.ts",
43+
"sourcemap.ts",
4344
"declarationEmitter.ts",
4445
"emitter.ts",
4546
"program.ts",
@@ -59,6 +60,7 @@ var servicesSources = [
5960
"utilities.ts",
6061
"binder.ts",
6162
"checker.ts",
63+
"sourcemap.ts",
6264
"declarationEmitter.ts",
6365
"emitter.ts",
6466
"program.ts",
@@ -111,7 +113,8 @@ var scriptSources = [
111113
"tslint/nextLineRule.ts",
112114
"tslint/noNullRule.ts",
113115
"tslint/preferConstRule.ts",
114-
"tslint/typeOperatorSpacingRule.ts"
116+
"tslint/typeOperatorSpacingRule.ts",
117+
"tslint/noInOperatorRule.ts"
115118
].map(function (f) {
116119
return path.join(scriptsDirectory, f);
117120
});
@@ -475,7 +478,7 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca
475478
var nodeDefinitionsFileContents = definitionFileContents + "\r\nexport = ts;";
476479
fs.writeFileSync(nodeDefinitionsFile, nodeDefinitionsFileContents);
477480

478-
// Node package definition file to be distributed without the package. Created by replacing
481+
// Node package definition file to be distributed without the package. Created by replacing
479482
// 'ts' namespace with '"typescript"' as a module.
480483
var nodeStandaloneDefinitionsFileContents = definitionFileContents.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
481484
fs.writeFileSync(nodeStandaloneDefinitionsFile, nodeStandaloneDefinitionsFileContents);
@@ -541,7 +544,8 @@ compileFile(word2mdJs,
541544
// The generated spec.md; built for the 'generate-spec' task
542545
file(specMd, [word2mdJs, specWord], function () {
543546
var specWordFullPath = path.resolve(specWord);
544-
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + specMd;
547+
var specMDFullPath = path.resolve(specMd);
548+
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + '"' + specMDFullPath + '"';
545549
console.log(cmd);
546550
child_process.exec(cmd, function () {
547551
complete();
@@ -873,7 +877,8 @@ var tslintRules = ([
873877
"noNullRule",
874878
"preferConstRule",
875879
"booleanTriviaRule",
876-
"typeOperatorSpacingRule"
880+
"typeOperatorSpacingRule",
881+
"noInOperatorRule"
877882
]);
878883
var tslintRulesFiles = tslintRules.map(function(p) {
879884
return path.join(tslintRuleDir, p + ".ts");
@@ -884,7 +889,7 @@ var tslintRulesOutFiles = tslintRules.map(function(p) {
884889
desc("Compiles tslint rules to js");
885890
task("build-rules", tslintRulesOutFiles);
886891
tslintRulesFiles.forEach(function(ruleFile, i) {
887-
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint"));
892+
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint"));
888893
});
889894

890895
function getLinterOptions() {
@@ -924,13 +929,17 @@ var lintTargets = compilerSources
924929
desc("Runs tslint on the compiler sources");
925930
task("lint", ["build-rules"], function() {
926931
var lintOptions = getLinterOptions();
932+
var failed = 0;
927933
for (var i in lintTargets) {
928934
var result = lintFile(lintOptions, lintTargets[i]);
929935
if (result.failureCount > 0) {
930936
console.log(result.output);
931-
fail('Linter errors.', result.failureCount);
937+
failed += result.failureCount;
932938
}
933939
}
940+
if (failed > 0) {
941+
fail('Linter errors.', failed);
942+
}
934943
});
935944

936945
/**
@@ -947,7 +956,7 @@ function lintWatchFile(filename) {
947956
if (event !== "change") {
948957
return;
949958
}
950-
959+
951960
if (!lintSemaphores[filename]) {
952961
lintSemaphores[filename] = true;
953962
lintFileAsync(getLinterOptions(), filename, function(err, result) {
-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.

scripts/tslint/noInOperatorRule.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as Lint from "tslint/lib/lint";
2+
import * as ts from "typescript";
3+
4+
5+
export class Rule extends Lint.Rules.AbstractRule {
6+
public static FAILURE_STRING = "Don't use the 'in' keyword - use 'hasProperty' to check for key presence instead";
7+
8+
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
9+
return this.applyWithWalker(new InWalker(sourceFile, this.getOptions()));
10+
}
11+
}
12+
13+
class InWalker extends Lint.RuleWalker {
14+
visitNode(node: ts.Node) {
15+
super.visitNode(node);
16+
if (node.kind === ts.SyntaxKind.InKeyword && node.parent && node.parent.kind === ts.SyntaxKind.BinaryExpression) {
17+
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
18+
}
19+
}
20+
}

src/compiler/binder.ts

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

0 commit comments

Comments
 (0)