@lwc/babel-plugin-component 2.9.0 → 2.10.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/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "bugs": {
11
11
  "url": "https://github.com/salesforce/lwc/issues"
12
12
  },
13
- "version": "2.9.0",
13
+ "version": "2.10.0",
14
14
  "main": "src/index.js",
15
15
  "typings": "types/index.d.ts",
16
16
  "license": "MIT",
@@ -21,7 +21,8 @@
21
21
  ],
22
22
  "dependencies": {
23
23
  "@babel/helper-module-imports": "~7.16.7",
24
- "@lwc/errors": "2.9.0",
24
+ "@lwc/errors": "2.10.0",
25
+ "@lwc/shared": "2.10.0",
25
26
  "line-column": "~1.0.2"
26
27
  },
27
28
  "devDependencies": {
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright (c) 2018, salesforce.com, inc.
3
+ * All rights reserved.
4
+ * SPDX-License-Identifier: MIT
5
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6
+ */
7
+ const { LWC_VERSION_COMMENT } = require('@lwc/shared');
8
+
9
+ module.exports = function compilerVersionNumber({ types: t }) {
10
+ return {
11
+ ClassBody(path) {
12
+ if (path.parent.superClass === null) {
13
+ // Components *must* extend from either LightningElement or some other superclass (e.g. a mixin).
14
+ // We can skip classes without a superclass to avoid adding unnecessary comments.
15
+ return;
16
+ }
17
+ // If the class body is empty, we want an inner comment. Otherwise we want it after the last child
18
+ // of the class body. In either case, we want it right before the `}` at the end of the function body.
19
+ if (path.node.body.length > 0) {
20
+ // E.g. `class Foo extends Lightning Element { /*LWC compiler v1.2.3*/ }`
21
+ t.addComment(
22
+ path.node.body[path.node.body.length - 1],
23
+ 'trailing',
24
+ LWC_VERSION_COMMENT,
25
+ /* line */ false
26
+ );
27
+ } else {
28
+ // E.g. `class Foo extends Lightning Element { bar = 'baz'; /*LWC compiler v1.2.3*/ }`
29
+ t.addComment(path.node, 'inner', LWC_VERSION_COMMENT, /* line */ false);
30
+ }
31
+ },
32
+ };
33
+ };
package/src/index.js CHANGED
@@ -15,6 +15,7 @@ const {
15
15
  } = require('./decorators');
16
16
  const dedupeImports = require('./dedupe-imports');
17
17
  const dynamicImports = require('./dynamic-imports');
18
+ const compilerVersionNumber = require('./compiler-version-number');
18
19
  const { generateError, getEngineImportSpecifiers } = require('./utils');
19
20
 
20
21
  /**
@@ -26,6 +27,7 @@ module.exports = function LwcClassTransform(api) {
26
27
  const { ExportDefaultDeclaration: transformCreateRegisterComponent } = component(api);
27
28
  const { Class: transformDecorators } = decorators(api);
28
29
  const { Import: transformDynamicImports } = dynamicImports(api);
30
+ const { ClassBody: addCompilerVersionNumber } = compilerVersionNumber(api);
29
31
 
30
32
  return {
31
33
  manipulateOptions(opts, parserOpts) {
@@ -73,6 +75,10 @@ module.exports = function LwcClassTransform(api) {
73
75
  transformDecorators(path);
74
76
  },
75
77
 
78
+ ClassBody(path) {
79
+ addCompilerVersionNumber(path);
80
+ },
81
+
76
82
  ExportDefaultDeclaration(path, state) {
77
83
  transformCreateRegisterComponent(path, state);
78
84
  },