Skip to content

Commit fce9f32

Browse files
committed
When tsconfig file doesnt contain file names, consume .js files of directory only if specified in the options
1 parent 68c65cd commit fce9f32

File tree

31 files changed

+144
-8
lines changed

31 files changed

+144
-8
lines changed

src/compiler/commandLineParser.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ namespace ts {
245245
},
246246
description: Diagnostics.Specifies_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
247247
error: Diagnostics.Argument_for_moduleResolution_option_must_be_node_or_classic,
248+
},
249+
{
250+
name: "consumeJsFiles",
251+
type: "boolean",
248252
}
249253
];
250254

@@ -414,8 +418,9 @@ namespace ts {
414418
export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine {
415419
let errors: Diagnostic[] = [];
416420

421+
let options = getCompilerOptions();
417422
return {
418-
options: getCompilerOptions(),
423+
options,
419424
fileNames: getFileNames(),
420425
errors
421426
};
@@ -474,7 +479,10 @@ namespace ts {
474479
}
475480
else {
476481
let exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
477-
let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude)).concat(host.readDirectory(basePath, ".js", exclude));
482+
let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
483+
if (options.consumeJsFiles) {
484+
sysFiles = sysFiles.concat(host.readDirectory(basePath, ".js", exclude));
485+
}
478486
for (let i = 0; i < sysFiles.length; i++) {
479487
let name = sysFiles[i];
480488
if (fileExtensionIs(name, ".js")) {

src/compiler/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,8 @@ namespace ts {
20612061
experimentalDecorators?: boolean;
20622062
experimentalAsyncFunctions?: boolean;
20632063
emitDecoratorMetadata?: boolean;
2064-
moduleResolution?: ModuleResolutionKind
2064+
moduleResolution?: ModuleResolutionKind;
2065+
consumeJsFiles?: boolean;
20652066
/* @internal */ stripInternal?: boolean;
20662067

20672068
// Skip checking lib.d.ts to help speed up tests.

tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecified/amd/jsFileCompilationDifferentNamesNotSpecified.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"project": "DifferentNamesNotSpecified",
77
"resolvedInputFiles": [
88
"lib.d.ts",
9-
"DifferentNamesNotSpecified/a.ts",
10-
"DifferentNamesNotSpecified/b.js"
9+
"DifferentNamesNotSpecified/a.ts"
1110
],
1211
"emittedFiles": [
1312
"test.js",

tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecified/node/jsFileCompilationDifferentNamesNotSpecified.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"project": "DifferentNamesNotSpecified",
77
"resolvedInputFiles": [
88
"lib.d.ts",
9-
"DifferentNamesNotSpecified/a.ts",
10-
"DifferentNamesNotSpecified/b.js"
9+
"DifferentNamesNotSpecified/a.ts"
1110
],
1211
"emittedFiles": [
1312
"test.js",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"scenario": "Verify when different named .ts and .js file exists in the folder and tsconfig.json doesnt specify any files and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "DifferentNamesNotSpecifiedWithConsumeJsFiles",
7+
"resolvedInputFiles": [
8+
"lib.d.ts",
9+
"DifferentNamesNotSpecifiedWithConsumeJsFiles/a.ts",
10+
"DifferentNamesNotSpecifiedWithConsumeJsFiles/b.js"
11+
],
12+
"emittedFiles": [
13+
"test.js",
14+
"test.d.ts"
15+
]
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var test: number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test = 10;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"scenario": "Verify when different named .ts and .js file exists in the folder and tsconfig.json doesnt specify any files and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "DifferentNamesNotSpecifiedWithConsumeJsFiles",
7+
"resolvedInputFiles": [
8+
"lib.d.ts",
9+
"DifferentNamesNotSpecifiedWithConsumeJsFiles/a.ts",
10+
"DifferentNamesNotSpecifiedWithConsumeJsFiles/b.js"
11+
],
12+
"emittedFiles": [
13+
"test.js",
14+
"test.d.ts"
15+
]
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var test: number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test = 10;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"scenario": "Verify when same named .ts and .js file exists in the folder but no file is specified in tsconfig.json and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "SameNameDTsNotSpecifiedWithConsumeJsFiles",
7+
"resolvedInputFiles": [
8+
"lib.d.ts",
9+
"SameNameDTsNotSpecifiedWithConsumeJsFiles/a.d.ts"
10+
],
11+
"emittedFiles": []
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"scenario": "Verify when same named .ts and .js file exists in the folder but no file is specified in tsconfig.json and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "SameNameDTsNotSpecifiedWithConsumeJsFiles",
7+
"resolvedInputFiles": [
8+
"lib.d.ts",
9+
"SameNameDTsNotSpecifiedWithConsumeJsFiles/a.d.ts"
10+
],
11+
"emittedFiles": []
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var test: number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test = 10;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"scenario": "Verify when same named .ts and .js file exists in the folder but no file is specified in tsconfig.json and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "SameNameFilesNotSpecifiedWithConsumeJsFiles",
7+
"resolvedInputFiles": [
8+
"lib.d.ts",
9+
"SameNameFilesNotSpecifiedWithConsumeJsFiles/a.ts"
10+
],
11+
"emittedFiles": [
12+
"SameNameFilesNotSpecifiedWithConsumeJsFiles/a.js",
13+
"SameNameFilesNotSpecifiedWithConsumeJsFiles/a.d.ts"
14+
]
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var test: number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test = 10;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"scenario": "Verify when same named .ts and .js file exists in the folder but no file is specified in tsconfig.json and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "SameNameFilesNotSpecifiedWithConsumeJsFiles",
7+
"resolvedInputFiles": [
8+
"lib.d.ts",
9+
"SameNameFilesNotSpecifiedWithConsumeJsFiles/a.ts"
10+
],
11+
"emittedFiles": [
12+
"SameNameFilesNotSpecifiedWithConsumeJsFiles/a.js",
13+
"SameNameFilesNotSpecifiedWithConsumeJsFiles/a.d.ts"
14+
]
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"scenario": "Verify when different named .ts and .js file exists in the folder and tsconfig.json doesnt specify any files and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "DifferentNamesNotSpecifiedWithConsumeJsFiles"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"scenario": "Verify when same named .ts and .js file exists in the folder but no file is specified in tsconfig.json and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "SameNameDTsNotSpecifiedWithConsumeJsFiles"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"scenario": "Verify when same named .ts and .js file exists in the folder but no file is specified in tsconfig.json and consumeJsFiles is true",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": true,
6+
"project": "SameNameFilesNotSpecifiedWithConsumeJsFiles"
7+
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
var test2 = 10; // Should get compiled
1+
var test2 = 10; // Shouldnt get compiled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test = 10;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test2 = 10; // Should get compiled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"out": "test.js",
4+
"consumeJsFiles": true
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var a: number;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test1 = 10; // Shouldnt get compiled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "compilerOptions": { "consumeJsFiles": true } }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test1 = 10; // Shouldnt get compiled
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var test = 10;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "compilerOptions": { "consumeJsFiles": true } }

0 commit comments

Comments
 (0)