@@ -19,7 +19,7 @@ func TestESModuleTransformer(t *testing.T) {
19
19
output string
20
20
other string
21
21
jsx bool
22
- options core.CompilerOptions
22
+ options * core.CompilerOptions
23
23
}{
24
24
// ImportDeclaration
25
25
{
@@ -31,19 +31,19 @@ func TestESModuleTransformer(t *testing.T) {
31
31
title : "ImportDeclaration#2" ,
32
32
input : `import "./other.ts"` ,
33
33
output : `import "./other.js";` ,
34
- options : core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
34
+ options : & core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
35
35
},
36
36
{
37
37
title : "ImportDeclaration#3" ,
38
38
input : `import "./other.tsx"` ,
39
39
output : `import "./other.js";` ,
40
- options : core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
40
+ options : & core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
41
41
},
42
42
{
43
43
title : "ImportDeclaration#4" ,
44
44
input : `import "./other.tsx"` ,
45
45
output : `import "./other.jsx";` ,
46
- options : core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue , Jsx : core .JsxEmitPreserve },
46
+ options : & core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue , Jsx : core .JsxEmitPreserve },
47
47
},
48
48
49
49
// ImportEqualsDeclaration
@@ -58,31 +58,31 @@ func TestESModuleTransformer(t *testing.T) {
58
58
output : `import { createRequire as _createRequire } from "module";
59
59
const __require = _createRequire(import.meta.url);
60
60
const x = __require("other");` ,
61
- options : core.CompilerOptions {Module : core .ModuleKindNode16 },
61
+ options : & core.CompilerOptions {Module : core .ModuleKindNode16 },
62
62
},
63
63
{
64
64
title : "ImportEqualsDeclaration#3" ,
65
65
input : `import x = require("./other.ts")` ,
66
66
output : `import { createRequire as _createRequire } from "module";
67
67
const __require = _createRequire(import.meta.url);
68
68
const x = __require("./other.js");` ,
69
- options : core.CompilerOptions {Module : core .ModuleKindNode16 , RewriteRelativeImportExtensions : core .TSTrue },
69
+ options : & core.CompilerOptions {Module : core .ModuleKindNode16 , RewriteRelativeImportExtensions : core .TSTrue },
70
70
},
71
71
{
72
72
title : "ImportEqualsDeclaration#4" ,
73
73
input : `import x = require("./other.tsx")` ,
74
74
output : `import { createRequire as _createRequire } from "module";
75
75
const __require = _createRequire(import.meta.url);
76
76
const x = __require("./other.js");` ,
77
- options : core.CompilerOptions {Module : core .ModuleKindNode16 , RewriteRelativeImportExtensions : core .TSTrue },
77
+ options : & core.CompilerOptions {Module : core .ModuleKindNode16 , RewriteRelativeImportExtensions : core .TSTrue },
78
78
},
79
79
{
80
80
title : "ImportEqualsDeclaration#5" ,
81
81
input : `import x = require("./other.tsx")` ,
82
82
output : `import { createRequire as _createRequire } from "module";
83
83
const __require = _createRequire(import.meta.url);
84
84
const x = __require("./other.jsx");` ,
85
- options : core.CompilerOptions {Module : core .ModuleKindNode16 , RewriteRelativeImportExtensions : core .TSTrue , Jsx : core .JsxEmitPreserve },
85
+ options : & core.CompilerOptions {Module : core .ModuleKindNode16 , RewriteRelativeImportExtensions : core .TSTrue , Jsx : core .JsxEmitPreserve },
86
86
},
87
87
{
88
88
title : "ImportEqualsDeclaration#6" ,
@@ -91,7 +91,7 @@ const x = __require("./other.jsx");`,
91
91
const __require = _createRequire(import.meta.url);
92
92
const x = __require("other");
93
93
export { x };` ,
94
- options : core.CompilerOptions {Module : core .ModuleKindNode16 },
94
+ options : & core.CompilerOptions {Module : core .ModuleKindNode16 },
95
95
},
96
96
97
97
// ExportAssignment
@@ -104,7 +104,7 @@ export { x };`,
104
104
title : "ExportAssignment#2" ,
105
105
input : `export = x` ,
106
106
output : `module.exports = x;` ,
107
- options : core.CompilerOptions {Module : core .ModuleKindPreserve },
107
+ options : & core.CompilerOptions {Module : core .ModuleKindPreserve },
108
108
},
109
109
110
110
// ExportDeclaration
@@ -117,13 +117,13 @@ export { x };`,
117
117
title : "ExportDeclaration#2" ,
118
118
input : `export * from "./other.ts";` ,
119
119
output : `export * from "./other.js";` ,
120
- options : core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
120
+ options : & core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
121
121
},
122
122
{
123
123
title : "ExportDeclaration#3" ,
124
124
input : `export * as x from "other";` ,
125
125
output : `export * as x from "other";` ,
126
- options : core.CompilerOptions {Module : core .ModuleKindESNext },
126
+ options : & core.CompilerOptions {Module : core .ModuleKindESNext },
127
127
},
128
128
{
129
129
title : "ExportDeclaration#4" ,
@@ -160,7 +160,7 @@ export default default_1;`,
160
160
import("./other.ts");` ,
161
161
output : `export {};
162
162
import("./other.js");` ,
163
- options : core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
163
+ options : & core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
164
164
},
165
165
{
166
166
title : "CallExpression#4" ,
@@ -176,7 +176,7 @@ import(x);`,
176
176
};
177
177
export {};
178
178
import(__rewriteRelativeImportExtension(x));` ,
179
- options : core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
179
+ options : & core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue },
180
180
},
181
181
{
182
182
title : "CallExpression#5" ,
@@ -192,7 +192,7 @@ import(x);`,
192
192
};
193
193
export {};
194
194
import(__rewriteRelativeImportExtension(x, true));` ,
195
- options : core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue , Jsx : core .JsxEmitPreserve },
195
+ options : & core.CompilerOptions {RewriteRelativeImportExtensions : core .TSTrue , Jsx : core .JsxEmitPreserve },
196
196
},
197
197
{
198
198
title : "CallExpression#6" ,
@@ -201,7 +201,7 @@ import(x);`,
201
201
output : `import { __rewriteRelativeImportExtension } from "tslib";
202
202
export {};
203
203
import(__rewriteRelativeImportExtension(x));` ,
204
- options : core.CompilerOptions {Module : core .ModuleKindESNext , RewriteRelativeImportExtensions : core .TSTrue , ImportHelpers : core .TSTrue },
204
+ options : & core.CompilerOptions {Module : core .ModuleKindESNext , RewriteRelativeImportExtensions : core .TSTrue , ImportHelpers : core .TSTrue },
205
205
},
206
206
{
207
207
title : "CallExpression#7" ,
@@ -212,14 +212,18 @@ var __rewriteRelativeImportExtension;`,
212
212
export {};
213
213
import(__rewriteRelativeImportExtension_1(x));
214
214
var __rewriteRelativeImportExtension;` ,
215
- options : core.CompilerOptions {Module : core .ModuleKindESNext , RewriteRelativeImportExtensions : core .TSTrue , ImportHelpers : core .TSTrue },
215
+ options : & core.CompilerOptions {Module : core .ModuleKindESNext , RewriteRelativeImportExtensions : core .TSTrue , ImportHelpers : core .TSTrue },
216
216
},
217
217
}
218
218
for _ , rec := range data {
219
219
t .Run (rec .title , func (t * testing.T ) {
220
220
t .Parallel ()
221
221
222
222
compilerOptions := rec .options
223
+ if compilerOptions == nil {
224
+ compilerOptions = & core.CompilerOptions {}
225
+ }
226
+
223
227
sourceFileAffecting := compilerOptions .SourceFileAffecting ()
224
228
file := parsetestutil .ParseTypeScript (rec .input , rec .jsx )
225
229
parsetestutil .CheckDiagnostics (t , file )
@@ -233,10 +237,10 @@ var __rewriteRelativeImportExtension;`,
233
237
}
234
238
235
239
emitContext := printer .NewEmitContext ()
236
- resolver := binder .NewReferenceResolver (& compilerOptions , binder.ReferenceResolverHooks {})
240
+ resolver := binder .NewReferenceResolver (compilerOptions , binder.ReferenceResolverHooks {})
237
241
238
- file = NewRuntimeSyntaxTransformer (emitContext , & compilerOptions , resolver ).TransformSourceFile (file )
239
- file = NewESModuleTransformer (emitContext , & compilerOptions , resolver , fakeGetEmitModuleFormatOfFile ).TransformSourceFile (file )
242
+ file = NewRuntimeSyntaxTransformer (emitContext , compilerOptions , resolver ).TransformSourceFile (file )
243
+ file = NewESModuleTransformer (emitContext , compilerOptions , resolver , fakeGetEmitModuleFormatOfFile ).TransformSourceFile (file )
240
244
emittestutil .CheckEmit (t , emitContext , file , rec .output )
241
245
})
242
246
}
0 commit comments