Skip to content

Commit 67b2f13

Browse files
Merge branch 'master' into layering
Conflicts: src/compiler/parser.ts
2 parents b155351 + 6fed3e2 commit 67b2f13

12 files changed

Lines changed: 111 additions & 15 deletions

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3342,7 +3342,7 @@ module ts {
33423342
}
33433343

33443344
function isContextSensitiveFunctionLikeDeclaration(node: FunctionLikeDeclaration) {
3345-
return !node.typeParameters && !forEach(node.parameters, p => p.type);
3345+
return !node.typeParameters && node.parameters.length && !forEach(node.parameters, p => p.type);
33463346
}
33473347

33483348
function getTypeWithoutConstructors(type: Type): Type {

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ module ts {
5454
paramType: Diagnostics.KIND,
5555
error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd
5656
},
57+
{
58+
name: "noEmit",
59+
type: "boolean",
60+
description: Diagnostics.Do_not_emit_outputs,
61+
},
5762
{
5863
name: "noEmitOnError",
5964
type: "boolean",

src/compiler/diagnosticInformationMap.generated.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ module ts {
380380
Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" },
381381
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5038, category: DiagnosticCategory.Error, key: "Option mapRoot cannot be specified without specifying sourcemap option." },
382382
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: { code: 5039, category: DiagnosticCategory.Error, key: "Option sourceRoot cannot be specified without specifying sourcemap option." },
383+
Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option out or outDir." },
384+
Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option noEmit cannot be specified with option declaration." },
383385
Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." },
384386
Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." },
385387
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." },
@@ -389,6 +391,7 @@ module ts {
389391
Do_not_erase_const_enum_declarations_in_generated_code: { code: 6007, category: DiagnosticCategory.Message, key: "Do not erase const enum declarations in generated code." },
390392
Do_not_emit_outputs_if_any_type_checking_errors_were_reported: { code: 6008, category: DiagnosticCategory.Message, key: "Do not emit outputs if any type checking errors were reported." },
391393
Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." },
394+
Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." },
392395
Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" },
393396
Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" },
394397
Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." },

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,14 @@
16161616
"category": "Error",
16171617
"code": 5039
16181618
},
1619+
"Option noEmit cannot be specified with option out or outDir.": {
1620+
"category": "Error",
1621+
"code": 5040
1622+
},
1623+
"Option noEmit cannot be specified with option declaration.": {
1624+
"category": "Error",
1625+
"code": 5041
1626+
},
16191627
"Concatenate and emit output to single file.": {
16201628
"category": "Message",
16211629
"code": 6001
@@ -1652,6 +1660,10 @@
16521660
"category": "Message",
16531661
"code": 6009
16541662
},
1663+
"Do not emit outputs.": {
1664+
"category": "Message",
1665+
"code": 6010
1666+
},
16551667
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)": {
16561668
"category": "Message",
16571669
"code": 6015

src/compiler/program.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ module ts {
8888
verifyCompilerOptions();
8989
errors.sort(compareDiagnostics);
9090

91+
9192
var diagnosticsProducingTypeChecker: TypeChecker;
9293
var noDiagnosticsTypeChecker: TypeChecker;
9394
var emitHost: EmitHost;
@@ -145,9 +146,7 @@ module ts {
145146
function invokeEmitter(targetSourceFile?: SourceFile) {
146147
var resolver = getDiagnosticsProducingTypeChecker().getEmitResolver();
147148
return emitFiles(resolver, getEmitHost(), targetSourceFile);
148-
}
149-
150-
function getSourceFile(filename: string) {
149+
} function getSourceFile(filename: string) {
151150
filename = host.getCanonicalFileName(filename);
152151
return hasProperty(filesByName, filename) ? filesByName[filename] : undefined;
153152
}
@@ -218,8 +217,13 @@ module ts {
218217

219218
// We haven't looked for this file, do so now and cache result
220219
var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, hostErrorMessage => {
221-
errors.push(createFileDiagnostic(refFile, refStart, refLength,
222-
Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
220+
if (refFile) {
221+
errors.push(createFileDiagnostic(refFile, refStart, refLength,
222+
Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
223+
}
224+
else {
225+
errors.push(createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
226+
}
223227
});
224228
if (file) {
225229
seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib;
@@ -389,6 +393,16 @@ module ts {
389393
commonSourceDirectory += directorySeparator;
390394
}
391395
}
396+
397+
if (options.noEmit) {
398+
if (options.out || options.outDir) {
399+
errors.push(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_out_or_outDir));
400+
}
401+
402+
if (options.declaration) {
403+
errors.push(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
404+
}
405+
}
392406
}
393407
}
394408
}

src/compiler/tsc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ module ts {
289289
if (program.isEmitBlocked()) {
290290
exitStatus = EmitReturnStatus.AllOutputGenerationSkipped;
291291
}
292+
else if (compilerOptions.noEmit) {
293+
exitStatus = EmitReturnStatus.Succeeded;
294+
}
292295
else {
293296
var emitStart = new Date().getTime();
294297
var emitOutput = program.emitFiles();

src/compiler/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ module ts {
974974

975975
// Return code used by getEmitOutput function to indicate status of the function
976976
export enum EmitReturnStatus {
977-
Succeeded = 0, // All outputs generated as requested (.js, .map, .d.ts), no errors reported
977+
Succeeded = 0, // All outputs generated if requested (.js, .map, .d.ts), no errors reported
978978
AllOutputGenerationSkipped = 1, // No .js generated because of syntax errors, nothing generated
979979
JSGeneratedWithSemanticErrors = 2, // .js and .map generated with semantic errors
980980
DeclarationGenerationSkipped = 3, // .d.ts generation skipped because of semantic errors or declaration emitter specific errors; Output .js with semantic errors
@@ -1453,6 +1453,7 @@ module ts {
14531453
locale?: string;
14541454
mapRoot?: string;
14551455
module?: ModuleKind;
1456+
noEmit?: boolean;
14561457
noEmitOnError?: boolean;
14571458
noErrorTruncation?: boolean;
14581459
noImplicitAny?: boolean;
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(2,22): error TS2339: Property 'foo' does not exist on type 'string'.
2-
tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts(3,10): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
3-
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
42

53

6-
==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (2 errors) ====
4+
==== tests/cases/compiler/contextualTypingWithFixedTypeParameters1.ts (1 errors) ====
75
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
86
f10('', () => a => a.foo, ''); // a is string
97
~~~
108
!!! error TS2339: Property 'foo' does not exist on type 'string'.
11-
var r9 = f10('', () => (a => a.foo), 1); // error
12-
~~~
13-
!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
14-
!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'.
9+
var r9 = f10('', () => (a => a.foo), 1); // error
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [inferenceFromParameterlessLambda.ts]
2+
function foo<T>(o: Take<T>, i: Make<T>) { }
3+
interface Make<T> {
4+
(): T;
5+
}
6+
interface Take<T> {
7+
(n: T): void;
8+
}
9+
// Infer string from second argument because it isn't context sensitive
10+
foo(n => n.length, () => 'hi');
11+
12+
13+
//// [inferenceFromParameterlessLambda.js]
14+
function foo(o, i) {
15+
}
16+
// Infer string from second argument because it isn't context sensitive
17+
foo(function (n) { return n.length; }, function () { return 'hi'; });
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/inferenceFromParameterlessLambda.ts ===
2+
function foo<T>(o: Take<T>, i: Make<T>) { }
3+
>foo : <T>(o: Take<T>, i: Make<T>) => void
4+
>T : T
5+
>o : Take<T>
6+
>Take : Take<T>
7+
>T : T
8+
>i : Make<T>
9+
>Make : Make<T>
10+
>T : T
11+
12+
interface Make<T> {
13+
>Make : Make<T>
14+
>T : T
15+
16+
(): T;
17+
>T : T
18+
}
19+
interface Take<T> {
20+
>Take : Take<T>
21+
>T : T
22+
23+
(n: T): void;
24+
>n : T
25+
>T : T
26+
}
27+
// Infer string from second argument because it isn't context sensitive
28+
foo(n => n.length, () => 'hi');
29+
>foo(n => n.length, () => 'hi') : void
30+
>foo : <T>(o: Take<T>, i: Make<T>) => void
31+
>n => n.length : (n: string) => number
32+
>n : string
33+
>n.length : number
34+
>n : string
35+
>length : number
36+
>() => 'hi' : () => string
37+

0 commit comments

Comments
 (0)