Skip to content

Commit

Permalink
chore(deps): update prettier to v3 (#4443)
Browse files Browse the repository at this point in the history
  • Loading branch information
cardoso authored Aug 7, 2024
1 parent fd3c9e6 commit cdb169a
Show file tree
Hide file tree
Showing 46 changed files with 588 additions and 558 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"@rollup/plugin-typescript": "^11.1.6",
"@types/babel__core": "^7.20.5",
"@types/node": "^22.1.0",
"@types/prettier": "^2.7.3",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/ui": "^2.0.5",
"bytes": "^3.1.2",
Expand All @@ -64,7 +63,7 @@
"lint-staged": "^15.2.8",
"magic-string": "^0.30.11",
"nx": "19.5.6",
"prettier": "^2.8.8",
"prettier": "^3.3.3",
"rollup": "^4.20.0",
"terser": "^5.31.3",
"tslib": "^2.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,33 @@ function computePublicPropsConfig(
publicPropertyMetas: DecoratorMeta[],
classBodyItems: NodePath<ClassBodyItem>[]
) {
return publicPropertyMetas.reduce((acc, { propertyName, decoratedNodeType }) => {
if (!(propertyName in acc)) {
acc[propertyName] = {};
}
acc[propertyName].config |= getPropertyBitmask(decoratedNodeType);
return publicPropertyMetas.reduce(
(acc, { propertyName, decoratedNodeType }) => {
if (!(propertyName in acc)) {
acc[propertyName] = {};
}
acc[propertyName].config |= getPropertyBitmask(decoratedNodeType);

if (
decoratedNodeType === DECORATOR_TYPES.GETTER ||
decoratedNodeType === DECORATOR_TYPES.SETTER
) {
// With the latest decorator spec, only one of the getter/setter pair needs a decorator.
// We need to add the proper bitmask for the sibling getter/setter if it exists.
const pairType = getSiblingGetSetPairType(
propertyName,
decoratedNodeType,
classBodyItems
);
if (pairType) {
acc[propertyName].config |= getPropertyBitmask(pairType);
if (
decoratedNodeType === DECORATOR_TYPES.GETTER ||
decoratedNodeType === DECORATOR_TYPES.SETTER
) {
// With the latest decorator spec, only one of the getter/setter pair needs a decorator.
// We need to add the proper bitmask for the sibling getter/setter if it exists.
const pairType = getSiblingGetSetPairType(
propertyName,
decoratedNodeType,
classBodyItems
);
if (pairType) {
acc[propertyName].config |= getPropertyBitmask(pairType);
}
}
}

return acc;
}, {} as { [key: string]: { [key: string]: number } });
return acc;
},
{} as { [key: string]: { [key: string]: number } }
);
}

export default function transform(
Expand Down
29 changes: 16 additions & 13 deletions packages/@lwc/babel-plugin-component/src/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,22 @@ function validateImportedLwcDecoratorUsage(
) {
engineImportSpecifiers
.filter(({ name }) => isLwcDecoratorName(name))
.reduce((acc, { name, path }) => {
// Get a list of all the local references
const local = path.get('imported') as NodePath<types.Identifier>;
const references = getReferences(local).map((reference) => ({
name,
reference,
}));

return [...acc, ...references] as {
name: string;
reference: NodePath<types.Node>;
}[];
}, [] as { name: string; reference: NodePath<types.Node> }[])
.reduce(
(acc, { name, path }) => {
// Get a list of all the local references
const local = path.get('imported') as NodePath<types.Identifier>;
const references = getReferences(local).map((reference) => ({
name,
reference,
}));

return [...acc, ...references] as {
name: string;
reference: NodePath<types.Node>;
}[];
},
[] as { name: string; reference: NodePath<types.Node> }[]
)
.forEach(({ name, reference }) => {
// Get the decorator from the identifier
// If the the decorator is:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ function transform(t: BabelTypes, decoratorMetas: DecoratorMeta[]) {
const objectProperties = [];
const trackDecoratorMetas = decoratorMetas.filter(isTrackDecorator);
if (trackDecoratorMetas.length) {
const config = trackDecoratorMetas.reduce((acc, meta) => {
acc[meta.propertyName] = TRACK_PROPERTY_VALUE;
return acc;
}, {} as { [key: string]: number });
const config = trackDecoratorMetas.reduce(
(acc, meta) => {
acc[meta.propertyName] = TRACK_PROPERTY_VALUE;
return acc;
},
{} as { [key: string]: number }
);
objectProperties.push(
t.objectProperty(t.identifier(LWC_COMPONENT_PROPERTIES.TRACK), t.valueToNode(config))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default function transform(t: BabelTypes, decoratorMetas: DecoratorMeta[]
const wiredValues = decoratorMetas.filter(isWireDecorator).map(({ path }) => {
const [id, config] = path.get('expression.arguments') as [
NodePath,
NodePath<types.ObjectExpression> | undefined
NodePath<types.ObjectExpression> | undefined,
];

const propertyName = (path.parentPath.get('key.name') as any).node as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ if (process.env.IS_BROWSER) {
// aria* properties
for (const [propName, descriptor] of entries(ariaReflectionPolyfillDescriptors) as [
name: string,
descriptor: PropertyDescriptor
descriptor: PropertyDescriptor,
][]) {
lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, descriptor);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/@lwc/engine-core/src/framework/wiring/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type ContextValue = Record<string, any>;

export interface WireAdapter<
Config extends ConfigValue = ConfigValue,
Context extends ContextValue = ContextValue
Context extends ContextValue = ContextValue,
> {
update(config: Config, context?: Context): void;
connect(): void;
Expand All @@ -25,12 +25,12 @@ export interface WireAdapter<
export interface WireAdapterConstructor<
Config extends ConfigValue = ConfigValue,
Value = any,
Context extends ContextValue = ContextValue
Context extends ContextValue = ContextValue,
> {
new (callback: DataCallback<Value>, sourceContext?: { tagName: string }): WireAdapter<
Config,
Context
>;
new (
callback: DataCallback<Value>,
sourceContext?: { tagName: string }
): WireAdapter<Config, Context>;
configSchema?: Record<keyof Config, WireAdapterSchemaValue>;
contextSchema?: Record<keyof Context, WireAdapterSchemaValue>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,10 @@ function createHCONFIG2JSPreprocessor(config, logger, emitter) {
const describeTitle = path.relative(basePath, suiteDir).split(path.sep).join(' ');

try {
const { code: testCode, watchFiles: testWatchFiles } = await getTestModuleCode(
filePath
);
const { code: componentDef, watchFiles: componentWatchFiles } = await getCompiledModule(
suiteDir
);
const { code: testCode, watchFiles: testWatchFiles } =
await getTestModuleCode(filePath);
const { code: componentDef, watchFiles: componentWatchFiles } =
await getCompiledModule(suiteDir);
// You can add an `.only` file alongside an `index.spec.js` file to make it `fdescribe()`
const onlyFileExists = await exists(path.join(suiteDir, '.only'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ describe('slot forwarding', () => {
const defaultSlotTextIndex = USE_LIGHT_DOM_SLOT_FORWARDING
? 12
: USE_COMMENTS_FOR_FRAGMENT_BOOKENDS
? 11
: 4;
? 11
: 4;
const defaultSlotCommentIndex = USE_LIGHT_DOM_SLOT_FORWARDING
? 13
: USE_COMMENTS_FOR_FRAGMENT_BOOKENDS
? 12
: 5;
? 12
: 5;

expect(lightLightLeaf.childNodes[defaultSlotTextIndex].textContent).toEqual(
expectedDefaultSlot.textContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,20 +328,20 @@ describe('regression test (#3827)', () => {
process.env.NATIVE_SHADOW
? []
: !lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
? [
`leaf:${currentLeafName}:connectedCallback`,
`leaf:${previousLeafName}:disconnectedCallback`,
]
: [`leaf:${currentLeafName}:connectedCallback`],
? [
`leaf:${currentLeafName}:connectedCallback`,
`leaf:${previousLeafName}:disconnectedCallback`,
]
: [`leaf:${currentLeafName}:connectedCallback`],
elseIfBlock: (currentLeafName, previousLeafName) =>
process.env.NATIVE_SHADOW
? []
: !lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
? [
`leaf:${currentLeafName}:connectedCallback`,
`leaf:${previousLeafName}:disconnectedCallback`,
]
: [`leaf:${currentLeafName}:connectedCallback`],
? [
`leaf:${currentLeafName}:connectedCallback`,
`leaf:${previousLeafName}:disconnectedCallback`,
]
: [`leaf:${currentLeafName}:connectedCallback`],
},
{
fixtureName: 'light DOM',
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/integration-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Here `<functional-area>` would be the broader area under test such as events, sl

In the above example, `app` and `child` are present because the test verifies event handling between a child and parent component and to reflect the playground setup, but are not required for every test. `<specific-repro>.html` may also use the `<test-case>` template currently used in some lwc-integration tests to cleanly display Github issue and Lightning Web Components playground links.

The level describe blocks inside `<specific-repro>.spec.js` should also note the Github issue number if relevant. For example, `` describe('Issue 657: Cannot attach event in `connectedCallback`', () => {...}) ``.
The level describe blocks inside `<specific-repro>.spec.js` should also note the Github issue number if relevant. For example, ``describe('Issue 657: Cannot attach event in `connectedCallback`', () => {...})``.

If it doesn't require additional components for the repro, you could simply have

Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/ssr-compiler/src/compile-template/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const bYieldEscapedString = esTemplateWithYield<
EsIdentifier,
EsIdentifier,
EsIdentifier,
EsIdentifier
EsIdentifier,
]
>`
const ${is.identifier} = ${is.expression};
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/ssr-compiler/src/estemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function esTemplateImpl<RetType = EsNode, ArgTypes extends ReplacementNode[] = R

export function esTemplate<
RetType = EsNode,
ArgTypes extends ReplacementNode[] = ReplacementNode[]
ArgTypes extends ReplacementNode[] = ReplacementNode[],
>(
javascriptSegments: TemplateStringsArray,
...validatorFns: Validator[]
Expand All @@ -149,7 +149,7 @@ export function esTemplate<

export function esTemplateWithYield<
RetType = EsNode,
ArgTypes extends ReplacementNode[] = ReplacementNode[]
ArgTypes extends ReplacementNode[] = ReplacementNode[],
>(
javascriptSegments: TemplateStringsArray,
...validatorFns: Validator[]
Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/ssr-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class LightningElement {

getAttribute(attrName: string): string | null {
const value = this.__attrs?.[attrName];
return value === true ? '' : value ?? null;
return value === true ? '' : (value ?? null);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@lwc/synthetic-shadow/src/faux-shadow/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ if (process.env.NODE_ENV !== 'test') {
this,
ArraySlice.call(arguments as unknown as unknown[]) as [
namespace: string,
localName: string
localName: string,
]
)
);
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/synthetic-shadow/src/faux-shadow/slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ defineProperties(HTMLSlotElement.prototype, {
return originalAssignedElements.apply(
this,
ArraySlice.call(arguments as unknown as unknown[]) as [
options?: AssignedNodesOptions
options?: AssignedNodesOptions,
]
);
}
Expand All @@ -176,7 +176,7 @@ defineProperties(HTMLSlotElement.prototype, {
return originalAssignedNodes.apply(
this,
ArraySlice.call(arguments as unknown as unknown[]) as [
options?: AssignedNodesOptions
options?: AssignedNodesOptions,
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('fixtures', () => {
root: path.resolve(__dirname, 'fixtures'),
pattern: '**/actual.html',
},
({ src, dirname }) => {
async ({ src, dirname }) => {
const configPath = path.resolve(dirname, 'config.json');
const filename = path.basename(dirname);

Expand All @@ -38,8 +38,10 @@ describe('fixtures', () => {
);

return {
// TODO [#4386]: Prettier v3 returns a promise - add an `await` here
'expected.js': prettier.format(code, { parser: 'babel' }),
'expected.js': await prettier.format(code, {
parser: 'babel',
trailingComma: 'es5',
}),
'ast.json': JSON.stringify({ root }, null, 4),
'metadata.json': JSON.stringify({ warnings }, null, 4),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,30 @@ function tmpl($api, $cmp, $slotset, $ctx) {
$cmp.outer.if
? api_fragment(0, [api_static_fragment($fragment1, 2)], 0)
: $cmp.outer.elseif1
? api_fragment(0, [api_static_fragment($fragment2, 4)], 0)
: $cmp.outer.elseif2
? api_fragment(
0,
[
$cmp.inner.if
? api_fragment(5, [api_static_fragment($fragment3, 7)], 0)
: $cmp.inner.elseif
? api_fragment(5, [api_static_fragment($fragment4, 9)], 0)
: $cmp.inner.elseif2
? api_fragment(
5,
[api_dynamic_component($cmp.trackedProp.foo, stc0)],
0
)
: api_fragment(5, [api_static_fragment($fragment5, 12)], 0),
],
0
)
: api_fragment(0, [api_static_fragment($fragment6, 14)], 0),
? api_fragment(0, [api_static_fragment($fragment2, 4)], 0)
: $cmp.outer.elseif2
? api_fragment(
0,
[
$cmp.inner.if
? api_fragment(5, [api_static_fragment($fragment3, 7)], 0)
: $cmp.inner.elseif
? api_fragment(5, [api_static_fragment($fragment4, 9)], 0)
: $cmp.inner.elseif2
? api_fragment(
5,
[api_dynamic_component($cmp.trackedProp.foo, stc0)],
0
)
: api_fragment(
5,
[api_static_fragment($fragment5, 12)],
0
),
],
0
)
: api_fragment(0, [api_static_fragment($fragment6, 14)], 0),
];
/*LWC compiler vX.X.X*/
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ function tmpl($api, $cmp, $slotset, $ctx) {
$cmp.visible.if
? api_fragment(0, [api_static_fragment($fragment1, 2)], 0)
: $cmp.visible.elseif
? api_fragment(0, [api_static_fragment($fragment2, 4)], 0)
: api_fragment(0, [api_dynamic_component($cmp.trackedProp.foo, stc0)], 0),
? api_fragment(0, [api_static_fragment($fragment2, 4)], 0)
: api_fragment(
0,
[api_dynamic_component($cmp.trackedProp.foo, stc0)],
0
),
];
/*LWC compiler vX.X.X*/
}
Expand Down
Loading

0 comments on commit cdb169a

Please sign in to comment.