Skip to content

Commit

Permalink
fix(compiler): warn about properties that look like events
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Oct 10, 2019
1 parent d50c1b0 commit 25f60fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/compiler/transformers/reserved-public-members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import ts from 'typescript';


export const validatePublicName = (config: d.Config, diagnostics: d.Diagnostic[], memberName: string, decorator: string, memberType: string, node: ts.Node) => {
if (/^on(-|[A-Z])/.test(memberName)) {
const warn = buildWarn(diagnostics);
warn.messageText = [
`The ${decorator} name "${memberName}" looks like an event.`,
`Please use the "@Event()" decorator to expose events instead, not properties or methods.`,
].join('');
augmentDiagnosticWithNode(config, warn, node);
return;
}
if (RESERVED_PUBLIC_MEMBERS.has(memberName.toLowerCase())) {
const warn = buildWarn(diagnostics);
warn.messageText = [
Expand All @@ -13,6 +22,7 @@ export const validatePublicName = (config: d.Config, diagnostics: d.Diagnostic[]
`unexpected runtime errors or user-interface issues on various browsers, so it's best to avoid them entirely.`
].join('');
augmentDiagnosticWithNode(config, warn, node);
return;
}
};

Expand Down Expand Up @@ -267,9 +277,11 @@ const JSX_KEYS = [
'key'
];

const RESERVED_PUBLIC_MEMBERS = new Set([
const ALL_KEYS = [
...HTML_ELEMENT_KEYS,
...ELEMENT_KEYS,
...NODE_KEYS,
...JSX_KEYS,
].map(p => p.toLowerCase()));
].map(p => p.toLowerCase());

const RESERVED_PUBLIC_MEMBERS = new Set(ALL_KEYS);
2 changes: 1 addition & 1 deletion src/testing/puppeteer/puppeteer-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function consoleMessage(c: puppeteer.ConsoleMessage) {
}

function serializeConsoleMessage(c: puppeteer.ConsoleMessage) {
return `${c.text()} ${serializeLocation(c.location())}`
return `${c.text()} ${serializeLocation(c.location())}`;
}

function serializeLocation(loc: puppeteer.ConsoleMessageLocation) {
Expand Down

0 comments on commit 25f60fe

Please sign in to comment.