Skip to content

Commit f6f0813

Browse files
author
Kanchalai Tanglertsampan
committed
Merge branch 'master' into master-jsxChildren
# Conflicts: # src/compiler/checker.ts # src/compiler/diagnosticMessages.json
2 parents d290cf7 + 4e29b18 commit f6f0813

File tree

325 files changed

+6727
-2567
lines changed

Some content is hidden

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

325 files changed

+6727
-2567
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ branches:
1818
- master
1919
- release-2.1
2020
- release-2.2
21+
- release-2.3
2122

2223
install:
2324
- npm uninstall typescript
2425
- npm uninstall tslint
2526
- npm install
26-
- npm update
2727

2828
cache:
2929
directories:

Gulpfile.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
4141
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
4242
string: ["browser", "tests", "host", "reporter", "stackTraceLimit"],
4343
alias: {
44+
b: "browser",
4445
d: "debug",
4546
t: "tests",
4647
test: "tests",
@@ -162,7 +163,10 @@ const librarySourceMap = [
162163

163164
// JavaScript + all host library
164165
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
165-
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") }
166+
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
167+
{ target: "lib.es2016.full.d.ts", sources: ["header.d.ts", "es2016.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
168+
{ target: "lib.es2017.full.d.ts", sources: ["header.d.ts", "es2017.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
169+
{ target: "lib.esnext.full.d.ts", sources: ["header.d.ts", "esnext.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
166170
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap, esnextLibrarySourceMap);
167171

168172
const libraryTargets = librarySourceMap.map(function(f) {
@@ -384,7 +388,7 @@ function prependCopyright(outputCopyright: boolean = !useDebugMode) {
384388
}
385389

386390
gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
387-
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
391+
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
388392
return localCompilerProject.src()
389393
.pipe(newer(builtLocalCompiler))
390394
.pipe(sourcemaps.init())
@@ -395,14 +399,14 @@ gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
395399
});
396400

397401
gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
398-
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false));
402+
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/ false));
399403
const {js, dts} = servicesProject.src()
400404
.pipe(newer(servicesFile))
401405
.pipe(sourcemaps.init())
402406
.pipe(servicesProject());
403407
const completedJs = js.pipe(prependCopyright())
404408
.pipe(sourcemaps.write("."));
405-
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
409+
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/ true))
406410
.pipe(insert.transform((contents, file) => {
407411
file.path = standaloneDefinitionsFile;
408412
return contents.replace(/^(\s*)(export )?const enum (\S+) {(\s*)$/gm, "$1$2enum $3 {$4");
@@ -429,7 +433,7 @@ gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
429433
// cancellationToken.js
430434
const cancellationTokenJs = path.join(builtLocalDirectory, "cancellationToken.js");
431435
gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => {
432-
const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
436+
const cancellationTokenProject = tsc.createProject("src/server/cancellationToken/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
433437
return cancellationTokenProject.src()
434438
.pipe(newer(cancellationTokenJs))
435439
.pipe(sourcemaps.init())
@@ -442,7 +446,7 @@ gulp.task(cancellationTokenJs, /*help*/ false, [servicesFile], () => {
442446
// typingsInstallerFile.js
443447
const typingsInstallerJs = path.join(builtLocalDirectory, "typingsInstaller.js");
444448
gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => {
445-
const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
449+
const cancellationTokenProject = tsc.createProject("src/server/typingsInstaller/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
446450
return cancellationTokenProject.src()
447451
.pipe(newer(typingsInstallerJs))
448452
.pipe(sourcemaps.init())
@@ -455,7 +459,7 @@ gulp.task(typingsInstallerJs, /*help*/ false, [servicesFile], () => {
455459
const serverFile = path.join(builtLocalDirectory, "tsserver.js");
456460

457461
gulp.task(serverFile, /*help*/ false, [servicesFile, typingsInstallerJs, cancellationTokenJs], () => {
458-
const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
462+
const serverProject = tsc.createProject("src/server/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
459463
return serverProject.src()
460464
.pipe(newer(serverFile))
461465
.pipe(sourcemaps.init())
@@ -479,7 +483,7 @@ gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile], (done) => {
479483
js.pipe(prependCopyright())
480484
.pipe(sourcemaps.write("."))
481485
.pipe(gulp.dest("src/server")),
482-
dts.pipe(prependCopyright(/*outputCopyright*/true))
486+
dts.pipe(prependCopyright(/*outputCopyright*/ true))
483487
.pipe(insert.transform((content) => {
484488
return content + "\r\nexport = ts;\r\nexport as namespace ts;";
485489
}))
@@ -551,7 +555,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
551555
// Task to build the tests infrastructure using the built compiler
552556
const run = path.join(builtLocalDirectory, "run.js");
553557
gulp.task(run, /*help*/ false, [servicesFile], () => {
554-
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
558+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
555559
return testProject.src()
556560
.pipe(newer(run))
557561
.pipe(sourcemaps.init())
@@ -757,7 +761,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
757761
browserify(intoStream(file.contents), { debug: true })
758762
.bundle((err, res) => {
759763
// assumes file.contents is a Buffer
760-
const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/true).toJSON());
764+
const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/ true).toJSON());
761765
delete maps.sourceRoot;
762766
maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s));
763767
// Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
@@ -775,7 +779,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
775779
});
776780
const finalMap = chain.apply();
777781
file.sourceMap = finalMap;
778-
next(undefined, file);
782+
next(/*err*/ undefined, file);
779783
});
780784
}))
781785
.pipe(sourcemaps.write(".", { includeContent: false }))
@@ -1024,7 +1028,7 @@ gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are:
10241028
const fileMatcher = cmdLineOptions["files"];
10251029
const files = fileMatcher
10261030
? `src/**/${fileMatcher}`
1027-
: "Gulpfile.ts 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
1031+
: "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
10281032
const cmd = `node node_modules/tslint/bin/tslint ${files} --format stylish`;
10291033
console.log("Linting: " + cmd);
10301034
child_process.execSync(cmd, { stdio: [0, 1, 2] });

Jakefile.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,10 @@ var librarySourceMap = [
205205

206206
// JavaScript + all host library
207207
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
208-
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") }
208+
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
209+
{ target: "lib.es2016.full.d.ts", sources: ["header.d.ts", "es2016.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
210+
{ target: "lib.es2017.full.d.ts", sources: ["header.d.ts", "es2017.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
211+
{ target: "lib.esnext.full.d.ts", sources: ["header.d.ts", "esnext.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
209212
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap, esnextLibrarySourceMap);
210213

211214
var libraryTargets = librarySourceMap.map(function (f) {
@@ -1197,7 +1200,7 @@ task("lint", ["build-rules"], () => {
11971200
const fileMatcher = process.env.f || process.env.file || process.env.files;
11981201
const files = fileMatcher
11991202
? `src/**/${fileMatcher}`
1200-
: "Gulpfile.ts 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
1203+
: "Gulpfile.ts 'scripts/tslint/*.ts' 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'";
12011204
const cmd = `node node_modules/tslint/bin/tslint ${files} --format stylish`;
12021205
console.log("Linting: " + cmd);
12031206
jake.exec([cmd], { interactive: true }, () => {

scripts/tslint/booleanTriviaRule.ts

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,88 @@ export class Rule extends Lint.Rules.AbstractRule {
88
}
99

1010
function walk(ctx: Lint.WalkContext<void>): void {
11-
ts.forEachChild(ctx.sourceFile, recur);
12-
function recur(node: ts.Node): void {
11+
const { sourceFile } = ctx;
12+
ts.forEachChild(sourceFile, function recur(node: ts.Node): void {
1313
if (node.kind === ts.SyntaxKind.CallExpression) {
1414
checkCall(node as ts.CallExpression);
1515
}
1616
ts.forEachChild(node, recur);
17-
}
17+
});
1818

1919
function checkCall(node: ts.CallExpression): void {
20-
for (const arg of node.arguments) {
21-
if (arg.kind !== ts.SyntaxKind.TrueKeyword && arg.kind !== ts.SyntaxKind.FalseKeyword) {
22-
continue;
20+
if (!shouldIgnoreCalledExpression(node.expression)) {
21+
for (const arg of node.arguments) {
22+
checkArg(arg);
2323
}
24+
}
25+
}
2426

25-
if (node.expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
26-
const methodName = (node.expression as ts.PropertyAccessExpression).name.text
27-
// Skip certain method names whose parameter names are not informative
28-
if (methodName === 'set' ||
29-
methodName === 'equal' ||
30-
methodName === 'fail' ||
31-
methodName === 'isTrue' ||
32-
methodName === 'assert') {
33-
continue;
34-
}
27+
/** Skip certain function/method names whose parameter names are not informative. */
28+
function shouldIgnoreCalledExpression(expression: ts.Expression): boolean {
29+
if (expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
30+
const methodName = (expression as ts.PropertyAccessExpression).name.text;
31+
if (methodName.indexOf("set") === 0) {
32+
return true;
3533
}
36-
else if (node.expression.kind === ts.SyntaxKind.Identifier) {
37-
const functionName = (node.expression as ts.Identifier).text;
38-
// Skip certain function names whose parameter names are not informative
39-
if (functionName === 'assert') {
40-
continue;
41-
}
34+
switch (methodName) {
35+
case "apply":
36+
case "assert":
37+
case "call":
38+
case "equal":
39+
case "fail":
40+
case "isTrue":
41+
case "output":
42+
case "stringify":
43+
return true;
4244
}
43-
44-
const ranges = ts.getLeadingCommentRanges(arg.getFullText(), 0);
45-
if (!(ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia)) {
46-
ctx.addFailureAtNode(arg, 'Tag boolean argument with parameter name');
45+
}
46+
else if (expression.kind === ts.SyntaxKind.Identifier) {
47+
const functionName = (expression as ts.Identifier).text;
48+
if (functionName.indexOf("set") === 0) {
49+
return true;
50+
}
51+
switch (functionName) {
52+
case "assert":
53+
case "contains":
54+
case "createAnonymousType":
55+
case "createImportSpecifier":
56+
case "createProperty":
57+
case "createSignature":
58+
case "resolveName":
59+
return true;
4760
}
4861
}
62+
return false;
63+
}
64+
65+
function checkArg(arg: ts.Expression): void {
66+
if (!isTrivia(arg)) {
67+
return;
68+
}
69+
70+
const ranges = ts.getTrailingCommentRanges(sourceFile.text, arg.pos) || ts.getLeadingCommentRanges(sourceFile.text, arg.pos);
71+
if (ranges === undefined || ranges.length !== 1 || ranges[0].kind !== ts.SyntaxKind.MultiLineCommentTrivia) {
72+
ctx.addFailureAtNode(arg, "Tag boolean argument with parameter name");
73+
return;
74+
}
75+
76+
const range = ranges[0];
77+
const argStart = arg.getStart(sourceFile);
78+
if (range.end + 1 !== argStart && sourceFile.text.slice(range.end, argStart).indexOf("\n") === -1) {
79+
ctx.addFailureAtNode(arg, "There should be 1 space between an argument and its comment.");
80+
}
81+
}
82+
83+
function isTrivia(arg: ts.Expression): boolean {
84+
switch (arg.kind) {
85+
case ts.SyntaxKind.TrueKeyword:
86+
case ts.SyntaxKind.FalseKeyword:
87+
case ts.SyntaxKind.NullKeyword:
88+
return true;
89+
case ts.SyntaxKind.Identifier:
90+
return (arg as ts.Identifier).originalKeywordKind === ts.SyntaxKind.UndefinedKeyword;
91+
default:
92+
return false;
93+
}
4994
}
5095
}

src/compiler/binder.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ namespace ts {
418418
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
419419
}
420420
else {
421-
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
421+
return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
422422
}
423423
}
424424
else {
@@ -447,13 +447,13 @@ namespace ts {
447447
(symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) |
448448
(symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) |
449449
(symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0);
450-
const local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
450+
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
451451
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
452452
node.localSymbol = local;
453453
return local;
454454
}
455455
else {
456-
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
456+
return declareSymbol(container.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
457457
}
458458
}
459459
}
@@ -1545,7 +1545,7 @@ namespace ts {
15451545
function declareSourceFileMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {
15461546
return isExternalModule(file)
15471547
? declareModuleMember(node, symbolFlags, symbolExcludes)
1548-
: declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
1548+
: declareSymbol(file.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
15491549
}
15501550

15511551
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
@@ -1721,7 +1721,7 @@ namespace ts {
17211721
blockScopeContainer.locals = createMap<Symbol>();
17221722
addToContainerChain(blockScopeContainer);
17231723
}
1724-
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
1724+
declareSymbol(blockScopeContainer.locals, /*parent*/ undefined, node, symbolFlags, symbolExcludes);
17251725
}
17261726
}
17271727

@@ -2298,7 +2298,7 @@ namespace ts {
22982298

22992299
function isNameOfExportsOrModuleExportsAliasDeclaration(node: Node) {
23002300
if (node.kind === SyntaxKind.Identifier) {
2301-
const symbol = container.locals.get((<Identifier>node).text);
2301+
const symbol = lookupSymbolForName((<Identifier>node).text);
23022302
if (symbol && symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.VariableDeclaration) {
23032303
const declaration = symbol.valueDeclaration as VariableDeclaration;
23042304
if (declaration.initializer) {
@@ -2333,7 +2333,7 @@ namespace ts {
23332333

23342334
function bindThisPropertyAssignment(node: BinaryExpression) {
23352335
Debug.assert(isInJavaScriptFile(node));
2336-
const container = getThisContainer(node, /*includeArrowFunctions*/false);
2336+
const container = getThisContainer(node, /*includeArrowFunctions*/ false);
23372337
switch (container.kind) {
23382338
case SyntaxKind.FunctionDeclaration:
23392339
case SyntaxKind.FunctionExpression:
@@ -2400,8 +2400,12 @@ namespace ts {
24002400
}
24012401
}
24022402

2403+
function lookupSymbolForName(name: string) {
2404+
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || container.locals.get(name);
2405+
}
2406+
24032407
function bindPropertyAssignment(functionName: string, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) {
2404-
let targetSymbol = container.locals.get(functionName);
2408+
let targetSymbol = lookupSymbolForName(functionName);
24052409

24062410
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
24072411
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
@@ -2423,7 +2427,7 @@ namespace ts {
24232427
function bindCallExpression(node: CallExpression) {
24242428
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
24252429
// this check if we've already seen the module indicator
2426-
if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/false)) {
2430+
if (!file.commonJsModuleIndicator && isRequireCall(node, /*checkArgumentIsStringLiteral*/ false)) {
24272431
setCommonJsModuleIndicator(node);
24282432
}
24292433
}

0 commit comments

Comments
 (0)