@pi-r/babel 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +45 -1
  2. package/package.json +3 -2
package/index.js CHANGED
@@ -1,9 +1,53 @@
1
1
  "use strict";
2
2
  const path = require("path");
3
+ const types_1 = require("@e-mc/types");
4
+ const REGEXP_LITERAL = /^\/[^/]+\/[dgimsuvy]*$/;
5
+ const MATCH_PATTERN = ['babelrcRoots', 'include', 'exclude', 'ignore', 'only'];
6
+ function checkMatchPattern(options) {
7
+ for (const attr of MATCH_PATTERN) {
8
+ if (attr in options) {
9
+ const value = options[attr];
10
+ if (typeof value === 'string') {
11
+ const out = parseString(value);
12
+ if (out !== null) {
13
+ options[attr] = out;
14
+ }
15
+ }
16
+ else if (Array.isArray(value)) {
17
+ for (let i = 0; i < value.length; i++) {
18
+ const item = value[i];
19
+ if (typeof item === 'string') {
20
+ const out = parseString(item);
21
+ if (out !== null) {
22
+ value[i] = out;
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ return options;
30
+ }
31
+ function parseString(value) {
32
+ if (REGEXP_LITERAL.test(value)) {
33
+ if (!value.includes('**')) {
34
+ try {
35
+ const pattern = eval(value);
36
+ if (pattern instanceof RegExp) {
37
+ return pattern;
38
+ }
39
+ }
40
+ catch {
41
+ }
42
+ }
43
+ return null;
44
+ }
45
+ return (0, types_1.asFunction)(value);
46
+ }
3
47
  function transform(context, value, options) {
4
48
  context = options.upgrade(context, __dirname, '@babel/core');
5
49
  const { sourceMap, supplementChunks } = options;
6
- const baseConfig = options.toBaseConfig();
50
+ const baseConfig = checkMatchPattern(options.toBaseConfig());
7
51
  let url;
8
52
  if (baseConfig.sourceMaps === false) {
9
53
  sourceMap.reset();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/babel",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Babel transform function for E-mc.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -20,6 +20,7 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@babel/core": "^7.25.2"
23
+ "@babel/core": "^7.25.2",
24
+ "@e-mc/types": "^0.10.0"
24
25
  }
25
26
  }