Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1bf2182

Browse filesBrowse files
authored
Fix default behavior for transpileModule when fileName not provided (microsoft#32982)
1 parent 6ca9d04 commit 1bf2182
Copy full SHA for 1bf2182

4 files changed

+17-4Lines changed: 17 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/services/transpile.ts‎

Copy file name to clipboardExpand all lines: src/services/transpile.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace ts {
6666
options.noResolve = true;
6767

6868
// if jsx is specified then treat file as .tsx
69-
const inputFileName = transpileOptions.fileName || (options.jsx ? "module.tsx" : "module.ts");
69+
const inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
7070
const sourceFile = createSourceFile(inputFileName, input, options.target!); // TODO: GH#18217
7171
if (transpileOptions.moduleName) {
7272
sourceFile.moduleName = transpileOptions.moduleName;
Collapse file

‎src/testRunner/unittests/services/transpile.ts‎

Copy file name to clipboardExpand all lines: src/testRunner/unittests/services/transpile.ts
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace ts {
33

44
interface TranspileTestSettings {
55
options?: TranspileOptions;
6+
noSetFileName?: boolean;
67
}
78

89
function transpilesCorrectly(name: string, input: string, testSettings: TranspileTestSettings) {
@@ -30,15 +31,19 @@ namespace ts {
3031

3132
transpileOptions.compilerOptions.sourceMap = true;
3233

33-
if (!transpileOptions.fileName) {
34-
transpileOptions.fileName = transpileOptions.compilerOptions.jsx ? "file.tsx" : "file.ts";
34+
let unitName = transpileOptions.fileName;
35+
if (!unitName) {
36+
unitName = transpileOptions.compilerOptions.jsx ? "file.tsx" : "file.ts";
37+
if (!testSettings.noSetFileName) {
38+
transpileOptions.fileName = unitName;
39+
}
3540
}
3641

3742
transpileOptions.reportDiagnostics = true;
3843

3944
justName = "transpile/" + name.replace(/[^a-z0-9\-. ]/ig, "") + (transpileOptions.compilerOptions.jsx ? Extension.Tsx : Extension.Ts);
4045
toBeCompiled = [{
41-
unitName: transpileOptions.fileName,
46+
unitName,
4247
content: input
4348
}];
4449

@@ -456,5 +461,9 @@ var x = 0;`, {
456461
transpilesCorrectly("Supports 'as const' arrays", `([] as const).forEach(k => console.log(k));`, {
457462
options: { compilerOptions: { module: ModuleKind.CommonJS } }
458463
});
464+
465+
transpilesCorrectly("Infer correct file extension", `const fn = <T>(a: T) => a`, {
466+
noSetFileName: true
467+
});
459468
});
460469
}
Collapse file

‎tests/baselines/reference/transpile/Infer correct file extension.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/transpile/Infer correct file extension.js
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎tests/baselines/reference/transpile/Infer correct file extension.oldTranspile.js‎

Copy file name to clipboardExpand all lines: tests/baselines/reference/transpile/Infer correct file extension.oldTranspile.js
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.