Skip to content

Commit 266600d

Browse files
committed
Merge pull request #5780 from Microsoft/extractSourceMaps
Extract source map generation logic out of the emitter.
2 parents 78ba4b2 + 04d53c1 commit 266600d

File tree

6 files changed

+574
-449
lines changed

6 files changed

+574
-449
lines changed

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",
@@ -475,7 +477,7 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca
475477
var nodeDefinitionsFileContents = definitionFileContents + "\r\nexport = ts;";
476478
fs.writeFileSync(nodeDefinitionsFile, nodeDefinitionsFileContents);
477479

478-
// Node package definition file to be distributed without the package. Created by replacing
480+
// Node package definition file to be distributed without the package. Created by replacing
479481
// 'ts' namespace with '"typescript"' as a module.
480482
var nodeStandaloneDefinitionsFileContents = definitionFileContents.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
481483
fs.writeFileSync(nodeStandaloneDefinitionsFile, nodeStandaloneDefinitionsFileContents);
@@ -884,7 +886,7 @@ var tslintRulesOutFiles = tslintRules.map(function(p) {
884886
desc("Compiles tslint rules to js");
885887
task("build-rules", tslintRulesOutFiles);
886888
tslintRulesFiles.forEach(function(ruleFile, i) {
887-
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint"));
889+
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false, /*noOutFile*/ true, /*generateDeclarations*/ false, path.join(builtLocalDirectory, "tslint"));
888890
});
889891

890892
function getLinterOptions() {
@@ -947,7 +949,7 @@ function lintWatchFile(filename) {
947949
if (event !== "change") {
948950
return;
949951
}
950-
952+
951953
if (!lintSemaphores[filename]) {
952954
lintSemaphores[filename] = true;
953955
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) : value instanceof Array;
384+
}
385+
359386
export function memoize<T>(callback: () => T): () => T {
360387
let value: T;
361388
return () => {

0 commit comments

Comments
 (0)