Skip to content

Commit dbd0502

Browse files
authored
Merge pull request #152 from Igorbek/tab-minification
Fix tab minification
2 parents 9c63533 + 519cbce commit dbd0502

File tree

4 files changed

+99
-5
lines changed

4 files changed

+99
-5
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`issue142.tsx 1`] = `
4+
5+
File: issue142.tsx
6+
Source code:
7+
8+
declare const styled: any;
9+
10+
const Header = styled.div\`
11+
display: flex;
12+
\\t align-items: center;
13+
justify-content: space-between;
14+
\\t \\t font-weight: 600;
15+
padding: 0.8em 1.6em;\\t \\t
16+
background: peachpuff;
17+
\`;
18+
19+
20+
TypeScript before transform:
21+
22+
declare const styled: any;
23+
const Header = styled.div \`
24+
display: flex;
25+
\\t align-items: center;
26+
justify-content: space-between;
27+
\\t \\t font-weight: 600;
28+
padding: 0.8em 1.6em;\\t \\t
29+
background: peachpuff;
30+
\`;
31+
32+
33+
TypeScript after transform:
34+
35+
declare const styled: any;
36+
const Header = styled.div \`display:flex;align-items:center;justify-content:space-between;font-weight:600;padding:0.8em 1.6em;background:peachpuff;\`;
37+
38+
39+
40+
`;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`issue142.tsx 1`] = `
4+
5+
File: issue142.tsx
6+
Source code:
7+
8+
declare const styled: any;
9+
10+
const Header = styled.div\`
11+
display: flex;
12+
\\t align-items: center;
13+
justify-content: space-between;
14+
\\t \\t font-weight: 600;
15+
padding: 0.8em 1.6em;\\t \\t
16+
background: peachpuff;
17+
\`;
18+
19+
20+
TypeScript before transform:
21+
22+
declare const styled: any;
23+
const Header = styled.div \`
24+
display: flex;
25+
\\t align-items: center;
26+
justify-content: space-between;
27+
\\t \\t font-weight: 600;
28+
padding: 0.8em 1.6em;\\t \\t
29+
background: peachpuff;
30+
\`;
31+
32+
33+
TypeScript after transform:
34+
35+
declare const styled: any;
36+
const Header = styled.div.withConfig({ displayName: "Header" }) \`display:flex;align-items:center;justify-content:space-between;font-weight:600;padding:0.8em 1.6em;background:peachpuff;\`;
37+
38+
39+
40+
`;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
declare const styled: any;
2+
3+
const Header = styled.div`
4+
display: flex;
5+
\t align-items: center;
6+
justify-content: space-between;
7+
\t \t font-weight: 600;
8+
padding: 0.8em 1.6em;\t \t
9+
background: peachpuff;
10+
`;

src/minify.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ function isSymbol(ch: string) {
1414
return ch == ';' || ch == ':' || ch == '{' || ch == '}' || ch == ',';
1515
}
1616

17+
function isSpace(ch: string) {
18+
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
19+
}
20+
1721
const stateMachine: StateMachine = {
1822
';': {
1923
next(ch) {
2024
if (ch == '\'' || ch == '"' || ch == '(') return { state: ch }
21-
if (ch == ' ' || ch == '\n' || ch == '\r') return { skipEmit: true }
25+
if (isSpace(ch)) return { skipEmit: true }
2226
if (ch == '/') return { state: ';/', skipEmit: true }
2327
if (isSymbol(ch)) return;
2428
return { state: 'x' }
@@ -30,7 +34,7 @@ const stateMachine: StateMachine = {
3034
';$': { // after placeholder
3135
next(ch) {
3236
if (ch == '\'' || ch == '"' || ch == '(') return { state: ch }
33-
if (ch == ' ' || ch == '\n' || ch == '\r') return { skipEmit: true, state: ' ' } // we may need a space
37+
if (isSpace(ch)) return { skipEmit: true, state: ' ' } // we may need a space
3438
if (ch == '/') return { state: '/', skipEmit: true }
3539
if (isSymbol(ch)) return { state: ';' };
3640
return { state: 'x' }
@@ -39,15 +43,15 @@ const stateMachine: StateMachine = {
3943
'x': {
4044
next(ch) {
4145
if (ch == '\'' || ch == '"' || ch == '(') return { state: ch }
42-
if (ch == ' ' || ch == '\n' || ch == '\r') return { state: ' ', skipEmit: true }
46+
if (isSpace(ch)) return { state: ' ', skipEmit: true }
4347
if (ch == '/') return { state: '/', skipEmit: true }
4448
if (isSymbol(ch)) return { state: ';' };
4549
}
4650
},
4751
' ': { // may need space
4852
next(ch) {
4953
if (ch == '\'' || ch == '"' || ch == '(') return { state: ch, emit: ' ' + ch }
50-
if (ch == ' ' || ch == '\n' || ch == '\r') return { state: ' ', skipEmit: true }
54+
if (isSpace(ch)) return { state: ' ', skipEmit: true }
5155
if (ch == '/') return { state: '/', skipEmit: true }
5256
if (isSymbol(ch)) return { state: ';' };
5357
return { state: 'x', emit: ' ' + ch };
@@ -59,7 +63,7 @@ const stateMachine: StateMachine = {
5963
'\n': { // may need new line
6064
next(ch) {
6165
if (ch == '\'' || ch == '"' || ch == '(') return { state: ch, emit: '\n' + ch }
62-
if (ch == ' ' || ch == '\n' || ch == '\r') return { state: '\n', skipEmit: true }
66+
if (isSpace(ch)) return { state: '\n', skipEmit: true }
6367
if (ch == '/') return { state: '/', emit: '\n' }
6468
if (isSymbol(ch)) return { state: ';', emit: '\n' + ch };
6569
return { state: 'x', emit: '\n' + ch };

0 commit comments

Comments
 (0)