10000 addressed PR feedback · johnangularjs/TypeScript@5989d48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5989d48

Browse files
committed
addressed PR feedback
1 parent aa29644 commit 5989d48

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

src/compiler/parser.ts

Lines changed: 13 additions & 21 deletions
-
return (isIdentifierOrKeyword() || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak();
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ namespace ts {
1212
export function createNode(kind: SyntaxKind): Node {
1313
return new (getNodeConstructor(kind))();
1414
}
15-
16-
export function tokenIsIdentifierOrKeyword(token: SyntaxKind) 10000 : boolean {
17-
return token >= SyntaxKind.Identifier;
18-
}
1915

2016
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
2117
if (node) {
@@ -1062,11 +1058,11 @@ namespace ts {
10621058
}
10631059

10641060
function parseIdentifierName(): Identifier {
1065-
return createIdentifier(isIdentifierOrKeyword());
1061+
return createIdentifier(tokenIsIdentifierOrKeyword(token));
10661062
}
10671063

10681064
function isLiteralPropertyName(): boolean {
1069-
return isIdentifierOrKeyword() ||
1065+
return tokenIsIdentifierOrKeyword(token) ||
10701066
token === SyntaxKind.StringLiteral ||
10711067
token === SyntaxKind.NumericLiteral;
10721068
}
@@ -1090,7 +1086,7 @@ namespace ts {
10901086
}
10911087

10921088
function isSimplePropertyName() {
1093-
return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || isIdentifierOrKeyword();
1089+
return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token);
10941090
}
10951091

10961092
function parseComputedPropertyName(): ComputedPropertyName {
@@ -1217,9 +1213,9 @@ namespace ts {
12171213
case ParsingContext.HeritageClauses:
12181214
return isHeritageClause();
12191215
case ParsingContext.ImportOrExportSpecifiers:
1220-
return isIdentifierOrKeyword();
1216+
return tokenIsIdentifierOrKeyword(token);
12211217
case ParsingContext.JsxAttributes:
1222-
return isIdentifierOrKeyword() || token === SyntaxKind.OpenBraceToken;
1218+
return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.OpenBraceToken;
12231219
case ParsingContext.JsxChildren:
12241220
return true;
12251221
case ParsingContext.JSDocFunctionParameters:
@@ -1258,7 +1254,7 @@ namespace ts {
12581254

12591255
function nextTokenIsIdentifierOrKeyword() {
12601256
nextToken();
1261-
return isIdentifierOrKeyword();
1257+
return tokenIsIdentifierOrKeyword(token);
12621258
}
12631259

12641260
function isHeritageClauseExtendsOrImplementsKeyword(): boolean {
@@ -1828,7 +1824,7 @@ namespace ts {
18281824
// the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword".
18291825
// In the first case though, ASI will not take effect because there is not a
18301826
// line terminator after the identifier or keyword.
1831-
if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) {
1827+
if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token)) {
18321828
let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
18331829

18341830
if (matchesPattern) {
@@ -2286,7 +2282,7 @@ namespace ts {
22862282
}
22872283
}
22882284

2289-
if (isIdentifierOrKeyword()) {
2285+
if (tokenIsIdentifierOrKeyword(token)) {
22902286
return parsePropertyOrMethodSignature();
22912287
}
22922288
}
@@ -4105,13 +4101,9 @@ namespace ts {
41054101
}
41064102
}
41074103

4108-
function isIdentifierOrKeyword() {
4109-
return tokenIsIdentifierOrKeyword(token);
4110-
}
4111-
41124104
function nextTokenIsIdentifierOrKeywordOnSameLine() {
41134105
nextToken();
4114-
return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
4106+
return tokenIsIdentifierOrKeyword(token) && !scanner.hasPrecedingLineBreak();
41154107
}
41164108

41174109
function nextTokenIsFunctionKeywordOnSameLine() {
@@ -4121,7 +4113,7 @@ namespace ts {
41214113

41224114
function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
41234115
nextToken();
4124
4116+
return (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak();
41254117
}
41264118

41274119
function isDeclaration(): boolean {
@@ -4174,7 +4166,7 @@ namespace ts {
41744166
case SyntaxKind.ImportKeyword:
41754167
nextToken();
41764168
return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken ||
4177-
token === SyntaxKind.OpenBraceToken || isIdentifierOrKeyword();
4169+
token === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token);
41784170
case SyntaxKind.ExportKeyword:
41794171
nextToken();
41804172
if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken ||
@@ -4781,7 +4773,7 @@ namespace ts {
47814773

47824774
// It is very important that we check this *after* checking indexers because
47834775
// the [ token can start an index signature or a computed property name
4784-
if (isIdentifierOrKeyword() ||
4776+
if (tokenIsIdentifierOrKeyword(token) ||
47854777
token === SyntaxKind.StringLiteral ||
47864778
token === SyntaxKind.NumericLiteral ||
47874779
token === SyntaxKind.AsteriskToken ||
@@ -5324,7 +5316,7 @@ namespace ts {
53245316
return true;
53255317
}
53265318

5327-
return isIdentifierOrKeyword();
5319+
return tokenIsIdentifierOrKeyword(token);
53285320
}
53295321

53305322
export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) {

src/compiler/scanner.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ namespace ts {
66
(message: DiagnosticMessage, length: number): void;
77
}
88

9+
/* @internal */
10+
export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
11+
return token >= SyntaxKind.Identifier;
12+
}
13+
914
export interface Scanner {
1015
getStartPos(): number;
1116
getToken(): SyntaxKind;
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
//// [keywordInJsxIdentifier.tsx]
22

33
declare var React: any;
4-
<foo class-id/>
4+
<foo class-id/>;
5+
<foo class/>;
6+
<foo class-id="1"/>;
7+
<foo class="1"/>;
8+
59

610
//// [keywordInJsxIdentifier.js]
711
React.createElement("foo", {"class-id": true});
12+
React.createElement("foo", {"class": true});
13+
React.createElement("foo", {"class-id": "1"});
14+
React.createElement("foo", {"class": "1"});

tests/baselines/reference/keywordInJsxIdentifier.symbols

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
declare var React: any;
44
>React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11))
55

6-
<foo class-id/>
6+
<foo class-id/>;
77
>class-id : Symbol(unknown)
88

9+
<foo class/>;
10+
>class : Symbol(unknown)
11+
12+
<foo class-id="1"/>;
13+
>class-id : Symbol(unknown)
14+
15+
<foo class="1"/>;
16+
>class : Symbol(unknown)
17+

tests/baselines/reference/keywordInJsxIdentifier.types

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,23 @@
33
declare var React: any;
44
>React : any
55

6-
<foo class-id/>
6+
<foo class-id/>;
77
><foo class-id/> : any
88
>foo : any
99
>class-id : any
1010

11+
<foo class/>;
12+
><foo class/> : any
13+
>foo : any
14+
>class : any
15+
16+
<foo class-id="1"/>;
17+
><foo class-id="1"/> : any
18+
>foo : any
19+
>class-id : any
20+
21+
<foo class="1"/>;
22+
><foo class="1"/> : any
23+
>foo : any
24+
>class : any
25+
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
//@jsx: react
22

33
declare var React: any;
4-
<foo class-id/>
4+
<foo class-id/>;
5+
<foo class/>;
6+
<foo class-id="1"/>;
7+
<foo class="1"/>;

0 commit comments

Comments
 (0)
0