rollup-plugin-react-scoped-css 0.4.0 → 0.5.2
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/.github/workflows/pull-request.yml +19 -0
- package/.github/workflows/release.yml +30 -0
- package/.releaserc +13 -0
- package/README.md +25 -2
- package/dist/ast-iterator.d.ts +1 -0
- package/dist/ast-iterator.js +114 -0
- package/dist/ast-transformer.d.ts +1 -0
- package/dist/ast-transformer.js +50 -0
- package/dist/ast.utils.d.ts +4 -0
- package/dist/ast.utils.js +49 -108
- package/dist/index.js +12 -12
- package/dist/parsers/classic-parser.d.ts +7 -0
- package/dist/parsers/classic-parser.js +95 -0
- package/dist/parsers/jsx-parser.model.d.ts +9 -0
- package/dist/parsers/jsx-parser.model.js +8 -0
- package/dist/parsers/new-parser.d.ts +7 -0
- package/dist/parsers/new-parser.js +94 -0
- package/package.json +9 -3
- package/src/__mocks__/{compiled-jsx-with-attr.js → classic-compiled-jsx-with-attr.js} +0 -0
- package/src/__mocks__/{compiled-jsx.js → classic-compiled-jsx.js} +0 -0
- package/src/__mocks__/new-compiled-jsx-with-attr.js +101 -0
- package/src/__mocks__/new-compiled-jsx.js +64 -0
- package/src/__mocks__/sample-code-file.js +4 -0
- package/src/ast-iterator.spec.ts +19 -0
- package/src/ast-iterator.ts +27 -0
- package/src/ast-transformer.spec.ts +20 -0
- package/src/ast-transformer.ts +24 -0
- package/src/ast.utils.spec.ts +36 -12
- package/src/ast.utils.ts +36 -95
- package/src/index.ts +0 -1
- package/src/parsers/classic-parser.ts +58 -0
- package/src/parsers/jsx-parser.model.ts +10 -0
- package/src/parsers/new-parser.ts +58 -0
- package/tsconfig.json +2 -1
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { JsxParser } from "./jsx-parser.model";
|
|
2
|
+
|
|
3
|
+
export class ClassicJsxParser implements JsxParser {
|
|
4
|
+
isNodeReactFragment(node: any) {
|
|
5
|
+
return node?.arguments?.[0]?.object?.name === "React" &&
|
|
6
|
+
node?.arguments?.[0]?.property?.name === "Fragment"
|
|
7
|
+
}
|
|
8
|
+
isNodeReactElement(node: any) {
|
|
9
|
+
return node?.type === 'CallExpression' &&
|
|
10
|
+
node?.callee?.object?.name === 'React' &&
|
|
11
|
+
node?.callee?.property?.name === 'createElement'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public extendNodeWithAttributes(node: any, attr: string) {
|
|
15
|
+
const arg = node?.arguments?.[1]
|
|
16
|
+
return {
|
|
17
|
+
...node,
|
|
18
|
+
arguments: node?.arguments.map((v: any, i: number) => {
|
|
19
|
+
if (i === 1) {
|
|
20
|
+
if (v.type === 'ObjectExpression') {
|
|
21
|
+
return {
|
|
22
|
+
...v,
|
|
23
|
+
properties: [
|
|
24
|
+
...arg.properties,
|
|
25
|
+
this.createAttributeNode(attr)
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
return {
|
|
30
|
+
type: 'ObjectExpression',
|
|
31
|
+
properties: [this.createAttributeNode(attr)]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return v
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private createAttributeNode(attr: string) {
|
|
41
|
+
return {
|
|
42
|
+
type: 'Property',
|
|
43
|
+
method: false,
|
|
44
|
+
shorthand: false,
|
|
45
|
+
computed: false,
|
|
46
|
+
key: {
|
|
47
|
+
type: 'Identifier',
|
|
48
|
+
name: `"${attr}"`
|
|
49
|
+
},
|
|
50
|
+
value: {
|
|
51
|
+
type: 'Literal',
|
|
52
|
+
value: true,
|
|
53
|
+
raw: "true"
|
|
54
|
+
},
|
|
55
|
+
kind: 'init'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface JsxParser {
|
|
2
|
+
isNodeReactElement: (node: any) => boolean
|
|
3
|
+
isNodeReactFragment: (node: any) => boolean
|
|
4
|
+
extendNodeWithAttributes: (node: any, attr: string) => any
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum ParserImplementations {
|
|
8
|
+
new = 'new',
|
|
9
|
+
classic = 'classic'
|
|
10
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { JsxParser } from "./jsx-parser.model";
|
|
2
|
+
|
|
3
|
+
export class NewJsxParser implements JsxParser {
|
|
4
|
+
isNodeReactFragment(node: any) {
|
|
5
|
+
return node.arguments?.[0]?.type === "Identifier" &&
|
|
6
|
+
['_Fragment', 'Fragment'].includes(node.arguments?.[0]?.name)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
isNodeReactElement(node: any) {
|
|
10
|
+
return node?.type === 'CallExpression' &&
|
|
11
|
+
['_jsxDEV', '_jsx', '_jsxs', 'jsxDev', 'jsx', 'jsxs'].includes(node?.callee?.name)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public extendNodeWithAttributes(node: any, attr: string) {
|
|
15
|
+
const arg = node?.arguments?.[1]
|
|
16
|
+
return {
|
|
17
|
+
...node,
|
|
18
|
+
arguments: node?.arguments.map((v: any, i: number) => {
|
|
19
|
+
if (i === 1) {
|
|
20
|
+
if (v.type === 'ObjectExpression') {
|
|
21
|
+
return {
|
|
22
|
+
...v,
|
|
23
|
+
properties: [
|
|
24
|
+
...arg.properties,
|
|
25
|
+
this.createAttributeNode(attr)
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
return {
|
|
30
|
+
type: 'ObjectExpression',
|
|
31
|
+
properties: [this.createAttributeNode(attr)]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return v
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private createAttributeNode(attr: string) {
|
|
41
|
+
return {
|
|
42
|
+
type: 'Property',
|
|
43
|
+
method: false,
|
|
44
|
+
shorthand: false,
|
|
45
|
+
computed: false,
|
|
46
|
+
key: {
|
|
47
|
+
type: 'Identifier',
|
|
48
|
+
name: `"${attr}"`
|
|
49
|
+
},
|
|
50
|
+
value: {
|
|
51
|
+
type: 'Literal',
|
|
52
|
+
value: true,
|
|
53
|
+
raw: "true"
|
|
54
|
+
},
|
|
55
|
+
kind: 'init'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|