rollup-plugin-react-scoped-css 0.7.0 → 0.8.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/babel.config.cjs +7 -0
- package/dist/ast-iterator.js +26 -107
- package/dist/ast-program.js +20 -42
- package/dist/ast-transformer.js +15 -38
- package/dist/ast.utils.js +22 -51
- package/dist/index.js +41 -67
- package/dist/parsers/jsx-parser.model.d.ts +2 -2
- package/dist/parsers/jsx-parser.model.js +2 -2
- package/dist/parsers/{new-parser.d.ts → legacy-jsx-parser.d.ts} +1 -1
- package/dist/parsers/legacy-jsx-parser.js +62 -0
- package/dist/parsers/{classic-parser.d.ts → modern-jsx-parser.d.ts} +2 -1
- package/dist/parsers/modern-jsx-parser.js +91 -0
- package/package.json +29 -28
- package/tsconfig.json +5 -4
- package/dist/parsers/classic-parser.js +0 -76
- package/dist/parsers/new-parser.js +0 -94
package/babel.config.cjs
ADDED
package/dist/ast-iterator.js
CHANGED
|
@@ -1,114 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (_) try {
|
|
9
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var __values = (this && this.__values) || function(o) {
|
|
30
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
31
|
-
if (m) return m.call(o);
|
|
32
|
-
if (o && typeof o.length === "number") return {
|
|
33
|
-
next: function () {
|
|
34
|
-
if (o && i >= o.length) o = void 0;
|
|
35
|
-
return { value: o && o[i++], done: !o };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
39
|
-
};
|
|
40
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
3
|
exports.astIterator = void 0;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
typeof
|
|
47
|
-
typeof
|
|
4
|
+
const isNode = (key, value) => {
|
|
5
|
+
if (key === "loc")
|
|
6
|
+
return false;
|
|
7
|
+
return (typeof value === "object" &&
|
|
8
|
+
typeof value?.end === "number" &&
|
|
9
|
+
typeof value?.start === "number" &&
|
|
10
|
+
typeof value?.type === "string");
|
|
48
11
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
case 2:
|
|
64
|
-
if (!!_b.done) return [3 /*break*/, 10];
|
|
65
|
-
key = _b.value;
|
|
66
|
-
// Skip useless keys
|
|
67
|
-
if (["end", "start", "type"].includes(key)) {
|
|
68
|
-
return [3 /*break*/, 9];
|
|
69
|
-
}
|
|
70
|
-
if (!Array.isArray(ast[key])) return [3 /*break*/, 7];
|
|
71
|
-
_c = [];
|
|
72
|
-
for (_d in ast[key])
|
|
73
|
-
_c.push(_d);
|
|
74
|
-
_i = 0;
|
|
75
|
-
_f.label = 3;
|
|
76
|
-
case 3:
|
|
77
|
-
if (!(_i < _c.length)) return [3 /*break*/, 6];
|
|
78
|
-
nodeIndex = _c[_i];
|
|
79
|
-
return [5 /*yield**/, __values((0, exports.astIterator)(ast[key][nodeIndex]))];
|
|
80
|
-
case 4:
|
|
81
|
-
_f.sent();
|
|
82
|
-
_f.label = 5;
|
|
83
|
-
case 5:
|
|
84
|
-
_i++;
|
|
85
|
-
return [3 /*break*/, 3];
|
|
86
|
-
case 6: return [3 /*break*/, 9];
|
|
87
|
-
case 7:
|
|
88
|
-
if (!isNode(ast[key])) return [3 /*break*/, 9];
|
|
89
|
-
return [5 /*yield**/, __values((0, exports.astIterator)(ast[key]))];
|
|
90
|
-
case 8:
|
|
91
|
-
_f.sent();
|
|
92
|
-
_f.label = 9;
|
|
93
|
-
case 9:
|
|
94
|
-
_b = _a.next();
|
|
95
|
-
return [3 /*break*/, 2];
|
|
96
|
-
case 10: return [3 /*break*/, 13];
|
|
97
|
-
case 11:
|
|
98
|
-
e_1_1 = _f.sent();
|
|
99
|
-
e_1 = { error: e_1_1 };
|
|
100
|
-
return [3 /*break*/, 13];
|
|
101
|
-
case 12:
|
|
102
|
-
try {
|
|
103
|
-
if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
|
|
104
|
-
}
|
|
105
|
-
finally { if (e_1) throw e_1.error; }
|
|
106
|
-
return [7 /*endfinally*/];
|
|
107
|
-
case 13: return [4 /*yield*/, ast];
|
|
108
|
-
case 14:
|
|
109
|
-
_f.sent();
|
|
110
|
-
return [2 /*return*/];
|
|
12
|
+
const astIterator = function* (ast) {
|
|
13
|
+
if (!ast) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
for (const key of Object.keys(ast)) {
|
|
17
|
+
// Skip useless keys
|
|
18
|
+
if (["end", "start", "type"].includes(key)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
// If key value is an array, iterate over it
|
|
22
|
+
if (Array.isArray(ast[key])) {
|
|
23
|
+
for (const nodeIndex in ast[key]) {
|
|
24
|
+
yield* (0, exports.astIterator)(ast[key][nodeIndex]);
|
|
25
|
+
}
|
|
111
26
|
}
|
|
112
|
-
|
|
27
|
+
else if (isNode(key, ast[key])) {
|
|
28
|
+
yield* (0, exports.astIterator)(ast[key]);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
yield ast;
|
|
113
32
|
};
|
|
114
33
|
exports.astIterator = astIterator;
|
package/dist/ast-program.js
CHANGED
|
@@ -1,48 +1,26 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.addHashAttributesToJsxTagsAst = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const ast_iterator_1 = require("./ast-iterator");
|
|
5
|
+
const ast_transformer_1 = require("./ast-transformer");
|
|
6
|
+
const ast_utils_1 = require("./ast.utils");
|
|
7
|
+
const legacy_jsx_parser_1 = require("./parsers/legacy-jsx-parser");
|
|
8
|
+
const modern_jsx_parser_1 = require("./parsers/modern-jsx-parser");
|
|
9
|
+
const jsx_parser_model_1 = require("./parsers/jsx-parser.model");
|
|
21
10
|
global.implementation = null;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
}
|
|
11
|
+
const legacyJsxParser = new legacy_jsx_parser_1.LegacyJsxParser();
|
|
12
|
+
const modernJsxParser = new modern_jsx_parser_1.ModernJsxParser();
|
|
13
|
+
let parser = legacyJsxParser;
|
|
14
|
+
const findImplementation = (program) => {
|
|
15
|
+
const implementation = jsx_parser_model_1.ParserImplementations.legacy;
|
|
16
|
+
for (const node of (0, ast_iterator_1.astIterator)(program)) {
|
|
17
|
+
if (!(0, ast_utils_1.isNodeImportOrRequire)(node)) {
|
|
18
|
+
continue;
|
|
38
19
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
20
|
+
const src = (0, ast_utils_1.getSrcFromImportOrRequire)(node);
|
|
21
|
+
if (["react/jsx-dev-runtime", "react/jsx-runtime"].includes(src)) {
|
|
22
|
+
return jsx_parser_model_1.ParserImplementations.modern;
|
|
44
23
|
}
|
|
45
|
-
finally { if (e_1) throw e_1.error; }
|
|
46
24
|
}
|
|
47
25
|
return implementation;
|
|
48
26
|
};
|
|
@@ -50,11 +28,11 @@ function addHashAttributesToJsxTagsAst(program, attr) {
|
|
|
50
28
|
// Once in the program, we can determine which parser to use
|
|
51
29
|
if (global.implementation === null) {
|
|
52
30
|
global.implementation = findImplementation(program);
|
|
53
|
-
if (global.implementation === jsx_parser_model_1.ParserImplementations.
|
|
54
|
-
parser =
|
|
31
|
+
if (global.implementation === jsx_parser_model_1.ParserImplementations.modern) {
|
|
32
|
+
parser = modernJsxParser;
|
|
55
33
|
}
|
|
56
34
|
}
|
|
57
|
-
return (0, ast_transformer_1.astTransformer)(program,
|
|
35
|
+
return (0, ast_transformer_1.astTransformer)(program, (node) => {
|
|
58
36
|
if (parser.isNodeReactElement(node) && !parser.isNodeReactFragment(node)) {
|
|
59
37
|
return parser.extendNodeWithAttributes(node, attr);
|
|
60
38
|
}
|
package/dist/ast-transformer.js
CHANGED
|
@@ -1,50 +1,27 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.astTransformer = void 0;
|
|
15
|
-
|
|
16
|
-
var _a, _b, _c;
|
|
4
|
+
const isNode = (obj) => {
|
|
17
5
|
return (typeof obj === "object" &&
|
|
18
|
-
typeof
|
|
19
|
-
typeof
|
|
20
|
-
typeof
|
|
6
|
+
typeof obj?.end === "number" &&
|
|
7
|
+
typeof obj?.start === "number" &&
|
|
8
|
+
typeof obj?.type === "string");
|
|
21
9
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (Array.isArray(ast[key])) {
|
|
31
|
-
for (var nodeIndex in ast[key]) {
|
|
32
|
-
ast[key][nodeIndex] = (0, exports.astTransformer)(ast[key][nodeIndex], callback);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (isNode(ast[key])) {
|
|
36
|
-
ast[key] = (0, exports.astTransformer)(ast[key], callback);
|
|
10
|
+
const astTransformer = (ast, callback) => {
|
|
11
|
+
for (const key of Object.keys(ast)) {
|
|
12
|
+
if (["end", "start", "type"].includes(key)) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(ast[key])) {
|
|
16
|
+
for (const nodeIndex in ast[key]) {
|
|
17
|
+
ast[key][nodeIndex] = (0, exports.astTransformer)(ast[key][nodeIndex], callback);
|
|
37
18
|
}
|
|
38
19
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
finally {
|
|
42
|
-
try {
|
|
43
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
20
|
+
else if (isNode(ast[key])) {
|
|
21
|
+
ast[key] = (0, exports.astTransformer)(ast[key], callback);
|
|
44
22
|
}
|
|
45
|
-
finally { if (e_1) throw e_1.error; }
|
|
46
23
|
}
|
|
47
|
-
|
|
24
|
+
const result = callback(ast);
|
|
48
25
|
return typeof result !== "undefined" ? result : ast;
|
|
49
26
|
};
|
|
50
27
|
exports.astTransformer = astTransformer;
|
package/dist/ast.utils.js
CHANGED
|
@@ -1,43 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
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];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
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
|
-
|
|
4
|
+
const createObjectAssignCallExpressionWithIdentifier = (identifier, objectExpression) => {
|
|
41
5
|
return {
|
|
42
6
|
type: "CallExpression",
|
|
43
7
|
callee: {
|
|
@@ -67,55 +31,62 @@ var createObjectAssignCallExpressionWithIdentifier = function (identifier, objec
|
|
|
67
31
|
};
|
|
68
32
|
};
|
|
69
33
|
exports.createObjectAssignCallExpressionWithIdentifier = createObjectAssignCallExpressionWithIdentifier;
|
|
70
|
-
|
|
34
|
+
const createObjectExpressionWithAttr = (attrNode) => {
|
|
71
35
|
return {
|
|
72
36
|
type: "ObjectExpression",
|
|
73
37
|
properties: [attrNode],
|
|
74
38
|
};
|
|
75
39
|
};
|
|
76
40
|
exports.createObjectExpressionWithAttr = createObjectExpressionWithAttr;
|
|
77
|
-
|
|
78
|
-
return
|
|
41
|
+
const extendObjectExpression = (objectExpression, prop) => {
|
|
42
|
+
return {
|
|
43
|
+
...objectExpression,
|
|
44
|
+
properties: [...objectExpression.properties, prop],
|
|
45
|
+
};
|
|
79
46
|
};
|
|
80
47
|
exports.extendObjectExpression = extendObjectExpression;
|
|
81
|
-
|
|
82
|
-
return
|
|
48
|
+
const hackIntoExtenderCallExpression = (callExpression, prop) => {
|
|
49
|
+
return {
|
|
50
|
+
...callExpression,
|
|
51
|
+
arguments: [
|
|
52
|
+
...callExpression.arguments,
|
|
83
53
|
(0, exports.createObjectExpressionWithAttr)(prop),
|
|
84
|
-
],
|
|
54
|
+
],
|
|
55
|
+
};
|
|
85
56
|
};
|
|
86
57
|
exports.hackIntoExtenderCallExpression = hackIntoExtenderCallExpression;
|
|
87
|
-
|
|
58
|
+
const isNodeCallExpression = (node) => {
|
|
88
59
|
return node.type === "CallExpression";
|
|
89
60
|
};
|
|
90
61
|
exports.isNodeCallExpression = isNodeCallExpression;
|
|
91
|
-
|
|
62
|
+
const isNodeObjectExpression = (node) => {
|
|
92
63
|
return node.type === "ObjectExpression";
|
|
93
64
|
};
|
|
94
65
|
exports.isNodeObjectExpression = isNodeObjectExpression;
|
|
95
|
-
|
|
66
|
+
const isNodeExtender = (node) => {
|
|
96
67
|
return ((0, exports.isNodeCallExpression)(node) &&
|
|
97
68
|
(node.callee.name === "_objectSpread" || node.callee.name === "_extends"));
|
|
98
69
|
};
|
|
99
70
|
exports.isNodeExtender = isNodeExtender;
|
|
100
|
-
|
|
71
|
+
const isNodeIdentifier = (node) => {
|
|
101
72
|
return node.type === "Identifier";
|
|
102
73
|
};
|
|
103
74
|
exports.isNodeIdentifier = isNodeIdentifier;
|
|
104
|
-
|
|
75
|
+
const isNodeImportDeclaration = (node) => {
|
|
105
76
|
return node.type === "ImportDeclaration";
|
|
106
77
|
};
|
|
107
78
|
exports.isNodeImportDeclaration = isNodeImportDeclaration;
|
|
108
|
-
|
|
79
|
+
const isNodeRequireCallExpression = (node) => {
|
|
109
80
|
return ((0, exports.isNodeCallExpression)(node) &&
|
|
110
81
|
node.callee.name === "require" &&
|
|
111
82
|
node.arguments.length === 1);
|
|
112
83
|
};
|
|
113
84
|
exports.isNodeRequireCallExpression = isNodeRequireCallExpression;
|
|
114
|
-
|
|
85
|
+
const isNodeImportOrRequire = (node) => {
|
|
115
86
|
return (0, exports.isNodeImportDeclaration)(node) || (0, exports.isNodeRequireCallExpression)(node);
|
|
116
87
|
};
|
|
117
88
|
exports.isNodeImportOrRequire = isNodeImportOrRequire;
|
|
118
|
-
|
|
89
|
+
const getSrcFromImportOrRequire = (node) => {
|
|
119
90
|
if ((0, exports.isNodeImportDeclaration)(node)) {
|
|
120
91
|
return node.source.value;
|
|
121
92
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,94 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
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];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
16
|
-
}) : (function(o, m, k, k2) {
|
|
17
|
-
if (k2 === undefined) k2 = k;
|
|
18
|
-
o[k2] = m[k];
|
|
19
|
-
}));
|
|
20
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
-
}) : function(o, v) {
|
|
23
|
-
o["default"] = v;
|
|
24
|
-
});
|
|
25
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
-
if (mod && mod.__esModule) return mod;
|
|
27
|
-
var result = {};
|
|
28
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
-
__setModuleDefault(result, mod);
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
3
|
exports.reactScopedCssPlugin = void 0;
|
|
34
4
|
/* eslint-disable no-useless-escape */
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const js_xxhash_1 = require("js-xxhash");
|
|
7
|
+
const pluginutils_1 = require("@rollup/pluginutils");
|
|
8
|
+
const component_compiler_utils_1 = require("@vue/component-compiler-utils");
|
|
9
|
+
const escodegen_1 = require("escodegen");
|
|
10
|
+
const ast_program_1 = require("./ast-program");
|
|
11
|
+
const getFilenameFromPath = (filePath) => {
|
|
12
|
+
const parts = filePath.split("/");
|
|
43
13
|
return parts[parts.length - 1].split("?")[0];
|
|
44
14
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
15
|
+
const getHashFromPath = (filePath) => {
|
|
16
|
+
const search = "?scope=";
|
|
17
|
+
const hash = filePath.slice(filePath.indexOf(search) + search.length);
|
|
48
18
|
return hash;
|
|
49
19
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var hashNum = (0, js_xxhash_1.xxHash32)(Buffer.from(input, "utf8"), seed);
|
|
20
|
+
const generateHash = (input, seed = 0) => {
|
|
21
|
+
const hashNum = (0, js_xxhash_1.xxHash32)(Buffer.from(input, "utf8"), seed);
|
|
53
22
|
return hashNum.toString(16);
|
|
54
23
|
};
|
|
55
|
-
|
|
56
|
-
|
|
24
|
+
const addAttributesToCss = (src, fileName, hash) => {
|
|
25
|
+
const { code } = (0, component_compiler_utils_1.compileStyle)({
|
|
57
26
|
source: src,
|
|
58
27
|
filename: fileName,
|
|
59
28
|
id: hash,
|
|
60
29
|
scoped: true,
|
|
61
30
|
trim: true,
|
|
62
|
-
})
|
|
31
|
+
});
|
|
63
32
|
return code;
|
|
64
33
|
};
|
|
65
|
-
function reactScopedCssPlugin(optionsIn) {
|
|
66
|
-
|
|
67
|
-
|
|
34
|
+
function reactScopedCssPlugin(optionsIn = {}) {
|
|
35
|
+
const options = {
|
|
36
|
+
hashPrefix: "v",
|
|
37
|
+
styleFileSuffix: "scoped",
|
|
38
|
+
styleFileExtensions: ["scss", "css", "sass", "less"],
|
|
39
|
+
jsxFileExtensions: ["jsx", "tsx"],
|
|
40
|
+
...optionsIn,
|
|
41
|
+
};
|
|
68
42
|
if (!options.styleFileExtensions || !options.styleFileExtensions.length) {
|
|
69
43
|
throw new Error("You need to provide at least one style file extension");
|
|
70
44
|
}
|
|
71
45
|
if (!options.jsxFileExtensions || !options.jsxFileExtensions.length) {
|
|
72
46
|
throw new Error("You need to provide at least one jsx file extension");
|
|
73
47
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
? new RegExp(
|
|
77
|
-
: new RegExp(
|
|
78
|
-
|
|
79
|
-
? new RegExp(
|
|
80
|
-
: new RegExp(
|
|
81
|
-
|
|
48
|
+
const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
|
|
49
|
+
const scopedCssRegex = options.styleFileSuffix
|
|
50
|
+
? new RegExp(`\.${options.styleFileSuffix}\.(${options.styleFileExtensions.join("|")})$`)
|
|
51
|
+
: new RegExp(`\.(${options.styleFileExtensions.join("|")})$`);
|
|
52
|
+
const scopedCssInFileRegex = options.styleFileSuffix
|
|
53
|
+
? new RegExp(`\.${options.styleFileSuffix}\.(${options.styleFileExtensions.join("|")})(\"|\')`)
|
|
54
|
+
: new RegExp(`\.(${options.styleFileExtensions.join("|")})(\"|\')`);
|
|
55
|
+
const jsxRegex = new RegExp(`\.(${options.jsxFileExtensions.join("|")})$`);
|
|
82
56
|
return [
|
|
83
57
|
{
|
|
84
58
|
name: "rollup-plugin-react-scoped-css:pre",
|
|
85
|
-
resolveId
|
|
59
|
+
resolveId(source, importer) {
|
|
86
60
|
if (!importer) {
|
|
87
61
|
return;
|
|
88
62
|
}
|
|
89
63
|
if (scopedCssRegex.test(source) && jsxRegex.test(importer)) {
|
|
90
|
-
|
|
91
|
-
|
|
64
|
+
const importerHash = generateHash(importer);
|
|
65
|
+
const url = (0, path_1.resolve)((0, path_1.dirname)(importer), `${source}?scope=${importerHash}`);
|
|
92
66
|
return url;
|
|
93
67
|
}
|
|
94
68
|
},
|
|
@@ -96,19 +70,19 @@ function reactScopedCssPlugin(optionsIn) {
|
|
|
96
70
|
},
|
|
97
71
|
{
|
|
98
72
|
name: "rollup-plugin-react-scoped-css:post",
|
|
99
|
-
transform
|
|
73
|
+
transform(code, id) {
|
|
100
74
|
if (!filter(id)) {
|
|
101
75
|
return;
|
|
102
76
|
}
|
|
103
77
|
if (scopedCssInFileRegex.test(code)) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
78
|
+
const importerHash = generateHash(id);
|
|
79
|
+
const program = this.parse(code);
|
|
80
|
+
const newAst = (0, ast_program_1.addHashAttributesToJsxTagsAst)(program, `data-${options.hashPrefix}-${importerHash}`);
|
|
107
81
|
return (0, escodegen_1.generate)(newAst);
|
|
108
82
|
}
|
|
109
83
|
if (scopedCssRegex.test(getFilenameFromPath(id))) {
|
|
110
|
-
|
|
111
|
-
return addAttributesToCss(code, getFilenameFromPath(id),
|
|
84
|
+
const importerHash = getHashFromPath(id);
|
|
85
|
+
return addAttributesToCss(code, getFilenameFromPath(id), `data-${options.hashPrefix}-${importerHash}`);
|
|
112
86
|
}
|
|
113
87
|
},
|
|
114
88
|
},
|
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ParserImplementations = void 0;
|
|
4
4
|
var ParserImplementations;
|
|
5
5
|
(function (ParserImplementations) {
|
|
6
|
-
ParserImplementations["
|
|
7
|
-
ParserImplementations["
|
|
6
|
+
ParserImplementations["modern"] = "modern";
|
|
7
|
+
ParserImplementations["legacy"] = "legacy";
|
|
8
8
|
})(ParserImplementations = exports.ParserImplementations || (exports.ParserImplementations = {}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsxParser } from "./jsx-parser.model";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class LegacyJsxParser implements JsxParser {
|
|
3
3
|
isNodeReactFragment(node: any): boolean;
|
|
4
4
|
isNodeReactElement(node: any): boolean;
|
|
5
5
|
extendNodeWithAttributes(node: any, attr: string): any;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LegacyJsxParser = void 0;
|
|
4
|
+
const ast_utils_1 = require("../ast.utils");
|
|
5
|
+
class LegacyJsxParser {
|
|
6
|
+
isNodeReactFragment(node) {
|
|
7
|
+
return ((node?.callee?.object?.name === "React" ||
|
|
8
|
+
node?.callee?.object?.object?.name === "_react") &&
|
|
9
|
+
node?.arguments?.[0]?.property?.name === "Fragment");
|
|
10
|
+
}
|
|
11
|
+
isNodeReactElement(node) {
|
|
12
|
+
return (node?.type === "CallExpression" &&
|
|
13
|
+
(node?.callee?.object?.name === "React" ||
|
|
14
|
+
node?.callee?.object?.object?.name === "_react") &&
|
|
15
|
+
node?.callee?.property?.name === "createElement");
|
|
16
|
+
}
|
|
17
|
+
extendNodeWithAttributes(node, attr) {
|
|
18
|
+
return {
|
|
19
|
+
...node,
|
|
20
|
+
arguments: node?.arguments.map((v, i) => {
|
|
21
|
+
// Second argument is attributes so ignore others
|
|
22
|
+
if (i !== 1) {
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
25
|
+
const attrNode = this.createAttributeNode(attr);
|
|
26
|
+
// If it's an object expression, extend it
|
|
27
|
+
if ((0, ast_utils_1.isNodeObjectExpression)(v)) {
|
|
28
|
+
return (0, ast_utils_1.extendObjectExpression)(v, attrNode);
|
|
29
|
+
}
|
|
30
|
+
// If it's an extender, hack into it
|
|
31
|
+
if ((0, ast_utils_1.isNodeExtender)(v)) {
|
|
32
|
+
return (0, ast_utils_1.hackIntoExtenderCallExpression)(v, attrNode);
|
|
33
|
+
}
|
|
34
|
+
// If it's an identifier, do Object.assign to be safe
|
|
35
|
+
if ((0, ast_utils_1.isNodeIdentifier)(v)) {
|
|
36
|
+
return (0, ast_utils_1.createObjectAssignCallExpressionWithIdentifier)(v, (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode));
|
|
37
|
+
}
|
|
38
|
+
// Worst case override with
|
|
39
|
+
return (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode);
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
createAttributeNode(attr) {
|
|
44
|
+
return {
|
|
45
|
+
type: "Property",
|
|
46
|
+
method: false,
|
|
47
|
+
shorthand: false,
|
|
48
|
+
computed: false,
|
|
49
|
+
key: {
|
|
50
|
+
type: "Identifier",
|
|
51
|
+
name: `"${attr}"`,
|
|
52
|
+
},
|
|
53
|
+
value: {
|
|
54
|
+
type: "Literal",
|
|
55
|
+
value: true,
|
|
56
|
+
raw: "true",
|
|
57
|
+
},
|
|
58
|
+
kind: "init",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.LegacyJsxParser = LegacyJsxParser;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsxParser } from "./jsx-parser.model";
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class ModernJsxParser implements JsxParser {
|
|
3
|
+
private reactCalleeNames;
|
|
3
4
|
isNodeReactFragment(node: any): boolean;
|
|
4
5
|
isNodeReactElement(node: any): boolean;
|
|
5
6
|
extendNodeWithAttributes(node: any, attr: string): any;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModernJsxParser = void 0;
|
|
4
|
+
const ast_utils_1 = require("../ast.utils");
|
|
5
|
+
class ModernJsxParser {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.reactCalleeNames = [
|
|
8
|
+
"_jsxDEV",
|
|
9
|
+
"_jsx",
|
|
10
|
+
"_jsxs",
|
|
11
|
+
"jsxDev",
|
|
12
|
+
"jsx",
|
|
13
|
+
"jsxs",
|
|
14
|
+
"jsxDEV",
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
isNodeReactFragment(node) {
|
|
18
|
+
// Always a call expression
|
|
19
|
+
if (node?.type !== "CallExpression") {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (node.arguments?.[0]?.type === "Identifier" &&
|
|
23
|
+
["_Fragment", "Fragment"].includes(node.arguments?.[0]?.name)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (node.arguments?.[0]?.type === "MemberExpression" &&
|
|
27
|
+
["_Fragment", "Fragment"].includes(node.arguments?.[0]?.property?.name)) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
isNodeReactElement(node) {
|
|
33
|
+
// Always a call expression
|
|
34
|
+
if (node?.type !== "CallExpression") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (this.reactCalleeNames.includes(node?.callee?.name)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (node?.callee?.type === "SequenceExpression" &&
|
|
41
|
+
this.reactCalleeNames.includes(node?.callee?.expressions?.[1]?.property?.name)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
extendNodeWithAttributes(node, attr) {
|
|
47
|
+
return {
|
|
48
|
+
...node,
|
|
49
|
+
arguments: node?.arguments.map((v, i) => {
|
|
50
|
+
// Second argument is attributes so ignore others
|
|
51
|
+
if (i !== 1) {
|
|
52
|
+
return v;
|
|
53
|
+
}
|
|
54
|
+
const attrNode = this.createAttributeNode(attr);
|
|
55
|
+
// If it's an object expression, extend it
|
|
56
|
+
if ((0, ast_utils_1.isNodeObjectExpression)(v)) {
|
|
57
|
+
return (0, ast_utils_1.extendObjectExpression)(v, attrNode);
|
|
58
|
+
}
|
|
59
|
+
// If it's an extender, hack into it
|
|
60
|
+
if ((0, ast_utils_1.isNodeExtender)(v)) {
|
|
61
|
+
return (0, ast_utils_1.hackIntoExtenderCallExpression)(v, attrNode);
|
|
62
|
+
}
|
|
63
|
+
// If it's an identifier, do Object.assign to be safe
|
|
64
|
+
if ((0, ast_utils_1.isNodeIdentifier)(v)) {
|
|
65
|
+
return (0, ast_utils_1.createObjectAssignCallExpressionWithIdentifier)(v, (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode));
|
|
66
|
+
}
|
|
67
|
+
// Worst case override with
|
|
68
|
+
return (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode);
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
createAttributeNode(attr) {
|
|
73
|
+
return {
|
|
74
|
+
type: "Property",
|
|
75
|
+
method: false,
|
|
76
|
+
shorthand: false,
|
|
77
|
+
computed: false,
|
|
78
|
+
key: {
|
|
79
|
+
type: "Identifier",
|
|
80
|
+
name: `"${attr}"`,
|
|
81
|
+
},
|
|
82
|
+
value: {
|
|
83
|
+
type: "Literal",
|
|
84
|
+
value: true,
|
|
85
|
+
raw: "true",
|
|
86
|
+
},
|
|
87
|
+
kind: "init",
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.ModernJsxParser = ModernJsxParser;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-react-scoped-css",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -33,35 +33,36 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/cmseguin/rollup-plugin-react-scoped-css#readme",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@rollup/pluginutils": "
|
|
37
|
-
"@vue/component-compiler-utils": "
|
|
38
|
-
"escodegen": "
|
|
39
|
-
"js-xxhash": "
|
|
40
|
-
"rollup": "
|
|
36
|
+
"@rollup/pluginutils": "5.0.2",
|
|
37
|
+
"@vue/component-compiler-utils": "3.2.2",
|
|
38
|
+
"escodegen": "2.0.0",
|
|
39
|
+
"js-xxhash": "2.0.0",
|
|
40
|
+
"rollup": "3.10.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@babel/core": "
|
|
44
|
-
"@babel/preset-env": "
|
|
45
|
-
"@babel/preset-react": "
|
|
46
|
-
"@babel/preset-typescript": "
|
|
47
|
-
"@semantic-release/commit-analyzer": "
|
|
48
|
-
"@semantic-release/git": "
|
|
49
|
-
"@semantic-release/github": "
|
|
50
|
-
"@semantic-release/npm": "
|
|
51
|
-
"@semantic-release/release-notes-generator": "
|
|
43
|
+
"@babel/core": "7.20.12",
|
|
44
|
+
"@babel/preset-env": "7.20.2",
|
|
45
|
+
"@babel/preset-react": "7.18.6",
|
|
46
|
+
"@babel/preset-typescript": "7.18.6",
|
|
47
|
+
"@semantic-release/commit-analyzer": "9.0.2",
|
|
48
|
+
"@semantic-release/git": "10.0.1",
|
|
49
|
+
"@semantic-release/github": "8.0.7",
|
|
50
|
+
"@semantic-release/npm": "9.0.2",
|
|
51
|
+
"@semantic-release/release-notes-generator": "10.0.3",
|
|
52
52
|
"@types/escodegen": "0.0.7",
|
|
53
|
-
"@types/estree": "0.0
|
|
54
|
-
"@types/jest": "
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "
|
|
56
|
-
"@typescript-eslint/parser": "
|
|
57
|
-
"acorn": "
|
|
58
|
-
"eslint": "
|
|
59
|
-
"eslint-config-prettier": "
|
|
60
|
-
"eslint-plugin-import": "
|
|
61
|
-
"eslint-plugin-node": "
|
|
62
|
-
"eslint-plugin-prettier": "
|
|
63
|
-
"eslint-plugin-react": "
|
|
64
|
-
"jest": "
|
|
65
|
-
"semantic-release": "
|
|
53
|
+
"@types/estree": "1.0.0",
|
|
54
|
+
"@types/jest": "29.2.5",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "5.48.1",
|
|
56
|
+
"@typescript-eslint/parser": "5.48.1",
|
|
57
|
+
"acorn": "8.8.1",
|
|
58
|
+
"eslint": "8.32.0",
|
|
59
|
+
"eslint-config-prettier": "8.6.0",
|
|
60
|
+
"eslint-plugin-import": "2.27.4",
|
|
61
|
+
"eslint-plugin-node": "11.1.0",
|
|
62
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
63
|
+
"eslint-plugin-react": "7.32.0",
|
|
64
|
+
"jest": "29.3.1",
|
|
65
|
+
"semantic-release": "20.0.2",
|
|
66
|
+
"typescript": "4.9.4"
|
|
66
67
|
}
|
|
67
68
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
5
|
-
"
|
|
3
|
+
"target": "ES2021",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
6
|
"declaration": true,
|
|
7
7
|
"outDir": "dist",
|
|
8
8
|
"strict": true,
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"exclude": [
|
|
13
13
|
"node_modules",
|
|
14
14
|
"dist",
|
|
15
|
-
"**/*.spec.*"
|
|
15
|
+
"**/*.spec.*",
|
|
16
|
+
"examples/**?*"
|
|
16
17
|
]
|
|
17
18
|
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ClassicJsxParser = void 0;
|
|
15
|
-
var ast_utils_1 = require("../ast.utils");
|
|
16
|
-
var ClassicJsxParser = /** @class */ (function () {
|
|
17
|
-
function ClassicJsxParser() {
|
|
18
|
-
}
|
|
19
|
-
ClassicJsxParser.prototype.isNodeReactFragment = function (node) {
|
|
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");
|
|
24
|
-
};
|
|
25
|
-
ClassicJsxParser.prototype.isNodeReactElement = function (node) {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
27
|
-
return ((node === null || node === void 0 ? void 0 : node.type) === "CallExpression" &&
|
|
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");
|
|
31
|
-
};
|
|
32
|
-
ClassicJsxParser.prototype.extendNodeWithAttributes = function (node, attr) {
|
|
33
|
-
var _this = this;
|
|
34
|
-
return __assign(__assign({}, node), { arguments: node === null || node === void 0 ? void 0 : node.arguments.map(function (v, i) {
|
|
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));
|
|
51
|
-
}
|
|
52
|
-
// Worst case override with
|
|
53
|
-
return (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode);
|
|
54
|
-
}) });
|
|
55
|
-
};
|
|
56
|
-
ClassicJsxParser.prototype.createAttributeNode = function (attr) {
|
|
57
|
-
return {
|
|
58
|
-
type: "Property",
|
|
59
|
-
method: false,
|
|
60
|
-
shorthand: false,
|
|
61
|
-
computed: false,
|
|
62
|
-
key: {
|
|
63
|
-
type: "Identifier",
|
|
64
|
-
name: "\"".concat(attr, "\""),
|
|
65
|
-
},
|
|
66
|
-
value: {
|
|
67
|
-
type: "Literal",
|
|
68
|
-
value: true,
|
|
69
|
-
raw: "true",
|
|
70
|
-
},
|
|
71
|
-
kind: "init",
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
return ClassicJsxParser;
|
|
75
|
-
}());
|
|
76
|
-
exports.ClassicJsxParser = ClassicJsxParser;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.NewJsxParser = void 0;
|
|
15
|
-
var ast_utils_1 = require("../ast.utils");
|
|
16
|
-
var NewJsxParser = /** @class */ (function () {
|
|
17
|
-
function NewJsxParser() {
|
|
18
|
-
}
|
|
19
|
-
NewJsxParser.prototype.isNodeReactFragment = function (node) {
|
|
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;
|
|
34
|
-
};
|
|
35
|
-
NewJsxParser.prototype.isNodeReactElement = function (node) {
|
|
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;
|
|
49
|
-
};
|
|
50
|
-
NewJsxParser.prototype.extendNodeWithAttributes = function (node, attr) {
|
|
51
|
-
var _this = this;
|
|
52
|
-
return __assign(__assign({}, node), { arguments: node === null || node === void 0 ? void 0 : node.arguments.map(function (v, i) {
|
|
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));
|
|
69
|
-
}
|
|
70
|
-
// Worst case override with
|
|
71
|
-
return (0, ast_utils_1.createObjectExpressionWithAttr)(attrNode);
|
|
72
|
-
}) });
|
|
73
|
-
};
|
|
74
|
-
NewJsxParser.prototype.createAttributeNode = function (attr) {
|
|
75
|
-
return {
|
|
76
|
-
type: "Property",
|
|
77
|
-
method: false,
|
|
78
|
-
shorthand: false,
|
|
79
|
-
computed: false,
|
|
80
|
-
key: {
|
|
81
|
-
type: "Identifier",
|
|
82
|
-
name: "\"".concat(attr, "\""),
|
|
83
|
-
},
|
|
84
|
-
value: {
|
|
85
|
-
type: "Literal",
|
|
86
|
-
value: true,
|
|
87
|
-
raw: "true",
|
|
88
|
-
},
|
|
89
|
-
kind: "init",
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
return NewJsxParser;
|
|
93
|
-
}());
|
|
94
|
-
exports.NewJsxParser = NewJsxParser;
|