Skip to content

Ensure that sys is not used outside tsc.ts #562

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

Merged
merged 3 commits into from
Aug 29, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var compilerSources = [

var servicesSources = [
"core.ts",
"sys.ts",
"types.ts",
"scanner.ts",
"parser.ts",
Expand Down
97 changes: 68 additions & 29 deletions bin/tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -6025,7 +6021,7 @@ var ts;
}
}
else {
writer.writeLiteral(sys.newLine);
writer.writeLiteral(newLine);
}
}
function calculateIndent(pos, end) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -7191,6 +7196,9 @@ var ts;
}
}
}
function emitInterfaceDeclaration(node) {
emitPinnedOrTripleSlashComments(node);
}
function emitEnumDeclaration(node) {
emitLeadingComments(node);
if (!(node.flags & 1 /* Export */)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */:
Expand All @@ -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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 */));
}
Expand Down Expand Up @@ -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 */:
Expand Down Expand Up @@ -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 */:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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; }
};
}
Expand Down
Loading