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