@atlaskit/code 15.2.0 → 15.3.0
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.
- package/CHANGELOG.md +653 -645
- package/__perf__/code-block-syntax-highlighting.tsx +4 -1
- package/__perf__/source-code-examples/100-line-example.tsx +52 -40
- package/codemods/13.0.0-remove-unnecessary-code-props.tsx +61 -75
- package/codemods/13.0.0-rename-imports.tsx +214 -251
- package/codemods/14.0.0-lite-mode.tsx +5 -9
- package/codemods/__tests__/13.0.0-remove-unnecessary-code-props.tsx +43 -43
- package/codemods/__tests__/13.0.0-rename-imports.tsx +143 -143
- package/codemods/__tests__/14.0.0-lite-mode/14.0.0-lite-mode.tsx +35 -35
- package/codemods/__tests__/14.0.0-lite-mode/remove-language.tsx +21 -21
- package/codemods/__tests__/14.0.0-lite-mode/text-to-child.tsx +35 -35
- package/codemods/migrations/14.0.0-lite-mode/remove-language.tsx +1 -6
- package/codemods/migrations/14.0.0-lite-mode/text-to-child.tsx +53 -61
- package/codemods/utils/helpers.tsx +161 -201
- package/dist/cjs/bidi-warning/ui/styled.js +7 -0
- package/dist/cjs/code-block.js +8 -1
- package/dist/cjs/code.js +5 -0
- package/dist/cjs/internal/theme/styles.js +3 -2
- package/dist/cjs/syntax-highlighter/types.js +1 -0
- package/dist/es2019/bidi-warning/ui/styled.js +7 -0
- package/dist/es2019/code-block.js +8 -1
- package/dist/es2019/code.js +6 -0
- package/dist/es2019/internal/theme/styles.js +4 -1
- package/dist/es2019/syntax-highlighter/types.js +3 -0
- package/dist/esm/bidi-warning/ui/styled.js +7 -0
- package/dist/esm/code-block.js +8 -1
- package/dist/esm/code.js +6 -0
- package/dist/esm/internal/theme/styles.js +4 -1
- package/dist/esm/syntax-highlighter/types.js +3 -0
- package/dist/types/bidi-warning/ui/index.d.ts +1 -1
- package/dist/types/bidi-warning/ui/styled.d.ts +4 -1
- package/dist/types/code.d.ts +3 -0
- package/dist/types/extract-react-types/code-block.d.ts +16 -16
- package/dist/types/internal/hooks/use-highlight.d.ts +1 -1
- package/dist/types/internal/utils/get-normalized-language.d.ts +1 -1
- package/dist/types/syntax-highlighter/async.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/highlight.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/create-line.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/process/index.d.ts +1 -1
- package/dist/types/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
- package/dist/types/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
- package/dist/types/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
- package/dist/types/syntax-highlighter/types.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/types-ts4.5/bidi-warning/ui/index.d.ts +1 -1
- package/dist/types-ts4.5/bidi-warning/ui/styled.d.ts +4 -1
- package/dist/types-ts4.5/code.d.ts +3 -0
- package/dist/types-ts4.5/extract-react-types/code-block.d.ts +16 -16
- package/dist/types-ts4.5/internal/hooks/use-highlight.d.ts +1 -1
- package/dist/types-ts4.5/internal/utils/get-normalized-language.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/async.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/highlight.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line-element.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/create-line.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/flatten-code-tree.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/get-code-tree.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/get-inline-line-number.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/process/index.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-children.d.ts +2 -2
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/create-element.d.ts +2 -2
- package/dist/types-ts4.5/syntax-highlighter/lib/react-renderer/index.d.ts +1 -1
- package/dist/types-ts4.5/syntax-highlighter/types.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/package.json +108 -110
- package/report.api.md +807 -807
|
@@ -7,10 +7,10 @@ const transformer = createTransformer([textToChild]);
|
|
|
7
7
|
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
|
|
8
8
|
|
|
9
9
|
describe('make the test prop a child', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
defineInlineTest(
|
|
11
|
+
{ default: transformer, parser: 'tsx' },
|
|
12
|
+
{},
|
|
13
|
+
`
|
|
14
14
|
import React from 'react';
|
|
15
15
|
|
|
16
16
|
import { Code } from '@atlaskit/code';
|
|
@@ -25,7 +25,7 @@ describe('make the test prop a child', () => {
|
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
`,
|
|
28
|
-
|
|
28
|
+
`
|
|
29
29
|
import React from 'react';
|
|
30
30
|
|
|
31
31
|
import { Code } from '@atlaskit/code';
|
|
@@ -40,13 +40,13 @@ describe('make the test prop a child', () => {
|
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
`,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
'should make the text prop a child if it is a string',
|
|
44
|
+
);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
defineInlineTest(
|
|
47
|
+
{ default: transformer, parser: 'tsx' },
|
|
48
|
+
{},
|
|
49
|
+
`
|
|
50
50
|
import React from 'react';
|
|
51
51
|
|
|
52
52
|
import { Code } from '@atlaskit/code';
|
|
@@ -63,7 +63,7 @@ describe('make the test prop a child', () => {
|
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
65
|
`,
|
|
66
|
-
|
|
66
|
+
`
|
|
67
67
|
import React from 'react';
|
|
68
68
|
|
|
69
69
|
import { Code } from '@atlaskit/code';
|
|
@@ -80,13 +80,13 @@ describe('make the test prop a child', () => {
|
|
|
80
80
|
);
|
|
81
81
|
}
|
|
82
82
|
`,
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
'should make the text prop a child if it is a variable',
|
|
84
|
+
);
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
defineInlineTest(
|
|
87
|
+
{ default: transformer, parser: 'tsx' },
|
|
88
|
+
{},
|
|
89
|
+
`
|
|
90
90
|
import React from 'react';
|
|
91
91
|
|
|
92
92
|
import { Code } from '@atlaskit/code';
|
|
@@ -101,7 +101,7 @@ describe('make the test prop a child', () => {
|
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
`,
|
|
104
|
-
|
|
104
|
+
`
|
|
105
105
|
import React from 'react';
|
|
106
106
|
|
|
107
107
|
import { Code } from '@atlaskit/code';
|
|
@@ -116,13 +116,13 @@ describe('make the test prop a child', () => {
|
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
`,
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
'should retain other props when converting to children',
|
|
120
|
+
);
|
|
121
121
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
defineInlineTest(
|
|
123
|
+
{ default: transformer, parser: 'tsx' },
|
|
124
|
+
{},
|
|
125
|
+
`
|
|
126
126
|
import React from 'react';
|
|
127
127
|
|
|
128
128
|
import { Code } from '@atlaskit/code';
|
|
@@ -139,7 +139,7 @@ describe('make the test prop a child', () => {
|
|
|
139
139
|
);
|
|
140
140
|
}
|
|
141
141
|
`,
|
|
142
|
-
|
|
142
|
+
`
|
|
143
143
|
import React from 'react';
|
|
144
144
|
|
|
145
145
|
import { Code } from '@atlaskit/code';
|
|
@@ -156,13 +156,13 @@ describe('make the test prop a child', () => {
|
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
158
|
`,
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
'should retain other props that are spread when converting to children',
|
|
160
|
+
);
|
|
161
161
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
defineInlineTest(
|
|
163
|
+
{ default: transformer, parser: 'tsx' },
|
|
164
|
+
{},
|
|
165
|
+
`
|
|
166
166
|
import React from 'react';
|
|
167
167
|
|
|
168
168
|
import { Code } from '@atlaskit/code';
|
|
@@ -180,7 +180,7 @@ describe('make the test prop a child', () => {
|
|
|
180
180
|
);
|
|
181
181
|
}
|
|
182
182
|
`,
|
|
183
|
-
|
|
183
|
+
`
|
|
184
184
|
import React from 'react';
|
|
185
185
|
|
|
186
186
|
import { Code } from '@atlaskit/code';
|
|
@@ -198,6 +198,6 @@ describe('make the test prop a child', () => {
|
|
|
198
198
|
);
|
|
199
199
|
}
|
|
200
200
|
`,
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
'should make the text prop a child with 2 usages',
|
|
202
|
+
);
|
|
203
203
|
});
|
|
@@ -8,11 +8,6 @@ been removed to make \`Code\` lighter, quicker and more composable. If you need
|
|
|
8
8
|
highlighting it is still available in \`CodeBlock\`.
|
|
9
9
|
`;
|
|
10
10
|
|
|
11
|
-
const removeLanguageProp = createRemoveFuncFor(
|
|
12
|
-
'@atlaskit/code',
|
|
13
|
-
'Code',
|
|
14
|
-
'language',
|
|
15
|
-
comment,
|
|
16
|
-
);
|
|
11
|
+
const removeLanguageProp = createRemoveFuncFor('@atlaskit/code', 'Code', 'language', comment);
|
|
17
12
|
|
|
18
13
|
export default removeLanguageProp;
|
|
@@ -1,75 +1,67 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Collection } from 'jscodeshift/src/Collection';
|
|
1
|
+
import type { ASTPath, default as core, JSXAttribute, JSXElement } from 'jscodeshift';
|
|
2
|
+
import { type Collection } from 'jscodeshift/src/Collection';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
getJSXAttributesByName,
|
|
6
|
-
getNamedSpecifier,
|
|
7
|
-
} from '@atlaskit/codemod-utils';
|
|
4
|
+
import { getJSXAttributesByName, getNamedSpecifier } from '@atlaskit/codemod-utils';
|
|
8
5
|
|
|
9
6
|
const textToChild = (j: core.JSCodeshift, source: Collection<Node>) => {
|
|
10
|
-
|
|
7
|
+
const specifier = getNamedSpecifier(j, source, '@atlaskit/code', 'Code');
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (!specifier) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
13
|
+
source.findJSXElements(specifier).forEach((element: ASTPath<JSXElement>) => {
|
|
14
|
+
getJSXAttributesByName(j, element, 'text').forEach((attribute: ASTPath<JSXAttribute>) => {
|
|
15
|
+
const { value } = attribute.node;
|
|
16
|
+
if (!value) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
let codeChild = value;
|
|
21
|
+
switch (value.type) {
|
|
22
|
+
// case when object value is provided
|
|
23
|
+
case 'JSXExpressionContainer':
|
|
24
|
+
const { expression } = value;
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
// case when string is provided inside JSX expression
|
|
27
|
+
// e.g.: text={"rm -rf"}
|
|
28
|
+
if (expression.type === 'StringLiteral') {
|
|
29
|
+
codeChild = j.jsxText(expression.value);
|
|
30
|
+
}
|
|
31
|
+
// case when a variable is provided as value
|
|
32
|
+
// e.g.: text={someVariable}
|
|
33
|
+
else {
|
|
34
|
+
codeChild = j.jsxExpressionContainer(expression);
|
|
35
|
+
}
|
|
40
36
|
|
|
41
|
-
|
|
37
|
+
break;
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
// case when string value is provided
|
|
40
|
+
// e.g.: text="rm -rf"
|
|
41
|
+
case 'StringLiteral':
|
|
42
|
+
codeChild = j.jsxText(value.value);
|
|
43
|
+
}
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
// Remove text prop
|
|
46
|
+
j(attribute).remove();
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
);
|
|
72
|
-
});
|
|
48
|
+
j(element)
|
|
49
|
+
.find(j.JSXOpeningElement)
|
|
50
|
+
.forEach((openingElement) => {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
if (openingElement.value.name.name === specifier) {
|
|
53
|
+
// Create opening and closing tag with the text content as a child
|
|
54
|
+
j(openingElement).replaceWith(
|
|
55
|
+
j.jsxElement(
|
|
56
|
+
j.jsxOpeningElement(j.jsxIdentifier(specifier), openingElement.value.attributes),
|
|
57
|
+
j.jsxClosingElement(j.jsxIdentifier(specifier)),
|
|
58
|
+
[codeChild],
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
73
65
|
};
|
|
74
66
|
|
|
75
67
|
export default textToChild;
|