diff options
-rw-r--r-- | build-id | 2 | ||||
-rw-r--r-- | integration/scripts/snippets.json | 3 | ||||
-rw-r--r-- | integration/snapshots/optional-chain-with-function.debug.js | 13 | ||||
-rw-r--r-- | integration/snapshots/optional-chain-with-function.hmr.debug.js | 35 | ||||
-rw-r--r-- | integration/snapshots/optional-chain-with-function.hmr.js | 32 | ||||
-rw-r--r-- | integration/snippets/optional-chain-with-function.js | 15 | ||||
-rw-r--r-- | src/js_printer.zig | 17 | ||||
-rw-r--r-- | src/runtime.version | 2 |
8 files changed, 110 insertions, 9 deletions
@@ -1 +1 @@ -46 +47 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); +} diff --git a/src/js_printer.zig b/src/js_printer.zig index d6be0aeb7..06e309665 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -1159,9 +1159,9 @@ pub fn NewPrinter( .e_dot => |e| { var wrap = false; if (e.optional_chain == null) { - flags.has_non_optional_chain_parent = false; + flags.has_non_optional_chain_parent = true; } else { - if (flags.has_non_optional_chain_parent) { + if (!flags.has_non_optional_chain_parent) { wrap = true; p.print("("); } @@ -1173,18 +1173,23 @@ pub fn NewPrinter( // https://github.com/ziglang/zig/issues/6059 const isOptionalChain = (e.optional_chain orelse js_ast.OptionalChain.ccontinue) == js_ast.OptionalChain.start; - if (isOptionalChain) { - p.print("?"); - } if (p.canPrintIdentifier(e.name)) { if (isOptionalChain and p.prev_num_end == p.writer.written) { // "1.toString" is a syntax error, so print "1 .toString" instead p.print(" "); } - p.print("."); + if (isOptionalChain) { + p.print("?."); + } else { + p.print("."); + } + p.addSourceMapping(e.name_loc); p.printIdentifier(e.name); } else { + if (isOptionalChain) { + p.print("?."); + } p.print("["); p.addSourceMapping(e.name_loc); p.printQuotedUTF8(e.name, true); diff --git a/src/runtime.version b/src/runtime.version index 4d5819864..e665ebdc7 100644 --- a/src/runtime.version +++ b/src/runtime.version @@ -1 +1 @@ -9e1331d72d627f15
\ No newline at end of file +ccb6eb48b1a69b4
\ No newline at end of file |