@atlaskit/section-message 6.5.2 → 6.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,11 +7,11 @@ const transformer = createTransformer([mapActionsProp]);
7
7
  const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
8
8
 
9
9
  describe('map actions prop to components', () => {
10
- describe('for default & named imports', () => {
11
- defineInlineTest(
12
- { default: transformer, parser: 'tsx' },
13
- {},
14
- `
10
+ describe('for default & named imports', () => {
11
+ defineInlineTest(
12
+ { default: transformer, parser: 'tsx' },
13
+ {},
14
+ `
15
15
  import React from "react";
16
16
  import SectionMessage from "@atlaskit/section-message";
17
17
 
@@ -28,7 +28,7 @@ describe('map actions prop to components', () => {
28
28
  />
29
29
  );
30
30
  `,
31
- `
31
+ `
32
32
  import React from "react";
33
33
  import SectionMessage, { SectionMessageAction } from "@atlaskit/section-message";
34
34
 
@@ -50,13 +50,13 @@ describe('map actions prop to components', () => {
50
50
  />
51
51
  );
52
52
  `,
53
- 'should map actions correctly',
54
- );
53
+ 'should map actions correctly',
54
+ );
55
55
 
56
- defineInlineTest(
57
- { default: transformer, parser: 'tsx' },
58
- {},
59
- `
56
+ defineInlineTest(
57
+ { default: transformer, parser: 'tsx' },
58
+ {},
59
+ `
60
60
  import React from "react";
61
61
  import SectionMessage, { SectionMessageProps } from "@atlaskit/section-message";
62
62
 
@@ -71,7 +71,7 @@ describe('map actions prop to components', () => {
71
71
  />
72
72
  );
73
73
  `,
74
- `
74
+ `
75
75
  import React from "react";
76
76
  import SectionMessage, { SectionMessageProps, SectionMessageAction } from "@atlaskit/section-message";
77
77
 
@@ -91,13 +91,13 @@ describe('map actions prop to components', () => {
91
91
  />
92
92
  );
93
93
  `,
94
- 'should map actions correctly if defined inline',
95
- );
94
+ 'should map actions correctly if defined inline',
95
+ );
96
96
 
97
- defineInlineTest(
98
- { default: transformer, parser: 'tsx' },
99
- {},
100
- `
97
+ defineInlineTest(
98
+ { default: transformer, parser: 'tsx' },
99
+ {},
100
+ `
101
101
  import React from "react";
102
102
  import SectionMessage, { SectionMessageProps } from "@atlaskit/section-message";
103
103
 
@@ -118,7 +118,7 @@ describe('map actions prop to components', () => {
118
118
 
119
119
  export default Component;
120
120
  `,
121
- `
121
+ `
122
122
  import React from "react";
123
123
  import SectionMessage, { SectionMessageProps, SectionMessageAction as AtlaskitSectionMessageAction } from "@atlaskit/section-message";
124
124
 
@@ -144,13 +144,13 @@ describe('map actions prop to components', () => {
144
144
 
145
145
  export default Component;
146
146
  `,
147
- 'should map actions correctly - with alias',
148
- );
147
+ 'should map actions correctly - with alias',
148
+ );
149
149
 
150
- defineInlineTest(
151
- { default: transformer, parser: 'tsx' },
152
- {},
153
- `
150
+ defineInlineTest(
151
+ { default: transformer, parser: 'tsx' },
152
+ {},
153
+ `
154
154
  import React from "react";
155
155
  import SectionMessage from "@atlaskit/section-message";
156
156
 
@@ -165,7 +165,7 @@ describe('map actions prop to components', () => {
165
165
  <SectionMessage />
166
166
  );
167
167
  `,
168
- `
168
+ `
169
169
  import React from "react";
170
170
  import SectionMessage from "@atlaskit/section-message";
171
171
 
@@ -180,13 +180,13 @@ describe('map actions prop to components', () => {
180
180
  <SectionMessage />
181
181
  );
182
182
  `,
183
- 'should only map when "actions" prop is defined',
184
- );
183
+ 'should only map when "actions" prop is defined',
184
+ );
185
185
 
186
- defineInlineTest(
187
- { default: transformer, parser: 'tsx' },
188
- {},
189
- `
186
+ defineInlineTest(
187
+ { default: transformer, parser: 'tsx' },
188
+ {},
189
+ `
190
190
  import React from "react";
191
191
  import SectionMessage from "@atlaskit/section-message";
192
192
 
@@ -203,7 +203,7 @@ describe('map actions prop to components', () => {
203
203
  />
204
204
  );
205
205
  `,
206
- `
206
+ `
207
207
  import React from "react";
208
208
  import SectionMessage, { SectionMessageAction } from "@atlaskit/section-message";
209
209
 
@@ -225,13 +225,13 @@ describe('map actions prop to components', () => {
225
225
  />
226
226
  );
227
227
  `,
228
- 'should map actions correctly if result coming from a function call',
229
- );
228
+ 'should map actions correctly if result coming from a function call',
229
+ );
230
230
 
231
- defineInlineTest(
232
- { default: transformer, parser: 'tsx' },
233
- {},
234
- `
231
+ defineInlineTest(
232
+ { default: transformer, parser: 'tsx' },
233
+ {},
234
+ `
235
235
  import React from "react";
236
236
  import SectionMessage, { SectionMessageProps } from "@atlaskit/section-message";
237
237
 
@@ -246,7 +246,7 @@ describe('map actions prop to components', () => {
246
246
  />
247
247
  );
248
248
  `,
249
- `
249
+ `
250
250
  import React from "react";
251
251
  import SectionMessage, { SectionMessageProps, SectionMessageAction } from "@atlaskit/section-message";
252
252
 
@@ -266,13 +266,13 @@ describe('map actions prop to components', () => {
266
266
  />
267
267
  );
268
268
  `,
269
- 'should map actions correctly if defined inline based on a condition',
270
- );
269
+ 'should map actions correctly if defined inline based on a condition',
270
+ );
271
271
 
272
- defineInlineTest(
273
- { default: transformer, parser: 'tsx' },
274
- {},
275
- `
272
+ defineInlineTest(
273
+ { default: transformer, parser: 'tsx' },
274
+ {},
275
+ `
276
276
  import React from "react";
277
277
  import SectionMessage, { SectionMessageProps } from "@atlaskit/section-message";
278
278
 
@@ -290,7 +290,7 @@ describe('map actions prop to components', () => {
290
290
  />
291
291
  );
292
292
  `,
293
- `
293
+ `
294
294
  import React from "react";
295
295
  import SectionMessage, { SectionMessageProps, SectionMessageAction } from "@atlaskit/section-message";
296
296
 
@@ -311,13 +311,13 @@ describe('map actions prop to components', () => {
311
311
  ) => <SectionMessageAction linkComponent={CustomLink} {...restAction}>{text}</SectionMessageAction>)} />
312
312
  );
313
313
  `,
314
- 'should move "linkComponent" from "SectionMessage" to "SectionMessageAction" if pointing to a component',
315
- );
314
+ 'should move "linkComponent" from "SectionMessage" to "SectionMessageAction" if pointing to a component',
315
+ );
316
316
 
317
- defineInlineTest(
318
- { default: transformer, parser: 'tsx' },
319
- {},
320
- `
317
+ defineInlineTest(
318
+ { default: transformer, parser: 'tsx' },
319
+ {},
320
+ `
321
321
  import React from "react";
322
322
  import SectionMessage, { SectionMessageProps } from "@atlaskit/section-message";
323
323
 
@@ -333,7 +333,7 @@ describe('map actions prop to components', () => {
333
333
  />
334
334
  );
335
335
  `,
336
- `
336
+ `
337
337
  import React from "react";
338
338
  import SectionMessage, { SectionMessageProps, SectionMessageAction } from "@atlaskit/section-message";
339
339
 
@@ -352,13 +352,13 @@ describe('map actions prop to components', () => {
352
352
  ) => <SectionMessageAction linkComponent={() => <a></a>} {...restAction}>{text}</SectionMessageAction>)} />
353
353
  );
354
354
  `,
355
- 'should move "linkComponent" from "SectionMessage" to "SectionMessageAction" if component is defined inline',
356
- );
355
+ 'should move "linkComponent" from "SectionMessage" to "SectionMessageAction" if component is defined inline',
356
+ );
357
357
 
358
- defineInlineTest(
359
- { default: transformer, parser: 'tsx' },
360
- {},
361
- `
358
+ defineInlineTest(
359
+ { default: transformer, parser: 'tsx' },
360
+ {},
361
+ `
362
362
  import React from "react";
363
363
  import SectionMessage, { SectionMessageProps } from "@atlaskit/section-message";
364
364
 
@@ -370,7 +370,7 @@ describe('map actions prop to components', () => {
370
370
  />
371
371
  );
372
372
  `,
373
- `
373
+ `
374
374
  import React from "react";
375
375
  import SectionMessage, { SectionMessageProps } from "@atlaskit/section-message";
376
376
 
@@ -380,15 +380,15 @@ describe('map actions prop to components', () => {
380
380
  <SectionMessage />
381
381
  );
382
382
  `,
383
- 'should remove "linkComponent" from "SectionMessage" if no actions are present',
384
- );
385
- });
386
-
387
- describe('for dynamic imports', () => {
388
- defineInlineTest(
389
- { default: transformer, parser: 'tsx' },
390
- {},
391
- `
383
+ 'should remove "linkComponent" from "SectionMessage" if no actions are present',
384
+ );
385
+ });
386
+
387
+ describe('for dynamic imports', () => {
388
+ defineInlineTest(
389
+ { default: transformer, parser: 'tsx' },
390
+ {},
391
+ `
392
392
  import React from "react";
393
393
 
394
394
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -406,7 +406,7 @@ describe('map actions prop to components', () => {
406
406
  />
407
407
  );
408
408
  `,
409
- `
409
+ `
410
410
  import React from "react";
411
411
 
412
412
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -432,13 +432,13 @@ describe('map actions prop to components', () => {
432
432
  />
433
433
  );
434
434
  `,
435
- 'should map actions correctly',
436
- );
435
+ 'should map actions correctly',
436
+ );
437
437
 
438
- defineInlineTest(
439
- { default: transformer, parser: 'tsx' },
440
- {},
441
- `
438
+ defineInlineTest(
439
+ { default: transformer, parser: 'tsx' },
440
+ {},
441
+ `
442
442
  import React from "react";
443
443
 
444
444
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -454,7 +454,7 @@ describe('map actions prop to components', () => {
454
454
  />
455
455
  );
456
456
  `,
457
- `
457
+ `
458
458
  import React from "react";
459
459
 
460
460
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -478,13 +478,13 @@ describe('map actions prop to components', () => {
478
478
  />
479
479
  );
480
480
  `,
481
- 'should map actions correctly if defined inline',
482
- );
481
+ 'should map actions correctly if defined inline',
482
+ );
483
483
 
484
- defineInlineTest(
485
- { default: transformer, parser: 'tsx' },
486
- {},
487
- `
484
+ defineInlineTest(
485
+ { default: transformer, parser: 'tsx' },
486
+ {},
487
+ `
488
488
  import React from "react";
489
489
 
490
490
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -506,7 +506,7 @@ describe('map actions prop to components', () => {
506
506
 
507
507
  export default Component;
508
508
  `,
509
- `
509
+ `
510
510
  import React from "react";
511
511
 
512
512
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -536,13 +536,13 @@ describe('map actions prop to components', () => {
536
536
 
537
537
  export default Component;
538
538
  `,
539
- 'should map actions correctly - with alias',
540
- );
539
+ 'should map actions correctly - with alias',
540
+ );
541
541
 
542
- defineInlineTest(
543
- { default: transformer, parser: 'tsx' },
544
- {},
545
- `
542
+ defineInlineTest(
543
+ { default: transformer, parser: 'tsx' },
544
+ {},
545
+ `
546
546
  import React from "react";
547
547
 
548
548
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -558,7 +558,7 @@ describe('map actions prop to components', () => {
558
558
  <SectionMessageDynamicImport />
559
559
  );
560
560
  `,
561
- `
561
+ `
562
562
  import React from "react";
563
563
 
564
564
  const SectionMessageDynamicImport = React.lazy(() => import('@atlaskit/section-message'));
@@ -574,7 +574,7 @@ describe('map actions prop to components', () => {
574
574
  <SectionMessageDynamicImport />
575
575
  );
576
576
  `,
577
- 'should only map when "actions" prop is defined',
578
- );
579
- });
577
+ 'should only map when "actions" prop is defined',
578
+ );
579
+ });
580
580
  });
@@ -1,121 +1,101 @@
1
1
  import {
2
- type ASTPath,
3
- type default as core,
4
- type JSXAttribute,
5
- type JSXElement,
2
+ type ASTPath,
3
+ type default as core,
4
+ type JSXAttribute,
5
+ type JSXElement,
6
6
  } from 'jscodeshift';
7
7
  import { type Collection } from 'jscodeshift/src/Collection';
8
8
 
9
9
  import {
10
- addCommentBefore,
11
- getDefaultSpecifier,
12
- getJSXAttributesByName,
10
+ addCommentBefore,
11
+ getDefaultSpecifier,
12
+ getJSXAttributesByName,
13
13
  } from '@atlaskit/codemod-utils';
14
14
 
15
15
  import {
16
- APPEARANCE_OLD_TO_NEW_MAPPING,
17
- APPEARANCE_PROP_NAME,
18
- SECTION_MESSAGE_PACKAGE_NAME,
16
+ APPEARANCE_OLD_TO_NEW_MAPPING,
17
+ APPEARANCE_PROP_NAME,
18
+ SECTION_MESSAGE_PACKAGE_NAME,
19
19
  } from './constants';
20
20
 
21
- export const changeAppearanceProp = (
22
- j: core.JSCodeshift,
23
- source: Collection<Node>,
24
- ) => {
25
- const defaultSpecifier = getDefaultSpecifier(
26
- j,
27
- source,
28
- SECTION_MESSAGE_PACKAGE_NAME,
29
- );
21
+ export const changeAppearanceProp = (j: core.JSCodeshift, source: Collection<Node>) => {
22
+ const defaultSpecifier = getDefaultSpecifier(j, source, SECTION_MESSAGE_PACKAGE_NAME);
30
23
 
31
- if (!defaultSpecifier) {
32
- return;
33
- }
24
+ if (!defaultSpecifier) {
25
+ return;
26
+ }
34
27
 
35
- source
36
- .findJSXElements(defaultSpecifier)
37
- .forEach((element: ASTPath<JSXElement>) => {
38
- getJSXAttributesByName(j, element, APPEARANCE_PROP_NAME).forEach(
39
- (attribute: ASTPath<JSXAttribute>) => {
40
- const { value } = attribute.node;
41
- if (!value) {
42
- return;
43
- }
44
- // appearance prop can be provided in multiple ways. Handling different cases here
45
- switch (value.type) {
46
- // case when object value is provided
47
- case 'JSXExpressionContainer':
48
- const { expression } = value;
28
+ source.findJSXElements(defaultSpecifier).forEach((element: ASTPath<JSXElement>) => {
29
+ getJSXAttributesByName(j, element, APPEARANCE_PROP_NAME).forEach(
30
+ (attribute: ASTPath<JSXAttribute>) => {
31
+ const { value } = attribute.node;
32
+ if (!value) {
33
+ return;
34
+ }
35
+ // appearance prop can be provided in multiple ways. Handling different cases here
36
+ switch (value.type) {
37
+ // case when object value is provided
38
+ case 'JSXExpressionContainer':
39
+ const { expression } = value;
49
40
 
50
- // case when string is provided inside JSX expression
51
- // e.g.: <SectionMessage appearance={"information"} />
52
- if (expression.type === 'StringLiteral') {
53
- replaceAppearanceStringValue(j, attribute, expression.value);
54
- }
55
- // case when a variable is provided as value
56
- // e.g.: <SectionMessage appearance={someVariable} />
57
- else if (expression.type !== 'JSXEmptyExpression') {
58
- const mappingValue = j.memberExpression(
59
- j.objectExpression(
60
- Object.entries(APPEARANCE_OLD_TO_NEW_MAPPING).map(
61
- ([key, value]) =>
62
- j.objectProperty(
63
- j.identifier(key),
64
- j.stringLiteral(value),
65
- ),
66
- ),
67
- ),
68
- expression,
69
- );
70
- mappingValue.computed = true;
41
+ // case when string is provided inside JSX expression
42
+ // e.g.: <SectionMessage appearance={"information"} />
43
+ if (expression.type === 'StringLiteral') {
44
+ replaceAppearanceStringValue(j, attribute, expression.value);
45
+ }
46
+ // case when a variable is provided as value
47
+ // e.g.: <SectionMessage appearance={someVariable} />
48
+ else if (expression.type !== 'JSXEmptyExpression') {
49
+ const mappingValue = j.memberExpression(
50
+ j.objectExpression(
51
+ Object.entries(APPEARANCE_OLD_TO_NEW_MAPPING).map(([key, value]) =>
52
+ j.objectProperty(j.identifier(key), j.stringLiteral(value)),
53
+ ),
54
+ ),
55
+ expression,
56
+ );
57
+ mappingValue.computed = true;
71
58
 
72
- const propValue = j.logicalExpression(
73
- '||',
74
- mappingValue,
75
- expression,
76
- );
59
+ const propValue = j.logicalExpression('||', mappingValue, expression);
77
60
 
78
- j(attribute).replaceWith(
79
- j.jsxAttribute(
80
- j.jsxIdentifier(APPEARANCE_PROP_NAME),
81
- j.jsxExpressionContainer(propValue),
82
- ),
83
- );
61
+ j(attribute).replaceWith(
62
+ j.jsxAttribute(
63
+ j.jsxIdentifier(APPEARANCE_PROP_NAME),
64
+ j.jsxExpressionContainer(propValue),
65
+ ),
66
+ );
84
67
 
85
- addCommentBefore(
86
- j,
87
- j(attribute),
88
- `We have added this temporary appearance mapping here to make things work. Feel free to change it accordingly. We have also added @ts-ignore for typescript files.
68
+ addCommentBefore(
69
+ j,
70
+ j(attribute),
71
+ `We have added this temporary appearance mapping here to make things work. Feel free to change it accordingly. We have also added @ts-ignore for typescript files.
89
72
  @ts-ignore
90
73
  `,
91
- );
92
- }
74
+ );
75
+ }
93
76
 
94
- break;
77
+ break;
95
78
 
96
- // case when string value is provided
97
- // e.g.: <SectionMessage appearance="information" />
98
- case 'StringLiteral':
99
- replaceAppearanceStringValue(j, attribute, value.value);
100
- }
101
- },
102
- );
103
- });
79
+ // case when string value is provided
80
+ // e.g.: <SectionMessage appearance="information" />
81
+ case 'StringLiteral':
82
+ replaceAppearanceStringValue(j, attribute, value.value);
83
+ }
84
+ },
85
+ );
86
+ });
104
87
  };
105
88
 
106
89
  const replaceAppearanceStringValue = (
107
- j: core.JSCodeshift,
108
- attribute: core.ASTPath<JSXAttribute>,
109
- propValue: string,
90
+ j: core.JSCodeshift,
91
+ attribute: core.ASTPath<JSXAttribute>,
92
+ propValue: string,
110
93
  ) => {
111
- const newPropValue: string = APPEARANCE_OLD_TO_NEW_MAPPING[propValue];
94
+ const newPropValue: string = APPEARANCE_OLD_TO_NEW_MAPPING[propValue];
112
95
 
113
- if (newPropValue) {
114
- j(attribute).replaceWith(
115
- j.jsxAttribute(
116
- j.jsxIdentifier(APPEARANCE_PROP_NAME),
117
- j.stringLiteral(newPropValue),
118
- ),
119
- );
120
- }
96
+ if (newPropValue) {
97
+ j(attribute).replaceWith(
98
+ j.jsxAttribute(j.jsxIdentifier(APPEARANCE_PROP_NAME), j.stringLiteral(newPropValue)),
99
+ );
100
+ }
121
101
  };
@@ -1,11 +1,11 @@
1
1
  export const SECTION_MESSAGE_PACKAGE_NAME = '@atlaskit/section-message';
2
2
  export const APPEARANCE_PROP_NAME = 'appearance';
3
3
  export const APPEARANCE_OLD_TO_NEW_MAPPING: {
4
- [index: string]: string;
4
+ [index: string]: string;
5
5
  } = {
6
- info: 'information',
7
- confirmation: 'success',
8
- change: 'discovery',
6
+ info: 'information',
7
+ confirmation: 'success',
8
+ change: 'discovery',
9
9
  };
10
10
  export const SECTION_MESSAGE_ACTION_PACKAGE_NAME = `${SECTION_MESSAGE_PACKAGE_NAME}/section-message-action`;
11
11
  export const SECTION_MESSAGE_ACTION_COMPONENT_NAME = 'SectionMessageAction';