Skip to content

Commit 5c23a5f

Browse files
committed
Extract source map generation logic out of the emitter.
1 parent 4edf330 commit 5c23a5f

6 files changed

Lines changed: 530 additions & 433 deletions

File tree

Jakefile.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var compilerSources = [
4040
"utilities.ts",
4141
"binder.ts",
4242
"checker.ts",
43+
"sourcemap.ts",
4344
"declarationEmitter.ts",
4445
"emitter.ts",
4546
"program.ts",
@@ -59,6 +60,7 @@ var servicesSources = [
5960
"utilities.ts",
6061
"binder.ts",
6162
"checker.ts",
63+
"sourcemap.ts",
6264
"declarationEmitter.ts",
6365
"emitter.ts",
6466
"program.ts",
@@ -466,7 +468,7 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca
466468
var nodeDefinitionsFileContents = definitionFileContents + "\r\nexport = ts;";
467469
fs.writeFileSync(nodeDefinitionsFile, nodeDefinitionsFileContents);
468470

469-
// Node package definition file to be distributed without the package. Created by replacing
471+
// Node package definition file to be distributed without the package. Created by replacing
470472
// 'ts' namespace with '"typescript"' as a module.
471473
var nodeStandaloneDefinitionsFileContents = definitionFileContents.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
472474
fs.writeFileSync(nodeStandaloneDefinitionsFile, nodeStandaloneDefinitionsFileContents);
@@ -875,7 +877,7 @@ var tslintRulesOutFiles = tslintRules.map(function(p) {
875877
desc("Compiles tslint rules to js");
876878
task("build-rules", tslintRulesOutFiles);
877879
tslintRulesFiles.forEach(function(ruleFile, i) {
878-
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint"));
880+
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint"));
879881
});
880882

881883
function getLinterOptions() {
@@ -937,7 +939,7 @@ function lintWatchFile(filename) {
937939
if (event !== "change") {
938940
return;
939941
}
940-
942+
941943
if (!lintSemaphores[filename]) {
942944
lintSemaphores[filename] = true;
943945
lintFileAsync(getLinterOptions(), filename, function(err, result) {

src/compiler/core.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,33 @@ namespace ts {
356356
return result;
357357
}
358358

359+
/**
360+
* Reduce the properties of a map.
361+
*
362+
* @param map The map to reduce
363+
* @param callback An aggregation function that is called for each entry in the map
364+
* @param initial The initial value for the reduction.
365+
*/
366+
export function reduceProperties<T, U>(map: Map<T>, callback: (aggregate: U, value: T, key: string) => U, initial: U): U {
367+
let result = initial;
368+
if (map) {
369+
for (const key in map) {
370+
if (hasProperty(map, key)) {
371+
result = callback(result, map[key], String(key));
372+
}
373+
}
374+
}
375+
376+
return result;
377+
}
378+
379+
/**
380+
* Tests whether a value is an array.
381+
*/
382+
export function isArray(value: any): value is any[] {
383+
return Array.isArray ? Array.isArray(value) : typeof value === "object" && value instanceof Array;
384+
}
385+
359386
export function memoize<T>(callback: () => T): () => T {
360387
let value: T;
361388
return () => {

0 commit comments

Comments
 (0)