mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 17:05:58 -05:00
Emit first encounter shebang at the top of a output file
This commit is contained in:
@@ -274,6 +274,7 @@ namespace ts {
|
||||
function writeBundle(bundle: Bundle, output: EmitTextWriter) {
|
||||
const previousWriter = writer;
|
||||
setWriter(output);
|
||||
emitShebangIfNeeded(bundle);
|
||||
emitHelpersIndirect(bundle);
|
||||
for (const sourceFile of bundle.sourceFiles) {
|
||||
print(EmitHint.SourceFile, sourceFile, sourceFile);
|
||||
@@ -285,6 +286,7 @@ namespace ts {
|
||||
function writeFile(sourceFile: SourceFile, output: EmitTextWriter) {
|
||||
const previousWriter = writer;
|
||||
setWriter(output);
|
||||
emitShebangIfNeeded(sourceFile);
|
||||
print(EmitHint.SourceFile, sourceFile, sourceFile);
|
||||
reset();
|
||||
writer = previousWriter;
|
||||
@@ -2051,7 +2053,6 @@ namespace ts {
|
||||
|
||||
function emitSourceFile(node: SourceFile) {
|
||||
writeLine();
|
||||
emitShebang();
|
||||
emitBodyIndirect(node, node.statements, emitSourceFileWorker);
|
||||
}
|
||||
|
||||
@@ -2095,11 +2096,26 @@ namespace ts {
|
||||
// Helpers
|
||||
//
|
||||
|
||||
function emitShebang() {
|
||||
const shebang = getShebang(currentSourceFile.text);
|
||||
if (shebang) {
|
||||
write(shebang);
|
||||
writeLine();
|
||||
function emitShebangIfNeeded(sourceFileOrBundle: Bundle | SourceFile) {
|
||||
if (sourceFileOrBundle.kind === SyntaxKind.SourceFile) {
|
||||
emitShebangInSourceFile(sourceFileOrBundle as SourceFile);
|
||||
}
|
||||
else {
|
||||
for (const sourceFile of (sourceFileOrBundle as Bundle).sourceFiles) {
|
||||
// Emit only the first Shebang with encounter
|
||||
if (emitShebangInSourceFile(sourceFile)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitShebangInSourceFile(sourceFile: SourceFile): boolean {
|
||||
const shebang = getShebang(sourceFile.text);
|
||||
if (shebang) {
|
||||
write(shebang);
|
||||
writeLine();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ class Doo {}
|
||||
class Scooby extends Doo {}
|
||||
|
||||
//// [outFile.js]
|
||||
#!/usr/bin/env gjs
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
@@ -14,7 +15,6 @@ var __extends = (this && this.__extends) || (function () {
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
#!/usr/bin/env gjs
|
||||
var Doo = (function () {
|
||||
function Doo() {
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class Dood {}
|
||||
class Scoobyd extends Dood {}
|
||||
|
||||
//// [outFile.js]
|
||||
#!/usr/bin/env gjs
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
@@ -21,7 +22,6 @@ var __extends = (this && this.__extends) || (function () {
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
#!/usr/bin/env gjs
|
||||
var Doo = (function () {
|
||||
function Doo() {
|
||||
}
|
||||
@@ -34,7 +34,6 @@ var Scooby = (function (_super) {
|
||||
}
|
||||
return Scooby;
|
||||
}(Doo));
|
||||
#!/usr/bin/env js
|
||||
var Dood = (function () {
|
||||
function Dood() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user