8000 Merge pull request #8223 from Microsoft/typeReferenceDirectives · creatio/TypeScript@3667b30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3667b30

Browse files
committed
Merge pull request microsoft#8223 from Microsoft/typeReferenceDirectives
[Transforms] Fix type reference directive tests by adding --module amd
2 parents a86188c + 1814569 commit 3667b30

10 files changed

+50
-9
lines changed

src/compiler/program.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,10 @@ namespace ts {
20762076
}
20772077

20782078
// Cannot specify module gen that isn't amd or system with --out
2079-
if (outFile && options.module && !(options.module === ModuleKind.AMD || options.module === ModuleKind.System)) {
2079+
// Report this error if user specified --module moduleKind
2080+
// or if there is external module in compilation which defaults to commonjs
2081+
const emitModuleKind = getEmitModuleKind(options);
2082+
if (outFile && (options.module || firstExternalModuleSourceFile) && !(emitModuleKind === ModuleKind.AMD || emitModuleKind === ModuleKind.System)) {
20802083
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile"));
20812084
}
20822085

tests/baselines/reference/isolatedModulesOut.errors.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
error TS5053: Option 'out' cannot be specified with option 'isolatedModules'.
2+
error TS6082: Only 'amd' and 'system' modules are supported alongside --out.
23
tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided.
34

45

56
!!! error TS5053: Option 'out' cannot be specified with option 'isolatedModules'.
7+
!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out.
68
==== tests/cases/compiler/file1.ts (0 errors) ====
79

810
export var x;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error TS6082: Only 'amd' and 'system' modules are supported alongside --out.
2+
3+
4+
!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out.
5+
==== tests/cases/compiler/optionsOutAndNoModuleGen.ts (0 errors) ====
6+
7+
export var x = 10;

tests/baselines/reference/typeReferenceDirectives11.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ import {foo} from "./mod1";
1515
export const bar = foo();
1616

1717
//// [output.js]
18+
define("mod1", ["require", "exports"], function (require, exports) {
19+
"use strict";
20+
function foo() { return { x: 1 }; }
21+
exports.foo = foo;
22+
});
23+
define("mod2", ["require", "exports", "mod1"], function (require, exports, mod1_1) {
24+
"use strict";
25+
exports.bar = mod1_1.foo();
26+
});
1827

1928

2029
//// [output.d.ts]

tests/baselines/reference/typeReferenceDirectives11.trace.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"File '/types/lib/index.d.ts' exist - use it as a name resolution result.",
66
"======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========",
77
"======== Resolving module './mod1' from '/mod2.ts'. ========",
8-
"Module resolution kind is not specified, using 'NodeJs'.",
9-
"Loading module as file / folder, candidate module location '/mod1'.",
8+
"Module resolution kind is not specified, using 'Classic'.",
109
"File '/mod1.ts' exist - use it as a name resolution result.",
1110
"======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========"
1211
]

tests/baselines/reference/typeReferenceDirectives12.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,26 @@ export const foo = new Cls().foo();
3434
export const bar = Cls.bar();
3535

3636
//// [output.js]
37+
define("main", ["require", "exports"], function (require, exports) {
38+
"use strict";
39+
var Cls = (function () {
40+
function Cls() {
41+
}
42+
return Cls;
43+
}());
44+
exports.Cls = Cls;
45+
});
3746
/// <reference types="lib" />
47+
define("mod1", ["require", "exports", "main"], function (require, exports, main_1) {
48+
"use strict";
49+
main_1.Cls.prototype.foo = function () { return undefined; };
50+
});
51+
define("mod2", ["require", "exports", "main", "mod1"], function (require, exports, main_2) {
52+
"use strict";
53+
exports.cls = main_2.Cls;
54+
exports.foo = new main_2.Cls().foo();
55+
exports.bar = main_2.Cls.bar();
56+
});
3857

3958

4059
//// [output.d.ts]
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
[
22
"======== Resolving module './main' from '/mod2.ts'. ========",
3-
"Module resolution kind is not specified, using 'NodeJs'.",
4-
"Loading module as file / folder, candidate module location '/main'.",
3+
"Module resolution kind is not specified, using 'Classic'.",
54
"File '/main.ts' exist - use it as a name resolution result.",
65
"======== Module name './main' was successfully resolved to '/main.ts'. ========",
76
"======== Resolving module './mod1' from '/mod2.ts'. ========",
8-
"Module resolution kind is not specified, using 'NodeJs'.",
9-
"Loading module as file / folder, candidate module location '/mod1'.",
7+
"Module resolution kind is not specified, using 'Classic'.",
108
"File '/mod1.ts' exist - use it as a name resolution result.",
119
"======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========",
1210
"======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/'. ========",
@@ -15,8 +13,7 @@
1513
"File '/types/lib/index.d.ts' exist - use it as a name resolution result.",
1614
"======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========",
1715
"======== Resolving module './main' from '/mod1.ts'. ========",
18-
"Module resolution kind is not specified, using 'NodeJs'.",
19-
"Loading module as file / folder, candidate module location '/main'.",
16+
"Module resolution kind is not specified, using 'Classic'.",
2017
"File '/main.ts' exist - use it as a name resolution result.",
2118
"======== Module name './main' was successfully resolved to '/main.ts'. ========"
2219
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @out: output.js
2+
3+
export var x = 10;

tests/cases/compiler/typeReferenceDirectives11.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// @traceResolution: true
55
// @types: lib
66
// @out: output.js
7+
// @module: amd
78

89
// @filename: /types/lib/index.d.ts
910

tests/cases/compiler/typeReferenceDirectives12.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// @typesRoot: /
44
// @traceResolution: true
55
// @out: output.js
6+
// @module: amd
67

78
// @filename: /types/lib/index.d.ts
89

0 commit comments

Comments
 (0)
0