Skip to content

Commit 0ce3861

Browse files
Moved non-exposed functions to utilities; fix up emitted .d.ts in Jakefile.
Conflicts: src/compiler/parser.ts
1 parent a173017 commit 0ce3861

6 files changed

Lines changed: 1004 additions & 927 deletions

File tree

Jakefile

Lines changed: 88 additions & 23 deletions
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",
@@ -149,25 +177,48 @@ var compilerFilename = "tsc.js";
149177
* @param prefixes: a list of files to prepend to the target file
150178
* @param useBuiltCompiler: true to use the built compiler, false to use the LKG
151179
* @param noOutFile: true to compile without using --out
180+
* @param generateDeclarations: true to compile using --declaration
181+
* @param outDir: true to compile using --outDir
182+
* @param keepComments: false to compile using --removeComments
183+
* @param callback: a function to execute after the compilation process ends
152184
*/
153-
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, callback) {
185+
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, keepComments, noResolve, callback) {
154186
file(outFile, prereqs, function() {
155187
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
156-
var options = "-removeComments --module commonjs -noImplicitAny ";
188+
var options = "--module commonjs -noImplicitAny";
189+
190+
if (!keepComments) {
191+
options += " -removeComments";
192+
}
193+
157194
if (generateDeclarations) {
158-
options += "--declaration ";
195+
options += " --declaration";
159196
}
160197

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

165-
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
166-
cmd = cmd + sources.join(" ") + (!noOutFile ? " -out " + outFile : "");
167214
if (useDebugMode) {
168-
cmd = cmd + " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile));
215+
options += " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile));
169216
}
217+
218+
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
219+
cmd = cmd + sources.join(" ");
170220
console.log(cmd + "\n");
221+
171222
var ex = jake.createExec([cmd]);
172223
// Add listeners for output and error
173224
ex.addListener("stdout", function(output) {
@@ -260,24 +311,38 @@ var tscFile = path.join(builtLocalDirectory, compilerFilename);
260311
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
261312

262313
var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
263-
var servicesDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts");
314+
compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler*/ true);
264315

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

278343
// Local target to build the compiler and services
279344
desc("Builds the full compiler and services");
280-
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile]);
345+
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile]);
281346

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

src/compiler/checker.ts

Lines changed: 2 additions & 52 deletions
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
@@ -1012,11 +967,6 @@ module ts {
1012967
};
1013968
}
1014969

1015-
function releaseStringWriter(writer: StringSymbolWriter) {
1016-
writer.clear()
1017-
stringWriters.push(writer);
1018-
}
1019-
1020970
function writeKeyword(writer: SymbolWriter, kind: SyntaxKind) {
1021971
writer.writeKeyword(tokenToString(kind));
1022972
}

0 commit comments

Comments
 (0)