mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Merge from vscode merge-base (#22769)
* Merge from vscode merge-base * Turn off basic checks * Enable compilation, unit, and integration tests
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"use strict";
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.shake = exports.toStringShakeLevel = exports.ShakeLevel = void 0;
|
||||
const fs = require("fs");
|
||||
@@ -32,7 +32,7 @@ function printDiagnostics(options, diagnostics) {
|
||||
result += `${path.join(options.sourcesRoot, diag.file.fileName)}`;
|
||||
}
|
||||
if (diag.file && diag.start) {
|
||||
let location = diag.file.getLineAndCharacterOfPosition(diag.start);
|
||||
const location = diag.file.getLineAndCharacterOfPosition(diag.start);
|
||||
result += `:${location.line + 1}:${location.character}`;
|
||||
}
|
||||
result += ` - ` + JSON.stringify(diag.messageText);
|
||||
@@ -89,6 +89,8 @@ function discoverAndReadFiles(ts, options) {
|
||||
const in_queue = Object.create(null);
|
||||
const queue = [];
|
||||
const enqueue = (moduleId) => {
|
||||
// To make the treeshaker work on windows...
|
||||
moduleId = moduleId.replace(/\\/g, '/');
|
||||
if (in_queue[moduleId]) {
|
||||
return;
|
||||
}
|
||||
@@ -150,7 +152,7 @@ function processLibFiles(ts, options) {
|
||||
result[key] = sourceText;
|
||||
// precess dependencies and "recurse"
|
||||
const info = ts.preProcessFile(sourceText);
|
||||
for (let ref of info.libReferenceDirectives) {
|
||||
for (const ref of info.libReferenceDirectives) {
|
||||
stack.push(ref.fileName);
|
||||
}
|
||||
}
|
||||
@@ -226,6 +228,12 @@ function getColor(node) {
|
||||
function setColor(node, color) {
|
||||
node.$$$color = color;
|
||||
}
|
||||
function markNeededSourceFile(node) {
|
||||
node.$$$neededSourceFile = true;
|
||||
}
|
||||
function isNeededSourceFile(node) {
|
||||
return Boolean(node.$$$neededSourceFile);
|
||||
}
|
||||
function nodeOrParentIsBlack(node) {
|
||||
while (node) {
|
||||
const color = getColor(node);
|
||||
@@ -351,6 +359,19 @@ function markNodes(ts, languageService, options) {
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Return the parent of `node` which is an ImportDeclaration
|
||||
*/
|
||||
function findParentImportDeclaration(node) {
|
||||
let _node = node;
|
||||
do {
|
||||
if (ts.isImportDeclaration(_node)) {
|
||||
return _node;
|
||||
}
|
||||
_node = _node.parent;
|
||||
} while (_node);
|
||||
return null;
|
||||
}
|
||||
function enqueue_gray(node) {
|
||||
if (nodeOrParentIsBlack(node) || getColor(node) === 1 /* Gray */) {
|
||||
return;
|
||||
@@ -418,6 +439,8 @@ function markNodes(ts, languageService, options) {
|
||||
console.warn(`Cannot find source file ${filename}`);
|
||||
return;
|
||||
}
|
||||
// This source file should survive even if it is empty
|
||||
markNeededSourceFile(sourceFile);
|
||||
enqueue_black(sourceFile);
|
||||
}
|
||||
function enqueueImport(node, importText) {
|
||||
@@ -469,7 +492,11 @@ 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 */);
|
||||
const importDeclarationNode = findParentImportDeclaration(symbolImportNode);
|
||||
if (importDeclarationNode && ts.isStringLiteral(importDeclarationNode.moduleSpecifier)) {
|
||||
enqueueImport(importDeclarationNode, importDeclarationNode.moduleSpecifier.text);
|
||||
}
|
||||
}
|
||||
if (isSymbolWithDeclarations(symbol) && !nodeIsInItsOwnDeclaration(nodeSourceFile, node, symbol)) {
|
||||
for (let i = 0, len = symbol.declarations.length; i < len; i++) { // {{SQL CARBON EDIT}} Compile fixes
|
||||
@@ -503,7 +530,7 @@ function markNodes(ts, languageService, options) {
|
||||
}
|
||||
// queue the heritage clauses
|
||||
if (declaration.heritageClauses) {
|
||||
for (let heritageClause of declaration.heritageClauses) {
|
||||
for (const heritageClause of declaration.heritageClauses) {
|
||||
enqueue_black(heritageClause);
|
||||
}
|
||||
}
|
||||
@@ -551,7 +578,7 @@ function generateResult(ts, languageService, shakeLevel) {
|
||||
if (!program) {
|
||||
throw new Error('Could not get program from language service');
|
||||
}
|
||||
let result = {};
|
||||
const result = {};
|
||||
const writeFile = (filePath, contents) => {
|
||||
result[filePath] = contents;
|
||||
};
|
||||
@@ -567,7 +594,7 @@ function generateResult(ts, languageService, shakeLevel) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
let text = sourceFile.text;
|
||||
const text = sourceFile.text;
|
||||
let result = '';
|
||||
function keep(node) {
|
||||
result += text.substring(node.pos, node.end);
|
||||
@@ -597,7 +624,7 @@ function generateResult(ts, languageService, shakeLevel) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
let survivingImports = [];
|
||||
const survivingImports = [];
|
||||
for (const importNode of node.importClause.namedBindings.elements) {
|
||||
if (getColor(importNode) === 2 /* Black */) {
|
||||
survivingImports.push(importNode.getFullText(sourceFile));
|
||||
@@ -626,7 +653,7 @@ function generateResult(ts, languageService, shakeLevel) {
|
||||
}
|
||||
if (ts.isExportDeclaration(node)) {
|
||||
if (node.exportClause && node.moduleSpecifier && ts.isNamedExports(node.exportClause)) {
|
||||
let survivingExports = [];
|
||||
const survivingExports = [];
|
||||
for (const exportSpecifier of node.exportClause.elements) {
|
||||
if (getColor(exportSpecifier) === 2 /* Black */) {
|
||||
survivingExports.push(exportSpecifier.getFullText(sourceFile));
|
||||
@@ -647,8 +674,8 @@ function generateResult(ts, languageService, shakeLevel) {
|
||||
// keep method
|
||||
continue;
|
||||
}
|
||||
let pos = member.pos - node.pos;
|
||||
let end = member.end - node.pos;
|
||||
const pos = member.pos - node.pos;
|
||||
const end = member.end - node.pos;
|
||||
toWrite = toWrite.substring(0, pos) + toWrite.substring(end);
|
||||
}
|
||||
return write(toWrite);
|
||||
@@ -661,11 +688,23 @@ function generateResult(ts, languageService, shakeLevel) {
|
||||
}
|
||||
if (getColor(sourceFile) !== 2 /* Black */) {
|
||||
if (!nodeOrChildIsBlack(sourceFile)) {
|
||||
// none of the elements are reachable => don't write this file at all!
|
||||
return;
|
||||
// none of the elements are reachable
|
||||
if (isNeededSourceFile(sourceFile)) {
|
||||
// this source file must be written, even if nothing is used from it
|
||||
// because there is an import somewhere for it.
|
||||
// However, TS complains with empty files with the error "x" is not a module,
|
||||
// so we will export a dummy variable
|
||||
result = 'export const __dummy = 0;';
|
||||
}
|
||||
else {
|
||||
// don't write this file at all!
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sourceFile.forEachChild(writeMarkedNodes);
|
||||
result += sourceFile.endOfFileToken.getFullText(sourceFile);
|
||||
}
|
||||
sourceFile.forEachChild(writeMarkedNodes);
|
||||
result += sourceFile.endOfFileToken.getFullText(sourceFile);
|
||||
}
|
||||
else {
|
||||
result = text;
|
||||
@@ -839,3 +878,4 @@ function getTokenAtPosition(ts, sourceFile, position, allowPositionInLeadingTriv
|
||||
return current;
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
|
||||
Reference in New Issue
Block a user