Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): not able to correctly parse quoted array shape and object shape key #74

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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);
}
}