@lwc/babel-plugin-component 2.41.3 → 2.43.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.
Files changed (45) hide show
  1. package/README.md +37 -0
  2. package/dist/index.cjs.js +1145 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.js +1143 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +25 -8
  7. package/types/compiler-version-number.d.ts +3 -0
  8. package/types/component.d.ts +3 -0
  9. package/types/constants.d.ts +26 -0
  10. package/types/decorators/api/index.d.ts +8 -0
  11. package/types/decorators/api/shared.d.ts +3 -0
  12. package/types/decorators/api/transform.d.ts +6 -0
  13. package/types/decorators/api/validate.d.ts +2 -0
  14. package/types/decorators/index.d.ts +21 -0
  15. package/types/decorators/track/index.d.ts +10 -0
  16. package/types/decorators/types.d.ts +20 -0
  17. package/types/decorators/wire/index.d.ts +8 -0
  18. package/types/decorators/wire/shared.d.ts +3 -0
  19. package/types/decorators/wire/transform.d.ts +4 -0
  20. package/types/decorators/wire/validate.d.ts +2 -0
  21. package/types/dedupe-imports.d.ts +4 -0
  22. package/types/dynamic-imports.d.ts +3 -0
  23. package/types/index.d.ts +9 -0
  24. package/types/scope-css-imports.d.ts +3 -0
  25. package/types/types.d.ts +18 -0
  26. package/types/utils.d.ts +21 -0
  27. package/src/compiler-version-number.js +0 -33
  28. package/src/component.js +0 -89
  29. package/src/constants.js +0 -67
  30. package/src/decorators/api/index.js +0 -18
  31. package/src/decorators/api/shared.js +0 -17
  32. package/src/decorators/api/transform.js +0 -95
  33. package/src/decorators/api/validate.js +0 -160
  34. package/src/decorators/index.js +0 -271
  35. package/src/decorators/track/index.js +0 -49
  36. package/src/decorators/wire/index.js +0 -18
  37. package/src/decorators/wire/shared.js +0 -17
  38. package/src/decorators/wire/transform.js +0 -261
  39. package/src/decorators/wire/validate.js +0 -100
  40. package/src/dedupe-imports.js +0 -56
  41. package/src/dynamic-imports.js +0 -70
  42. package/src/index.d.ts +0 -10
  43. package/src/index.js +0 -77
  44. package/src/scope-css-imports.js +0 -23
  45. package/src/utils.js +0 -116
@@ -1,261 +0,0 @@
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_COMPONENT_PROPERTIES } = require('../../constants');
8
-
9
- const { isWireDecorator } = require('./shared');
10
-
11
- const WIRE_PARAM_PREFIX = '$';
12
- const WIRE_CONFIG_ARG_NAME = '$cmp';
13
-
14
- function isObservedProperty(configProperty) {
15
- const propertyValue = configProperty.get('value');
16
- return (
17
- propertyValue.isStringLiteral() && propertyValue.node.value.startsWith(WIRE_PARAM_PREFIX)
18
- );
19
- }
20
-
21
- function getWiredStatic(wireConfig) {
22
- return wireConfig
23
- .get('properties')
24
- .filter((property) => !isObservedProperty(property))
25
- .map((path) => path.node);
26
- }
27
-
28
- function getWiredParams(t, wireConfig) {
29
- return wireConfig
30
- .get('properties')
31
- .filter((property) => isObservedProperty(property))
32
- .map((path) => {
33
- // Need to clone deep the observed property to remove the param prefix
34
- const clonedProperty = t.cloneDeep(path.node);
35
- clonedProperty.value.value = clonedProperty.value.value.slice(1);
36
-
37
- return clonedProperty;
38
- });
39
- }
40
-
41
- function getGeneratedConfig(t, wiredValue) {
42
- let counter = 0;
43
- const configBlockBody = [];
44
- const configProps = [];
45
- const generateParameterConfigValue = (memberExprPaths) => {
46
- // Note: When memberExprPaths ($foo.bar) has an invalid identifier (eg: foo..bar, foo.bar[3])
47
- // it should (ideally) resolve in a compilation error during validation phase.
48
- // This is not possible due that platform components may have a param definition which is invalid
49
- // but passes compilation, and throwing at compile time would break such components.
50
- // In such cases where the param does not have proper notation, the config generated will use the bracket
51
- // notation to match the current behavior (that most likely end up resolving that param as undefined).
52
- const isInvalidMemberExpr = memberExprPaths.some(
53
- (maybeIdentifier) =>
54
- !(t.isValidES3Identifier(maybeIdentifier) && maybeIdentifier.length > 0)
55
- );
56
- const memberExprPropertyGen = !isInvalidMemberExpr ? t.identifier : t.StringLiteral;
57
-
58
- if (memberExprPaths.length === 1) {
59
- return {
60
- configValueExpression: t.memberExpression(
61
- t.identifier(WIRE_CONFIG_ARG_NAME),
62
- memberExprPropertyGen(memberExprPaths[0])
63
- ),
64
- };
65
- }
66
-
67
- const varName = 'v' + ++counter;
68
- const varDeclaration = t.variableDeclaration('let', [
69
- t.variableDeclarator(
70
- t.identifier(varName),
71
- t.memberExpression(
72
- t.identifier(WIRE_CONFIG_ARG_NAME),
73
- memberExprPropertyGen(memberExprPaths[0]),
74
- isInvalidMemberExpr
75
- )
76
- ),
77
- ]);
78
-
79
- // Results in: v != null && ... (v = v.i) != null && ... (v = v.(n-1)) != null
80
- let conditionTest = t.binaryExpression('!=', t.identifier(varName), t.nullLiteral());
81
-
82
- for (let i = 1, n = memberExprPaths.length; i < n - 1; i++) {
83
- const nextPropValue = t.assignmentExpression(
84
- '=',
85
- t.identifier(varName),
86
- t.memberExpression(
87
- t.identifier(varName),
88
- memberExprPropertyGen(memberExprPaths[i]),
89
- isInvalidMemberExpr
90
- )
91
- );
92
-
93
- conditionTest = t.logicalExpression(
94
- '&&',
95
- conditionTest,
96
- t.binaryExpression('!=', nextPropValue, t.nullLiteral())
97
- );
98
- }
99
-
100
- // conditionTest ? v.n : undefined
101
- const configValueExpression = t.conditionalExpression(
102
- conditionTest,
103
- t.memberExpression(
104
- t.identifier(varName),
105
- memberExprPropertyGen(memberExprPaths[memberExprPaths.length - 1]),
106
- isInvalidMemberExpr
107
- ),
108
- t.identifier('undefined')
109
- );
110
-
111
- return {
112
- varDeclaration,
113
- configValueExpression,
114
- };
115
- };
116
-
117
- if (wiredValue.static) {
118
- Array.prototype.push.apply(configProps, wiredValue.static);
119
- }
120
-
121
- if (wiredValue.params) {
122
- wiredValue.params.forEach((param) => {
123
- const memberExprPaths = param.value.value.split('.');
124
- const paramConfigValue = generateParameterConfigValue(memberExprPaths);
125
-
126
- configProps.push(t.objectProperty(param.key, paramConfigValue.configValueExpression));
127
-
128
- if (paramConfigValue.varDeclaration) {
129
- configBlockBody.push(paramConfigValue.varDeclaration);
130
- }
131
- });
132
- }
133
-
134
- configBlockBody.push(t.returnStatement(t.objectExpression(configProps)));
135
-
136
- const fnExpression = t.functionExpression(
137
- null,
138
- [t.identifier(WIRE_CONFIG_ARG_NAME)],
139
- t.blockStatement(configBlockBody)
140
- );
141
-
142
- return t.objectProperty(t.identifier('config'), fnExpression);
143
- }
144
-
145
- function buildWireConfigValue(t, wiredValues) {
146
- return t.objectExpression(
147
- wiredValues.map((wiredValue) => {
148
- const wireConfig = [];
149
- if (wiredValue.adapter) {
150
- wireConfig.push(
151
- t.objectProperty(t.identifier('adapter'), wiredValue.adapter.expression)
152
- );
153
- }
154
-
155
- if (wiredValue.params) {
156
- const dynamicParamNames = wiredValue.params.map((p) => {
157
- return t.stringLiteral(t.isIdentifier(p.key) ? p.key.name : p.key.value);
158
- });
159
- wireConfig.push(
160
- t.objectProperty(t.identifier('dynamic'), t.arrayExpression(dynamicParamNames))
161
- );
162
- }
163
-
164
- if (wiredValue.isClassMethod) {
165
- wireConfig.push(t.objectProperty(t.identifier('method'), t.numericLiteral(1)));
166
- }
167
-
168
- wireConfig.push(getGeneratedConfig(t, wiredValue));
169
-
170
- return t.objectProperty(
171
- t.identifier(wiredValue.propertyName),
172
- t.objectExpression(wireConfig)
173
- );
174
- })
175
- );
176
- }
177
-
178
- const SUPPORTED_VALUE_TO_TYPE_MAP = {
179
- StringLiteral: 'string',
180
- NumericLiteral: 'number',
181
- BooleanLiteral: 'boolean',
182
- };
183
-
184
- const scopedReferenceLookup = (scope) => (name) => {
185
- const binding = scope.getBinding(name);
186
-
187
- let type;
188
- let value;
189
-
190
- if (binding) {
191
- if (binding.kind === 'module') {
192
- // Resolves module import to the name of the module imported
193
- // e.g. import { foo } from 'bar' gives value 'bar' for `name == 'foo'
194
- const parentPathNode = binding.path.parentPath.node;
195
- if (parentPathNode && parentPathNode.source) {
196
- type = 'module';
197
- value = parentPathNode.source.value;
198
- }
199
- } else if (binding.kind === 'const') {
200
- // Resolves `const foo = 'text';` references to value 'text', where `name == 'foo'`
201
- const init = binding.path.node.init;
202
- if (init && SUPPORTED_VALUE_TO_TYPE_MAP[init.type]) {
203
- type = SUPPORTED_VALUE_TO_TYPE_MAP[init.type];
204
- value = init.value;
205
- }
206
- }
207
- }
208
- return {
209
- type,
210
- value,
211
- };
212
- };
213
-
214
- module.exports = function transform(t, decoratorMetas) {
215
- const objectProperties = [];
216
- const wiredValues = decoratorMetas.filter(isWireDecorator).map(({ path }) => {
217
- const [id, config] = path.get('expression.arguments');
218
-
219
- const propertyName = path.parentPath.get('key.name').node;
220
- const isClassMethod = path.parentPath.isClassMethod({
221
- kind: 'method',
222
- });
223
-
224
- const wiredValue = {
225
- propertyName,
226
- isClassMethod,
227
- };
228
-
229
- if (config) {
230
- wiredValue.static = getWiredStatic(config);
231
- wiredValue.params = getWiredParams(t, config);
232
- }
233
-
234
- const referenceLookup = scopedReferenceLookup(path.scope);
235
- const isMemberExpression = id.isMemberExpression();
236
- const isIdentifier = id.isIdentifier();
237
-
238
- if (isIdentifier || isMemberExpression) {
239
- const referenceName = isMemberExpression ? id.node.object.name : id.node.name;
240
- const reference = referenceLookup(referenceName);
241
- wiredValue.adapter = {
242
- name: referenceName,
243
- expression: t.cloneDeep(id.node),
244
- reference: reference.type === 'module' ? reference.value : undefined,
245
- };
246
- }
247
-
248
- return wiredValue;
249
- });
250
-
251
- if (wiredValues.length) {
252
- objectProperties.push(
253
- t.objectProperty(
254
- t.identifier(LWC_COMPONENT_PROPERTIES.WIRE),
255
- buildWireConfigValue(t, wiredValues)
256
- )
257
- );
258
- }
259
-
260
- return objectProperties;
261
- };
@@ -1,100 +0,0 @@
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 { DecoratorErrors } = require('@lwc/errors');
8
- const {
9
- LWC_PACKAGE_EXPORTS: { WIRE_DECORATOR, TRACK_DECORATOR, API_DECORATOR },
10
- } = require('../../constants');
11
- const { generateError } = require('../../utils');
12
-
13
- const { isWireDecorator } = require('./shared');
14
-
15
- function validateWireParameters(path) {
16
- const [id, config] = path.get('expression.arguments');
17
-
18
- if (!id) {
19
- throw generateError(path, {
20
- errorInfo: DecoratorErrors.ADAPTER_SHOULD_BE_FIRST_PARAMETER,
21
- });
22
- }
23
-
24
- const isIdentifier = id.isIdentifier();
25
- const isMemberExpression = id.isMemberExpression();
26
-
27
- if (!isIdentifier && !isMemberExpression) {
28
- throw generateError(id, {
29
- errorInfo: DecoratorErrors.FUNCTION_IDENTIFIER_SHOULD_BE_FIRST_PARAMETER,
30
- });
31
- }
32
-
33
- if (id.isMemberExpression({ computed: true })) {
34
- throw generateError(id, {
35
- errorInfo: DecoratorErrors.FUNCTION_IDENTIFIER_CANNOT_HAVE_COMPUTED_PROPS,
36
- });
37
- }
38
-
39
- if (isMemberExpression && !id.get('object').isIdentifier()) {
40
- throw generateError(id, {
41
- errorInfo: DecoratorErrors.FUNCTION_IDENTIFIER_CANNOT_HAVE_NESTED_MEMBER_EXRESSIONS,
42
- });
43
- }
44
-
45
- // Ensure wire adapter is imported (check for member expression or identifier)
46
- const wireBinding = isMemberExpression ? id.node.object.name : id.node.name;
47
- if (!path.scope.getBinding(wireBinding)) {
48
- throw generateError(id, {
49
- errorInfo: DecoratorErrors.WIRE_ADAPTER_SHOULD_BE_IMPORTED,
50
- messageArgs: [id.node.name],
51
- });
52
- }
53
-
54
- // ensure wire adapter is a first parameter
55
- if (
56
- wireBinding &&
57
- !path.scope.getBinding(wireBinding).path.isImportSpecifier() &&
58
- !path.scope.getBinding(wireBinding).path.isImportDefaultSpecifier()
59
- ) {
60
- throw generateError(id, {
61
- errorInfo: DecoratorErrors.IMPORTED_FUNCTION_IDENTIFIER_SHOULD_BE_FIRST_PARAMETER,
62
- });
63
- }
64
-
65
- if (config && !config.isObjectExpression()) {
66
- throw generateError(config, {
67
- errorInfo: DecoratorErrors.CONFIG_OBJECT_SHOULD_BE_SECOND_PARAMETER,
68
- });
69
- }
70
- }
71
-
72
- function validateUsageWithOtherDecorators(path, decorators) {
73
- decorators.forEach((decorator) => {
74
- if (
75
- path !== decorator.path &&
76
- decorator.name === WIRE_DECORATOR &&
77
- decorator.path.parentPath.node === path.parentPath.node
78
- ) {
79
- throw generateError(path, {
80
- errorInfo: DecoratorErrors.ONE_WIRE_DECORATOR_ALLOWED,
81
- });
82
- }
83
- if (
84
- (decorator.name === API_DECORATOR || decorator.name === TRACK_DECORATOR) &&
85
- decorator.path.parentPath.node === path.parentPath.node
86
- ) {
87
- throw generateError(path, {
88
- errorInfo: DecoratorErrors.CONFLICT_WITH_ANOTHER_DECORATOR,
89
- messageArgs: [decorator.name],
90
- });
91
- }
92
- });
93
- }
94
-
95
- module.exports = function validate(decorators) {
96
- decorators.filter(isWireDecorator).forEach(({ path }) => {
97
- validateUsageWithOtherDecorators(path, decorators);
98
- validateWireParameters(path, decorators);
99
- });
100
- };
@@ -1,56 +0,0 @@
1
- /*
2
- * Copyright (c) 2020, 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
-
8
- function defaultImport(t, specifiers) {
9
- const defaultImport = specifiers.find((s) => t.isImportDefaultSpecifier(s));
10
- return defaultImport && defaultImport.local.name;
11
- }
12
-
13
- module.exports = function ({ types: t }) {
14
- return function (path) {
15
- const body = path.get('body');
16
- const importStatements = body.filter((s) => s.isImportDeclaration());
17
- const visited = new Map();
18
-
19
- importStatements.forEach((importPath) => {
20
- const sourceLiteral = importPath.node.source;
21
-
22
- // If the import is of the type import * as X, just ignore it since we can't dedupe
23
- if (importPath.node.specifiers.some(t.isImportNamespaceSpecifier)) {
24
- return;
25
- }
26
-
27
- // If we have seen the same source, we will try to dedupe it
28
- if (visited.has(sourceLiteral.value)) {
29
- const visitedImport = visited.get(sourceLiteral.value);
30
- const visitedSpecifiers = visitedImport.node.specifiers;
31
- const visitedDefaultImport = defaultImport(t, visitedSpecifiers);
32
-
33
- // We merge all the named imports unless is a default with the same name
34
- let canImportBeRemoved = true;
35
- importPath.node.specifiers.forEach((s) => {
36
- if (visitedDefaultImport && t.isImportDefaultSpecifier(s)) {
37
- if (visitedDefaultImport !== s.local.name) {
38
- canImportBeRemoved = false;
39
- }
40
- } else {
41
- visitedSpecifiers.push(s);
42
- }
43
- });
44
-
45
- if (canImportBeRemoved) {
46
- importPath.remove();
47
- }
48
-
49
- // We need to sort the imports due to a bug in babel where default must be first
50
- visitedSpecifiers.sort((a) => (t.isImportDefaultSpecifier(a) ? -1 : 1));
51
- } else {
52
- visited.set(sourceLiteral.value, importPath);
53
- }
54
- });
55
- };
56
- };
@@ -1,70 +0,0 @@
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 moduleImports = require('@babel/helper-module-imports');
8
- const { LWCClassErrors } = require('@lwc/errors');
9
-
10
- const { generateError } = require('./utils');
11
-
12
- function getImportSource(path) {
13
- return path.parentPath.get('arguments.0');
14
- }
15
-
16
- function validateImport(sourcePath) {
17
- if (!sourcePath.isStringLiteral()) {
18
- throw generateError(sourcePath, {
19
- errorInfo: LWCClassErrors.INVALID_DYNAMIC_IMPORT_SOURCE_STRICT,
20
- messageArgs: [String(sourcePath)],
21
- });
22
- }
23
- }
24
- /*
25
- * Expected API for this plugin:
26
- * { dynamicImports: { loader: string, strictSpecifier: boolean } }
27
- */
28
- module.exports = function () {
29
- function getLoaderRef(path, loaderName, state) {
30
- if (!state.loaderRef) {
31
- state.loaderRef = moduleImports.addNamed(path, 'load', loaderName);
32
- }
33
- return state.loaderRef;
34
- }
35
-
36
- function addDynamicImportDependency(dependency, state) {
37
- if (!state.dynamicImports) {
38
- state.dynamicImports = [];
39
- }
40
-
41
- if (!state.dynamicImports.includes(dependency)) {
42
- state.dynamicImports.push(dependency);
43
- }
44
- }
45
-
46
- return {
47
- Import(path, state) {
48
- const { dynamicImports } = state.opts;
49
- if (!dynamicImports) {
50
- return;
51
- }
52
-
53
- const { loader, strictSpecifier } = dynamicImports;
54
- const sourcePath = getImportSource(path);
55
-
56
- if (strictSpecifier) {
57
- validateImport(sourcePath);
58
- }
59
-
60
- if (loader) {
61
- const loaderId = getLoaderRef(path, loader, state);
62
- path.replaceWith(loaderId);
63
- }
64
-
65
- if (sourcePath.isStringLiteral()) {
66
- addDynamicImportDependency(sourcePath.node.value, state);
67
- }
68
- },
69
- };
70
- };
package/src/index.d.ts DELETED
@@ -1,10 +0,0 @@
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
-
8
- import type { PluginObj } from '@babel/core';
9
-
10
- export default function babelPluginComponent(): PluginObj;
package/src/index.js DELETED
@@ -1,77 +0,0 @@
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 component = require('./component');
8
- const {
9
- decorators,
10
- removeImportedDecoratorSpecifiers,
11
- validateImportedLwcDecoratorUsage,
12
- } = require('./decorators');
13
- const dedupeImports = require('./dedupe-imports');
14
- const dynamicImports = require('./dynamic-imports');
15
- const scopeCssImports = require('./scope-css-imports');
16
- const compilerVersionNumber = require('./compiler-version-number');
17
- const { getEngineImportSpecifiers } = require('./utils');
18
-
19
- /**
20
- * The transform is done in 2 passes:
21
- * - First, apply in a single AST traversal the decorators and the component transformation.
22
- * - Then, in a second path transform class properties using the official babel plugin "babel-plugin-transform-class-properties".
23
- */
24
- module.exports = function LwcClassTransform(api) {
25
- const { ExportDefaultDeclaration: transformCreateRegisterComponent } = component(api);
26
- const { Class: transformDecorators } = decorators(api);
27
- const { Import: transformDynamicImports } = dynamicImports(api);
28
- const { ClassBody: addCompilerVersionNumber } = compilerVersionNumber(api);
29
-
30
- return {
31
- manipulateOptions(opts, parserOpts) {
32
- parserOpts.plugins.push('classProperties', [
33
- 'decorators',
34
- { decoratorsBeforeExport: true },
35
- ]);
36
- },
37
-
38
- visitor: {
39
- // The LWC babel plugin is incompatible with other plugins. To get around this, we run the LWC babel plugin
40
- // first by running all its traversals from this Program visitor.
41
- Program: {
42
- enter(path) {
43
- const engineImportSpecifiers = getEngineImportSpecifiers(path);
44
-
45
- // Validate the usage of LWC decorators.
46
- validateImportedLwcDecoratorUsage(engineImportSpecifiers);
47
-
48
- // Add ?scoped=true to *.scoped.css imports
49
- scopeCssImports(api, path);
50
- },
51
- exit(path) {
52
- const engineImportSpecifiers = getEngineImportSpecifiers(path);
53
- removeImportedDecoratorSpecifiers(engineImportSpecifiers);
54
-
55
- // Will eventually be removed to eliminate unnecessary complexity. Rollup already does this for us.
56
- dedupeImports(api)(path);
57
- },
58
- },
59
-
60
- Import(path, state) {
61
- transformDynamicImports(path, state);
62
- },
63
-
64
- Class(path) {
65
- transformDecorators(path);
66
- },
67
-
68
- ClassBody(path) {
69
- addCompilerVersionNumber(path);
70
- },
71
-
72
- ExportDefaultDeclaration(path, state) {
73
- transformCreateRegisterComponent(path, state);
74
- },
75
- },
76
- };
77
- };
@@ -1,23 +0,0 @@
1
- /*
2
- * Copyright (c) 2020, 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
-
8
- // Add ?scoped=true to any imports ending with .scoped.css. This signals that the stylesheet
9
- // should be treated as "scoped".
10
- module.exports = function ({ types: t }, path) {
11
- const programPath = path.isProgram() ? path : path.findParent((node) => node.isProgram());
12
-
13
- return programPath.get('body').forEach((node) => {
14
- const source = node.get('source');
15
- if (
16
- node.isImportDeclaration() &&
17
- source.type === 'StringLiteral' &&
18
- source.node.value.endsWith('.scoped.css')
19
- ) {
20
- source.replaceWith(t.stringLiteral(source.node.value + '?scoped=true'));
21
- }
22
- });
23
- };