Skip to content

Commit 2daa5df

Browse files
authored
Update TypeScript to 5.1 and support TS 4.8+ (#713)
fixes #710, supersedes #711 - the peer dependency is set to 4.8+ because there [was a breaking change in the API we use in 4.8](https://github.com/microsoft/TypeScript/wiki/API-Breaking-Changes#decorators-are-placed-on-modifiers-on-typescripts-syntax-trees) - use `styled-components` package for types instead of `@types/styled-components`
1 parent bcad238 commit 2daa5df

7 files changed

+266
-59
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@
2121
},
2222
"typings": "dist/index.d.ts",
2323
"peerDependencies": {
24-
"typescript": "^4.0"
24+
"typescript": "~4.8 || 5"
2525
},
2626
"devDependencies": {
2727
"@types/jest": "^25.2.1",
2828
"@types/jest-specific-snapshot": "^0.5.4",
2929
"@types/node": "^13.1.2",
3030
"@types/react": "^16.7.22",
31-
"@types/styled-components": "^5.1.9",
3231
"jest": "^24.1.0",
3332
"jest-specific-snapshot": "^2.0.0",
33+
"styled-components": "^5.3.11",
3434
"ts-jest": "24.3.0",
3535
"ts-node": "^8.0.2",
36-
"typescript": "~4.2"
36+
"typescript": "~5.1"
3737
},
3838
"files": [
3939
"dist"

src/__tests__/baselines/minification-only/minify-css-in-helpers.ts.baseline

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,15 @@ TypeScript after transform:
6464
declare const theColor: any;
6565
const key = keyframes \`to{transform:rotate(360deg);}\`;
6666
const color = css \`color:\${theColor};\`;
67-
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}
68-
}\`;
67+
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}\\n}\`;
6968
export {};
7069

7170

7271
TypeScript after transpile module:
7372

7473
const key = keyframes \`to{transform:rotate(360deg);}\`;
7574
const color = css \`color:\${theColor};\`;
76-
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}
77-
}\`;
75+
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}\\n}\`;
7876
export {};
7977

8078

src/__tests__/baselines/minification-only/minify-single-line-comments-with-interpolations.ts.baseline

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,9 @@ TypeScript after transform:
111111
const Test4 = styled.div \`width:100%;//\${'red'}\`;
112112
const Test5 = styled.div \`width:100%;//\${'red'}\${'blue'}\`;
113113
const Test6 = styled.div \`background:url("https://google.com");width:100%;\${'green'}//\${'red'}\${'blue'}\`;
114-
const Test7 = styled.div \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}
115-
height:\${p => p.props.height};\`;
114+
const Test7 = styled.div \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}\\nheight:\${p => p.props.height};\`;
116115
const Test8 = styled.dev \`color:/*\${'red'}*/blue;\`;
117-
const Test9 = styled.dev \`color://\${'red'}
118-
blue\`;
116+
const Test9 = styled.dev \`color://\${'red'}\\nblue\`;
119117
export {};
120118

121119

@@ -127,11 +125,9 @@ TypeScript after transpile module:
127125
const Test4 = styled.div \`width:100%;//\${'red'}\`;
128126
const Test5 = styled.div \`width:100%;//\${'red'}\${'blue'}\`;
129127
const Test6 = styled.div \`background:url("https://google.com");width:100%;\${'green'}//\${'red'}\${'blue'}\`;
130-
const Test7 = styled.div \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}
131-
height:\${p => p.props.height};\`;
128+
const Test7 = styled.div \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}\\nheight:\${p => p.props.height};\`;
132129
const Test8 = styled.dev \`color:/*\${'red'}*/blue;\`;
133-
const Test9 = styled.dev \`color://\${'red'}
134-
blue\`;
130+
const Test9 = styled.dev \`color://\${'red'}\\nblue\`;
135131
export {};
136132

137133

src/__tests__/baselines/minification/minify-css-in-helpers.ts.baseline

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,15 @@ TypeScript after transform:
6464
declare const theColor: any;
6565
const key = keyframes \`to{transform:rotate(360deg);}\`;
6666
const color = css \`color:\${theColor};\`;
67-
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}
68-
}\`;
67+
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}\\n}\`;
6968
export {};
7069

7170

7271
TypeScript after transpile module:
7372

7473
const key = keyframes \`to{transform:rotate(360deg);}\`;
7574
const color = css \`color:\${theColor};\`;
76-
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}
77-
}\`;
75+
const MyRedBody = createGlobalStyle \`body{background-color:red;\${color}//\${color}\\n}\`;
7876
export {};
7977

8078

src/__tests__/baselines/minification/minify-single-line-comments-with-interpolations.ts.baseline

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,9 @@ TypeScript after transform:
111111
const Test4 = styled.div.withConfig({ displayName: "Test4" }) \`width:100%;//\${'red'}\`;
112112
const Test5 = styled.div.withConfig({ displayName: "Test5" }) \`width:100%;//\${'red'}\${'blue'}\`;
113113
const Test6 = styled.div.withConfig({ displayName: "Test6" }) \`background:url("https://google.com");width:100%;\${'green'}//\${'red'}\${'blue'}\`;
114-
const Test7 = styled.div.withConfig({ displayName: "Test7" }) \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}
115-
height:\${p => p.props.height};\`;
114+
const Test7 = styled.div.withConfig({ displayName: "Test7" }) \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}\\nheight:\${p => p.props.height};\`;
116115
const Test8 = styled.dev.withConfig({ displayName: "Test8" }) \`color:/*\${'red'}*/blue;\`;
117-
const Test9 = styled.dev.withConfig({ displayName: "Test9" }) \`color://\${'red'}
118-
blue\`;
116+
const Test9 = styled.dev.withConfig({ displayName: "Test9" }) \`color://\${'red'}\\nblue\`;
119117
export {};
120118

121119

@@ -127,11 +125,9 @@ TypeScript after transpile module:
127125
const Test4 = styled.div.withConfig({ displayName: "Test4" }) \`width:100%;//\${'red'}\`;
128126
const Test5 = styled.div.withConfig({ displayName: "Test5" }) \`width:100%;//\${'red'}\${'blue'}\`;
129127
const Test6 = styled.div.withConfig({ displayName: "Test6" }) \`background:url("https://google.com");width:100%;\${'green'}//\${'red'}\${'blue'}\`;
130-
const Test7 = styled.div.withConfig({ displayName: "Test7" }) \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}
131-
height:\${p => p.props.height};\`;
128+
const Test7 = styled.div.withConfig({ displayName: "Test7" }) \`background:url("https://google.com");width:\${p => p.props.width};\${'green'}//\${'red'}\${'blue'}\\nheight:\${p => p.props.height};\`;
132129
const Test8 = styled.dev.withConfig({ displayName: "Test8" }) \`color:/*\${'red'}*/blue;\`;
133-
const Test9 = styled.dev.withConfig({ displayName: "Test9" }) \`color://\${'red'}
134-
blue\`;
130+
const Test9 = styled.dev.withConfig({ displayName: "Test9" }) \`color://\${'red'}\\nblue\`;
135131
export {};
136132

137133

src/createTransformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export function createTransformer({
261261
);
262262

263263
const updateExportAssignmentExpression = (node: ts.ExportAssignment, expression: ts.Expression) =>
264-
context.factory.updateExportAssignment(node, node.decorators, node.modifiers, expression);
264+
context.factory.updateExportAssignment(node, node.modifiers, expression);
265265

266266
const transformNode = (node: ts.Node) =>
267267
isVariableDeclaration(node) && node.initializer
@@ -282,7 +282,7 @@ export function createTransformer({
282282

283283
const visitNode: ts.Visitor = (node) => transformNode(node) || ts.visitEachChild(node, visitNode, context);
284284

285-
return ts.visitNode(sourceFile, visitNode);
285+
return ts.visitNode(sourceFile, visitNode) as ts.SourceFile;
286286
};
287287
};
288288

0 commit comments

Comments
 (0)