Skip to content

Commit

Permalink
Emit ES5 Friendly Code in Program#exit Visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Feb 19, 2020
1 parent 56a45f0 commit 298f7c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/babel/plugins/next-ssg-transform.ts
Expand Up @@ -42,7 +42,7 @@ function decorateSsgExport(

// @ts-ignore invalid return type
const [pageCompPath] = path.replaceWithMultiple([
t.variableDeclaration('const', [
t.variableDeclaration('var', [
t.variableDeclarator(t.identifier(pageComponentVar), prev as any),
]),
t.assignmentExpression(
Expand Down
32 changes: 16 additions & 16 deletions test/unit/babel-plugin-next-ssg-transform.test.js
Expand Up @@ -40,7 +40,7 @@ describe('babel plugin (next-ssg-transform)', () => {
}
`)
expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -53,7 +53,7 @@ describe('babel plugin (next-ssg-transform)', () => {
}
`)
expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -66,7 +66,7 @@ describe('babel plugin (next-ssg-transform)', () => {
}
`)
expect(output).toMatchInlineSnapshot(
`"export{foo,bar as baz}from'.';const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"export{foo,bar as baz}from'.';var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -86,7 +86,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -106,7 +106,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -124,7 +124,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"export function Noop(){}const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"export function Noop(){}var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -144,7 +144,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -164,7 +164,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -184,7 +184,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"export const foo=2;const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"export const foo=2;var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -202,7 +202,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -220,7 +220,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const a=2;const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"const a=2;var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -238,7 +238,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -258,7 +258,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"export class MyClass{}const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"export class MyClass{}var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand Down Expand Up @@ -305,7 +305,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"import keep_me from'hello';import{keep_me2}from'hello2';import*as keep_me3 from'hello3';import{but_not_me}from'bar';var leave_me_alone=1;function dont_bug_me_either(){}const __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"import keep_me from'hello';import{keep_me2}from'hello2';import*as keep_me3 from'hello3';import{but_not_me}from'bar';var leave_me_alone=1;function dont_bug_me_either(){}var __NEXT_COMP=function Test(){return __jsx(\\"div\\",null);};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand Down Expand Up @@ -346,7 +346,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"const __NEXT_COMP=class Test extends React.Component{render(){return __jsx(\\"div\\",null);}};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"var __NEXT_COMP=class Test extends React.Component{render(){return __jsx(\\"div\\",null);}};__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand All @@ -366,7 +366,7 @@ describe('babel plugin (next-ssg-transform)', () => {
`)

expect(output).toMatchInlineSnapshot(
`"class Test extends React.Component{render(){return __jsx(\\"div\\",null);}}const __NEXT_COMP=Test;__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
`"class Test extends React.Component{render(){return __jsx(\\"div\\",null);}}var __NEXT_COMP=Test;__NEXT_COMP.__N_SSG=true export default __NEXT_COMP;"`
)
})

Expand Down

0 comments on commit 298f7c0

Please sign in to comment.