Skip to content

Commit

Permalink
Fix minification (fix #44)
Browse files Browse the repository at this point in the history
- avoid adding extra space after interpolation
  • Loading branch information
Igorbek committed May 15, 2019
1 parent 8a68540 commit b513bc0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/__tests__/baselines/minification-only/issue44.tsx.baseline
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`issue44.tsx 1`] = `

File: issue44.tsx
Source code:

declare const styled: any;
styled.div\` transition: width \${100}ms ease-in;\`;
styled.div\` transition: width \${'100ms'} ease-in;\`;


TypeScript before transform:

declare const styled: any;
styled.div \` transition: width \${100}ms ease-in;\`;
styled.div \` transition: width \${"100ms"} ease-in;\`;


TypeScript after transform:

declare const styled: any;
styled.div \`transition:width \${100}ms ease-in;\`;
styled.div \`transition:width \${'100ms'} ease-in;\`;



`;
28 changes: 28 additions & 0 deletions src/__tests__/baselines/minification/issue44.tsx.baseline
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`issue44.tsx 1`] = `

File: issue44.tsx
Source code:

declare const styled: any;
styled.div\` transition: width \${100}ms ease-in;\`;
styled.div\` transition: width \${'100ms'} ease-in;\`;


TypeScript before transform:

declare const styled: any;
styled.div \` transition: width \${100}ms ease-in;\`;
styled.div \` transition: width \${"100ms"} ease-in;\`;


TypeScript after transform:

declare const styled: any;
styled.div \`transition:width \${100}ms ease-in;\`;
styled.div \`transition:width \${'100ms'} ease-in;\`;



`;
3 changes: 3 additions & 0 deletions src/__tests__/fixtures/minification/issue44.tsx
@@ -0,0 +1,3 @@
declare const styled: any;
styled.div` transition: width ${100}ms ease-in;`;
styled.div` transition: width ${'100ms'} ease-in;`;
6 changes: 3 additions & 3 deletions src/minify.ts
Expand Up @@ -53,7 +53,7 @@ const stateMachine: StateMachine = {
return { state: 'x', emit: ' ' + ch };
},
flush(last) {
if (!last) return { emit: ' ' };
if (!last) return { emit: ' ', state: ';$' };
}
},
'\n': { // may need new line
Expand Down Expand Up @@ -201,14 +201,14 @@ export function createMinifier(): (next: string, last?: boolean) => string {
const prevState = state;
const reducerResult = reducer.next && reducer.next(ch);
apply(reducerResult, ch)
//console.log('next(', { ch, state: prevState }, '): ', reducerResult, ' -> ', { state, minified });
// console.log('next(', { ch, state: prevState }, '): ', reducerResult, ' -> ', { state, minified });
}

const reducer = stateMachine[state];
const prevState = state;
const reducerResult = reducer.flush && reducer.flush(last);
apply(reducerResult);
//console.log('flush', { state: prevState }, '): ', reducerResult, ' -> ', { state, minified });
// console.log('flush', { state: prevState }, '): ', reducerResult, ' -> ', { state, minified });

return minified;
}
Expand Down

0 comments on commit b513bc0

Please sign in to comment.