Skip to content
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

Pick up TS 4.7 for building VS Code #145273

Merged
merged 2 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions build/lib/monaco-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,12 @@ class TypeScriptLanguageServiceHost {
isDefaultLibFileName(fileName) {
return fileName === this.getDefaultLibFileName(this._compilerOptions);
}
readFile(path, _encoding) {
return this._files[path] || this._libs[path];
}
fileExists(path) {
return path in this._files || path in this._libs;
}
}
function execute() {
let r = run3(new DeclarationResolver(new FSProvider()));
Expand Down
8 changes: 7 additions & 1 deletion build/lib/monaco-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class CacheEntry {
constructor(
public readonly sourceFile: ts.SourceFile,
public readonly mtime: number
) {}
) { }
}

export class DeclarationResolver {
Expand Down Expand Up @@ -723,6 +723,12 @@ class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
isDefaultLibFileName(fileName: string): boolean {
return fileName === this.getDefaultLibFileName(this._compilerOptions);
}
readFile(path: string, _encoding?: string): string | undefined {
return this._files[path] || this._libs[path];
}
fileExists(path: string): boolean {
return path in this._files || path in this._libs;
}
}

export function execute(): IMonacoDeclarationResult {
Expand Down
9 changes: 9 additions & 0 deletions build/lib/nls.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ var _nls;
this.file = ts.ScriptSnapshot.fromString(contents);
this.lib = ts.ScriptSnapshot.fromString('');
}
readFile(path, _encoding) {
if (path === this.filename) {
return this.file.getText(0, this.file.getLength());
}
return undefined;
}
fileExists(path) {
return path === this.filename;
}
}
function isCallExpressionWithinTextSpanCollectStep(ts, textSpan, node) {
if (!ts.textSpanContainsTextSpan({ start: node.pos, length: node.end - node.pos }, textSpan)) {
Expand Down
12 changes: 11 additions & 1 deletion build/lib/nls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function template(lines: string[]): string {
return `/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
define([], [${ wrap + lines.map(l => indent + l).join(',\n') + wrap}]);`;
define([], [${wrap + lines.map(l => indent + l).join(',\n') + wrap}]);`;
}

/**
Expand Down Expand Up @@ -161,6 +161,16 @@ module _nls {
getScriptSnapshot = (name: string) => name === this.filename ? this.file : this.lib;
getCurrentDirectory = () => '';
getDefaultLibFileName = () => 'lib.d.ts';

readFile(path: string, _encoding?: string): string | undefined {
if (path === this.filename) {
return this.file.getText(0, this.file.getLength());
}
return undefined;
}
fileExists(path: string): boolean {
return path === this.filename;
}
}

function isCallExpressionWithinTextSpanCollectStep(ts: typeof import('typescript'), textSpan: ts.TextSpan, node: ts.Node): CollectStepResult {
Expand Down
70 changes: 38 additions & 32 deletions build/lib/treeshaking.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ var ShakeLevel;
})(ShakeLevel = exports.ShakeLevel || (exports.ShakeLevel = {}));
function toStringShakeLevel(shakeLevel) {
switch (shakeLevel) {
case 0 /* Files */:
case 0 /* ShakeLevel.Files */:
return 'Files (0)';
case 1 /* InnerFile */:
case 1 /* ShakeLevel.InnerFile */:
return 'InnerFile (1)';
case 2 /* ClassMembers */:
case 2 /* ShakeLevel.ClassMembers */:
return 'ClassMembers (2)';
}
}
Expand Down Expand Up @@ -205,6 +205,12 @@ class TypeScriptLanguageServiceHost {
isDefaultLibFileName(fileName) {
return fileName === this.getDefaultLibFileName(this._compilerOptions);
}
readFile(path, _encoding) {
return this._files[path] || this._libs[path];
}
fileExists(path) {
return path in this._files || path in this._libs;
}
}
//#endregion
//#region Tree Shaking
Expand All @@ -215,23 +221,23 @@ var NodeColor;
NodeColor[NodeColor["Black"] = 2] = "Black";
})(NodeColor || (NodeColor = {}));
function getColor(node) {
return node.$$$color || 0 /* White */;
return node.$$$color || 0 /* NodeColor.White */;
}
function setColor(node, color) {
node.$$$color = color;
}
function nodeOrParentIsBlack(node) {
while (node) {
const color = getColor(node);
if (color === 2 /* Black */) {
if (color === 2 /* NodeColor.Black */) {
return true;
}
node = node.parent;
}
return false;
}
function nodeOrChildIsBlack(node) {
if (getColor(node) === 2 /* Black */) {
if (getColor(node) === 2 /* NodeColor.Black */) {
return true;
}
for (const child of node.getChildren()) {
Expand Down Expand Up @@ -295,10 +301,10 @@ function markNodes(ts, languageService, options) {
if (!program) {
throw new Error('Could not get program from language service');
}
if (options.shakeLevel === 0 /* Files */) {
if (options.shakeLevel === 0 /* ShakeLevel.Files */) {
// Mark all source files Black
program.getSourceFiles().forEach((sourceFile) => {
setColor(sourceFile, 2 /* Black */);
setColor(sourceFile, 2 /* NodeColor.Black */);
});
return;
}
Expand All @@ -310,15 +316,15 @@ function markNodes(ts, languageService, options) {
sourceFile.forEachChild((node) => {
if (ts.isImportDeclaration(node)) {
if (!node.importClause && ts.isStringLiteral(node.moduleSpecifier)) {
setColor(node, 2 /* Black */);
setColor(node, 2 /* NodeColor.Black */);
enqueueImport(node, node.moduleSpecifier.text);
}
return;
}
if (ts.isExportDeclaration(node)) {
if (!node.exportClause && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
// export * from "foo";
setColor(node, 2 /* Black */);
setColor(node, 2 /* NodeColor.Black */);
enqueueImport(node, node.moduleSpecifier.text);
}
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
Expand Down Expand Up @@ -346,21 +352,21 @@ function markNodes(ts, languageService, options) {
});
}
function enqueue_gray(node) {
if (nodeOrParentIsBlack(node) || getColor(node) === 1 /* Gray */) {
if (nodeOrParentIsBlack(node) || getColor(node) === 1 /* NodeColor.Gray */) {
return;
}
setColor(node, 1 /* Gray */);
setColor(node, 1 /* NodeColor.Gray */);
gray_queue.push(node);
}
function enqueue_black(node) {
const previousColor = getColor(node);
if (previousColor === 2 /* Black */) {
if (previousColor === 2 /* NodeColor.Black */) {
return;
}
if (previousColor === 1 /* Gray */) {
if (previousColor === 1 /* NodeColor.Gray */) {
// remove from gray queue
gray_queue.splice(gray_queue.indexOf(node), 1);
setColor(node, 0 /* White */);
setColor(node, 0 /* NodeColor.White */);
// add to black queue
enqueue_black(node);
// move from one queue to the other
Expand All @@ -373,7 +379,7 @@ function markNodes(ts, languageService, options) {
}
const fileName = node.getSourceFile().fileName;
if (/^defaultLib:/.test(fileName) || /\.d\.ts$/.test(fileName)) {
setColor(node, 2 /* Black */);
setColor(node, 2 /* NodeColor.Black */);
return;
}
const sourceFile = node.getSourceFile();
Expand All @@ -384,9 +390,9 @@ function markNodes(ts, languageService, options) {
if (ts.isSourceFile(node)) {
return;
}
setColor(node, 2 /* Black */);
setColor(node, 2 /* NodeColor.Black */);
black_queue.push(node);
if (options.shakeLevel === 2 /* ClassMembers */ && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || ts.isPropertySignature(node) || ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node))) {
if (options.shakeLevel === 2 /* ShakeLevel.ClassMembers */ && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || ts.isPropertySignature(node) || ts.isPropertyDeclaration(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node))) {
const references = languageService.getReferencesAtPosition(node.getSourceFile().fileName, node.name.pos + node.name.getLeadingTriviaWidth());
if (references) {
for (let i = 0, len = references.length; i < len; i++) {
Expand Down Expand Up @@ -447,7 +453,7 @@ function markNodes(ts, languageService, options) {
if ((ts.isClassDeclaration(nodeParent) || ts.isInterfaceDeclaration(nodeParent)) && nodeOrChildIsBlack(nodeParent)) {
gray_queue.splice(i, 1);
black_queue.push(node);
setColor(node, 2 /* Black */);
setColor(node, 2 /* NodeColor.Black */);
i--;
}
}
Expand All @@ -463,7 +469,7 @@ function markNodes(ts, languageService, options) {
const loop = (node) => {
const [symbol, symbolImportNode] = getRealNodeSymbol(ts, checker, node);
if (symbolImportNode) {
setColor(symbolImportNode, 2 /* Black */);
setColor(symbolImportNode, 2 /* NodeColor.Black */);
}
if (isSymbolWithDeclarations(symbol) && !nodeIsInItsOwnDeclaration(nodeSourceFile, node, symbol)) {
for (let i = 0, len = symbol.declarations.length; i < len; i++) {
Expand All @@ -473,7 +479,7 @@ function markNodes(ts, languageService, options) {
// (they can be the declaration of a module import)
continue;
}
if (options.shakeLevel === 2 /* ClassMembers */ && (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration)) && !isLocalCodeExtendingOrInheritingFromDefaultLibSymbol(ts, program, checker, declaration)) {
if (options.shakeLevel === 2 /* ShakeLevel.ClassMembers */ && (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration)) && !isLocalCodeExtendingOrInheritingFromDefaultLibSymbol(ts, program, checker, declaration)) {
enqueue_black(declaration.name);
for (let j = 0; j < declaration.members.length; j++) {
const member = declaration.members[j];
Expand Down Expand Up @@ -523,7 +529,7 @@ function markNodes(ts, languageService, options) {
const aliased = checker.getAliasedSymbol(symbol);
if (aliased.declarations && aliased.declarations.length > 0) {
if (nodeOrParentIsBlack(aliased.declarations[0]) || nodeOrChildIsBlack(aliased.declarations[0])) {
setColor(node, 2 /* Black */);
setColor(node, 2 /* NodeColor.Black */);
}
}
}
Expand Down Expand Up @@ -570,7 +576,7 @@ function generateResult(ts, languageService, shakeLevel) {
result += data;
}
function writeMarkedNodes(node) {
if (getColor(node) === 2 /* Black */) {
if (getColor(node) === 2 /* NodeColor.Black */) {
return keep(node);
}
// Always keep certain top-level statements
Expand All @@ -586,34 +592,34 @@ function generateResult(ts, languageService, shakeLevel) {
if (ts.isImportDeclaration(node)) {
if (node.importClause && node.importClause.namedBindings) {
if (ts.isNamespaceImport(node.importClause.namedBindings)) {
if (getColor(node.importClause.namedBindings) === 2 /* Black */) {
if (getColor(node.importClause.namedBindings) === 2 /* NodeColor.Black */) {
return keep(node);
}
}
else {
let survivingImports = [];
for (const importNode of node.importClause.namedBindings.elements) {
if (getColor(importNode) === 2 /* Black */) {
if (getColor(importNode) === 2 /* NodeColor.Black */) {
survivingImports.push(importNode.getFullText(sourceFile));
}
}
const leadingTriviaWidth = node.getLeadingTriviaWidth();
const leadingTrivia = sourceFile.text.substr(node.pos, leadingTriviaWidth);
if (survivingImports.length > 0) {
if (node.importClause && node.importClause.name && getColor(node.importClause) === 2 /* Black */) {
if (node.importClause && node.importClause.name && getColor(node.importClause) === 2 /* NodeColor.Black */) {
return write(`${leadingTrivia}import ${node.importClause.name.text}, {${survivingImports.join(',')} } from${node.moduleSpecifier.getFullText(sourceFile)};`);
}
return write(`${leadingTrivia}import {${survivingImports.join(',')} } from${node.moduleSpecifier.getFullText(sourceFile)};`);
}
else {
if (node.importClause && node.importClause.name && getColor(node.importClause) === 2 /* Black */) {
if (node.importClause && node.importClause.name && getColor(node.importClause) === 2 /* NodeColor.Black */) {
return write(`${leadingTrivia}import ${node.importClause.name.text} from${node.moduleSpecifier.getFullText(sourceFile)};`);
}
}
}
}
else {
if (node.importClause && getColor(node.importClause) === 2 /* Black */) {
if (node.importClause && getColor(node.importClause) === 2 /* NodeColor.Black */) {
return keep(node);
}
}
Expand All @@ -622,7 +628,7 @@ function generateResult(ts, languageService, shakeLevel) {
if (node.exportClause && node.moduleSpecifier && ts.isNamedExports(node.exportClause)) {
let survivingExports = [];
for (const exportSpecifier of node.exportClause.elements) {
if (getColor(exportSpecifier) === 2 /* Black */) {
if (getColor(exportSpecifier) === 2 /* NodeColor.Black */) {
survivingExports.push(exportSpecifier.getFullText(sourceFile));
}
}
Expand All @@ -633,11 +639,11 @@ function generateResult(ts, languageService, shakeLevel) {
}
}
}
if (shakeLevel === 2 /* ClassMembers */ && (ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node)) && nodeOrChildIsBlack(node)) {
if (shakeLevel === 2 /* ShakeLevel.ClassMembers */ && (ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node)) && nodeOrChildIsBlack(node)) {
let toWrite = node.getFullText();
for (let i = node.members.length - 1; i >= 0; i--) {
const member = node.members[i];
if (getColor(member) === 2 /* Black */ || !member.name) {
if (getColor(member) === 2 /* NodeColor.Black */ || !member.name) {
// keep method
continue;
}
Expand All @@ -653,7 +659,7 @@ function generateResult(ts, languageService, shakeLevel) {
}
node.forEachChild(writeMarkedNodes);
}
if (getColor(sourceFile) !== 2 /* Black */) {
if (getColor(sourceFile) !== 2 /* NodeColor.Black */) {
if (!nodeOrChildIsBlack(sourceFile)) {
// none of the elements are reachable => don't write this file at all!
return;
Expand Down
6 changes: 6 additions & 0 deletions build/lib/treeshaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
isDefaultLibFileName(fileName: string): boolean {
return fileName === this.getDefaultLibFileName(this._compilerOptions);
}
readFile(path: string, _encoding?: string): string | undefined {
return this._files[path] || this._libs[path];
}
fileExists(path: string): boolean {
return path in this._files || path in this._libs;
}
}
//#endregion

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"style-loader": "^1.0.0",
"ts-loader": "^9.2.7",
"tsec": "0.1.4",
"typescript": "^4.7.0-dev.20220303",
"typescript": "^4.7.0-dev.20220316",
"typescript-formatter": "7.1.0",
"underscore": "^1.12.1",
"util": "^0.12.4",
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHostEditorTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ExtHostTabGroups {
get apiObject() {
if (!this._apiObject) {
const that = this;
this._apiObject = Object.freeze({
this._apiObject = Object.freeze<vscode.Tab>({
onDidChangeTabGroup: that._onDidChangeTagGroup, // never changes -> simple value
onDidChangeActiveTabGroup: that._onDidChangeActiveTabGroup,
get groups() { // dynamic -> getters
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11517,10 +11517,10 @@ typescript@^2.6.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.6.2.tgz#3c5b6fd7f6de0914269027f03c0946758f7673a4"
integrity sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q=

typescript@^4.7.0-dev.20220303:
version "4.7.0-dev.20220303"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.0-dev.20220303.tgz#845889467c51fa27e746100190f750444cfd22ca"
integrity sha512-Lhmh5V02dsae865qHgdZyygJQp7MuErTHJF63NB/by1vXBtuLEUnHoPWbZOGa5lemklMP+VGSjVH6jJyGjabLQ==
typescript@^4.7.0-dev.20220316:
version "4.7.0-dev.20220316"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.0-dev.20220316.tgz#255c8079e39df6182af0089fad6092a8ea49344a"
integrity sha512-026xY5jsAZ/uBqzY2wI28y+iTVHQH+V5Ws2FLIIsusz+ARgsLKF74nz+9JY5O/OQR4/fVB/ky1etIlEo3Tu7tw==

typical@^4.0.0:
version "4.0.0"
Expand Down