Skip to content

Commit 0c9453c

Browse files
authored
Merge pull request #74 from RightCapitalHQ/feature/support-parse-quoted-array-shape-key
fix(parser): not able to correctly parse quoted array shape and object shape key
2 parents d07d1f8 + dc7ee9c commit 0c9453c

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
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 correctly parse key in array shape and object shape node",
4+
"packageName": "@rightcapital/phpdoc-parser",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

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

+10-12
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);
@@ -839,8 +838,8 @@ export class TypeParser {
839838
): ConstExprStringNode | IdentifierTypeNode {
840839
const startLine = tokens.currentTokenLine();
841840
const startIndex = tokens.currentTokenIndex();
842-
843841
let key: ConstExprStringNode | IdentifierTypeNode;
842+
844843
if (tokens.isCurrentTokenType(Lexer.TOKEN_SINGLE_QUOTED_STRING)) {
845844
if (this.quoteAwareConstExprString) {
846845
key = new QuoteAwareConstExprStringNode(
@@ -849,12 +848,11 @@ export class TypeParser {
849848
);
850849
} else {
851850
key = new ConstExprStringNode(
852-
tokens.currentTokenValue().replace(/(^"|"$)/g, ''),
851+
tokens.currentTokenValue().replace(/(^'|'$)/g, ''),
853852
);
854853
}
855854
tokens.next();
856-
}
857-
if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
855+
} else if (tokens.isCurrentTokenType(Lexer.TOKEN_DOUBLE_QUOTED_STRING)) {
858856
if (this.quoteAwareConstExprString) {
859857
key = new QuoteAwareConstExprStringNode(
860858
StringUnescaper.unescapeString(tokens.currentTokenValue()),
@@ -865,12 +863,12 @@ export class TypeParser {
865863
tokens.currentTokenValue().replace(/(^"|"$)/g, ''),
866864
);
867865
}
868-
869866
tokens.next();
870867
} else {
871868
key = new IdentifierTypeNode(tokens.currentTokenValue());
872869
tokens.consumeTokenType(Lexer.TOKEN_IDENTIFIER);
873870
}
871+
874872
return this.enrichWithAttributes(tokens, key, startLine, startIndex);
875873
}
876874
}

0 commit comments

Comments
 (0)