Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@lwc/aria-reflection/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const ARIA_PROPERTIES = [
'ariaValueNow',
'ariaValueText',
'role',
];
] as const;

for (const prop of ARIA_PROPERTIES) {
const attribute = prop.replace(/^aria/, 'aria-').toLowerCase(); // e.g. ariaPosInSet => aria-posinset
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/
export { transform, transformSync } from './transformers/transformer';

export { TransformResult } from './transformers/shared';
export {
export type { TransformResult } from './transformers/shared';
export type {
NormalizedTransformOptions,
TransformOptions,
StylesheetConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/engine-core/src/framework/wiring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

export { createContextProviderWithRegister, createContextWatcher } from './context';

export {
export type {
ConfigCallback,
ConfigValue,
ContextConsumer,
Expand Down
24 changes: 12 additions & 12 deletions packages/@lwc/engine-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ export const HostValueKey = Symbol('value');
export const HostHostKey = Symbol('host');
export const HostContextProvidersKey = Symbol('context-providers');

export enum HostNodeType {
Text = 'text',
Comment = 'comment',
Raw = 'raw',
Element = 'element',
ShadowRoot = 'shadow-root',
}
export const HostNodeType = {
Text: 'text',
Comment: 'comment',
Raw: 'raw',
Element: 'element',
ShadowRoot: 'shadow-root',
} as const;

export interface HostText {
[HostTypeKey]: HostNodeType.Text;
[HostTypeKey]: typeof HostNodeType.Text;
[HostParentKey]: HostElement | null;
[HostValueKey]: string;
}

export interface HostComment {
[HostTypeKey]: HostNodeType.Comment;
[HostTypeKey]: typeof HostNodeType.Comment;
[HostParentKey]: HostElement | null;
[HostValueKey]: string;
}

export interface HostRaw {
[HostTypeKey]: HostNodeType.Raw;
[HostTypeKey]: typeof HostNodeType.Raw;
[HostParentKey]: HostElement | null;
[HostValueKey]: string;
}
Expand All @@ -57,15 +57,15 @@ export interface HostAttribute {
export type HostParentNode = HostElement | HostShadowRoot;

export interface HostShadowRoot {
[HostTypeKey]: HostNodeType.ShadowRoot;
[HostTypeKey]: typeof HostNodeType.ShadowRoot;
[HostChildrenKey]: HostChildNode[];
mode: 'open' | 'closed';
delegatesFocus: boolean;
[HostHostKey]: HostElement;
}

export interface HostElement {
[HostTypeKey]: HostNodeType.Element;
[HostTypeKey]: typeof HostNodeType.Element;
// tagName cannot be used as a public component property as it is
// explicitly given only a getter, so it doesn't need to be a Symbol.
tagName: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/errors/src/compiler/error-info/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const GENERIC_COMPILER_ERROR = {
level: DiagnosticLevel.Error,
strictLevel: DiagnosticLevel.Fatal,
url: '',
};
} as const satisfies LWCErrorInfo;

export const CompilerValidationErrors = {
INVALID_COMPAT_PROPERTY: {
Expand Down
8 changes: 6 additions & 2 deletions packages/@lwc/errors/src/compiler/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CompilerError, getCodeFromError, getFilename, getLocation } from './uti
import type { DiagnosticLevel, LWCErrorInfo } from '../shared/types';
import type { CompilerDiagnosticOrigin, CompilerDiagnostic } from './utils';

export { CompilerDiagnosticOrigin, CompilerDiagnostic, CompilerError } from './utils';
export { type CompilerDiagnosticOrigin, type CompilerDiagnostic, CompilerError } from './utils';

export * from './error-info';

Expand Down Expand Up @@ -98,7 +98,11 @@ export function generateCompilerError(
* @param args Values used to fill the error message template.
* @throws Throws a compiler error if the provided condition is falsy.
*/
export function invariant(condition: boolean, errorInfo: LWCErrorInfo, args?: any[]) {
export function invariant(
condition: boolean,
errorInfo: LWCErrorInfo,
args?: any[]
): asserts condition {
if (!condition) {
throw generateCompilerError(errorInfo, {
messageArgs: args,
Expand Down
14 changes: 8 additions & 6 deletions packages/@lwc/errors/src/compiler/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import type { ErrorConfig } from './errors';
/**
* Pattern modeled after @lwc/engine-core's reporting.ts system
*/
export enum CompilerMetrics {
LWCDynamicDirective = 'lwc-dynamic-directive',
LWCRenderModeDirective = 'lwc-render-mode-directive',
LWCSpreadDirective = 'lwc-spread-directive',
DynamicImportTransform = 'dynamic-import-transform',
}
export const CompilerMetrics = {
LWCDynamicDirective: 'lwc-dynamic-directive',
LWCRenderModeDirective: 'lwc-render-mode-directive',
LWCSpreadDirective: 'lwc-spread-directive',
DynamicImportTransform: 'dynamic-import-transform',
} as const;

export type CompilerMetrics = (typeof CompilerMetrics)[keyof typeof CompilerMetrics];

export interface InstrumentationObject {
log: (errorInfo: LWCErrorInfo, config: ErrorConfig) => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/errors/src/compiler/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class CompilerError extends Error implements CompilerDiagnostic {
message: string,
filename?: string,
location?: Location,
level = DiagnosticLevel.Error
level: DiagnosticLevel = DiagnosticLevel.Error
) {
super(message);

Expand Down
14 changes: 8 additions & 6 deletions packages/@lwc/errors/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
export enum DiagnosticLevel {
export const DiagnosticLevel = {
/** Unexpected error, parsing error, bundling error */
Fatal = 0,
Fatal: 0,
/** Linting error with error level, invalid external reference, invalid import, invalid transform */
Error = 1,
Error: 1,
/** Linting error with warning level, usage of an API to be deprecated */
Warning = 2,
Warning: 2,
/** Logging messages */
Log = 3,
}
Log: 3,
} as const;

export type DiagnosticLevel = (typeof DiagnosticLevel)[keyof typeof DiagnosticLevel];

export interface LWCErrorInfo {
code: number;
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/module-resolver/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

export { resolveModule } from './resolve-module';
export {
export { RegistryType } from './types';
export type {
ModuleResolverConfig,
RegistryEntry,
RegistryType,
ModuleRecord,
AliasModuleRecord,
DirModuleRecord,
Expand Down
10 changes: 6 additions & 4 deletions packages/@lwc/module-resolver/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

export enum RegistryType {
alias = 'alias',
dir = 'dir',
}
export const RegistryType = {
alias: 'alias',
dir: 'dir',
} as const;

export type RegistryType = (typeof RegistryType)[keyof typeof RegistryType];

export interface RegistryEntry {
entry: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/module-resolver/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function validateNpmAlias(
exposed: string[],
map: { [key: string]: string },
opts: InnerResolverOptions
) {
): void {
Object.keys(map).forEach((specifier) => {
if (!exposed.includes(specifier)) {
throw new LwcConfigError(
Expand Down
6 changes: 3 additions & 3 deletions packages/@lwc/shared/src/api-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ const allVersions = [
APIVersion.V64_256_SUMMER_25,
APIVersion.V65_258_WINTER_26,
APIVersion.V66_260_SPRING_26,
];
] as const;
const allVersionsSet = /*@__PURE__@*/ new Set(allVersions);
export const LOWEST_API_VERSION = allVersions[0];
export const HIGHEST_API_VERSION = allVersions[allVersions.length - 1];
export const LOWEST_API_VERSION: APIVersion = allVersions[0];
export const HIGHEST_API_VERSION: APIVersion = allVersions[allVersions.length - 1];

/**
*
Expand Down
30 changes: 13 additions & 17 deletions packages/@lwc/shared/src/aria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,20 @@ type AriaAttrToPropMap = {
[Prop in AriaProperty as AriaPropToAttrMap[Prop]]: Prop;
};

const { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } = /*@__PURE__*/ (() => {
const AriaAttrNameToPropNameMap: AriaAttrToPropMap = create(null);
const AriaPropNameToAttrNameMap: AriaPropToAttrMap = create(null);
const AriaAttrNameToPropNameMap: AriaAttrToPropMap = create(null);
const AriaPropNameToAttrNameMap: AriaPropToAttrMap = create(null);

// Synthetic creation of all AOM property descriptors for Custom Elements
forEach.call(AriaPropertyNames, (propName) => {
const attrName = StringToLowerCase.call(
StringReplace.call(propName, /^aria/, () => 'aria-')
) as AriaAttribute;
// These type assertions are because the map types are a 1:1 mapping of ariaX to aria-x.
// TypeScript knows we have one of ariaX | ariaY and one of aria-x | aria-y, and tries to
// prevent us from doing ariaX: aria-y, but we that it's safe.
(AriaAttrNameToPropNameMap[attrName] as AriaProperty) = propName;
(AriaPropNameToAttrNameMap[propName] as AriaAttribute) = attrName;
});

return { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap };
})();
// Synthetic creation of all AOM property descriptors for Custom Elements
forEach.call(AriaPropertyNames, (propName) => {
const attrName = StringToLowerCase.call(
StringReplace.call(propName, /^aria/, () => 'aria-')
) as AriaAttribute;
// These type assertions are because the map types are a 1:1 mapping of ariaX to aria-x.
// TypeScript knows we have one of ariaX | ariaY and one of aria-x | aria-y, and tries to
// prevent us from doing ariaX: aria-y, but we that it's safe.
(AriaAttrNameToPropNameMap[attrName] as AriaProperty) = propName;
(AriaPropNameToAttrNameMap[propName] as AriaAttribute) = attrName;
});

/**
*
Expand Down
3 changes: 2 additions & 1 deletion packages/@lwc/shared/src/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

/**
*
* @param value
Expand Down Expand Up @@ -31,7 +32,7 @@ export function isTrue(value: any, msg: string): asserts value {
* @param value
* @param msg
*/
export function isFalse(value: any, msg: string) {
export function isFalse(value: any, msg: string): void {
if (value) {
throw new Error(`Assert Violation: ${msg}`);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/@lwc/shared/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ export interface ContextBinding<C extends object> {

let contextKeys: ContextKeys;

export function setContextKeys(config: ContextKeys) {
export function setContextKeys(config: ContextKeys): void {
isFalse(contextKeys, '`setContextKeys` cannot be called more than once');

contextKeys = config;
}

export function getContextKeys() {
export function getContextKeys(): ContextKeys {
return contextKeys;
}

export function setTrustedContextSet(context: WeakSet<object>) {
export function setTrustedContextSet(context: WeakSet<object>): void {
isFalse(trustedContext, 'Trusted Context Set is already set!');

trustedContext = context;
}

export function addTrustedContext(contextParticipant: object) {
export function addTrustedContext(contextParticipant: object): void {
// This should be a no-op when the trustedSignals set isn't set by runtime
trustedContext?.add(contextParticipant);
}
Expand Down
13 changes: 9 additions & 4 deletions packages/@lwc/shared/src/html-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function isGlobalHtmlAttribute(attrName: string): boolean {
}

// These are HTML standard prop/attribute IDL mappings, but are not predictable based on camel/kebab-case conversion
export const SPECIAL_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map([
export const SPECIAL_PROPERTY_ATTRIBUTE_MAPPING: Map<string, string> = /*@__PURE__@*/ new Map([
['accessKey', 'accesskey'],
['readOnly', 'readonly'],
['tabIndex', 'tabindex'],
Expand All @@ -121,7 +121,7 @@ export const SPECIAL_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map([
// descriptors for these properties are added from HTMLElement.prototype to
// LightningElement.prototype. For SSR, in order to match CSR behavior, this
// list is used to determine which attributes to reflect.
export const REFLECTIVE_GLOBAL_PROPERTY_SET = /*@__PURE__@*/ new Set([
export const REFLECTIVE_GLOBAL_PROPERTY_SET: Set<string> = /*@__PURE__@*/ new Set([
'accessKey',
'dir',
'draggable',
Expand Down Expand Up @@ -203,7 +203,7 @@ export function kebabCaseToCamelCase(attrName: string): string {
* Because the template will never call them. It'll always call the camel
* cased version.
*/
export const AMBIGUOUS_PROP_SET = /*@__PURE__@*/ new Map([
export const AMBIGUOUS_PROP_SET: Map<string, string> = /*@__PURE__@*/ new Map([
['bgcolor', 'bgColor'],
['accesskey', 'accessKey'],
['contenteditable', 'contentEditable'],
Expand All @@ -217,4 +217,9 @@ export const AMBIGUOUS_PROP_SET = /*@__PURE__@*/ new Map([
* by users on their components.
* We throw for these.
*/
export const DISALLOWED_PROP_SET = /*@__PURE__@*/ new Set(['is', 'class', 'slot', 'style']);
export const DISALLOWED_PROP_SET: Set<string> = /*@__PURE__@*/ new Set([
'is',
'class',
'slot',
'style',
]);
2 changes: 1 addition & 1 deletion packages/@lwc/ssr-client-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class StyleDeduplicator extends HTMLElement {
* stylesheet.
* It can also be implicitly invoked by importing `@lwc/ssr-client-utils/register-lwc-style` as a bare import.
*/
export function registerLwcStyleComponent() {
export function registerLwcStyleComponent(): void {
customElements.define('lwc-style', StyleDeduplicator);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/ssr-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
export { ClassList } from './class-list';
export {
LightningElement,
LightningElementConstructor,
type LightningElementConstructor,
SYMBOL__DEFAULT_TEMPLATE,
SYMBOL__GENERATE_MARKUP,
SYMBOL__SET_INTERNALS,
Expand All @@ -37,7 +37,7 @@ export { mutationTracker } from './mutation-tracker';
export {
fallbackTmpl,
fallbackTmplNoYield,
GenerateMarkupAsyncYield,
type GenerateMarkupAsyncYield,
renderAttrs,
renderAttrsNoYield,
addSlottedContent,
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/template-compiler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import type { CompilerDiagnostic } from '@lwc/errors';
import type { Root, TemplateCompileResult, TemplateParseResult } from './shared/types';

export * from './shared/types';
export { CustomRendererConfig, CustomRendererElementConfig } from './shared/renderer-hooks';
export { Config } from './config';
export type { CustomRendererConfig, CustomRendererElementConfig } from './shared/renderer-hooks';
export type { Config } from './config';
export { toPropertyName } from './shared/utils';
export { kebabcaseToCamelcase } from './shared/naming';
export { generateScopeTokens } from './scopeTokens';
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/template-compiler/src/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function parseLwcComponent(
);
}

return ast.lwcComponent(parse5Elm.tagName as LwcTagName.Component, parse5ElmLocation);
return ast.lwcComponent(parse5Elm.tagName as typeof LwcTagName.Component, parse5ElmLocation);
}

function parseLwcElementAsBuiltIn(
Expand Down
Loading
Loading