From 2b9a56d6272d010f4cf010aa77d0af1035f78cd8 Mon Sep 17 00:00:00 2001 From: Simon Haugen Date: Sun, 21 Apr 2024 20:27:54 +0200 Subject: [PATCH] fix(replace): fix replace for ternary operators --- packages/replace/src/index.js | 5 +++-- .../fixtures/form/ternary-operator/_config.js | 9 +++++++++ .../fixtures/form/ternary-operator/input.js | 3 +++ .../fixtures/form/ternary-operator/output.js | 3 +++ packages/replace/test/snapshots/form.js.md | 8 ++++++++ packages/replace/test/snapshots/form.js.snap | Bin 733 -> 801 bytes 6 files changed, 26 insertions(+), 2 deletions(-) create mode 100755 packages/replace/test/fixtures/form/ternary-operator/_config.js create mode 100644 packages/replace/test/fixtures/form/ternary-operator/input.js create mode 100644 packages/replace/test/fixtures/form/ternary-operator/output.js diff --git a/packages/replace/src/index.js b/packages/replace/src/index.js index acfb91990..cdbe6419a 100755 --- a/packages/replace/src/index.js +++ b/packages/replace/src/index.js @@ -74,9 +74,10 @@ export default function replace(options = {}) { if (objectGuards) expandTypeofReplacements(replacements); const functionValues = mapToFunctions(replacements); const keys = Object.keys(functionValues).sort(longest).map(escape); - const lookahead = preventAssignment ? '(?!\\s*(=[^=]|:[^:]))' : ''; + const lookbehind = preventAssignment ? '(? Snapshot 1 + + `/* eslint-disable */␊ + first ? second : third;␊ + console.log(first, second, third);` + ## typescript-declare: doesn't replace lvalue in typescript declare > Snapshot 1 diff --git a/packages/replace/test/snapshots/form.js.snap b/packages/replace/test/snapshots/form.js.snap index e907e7442b28b234108504ee7b6f80061beeb5d4..242f1c08c07fa821ff2f54c6fba036f3c48d578e 100644 GIT binary patch literal 801 zcmV++1K#{WRzVt8ox&7vkUB2f;Gn zhm+Ijz#oeU00000000AxmCtX}Fcil(A%v70S2*xiX-hjTX@`(t=~{k>0YVH8Xc8Qd z=Grf7Eczvo`X6J_{0{rQVdI)xVlMkJ?t zj@m^a43hR8SWFb-2x`GpiXb&qDoL6pG&7EVUkSk+`_{X+@n9qSZQkE_xcNA-h9gmk zdJ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