rollup-plugin-react-scoped-css 0.4.1 → 0.5.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.
Files changed (36) hide show
  1. package/.github/workflows/pull-request.yml +19 -0
  2. package/.github/workflows/release.yml +30 -0
  3. package/.releaserc +12 -0
  4. package/README.md +25 -2
  5. package/dist/ast-iterator.d.ts +1 -0
  6. package/dist/ast-iterator.js +114 -0
  7. package/dist/ast-transformer.d.ts +1 -0
  8. package/dist/ast-transformer.js +50 -0
  9. package/dist/ast.utils.d.ts +4 -0
  10. package/dist/ast.utils.js +46 -108
  11. package/dist/index.js +12 -12
  12. package/dist/parsers/classic-parser.d.ts +3 -2
  13. package/dist/parsers/classic-parser.js +76 -19
  14. package/dist/parsers/jsx-parser.model.d.ts +0 -3
  15. package/dist/parsers/new-parser.d.ts +3 -2
  16. package/dist/parsers/new-parser.js +78 -21
  17. package/package.json +8 -3
  18. package/src/__mocks__/{compiled-jsx-with-attr.js → classic-compiled-jsx-with-attr.js} +0 -0
  19. package/src/__mocks__/{compiled-jsx.js → classic-compiled-jsx.js} +0 -0
  20. package/src/__mocks__/new-compiled-jsx-with-attr.js +101 -0
  21. package/src/__mocks__/new-compiled-jsx.js +64 -0
  22. package/src/__mocks__/sample-code-file.js +4 -0
  23. package/src/ast-iterator.spec.ts +19 -0
  24. package/src/ast-iterator.ts +27 -0
  25. package/src/ast-transformer.spec.ts +20 -0
  26. package/src/ast-transformer.ts +24 -0
  27. package/src/ast.utils.spec.ts +36 -12
  28. package/src/ast.utils.ts +32 -95
  29. package/src/parsers/classic-parser.ts +58 -0
  30. package/src/parsers/jsx-parser.model.ts +10 -0
  31. package/src/parsers/new-parser.ts +58 -0
  32. package/tsconfig.json +2 -1
  33. package/dist/parsers/base-parser.d.ts +0 -15
  34. package/dist/parsers/base-parser.js +0 -109
  35. package/dist/parsers/jsx-parser.interface.d.ts +0 -6
  36. package/dist/parsers/jsx-parser.interface.js +0 -2
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,30 @@
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/.releaserc ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "branches": ["main", "next"],
3
+ "plugins": [
4
+ "@semantic-release/commit-analyzer",
5
+ "@semantic-release/release-notes-generator",
6
+ "@semantic-release/npm",
7
+ ["@semantic-release/git", {
8
+ "assets": ["dist/**/*.{js,css}", "docs", "package.json"],
9
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
10
+ }]
11
+ ]
12
+ }
package/README.md CHANGED
@@ -1,10 +1,33 @@
1
1
  # rollup-plugin-react-scoped-css
2
2
 
3
- **IMPORTANT: This plugin is still in its early phase, use at your own risk, but feel free to contribute.**
4
-
5
3
  ## Motivations
6
4
  While using react in a professional context, I realized that it was lacking the scopped css feature that I learned to love from Vue and Angular. After some reasearch I came across good plugins, but sadly were not compatible with vite and/or rollup. Thus, I decided to create this plugin which was greatly inspired by the amazing work of [gaoxiaoliangz](https://github.com/gaoxiaoliangz) with his [react-scoped-css plugin](https://github.com/gaoxiaoliangz/react-scoped-css).
7
5
 
6
+ ## Usage
7
+
8
+ ```jsx
9
+ // Component.jsx
10
+ import './Component.scoped.scss'
11
+
12
+ export default function Sub() {
13
+ return (
14
+ <div className="wrap">
15
+ <h1>My Component</h1>
16
+ </div>
17
+ )
18
+ }
19
+ ```
20
+
21
+ ```jsx
22
+ // Component.scoped.jsx
23
+ .wrap {
24
+ width: 500px;
25
+ h1 { color: red; }
26
+ }
27
+ ```
28
+
29
+ And just like that the styles will be scoped to the component.
30
+
8
31
  ## How to install
9
32
 
10
33
  ```sh
@@ -0,0 +1 @@
1
+ export declare const astIterator: (ast: any) => IterableIterator<any>;
@@ -0,0 +1,114 @@
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
+ 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*/];
111
+ }
112
+ });
113
+ };
114
+ exports.astIterator = astIterator;
@@ -0,0 +1 @@
1
+ export declare const astTransformer: (ast: any, callback: Function) => any;
@@ -0,0 +1,50 @@
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;
17
+ 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';
21
+ };
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);
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
+ var result = callback(ast);
48
+ return typeof result !== 'undefined' ? result : ast;
49
+ };
50
+ exports.astTransformer = astTransformer;
@@ -1 +1,5 @@
1
+ import { ParserImplementations } from "./parsers/jsx-parser.model";
2
+ declare global {
3
+ var implementation: null | ParserImplementations;
4
+ }
1
5
  export declare function addHashAttributesToJsxTagsAst(program: any, attr: string): any;
package/dist/ast.utils.js CHANGED
@@ -1,122 +1,60 @@
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];
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 };
8
9
  }
9
- return t;
10
10
  };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
14
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
15
- to[j] = from[i];
16
- return to;
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
17
12
  };
18
13
  Object.defineProperty(exports, "__esModule", { value: true });
19
14
  exports.addHashAttributesToJsxTagsAst = void 0;
20
- /**
21
- * Traverses the AST tree and calls callback for each node.
22
- * -
23
- * @param ast The ast tree
24
- * @param callback Callback function to be called for each node
25
- * @returns
26
- */
27
- function traverse(ast, callback) {
28
- for (var _i = 0, _a = Object.keys(ast); _i < _a.length; _i++) {
29
- var key = _a[_i];
30
- if (['end', 'start', 'type'].includes(key)) {
31
- continue;
32
- }
33
- if (Array.isArray(ast[key])) {
34
- for (var nodeIndex in ast[key]) {
35
- ast[key][nodeIndex] = traverse(ast[key][nodeIndex], callback);
15
+ var ast_iterator_1 = require("./ast-iterator");
16
+ var ast_transformer_1 = require("./ast-transformer");
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;
27
+ try {
28
+ for (var _b = __values((0, ast_iterator_1.astIterator)(program)), _c = _b.next(); !_c.done; _c = _b.next()) {
29
+ var node = _c.value;
30
+ if (node.type !== 'ImportDeclaration') {
31
+ continue;
32
+ }
33
+ if (node.specifiers.some(function (n) { return n.local.name === 'jsxRuntime'; }) || node.source.value === 'react/jsx-runtime') {
34
+ return jsx_parser_model_1.ParserImplementations.new;
36
35
  }
37
36
  }
38
- else if (isNode(ast[key])) {
39
- ast[key] = traverse(ast[key], callback);
37
+ }
38
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
39
+ finally {
40
+ try {
41
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
40
42
  }
43
+ finally { if (e_1) throw e_1.error; }
41
44
  }
42
- var result = callback(ast);
43
- return typeof result !== 'undefined' ? result : ast;
44
- }
45
- function isNode(obj) {
46
- var _a, _b, _c;
47
- return typeof obj === 'object' &&
48
- typeof ((_a = obj) === null || _a === void 0 ? void 0 : _a.end) === 'number' &&
49
- typeof ((_b = obj) === null || _b === void 0 ? void 0 : _b.start) === 'number' &&
50
- typeof ((_c = obj) === null || _c === void 0 ? void 0 : _c.type) === 'string';
51
- }
52
- function isElementWithOldJsxTransform(node) {
53
- var _a, _b, _c, _d;
54
- return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' &&
55
- ((_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' &&
56
- ((_d = (_c = node === null || node === void 0 ? void 0 : node.callee) === null || _c === void 0 ? void 0 : _c.property) === null || _d === void 0 ? void 0 : _d.name) === 'createElement';
57
- }
58
- function isElementWithNewJsxTransform(node) {
59
- var _a;
60
- return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' &&
61
- ['_jsxDEV', '_jsx', '_jsxs'].includes((_a = node === null || node === void 0 ? void 0 : node.callee) === null || _a === void 0 ? void 0 : _a.name);
62
- }
63
- function isFragmentWithOldJsxTransform(node) {
64
- var _a, _b, _c, _d, _e, _f;
65
- return ((_c = (_b = (_a = node === null || node === void 0 ? void 0 : node.arguments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.object) === null || _c === void 0 ? void 0 : _c.name) === "React" &&
66
- ((_f = (_e = (_d = node === null || node === void 0 ? void 0 : node.arguments) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.property) === null || _f === void 0 ? void 0 : _f.name) === "Fragment";
67
- }
68
- function isFragmentWithNewJsxTransform(node) {
69
- var _a, _b, _c, _d;
70
- return ((_b = (_a = node.arguments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === "Identifier" &&
71
- ((_d = (_c = node.arguments) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) === "_Fragment";
72
- }
73
- function isFragment(node) {
74
- return isFragmentWithOldJsxTransform(node) ||
75
- isFragmentWithNewJsxTransform(node);
76
- }
77
- function isReactElement(node) {
78
- return isElementWithOldJsxTransform(node) ||
79
- isElementWithNewJsxTransform(node);
80
- }
81
- function createAttributeNode(attr) {
82
- return {
83
- type: 'Property',
84
- method: false,
85
- shorthand: false,
86
- computed: false,
87
- key: {
88
- type: 'Identifier',
89
- name: "\"" + attr + "\""
90
- },
91
- value: {
92
- type: 'Literal',
93
- value: true,
94
- raw: "true"
95
- },
96
- kind: 'init'
97
- };
98
- }
45
+ return implementation;
46
+ };
99
47
  function addHashAttributesToJsxTagsAst(program, attr) {
100
- return traverse(program, function (node) {
101
- var _a;
102
- if (isReactElement(node) && !isFragment(node)) {
103
- var arg_1 = (_a = node === null || node === void 0 ? void 0 : node.arguments) === null || _a === void 0 ? void 0 : _a[1];
104
- return __assign(__assign({}, node), { arguments: node === null || node === void 0 ? void 0 : node.arguments.map(function (v, i) {
105
- if (i === 1) {
106
- if (v.type === 'ObjectExpression') {
107
- return __assign(__assign({}, v), { properties: __spreadArray(__spreadArray([], arg_1.properties), [
108
- createAttributeNode(attr)
109
- ]) });
110
- }
111
- else {
112
- return {
113
- type: 'ObjectExpression',
114
- properties: [createAttributeNode(attr)]
115
- };
116
- }
117
- }
118
- return v;
119
- }) });
48
+ // Once in the program, we can determine which parser to use
49
+ if (global.implementation === null) {
50
+ global.implementation = findImplementation(program);
51
+ if (global.implementation === jsx_parser_model_1.ParserImplementations.new) {
52
+ parser = newParser;
53
+ }
54
+ }
55
+ return (0, ast_transformer_1.astTransformer)(program, function (node) {
56
+ if (parser.isNodeReactElement(node) && !parser.isNodeReactFragment(node)) {
57
+ return parser.extendNodeWithAttributes(node, attr);
120
58
  }
121
59
  });
122
60
  }
package/dist/index.js CHANGED
@@ -47,11 +47,11 @@ var getHashFromPath = function (filePath) {
47
47
  };
48
48
  var generateHash = function (input, seed) {
49
49
  if (seed === void 0) { seed = 0; }
50
- var hashNum = js_xxhash_1.xxHash32(Buffer.from(input, 'utf8'), seed);
50
+ var hashNum = (0, js_xxhash_1.xxHash32)(Buffer.from(input, 'utf8'), seed);
51
51
  return hashNum.toString(16);
52
52
  };
53
53
  var addAttributesToCss = function (src, fileName, hash) {
54
- var code = component_compiler_utils_1.compileStyle({
54
+ var code = (0, component_compiler_utils_1.compileStyle)({
55
55
  source: src,
56
56
  filename: fileName,
57
57
  id: hash,
@@ -69,14 +69,14 @@ function reactScopedCssPlugin(optionsIn) {
69
69
  if (!options.jsxFileExtensions || !options.jsxFileExtensions.length) {
70
70
  throw new Error('You need to provide at least one jsx file extension');
71
71
  }
72
- var filter = pluginutils_1.createFilter(options.include, options.exclude);
72
+ var filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
73
73
  var scopedCssRegex = options.styleFileSuffix
74
- ? new RegExp("." + options.styleFileSuffix + ".(" + options.styleFileExtensions.join('|') + ")$")
75
- : new RegExp(".(" + options.styleFileExtensions.join('|') + ")$");
74
+ ? new RegExp(".".concat(options.styleFileSuffix, ".(").concat(options.styleFileExtensions.join('|'), ")$"))
75
+ : new RegExp(".(".concat(options.styleFileExtensions.join('|'), ")$"));
76
76
  var scopedCssInFileRegex = options.styleFileSuffix
77
- ? new RegExp("." + options.styleFileSuffix + ".(" + options.styleFileExtensions.join('|') + ")(\"|')")
78
- : new RegExp(".(" + options.styleFileExtensions.join('|') + ")(\"|')");
79
- var jsxRegex = new RegExp(".(" + options.jsxFileExtensions.join('|') + ")$");
77
+ ? new RegExp(".".concat(options.styleFileSuffix, ".(").concat(options.styleFileExtensions.join('|'), ")(\"|')"))
78
+ : new RegExp(".(".concat(options.styleFileExtensions.join('|'), ")(\"|')"));
79
+ var jsxRegex = new RegExp(".(".concat(options.jsxFileExtensions.join('|'), ")$"));
80
80
  return [
81
81
  {
82
82
  name: 'rollup-plugin-react-scoped-css:pre',
@@ -86,7 +86,7 @@ function reactScopedCssPlugin(optionsIn) {
86
86
  }
87
87
  if (scopedCssRegex.test(source) && jsxRegex.test(importer)) {
88
88
  var importerHash = generateHash(importer);
89
- var url = path.resolve(path.dirname(importer), source + "?scope=" + importerHash);
89
+ var url = path.resolve(path.dirname(importer), "".concat(source, "?scope=").concat(importerHash));
90
90
  return url;
91
91
  }
92
92
  },
@@ -101,12 +101,12 @@ function reactScopedCssPlugin(optionsIn) {
101
101
  if (scopedCssInFileRegex.test(code)) {
102
102
  var importerHash = generateHash(id);
103
103
  var program = this.parse(code);
104
- var newAst = ast_utils_1.addHashAttributesToJsxTagsAst(program, "data-" + options.hashPrefix + "-" + importerHash);
105
- return escodegen_1.generate(newAst);
104
+ var newAst = (0, ast_utils_1.addHashAttributesToJsxTagsAst)(program, "data-".concat(options.hashPrefix, "-").concat(importerHash));
105
+ return (0, escodegen_1.generate)(newAst);
106
106
  }
107
107
  if (scopedCssRegex.test(getFilenameFromPath(id))) {
108
108
  var importerHash = getHashFromPath(id);
109
- return addAttributesToCss(code, getFilenameFromPath(id), "data-" + options.hashPrefix + "-" + importerHash);
109
+ return addAttributesToCss(code, getFilenameFromPath(id), "data-".concat(options.hashPrefix, "-").concat(importerHash));
110
110
  }
111
111
  }
112
112
  }
@@ -1,6 +1,7 @@
1
- import { BaseParser } from "./base-parser";
2
1
  import { JsxParser } from "./jsx-parser.model";
3
- export declare class ClassicJsxParser extends BaseParser implements JsxParser {
2
+ export declare class ClassicJsxParser implements JsxParser {
4
3
  isNodeReactFragment(node: any): boolean;
5
4
  isNodeReactElement(node: any): boolean;
5
+ extendNodeWithAttributes(node: any, attr: string): any;
6
+ private createAttributeNode;
6
7
  }
@@ -1,26 +1,44 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
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;
8
10
  };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
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
+ };
17
38
  Object.defineProperty(exports, "__esModule", { value: true });
18
39
  exports.ClassicJsxParser = void 0;
19
- var base_parser_1 = require("./base-parser");
20
- var ClassicJsxParser = /** @class */ (function (_super) {
21
- __extends(ClassicJsxParser, _super);
40
+ var ClassicJsxParser = /** @class */ (function () {
22
41
  function ClassicJsxParser() {
23
- return _super !== null && _super.apply(this, arguments) || this;
24
42
  }
25
43
  ClassicJsxParser.prototype.isNodeReactFragment = function (node) {
26
44
  var _a, _b, _c, _d, _e, _f;
@@ -33,6 +51,45 @@ var ClassicJsxParser = /** @class */ (function (_super) {
33
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' &&
34
52
  ((_d = (_c = node === null || node === void 0 ? void 0 : node.callee) === null || _c === void 0 ? void 0 : _c.property) === null || _d === void 0 ? void 0 : _d.name) === 'createElement';
35
53
  };
54
+ ClassicJsxParser.prototype.extendNodeWithAttributes = function (node, attr) {
55
+ 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
+ return __assign(__assign({}, node), { arguments: node === null || node === void 0 ? void 0 : node.arguments.map(function (v, i) {
59
+ if (i === 1) {
60
+ if (v.type === 'ObjectExpression') {
61
+ return __assign(__assign({}, v), { properties: __spreadArray(__spreadArray([], __read(arg.properties), false), [
62
+ _this.createAttributeNode(attr)
63
+ ], false) });
64
+ }
65
+ else {
66
+ return {
67
+ type: 'ObjectExpression',
68
+ properties: [_this.createAttributeNode(attr)]
69
+ };
70
+ }
71
+ }
72
+ return v;
73
+ }) });
74
+ };
75
+ ClassicJsxParser.prototype.createAttributeNode = function (attr) {
76
+ return {
77
+ type: 'Property',
78
+ method: false,
79
+ shorthand: false,
80
+ computed: false,
81
+ key: {
82
+ type: 'Identifier',
83
+ name: "\"".concat(attr, "\"")
84
+ },
85
+ value: {
86
+ type: 'Literal',
87
+ value: true,
88
+ raw: "true"
89
+ },
90
+ kind: 'init'
91
+ };
92
+ };
36
93
  return ClassicJsxParser;
37
- }(base_parser_1.BaseParser));
94
+ }());
38
95
  exports.ClassicJsxParser = ClassicJsxParser;
@@ -1,9 +1,6 @@
1
1
  export interface JsxParser {
2
2
  isNodeReactElement: (node: any) => boolean;
3
3
  isNodeReactFragment: (node: any) => boolean;
4
- isNode: (node: any) => boolean;
5
- traverse: (ast: any, callback: (ast: any) => void) => void;
6
- findImplementation: (ast: any) => ParserImplementations;
7
4
  extendNodeWithAttributes: (node: any, attr: string) => any;
8
5
  }
9
6
  export declare enum ParserImplementations {
@@ -1,6 +1,7 @@
1
- import { BaseParser } from "./base-parser";
2
1
  import { JsxParser } from "./jsx-parser.model";
3
- export declare class NewJsxParser extends BaseParser implements JsxParser {
2
+ export declare class NewJsxParser implements JsxParser {
4
3
  isNodeReactFragment(node: any): boolean;
5
4
  isNodeReactElement(node: any): boolean;
5
+ extendNodeWithAttributes(node: any, attr: string): any;
6
+ private createAttributeNode;
6
7
  }