From 0538c3cd8c811646fc653fe8b7e256df4040fed8 Mon Sep 17 00:00:00 2001 From: Diogo Franco Date: Sat, 12 Aug 2017 14:11:27 +0900 Subject: [PATCH] Add another test for runtime order of template literals (#6092) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More proof that it really is unsafe to merge the .concat calls if the value is an expression that has any chance of executing impure code 😢 --- .../test/fixtures/spec/order2/exec.js | 19 +++++++++++++++++++ .../test/fixtures/spec/order2/options.json | 3 +++ 2 files changed, 22 insertions(+) create mode 100644 packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/exec.js create mode 100644 packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/options.json diff --git a/packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/exec.js b/packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/exec.js new file mode 100644 index 0000000000..6883703459 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/exec.js @@ -0,0 +1,19 @@ +const calls = []; + +` + ${{ + [Symbol.toPrimitive]() { + calls.push(1); + return "foo"; + } + }} + ${1 + + { + valueOf() { + calls.push(2); + return 2; + } + }} +`; + +assert.deepEqual(calls, [1, 2]); diff --git a/packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/options.json b/packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/options.json new file mode 100644 index 0000000000..7d8c3c204c --- /dev/null +++ b/packages/babel-plugin-transform-es2015-template-literals/test/fixtures/spec/order2/options.json @@ -0,0 +1,3 @@ +{ + "minNodeVersion": "6.0.0" +}