Skip to content

Commit

Permalink
Merge pull request #74 from RightCapitalHQ/feature/support-parse-quot…
Browse files Browse the repository at this point in the history
…ed-array-shape-key

fix(parser): not able to correctly parse quoted array shape and object shape key
  • Loading branch information
rainx committed Jan 9, 2024
2 parents d07d1f8 + dc7ee9c commit 0c9453c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix(parser): not able to correctly parse key in array shape and object shape node",
"packageName": "@rightcapital/phpdoc-parser",
"email": "yilunsun11@yeah.net",
"dependentChangeType": "patch"
}
22 changes: 10 additions & 12 deletions src/phpdoc-parser/parser/type-parser.ts
Expand Up @@ -751,16 +751,14 @@ export class TypeParser {
): ConstExprIntegerNode | ConstExprStringNode | IdentifierTypeNode {
const startLine = tokens.currentTokenLine();
const startIndex = tokens.currentTokenIndex();
let key: ConstExprIntegerNode | IdentifierTypeNode | ConstExprStringNode;

if (tokens.isCurrentTokenType(Lexer.TOKEN_INTEGER)) {
const key = new ConstExprIntegerNode(
key = new ConstExprIntegerNode(
tokens.currentTokenValue().replaceAll('_', ''),
);
tokens.next();
return this.enrichWithAttributes(tokens, key, startLine, startIndex);
}
let key: ConstExprIntegerNode | IdentifierTypeNode | ConstExprStringNode;
if (tokens.isCurrentTokenType(Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
} else if (tokens.isCurrentTokenType(Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
if (this.quoteAwareConstExprString) {
key = new QuoteAwareConstExprStringNode(
StringUnescaper.unescapeString(tokens.currentTokenValue()),
Expand All @@ -772,8 +770,7 @@ export class TypeParser {
);
}
tokens.next();
}
if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
} else if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
if (this.quoteAwareConstExprString) {
key = new QuoteAwareConstExprStringNode(
StringUnescaper.unescapeString(tokens.currentTokenValue()),
Expand All @@ -784,10 +781,12 @@ export class TypeParser {
tokens.currentTokenValue().replace(/(^"|"$)/g, ''),
);
}
tokens.next();
} else {
key = new IdentifierTypeNode(tokens.currentTokenValue());
tokens.consumeTokenType(Lexer.TOKEN_IDENTIFIER);
}

return this.enrichWithAttributes<
ConstExprIntegerNode | IdentifierTypeNode | ConstExprStringNode
>(tokens, key, startLine, startIndex);
Expand Down Expand Up @@ -839,8 +838,8 @@ export class TypeParser {
): ConstExprStringNode | IdentifierTypeNode {
const startLine = tokens.currentTokenLine();
const startIndex = tokens.currentTokenIndex();

let key: ConstExprStringNode | IdentifierTypeNode;

if (tokens.isCurrentTokenType(Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
if (this.quoteAwareConstExprString) {
key = new QuoteAwareConstExprStringNode(
Expand All @@ -849,12 +848,11 @@ export class TypeParser {
);
} else {
key = new ConstExprStringNode(
tokens.currentTokenValue().replace(/(^"|"$)/g, ''),
tokens.currentTokenValue().replace(/(^'|'$)/g, ''),
);
}
tokens.next();
}
if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
} else if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
if (this.quoteAwareConstExprString) {
key = new QuoteAwareConstExprStringNode(
StringUnescaper.unescapeString(tokens.currentTokenValue()),
Expand All @@ -865,12 +863,12 @@ export class TypeParser {
tokens.currentTokenValue().replace(/(^"|"$)/g, ''),
);
}

tokens.next();
} else {
key = new IdentifierTypeNode(tokens.currentTokenValue());
tokens.consumeTokenType(Lexer.TOKEN_IDENTIFIER);
}

return this.enrichWithAttributes(tokens, key, startLine, startIndex);
}
}

0 comments on commit 0c9453c

Please sign in to comment.