mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Merge branch 'master' into typeBaselines
This commit is contained in:
@@ -336,6 +336,9 @@ module ts {
|
||||
/** Emit detached comments of the node */
|
||||
var emitDetachedComments = compilerOptions.removeComments ? (node: TextRange) => { } : emitDetachedCommentsAtPosition;
|
||||
|
||||
/** Emits /// or pinned which is comment starting with /*! comments */
|
||||
var emitPinnedOrTripleSlashComments = compilerOptions.removeComments ? (node: Node) => { } : emitPinnedOrTripleSlashCommentsOfNode;
|
||||
|
||||
var writeComment = writeCommentRange;
|
||||
|
||||
/** Emit a node */
|
||||
@@ -1318,7 +1321,10 @@ module ts {
|
||||
}
|
||||
|
||||
function emitFunctionDeclaration(node: FunctionDeclaration) {
|
||||
if (!node.body) return;
|
||||
if (!node.body) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
if (node.kind !== SyntaxKind.Method) {
|
||||
// Methods will emit the comments as part of emitting method declaration
|
||||
emitLeadingComments(node);
|
||||
@@ -1488,7 +1494,10 @@ module ts {
|
||||
function emitMemberFunctions(node: ClassDeclaration) {
|
||||
forEach(node.members, member => {
|
||||
if (member.kind === SyntaxKind.Method) {
|
||||
if (!(<MethodDeclaration>member).body) return;
|
||||
if (!(<MethodDeclaration>member).body) {
|
||||
return emitPinnedOrTripleSlashComments(member);
|
||||
}
|
||||
|
||||
writeLine();
|
||||
emitLeadingComments(member);
|
||||
emitStart(member);
|
||||
@@ -1611,6 +1620,13 @@ module ts {
|
||||
emitTrailingComments(node);
|
||||
|
||||
function emitConstructorOfClass() {
|
||||
// Emit the constructor overload pinned comments
|
||||
forEach(node.members, member => {
|
||||
if (member.kind === SyntaxKind.Constructor && !(<ConstructorDeclaration>member).body) {
|
||||
emitPinnedOrTripleSlashComments(member);
|
||||
}
|
||||
});
|
||||
|
||||
var ctor = getFirstConstructorWithBody(node);
|
||||
if (ctor) {
|
||||
emitLeadingComments(ctor);
|
||||
@@ -1666,6 +1682,10 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitInterfaceDeclaration(node: InterfaceDeclaration) {
|
||||
emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
function emitEnumDeclaration(node: EnumDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
@@ -1741,7 +1761,10 @@ module ts {
|
||||
}
|
||||
|
||||
function emitModuleDeclaration(node: ModuleDeclaration) {
|
||||
if (!isInstantiated(node)) return;
|
||||
if (!isInstantiated(node)) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
emitStart(node);
|
||||
@@ -1969,7 +1992,14 @@ module ts {
|
||||
}
|
||||
|
||||
function emitNode(node: Node) {
|
||||
if (!node || node.flags & NodeFlags.Ambient) return;
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.flags & NodeFlags.Ambient) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
return emitIdentifier(<Identifier>node);
|
||||
@@ -2073,6 +2103,8 @@ module ts {
|
||||
return emitVariableDeclaration(<VariableDeclaration>node);
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
return emitClassDeclaration(<ClassDeclaration>node);
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
return emitInterfaceDeclaration(<InterfaceDeclaration>node);
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return emitEnumDeclaration(<EnumDeclaration>node);
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
@@ -2101,7 +2133,7 @@ module ts {
|
||||
return leadingComments;
|
||||
}
|
||||
|
||||
function emitLeadingDeclarationComments(node: Node) {
|
||||
function getLeadingCommentsToEmit(node: Node) {
|
||||
// Emit the leading comments only if the parent's pos doesnt match because parent should take care of emitting these comments
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) {
|
||||
var leadingComments: Comment[];
|
||||
@@ -2113,12 +2145,17 @@ module ts {
|
||||
// get the leading comments from the node
|
||||
leadingComments = getLeadingCommentsOfNode(node, currentSourceFile);
|
||||
}
|
||||
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
|
||||
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
|
||||
emitComments(leadingComments, /*trailingSeparator*/ true, writer, writeComment);
|
||||
return leadingComments;
|
||||
}
|
||||
}
|
||||
|
||||
function emitLeadingDeclarationComments(node: Node) {
|
||||
var leadingComments = getLeadingCommentsToEmit(node);
|
||||
emitNewLineBeforeLeadingComments(node, leadingComments, writer);
|
||||
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
|
||||
emitComments(leadingComments, /*trailingSeparator*/ true, writer, writeComment);
|
||||
}
|
||||
|
||||
function emitTrailingDeclarationComments(node: Node) {
|
||||
// Emit the trailing comments only if the parent's end doesnt match
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
|
||||
@@ -2166,7 +2203,7 @@ module ts {
|
||||
lastComment = comment;
|
||||
});
|
||||
|
||||
if (detachedComments && detachedComments.length) {
|
||||
if (detachedComments.length) {
|
||||
// All comments look like they could have been part of the copyright header. Make
|
||||
// sure there is at least one blank line between it and the node. If not, it's not
|
||||
// a copyright header.
|
||||
@@ -2188,6 +2225,28 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitPinnedOrTripleSlashCommentsOfNode(node: Node) {
|
||||
var pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment);
|
||||
|
||||
function isPinnedOrTripleSlashComment(comment: Comment) {
|
||||
if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
|
||||
return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation;
|
||||
}
|
||||
// Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text
|
||||
// so that we dont end up computing comment string and doing match for all // comments
|
||||
else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash &&
|
||||
comment.pos + 2 < comment.end &&
|
||||
currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash &&
|
||||
currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
emitNewLineBeforeLeadingComments(node, pinnedComments, writer);
|
||||
// Leading comments are emitted at /*leading comment1 */space/*leading comment*/space
|
||||
emitComments(pinnedComments, /*trailingSeparator*/ true, writer, writeComment);
|
||||
}
|
||||
|
||||
if (compilerOptions.sourceMap) {
|
||||
initializeEmitterWithSourceMaps();
|
||||
}
|
||||
|
||||
@@ -165,6 +165,8 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
export var fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/
|
||||
|
||||
// Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
|
||||
// stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
|
||||
// embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns
|
||||
@@ -3506,8 +3508,7 @@ module ts {
|
||||
file.hasNoDefaultLib = true;
|
||||
}
|
||||
else {
|
||||
var fullReferenceRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
|
||||
var matchResult = fullReferenceRegEx.exec(comment);
|
||||
var matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
|
||||
if (!matchResult) {
|
||||
var start = range.pos;
|
||||
var length = range.end - start;
|
||||
|
||||
Reference in New Issue
Block a user