Merge pull request #562 from Microsoft/restrictUseOfSys
Ensure that sys is not used outside tsc.ts
This commit is contained in:
commit
4fbc0037c6
1
Jakefile
1
Jakefile
|
@ -43,7 +43,6 @@ var compilerSources = [
|
|||
|
||||
var servicesSources = [
|
||||
"core.ts",
|
||||
"sys.ts",
|
||||
"types.ts",
|
||||
"scanner.ts",
|
||||
"parser.ts",
|
||||
|
|
97
bin/tsc.js
97
bin/tsc.js
|
@ -2207,10 +2207,6 @@ var ts;
|
|||
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
|
||||
}
|
||||
ts.fileExtensionIs = fileExtensionIs;
|
||||
function getCanonicalFileName(fileName) {
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
ts.getCanonicalFileName = getCanonicalFileName;
|
||||
function Symbol(flags, name) {
|
||||
this.flags = flags;
|
||||
this.name = name;
|
||||
|
@ -2591,6 +2587,7 @@ var ts;
|
|||
}
|
||||
}
|
||||
ts.getJsDocComments = getJsDocComments;
|
||||
ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
|
||||
function forEachChild(node, cbNode, cbNodes) {
|
||||
function child(node) {
|
||||
if (node)
|
||||
|
@ -5252,8 +5249,7 @@ var ts;
|
|||
file.hasNoDefaultLib = true;
|
||||
}
|
||||
else {
|
||||
var fullReferenceRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
|
||||
var matchResult = fullReferenceRegEx.exec(comment);
|
||||
var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment);
|
||||
if (!matchResult) {
|
||||
var start = range.pos;
|
||||
var length = range.end - start;
|
||||
|
@ -6025,7 +6021,7 @@ var ts;
|
|||
}
|
||||
}
|
||||
else {
|
||||
writer.writeLiteral(sys.newLine);
|
||||
writer.writeLiteral(newLine);
|
||||
}
|
||||
}
|
||||
function calculateIndent(pos, end) {
|
||||
|
@ -6059,6 +6055,8 @@ var ts;
|
|||
var detachedCommentsInfo;
|
||||
var emitDetachedComments = compilerOptions.removeComments ? function (node) {
|
||||
} : emitDetachedCommentsAtPosition;
|
||||
var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) {
|
||||
} : emitPinnedOrTripleSlashCommentsOfNode;
|
||||
var writeComment = writeCommentRange;
|
||||
var emit = emitNode;
|
||||
var emitStart = function (node) {
|
||||
|
@ -6854,8 +6852,9 @@ var ts;
|
|||
emitTrailingComments(node);
|
||||
}
|
||||
function emitFunctionDeclaration(node) {
|
||||
if (!node.body)
|
||||
return;
|
||||
if (!node.body) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
if (node.kind !== 116 /* Method */) {
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
@ -7014,8 +7013,9 @@ var ts;
|
|||
function emitMemberFunctions(node) {
|
||||
ts.forEach(node.members, function (member) {
|
||||
if (member.kind === 116 /* Method */) {
|
||||
if (!member.body)
|
||||
return;
|
||||
if (!member.body) {
|
||||
return emitPinnedOrTripleSlashComments(member);
|
||||
}
|
||||
writeLine();
|
||||
emitLeadingComments(member);
|
||||
emitStart(member);
|
||||
|
@ -7136,6 +7136,11 @@ var ts;
|
|||
}
|
||||
emitTrailingComments(node);
|
||||
function emitConstructorOfClass() {
|
||||
ts.forEach(node.members, function (member) {
|
||||
if (member.kind === 117 /* Constructor */ && !member.body) {
|
||||
emitPinnedOrTripleSlashComments(member);
|
||||
}
|
||||
});
|
||||
var ctor = getFirstConstructorWithBody(node);
|
||||
if (ctor) {
|
||||
emitLeadingComments(ctor);
|
||||
|
@ -7191,6 +7196,9 @@ var ts;
|
|||
}
|
||||
}
|
||||
}
|
||||
function emitInterfaceDeclaration(node) {
|
||||
emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
function emitEnumDeclaration(node) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & 1 /* Export */)) {
|
||||
|
@ -7263,8 +7271,9 @@ var ts;
|
|||
}
|
||||
}
|
||||
function emitModuleDeclaration(node) {
|
||||
if (!ts.isInstantiated(node))
|
||||
return;
|
||||
if (!ts.isInstantiated(node)) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & 1 /* Export */)) {
|
||||
emitStart(node);
|
||||
|
@ -7477,8 +7486,12 @@ var ts;
|
|||
}
|
||||
}
|
||||
function emitNode(node) {
|
||||
if (!node || node.flags & 2 /* Ambient */)
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
if (node.flags & 2 /* Ambient */) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
switch (node.kind) {
|
||||
case 55 /* Identifier */:
|
||||
return emitIdentifier(node);
|
||||
|
@ -7582,6 +7595,8 @@ var ts;
|
|||
return emitVariableDeclaration(node);
|
||||
case 169 /* ClassDeclaration */:
|
||||
return emitClassDeclaration(node);
|
||||
case 170 /* InterfaceDeclaration */:
|
||||
return emitInterfaceDeclaration(node);
|
||||
case 171 /* EnumDeclaration */:
|
||||
return emitEnumDeclaration(node);
|
||||
case 172 /* ModuleDeclaration */:
|
||||
|
@ -7605,7 +7620,7 @@ var ts;
|
|||
}
|
||||
return leadingComments;
|
||||
}
|
||||
function emitLeadingDeclarationComments(node) {
|
||||
function getLeadingCommentsToEmit(node) {
|
||||
if (node.parent.kind === 177 /* SourceFile */ || node.pos !== node.parent.pos) {
|
||||
var leadingComments;
|
||||
if (hasDetachedComments(node.pos)) {
|
||||
|
@ -7614,10 +7629,14 @@ var ts;
|
|||
else {
|
||||
leadingComments = ts.getLeadingCommentsOfNode(node, currentSourceFile);
|
||||
}
|
||||
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
|
||||
emitComments(leadingComments, true, writer, writeComment);
|
||||
return leadingComments;
|
||||
}
|
||||
}
|
||||
function emitLeadingDeclarationComments(node) {
|
||||
var leadingComments = getLeadingCommentsToEmit(node);
|
||||
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
|
||||
emitComments(leadingComments, true, writer, writeComment);
|
||||
}
|
||||
function emitTrailingDeclarationComments(node) {
|
||||
if (node.parent.kind === 177 /* SourceFile */ || node.end !== node.parent.end) {
|
||||
var trailingComments = ts.getTrailingComments(currentSourceFile.text, node.end);
|
||||
|
@ -7651,7 +7670,7 @@ var ts;
|
|||
detachedComments.push(comment);
|
||||
lastComment = comment;
|
||||
});
|
||||
if (detachedComments && detachedComments.length) {
|
||||
if (detachedComments.length) {
|
||||
var lastCommentLine = getLineOfLocalPosition(detachedComments[detachedComments.length - 1].end);
|
||||
var astLine = getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node.pos));
|
||||
if (astLine >= lastCommentLine + 2) {
|
||||
|
@ -7668,6 +7687,19 @@ var ts;
|
|||
}
|
||||
}
|
||||
}
|
||||
function emitPinnedOrTripleSlashCommentsOfNode(node) {
|
||||
var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment);
|
||||
function isPinnedOrTripleSlashComment(comment) {
|
||||
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) {
|
||||
return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */;
|
||||
}
|
||||
else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && comment.pos + 2 < comment.end && currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */ && currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
emitNewLineBeforeLeadingComments(node, pinnedComments, writer);
|
||||
emitComments(pinnedComments, true, writer, writeComment);
|
||||
}
|
||||
if (compilerOptions.sourceMap) {
|
||||
initializeEmitterWithSourceMaps();
|
||||
}
|
||||
|
@ -9102,7 +9134,7 @@ var ts;
|
|||
}
|
||||
return symbol.name;
|
||||
}
|
||||
if (enclosingDeclaration && !(symbol.flags & ts.SymbolFlags.PropertyOrAccessor & ts.SymbolFlags.Signature & 4096 /* Constructor */ & 2048 /* Method */ & 262144 /* TypeParameter */)) {
|
||||
if (enclosingDeclaration && !(symbol.flags & (ts.SymbolFlags.PropertyOrAccessor | ts.SymbolFlags.Signature | 4096 /* Constructor */ | 2048 /* Method */ | 262144 /* TypeParameter */))) {
|
||||
var symbolName;
|
||||
while (symbol) {
|
||||
var isFirstName = !symbolName;
|
||||
|
@ -10257,13 +10289,12 @@ var ts;
|
|||
return emptyObjectType;
|
||||
}
|
||||
var type = getDeclaredTypeOfSymbol(symbol);
|
||||
var name = symbol.name;
|
||||
if (!(type.flags & ts.TypeFlags.ObjectType)) {
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, name);
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
|
||||
return emptyObjectType;
|
||||
}
|
||||
if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) {
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, name, arity);
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
|
||||
return emptyObjectType;
|
||||
}
|
||||
return type;
|
||||
|
@ -11395,7 +11426,8 @@ var ts;
|
|||
}
|
||||
return false;
|
||||
}
|
||||
function checkSuperExpression(node, isCallExpression) {
|
||||
function checkSuperExpression(node) {
|
||||
var isCallExpression = node.parent.kind === 132 /* CallExpression */ && node.parent.func === node;
|
||||
var enclosingClass = getAncestor(node, 169 /* ClassDeclaration */);
|
||||
var baseClass;
|
||||
if (enclosingClass && enclosingClass.baseType) {
|
||||
|
@ -11897,7 +11929,7 @@ var ts;
|
|||
}
|
||||
function resolveCallExpression(node) {
|
||||
if (node.func.kind === 81 /* SuperKeyword */) {
|
||||
var superType = checkSuperExpression(node.func, true);
|
||||
var superType = checkSuperExpression(node.func);
|
||||
if (superType !== unknownType) {
|
||||
return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */));
|
||||
}
|
||||
|
@ -12370,7 +12402,7 @@ var ts;
|
|||
case 83 /* ThisKeyword */:
|
||||
return checkThisExpression(node);
|
||||
case 81 /* SuperKeyword */:
|
||||
return checkSuperExpression(node, false);
|
||||
return checkSuperExpression(node);
|
||||
case 79 /* NullKeyword */:
|
||||
return nullType;
|
||||
case 85 /* TrueKeyword */:
|
||||
|
@ -13811,6 +13843,7 @@ var ts;
|
|||
case 114 /* Parameter */:
|
||||
case 115 /* Property */:
|
||||
case 176 /* EnumMember */:
|
||||
case 129 /* PropertyAssignment */:
|
||||
return parent.initializer === node;
|
||||
case 146 /* ExpressionStatement */:
|
||||
case 147 /* IfStatement */:
|
||||
|
@ -13913,6 +13946,9 @@ var ts;
|
|||
if (entityName.parent.kind === 175 /* ExportAssignment */) {
|
||||
return resolveEntityName(entityName.parent.parent, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace | 4194304 /* Import */);
|
||||
}
|
||||
if (isInRightSideOfImportOrExportAssignment(entityName)) {
|
||||
return getSymbolOfPartOfRightHandSideOfImport(entityName);
|
||||
}
|
||||
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
|
||||
entityName = entityName.parent;
|
||||
}
|
||||
|
@ -14001,8 +14037,7 @@ var ts;
|
|||
return getTypeOfSymbol(symbol);
|
||||
}
|
||||
if (isInRightSideOfImportOrExportAssignment(node)) {
|
||||
var symbol;
|
||||
symbol = node.parent.kind === 175 /* ExportAssignment */ ? getSymbolInfo(node) : getSymbolOfPartOfRightHandSideOfImport(node);
|
||||
var symbol = getSymbolInfo(node);
|
||||
var declaredType = getDeclaredTypeOfSymbol(symbol);
|
||||
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
|
||||
}
|
||||
|
@ -14138,7 +14173,8 @@ var ts;
|
|||
function isImplementationOfOverload(node) {
|
||||
if (node.body) {
|
||||
var symbol = getSymbolOfNode(node);
|
||||
return getSignaturesOfSymbol(symbol).length > 1;
|
||||
var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
|
||||
return signaturesOfSymbol.length > 1 || (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -14528,6 +14564,9 @@ var ts;
|
|||
function createCompilerHost(options) {
|
||||
var currentDirectory;
|
||||
var existingDirectories = {};
|
||||
function getCanonicalFileName(fileName) {
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
function getSourceFile(filename, languageVersion, onError) {
|
||||
try {
|
||||
var text = sys.readFile(filename, options.charset);
|
||||
|
@ -14573,7 +14612,7 @@ var ts;
|
|||
writeFile: writeFile,
|
||||
getCurrentDirectory: function () { return currentDirectory || (currentDirectory = sys.getCurrentDirectory()); },
|
||||
useCaseSensitiveFileNames: function () { return sys.useCaseSensitiveFileNames; },
|
||||
getCanonicalFileName: ts.getCanonicalFileName,
|
||||
getCanonicalFileName: getCanonicalFileName,
|
||||
getNewLine: function () { return sys.newLine; }
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2207,10 +2207,6 @@ var ts;
|
|||
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
|
||||
}
|
||||
ts.fileExtensionIs = fileExtensionIs;
|
||||
function getCanonicalFileName(fileName) {
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
ts.getCanonicalFileName = getCanonicalFileName;
|
||||
function Symbol(flags, name) {
|
||||
this.flags = flags;
|
||||
this.name = name;
|
||||
|
@ -2268,201 +2264,6 @@ var ts;
|
|||
})(ts.Debug || (ts.Debug = {}));
|
||||
var Debug = ts.Debug;
|
||||
})(ts || (ts = {}));
|
||||
var sys = (function () {
|
||||
function getWScriptSystem() {
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
var fileStream = new ActiveXObject("ADODB.Stream");
|
||||
fileStream.Type = 2;
|
||||
var binaryStream = new ActiveXObject("ADODB.Stream");
|
||||
binaryStream.Type = 1;
|
||||
var args = [];
|
||||
for (var i = 0; i < WScript.Arguments.length; i++) {
|
||||
args[i] = WScript.Arguments.Item(i);
|
||||
}
|
||||
function readFile(fileName, encoding) {
|
||||
if (!fso.FileExists(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
fileStream.Open();
|
||||
try {
|
||||
if (encoding) {
|
||||
fileStream.Charset = encoding;
|
||||
fileStream.LoadFromFile(fileName);
|
||||
}
|
||||
else {
|
||||
fileStream.Charset = "x-ansi";
|
||||
fileStream.LoadFromFile(fileName);
|
||||
var bom = fileStream.ReadText(2) || "";
|
||||
fileStream.Position = 0;
|
||||
fileStream.Charset = bom.length >= 2 && (bom.charCodeAt(0) === 0xFF && bom.charCodeAt(1) === 0xFE || bom.charCodeAt(0) === 0xFE && bom.charCodeAt(1) === 0xFF) ? "unicode" : "utf-8";
|
||||
}
|
||||
return fileStream.ReadText();
|
||||
}
|
||||
catch (e) {
|
||||
throw e.number === -2147024809 ? new Error(ts.Diagnostics.Unsupported_file_encoding.key) : e;
|
||||
}
|
||||
finally {
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
function writeFile(fileName, data, writeByteOrderMark) {
|
||||
fileStream.Open();
|
||||
binaryStream.Open();
|
||||
try {
|
||||
fileStream.Charset = "utf-8";
|
||||
fileStream.WriteText(data);
|
||||
if (writeByteOrderMark) {
|
||||
fileStream.Position = 0;
|
||||
}
|
||||
else {
|
||||
fileStream.Position = 3;
|
||||
}
|
||||
fileStream.CopyTo(binaryStream);
|
||||
binaryStream.SaveToFile(fileName, 2);
|
||||
}
|
||||
finally {
|
||||
binaryStream.Close();
|
||||
fileStream.Close();
|
||||
}
|
||||
}
|
||||
return {
|
||||
args: args,
|
||||
newLine: "\r\n",
|
||||
useCaseSensitiveFileNames: false,
|
||||
write: function (s) {
|
||||
WScript.StdOut.Write(s);
|
||||
},
|
||||
readFile: readFile,
|
||||
writeFile: writeFile,
|
||||
resolvePath: function (path) {
|
||||
return fso.GetAbsolutePathName(path);
|
||||
},
|
||||
fileExists: function (path) {
|
||||
return fso.FileExists(path);
|
||||
},
|
||||
directoryExists: function (path) {
|
||||
return fso.FolderExists(path);
|
||||
},
|
||||
createDirectory: function (directoryName) {
|
||||
if (!this.directoryExists(directoryName)) {
|
||||
fso.CreateFolder(directoryName);
|
||||
}
|
||||
},
|
||||
getExecutingFilePath: function () {
|
||||
return WScript.ScriptFullName;
|
||||
},
|
||||
getCurrentDirectory: function () {
|
||||
return new ActiveXObject("WScript.Shell").CurrentDirectory;
|
||||
},
|
||||
exit: function (exitCode) {
|
||||
try {
|
||||
WScript.Quit(exitCode);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function getNodeSystem() {
|
||||
var _fs = require("fs");
|
||||
var _path = require("path");
|
||||
var _os = require('os');
|
||||
var platform = _os.platform();
|
||||
var useCaseSensitiveFileNames = platform !== "win32" && platform !== "win64" && platform !== "darwin";
|
||||
function readFile(fileName, encoding) {
|
||||
if (!_fs.existsSync(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
var buffer = _fs.readFileSync(fileName);
|
||||
var len = buffer.length;
|
||||
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
|
||||
len &= ~1;
|
||||
for (var i = 0; i < len; i += 2) {
|
||||
var temp = buffer[i];
|
||||
buffer[i] = buffer[i + 1];
|
||||
buffer[i + 1] = temp;
|
||||
}
|
||||
return buffer.toString("utf16le", 2);
|
||||
}
|
||||
if (len >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
|
||||
return buffer.toString("utf16le", 2);
|
||||
}
|
||||
if (len >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
|
||||
return buffer.toString("utf8", 3);
|
||||
}
|
||||
return buffer.toString("utf8");
|
||||
}
|
||||
function writeFile(fileName, data, writeByteOrderMark) {
|
||||
if (writeByteOrderMark) {
|
||||
data = '\uFEFF' + data;
|
||||
}
|
||||
_fs.writeFileSync(fileName, data, "utf8");
|
||||
}
|
||||
return {
|
||||
args: process.argv.slice(2),
|
||||
newLine: _os.EOL,
|
||||
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
|
||||
write: function (s) {
|
||||
_fs.writeSync(1, s);
|
||||
},
|
||||
readFile: readFile,
|
||||
writeFile: writeFile,
|
||||
watchFile: function (fileName, callback) {
|
||||
_fs.watchFile(fileName, { persistent: true, interval: 250 }, fileChanged);
|
||||
return {
|
||||
close: function () {
|
||||
_fs.unwatchFile(fileName, fileChanged);
|
||||
}
|
||||
};
|
||||
function fileChanged(curr, prev) {
|
||||
if (+curr.mtime <= +prev.mtime) {
|
||||
return;
|
||||
}
|
||||
callback(fileName);
|
||||
}
|
||||
;
|
||||
},
|
||||
resolvePath: function (path) {
|
||||
return _path.resolve(path);
|
||||
},
|
||||
fileExists: function (path) {
|
||||
return _fs.existsSync(path);
|
||||
},
|
||||
directoryExists: function (path) {
|
||||
return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
|
||||
},
|
||||
createDirectory: function (directoryName) {
|
||||
if (!this.directoryExists(directoryName)) {
|
||||
_fs.mkdirSync(directoryName);
|
||||
}
|
||||
},
|
||||
getExecutingFilePath: function () {
|
||||
return process.mainModule.filename;
|
||||
},
|
||||
getCurrentDirectory: function () {
|
||||
return process.cwd();
|
||||
},
|
||||
getMemoryUsage: function () {
|
||||
if (global.gc) {
|
||||
global.gc();
|
||||
}
|
||||
return process.memoryUsage().heapUsed;
|
||||
},
|
||||
exit: function (exitCode) {
|
||||
process.exit(exitCode);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
|
||||
return getWScriptSystem();
|
||||
}
|
||||
else if (typeof module !== "undefined" && module.exports) {
|
||||
return getNodeSystem();
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
})();
|
||||
var ts;
|
||||
(function (ts) {
|
||||
var nodeConstructors = new Array(180 /* Count */);
|
||||
|
@ -2591,6 +2392,7 @@ var ts;
|
|||
}
|
||||
}
|
||||
ts.getJsDocComments = getJsDocComments;
|
||||
ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
|
||||
function forEachChild(node, cbNode, cbNodes) {
|
||||
function child(node) {
|
||||
if (node)
|
||||
|
@ -5252,8 +5054,7 @@ var ts;
|
|||
file.hasNoDefaultLib = true;
|
||||
}
|
||||
else {
|
||||
var fullReferenceRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
|
||||
var matchResult = fullReferenceRegEx.exec(comment);
|
||||
var matchResult = ts.fullTripleSlashReferencePathRegEx.exec(comment);
|
||||
if (!matchResult) {
|
||||
var start = range.pos;
|
||||
var length = range.end - start;
|
||||
|
@ -6025,7 +5826,7 @@ var ts;
|
|||
}
|
||||
}
|
||||
else {
|
||||
writer.writeLiteral(sys.newLine);
|
||||
writer.writeLiteral(newLine);
|
||||
}
|
||||
}
|
||||
function calculateIndent(pos, end) {
|
||||
|
@ -6059,6 +5860,8 @@ var ts;
|
|||
var detachedCommentsInfo;
|
||||
var emitDetachedComments = compilerOptions.removeComments ? function (node) {
|
||||
} : emitDetachedCommentsAtPosition;
|
||||
var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? function (node) {
|
||||
} : emitPinnedOrTripleSlashCommentsOfNode;
|
||||
var writeComment = writeCommentRange;
|
||||
var emit = emitNode;
|
||||
var emitStart = function (node) {
|
||||
|
@ -6854,8 +6657,9 @@ var ts;
|
|||
emitTrailingComments(node);
|
||||
}
|
||||
function emitFunctionDeclaration(node) {
|
||||
if (!node.body)
|
||||
return;
|
||||
if (!node.body) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
if (node.kind !== 116 /* Method */) {
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
@ -7014,8 +6818,9 @@ var ts;
|
|||
function emitMemberFunctions(node) {
|
||||
ts.forEach(node.members, function (member) {
|
||||
if (member.kind === 116 /* Method */) {
|
||||
if (!member.body)
|
||||
return;
|
||||
if (!member.body) {
|
||||
return emitPinnedOrTripleSlashComments(member);
|
||||
}
|
||||
writeLine();
|
||||
emitLeadingComments(member);
|
||||
emitStart(member);
|
||||
|
@ -7136,6 +6941,11 @@ var ts;
|
|||
}
|
||||
emitTrailingComments(node);
|
||||
function emitConstructorOfClass() {
|
||||
ts.forEach(node.members, function (member) {
|
||||
if (member.kind === 117 /* Constructor */ && !member.body) {
|
||||
emitPinnedOrTripleSlashComments(member);
|
||||
}
|
||||
});
|
||||
var ctor = getFirstConstructorWithBody(node);
|
||||
if (ctor) {
|
||||
emitLeadingComments(ctor);
|
||||
|
@ -7191,6 +7001,9 @@ var ts;
|
|||
}
|
||||
}
|
||||
}
|
||||
function emitInterfaceDeclaration(node) {
|
||||
emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
function emitEnumDeclaration(node) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & 1 /* Export */)) {
|
||||
|
@ -7263,8 +7076,9 @@ var ts;
|
|||
}
|
||||
}
|
||||
function emitModuleDeclaration(node) {
|
||||
if (!ts.isInstantiated(node))
|
||||
return;
|
||||
if (!ts.isInstantiated(node)) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & 1 /* Export */)) {
|
||||
emitStart(node);
|
||||
|
@ -7477,8 +7291,12 @@ var ts;
|
|||
}
|
||||
}
|
||||
function emitNode(node) {
|
||||
if (!node || node.flags & 2 /* Ambient */)
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
if (node.flags & 2 /* Ambient */) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
switch (node.kind) {
|
||||
case 55 /* Identifier */:
|
||||
return emitIdentifier(node);
|
||||
|
@ -7582,6 +7400,8 @@ var ts;
|
|||
return emitVariableDeclaration(node);
|
||||
case 169 /* ClassDeclaration */:
|
||||
return emitClassDeclaration(node);
|
||||
case 170 /* InterfaceDeclaration */:
|
||||
return emitInterfaceDeclaration(node);
|
||||
case 171 /* EnumDeclaration */:
|
||||
return emitEnumDeclaration(node);
|
||||
case 172 /* ModuleDeclaration */:
|
||||
|
@ -7605,7 +7425,7 @@ var ts;
|
|||
}
|
||||
return leadingComments;
|
||||
}
|
||||
function emitLeadingDeclarationComments(node) {
|
||||
function getLeadingCommentsToEmit(node) {
|
||||
if (node.parent.kind === 177 /* SourceFile */ || node.pos !== node.parent.pos) {
|
||||
var leadingComments;
|
||||
if (hasDetachedComments(node.pos)) {
|
||||
|
@ -7614,10 +7434,14 @@ var ts;
|
|||
else {
|
||||
leadingComments = ts.getLeadingCommentsOfNode(node, currentSourceFile);
|
||||
}
|
||||
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
|
||||
emitComments(leadingComments, true, writer, writeComment);
|
||||
return leadingComments;
|
||||
}
|
||||
}
|
||||
function emitLeadingDeclarationComments(node) {
|
||||
var leadingComments = getLeadingCommentsToEmit(node);
|
||||
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
|
||||
emitComments(leadingComments, true, writer, writeComment);
|
||||
}
|
||||
function emitTrailingDeclarationComments(node) {
|
||||
if (node.parent.kind === 177 /* SourceFile */ || node.end !== node.parent.end) {
|
||||
var trailingComments = ts.getTrailingComments(currentSourceFile.text, node.end);
|
||||
|
@ -7651,7 +7475,7 @@ var ts;
|
|||
detachedComments.push(comment);
|
||||
lastComment = comment;
|
||||
});
|
||||
if (detachedComments && detachedComments.length) {
|
||||
if (detachedComments.length) {
|
||||
var lastCommentLine = getLineOfLocalPosition(detachedComments[detachedComments.length - 1].end);
|
||||
var astLine = getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node.pos));
|
||||
if (astLine >= lastCommentLine + 2) {
|
||||
|
@ -7668,6 +7492,19 @@ var ts;
|
|||
}
|
||||
}
|
||||
}
|
||||
function emitPinnedOrTripleSlashCommentsOfNode(node) {
|
||||
var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment);
|
||||
function isPinnedOrTripleSlashComment(comment) {
|
||||
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) {
|
||||
return currentSourceFile.text.charCodeAt(comment.pos + 2) === 33 /* exclamation */;
|
||||
}
|
||||
else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 47 /* slash */ && comment.pos + 2 < comment.end && currentSourceFile.text.charCodeAt(comment.pos + 2) === 47 /* slash */ && currentSourceFile.text.substring(comment.pos, comment.end).match(ts.fullTripleSlashReferencePathRegEx)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
emitNewLineBeforeLeadingComments(node, pinnedComments, writer);
|
||||
emitComments(pinnedComments, true, writer, writeComment);
|
||||
}
|
||||
if (compilerOptions.sourceMap) {
|
||||
initializeEmitterWithSourceMaps();
|
||||
}
|
||||
|
@ -9102,7 +8939,7 @@ var ts;
|
|||
}
|
||||
return symbol.name;
|
||||
}
|
||||
if (enclosingDeclaration && !(symbol.flags & ts.SymbolFlags.PropertyOrAccessor & ts.SymbolFlags.Signature & 4096 /* Constructor */ & 2048 /* Method */ & 262144 /* TypeParameter */)) {
|
||||
if (enclosingDeclaration && !(symbol.flags & (ts.SymbolFlags.PropertyOrAccessor | ts.SymbolFlags.Signature | 4096 /* Constructor */ | 2048 /* Method */ | 262144 /* TypeParameter */))) {
|
||||
var symbolName;
|
||||
while (symbol) {
|
||||
var isFirstName = !symbolName;
|
||||
|
@ -10257,13 +10094,12 @@ var ts;
|
|||
return emptyObjectType;
|
||||
}
|
||||
var type = getDeclaredTypeOfSymbol(symbol);
|
||||
var name = symbol.name;
|
||||
if (!(type.flags & ts.TypeFlags.ObjectType)) {
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, name);
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name);
|
||||
return emptyObjectType;
|
||||
}
|
||||
if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) {
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, name, arity);
|
||||
error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity);
|
||||
return emptyObjectType;
|
||||
}
|
||||
return type;
|
||||
|
@ -11395,7 +11231,8 @@ var ts;
|
|||
}
|
||||
return false;
|
||||
}
|
||||
function checkSuperExpression(node, isCallExpression) {
|
||||
function checkSuperExpression(node) {
|
||||
var isCallExpression = node.parent.kind === 132 /* CallExpression */ && node.parent.func === node;
|
||||
var enclosingClass = getAncestor(node, 169 /* ClassDeclaration */);
|
||||
var baseClass;
|
||||
if (enclosingClass && enclosingClass.baseType) {
|
||||
|
@ -11897,7 +11734,7 @@ var ts;
|
|||
}
|
||||
function resolveCallExpression(node) {
|
||||
if (node.func.kind === 81 /* SuperKeyword */) {
|
||||
var superType = checkSuperExpression(node.func, true);
|
||||
var superType = checkSuperExpression(node.func);
|
||||
if (superType !== unknownType) {
|
||||
return resolveCall(node, getSignaturesOfType(superType, 1 /* Construct */));
|
||||
}
|
||||
|
@ -12370,7 +12207,7 @@ var ts;
|
|||
case 83 /* ThisKeyword */:
|
||||
return checkThisExpression(node);
|
||||
case 81 /* SuperKeyword */:
|
||||
return checkSuperExpression(node, false);
|
||||
return checkSuperExpression(node);
|
||||
case 79 /* NullKeyword */:
|
||||
return nullType;
|
||||
case 85 /* TrueKeyword */:
|
||||
|
@ -13811,6 +13648,7 @@ var ts;
|
|||
case 114 /* Parameter */:
|
||||
case 115 /* Property */:
|
||||
case 176 /* EnumMember */:
|
||||
case 129 /* PropertyAssignment */:
|
||||
return parent.initializer === node;
|
||||
case 146 /* ExpressionStatement */:
|
||||
case 147 /* IfStatement */:
|
||||
|
@ -13913,6 +13751,9 @@ var ts;
|
|||
if (entityName.parent.kind === 175 /* ExportAssignment */) {
|
||||
return resolveEntityName(entityName.parent.parent, entityName, ts.SymbolFlags.Value | ts.SymbolFlags.Type | ts.SymbolFlags.Namespace | 4194304 /* Import */);
|
||||
}
|
||||
if (isInRightSideOfImportOrExportAssignment(entityName)) {
|
||||
return getSymbolOfPartOfRightHandSideOfImport(entityName);
|
||||
}
|
||||
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
|
||||
entityName = entityName.parent;
|
||||
}
|
||||
|
@ -14001,8 +13842,7 @@ var ts;
|
|||
return getTypeOfSymbol(symbol);
|
||||
}
|
||||
if (isInRightSideOfImportOrExportAssignment(node)) {
|
||||
var symbol;
|
||||
symbol = node.parent.kind === 175 /* ExportAssignment */ ? getSymbolInfo(node) : getSymbolOfPartOfRightHandSideOfImport(node);
|
||||
var symbol = getSymbolInfo(node);
|
||||
var declaredType = getDeclaredTypeOfSymbol(symbol);
|
||||
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
|
||||
}
|
||||
|
@ -14138,7 +13978,8 @@ var ts;
|
|||
function isImplementationOfOverload(node) {
|
||||
if (node.body) {
|
||||
var symbol = getSymbolOfNode(node);
|
||||
return getSignaturesOfSymbol(symbol).length > 1;
|
||||
var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
|
||||
return signaturesOfSymbol.length > 1 || (signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -15393,7 +15234,7 @@ var TypeScript;
|
|||
})(Location);
|
||||
TypeScript.Diagnostic = Diagnostic;
|
||||
function newLine() {
|
||||
return sys.newLine ? sys.newLine : "\r\n";
|
||||
return "\r\n";
|
||||
}
|
||||
TypeScript.newLine = newLine;
|
||||
function getLargestIndex(diagnostic) {
|
||||
|
|
|
@ -509,12 +509,6 @@ module ts {
|
|||
return pathLen > extLen && path.substr(pathLen - extLen, extLen) === extension;
|
||||
}
|
||||
|
||||
export function getCanonicalFileName(fileName: string): string {
|
||||
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
|
||||
// otherwise use toLowerCase as a canonical form.
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
|
||||
export interface ObjectAllocator {
|
||||
getNodeConstructor(kind: SyntaxKind): new () => Node;
|
||||
getSymbolConstructor(): new (flags: SymbolFlags, name: string) => Symbol;
|
||||
|
|
|
@ -290,7 +290,7 @@ module ts {
|
|||
}
|
||||
else {
|
||||
// Empty string - make sure we write empty line
|
||||
writer.writeLiteral(sys.newLine);
|
||||
writer.writeLiteral(newLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/// <reference path="sys.ts"/>
|
||||
/// <reference path="types.ts"/>
|
||||
/// <reference path="core.ts"/>
|
||||
/// <reference path="scanner.ts"/>
|
||||
|
|
|
@ -137,6 +137,12 @@ module ts {
|
|||
var currentDirectory: string;
|
||||
var existingDirectories: Map<boolean> = {};
|
||||
|
||||
function getCanonicalFileName(fileName: string): string {
|
||||
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
|
||||
// otherwise use toLowerCase as a canonical form.
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
|
||||
function getSourceFile(filename: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile {
|
||||
try {
|
||||
var text = sys.readFile(filename, options.charset);
|
||||
|
@ -323,6 +329,7 @@ module ts {
|
|||
function compile(commandLine: ParsedCommandLine, compilerHost: CompilerHost) {
|
||||
var parseStart = new Date().getTime();
|
||||
var program = createProgram(commandLine.filenames, commandLine.options, compilerHost);
|
||||
|
||||
var bindStart = new Date().getTime();
|
||||
var errors = program.getDiagnostics();
|
||||
if (errors.length) {
|
||||
|
|
|
@ -1893,9 +1893,9 @@ module FourSlash {
|
|||
fourslashSourceFile = fourslashSourceFile || ts.createSourceFile(tsFn, Harness.IO.readFile(tsFn), ts.ScriptTarget.ES5, /*version*/ "0", /*isOpen*/ false);
|
||||
|
||||
var files: { [filename: string]: ts.SourceFile; } = {};
|
||||
files[ts.getCanonicalFileName(fourslashFilename)] = fourslashSourceFile;
|
||||
files[ts.getCanonicalFileName(fileName)] = ts.createSourceFile(fileName, content, ts.ScriptTarget.ES5, /*version*/ "0", /*isOpen*/ false);
|
||||
files[ts.getCanonicalFileName(Harness.Compiler.defaultLibFileName)] = Harness.Compiler.defaultLibSourceFile;
|
||||
files[Harness.Compiler.getCanonicalFileName(fourslashFilename)] = fourslashSourceFile;
|
||||
files[Harness.Compiler.getCanonicalFileName(fileName)] = ts.createSourceFile(fileName, content, ts.ScriptTarget.ES5, /*version*/ "0", /*isOpen*/ false);
|
||||
files[Harness.Compiler.getCanonicalFileName(Harness.Compiler.defaultLibFileName)] = Harness.Compiler.defaultLibSourceFile;
|
||||
|
||||
var host = Harness.Compiler.createCompilerHost(files, (fn, contents) => result = contents);
|
||||
var program = ts.createProgram([fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host);
|
||||
|
|
|
@ -534,13 +534,17 @@ module Harness {
|
|||
export var defaultLibFileName = 'lib.d.ts';
|
||||
export var defaultLibSourceFile = ts.createSourceFile(defaultLibFileName, IO.readFile(libFolder + 'lib.core.d.ts'), /*languageVersion*/ ts.ScriptTarget.ES5, /*version:*/ "0");
|
||||
|
||||
export function getCanonicalFileName(fileName: string): string {
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
|
||||
export function createCompilerHost(filemap: { [filename: string]: ts.SourceFile; }, writeFile: (fn: string, contents: string, writeByteOrderMark:boolean) => void): ts.CompilerHost {
|
||||
return {
|
||||
getCurrentDirectory: sys.getCurrentDirectory,
|
||||
getCancellationToken: (): any => undefined,
|
||||
getSourceFile: (fn, languageVersion) => {
|
||||
if (Object.prototype.hasOwnProperty.call(filemap, ts.getCanonicalFileName(fn))) {
|
||||
return filemap[ts.getCanonicalFileName(fn)];
|
||||
if (Object.prototype.hasOwnProperty.call(filemap, getCanonicalFileName(fn))) {
|
||||
return filemap[getCanonicalFileName(fn)];
|
||||
} else {
|
||||
var lib = defaultLibFileName;
|
||||
if (fn === defaultLibFileName) {
|
||||
|
@ -552,7 +556,7 @@ module Harness {
|
|||
},
|
||||
getDefaultLibFilename: () => defaultLibFileName,
|
||||
writeFile: writeFile,
|
||||
getCanonicalFileName: ts.getCanonicalFileName,
|
||||
getCanonicalFileName: getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
||||
getNewLine: ()=> sys.newLine
|
||||
};
|
||||
|
@ -729,7 +733,7 @@ module Harness {
|
|||
var filemap: { [name: string]: ts.SourceFile; } = {};
|
||||
var register = (file: { unitName: string; content: string; }) => {
|
||||
var filename = Path.switchToForwardSlashes(file.unitName);
|
||||
filemap[ts.getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, options.target, /*version:*/ "0");
|
||||
filemap[getCanonicalFileName(filename)] = ts.createSourceFile(filename, file.content, options.target, /*version:*/ "0");
|
||||
};
|
||||
inputFiles.forEach(register);
|
||||
otherFiles.forEach(register);
|
||||
|
|
|
@ -187,7 +187,7 @@ class ProjectRunner extends RunnerBase {
|
|||
getDefaultLibFilename: () => "lib.d.ts",
|
||||
writeFile: writeFile,
|
||||
getCurrentDirectory: getCurrentDirectory,
|
||||
getCanonicalFileName: ts.getCanonicalFileName,
|
||||
getCanonicalFileName: Harness.Compiler.getCanonicalFileName,
|
||||
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
|
||||
getNewLine: () => sys.newLine
|
||||
};
|
||||
|
|
|
@ -120,7 +120,7 @@ module TypeScript {
|
|||
// TODO: We need to expose an extensibility point on our hosts to have them tell us what
|
||||
// they want the newline string to be. That way we can get the correct result regardless
|
||||
// of which host we use
|
||||
return sys.newLine ? sys.newLine : "\r\n";
|
||||
return "\r\n";
|
||||
}
|
||||
|
||||
function getLargestIndex(diagnostic: string): number {
|
||||
|
|
Loading…
Reference in a new issue