diff --git a/package.json b/package.json index 30c77df..211d931 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "fs-extra": "^7.0.1", "lodash": "^4.17.11", "ts-morph": "^2.3.0", - "typescript": "3.4.5", + "typescript": "~3.4.5", "yargs": "^13.2.4" }, "nyc": { diff --git a/src/emitter.ts b/src/emitter.ts index 3411323..822d25a 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -659,7 +659,8 @@ export function emitFile( // SyntaxKind.TemplateMiddle // SyntaxKind.TemplateTail function emitLiteral(node: ts.LiteralLikeNode) { - const text = getLiteralTextOfNode(node, true); + let text = getLiteralTextOfNode(node, true); + text = text.replace(/(\\)?\$/g, '\\$'); // Quick info expects all literals to be called with writeStringLiteral, as there's no specific type for numberLiterals writeStringLiteral(text); } @@ -2338,6 +2339,9 @@ export function emitFile( if (ts.isLiteralExpression(node.name)) { emitLiteral(node.name); } + else if (ts.isIdentifier(node.name)) { + emit(node.name); + } else { emit(node.name); } @@ -3244,7 +3248,6 @@ export function emitFile( // return idText(node); // } if (isIdentifier(node)) { - const name = (node).escapedText as string; let head = ''; let tail = ''; @@ -3265,7 +3268,7 @@ export function emitFile( // head = className + '::' + head; // } - return head + idText(node) + tail; + return head + idText(node).replace(/(\\)?\$/g, '\\$') + tail; } if (isImportSpecifier(node)) { diff --git a/test/features/ObjectLiteralExpression.php b/test/features/ObjectLiteralExpression.php index b4801da..d579e2a 100644 --- a/test/features/ObjectLiteralExpression.php +++ b/test/features/ObjectLiteralExpression.php @@ -10,3 +10,7 @@ "a-b" => $b ); $c = array_key_exists("b", $a); +$d = array( + "\$a" => "a", + "b" => "\$b" +); diff --git a/test/features/ObjectLiteralExpression.ts b/test/features/ObjectLiteralExpression.ts index 5a7a49a..f5ee108 100644 --- a/test/features/ObjectLiteralExpression.ts +++ b/test/features/ObjectLiteralExpression.ts @@ -10,3 +10,8 @@ const a = { }; const c = 'b' in a; + +const d = { + $a: "a", + b: "$b" +};