Skip to content

Commit

Permalink
chore: move duplicate consts to @lwc/shared
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso committed Jan 6, 2025
1 parent 147e6b0 commit 9ec59fb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 43 deletions.
21 changes: 0 additions & 21 deletions packages/@lwc/babel-plugin-component/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

// This set is for attributes that have a camel cased property name
// For example, div.tabIndex.
// We do not want users to define @api properties with these names
// Because the template will never call them. It'll always call the camel
// cased version.
const AMBIGUOUS_PROP_SET = new Map([
['bgcolor', 'bgColor'],
['accesskey', 'accessKey'],
['contenteditable', 'contentEditable'],
['tabindex', 'tabIndex'],
['maxlength', 'maxLength'],
['maxvalue', 'maxValue'],
]);

// This set is for attributes that can never be defined
// by users on their components.
// We throw for these.
const DISALLOWED_PROP_SET = new Set(['is', 'class', 'slot', 'style']);

const LWC_PACKAGE_ALIAS = 'lwc';

const LWC_PACKAGE_EXPORTS = {
Expand Down Expand Up @@ -55,9 +36,7 @@ const API_VERSION_KEY = 'apiVersion';
const COMPONENT_CLASS_ID = '__lwc_component_class_internal';

export {
AMBIGUOUS_PROP_SET,
DECORATOR_TYPES,
DISALLOWED_PROP_SET,
LWC_PACKAGE_ALIAS,
LWC_PACKAGE_EXPORTS,
LWC_COMPONENT_PROPERTIES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { DecoratorErrors } from '@lwc/errors';
import { AMBIGUOUS_PROP_SET, DISALLOWED_PROP_SET } from '@lwc/shared';
import { generateError } from '../../utils';
import {
AMBIGUOUS_PROP_SET,
DECORATOR_TYPES,
DISALLOWED_PROP_SET,
LWC_PACKAGE_EXPORTS,
} from '../../constants';
import { DECORATOR_TYPES, LWC_PACKAGE_EXPORTS } from '../../constants';
import { isApiDecorator } from './shared';
import type { types, NodePath } from '@babel/core';
import type { LwcBabelPluginPass } from '../../types';
Expand Down
23 changes: 23 additions & 0 deletions packages/@lwc/shared/src/html-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,26 @@ export function kebabCaseToCamelCase(attrName: string): string {

return result;
}

/**
* This set is for attributes that have a camel cased property name
* For example, div.tabIndex.
* We do not want users to define `@api` properties with these names
* Because the template will never call them. It'll always call the camel
* cased version.
*/
export const AMBIGUOUS_PROP_SET = /*@__PURE__@*/ new Map([
['bgcolor', 'bgColor'],
['accesskey', 'accessKey'],
['contenteditable', 'contentEditable'],
['tabindex', 'tabIndex'],
['maxlength', 'maxLength'],
['maxvalue', 'maxValue'],
]);

/**
* This set is for attributes that can never be defined
* by users on their components.
* We throw for these.
*/
export const DISALLOWED_PROP_SET = /*@__PURE__@*/ new Set(['is', 'class', 'slot', 'style']);
15 changes: 0 additions & 15 deletions packages/@lwc/ssr-compiler/src/compile-js/decorators/api/consts.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import { DecoratorErrors } from '@lwc/errors';
import { DISALLOWED_PROP_SET, AMBIGUOUS_PROP_SET } from '@lwc/shared';
import { generateError } from '../../errors';
import { type ComponentMetaState } from '../../types';
import { DISALLOWED_PROP_SET, AMBIGUOUS_PROP_SET } from './consts';
import type { Identifier, MethodDefinition, PropertyDefinition } from 'estree';

export type ApiMethodDefinition = MethodDefinition & {
Expand Down

0 comments on commit 9ec59fb

Please sign in to comment.