mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 07:45:18 -06:00
Emit amd-module and amd-dependency comments in emitter if printing declaration comments (#22740)
* Emit amd-module and amd-dependency comments in emitter if printing declaration comments * Move code a bit * Move again
This commit is contained in:
parent
509a53fea7
commit
43a482f03f
@ -2481,6 +2481,21 @@ namespace ts {
|
||||
}
|
||||
|
||||
function emitTripleSlashDirectives(files: ReadonlyArray<FileReference>, types: ReadonlyArray<FileReference>) {
|
||||
if (currentSourceFile && currentSourceFile.moduleName) {
|
||||
write(`/// <amd-module name="${currentSourceFile.moduleName}" />`);
|
||||
writeLine();
|
||||
}
|
||||
if (currentSourceFile && currentSourceFile.amdDependencies) {
|
||||
for (const dep of currentSourceFile.amdDependencies) {
|
||||
if (dep.name) {
|
||||
write(`/// <amd-dependency name="${dep.name}" path="${dep.path}" />`);
|
||||
}
|
||||
else {
|
||||
write(`/// <amd-dependency path="${dep.path}" />`);
|
||||
}
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
for (const directive of files) {
|
||||
write(`/// <reference path="${directive.fileName}" />`);
|
||||
writeLine();
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
//// [tests/cases/compiler/declarationEmitAmdModuleNameDirective.ts] ////
|
||||
|
||||
//// [foo.ts]
|
||||
/// <amd-module name="name_of_foo"/>
|
||||
export const foo = 1;
|
||||
//// [bar.ts]
|
||||
/// <amd-dependency name="name_of_foo" path="./foo" />
|
||||
import {foo} from './foo';
|
||||
void foo;
|
||||
|
||||
//// [foo.js]
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") {
|
||||
var v = factory(require, exports);
|
||||
if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === "function" && define.amd) {
|
||||
define("name_of_foo", ["require", "exports"], factory);
|
||||
}
|
||||
})(function (require, exports) {
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
/// <amd-module name="name_of_foo"/>
|
||||
exports.foo = 1;
|
||||
});
|
||||
//// [bar.js]
|
||||
(function (factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") {
|
||||
var v = factory(require, exports);
|
||||
if (v !== undefined) module.exports = v;
|
||||
}
|
||||
else if (typeof define === "function" && define.amd) {
|
||||
define(["require", "exports", "./foo", "name_of_foo"], factory);
|
||||
}
|
||||
})(function (require, exports, name_of_foo) {
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
/// <amd-dependency name="name_of_foo" path="./foo" />
|
||||
var foo_1 = require("name_of_foo");
|
||||
void foo_1.foo;
|
||||
});
|
||||
|
||||
|
||||
//// [foo.d.ts]
|
||||
/// <amd-module name="name_of_foo" />
|
||||
export declare const foo = 1;
|
||||
//// [bar.d.ts]
|
||||
/// <amd-dependency name="name_of_foo" path="./foo" />
|
||||
export {};
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/foo.ts ===
|
||||
/// <amd-module name="name_of_foo"/>
|
||||
export const foo = 1;
|
||||
>foo : Symbol(foo, Decl(foo.ts, 1, 12))
|
||||
|
||||
=== tests/cases/compiler/bar.ts ===
|
||||
/// <amd-dependency name="name_of_foo" path="./foo" />
|
||||
import {foo} from './foo';
|
||||
>foo : Symbol(foo, Decl(bar.ts, 1, 8))
|
||||
|
||||
void foo;
|
||||
>foo : Symbol(foo, Decl(bar.ts, 1, 8))
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/foo.ts ===
|
||||
/// <amd-module name="name_of_foo"/>
|
||||
export const foo = 1;
|
||||
>foo : 1
|
||||
>1 : 1
|
||||
|
||||
=== tests/cases/compiler/bar.ts ===
|
||||
/// <amd-dependency name="name_of_foo" path="./foo" />
|
||||
import {foo} from './foo';
|
||||
>foo : 1
|
||||
|
||||
void foo;
|
||||
>void foo : undefined
|
||||
>foo : 1
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
// @declaration: true
|
||||
// @module: umd
|
||||
// @filename: foo.ts
|
||||
/// <amd-module name="name_of_foo"/>
|
||||
export const foo = 1;
|
||||
// @filename: bar.ts
|
||||
/// <amd-dependency name="name_of_foo" path="./foo" />
|
||||
import {foo} from './foo';
|
||||
void foo;
|
||||
Loading…
x
Reference in New Issue
Block a user