Skip to content

Commit

Permalink
fix: avoid using es2015+ in generated code (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn authored Aug 15, 2019
1 parent d8d5bb2 commit d2ca96a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/template/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function createRoute(meta: PageMeta): string {

function createImport(meta: PageMeta, dynamic: boolean): string {
const code = dynamic
? `const ${meta.specifier} = () => import(/* webpackChunkName: "${
? `function ${meta.specifier}() { return import(/* webpackChunkName: "${
meta.name
}" */ '${meta.component}')`
}" */ '${meta.component}') }`
: `import ${meta.specifier} from '${meta.component}'`

return meta.children
Expand Down
37 changes: 24 additions & 13 deletions test/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Integration test 1`] = `
"const Index = () => import(/* webpackChunkName: \\"index\\" */ '@/pages/index.vue')
const Foo = () => import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
const FooIndex = () =>
import(/* webpackChunkName: \\"foo-index\\" */ '@/pages/foo/index.vue')
const FooBar = () =>
import(/* webpackChunkName: \\"foo-bar\\" */ '@/pages/foo/bar.vue')
const FooId = () =>
import(/* webpackChunkName: \\"foo-id\\" */ '@/pages/foo/_id.vue')
const Meta = () => import(/* webpackChunkName: \\"meta\\" */ '@/pages/meta.vue')
const IdIndex = () =>
import(/* webpackChunkName: \\"id-index\\" */ '@/pages/_id/index.vue')
const IdTest = () =>
import(/* webpackChunkName: \\"id-test\\" */ '@/pages/_id/test.vue')
"function Index() {
return import(/* webpackChunkName: \\"index\\" */ '@/pages/index.vue')
}
function Foo() {
return import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
}
function FooIndex() {
return import(/* webpackChunkName: \\"foo-index\\" */ '@/pages/foo/index.vue')
}
function FooBar() {
return import(/* webpackChunkName: \\"foo-bar\\" */ '@/pages/foo/bar.vue')
}
function FooId() {
return import(/* webpackChunkName: \\"foo-id\\" */ '@/pages/foo/_id.vue')
}
function Meta() {
return import(/* webpackChunkName: \\"meta\\" */ '@/pages/meta.vue')
}
function IdIndex() {
return import(/* webpackChunkName: \\"id-index\\" */ '@/pages/_id/index.vue')
}
function IdTest() {
return import(/* webpackChunkName: \\"id-test\\" */ '@/pages/_id/test.vue')
}
export default [
{
Expand Down
29 changes: 21 additions & 8 deletions test/__snapshots__/route-template.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Route template should generate nested routes 1`] = `
"const Foo = () => import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
const FooBar = () => import(/* webpackChunkName: \\"bar\\" */ '@/pages/bar.vue')
const FooBaz = () => import(/* webpackChunkName: \\"baz\\" */ '@/pages/baz.vue')
"function Foo() {
return import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
}
function FooBar() {
return import(/* webpackChunkName: \\"bar\\" */ '@/pages/bar.vue')
}
function FooBaz() {
return import(/* webpackChunkName: \\"baz\\" */ '@/pages/baz.vue')
}
export default [
{
Expand Down Expand Up @@ -44,8 +50,12 @@ export default [
`;

exports[`Route template should generate routes 1`] = `
"const Foo = () => import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
const Bar = () => import(/* webpackChunkName: \\"bar\\" */ '@/pages/bar.vue')
"function Foo() {
return import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
}
function Bar() {
return import(/* webpackChunkName: \\"bar\\" */ '@/pages/bar.vue')
}
export default [
{
Expand Down Expand Up @@ -82,9 +92,12 @@ export default [
`;

exports[`Route template should not include name if the route has a default child 1`] = `
"const Foo = () => import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
const FooIndex = () =>
import(/* webpackChunkName: \\"foo-index\\" */ '@/pages/foo/index.vue')
"function Foo() {
return import(/* webpackChunkName: \\"foo\\" */ '@/pages/foo.vue')
}
function FooIndex() {
return import(/* webpackChunkName: \\"foo-index\\" */ '@/pages/foo/index.vue')
}
export default [
{
Expand Down

0 comments on commit d2ca96a

Please sign in to comment.