Skip to content

Commit 60191f3

Browse files
Update numeric operator detection to check all node types (#7487)
Co-Authored-By: Aaron Casanova <32409546+aaronccasanova@users.noreply.github.com> ### WHAT is this pull request doing? <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> Updating numeric operator logic to detect `/` on all node types (as opposed to just word nodes). Co-authored-by: Aaron Casanova <32409546+aaronccasanova@users.noreply.github.com>
1 parent 8194e17 commit 60191f3

File tree

8 files changed

+49
-34
lines changed

8 files changed

+49
-34
lines changed

.changeset/itchy-foxes-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris-migrator': patch
3+
---
4+
5+
Update numeric operator detection to check all node types

polaris-migrator/src/migrations/replace-border-declarations/replace-border-declarations.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ const plugin = (options: PluginOptions = {}): Plugin => {
7979

8080
function handleBorderProps() {
8181
parsedValue.walk((node) => {
82+
if (isNumericOperator(node)) {
83+
hasNumericOperator = true;
84+
return;
85+
}
86+
8287
if (node.type === 'word') {
8388
if (globalValues.has(node.value)) return;
84-
if (isNumericOperator(node)) {
85-
hasNumericOperator = true;
86-
return;
87-
}
8889

8990
const dimension = valueParser.unit(node.value);
9091

@@ -187,12 +188,13 @@ const plugin = (options: PluginOptions = {}): Plugin => {
187188

188189
function handleBorderRadiusProps() {
189190
parsedValue.walk((node) => {
191+
if (isNumericOperator(node)) {
192+
hasNumericOperator = true;
193+
return;
194+
}
195+
190196
if (node.type === 'word') {
191197
if (globalValues.has(node.value)) return;
192-
if (isNumericOperator(node)) {
193-
hasNumericOperator = true;
194-
return;
195-
}
196198

197199
const dimension = valueParser.unit(node.value);
198200

polaris-migrator/src/migrations/replace-border-declarations/tests/replace-border-declarations.input.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898

9999
/* Comment */
100100
border-radius: 1px;
101+
border-radius: 20px / 50%;
101102

102103
/* --- REM FUNCTION --- */
103104

polaris-migrator/src/migrations/replace-border-declarations/tests/replace-border-declarations.output.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@
124124
// polaris-migrator: Unable to migrate the following expression. Please upgrade manually.
125125
// border-radius: 1px;
126126
border-radius: 1px;
127+
// polaris-migrator: Unable to migrate the following expression. Please upgrade manually.
128+
// border-radius: var(--p-border-radius-5) / 50%;
129+
border-radius: 20px / 50%;
127130

128131
/* --- REM FUNCTION --- */
129132

polaris-migrator/src/migrations/replace-border-declarations/tests/with-namespace.input.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102

103103
/* Comment */
104104
border-radius: 1px;
105+
border-radius: 20px / 50%;
105106

106107
/* --- REM FUNCTION --- */
107108

polaris-migrator/src/migrations/replace-border-declarations/tests/with-namespace.output.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@
128128
// polaris-migrator: Unable to migrate the following expression. Please upgrade manually.
129129
// border-radius: 1px;
130130
border-radius: 1px;
131+
// polaris-migrator: Unable to migrate the following expression. Please upgrade manually.
132+
// border-radius: var(--p-border-radius-5) / 50%;
133+
border-radius: 20px / 50%;
131134

132135
/* --- REM FUNCTION --- */
133136

polaris-migrator/src/migrations/replace-spacing-lengths/replace-spacing-lengths.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ const plugin = (options: PluginOptions = {}): Plugin => {
7070

7171
function handleSpaceProps() {
7272
parsedValue.walk((node) => {
73+
if (isNumericOperator(node)) {
74+
hasNumericOperator = true;
75+
return;
76+
}
77+
7378
if (node.type === 'word') {
7479
if (globalValues.has(node.value)) return;
75-
if (isNumericOperator(node)) {
76-
hasNumericOperator = true;
77-
return;
78-
}
7980

8081
const dimension = valueParser.unit(node.value);
8182

polaris-migrator/src/migrations/replace-typography-declarations/replace-typography-declarations.ts

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ const plugin = (options: PluginOptions = {}): Plugin => {
8484

8585
function handleFontFamily() {
8686
parsedValue.walk((node) => {
87-
if (node.type === 'word') {
88-
if (isNumericOperator(node)) {
89-
hasNumericOperator = true;
90-
// eslint-disable-next-line no-useless-return
91-
return;
92-
}
93-
} else if (node.type === 'function') {
87+
if (isNumericOperator(node)) {
88+
hasNumericOperator = true;
89+
return;
90+
}
91+
92+
if (node.type === 'function') {
9493
if (isSassFunction(namespacedFontFamily, node)) {
9594
targets.push({replaced: false});
9695

@@ -126,14 +125,14 @@ const plugin = (options: PluginOptions = {}): Plugin => {
126125

127126
function handleFontSize() {
128127
parsedValue.walk((node) => {
128+
if (isNumericOperator(node)) {
129+
hasNumericOperator = true;
130+
return;
131+
}
132+
129133
if (node.type === 'word') {
130134
if (globalValues.has(node.value)) return;
131135

132-
if (isNumericOperator(node)) {
133-
hasNumericOperator = true;
134-
return;
135-
}
136-
137136
const dimension = valueParser.unit(node.value);
138137

139138
if (!isTransformableLength(dimension)) return;
@@ -225,14 +224,14 @@ const plugin = (options: PluginOptions = {}): Plugin => {
225224
parsedValue.walk((node) => {
226225
if (node.type === 'function') return StopWalkingFunctionNodes;
227226

227+
if (isNumericOperator(node)) {
228+
hasNumericOperator = true;
229+
return;
230+
}
231+
228232
if (node.type === 'word') {
229233
if (globalValues.has(node.value)) return;
230234

231-
if (isNumericOperator(node)) {
232-
hasNumericOperator = true;
233-
return;
234-
}
235-
236235
targets.push({replaced: false});
237236

238237
const fontWeight = node.value;
@@ -248,14 +247,14 @@ const plugin = (options: PluginOptions = {}): Plugin => {
248247

249248
function handleFontLineHeight() {
250249
parsedValue.walk((node) => {
250+
if (isNumericOperator(node)) {
251+
hasNumericOperator = true;
252+
return;
253+
}
254+
251255
if (node.type === 'word') {
252256
if (globalValues.has(node.value)) return;
253257

254-
if (isNumericOperator(node)) {
255-
hasNumericOperator = true;
256-
return;
257-
}
258-
259258
targets.push({replaced: false});
260259

261260
const lineHeighInPx = toTransformablePx(node.value);

0 commit comments

Comments
 (0)