From aed333817d73479337124e8eed4b5aab9ecc67cc Mon Sep 17 00:00:00 2001 From: OneNail <31649110+OneNail@users.noreply.github.com> Date: Thu, 24 Jun 2021 20:28:25 +0800 Subject: [PATCH] chore(playground): text util (#3851) --- packages/playground/data-uri/index.html | 8 ++++++-- packages/playground/legacy/main.js | 20 ++++++++++--------- .../playground/optimize-deps/cjs-dynamic.js | 8 ++++++-- packages/playground/optimize-deps/cjs.js | 8 ++++++-- packages/playground/optimize-deps/index.html | 18 +++++++++-------- packages/playground/worker/index.html | 12 +++++++---- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/packages/playground/data-uri/index.html b/packages/playground/data-uri/index.html index 80e0fc6fcc6c17..32cc458940e60c 100644 --- a/packages/playground/data-uri/index.html +++ b/packages/playground/data-uri/index.html @@ -3,8 +3,12 @@ diff --git a/packages/playground/legacy/main.js b/packages/playground/legacy/main.js index c337989413a081..78322d69455af0 100644 --- a/packages/playground/legacy/main.js +++ b/packages/playground/legacy/main.js @@ -14,17 +14,19 @@ if (import.meta.env.LEGACY) { if (import.meta.env.LEGACY === false) isLegacy = false } -document.getElementById('env').textContent = `is legacy: ${isLegacy}` +text('#env', `is legacy: ${isLegacy}`) // Iterators - -document.getElementById('iterators').textContent = [...new Set(['hello'])].join( - '' -) +text('#iterators', [...new Set(['hello'])].join('')) // babel-helpers - -document.getElementById('babel-helpers').textContent = - // Using `String.raw` to inject `@babel/plugin-transform-template-literals` - // helpers. +// Using `String.raw` to inject `@babel/plugin-transform-template-literals` +// helpers. +text( + '#babel-helpers', String.raw`exposed babel helpers: ${window._templateObject != null}` +) + +function text(el, text) { + document.querySelector(el).textContent = text +} diff --git a/packages/playground/optimize-deps/cjs-dynamic.js b/packages/playground/optimize-deps/cjs-dynamic.js index dceffd811772d7..4d3856d8f69a92 100644 --- a/packages/playground/optimize-deps/cjs-dynamic.js +++ b/packages/playground/optimize-deps/cjs-dynamic.js @@ -8,12 +8,12 @@ const clip = await import('clipboard') if (typeof clip.default === 'function') { - document.querySelector('.cjs-dynamic-clipboard').textContent = 'ok' + text('.cjs-dynamic-clipboard', 'ok') } const { Socket } = await import('phoenix') if (typeof Socket === 'function') { - document.querySelector('.cjs-dynamic-phoenix').textContent = 'ok' + text('.cjs-dynamic-phoenix', 'ok') } function App() { @@ -34,4 +34,8 @@ React.createElement(App), document.querySelector('.cjs-dynamic') ) + + function text(el, text) { + document.querySelector(el).textContent = text + } })() diff --git a/packages/playground/optimize-deps/cjs.js b/packages/playground/optimize-deps/cjs.js index 196d395edc30a2..9dc613c4b3ba71 100644 --- a/packages/playground/optimize-deps/cjs.js +++ b/packages/playground/optimize-deps/cjs.js @@ -7,11 +7,11 @@ import { Socket } from 'phoenix' import clip from 'clipboard' if (typeof clip === 'function') { - document.querySelector('.cjs-clipboard').textContent = 'ok' + text('.cjs-clipboard', 'ok') } if (typeof Socket === 'function') { - document.querySelector('.cjs-phoenix').textContent = 'ok' + text('.cjs-phoenix', 'ok') } function App() { @@ -29,3 +29,7 @@ function App() { } ReactDOM.render(React.createElement(App), document.querySelector('.cjs')) + +function text(el, text) { + document.querySelector(el).textContent = text +} diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html index 1bf9be5ca2d2e2..7310ab759f4249 100644 --- a/packages/playground/optimize-deps/index.html +++ b/packages/playground/optimize-deps/index.html @@ -48,26 +48,28 @@