rollup-plugin-react-scoped-css 0.4.1 → 0.6.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 (41) hide show
  1. package/.eslintrc.yml +29 -0
  2. package/.github/workflows/pull-request.yml +20 -0
  3. package/.github/workflows/release.yml +30 -0
  4. package/.releaserc +13 -0
  5. package/.vscode/settings.json +8 -0
  6. package/README.md +55 -7
  7. package/babel.config.js +6 -2
  8. package/dist/ast-iterator.d.ts +1 -0
  9. package/dist/ast-iterator.js +114 -0
  10. package/dist/ast-transformer.d.ts +1 -0
  11. package/dist/ast-transformer.js +50 -0
  12. package/dist/ast.utils.d.ts +4 -0
  13. package/dist/ast.utils.js +49 -108
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +24 -23
  16. package/dist/parsers/classic-parser.d.ts +3 -2
  17. package/dist/parsers/classic-parser.js +87 -24
  18. package/dist/parsers/jsx-parser.model.d.ts +0 -3
  19. package/dist/parsers/new-parser.d.ts +3 -2
  20. package/dist/parsers/new-parser.js +86 -23
  21. package/package.json +18 -3
  22. package/src/__mocks__/{compiled-jsx-with-attr.js → classic-compiled-jsx-with-attr.js} +0 -0
  23. package/src/__mocks__/{compiled-jsx.js → classic-compiled-jsx.js} +0 -0
  24. package/src/__mocks__/new-compiled-jsx-with-attr.js +101 -0
  25. package/src/__mocks__/new-compiled-jsx.js +64 -0
  26. package/src/__mocks__/sample-code-file.js +4 -0
  27. package/src/ast-iterator.spec.ts +22 -0
  28. package/src/ast-iterator.ts +32 -0
  29. package/src/ast-transformer.spec.ts +23 -0
  30. package/src/ast-transformer.ts +28 -0
  31. package/src/ast.utils.spec.ts +59 -20
  32. package/src/ast.utils.ts +41 -99
  33. package/src/index.ts +77 -57
  34. package/src/parsers/classic-parser.ts +72 -0
  35. package/src/parsers/jsx-parser.model.ts +10 -0
  36. package/src/parsers/new-parser.ts +74 -0
  37. package/tsconfig.json +2 -1
  38. package/dist/parsers/base-parser.d.ts +0 -15
  39. package/dist/parsers/base-parser.js +0 -109
  40. package/dist/parsers/jsx-parser.interface.d.ts +0 -6
  41. package/dist/parsers/jsx-parser.interface.js +0 -2
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
30
30
  return result;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
+ /* eslint-disable no-useless-escape */
33
34
  var path = __importStar(require("path"));
34
35
  var js_xxhash_1 = require("js-xxhash");
35
36
  var pluginutils_1 = require("@rollup/pluginutils");
@@ -37,21 +38,21 @@ var component_compiler_utils_1 = require("@vue/component-compiler-utils");
37
38
  var escodegen_1 = require("escodegen");
38
39
  var ast_utils_1 = require("./ast.utils");
39
40
  var getFilenameFromPath = function (filePath) {
40
- var parts = filePath.split('/');
41
- return parts[parts.length - 1].split('?')[0];
41
+ var parts = filePath.split("/");
42
+ return parts[parts.length - 1].split("?")[0];
42
43
  };
43
44
  var getHashFromPath = function (filePath) {
44
- var search = '?scope=';
45
+ var search = "?scope=";
45
46
  var hash = filePath.slice(filePath.indexOf(search) + search.length);
46
47
  return hash;
47
48
  };
48
49
  var generateHash = function (input, seed) {
49
50
  if (seed === void 0) { seed = 0; }
50
- var hashNum = js_xxhash_1.xxHash32(Buffer.from(input, 'utf8'), seed);
51
+ var hashNum = (0, js_xxhash_1.xxHash32)(Buffer.from(input, "utf8"), seed);
51
52
  return hashNum.toString(16);
52
53
  };
53
54
  var addAttributesToCss = function (src, fileName, hash) {
54
- var code = component_compiler_utils_1.compileStyle({
55
+ var code = (0, component_compiler_utils_1.compileStyle)({
55
56
  source: src,
56
57
  filename: fileName,
57
58
  id: hash,
@@ -62,38 +63,38 @@ var addAttributesToCss = function (src, fileName, hash) {
62
63
  };
63
64
  function reactScopedCssPlugin(optionsIn) {
64
65
  if (optionsIn === void 0) { optionsIn = {}; }
65
- var options = __assign({ hashPrefix: 'v', styleFileSuffix: 'scoped', styleFileExtensions: ['scss', 'css', 'sass', 'less'], jsxFileExtensions: ['jsx', 'tsx'] }, optionsIn);
66
+ var options = __assign({ hashPrefix: "v", styleFileSuffix: "scoped", styleFileExtensions: ["scss", "css", "sass", "less"], jsxFileExtensions: ["jsx", "tsx"] }, optionsIn);
66
67
  if (!options.styleFileExtensions || !options.styleFileExtensions.length) {
67
- throw new Error('You need to provide at least one style file extension');
68
+ throw new Error("You need to provide at least one style file extension");
68
69
  }
69
70
  if (!options.jsxFileExtensions || !options.jsxFileExtensions.length) {
70
- throw new Error('You need to provide at least one jsx file extension');
71
+ throw new Error("You need to provide at least one jsx file extension");
71
72
  }
72
- var filter = pluginutils_1.createFilter(options.include, options.exclude);
73
+ var filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
73
74
  var scopedCssRegex = options.styleFileSuffix
74
- ? new RegExp("." + options.styleFileSuffix + ".(" + options.styleFileExtensions.join('|') + ")$")
75
- : new RegExp(".(" + options.styleFileExtensions.join('|') + ")$");
75
+ ? new RegExp(".".concat(options.styleFileSuffix, ".(").concat(options.styleFileExtensions.join("|"), ")$"))
76
+ : new RegExp(".(".concat(options.styleFileExtensions.join("|"), ")$"));
76
77
  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('|') + ")$");
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("|"), ")$"));
80
81
  return [
81
82
  {
82
- name: 'rollup-plugin-react-scoped-css:pre',
83
+ name: "rollup-plugin-react-scoped-css:pre",
83
84
  resolveId: function (source, importer) {
84
85
  if (!importer) {
85
86
  return;
86
87
  }
87
88
  if (scopedCssRegex.test(source) && jsxRegex.test(importer)) {
88
89
  var importerHash = generateHash(importer);
89
- var url = path.resolve(path.dirname(importer), source + "?scope=" + importerHash);
90
+ var url = path.resolve(path.dirname(importer), "".concat(source, "?scope=").concat(importerHash));
90
91
  return url;
91
92
  }
92
93
  },
93
- enforce: 'pre'
94
+ enforce: "pre",
94
95
  },
95
96
  {
96
- name: 'rollup-plugin-react-scoped-css:post',
97
+ name: "rollup-plugin-react-scoped-css:post",
97
98
  transform: function (code, id) {
98
99
  if (!filter(id)) {
99
100
  return;
@@ -101,15 +102,15 @@ function reactScopedCssPlugin(optionsIn) {
101
102
  if (scopedCssInFileRegex.test(code)) {
102
103
  var importerHash = generateHash(id);
103
104
  var program = this.parse(code);
104
- var newAst = ast_utils_1.addHashAttributesToJsxTagsAst(program, "data-" + options.hashPrefix + "-" + importerHash);
105
- return escodegen_1.generate(newAst);
105
+ var newAst = (0, ast_utils_1.addHashAttributesToJsxTagsAst)(program, "data-".concat(options.hashPrefix, "-").concat(importerHash));
106
+ return (0, escodegen_1.generate)(newAst);
106
107
  }
107
108
  if (scopedCssRegex.test(getFilenameFromPath(id))) {
108
109
  var importerHash = getHashFromPath(id);
109
- return addAttributesToCss(code, getFilenameFromPath(id), "data-" + options.hashPrefix + "-" + importerHash);
110
+ return addAttributesToCss(code, getFilenameFromPath(id), "data-".concat(options.hashPrefix, "-").concat(importerHash));
110
111
  }
111
- }
112
- }
112
+ },
113
+ },
113
114
  ];
114
115
  }
115
116
  exports.default = reactScopedCssPlugin;
@@ -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,38 +1,101 @@
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;
27
- 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" &&
28
- ((_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";
45
+ 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" &&
46
+ ((_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");
29
47
  };
30
48
  ClassicJsxParser.prototype.isNodeReactElement = function (node) {
31
49
  var _a, _b, _c, _d;
32
- return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' &&
33
- ((_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
- ((_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';
50
+ return ((node === null || node === void 0 ? void 0 : node.type) === "CallExpression" &&
51
+ ((_b = (_a = node === null || node === void 0 ? void 0 : node.callee) === null || _a === void 0 ? void 0 : _a.object) === null || _b === void 0 ? void 0 : _b.name) === "React" &&
52
+ ((_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");
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), [_this.createAttributeNode(attr)], false) });
62
+ }
63
+ else if (v.type === "CallExpression" &&
64
+ v.callee.name === "_objectSpread") {
65
+ var args = __spreadArray([], __read(v.arguments), false);
66
+ args[0].properties = __spreadArray(__spreadArray([], __read(args[0].properties), false), [
67
+ _this.createAttributeNode(attr),
68
+ ], false);
69
+ return __assign(__assign({}, v), { arguments: args });
70
+ }
71
+ else {
72
+ return {
73
+ type: "ObjectExpression",
74
+ properties: [_this.createAttributeNode(attr)],
75
+ };
76
+ }
77
+ }
78
+ return v;
79
+ }) });
80
+ };
81
+ ClassicJsxParser.prototype.createAttributeNode = function (attr) {
82
+ return {
83
+ type: "Property",
84
+ method: false,
85
+ shorthand: false,
86
+ computed: false,
87
+ key: {
88
+ type: "Identifier",
89
+ name: "\"".concat(attr, "\""),
90
+ },
91
+ value: {
92
+ type: "Literal",
93
+ value: true,
94
+ raw: "true",
95
+ },
96
+ kind: "init",
97
+ };
35
98
  };
36
99
  return ClassicJsxParser;
37
- }(base_parser_1.BaseParser));
100
+ }());
38
101
  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
  }
@@ -1,37 +1,100 @@
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.NewJsxParser = void 0;
19
- var base_parser_1 = require("./base-parser");
20
- var NewJsxParser = /** @class */ (function (_super) {
21
- __extends(NewJsxParser, _super);
40
+ var NewJsxParser = /** @class */ (function () {
22
41
  function NewJsxParser() {
23
- return _super !== null && _super.apply(this, arguments) || this;
24
42
  }
25
43
  NewJsxParser.prototype.isNodeReactFragment = function (node) {
26
44
  var _a, _b, _c, _d;
27
- return ((_b = (_a = node.arguments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === "Identifier" &&
28
- ((_d = (_c = node.arguments) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name) === "_Fragment";
45
+ return (((_b = (_a = node.arguments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === "Identifier" &&
46
+ ["_Fragment", "Fragment"].includes((_d = (_c = node.arguments) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.name));
29
47
  };
30
48
  NewJsxParser.prototype.isNodeReactElement = function (node) {
31
49
  var _a;
32
- return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' &&
33
- ['_jsxDEV', '_jsx', '_jsxs'].includes((_a = node === null || node === void 0 ? void 0 : node.callee) === null || _a === void 0 ? void 0 : _a.name);
50
+ return ((node === null || node === void 0 ? void 0 : node.type) === "CallExpression" &&
51
+ ["_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));
52
+ };
53
+ NewJsxParser.prototype.extendNodeWithAttributes = function (node, attr) {
54
+ var _this = this;
55
+ var _a;
56
+ var arg = (_a = node === null || node === void 0 ? void 0 : node.arguments) === null || _a === void 0 ? void 0 : _a[1];
57
+ return __assign(__assign({}, node), { arguments: node === null || node === void 0 ? void 0 : node.arguments.map(function (v, i) {
58
+ if (i === 1) {
59
+ if (v.type === "ObjectExpression") {
60
+ return __assign(__assign({}, v), { properties: __spreadArray(__spreadArray([], __read(arg.properties), false), [_this.createAttributeNode(attr)], false) });
61
+ }
62
+ else if (v.type === "CallExpression" &&
63
+ v.callee.name === "_objectSpread") {
64
+ var args = __spreadArray([], __read(v.arguments), false);
65
+ args[0].properties = __spreadArray(__spreadArray([], __read(args[0].properties), false), [
66
+ _this.createAttributeNode(attr),
67
+ ], false);
68
+ return __assign(__assign({}, v), { arguments: args });
69
+ }
70
+ else {
71
+ return {
72
+ type: "ObjectExpression",
73
+ properties: [_this.createAttributeNode(attr)],
74
+ };
75
+ }
76
+ }
77
+ return v;
78
+ }) });
79
+ };
80
+ NewJsxParser.prototype.createAttributeNode = function (attr) {
81
+ return {
82
+ type: "Property",
83
+ method: false,
84
+ shorthand: false,
85
+ computed: false,
86
+ key: {
87
+ type: "Identifier",
88
+ name: "\"".concat(attr, "\""),
89
+ },
90
+ value: {
91
+ type: "Literal",
92
+ value: true,
93
+ raw: "true",
94
+ },
95
+ kind: "init",
96
+ };
34
97
  };
35
98
  return NewJsxParser;
36
- }(base_parser_1.BaseParser));
99
+ }());
37
100
  exports.NewJsxParser = NewJsxParser;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "rollup-plugin-react-scoped-css",
3
- "version": "0.4.1",
3
+ "version": "0.6.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
7
  "scripts": {
8
8
  "build": "tsc",
9
9
  "build:watch": "tsc --watch",
10
- "prepare": "npm run build && npm test",
10
+ "lint": "eslint '*/**/*.{js,jsx,ts,tsx}'",
11
11
  "test": "jest"
12
12
  },
13
13
  "repository": {
@@ -42,9 +42,24 @@
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.15.0",
44
44
  "@babel/preset-typescript": "^7.15.0",
45
+ "@semantic-release/commit-analyzer": "^9.0.2",
46
+ "@semantic-release/git": "^10.0.1",
47
+ "@semantic-release/github": "^8.0.2",
48
+ "@semantic-release/npm": "^8.0.3",
49
+ "@semantic-release/release-notes-generator": "^10.0.3",
45
50
  "@types/escodegen": "0.0.7",
46
51
  "@types/estree": "0.0.50",
47
52
  "@types/jest": "^27.0.1",
48
- "jest": "^27.0.6"
53
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
54
+ "@typescript-eslint/parser": "^5.5.0",
55
+ "acorn": "^8.6.0",
56
+ "eslint": "^8.3.0",
57
+ "eslint-config-prettier": "^8.3.0",
58
+ "eslint-plugin-import": "^2.25.3",
59
+ "eslint-plugin-node": "^11.1.0",
60
+ "eslint-plugin-prettier": "^4.0.0",
61
+ "eslint-plugin-react": "^7.27.1",
62
+ "jest": "^27.0.6",
63
+ "semantic-release": "^18.0.1"
49
64
  }
50
65
  }
@@ -0,0 +1,101 @@
1
+ import {
2
+ j as jsxRuntime,
3
+ r as react,
4
+ R as ReactDOM,
5
+ a as React
6
+ } from "./vendor.1137a3d7.js";
7
+ var index = "body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n";
8
+ var App$1 = ".sub {\n color: green;\n}";
9
+ var App_scoped = ".App {\n text-align: center;\n}\n\n.sub {\n color: blue !important;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n\nbutton {\n font-size: calc(10px + 2vmin);\n}\n";
10
+ var logo = "/assets/logo.ecc203fb.svg";
11
+ var Sub_scoped = ".sub {\n color: red;\n}\n.sub__test {\n margin: 0;\n}\n.sub h2 {\n font-weight: 300;\n font-size: 3rem;\n}\n\nh2 {\n font-size: 10rem;\n}\n\n.drawer {\n width: 400px;\n}\n.drawer__list-item {\n padding: 0;\n}\n.drawer__list-item-icon {\n margin-right: 1rem;\n}\n.drawer__link {\n display: flex;\n width: 300px;\n padding: 1rem;\n align-items: center;\n text-decoration: none;\n border: 0;\n outline: 0;\n background: transparent;\n font-family: \"Quicksand\", \"Roboto\", sans-serif;\n font-size: 1rem;\n font-weight: 400;\n}\n.drawer__link:hover {\n background-color: #fafafa;\n}";
12
+ const jsx = jsxRuntime.exports.jsx;
13
+ const jsxs = jsxRuntime.exports.jsxs;
14
+ const Fragment = jsxRuntime.exports.Fragment;
15
+ function Sub() {
16
+ return jsx("div", {
17
+ className: "sub",
18
+ children: jsx("h2", {
19
+ children: "Sub",
20
+ "data-v-123456": true
21
+ }),
22
+ "data-v-123456": true
23
+ });
24
+ }
25
+ function App() {
26
+ const [count, setCount] = react.exports.useState(0);
27
+ return jsx(Fragment, {
28
+ children: jsxs("div", {
29
+ className: "App",
30
+ children: [
31
+ jsxs("header", {
32
+ className: "App-header",
33
+ children: [
34
+ jsx("img", {
35
+ src: logo,
36
+ className: "App-logo",
37
+ alt: "logo",
38
+ "data-v-123456": true
39
+ }),
40
+ jsx("p", {
41
+ children: "Hello Vite + React!",
42
+ "data-v-123456": true
43
+ }),
44
+ jsx("p", {
45
+ children: jsxs("button", {
46
+ type: "button",
47
+ onClick: () => setCount(count2 => count2 + 1),
48
+ children: [
49
+ "count is: ",
50
+ count
51
+ ],
52
+ "data-v-123456": true
53
+ }),
54
+ "data-v-123456": true
55
+ }),
56
+ jsxs("p", {
57
+ children: [
58
+ "Edit ",
59
+ jsx("code", {
60
+ children: "App.jsx",
61
+ "data-v-123456": true
62
+ }),
63
+ " and save to test HMR updates."
64
+ ],
65
+ "data-v-123456": true
66
+ }),
67
+ jsxs("p", {
68
+ children: [
69
+ jsx("a", {
70
+ className: "App-link",
71
+ href: "https://reactjs.org",
72
+ target: "_blank",
73
+ rel: "noopener noreferrer",
74
+ children: "Learn React",
75
+ "data-v-123456": true
76
+ }),
77
+ " | ",
78
+ jsx("a", {
79
+ className: "App-link",
80
+ href: "https://vitejs.dev/guide/features.html",
81
+ target: "_blank",
82
+ rel: "noopener noreferrer",
83
+ children: "Vite Docs",
84
+ "data-v-123456": true
85
+ })
86
+ ],
87
+ "data-v-123456": true
88
+ })
89
+ ],
90
+ "data-v-123456": true
91
+ }),
92
+ jsx(Fragment, { children: jsx(Sub, { "data-v-123456": true }) })
93
+ ],
94
+ "data-v-123456": true
95
+ })
96
+ });
97
+ }
98
+ ReactDOM.render(jsx(React.StrictMode, {
99
+ children: jsx(App, { "data-v-123456": true }),
100
+ "data-v-123456": true
101
+ }), document.getElementById("root"));
@@ -0,0 +1,64 @@
1
+ import { j as jsxRuntime, r as react, R as ReactDOM, a as React } from "./vendor.1137a3d7.js";
2
+ var index = "body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n";
3
+ var App$1 = ".sub {\n color: green;\n}";
4
+ var App_scoped = ".App {\n text-align: center;\n}\n\n.sub {\n color: blue !important;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n\nbutton {\n font-size: calc(10px + 2vmin);\n}\n";
5
+ var logo = "/assets/logo.ecc203fb.svg";
6
+ var Sub_scoped = '.sub {\n color: red;\n}\n.sub__test {\n margin: 0;\n}\n.sub h2 {\n font-weight: 300;\n font-size: 3rem;\n}\n\nh2 {\n font-size: 10rem;\n}\n\n.drawer {\n width: 400px;\n}\n.drawer__list-item {\n padding: 0;\n}\n.drawer__list-item-icon {\n margin-right: 1rem;\n}\n.drawer__link {\n display: flex;\n width: 300px;\n padding: 1rem;\n align-items: center;\n text-decoration: none;\n border: 0;\n outline: 0;\n background: transparent;\n font-family: "Quicksand", "Roboto", sans-serif;\n font-size: 1rem;\n font-weight: 400;\n}\n.drawer__link:hover {\n background-color: #fafafa;\n}';
7
+ const jsx = jsxRuntime.exports.jsx;
8
+ const jsxs = jsxRuntime.exports.jsxs;
9
+ const Fragment = jsxRuntime.exports.Fragment;
10
+ function Sub() {
11
+ return /* @__PURE__ */ jsx("div", {
12
+ className: "sub",
13
+ children: /* @__PURE__ */ jsx("h2", {
14
+ children: "Sub"
15
+ })
16
+ });
17
+ }
18
+ function App() {
19
+ const [count, setCount] = react.exports.useState(0);
20
+ return /* @__PURE__ */ jsx(Fragment, {
21
+ children: /* @__PURE__ */ jsxs("div", {
22
+ className: "App",
23
+ children: [/* @__PURE__ */ jsxs("header", {
24
+ className: "App-header",
25
+ children: [/* @__PURE__ */ jsx("img", {
26
+ src: logo,
27
+ className: "App-logo",
28
+ alt: "logo"
29
+ }), /* @__PURE__ */ jsx("p", {
30
+ children: "Hello Vite + React!"
31
+ }), /* @__PURE__ */ jsx("p", {
32
+ children: /* @__PURE__ */ jsxs("button", {
33
+ type: "button",
34
+ onClick: () => setCount((count2) => count2 + 1),
35
+ children: ["count is: ", count]
36
+ })
37
+ }), /* @__PURE__ */ jsxs("p", {
38
+ children: ["Edit ", /* @__PURE__ */ jsx("code", {
39
+ children: "App.jsx"
40
+ }), " and save to test HMR updates."]
41
+ }), /* @__PURE__ */ jsxs("p", {
42
+ children: [/* @__PURE__ */ jsx("a", {
43
+ className: "App-link",
44
+ href: "https://reactjs.org",
45
+ target: "_blank",
46
+ rel: "noopener noreferrer",
47
+ children: "Learn React"
48
+ }), " | ", /* @__PURE__ */ jsx("a", {
49
+ className: "App-link",
50
+ href: "https://vitejs.dev/guide/features.html",
51
+ target: "_blank",
52
+ rel: "noopener noreferrer",
53
+ children: "Vite Docs"
54
+ })]
55
+ })]
56
+ }), /* @__PURE__ */ jsx(Fragment, {
57
+ children: /* @__PURE__ */ jsx(Sub, {})
58
+ })]
59
+ })
60
+ });
61
+ }
62
+ ReactDOM.render(/* @__PURE__ */ jsx(React.StrictMode, {
63
+ children: /* @__PURE__ */ jsx(App, {})
64
+ }), document.getElementById("root"));
@@ -0,0 +1,4 @@
1
+ let array = [1, 2, 3];
2
+
3
+ const multiply = (arr) => arr.map(x => x * 2);
4
+ const newArray = multiply(array);
@@ -0,0 +1,22 @@
1
+ import { readFile } from "fs/promises";
2
+ import { resolve } from "path";
3
+ import { parse } from "acorn";
4
+ import { astIterator } from "./ast-iterator";
5
+
6
+ describe("astIterator", () => {
7
+ it("should iterate through all nodes", async () => {
8
+ let iterationCount = 0;
9
+ const file = await readFile(
10
+ resolve(__dirname, "./__mocks__/sample-code-file.js"),
11
+ { encoding: "utf-8" }
12
+ );
13
+ const ast = parse(file, { sourceType: "module", ecmaVersion: 2022 });
14
+
15
+ for (const node of astIterator(ast)) {
16
+ iterationCount++;
17
+ expect(node).toBeTruthy();
18
+ }
19
+
20
+ expect(iterationCount).toBe(28);
21
+ });
22
+ });