Skip to content

Commit f427ee6

Browse files
committed
test: add #21 animate case
1 parent 753c9f8 commit f427ee6

File tree

6 files changed

+85
-1
lines changed

6 files changed

+85
-1
lines changed

packages/core/src/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const isProd = () => process.env.NODE_ENV === 'production'
2+
export const isDev = () => process.env.NODE_ENV === 'development'

packages/core/src/js/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as t from '@babel/types'
33
import { transformSync, type BabelFileResult, type NodePath } from '@babel/core'
44
import type { IJsHandlerOptions } from '../types'
55
import { makeRegex, splitCode } from '../shared'
6+
import { isProd } from '../env'
67

78
export function handleValue(str: string, node: StringLiteral | TemplateElement, options: IJsHandlerOptions) {
89
const { runtimeSet: set, classGenerator: clsGen, splitQuote = true } = options
@@ -66,7 +67,7 @@ export function jsHandler(rawSource: string, options: IJsHandlerOptions) {
6667
}
6768
}
6869
],
69-
minified: true,
70+
minified: options.minified ?? isProd(),
7071
sourceMaps: false,
7172
configFile: false
7273
})

packages/core/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface IHtmlHandlerOptions extends IHandlerOptions {}
2424

2525
export interface IJsHandlerOptions extends IHandlerOptions {
2626
splitQuote?: boolean
27+
minified?: boolean
2728
}
2829

2930
export interface ICssHandlerOptions extends IHandlerOptions {

packages/core/test/__snapshots__/js.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`js handler comment-ignore case 1`] = `
4+
"const clipPath = [\`circle()\`];
5+
document.documentElement.animate({
6+
clipPath
7+
}, {
8+
duration: 500,
9+
easing: "tw-a",
10+
pseudoElement: '::view-transition-new(root)'
11+
});
12+
document.documentElement.animate({
13+
clipPath
14+
}, {
15+
duration: 500,
16+
easing: /* tw-mangle ignore */'ease-out',
17+
pseudoElement: '::view-transition-new(root)'
18+
});"
19+
`;
20+
321
exports[`js handler common StringLiteral 1`] = `"element.innerHTML = "<div class=\\"tw-a tw-b\\">count is counter</div>";"`;
422
523
exports[`js handler common StringLiteral with splitQuote false 1`] = `"element.innerHTML = '<div class="dark:bg-zinc-800/30 lg:dark:bg-zinc-800/30">count is counter</div>';"`;
@@ -17,6 +35,10 @@ exports[`js handler eval script case 1`] = `
1735
});"
1836
`;
1937
38+
exports[`js handler minified js true 1`] = `"const clipPath=[\`circle()\`];document.documentElement.animate({clipPath},{duration:500,easing:"tw-a",pseudoElement:"::view-transition-new(root)"});document.documentElement.animate({clipPath},{duration:500,easing:/* tw-mangle ignore */"ease-out",pseudoElement:"::view-transition-new(root)"});"`;
39+
40+
exports[`js handler minified js with NODE_ENV 1`] = `"const clipPath=[\`circle()\`];document.documentElement.animate({clipPath},{duration:500,easing:"tw-a",pseudoElement:"::view-transition-new(root)"});document.documentElement.animate({clipPath},{duration:500,easing:/* tw-mangle ignore */"ease-out",pseudoElement:"::view-transition-new(root)"});"`;
41+
2042
exports[`js handler nextjs server side mangle 1`] = `
2143
""use strict";
2244
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const clipPath = [`circle()`]
2+
3+
document.documentElement.animate(
4+
{
5+
clipPath
6+
},
7+
{
8+
duration: 500,
9+
easing: 'ease-out',
10+
pseudoElement: '::view-transition-new(root)'
11+
}
12+
)
13+
14+
document.documentElement.animate(
15+
{
16+
clipPath
17+
},
18+
{
19+
duration: 500,
20+
easing: /* tw-mangle ignore */ 'ease-out',
21+
pseudoElement: '::view-transition-new(root)'
22+
}
23+
)

packages/core/test/js.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,39 @@ describe('js handler', () => {
114114
}).code
115115
expect(code).toMatchSnapshot()
116116
})
117+
118+
it('comment-ignore case', () => {
119+
const testCase = getTestCase('comment-ignore.js')
120+
const runtimeSet = new Set<string>()
121+
runtimeSet.add('ease-out')
122+
const code = jsHandler(testCase, {
123+
classGenerator,
124+
runtimeSet
125+
}).code
126+
expect(code).toMatchSnapshot()
127+
})
128+
129+
it('minified js true', () => {
130+
const testCase = getTestCase('comment-ignore.js')
131+
const runtimeSet = new Set<string>()
132+
runtimeSet.add('ease-out')
133+
const code = jsHandler(testCase, {
134+
classGenerator,
135+
runtimeSet,
136+
minified: true
137+
}).code
138+
expect(code).toMatchSnapshot()
139+
})
140+
141+
it('minified js with NODE_ENV', () => {
142+
process.env.NODE_ENV = 'production'
143+
const testCase = getTestCase('comment-ignore.js')
144+
const runtimeSet = new Set<string>()
145+
runtimeSet.add('ease-out')
146+
const code = jsHandler(testCase, {
147+
classGenerator,
148+
runtimeSet
149+
}).code
150+
expect(code).toMatchSnapshot()
151+
})
117152
})

0 commit comments

Comments
 (0)