Skip to content

Commit 437463e

Browse files
committed
fix(parser): not able to parse quoted array shape key
1 parent d07d1f8 commit 437463e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix(parser): not able to parse quoted array shape key",
4+
"packageName": "@rightcapital/phpdoc-parser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

src/phpdoc-parser/parser/type-parser.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -751,16 +751,14 @@ export class TypeParser {
751751
): ConstExprIntegerNode | ConstExprStringNode | IdentifierTypeNode {
752752
const startLine = tokens.currentTokenLine();
753753
const startIndex = tokens.currentTokenIndex();
754+
let key: ConstExprIntegerNode | IdentifierTypeNode | ConstExprStringNode;
754755

755756
if (tokens.isCurrentTokenType(Lexer.TOKEN_INTEGER)) {
756-
const key = new ConstExprIntegerNode(
757+
key = new ConstExprIntegerNode(
757758
tokens.currentTokenValue().replaceAll('_', ''),
758759
);
759760
tokens.next();
760-
return this.enrichWithAttributes(tokens, key, startLine, startIndex);
761-
}
762-
let key: ConstExprIntegerNode | IdentifierTypeNode | ConstExprStringNode;
763-
if (tokens.isCurrentTokenType(Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
761+
} else if (tokens.isCurrentTokenType(Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
764762
if (this.quoteAwareConstExprString) {
765763
key = new QuoteAwareConstExprStringNode(
766764
StringUnescaper.unescapeString(tokens.currentTokenValue()),
@@ -772,8 +770,7 @@ export class TypeParser {
772770
);
773771
}
774772
tokens.next();
775-
}
776-
if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
773+
} else if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
777774
if (this.quoteAwareConstExprString) {
778775
key = new QuoteAwareConstExprStringNode(
779776
StringUnescaper.unescapeString(tokens.currentTokenValue()),
@@ -784,10 +781,12 @@ export class TypeParser {
784781
tokens.currentTokenValue().replace(/(^"|"$)/g, ''),
785782
);
786783
}
784+
tokens.next();
787785
} else {
788786
key = new IdentifierTypeNode(tokens.currentTokenValue());
789787
tokens.consumeTokenType(Lexer.TOKEN_IDENTIFIER);
790788
}
789+
791790
return this.enrichWithAttributes<
792791
ConstExprIntegerNode | IdentifierTypeNode | ConstExprStringNode
793792
>(tokens, key, startLine, startIndex);

0 commit comments

Comments
 (0)