Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add JSDoc for some exports @W-13278716 #4014

Merged
merged 44 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
8196282
chore: add temp file for tracking all exports
wjhsf Feb 19, 2024
f5ec19c
docs(shared): add jsdoc for language features
wjhsf Feb 19, 2024
6b76c28
Merge branch 'master' into wjh/document-exports-0
wjhsf Feb 21, 2024
3c28e31
chore: missed an export
wjhsf Feb 21, 2024
3141cb1
docs(exports): add jsdoc for @lwc/shared language features
wjhsf Feb 21, 2024
1d79d67
style: add eslint-plugin-jsdoc
wjhsf Feb 21, 2024
bf1213f
chore: eslint-plugin-jsdoc auto fixes
wjhsf Feb 21, 2024
43605be
chore(linter): manual fixes for jsdoc rules
wjhsf Feb 21, 2024
d62f634
chore: simplify env config for test files
wjhsf Feb 21, 2024
d43a1a1
style(jsdoc): enforce documenting yields
wjhsf Feb 21, 2024
8be08d4
docs: include @param in all jsdocs, but not descriptions (yet)
wjhsf Feb 21, 2024
210f565
Merge branch 'wjh/eslint-plugin-jsdoc' into wjh/document-exports-0
wjhsf Feb 21, 2024
8dca33d
docs(exports): fully document all @lwc/shared language features
wjhsf Feb 21, 2024
dc4220e
chore: remove temp file
wjhsf Feb 21, 2024
e4eff02
chore: lint JSDoc in @lwc/shared
wjhsf Feb 21, 2024
b835d63
chore(eslint): suppress unimportant warnings
wjhsf Feb 21, 2024
269d4e7
docs(rollup-plugin): add jsdoc for main export
wjhsf Feb 21, 2024
f2778f9
fix: use JSDoc comment instead of plain multiline
wjhsf Feb 21, 2024
4de1ed2
docs(babel-plugin-component): polish JSDoc for main plugin export
wjhsf Feb 21, 2024
0ee1a95
chore: mark progress in .eslintrc
wjhsf Feb 21, 2024
6cc5d68
docs(wire-service): polish JSDoc for `register`
wjhsf Feb 21, 2024
ee984f0
docs(errors): add JSDoc for @lwc/errors
wjhsf Feb 21, 2024
677cd9c
docs(errors): polish JSDoc for @lwc/features
wjhsf Feb 21, 2024
6023652
chore: mark @lwc/style-compiler as documented
wjhsf Feb 21, 2024
1b334b7
docs(template-compiler): add bad JSDoc for top-level exports
wjhsf Feb 21, 2024
84badcc
chore(jsdoc): comment block is not jsdoc
wjhsf Feb 22, 2024
3b61a9b
chore: revert jsdoc changes to 3rd party files
wjhsf Feb 22, 2024
bcd8f21
chore(eslint): enforce stricter JSDoc rules
wjhsf Feb 22, 2024
e4abc8f
docs: improve JSDoc in root scripts
wjhsf Feb 22, 2024
eb014b6
chore(eslint): auto-fixes for new JSDoc rules
wjhsf Feb 22, 2024
0f0de70
chore(eslint): manual for new JSDoc rules
wjhsf Feb 22, 2024
eabbfee
Merge branch 'wjh/eslint-plugin-jsdoc-tweaks' into wjh/document-expor…
wjhsf Feb 22, 2024
3e48974
chore: fix bad merge
wjhsf Feb 22, 2024
7c30350
docs: manual JSDoc tweaks post-merge
wjhsf Feb 22, 2024
2e022d0
docs(style-compiler): add JSDoc for top-level exports
wjhsf Feb 22, 2024
0a8c2bd
chore: mark style-compiler as complete
wjhsf Feb 22, 2024
9c37470
docs(style-compiler): use correct name in README
wjhsf Feb 22, 2024
a9df37c
revert: remove useless empty JSDoc
wjhsf Feb 22, 2024
fc6404c
revert: don't JSDoc 3rd party
wjhsf Feb 22, 2024
e295ab4
Merge branch 'master' into wjh/document-exports-1
wjhsf Feb 22, 2024
9431f24
docs(module-resolver): add JSDoc for main export
wjhsf Feb 22, 2024
a487ef0
Merge branch 'master' into wjh/document-exports-1
wjhsf Feb 23, 2024
a5dba28
revert: accidental JSDocification of __PURE__ annotations
wjhsf Feb 23, 2024
62be5dc
Update packages/@lwc/errors/src/compiler/utils.ts
wjhsf Feb 27, 2024
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
23 changes: 17 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,18 @@
"packages/@lwc/perf-benchmarks-components/**",
"packages/@lwc/perf-benchmarks/**",
// TODO [W-13278716]: All top-level exports should have JSDOC enforced
"packages/@lwc/babel-plugin-component/**",
"packages/@lwc/compiler/**",
"packages/@lwc/engine-core/**",
"packages/@lwc/engine-dom/**",
"packages/@lwc/engine-server/**",
"packages/@lwc/errors/**",
"packages/@lwc/features/**",
// Package-level exports are documented, but not all file-level exports are, so we
// should keep these disabled for now
"packages/@lwc/babel-plugin-component/**",
"packages/@lwc/module-resolver/**",
"packages/@lwc/rollup-plugin/**",
"packages/@lwc/shared/**",
"packages/@lwc/style-compiler/**",
"packages/@lwc/synthetic-shadow/**",
"packages/@lwc/template-compiler/**",
"packages/@lwc/wire-service/**"
"packages/@lwc/template-compiler/**"
],
"rules": {
"jsdoc/require-jsdoc": "off",
Expand All @@ -337,6 +335,19 @@
"jsdoc/require-returns": "off",
"jsdoc/require-throws": "off"
}
},
// TODO [W-13278716]: Not everything *needs* an example, so I'll probably disable the rule
// when the ticket is complete, but for now I want to enable by default and disable as I go.
{
"files": [
"packages/@lwc/babel-plugin-component/**",
"packages/@lwc/errors/**",
"packages/@lwc/rollup-plugin/**",
"packages/@lwc/wire-service/**"
],
"rules": {
"jsdoc/require-example": "off"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function validateImport(sourcePath: NodePath<types.Node>, state: LwcBabelPluginP
}
}

/*
/**
* Expected API for this plugin:
* { dynamicImports: { loader: string, strictSpecifier: boolean } }
*/
Expand Down
31 changes: 24 additions & 7 deletions packages/@lwc/errors/src/compiler/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
Expand All @@ -25,6 +25,12 @@ export interface ErrorConfig {
origin?: CompilerDiagnosticOrigin;
}

/**
* Generates a friendly error message for the given error type, using the provided template values.
* @param errorInfo The object holding the error metadata.
* @param args Values used to fill the error message template.
* @returns The generated error message.
*/
export function generateErrorMessage(errorInfo: LWCErrorInfo, args?: any[]): string {
const message = Array.isArray(args)
? templateString(errorInfo.message, args)
Expand All @@ -43,6 +49,7 @@ export function generateErrorMessage(errorInfo: LWCErrorInfo, args?: any[]): str
* info about the error's code and its origin (filename, line, column) when applicable.
* @param errorInfo The object holding the error metadata.
* @param config A config object providing any message arguments and origin info needed to create the error.
* @returns The generated compiler diagnostic object.
*/
export function generateCompilerDiagnostic(
errorInfo: LWCErrorInfo,
Expand All @@ -69,6 +76,7 @@ export function generateCompilerDiagnostic(
* the error's code and its origin (filename, line, column) when applicable.
* @param errorInfo The object holding the error metadata.
* @param config A config object providing any message arguments and origin info needed to create the error.
* @returns The generated compiler error.
*/
export function generateCompilerError(
errorInfo: LWCErrorInfo,
Expand All @@ -85,6 +93,13 @@ export function generateCompilerError(
return error;
}

/**
* Validates that the provided condition is truthy.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Validates that the provided condition is truthy.
* Validates that the provided condition is true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function checks for truthiness, not for === true, so I think "truthy"/"falsy" are more accurate here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, I just saw that the type was boolean so we would only get either true or false

* @param condition Condition to check.
* @param errorInfo The object holding the error metadata.
* @param args Values used to fill the error message template.
* @throws Throws a compiler error if the provided condition is falsy.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @throws Throws a compiler error if the provided condition is falsy.
* @throws Throws a compiler error if the provided condition is false.

*/
export function invariant(condition: boolean, errorInfo: LWCErrorInfo, args?: any[]) {
if (!condition) {
throw generateCompilerError(errorInfo, {
Expand All @@ -95,9 +110,10 @@ export function invariant(condition: boolean, errorInfo: LWCErrorInfo, args?: an

/**
* Normalizes a received error into a CompilerError. Adds any provided additional origin info.
* @param errorInfo
* @param error
* @param origin
* @param errorInfo The object holding the error metadata.
* @param error The original error.
* @param origin The origin associated with the error.
* @returns The normalized compiler error.
*/
export function normalizeToCompilerError(
errorInfo: LWCErrorInfo,
Expand Down Expand Up @@ -125,9 +141,10 @@ export function normalizeToCompilerError(

/**
* Normalizes a received error into a CompilerDiagnostic. Adds any provided additional origin info.
* @param errorInfo
* @param error
* @param origin
* @param errorInfo The object holding the error metadata.
* @param error The original error.
* @param origin The origin of the error.
* @returns The normalized compiler diagnostic object.
*/
export function normalizeToDiagnostic(
errorInfo: LWCErrorInfo,
Expand Down
21 changes: 20 additions & 1 deletion packages/@lwc/errors/src/compiler/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
Expand Down Expand Up @@ -58,6 +58,11 @@ export class CompilerError extends Error implements CompilerDiagnostic {
}
}

/**
* Extracts an error code from the given error.
* @param error The error to check.
* @returns The found error code.
wjhsf marked this conversation as resolved.
Show resolved Hide resolved
*/
export function getCodeFromError(error: any): number | undefined {
if (error.lwcCode && typeof error.lwcCode === 'number') {
return error.lwcCode;
Expand All @@ -67,6 +72,13 @@ export function getCodeFromError(error: any): number | undefined {
return undefined;
}

/**
* Extracts the filename from the provided parameters, preferring to use the compiler diagnostic
* origin, if provided.
* @param origin Compiler diagnositic origin data
* @param obj Any object that might have a filename associated
* @returns The filename, if found.
*/
export function getFilename(
origin: CompilerDiagnosticOrigin | undefined,
obj?: any
Expand All @@ -80,6 +92,13 @@ export function getFilename(
return undefined;
}

/**
* Extracts the location from the provided parameters, preferring to use the compiler diagnostic
* origin, if provided.
* @param origin Compiler diagnositic origin data
* @param obj Any object that might have a location property
* @returns The location, if found.
*/
export function getLocation(
origin: CompilerDiagnosticOrigin | undefined,
obj?: any
Expand Down
8 changes: 7 additions & 1 deletion packages/@lwc/errors/src/shared/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
const templateRegex = /\{([0-9]+)\}/g;
/**
* Replaces {0} in the given string with the value from the given array
* @param template Template string to fill
* @param args Values to fill with
* @returns Filled string
*/
export function templateString(template: string, args: any[]) {
return template.replace(templateRegex, (_, index) => {
return args[index];
Expand Down
13 changes: 8 additions & 5 deletions packages/@lwc/features/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
Expand Down Expand Up @@ -31,8 +31,10 @@ const flags: Partial<FeatureFlagMap> = (globalThis as any).lwcRuntimeFlags;
/**
* Set the value at runtime of a given feature flag. This method only be invoked once per feature
* flag. It is meant to be used during the app initialization.
* @param name
* @param value
* @param name Name of the feature flag to set
* @param value Whether the feature flag should be enabled
* @throws Will throw if a non-boolean value is provided when running in production.
* @example setFeatureFlag("DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE", true)
*/
export function setFeatureFlag(name: FeatureFlagName, value: FeatureFlagValue): void {
if (!isBoolean(value)) {
Expand Down Expand Up @@ -73,8 +75,9 @@ export function setFeatureFlag(name: FeatureFlagName, value: FeatureFlagValue):
/**
* Set the value at runtime of a given feature flag. This method should only be used for testing
* purposes. It is a no-op when invoked in production mode.
* @param name
* @param value
* @param name Name of the feature flag to enable or disable
* @param value Whether the feature flag should be enabled
* @example setFeatureFlag("DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE", true)
*/
export function setFeatureFlagForTest(name: FeatureFlagName, value: FeatureFlagValue): void {
// This may seem redundant, but `process.env.NODE_ENV === 'test-karma-lwc'` is replaced by Karma tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createElement } from 'lwc';
import Container from 'x/container';
import ParentSpecialized from 'x/parentSpecialized';

/**
/*
<div>
<x-container>
<p>ctx first text</p>
Expand Down
21 changes: 20 additions & 1 deletion packages/@lwc/module-resolver/src/resolve-module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
Expand Down Expand Up @@ -186,6 +186,25 @@ function resolveModuleRecordType(
});
}

/**
* Resolves LWC modules using a custom resolution algorithm, using the configuration from your
* project's `lwc.config.json` or the `"lwc"` key in the `package.json`. The resolver iterates
* through the modules provided in the config and returns the first module that matches the
* requested module specifier. There are three types of module record:
* - Alias module record: A file path where an LWC module can be resolved.
* - Directory module record: A folder path where LWC modules can be resolved.
* - NPM package module record: An NPM package that exposes one or more LWC modules.
* @param importee The module specifier to resolve
* @param dirname The directory to resolve relative to
* @param config Root directory and additional modules to
* @param config.rootDir Root dir use for module resolution, defaults to `process.cwd()`
* @param config.modules Array of additional modules to check, takes precedence over the project config
* @returns A registry entry for the resolved module
* @throws If the resolver processes an invalid configuration, it throws an error with the
* LWC_CONFIG_ERROR error code. If the resolver can't locate the module, it throws an error with the
* NO_LWC_MODULE_FOUND error code.
* @example resolveModule('x/foo', './index.js')
*/
export function resolveModule(
importee: string,
dirname: string,
Expand Down
10 changes: 8 additions & 2 deletions packages/@lwc/module-resolver/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/

export function isObject(obj: any): obj is object {
/**
* Determines whether the given value is an object or null.
* @param obj The value to check
* @returns true if the value is an object or null
* @example isObject(null) // true
*/
export function isObject(obj: any): obj is object | null {
return typeof obj === 'object';
}
7 changes: 6 additions & 1 deletion packages/@lwc/rollup-plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
Expand Down Expand Up @@ -144,6 +144,11 @@ function transformWarningToRollupLog(
return result;
}

/**
* Rollup plugin for bundling LWC components
* @param pluginOptions LWC rollup plugin options
* @returns LWC rollup plugin
*/
export default function lwc(pluginOptions: RollupLwcOptions = {}): Plugin {
const filter = pluginUtils.createFilter(pluginOptions.include, pluginOptions.exclude);

Expand Down
6 changes: 3 additions & 3 deletions packages/@lwc/style-compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ yarn add --dev @lwc/style-compiler
## Usage

```js
const compile = require('@lwc/style-compiler');
const { transform } = require('@lwc/style-compiler');

const source = `
:host {
Expand All @@ -32,12 +32,12 @@ const source = `
}
`;

const { code } = compile(source, 'example.css');
const { code } = transform(source, 'example.css');
```

### API

#### `compile(source, id, options)`
#### `transform(source, id, options)`

**Options:**

Expand Down
22 changes: 20 additions & 2 deletions packages/@lwc/style-compiler/src/transform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, salesforce.com, inc.
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
Expand All @@ -10,10 +10,11 @@ import { getAPIVersionFromNumber } from '@lwc/shared';
import serialize from './serialize';
import postcssLwc from './postcss-lwc-plugin';

/** Configuration options for CSS transforms. */
export interface Config {
/**
* @deprecated - Custom property transforms are deprecated because IE11 and other legacy browsers are no longer supported.
* CSS custom properties configuration
* @deprecated Custom property transforms are deprecated because IE11 and other legacy browsers are no longer supported.
*/
// TODO [#3266]: Remove StylesheetConfig as part of breaking change wishlist
customProperties?: {
Expand All @@ -28,6 +29,23 @@ export interface Config {
apiVersion?: number;
}

/**
* Transforms CSS for use with LWC components.
* @param src Contents of the CSS source file
* @param id Filename of the CSS source file
* @param config Transformation options
* @returns Transformed CSS
* @example
* const {transform} = require('@lwc/style-compiler');
* const source = `
* :host {
* opacity: 0.4;
* }
* span {
* text-transform: uppercase;
* }`;
* const { code } = transform(source, 'example.css');
*/
export function transform(src: string, id: string, config: Config = {}): { code: string } {
if (src === '') {
return { code: 'export default undefined' };
Expand Down
1 change: 0 additions & 1 deletion packages/@lwc/synthetic-shadow/src/faux-shadow/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ function markElementAsPortal(elm: Element) {
* child nodes.
* - at the moment, there is no way to undo this operation, once the element is
* marked as $domManual$, setting it to false does nothing.
*
*/
// TODO [#1306]: rename this to $observerConnection$
defineProperty(Element.prototype, '$domManual$', {
Expand Down
Loading
Loading