@lwc/babel-plugin-component 9.0.4-alpha.1 → 9.1.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/dist/index.cjs +67 -75
- package/dist/index.js +67 -75
- package/dist/private-method-transform.d.ts +2 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1290,84 +1290,76 @@ const METHOD_KIND = 'method';
|
|
|
1290
1290
|
* private methods are converted to regular methods before decorator and class
|
|
1291
1291
|
* property processing.
|
|
1292
1292
|
*
|
|
1293
|
-
* Uses
|
|
1294
|
-
*
|
|
1295
|
-
* A direct ClassPrivateMethod visitor would replace nodes that the reverse transform
|
|
1296
|
-
* immediately converts back, creating an infinite loop. The manual traverse ensures
|
|
1297
|
-
* all forward replacements complete before the reverse visitor sees any ClassMethod.
|
|
1293
|
+
* Uses the `pre` lifecycle hook to run all transformations in a single pass
|
|
1294
|
+
* before the visitor phase, guaranteeing the traversal executes exactly once.
|
|
1298
1295
|
*/
|
|
1299
1296
|
function privateMethodTransform({ types: t, }) {
|
|
1300
1297
|
return {
|
|
1301
|
-
visitor: {
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
}, methodState);
|
|
1328
|
-
return;
|
|
1329
|
-
}
|
|
1330
|
-
const node = methodPath.node;
|
|
1331
|
-
// Reject private methods with decorators (e.g. @api, @track, @wire)
|
|
1332
|
-
if (node.decorators && node.decorators.length > 0) {
|
|
1333
|
-
handleError(methodPath, {
|
|
1334
|
-
errorInfo: errors.DecoratorErrors.DECORATOR_ON_PRIVATE_METHOD,
|
|
1335
|
-
}, methodState);
|
|
1336
|
-
return;
|
|
1337
|
-
}
|
|
1338
|
-
const privateName = key.node.id.name;
|
|
1339
|
-
const transformedName = `${PRIVATE_METHOD_PREFIX}${privateName}`;
|
|
1340
|
-
const keyReplacement = t.identifier(transformedName);
|
|
1341
|
-
// Create a new ClassMethod node to replace the ClassPrivateMethod
|
|
1342
|
-
// https://babeljs.io/docs/babel-types#classmethod
|
|
1343
|
-
const classMethod = t.classMethod(METHOD_KIND, keyReplacement, node.params, node.body, node.computed, node.static, node.generator, node.async);
|
|
1344
|
-
copyMethodMetadata(node, classMethod);
|
|
1345
|
-
// Replace the entire ClassPrivateMethod node with the new ClassMethod node
|
|
1346
|
-
// (we can't just replace the key of type PrivateName with type Identifier)
|
|
1347
|
-
methodPath.replaceWith(classMethod);
|
|
1348
|
-
transformedNames.add(transformedName);
|
|
1349
|
-
},
|
|
1350
|
-
MemberExpression(memberPath) {
|
|
1351
|
-
const property = memberPath.node.property;
|
|
1352
|
-
if (t.isPrivateName(property)) {
|
|
1353
|
-
const baseName = property.id.name;
|
|
1354
|
-
if (privateMethodBaseNames.has(baseName)) {
|
|
1355
|
-
const prefixedName = `${PRIVATE_METHOD_PREFIX}${baseName}`;
|
|
1356
|
-
memberPath
|
|
1357
|
-
.get('property')
|
|
1358
|
-
.replaceWith(t.identifier(prefixedName));
|
|
1359
|
-
}
|
|
1360
|
-
}
|
|
1361
|
-
},
|
|
1362
|
-
ClassPrivateProperty(propPath, propState) {
|
|
1363
|
-
handleError(propPath, {
|
|
1298
|
+
visitor: {},
|
|
1299
|
+
pre() {
|
|
1300
|
+
const state = this;
|
|
1301
|
+
const programPath = state.file.path;
|
|
1302
|
+
const transformedNames = new Set();
|
|
1303
|
+
// Phase 1: Collect base names of all private methods (kind: 'method')
|
|
1304
|
+
// so that Phase 2 can transform invocations even for forward references
|
|
1305
|
+
// (call site visited before the method definition).
|
|
1306
|
+
const privateMethodBaseNames = new Set();
|
|
1307
|
+
programPath.traverse({
|
|
1308
|
+
ClassPrivateMethod(methodPath) {
|
|
1309
|
+
const key = methodPath.get('key');
|
|
1310
|
+
if (key.isPrivateName() && methodPath.node.kind === METHOD_KIND) {
|
|
1311
|
+
privateMethodBaseNames.add(key.node.id.name);
|
|
1312
|
+
}
|
|
1313
|
+
},
|
|
1314
|
+
});
|
|
1315
|
+
// Phase 2: Transform definitions and invocations
|
|
1316
|
+
programPath.traverse({
|
|
1317
|
+
ClassPrivateMethod(methodPath, methodState) {
|
|
1318
|
+
const key = methodPath.get('key');
|
|
1319
|
+
if (!key.isPrivateName()) {
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (methodPath.node.kind !== METHOD_KIND) {
|
|
1323
|
+
handleError(methodPath, {
|
|
1364
1324
|
errorInfo: errors.DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
|
|
1365
|
-
messageArgs: ['
|
|
1366
|
-
},
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1325
|
+
messageArgs: ['accessor methods'],
|
|
1326
|
+
}, methodState);
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
const node = methodPath.node;
|
|
1330
|
+
if (node.decorators && node.decorators.length > 0) {
|
|
1331
|
+
handleError(methodPath, {
|
|
1332
|
+
errorInfo: errors.DecoratorErrors.DECORATOR_ON_PRIVATE_METHOD,
|
|
1333
|
+
}, methodState);
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
const privateName = key.node.id.name;
|
|
1337
|
+
const transformedName = `${PRIVATE_METHOD_PREFIX}${privateName}`;
|
|
1338
|
+
const keyReplacement = t.identifier(transformedName);
|
|
1339
|
+
const classMethod = t.classMethod(METHOD_KIND, keyReplacement, node.params, node.body, node.computed, node.static, node.generator, node.async);
|
|
1340
|
+
copyMethodMetadata(node, classMethod);
|
|
1341
|
+
methodPath.replaceWith(classMethod);
|
|
1342
|
+
transformedNames.add(transformedName);
|
|
1343
|
+
},
|
|
1344
|
+
PrivateName(privatePath) {
|
|
1345
|
+
const baseName = privatePath.node.id.name;
|
|
1346
|
+
if (!privateMethodBaseNames.has(baseName)) {
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
const parentPath = privatePath.parentPath;
|
|
1350
|
+
if (parentPath.isMemberExpression()) {
|
|
1351
|
+
const prefixedName = `${PRIVATE_METHOD_PREFIX}${baseName}`;
|
|
1352
|
+
privatePath.replaceWith(t.identifier(prefixedName));
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
ClassPrivateProperty(propPath, propState) {
|
|
1356
|
+
handleError(propPath, {
|
|
1357
|
+
errorInfo: errors.DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
|
|
1358
|
+
messageArgs: ['fields'],
|
|
1359
|
+
}, propState);
|
|
1360
|
+
},
|
|
1361
|
+
}, state);
|
|
1362
|
+
state.file.metadata[PRIVATE_METHOD_METADATA_KEY] = transformedNames;
|
|
1371
1363
|
},
|
|
1372
1364
|
};
|
|
1373
1365
|
}
|
|
@@ -1516,5 +1508,5 @@ function LwcClassTransform(api) {
|
|
|
1516
1508
|
exports.LwcPrivateMethodTransform = privateMethodTransform;
|
|
1517
1509
|
exports.LwcReversePrivateMethodTransform = reversePrivateMethodTransform;
|
|
1518
1510
|
exports.default = LwcClassTransform;
|
|
1519
|
-
/** version: 9.0
|
|
1511
|
+
/** version: 9.1.0 */
|
|
1520
1512
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1286,84 +1286,76 @@ const METHOD_KIND = 'method';
|
|
|
1286
1286
|
* private methods are converted to regular methods before decorator and class
|
|
1287
1287
|
* property processing.
|
|
1288
1288
|
*
|
|
1289
|
-
* Uses
|
|
1290
|
-
*
|
|
1291
|
-
* A direct ClassPrivateMethod visitor would replace nodes that the reverse transform
|
|
1292
|
-
* immediately converts back, creating an infinite loop. The manual traverse ensures
|
|
1293
|
-
* all forward replacements complete before the reverse visitor sees any ClassMethod.
|
|
1289
|
+
* Uses the `pre` lifecycle hook to run all transformations in a single pass
|
|
1290
|
+
* before the visitor phase, guaranteeing the traversal executes exactly once.
|
|
1294
1291
|
*/
|
|
1295
1292
|
function privateMethodTransform({ types: t, }) {
|
|
1296
1293
|
return {
|
|
1297
|
-
visitor: {
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
}, methodState);
|
|
1324
|
-
return;
|
|
1325
|
-
}
|
|
1326
|
-
const node = methodPath.node;
|
|
1327
|
-
// Reject private methods with decorators (e.g. @api, @track, @wire)
|
|
1328
|
-
if (node.decorators && node.decorators.length > 0) {
|
|
1329
|
-
handleError(methodPath, {
|
|
1330
|
-
errorInfo: DecoratorErrors.DECORATOR_ON_PRIVATE_METHOD,
|
|
1331
|
-
}, methodState);
|
|
1332
|
-
return;
|
|
1333
|
-
}
|
|
1334
|
-
const privateName = key.node.id.name;
|
|
1335
|
-
const transformedName = `${PRIVATE_METHOD_PREFIX}${privateName}`;
|
|
1336
|
-
const keyReplacement = t.identifier(transformedName);
|
|
1337
|
-
// Create a new ClassMethod node to replace the ClassPrivateMethod
|
|
1338
|
-
// https://babeljs.io/docs/babel-types#classmethod
|
|
1339
|
-
const classMethod = t.classMethod(METHOD_KIND, keyReplacement, node.params, node.body, node.computed, node.static, node.generator, node.async);
|
|
1340
|
-
copyMethodMetadata(node, classMethod);
|
|
1341
|
-
// Replace the entire ClassPrivateMethod node with the new ClassMethod node
|
|
1342
|
-
// (we can't just replace the key of type PrivateName with type Identifier)
|
|
1343
|
-
methodPath.replaceWith(classMethod);
|
|
1344
|
-
transformedNames.add(transformedName);
|
|
1345
|
-
},
|
|
1346
|
-
MemberExpression(memberPath) {
|
|
1347
|
-
const property = memberPath.node.property;
|
|
1348
|
-
if (t.isPrivateName(property)) {
|
|
1349
|
-
const baseName = property.id.name;
|
|
1350
|
-
if (privateMethodBaseNames.has(baseName)) {
|
|
1351
|
-
const prefixedName = `${PRIVATE_METHOD_PREFIX}${baseName}`;
|
|
1352
|
-
memberPath
|
|
1353
|
-
.get('property')
|
|
1354
|
-
.replaceWith(t.identifier(prefixedName));
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
},
|
|
1358
|
-
ClassPrivateProperty(propPath, propState) {
|
|
1359
|
-
handleError(propPath, {
|
|
1294
|
+
visitor: {},
|
|
1295
|
+
pre() {
|
|
1296
|
+
const state = this;
|
|
1297
|
+
const programPath = state.file.path;
|
|
1298
|
+
const transformedNames = new Set();
|
|
1299
|
+
// Phase 1: Collect base names of all private methods (kind: 'method')
|
|
1300
|
+
// so that Phase 2 can transform invocations even for forward references
|
|
1301
|
+
// (call site visited before the method definition).
|
|
1302
|
+
const privateMethodBaseNames = new Set();
|
|
1303
|
+
programPath.traverse({
|
|
1304
|
+
ClassPrivateMethod(methodPath) {
|
|
1305
|
+
const key = methodPath.get('key');
|
|
1306
|
+
if (key.isPrivateName() && methodPath.node.kind === METHOD_KIND) {
|
|
1307
|
+
privateMethodBaseNames.add(key.node.id.name);
|
|
1308
|
+
}
|
|
1309
|
+
},
|
|
1310
|
+
});
|
|
1311
|
+
// Phase 2: Transform definitions and invocations
|
|
1312
|
+
programPath.traverse({
|
|
1313
|
+
ClassPrivateMethod(methodPath, methodState) {
|
|
1314
|
+
const key = methodPath.get('key');
|
|
1315
|
+
if (!key.isPrivateName()) {
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
if (methodPath.node.kind !== METHOD_KIND) {
|
|
1319
|
+
handleError(methodPath, {
|
|
1360
1320
|
errorInfo: DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
|
|
1361
|
-
messageArgs: ['
|
|
1362
|
-
},
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1321
|
+
messageArgs: ['accessor methods'],
|
|
1322
|
+
}, methodState);
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
const node = methodPath.node;
|
|
1326
|
+
if (node.decorators && node.decorators.length > 0) {
|
|
1327
|
+
handleError(methodPath, {
|
|
1328
|
+
errorInfo: DecoratorErrors.DECORATOR_ON_PRIVATE_METHOD,
|
|
1329
|
+
}, methodState);
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
const privateName = key.node.id.name;
|
|
1333
|
+
const transformedName = `${PRIVATE_METHOD_PREFIX}${privateName}`;
|
|
1334
|
+
const keyReplacement = t.identifier(transformedName);
|
|
1335
|
+
const classMethod = t.classMethod(METHOD_KIND, keyReplacement, node.params, node.body, node.computed, node.static, node.generator, node.async);
|
|
1336
|
+
copyMethodMetadata(node, classMethod);
|
|
1337
|
+
methodPath.replaceWith(classMethod);
|
|
1338
|
+
transformedNames.add(transformedName);
|
|
1339
|
+
},
|
|
1340
|
+
PrivateName(privatePath) {
|
|
1341
|
+
const baseName = privatePath.node.id.name;
|
|
1342
|
+
if (!privateMethodBaseNames.has(baseName)) {
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
const parentPath = privatePath.parentPath;
|
|
1346
|
+
if (parentPath.isMemberExpression()) {
|
|
1347
|
+
const prefixedName = `${PRIVATE_METHOD_PREFIX}${baseName}`;
|
|
1348
|
+
privatePath.replaceWith(t.identifier(prefixedName));
|
|
1349
|
+
}
|
|
1350
|
+
},
|
|
1351
|
+
ClassPrivateProperty(propPath, propState) {
|
|
1352
|
+
handleError(propPath, {
|
|
1353
|
+
errorInfo: DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
|
|
1354
|
+
messageArgs: ['fields'],
|
|
1355
|
+
}, propState);
|
|
1356
|
+
},
|
|
1357
|
+
}, state);
|
|
1358
|
+
state.file.metadata[PRIVATE_METHOD_METADATA_KEY] = transformedNames;
|
|
1367
1359
|
},
|
|
1368
1360
|
};
|
|
1369
1361
|
}
|
|
@@ -1510,5 +1502,5 @@ function LwcClassTransform(api) {
|
|
|
1510
1502
|
}
|
|
1511
1503
|
|
|
1512
1504
|
export { privateMethodTransform as LwcPrivateMethodTransform, reversePrivateMethodTransform as LwcReversePrivateMethodTransform, LwcClassTransform as default };
|
|
1513
|
-
/** version: 9.0
|
|
1505
|
+
/** version: 9.1.0 */
|
|
1514
1506
|
//# sourceMappingURL=index.js.map
|
|
@@ -8,11 +8,8 @@ import type { PluginObj } from '@babel/core';
|
|
|
8
8
|
* private methods are converted to regular methods before decorator and class
|
|
9
9
|
* property processing.
|
|
10
10
|
*
|
|
11
|
-
* Uses
|
|
12
|
-
*
|
|
13
|
-
* A direct ClassPrivateMethod visitor would replace nodes that the reverse transform
|
|
14
|
-
* immediately converts back, creating an infinite loop. The manual traverse ensures
|
|
15
|
-
* all forward replacements complete before the reverse visitor sees any ClassMethod.
|
|
11
|
+
* Uses the `pre` lifecycle hook to run all transformations in a single pass
|
|
12
|
+
* before the visitor phase, guaranteeing the traversal executes exactly once.
|
|
16
13
|
*/
|
|
17
14
|
export default function privateMethodTransform({ types: t, }: BabelAPI): PluginObj<LwcBabelPluginPass>;
|
|
18
15
|
//# sourceMappingURL=private-method-transform.d.ts.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"You can safely modify dependencies, devDependencies, keywords, etc., but other props will be overwritten."
|
|
5
5
|
],
|
|
6
6
|
"name": "@lwc/babel-plugin-component",
|
|
7
|
-
"version": "9.0
|
|
7
|
+
"version": "9.1.0",
|
|
8
8
|
"description": "Babel plugin to transform a LWC module",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"lwc"
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@babel/helper-module-imports": "7.28.6",
|
|
55
|
-
"@lwc/errors": "9.0
|
|
56
|
-
"@lwc/shared": "9.0
|
|
55
|
+
"@lwc/errors": "9.1.0",
|
|
56
|
+
"@lwc/shared": "9.1.0",
|
|
57
57
|
"line-column": "~1.0.2"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|