From 33fb951d55cb4e96ef78ef8201d0d71d80926077 Mon Sep 17 00:00:00 2001
From: Troy Morehouse
Date: Fri, 14 Dec 2018 21:05:38 -0400
Subject: [PATCH 1/6] Create needs-transpiler.js
---
docs/utils/needs-transpiler.js | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 docs/utils/needs-transpiler.js
diff --git a/docs/utils/needs-transpiler.js b/docs/utils/needs-transpiler.js
new file mode 100644
index 00000000000..a99a1a948b8
--- /dev/null
+++ b/docs/utils/needs-transpiler.js
@@ -0,0 +1,24 @@
+// Determine if the broser needs to use @babel/standalone compiler for v-play and playground
+
+let needsTranspiler = false
+
+// Tests to see if we need to compile ES6 to ES5
+// If any test fails, then we need to transpile code with @babel/standalone
+const tests = [
+ 'const test1 = (a) => a',
+ 'const test2 = { a: 1, b () { return 0 } }',
+ 'const test3a = { a: 1, b: 2}; const test3b = { c: 3, ...test3a }'
+]
+
+// Run tests to see if transpilation is needed
+if (typeof window !== 'undefined') {
+ for (let i = 0; i < tests.length && !needsTranspiler; i++) {
+ try {
+ eval(tests[i])
+ } catch (e) {
+ needsTranspiler = true
+ }
+ }
+}
+
+export defailt needsTranspiler
From 0ddec91eca6f1ba3954f302a3961688b86bb4766 Mon Sep 17 00:00:00 2001
From: Troy Morehouse
Date: Fri, 14 Dec 2018 21:18:45 -0400
Subject: [PATCH 2/6] Update needs-transpiler.js
---
docs/utils/needs-transpiler.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docs/utils/needs-transpiler.js b/docs/utils/needs-transpiler.js
index a99a1a948b8..a0c993a371e 100644
--- a/docs/utils/needs-transpiler.js
+++ b/docs/utils/needs-transpiler.js
@@ -21,4 +21,4 @@ if (typeof window !== 'undefined') {
}
}
-export defailt needsTranspiler
+export default needsTranspiler
From dc8b7f225d589e3e452303c15b2a97a068c26ae2 Mon Sep 17 00:00:00 2001
From: Troy Morehouse
Date: Fri, 14 Dec 2018 21:32:22 -0400
Subject: [PATCH 3/6] Update needs-transpiler.js
---
docs/utils/needs-transpiler.js | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/docs/utils/needs-transpiler.js b/docs/utils/needs-transpiler.js
index a0c993a371e..d9898ceac68 100644
--- a/docs/utils/needs-transpiler.js
+++ b/docs/utils/needs-transpiler.js
@@ -2,16 +2,24 @@
let needsTranspiler = false
-// Tests to see if we need to compile ES6 to ES5
-// If any test fails, then we need to transpile code with @babel/standalone
+// Tests to see if we need to compile ES6 to ES5. Tests for commonly used ES6 features.
+// If any test fails, then we need to transpile code with @babel/standalone.
const tests = [
+ // Arrow functions
'const test1 = (a) => a',
+ // Object function shortcut
'const test2 = { a: 1, b () { return 0 } }',
- 'const test3a = { a: 1, b: 2}; const test3b = { c: 3, ...test3a }'
+ // Object shortcut
+ 'const test3a = { a: 1}; const test3b = { test3a, b: 2 }',
+ // Object rest spread
+ 'const test4a = { a: 1, b: 2}; const test4b = { c: 3, ...test4a }',
+ // String interpolation
+ 'const test5a = "bar"; const test5b = `foo${test5a}`'
]
-// Run tests to see if transpilation is needed
+// Run tests to see if transpilation is needed. Returns after first test that fails
if (typeof window !== 'undefined') {
+ /* eslint-disable no-eval */
for (let i = 0; i < tests.length && !needsTranspiler; i++) {
try {
eval(tests[i])
@@ -19,6 +27,7 @@ if (typeof window !== 'undefined') {
needsTranspiler = true
}
}
+ /* eslint-enable no-eval */
}
export default needsTranspiler
From 61c1ed34c3df0723deeca470b2eb645b647571d0 Mon Sep 17 00:00:00 2001
From: Troy Morehouse
Date: Fri, 14 Dec 2018 21:45:06 -0400
Subject: [PATCH 4/6] lint
---
docs/utils/needs-transpiler.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/utils/needs-transpiler.js b/docs/utils/needs-transpiler.js
index d9898ceac68..98493a662d1 100644
--- a/docs/utils/needs-transpiler.js
+++ b/docs/utils/needs-transpiler.js
@@ -14,7 +14,9 @@ const tests = [
// Object rest spread
'const test4a = { a: 1, b: 2}; const test4b = { c: 3, ...test4a }',
// String interpolation
+ /* eslint-disable no-template-curly-in-string */
'const test5a = "bar"; const test5b = `foo${test5a}`'
+ /* eslint-enable no-template-curly-in-string */
]
// Run tests to see if transpilation is needed. Returns after first test that fails
From 41e1b04e0c6b48e9c0e28183a93d96deb00b50fd Mon Sep 17 00:00:00 2001
From: Troy Morehouse
Date: Fri, 14 Dec 2018 22:05:23 -0400
Subject: [PATCH 5/6] play.vue: conditionally include babel-standalone
Only include compiler if browser needs it.
---
docs/pages/play.vue | 81 +++++++++++++++++++++++++--------------------
1 file changed, 45 insertions(+), 36 deletions(-)
diff --git a/docs/pages/play.vue b/docs/pages/play.vue
index 800a5943996..1bf0ee9b9be 100755
--- a/docs/pages/play.vue
+++ b/docs/pages/play.vue
@@ -13,24 +13,25 @@
You can clone docs repo, to hack and develop components.
changes will be reflected and hot-reloaded instantly.
+
+
Loading JavaScript Compiler...
-
-
-
-
Reset to default
+
+
+ Reset to default
+
@@ -163,6 +164,7 @@