Add helpers from source files to the bundleInfo to be used later

This commit is contained in:
Sheetal Nandi
2019-02-01 17:52:01 -08:00
parent 4050378819
commit e3eb7bc4b7
16 changed files with 182 additions and 27 deletions
+27
View File
@@ -572,6 +572,12 @@ namespace ts {
if (bundleFileInfo) {
bundleFileInfo.sections.push({ pos, end: writer.getTextPos(), kind: BundleFileSectionKind.Text });
// Source file metadata if needed later on
// Store helpes
const helpers = getHelpersFromBundledSourceFiles(bundle);
if (helpers) {
bundleFileInfo.sources.helpers = helpers;
}
}
reset();
@@ -1142,6 +1148,27 @@ namespace ts {
pipelinePhase(hint, substituteNode(hint, node));
}
function getHelpersFromBundledSourceFiles(bundle: Bundle): string[] | undefined {
let result: string[] | undefined;
if (moduleKind === ModuleKind.None || printerOptions.noEmitHelpers) {
return undefined;
}
const bundledHelpers = createMap<boolean>();
for (const sourceFile of bundle.sourceFiles) {
const shouldSkip = getExternalHelpersModuleName(sourceFile) !== undefined;
const helpers = getSortedEmitHelpers(sourceFile);
if (!helpers) continue;
for (const helper of helpers) {
if (!helper.scoped && !shouldSkip && !bundledHelpers.get(helper.name)) {
bundledHelpers.set(helper.name, true);
(result || (result = [])).push(helper.name);
}
}
}
return result;
}
function emitHelpers(node: Node) {
let helpersEmitted = false;
const bundle = node.kind === SyntaxKind.Bundle ? <Bundle>node : undefined;
+2
View File
@@ -5529,6 +5529,8 @@ namespace ts {
/*@internal*/
export interface SourceFileInfo {
// List of helpers in own source files emitted if no prepend is present
helpers?: string[];
}
/*@internal*/
@@ -31,7 +31,11 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/first/bin/first-output.d.ts]
@@ -498,7 +502,11 @@ const { b, ...rest } = { a: 10, b: 30, yy: 30 };
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts]
@@ -43,7 +43,13 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/first/bin/first-output.d.ts]
@@ -695,7 +701,13 @@ const { b, ...rest } = { a: 10, b: 30, yy: 30 };
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts]
@@ -31,7 +31,11 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/first/bin/first-output.d.ts]
@@ -510,7 +514,11 @@ const { b, ...rest } = { a: 10, b: 30, yy: 30 };
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts]
@@ -31,7 +31,11 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/first/bin/first-output.js]
@@ -362,7 +366,11 @@ const { b, ...rest } = { a: 10, b: 30, yy: 30 };
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.js]
@@ -43,7 +43,13 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/first/bin/first-output.js]
@@ -528,7 +534,13 @@ const { b, ...rest } = { a: 10, b: 30, yy: 30 };
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/third/thirdjs/output/third-output.js]
@@ -31,7 +31,11 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/first/bin/first-output.js]
@@ -374,7 +378,11 @@ const { b, ...rest } = { a: 10, b: 30, yy: 30 };
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.js]
@@ -424,7 +424,11 @@ function forfirstfirst_PART1Rest() { }
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts.map]
@@ -31,7 +31,11 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/first/bin/first-output.d.ts.map]
@@ -37,7 +37,12 @@
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/first/bin/first-output.d.ts.map]
@@ -620,7 +625,13 @@ function forfirstfirst_PART1Rest() { }
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts.map]
@@ -436,7 +436,11 @@ function forfirstfirst_PART1Rest() { }
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts.map]
@@ -31,7 +31,11 @@
}
],
"commonSourceDirectory": "/src/second/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/2/second-output.d.ts]
@@ -541,7 +545,11 @@ sourceFile:../second/second_part2.ts
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/first/bin/first-output.d.ts]
@@ -1024,7 +1032,11 @@ const { b, ...rest } = { a: 10, b: 30, yy: 30 };
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts]
@@ -31,7 +31,11 @@
}
],
"commonSourceDirectory": "/src/second/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/2/second-output.d.ts]
@@ -43,7 +43,13 @@
}
],
"commonSourceDirectory": "/src/second/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/2/second-output.d.ts]
@@ -740,7 +746,13 @@ sourceFile:../second/second_part2.ts
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/first/bin/first-output.d.ts]
@@ -1467,7 +1479,13 @@ secondsecond_part2Spread(...[10, 20, 30]);
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest",
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts]
@@ -37,7 +37,12 @@
}
],
"commonSourceDirectory": "/src/second/",
"sources": {}
"sources": {
"helpers": [
"typescript:read",
"typescript:spread"
]
}
}
//// [/src/2/second-output.d.ts]
@@ -633,7 +638,11 @@ sourceFile:../second/second_part2.ts
}
],
"commonSourceDirectory": "/src/first/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/first/bin/first-output.d.ts]
@@ -1147,7 +1156,11 @@ secondsecond_part1Spread(...[10, 20, 30]);
}
],
"commonSourceDirectory": "/src/third/",
"sources": {}
"sources": {
"helpers": [
"typescript:rest"
]
}
}
//// [/src/third/thirdjs/output/third-output.d.ts]