Skip to content

Commit

Permalink
feat(listener): remove deprecated listen target
Browse files Browse the repository at this point in the history
Use @listen(eventName, { target: 'window' }) instead
  • Loading branch information
adamdbradley committed Aug 5, 2020
1 parent 7480f92 commit 1a3b519
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions src/compiler/transformers/decorators-to-static/listen-decorator.ts
@@ -1,5 +1,5 @@
import * as d from '../../../declarations';
import { augmentDiagnosticWithNode, buildError, buildWarn, flatOne } from '@utils';
import { augmentDiagnosticWithNode, buildError, flatOne } from '@utils';
import { convertValueToLiteral, createStaticGetter } from '../transform-utils';
import { getDeclarationParameters, isDecoratorNamed } from './decorator-utils';
import ts from 'typescript';
Expand Down Expand Up @@ -30,40 +30,16 @@ const parseListenDecorators = (diagnostics: d.Diagnostic[], method: ts.MethodDec
augmentDiagnosticWithNode(err, listenDecorator);
}

return parseListener(diagnostics, eventNames[0], listenOptions, methodName, listenDecorator);
return parseListener(eventNames[0], listenOptions, methodName);
});
};

export const parseListener = (diagnostics: d.Diagnostic[], eventName: string, opts: d.ListenOptions = {}, methodName: string, decoratorNode: ts.Decorator) => {
let rawEventName = eventName.trim();
let target = opts.target;

// DEPRECATED: handle old syntax (`TARGET:event`)
if (!target) {
const splt = eventName.split(':');
const prefix = splt[0].toLowerCase().trim();
if (splt.length > 1 && isValidTargetValue(prefix)) {
rawEventName = splt[1].trim();
target = prefix;
const warn = buildWarn(diagnostics);
warn.messageText = `Deprecated @Listen() feature on "${methodName}". Use @Listen('${rawEventName}', { target: '${prefix}' }) instead.`;
augmentDiagnosticWithNode(warn, decoratorNode);
}
}

// DEPRECATED: handle keycode syntax (`event:KEY`)
const [finalEvent, keycode, rest] = rawEventName.split('.');
if (rest === undefined && isValidKeycodeSuffix(keycode)) {
rawEventName = finalEvent;
const warn = buildError(diagnostics);
warn.messageText = `Deprecated @Listen() feature on "${methodName}". Using "${rawEventName}" is no longer supported, use "event.key" within the function itself instead.`;
augmentDiagnosticWithNode(warn, decoratorNode);
}

export const parseListener = (eventName: string, opts: d.ListenOptions = {}, methodName: string) => {
const rawEventName = eventName.trim();
const listener: d.ComponentCompilerListener = {
name: rawEventName,
method: methodName,
target,
target: opts.target,
capture: typeof opts.capture === 'boolean' ? opts.capture : false,
passive:
typeof opts.passive === 'boolean'
Expand Down

0 comments on commit 1a3b519

Please sign in to comment.