@pi-r/babel 0.12.4 → 0.13.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/index.js +44 -11
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const path = require('node:path');
|
|
4
|
-
const { asFunction } = require('@e-mc/types');
|
|
5
|
-
const MATCH_PATTERN = ['babelrcRoots', 'include', 'exclude', 'ignore', 'only'];
|
|
6
|
-
|
|
4
|
+
const { asFunction, isPlainObject } = require('@e-mc/types');
|
|
5
|
+
const MATCH_PATTERN = ['babelrcRoots', 'include', 'exclude', 'ignore', 'only', 'test'];
|
|
6
|
+
const FUNCTION = ['wrapPluginVisitorMethod', 'shouldPrintComment'];
|
|
7
|
+
function checkMatchPattern(options, method) {
|
|
7
8
|
for (const attr of MATCH_PATTERN) {
|
|
8
9
|
if (attr in options) {
|
|
9
10
|
const value = options[attr];
|
|
10
11
|
if (typeof value === 'string') {
|
|
11
|
-
const out = parseString(value);
|
|
12
|
+
const out = parseString(value, method);
|
|
12
13
|
if (out !== null) {
|
|
13
14
|
options[attr] = [out];
|
|
14
15
|
}
|
|
@@ -17,7 +18,7 @@ function checkMatchPattern(options) {
|
|
|
17
18
|
for (let i = 0; i < value.length; i++) {
|
|
18
19
|
const item = value[i];
|
|
19
20
|
if (typeof item === 'string') {
|
|
20
|
-
const out = parseString(item);
|
|
21
|
+
const out = parseString(item, method);
|
|
21
22
|
if (out !== null) {
|
|
22
23
|
value[i] = out;
|
|
23
24
|
}
|
|
@@ -26,9 +27,21 @@ function checkMatchPattern(options) {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
return options;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function checkFunction(options) {
|
|
32
|
+
for (const attr of FUNCTION) {
|
|
33
|
+
if (attr in options) {
|
|
34
|
+
const value = options[attr];
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
const out = asFunction(value);
|
|
37
|
+
if (out) {
|
|
38
|
+
options[attr] = out;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function parseString(value, method) {
|
|
32
45
|
if (/^\/(?:[^/]|(?<=\\)\/)+\/[dgimsuvy]*$/.test(value)) {
|
|
33
46
|
if (!value.includes('**')) {
|
|
34
47
|
try {
|
|
@@ -42,12 +55,19 @@ function parseString(value) {
|
|
|
42
55
|
}
|
|
43
56
|
return null;
|
|
44
57
|
}
|
|
45
|
-
return asFunction(value);
|
|
58
|
+
return method ? asFunction(value) : null;
|
|
46
59
|
}
|
|
47
60
|
function transform(context, value, options) {
|
|
48
61
|
context = options.upgrade(context, __dirname, '@babel/core');
|
|
49
62
|
const { sourceMap, supplementChunks } = options;
|
|
50
|
-
const baseConfig =
|
|
63
|
+
const baseConfig = options.toBaseConfig();
|
|
64
|
+
if (options.hasEval('function')) {
|
|
65
|
+
checkMatchPattern(baseConfig, true);
|
|
66
|
+
checkFunction(baseConfig);
|
|
67
|
+
}
|
|
68
|
+
else if (options.hasEval('regexp')) {
|
|
69
|
+
checkMatchPattern(baseConfig, false);
|
|
70
|
+
}
|
|
51
71
|
let url;
|
|
52
72
|
if (baseConfig.sourceMaps === false) {
|
|
53
73
|
sourceMap.reset();
|
|
@@ -63,6 +83,19 @@ function transform(context, value, options) {
|
|
|
63
83
|
}
|
|
64
84
|
baseConfig.filename ||= options.filename;
|
|
65
85
|
baseConfig.sourceType ||= options.imported ? 'module' : 'script';
|
|
86
|
+
const plugins = baseConfig.plugins;
|
|
87
|
+
if (Array.isArray(plugins)) {
|
|
88
|
+
for (let i = 0; i < plugins.length; ++i) {
|
|
89
|
+
const item = plugins[i];
|
|
90
|
+
if (Array.isArray(item) && item.length === 2 && isPlainObject(item[1]) && (item[1].type === 'plugin' || item[1].type === 'preset') && Object.keys(item[1]).filter(key => key !== 'type' && key !== 'dirname').length === 0) {
|
|
91
|
+
try {
|
|
92
|
+
plugins[i] = context.createConfigItemSync(item[0], item[1]);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
66
99
|
if (!baseConfig.cwd) {
|
|
67
100
|
const esmData = options.getMainFile(value);
|
|
68
101
|
if (esmData?.code) {
|
|
@@ -77,7 +110,7 @@ function transform(context, value, options) {
|
|
|
77
110
|
chunkConfig.sourceFileName = chunk.filename;
|
|
78
111
|
}
|
|
79
112
|
chunkConfig.filename = chunk.filename;
|
|
80
|
-
const result = context.
|
|
113
|
+
const result = context.transformSync(value, chunkConfig);
|
|
81
114
|
if (result) {
|
|
82
115
|
const { code, map } = result;
|
|
83
116
|
if (code) {
|
|
@@ -92,7 +125,7 @@ function transform(context, value, options) {
|
|
|
92
125
|
}
|
|
93
126
|
}
|
|
94
127
|
options.out.ignoreCache = baseConfig.sourceType === 'module' || baseConfig.sourceType === 'unambiguous';
|
|
95
|
-
const result = context.
|
|
128
|
+
const result = context.transformSync(value, baseConfig);
|
|
96
129
|
const code = result?.code;
|
|
97
130
|
if (code) {
|
|
98
131
|
if (result.map) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/babel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Babel transform function for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@babel/core": "^
|
|
20
|
-
"@e-mc/types": "^0.14.
|
|
19
|
+
"@babel/core": "^8.0.1",
|
|
20
|
+
"@e-mc/types": "^0.14.6"
|
|
21
21
|
}
|
|
22
22
|
}
|