Skip to content

Commit 9a9b51f

Browse files
committed
merge with master
2 parents f18e203 + 19d7e62 commit 9a9b51f

87 files changed

Lines changed: 19546 additions & 178 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.

Jakefile.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ var scriptSources = [
113113
"tslint/nextLineRule.ts",
114114
"tslint/noNullRule.ts",
115115
"tslint/preferConstRule.ts",
116-
"tslint/typeOperatorSpacingRule.ts"
116+
"tslint/typeOperatorSpacingRule.ts",
117+
"tslint/noInOperatorRule.ts"
117118
].map(function (f) {
118119
return path.join(scriptsDirectory, f);
119120
});
@@ -875,7 +876,8 @@ var tslintRules = ([
875876
"noNullRule",
876877
"preferConstRule",
877878
"booleanTriviaRule",
878-
"typeOperatorSpacingRule"
879+
"typeOperatorSpacingRule",
880+
"noInOperatorRule"
879881
]);
880882
var tslintRulesFiles = tslintRules.map(function(p) {
881883
return path.join(tslintRuleDir, p + ".ts");
@@ -926,13 +928,17 @@ var lintTargets = compilerSources
926928
desc("Runs tslint on the compiler sources");
927929
task("lint", ["build-rules"], function() {
928930
var lintOptions = getLinterOptions();
931+
var failed = 0;
929932
for (var i in lintTargets) {
930933
var result = lintFile(lintOptions, lintTargets[i]);
931934
if (result.failureCount > 0) {
932935
console.log(result.output);
933-
fail('Linter errors.', result.failureCount);
936+
failed += result.failureCount;
934937
}
935938
}
939+
if (failed > 0) {
940+
fail('Linter errors.', failed);
941+
}
936942
});
937943

938944
/**

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/checker.ts

Lines changed: 87 additions & 52 deletions
Large diffs are not rendered by default.

src/compiler/declarationEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ namespace ts {
16751675
/* @internal */
16761676
export function writeDeclarationFile(declarationFilePath: string, sourceFiles: SourceFile[], isBundledEmit: boolean, host: EmitHost, resolver: EmitResolver, emitterDiagnostics: DiagnosticCollection) {
16771677
const emitDeclarationResult = emitDeclarations(host, resolver, emitterDiagnostics, declarationFilePath, sourceFiles, isBundledEmit);
1678-
const emitSkipped = emitDeclarationResult.reportedDeclarationError || host.isEmitBlocked(declarationFilePath);
1678+
const emitSkipped = emitDeclarationResult.reportedDeclarationError || host.isEmitBlocked(declarationFilePath) || host.getCompilerOptions().noEmit;
16791679
if (!emitSkipped) {
16801680
const declarationOutput = emitDeclarationResult.referencePathsOutput
16811681
+ getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo);

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,14 @@
783783
"category": "Error",
784784
"code": 1245
785785
},
786+
"An interface property cannot have an initializer.": {
787+
"category": "Error",
788+
"code": 1246
789+
},
790+
"A type literal property cannot have an initializer.": {
791+
"category": "Error",
792+
"code": 1247
793+
},
786794

787795
"'with' statements are not allowed in an async function block.": {
788796
"category": "Error",
@@ -2567,7 +2575,7 @@
25672575
"Not all code paths return a value.": {
25682576
"category": "Error",
25692577
"code": 7030
2570-
},
2578+
},
25712579
"You cannot rename this element.": {
25722580
"category": "Error",
25732581
"code": 8000

src/compiler/emitter.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
21902190
emit(node.right);
21912191
}
21922192

2193-
function emitEntityNameAsExpression(node: EntityName, useFallback: boolean) {
2193+
function emitEntityNameAsExpression(node: EntityName | Expression, useFallback: boolean) {
21942194
switch (node.kind) {
21952195
case SyntaxKind.Identifier:
21962196
if (useFallback) {
@@ -2205,6 +2205,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
22052205
case SyntaxKind.QualifiedName:
22062206
emitQualifiedNameAsExpression(<QualifiedName>node, useFallback);
22072207
break;
2208+
2209+
default:
2210+
emitNodeWithoutSourceMap(node);
2211+
break;
22082212
}
22092213
}
22102214

@@ -2978,7 +2982,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
29782982
}
29792983
else {
29802984
// this is top level converted loop so we need to create an alias for 'this' here
2981-
// NOTE:
2985+
// NOTE:
29822986
// if converted loops were all nested in arrow function then we'll always emit '_this' so convertedLoopState.thisName will not be set.
29832987
// If it is set this means that all nested loops are not nested in arrow function and it is safe to capture 'this'.
29842988
write(`var ${convertedLoopState.thisName} = this;`);
@@ -4273,7 +4277,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
42734277
}
42744278
if (node.kind === SyntaxKind.FunctionDeclaration) {
42754279
// Emit name if one is present, or emit generated name in down-level case (for export default case)
4276-
return !!node.name || languageVersion < ScriptTarget.ES6;
4280+
return !!node.name || modulekind !== ModuleKind.ES6;
42774281
}
42784282
}
42794283

@@ -4455,18 +4459,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
44554459

44564460
write(" __awaiter(this");
44574461
if (hasLexicalArguments) {
4458-
write(", arguments");
4462+
write(", arguments, ");
44594463
}
44604464
else {
4461-
write(", void 0");
4465+
write(", void 0, ");
44624466
}
44634467

44644468
if (promiseConstructor) {
4465-
write(", ");
4466-
emitNodeWithoutSourceMap(promiseConstructor);
4469+
emitEntityNameAsExpression(promiseConstructor, /*useFallback*/ false);
44674470
}
44684471
else {
4469-
write(", Promise");
4472+
write("Promise");
44704473
}
44714474

44724475
// Emit the call to __awaiter.
@@ -4527,7 +4530,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
45274530
}
45284531

45294532
const isAsync = isAsyncFunctionLike(node);
4530-
if (isAsync && languageVersion === ScriptTarget.ES6) {
4533+
if (isAsync) {
45314534
emitAsyncFunctionBodyForES6(node);
45324535
}
45334536
else {
@@ -5108,7 +5111,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
51085111
// emit name if
51095112
// - node has a name
51105113
// - this is default export with static initializers
5111-
if ((node.name || (node.flags & NodeFlags.Default && staticProperties.length > 0)) && !thisNodeIsDecorated) {
5114+
if ((node.name || (node.flags & NodeFlags.Default && (staticProperties.length > 0 || modulekind !== ModuleKind.ES6))) && !thisNodeIsDecorated) {
51125115
write(" ");
51135116
emitDeclarationName(node);
51145117
}
@@ -5729,7 +5732,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
57295732
}
57305733

57315734
/** Serializes the return type of function. Used by the __metadata decorator for a method. */
5732-
function emitSerializedReturnTypeOfNode(node: Node): string | string[] {
5735+
function emitSerializedReturnTypeOfNode(node: Node) {
57335736
if (node && isFunctionLike(node) && (<FunctionLikeDeclaration>node).type) {
57345737
emitSerializedTypeNode((<FunctionLikeDeclaration>node).type);
57355738
return;
@@ -7823,7 +7826,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
78237826
function emitFile({ jsFilePath, sourceMapFilePath, declarationFilePath}: { jsFilePath: string, sourceMapFilePath: string, declarationFilePath: string },
78247827
sourceFiles: SourceFile[], isBundledEmit: boolean) {
78257828
// Make sure not to write js File and source map file if any of them cannot be written
7826-
if (!host.isEmitBlocked(jsFilePath)) {
7829+
if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit) {
78277830
emitJavaScript(jsFilePath, sourceMapFilePath, sourceFiles, isBundledEmit);
78287831
}
78297832
else {

src/compiler/parser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,6 +2259,14 @@ namespace ts {
22592259
property.name = name;
22602260
property.questionToken = questionToken;
22612261
property.type = parseTypeAnnotation();
2262+
2263+
if (token === SyntaxKind.EqualsToken) {
2264+
// Although type literal properties cannot not have initializers, we attempt
2265+
// to parse an initializer so we can report in the checker that an interface
2266+
// property or type literal property cannot have an initializer.
2267+
property.initializer = parseNonParameterInitializer();
2268+
}
2269+
22622270
parseTypeMemberSemicolon();
22632271
return finishNode(property);
22642272
}

src/compiler/types.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,16 @@ namespace ts {
439439

440440
export const enum JsxFlags {
441441
None = 0,
442+
/** An element from a named property of the JSX.IntrinsicElements interface */
442443
IntrinsicNamedElement = 1 << 0,
444+
/** An element inferred from the string index signature of the JSX.IntrinsicElements interface */
443445
IntrinsicIndexedElement = 1 << 1,
444-
ClassElement = 1 << 2,
445-
UnknownElement = 1 << 3,
446+
/** An element backed by a class, class-like, or function value */
447+
ValueElement = 1 << 2,
448+
/** Element resolution failed */
449+
UnknownElement = 1 << 4,
446450

447-
IntrinsicElement = IntrinsicNamedElement | IntrinsicIndexedElement
451+
IntrinsicElement = IntrinsicNamedElement | IntrinsicIndexedElement,
448452
}
449453

450454

@@ -587,6 +591,7 @@ namespace ts {
587591
name: PropertyName; // Declared property name
588592
questionToken?: Node; // Present on optional property
589593
type?: TypeNode; // Optional type annotation
594+
initializer?: Expression; // Optional initializer
590595
}
591596

592597
// @kind(SyntaxKind.PropertyDeclaration)

src/harness/compilerRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class CompilerBaselineRunner extends RunnerBase {
155155

156156
it("Correct JS output for " + fileName, () => {
157157
if (hasNonDtsFiles && this.emit) {
158-
if (result.files.length === 0 && result.errors.length === 0) {
158+
if (!options.noEmit && result.files.length === 0 && result.errors.length === 0) {
159159
throw new Error("Expected at least one js file to be emitted or at least one error to be created.");
160160
}
161161

src/harness/harness.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ namespace Harness {
908908
useCaseSensitiveFileNames?: boolean;
909909
includeBuiltFile?: string;
910910
baselineFile?: string;
911+
libFiles?: string;
911912
}
912913

913914
// Additional options not already in ts.optionDeclarations
@@ -917,6 +918,7 @@ namespace Harness {
917918
{ name: "baselineFile", type: "string" },
918919
{ name: "includeBuiltFile", type: "string" },
919920
{ name: "fileName", type: "string" },
921+
{ name: "libFiles", type: "string" },
920922
{ name: "noErrorTruncation", type: "boolean" }
921923
];
922924

@@ -995,20 +997,17 @@ namespace Harness {
995997
currentDirectory = currentDirectory || Harness.IO.getCurrentDirectory();
996998

997999
// Parse settings
998-
let useCaseSensitiveFileNames = Harness.IO.useCaseSensitiveFileNames();
9991000
if (harnessSettings) {
10001001
setCompilerOptionsFromHarnessSetting(harnessSettings, options);
10011002
}
1002-
if (options.useCaseSensitiveFileNames !== undefined) {
1003-
useCaseSensitiveFileNames = options.useCaseSensitiveFileNames;
1004-
}
10051003
if (options.inferredBaseUrl) {
10061004
options.inferredBaseUrl = ts.getNormalizedAbsolutePath(options.inferredBaseUrl, currentDirectory);
10071005
}
10081006
if (options.rootDirs) {
10091007
options.rootDirs = ts.map(options.rootDirs, d => ts.getNormalizedAbsolutePath(d, currentDirectory));
10101008
}
10111009

1010+
const useCaseSensitiveFileNames = options.useCaseSensitiveFileNames !== undefined ? options.useCaseSensitiveFileNames : Harness.IO.useCaseSensitiveFileNames();
10121011
const programFiles: TestFile[] = inputFiles.slice();
10131012
// Files from built\local that are requested by test "@includeBuiltFiles" to be in the context.
10141013
// Treat them as library files, so include them in build, but not in baselines.
@@ -1023,6 +1022,15 @@ namespace Harness {
10231022

10241023
const fileOutputs: GeneratedFile[] = [];
10251024

1025+
// Files from tests\lib that are requested by "@libFiles"
1026+
if (options.libFiles) {
1027+
for (const fileName of options.libFiles.split(",")) {
1028+
const libFileName = "tests/lib/" + fileName;
1029+
programFiles.push({ unitName: libFileName, content: normalizeLineEndings(IO.readFile(libFileName), Harness.IO.newLine()) });
1030+
}
1031+
}
1032+
1033+
10261034
const programFileNames = programFiles.map(file => file.unitName);
10271035

10281036
const compilerHost = createCompilerHost(

0 commit comments

Comments
 (0)