Skip to content

Commit d58cfa2

Browse files
author
Andy Hanson
committed
Merge branch 'master' into lint_better
2 parents 8371eb6 + b152034 commit d58cfa2

File tree

69 files changed

+638
-267
lines changed

Some content is hidden

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

69 files changed

+638
-267
lines changed

Gulpfile.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ gulp.task(builtLocalCompiler, false, [servicesFile], () => {
390390
.pipe(localCompilerProject())
391391
.pipe(prependCopyright())
392392
.pipe(sourcemaps.write("."))
393-
.pipe(gulp.dest("."));
393+
.pipe(gulp.dest("src/compiler"));
394394
});
395395

396396
gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
@@ -422,7 +422,7 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
422422
file.path = nodeStandaloneDefinitionsFile;
423423
return content.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
424424
}))
425-
]).pipe(gulp.dest("."));
425+
]).pipe(gulp.dest("src/services"));
426426
});
427427

428428
// cancellationToken.js
@@ -448,7 +448,7 @@ gulp.task(typingsInstallerJs, false, [servicesFile], () => {
448448
.pipe(cancellationTokenProject())
449449
.pipe(prependCopyright())
450450
.pipe(sourcemaps.write("."))
451-
.pipe(gulp.dest("."));
451+
.pipe(gulp.dest("src/server/typingsInstaller"));
452452
});
453453

454454
const serverFile = path.join(builtLocalDirectory, "tsserver.js");
@@ -461,7 +461,7 @@ gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationToke
461461
.pipe(serverProject())
462462
.pipe(prependCopyright())
463463
.pipe(sourcemaps.write("."))
464-
.pipe(gulp.dest("."));
464+
.pipe(gulp.dest("src/server"));
465465
});
466466

467467
const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
@@ -556,7 +556,7 @@ gulp.task(run, false, [servicesFile], () => {
556556
.pipe(sourcemaps.init())
557557
.pipe(testProject())
558558
.pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" }))
559-
.pipe(gulp.dest("."));
559+
.pipe(gulp.dest("src/harness"));
560560
});
561561

562562
const internalTests = "internal/";
@@ -778,7 +778,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
778778
});
779779
}))
780780
.pipe(sourcemaps.write(".", { includeContent: false }))
781-
.pipe(gulp.dest("."));
781+
.pipe(gulp.dest("src/harness"));
782782
});
783783

784784

Jakefile.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,14 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
328328
if (opts.stripInternal) {
329329
options += " --stripInternal";
330330
}
331-
332-
options += " --target es5 --lib es5,scripthost --noUnusedLocals --noUnusedParameters";
331+
options += " --target es5";
332+
if (opts.lib) {
333+
options += " --lib " + opts.lib
334+
}
335+
else {
336+
options += " --lib es5,scripthost"
337+
}
338+
options += " --noUnusedLocals --noUnusedParameters";
333339

334340
var cmd = host + " " + compilerPath + " " + options + " ";
335341
cmd = cmd + sources.join(" ");
@@ -1111,7 +1117,7 @@ desc("Compiles tslint rules to js");
11111117
task("build-rules", ["build-rules-start"].concat(tslintRulesOutFiles).concat(["build-rules-end"]));
11121118
tslintRulesFiles.forEach(function (ruleFile, i) {
11131119
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false,
1114-
{ noOutFile: true, generateDeclarations: false, outDir: path.join(builtLocalDirectory, "tslint") });
1120+
{ noOutFile: true, generateDeclarations: false, outDir: path.join(builtLocalDirectory, "tslint"), lib: "es6" });
11151121
});
11161122

11171123
desc("Emit the start of the build-rules fold");

lib/protocol.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,6 +1742,7 @@ declare namespace ts.server.protocol {
17421742
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
17431743
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
17441744
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
1745+
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
17451746
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
17461747
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
17471748
insertSpaceBeforeFunctionParenthesis?: boolean;

scripts/parallel-lint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var tslint = require("tslint");
22
var fs = require("fs");
3+
var path = require("path");
34

45
function getLinterOptions() {
56
return {
@@ -9,7 +10,7 @@ function getLinterOptions() {
910
};
1011
}
1112
function getLinterConfiguration() {
12-
return require("../tslint.json");
13+
return tslint.Configuration.loadConfigurationFromPath(path.join(__dirname, "../tslint.json"));
1314
}
1415

1516
function lintFileContents(options, configuration, path, contents) {

src/compiler/checker.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace ts {
141141
getAugmentedPropertiesOfType,
142142
getRootSymbols,
143143
getContextualType: node => {
144-
node = getParseTreeNode(node, isExpression)
144+
node = getParseTreeNode(node, isExpression);
145145
return node ? getContextualType(node) : undefined;
146146
},
147147
getFullyQualifiedName,
@@ -197,6 +197,8 @@ namespace ts {
197197
const evolvingArrayTypes: EvolvingArrayType[] = [];
198198

199199
const unknownSymbol = createSymbol(SymbolFlags.Property, "unknown");
200+
const untypedModuleSymbol = createSymbol(SymbolFlags.ValueModule, "<untyped>");
201+
untypedModuleSymbol.exports = createMap<Symbol>();
200202
const resolvingSymbol = createSymbol(0, "__resolving__");
201203

202204
const anyType = createIntrinsicType(TypeFlags.Any, "any");
@@ -1227,7 +1229,7 @@ namespace ts {
12271229

12281230
if (moduleSymbol) {
12291231
let exportDefaultSymbol: Symbol;
1230-
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
1232+
if (isUntypedOrShorthandAmbientModuleSymbol(moduleSymbol)) {
12311233
exportDefaultSymbol = moduleSymbol;
12321234
}
12331235
else {
@@ -1307,7 +1309,7 @@ namespace ts {
13071309
if (targetSymbol) {
13081310
const name = specifier.propertyName || specifier.name;
13091311
if (name.text) {
1310-
if (isShorthandAmbientModuleSymbol(moduleSymbol)) {
1312+
if (isUntypedOrShorthandAmbientModuleSymbol(moduleSymbol)) {
13111313
return moduleSymbol;
13121314
}
13131315

@@ -1560,15 +1562,19 @@ namespace ts {
15601562
if (isForAugmentation) {
15611563
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
15621564
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
1565+
return undefined;
15631566
}
15641567
else if (compilerOptions.noImplicitAny && moduleNotFoundError) {
15651568
error(errorNode,
15661569
Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type,
15671570
moduleReference,
15681571
resolvedModule.resolvedFileName);
1572+
return undefined;
15691573
}
1570-
// Failed imports and untyped modules are both treated in an untyped manner; only difference is whether we give a diagnostic first.
1571-
return undefined;
1574+
// Unlike a failed import, an untyped module produces a dummy symbol.
1575+
// This is checked for by `isUntypedOrShorthandAmbientModuleSymbol`.
1576+
// This must be different than `unknownSymbol` because `getBaseConstructorTypeOfClass` won't fail for `unknownSymbol`.
1577+
return untypedModuleSymbol;
15721578
}
15731579

15741580
if (moduleNotFoundError) {
@@ -3753,7 +3759,7 @@ namespace ts {
37533759
function getTypeOfFuncClassEnumModule(symbol: Symbol): Type {
37543760
const links = getSymbolLinks(symbol);
37553761
if (!links.type) {
3756-
if (symbol.flags & SymbolFlags.Module && isShorthandAmbientModuleSymbol(symbol)) {
3762+
if (symbol.flags & SymbolFlags.Module && isUntypedOrShorthandAmbientModuleSymbol(symbol)) {
37573763
links.type = anyType;
37583764
}
37593765
else {
@@ -11578,7 +11584,7 @@ namespace ts {
1157811584
if (isBindingPattern(declaration.parent)) {
1157911585
const parentDeclaration = declaration.parent.parent;
1158011586
const name = declaration.propertyName || declaration.name;
11581-
if (isVariableLike(parentDeclaration) &&
11587+
if (parentDeclaration.kind !== SyntaxKind.BindingElement &&
1158211588
parentDeclaration.type &&
1158311589
!isBindingPattern(name)) {
1158411590
const text = getTextOfPropertyName(name);
@@ -16125,7 +16131,7 @@ namespace ts {
1612516131
}
1612616132

1612716133
function checkDeclarationInitializer(declaration: VariableLikeDeclaration) {
16128-
const type = checkExpressionCached(declaration.initializer);
16134+
const type = getTypeOfExpression(declaration.initializer, /*cache*/ true);
1612916135
return getCombinedNodeFlags(declaration) & NodeFlags.Const ||
1613016136
getCombinedModifierFlags(declaration) & ModifierFlags.Readonly && !isParameterPropertyDeclaration(declaration) ||
1613116137
isTypeAssertion(declaration.initializer) ? type : getWidenedLiteralType(type);
@@ -16198,10 +16204,12 @@ namespace ts {
1619816204

1619916205
// Returns the type of an expression. Unlike checkExpression, this function is simply concerned
1620016206
// with computing the type and may not fully check all contained sub-expressions for errors.
16201-
function getTypeOfExpression(node: Expression) {
16207+
// A cache argument of true indicates that if the function performs a full type check, it is ok
16208+
// to cache the result.
16209+
function getTypeOfExpression(node: Expression, cache?: boolean) {
1620216210
// Optimize for the common case of a call to a function with a single non-generic call
1620316211
// signature where we can just fetch the return type without checking the arguments.
16204-
if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword) {
16212+
if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) {
1620516213
const funcType = checkNonNullExpression((<CallExpression>node).expression);
1620616214
const signature = getSingleCallSignature(funcType);
1620716215
if (signature && !signature.typeParameters) {
@@ -16211,7 +16219,7 @@ namespace ts {
1621116219
// Otherwise simply call checkExpression. Ideally, the entire family of checkXXX functions
1621216220
// should have a parameter that indicates whether full error checking is required such that
1621316221
// we can perform the optimizations locally.
16214-
return checkExpression(node);
16222+
return cache ? checkExpressionCached(node) : checkExpression(node);
1621516223
}
1621616224

1621716225
// Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When
@@ -20668,7 +20676,7 @@ namespace ts {
2066820676
}
2066920677

2067020678
if (potentialNewTargetCollisions.length) {
20671-
forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope)
20679+
forEach(potentialNewTargetCollisions, checkIfNewTargetIsCapturedInEnclosingScope);
2067220680
potentialNewTargetCollisions.length = 0;
2067320681
}
2067420682

@@ -21138,7 +21146,15 @@ namespace ts {
2113821146
}
2113921147

2114021148
if (isPartOfTypeNode(node)) {
21141-
return getTypeFromTypeNode(<TypeNode>node);
21149+
let typeFromTypeNode = getTypeFromTypeNode(<TypeNode>node);
21150+
21151+
if (typeFromTypeNode && isExpressionWithTypeArgumentsInClassImplementsClause(node)) {
21152+
const containingClass = getContainingClass(node);
21153+
const classType = getTypeOfNode(containingClass) as InterfaceType;
21154+
typeFromTypeNode = getTypeWithThisArgument(typeFromTypeNode, classType.thisType);
21155+
}
21156+
21157+
return typeFromTypeNode;
2114221158
}
2114321159

2114421160
if (isPartOfExpression(node)) {
@@ -21148,7 +21164,10 @@ namespace ts {
2114821164
if (isExpressionWithTypeArgumentsInClassExtendsClause(node)) {
2114921165
// A SyntaxKind.ExpressionWithTypeArguments is considered a type node, except when it occurs in the
2115021166
// extends clause of a class. We handle that case here.
21151-
return getBaseTypes(<InterfaceType>getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0];
21167+
const classNode = getContainingClass(node);
21168+
const classType = getDeclaredTypeOfSymbol(getSymbolOfNode(classNode)) as InterfaceType;
21169+
const baseType = getBaseTypes(classType)[0];
21170+
return baseType && getTypeWithThisArgument(baseType, classType.thisType);
2115221171
}
2115321172

2115421173
if (isTypeDeclaration(node)) {
@@ -21316,7 +21335,7 @@ namespace ts {
2131621335

2131721336
function moduleExportsSomeValue(moduleReferenceExpression: Expression): boolean {
2131821337
let moduleSymbol = resolveExternalModuleName(moduleReferenceExpression.parent, moduleReferenceExpression);
21319-
if (!moduleSymbol || isShorthandAmbientModuleSymbol(moduleSymbol)) {
21338+
if (!moduleSymbol || isUntypedOrShorthandAmbientModuleSymbol(moduleSymbol)) {
2132021339
// If the module is not found or is shorthand, assume that it may export a value.
2132121340
return true;
2132221341
}

src/compiler/core.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace ts {
8484
this.index++;
8585
return { value: this.selector(this.data, this.keys[index]), done: false };
8686
}
87-
return { value: undefined as never, done: true }
87+
return { value: undefined as never, done: true };
8888
}
8989
}
9090

@@ -140,7 +140,7 @@ namespace ts {
140140
action(this.data[key], key);
141141
}
142142
}
143-
}
143+
};
144144
}
145145

146146
export function createFileMap<T>(keyMapper?: (key: string) => string): FileMap<T> {

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ namespace ts {
11641164
emitTypeParameters(node.typeParameters);
11651165
const baseTypeNode = getClassExtendsHeritageClauseElement(node);
11661166
if (baseTypeNode) {
1167-
node.name
1167+
node.name;
11681168
emitHeritageClause(node.name, [baseTypeNode], /*isImplementsList*/ false);
11691169
}
11701170
emitHeritageClause(node.name, getClassImplementsHeritageClauseElements(node), /*isImplementsList*/ true);

src/compiler/moduleNameResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ namespace ts {
675675
}
676676

677677
export function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations {
678-
return nodeModuleNameResolverWorker(moduleName, containingFile, compilerOptions, host, cache, /* jsOnly*/ false);
678+
return nodeModuleNameResolverWorker(moduleName, containingFile, compilerOptions, host, cache, /*jsOnly*/ false);
679679
}
680680

681681
/* @internal */
@@ -962,7 +962,7 @@ namespace ts {
962962
const result = cache && cache.get(containingDirectory);
963963
if (result) {
964964
if (traceEnabled) {
965-
trace(host, Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName)
965+
trace(host, Diagnostics.Resolution_for_module_0_was_found_in_cache, moduleName);
966966
}
967967
return { value: result.resolvedModule && { path: result.resolvedModule.resolvedFileName, extension: result.resolvedModule.extension } };
968968
}

src/compiler/transformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ namespace ts {
121121
enableEmitNotification,
122122
isSubstitutionEnabled,
123123
isEmitNotificationEnabled,
124-
get onSubstituteNode() { return onSubstituteNode },
124+
get onSubstituteNode() { return onSubstituteNode; },
125125
set onSubstituteNode(value) {
126126
Debug.assert(state < TransformationState.Initialized, "Cannot modify transformation hooks after initialization has completed.");
127127
Debug.assert(value !== undefined, "Value must not be 'undefined'");
128128
onSubstituteNode = value;
129129
},
130-
get onEmitNode() { return onEmitNode },
130+
get onEmitNode() { return onEmitNode; },
131131
set onEmitNode(value) {
132132
Debug.assert(state < TransformationState.Initialized, "Cannot modify transformation hooks after initialization has completed.");
133133
Debug.assert(value !== undefined, "Value must not be 'undefined'");

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ namespace ts {
26902690
if (loopOutParameters.length) {
26912691
copyOutParameters(loopOutParameters, CopyDirection.ToOutParameter, statements);
26922692
}
2693-
addRange(statements, lexicalEnvironment)
2693+
addRange(statements, lexicalEnvironment);
26942694
loopBody = createBlock(statements, /*multiline*/ true);
26952695
}
26962696

0 commit comments

Comments
 (0)