Skip to content

Commit

Permalink
Remove Lit 1 -> Lit 2 migration warnings (#3762)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfagnani committed Mar 24, 2023
1 parent f26de47 commit 23c404f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 193 deletions.
8 changes: 8 additions & 0 deletions .changeset/fifty-forks-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@lit/reactive-element': patch
'lit-element': patch
'lit-html': patch
'lit': patch
---

Remove Lit 1 -> Lit 2 migration warnings
30 changes: 0 additions & 30 deletions packages/lit-element/src/lit-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,36 +235,6 @@ const polyfillSupport = DEV_MODE
: globalThis.litElementPolyfillSupport;
polyfillSupport?.({LitElement});

// DEV mode warnings
if (DEV_MODE) {
/* eslint-disable @typescript-eslint/no-explicit-any */
// Note, for compatibility with closure compilation, this access
// needs to be as a string property index.
(LitElement as any)['finalize'] = function (this: typeof LitElement) {
const finalized = (ReactiveElement as any).finalize.call(this);
if (!finalized) {
return false;
}
const warnRemovedOrRenamed = (obj: any, name: string, renamed = false) => {
if (obj.hasOwnProperty(name)) {
const ctorName = (typeof obj === 'function' ? obj : obj.constructor)
.name;
issueWarning(
renamed ? 'renamed-api' : 'removed-api',
`\`${name}\` is implemented on class ${ctorName}. It ` +
`has been ${renamed ? 'renamed' : 'removed'} ` +
`in this version of LitElement.`
);
}
};
warnRemovedOrRenamed(this, 'render');
warnRemovedOrRenamed(this, 'getStyles', true);
warnRemovedOrRenamed((this as typeof LitElement).prototype, 'adoptStyles');
return true;
};
/* eslint-enable @typescript-eslint/no-explicit-any */
}

/**
* END USERS SHOULD NOT RELY ON THIS OBJECT.
*
Expand Down
57 changes: 0 additions & 57 deletions packages/lit-element/src/test/lit-element_dev_mode_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import {LitElement} from 'lit-element';
import {generateElementName} from './test-helpers.js';
import {assert} from '@esm-bundle/chai';

// Note, since tests are not built with production support, detect DEV_MODE
Expand Down Expand Up @@ -47,61 +46,5 @@ if (DEV_MODE) {
1
);
});

test('warns when `static render` is implemented', () => {
class WarnRender extends LitElement {
static render() {}
}
customElements.define(generateElementName(), WarnRender);
new WarnRender();
assert.equal(warnings.length, 1);
assert.include(warnings[0], 'render');
});

test('warns on first instance only', () => {
class WarnFirstInstance extends LitElement {
static render() {}
}
customElements.define(generateElementName(), WarnFirstInstance);
new WarnFirstInstance();
new WarnFirstInstance();
new WarnFirstInstance();
assert.equal(warnings.length, 1);
assert.include(warnings[0], 'render');
});

test('warns once per implementation (does not spam)', () => {
class WarnPerImpl extends LitElement {
static render() {}
}
customElements.define(generateElementName(), WarnPerImpl);
class WarnPerImplSub extends WarnPerImpl {}
customElements.define(generateElementName(), WarnPerImplSub);
new WarnPerImpl();
new WarnPerImplSub();
assert.equal(warnings.length, 1);
assert.include(warnings[0], WarnPerImpl.name);
assert.include(warnings[0], 'render');
});

test('warns when `static getStyles` is implemented', () => {
class WarnGetStyles extends LitElement {
static getStyles() {}
}
customElements.define(generateElementName(), WarnGetStyles);
new WarnGetStyles();
assert.equal(warnings.length, 1);
assert.include(warnings[0], 'getStyles');
});

test('warns when `adoptStyles` is implemented', () => {
class WarnAdoptStyles extends LitElement {
adoptStyles() {}
}
customElements.define(generateElementName(), WarnAdoptStyles);
new WarnAdoptStyles();
assert.equal(warnings.length, 1);
assert.include(warnings[0], 'adoptStyles');
});
});
}
44 changes: 0 additions & 44 deletions packages/reactive-element/src/reactive-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ if (NODE_MODE) {

const DEV_MODE = true;

let requestUpdateThenable: (name: string) => {
then: (
onfulfilled?: (value: boolean) => void,
_onrejected?: () => void
) => void;
};

let issueWarning: (code: string, warning: string) => void;

const trustedTypes = (global as unknown as {trustedTypes?: {emptyScript: ''}})
Expand Down Expand Up @@ -93,22 +86,6 @@ if (DEV_MODE) {
`the \`polyfill-support\` module has not been loaded.`
);
}

requestUpdateThenable = (name) => ({
then: (
onfulfilled?: (value: boolean) => void,
_onrejected?: () => void
) => {
issueWarning(
'request-update-promise',
`The \`requestUpdate\` method should no longer return a Promise but ` +
`does so on \`${name}\`. Use \`updateComplete\` instead.`
);
if (onfulfilled !== undefined) {
onfulfilled(false);
}
},
});
}

/**
Expand Down Expand Up @@ -797,22 +774,6 @@ export abstract class ReactiveElement
}
}
this.elementStyles = this.finalizeStyles(this.styles);
// DEV mode warnings
if (DEV_MODE) {
const warnRemovedOrRenamed = (name: string, renamed = false) => {
if (this.prototype.hasOwnProperty(name)) {
issueWarning(
renamed ? 'renamed-api' : 'removed-api',
`\`${name}\` is implemented on class ${this.name}. It ` +
`has been ${renamed ? 'renamed' : 'removed'} ` +
`in this version of LitElement.`
);
}
};
warnRemovedOrRenamed('initialize');
warnRemovedOrRenamed('requestUpdateInternal');
warnRemovedOrRenamed('_getUpdateComplete', true);
}
return true;
}

Expand Down Expand Up @@ -1211,11 +1172,6 @@ export abstract class ReactiveElement
if (!this.isUpdatePending && shouldRequestUpdate) {
this.__updatePromise = this.__enqueueUpdate();
}
// Note, since this no longer returns a promise, in dev mode we return a
// thenable which warns if it's called.
return DEV_MODE
? (requestUpdateThenable(this.localName) as unknown as void)
: undefined;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,54 +62,6 @@ if (DEV_MODE) {
);
});

test('warns when `initialize` is implemented', () => {
class WarnInitialize extends ReactiveElement {
initialize() {}
}
customElements.define(generateElementName(), WarnInitialize);
new WarnInitialize();
assert.equal(warnings.length, 1);
assert.include(warnings[0], WarnInitialize.name);
assert.include(warnings[0], 'initialize');
});

test('warns on first instance only', () => {
class WarnFirstInstance extends ReactiveElement {
initialize() {}
}
customElements.define(generateElementName(), WarnFirstInstance);
new WarnFirstInstance();
new WarnFirstInstance();
new WarnFirstInstance();
assert.equal(warnings.length, 1);
assert.include(warnings[0], WarnFirstInstance.name);
assert.include(warnings[0], 'initialize');
});

test('warns once per implementation (does not spam)', () => {
class WarnPerImplBase extends ReactiveElement {
initialize() {}
}
customElements.define(generateElementName(), WarnPerImplBase);
class WarnPerImplSub extends WarnPerImplBase {}
customElements.define(generateElementName(), WarnPerImplSub);
new WarnPerImplBase();
new WarnPerImplSub();
assert.equal(warnings.length, 1);
assert.include(warnings[0], WarnPerImplBase.name);
assert.include(warnings[0], 'initialize');
});

test('warns when `requestUpdateInternal` is implemented', () => {
class WarnRequestUpdateInternal extends ReactiveElement {
requestUpdateInternal() {}
}
customElements.define(generateElementName(), WarnRequestUpdateInternal);
new WarnRequestUpdateInternal();
assert.equal(warnings.length, 1);
assert.include(warnings[0], 'requestUpdateInternal');
});

suite('shadowed reactive properties', () => {
test('throws when reactive properties defined by the current class are shadowed by class fields', async () => {
class ShadowedProps extends ReactiveElement {
Expand Down Expand Up @@ -271,20 +223,6 @@ if (DEV_MODE) {
});
});

test('warns when awaiting `requestUpdate`', async () => {
class WarnAwaitRequestUpdate extends ReactiveElement {}
customElements.define(generateElementName(), WarnAwaitRequestUpdate);
const a = new WarnAwaitRequestUpdate();
container.appendChild(a);
await a.requestUpdate();
assert.equal(warnings.length, 1);
assert.include(warnings[0], 'requestUpdate');
assert.include(warnings[0], 'Promise');
// warns once, does not spam.
await a.requestUpdate();
assert.equal(warnings.length, 1);
});

suite('conditional warnings', () => {
test('warns when `toAttribute` returns undefined with migration warnings on', async () => {
class WarnAttribute extends ReactiveElement {
Expand Down

0 comments on commit 23c404f

Please sign in to comment.