Skip to content

Commit 0b7dfc4

Browse files
committed
Fix missing space after placeholder
1 parent aff4796 commit 0b7dfc4

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

src/__tests__/baselines/minification-only/issue36-extended.ts.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TypeScript before transform:
2121
TypeScript after transform:
2222

2323
declare const styled: any;
24-
export const A = styled.div \`border:\${'solid'}10px;\`;
24+
export const A = styled.div \`border:\${'solid'} 10px;\`;
2525

2626

2727

src/__tests__/baselines/minification-only/issue36.tsx.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TypeScript after transform:
3838
declare const keyframes: any;
3939
declare const styled: any;
4040
const rotate360 = keyframes \`from{transform:rotate(0deg);}to{transform:rotate(360deg);}\`;
41-
export const StyledDiv = styled.div \`width:100px;height:100px;background-color:greenyellow;animation:\${rotate360}2s linear infinite;\`;
41+
export const StyledDiv = styled.div \`width:100px;height:100px;background-color:greenyellow;animation:\${rotate360} 2s linear infinite;\`;
4242

4343

4444

src/__tests__/baselines/minification/issue36-extended.ts.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TypeScript before transform:
2121
TypeScript after transform:
2222

2323
declare const styled: any;
24-
export const A = styled.div.withConfig({ displayName: "A" }) \`border:\${'solid'}10px;\`;
24+
export const A = styled.div.withConfig({ displayName: "A" }) \`border:\${'solid'} 10px;\`;
2525

2626

2727

src/__tests__/baselines/minification/issue36.tsx.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TypeScript after transform:
3838
declare const keyframes: any;
3939
declare const styled: any;
4040
const rotate360 = keyframes \`from{transform:rotate(0deg);}to{transform:rotate(360deg);}\`;
41-
export const StyledDiv = styled.div.withConfig({ displayName: "StyledDiv" }) \`width:100px;height:100px;background-color:greenyellow;animation:\${rotate360}2s linear infinite;\`;
41+
export const StyledDiv = styled.div.withConfig({ displayName: "StyledDiv" }) \`width:100px;height:100px;background-color:greenyellow;animation:\${rotate360} 2s linear infinite;\`;
4242

4343

4444

src/minify.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import * as ts from 'typescript';
22
import { isNoSubstitutionTemplateLiteral, isTemplateExpression } from './ts-is-kind';
33

4-
type State = ';' | 'x' | ' ' | '\n' | '"' | '(' | '\'' | '/' | '//' | '/$' | '//$' | '/*' | '/**' | '/*$' | '/*$*';
4+
type State = ';' | ';$' | 'x' | ' ' | '\n' | '"' | '(' | '\'' | '/' | '//' | '/$' | '//$' | '/*' | '/**' | '/*$' | '/*$*';
55
type ReducerResult = { emit?: string; skipEmit?: boolean; state?: State } | void;
66
type StateMachine = {
77
[K in State]: {
88
next?(ch: string): ReducerResult;
99
flush?(last: boolean): ReducerResult;
10+
placeholder?(): ReducerResult;
1011
}
1112
};
1213

@@ -22,6 +23,18 @@ const stateMachine: StateMachine = {
2223
if (ch == '/') return { state: '/', skipEmit: true }
2324
if (isSymbol(ch)) return;
2425
return { state: 'x' }
26+
},
27+
flush() {
28+
return { state: ';$' }
29+
}
30+
},
31+
';$': { // after placeholder
32+
next(ch) {
33+
if (ch == '\'' || ch == '"' || ch == '(') return { state: ch }
34+
if (ch == ' ' || ch == '\n' || ch == '\r') return { skipEmit: true, state: ' ' } // we may need a space
35+
if (ch == '/') return { state: '/', skipEmit: true }
36+
if (isSymbol(ch)) return;
37+
return { state: 'x' }
2538
}
2639
},
2740
'x': {
@@ -141,16 +154,19 @@ function createMinifier(): (next: string, last?: boolean) => string {
141154
minified += ch;
142155
}
143156
}
157+
158+
let reducer = stateMachine[state];
159+
apply(reducer.placeholder && reducer.placeholder());
144160

145161
let pos = 0;
146162
let len = next.length;
147163
while (pos < len) {
148164
const ch = next[pos++];
149-
const reducer = stateMachine[state];
165+
reducer = stateMachine[state];
150166
apply(reducer.next && reducer.next(ch), ch)
151167
}
152168

153-
const reducer = stateMachine[state];
169+
reducer = stateMachine[state];
154170
apply(reducer.flush && reducer.flush(last));
155171

156172
return minified;

0 commit comments

Comments
 (0)