rollup-plugin-react-scoped-css 0.6.0 → 0.6.1
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/README.md +3 -0
- package/dist/ast-program.d.ts +5 -0
- package/dist/ast-program.js +63 -0
- package/dist/ast.utils.d.ts +32 -5
- package/dist/ast.utils.js +114 -51
- package/dist/index.js +2 -2
- package/dist/parsers/classic-parser.js +27 -52
- package/dist/parsers/new-parser.js +46 -52
- package/package.json +3 -1
- package/.github/workflows/pull-request.yml +0 -20
- package/.github/workflows/release.yml +0 -30
- package/.vscode/settings.json +0 -8
- package/babel.config.js +0 -7
- package/src/__mocks__/classic-compiled-jsx-with-attr.js +0 -37
- package/src/__mocks__/classic-compiled-jsx.js +0 -31
- package/src/__mocks__/new-compiled-jsx-with-attr.js +0 -101
- package/src/__mocks__/new-compiled-jsx.js +0 -64
- package/src/__mocks__/sample-code-file.js +0 -4
- package/src/ast-iterator.spec.ts +0 -22
- package/src/ast-iterator.ts +0 -32
- package/src/ast-transformer.spec.ts +0 -23
- package/src/ast-transformer.ts +0 -28
- package/src/ast.utils.spec.ts +0 -61
- package/src/ast.utils.ts +0 -53
- package/src/index.ts +0 -164
- package/src/parsers/classic-parser.ts +0 -72
- package/src/parsers/jsx-parser.model.ts +0 -10
- package/src/parsers/new-parser.ts +0 -74
package/README.md
CHANGED
|
@@ -27,6 +27,9 @@ export default function Sub() {
|
|
|
27
27
|
```
|
|
28
28
|
And just like that the styles will be scoped to the component.
|
|
29
29
|
|
|
30
|
+
## Limitations
|
|
31
|
+
Due to the way this plugin is working, it will apply the scope to the file and not the component individually... This may differ from other frameworks since they don't really let you define multiple components in the same file. This then means that if you have 2 components in the same file, the styles might conflict.
|
|
32
|
+
|
|
30
33
|
## Technicality
|
|
31
34
|
since this plugin uses the engine of vue to scope the css to the components, the following sections come straight from the [vue documentation](https://vue-loader.vuejs.org/guide/scoped-css.html#deep-selectors).
|
|
32
35
|
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.addHashAttributesToJsxTagsAst = void 0;
|
|
15
|
+
var ast_iterator_1 = require("./ast-iterator");
|
|
16
|
+
var ast_transformer_1 = require("./ast-transformer");
|
|
17
|
+
var ast_utils_1 = require("./ast.utils");
|
|
18
|
+
var classic_parser_1 = require("./parsers/classic-parser");
|
|
19
|
+
var jsx_parser_model_1 = require("./parsers/jsx-parser.model");
|
|
20
|
+
var new_parser_1 = require("./parsers/new-parser");
|
|
21
|
+
global.implementation = null;
|
|
22
|
+
var classicParser = new classic_parser_1.ClassicJsxParser();
|
|
23
|
+
var newParser = new new_parser_1.NewJsxParser();
|
|
24
|
+
var parser = classicParser;
|
|
25
|
+
var findImplementation = function (program) {
|
|
26
|
+
var e_1, _a;
|
|
27
|
+
var implementation = jsx_parser_model_1.ParserImplementations.classic;
|
|
28
|
+
try {
|
|
29
|
+
for (var _b = __values((0, ast_iterator_1.astIterator)(program)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
30
|
+
var node = _c.value;
|
|
31
|
+
if (!(0, ast_utils_1.isNodeImportOrRequire)(node)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
var src = (0, ast_utils_1.getSrcFromImportOrRequire)(node);
|
|
35
|
+
if (["react/jsx-dev-runtime", "react/jsx-runtime"].includes(src)) {
|
|
36
|
+
return jsx_parser_model_1.ParserImplementations.new;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
41
|
+
finally {
|
|
42
|
+
try {
|
|
43
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
44
|
+
}
|
|
45
|
+
finally { if (e_1) throw e_1.error; }
|
|
46
|
+
}
|
|
47
|
+
return implementation;
|
|
48
|
+
};
|
|
49
|
+
function addHashAttributesToJsxTagsAst(program, attr) {
|
|
50
|
+
// Once in the program, we can determine which parser to use
|
|
51
|
+
if (global.implementation === null) {
|
|
52
|
+
global.implementation = findImplementation(program);
|
|
53
|
+
if (global.implementation === jsx_parser_model_1.ParserImplementations.new) {
|
|
54
|
+
parser = newParser;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return (0, ast_transformer_1.astTransformer)(program, function (node) {
|
|
58
|
+
if (parser.isNodeReactElement(node) && !parser.isNodeReactFragment(node)) {
|
|
59
|
+
return parser.extendNodeWithAttributes(node, attr);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.addHashAttributesToJsxTagsAst = addHashAttributesToJsxTagsAst;
|
package/dist/ast.utils.d.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export declare const createObjectAssignCallExpressionWithIdentifier: (identifier: any, objectExpression: any) => {
|
|
2
|
+
type: string;
|
|
3
|
+
callee: {
|
|
4
|
+
type: string;
|
|
5
|
+
object: {
|
|
6
|
+
type: string;
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
property: {
|
|
10
|
+
type: string;
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
13
|
+
computed: boolean;
|
|
14
|
+
optional: boolean;
|
|
15
|
+
};
|
|
16
|
+
arguments: any[];
|
|
17
|
+
optional: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare const createObjectExpressionWithAttr: (attrNode: any) => {
|
|
20
|
+
type: string;
|
|
21
|
+
properties: any[];
|
|
22
|
+
};
|
|
23
|
+
export declare const extendObjectExpression: (objectExpression: any, prop: any) => any;
|
|
24
|
+
export declare const hackIntoExtenderCallExpression: (callExpression: any, prop: any) => any;
|
|
25
|
+
export declare const isNodeCallExpression: (node: any) => boolean;
|
|
26
|
+
export declare const isNodeObjectExpression: (node: any) => boolean;
|
|
27
|
+
export declare const isNodeExtender: (node: any) => boolean;
|
|
28
|
+
export declare const isNodeIdentifier: (node: any) => boolean;
|
|
29
|
+
export declare const isNodeImportDeclaration: (node: any) => boolean;
|
|
30
|
+
export declare const isNodeRequireCallExpression: (node: any) => boolean;
|
|
31
|
+
export declare const isNodeImportOrRequire: (node: any) => boolean;
|
|
32
|
+
export declare const getSrcFromImportOrRequire: (node: any) => any;
|
package/dist/ast.utils.js
CHANGED
|
@@ -1,64 +1,127 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
9
8
|
}
|
|
9
|
+
return t;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
var classic_parser_1 = require("./parsers/classic-parser");
|
|
18
|
-
var jsx_parser_model_1 = require("./parsers/jsx-parser.model");
|
|
19
|
-
var new_parser_1 = require("./parsers/new-parser");
|
|
20
|
-
global.implementation = null;
|
|
21
|
-
var classicParser = new classic_parser_1.ClassicJsxParser();
|
|
22
|
-
var newParser = new new_parser_1.NewJsxParser();
|
|
23
|
-
var parser = classicParser;
|
|
24
|
-
var findImplementation = function (program) {
|
|
25
|
-
var e_1, _a;
|
|
26
|
-
var implementation = jsx_parser_model_1.ParserImplementations.classic;
|
|
13
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
27
17
|
try {
|
|
28
|
-
|
|
29
|
-
var node = _c.value;
|
|
30
|
-
if (node.type !== "ImportDeclaration") {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (node.specifiers.some(function (n) {
|
|
34
|
-
return ["_jsxDEV", "jsxRuntime"].includes(n.local.name);
|
|
35
|
-
}) ||
|
|
36
|
-
["react/jsx-dev-runtime", "react/jsx-runtime"].includes(node.source.value)) {
|
|
37
|
-
return jsx_parser_model_1.ParserImplementations.new;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
40
19
|
}
|
|
41
|
-
catch (
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
42
21
|
finally {
|
|
43
22
|
try {
|
|
44
|
-
if (
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
45
24
|
}
|
|
46
|
-
finally { if (
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
47
26
|
}
|
|
48
|
-
return
|
|
27
|
+
return ar;
|
|
49
28
|
};
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
parser = newParser;
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
56
34
|
}
|
|
57
35
|
}
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getSrcFromImportOrRequire = exports.isNodeImportOrRequire = exports.isNodeRequireCallExpression = exports.isNodeImportDeclaration = exports.isNodeIdentifier = exports.isNodeExtender = exports.isNodeObjectExpression = exports.isNodeCallExpression = exports.hackIntoExtenderCallExpression = exports.extendObjectExpression = exports.createObjectExpressionWithAttr = exports.createObjectAssignCallExpressionWithIdentifier = void 0;
|
|
40
|
+
var createObjectAssignCallExpressionWithIdentifier = function (identifier, objectExpression) {
|
|
41
|
+
return {
|
|
42
|
+
type: "CallExpression",
|
|
43
|
+
callee: {
|
|
44
|
+
type: "MemberExpression",
|
|
45
|
+
object: {
|
|
46
|
+
type: "Identifier",
|
|
47
|
+
name: "Object",
|
|
48
|
+
},
|
|
49
|
+
property: {
|
|
50
|
+
type: "Identifier",
|
|
51
|
+
name: "assign",
|
|
52
|
+
},
|
|
53
|
+
computed: false,
|
|
54
|
+
optional: false,
|
|
55
|
+
},
|
|
56
|
+
arguments: [
|
|
57
|
+
{
|
|
58
|
+
type: "ObjectExpression",
|
|
59
|
+
start: 14,
|
|
60
|
+
end: 16,
|
|
61
|
+
properties: [],
|
|
62
|
+
},
|
|
63
|
+
identifier,
|
|
64
|
+
objectExpression,
|
|
65
|
+
],
|
|
66
|
+
optional: false,
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.createObjectAssignCallExpressionWithIdentifier = createObjectAssignCallExpressionWithIdentifier;
|
|
70
|
+
var createObjectExpressionWithAttr = function (attrNode) {
|
|
71
|
+
return {
|
|
72
|
+
type: "ObjectExpression",
|
|
73
|
+
properties: [attrNode],
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
exports.createObjectExpressionWithAttr = createObjectExpressionWithAttr;
|
|
77
|
+
var extendObjectExpression = function (objectExpression, prop) {
|
|
78
|
+
return __assign(__assign({}, objectExpression), { properties: __spreadArray(__spreadArray([], __read(objectExpression.properties), false), [prop], false) });
|
|
79
|
+
};
|
|
80
|
+
exports.extendObjectExpression = extendObjectExpression;
|
|
81
|
+
var hackIntoExtenderCallExpression = function (callExpression, prop) {
|
|
82
|
+
return __assign(__assign({}, callExpression), { arguments: __spreadArray(__spreadArray([], __read(callExpression.arguments), false), [
|
|
83
|
+
(0, exports.createObjectExpressionWithAttr)(prop),
|
|
84
|
+
], false) });
|
|
85
|
+
};
|
|
86
|
+
exports.hackIntoExtenderCallExpression = hackIntoExtenderCallExpression;
|
|
87
|
+
var isNodeCallExpression = function (node) {
|
|
88
|
+
return node.type === "CallExpression";
|
|
89
|
+
};
|
|
90
|
+
exports.isNodeCallExpression = isNodeCallExpression;
|
|
91
|
+
var isNodeObjectExpression = function (node) {
|
|
92
|
+
return node.type === "ObjectExpression";
|
|
93
|
+
};
|
|
94
|
+
exports.isNodeObjectExpression = isNodeObjectExpression;
|
|
95
|
+
var isNodeExtender = function (node) {
|
|
96
|
+
return ((0, exports.isNodeCallExpression)(node) &&
|
|
97
|
+
(node.callee.name === "_objectSpread" || node.callee.name === "_extends"));
|
|
98
|
+
};
|
|
99
|
+
exports.isNodeExtender = isNodeExtender;
|
|
100
|
+
var isNodeIdentifier = function (node) {
|
|
101
|
+
return node.type === "Identifier";
|
|
102
|
+
};
|
|
103
|
+
exports.isNodeIdentifier = isNodeIdentifier;
|
|
104
|
+
var isNodeImportDeclaration = function (node) {
|
|
105
|
+
return node.type === "ImportDeclaration";
|
|
106
|
+
};
|
|
107
|
+
exports.isNodeImportDeclaration = isNodeImportDeclaration;
|
|
108
|
+
var isNodeRequireCallExpression = function (node) {
|
|
109
|
+
return ((0, exports.isNodeCallExpression)(node) &&
|
|
110
|
+
node.callee.name === "require" &&
|
|
111
|
+
node.arguments.length === 1);
|
|
112
|
+
};
|
|
113
|
+
exports.isNodeRequireCallExpression = isNodeRequireCallExpression;
|
|
114
|
+
var isNodeImportOrRequire = function (node) {
|
|
115
|
+
return (0, exports.isNodeImportDeclaration)(node) || (0, exports.isNodeRequireCallExpression)(node);
|
|
116
|
+
};
|
|
117
|
+
exports.isNodeImportOrRequire = isNodeImportOrRequire;
|
|
118
|
+
var getSrcFromImportOrRequire = function (node) {
|
|
119
|
+
if ((0, exports.isNodeImportDeclaration)(node)) {
|
|
120
|
+
return node.source.value;
|
|
121
|
+
}
|
|
122
|
+
if ((0, exports.isNodeRequireCallExpression)(node)) {
|
|
123
|
+
return node.arguments[0].value;
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
};
|
|
127
|
+
exports.getSrcFromImportOrRequire = getSrcFromImportOrRequire;
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var js_xxhash_1 = require("js-xxhash");
|
|
|
36
36
|
var pluginutils_1 = require("@rollup/pluginutils");
|
|
37
37
|
var component_compiler_utils_1 = require("@vue/component-compiler-utils");
|
|
38
38
|
var escodegen_1 = require("escodegen");
|
|
39
|
-
var
|
|
39
|
+
var ast_program_1 = require("./ast-program");
|
|
40
40
|
var getFilenameFromPath = function (filePath) {
|
|
41
41
|
var parts = filePath.split("/");
|
|
42
42
|
return parts[parts.length - 1].split("?")[0];
|
|
@@ -102,7 +102,7 @@ function reactScopedCssPlugin(optionsIn) {
|
|
|
102
102
|
if (scopedCssInFileRegex.test(code)) {
|
|
103
103
|
var importerHash = generateHash(id);
|
|
104
104
|
var program = this.parse(code);
|
|
105
|
-
var newAst = (0,
|
|
105
|
+
var newAst = (0, ast_program_1.addHashAttributesToJsxTagsAst)(program, "data-".concat(options.hashPrefix, "-").concat(importerHash));
|
|
106
106
|
return (0, escodegen_1.generate)(newAst);
|
|
107
107
|
}
|
|
108
108
|
if (scopedCssRegex.test(getFilenameFromPath(id))) {
|
|
@@ -10,72 +10,47 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
14
|
exports.ClassicJsxParser = void 0;
|
|
15
|
+
var ast_utils_1 = require("../ast.utils");
|
|
40
16
|
var ClassicJsxParser = /** @class */ (function () {
|
|
41
17
|
function ClassicJsxParser() {
|
|
42
18
|
}
|
|
43
19
|
ClassicJsxParser.prototype.isNodeReactFragment = function (node) {
|
|
44
|
-
var _a, _b, _c, _d, _e, _f;
|
|
45
|
-
return (((
|
|
46
|
-
((
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
21
|
+
return ((((_b = (_a = node === null || node === void 0 ? void 0 : node.callee) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.name) === "React" ||
|
|
22
|
+
((_e = (_d = (_c = node === null || node === void 0 ? void 0 : node.callee) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.object) === null || _e === void 0 ? void 0 : _e.name) === "_react") &&
|
|
23
|
+
((_h = (_g = (_f = node === null || node === void 0 ? void 0 : node.arguments) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.property) === null || _h === void 0 ? void 0 : _h.name) === "Fragment");
|
|
47
24
|
};
|
|
48
25
|
ClassicJsxParser.prototype.isNodeReactElement = function (node) {
|
|
49
|
-
var _a, _b, _c, _d;
|
|
26
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
50
27
|
return ((node === null || node === void 0 ? void 0 : node.type) === "CallExpression" &&
|
|
51
|
-
((_b = (_a = node === null || node === void 0 ? void 0 : node.callee) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.name) === "React"
|
|
52
|
-
|
|
28
|
+
(((_b = (_a = node === null || node === void 0 ? void 0 : node.callee) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.name) === "React" ||
|
|
29
|
+
((_e = (_d = (_c = node === null || node === void 0 ? void 0 : node.callee) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.object) === null || _e === void 0 ? void 0 : _e.name) === "_react") &&
|
|
30
|
+
((_g = (_f = node === null || node === void 0 ? void 0 : node.callee) === null || _f === void 0 ? void 0 : _f.property) === null || _g === void 0 ? void 0 : _g.name) === "createElement");
|
|
53
31
|
};
|
|
54
32
|
ClassicJsxParser.prototype.extendNodeWithAttributes = function (node, attr) {
|
|
55
33
|
var _this = this;
|
|
56
|
-
var _a;
|
|
57
|
-
var arg = (_a = node === null || node === void 0 ? void 0 : node.arguments) === null || _a === void 0 ? void 0 : _a[1];
|
|
58
34
|
return __assign(__assign({}, node), { arguments: node === null || node === void 0 ? void 0 : node.arguments.map(function (v, i) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
};
|
|
76
|
-
}
|
|
35
|
+
// Second argument is attributes so ignore others
|
|
36
|
+
if (i !== 1) {
|
|
37
|
+
return v;
|
|
38
|
+
}
|
|
39
|
+
var attrNode = _this.createAttributeNode(attr);
|
|
40
|
+
// If it's an object expression, extend it
|
|
41
|
+
if ((0, ast_utils_1.isNodeObjectExpression)(v)) {
|
|
42
|
+
return (0, ast_utils_1.extendObjectExpression)(v, attrNode);
|
|
43
|
+
}
|
|
44
|
+
// If it's an extender, hack into it
|
|
45
|
+
if ((0, ast_utils_1.isNodeExtender)(v)) {
|
|
46
|
+
return (0, ast_utils_1.hackIntoExtenderCallExpression)(v, attrNode);
|
|
47
|
+
}
|
|
48
|
+
// If it's an identifier, do Object.assign to be safe
|
|
49
|
+
if ((0, ast_utils_1.isNodeIdentifier)(v)) {
|
|
50
|
+
return (0, ast_utils_1.createObjectAssignCallExpressionWithIdentifier)(v, (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode));
|
|
77
51
|
}
|
|
78
|
-
|
|
52
|
+
// Worst case override with
|
|
53
|
+
return (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode);
|
|
79
54
|
}) });
|
|
80
55
|
};
|
|
81
56
|
ClassicJsxParser.prototype.createAttributeNode = function (attr) {
|
|
@@ -10,71 +10,65 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
14
|
exports.NewJsxParser = void 0;
|
|
15
|
+
var ast_utils_1 = require("../ast.utils");
|
|
40
16
|
var NewJsxParser = /** @class */ (function () {
|
|
41
17
|
function NewJsxParser() {
|
|
42
18
|
}
|
|
43
19
|
NewJsxParser.prototype.isNodeReactFragment = function (node) {
|
|
44
|
-
var _a, _b, _c, _d;
|
|
45
|
-
|
|
46
|
-
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
21
|
+
// Always a call expression
|
|
22
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== "CallExpression") {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (((_b = (_a = node.arguments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === "Identifier" &&
|
|
26
|
+
["_Fragment", "Fragment"].includes((_d = (_c = node.arguments) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
if (((_f = (_e = node.arguments) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.type) === "MemberExpression" &&
|
|
30
|
+
["_Fragment", "Fragment"].includes((_j = (_h = (_g = node.arguments) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.property) === null || _j === void 0 ? void 0 : _j.name)) {
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
47
34
|
};
|
|
48
35
|
NewJsxParser.prototype.isNodeReactElement = function (node) {
|
|
49
|
-
var _a;
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
var _a, _b, _c, _d, _e, _f;
|
|
37
|
+
// Always a call expression
|
|
38
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== "CallExpression") {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (["_jsxDEV", "_jsx", "_jsxs", "jsxDev", "jsx", "jsxs"].includes((_a = node === null || node === void 0 ? void 0 : node.callee) === null || _a === void 0 ? void 0 : _a.name)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (((_b = node === null || node === void 0 ? void 0 : node.callee) === null || _b === void 0 ? void 0 : _b.type) === "SequenceExpression" &&
|
|
45
|
+
["_jsxDEV", "_jsx", "_jsxs", "jsxDev", "jsx", "jsxs"].includes((_f = (_e = (_d = (_c = node === null || node === void 0 ? void 0 : node.callee) === null || _c === void 0 ? void 0 : _c.expressions) === null || _d === void 0 ? void 0 : _d[1]) === null || _e === void 0 ? void 0 : _e.property) === null || _f === void 0 ? void 0 : _f.name)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
52
49
|
};
|
|
53
50
|
NewJsxParser.prototype.extendNodeWithAttributes = function (node, attr) {
|
|
54
51
|
var _this = this;
|
|
55
|
-
var _a;
|
|
56
|
-
var arg = (_a = node === null || node === void 0 ? void 0 : node.arguments) === null || _a === void 0 ? void 0 : _a[1];
|
|
57
52
|
return __assign(__assign({}, node), { arguments: node === null || node === void 0 ? void 0 : node.arguments.map(function (v, i) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
75
|
-
}
|
|
53
|
+
// Second argument is attributes so ignore others
|
|
54
|
+
if (i !== 1) {
|
|
55
|
+
return v;
|
|
56
|
+
}
|
|
57
|
+
var attrNode = _this.createAttributeNode(attr);
|
|
58
|
+
// If it's an object expression, extend it
|
|
59
|
+
if ((0, ast_utils_1.isNodeObjectExpression)(v)) {
|
|
60
|
+
return (0, ast_utils_1.extendObjectExpression)(v, attrNode);
|
|
61
|
+
}
|
|
62
|
+
// If it's an extender, hack into it
|
|
63
|
+
if ((0, ast_utils_1.isNodeExtender)(v)) {
|
|
64
|
+
return (0, ast_utils_1.hackIntoExtenderCallExpression)(v, attrNode);
|
|
65
|
+
}
|
|
66
|
+
// If it's an identifier, do Object.assign to be safe
|
|
67
|
+
if ((0, ast_utils_1.isNodeIdentifier)(v)) {
|
|
68
|
+
return (0, ast_utils_1.createObjectAssignCallExpressionWithIdentifier)(v, (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode));
|
|
76
69
|
}
|
|
77
|
-
|
|
70
|
+
// Worst case override with
|
|
71
|
+
return (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode);
|
|
78
72
|
}) });
|
|
79
73
|
};
|
|
80
74
|
NewJsxParser.prototype.createAttributeNode = function (attr) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-react-scoped-css",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A rollup plugin designed to allow scoped css to be run in react (Compatible with vite and rollup)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,7 +40,9 @@
|
|
|
40
40
|
"rollup": "^2.56.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
+
"@babel/core": "^7.16.0",
|
|
43
44
|
"@babel/preset-env": "^7.15.0",
|
|
45
|
+
"@babel/preset-react": "^7.16.0",
|
|
44
46
|
"@babel/preset-typescript": "^7.15.0",
|
|
45
47
|
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
46
48
|
"@semantic-release/git": "^10.0.1",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
name: Pull Request Workflow
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
- pull_request
|
|
5
|
-
|
|
6
|
-
jobs:
|
|
7
|
-
build:
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v2
|
|
12
|
-
- name: Use Node.js 16.x
|
|
13
|
-
uses: actions/setup-node@v2
|
|
14
|
-
with:
|
|
15
|
-
node-version: 16.x
|
|
16
|
-
cache: 'npm'
|
|
17
|
-
- run: npm ci
|
|
18
|
-
- run: npm run build --if-present
|
|
19
|
-
- run: npm test
|
|
20
|
-
- run: npm run lint
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
name: Release Workflow
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches:
|
|
6
|
-
- 'main'
|
|
7
|
-
paths-ignore:
|
|
8
|
-
- '.github/**'
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
release:
|
|
12
|
-
runs-on: ubuntu-latest
|
|
13
|
-
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v2
|
|
16
|
-
- name: Use Node.js 16.x
|
|
17
|
-
uses: actions/setup-node@v2
|
|
18
|
-
with:
|
|
19
|
-
node-version: 16.x
|
|
20
|
-
registry-url: 'https://registry.npmjs.org'
|
|
21
|
-
cache: 'npm'
|
|
22
|
-
- run: npm ci
|
|
23
|
-
- run: npm run build --if-present
|
|
24
|
-
- name: Release
|
|
25
|
-
env:
|
|
26
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
27
|
-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
28
|
-
run: npx semantic-release
|
|
29
|
-
|
|
30
|
-
|
package/.vscode/settings.json
DELETED