diff --git a/src/compiler/transformers/decorators-to-static/watch-decorator.ts b/src/compiler/transformers/decorators-to-static/watch-decorator.ts index 1dad4758af5..d88db9fe32a 100644 --- a/src/compiler/transformers/decorators-to-static/watch-decorator.ts +++ b/src/compiler/transformers/decorators-to-static/watch-decorator.ts @@ -20,25 +20,19 @@ export const watchDecoratorsToStatic = ( } }; -const isWatchDecorator = isDecoratorNamed('Watch'); -const isPropWillChangeDecorator = isDecoratorNamed('PropWillChange'); -const isPropDidChangeDecorator = isDecoratorNamed('PropDidChange'); - const parseWatchDecorator = (config: d.Config, diagnostics: d.Diagnostic[], watchable: Set, method: ts.MethodDeclaration): d.ComponentCompilerWatch[] => { const methodName = method.name.getText(); - return method.decorators - .filter(decorator => isWatchDecorator(decorator) || isPropWillChangeDecorator(decorator) || isPropDidChangeDecorator(decorator)) - .map(decorator => { - const [propName] = getDeclarationParameters(decorator); - if (!watchable.has(propName)) { - const dianostic = config.devMode ? buildWarn(diagnostics) : buildError(diagnostics); - dianostic.messageText = `@Watch('${propName}') is trying to watch for changes in a property that does not exist. + return method.decorators.filter(isDecoratorNamed('Watch')).map(decorator => { + const [propName] = getDeclarationParameters(decorator); + if (!watchable.has(propName)) { + const dianostic = config.devMode ? buildWarn(diagnostics) : buildError(diagnostics); + dianostic.messageText = `@Watch('${propName}') is trying to watch for changes in a property that does not exist. Make sure only properties decorated with @State() or @Prop() are watched.`; - augmentDiagnosticWithNode(dianostic, decorator); - } - return { - propName, - methodName, - }; - }); + augmentDiagnosticWithNode(dianostic, decorator); + } + return { + propName, + methodName, + }; + }); }; diff --git a/src/compiler/transformers/test/parse-watch.spec.ts b/src/compiler/transformers/test/parse-watch.spec.ts index b03af821d3f..d50291448f7 100644 --- a/src/compiler/transformers/test/parse-watch.spec.ts +++ b/src/compiler/transformers/test/parse-watch.spec.ts @@ -30,29 +30,4 @@ describe('parse watch', () => { { methodName: 'onStateUpdated', propName: 'state1' }, ]); }); - - it('legacy PropWillChange and PropDidChange', () => { - const t = transpileModule(` - @Component({tag: 'cmp-a'}) - export class CmpA { - @Prop() prop1; - @Prop() prop2; - - @PropWillChange('prop1') - onUpdate() { - console.log('update'); - } - - @PropDidChange('prop2') - onStateUpdated() { - console.log('state updated'); - } - } - `); - - expect(getStaticGetter(t.outputText, 'watchers')).toEqual([ - { methodName: 'onUpdate', propName: 'prop1' }, - { methodName: 'onStateUpdated', propName: 'prop2' }, - ]); - }); });