-
Notifications
You must be signed in to change notification settings - Fork 396
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): log warning for missing name/namespace (#4825)
- Loading branch information
1 parent
c4218fc
commit 5d1837b
Showing
5 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
packages/@lwc/babel-plugin-component/src/__tests__/warnings.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, 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 | ||
*/ | ||
import { afterEach, beforeEach, expect, vi, test } from 'vitest'; | ||
import { transformSync } from '@babel/core'; | ||
import plugin from '../index'; | ||
|
||
let spy; | ||
|
||
beforeEach(() => { | ||
spy = vi.spyOn(console, 'warn'); | ||
}); | ||
|
||
afterEach(() => { | ||
spy!.mockReset(); | ||
}); | ||
|
||
test('warns on missing name/namespace', () => { | ||
const source = ` | ||
import { LightningElement } from 'lwc'; | ||
export default class extends LightningElement {}; | ||
`; | ||
|
||
const { code } = transformSync(source, { | ||
babelrc: false, | ||
configFile: false, | ||
filename: `foo.js`, | ||
plugins: [ | ||
[ | ||
plugin, | ||
{ | ||
namespace: '', | ||
name: '', | ||
}, | ||
], | ||
], | ||
})!; | ||
|
||
// compilation works successfully | ||
expect(code).toBeTypeOf('string'); | ||
|
||
expect(spy!).toHaveBeenCalledOnce(); | ||
expect(spy!).toHaveBeenCalledWith( | ||
'The namespace and name should both be non-empty strings. You may get unexpected behavior at runtime. Found: namespace="" and name=""' | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters