Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/word-wrap-1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
CristiCanizales authored Oct 10, 2023
2 parents 49714ba + 53c027c commit 2efa052
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/onPushToMain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:

jobs:
tests:
uses: salesforcecli/github-workflows/.github/workflows/unitTest.yml@main
uses: ./.github/workflows/unitTests.yml
with:
branch: main
release:
runs-on: ubuntu-latest
needs:
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/testCommitExceptMain.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/unitTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Unit Tests
on:
push:
branches-ignore: [main]
workflow_dispatch:
workflow_call:
inputs:
branch:
type: string
required: false

jobs:
unit-tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
nodeVersion: [lts/-1, lts/*]
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
cache: yarn
- uses: google/wireit@setup-github-actions-caching/v1
- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: "**/node_modules"
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}

- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }}
- run: yarn build
- uses: nick-fields/retry@943e742917ac94714d2f408a0e8320f2d1fcafcd
env:
SF_DISABLE_TELEMETRY: true
name: yarn test
with:
max_attempts: 2
command: yarn test
timeout_minutes: 60
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "4.7.0"
"version": "4.7.1"
}
4 changes: 2 additions & 2 deletions packages/aura-language-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/aura-language-server",
"version": "4.7.0",
"version": "4.7.1",
"description": "Language server for Aura components.",
"main": "lib/aura-indexer/indexer.js",
"typings": "lib/shared.d.ts",
Expand All @@ -24,7 +24,7 @@
"package": "yarn pack"
},
"dependencies": {
"@salesforce/lightning-lsp-common": "4.7.0",
"@salesforce/lightning-lsp-common": "4.7.1",
"acorn": "^6.0.0",
"acorn-loose": "^6.0.0",
"acorn-walk": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/lightning-lsp-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/lightning-lsp-common",
"version": "4.7.0",
"version": "4.7.1",
"description": "Common components for lwc-language-server and aura-language-server.",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/lwc-language-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/lwc-language-server",
"version": "4.7.0",
"version": "4.7.1",
"description": "Language server for Lightning Web Components.",
"main": "lib/indexer.js",
"license": "BSD-3-Clause",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@lwc/template-compiler": "2.50.0",
"@salesforce/apex": "0.0.12",
"@salesforce/label": "0.0.12",
"@salesforce/lightning-lsp-common": "4.7.0",
"@salesforce/lightning-lsp-common": "4.7.1",
"@salesforce/resourceurl": "0.0.12",
"@salesforce/schema": "0.0.12",
"@salesforce/user": "0.0.12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ export default class Foo extends LightningElement {
@api property = true;
}
`;
const codeWithoutDefaultExportSingleClass = `
import { api, LightningElement } from 'lwc';
class Foo extends LightningElement {
@api foo;
}
`;
const codeWithoutDefaultExportMultipleClasses = `
import { api, LightningElement } from 'lwc';
class Foo extends LightningElement {
@api foo;
}
class Bar extends LightningElement {
@api bar;
}
`;

it('can get metadata from a simple component', async () => {
await compileSource(codeOk, 'foo.js');
Expand All @@ -46,6 +61,21 @@ it('displays an error for a component with syntax error', async () => {
expect(diagnostic.message).toMatch('Unexpected token (4:17)');
});

it('returns empty metadata for a script without a clear main component class', async () => {
const result = await compileSource(codeWithoutDefaultExportMultipleClasses, 'foo.js');
expect(result.metadata?.decorators).toHaveLength(0);
expect(result.metadata?.classMembers).toHaveLength(0);
expect(result.metadata?.exports).toHaveLength(0);
});

it('returns metadata for a script with one component class, even when not exported', async () => {
const result = await compileSource(codeWithoutDefaultExportSingleClass, 'foo.js');
console.log(result);
expect(result.metadata?.decorators).toHaveLength(1);
expect(result.metadata?.classMembers).toHaveLength(1);
expect(result.metadata?.exports).toHaveLength(0);
});

it('displays an error for a component with other errors', async () => {
const result = await compileSource(codeError, 'foo.js');
expect(result.metadata).toBeUndefined();
Expand Down
21 changes: 18 additions & 3 deletions packages/lwc-language-server/src/javascript/type-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,24 @@ function getExports(lwcExports: LwcExport[]): InternalModuleExports[] {
* LWC language server to analyze code in a user's IDE.
*/
export function mapLwcMetadataToInternal(lwcMeta: ScriptFile): InternalMetadata {
const mainClassObj = lwcMeta.classes.find(classObj => {
return classObj.id == lwcMeta.mainClass.refId;
});
let mainClassObj;
if (lwcMeta.mainClass) {
mainClassObj = lwcMeta.classes.find(classObj => {
return classObj.id == lwcMeta.mainClass.refId;
});
} else if (lwcMeta.classes.length === 1) {
mainClassObj = lwcMeta.classes[0];
}

// If we are unable to identify the main class object from the provided metadata,
// it will not be possible calculate decorators, members, etc.
if (!mainClassObj) {
return {
decorators: [],
classMembers: [],
exports: [],
};
}

const defaultExport = lwcMeta.exports.filter((exp) => exp.defaultExport)[0];
const declarationLoc = externalToInternalLoc(defaultExport?.location ?? mainClassObj.location);
Expand Down

0 comments on commit 2efa052

Please sign in to comment.