diff options
author | 2021-11-08 15:37:31 -0800 | |
---|---|---|
committer | 2021-11-08 15:37:31 -0800 | |
commit | 241525947c033de9a8a46abfb8f064cc95a5c0b0 (patch) | |
tree | 52e750e49462b737f7f8aa49d57840e91dee020a /integration | |
parent | c7705a6325143aee71b351d5701ba46373704ff6 (diff) | |
download | bun-241525947c033de9a8a46abfb8f064cc95a5c0b0.tar.gz bun-241525947c033de9a8a46abfb8f064cc95a5c0b0.tar.zst bun-241525947c033de9a8a46abfb8f064cc95a5c0b0.zip |
[JS Printer] Fix bug with optional chain
Diffstat (limited to 'integration')
5 files changed, 97 insertions, 1 deletions
diff --git a/integration/scripts/snippets.json b/integration/scripts/snippets.json index b877487e7..233d508d8 100644 --- a/integration/scripts/snippets.json +++ b/integration/scripts/snippets.json @@ -21,5 +21,6 @@ "/react-context-value-func.tsx", "/latin1-chars-in-regexp.js", "/jsx-spacing.jsx", - "/jsx-entities.jsx" + "/jsx-entities.jsx", + "/optional-chain-with-function.js" ] diff --git a/integration/snapshots/optional-chain-with-function.debug.js b/integration/snapshots/optional-chain-with-function.debug.js new file mode 100644 index 000000000..bf007b0a8 --- /dev/null +++ b/integration/snapshots/optional-chain-with-function.debug.js @@ -0,0 +1,13 @@ +export function test() { + try { + const multipleSecondaryValues = undefined; + const ratings = ["123"]; + var bar = multipleSecondaryValues?.map((value) => false); + bar = (bar?.multipleSecondaryValues)?.map((value) => false); + bar = (bar?.bar?.multipleSecondaryValues)?.map((value) => false); + bar = ({}?.bar?.multipleSecondaryValues)?.map((value) => false); + } catch (e) { + throw e; + } + return testDone(import.meta.url); +} diff --git a/integration/snapshots/optional-chain-with-function.hmr.debug.js b/integration/snapshots/optional-chain-with-function.hmr.debug.js new file mode 100644 index 000000000..5bf65a6f8 --- /dev/null +++ b/integration/snapshots/optional-chain-with-function.hmr.debug.js @@ -0,0 +1,35 @@ +import { +__HMRModule as HMR +} from "http://localhost:8080/__runtime.js"; +import { +__HMRClient as Bun +} from "http://localhost:8080/__runtime.js"; +Bun.activate(true); + +var hmr = new HMR(3608848620, "optional-chain-with-function.js"), exports = hmr.exports; +(hmr._load = function() { + function test() { + try { + const multipleSecondaryValues = undefined; + const ratings = ["123"]; + var bar = multipleSecondaryValues?.map((value) => false); + bar = (bar?.multipleSecondaryValues)?.map((value) => false); + bar = (bar?.bar?.multipleSecondaryValues)?.map((value) => false); + bar = ({}?.bar?.multipleSecondaryValues)?.map((value) => false); + } catch (e) { + throw e; + } + return testDone(import.meta.url); + } + hmr.exportAll({ + test: () => test + }); +})(); +var $$hmr_test = hmr.exports.test; +hmr._update = function(exports) { + $$hmr_test = exports.test; +}; + +export { + $$hmr_test as test +}; diff --git a/integration/snapshots/optional-chain-with-function.hmr.js b/integration/snapshots/optional-chain-with-function.hmr.js new file mode 100644 index 000000000..77ea50dd0 --- /dev/null +++ b/integration/snapshots/optional-chain-with-function.hmr.js @@ -0,0 +1,32 @@ +import { +__HMRModule as HMR +} from "http://localhost:8080/__runtime.js"; +import { +__HMRClient as Bun +} from "http://localhost:8080/__runtime.js"; +Bun.activate(false); + +var hmr = new HMR(3608848620, "optional-chain-with-function.js"), exports = hmr.exports; +(hmr._load = function() { + function test() { + try { + const multipleSecondaryValues = undefined; + const ratings = ["123"]; + const multipleSecondaryIds = ratings && (multipleSecondaryValues?.map)((value) => false); + } catch (e) { + throw e; + } + return testDone(import.meta.url); + } + hmr.exportAll({ + test: () => test + }); +})(); +var $$hmr_test = hmr.exports.test; +hmr._update = function(exports) { + $$hmr_test = exports.test; +}; + +export { + $$hmr_test as test +}; diff --git a/integration/snippets/optional-chain-with-function.js b/integration/snippets/optional-chain-with-function.js new file mode 100644 index 000000000..82ad51d46 --- /dev/null +++ b/integration/snippets/optional-chain-with-function.js @@ -0,0 +1,15 @@ +export function test() { + try { + const multipleSecondaryValues = undefined; + const ratings = ["123"]; + + var bar = multipleSecondaryValues?.map((value) => false); + bar = bar?.multipleSecondaryValues?.map((value) => false); + bar = bar?.bar?.multipleSecondaryValues?.map((value) => false); + bar = {}?.bar?.multipleSecondaryValues?.map((value) => false); + } catch (e) { + throw e; + } + + return testDone(import.meta.url); +} |