use Records to remove TS errors

pull/736/head
Rich Harris 8 years ago
parent aa59dafb81
commit ac3c1086e3

@ -16,10 +16,14 @@ import DomBlock from './dom/Block';
import SsrBlock from './server-side-rendering/Block';
import Stylesheet from '../css/Stylesheet';
import { Node, GenerateOptions, Parsed, CompileOptions } from '../interfaces';
import { Computation, TemplateProperties } from './interfaces';
const test = typeof global !== 'undefined' && global.__svelte_test;
interface Computation {
key: string;
deps: string[]
}
export default class Generator {
ast: Parsed;
parsed: Parsed;
@ -38,7 +42,7 @@ export default class Generator {
hasComponents: boolean;
hasJs: boolean;
computations: Computation[];
templateProperties: TemplateProperties;
templateProperties: Record<string, Node>;
code: MagicString;
@ -410,7 +414,7 @@ export default class Generator {
const imports = this.imports;
const computations: Computation[] = [];
const templateProperties: TemplateProperties = {};
const templateProperties: Record<string, Node> = {};
let namespace = null;
let hasJs = !!js;
@ -444,7 +448,7 @@ export default class Generator {
['helpers', 'events', 'components', 'transitions'].forEach(key => {
if (templateProperties[key]) {
templateProperties[key].value.properties.forEach((prop: node) => {
templateProperties[key].value.properties.forEach((prop: Node) => {
this[key].add(prop.key.name);
});
}
@ -466,7 +470,7 @@ export default class Generator {
const visited = new Set();
function visit(key: string) {
const visit = function visit(key: string) {
if (!dependencies.has(key)) return; // not a computation
if (visited.has(key)) return;

@ -1,23 +0,0 @@
import { Node } from '../interfaces';
export interface Computation {
key: string;
deps: string[]
}
export interface TemplateProperties {
computed?: Node;
components?: Node;
data?: Node;
events?: Node;
helpers?: Node;
methods?: Node;
namespace?: Node;
oncreate?: Node;
ondestroy?: Node;
transitions?: Node;
// TODO remove in v2
onrender?: Node;
onteardown?: Node;
}

@ -1,6 +1,6 @@
import { Node, Visitor } from '../../../interfaces';
export default function walkHtml(html: Node, visitors) {
export default function walkHtml(html: Node, visitors: Record<string, Visitor>) {
function visit(node: Node) {
const visitor = visitors[node.type];
if (!visitor) throw new Error(`Not implemented: ${node.type}`);

@ -20,4 +20,6 @@ export const validNamespaces = [
xmlns,
];
export default { html, mathml, svg, xlink, xml, xmlns };
const namespaces: Record<string, string> = { html, mathml, svg, xlink, xml, xmlns };
export default namespaces;

Loading…
Cancel
Save