Skip to content

[fix] fix missing space before "-" #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/__tests__/baselines/minification-only/issue233.tsx.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`issue233.tsx 1`] = `

File: issue233.tsx
Source code:

declare const styled: any;

const ValueCalc = styled.div\`
height: calc(var(--line-height) - 5px);
width: calc(100% - 5px);
\`;


TypeScript before transform:

declare const styled: any;
const ValueCalc = styled.div \`
height: calc(var(--line-height) - 5px);
width: calc(100% - 5px);
\`;


TypeScript after transform:

declare const styled: any;
const ValueCalc = styled.div \`height:calc(var(--line-height) - 5px);width:calc(100% - 5px);\`;



`;
32 changes: 32 additions & 0 deletions src/__tests__/baselines/minification/issue233.tsx.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`issue233.tsx 1`] = `

File: issue233.tsx
Source code:

declare const styled: any;

const ValueCalc = styled.div\`
height: calc(var(--line-height) - 5px);
width: calc(100% - 5px);
\`;


TypeScript before transform:

declare const styled: any;
const ValueCalc = styled.div \`
height: calc(var(--line-height) - 5px);
width: calc(100% - 5px);
\`;


TypeScript after transform:

declare const styled: any;
const ValueCalc = styled.div.withConfig({ displayName: "ValueCalc" }) \`height:calc(var(--line-height) - 5px);width:calc(100% - 5px);\`;



`;
6 changes: 6 additions & 0 deletions src/__tests__/fixtures/minification/issue233.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare const styled: any;

const ValueCalc = styled.div`
height: calc(var(--line-height) - 5px);
width: calc(100% - 5px);
`;
8 changes: 7 additions & 1 deletion src/minify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ts from 'typescript';
import { isNoSubstitutionTemplateLiteral, isTemplateExpression } from './ts-is-kind';

type State = ';' | ';$' | 'x' | ' ' | '\n' | '"' | '(' | '\'' | '/' | '//' | ';/' | ';//' | '/$' | '//$' | '/*' | '/**' | ';/*' | ';/**' | '/*$' | '/*$*';
type State = ';' | ';$' | 'x' | ' ' | '\n' | '"' | '(' | "((" | '\'' | '/' | '//' | ';/' | ';//' | '/$' | '//$' | '/*' | '/**' | ';/*' | ';/**' | '/*$' | '/*$*';
type ReducerResult = { emit?: string; skipEmit?: boolean; state?: State; } | void;
type StateMachine = {
[K in State]: {
Expand Down Expand Up @@ -81,9 +81,15 @@ const stateMachine: StateMachine = {
},
'(': {
next(ch) {
if (ch == "(") return { state: '((' };
if (ch == ')') return { state: ';' }; // maybe return ' '? then it'd always add space after
}
},
'((': {
next(ch) {
if(ch == ')') return { state: "(" };
}
},
'/': {
next(ch) {
if (ch == '/') return { state: '//', skipEmit: true }
Expand Down