Skip to content

Commit

Permalink
fix: fixed for:each error on hover (#491)
Browse files Browse the repository at this point in the history
* fix: fixed for:each error on hover

Addressed an issue where a for:each was not available, and was causing an undefined error.

vscode #3929

* feat: added unit test for case when t.classMembers is undefined

Co-authored-by: Jeff Beeghly <[email protected]>
  • Loading branch information
randi274 and jeffb-sfdc authored Apr 4, 2022
1 parent d37d48f commit 6e8739d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import ComponentIndexer from '../component-indexer';
import { ModuleExports, WireDecorator } from '../decorators';
import { DataProviderAttributes, LWCDataProvider } from '../lwc-data-provider';
import Tag, { TagAttrs } from '../tag';
import * as path from 'path';
import { LWCDataProvider, DataProviderAttributes } from '../lwc-data-provider';

const workspaceRoot: string = path.resolve('../../test-workspaces/sfdx-workspace');
const componentIndexer: ComponentIndexer = new ComponentIndexer({
Expand All @@ -24,6 +26,33 @@ describe('provideValues()', () => {
expect(names).toInclude('info');
expect(names).toInclude('iconName');
});

it('should validate an empty array is returned when tag.classMembers is undefined', () => {
// The setting of the TagAttrs's file property needs to be delayed. It needs to be undefined
// when passed into the ctor(), and then we'll manually set it afterwards.
const tagAttrs: TagAttrs = {
file: undefined,
metadata: {
decorators: [] as WireDecorator[],
exports: [] as ModuleExports[],
},
updatedAt: undefined,
};
const tag = new Tag(tagAttrs);
tag.file = 'path/to/some-file';

const componentIndexer = new ComponentIndexer({
workspaceRoot,
});
componentIndexer.tags.set(tag.name, tag);

const provider = new LWCDataProvider({
indexer: componentIndexer,
});

const values = provider.provideValues();
expect(values).toEqual([]);
});
});

describe('provideAttributes()', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/lwc-language-server/src/lwc-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class LWCDataProvider implements IHTMLDataProvider {
provideValues(): IValueData[] {
const values: IValueData[] = [];
this.indexer.customData.forEach(t => {
t.classMembers.forEach(cm => {
t.classMembers?.forEach(cm => {
const bindName = `${t.name}.${cm.name}`;
values.push({ name: cm.name, description: `${bindName}` });
});
Expand Down

0 comments on commit 6e8739d

Please sign in to comment.