Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<x-parent>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this test for symmetry (I know it is covered elsewhere too)

<template shadowrootmode="open">
<x-child>
<template shadowrootmode="open">
const field api value
</template>
</x-child>
<x-child>
<template shadowrootmode="open">
field api value
</template>
</x-child>
</template>
</x-parent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-parent';
export { default } from 'x/parent';
export * from 'x/parent';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
{fieldApi}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement, api } from 'lwc';

export default class Child extends LightningElement {
@api fieldApi;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<template>
<x-child field-api="const field api value"></x-child>
<x-child field-api={fieldApiValue}></x-child>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class Parent extends LightningElement {
fieldApiValue = 'field api value';
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<x-parent>
<template shadowrootmode="open">
<x-child>
<template shadowrootmode="open">
const setter getter api value
</template>
</x-child>
<x-child>
<template shadowrootmode="open">
setter getter api value
</template>
</x-child>
</template>
</x-parent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const tagName = 'x-parent';
export { default } from 'x/parent';
export * from 'x/parent';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
{setterGetterApi}
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { LightningElement, api } from 'lwc';

export default class Child extends LightningElement {
@api set setterGetterApi(value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@api set setterGetterApi(value) {
@api set setter(value) {

Can we also add a @api get getter in this test, to make sure we cover both?

this._someApi = value;
}

get setterGetterApi() {
return this._someApi;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<template>
<x-child setter-getter-api="const setter getter api value"></x-child>
<x-child setter-getter-api={setterGetterApiValue}></x-child>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement } from 'lwc';

export default class Parent extends LightningElement {
setterGetterApiValue = 'setter getter api value';
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LightningElement } from 'lwc';

const privateFields = undefined;
const publicFields = undefined;
const api = undefined;
const stylesheetScopeToken = undefined;
const hasScopedStylesheets = undefined;
const defaultScopedStylesheets = undefined;
Expand All @@ -13,7 +13,7 @@ export default class extends LightningElement {
{},
{
privateFields,
publicFields,
api,
stylesheetScopeToken,
hasScopedStylesheets,
defaultScopedStylesheets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { ComponentMetaState } from './types';

const bGenerateMarkup = esTemplate`
// These variables may mix with component-authored variables, so should be reasonably unique
const __lwcPublicFields__ = new Set(${/*public fields*/ is.arrayExpression});
const __lwcApi__ = new Set(${/*api*/ is.arrayExpression});
const __lwcPrivateFields__ = new Set(${/*private fields*/ is.arrayExpression});

async function* generateMarkup(
Expand All @@ -43,7 +43,7 @@ const bGenerateMarkup = esTemplate`
instance[__SYMBOL__SET_INTERNALS](
props,
attrs,
__lwcPublicFields__,
__lwcApi__,
__lwcPrivateFields__,
);
instance.isConnected = true;
Expand Down Expand Up @@ -101,7 +101,7 @@ export function addGenerateMarkupFunction(
tagName: string,
filename: string
) {
const { privateFields, publicFields, tmplExplicitImports } = state;
const { privateFields, api, tmplExplicitImports } = state;

// The default tag name represents the component name that's passed to the transformer.
// This is needed to generate markup for dynamic components which are invoked through
Expand Down Expand Up @@ -141,7 +141,7 @@ export function addGenerateMarkupFunction(
);
program.body.push(
...bGenerateMarkup(
b.arrayExpression(publicFields.map(b.literal)),
b.arrayExpression(api.map(b.literal)),
b.arrayExpression(privateFields.map(b.literal)),
defaultTagName,
classIdentifier,
Expand Down
6 changes: 4 additions & 2 deletions packages/@lwc/ssr-compiler/src/compile-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const visitors: Visitors = {
validateUniqueDecorator(decorators);
const decoratedExpression = decorators?.[0]?.expression;
if (is.identifier(decoratedExpression) && decoratedExpression.name === 'api') {
state.publicFields.push(node.key.name);
state.api.push(node.key.name);
} else if (
is.callExpression(decoratedExpression) &&
is.identifier(decoratedExpression.callee) &&
Expand Down Expand Up @@ -164,6 +164,8 @@ const visitors: Visitors = {
} else {
catalogWireAdapters(path, state);
}
} else if (is.identifier(decoratedExpression) && decoratedExpression.name === 'api') {
state.api.push(node.key.name);
}

switch (node.key.name) {
Expand Down Expand Up @@ -269,7 +271,7 @@ export default function compileJS(
tmplExplicitImports: null,
cssExplicitImports: null,
staticStylesheetIds: null,
publicFields: [],
api: [],
privateFields: [],
wireAdapters: [],
experimentalDynamicComponent: options.experimentalDynamicComponent,
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/ssr-compiler/src/compile-js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export interface ComponentMetaState {
cssExplicitImports: Map<string, string> | null;
// the set of variable names associated with explicitly imported CSS files
staticStylesheetIds: Set<string> | null;
// the public (`@api`-annotated) fields of the component class
publicFields: Array<string>;
// the public (`@api`-annotated) fields and methods of the component class
api: Array<string>;
// the private fields of the component class
privateFields: Array<string>;
// indicates whether the LightningElement has any wired props
Expand Down
4 changes: 2 additions & 2 deletions packages/@lwc/ssr-runtime/src/lightning-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class LightningElement implements PropsAvailableAtConstruction {
[SYMBOL__SET_INTERNALS](
props: Properties,
attrs: Attributes,
publicFields: Set<string>,
api: Set<string>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I like publicFields better. Makes the high-level intent more obvious.

privateFields: Set<string>
) {
this.#props = props;
Expand All @@ -91,7 +91,7 @@ export class LightningElement implements PropsAvailableAtConstruction {
for (const propName of keys(props)) {
const attrName = htmlPropertyToAttribute(propName);
if (
publicFields.has(propName) ||
api.has(propName) ||
((REFLECTIVE_GLOBAL_PROPERTY_SET.has(propName) || isAriaAttribute(attrName)) &&
!privateFields.has(propName))
) {
Expand Down