Skip to content

Commit 7815ccf

Browse files
author
Kanchalai Tanglertsampan
committed
Merge branch 'master' into master-refactorJsDocTest
2 parents 1459395 + d82a57e commit 7815ccf

32 files changed

+434
-100
lines changed

src/compiler/parser.ts

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6510,7 +6510,7 @@ namespace ts {
65106510
case "arg":
65116511
case "argument":
65126512
case "param":
6513-
tag = parseParamTag(atToken, tagName);
6513+
tag = parseParameterOrPropertyTag(atToken, tagName, /*shouldParseParamTag*/ true);
65146514
break;
65156515
case "return":
65166516
case "returns":
@@ -6655,11 +6655,12 @@ namespace ts {
66556655
return { name, isBracketed };
66566656
}
66576657

6658-
function parseParamTag(atToken: AtToken, tagName: Identifier) {
6658+
function parseParameterOrPropertyTag(atToken: AtToken, tagName: Identifier, shouldParseParamTag: boolean): JSDocPropertyTag | JSDocParameterTag {
66596659
let typeExpression = tryParseTypeExpression();
66606660
skipWhitespace();
66616661

66626662
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
6663+
skipWhitespace();
66636664

66646665
if (!name) {
66656666
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
@@ -6678,13 +6679,15 @@ namespace ts {
66786679
typeExpression = tryParseTypeExpression();
66796680
}
66806681

6681-
const result = <JSDocParameterTag>createNode(SyntaxKind.JSDocParameterTag, atToken.pos);
6682+
const result = shouldParseParamTag ?
6683+
<JSDocParameterTag>createNode(SyntaxKind.JSDocParameterTag, atToken.pos) :
6684+
<JSDocPropertyTag>createNode(SyntaxKind.JSDocPropertyTag, atToken.pos);
66826685
result.atToken = atToken;
66836686
result.tagName = tagName;
66846687
result.preParameterName = preName;
66856688
result.typeExpression = typeExpression;
66866689
result.postParameterName = postName;
6687-
result.parameterName = postName || preName;
6690+
result.name = postName || preName;
66886691
result.isBracketed = isBracketed;
66896692
return finishNode(result);
66906693
}
@@ -6713,26 +6716,6 @@ namespace ts {
67136716
return finishNode(result);
67146717
}
67156718

6716-
function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag {
6717-
const typeExpression = tryParseTypeExpression();
6718-
skipWhitespace();
6719-
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
6720-
skipWhitespace();
6721-
6722-
if (!name) {
6723-
parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected);
6724-
return undefined;
6725-
}
6726-
6727-
const result = <JSDocPropertyTag>createNode(SyntaxKind.JSDocPropertyTag, atToken.pos);
6728-
result.atToken = atToken;
6729-
result.tagName = tagName;
6730-
result.name = name;
6731-
result.typeExpression = typeExpression;
6732-
result.isBracketed = isBracketed;
6733-
return finishNode(result);
6734-
}
6735-
67366719
function parseAugmentsTag(atToken: AtToken, tagName: Identifier): JSDocAugmentsTag {
67376720
const typeExpression = tryParseTypeExpression();
67386721

@@ -6869,7 +6852,7 @@ namespace ts {
68696852
return true;
68706853
case "prop":
68716854
case "property":
6872-
const propertyTag = parsePropertyTag(atToken, tagName);
6855+
const propertyTag = parseParameterOrPropertyTag(atToken, tagName, /*shouldParseParamTag*/ false) as JSDocPropertyTag;
68736856
if (propertyTag) {
68746857
if (!parentTag.jsDocPropertyTags) {
68756858
parentTag.jsDocPropertyTags = <NodeArray<JSDocPropertyTag>>[];

src/compiler/scanner.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ namespace ts {
429429
case CharacterCodes.slash:
430430
// starts of normal trivia
431431
case CharacterCodes.lessThan:
432+
case CharacterCodes.bar:
432433
case CharacterCodes.equals:
433434
case CharacterCodes.greaterThan:
434435
// Starts of conflict marker trivia
@@ -496,6 +497,7 @@ namespace ts {
496497
break;
497498

498499
case CharacterCodes.lessThan:
500+
case CharacterCodes.bar:
499501
case CharacterCodes.equals:
500502
case CharacterCodes.greaterThan:
501503
if (isConflictMarkerTrivia(text, pos)) {
@@ -562,12 +564,12 @@ namespace ts {
562564
}
563565
}
564566
else {
565-
Debug.assert(ch === CharacterCodes.equals);
566-
// Consume everything from the start of the mid-conflict marker to the start of the next
567-
// end-conflict marker.
567+
Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
568+
// Consume everything from the start of a ||||||| or ======= marker to the start
569+
// of the next ======= or >>>>>>> marker.
568570
while (pos < len) {
569-
const ch = text.charCodeAt(pos);
570-
if (ch === CharacterCodes.greaterThan && isConflictMarkerTrivia(text, pos)) {
571+
const currentChar = text.charCodeAt(pos);
572+
if ((currentChar === CharacterCodes.equals || currentChar === CharacterCodes.greaterThan) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) {
571573
break;
572574
}
573575

@@ -1562,6 +1564,16 @@ namespace ts {
15621564
pos++;
15631565
return token = SyntaxKind.OpenBraceToken;
15641566
case CharacterCodes.bar:
1567+
if (isConflictMarkerTrivia(text, pos)) {
1568+
pos = scanConflictMarkerTrivia(text, pos, error);
1569+
if (skipTrivia) {
1570+
continue;
1571+
}
1572+
else {
1573+
return token = SyntaxKind.ConflictMarkerTrivia;
1574+
}
1575+
}
1576+
15651577
if (text.charCodeAt(pos + 1) === CharacterCodes.bar) {
15661578
return pos += 2, token = SyntaxKind.BarBarToken;
15671579
}

src/compiler/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,10 @@ namespace ts {
21452145
parent: JSDoc;
21462146
kind: SyntaxKind.JSDocPropertyTag;
21472147
name: Identifier;
2148+
/** the parameter name, if provided *before* the type (TypeScript-style) */
2149+
preParameterName?: Identifier;
2150+
/** the parameter name, if provided *after* the type (JSDoc-standard) */
2151+
postParameterName?: Identifier;
21482152
typeExpression: JSDocTypeExpression;
21492153
isBracketed: boolean;
21502154
}
@@ -2163,7 +2167,7 @@ namespace ts {
21632167
/** the parameter name, if provided *after* the type (JSDoc-standard) */
21642168
postParameterName?: Identifier;
21652169
/** the parameter name, regardless of the location it was provided */
2166-
parameterName: Identifier;
2170+
name: Identifier;
21672171
isBracketed: boolean;
21682172
}
21692173

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ namespace ts {
16351635
}
16361636
else if (param.name.kind === SyntaxKind.Identifier) {
16371637
const name = (param.name as Identifier).text;
1638-
return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.parameterName.text === name);
1638+
return filter(tags, tag => tag.kind === SyntaxKind.JSDocParameterTag && tag.name.text === name);
16391639
}
16401640
else {
16411641
// TODO: it's a destructured parameter, so it should look up an "object type" series of multiple lines
@@ -1646,7 +1646,7 @@ namespace ts {
16461646

16471647
/** Does the opposite of `getJSDocParameterTags`: given a JSDoc parameter, finds the parameter corresponding to it. */
16481648
export function getParameterFromJSDoc(node: JSDocParameterTag): ParameterDeclaration | undefined {
1649-
const name = node.parameterName.text;
1649+
const name = node.name.text;
16501650
const grandParent = node.parent!.parent!;
16511651
Debug.assert(node.parent!.kind === SyntaxKind.JSDocComment);
16521652
if (!isFunctionLike(grandParent)) {

src/harness/unittests/services/colorization.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,50 @@ class D { }\r\n\
424424
comment("=======\r\nclass D { }\r\n"),
425425
comment(">>>>>>> Branch - a"),
426426
finalEndOfLineState(ts.EndOfLineState.None));
427+
428+
testLexicalClassification(
429+
"class C {\r\n\
430+
<<<<<<< HEAD\r\n\
431+
v = 1;\r\n\
432+
||||||| merged common ancestors\r\n\
433+
v = 3;\r\n\
434+
=======\r\n\
435+
v = 2;\r\n\
436+
>>>>>>> Branch - a\r\n\
437+
}",
438+
ts.EndOfLineState.None,
439+
keyword("class"),
440+
identifier("C"),
441+
punctuation("{"),
442+
comment("<<<<<<< HEAD"),
443+
identifier("v"),
444+
operator("="),
445+
numberLiteral("1"),
446+
punctuation(";"),
447+
comment("||||||| merged common ancestors\r\n v = 3;\r\n"),
448+
comment("=======\r\n v = 2;\r\n"),
449+
comment(">>>>>>> Branch - a"),
450+
punctuation("}"),
451+
finalEndOfLineState(ts.EndOfLineState.None));
452+
453+
testLexicalClassification(
454+
"<<<<<<< HEAD\r\n\
455+
class C { }\r\n\
456+
||||||| merged common ancestors\r\n\
457+
class E { }\r\n\
458+
=======\r\n\
459+
class D { }\r\n\
460+
>>>>>>> Branch - a\r\n",
461+
ts.EndOfLineState.None,
462+
comment("<<<<<<< HEAD"),
463+
keyword("class"),
464+
identifier("C"),
465+
punctuation("{"),
466+
punctuation("}"),
467+
comment("||||||| merged common ancestors\r\nclass E { }\r\n"),
468+
comment("=======\r\nclass D { }\r\n"),
469+
comment(">>>>>>> Branch - a"),
470+
finalEndOfLineState(ts.EndOfLineState.None));
427471
});
428472

429473
it("'of' keyword", function () {

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ namespace ts.server.typingsInstaller {
8585
throttleLimit,
8686
log);
8787
this.npmPath = npmLocation !== undefined ? npmLocation : getDefaultNPMLocation(process.argv[0]);
88+
89+
// If the NPM path contains spaces and isn't wrapped in quotes, do so.
90+
if (this.npmPath.indexOf(" ") !== -1 && this.npmPath[0] !== `"`) {
91+
this.npmPath = `"${this.npmPath}"`;
92+
}
8893
if (this.log.isEnabled()) {
8994
this.log.writeLine(`Process id: ${process.pid}`);
9095
this.log.writeLine(`NPM location: ${this.npmPath} (explicit '${Arguments.NpmLocation}' ${npmLocation === undefined ? "not " : ""} provided)`);
@@ -186,4 +191,4 @@ namespace ts.server.typingsInstaller {
186191
});
187192
const installer = new NodeTypingsInstaller(globalTypingsCacheLocation, typingSafeListLocation, npmLocation, /*throttleLimit*/5, log);
188193
installer.listen();
189-
}
194+
}

src/services/classifier.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,9 @@ namespace ts {
685685
continue;
686686
}
687687

688-
// for the ======== add a comment for the first line, and then lex all
689-
// subsequent lines up until the end of the conflict marker.
690-
Debug.assert(ch === CharacterCodes.equals);
688+
// for the ||||||| and ======== markers, add a comment for the first line,
689+
// and then lex all subsequent lines up until the end of the conflict marker.
690+
Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
691691
classifyDisabledMergeCode(text, start, end);
692692
}
693693
}
@@ -782,8 +782,8 @@ namespace ts {
782782
}
783783

784784
function classifyDisabledMergeCode(text: string, start: number, end: number) {
785-
// Classify the line that the ======= marker is on as a comment. Then just lex
786-
// all further tokens and add them to the result.
785+
// Classify the line that the ||||||| or ======= marker is on as a comment.
786+
// Then just lex all further tokens and add them to the result.
787787
let i: number;
788788
for (i = start; i < end; i++) {
789789
if (isLineBreak(text.charCodeAt(i))) {

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argSynonymForParamTag.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 27,
9+
"end": 28,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 27,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 22,
4040
"end": 27,
@@ -44,6 +44,6 @@
4444
},
4545
"length": 1,
4646
"pos": 8,
47-
"end": 27
47+
"end": 28
4848
}
4949
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.argumentSynonymForParamTag.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 32,
9+
"end": 33,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 32,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 27,
4040
"end": 32,
@@ -44,6 +44,6 @@
4444
},
4545
"length": 1,
4646
"pos": 8,
47-
"end": 32
47+
"end": 33
4848
}
4949
}

tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.oneParamTag.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"0": {
77
"kind": "JSDocParameterTag",
88
"pos": 8,
9-
"end": 29,
9+
"end": 30,
1010
"atToken": {
1111
"kind": "AtToken",
1212
"pos": 8,
@@ -34,7 +34,7 @@
3434
"end": 29,
3535
"text": "name1"
3636
},
37-
"parameterName": {
37+
"name": {
3838
"kind": "Identifier",
3939
"pos": 24,
4040
"end": 29,
@@ -44,6 +44,6 @@
4444
},
4545
"length": 1,
4646
"pos": 8,
47-
"end": 29
47+
"end": 30
4848
}
4949
}

0 commit comments

Comments
 (0)