MCPcopy Index your code
hub / github.com/TypeScriptToLua/TypeScriptToLua / getEmitPlan

Method getEmitPlan

src/transpilation/transpiler.ts:110–163  ·  view source on GitHub ↗
(
        program: ts.Program,
        diagnostics: ts.Diagnostic[],
        files: ProcessedFile[],
        plugins: Plugin[]
    )

Source from the content-addressed store, hash-verified

108 }
109
110 protected getEmitPlan(
111 program: ts.Program,
112 diagnostics: ts.Diagnostic[],
113 files: ProcessedFile[],
114 plugins: Plugin[]
115 ): { emitPlan: EmitFile[] } {
116 performance.startSection("getEmitPlan");
117 const options = program.getCompilerOptions() as CompilerOptions;
118
119 if (options.tstlVerbose) {
120 console.log("Constructing emit plan");
121 }
122
123 // Resolve imported modules and modify output Lua requires
124 const resolutionResult = resolveDependencies(program, files, this.emitHost, plugins);
125 diagnostics.push(...resolutionResult.diagnostics);
126
127 const lualibRequired = resolutionResult.resolvedFiles.some(f => f.fileName === "lualib_bundle");
128 if (lualibRequired) {
129 // Remove lualib placeholders from resolution result
130 resolutionResult.resolvedFiles = resolutionResult.resolvedFiles.filter(f => f.fileName !== "lualib_bundle");
131
132 if (options.tstlVerbose) {
133 console.log("Including lualib bundle");
134 }
135 // Add lualib bundle to source dir 'virtually', will be moved to correct output dir in emitPlan
136 const fileName = normalizeSlashes(path.resolve(getSourceDir(program), "lualib_bundle.lua"));
137 const code = this.getLuaLibBundleContent(options, resolutionResult.resolvedFiles);
138 resolutionResult.resolvedFiles.unshift({ fileName, code });
139 }
140
141 let emitPlan: EmitFile[];
142 if (isBundleEnabled(options)) {
143 const [bundleDiagnostics, bundleFile] = getBundleResult(program, resolutionResult.resolvedFiles);
144 diagnostics.push(...bundleDiagnostics);
145 emitPlan = [bundleFile];
146 } else {
147 const outputPathMap = new Map<string, string>();
148 emitPlan = resolutionResult.resolvedFiles.map(file => {
149 const outputPath = getEmitPath(file.fileName, program);
150 const existing = outputPathMap.get(outputPath);
151 if (existing) {
152 diagnostics.push(emitPathCollision(outputPath, existing, file.fileName));
153 } else {
154 outputPathMap.set(outputPath, file.fileName);
155 }
156 return { ...file, outputPath };
157 });
158 }
159
160 performance.endSection("getEmitPlan");
161
162 return { emitPlan };
163 }
164
165 private getLuaLibBundleContent(options: CompilerOptions, resolvedFiles: ProcessedFile[]) {
166 const luaTarget = options.luaTarget ?? LuaTarget.Universal;

Callers 1

emitMethod · 0.95

Calls 10

getMethod · 0.95
setMethod · 0.95
resolveDependenciesFunction · 0.90
normalizeSlashesFunction · 0.90
isBundleEnabledFunction · 0.90
getBundleResultFunction · 0.90
getSourceDirFunction · 0.85
getEmitPathFunction · 0.85
resolveMethod · 0.80

Tested by

no test coverage detected