@lwc/babel-plugin-component 9.0.4-alpha.0 → 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.
@@ -25,7 +25,8 @@ declare const API_VERSION_KEY = "apiVersion";
25
25
  declare const COMPONENT_CLASS_ID = "__lwc_component_class_internal";
26
26
  declare const PRIVATE_METHOD_PREFIX = "__lwc_component_class_internal_private_";
27
27
  declare const PRIVATE_METHOD_METADATA_KEY = "__lwcTransformedPrivateMethods";
28
+ declare const ENABLE_PRIVATE_METHODS_KEY = "enablePrivateMethods";
28
29
  declare const SYNTHETIC_ELEMENT_INTERNALS_KEY = "enableSyntheticElementInternals";
29
30
  declare const COMPONENT_FEATURE_FLAG_KEY = "componentFeatureFlag";
30
- export { DECORATOR_TYPES, LWC_PACKAGE_ALIAS, LWC_PACKAGE_EXPORTS, LWC_COMPONENT_PROPERTIES, REGISTER_COMPONENT_ID, REGISTER_DECORATORS_ID, TEMPLATE_KEY, COMPONENT_NAME_KEY, API_VERSION_KEY, COMPONENT_CLASS_ID, PRIVATE_METHOD_PREFIX, PRIVATE_METHOD_METADATA_KEY, SYNTHETIC_ELEMENT_INTERNALS_KEY, COMPONENT_FEATURE_FLAG_KEY, };
31
+ export { DECORATOR_TYPES, LWC_PACKAGE_ALIAS, LWC_PACKAGE_EXPORTS, LWC_COMPONENT_PROPERTIES, REGISTER_COMPONENT_ID, REGISTER_DECORATORS_ID, TEMPLATE_KEY, COMPONENT_NAME_KEY, API_VERSION_KEY, COMPONENT_CLASS_ID, PRIVATE_METHOD_PREFIX, PRIVATE_METHOD_METADATA_KEY, ENABLE_PRIVATE_METHODS_KEY, SYNTHETIC_ELEMENT_INTERNALS_KEY, COMPONENT_FEATURE_FLAG_KEY, };
31
32
  //# sourceMappingURL=constants.d.ts.map
package/dist/index.cjs CHANGED
@@ -43,6 +43,7 @@ const API_VERSION_KEY = 'apiVersion';
43
43
  const COMPONENT_CLASS_ID = '__lwc_component_class_internal';
44
44
  const PRIVATE_METHOD_PREFIX = '__lwc_component_class_internal_private_';
45
45
  const PRIVATE_METHOD_METADATA_KEY = '__lwcTransformedPrivateMethods';
46
+ const ENABLE_PRIVATE_METHODS_KEY = 'enablePrivateMethods';
46
47
  const SYNTHETIC_ELEMENT_INTERNALS_KEY = 'enableSyntheticElementInternals';
47
48
  const COMPONENT_FEATURE_FLAG_KEY = 'componentFeatureFlag';
48
49
 
@@ -125,6 +126,9 @@ function component ({ types: t }) {
125
126
  if (state.opts.enableSyntheticElementInternals === true) {
126
127
  properties.push(t.objectProperty(t.identifier(SYNTHETIC_ELEMENT_INTERNALS_KEY), t.booleanLiteral(true)));
127
128
  }
129
+ if (state.opts.enablePrivateMethods === true) {
130
+ properties.push(t.objectProperty(t.identifier(ENABLE_PRIVATE_METHODS_KEY), t.booleanLiteral(true)));
131
+ }
128
132
  const registerComponentExpression = t.callExpression(registerComponentId, [
129
133
  node,
130
134
  t.objectExpression(properties),
@@ -1286,84 +1290,76 @@ const METHOD_KIND = 'method';
1286
1290
  * private methods are converted to regular methods before decorator and class
1287
1291
  * property processing.
1288
1292
  *
1289
- * Uses Program > path.traverse() rather than a top-level ClassPrivateMethod visitor
1290
- * because the reverse transform has a ClassMethod visitor in the same Babel pass.
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.
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.
1294
1295
  */
1295
1296
  function privateMethodTransform({ types: t, }) {
1296
1297
  return {
1297
- visitor: {
1298
- Program(path, state) {
1299
- const transformedNames = new Set();
1300
- // Phase 1: Collect base names of all private methods (kind: 'method')
1301
- // so that Phase 2 can transform invocations even for forward references
1302
- // (call site visited before the method definition).
1303
- const privateMethodBaseNames = new Set();
1304
- path.traverse({
1305
- ClassPrivateMethod(methodPath) {
1306
- const key = methodPath.get('key');
1307
- if (key.isPrivateName() && methodPath.node.kind === METHOD_KIND) {
1308
- privateMethodBaseNames.add(key.node.id.name);
1309
- }
1310
- },
1311
- });
1312
- // Phase 2: Transform definitions and invocations
1313
- path.traverse({
1314
- ClassPrivateMethod(methodPath, methodState) {
1315
- const key = methodPath.get('key');
1316
- if (!key.isPrivateName()) {
1317
- return;
1318
- }
1319
- if (methodPath.node.kind !== METHOD_KIND) {
1320
- handleError(methodPath, {
1321
- errorInfo: errors.DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
1322
- messageArgs: ['accessor methods'],
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: errors.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, {
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, {
1360
1324
  errorInfo: errors.DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
1361
- messageArgs: ['fields'],
1362
- }, propState);
1363
- },
1364
- }, state);
1365
- state.file.metadata[PRIVATE_METHOD_METADATA_KEY] = transformedNames;
1366
- },
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;
1367
1363
  },
1368
1364
  };
1369
1365
  }
@@ -1512,5 +1508,5 @@ function LwcClassTransform(api) {
1512
1508
  exports.LwcPrivateMethodTransform = privateMethodTransform;
1513
1509
  exports.LwcReversePrivateMethodTransform = reversePrivateMethodTransform;
1514
1510
  exports.default = LwcClassTransform;
1515
- /** version: 9.0.4-alpha.0 */
1511
+ /** version: 9.1.0 */
1516
1512
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ const API_VERSION_KEY = 'apiVersion';
39
39
  const COMPONENT_CLASS_ID = '__lwc_component_class_internal';
40
40
  const PRIVATE_METHOD_PREFIX = '__lwc_component_class_internal_private_';
41
41
  const PRIVATE_METHOD_METADATA_KEY = '__lwcTransformedPrivateMethods';
42
+ const ENABLE_PRIVATE_METHODS_KEY = 'enablePrivateMethods';
42
43
  const SYNTHETIC_ELEMENT_INTERNALS_KEY = 'enableSyntheticElementInternals';
43
44
  const COMPONENT_FEATURE_FLAG_KEY = 'componentFeatureFlag';
44
45
 
@@ -121,6 +122,9 @@ function component ({ types: t }) {
121
122
  if (state.opts.enableSyntheticElementInternals === true) {
122
123
  properties.push(t.objectProperty(t.identifier(SYNTHETIC_ELEMENT_INTERNALS_KEY), t.booleanLiteral(true)));
123
124
  }
125
+ if (state.opts.enablePrivateMethods === true) {
126
+ properties.push(t.objectProperty(t.identifier(ENABLE_PRIVATE_METHODS_KEY), t.booleanLiteral(true)));
127
+ }
124
128
  const registerComponentExpression = t.callExpression(registerComponentId, [
125
129
  node,
126
130
  t.objectExpression(properties),
@@ -1282,84 +1286,76 @@ const METHOD_KIND = 'method';
1282
1286
  * private methods are converted to regular methods before decorator and class
1283
1287
  * property processing.
1284
1288
  *
1285
- * Uses Program > path.traverse() rather than a top-level ClassPrivateMethod visitor
1286
- * because the reverse transform has a ClassMethod visitor in the same Babel pass.
1287
- * A direct ClassPrivateMethod visitor would replace nodes that the reverse transform
1288
- * immediately converts back, creating an infinite loop. The manual traverse ensures
1289
- * 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.
1290
1291
  */
1291
1292
  function privateMethodTransform({ types: t, }) {
1292
1293
  return {
1293
- visitor: {
1294
- Program(path, state) {
1295
- const transformedNames = new Set();
1296
- // Phase 1: Collect base names of all private methods (kind: 'method')
1297
- // so that Phase 2 can transform invocations even for forward references
1298
- // (call site visited before the method definition).
1299
- const privateMethodBaseNames = new Set();
1300
- path.traverse({
1301
- ClassPrivateMethod(methodPath) {
1302
- const key = methodPath.get('key');
1303
- if (key.isPrivateName() && methodPath.node.kind === METHOD_KIND) {
1304
- privateMethodBaseNames.add(key.node.id.name);
1305
- }
1306
- },
1307
- });
1308
- // Phase 2: Transform definitions and invocations
1309
- path.traverse({
1310
- ClassPrivateMethod(methodPath, methodState) {
1311
- const key = methodPath.get('key');
1312
- if (!key.isPrivateName()) {
1313
- return;
1314
- }
1315
- if (methodPath.node.kind !== METHOD_KIND) {
1316
- handleError(methodPath, {
1317
- errorInfo: DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
1318
- messageArgs: ['accessor methods'],
1319
- }, methodState);
1320
- return;
1321
- }
1322
- const node = methodPath.node;
1323
- // Reject private methods with decorators (e.g. @api, @track, @wire)
1324
- if (node.decorators && node.decorators.length > 0) {
1325
- handleError(methodPath, {
1326
- errorInfo: DecoratorErrors.DECORATOR_ON_PRIVATE_METHOD,
1327
- }, methodState);
1328
- return;
1329
- }
1330
- const privateName = key.node.id.name;
1331
- const transformedName = `${PRIVATE_METHOD_PREFIX}${privateName}`;
1332
- const keyReplacement = t.identifier(transformedName);
1333
- // Create a new ClassMethod node to replace the ClassPrivateMethod
1334
- // https://babeljs.io/docs/babel-types#classmethod
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
- // Replace the entire ClassPrivateMethod node with the new ClassMethod node
1338
- // (we can't just replace the key of type PrivateName with type Identifier)
1339
- methodPath.replaceWith(classMethod);
1340
- transformedNames.add(transformedName);
1341
- },
1342
- MemberExpression(memberPath) {
1343
- const property = memberPath.node.property;
1344
- if (t.isPrivateName(property)) {
1345
- const baseName = property.id.name;
1346
- if (privateMethodBaseNames.has(baseName)) {
1347
- const prefixedName = `${PRIVATE_METHOD_PREFIX}${baseName}`;
1348
- memberPath
1349
- .get('property')
1350
- .replaceWith(t.identifier(prefixedName));
1351
- }
1352
- }
1353
- },
1354
- ClassPrivateProperty(propPath, propState) {
1355
- 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, {
1356
1320
  errorInfo: DecoratorErrors.UNSUPPORTED_PRIVATE_MEMBER,
1357
- messageArgs: ['fields'],
1358
- }, propState);
1359
- },
1360
- }, state);
1361
- state.file.metadata[PRIVATE_METHOD_METADATA_KEY] = transformedNames;
1362
- },
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;
1363
1359
  },
1364
1360
  };
1365
1361
  }
@@ -1506,5 +1502,5 @@ function LwcClassTransform(api) {
1506
1502
  }
1507
1503
 
1508
1504
  export { privateMethodTransform as LwcPrivateMethodTransform, reversePrivateMethodTransform as LwcReversePrivateMethodTransform, LwcClassTransform as default };
1509
- /** version: 9.0.4-alpha.0 */
1505
+ /** version: 9.1.0 */
1510
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 Program > path.traverse() rather than a top-level ClassPrivateMethod visitor
12
- * because the reverse transform has a ClassMethod visitor in the same Babel pass.
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/dist/types.d.ts CHANGED
@@ -14,6 +14,7 @@ export interface LwcBabelPluginOptions {
14
14
  instrumentation?: InstrumentationObject;
15
15
  apiVersion?: number;
16
16
  enableSyntheticElementInternals?: boolean;
17
+ enablePrivateMethods?: boolean;
17
18
  componentFeatureFlagModulePath?: string;
18
19
  }
19
20
  export interface LwcBabelPluginPass extends PluginPass {
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.4-alpha.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.4-alpha.0",
56
- "@lwc/shared": "9.0.4-alpha.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": {