Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
124 lines (110 loc) · 4.48 KB

File metadata and controls

124 lines (110 loc) · 4.48 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/// <reference path="../src/harness/external/node.d.ts" />
/// <reference path="../built/local/typescript.d.ts" />
import * as fs from "fs";
import * as path from "path";
import * as typescript from "typescript";
declare var ts: typeof typescript;
var tsSourceDir = "../src";
var tsBuildDir = "../built/local";
var testOutputDir = "../built/benchmark";
var sourceFiles = [
"compiler/types.ts",
"compiler/core.ts",
"compiler/sys.ts",
"compiler/diagnosticInformationMap.generated.ts",
"compiler/scanner.ts",
"compiler/binder.ts",
"compiler/utilities.ts",
"compiler/parser.ts",
"compiler/checker.ts",
"compiler/declarationEmitter.ts",
"compiler/emitter.ts",
"compiler/program.ts",
"compiler/commandLineParser.ts",
"compiler/tsc.ts"];
// .ts sources for the compiler, used as a test input
var rawCompilerSources = "";
sourceFiles.forEach(f=> {
rawCompilerSources += "\r\n" + fs.readFileSync(path.join(tsSourceDir, f)).toString();
});
var compilerSoruces = `var compilerSources = ${JSON.stringify(rawCompilerSources) };`;
// .js code for the compiler, what we are actuallty testing
var rawCompilerJavaScript = fs.readFileSync(path.join(tsBuildDir, "tsc.js")).toString();
rawCompilerJavaScript = rawCompilerJavaScript.replace("ts.executeCommandLine(ts.sys.args);", "");
// lib.d.ts sources
var rawLibSources = fs.readFileSync(path.join(tsBuildDir, "lib.d.ts")).toString();
var libSoruces = `var libSources = ${JSON.stringify(rawLibSources) };`;
// write test output
if (!fs.existsSync(testOutputDir)) {
fs.mkdirSync(testOutputDir);
}
// 1. compiler ts sources, used to test
fs.writeFileSync(
path.join(testOutputDir, "compilerSources.js"),
`${ compilerSoruces } \r\n ${ libSoruces }`);
// 2. the compiler js sources + a call the compiler
fs.writeFileSync(
path.join(testOutputDir, "benchmarktsc.js"),
`${ rawCompilerJavaScript }\r\n${ compile.toString() }\r\ncompile(compilerSources, libSources);`);
// 3. test html file to drive the test
fs.writeFileSync(
path.join(testOutputDir, "benchmarktsc.html"),
`<!DOCTYPE HTML>
<html>
<head>
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<title>Typescript 1.1 Compiler</title>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
</head>
<body>
<div><span>Status: </span><span id="status">Running</span></div>
<div id="main"><span>End-to-End Time: </span><span id="totalTime">N/A</span></div>
<script>
var startTime = performance.now();
</script>
<script src="compilerSources.js"></script>
<script src="benchmarktsc.js"></script>
<script>
var endTime = performance.now();
document.getElementById("totalTime").innerHTML = parseInt(endTime - startTime, 10);
document.getElementById("status").innerHTML = "DONE";
</script>
</body>
</html>`);
function compile(compilerSources, librarySources) {
var program = ts.createProgram(
["lib.d.ts", "compiler.ts"],
{
noResolve: true,
out: "compiler.js",
removeComments: true,
target: ts.ScriptTarget.ES3
}, {
getDefaultLibFileName: () => "lib.d.ts",
getSourceFile: (filename, languageVersion) => {
var source: string;
if (filename === "lib.d.ts") source = librarySources;
else if (filename === "compiler.ts") source = compilerSources;
else console.error("Unexpected read file request: " + filename);
return ts.createSourceFile(filename, source, languageVersion);
},
writeFile: (filename, data, writeByteOrderMark) => {
if (filename !== "compiler.js")
console.error("Unexpected write file request: " + filename);
// console.log(data);
},
getCurrentDirectory: () => "",
getCanonicalFileName: (filename) => filename,
useCaseSensitiveFileNames: () => false,
getNewLine: () => "\r\n"
});
var emitOutput = program.emit();
var errors = program.getSyntacticDiagnostics()
.concat(program.getSemanticDiagnostics())
.concat(program.getGlobalDiagnostics())
.concat(emitOutput.diagnostics);
if (errors.length) {
console.error("Unexpected errors.");
errors.forEach(e=> console.log(`${e.code}: ${e.messageText}`))
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.