mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Merge from vscode cfc1ab4c5f816765b91fb7ead3c3427a7c8581a3
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createAsar = void 0;
|
||||
const path = require("path");
|
||||
const es = require("event-stream");
|
||||
const pickle = require('chromium-pickle-js');
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.bundle = void 0;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const vm = require("vm");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.watchTask = exports.compileTask = void 0;
|
||||
const es = require("event-stream");
|
||||
const fs = require("fs");
|
||||
const gulp = require("gulp");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.config = exports.getElectronVersion = void 0;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const vfs = require("vinyl-fs");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createImportRuleListener = void 0;
|
||||
function createImportRuleListener(validateImport) {
|
||||
function _checkImport(node) {
|
||||
if (node && node.type === 'Literal' && typeof node.value === 'string') {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.packageRebuildExtensionsStream = exports.cleanRebuildExtensions = exports.packageExternalExtensionsStream = exports.packageMarketplaceExtensionsStream = exports.packageLocalExtensionsStream = exports.fromMarketplace = void 0;
|
||||
const es = require("event-stream");
|
||||
const fs = require("fs");
|
||||
const glob = require("glob");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getVersion = void 0;
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.prepareIslFiles = exports.prepareI18nPackFiles = exports.pullI18nPackFiles = exports.prepareI18nFiles = exports.pullSetupXlfFiles = exports.pullCoreAndExtensionsXlfFiles = exports.findObsoleteResources = exports.pushXlfFiles = exports.createXlfFilesForIsl = exports.createXlfFilesForExtensions = exports.createXlfFilesForCoreBundle = exports.getResource = exports.processNlsFiles = exports.Limiter = exports.XLF = exports.Line = exports.externalExtensionsWithTranslations = exports.extraLanguages = exports.defaultLanguages = void 0;
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const event_stream_1 = require("event-stream");
|
||||
@@ -100,155 +101,161 @@ class TextModel {
|
||||
return this._lines;
|
||||
}
|
||||
}
|
||||
class XLF {
|
||||
constructor(project) {
|
||||
this.project = project;
|
||||
this.buffer = [];
|
||||
this.files = Object.create(null);
|
||||
this.numberOfMessages = 0;
|
||||
}
|
||||
toString() {
|
||||
this.appendHeader();
|
||||
for (let file in this.files) {
|
||||
this.appendNewLine(`<file original="${file}" source-language="en" datatype="plaintext"><body>`, 2);
|
||||
for (let item of this.files[file]) {
|
||||
this.addStringItem(item);
|
||||
}
|
||||
this.appendNewLine('</body></file>', 2);
|
||||
let XLF = /** @class */ (() => {
|
||||
class XLF {
|
||||
constructor(project) {
|
||||
this.project = project;
|
||||
this.buffer = [];
|
||||
this.files = Object.create(null);
|
||||
this.numberOfMessages = 0;
|
||||
}
|
||||
this.appendFooter();
|
||||
return this.buffer.join('\r\n');
|
||||
}
|
||||
addFile(original, keys, messages) {
|
||||
if (keys.length === 0) {
|
||||
console.log('No keys in ' + original);
|
||||
return;
|
||||
}
|
||||
if (keys.length !== messages.length) {
|
||||
throw new Error(`Unmatching keys(${keys.length}) and messages(${messages.length}).`);
|
||||
}
|
||||
this.numberOfMessages += keys.length;
|
||||
this.files[original] = [];
|
||||
let existingKeys = new Set();
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
let realKey;
|
||||
let comment;
|
||||
if (Is.string(key)) {
|
||||
realKey = key;
|
||||
comment = undefined;
|
||||
}
|
||||
else if (LocalizeInfo.is(key)) {
|
||||
realKey = key.key;
|
||||
if (key.comment && key.comment.length > 0) {
|
||||
comment = key.comment.map(comment => encodeEntities(comment)).join('\r\n');
|
||||
toString() {
|
||||
this.appendHeader();
|
||||
for (let file in this.files) {
|
||||
this.appendNewLine(`<file original="${file}" source-language="en" datatype="plaintext"><body>`, 2);
|
||||
for (let item of this.files[file]) {
|
||||
this.addStringItem(file, item);
|
||||
}
|
||||
this.appendNewLine('</body></file>', 2);
|
||||
}
|
||||
if (!realKey || existingKeys.has(realKey)) {
|
||||
continue;
|
||||
this.appendFooter();
|
||||
return this.buffer.join('\r\n');
|
||||
}
|
||||
addFile(original, keys, messages) {
|
||||
if (keys.length === 0) {
|
||||
console.log('No keys in ' + original);
|
||||
return;
|
||||
}
|
||||
existingKeys.add(realKey);
|
||||
let message = encodeEntities(messages[i]);
|
||||
this.files[original].push({ id: realKey, message: message, comment: comment });
|
||||
if (keys.length !== messages.length) {
|
||||
throw new Error(`Unmatching keys(${keys.length}) and messages(${messages.length}).`);
|
||||
}
|
||||
this.numberOfMessages += keys.length;
|
||||
this.files[original] = [];
|
||||
let existingKeys = new Set();
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
let key = keys[i];
|
||||
let realKey;
|
||||
let comment;
|
||||
if (Is.string(key)) {
|
||||
realKey = key;
|
||||
comment = undefined;
|
||||
}
|
||||
else if (LocalizeInfo.is(key)) {
|
||||
realKey = key.key;
|
||||
if (key.comment && key.comment.length > 0) {
|
||||
comment = key.comment.map(comment => encodeEntities(comment)).join('\r\n');
|
||||
}
|
||||
}
|
||||
if (!realKey || existingKeys.has(realKey)) {
|
||||
continue;
|
||||
}
|
||||
existingKeys.add(realKey);
|
||||
let message = encodeEntities(messages[i]);
|
||||
this.files[original].push({ id: realKey, message: message, comment: comment });
|
||||
}
|
||||
}
|
||||
addStringItem(file, item) {
|
||||
if (!item.id || item.message === undefined || item.message === null) {
|
||||
throw new Error(`No item ID or value specified: ${JSON.stringify(item)}. File: ${file}`);
|
||||
}
|
||||
if (item.message.length === 0) {
|
||||
log(`Item with id ${item.id} in file ${file} has an empty message.`);
|
||||
}
|
||||
this.appendNewLine(`<trans-unit id="${item.id}">`, 4);
|
||||
this.appendNewLine(`<source xml:lang="en">${item.message}</source>`, 6);
|
||||
if (item.comment) {
|
||||
this.appendNewLine(`<note>${item.comment}</note>`, 6);
|
||||
}
|
||||
this.appendNewLine('</trans-unit>', 4);
|
||||
}
|
||||
appendHeader() {
|
||||
this.appendNewLine('<?xml version="1.0" encoding="utf-8"?>', 0);
|
||||
this.appendNewLine('<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">', 0);
|
||||
}
|
||||
appendFooter() {
|
||||
this.appendNewLine('</xliff>', 0);
|
||||
}
|
||||
appendNewLine(content, indent) {
|
||||
let line = new Line(indent);
|
||||
line.append(content);
|
||||
this.buffer.push(line.toString());
|
||||
}
|
||||
}
|
||||
addStringItem(item) {
|
||||
if (!item.id || !item.message) {
|
||||
throw new Error(`No item ID or value specified: ${JSON.stringify(item)}`);
|
||||
}
|
||||
this.appendNewLine(`<trans-unit id="${item.id}">`, 4);
|
||||
this.appendNewLine(`<source xml:lang="en">${item.message}</source>`, 6);
|
||||
if (item.comment) {
|
||||
this.appendNewLine(`<note>${item.comment}</note>`, 6);
|
||||
}
|
||||
this.appendNewLine('</trans-unit>', 4);
|
||||
}
|
||||
appendHeader() {
|
||||
this.appendNewLine('<?xml version="1.0" encoding="utf-8"?>', 0);
|
||||
this.appendNewLine('<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">', 0);
|
||||
}
|
||||
appendFooter() {
|
||||
this.appendNewLine('</xliff>', 0);
|
||||
}
|
||||
appendNewLine(content, indent) {
|
||||
let line = new Line(indent);
|
||||
line.append(content);
|
||||
this.buffer.push(line.toString());
|
||||
}
|
||||
}
|
||||
XLF.parsePseudo = function (xlfString) {
|
||||
return new Promise((resolve) => {
|
||||
let parser = new xml2js.Parser();
|
||||
let files = [];
|
||||
parser.parseString(xlfString, function (_err, result) {
|
||||
const fileNodes = result['xliff']['file'];
|
||||
fileNodes.forEach(file => {
|
||||
const originalFilePath = file.$.original;
|
||||
const messages = {};
|
||||
const transUnits = file.body[0]['trans-unit'];
|
||||
if (transUnits) {
|
||||
transUnits.forEach((unit) => {
|
||||
const key = unit.$.id;
|
||||
const val = pseudify(unit.source[0]['_'].toString());
|
||||
if (key && val) {
|
||||
messages[key] = decodeEntities(val);
|
||||
}
|
||||
});
|
||||
files.push({ messages: messages, originalFilePath: originalFilePath, language: 'ps' });
|
||||
}
|
||||
});
|
||||
resolve(files);
|
||||
});
|
||||
});
|
||||
};
|
||||
XLF.parse = function (xlfString) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let parser = new xml2js.Parser();
|
||||
let files = [];
|
||||
parser.parseString(xlfString, function (err, result) {
|
||||
if (err) {
|
||||
reject(new Error(`XLF parsing error: Failed to parse XLIFF string. ${err}`));
|
||||
}
|
||||
const fileNodes = result['xliff']['file'];
|
||||
if (!fileNodes) {
|
||||
reject(new Error(`XLF parsing error: XLIFF file does not contain "xliff" or "file" node(s) required for parsing.`));
|
||||
}
|
||||
fileNodes.forEach((file) => {
|
||||
const originalFilePath = file.$.original;
|
||||
if (!originalFilePath) {
|
||||
reject(new Error(`XLF parsing error: XLIFF file node does not contain original attribute to determine the original location of the resource file.`));
|
||||
}
|
||||
let language = file.$['target-language'];
|
||||
if (!language) {
|
||||
reject(new Error(`XLF parsing error: XLIFF file node does not contain target-language attribute to determine translated language.`));
|
||||
}
|
||||
const messages = {};
|
||||
const transUnits = file.body[0]['trans-unit'];
|
||||
if (transUnits) {
|
||||
transUnits.forEach((unit) => {
|
||||
const key = unit.$.id;
|
||||
if (!unit.target) {
|
||||
return; // No translation available
|
||||
}
|
||||
let val = unit.target[0];
|
||||
if (typeof val !== 'string') {
|
||||
val = val._;
|
||||
}
|
||||
if (key && val) {
|
||||
messages[key] = decodeEntities(val);
|
||||
}
|
||||
else {
|
||||
reject(new Error(`XLF parsing error: XLIFF file ${originalFilePath} does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.`));
|
||||
}
|
||||
});
|
||||
files.push({ messages: messages, originalFilePath: originalFilePath, language: language.toLowerCase() });
|
||||
}
|
||||
});
|
||||
resolve(files);
|
||||
});
|
||||
});
|
||||
};
|
||||
return XLF;
|
||||
})();
|
||||
exports.XLF = XLF;
|
||||
XLF.parsePseudo = function (xlfString) {
|
||||
return new Promise((resolve) => {
|
||||
let parser = new xml2js.Parser();
|
||||
let files = [];
|
||||
parser.parseString(xlfString, function (_err, result) {
|
||||
const fileNodes = result['xliff']['file'];
|
||||
fileNodes.forEach(file => {
|
||||
const originalFilePath = file.$.original;
|
||||
const messages = {};
|
||||
const transUnits = file.body[0]['trans-unit'];
|
||||
if (transUnits) {
|
||||
transUnits.forEach((unit) => {
|
||||
const key = unit.$.id;
|
||||
const val = pseudify(unit.source[0]['_'].toString());
|
||||
if (key && val) {
|
||||
messages[key] = decodeEntities(val);
|
||||
}
|
||||
});
|
||||
files.push({ messages: messages, originalFilePath: originalFilePath, language: 'ps' });
|
||||
}
|
||||
});
|
||||
resolve(files);
|
||||
});
|
||||
});
|
||||
};
|
||||
XLF.parse = function (xlfString) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let parser = new xml2js.Parser();
|
||||
let files = [];
|
||||
parser.parseString(xlfString, function (err, result) {
|
||||
if (err) {
|
||||
reject(new Error(`XLF parsing error: Failed to parse XLIFF string. ${err}`));
|
||||
}
|
||||
const fileNodes = result['xliff']['file'];
|
||||
if (!fileNodes) {
|
||||
reject(new Error(`XLF parsing error: XLIFF file does not contain "xliff" or "file" node(s) required for parsing.`));
|
||||
}
|
||||
fileNodes.forEach((file) => {
|
||||
const originalFilePath = file.$.original;
|
||||
if (!originalFilePath) {
|
||||
reject(new Error(`XLF parsing error: XLIFF file node does not contain original attribute to determine the original location of the resource file.`));
|
||||
}
|
||||
let language = file.$['target-language'];
|
||||
if (!language) {
|
||||
reject(new Error(`XLF parsing error: XLIFF file node does not contain target-language attribute to determine translated language.`));
|
||||
}
|
||||
const messages = {};
|
||||
const transUnits = file.body[0]['trans-unit'];
|
||||
if (transUnits) {
|
||||
transUnits.forEach((unit) => {
|
||||
const key = unit.$.id;
|
||||
if (!unit.target) {
|
||||
return; // No translation available
|
||||
}
|
||||
let val = unit.target[0];
|
||||
if (typeof val !== 'string') {
|
||||
val = val._;
|
||||
}
|
||||
if (key && val) {
|
||||
messages[key] = decodeEntities(val);
|
||||
}
|
||||
else {
|
||||
reject(new Error(`XLF parsing error: XLIFF file ${originalFilePath} does not contain full localization data. ID or target translation for one of the trans-unit nodes is not present.`));
|
||||
}
|
||||
});
|
||||
files.push({ messages: messages, originalFilePath: originalFilePath, language: language.toLowerCase() });
|
||||
}
|
||||
});
|
||||
resolve(files);
|
||||
});
|
||||
});
|
||||
};
|
||||
class Limiter {
|
||||
constructor(maxDegreeOfParalellism) {
|
||||
this.maxDegreeOfParalellism = maxDegreeOfParalellism;
|
||||
|
||||
@@ -122,6 +122,10 @@
|
||||
"name": "vs/workbench/contrib/preferences",
|
||||
"project": "vscode-workbench"
|
||||
},
|
||||
{
|
||||
"name": "vs/workbench/contrib/quickaccess",
|
||||
"project": "vscode-workbench"
|
||||
},
|
||||
{
|
||||
"name": "vs/workbench/contrib/quickopen",
|
||||
"project": "vscode-workbench"
|
||||
@@ -262,6 +266,10 @@
|
||||
"name": "vs/workbench/services/files",
|
||||
"project": "vscode-workbench"
|
||||
},
|
||||
{
|
||||
"name": "vs/workbench/services/log",
|
||||
"project": "vscode-workbench"
|
||||
},
|
||||
{
|
||||
"name": "vs/workbench/services/integrity",
|
||||
"project": "vscode-workbench"
|
||||
|
||||
@@ -201,7 +201,7 @@ export class XLF {
|
||||
for (let file in this.files) {
|
||||
this.appendNewLine(`<file original="${file}" source-language="en" datatype="plaintext"><body>`, 2);
|
||||
for (let item of this.files[file]) {
|
||||
this.addStringItem(item);
|
||||
this.addStringItem(file, item);
|
||||
}
|
||||
this.appendNewLine('</body></file>', 2);
|
||||
}
|
||||
@@ -243,9 +243,12 @@ export class XLF {
|
||||
}
|
||||
}
|
||||
|
||||
private addStringItem(item: Item): void {
|
||||
if (!item.id || !item.message) {
|
||||
throw new Error(`No item ID or value specified: ${JSON.stringify(item)}`);
|
||||
private addStringItem(file: string, item: Item): void {
|
||||
if (!item.id || item.message === undefined || item.message === null) {
|
||||
throw new Error(`No item ID or value specified: ${JSON.stringify(item)}. File: ${file}`);
|
||||
}
|
||||
if (item.message.length === 0) {
|
||||
log(`Item with id ${item.id} in file ${file} has an empty message.`);
|
||||
}
|
||||
|
||||
this.appendNewLine(`<trans-unit id="${item.id}">`, 4);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.minifyTask = exports.optimizeTask = exports.loaderConfig = void 0;
|
||||
const es = require("event-stream");
|
||||
const fs = require("fs");
|
||||
const gulp = require("gulp");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createReporter = void 0;
|
||||
const es = require("event-stream");
|
||||
const _ = require("underscore");
|
||||
const fancyLog = require("fancy-log");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.rollupAngular = exports.rollupAngularSlickgrid = void 0;
|
||||
const fs = require("fs");
|
||||
const rollup = require("rollup");
|
||||
const path = require("path");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createESMSourcesAndResources2 = exports.extractEditor = void 0;
|
||||
const ts = require("typescript");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.submitAllStats = exports.createStatsStream = void 0;
|
||||
const es = require("event-stream");
|
||||
const fancyLog = require("fancy-log");
|
||||
const ansiColors = require("ansi-colors");
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.define = exports.parallel = exports.series = void 0;
|
||||
const fancyLog = require("fancy-log");
|
||||
const ansiColors = require("ansi-colors");
|
||||
function _isPromise(p) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.shake = exports.toStringShakeLevel = exports.ShakeLevel = void 0;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const ts = require("typescript");
|
||||
@@ -75,11 +76,7 @@ function createTypeScriptLanguageService(options) {
|
||||
FILES[typing] = fs.readFileSync(filePath).toString();
|
||||
});
|
||||
// Resolve libs
|
||||
const RESOLVED_LIBS = {};
|
||||
options.libs.forEach((filename) => {
|
||||
const filepath = path.join(TYPESCRIPT_LIB_FOLDER, filename);
|
||||
RESOLVED_LIBS[`defaultLib:${filename}`] = fs.readFileSync(filepath).toString();
|
||||
});
|
||||
const RESOLVED_LIBS = processLibFiles(options);
|
||||
const compilerOptions = ts.convertCompilerOptionsFromJson(options.compilerOptions, options.sourcesRoot).options;
|
||||
const host = new TypeScriptLanguageServiceHost(RESOLVED_LIBS, FILES, compilerOptions);
|
||||
return ts.createLanguageService(host);
|
||||
@@ -137,6 +134,29 @@ function discoverAndReadFiles(options) {
|
||||
}
|
||||
return FILES;
|
||||
}
|
||||
/**
|
||||
* Read lib files and follow lib references
|
||||
*/
|
||||
function processLibFiles(options) {
|
||||
const stack = [...options.compilerOptions.lib];
|
||||
const result = {};
|
||||
while (stack.length > 0) {
|
||||
const filename = `lib.${stack.shift().toLowerCase()}.d.ts`;
|
||||
const key = `defaultLib:${filename}`;
|
||||
if (!result[key]) {
|
||||
// add this file
|
||||
const filepath = path.join(TYPESCRIPT_LIB_FOLDER, filename);
|
||||
const sourceText = fs.readFileSync(filepath).toString();
|
||||
result[key] = sourceText;
|
||||
// precess dependencies and "recurse"
|
||||
const info = ts.preProcessFile(sourceText);
|
||||
for (let ref of info.libReferenceDirectives) {
|
||||
stack.push(ref.fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* A TypeScript language service host
|
||||
*/
|
||||
@@ -234,6 +254,7 @@ function markNodes(languageService, options) {
|
||||
}
|
||||
const black_queue = [];
|
||||
const gray_queue = [];
|
||||
const export_import_queue = [];
|
||||
const sourceFilesLoaded = {};
|
||||
function enqueueTopLevelModuleStatements(sourceFile) {
|
||||
sourceFile.forEachChild((node) => {
|
||||
@@ -245,10 +266,16 @@ function markNodes(languageService, options) {
|
||||
return;
|
||||
}
|
||||
if (ts.isExportDeclaration(node)) {
|
||||
if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
||||
if (!node.exportClause && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
||||
// export * from "foo";
|
||||
setColor(node, 2 /* Black */);
|
||||
enqueueImport(node, node.moduleSpecifier.text);
|
||||
}
|
||||
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
|
||||
for (const exportSpecifier of node.exportClause.elements) {
|
||||
export_import_queue.push(exportSpecifier);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (ts.isExpressionStatement(node)
|
||||
@@ -402,6 +429,7 @@ function markNodes(languageService, options) {
|
||||
|| ts.isConstructSignatureDeclaration(member)
|
||||
|| ts.isIndexSignatureDeclaration(member)
|
||||
|| ts.isCallSignatureDeclaration(member)
|
||||
|| memberName === '[Symbol.iterator]'
|
||||
|| memberName === 'toJSON'
|
||||
|| memberName === 'toString'
|
||||
|| memberName === 'dispose' // TODO: keeping all `dispose` methods
|
||||
@@ -426,6 +454,22 @@ function markNodes(languageService, options) {
|
||||
};
|
||||
node.forEachChild(loop);
|
||||
}
|
||||
while (export_import_queue.length > 0) {
|
||||
const node = export_import_queue.shift();
|
||||
if (nodeOrParentIsBlack(node)) {
|
||||
continue;
|
||||
}
|
||||
const symbol = node.symbol;
|
||||
if (!symbol) {
|
||||
continue;
|
||||
}
|
||||
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 */);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function nodeIsInItsOwnDeclaration(nodeSourceFile, node, symbol) {
|
||||
for (let i = 0, len = symbol.declarations.length; i < len; i++) {
|
||||
@@ -517,6 +561,21 @@ function generateResult(languageService, shakeLevel) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ts.isExportDeclaration(node)) {
|
||||
if (node.exportClause && node.moduleSpecifier && ts.isNamedExports(node.exportClause)) {
|
||||
let survivingExports = [];
|
||||
for (const exportSpecifier of node.exportClause.elements) {
|
||||
if (getColor(exportSpecifier) === 2 /* Black */) {
|
||||
survivingExports.push(exportSpecifier.getFullText(sourceFile));
|
||||
}
|
||||
}
|
||||
const leadingTriviaWidth = node.getLeadingTriviaWidth();
|
||||
const leadingTrivia = sourceFile.text.substr(node.pos, leadingTriviaWidth);
|
||||
if (survivingExports.length > 0) {
|
||||
return write(`${leadingTrivia}export {${survivingExports.join(',')} } from${node.moduleSpecifier.getFullText(sourceFile)};`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shakeLevel === 2 /* ClassMembers */ && (ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node)) && nodeOrChildIsBlack(node)) {
|
||||
let toWrite = node.getFullText();
|
||||
for (let i = node.members.length - 1; i >= 0; i--) {
|
||||
@@ -567,7 +626,7 @@ function getRealNodeSymbol(checker, node) {
|
||||
// (2) when the aliased symbol is originating from an import.
|
||||
//
|
||||
function shouldSkipAlias(node, declaration) {
|
||||
if (node.kind !== ts.SyntaxKind.Identifier) {
|
||||
if (!ts.isShorthandPropertyAssignment(node) && node.kind !== ts.SyntaxKind.Identifier) {
|
||||
return false;
|
||||
}
|
||||
if (node.parent === declaration) {
|
||||
@@ -589,7 +648,9 @@ function getRealNodeSymbol(checker, node) {
|
||||
}
|
||||
}
|
||||
const { parent } = node;
|
||||
let symbol = checker.getSymbolAtLocation(node);
|
||||
let symbol = (ts.isShorthandPropertyAssignment(node)
|
||||
? checker.getShorthandAssignmentValueSymbol(node)
|
||||
: checker.getSymbolAtLocation(node));
|
||||
let importNode = null;
|
||||
// If this is an alias, and the request came at the declaration location
|
||||
// get the aliased symbol instead. This allows for goto def on an import e.g.
|
||||
|
||||
@@ -18,7 +18,7 @@ export const enum ShakeLevel {
|
||||
}
|
||||
|
||||
export function toStringShakeLevel(shakeLevel: ShakeLevel): string {
|
||||
switch(shakeLevel) {
|
||||
switch (shakeLevel) {
|
||||
case ShakeLevel.Files:
|
||||
return 'Files (0)';
|
||||
case ShakeLevel.InnerFile:
|
||||
@@ -42,11 +42,6 @@ export interface ITreeShakingOptions {
|
||||
* Inline usages.
|
||||
*/
|
||||
inlineEntryPoints: string[];
|
||||
/**
|
||||
* TypeScript libs.
|
||||
* e.g. `lib.d.ts`, `lib.es2015.collection.d.ts`
|
||||
*/
|
||||
libs: string[];
|
||||
/**
|
||||
* Other .d.ts files
|
||||
*/
|
||||
@@ -130,11 +125,7 @@ function createTypeScriptLanguageService(options: ITreeShakingOptions): ts.Langu
|
||||
});
|
||||
|
||||
// Resolve libs
|
||||
const RESOLVED_LIBS: ILibMap = {};
|
||||
options.libs.forEach((filename) => {
|
||||
const filepath = path.join(TYPESCRIPT_LIB_FOLDER, filename);
|
||||
RESOLVED_LIBS[`defaultLib:${filename}`] = fs.readFileSync(filepath).toString();
|
||||
});
|
||||
const RESOLVED_LIBS = processLibFiles(options);
|
||||
|
||||
const compilerOptions = ts.convertCompilerOptionsFromJson(options.compilerOptions, options.sourcesRoot).options;
|
||||
|
||||
@@ -205,6 +196,34 @@ function discoverAndReadFiles(options: ITreeShakingOptions): IFileMap {
|
||||
return FILES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read lib files and follow lib references
|
||||
*/
|
||||
function processLibFiles(options: ITreeShakingOptions): ILibMap {
|
||||
|
||||
const stack: string[] = [...options.compilerOptions.lib];
|
||||
const result: ILibMap = {};
|
||||
|
||||
while (stack.length > 0) {
|
||||
const filename = `lib.${stack.shift()!.toLowerCase()}.d.ts`;
|
||||
const key = `defaultLib:${filename}`;
|
||||
if (!result[key]) {
|
||||
// add this file
|
||||
const filepath = path.join(TYPESCRIPT_LIB_FOLDER, filename);
|
||||
const sourceText = fs.readFileSync(filepath).toString();
|
||||
result[key] = sourceText;
|
||||
|
||||
// precess dependencies and "recurse"
|
||||
const info = ts.preProcessFile(sourceText);
|
||||
for (let ref of info.libReferenceDirectives) {
|
||||
stack.push(ref.fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
interface ILibMap { [libName: string]: string; }
|
||||
interface IFileMap { [fileName: string]: string; }
|
||||
|
||||
@@ -317,6 +336,7 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
|
||||
|
||||
const black_queue: ts.Node[] = [];
|
||||
const gray_queue: ts.Node[] = [];
|
||||
const export_import_queue: ts.Node[] = [];
|
||||
const sourceFilesLoaded: { [fileName: string]: boolean } = {};
|
||||
|
||||
function enqueueTopLevelModuleStatements(sourceFile: ts.SourceFile): void {
|
||||
@@ -332,10 +352,16 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
|
||||
}
|
||||
|
||||
if (ts.isExportDeclaration(node)) {
|
||||
if (node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
||||
if (!node.exportClause && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)) {
|
||||
// export * from "foo";
|
||||
setColor(node, NodeColor.Black);
|
||||
enqueueImport(node, node.moduleSpecifier.text);
|
||||
}
|
||||
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
|
||||
for (const exportSpecifier of node.exportClause.elements) {
|
||||
export_import_queue.push(exportSpecifier);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -475,7 +501,7 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
|
||||
}
|
||||
|
||||
if (black_queue.length === 0) {
|
||||
for (let i = 0; i< gray_queue.length; i++) {
|
||||
for (let i = 0; i < gray_queue.length; i++) {
|
||||
const node = gray_queue[i];
|
||||
const nodeParent = node.parent;
|
||||
if ((ts.isClassDeclaration(nodeParent) || ts.isInterfaceDeclaration(nodeParent)) && nodeOrChildIsBlack(nodeParent)) {
|
||||
@@ -521,6 +547,7 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
|
||||
|| ts.isConstructSignatureDeclaration(member)
|
||||
|| ts.isIndexSignatureDeclaration(member)
|
||||
|| ts.isCallSignatureDeclaration(member)
|
||||
|| memberName === '[Symbol.iterator]'
|
||||
|| memberName === 'toJSON'
|
||||
|| memberName === 'toString'
|
||||
|| memberName === 'dispose'// TODO: keeping all `dispose` methods
|
||||
@@ -545,6 +572,23 @@ function markNodes(languageService: ts.LanguageService, options: ITreeShakingOpt
|
||||
};
|
||||
node.forEachChild(loop);
|
||||
}
|
||||
|
||||
while (export_import_queue.length > 0) {
|
||||
const node = export_import_queue.shift()!;
|
||||
if (nodeOrParentIsBlack(node)) {
|
||||
continue;
|
||||
}
|
||||
const symbol: ts.Symbol | undefined = (<any>node).symbol;
|
||||
if (!symbol) {
|
||||
continue;
|
||||
}
|
||||
const aliased = checker.getAliasedSymbol(symbol);
|
||||
if (aliased.declarations && aliased.declarations.length > 0) {
|
||||
if (nodeOrParentIsBlack(aliased.declarations[0]) || nodeOrChildIsBlack(aliased.declarations[0])) {
|
||||
setColor(node, NodeColor.Black);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function nodeIsInItsOwnDeclaration(nodeSourceFile: ts.SourceFile, node: ts.Node, symbol: ts.Symbol): boolean {
|
||||
@@ -646,6 +690,22 @@ function generateResult(languageService: ts.LanguageService, shakeLevel: ShakeLe
|
||||
}
|
||||
}
|
||||
|
||||
if (ts.isExportDeclaration(node)) {
|
||||
if (node.exportClause && node.moduleSpecifier && ts.isNamedExports(node.exportClause)) {
|
||||
let survivingExports: string[] = [];
|
||||
for (const exportSpecifier of node.exportClause.elements) {
|
||||
if (getColor(exportSpecifier) === NodeColor.Black) {
|
||||
survivingExports.push(exportSpecifier.getFullText(sourceFile));
|
||||
}
|
||||
}
|
||||
const leadingTriviaWidth = node.getLeadingTriviaWidth();
|
||||
const leadingTrivia = sourceFile.text.substr(node.pos, leadingTriviaWidth);
|
||||
if (survivingExports.length > 0) {
|
||||
return write(`${leadingTrivia}export {${survivingExports.join(',')} } from${node.moduleSpecifier.getFullText(sourceFile)};`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shakeLevel === ShakeLevel.ClassMembers && (ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node)) && nodeOrChildIsBlack(node)) {
|
||||
let toWrite = node.getFullText();
|
||||
for (let i = node.members.length - 1; i >= 0; i--) {
|
||||
@@ -708,7 +768,7 @@ function getRealNodeSymbol(checker: ts.TypeChecker, node: ts.Node): [ts.Symbol |
|
||||
// (2) when the aliased symbol is originating from an import.
|
||||
//
|
||||
function shouldSkipAlias(node: ts.Node, declaration: ts.Node): boolean {
|
||||
if (node.kind !== ts.SyntaxKind.Identifier) {
|
||||
if (!ts.isShorthandPropertyAssignment(node) && node.kind !== ts.SyntaxKind.Identifier) {
|
||||
return false;
|
||||
}
|
||||
if (node.parent === declaration) {
|
||||
@@ -733,7 +793,12 @@ function getRealNodeSymbol(checker: ts.TypeChecker, node: ts.Node): [ts.Symbol |
|
||||
|
||||
const { parent } = node;
|
||||
|
||||
let symbol = checker.getSymbolAtLocation(node);
|
||||
let symbol = (
|
||||
ts.isShorthandPropertyAssignment(node)
|
||||
? checker.getShorthandAssignmentValueSymbol(node)
|
||||
: checker.getSymbolAtLocation(node)
|
||||
);
|
||||
|
||||
let importNode: ts.Declaration | null = null;
|
||||
// If this is an alias, and the request came at the declaration location
|
||||
// get the aliased symbol instead. This allows for goto def on an import e.g.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.streamToPromise = exports.versionStringToNumber = exports.filter = exports.rebase = exports.getVersion = exports.ensureDir = exports.rreddir = exports.rimraf = exports.stripSourceMappingURL = exports.loadSourcemaps = exports.cleanNodeModules = exports.skipDirectories = exports.toFileUri = exports.setExecutableBit = exports.fixWin32DirectoryPermissions = exports.incremental = void 0;
|
||||
const es = require("event-stream");
|
||||
const debounce = require("debounce");
|
||||
const _filter = require("gulp-filter");
|
||||
|
||||
Reference in New Issue
Block a user