Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fbeb58a

Browse files
authored
Merge pull request #23893 from Microsoft/libReference
Adds 'lib' reference directives
2 parents c437404 + 6668412 commit fbeb58a

File tree

1,559 files changed

+9716
-9288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,559 files changed

+9716
-9288
lines changed

Gulpfile.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const concat = require("gulp-concat");
1111
const clone = require("gulp-clone");
1212
const newer = require("gulp-newer");
1313
const tsc = require("gulp-typescript");
14+
const tsc_oop = require("./scripts/build/gulp-typescript-oop");
1415
const insert = require("gulp-insert");
1516
const sourcemaps = require("gulp-sourcemaps");
1617
const Q = require("q");
@@ -412,6 +413,10 @@ function prependCopyright(outputCopyright = !useDebugMode) {
412413
return insert.prepend(outputCopyright ? (copyrightContent || (copyrightContent = fs.readFileSync(copyright).toString())) : "");
413414
}
414415

416+
function getCompilerPath(useBuiltCompiler) {
417+
return useBuiltCompiler ? "./built/local/typescript.js" : "./lib/typescript.js";
418+
}
419+
415420
gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
416421
const localCompilerProject = tsc.createProject("src/compiler/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
417422
return localCompilerProject.src()
@@ -424,7 +429,7 @@ gulp.task(builtLocalCompiler, /*help*/ false, [servicesFile], () => {
424429
});
425430

426431
gulp.task(servicesFile, /*help*/ false, ["lib", "generate-diagnostics"], () => {
427-
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/ false));
432+
const servicesProject = tsc_oop.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }), { typescript: getCompilerPath(/*useBuiltCompiler*/ false) });
428433
const {js, dts} = servicesProject.src()
429434
.pipe(newer(servicesFile))
430435
.pipe(sourcemaps.init())
@@ -499,7 +504,7 @@ const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js")
499504
const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
500505

501506
gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile, typesMapJson], (done) => {
502-
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/ true));
507+
const serverLibraryProject = tsc_oop.createProject("src/server/tsconfig.library.json", getCompilerSettings({ removeComments: false }), { typescript: getCompilerPath(/*useBuiltCompiler*/ true) });
503508
/** @type {{ js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream }} */
504509
const {js, dts} = serverLibraryProject.src()
505510
.pipe(sourcemaps.init())
@@ -590,7 +595,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
590595
// Task to build the tests infrastructure using the built compiler
591596
const run = path.join(builtLocalDirectory, "run.js");
592597
gulp.task(run, /*help*/ false, [servicesFile, tsserverLibraryFile], () => {
593-
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
598+
const testProject = tsc_oop.createProject("src/harness/tsconfig.json", getCompilerSettings({}), { typescript: getCompilerPath(/*useBuiltCompiler*/ true) });
594599
return testProject.src()
595600
.pipe(newer(run))
596601
.pipe(sourcemaps.init())

scripts/build/gulp-typescript-oop.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// @ts-check
2+
const path = require("path");
3+
const child_process = require("child_process");
4+
const tsc = require("gulp-typescript");
5+
const Vinyl = require("vinyl");
6+
const { Duplex, Readable } = require("stream");
7+
8+
/**
9+
* @param {string} tsConfigFileName
10+
* @param {tsc.Settings} settings
11+
* @param {Object} options
12+
* @param {string} [options.typescript]
13+
*/
14+
function createProject(tsConfigFileName, settings, options) {
15+
settings = { ...settings };
16+
options = { ...options };
17+
if (settings.typescript) throw new Error();
18+
19+
const localSettings = { ...settings };
20+
if (options.typescript) {
21+
options.typescript = path.resolve(options.typescript);
22+
localSettings.typescript = require(options.typescript);
23+
}
24+
25+
const project = tsc.createProject(tsConfigFileName, localSettings);
26+
const wrappedProject = /** @type {tsc.Project} */(() => {
27+
const proc = child_process.fork(require.resolve("./main.js"));
28+
/** @type {Duplex & { js?: Readable, dts?: Readable }} */
29+
const compileStream = new Duplex({
30+
objectMode: true,
31+
read() {},
32+
/** @param {*} file */
33+
write(file, encoding, callback) {
34+
proc.send({ method: "write", params: { path: file.path, cwd: file.cwd, base: file.base }});
35+
callback();
36+
},
37+
final(callback) {
38+
proc.send({ method: "final" });
39+
callback();
40+
}
41+
});
42+
const jsStream = compileStream.js = new Readable({
43+
objectMode: true,
44+
read() {}
45+
});
46+
const dtsStream = compileStream.dts = new Readable({
47+
objectMode: true,
48+
read() {}
49+
});
50+
proc.send({ method: "createProject", params: { tsConfigFileName, settings, options } });
51+
proc.on("message", ({ method, params }) => {
52+
if (method === "write") {
53+
const file = new Vinyl({
54+
path: params.path,
55+
cwd: params.cwd,
56+
base: params.base,
57+
contents: Buffer.from(params.contents, "utf8")
58+
});
59+
if (params.sourceMap) file.sourceMap = params.sourceMap
60+
compileStream.push(file);;
61+
if (file.path.endsWith(".d.ts")) {
62+
dtsStream.push(file);
63+
}
64+
else {
65+
jsStream.push(file);
66+
}
67+
}
68+
else if (method === "final") {
69+
compileStream.push(null);
70+
jsStream.push(null);
71+
dtsStream.push(null);
72+
proc.kill();
73+
}
74+
else if (method === "error") {
75+
const error = new Error();
76+
error.name = params.name;
77+
error.message = params.message;
78+
error.stack = params.stack;
79+
compileStream.emit("error", error);
80+
proc.kill();
81+
}
82+
});
83+
return /** @type {*} */(compileStream);
84+
});
85+
return Object.assign(wrappedProject, project);
86+
}
87+
88+
exports.createProject = createProject;

scripts/build/main.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// @ts-check
2+
const path = require("path");
3+
const fs = require("fs");
4+
const tsc = require("gulp-typescript");
5+
const Vinyl = require("vinyl");
6+
const { Readable, Writable } = require("stream");
7+
8+
/** @type {tsc.Project} */
9+
let project;
10+
11+
/** @type {Readable} */
12+
let inputStream;
13+
14+
/** @type {Writable} */
15+
let outputStream;
16+
17+
/** @type {tsc.CompileStream} */
18+
let compileStream;
19+
20+
process.on("message", ({ method, params }) => {
21+
try {
22+
if (method === "createProject") {
23+
const { tsConfigFileName, settings, options } = params;
24+
if (options.typescript) {
25+
settings.typescript = require(options.typescript);
26+
}
27+
project = tsc.createProject(tsConfigFileName, settings);
28+
inputStream = new Readable({
29+
objectMode: true,
30+
read() {}
31+
});
32+
outputStream = new Writable({
33+
objectMode: true,
34+
/**
35+
* @param {*} file
36+
*/
37+
write(file, encoding, callback) {
38+
process.send({
39+
method: "write",
40+
params: {
41+
path: file.path,
42+
cwd: file.cwd,
43+
base: file.base,
44+
contents: file.contents.toString(),
45+
sourceMap: file.sourceMap
46+
}
47+
});
48+
callback();
49+
},
50+
final(callback) {
51+
process.send({ method: "final" });
52+
callback();
53+
}
54+
});
55+
outputStream.on("error", error => {
56+
process.send({
57+
method: "error",
58+
params: {
59+
name: error.name,
60+
message: error.message,
61+
stack: error.stack
62+
}
63+
});
64+
});
65+
compileStream = project();
66+
inputStream.pipe(compileStream).pipe(outputStream);
67+
}
68+
else if (method === "write") {
69+
const file = new Vinyl({
70+
path: params.path,
71+
cwd: params.cwd,
72+
base: params.base
73+
});
74+
file.contents = fs.readFileSync(file.path);
75+
inputStream.push(/** @type {*} */(file));
76+
}
77+
else if (method === "final") {
78+
inputStream.push(null);
79+
}
80+
}
81+
catch (e) {
82+
process.send({
83+
method: "error",
84+
params: {
85+
name: e.name,
86+
message: e.message,
87+
stack: e.stack
88+
}
89+
});
90+
}
91+
});

src/compiler/checker.ts

+3-80
Original file line numberDiff line numberDiff line change
@@ -17382,88 +17382,11 @@ namespace ts {
1738217382
* and 1 insertion/deletion at 3 characters)
1738317383
*/
1738417384
function getSpellingSuggestionForName(name: string, symbols: Symbol[], meaning: SymbolFlags): Symbol | undefined {
17385-
const maximumLengthDifference = Math.min(2, Math.floor(name.length * 0.34));
17386-
let bestDistance = Math.floor(name.length * 0.4) + 1; // If the best result isn't better than this, don't bother.
17387-
let bestCandidate: Symbol | undefined;
17388-
let justCheckExactMatches = false;
17389-
const nameLowerCase = name.toLowerCase();
17390-
for (const candidate of symbols) {
17385+
return getSpellingSuggestion(name, symbols, getCandidateName);
17386+
function getCandidateName(candidate: Symbol) {
1739117387
const candidateName = symbolName(candidate);
17392-
if (candidateName.charCodeAt(0) === CharacterCodes.doubleQuote
17393-
|| !(candidate.flags & meaning && Math.abs(candidateName.length - nameLowerCase.length) <= maximumLengthDifference)) {
17394-
continue;
17395-
}
17396-
const candidateNameLowerCase = candidateName.toLowerCase();
17397-
if (candidateNameLowerCase === nameLowerCase) {
17398-
return candidate;
17399-
}
17400-
if (justCheckExactMatches) {
17401-
continue;
17402-
}
17403-
if (candidateName.length < 3) {
17404-
// Don't bother, user would have noticed a 2-character name having an extra character
17405-
continue;
17406-
}
17407-
// Only care about a result better than the best so far.
17408-
const distance = levenshteinWithMax(nameLowerCase, candidateNameLowerCase, bestDistance - 1);
17409-
if (distance === undefined) {
17410-
continue;
17411-
}
17412-
if (distance < 3) {
17413-
justCheckExactMatches = true;
17414-
bestCandidate = candidate;
17415-
}
17416-
else {
17417-
Debug.assert(distance < bestDistance); // Else `levenshteinWithMax` should return undefined
17418-
bestDistance = distance;
17419-
bestCandidate = candidate;
17420-
}
17388+
return !startsWith(candidateName, "\"") && candidate.flags & meaning ? candidateName : undefined;
1742117389
}
17422-
return bestCandidate;
17423-
}
17424-
17425-
function levenshteinWithMax(s1: string, s2: string, max: number): number | undefined {
17426-
let previous = new Array(s2.length + 1);
17427-
let current = new Array(s2.length + 1);
17428-
/** Represents any value > max. We don't care about the particular value. */
17429-
const big = max + 1;
17430-
17431-
for (let i = 0; i <= s2.length; i++) {
17432-
previous[i] = i;
17433-
}
17434-
17435-
for (let i = 1; i <= s1.length; i++) {
17436-
const c1 = s1.charCodeAt(i - 1);
17437-
const minJ = i > max ? i - max : 1;
17438-
const maxJ = s2.length > max + i ? max + i : s2.length;
17439-
current[0] = i;
17440-
/** Smallest value of the matrix in the ith column. */
17441-
let colMin = i;
17442-
for (let j = 1; j < minJ; j++) {
17443-
current[j] = big;
17444-
}
17445-
for (let j = minJ; j <= maxJ; j++) {
17446-
const dist = c1 === s2.charCodeAt(j - 1)
17447-
? previous[j - 1]
17448-
: Math.min(/*delete*/ previous[j] + 1, /*insert*/ current[j - 1] + 1, /*substitute*/ previous[j - 1] + 2);
17449-
current[j] = dist;
17450-
colMin = Math.min(colMin, dist);
17451-
}
17452-
for (let j = maxJ + 1; j <= s2.length; j++) {
17453-
current[j] = big;
17454-
}
17455-
if (colMin > max) {
17456-
// Give up -- everything in this column is > max and it can't get better in future columns.
17457-
return undefined;
17458-
}
17459-
17460-
const temp = previous;
17461-
previous = current;
17462-
current = temp;
17463-
}
17464-
17465-
const res = previous[s2.length];
17466-
return res > max ? undefined : res;
1746717390
}
1746817391

1746917392
function markPropertyAsReferenced(prop: Symbol, nodeForCheckWriteOnly: Node | undefined, isThisAccess: boolean) {

0 commit comments

Comments
 (0)