Skip to content

Commit 4c639b8

Browse files
committed
Merge branch 'master' into declaration-emit-refactor
2 parents 9f42eb8 + 4833657 commit 4c639b8

File tree

97 files changed

+2607
-1181
lines changed

Some content is hidden

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

97 files changed

+2607
-1181
lines changed

.circleci/config.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
workflows:
2+
version: 2
3+
main:
4+
jobs:
5+
- node9:
6+
filters:
7+
branches:
8+
only:
9+
- master
10+
- release-2.5
11+
- release-2.6
12+
- release-2.7
13+
- node8:
14+
filters:
15+
branches:
16+
only:
17+
- master
18+
- release-2.5
19+
- release-2.6
20+
- release-2.7
21+
- node6:
22+
filters:
23+
branches:
24+
only:
25+
- master
26+
- release-2.5
27+
- release-2.6
28+
- release-2.7
29+
nightly:
30+
triggers:
31+
- schedule:
32+
cron: "0 8 * * *"
33+
filters:
34+
branches:
35+
only: master
36+
jobs:
37+
- node9:
38+
filters:
39+
branches:
40+
only:
41+
- master
42+
- release-2.5
43+
- release-2.6
44+
- release-2.7
45+
context: nightlies
46+
- node8:
47+
filters:
48+
branches:
49+
only:
50+
- master
51+
- release-2.5
52+
- release-2.6
53+
- release-2.7
54+
context: nightlies
55+
- node6:
56+
filters:
57+
branches:
58+
only:
59+
- master
60+
- release-2.5
61+
- release-2.6
62+
- release-2.7
63+
context: nightlies
64+
65+
base: &base
66+
environment:
67+
- workerCount: 4
68+
steps:
69+
- checkout
70+
- run: |
71+
npm uninstall typescript --no-save
72+
npm uninstall tslint --no-save
73+
npm install
74+
#npm update Appeared in Jenkins only
75+
npm test
76+
77+
version: 2
78+
jobs:
79+
node9:
80+
docker:
81+
- image: circleci/node:9
82+
<<: *base
83+
node8:
84+
docker:
85+
- image: circleci/node:8
86+
<<: *base
87+
node6:
88+
docker:
89+
- image: circleci/node:6
90+
<<: *base

Gulpfile.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
5353
"ru": "runners", "runner": "runners",
5454
"r": "reporter",
5555
"c": "colors", "color": "colors",
56-
"f": "files", "file": "files",
5756
"w": "workers",
5857
},
5958
default: {
@@ -69,7 +68,6 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
6968
light: process.env.light === undefined || process.env.light !== "false",
7069
reporter: process.env.reporter || process.env.r,
7170
lint: process.env.lint || true,
72-
files: process.env.f || process.env.file || process.env.files || "",
7371
workers: process.env.workerCount || os.cpus().length,
7472
}
7573
});
@@ -1112,13 +1110,11 @@ function spawnLintWorker(files: {path: string}[], callback: (failures: number) =
11121110

11131111
gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
11141112
if (fold.isTravis()) console.log(fold.start("lint"));
1115-
const fileMatcher = cmdLineOptions.files;
1116-
const files = fileMatcher
1117-
? `src/**/${fileMatcher}`
1118-
: `Gulpfile.ts "scripts/generateLocalizedDiagnosticMessages.ts" "scripts/tslint/**/*.ts" "src/**/*.ts" --exclude "src/lib/*.d.ts"`;
1119-
const cmd = `node node_modules/tslint/bin/tslint ${files} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
1120-
console.log("Linting: " + cmd);
1121-
child_process.execSync(cmd, { stdio: [0, 1, 2] });
1113+
for (const project of ["scripts/tslint/tsconfig.json", "src/tsconfig-base.json"]) {
1114+
const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
1115+
console.log("Linting: " + cmd);
1116+
child_process.execSync(cmd, { stdio: [0, 1, 2] });
1117+
}
11221118
if (fold.isTravis()) console.log(fold.end("lint"));
11231119
});
11241120

Jakefile.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ var harnessSources = harnessCoreSources.concat([
141141
"typingsInstaller.ts",
142142
"projectErrors.ts",
143143
"matchFiles.ts",
144+
"organizeImports.ts",
144145
"initializeTSConfig.ts",
145146
"extractConstants.ts",
146147
"extractFunctions.ts",
@@ -1301,15 +1302,13 @@ function spawnLintWorker(files, callback) {
13011302
desc("Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex");
13021303
task("lint", ["build-rules"], () => {
13031304
if (fold.isTravis()) console.log(fold.start("lint"));
1304-
const fileMatcher = process.env.f || process.env.file || process.env.files;
1305-
1306-
const files = fileMatcher
1307-
? `src/**/${fileMatcher}`
1308-
: `Gulpfile.ts scripts/generateLocalizedDiagnosticMessages.ts "scripts/tslint/**/*.ts" "src/**/*.ts" --exclude "src/lib/*.d.ts"`;
1309-
const cmd = `node node_modules/tslint/bin/tslint ${files} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
1310-
console.log("Linting: " + cmd);
1311-
jake.exec([cmd], { interactive: true, windowsVerbatimArguments: true }, () => {
1305+
function lint(project, cb) {
1306+
const cmd = `node node_modules/tslint/bin/tslint --project ${project} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
1307+
console.log("Linting: " + cmd);
1308+
jake.exec([cmd], { interactive: true, windowsVerbatimArguments: true }, cb);
1309+
}
1310+
lint("scripts/tslint/tsconfig.json", () => lint("src/tsconfig-base.json", () => {
13121311
if (fold.isTravis()) console.log(fold.end("lint"));
13131312
complete();
1314-
});
1313+
}));
13151314
});

scripts/tslint/rules/booleanTriviaRule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function walk(ctx: Lint.WalkContext<void>): void {
2727
/** Skip certain function/method names whose parameter names are not informative. */
2828
function shouldIgnoreCalledExpression(expression: ts.Expression): boolean {
2929
if (expression.kind === ts.SyntaxKind.PropertyAccessExpression) {
30-
const methodName = (expression as ts.PropertyAccessExpression).name.text as string;
30+
const methodName = (expression as ts.PropertyAccessExpression).name.text;
3131
if (methodName.indexOf("set") === 0) {
3232
return true;
3333
}
@@ -45,7 +45,7 @@ function walk(ctx: Lint.WalkContext<void>): void {
4545
}
4646
}
4747
else if (expression.kind === ts.SyntaxKind.Identifier) {
48-
const functionName = (expression as ts.Identifier).text as string;
48+
const functionName = (expression as ts.Identifier).text;
4949
if (functionName.indexOf("set") === 0) {
5050
return true;
5151
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* @license
3+
* Copyright 2016 Palantir Technologies, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as ts from "typescript";
19+
import * as Lint from "tslint";
20+
21+
export class Rule extends Lint.Rules.TypedRule {
22+
/* tslint:disable:object-literal-sort-keys */
23+
public static metadata: Lint.IRuleMetadata = {
24+
ruleName: "no-unnecessary-type-assertion",
25+
description: "Warns if a type assertion does not change the type of an expression.",
26+
options: {
27+
type: "list",
28+
listType: {
29+
type: "array",
30+
items: { type: "string" },
31+
},
32+
},
33+
optionsDescription: "A list of whitelisted assertion types to ignore",
34+
type: "typescript",
35+
hasFix: true,
36+
typescriptOnly: true,
37+
requiresTypeInfo: true,
38+
};
39+
/* tslint:enable:object-literal-sort-keys */
40+
41+
public static FAILURE_STRING = "This assertion is unnecessary since it does not change the type of the expression.";
42+
43+
public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
44+
return this.applyWithWalker(new Walker(sourceFile, this.ruleName, this.ruleArguments, program.getTypeChecker()));
45+
}
46+
}
47+
48+
class Walker extends Lint.AbstractWalker<string[]> {
49+
constructor(sourceFile: ts.SourceFile, ruleName: string, options: string[], private readonly checker: ts.TypeChecker) {
50+
super(sourceFile, ruleName, options);
51+
}
52+
53+
public walk(sourceFile: ts.SourceFile) {
54+
const cb = (node: ts.Node): void => {
55+
switch (node.kind) {
56+
case ts.SyntaxKind.TypeAssertionExpression:
57+
case ts.SyntaxKind.AsExpression:
58+
this.verifyCast(node as ts.TypeAssertion | ts.AsExpression);
59+
}
60+
61+
return ts.forEachChild(node, cb);
62+
};
63+
64+
return ts.forEachChild(sourceFile, cb);
65+
}
66+
67+
private verifyCast(node: ts.TypeAssertion | ts.NonNullExpression | ts.AsExpression) {
68+
if (ts.isAssertionExpression(node) && this.options.indexOf(node.type.getText(this.sourceFile)) !== -1) {
69+
return;
70+
}
71+
const castType = this.checker.getTypeAtLocation(node);
72+
if (castType === undefined) {
73+
return;
74+
}
75+
76+
if (node.kind !== ts.SyntaxKind.NonNullExpression &&
77+
(castType.flags & ts.TypeFlags.Literal ||
78+
castType.flags & ts.TypeFlags.Object &&
79+
(castType as ts.ObjectType).objectFlags & ts.ObjectFlags.Tuple) ||
80+
// Sometimes tuple types don't have ObjectFlags.Tuple set, like when
81+
// they're being matched against an inferred type. So, in addition,
82+
// check if any properties are numbers, which implies that this is
83+
// likely a tuple type.
84+
(castType.getProperties().some((symbol) => !isNaN(Number(symbol.name))))) {
85+
86+
// It's not always safe to remove a cast to a literal type or tuple
87+
// type, as those types are sometimes widened without the cast.
88+
return;
89+
}
90+
91+
const uncastType = this.checker.getTypeAtLocation(node.expression);
92+
if (uncastType === castType) {
93+
this.addFailureAtNode(node, Rule.FAILURE_STRING, node.kind === ts.SyntaxKind.TypeAssertionExpression
94+
? Lint.Replacement.deleteFromTo(node.getStart(), node.expression.getStart())
95+
: Lint.Replacement.deleteFromTo(node.expression.getEnd(), node.getEnd()));
96+
}
97+
}
98+
}

scripts/tslint/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"lib": ["es6"],
34
"noImplicitAny": true,
45
"noImplicitReturns": true,
56
"noImplicitThis": true,

src/compiler/binder.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ namespace ts {
264264
return (isGlobalScopeAugmentation(<ModuleDeclaration>node) ? "__global" : `"${moduleName}"`) as __String;
265265
}
266266
if (name.kind === SyntaxKind.ComputedPropertyName) {
267-
const nameExpression = (<ComputedPropertyName>name).expression;
267+
const nameExpression = name.expression;
268268
// treat computed property names where expression is string/numeric literal as just string/numeric literal
269269
if (isStringOrNumericLiteral(nameExpression)) {
270270
return escapeLeadingUnderscores(nameExpression.text);
@@ -459,10 +459,7 @@ namespace ts {
459459
// and this case is specially handled. Module augmentations should only be merged with original module definition
460460
// and should never be merged directly with other augmentation, and the latter case would be possible if automatic merge is allowed.
461461
if (node.kind === SyntaxKind.JSDocTypedefTag) Debug.assert(isInJavaScriptFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file.
462-
const isJSDocTypedefInJSDocNamespace = node.kind === SyntaxKind.JSDocTypedefTag &&
463-
(node as JSDocTypedefTag).name &&
464-
(node as JSDocTypedefTag).name.kind === SyntaxKind.Identifier &&
465-
((node as JSDocTypedefTag).name as Identifier).isInJSDocNamespace;
462+
const isJSDocTypedefInJSDocNamespace = isJSDocTypedefTag(node) && node.name && node.name.kind === SyntaxKind.Identifier && node.name.isInJSDocNamespace;
466463
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypedefInJSDocNamespace) {
467464
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
468465
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
@@ -527,7 +524,7 @@ namespace ts {
527524
if (!isIIFE) {
528525
currentFlow = { flags: FlowFlags.Start };
529526
if (containerFlags & (ContainerFlags.IsFunctionExpression | ContainerFlags.IsObjectLiteralOrClassExpressionMethod)) {
530-
(<FlowStart>currentFlow).container = <FunctionExpression | ArrowFunction | MethodDeclaration>node;
527+
currentFlow.container = <FunctionExpression | ArrowFunction | MethodDeclaration>node;
531528
}
532529
}
533530
// We create a return control flow graph for IIFEs and constructors. For constructors
@@ -997,7 +994,7 @@ namespace ts {
997994
addAntecedent(postLoopLabel, currentFlow);
998995
bind(node.initializer);
999996
if (node.initializer.kind !== SyntaxKind.VariableDeclarationList) {
1000-
bindAssignmentTargetFlow(<Expression>node.initializer);
997+
bindAssignmentTargetFlow(node.initializer);
1001998
}
1002999
bindIterativeStatement(node.statement, postLoopLabel, preLoopLabel);
10031000
addAntecedent(preLoopLabel, currentFlow);
@@ -1170,7 +1167,7 @@ namespace ts {
11701167
i++;
11711168
}
11721169
const preCaseLabel = createBranchLabel();
1173-
addAntecedent(preCaseLabel, createFlowSwitchClause(preSwitchCaseFlow, <SwitchStatement>node.parent, clauseStart, i + 1));
1170+
addAntecedent(preCaseLabel, createFlowSwitchClause(preSwitchCaseFlow, node.parent, clauseStart, i + 1));
11741171
addAntecedent(preCaseLabel, fallthroughFlow);
11751172
currentFlow = finishFlowLabel(preCaseLabel);
11761173
const clause = clauses[i];
@@ -1251,13 +1248,13 @@ namespace ts {
12511248
else if (node.kind === SyntaxKind.ObjectLiteralExpression) {
12521249
for (const p of (<ObjectLiteralExpression>node).properties) {
12531250
if (p.kind === SyntaxKind.PropertyAssignment) {
1254-
bindDestructuringTargetFlow((<PropertyAssignment>p).initializer);
1251+
bindDestructuringTargetFlow(p.initializer);
12551252
}
12561253
else if (p.kind === SyntaxKind.ShorthandPropertyAssignment) {
1257-
bindAssignmentTargetFlow((<ShorthandPropertyAssignment>p).name);
1254+
bindAssignmentTargetFlow(p.name);
12581255
}
12591256
else if (p.kind === SyntaxKind.SpreadAssignment) {
1260-
bindAssignmentTargetFlow((<SpreadAssignment>p).expression);
1257+
bindAssignmentTargetFlow(p.expression);
12611258
}
12621259
}
12631260
}
@@ -1572,7 +1569,7 @@ namespace ts {
15721569
}
15731570

15741571
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
1575-
const body = node.kind === SyntaxKind.SourceFile ? node : (<ModuleDeclaration>node).body;
1572+
const body = node.kind === SyntaxKind.SourceFile ? node : node.body;
15761573
if (body && (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock)) {
15771574
for (const stat of (<BlockLike>body).statements) {
15781575
if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) {
@@ -2210,7 +2207,7 @@ namespace ts {
22102207
function checkTypePredicate(node: TypePredicateNode) {
22112208
const { parameterName, type } = node;
22122209
if (parameterName && parameterName.kind === SyntaxKind.Identifier) {
2213-
checkStrictModeIdentifier(parameterName as Identifier);
2210+
checkStrictModeIdentifier(parameterName);
22142211
}
22152212
if (parameterName && parameterName.kind === SyntaxKind.ThisType) {
22162213
seenThisKeyword = true;
@@ -2555,13 +2552,13 @@ namespace ts {
25552552
}
25562553
}
25572554

2558-
checkStrictModeFunctionName(<FunctionDeclaration>node);
2555+
checkStrictModeFunctionName(node);
25592556
if (inStrictMode) {
25602557
checkStrictModeFunctionDeclaration(node);
25612558
bindBlockScopedDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
25622559
}
25632560
else {
2564-
declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
2561+
declareSymbolAndAddToSymbolTable(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes);
25652562
}
25662563
}
25672564

src/compiler/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ namespace ts {
228228
host = oldProgramOrHost as CompilerHost;
229229
}
230230
else {
231-
newProgram = newProgramOrRootNames as Program;
231+
newProgram = newProgramOrRootNames;
232232
host = hostOrOptions as BuilderProgramHost;
233233
oldProgram = oldProgramOrHost as BuilderProgram;
234234
}

0 commit comments

Comments
 (0)