@makano/rew 1.2.88 → 1.2.90
Sign up to get free protection for your applications and to get access to all the features.
package/lib/rew/const/usage.js
CHANGED
@@ -139,7 +139,7 @@ function declareAlias(aliases, token) {
|
|
139
139
|
straceLog('==> DECLARE', name, 'as', value);
|
140
140
|
|
141
141
|
let aliasValue = value.startsWith('${')
|
142
|
-
? new Function('token', 'tokens', 'code', 'hooks', value.slice(2, -1))
|
142
|
+
? new Function('token', 'tokens', 'code', 'hooks', 'index', 'setIndex', value.slice(2, -1))
|
143
143
|
: value;
|
144
144
|
|
145
145
|
|
@@ -172,7 +172,7 @@ function declareAlias(aliases, token) {
|
|
172
172
|
let nextToken = gnextToken(index, offset+1, tokens);
|
173
173
|
const args = nextToken.token.value;
|
174
174
|
setIndex(ti + offset);
|
175
|
-
return `${nextToken2.value} = ${token.value}
|
175
|
+
return `${nextToken2.value} = ${token.value} ${args && args !== '(' ? `${args},` : ''} ${params.trim()}, ${args == '(' ? args : ''}`;
|
176
176
|
} else if(nextToken?.value == ' ' && (isDecOnly || nextToken2?.token.value == '=' || nextToken2?.token.value == ':')){
|
177
177
|
nextToken.value = '';
|
178
178
|
if(isDecOnly){
|
@@ -247,7 +247,7 @@ function useImp(token, options){
|
|
247
247
|
token.value = dem+packageName+dem;
|
248
248
|
const file = packageName.startsWith('./') || packageName.startsWith('../');
|
249
249
|
if(!(file) && packageName.match('/')) packageName = packageName.split('/').pop();
|
250
|
-
if(file) packageName = packageName.replace(path.extname(packageName), '.h.coffee');
|
250
|
+
if(file) packageName = path.extname(packageName) ? packageName.replace(path.extname(packageName), '.h.coffee') : packageName;
|
251
251
|
if(file && !packageName.endsWith('.h.coffee')) packageName += '.h.coffee';
|
252
252
|
straceLog('IMP() with HEADER for', packageName);
|
253
253
|
return includeFile(packageName, options);
|
@@ -540,8 +540,6 @@ const compileCivetStuff = (file, options) => {
|
|
540
540
|
straceLog('OPTION_PREPARE() for CURRENTFILE as', preCompileOptions);
|
541
541
|
const prepared = compileRewStuff(file.content, preCompileOptions);
|
542
542
|
|
543
|
-
// console.log(prepared);
|
544
|
-
|
545
543
|
const compileOptions = {
|
546
544
|
...preCompileOptions,
|
547
545
|
bare: true,
|
@@ -581,8 +579,9 @@ const cpl = (module.exports.compile = function (file, options = {}) {
|
|
581
579
|
...(doJSX ? [[babelReact, { throwIfNamespace: false, pragmaFrag: options.jsxPragmaFrag || execOptions.jsxPragmaFrag, pragma: options.jsxPragma || execOptions.jsxPragma }]] : [])
|
582
580
|
],
|
583
581
|
plugins: [
|
584
|
-
...(doDecorators ? [[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }], [require('@babel/plugin-proposal-class-properties'), { loose: true }], [require('@babel/plugin-transform-class-static-block'), {}]] : [])
|
585
|
-
|
582
|
+
...(doDecorators ? [[require('@babel/plugin-proposal-decorators'), { version: '2023-05' }], [require('@babel/plugin-proposal-class-properties'), { loose: true }], [require('@babel/plugin-transform-class-static-block'), {}]] : []),
|
583
|
+
// doJSX ? require('./jsx') : null
|
584
|
+
].filter(Boolean),
|
586
585
|
}).code;
|
587
586
|
}
|
588
587
|
|
@@ -0,0 +1,67 @@
|
|
1
|
+
// customJSXIdentifierPlugin.js
|
2
|
+
module.exports = function customJSXIdentifierPlugin({ types: t }) {
|
3
|
+
return {
|
4
|
+
visitor: {
|
5
|
+
FunctionDeclaration(path) {
|
6
|
+
if (containsJSXReturn(path.node.body.body, t)) {
|
7
|
+
addJSXReturnFlag(path, path.node.id.name, t);
|
8
|
+
}
|
9
|
+
},
|
10
|
+
FunctionExpression(path) {
|
11
|
+
if (containsJSXReturn(path.node.body.body, t)) {
|
12
|
+
handleFunctionExpressionOrArrow(path, t);
|
13
|
+
}
|
14
|
+
},
|
15
|
+
ArrowFunctionExpression(path) {
|
16
|
+
if (t.isJSXElement(path.node.body) || (t.isBlockStatement(path.node.body) && containsJSXReturn(path.node.body.body, t))) {
|
17
|
+
handleFunctionExpressionOrArrow(path, t);
|
18
|
+
}
|
19
|
+
},
|
20
|
+
}
|
21
|
+
};
|
22
|
+
};
|
23
|
+
|
24
|
+
function containsJSXReturn(body, t) {
|
25
|
+
return body.some(statement => t.isReturnStatement(statement) && t.isJSXElement(statement.argument));
|
26
|
+
}
|
27
|
+
|
28
|
+
function addJSXReturnFlag(path, functionName, t) {
|
29
|
+
path.insertAfter(
|
30
|
+
t.expressionStatement(
|
31
|
+
t.assignmentExpression(
|
32
|
+
'=',
|
33
|
+
t.memberExpression(t.identifier(functionName), t.identifier('__returnsJSX')),
|
34
|
+
t.booleanLiteral(true)
|
35
|
+
)
|
36
|
+
)
|
37
|
+
);
|
38
|
+
}
|
39
|
+
|
40
|
+
function handleFunctionExpressionOrArrow(path, t) {
|
41
|
+
// Check for variable declaration
|
42
|
+
if (t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id)) {
|
43
|
+
const functionName = path.parent.id.name;
|
44
|
+
path.findParent(p => p.isVariableDeclaration()).insertAfter(
|
45
|
+
t.expressionStatement(
|
46
|
+
t.assignmentExpression(
|
47
|
+
'=',
|
48
|
+
t.memberExpression(t.identifier(functionName), t.identifier('__returnsJSX')),
|
49
|
+
t.booleanLiteral(true)
|
50
|
+
)
|
51
|
+
)
|
52
|
+
);
|
53
|
+
}
|
54
|
+
// Check for variable assignment
|
55
|
+
else if (t.isAssignmentExpression(path.parent) && t.isIdentifier(path.parent.left)) {
|
56
|
+
const functionName = path.parent.left.name;
|
57
|
+
path.parentPath.insertAfter(
|
58
|
+
t.expressionStatement(
|
59
|
+
t.assignmentExpression(
|
60
|
+
'=',
|
61
|
+
t.memberExpression(t.identifier(functionName), t.identifier('__returnsJSX')),
|
62
|
+
t.booleanLiteral(true)
|
63
|
+
)
|
64
|
+
)
|
65
|
+
);
|
66
|
+
}
|
67
|
+
}
|