Skip to content

Commit

Permalink
chore(babel-plugin-component): remove redundant type-only dependencies (
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Nov 21, 2024
1 parent 7e27944 commit 9d0e5b9
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 34 deletions.
2 changes: 0 additions & 2 deletions packages/@lwc/babel-plugin-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
},
"dependencies": {
"@babel/helper-module-imports": "7.25.9",
"@babel/traverse": "^7.25.7",
"@babel/types": "^7.25.8",
"@lwc/errors": "8.10.1",
"@lwc/shared": "8.10.1",
"line-column": "~1.0.2"
Expand Down
4 changes: 1 addition & 3 deletions packages/@lwc/babel-plugin-component/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import {
API_VERSION_KEY,
COMPONENT_CLASS_ID,
} from './constants';
import type * as types from '@babel/types';
import type { NodePath } from '@babel/traverse';
import type { Visitor } from '@babel/core';
import type { types, NodePath, Visitor } from '@babel/core';
import type { BabelAPI, BabelTypes, LwcBabelPluginPass } from './types';

function getBaseName(classPath: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/
import { DECORATOR_TYPES, LWC_COMPONENT_PROPERTIES } from '../../constants';
import { isApiDecorator } from './shared';
import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { types, NodePath } from '@babel/core';
import type { DecoratorMeta } from '../index';
import type { BabelTypes } from '../../types';
import type { ClassBodyItem } from '../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
LWC_PACKAGE_EXPORTS,
} from '../../constants';
import { isApiDecorator } from './shared';
import type { NodePath } from '@babel/traverse';
import type { types } from '@babel/core';
import type { types, NodePath } from '@babel/core';
import type { LwcBabelPluginPass } from '../../types';
import type { DecoratorMeta } from '../index';

Expand Down
8 changes: 3 additions & 5 deletions packages/@lwc/babel-plugin-component/src/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import api from './api';
import wire from './wire';
import track from './track';
import type { BabelAPI, BabelTypes, LwcBabelPluginPass } from '../types';
import type { Binding, NodePath } from '@babel/traverse';
import type { Node, types, Visitor } from '@babel/core';
import type { Node, types, Visitor, NodePath } from '@babel/core';
import type { ClassBodyItem, ImportSpecifier, LwcDecoratorName } from './types';

const DECORATOR_TRANSFORMS = [api, wire, track];
Expand Down Expand Up @@ -127,8 +126,7 @@ function validateImportedLwcDecoratorUsage(
});
}

function isImportedFromLwcSource(decoratorBinding: Binding) {
const bindingPath = decoratorBinding.path;
function isImportedFromLwcSource(bindingPath: NodePath) {
return (
bindingPath.isImportSpecifier() &&
(bindingPath.parent as types.ImportDeclaration).source.value === 'lwc'
Expand All @@ -143,7 +141,7 @@ function isImportedFromLwcSource(decoratorBinding: Binding) {
function validate(decorators: DecoratorMeta[], state: LwcBabelPluginPass) {
for (const { name, path } of decorators) {
const binding = path.scope.getBinding(name);
if (binding === undefined || !isImportedFromLwcSource(binding)) {
if (binding === undefined || !isImportedFromLwcSource(binding.path)) {
throw generateInvalidDecoratorError(path, state);
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/@lwc/babel-plugin-component/src/decorators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import type { NodePath } from '@babel/traverse';
import type { types } from '@babel/core';
import type { types, NodePath } from '@babel/core';
import type { LWCErrorInfo } from '@lwc/errors';
import type * as t from '@babel/types';

export type ImportSpecifier = {
name: string;
Expand All @@ -24,8 +22,8 @@ export type DecoratorErrorOptions = {
// Copied from:
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a767e24/types/babel__traverse/index.d.ts#L143-L148
export type BindingOptions = {
id: t.LVal;
init?: t.Expression | undefined;
id: types.LVal;
init?: types.Expression | undefined;
unique?: boolean | undefined;
kind?: 'var' | 'let' | 'const' | undefined;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/
import { LWC_COMPONENT_PROPERTIES } from '../../constants';
import { isWireDecorator } from './shared';
import type { types } from '@babel/core';
import type { NodePath, Scope } from '@babel/traverse';
import type { types, NodePath } from '@babel/core';
import type { DecoratorMeta } from '../index';
import type { BabelTypes } from '../../types';
import type { BindingOptions } from '../types';
Expand Down Expand Up @@ -213,7 +212,7 @@ const SUPPORTED_VALUE_TO_TYPE_MAP = {
BooleanLiteral: 'boolean',
};

const scopedReferenceLookup = (scope: Scope) => (name: string) => {
const scopedReferenceLookup = (scope: NodePath['scope']) => (name: string) => {
const binding = scope.getBinding(name);

let type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { DecoratorErrors } from '@lwc/errors';
import { LWC_PACKAGE_EXPORTS } from '../../constants';
import { generateError } from '../../utils';
import { isWireDecorator } from './shared';
import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { types, NodePath } from '@babel/core';
import type { LwcBabelPluginPass } from '../../types';
import type { DecoratorMeta } from '../index';

Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/babel-plugin-component/src/dedupe-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { types, NodePath } from '@babel/core';
import type { BabelAPI, BabelTypes } from './types';

function defaultImport(
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/babel-plugin-component/src/dynamic-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import { addNamed } from '@babel/helper-module-imports';
import { CompilerMetrics, LWCClassErrors } from '@lwc/errors';
import { generateError, incrementMetricCounter } from './utils';
import type { types, Visitor } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { types, Visitor, NodePath } from '@babel/core';
import type { LwcBabelPluginPass } from './types';

function getImportSource(path: NodePath<types.Import>): NodePath<types.Node> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

// Add ?scoped=true to any imports ending with .scoped.css. This signals that the stylesheet
// should be treated as "scoped".
import type { Node } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { Node, NodePath } from '@babel/core';
import type { BabelAPI } from './types';

export default function ({ types: t }: BabelAPI, path: NodePath): void {
Expand Down
3 changes: 1 addition & 2 deletions packages/@lwc/babel-plugin-component/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import lineColumn from 'line-column';
import { generateErrorMessage } from '@lwc/errors';
import { LWC_PACKAGE_ALIAS } from './constants';
import type { types } from '@babel/core';
import type { NodePath } from '@babel/traverse';
import type { types, NodePath } from '@babel/core';
import type { CompilerMetrics } from '@lwc/errors';
import type { DecoratorErrorOptions, ImportSpecifier } from './decorators/types';
import type { LwcBabelPluginPass } from './types';
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@
"@babel/parser" "^7.25.9"
"@babel/types" "^7.25.9"

"@babel/traverse@^7.16.0", "@babel/traverse@^7.24.7", "@babel/traverse@^7.24.8", "@babel/traverse@^7.25.0", "@babel/traverse@^7.25.1", "@babel/traverse@^7.25.3", "@babel/traverse@^7.25.7", "@babel/traverse@^7.25.9", "@babel/traverse@^7.4.5":
"@babel/traverse@^7.16.0", "@babel/traverse@^7.24.7", "@babel/traverse@^7.24.8", "@babel/traverse@^7.25.0", "@babel/traverse@^7.25.1", "@babel/traverse@^7.25.3", "@babel/traverse@^7.25.9", "@babel/traverse@^7.4.5":
version "7.25.9"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.25.9.tgz#a50f8fe49e7f69f53de5bea7e413cd35c5e13c84"
integrity sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==
Expand All @@ -1076,7 +1076,7 @@
debug "^4.3.1"
globals "^11.1.0"

"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.10", "@babel/types@^7.24.7", "@babel/types@^7.24.8", "@babel/types@^7.25.4", "@babel/types@^7.25.8", "@babel/types@^7.25.9", "@babel/types@^7.26.0", "@babel/types@^7.4.4":
"@babel/types@^7.0.0", "@babel/types@^7.20.7", "@babel/types@^7.22.10", "@babel/types@^7.24.7", "@babel/types@^7.24.8", "@babel/types@^7.25.4", "@babel/types@^7.25.9", "@babel/types@^7.26.0", "@babel/types@^7.4.4":
version "7.26.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.26.0.tgz#deabd08d6b753bc8e0f198f8709fb575e31774ff"
integrity sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA==
Expand Down

0 comments on commit 9d0e5b9

Please sign in to comment.