Skip to content

Expose services as a consumable external module #1417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Dec 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5c8173b
Allow typescript to be importable in node.
DanielRosenwasser Dec 10, 2014
73ee038
Use __filename for 'getExecutingFilePath'.
DanielRosenwasser Dec 5, 2014
4deea66
Put 'sys' into the 'ts' module.
DanielRosenwasser Dec 6, 2014
0d9b2c8
move text defintions to services.ts
mhegazy Dec 6, 2014
523c179
use ts.System for tests
mhegazy Dec 8, 2014
fc950ed
Move Map to types to ensure it is visible in definition files
mhegazy Dec 8, 2014
cf340ef
remove unused file
mhegazy Dec 7, 2014
f90e725
move formatting.ts and smartIndernter.ts into formatting folder to ma…
mhegazy Dec 8, 2014
6da0b57
Removed tokenSpan.ts.
DanielRosenwasser Dec 10, 2014
1fab80f
move OutliningSpan definitions to services to ensure it is visible in…
mhegazy Dec 8, 2014
520979d
Make getLocalizedDiagnosticMessages and getCancellationToken optional
DanielRosenwasser Dec 10, 2014
f690f05
Remove unused parameter to getCompletionsAtPosition
mhegazy Dec 8, 2014
e2baddd
Explicit default target for fourslash tests in the harness.
DanielRosenwasser Dec 9, 2014
7c6d731
Moved non-exposed functions to utilities; fix up emitted .d.ts in Jak…
DanielRosenwasser Dec 11, 2014
2b4a769
Merge remote-tracking branch 'origin/release-1.4' into exposeServices2
DanielRosenwasser Dec 11, 2014
38bf383
Add tests for public declarations
mhegazy Dec 8, 2014
7fb92f8
Fixed up baselines.
DanielRosenwasser Dec 11, 2014
905d978
Moved createCompilerHost into parser.ts
DanielRosenwasser Dec 11, 2014
b6e8dd4
Responded to CR feedback.
DanielRosenwasser Dec 11, 2014
0aca3b9
Fixed 'use strict' check.
DanielRosenwasser Dec 11, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 88 additions & 23 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var compilerSources = [
"types.ts",
"scanner.ts",
"parser.ts",
"utilities.ts",
"binder.ts",
"checker.ts",
"emitter.ts",
Expand All @@ -47,26 +48,53 @@ var compilerSources = [

var servicesSources = [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
"utilities.ts",
"binder.ts",
"checker.ts",
"emitter.ts"
"emitter.ts",
"diagnosticInformationMap.generated.ts"
].map(function (f) {
return path.join(compilerDirectory, f);
}).concat([
"breakpoints.ts",
"navigationBar.ts",
"outliningElementsCollector.ts",
"services.ts",
"shims.ts",
"signatureHelp.ts",
"utilities.ts",
"navigationBar.ts",
"outliningElementsCollector.ts"
"formatting/formatting.ts",
"formatting/formattingContext.ts",
"formatting/formattingRequestKind.ts",
"formatting/formattingScanner.ts",
"formatting/references.ts",
"formatting/rule.ts",
"formatting/ruleAction.ts",
"formatting/ruleDescriptor.ts",
"formatting/ruleFlag.ts",
"formatting/ruleOperation.ts",
"formatting/ruleOperationContext.ts",
"formatting/rules.ts",
"formatting/rulesMap.ts",
"formatting/rulesProvider.ts",
"formatting/smartIndenter.ts",
"formatting/tokenRange.ts"
].map(function (f) {
return path.join(servicesDirectory, f);
}));

var definitionsRoots = [
"compiler/types.d.ts",
"compiler/scanner.d.ts",
"compiler/parser.d.ts",
"compiler/checker.d.ts",
"services/services.d.ts",
];

var harnessSources = [
"harness.ts",
"sourceMapRecorder.ts",
Expand Down Expand Up @@ -148,25 +176,48 @@ var compilerFilename = "tsc.js";
* @param prefixes: a list of files to prepend to the target file
* @param useBuiltCompiler: true to use the built compiler, false to use the LKG
* @param noOutFile: true to compile without using --out
* @param generateDeclarations: true to compile using --declaration
* @param outDir: true to compile using --outDir
* @param keepComments: false to compile using --removeComments
* @param callback: a function to execute after the compilation process ends
*/
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, callback) {
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations, outDir, keepComments, noResolve, callback) {
file(outFile, prereqs, function() {
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
var options = "-removeComments --module commonjs -noImplicitAny ";
var options = "--module commonjs -noImplicitAny";

if (!keepComments) {
options += " -removeComments";
}

if (generateDeclarations) {
options += "--declaration ";
options += " --declaration";
}

if (useDebugMode) {
options += "--preserveConstEnums ";
options += " --preserveConstEnums";
}

if (outDir) {
options += " --outDir " + outDir;
}

if (!noOutFile) {
options += " --out " + outFile;
}

if(noResolve) {
options += " --noResolve";
}

var cmd = host + " " + dir + compilerFilename + " " + options + " ";
cmd = cmd + sources.join(" ") + (!noOutFile ? " -out " + outFile : "");
if (useDebugMode) {
cmd = cmd + " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile));
options += " -sourcemap -mapRoot file:///" + path.resolve(path.dirname(outFile));
}

var cmd = host + " " + dir + compilerFilename + " " + options + " ";
cmd = cmd + sources.join(" ");
console.log(cmd + "\n");

var ex = jake.createExec([cmd]);
// Add listeners for output and error
ex.addListener("stdout", function(output) {
Expand Down Expand Up @@ -259,24 +310,38 @@ var tscFile = path.join(builtLocalDirectory, compilerFilename);
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);

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

compileFile(servicesFile,
servicesSources,
[builtLocalDirectory, copyright].concat(servicesSources),
[copyright],
var nodeDefinitionsFile = path.join(builtLocalDirectory, "typescript.d.ts");
var standaloneDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts");
var tempDirPath = path.join(builtLocalDirectory, "temptempdir");
compileFile(nodeDefinitionsFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources),
/*prefixes*/ undefined,
/*useBuiltCompiler*/ true,
/*noOutFile*/ false,
/*noOutFile*/ true,
/*generateDeclarations*/ true,
/*callback*/ fixDeclarationFile);

function fixDeclarationFile() {
fs.appendFileSync(servicesDefinitionsFile, os.EOL + "export = ts;")
}
/*outDir*/ tempDirPath,
/*keepComments*/ true,
/*noResolve*/ true,
/*callback*/ function () {
concatenateFiles(standaloneDefinitionsFile, definitionsRoots.map(function (f) {
return path.join(tempDirPath, f);
}));
prependFile(copyright, standaloneDefinitionsFile);

// Create the node definition file by replacing 'ts' module with '"typescript"' as a module.
jake.cpR(standaloneDefinitionsFile, nodeDefinitionsFile, {silent: true});
var definitionFileContents = fs.readFileSync(nodeDefinitionsFile).toString();
definitionFileContents = definitionFileContents.replace(/declare module ts/g, 'declare module "typescript"');
fs.writeFileSync(nodeDefinitionsFile, definitionFileContents);

// Delete the temp dir
jake.rmRf(tempDirPath, {silent: true});
});

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

// Local target to build the compiler and services
desc("Sets release mode flag");
Expand Down Expand Up @@ -327,7 +392,7 @@ task("generate-spec", [specMd])
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
desc("Makes a new LKG out of the built js files");
task("LKG", ["clean", "release", "local"].concat(libraryTargets), function() {
var expectedFiles = [tscFile, servicesFile, servicesDefinitionsFile].concat(libraryTargets);
var expectedFiles = [tscFile, servicesFile, nodeDefinitionsFile, standaloneDefinitionsFile].concat(libraryTargets);
var missingFiles = expectedFiles.filter(function (f) {
return !fs.existsSync(f);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"url" : "https://github.com/Microsoft/TypeScript.git"
},
"preferGlobal" : true,
"main" : "./bin/tsc.js",
"main" : "./bin/typescriptServices.js",
"bin" : {
"tsc" : "./bin/tsc"
},
Expand Down
54 changes: 2 additions & 52 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,12 @@
/// <reference path="parser.ts"/>
/// <reference path="binder.ts"/>
/// <reference path="emitter.ts"/>
/// <reference path="utilities.ts"/>

module ts {
var nextSymbolId = 1;
var nextNodeId = 1;
var nextMergeId = 1;

export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
var declarations = symbol.declarations;
for (var i = 0; i < declarations.length; i++) {
var declaration = declarations[i];
if (declaration.kind === kind) {
return declaration;
}
}

return undefined;
}

export interface StringSymbolWriter extends SymbolWriter {
string(): string;
}

// Pool writers to avoid needing to allocate them for every symbol we write.
var stringWriters: StringSymbolWriter[] = [];
export function getSingleLineStringWriter(): StringSymbolWriter {
if (stringWriters.length == 0) {
var str = "";

var writeText: (text: string) => void = text => str += text;
return {
string: () => str,
writeKeyword: writeText,
writeOperator: writeText,
writePunctuation: writeText,
writeSpace: writeText,
writeStringLiteral: writeText,
writeParameter: writeText,
writeSymbol: writeText,

// Completely ignore indentation for string writers. And map newlines to
// a single space.
writeLine: () => str += " ",
increaseIndent: () => { },
decreaseIndent: () => { },
clear: () => str = "",
trackSymbol: () => { }
};
}

return stringWriters.pop();
}
var nextMergeId = 1;

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

function releaseStringWriter(writer: StringSymbolWriter) {
writer.clear()
stringWriters.push(writer);
}

function writeKeyword(writer: SymbolWriter, kind: SyntaxKind) {
writer.writeKeyword(tokenToString(kind));
}
Expand Down
4 changes: 0 additions & 4 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ module ts {
True = -1
}

export interface Map<T> {
[index: string]: T;
}

export const enum Comparison {
LessThan = -1,
EqualTo = 0,
Expand Down
Loading