addressed PR feedback

This commit is contained in:
Vladimir Matveev 2015-09-10 12:05:23 -07:00
parent aa29644c2a
commit 5989d48267
6 changed files with 56 additions and 25 deletions

View File

@ -12,10 +12,6 @@ namespace ts {
export function createNode(kind: SyntaxKind): Node {
return new (getNodeConstructor(kind))();
}
export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
return token >= SyntaxKind.Identifier;
}
function visitNode<T>(cbNode: (node: Node) => T, node: Node): T {
if (node) {
@ -1062,11 +1058,11 @@ namespace ts {
}
function parseIdentifierName(): Identifier {
return createIdentifier(isIdentifierOrKeyword());
return createIdentifier(tokenIsIdentifierOrKeyword(token));
}
function isLiteralPropertyName(): boolean {
return isIdentifierOrKeyword() ||
return tokenIsIdentifierOrKeyword(token) ||
token === SyntaxKind.StringLiteral ||
token === SyntaxKind.NumericLiteral;
}
@ -1090,7 +1086,7 @@ namespace ts {
}
function isSimplePropertyName() {
return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || isIdentifierOrKeyword();
return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token);
}
function parseComputedPropertyName(): ComputedPropertyName {
@ -1217,9 +1213,9 @@ namespace ts {
case ParsingContext.HeritageClauses:
return isHeritageClause();
case ParsingContext.ImportOrExportSpecifiers:
return isIdentifierOrKeyword();
return tokenIsIdentifierOrKeyword(token);
case ParsingContext.JsxAttributes:
return isIdentifierOrKeyword() || token === SyntaxKind.OpenBraceToken;
return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.OpenBraceToken;
case ParsingContext.JsxChildren:
return true;
case ParsingContext.JSDocFunctionParameters:
@ -1258,7 +1254,7 @@ namespace ts {
function nextTokenIsIdentifierOrKeyword() {
nextToken();
return isIdentifierOrKeyword();
return tokenIsIdentifierOrKeyword(token);
}
function isHeritageClauseExtendsOrImplementsKeyword(): boolean {
@ -1828,7 +1824,7 @@ namespace ts {
// the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword".
// In the first case though, ASI will not take effect because there is not a
// line terminator after the identifier or keyword.
if (scanner.hasPrecedingLineBreak() && isIdentifierOrKeyword()) {
if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token)) {
let matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine);
if (matchesPattern) {
@ -2286,7 +2282,7 @@ namespace ts {
}
}
if (isIdentifierOrKeyword()) {
if (tokenIsIdentifierOrKeyword(token)) {
return parsePropertyOrMethodSignature();
}
}
@ -4105,13 +4101,9 @@ namespace ts {
}
}
function isIdentifierOrKeyword() {
return tokenIsIdentifierOrKeyword(token);
}
function nextTokenIsIdentifierOrKeywordOnSameLine() {
nextToken();
return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
return tokenIsIdentifierOrKeyword(token) && !scanner.hasPrecedingLineBreak();
}
function nextTokenIsFunctionKeywordOnSameLine() {
@ -4121,7 +4113,7 @@ namespace ts {
function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
nextToken();
return (isIdentifierOrKeyword() || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak();
return (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak();
}
function isDeclaration(): boolean {
@ -4174,7 +4166,7 @@ namespace ts {
case SyntaxKind.ImportKeyword:
nextToken();
return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken ||
token === SyntaxKind.OpenBraceToken || isIdentifierOrKeyword();
token === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token);
case SyntaxKind.ExportKeyword:
nextToken();
if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken ||
@ -4781,7 +4773,7 @@ namespace ts {
// It is very important that we check this *after* checking indexers because
// the [ token can start an index signature or a computed property name
if (isIdentifierOrKeyword() ||
if (tokenIsIdentifierOrKeyword(token) ||
token === SyntaxKind.StringLiteral ||
token === SyntaxKind.NumericLiteral ||
token === SyntaxKind.AsteriskToken ||
@ -5324,7 +5316,7 @@ namespace ts {
return true;
}
return isIdentifierOrKeyword();
return tokenIsIdentifierOrKeyword(token);
}
export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) {

View File

@ -6,6 +6,11 @@ namespace ts {
(message: DiagnosticMessage, length: number): void;
}
/* @internal */
export function tokenIsIdentifierOrKeyword(token: SyntaxKind): boolean {
return token >= SyntaxKind.Identifier;
}
export interface Scanner {
getStartPos(): number;
getToken(): SyntaxKind;

View File

@ -1,7 +1,14 @@
//// [keywordInJsxIdentifier.tsx]
declare var React: any;
<foo class-id/>
<foo class-id/>;
<foo class/>;
<foo class-id="1"/>;
<foo class="1"/>;
//// [keywordInJsxIdentifier.js]
React.createElement("foo", {"class-id": true});
React.createElement("foo", {"class": true});
React.createElement("foo", {"class-id": "1"});
React.createElement("foo", {"class": "1"});

View File

@ -3,6 +3,15 @@
declare var React: any;
>React : Symbol(React, Decl(keywordInJsxIdentifier.tsx, 1, 11))
<foo class-id/>
<foo class-id/>;
>class-id : Symbol(unknown)
<foo class/>;
>class : Symbol(unknown)
<foo class-id="1"/>;
>class-id : Symbol(unknown)
<foo class="1"/>;
>class : Symbol(unknown)

View File

@ -3,8 +3,23 @@
declare var React: any;
>React : any
<foo class-id/>
<foo class-id/>;
><foo class-id/> : any
>foo : any
>class-id : any
<foo class/>;
><foo class/> : any
>foo : any
>class : any
<foo class-id="1"/>;
><foo class-id="1"/> : any
>foo : any
>class-id : any
<foo class="1"/>;
><foo class="1"/> : any
>foo : any
>class : any

View File

@ -1,4 +1,7 @@
//@jsx: react
declare var React: any;
<foo class-id/>
<foo class-id/>;
<foo class/>;
<foo class-id="1"/>;
<foo class="1"/>;