Skip to content

Commit b7a17e2

Browse files
Merge pull request #1417 from Microsoft/exposeServices
Expose services as a consumable external module
2 parents c3bc360 + 0aca3b9 commit b7a17e2

32 files changed

+16972
-1764
lines changed

Jakefile

+88-23
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var compilerSources = [
3535
"types.ts",
3636
"scanner.ts",
3737
"parser.ts",
38+
"utilities.ts",
3839
"binder.ts",
3940
"checker.ts",
4041
"emitter.ts",
@@ -47,26 +48,53 @@ var compilerSources = [
4748

4849
var servicesSources = [
4950
"core.ts",
51+
"sys.ts",
5052
"types.ts",
5153
"scanner.ts",
5254
"parser.ts",
55+
"utilities.ts",
5356
"binder.ts",
5457
"checker.ts",
55-
"emitter.ts"
58+
"emitter.ts",
59+
"diagnosticInformationMap.generated.ts"
5660
].map(function (f) {
5761
return path.join(compilerDirectory, f);
5862
}).concat([
5963
"breakpoints.ts",
64+
"navigationBar.ts",
65+
"outliningElementsCollector.ts",
6066
"services.ts",
6167
"shims.ts",
6268
"signatureHelp.ts",
6369
"utilities.ts",
64-
"navigationBar.ts",
65-
"outliningElementsCollector.ts"
70+
"formatting/formatting.ts",
71+
"formatting/formattingContext.ts",
72+
"formatting/formattingRequestKind.ts",
73+
"formatting/formattingScanner.ts",
74+
"formatting/references.ts",
75+
"formatting/rule.ts",
76+
"formatting/ruleAction.ts",
77+
"formatting/ruleDescriptor.ts",
78+
"formatting/ruleFlag.ts",
79+
"formatting/ruleOperation.ts",
80+
"formatting/ruleOperationContext.ts",
81+
"formatting/rules.ts",
82+
"formatting/rulesMap.ts",
83+
"formatting/rulesProvider.ts",
84+
"formatting/smartIndenter.ts",
85+
"formatting/tokenRange.ts"
6686
].map(function (f) {
6787
return path.join(servicesDirectory, f);
6888
}));
6989

90+
var definitionsRoots = [
91+
"compiler/types.d.ts",
92+
"compiler/scanner.d.ts",
93+
"compiler/parser.d.ts",
94+
"compiler/checker.d.ts",
95+
"services/services.d.ts",
96+
];
97+
7098
var harnessSources = [
7199
"harness.ts",
72100
"sourceMapRecorder.ts",
@@ -148,25 +176,48 @@ var compilerFilename = "tsc.js";
148176
* @param prefixes: a list of files to prepend to the target file
149177
* @param useBuiltCompiler: true to use the built compiler, false to use the LKG
150178
* @param noOutFile: true to compile without using --out
179+
* @param generateDeclarations: true to compile using --declaration
180+
* @param outDir: true to compile using --outDir
181+
* @param keepComments: false to compile using --removeComments
182+
* @param callback: a function to execute after the compilation process ends
151183
*/
152-
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, callback) {
184+
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, keepComments, noResolve, callback) {
153185
file(outFile, prereqs, function() {
154186
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
155-
var options = "-removeComments --module commonjs -noImplicitAny ";
187+
var options = "--module commonjs -noImplicitAny";
188+
189+
if (!keepComments) {
190+
options += " -removeComments";
191+
}
192+
156193
if (generateDeclarations) {
157-
options += "--declaration ";
194+
options += " --declaration";
158195
}
159196

160197
if (useDebugMode) {
161-
options += "--preserveConstEnums ";
198+
options += " --preserveConstEnums";
199+
}
200+
201+
if (outDir) {
202+
options += " --outDir " + outDir;
203+
}
204+
205+
if (!noOutFile) {
206+
options += " --out " + outFile;
207+
}
208+
209+
if(noResolve) {
210+
options += " --noResolve";
162211
}
163212

164-
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
165-
cmd = cmd + sources.join(" ") + (!noOutFile ? " -out " + outFile : "");
166213
if (useDebugMode) {
167-
cmd = cmd + " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile));
214+
options += " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile));
168215
}
216+
217+
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
218+
cmd = cmd + sources.join(" ");
169219
console.log(cmd + "\n");
220+
170221
var ex = jake.createExec([cmd]);
171222
// Add listeners for output and error
172223
ex.addListener("stdout", function(output) {
@@ -259,24 +310,38 @@ var tscFile = path.join(builtLocalDirectory, compilerFilename);
259310
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
260311

261312
var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
262-
var servicesDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts");
313+
compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler*/ true);
263314

264-
compileFile(servicesFile,
265-
servicesSources,
266-
[builtLocalDirectory, copyright].concat(servicesSources),
267-
[copyright],
315+
var nodeDefinitionsFile = path.join(builtLocalDirectory, "typescript.d.ts");
316+
var standaloneDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts");
317+
var tempDirPath = path.join(builtLocalDirectory, "temptempdir");
318+
compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources),
319+
/*prefixes*/ undefined,
268320
/*useBuiltCompiler*/ true,
269-
/*noOutFile*/ false,
321+
/*noOutFile*/ true,
270322
/*generateDeclarations*/ true,
271-
/*callback*/ fixDeclarationFile);
272-
273-
function fixDeclarationFile() {
274-
fs.appendFileSync(servicesDefinitionsFile, os.EOL + "export = ts;")
275-
}
323+
/*outDir*/ tempDirPath,
324+
/*keepComments*/ true,
325+
/*noResolve*/ true,
326+
/*callback*/ function () {
327+
concatenateFiles(standaloneDefinitionsFile, definitionsRoots.map(function (f) {
328+
return path.join(tempDirPath, f);
329+
}));
330+
prependFile(copyright, standaloneDefinitionsFile);
331+
332+
// Create the node definition file by replacing 'ts' module with '"typescript"' as a module.
333+
jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, {silent: true});
334+
var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString();
335+
definitionFileContents = definitionFileContents.replace(/declare module ts/g, 'declare module "typescript"');
336+
fs.writeFileSync(nodeDefinitionsFile, definitionFileContents);
337+
338+
// Delete the temp dir
339+
jake.rmRf(tempDirPath, {silent: true});
340+
});
276341

277342
// Local target to build the compiler and services
278343
desc("Builds the full compiler and services");
279-
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile]);
344+
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile]);
280345

281346
// Local target to build the compiler and services
282347
desc("Sets release mode flag");
@@ -327,7 +392,7 @@ task("generate-spec", [specMd])
327392
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
328393
desc("Makes a new LKG out of the built js files");
329394
task("LKG", ["clean", "release", "local"].concat(libraryTargets), function() {
330-
var expectedFiles = [tscFile, servicesFile, servicesDefinitionsFile].concat(libraryTargets);
395+
var expectedFiles = [tscFile, servicesFile, nodeDefinitionsFile, standaloneDefinitionsFile].concat(libraryTargets);
331396
var missingFiles = expectedFiles.filter(function (f) {
332397
return !fs.existsSync(f);
333398
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"url" : "https://github.com/Microsoft/TypeScript.git"
2626
},
2727
"preferGlobal" : true,
28-
"main" : "./bin/tsc.js",
28+
"main" : "./bin/typescriptServices.js",
2929
"bin" : {
3030
"tsc" : "./bin/tsc"
3131
},

src/compiler/checker.ts

+2-52
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,12 @@
44
/// <reference path="parser.ts"/>
55
/// <reference path="binder.ts"/>
66
/// <reference path="emitter.ts"/>
7+
/// <reference path="utilities.ts"/>
78

89
module ts {
910
var nextSymbolId = 1;
1011
var nextNodeId = 1;
11-
var nextMergeId = 1;
12-
13-
export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
14-
var declarations = symbol.declarations;
15-
for (var i = 0; i < declarations.length; i++) {
16-
var declaration = declarations[i];
17-
if (declaration.kind === kind) {
18-
return declaration;
19-
}
20-
}
21-
22-
return undefined;
23-
}
24-
25-
export interface StringSymbolWriter extends SymbolWriter {
26-
string(): string;
27-
}
28-
29-
// Pool writers to avoid needing to allocate them for every symbol we write.
30-
var stringWriters: StringSymbolWriter[] = [];
31-
export function getSingleLineStringWriter(): StringSymbolWriter {
32-
if (stringWriters.length == 0) {
33-
var str = "";
34-
35-
var writeText: (text: string) => void = text => str += text;
36-
return {
37-
string: () => str,
38-
writeKeyword: writeText,
39-
writeOperator: writeText,
40-
writePunctuation: writeText,
41-
writeSpace: writeText,
42-
writeStringLiteral: writeText,
43-
writeParameter: writeText,
44-
writeSymbol: writeText,
45-
46-
// Completely ignore indentation for string writers. And map newlines to
47-
// a single space.
48-
writeLine: () => str += " ",
49-
increaseIndent: () => { },
50-
decreaseIndent: () => { },
51-
clear: () => str = "",
52-
trackSymbol: () => { }
53-
};
54-
}
55-
56-
return stringWriters.pop();
57-
}
12+
var nextMergeId = 1;
5813

5914
/// fullTypeCheck denotes if this instance of the typechecker will be used to get semantic diagnostics.
6015
/// If fullTypeCheck === true, then the typechecker should do every possible check to produce all errors
@@ -1019,11 +974,6 @@ module ts {
1019974
};
1020975
}
1021976

1022-
function releaseStringWriter(writer: StringSymbolWriter) {
1023-
writer.clear()
1024-
stringWriters.push(writer);
1025-
}
1026-
1027977
function writeKeyword(writer: SymbolWriter, kind: SyntaxKind) {
1028978
writer.writeKeyword(tokenToString(kind));
1029979
}

src/compiler/core.ts

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ module ts {
1515
True = -1
1616
}
1717

18-
export interface Map<T> {
19-
[index: string]: T;
20-
}
21-
2218
export const enum Comparison {
2319
LessThan = -1,
2420
EqualTo = 0,

0 commit comments

Comments
 (0)