mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Fix default behavior for transpileModule when fileName not provided (#32982)
This commit is contained in:
parent
6ca9d04b60
commit
1bf218291f
@ -66,7 +66,7 @@ namespace ts {
|
||||
options.noResolve = true;
|
||||
|
||||
// if jsx is specified then treat file as .tsx
|
||||
const inputFileName = transpileOptions.fileName || (options.jsx ? "module.tsx" : "module.ts");
|
||||
const inputFileName = transpileOptions.fileName || (transpileOptions.compilerOptions && transpileOptions.compilerOptions.jsx ? "module.tsx" : "module.ts");
|
||||
const sourceFile = createSourceFile(inputFileName, input, options.target!); // TODO: GH#18217
|
||||
if (transpileOptions.moduleName) {
|
||||
sourceFile.moduleName = transpileOptions.moduleName;
|
||||
|
||||
@ -3,6 +3,7 @@ namespace ts {
|
||||
|
||||
interface TranspileTestSettings {
|
||||
options?: TranspileOptions;
|
||||
noSetFileName?: boolean;
|
||||
}
|
||||
|
||||
function transpilesCorrectly(name: string, input: string, testSettings: TranspileTestSettings) {
|
||||
@ -30,15 +31,19 @@ namespace ts {
|
||||
|
||||
transpileOptions.compilerOptions.sourceMap = true;
|
||||
|
||||
if (!transpileOptions.fileName) {
|
||||
transpileOptions.fileName = transpileOptions.compilerOptions.jsx ? "file.tsx" : "file.ts";
|
||||
let unitName = transpileOptions.fileName;
|
||||
if (!unitName) {
|
||||
unitName = transpileOptions.compilerOptions.jsx ? "file.tsx" : "file.ts";
|
||||
if (!testSettings.noSetFileName) {
|
||||
transpileOptions.fileName = unitName;
|
||||
}
|
||||
}
|
||||
|
||||
transpileOptions.reportDiagnostics = true;
|
||||
|
||||
justName = "transpile/" + name.replace(/[^a-z0-9\-. ]/ig, "") + (transpileOptions.compilerOptions.jsx ? Extension.Tsx : Extension.Ts);
|
||||
toBeCompiled = [{
|
||||
unitName: transpileOptions.fileName,
|
||||
unitName,
|
||||
content: input
|
||||
}];
|
||||
|
||||
@ -456,5 +461,9 @@ var x = 0;`, {
|
||||
transpilesCorrectly("Supports 'as const' arrays", `([] as const).forEach(k => console.log(k));`, {
|
||||
options: { compilerOptions: { module: ModuleKind.CommonJS } }
|
||||
});
|
||||
|
||||
transpilesCorrectly("Infer correct file extension", `const fn = <T>(a: T) => a`, {
|
||||
noSetFileName: true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -0,0 +1,2 @@
|
||||
var fn = function (a) { return a; };
|
||||
//# sourceMappingURL=module.js.map
|
||||
@ -0,0 +1,2 @@
|
||||
var fn = function (a) { return a; };
|
||||
//# sourceMappingURL=module.js.map
|
||||
Loading…
x
Reference in New Issue
Block a user