Merge branch 'master' of https://github.com/Microsoft/TypeScript into feature/eslint
This commit is contained in:
commit
06c31f65cf
17 changed files with 302 additions and 0 deletions
|
@ -683,6 +683,11 @@ namespace ts {
|
|||
return;
|
||||
}
|
||||
}
|
||||
else if (kind === SyntaxKind.SingleLineCommentTrivia) {
|
||||
if (tryClassifyTripleSlashComment(start, width)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Simple comment. Just add as is.
|
||||
pushCommentRange(start, width);
|
||||
|
@ -755,6 +760,84 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function tryClassifyTripleSlashComment(start: number, width: number): boolean {
|
||||
const tripleSlashXMLCommentRegEx = /^(\/\/\/\s*)(<)(?:(\S+)((?:[^/]|\/[^>])*)(\/>)?)?/im;
|
||||
const attributeRegex = /(\S+)(\s*)(=)(\s*)('[^']+'|"[^"]+")/img;
|
||||
|
||||
const text = sourceFile.text.substr(start, width);
|
||||
const match = tripleSlashXMLCommentRegEx.exec(text);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let pos = start;
|
||||
|
||||
pushCommentRange(pos, match[1].length); // ///
|
||||
pos += match[1].length;
|
||||
|
||||
pushClassification(pos, match[2].length, ClassificationType.punctuation); // <
|
||||
pos += match[2].length;
|
||||
|
||||
if (!match[3]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
pushClassification(pos, match[3].length, ClassificationType.jsxSelfClosingTagName); // element name
|
||||
pos += match[3].length;
|
||||
|
||||
const attrText = match[4];
|
||||
let attrPos = pos;
|
||||
while (true) {
|
||||
const attrMatch = attributeRegex.exec(attrText);
|
||||
if (!attrMatch) {
|
||||
break;
|
||||
}
|
||||
|
||||
const newAttrPos = pos + attrMatch.index;
|
||||
if (newAttrPos > attrPos) {
|
||||
pushCommentRange(attrPos, newAttrPos - attrPos);
|
||||
attrPos = newAttrPos;
|
||||
}
|
||||
|
||||
pushClassification(attrPos, attrMatch[1].length, ClassificationType.jsxAttribute); // attribute name
|
||||
attrPos += attrMatch[1].length;
|
||||
|
||||
if (attrMatch[2].length) {
|
||||
pushCommentRange(attrPos, attrMatch[2].length); // whitespace
|
||||
attrPos += attrMatch[2].length;
|
||||
}
|
||||
|
||||
pushClassification(attrPos, attrMatch[3].length, ClassificationType.operator); // =
|
||||
attrPos += attrMatch[3].length;
|
||||
|
||||
if (attrMatch[4].length) {
|
||||
pushCommentRange(attrPos, attrMatch[4].length); // whitespace
|
||||
attrPos += attrMatch[4].length;
|
||||
}
|
||||
|
||||
pushClassification(attrPos, attrMatch[5].length, ClassificationType.jsxAttributeStringLiteralValue); // attribute value
|
||||
attrPos += attrMatch[5].length;
|
||||
}
|
||||
|
||||
pos += match[4].length;
|
||||
|
||||
if (pos > attrPos) {
|
||||
pushCommentRange(attrPos, pos - attrPos);
|
||||
}
|
||||
|
||||
if (match[5]) {
|
||||
pushClassification(pos, match[5].length, ClassificationType.punctuation); // />
|
||||
pos += match[5].length;
|
||||
}
|
||||
|
||||
const end = start + width;
|
||||
if (pos < end) {
|
||||
pushCommentRange(pos, end - pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function processJSDocTemplateTag(tag: JSDocTemplateTag) {
|
||||
for (const child of tag.getChildren()) {
|
||||
processElement(child);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts" />
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""),
|
||||
c.comment(" "),
|
||||
c.punctuation("/>"));
|
|
@ -0,0 +1,13 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts"
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""));
|
|
@ -0,0 +1,15 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts" /
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""),
|
||||
c.comment(" "),
|
||||
c.comment("/"));
|
|
@ -0,0 +1,19 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts" bad types="node" />
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""),
|
||||
c.comment(" bad "),
|
||||
c.jsxAttribute("types"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"node\""),
|
||||
c.comment(" "),
|
||||
c.punctuation("/>"));
|
|
@ -0,0 +1,16 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts" /> trailing
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""),
|
||||
c.comment(" "),
|
||||
c.punctuation("/>"),
|
||||
c.comment(" trailing"));
|
|
@ -0,0 +1,7 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// nonElement
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// nonElement"));
|
|
@ -0,0 +1,25 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module1.ts" />
|
||||
//// /// <reference path="./module2.ts" />
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module1.ts\""),
|
||||
c.comment(" "),
|
||||
c.punctuation("/>"),
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module2.ts\""),
|
||||
c.comment(" "),
|
||||
c.punctuation("/>"));
|
|
@ -0,0 +1,17 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts" />
|
||||
//// 1
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""),
|
||||
c.comment(" "),
|
||||
c.punctuation("/>"),
|
||||
c.numericLiteral("1"));
|
|
@ -0,0 +1,16 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// ///<reference path = "./module.ts"/>
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("///"),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.comment(" "),
|
||||
c.operator("="),
|
||||
c.comment(" "),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""),
|
||||
c.punctuation("/>"));
|
|
@ -0,0 +1,19 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts" types="node" />
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("path"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"./module.ts\""),
|
||||
c.comment(" "),
|
||||
c.jsxAttribute("types"),
|
||||
c.operator("="),
|
||||
c.jsxAttributeStringLiteralValue("\"node\""),
|
||||
c.comment(" "),
|
||||
c.punctuation("/>"));
|
|
@ -0,0 +1,8 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"));
|
|
@ -0,0 +1,9 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"));
|
|
@ -0,0 +1,10 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" path"));
|
|
@ -0,0 +1,10 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path=
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" path="));
|
|
@ -0,0 +1,10 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" path=\""));
|
|
@ -0,0 +1,10 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// /// <reference path="./module.ts
|
||||
|
||||
var c = classification;
|
||||
verify.syntacticClassificationsAre(
|
||||
c.comment("/// "),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("reference"),
|
||||
c.comment(" path=\"./module.ts"));
|
Loading…
Reference in a new issue